Package rocks.xmpp.extensions.disco.model.info

Examples of rocks.xmpp.extensions.disco.model.info.InfoNode


     * @throws rocks.xmpp.core.session.NoResponseException  If the server did not respond.
     * @see <a href="http://xmpp.org/extensions/xep-0013.html#request-number">2.2 Requesting Number of Messages</a>
     */
    public int requestNumberOfMessages() throws XmppException {
        ServiceDiscoveryManager serviceDiscoveryManager = xmppSession.getExtensionManager(ServiceDiscoveryManager.class);
        InfoNode infoDiscovery = serviceDiscoveryManager.discoverInformation(null, OfflineMessage.NAMESPACE);
        if (!infoDiscovery.getExtensions().isEmpty()) {
            DataForm dataForm = infoDiscovery.getExtensions().get(0);
            if (dataForm != null) {
                for (DataForm.Field field : dataForm.getFields()) {
                    if ("number_of_messages".equals(field.getVar())) {
                        String numberOfMessages = field.getValues().get(0);
                        return Integer.parseInt(numberOfMessages);
View Full Code Here


     * @see <a href="http://xmpp.org/extensions/xep-0065.html#disco">4. Discovering Proxies</a>
     */
    public List<StreamHost> discoverProxies() throws XmppException {
        ItemNode itemNode = serviceDiscoveryManager.discoverItems(null);
        for (Item item : itemNode.getItems()) {
            InfoNode infoNode = serviceDiscoveryManager.discoverInformation(item.getJid());
            if (infoNode.getFeatures().contains(new Feature(Socks5ByteStream.NAMESPACE))) {
                IQ result = xmppSession.query(new IQ(item.getJid(), IQ.Type.GET, new Socks5ByteStream()));
                Socks5ByteStream socks5ByteStream = result.getExtension(Socks5ByteStream.class);
                if (socks5ByteStream != null) {
                    return socks5ByteStream.getStreamHosts();
                }
View Full Code Here

    public Collection<ChatService> getChatServices() throws XmppException {
        ItemNode itemDiscovery = serviceDiscoveryManager.discoverItems(null);
        Collection<ChatService> chatServices = new ArrayList<>();

        for (Item item : itemDiscovery.getItems()) {
            InfoNode infoDiscovery = serviceDiscoveryManager.discoverInformation(item.getJid());
            if (infoDiscovery.getFeatures().contains(new Feature(Muc.NAMESPACE))) {
                chatServices.add(new ChatService(item.getJid(), xmppSession, serviceDiscoveryManager));
            }
        }
        return chatServices;
    }
View Full Code Here

    public void testInfoDiscovery() throws XmppException {
        MockServer mockServer = new MockServer();
        TestXmppSession connection1 = new TestXmppSession(ROMEO, mockServer);
        new TestXmppSession(JULIET, mockServer);
        ServiceDiscoveryManager serviceDiscoveryManager = connection1.getExtensionManager(ServiceDiscoveryManager.class);
        InfoNode result = serviceDiscoveryManager.discoverInformation(JULIET);
        Assert.assertNotNull(result);
        Assert.assertTrue(result.getFeatures().size() > 1);
        //  Every entity MUST have at least one identity
        Assert.assertTrue(result.getIdentities().size() > 0);
    }
View Full Code Here

        features.add(new Feature("http://jabber.org/protocol/disco#info"));
        features.add(new Feature("http://jabber.org/protocol/disco#items"));
        features.add(new Feature("http://jabber.org/protocol/muc"));
        features.add(new Feature("http://jabber.org/protocol/caps"));

        InfoNode infoNode = new InfoDiscovery();
        infoNode.getFeatures().addAll(features);
        infoNode.getIdentities().addAll(identities);
        String verificationString = EntityCapabilities.getVerificationString(infoNode, MessageDigest.getInstance("sha-1"));
        Assert.assertEquals(verificationString, "QgayPKawpkPSDYmwT/WM94uAlu0=");
    }
View Full Code Here

        features.add(new Feature("vcard-temp"));
        features.add(new Feature("urn:xmpp:time"));
        features.add(new Feature("http://jabber.org/protocol/shim"));
        features.add(new Feature("http://jabber.org/protocol/caps"));

        InfoNode infoNode = new InfoDiscovery();
        infoNode.getFeatures().addAll(features);
        infoNode.getIdentities().addAll(identities);
        String verificationString = EntityCapabilities.getVerificationString(infoNode, MessageDigest.getInstance("sha-1"));
        Assert.assertEquals(verificationString, "40K55pBx86cs2cR44flP35MpLCk=");
    }
View Full Code Here

     * @return The node info.
     * @throws rocks.xmpp.core.stanza.model.StanzaException If the entity returned a stanza error.
     * @throws rocks.xmpp.core.session.NoResponseException  If the entity did not respond.
     */
    public NodeInfo getNodeInfo() throws XmppException {
        InfoNode infoNode = serviceDiscoveryManager.discoverInformation(pubSubServiceAddress);
        Identity identity = null;
        Set<PubSubFeature> features = new HashSet<>();
        PubSubMetaDataForm metaDataForm = null;

        if (infoNode != null) {
            Set<Identity> identities = infoNode.getIdentities();
            Iterator<Identity> iterator = identities.iterator();
            if (iterator.hasNext()) {
                identity = iterator.next();
            }
            for (DataForm dataForm : infoNode.getExtensions()) {
                String formType = dataForm.getFormType();
                if (PubSubMetaDataForm.FORM_TYPE.equals(formType)) {
                    metaDataForm = new PubSubMetaDataForm(dataForm);
                    break;
                }
View Full Code Here

                        synchronized (EntityCapabilitiesManager.this) {

                            Verification verification = new Verification(entityCapabilities.getHashingAlgorithm(), entityCapabilities.getVerificationString());
                            // Check if the verification string is already known.
                            if (entityCapabilities.getHashingAlgorithm() != null && cache.containsKey(verification)) {
                                InfoNode infoNode = cache.get(verification);
                                // If its known, just update the information for this entity.
                                jidInfos.put(presence.getFrom(), infoNode);
                            } else {
                                // 1. Verify that the <c/> element includes a 'hash' attribute. If it does not, ignore the 'ver'
                                String hashAlgorithm = entityCapabilities.getHashingAlgorithm();
                                if (hashAlgorithm != null) {
                                    try {
                                        // 3. If the value of the 'hash' attribute matches one of the processing application's supported hash functions, validate the verification string by doing the following:
                                        MessageDigest messageDigest = MessageDigest.getInstance(entityCapabilities.getHashingAlgorithm());

                                        try {
                                            // 3.1 Send a service discovery information request to the generating entity.
                                            // 3.2 Receive a service discovery information response from the generating entity.
                                            InfoNode infoDiscovery = serviceDiscoveryManager.discoverInformation(presence.getFrom(), entityCapabilities.getNode() + "#" + entityCapabilities.getVerificationString());
                                            // 3.3 If the response includes more than one service discovery identity with the same category/type/lang/name, consider the entire response to be ill-formed.
                                            // 3.4 If the response includes more than one service discovery feature with the same XML character data, consider the entire response to be ill-formed.
                                            // => not possible due to java.util.Set semantics and equals method.
                                            // If the response had duplicates, just check the hash.

                                            // 3.5 If the response includes more than one extended service discovery information form with the same FORM_TYPE or the FORM_TYPE field contains more than one <value/> element with different XML character data, consider the entire response to be ill-formed.
                                            List<String> ftValues = new ArrayList<>();
                                            for (DataForm dataForm : infoDiscovery.getExtensions()) {
                                                DataForm.Field formType = dataForm.findField("FORM_TYPE");
                                                // 3.6 If the response includes an extended service discovery information form where the FORM_TYPE field is not of type "hidden" or the form does not include a FORM_TYPE field, ignore the form but continue processing.
                                                if (formType != null && formType.getType() == DataForm.Field.Type.HIDDEN && !formType.getValues().isEmpty()) {
                                                    List<String> values = new ArrayList<>();
                                                    for (String value : formType.getValues()) {
                                                        if (values.contains(value)) {
                                                            // ill-formed
                                                            return;
                                                        }
                                                        values.add(value);
                                                    }
                                                    String value = formType.getValues().get(0);
                                                    if (ftValues.contains(value)) {
                                                        // ill-formed
                                                        return;
                                                    }
                                                    ftValues.add(value);
                                                }
                                            }

                                            // 3.7 If the response is considered well-formed, reconstruct the hash by using the service discovery information response to generate a local hash in accordance with the Generation Method).
                                            String verificationString = EntityCapabilities.getVerificationString(infoDiscovery, messageDigest);

                                            // 3.8 If the values of the received and reconstructed hashes match, the processing application MUST consider the result to be valid and SHOULD globally cache the result for all JabberIDs with which it communicates.
                                            if (verificationString.equals(entityCapabilities.getVerificationString())) {
                                                cache(new Verification(hashAlgorithm, verificationString), infoDiscovery);
                                            }
                                            jidInfos.put(presence.getFrom(), infoDiscovery);

                                            // 3.9 If the values of the received and reconstructed hashes do not match, the processing application MUST consider the result to be invalid and MUST NOT globally cache the verification string;

                                        } catch (XmppException e1) {
                                            logger.log(Level.WARNING, e1.getMessage(), e1);
                                        }
                                    } catch (NoSuchAlgorithmException e1) {
                                        // 2. If the value of the 'hash' attribute does not match one of the processing application's supported hash functions, do the following:
                                        try {
                                            // 2.1 Send a service discovery information request to the generating entity.
                                            // 2.2 Receive a service discovery information response from the generating entity.
                                            InfoNode infoNode = serviceDiscoveryManager.discoverInformation(presence.getFrom(), entityCapabilities.getNode());
                                            // 2.3 Do not validate or globally cache the verification string as described below; instead, the processing application SHOULD associate the discovered identity+features only with the JabberID of the generating entity.
                                            jidInfos.put(presence.getFrom(), infoNode);
                                        } catch (XmppException e2) {
                                            logger.log(Level.WARNING, e2.getMessage(), e2);
                                        }
View Full Code Here

        final Set<Identity> identities = new HashSet<>(serviceDiscoveryManager.getIdentities());
        final Set<Feature> features = new HashSet<>(serviceDiscoveryManager.getFeatures());
        final List<DataForm> extensions = new ArrayList<>(serviceDiscoveryManager.getExtensions());
        final String node = getNode() + "#" + currentVerificationString;

        serviceDiscoveryManager.addInfoNode(new InfoNode() {
            @Override
            public String getNode() {
                return node;
            }
View Full Code Here

    public Collection<PubSubService> getPubSubServices() throws XmppException {
        ItemNode itemNode = serviceDiscoveryManager.discoverItems(null);
        Collection<PubSubService> pubSubServices = new ArrayList<>();

        for (Item item : itemNode.getItems()) {
            InfoNode infoNode = serviceDiscoveryManager.discoverInformation(item.getJid());
            if (infoNode.getFeatures().contains(new Feature(PubSub.NAMESPACE))) {
                pubSubServices.add(new PubSubService(item.getJid(), xmppSession, serviceDiscoveryManager));
            }
        }
        return pubSubServices;
    }
View Full Code Here

TOP

Related Classes of rocks.xmpp.extensions.disco.model.info.InfoNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.