Search in sources :

Example 66 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class JingleConnectionManager method deliverPacket.

public void deliverPacket(Account account, JinglePacket packet) {
    if (packet.isAction("session-initiate")) {
        JingleConnection connection = new JingleConnection(this);
        connection.init(account, packet);
        connections.add(connection);
    } else {
        for (JingleConnection connection : connections) {
            if (connection.getAccount() == account && connection.getSessionId().equals(packet.getSessionId()) && connection.getCounterPart().equals(packet.getFrom())) {
                connection.deliverPacket(packet);
                return;
            }
        }
        IqPacket response = packet.generateResponse(IqPacket.TYPE.ERROR);
        Element error = response.addChild("error");
        error.setAttribute("type", "cancel");
        error.addChild("item-not-found", "urn:ietf:params:xml:ns:xmpp-stanzas");
        error.addChild("unknown-session", "urn:xmpp:jingle:errors:1");
        account.getXmppConnection().sendIqPacket(response, null);
    }
}
Also used : Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 67 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class JingleConnectionManager method getPrimaryCandidate.

public void getPrimaryCandidate(Account account, final OnPrimaryCandidateFound listener) {
    if (Config.DISABLE_PROXY_LOOKUP) {
        listener.onPrimaryCandidateFound(false, null);
        return;
    }
    if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) {
        final Jid proxy = account.getXmppConnection().findDiscoItemByFeature(Namespace.BYTE_STREAMS);
        if (proxy != null) {
            IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
            iq.setTo(proxy);
            iq.query(Namespace.BYTE_STREAMS);
            account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() {

                @Override
                public void onIqPacketReceived(Account account, IqPacket packet) {
                    Element streamhost = packet.query().findChild("streamhost", Namespace.BYTE_STREAMS);
                    final String host = streamhost == null ? null : streamhost.getAttribute("host");
                    final String port = streamhost == null ? null : streamhost.getAttribute("port");
                    if (host != null && port != null) {
                        try {
                            JingleCandidate candidate = new JingleCandidate(nextRandomId(), true);
                            candidate.setHost(host);
                            candidate.setPort(Integer.parseInt(port));
                            candidate.setType(JingleCandidate.TYPE_PROXY);
                            candidate.setJid(proxy);
                            candidate.setPriority(655360 + 65535);
                            primaryCandidates.put(account.getJid().toBareJid(), candidate);
                            listener.onPrimaryCandidateFound(true, candidate);
                        } catch (final NumberFormatException e) {
                            listener.onPrimaryCandidateFound(false, null);
                            return;
                        }
                    } else {
                        listener.onPrimaryCandidateFound(false, null);
                    }
                }
            });
        } else {
            listener.onPrimaryCandidateFound(false, null);
        }
    } else {
        listener.onPrimaryCandidateFound(true, this.primaryCandidates.get(account.getJid().toBareJid()));
    }
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 68 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class JingleInbandTransport method connect.

public void connect(final OnTransportConnected callback) {
    IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
    iq.setTo(this.counterpart);
    Element open = iq.addChild("open", "http://jabber.org/protocol/ibb");
    open.setAttribute("sid", this.sessionId);
    open.setAttribute("stanza", "iq");
    open.setAttribute("block-size", Integer.toString(this.blockSize));
    this.connected = true;
    this.account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() != IqPacket.TYPE.RESULT) {
                callback.failed();
            } else {
                callback.established();
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 69 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class PushManagementService method registerPushTokenOnServer.

public void registerPushTokenOnServer(final Account account) {
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": has push support");
    retrieveGcmInstanceToken(new OnGcmInstanceTokenRetrieved() {

        @Override
        public void onGcmInstanceTokenRetrieved(String token) {
            try {
                final String deviceId = Settings.Secure.getString(mXmppConnectionService.getContentResolver(), Settings.Secure.ANDROID_ID);
                IqPacket packet = mXmppConnectionService.getIqGenerator().pushTokenToAppServer(Jid.fromString(APP_SERVER), token, deviceId);
                mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket packet) {
                        Element command = packet.findChild("command", "http://jabber.org/protocol/commands");
                        if (packet.getType() == IqPacket.TYPE.RESULT && command != null) {
                            Element x = command.findChild("x", Namespace.DATA);
                            if (x != null) {
                                Data data = Data.parse(x);
                                try {
                                    String node = data.getValue("node");
                                    String secret = data.getValue("secret");
                                    Jid jid = Jid.fromString(data.getValue("jid"));
                                    if (node != null && secret != null) {
                                        enablePushOnServer(account, jid, node, secret);
                                    }
                                } catch (InvalidJidException e) {
                                    e.printStackTrace();
                                }
                            }
                        } else {
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": invalid response from app server");
                        }
                    }
                });
            } catch (InvalidJidException ignored) {
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Data(de.pixart.messenger.xmpp.forms.Data) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 70 with Element

use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.

the class Content method setFileOffer.

public Element setFileOffer(DownloadableFile actualFile, boolean otr, Version version) {
    Element description = this.addChild("description", version.namespace);
    Element file;
    if (version == Version.FT_3) {
        Element offer = description.addChild("offer");
        file = offer.addChild("file");
    } else {
        file = description.addChild("file");
    }
    file.addChild("size").setContent(Long.toString(actualFile.getExpectedSize()));
    if (otr) {
        file.addChild("name").setContent(actualFile.getName() + ".otr");
    } else {
        file.addChild("name").setContent(actualFile.getName());
    }
    return file;
}
Also used : Element(de.pixart.messenger.xml.Element)

Aggregations

Element (de.pixart.messenger.xml.Element)100 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)48 Account (de.pixart.messenger.entities.Account)23 Jid (de.pixart.messenger.xmpp.jid.Jid)19 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)17 Contact (de.pixart.messenger.entities.Contact)9 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)8 ArrayList (java.util.ArrayList)7 Conversation (de.pixart.messenger.entities.Conversation)6 IOException (java.io.IOException)6 Data (de.pixart.messenger.xmpp.forms.Data)5 Avatar (de.pixart.messenger.xmpp.pep.Avatar)5 HashSet (java.util.HashSet)5 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)4 MucOptions (de.pixart.messenger.entities.MucOptions)4 ECPublicKey (org.whispersystems.libsignal.ecc.ECPublicKey)4 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)4 Pair (android.util.Pair)3 Bookmark (de.pixart.messenger.entities.Bookmark)3 Message (de.pixart.messenger.entities.Message)3