Java Code Examples for org.jivesoftware.smackx.disco.packet.DiscoverInfo#containsFeature()

The following examples show how to use org.jivesoftware.smackx.disco.packet.DiscoverInfo#containsFeature() . 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: ConferenceServiceBrowser.java    From Spark with Apache License 2.0 6 votes vote down vote up
public Collection<String> getConferenceServices(String serverString) throws Exception {
    Jid server = JidCreate.from(serverString);
    List<String> answer = new ArrayList<>();
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
    DiscoverItems items = discoManager.discoverItems(server);
    for (DiscoverItems.Item item : items.getItems() ) {
        if (item.getEntityID().toString().startsWith("conference") || item.getEntityID().toString().startsWith("private")) {
            answer.add(item.getEntityID().toString());
        }
        else {
            try {
                DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
                if (info.containsFeature("http://jabber.org/protocol/muc")) {
                    answer.add(item.getEntityID().toString());
                }
            }
            catch (XMPPException | SmackException e) {
                // Nothing to do
            }
        }
    }
    return answer;
}
 
Example 2
Source File: BookmarksUI.java    From Spark with Apache License 2.0 6 votes vote down vote up
private Collection<DomainBareJid> getConferenceServices(DomainBareJid server) throws Exception {
    List<DomainBareJid> answer = new ArrayList<>();
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
    DiscoverItems items = discoManager.discoverItems(server);
    for (DiscoverItems.Item item : items.getItems()) {
        DomainBareJid entityID = item.getEntityID().asDomainBareJid();
        // TODO: We should not simply assumet that this is MUC service just because it starts with a given prefix.
        if (entityID.toString().startsWith("conference") || entityID.toString().startsWith("private")) {
            answer.add(entityID);
        }
        else {
            try {
                DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
                if (info.containsFeature("http://jabber.org/protocol/muc")) {
                    answer.add(entityID);
                }
            }
            catch (XMPPException | SmackException e) {
                Log.error("Problem when loading conference service.", e);
            }
        }
    }
    return answer;
}
 
Example 3
Source File: TransportUtils.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the user is registered with a gateway.
 *
 * @param con       the XMPPConnection.
 * @param transport the transport.
 * @return true if the user is registered with the transport.
 */
public static boolean isRegistered(XMPPConnection con, Transport transport) {
    if (!con.isConnected()) {
        return false;
    }

    ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con);
    try {
        Jid jid = JidCreate.from(transport.getXMPPServiceDomain());
        DiscoverInfo info = discoveryManager.discoverInfo(jid);
        return info.containsFeature("jabber:iq:registered");
    }
    catch (XMPPException | SmackException | XmppStringprepException | InterruptedException e) {
        Log.error(e);
    }
    return false;
}
 
Example 4
Source File: Workgroup.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * The workgroup service may be configured to send email. This queries the Workgroup Service
 * to see if the email service has been configured and is available.
 *
 * @return true if the email service is available, otherwise return false.
 * @throws SmackException if Smack detected an exceptional situation.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public boolean isEmailAvailable() throws SmackException, InterruptedException {
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);

    try {
        DomainBareJid workgroupService = workgroupJID.asDomainBareJid();
        DiscoverInfo infoResult = discoManager.discoverInfo(workgroupService);
        return infoResult.containsFeature("jive:email:provider");
    }
    catch (XMPPException e) {
        return false;
    }
}
 
Example 5
Source File: ServiceDiscoveryManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public boolean supportsFeatures(Jid jid, Collection<? extends CharSequence> features) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    DiscoverInfo result = discoverInfo(jid);
    for (CharSequence feature : features) {
        if (!result.containsFeature(feature)) {
            return false;
        }
    }
    return true;
}
 
Example 6
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 7
Source File: ConferenceUtils.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the room requires a password.
 *
 * @param roomJID the JID of the room.
 * @return true if the room requires a password.
 */
public static boolean isPasswordRequired(EntityBareJid roomJID) {
    // Check to see if the room is password protected
	ServiceDiscoveryManager discover = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());

    try {
        DiscoverInfo info = discover.discoverInfo(roomJID);
        return info.containsFeature("muc_passwordprotected");
    }
    catch (XMPPException | SmackException | InterruptedException e) {
        Log.error(e);
    }
    return false;
}
 
Example 8
Source File: HttpFileUploadManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
private static boolean containsHttpFileUploadNamespace(DiscoverInfo discoverInfo) {
    return discoverInfo.containsFeature(NAMESPACE) || discoverInfo.containsFeature(NAMESPACE_0_2);
}