Search in sources :

Example 36 with Jid

use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.

the class MessageParser method extractInvite.

private Invite extractInvite(Element message) {
    final Element mucUser = message.findChild("x", Namespace.MUC_USER);
    if (mucUser != null) {
        Element invite = mucUser.findChild("invite");
        if (invite != null) {
            String password = mucUser.findChildContent("password");
            Jid from = InvalidJid.getNullForInvalid(invite.getAttributeAsJid("from"));
            Jid room = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from"));
            if (room == null) {
                return null;
            }
            return new Invite(room, password, false, from);
        }
    }
    final Element conference = message.findChild("x", "jabber:x:conference");
    if (conference != null) {
        Jid from = InvalidJid.getNullForInvalid(message.getAttributeAsJid("from"));
        Jid room = InvalidJid.getNullForInvalid(conference.getAttributeAsJid("jid"));
        if (room == null) {
            return null;
        }
        return new Invite(room, conference.getAttribute("password"), true, from);
    }
    return null;
}
Also used : InvalidJid(eu.siacs.conversations.xmpp.InvalidJid) Jid(eu.siacs.conversations.xmpp.Jid) Element(eu.siacs.conversations.xml.Element)

Example 37 with Jid

use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.

the class MessageParser method handleErrorMessage.

private boolean handleErrorMessage(final Account account, final MessagePacket packet) {
    if (packet.getType() == MessagePacket.TYPE_ERROR) {
        if (packet.fromServer(account)) {
            final Pair<MessagePacket, Long> forwarded = packet.getForwardedMessagePacket("received", "urn:xmpp:carbons:2");
            if (forwarded != null) {
                return handleErrorMessage(account, forwarded.first);
            }
        }
        final Jid from = packet.getFrom();
        final String id = packet.getId();
        if (from != null && id != null) {
            if (id.startsWith(JingleRtpConnection.JINGLE_MESSAGE_PROPOSE_ID_PREFIX)) {
                final String sessionId = id.substring(JingleRtpConnection.JINGLE_MESSAGE_PROPOSE_ID_PREFIX.length());
                mXmppConnectionService.getJingleConnectionManager().updateProposedSessionDiscovered(account, from, sessionId, JingleConnectionManager.DeviceDiscoveryState.FAILED);
                return true;
            }
            if (id.startsWith(JingleRtpConnection.JINGLE_MESSAGE_PROCEED_ID_PREFIX)) {
                final String sessionId = id.substring(JingleRtpConnection.JINGLE_MESSAGE_PROCEED_ID_PREFIX.length());
                mXmppConnectionService.getJingleConnectionManager().failProceed(account, from, sessionId);
                return true;
            }
            mXmppConnectionService.markMessage(account, from.asBareJid(), id, Message.STATUS_SEND_FAILED, extractErrorMessage(packet));
            final Element error = packet.findChild("error");
            final boolean pingWorthyError = error != null && (error.hasChild("not-acceptable") || error.hasChild("remote-server-timeout") || error.hasChild("remote-server-not-found"));
            if (pingWorthyError) {
                Conversation conversation = mXmppConnectionService.find(account, from);
                if (conversation != null && conversation.getMode() == Conversational.MODE_MULTI) {
                    if (conversation.getMucOptions().online()) {
                        Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received ping worthy error for seemingly online muc at " + from);
                        mXmppConnectionService.mucSelfPingAndRejoin(conversation);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) InvalidJid(eu.siacs.conversations.xmpp.InvalidJid) Jid(eu.siacs.conversations.xmpp.Jid) Element(eu.siacs.conversations.xml.Element) Conversation(eu.siacs.conversations.entities.Conversation)

Example 38 with Jid

use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.

the class IqParser method rosterItems.

private void rosterItems(final Account account, final Element query) {
    final String version = query.getAttribute("ver");
    if (version != null) {
        account.getRoster().setVersion(version);
    }
    for (final Element item : query.getChildren()) {
        if (item.getName().equals("item")) {
            final Jid jid = InvalidJid.getNullForInvalid(item.getAttributeAsJid("jid"));
            if (jid == null) {
                continue;
            }
            final String name = item.getAttribute("name");
            final String subscription = item.getAttribute("subscription");
            final Contact contact = account.getRoster().getContact(jid);
            boolean bothPre = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
            if (!contact.getOption(Contact.Options.DIRTY_PUSH)) {
                contact.setServerName(name);
                contact.parseGroupsFromElement(item);
            }
            if ("remove".equals(subscription)) {
                contact.resetOption(Contact.Options.IN_ROSTER);
                contact.resetOption(Contact.Options.DIRTY_DELETE);
                contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
            } else {
                contact.setOption(Contact.Options.IN_ROSTER);
                contact.resetOption(Contact.Options.DIRTY_PUSH);
                contact.parseSubscriptionFromElement(item);
            }
            boolean both = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
            if ((both != bothPre) && both) {
                Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": gained mutual presence subscription with " + contact.getJid());
                AxolotlService axolotlService = account.getAxolotlService();
                if (axolotlService != null) {
                    axolotlService.clearErrorsInFetchStatusMap(contact.getJid());
                }
            }
            mXmppConnectionService.getAvatarService().clear(contact);
        }
    }
    mXmppConnectionService.updateConversationUi();
    mXmppConnectionService.updateRosterUi();
    mXmppConnectionService.getShortcutService().refresh();
    mXmppConnectionService.syncRoster(account);
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) InvalidJid(eu.siacs.conversations.xmpp.InvalidJid) Jid(eu.siacs.conversations.xmpp.Jid) Element(eu.siacs.conversations.xml.Element) Contact(eu.siacs.conversations.entities.Contact)

Example 39 with Jid

use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.

the class IqParser method items.

public static List<Jid> items(IqPacket packet) {
    ArrayList<Jid> items = new ArrayList<>();
    final Element query = packet.findChild("query", Namespace.DISCO_ITEMS);
    if (query == null) {
        return items;
    }
    for (Element child : query.getChildren()) {
        if ("item".equals(child.getName())) {
            Jid jid = child.getAttributeAsJid("jid");
            if (jid != null) {
                items.add(jid);
            }
        }
    }
    return items;
}
Also used : InvalidJid(eu.siacs.conversations.xmpp.InvalidJid) Jid(eu.siacs.conversations.xmpp.Jid) Element(eu.siacs.conversations.xml.Element) ArrayList(java.util.ArrayList)

Example 40 with Jid

use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.

the class DatabaseBackend method getAccountJids.

public List<Jid> getAccountJids(final boolean enabledOnly) {
    SQLiteDatabase db = this.getReadableDatabase();
    final List<Jid> jids = new ArrayList<>();
    final String[] columns = new String[] { Account.USERNAME, Account.SERVER };
    String where = enabledOnly ? "not options & (1 <<1)" : null;
    Cursor cursor = db.query(Account.TABLENAME, columns, where, null, null, null, null);
    try {
        while (cursor.moveToNext()) {
            jids.add(Jid.of(cursor.getString(0), cursor.getString(1), null));
        }
        return jids;
    } catch (Exception e) {
        return jids;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
Also used : InvalidJid(eu.siacs.conversations.xmpp.InvalidJid) Jid(eu.siacs.conversations.xmpp.Jid) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) JSONException(org.json.JSONException) CertificateEncodingException(java.security.cert.CertificateEncodingException) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

Aggregations

Jid (eu.siacs.conversations.xmpp.Jid)106 Account (eu.siacs.conversations.entities.Account)35 Element (eu.siacs.conversations.xml.Element)24 Conversation (eu.siacs.conversations.entities.Conversation)22 Contact (eu.siacs.conversations.entities.Contact)17 InvalidJid (eu.siacs.conversations.xmpp.InvalidJid)16 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)16 Intent (android.content.Intent)15 ArrayList (java.util.ArrayList)13 MucOptions (eu.siacs.conversations.entities.MucOptions)12 Bookmark (eu.siacs.conversations.entities.Bookmark)10 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)7 Message (eu.siacs.conversations.entities.Message)7 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)6 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)6 Map (java.util.Map)6 XmppUri (eu.siacs.conversations.utils.XmppUri)5 XmppConnectionService (eu.siacs.conversations.services.XmppConnectionService)4 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)4 HashMap (java.util.HashMap)4