org.jivesoftware.smackx.disco.packet.DiscoverInfo Java Examples
The following examples show how to use
org.jivesoftware.smackx.disco.packet.DiscoverInfo.
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: ServiceDiscoveryManager.java From Smack with Apache License 2.0 | 6 votes |
/** * Returns the discovered information of a given XMPP entity addressed by its JID. * Use null as entityID to query the server * * @param entityID the address of the XMPP entity or null. * @return the discovered information. * @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 DiscoverInfo discoverInfo(Jid entityID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { if (entityID == null) return discoverInfo(null, null); synchronized (discoInfoLookupShortcutMechanisms) { for (DiscoInfoLookupShortcutMechanism discoInfoLookupShortcutMechanism : discoInfoLookupShortcutMechanisms) { DiscoverInfo info = discoInfoLookupShortcutMechanism.getDiscoverInfoByUser(this, entityID); if (info != null) { // We were able to retrieve the information from Entity Caps and // avoided a disco request, hurray! return info; } } } // Last resort: Standard discovery. return discoverInfo(entityID, null); }
Example #2
Source File: HttpFileUploadManager.java From Smack with Apache License 2.0 | 6 votes |
/** * Discover upload service. * * Called automatically when connection is authenticated. * * Note that this is a synchronous call -- Smack must wait for the server response. * * @return true if upload service was discovered * @throws XMPPException.XMPPErrorException if there was an XMPP error returned. * @throws SmackException.NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. * @throws SmackException.NoResponseException if there was no response from the remote entity. */ public boolean discoverUploadService() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException { ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection()); List<DiscoverInfo> servicesDiscoverInfo = sdm .findServicesDiscoverInfo(NAMESPACE, true, true); if (servicesDiscoverInfo.isEmpty()) { servicesDiscoverInfo = sdm.findServicesDiscoverInfo(NAMESPACE_0_2, true, true); if (servicesDiscoverInfo.isEmpty()) { return false; } } DiscoverInfo discoverInfo = servicesDiscoverInfo.get(0); defaultUploadService = uploadServiceFrom(discoverInfo); return true; }
Example #3
Source File: BookmarksUI.java From Spark with Apache License 2.0 | 6 votes |
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 #4
Source File: ConferenceUtils.java From Spark with Apache License 2.0 | 6 votes |
/** * Retrieve the date (in yyyyMMdd) format of the time the room was created. * * @param roomJID the jid of the room. * @return the formatted date. * @throws Exception throws an exception if we are unable to retrieve the date. */ public static String getCreationDate(EntityBareJid roomJID) throws Exception { ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection()); final DateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"); DiscoverInfo infoResult = discoManager.discoverInfo(roomJID); DataForm dataForm = infoResult.getExtension("x", "jabber:x:data"); if (dataForm == null) { return "Not available"; } String creationDate = ""; for ( final FormField field : dataForm.getFields() ) { String label = field.getLabel(); if (label != null && "Creation date".equalsIgnoreCase(label)) { for ( CharSequence value : field.getValues() ) { creationDate = value.toString(); Date date = dateFormatter.parse(creationDate); creationDate = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.MEDIUM).format(date); } } } return creationDate; }
Example #5
Source File: IoTDiscoveryManager.java From Smack with Apache License 2.0 | 6 votes |
/** * Try to find an XMPP IoT registry. * * @return the JID of a Thing Registry if one could be found, <code>null</code> otherwise. * @throws InterruptedException if the calling thread was interrupted. * @throws NotConnectedException if the XMPP connection is not connected. * @throws XMPPErrorException if there was an XMPP error returned. * @throws NoResponseException if there was no response from the remote entity. * @see <a href="http://xmpp.org/extensions/xep-0347.html#findingregistry">XEP-0347 § 3.5 Finding Thing Registry</a> */ public Jid findRegistry() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { if (preconfiguredRegistry != null) { return preconfiguredRegistry; } final XMPPConnection connection = connection(); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); List<DiscoverInfo> discoverInfos = sdm.findServicesDiscoverInfo(Constants.IOT_DISCOVERY_NAMESPACE, true, true); if (!discoverInfos.isEmpty()) { return discoverInfos.get(0).getFrom(); } return null; }
Example #6
Source File: PrivacyManager.java From Spark with Apache License 2.0 | 6 votes |
private boolean checkIfPrivacyIsSupported(XMPPConnection conn) { ServiceDiscoveryManager servDisc = ServiceDiscoveryManager.getInstanceFor(conn); DiscoverInfo info = null; try { info = servDisc.discoverInfo(conn.getXMPPServiceDomain()); } catch (XMPPException | SmackException | InterruptedException e) { // We could not query the server } if (info != null) { for ( final Feature feature : info.getFeatures() ) { if (feature.getVar().contains("jabber:iq:privacy")) { return true; } } } return false; }
Example #7
Source File: ConferenceServiceBrowser.java From Spark with Apache License 2.0 | 6 votes |
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 #8
Source File: MultiUserChat.java From Smack with Apache License 2.0 | 6 votes |
/** * 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 #9
Source File: EntityCapsManagerTest.java From Smack with Apache License 2.0 | 6 votes |
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 #10
Source File: EntityCapsManagerTest.java From Smack with Apache License 2.0 | 6 votes |
@SuppressWarnings("UnusedVariable") private static void testSimpleDirectoryCache(StringEncoder<String> stringEncoder) throws IOException { EntityCapsPersistentCache cache = new SimpleDirectoryPersistentCache(createTempDirectory()); EntityCapsManager.setPersistentCache(cache); DiscoverInfo di = createComplexSamplePacket(); CapsVersionAndHash versionAndHash = EntityCapsManager.generateVerificationString(di, StringUtils.SHA1); String nodeVer = di.getNode() + "#" + versionAndHash.version; // Save the data in EntityCapsManager EntityCapsManager.addDiscoverInfoByNode(nodeVer, di); // Lose all the data EntityCapsManager.clearMemoryCache(); DiscoverInfo restored_di = EntityCapsManager.getDiscoveryInfoByNodeVer(nodeVer); assertNotNull(restored_di); assertEquals(di.toXML().toString(), restored_di.toXML().toString()); }
Example #11
Source File: Socks5ByteStreamManagerTest.java From Smack with Apache License 2.0 | 6 votes |
/** * Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid)} should throw an exception * if the given target does not support SOCKS5 Bytestream. * @throws XMPPException if an XMPP protocol error was received. * @throws InterruptedException if the calling thread was interrupted. * @throws SmackException if Smack detected an exceptional situation. * @throws IOException if an I/O error occurred. */ @Test public void shouldFailIfTargetDoesNotSupportSocks5() throws XMPPException, SmackException, InterruptedException, IOException { final Protocol protocol = new Protocol(); final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID); Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection); FeatureNotSupportedException e = assertThrows(FeatureNotSupportedException.class, () -> { // build empty discover info as reply if targets features are queried DiscoverInfo discoverInfo = DiscoverInfo.builder("disco-1").build(); protocol.addResponse(discoverInfo); // start SOCKS5 Bytestream byteStreamManager.establishSession(targetJID); }); assertTrue(e.getFeature().equals("SOCKS5 Bytestream")); assertTrue(e.getJid().equals(targetJID)); }
Example #12
Source File: ConfigureFormTest.java From Smack with Apache License 2.0 | 6 votes |
@Test public void getConfigFormWithTimeout() throws XMPPException, InterruptedException, SmackException, IOException { ThreadedDummyConnection con = ThreadedDummyConnection.newInstance(); PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE); DiscoverInfoBuilder info = DiscoverInfo.builder("disco-result") .ofType(IQ.Type.result) .from(PubSubManagerTest.DUMMY_PUBSUB_SERVICE); Identity ident = new Identity("pubsub", null, "leaf"); info.addIdentity(ident); DiscoverInfo discoverInfo = info.build(); con.addIQReply(discoverInfo); Node node = mgr.getNode("princely_musings"); SmackConfiguration.setDefaultReplyTimeout(100); con.setTimeout(); assertThrows(SmackException.class, () -> { node.getNodeConfiguration(); }); }
Example #13
Source File: RoomInfoTest.java From Smack with Apache License 2.0 | 6 votes |
@Test public void validateRoomWithForm() { DataForm.Builder dataForm = DataForm.builder(DataForm.Type.result); TextSingleFormField.Builder desc = FormField.builder("muc#roominfo_description"); desc.setValue("The place for all good witches!"); dataForm.addField(desc.build()); TextSingleFormField.Builder subject = FormField.builder("muc#roominfo_subject"); subject.setValue("Spells"); dataForm.addField(subject.build()); TextSingleFormField.Builder occupants = FormField.builder("muc#roominfo_occupants"); occupants.setValue("3"); dataForm.addField(occupants.build()); DiscoverInfo discoInfo = DiscoverInfo.builder("disco1") .addExtension(dataForm.build()) .build(); RoomInfo roomInfo = new RoomInfo(discoInfo); assertEquals("The place for all good witches!", roomInfo.getDescription()); assertEquals("Spells", roomInfo.getSubject()); assertEquals(3, roomInfo.getOccupantsCount()); }
Example #14
Source File: EntityCapsManager.java From Smack with Apache License 2.0 | 6 votes |
/** * Verify DiscoverInfo and Caps Node as defined in XEP-0115 5.4 Processing * Method. * * @see <a href="http://xmpp.org/extensions/xep-0115.html#ver-proc">XEP-0115 * 5.4 Processing Method</a> * * @param ver TODO javadoc me please * @param hash TODO javadoc me please * @param info TODO javadoc me please * @return true if it's valid and should be cache, false if not */ public static boolean verifyDiscoverInfoVersion(String ver, String hash, DiscoverInfo info) { // step 3.3 check for duplicate identities if (info.containsDuplicateIdentities()) return false; // step 3.4 check for duplicate features if (info.containsDuplicateFeatures()) return false; // step 3.5 check for well-formed packet extensions if (!verifyPacketExtensions(info)) return false; String calculatedVer = generateVerificationString(info, hash).version; if (!ver.equals(calculatedVer)) return false; return true; }
Example #15
Source File: EntityCapsManager.java From Smack with Apache License 2.0 | 6 votes |
/** * Verify that the given discovery info is not ill-formed. * * @param info the discovery info to verify. * @return true if the stanza extensions is not ill-formed */ private static boolean verifyPacketExtensions(DiscoverInfo info) { Set<String> foundFormTypes = new HashSet<>(); List<DataForm> dataForms = info.getExtensions(DataForm.class); for (DataForm dataForm : dataForms) { FormField formFieldTypeField = dataForm.getHiddenFormTypeField(); if (formFieldTypeField == null) { continue; } String type = formFieldTypeField.getFirstValue(); boolean noDuplicate = foundFormTypes.add(type); if (!noDuplicate) { // Ill-formed extension: duplicate forms (by form field type string). return false; } } return true; }
Example #16
Source File: ServiceDiscoveryManager.java From Smack with Apache License 2.0 | 6 votes |
public DomainBareJid findService(String feature, boolean useCache, String category, String type) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { boolean noCategory = StringUtils.isNullOrEmpty(category); boolean noType = StringUtils.isNullOrEmpty(type); if (noType != noCategory) { throw new IllegalArgumentException("Must specify either both, category and type, or none"); } List<DiscoverInfo> services = findServicesDiscoverInfo(feature, false, useCache); if (services.isEmpty()) { return null; } if (!noCategory && !noType) { for (DiscoverInfo info : services) { if (info.hasIdentity(category, type)) { return info.getFrom().asDomainBareJid(); } } } return services.get(0).getFrom().asDomainBareJid(); }
Example #17
Source File: TransportUtils.java From Spark with Apache License 2.0 | 6 votes |
/** * 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 #18
Source File: Socks5PacketUtils.java From Smack with Apache License 2.0 | 5 votes |
/** * Returns a response to an info discovery request. The stanza doesn't contain any infos. * * @param from the target * @param to the initiator * @return response to an info discovery request */ public static DiscoverInfoBuilder createDiscoverInfo(Jid from, Jid to) { DiscoverInfoBuilder discoverInfo = DiscoverInfo.builder("disco-1") .from(from) .to(to) .ofType(IQ.Type.result) ; return discoverInfo; }
Example #19
Source File: EntityCapsManagerTest.java From Smack with Apache License 2.0 | 5 votes |
/** * <a href="http://xmpp.org/extensions/xep-0115.html#ver-gen-complex">XEP- * 0115 Complex Generation Example</a>. * @throws XmppStringprepException if the provided string is invalid. */ @Test public void testComplexGenerationExample() throws XmppStringprepException { DiscoverInfo di = createComplexSamplePacket(); CapsVersionAndHash versionAndHash = EntityCapsManager.generateVerificationString(di, StringUtils.SHA1); assertEquals("q07IKJEyjvHSyhy//CH0CxmKi8w=", versionAndHash.version); }
Example #20
Source File: ConferenceUtils.java From Spark with Apache License 2.0 | 5 votes |
/** * 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 #21
Source File: EntityCapsTest.java From Smack with Apache License 2.0 | 5 votes |
@SmackIntegrationTest public void testLocalEntityCaps() throws InterruptedException, NoResponseException, XMPPErrorException, NotConnectedException { final String dummyFeature = getNewDummyFeature(); DiscoverInfo info = EntityCapsManager.getDiscoveryInfoByNodeVer(ecmTwo.getLocalNodeVer()); assertFalse(info.containsFeature(dummyFeature)); dropWholeEntityCapsCache(); performActionAndWaitUntilStanzaReceived(new Runnable() { @Override public void run() { // This should cause a new presence stanza from con1 with and updated // 'ver' String sdmTwo.addFeature(dummyFeature); } }, conOne, new AndFilter(PresenceTypeFilter.AVAILABLE, FromMatchesFilter.create(conTwo.getUser()))); // The presence stanza should get received by con0 and the data should // be recorded in the map // Note that while both connections use the same static Entity Caps // cache, // it's assured that *not* con1 added the data to the Entity Caps cache. // Every time the entities features // and identities change only a new caps 'ver' is calculated and send // with the presence stanza // The other connection has to receive this stanza and record the // information in order for this test to succeed. info = EntityCapsManager.getDiscoveryInfoByNodeVer(ecmTwo.getLocalNodeVer()); assertNotNull(info); assertTrue(info.containsFeature(dummyFeature)); }
Example #22
Source File: EntityCapsTest.java From Smack with Apache License 2.0 | 5 votes |
/** * Test if entity caps actually prevent a disco info request and reply. * * @throws Exception if exception. */ @SmackIntegrationTest public void testPreventDiscoInfo() throws Exception { final String dummyFeature = getNewDummyFeature(); final AtomicBoolean discoInfoSend = new AtomicBoolean(); conOne.addStanzaSendingListener(new StanzaListener() { @Override public void processStanza(Stanza stanza) { discoInfoSend.set(true); } }, new AndFilter(new StanzaTypeFilter(DiscoverInfo.class), IQTypeFilter.GET)); addFeatureAndWaitForPresence(conOne, conTwo, dummyFeature); dropCapsCache(); // discover that DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser()); // that discovery should cause a disco#info assertTrue(discoInfoSend.get()); assertTrue(info.containsFeature(dummyFeature), "The info response '" + info + "' does not contain the expected feature '" + dummyFeature + '\''); discoInfoSend.set(false); // discover that info = sdmOne.discoverInfo(conTwo.getUser()); // that discovery shouldn't cause a disco#info assertFalse(discoInfoSend.get()); assertTrue(info.containsFeature(dummyFeature)); }
Example #23
Source File: RTPBridge.java From Smack with Apache License 2.0 | 5 votes |
/** * 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 #24
Source File: EntityCapsManagerTest.java From Smack with Apache License 2.0 | 5 votes |
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 #25
Source File: RoomInfoTest.java From Smack with Apache License 2.0 | 5 votes |
@Test public void validateRoomWithEmptyForm() { DataForm dataForm = DataForm.builder(DataForm.Type.result).build(); DiscoverInfo discoInfo = DiscoverInfo.builder("disco1") .addExtension(dataForm) .build(); RoomInfo roomInfo = new RoomInfo(discoInfo); assertTrue(roomInfo.getDescription().isEmpty()); assertTrue(roomInfo.getSubject().isEmpty()); assertEquals(-1, roomInfo.getOccupantsCount()); }
Example #26
Source File: ServiceDiscoveryManager.java From Smack with Apache License 2.0 | 5 votes |
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 #27
Source File: ServiceDiscoveryManager.java From Smack with Apache License 2.0 | 5 votes |
/** * 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 #28
Source File: ServiceDiscoveryManager.java From Smack with Apache License 2.0 | 5 votes |
/** * 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 #29
Source File: STUN.java From Smack with Apache License 2.0 | 5 votes |
/** * 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 #30
Source File: ServiceDiscoveryManager.java From Smack with Apache License 2.0 | 5 votes |
/** * 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(); }