Java Code Examples for org.jivesoftware.smackx.disco.packet.DiscoverInfo#Identity

The following examples show how to use org.jivesoftware.smackx.disco.packet.DiscoverInfo#Identity . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiUserChat.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the reserved room nickname for the user in the room. A user may have a reserved
 * nickname, for example through explicit room registration or database integration. In such
 * cases it may be desirable for the user to discover the reserved nickname before attempting
 * to enter the room.
 *
 * @return the reserved room nickname or <code>null</code> if none.
 * @throws SmackException if there was no response from the server.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public String getReservedNickname() throws SmackException, InterruptedException {
    try {
        DiscoverInfo result =
            ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(
                room,
                "x-roomuser-item");
        // Look for an Identity that holds the reserved nickname and return its name
        for (DiscoverInfo.Identity identity : result.getIdentities()) {
            return identity.getName();
        }
    }
    catch (XMPPException e) {
        LOGGER.log(Level.SEVERE, "Error retrieving room nickname", e);
    }
    // If no Identity was found then the user does not have a reserved room nickname
    return null;
}
 
Example 2
Source File: EntityCapsManagerTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
private static DiscoverInfo createComplexSamplePacket() throws XmppStringprepException {
    DiscoverInfoBuilder di = DiscoverInfo.builder("disco1");
    di.from(JidCreate.from("[email protected]/230193"));
    di.to(JidCreate.from("[email protected]/chamber"));
    di.ofType(IQ.Type.result);

    Collection<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>();
    DiscoverInfo.Identity i = new DiscoverInfo.Identity("client", "pc", "Psi 0.11", "en");
    identities.add(i);
    i = new DiscoverInfo.Identity("client", "pc", "Ψ 0.11", "el");
    identities.add(i);
    di.addIdentities(identities);

    di.addFeature("http://jabber.org/protocol/disco#items");
    di.addFeature(EntityCapsManager.NAMESPACE);
    di.addFeature("http://jabber.org/protocol/muc");
    di.addFeature("http://jabber.org/protocol/disco#info");

    DataForm softwareInfoDataForm = createSampleSoftwareInfoDataForm();
    di.addExtension(softwareInfoDataForm);
    return di.build();
}
 
Example 3
Source File: FeatureDiscovery.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
private static EnumMap<Feature, JID> discover(ServiceDiscoveryManager dm, JID entity) {
    DiscoverInfo info;
    try {
        // blocking
        // NOTE: null parameter does not work
        info = dm.discoverInfo(entity.toSmack());
    } catch (SmackException.NoResponseException |
            XMPPException.XMPPErrorException |
            SmackException.NotConnectedException |
            InterruptedException ex) {
        // not supported by all servers/server not reachable, we only know after trying
        //LOGGER.log(Level.WARNING, "can't get service discovery info", ex);
        LOGGER.warning("can't get info for " + entity + " " + ex.getMessage());
        return null;
    }

    EnumMap<Feature, JID> features = new EnumMap<>(FeatureDiscovery.Feature.class);
    for (DiscoverInfo.Feature feature: info.getFeatures()) {
        String var = feature.getVar();
        if (FEATURE_MAP.containsKey(var)) {
            features.put(FEATURE_MAP.get(var), entity);
        }
    }

    List<DiscoverInfo.Identity> identities = info.getIdentities();
    LOGGER.config("entity: " + entity
            + " identities: " + identities.stream()
            .map(DiscoverInfo.Identity::toXML).collect(Collectors.toList())
            + " features: " + info.getFeatures().stream()
            .map(DiscoverInfo.Feature::getVar).collect(Collectors.toList()));

    return features;
}
 
Example 4
Source File: ServiceDiscoveryManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Add an further identity to the client.
 *
 * @param identity TODO javadoc me please
 */
public synchronized void addIdentity(DiscoverInfo.Identity identity) {
    identities.add(identity);
    // Notify others of a state change of SDM. In order to keep the state consistent, this
    // method is synchronized
    renewEntityCapsVersion();
}
 
Example 5
Source File: ServiceDiscoveryManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Remove an identity from the client. Note that the client needs at least one identity, the default identity, which
 * can not be removed.
 *
 * @param identity TODO javadoc me please
 * @return true, if successful. Otherwise the default identity was given.
 */
public synchronized boolean removeIdentity(DiscoverInfo.Identity identity) {
    if (identity.equals(this.identity)) return false;
    identities.remove(identity);
    // Notify others of a state change of SDM. In order to keep the state consistent, this
    // method is synchronized
    renewEntityCapsVersion();
    return true;
}
 
Example 6
Source File: ServiceDiscoveryManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Returns all identities of this client as unmodifiable Collection.
 *
 * @return all identies as set
 */
public Set<DiscoverInfo.Identity> getIdentities() {
    Set<Identity> res = new HashSet<>(identities);
    // Add the main identity that must exist
    res.add(identity);
    return Collections.unmodifiableSet(res);
}
 
