Search in sources :

Example 1 with JinglePacket

use of de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket in project Pix-Art-Messenger by kriztan.

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() != null && 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) {
            try {
                callback.onIqPacketReceived(account, packet);
            } catch (StateChangingError error) {
                throw new StateChangingException(error.state);
            }
        }
    }
}
Also used : JinglePacket(de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 2 with JinglePacket

use of de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket in project Pix-Art-Messenger by kriztan.

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");
    }
    if (inSmacksSession) {
        ++stanzasReceived;
    } else if (features.sm()) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": 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);
    }
    return element;
}
Also used : MessagePacket(de.pixart.messenger.xmpp.stanzas.MessagePacket) JinglePacket(de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket) Element(de.pixart.messenger.xml.Element) Tag(de.pixart.messenger.xml.Tag) IOException(java.io.IOException) PresencePacket(de.pixart.messenger.xmpp.stanzas.PresencePacket) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 3 with JinglePacket

use of de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket in project Pix-Art-Messenger by kriztan.

the class JingleConnection method sendFallbackToIbb.

private void sendFallbackToIbb() {
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending fallback to ibb");
    JinglePacket packet = this.bootstrapPacket("transport-replace");
    Content content = new Content(this.contentCreator, this.contentName);
    this.transportId = this.mJingleConnectionManager.nextRandomId();
    content.setTransportId(this.transportId);
    content.ibbTransport().setAttribute("block-size", Integer.toString(this.ibbBlockSize));
    packet.setContent(content);
    this.sendJinglePacket(packet);
}
Also used : JinglePacket(de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket) Content(de.pixart.messenger.xmpp.jingle.stanzas.Content)

Example 4 with JinglePacket

use of de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket in project Pix-Art-Messenger by kriztan.

the class JingleConnection method sendAccept.

private void sendAccept() {
    mJingleStatus = JINGLE_STATUS_ACCEPTED;
    this.mStatus = Transferable.STATUS_DOWNLOADING;
    this.mJingleConnectionManager.updateConversationUi(true);
    this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() {

        @Override
        public void onPrimaryCandidateFound(boolean success, final JingleCandidate candidate) {
            final JinglePacket packet = bootstrapPacket("session-accept");
            final Content content = new Content(contentCreator, contentName);
            content.setFileOffer(fileOffer, ftVersion);
            content.setTransportId(transportId);
            if (success && candidate != null && !equalCandidateExists(candidate)) {
                final JingleSocks5Transport socksConnection = new JingleSocks5Transport(JingleConnection.this, candidate);
                connections.put(candidate.getCid(), socksConnection);
                socksConnection.connect(new OnTransportConnected() {

                    @Override
                    public void failed() {
                        Log.d(Config.LOGTAG, "connection to our own primary candidate failed");
                        content.socks5transport().setChildren(getCandidatesAsElements());
                        packet.setContent(content);
                        sendJinglePacket(packet);
                        connectNextCandidate();
                    }

                    @Override
                    public void established() {
                        Log.d(Config.LOGTAG, "connected to primary candidate");
                        mergeCandidate(candidate);
                        content.socks5transport().setChildren(getCandidatesAsElements());
                        packet.setContent(content);
                        sendJinglePacket(packet);
                        connectNextCandidate();
                    }
                });
            } else {
                Log.d(Config.LOGTAG, "did not find a primary candidate for ourself");
                content.socks5transport().setChildren(getCandidatesAsElements());
                packet.setContent(content);
                sendJinglePacket(packet);
                connectNextCandidate();
            }
        }
    });
}
Also used : JinglePacket(de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket) Content(de.pixart.messenger.xmpp.jingle.stanzas.Content)

Example 5 with JinglePacket

use of de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket in project Pix-Art-Messenger by kriztan.

the class JingleConnection method sendHash.

private void sendHash() {
    JinglePacket packet = this.bootstrapPacket("session-info");
    packet.addChecksum(file.getSha1Sum(), ftVersion.getNamespace());
    this.sendJinglePacket(packet);
}
Also used : JinglePacket(de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket)

Aggregations

JinglePacket (de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket)13 Content (de.pixart.messenger.xmpp.jingle.stanzas.Content)7 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)4 Account (de.pixart.messenger.entities.Account)2 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)2 Reason (de.pixart.messenger.xmpp.jingle.stanzas.Reason)2 Conversation (de.pixart.messenger.entities.Conversation)1 Element (de.pixart.messenger.xml.Element)1 Tag (de.pixart.messenger.xml.Tag)1 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)1 PresencePacket (de.pixart.messenger.xmpp.stanzas.PresencePacket)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1