public static void main(String[] args) throws Exception { BufferedReader inReader = new BufferedReader(new InputStreamReader(System.in)); Client c = new BaseClient(); int connected = c.connect(Constants.HOSTNAME, Constants.PORT); if (connected != 0) { exitApp(); } String msg; do { c.doLogin(); } while (c.isConnected() && !c.isLoggedIn()); while (c.isConnected()) { msg = inReader.readLine(); if (!StringUtils.isBlank(msg)) { if (Utils.matchesClinetCommonCommandPattern(msg)) { // сообщение содержит комманду c.sendRawText(msg); } else { c.send(msg); } } } c.stop(); exitApp(); }
public static void initCore() throws DaemonException, SuException { if (mCoreInitialized) return; String socket_path = getCorePath() + "/cSploitd.sock"; if (!Client.isConnected()) { if (!Client.Connect(socket_path)) { startCoreDaemon(); if (!Client.Connect(socket_path)) throw new DaemonException("cannot connect to core daemon"); } } if (!Client.isAuthenticated() && !Client.Login("android", "DEADBEEF")) { throw new DaemonException("cannot login to core daemon"); } if (!Client.LoadHandlers()) { throw new DaemonException("cannot load handlers"); } ChildManager.storeHandlers(); reloadTools(); mCoreInitialized = true; }
/** shutdown the core daemon */ public static void shutdownCoreDaemon() { if (!Client.isConnected() && !Client.Connect(getCorePath() + "/cSploitd.sock")) { return; // daemon is not running } if (!Client.isAuthenticated() && !Client.Login("android", "DEADBEEF")) { Logger.error("cannot login to daemon"); } Client.Shutdown(); Client.Disconnect(); mInitialized = false; }
public boolean isConnected() { return client.isConnected(); }
boolean sendMessage(OutMessage message, boolean sendChatState) { // check for correct receipt status and reset it KonMessage.Status status = message.getStatus(); assert status == KonMessage.Status.PENDING || status == KonMessage.Status.ERROR; message.setStatus(KonMessage.Status.PENDING); if (!mClient.isConnected()) { LOGGER.info("not sending message(s), not connected"); return false; } MessageContent content = message.getContent(); MessageContent.Attachment att = content.getAttachment().orElse(null); if (att != null && !att.hasURL()) { LOGGER.warning("attachment not uploaded"); message.setStatus(KonMessage.Status.ERROR); return false; } boolean encrypted = message.getCoderStatus().getEncryption() != Coder.Encryption.NOT || message.getCoderStatus().getSigning() != Coder.Signing.NOT; Chat chat = message.getChat(); Message protoMessage = encrypted ? new Message() : rawMessage(content, chat, false); protoMessage.setType(Message.Type.chat); protoMessage.setStanzaId(message.getXMPPID()); String threadID = chat.getXMPPID(); if (!threadID.isEmpty()) protoMessage.setThread(threadID); // extensions // TODO with group chat? (for muc "NOT RECOMMENDED") if (!chat.isGroupChat()) protoMessage.addExtension(new DeliveryReceiptRequest()); if (sendChatState) protoMessage.addExtension(new ChatStateExtension(ChatState.active)); if (encrypted) { byte[] encryptedData = content.isComplex() || chat.isGroupChat() ? Coder.encryptStanza(message, rawMessage(content, chat, true).toXML().toString()) .orElse(null) : Coder.encryptMessage(message).orElse(null); // check also for security errors just to be sure if (encryptedData == null || !message.getCoderStatus().getErrors().isEmpty()) { LOGGER.warning("encryption failed"); message.setStatus(KonMessage.Status.ERROR); mControl.handleSecurityErrors(message); return false; } protoMessage.addExtension(new E2EEncryption(encryptedData)); } // transmission specific Transmission[] transmissions = message.getTransmissions(); ArrayList<Message> sendMessages = new ArrayList<>(transmissions.length); for (Transmission transmission : message.getTransmissions()) { Message sendMessage = protoMessage.clone(); JID to = transmission.getJID(); if (!to.isValid()) { LOGGER.warning("invalid JID: " + to); return false; } sendMessage.setTo(to.string()); sendMessages.add(sendMessage); } return mClient.sendPackets(sendMessages.toArray(new Message[0])); }