Search in sources :

Example 11 with PresencePacket

use of eu.siacs.conversations.xmpp.stanzas.PresencePacket in project Conversations by siacs.

the class XmppConnection method processPacket.

@NonNull
private Element processPacket(final Tag currentTag, final int packetType) throws IOException {
    final Element element;
    switch(packetType) {
        case PACKET_IQ:
            element = new IqPacket();
            break;
        case PACKET_MESSAGE:
            element = new MessagePacket();
            break;
        case PACKET_PRESENCE:
            element = new PresencePacket();
            break;
        default:
            throw new AssertionError("Should never encounter invalid type");
    }
    element.setAttributes(currentTag.getAttributes());
    Tag nextTag = tagReader.readTag();
    if (nextTag == null) {
        throw new IOException("interrupted mid tag");
    }
    while (!nextTag.isEnd(element.getName())) {
        if (!nextTag.isNo()) {
            element.addChild(tagReader.readElement(nextTag));
        }
        nextTag = tagReader.readTag();
        if (nextTag == null) {
            throw new IOException("interrupted mid tag");
        }
    }
    if (stanzasReceived == Integer.MAX_VALUE) {
        resetStreamId();
        throw new IOException("time to restart the session. cant handle >2 billion pcks");
    }
    if (inSmacksSession) {
        ++stanzasReceived;
    } else if (features.sm()) {
        Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": not counting stanza(" + element.getClass().getSimpleName() + "). Not in smacks session.");
    }
    lastPacketReceived = SystemClock.elapsedRealtime();
    if (Config.BACKGROUND_STANZA_LOGGING && mXmppConnectionService.checkListeners()) {
        Log.d(Config.LOGTAG, "[background stanza] " + element);
    }
    if (element instanceof IqPacket && (((IqPacket) element).getType() == IqPacket.TYPE.SET) && element.hasChild("jingle", Namespace.JINGLE)) {
        return JinglePacket.upgrade((IqPacket) element);
    } else {
        return element;
    }
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Element(eu.siacs.conversations.xml.Element) Tag(eu.siacs.conversations.xml.Tag) IOException(java.io.IOException) PresencePacket(eu.siacs.conversations.xmpp.stanzas.PresencePacket) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket) NonNull(androidx.annotation.NonNull)

Aggregations

PresencePacket (eu.siacs.conversations.xmpp.stanzas.PresencePacket)11 MucOptions (eu.siacs.conversations.entities.MucOptions)3 Element (eu.siacs.conversations.xml.Element)3 Account (eu.siacs.conversations.entities.Account)2 Bookmark (eu.siacs.conversations.entities.Bookmark)2 Conversation (eu.siacs.conversations.entities.Conversation)2 Jid (eu.siacs.conversations.xmpp.Jid)2 NonNull (androidx.annotation.NonNull)1 OnRenameListener (eu.siacs.conversations.entities.MucOptions.OnRenameListener)1 Presence (eu.siacs.conversations.entities.Presence)1 Tag (eu.siacs.conversations.xml.Tag)1 XmppConnection (eu.siacs.conversations.xmpp.XmppConnection)1 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)1 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)1 IOException (java.io.IOException)1