Search in sources :

Example 26 with MessagePacket

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

the class MessageGenerator method generateAxolotlChat.

public MessagePacket generateAxolotlChat(Message message, XmppAxolotlMessage axolotlMessage) {
    MessagePacket packet = preparePacket(message);
    if (axolotlMessage == null) {
        return null;
    }
    packet.setAxolotlMessage(axolotlMessage.toElement());
    if (Config.supportUnencrypted() && !recipientSupportsOmemo(message)) {
        packet.setBody(OMEMO_FALLBACK_MESSAGE);
    }
    packet.addChild("store", "urn:xmpp:hints");
    packet.addChild("encryption", "urn:xmpp:eme:0").setAttribute("name", "OMEMO").setAttribute("namespace", AxolotlService.PEP_PREFIX);
    return packet;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket)

Example 27 with MessagePacket

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

the class XmppConnection method processPacket.

private Element processPacket(final Tag currentTag, final int packetType) throws XmlPullParserException, IOException {
    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:
            return null;
    }
    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()) {
            final Element child = tagReader.readElement(nextTag);
            final String type = currentTag.getAttribute("type");
            if (packetType == PACKET_IQ && "jingle".equals(child.getName()) && ("set".equalsIgnoreCase(type) || "get".equalsIgnoreCase(type))) {
                element = new JinglePacket();
                element.setAttributes(currentTag.getAttributes());
            }
            element.addChild(child);
        }
        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");
    }
    ++stanzasReceived;
    lastPacketReceived = SystemClock.elapsedRealtime();
    if (Config.BACKGROUND_STANZA_LOGGING && mXmppConnectionService.checkListeners()) {
        Log.d(Config.LOGTAG, "[background stanza] " + element);
    }
    return element;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) 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)

Example 28 with MessagePacket

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

the class XmppConnection method sendPacket.

private synchronized void sendPacket(final AbstractStanza packet) {
    if (stanzasSent == Integer.MAX_VALUE) {
        resetStreamId();
        disconnect(true);
        return;
    }
    synchronized (this.mStanzaQueue) {
        tagWriter.writeStanzaAsync(packet);
        if (packet instanceof AbstractAcknowledgeableStanza) {
            AbstractAcknowledgeableStanza stanza = (AbstractAcknowledgeableStanza) packet;
            ++stanzasSent;
            this.mStanzaQueue.append(stanzasSent, stanza);
            if (stanza instanceof MessagePacket && stanza.getId() != null && getFeatures().sm()) {
                if (Config.EXTENDED_SM_LOGGING) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": requesting ack for message stanza #" + stanzasSent);
                }
                tagWriter.writeStanzaAsync(new RequestPacket(this.smVersion));
            }
        }
    }
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) AbstractAcknowledgeableStanza(eu.siacs.conversations.xmpp.stanzas.AbstractAcknowledgeableStanza) RequestPacket(eu.siacs.conversations.xmpp.stanzas.streammgmt.RequestPacket)

Example 29 with MessagePacket

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

the class XmppConnection method processMessage.

private void processMessage(final Tag currentTag) throws XmlPullParserException, IOException {
    final MessagePacket packet = (MessagePacket) processPacket(currentTag, PACKET_MESSAGE);
    this.messageListener.onMessagePacketReceived(account, packet);
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket)

Aggregations

MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)29 Element (eu.siacs.conversations.xml.Element)8 Account (eu.siacs.conversations.entities.Account)6 Conversation (eu.siacs.conversations.entities.Conversation)6 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)5 Message (eu.siacs.conversations.entities.Message)5 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)4 Jid (eu.siacs.conversations.xmpp.jid.Jid)4 AbstractAcknowledgeableStanza (eu.siacs.conversations.xmpp.stanzas.AbstractAcknowledgeableStanza)3 Session (net.java.otr4j.session.Session)3 MucOptions (eu.siacs.conversations.entities.MucOptions)2 Tag (eu.siacs.conversations.xml.Tag)2 RequestPacket (eu.siacs.conversations.xmpp.stanzas.streammgmt.RequestPacket)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 OtrException (net.java.otr4j.OtrException)2 Bundle (android.os.Bundle)1 Bookmark (eu.siacs.conversations.entities.Bookmark)1 Contact (eu.siacs.conversations.entities.Contact)1 HttpConnectionManager (eu.siacs.conversations.http.HttpConnectionManager)1