Search in sources :

Example 1 with ServiceDiscoveryResult

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

the class JingleConnection method upgradeNamespace.

private void upgradeNamespace() {
    Jid jid = this.message.getCounterpart();
    String resource = jid != null ? jid.getResourcepart() : null;
    if (resource != null) {
        Presence presence = this.account.getRoster().getContact(jid).getPresences().getPresences().get(resource);
        ServiceDiscoveryResult result = presence != null ? presence.getServiceDiscoveryResult() : null;
        if (result != null) {
            List<String> features = result.getFeatures();
            if (features.contains(Content.Version.FT_4.getNamespace())) {
                this.ftVersion = Content.Version.FT_4;
            }
        }
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult) Presence(eu.siacs.conversations.entities.Presence)

Example 2 with ServiceDiscoveryResult

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

the class XmppConnectionService method fetchCaps.

public void fetchCaps(Account account, final Jid jid, final Presence presence) {
    final Pair<String, String> key = new Pair<>(presence.getHash(), presence.getVer());
    final ServiceDiscoveryResult disco = getCachedServiceDiscoveryResult(key);
    if (disco != null) {
        presence.setServiceDiscoveryResult(disco);
        final Contact contact = account.getRoster().getContact(jid);
        if (contact.refreshRtpCapability()) {
            syncRoster(account);
        }
    } else {
        final IqPacket request = new IqPacket(IqPacket.TYPE.GET);
        request.setTo(jid);
        final String node = presence.getNode();
        final String ver = presence.getVer();
        final Element query = request.query(Namespace.DISCO_INFO);
        if (node != null && ver != null) {
            query.setAttribute("node", node + "#" + ver);
        }
        Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": making disco request for " + key.second + " to " + jid);
        sendIqPacket(account, request, (a, response) -> {
            if (response.getType() == IqPacket.TYPE.RESULT) {
                final ServiceDiscoveryResult discoveryResult = new ServiceDiscoveryResult(response);
                if (presence.getVer().equals(discoveryResult.getVer())) {
                    databaseBackend.insertDiscoveryResult(discoveryResult);
                    injectServiceDiscoveryResult(a.getRoster(), presence.getHash(), presence.getVer(), discoveryResult);
                } else {
                    Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": mismatch in caps for contact " + jid + " " + presence.getVer() + " vs " + discoveryResult.getVer());
                }
            } else {
                Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": unable to fetch caps from " + jid);
            }
        });
    }
}
Also used : ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult) Element(eu.siacs.conversations.xml.Element) Pair(android.util.Pair) Contact(eu.siacs.conversations.entities.Contact) JabberIdContact(eu.siacs.conversations.android.JabberIdContact) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 3 with ServiceDiscoveryResult

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

the class XmppConnectionService method fetchConferenceConfiguration.

public void fetchConferenceConfiguration(final Conversation conversation, final OnConferenceConfigurationFetched callback) {
    IqPacket request = mIqGenerator.queryDiscoInfo(conversation.getJid().asBareJid());
    sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                final MucOptions mucOptions = conversation.getMucOptions();
                final Bookmark bookmark = conversation.getBookmark();
                final boolean sameBefore = StringUtils.equals(bookmark == null ? null : bookmark.getBookmarkName(), mucOptions.getName());
                if (mucOptions.updateConfiguration(new ServiceDiscoveryResult(packet))) {
                    Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": muc configuration changed for " + conversation.getJid().asBareJid());
                    updateConversation(conversation);
                }
                if (bookmark != null && (sameBefore || bookmark.getBookmarkName() == null)) {
                    if (bookmark.setBookmarkName(StringUtils.nullOnEmpty(mucOptions.getName()))) {
                        createBookmark(account, bookmark);
                    }
                }
                if (callback != null) {
                    callback.onConferenceConfigurationFetched(conversation);
                }
                updateConversationUi();
            } else if (packet.getType() == IqPacket.TYPE.TIMEOUT) {
                Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received timeout waiting for conference configuration fetch");
            } else {
                if (callback != null) {
                    callback.onFetchFailed(conversation, packet.getErrorCondition());
                }
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) MucOptions(eu.siacs.conversations.entities.MucOptions) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Bookmark(eu.siacs.conversations.entities.Bookmark) ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 4 with ServiceDiscoveryResult

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

