Search in sources :

Example 51 with DiscoverInfo

use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project xabber-android by redsolution.

the class CapabilitiesManager method isValid.

private boolean isValid(DiscoverInfo discoverInfo) {
    Set<DiscoverInfo.Identity> identities = new TreeSet<>(new Comparator<DiscoverInfo.Identity>() {

        private int compare(String string1, String string2) {
            return (string1 == null ? "" : string1).compareTo(string2 == null ? "" : string2);
        }

        @Override
        public int compare(DiscoverInfo.Identity identity1, DiscoverInfo.Identity identity2) {
            int result;
            result = compare(identity1.getCategory(), identity2.getCategory());
            if (result != 0) {
                return result;
            }
            result = compare(identity1.getType(), identity2.getType());
            if (result != 0) {
                return result;
            }
            result = compare(identity1.getLanguage(), identity2.getLanguage());
            if (result != 0) {
                return result;
            }
            result = compare(identity1.getName(), identity2.getName());
            if (result != 0) {
                return result;
            }
            return 0;
        }
    });
    for (DiscoverInfo.Identity identity : discoverInfo.getIdentities()) {
        if (!identities.add(identity)) {
            return false;
        }
    }
    Set<String> features = new HashSet<>();
    for (DiscoverInfo.Feature feature : discoverInfo.getFeatures()) {
        if (!features.add(feature.getVar())) {
            return false;
        }
    }
    Set<String> formTypes = new HashSet<>();
    for (ExtensionElement packetExtension : discoverInfo.getExtensions()) if (packetExtension instanceof DataForm) {
        DataForm dataForm = (DataForm) packetExtension;
        String formType = null;
        for (FormField formField : dataForm.getFields()) {
            if (FORM_TYPE.equals(formField.getVariable())) {
                for (String value : formField.getValues()) {
                    if (formType != null && !formType.equals(value)) {
                        return false;
                    }
                    formType = value;
                }
            }
        }
        if (!formTypes.add(formType)) {
            return false;
        }
    }
    return true;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) TreeSet(java.util.TreeSet) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField) HashSet(java.util.HashSet)

Example 52 with DiscoverInfo

use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project xabber-android by redsolution.

the class CapabilitiesManager method request.

/**
     * Requests disco info.
     *
     * @param account
     * @param user
     * @param capability
     */
private void request(String account, String user, Capability capability) {
    for (DiscoverInfoRequest check : requests) {
        if (capability.equals(check.getCapability())) {
            return;
        }
    }
    DiscoverInfo packet = new DiscoverInfo();
    packet.setTo(user);
    packet.setType(Type.get);
    if (capability.getNode() != null && capability.getVersion() != null)
        packet.setNode(capability.getNode() + "#" + capability.getVersion());
    try {
        ConnectionManager.getInstance().sendStanza(account, packet);
    } catch (NetworkException e) {
        return;
    }
    requests.add(new DiscoverInfoRequest(account, Jid.getStringPrep(user), packet.getStanzaId(), capability));
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) NetworkException(com.xabber.android.data.NetworkException)

Example 53 with DiscoverInfo

use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project xabber-android by redsolution.

the class ServerInfoManager method onReceived.

@Override
public void onReceived(String account, String packetId, IQ iq) {
    if (!(iq instanceof DiscoverInfo)) {
        onError(account, packetId, iq);
        return;
    }
    ArrayList<String> features = new ArrayList<String>();
    DiscoverInfo discoverInfo = (DiscoverInfo) iq;
    for (DiscoverInfo.Feature feature : discoverInfo.getFeatures()) {
        features.add(feature.getVar());
    }
    protocols.put(account, features);
    onAvailable(AccountManager.getInstance().getAccount(account));
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) ArrayList(java.util.ArrayList)

Aggregations

DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)53 Test (org.junit.Test)18 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)12 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)11 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)11 IOException (java.io.IOException)8 SmackException (org.jivesoftware.smack.SmackException)8 XMPPException (org.jivesoftware.smack.XMPPException)8 Item (org.jivesoftware.smackx.disco.packet.DiscoverItems.Item)8 ConnectException (java.net.ConnectException)7 FeatureNotSupportedException (org.jivesoftware.smack.SmackException.FeatureNotSupportedException)7 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)7 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)7 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)7 IQ (org.jivesoftware.smack.packet.IQ)6 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)6 FormField (org.jivesoftware.smackx.xdata.FormField)6 XMPPConnection (org.jivesoftware.smack.XMPPConnection)5 ArrayList (java.util.ArrayList)4 ThreadedDummyConnection (org.jivesoftware.smack.ThreadedDummyConnection)4