Search in sources :

Example 86 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class AxolotlService method publishOwnDeviceId.

public void publishOwnDeviceId(Set<Integer> deviceIds) {
    Set<Integer> deviceIdsCopy = new HashSet<>(deviceIds);
    Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "publishing own device ids");
    if (deviceIdsCopy.isEmpty()) {
        if (numPublishTriesOnEmptyPep >= publishTriesThreshold) {
            Log.w(Config.LOGTAG, getLogprefix(account) + "Own device publish attempt threshold exceeded, aborting...");
            pepBroken = true;
            return;
        } else {
            numPublishTriesOnEmptyPep++;
            Log.w(Config.LOGTAG, getLogprefix(account) + "Own device list empty, attempting to publish (try " + numPublishTriesOnEmptyPep + ")");
        }
    } else {
        numPublishTriesOnEmptyPep = 0;
    }
    deviceIdsCopy.add(getOwnDeviceId());
    IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(deviceIdsCopy);
    ownPushPending.set(true);
    mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            ownPushPending.set(false);
            if (packet.getType() == IqPacket.TYPE.ERROR) {
                pepBroken = true;
                Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while publishing own device id" + packet.findChild("error"));
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) HashSet(java.util.HashSet) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 87 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnection method sendEnableCarbons.

private void sendEnableCarbons() {
    final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
    iq.addChild("enable", "urn:xmpp:carbons:2");
    this.sendIqPacket(iq, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(final Account account, final IqPacket packet) {
            if (!packet.hasChild("error")) {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": successfully enabled carbons");
                features.carbonsEnabled = true;
            } else {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": error enableing carbons " + packet.toString());
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 88 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnection method sendServiceDiscoveryInfo.

private void sendServiceDiscoveryInfo(final Jid jid) {
    mPendingServiceDiscoveries.incrementAndGet();
    final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
    iq.setTo(jid);
    iq.query("http://jabber.org/protocol/disco#info");
    this.sendIqPacket(iq, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(final Account account, final IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                boolean advancedStreamFeaturesLoaded;
                synchronized (XmppConnection.this.disco) {
                    ServiceDiscoveryResult result = new ServiceDiscoveryResult(packet);
                    if (jid.equals(account.getServer())) {
                        mXmppConnectionService.databaseBackend.insertDiscoveryResult(result);
                    }
                    disco.put(jid, result);
                    advancedStreamFeaturesLoaded = disco.containsKey(account.getServer()) && disco.containsKey(account.getJid().toBareJid());
                }
                if (advancedStreamFeaturesLoaded && (jid.equals(account.getServer()) || jid.equals(account.getJid().toBareJid()))) {
                    enableAdvancedStreamFeatures();
                }
            } else {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not query disco info for " + jid.toString());
            }
            if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
                if (mPendingServiceDiscoveries.decrementAndGet() == 0 && mWaitForDisco.compareAndSet(true, false)) {
                    finalizeBind();
                }
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 89 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnection method sendServiceDiscoveryItems.

private void sendServiceDiscoveryItems(final Jid server) {
    mPendingServiceDiscoveries.incrementAndGet();
    final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
    iq.setTo(server.toDomainJid());
    iq.query("http://jabber.org/protocol/disco#items");
    this.sendIqPacket(iq, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(final Account account, final IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                final List<Element> elements = packet.query().getChildren();
                for (final Element element : elements) {
                    if (element.getName().equals("item")) {
                        final Jid jid = element.getAttributeAsJid("jid");
                        if (jid != null && !jid.equals(account.getServer())) {
                            sendServiceDiscoveryInfo(jid);
                        }
                    }
                }
            } else {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not query disco items of " + server);
            }
            if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
                if (mPendingServiceDiscoveries.decrementAndGet() == 0 && mWaitForDisco.compareAndSet(true, false)) {
                    finalizeBind();
                }
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) Element(eu.siacs.conversations.xml.Element) List(java.util.List) ArrayList(java.util.ArrayList) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 90 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

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(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Aggregations

Account (eu.siacs.conversations.entities.Account)100 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)41 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 Jid (eu.siacs.conversations.xmpp.jid.Jid)22 Element (eu.siacs.conversations.xml.Element)21 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)17 Conversation (eu.siacs.conversations.entities.Conversation)16 Contact (eu.siacs.conversations.entities.Contact)9 Message (eu.siacs.conversations.entities.Message)9 ArrayList (java.util.ArrayList)8 PendingIntent (android.app.PendingIntent)7 Intent (android.content.Intent)7 Bookmark (eu.siacs.conversations.entities.Bookmark)7 SuppressLint (android.annotation.SuppressLint)6 AlertDialog (android.app.AlertDialog)6 TextView (android.widget.TextView)6 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)6 FileNotFoundException (java.io.FileNotFoundException)6 DialogInterface (android.content.DialogInterface)5 View (android.view.View)5