Search in sources :

Example 6 with JinglePacket

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

the class XmppConnection method processIq.

private void processIq(final Tag currentTag) throws XmlPullParserException, IOException {
    final IqPacket packet = (IqPacket) processPacket(currentTag, PACKET_IQ);
    if (packet.getId() == null) {
        // an iq packet without id is definitely invalid
        return;
    }
    if (packet instanceof JinglePacket) {
        if (this.jingleListener != null) {
            this.jingleListener.onJinglePacketReceived(account, (JinglePacket) packet);
        }
    } else {
        OnIqPacketReceived callback = null;
        synchronized (this.packetCallbacks) {
            if (packetCallbacks.containsKey(packet.getId())) {
                final Pair<IqPacket, OnIqPacketReceived> packetCallbackDuple = packetCallbacks.get(packet.getId());
                // Packets to the server should have responses from the server
                if (packetCallbackDuple.first.toServer(account)) {
                    if (packet.fromServer(account)) {
                        callback = packetCallbackDuple.second;
                        packetCallbacks.remove(packet.getId());
                    } else {
                        Log.e(Config.LOGTAG, account.getJid().toBareJid().toString() + ": ignoring spoofed iq packet");
                    }
                } else {
                    if (packet.getFrom().equals(packetCallbackDuple.first.getTo())) {
                        callback = packetCallbackDuple.second;
                        packetCallbacks.remove(packet.getId());
                    } else {
                        Log.e(Config.LOGTAG, account.getJid().toBareJid().toString() + ": ignoring spoofed iq packet");
                    }
                }
            } else if (packet.getType() == IqPacket.TYPE.GET || packet.getType() == IqPacket.TYPE.SET) {
                callback = this.unregisteredIqListener;
            }
        }
        if (callback != null) {
            callback.onIqPacketReceived(account, packet);
        }
    }
}
Also used : JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 7 with JinglePacket

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

the class JingleConnection method sendInitRequest.

private void sendInitRequest() {
    JinglePacket packet = this.bootstrapPacket("session-initiate");
    Content content = new Content(this.contentCreator, this.contentName);
    if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) {
        content.setTransportId(this.transportId);
        this.file = this.mXmppConnectionService.getFileBackend().getFile(message, false);
        Pair<InputStream, Integer> pair;
        try {
            if (message.getEncryption() == Message.ENCRYPTION_OTR) {
                Conversation conversation = this.message.getConversation();
                if (!this.mXmppConnectionService.renewSymmetricKey(conversation)) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not set symmetric key");
                    cancel();
                }
                this.file.setKeyAndIv(conversation.getSymmetricKey());
                pair = AbstractConnectionManager.createInputStream(this.file, false);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, true, this.ftVersion);
            } else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
                this.file.setKey(mXmppAxolotlMessage.getInnerKey());
                this.file.setIv(mXmppAxolotlMessage.getIV());
                pair = AbstractConnectionManager.createInputStream(this.file, true);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, false, this.ftVersion).addChild(mXmppAxolotlMessage.toElement());
            } else {
                pair = AbstractConnectionManager.createInputStream(this.file, false);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, false, this.ftVersion);
            }
        } catch (FileNotFoundException e) {
            cancel();
            return;
        }
        this.mFileInputStream = pair.first;
        content.setTransportId(this.transportId);
        content.socks5transport().setChildren(getCandidatesAsElements());
        packet.setContent(content);
        this.sendJinglePacket(packet, new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(Account account, IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": other party received offer");
                    mJingleStatus = JINGLE_STATUS_INITIATED;
                    mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED);
                } else {
                    fail(IqParser.extractErrorMessage(packet));
                }
            }
        });
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Conversation(eu.siacs.conversations.entities.Conversation) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 8 with JinglePacket

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

the class JingleConnection method sendCandidateUsed.

private void sendCandidateUsed(final String cid) {
    JinglePacket packet = bootstrapPacket("transport-info");
    Content content = new Content(this.contentCreator, this.contentName);
    content.setTransportId(this.transportId);
    content.socks5transport().addChild("candidate-used").setAttribute("cid", cid);
    packet.setContent(content);
    this.sentCandidate = true;
    if ((receivedCandidate) && (mJingleStatus == JINGLE_STATUS_ACCEPTED)) {
        connect();
    }
    this.sendJinglePacket(packet);
}
Also used : JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content)

Example 9 with JinglePacket

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

the class JingleConnection method bootstrapPacket.

private JinglePacket bootstrapPacket(String action) {
    JinglePacket packet = new JinglePacket();
    packet.setAction(action);
    packet.setFrom(account.getJid());
    packet.setTo(this.message.getCounterpart());
    packet.setSessionId(this.sessionId);
    packet.setInitiator(this.initiator);
    return packet;
}
Also used : JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)

Example 10 with JinglePacket

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

the class JingleConnection method sendCancel.

private void sendCancel() {
    JinglePacket packet = bootstrapPacket("session-terminate");
    Reason reason = new Reason();
    reason.addChild("cancel");
    packet.setReason(reason);
    this.sendJinglePacket(packet);
}
Also used : JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) Reason(eu.siacs.conversations.xmpp.jingle.stanzas.Reason)

Aggregations

JinglePacket (eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)12 Content (eu.siacs.conversations.xmpp.jingle.stanzas.Content)7 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)4 Account (eu.siacs.conversations.entities.Account)2 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)2 Reason (eu.siacs.conversations.xmpp.jingle.stanzas.Reason)2 Conversation (eu.siacs.conversations.entities.Conversation)1 Element (eu.siacs.conversations.xml.Element)1 Tag (eu.siacs.conversations.xml.Tag)1 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)1 PresencePacket (eu.siacs.conversations.xmpp.stanzas.PresencePacket)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1