Example 7
Source File: EntityCapsManagerTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
private static DiscoverInfo createMalformedDiscoverInfo() throws XmppStringprepException {
    DiscoverInfoBuilder di = DiscoverInfo.builder("disco1");
    di.from("[email protected]/230193");
    di.to(")[email protected]/chamber");
    di.ofType(IQ.Type.result);

    Collection<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>();
    DiscoverInfo.Identity i = new DiscoverInfo.Identity("client", "pc", "Psi 0.11", "en");
    identities.add(i);
    i = new DiscoverInfo.Identity("client", "pc", "Ψ 0.11", "el");
    identities.add(i);
    di.addIdentities(identities);
    // Failure 1: Duplicate identities
    i = new DiscoverInfo.Identity("client", "pc", "Ψ 0.11", "el");
    identities.add(i);
    di.addIdentities(identities);

    di.addFeature("http://jabber.org/protocol/disco#items");
    di.addFeature(EntityCapsManager.NAMESPACE);
    di.addFeature("http://jabber.org/protocol/muc");
    di.addFeature("http://jabber.org/protocol/disco#info");
    // Failure 2: Duplicate features
    di.addFeature("http://jabber.org/protocol/disco#info");

    DataForm softwareInfoDataForm = createSampleSoftwareInfoDataForm();
    di.addExtension(softwareInfoDataForm);

    DiscoverInfo discoverInfo = di.buildWithoutValidiation();
    return discoverInfo;
}
 
Example 8
Source File: RTPBridge.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
     * Check if the server support RTPBridge Service.
     *
     * @param connection TODO javadoc me please
     * @return true if the server supports the RTPBridge service
     * @throws XMPPErrorException if there was an XMPP error returned.
     * @throws NoResponseException if there was no response from the remote entity.
     * @throws NotConnectedException if the XMPP connection is not connected.
     * @throws InterruptedException if the calling thread was interrupted.
     */
    public static boolean serviceAvailable(XMPPConnection connection) throws NoResponseException,
                    XMPPErrorException, NotConnectedException, InterruptedException {

        if (!connection.isConnected()) {
            return false;
        }

        LOGGER.fine("Service listing");

        ServiceDiscoveryManager disco = ServiceDiscoveryManager
                .getInstanceFor(connection);
//            DiscoverItems items = disco.discoverItems(connection.getXMPPServiceDomain());
//            Iterator iter = items.getItems();
//            while (iter.hasNext()) {
//                DiscoverItems.Item item = (DiscoverItems.Item) iter.next();
//                if (item.getEntityID().startsWith("rtpbridge.")) {
//                    return true;
//                }
//            }

        DiscoverInfo discoInfo = disco.discoverInfo(connection.getXMPPServiceDomain());
        for (DiscoverInfo.Identity identity : discoInfo.getIdentities()) {
            if (identity.getName() != null && identity.getName().startsWith("rtpbridge")) {
                return true;
            }
        }

        return false;
    }
 
Example 9
Source File: STUN.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the server support STUN Service.
 *
 * @param connection the connection
 * @return true if the server support STUN
 * @throws SmackException if Smack detected an exceptional situation.
 * @throws XMPPException if an XMPP protocol error was received.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public static boolean serviceAvailable(XMPPConnection connection) throws XMPPException, SmackException, InterruptedException {

    if (!connection.isConnected()) {
        return false;
    }

    LOGGER.fine("Service listing");

    ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection);
    DiscoverItems items = disco.discoverItems(connection.getXMPPServiceDomain());

    for (DiscoverItems.Item item : items.getItems()) {
        DiscoverInfo info = disco.discoverInfo(item.getEntityID());

        for (DiscoverInfo.Identity identity : info.getIdentities()) {
            if (identity.getCategory().equals("proxy") && identity.getType().equals("stun"))
                if (info.containsFeature(NAMESPACE))
                    return true;
        }

        LOGGER.fine(item.getName() + "-" + info.getType());

    }

    return false;
}
 
Example 10
Source File: DiscoverInfoProvider.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
public DiscoverInfo parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment)
        throws XmlPullParserException, IOException, SmackParsingException {
    DiscoverInfoBuilder discoverInfoBuilder = DiscoverInfo.builder(iqData);

    String node = parser.getAttributeValue("node");
    discoverInfoBuilder.setNode(node);

    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        if (eventType == XmlPullParser.Event.START_ELEMENT) {
            final String name = parser.getName();
            final String namespace = parser.getNamespace();
            if (namespace.equals(DiscoverInfo.NAMESPACE)) {
                switch (name) {
                case "identity":
                    String category = parser.getAttributeValue("category");
                    String identityName = parser.getAttributeValue("name");
                    String type = parser.getAttributeValue("type");
                    String lang = ParserUtils.getXmlLang(parser);
                    DiscoverInfo.Identity identity = new DiscoverInfo.Identity(category, type, identityName, lang);
                    discoverInfoBuilder.addIdentity(identity);
                    break;
                case "feature":
                    String feature = parser.getAttributeValue("var");
                    discoverInfoBuilder.addFeature(feature);
                    break;
                }
            }
            // Otherwise, it must be a packet extension.
            else {
                PacketParserUtils.addExtensionElement(discoverInfoBuilder, parser, xmlEnvironment);
            }
        } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
        }
    }

    DiscoverInfo discoverInfo = discoverInfoBuilder.buildWithoutValidiation();
    return discoverInfo;
}
 
Example 11
Source File: AbstractNodeInformationProvider.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
public List<DiscoverInfo.Identity> getNodeIdentities() {
    return null;
}
 
Example 12
Source File: NodeInformationProvider.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a list of the identities defined in the node. For
 * example, the x-command protocol must provide an identity of
 * category automation and type command-node for each command.
 *
 * @return a list of the Identities defined in the node.
 */
List<DiscoverInfo.Identity> getNodeIdentities();
 
Example 13
Source File: ServiceDiscoveryManager.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Set the default identity all new connections will have. If unchanged the default identity is an
 * identity where category is set to 'client', type is set to 'pc' and name is set to 'Smack'.
 *
 * @param identity TODO javadoc me please
 */
public static void setDefaultIdentity(DiscoverInfo.Identity identity) {
    defaultIdentity = identity;
}