the class XmppConnection method sendPostBindInitialization.

private void sendPostBindInitialization() {
    smVersion = 0;
    if (streamFeatures.hasChild("sm", "urn:xmpp:sm:3")) {
        smVersion = 3;
    } else if (streamFeatures.hasChild("sm", "urn:xmpp:sm:2")) {
        smVersion = 2;
    }
    if (smVersion != 0) {
        synchronized (this.mStanzaQueue) {
            final EnablePacket enable = new EnablePacket(smVersion);
            tagWriter.writeStanzaAsync(enable);
            stanzasSent = 0;
            mStanzaQueue.clear();
        }
    }
    features.carbonsEnabled = false;
    features.blockListRequested = false;
    synchronized (this.disco) {
        this.disco.clear();
    }
    Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": starting service discovery");
    mPendingServiceDiscoveries.set(0);
    if (smVersion == 0 || Patches.DISCO_EXCEPTIONS.contains(account.getJid().getDomain().toEscapedString())) {
        Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": do not wait for service discovery");
        mWaitForDisco.set(false);
    } else {
        mWaitForDisco.set(true);
    }
    lastDiscoStarted = SystemClock.elapsedRealtime();
    mXmppConnectionService.scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode());
    Element caps = streamFeatures.findChild("c");
    final String hash = caps == null ? null : caps.getAttribute("hash");
    final String ver = caps == null ? null : caps.getAttribute("ver");
    ServiceDiscoveryResult discoveryResult = null;
    if (hash != null && ver != null) {
        discoveryResult = mXmppConnectionService.getCachedServiceDiscoveryResult(new Pair<>(hash, ver));
    }
    final boolean requestDiscoItemsFirst = !account.isOptionSet(Account.OPTION_LOGGED_IN_SUCCESSFULLY);
    if (requestDiscoItemsFirst) {
        sendServiceDiscoveryItems(account.getDomain());
    }
    if (discoveryResult == null) {
        sendServiceDiscoveryInfo(account.getDomain());
    } else {
        Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server caps came from cache");
        disco.put(account.getDomain(), discoveryResult);
    }
    discoverMamPreferences();
    sendServiceDiscoveryInfo(account.getJid().asBareJid());
    if (!requestDiscoItemsFirst) {
        sendServiceDiscoveryItems(account.getDomain());
    }
    if (!mWaitForDisco.get()) {
        finalizeBind();
    }
    this.lastSessionStarted = SystemClock.elapsedRealtime();
}
Also used : EnablePacket(eu.siacs.conversations.xmpp.stanzas.streammgmt.EnablePacket) ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult) Element(eu.siacs.conversations.xml.Element) Pair(android.util.Pair)

Example 5 with ServiceDiscoveryResult

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

the class MessageParser method clientMightSendHtml.

private static boolean clientMightSendHtml(Account account, Jid from) {
    String resource = from.getResourcepart();
    if (resource == null) {
        return false;
    }
    Presence presence = account.getRoster().getContact(from).getPresences().getPresences().get(resource);
    ServiceDiscoveryResult disco = presence == null ? null : presence.getServiceDiscoveryResult();
    if (disco == null) {
        return false;
    }
    return hasIdentityKnowForSendingHtml(disco.getIdentities());
}
Also used : ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult) Presence(eu.siacs.conversations.entities.Presence)

Aggregations

ServiceDiscoveryResult (eu.siacs.conversations.entities.ServiceDiscoveryResult)9 Presence (eu.siacs.conversations.entities.Presence)3 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)3 Pair (android.util.Pair)2 Element (eu.siacs.conversations.xml.Element)2 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 JabberIdContact (eu.siacs.conversations.android.JabberIdContact)1 Account (eu.siacs.conversations.entities.Account)1 Bookmark (eu.siacs.conversations.entities.Bookmark)1 Contact (eu.siacs.conversations.entities.Contact)1 MucOptions (eu.siacs.conversations.entities.MucOptions)1 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)1 Jid (eu.siacs.conversations.xmpp.jid.Jid)1 EnablePacket (eu.siacs.conversations.xmpp.stanzas.streammgmt.EnablePacket)1 JSONException (org.json.JSONException)1