public Collection<String> getConferenceServices(String server) throws Exception { List<String> answer = new ArrayList<String>(); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection()); DiscoverItems items = discoManager.discoverItems(server); for (Iterator<Item> it = items.getItems(); it.hasNext();) { Item item = it.next(); if (item.getEntityID().startsWith("conference") || item.getEntityID().startsWith("private")) { answer.add(item.getEntityID()); } else { try { DiscoverInfo info = discoManager.discoverInfo(item.getEntityID()); if (info.containsFeature("http://jabber.org/protocol/muc")) { answer.add(item.getEntityID()); } } catch (XMPPException e) { // Nothing to do } } } return answer; }
/** * Loads all gateways the users server offers * @throws XMPPException */ private void loadLocalGateways() throws XMPPException{ DiscoverItems items = sdManager.discoverItems(connection.getHost()); Iterator<Item> iter = items.getItems(); while(iter.hasNext()){ String itemJID = iter.next().getEntityID(); discoverGateway(itemJID); } }
/** * Loads all gateways the users server offers * * @throws XMPPException */ private void loadLocalGateways() throws XMPPException { DiscoverItems items = sdManager.discoverItems(connection.getHost()); Iterator<Item> iter = items.getItems(); while (iter.hasNext()) { String itemJID = iter.next().getEntityID(); discoverGateway(itemJID); } }
public void serviceDiscoveryRequest() throws XMPPException { DiscoverItems discoItems = mServiceDiscoveryManager.discoverItems(connection.getServiceName()); Iterator<Item> it = discoItems.getItems(); while (it.hasNext()) { DiscoverItems.Item item = (DiscoverItems.Item) it.next(); Logger.log("Service available:" + item.getEntityID() + " " + item.getName()); } }
/** * Returns a list of JIDs of SOCKS5 proxies by querying the XMPP server. The SOCKS5 proxies are * in the same order as returned by the XMPP server. * * @return list of JIDs of SOCKS5 proxies * @throws XMPPException if there was an error querying the XMPP server for SOCKS5 proxies */ private List<String> determineProxies() throws XMPPException { ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(this.connection); List<String> proxies = new ArrayList<String>(); // get all items form XMPP server DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(this.connection.getServiceName()); Iterator<Item> itemIterator = discoverItems.getItems(); // query all items if they are SOCKS5 proxies while (itemIterator.hasNext()) { Item item = itemIterator.next(); // skip blacklisted servers if (this.proxyBlacklist.contains(item.getEntityID())) { continue; } try { DiscoverInfo proxyInfo; proxyInfo = serviceDiscoveryManager.discoverInfo(item.getEntityID()); Iterator<Identity> identities = proxyInfo.getIdentities(); // item must have category "proxy" and type "bytestream" while (identities.hasNext()) { Identity identity = identities.next(); if ("proxy".equalsIgnoreCase(identity.getCategory()) && "bytestreams".equalsIgnoreCase(identity.getType())) { proxies.add(item.getEntityID()); break; } /* * server is not a SOCKS5 proxy, blacklist server to skip next time a Socks5 * bytestream should be established */ this.proxyBlacklist.add(item.getEntityID()); } } catch (XMPPException e) { // blacklist errornous server this.proxyBlacklist.add(item.getEntityID()); } } return proxies; }
/** * Updates the local user Entity Caps information with the data provided * * If we are connected and there was already a presence send, another * presence is send to inform others about your new Entity Caps node string. * * @param discoverInfo * the local users discover info (mostly the service discovery * features) * @param identityType * the local users identity type * @param identityName * the local users identity name * @param extendedInfo * the local users extended info */ public void updateLocalEntityCaps() { Connection connection = weakRefConnection.get(); DiscoverInfo discoverInfo = new DiscoverInfo(); discoverInfo.setType(IQ.Type.RESULT); discoverInfo.setNode(getLocalNodeVer()); if (connection != null) discoverInfo.setFrom(connection.getUser()); sdm.addDiscoverInfoTo(discoverInfo); currentCapsVersion = generateVerificationString(discoverInfo, "sha-1"); addDiscoverInfoByNode(ENTITY_NODE + '#' + currentCapsVersion, discoverInfo); if (lastLocalCapsVersions.size() > 10) { String oldCapsVersion = lastLocalCapsVersions.poll(); sdm.removeNodeInformationProvider(ENTITY_NODE + '#' + oldCapsVersion); } lastLocalCapsVersions.add(currentCapsVersion); caps.put(currentCapsVersion, discoverInfo); if (connection != null) jidCaps.put(connection.getUser(), new NodeVerHash(ENTITY_NODE, currentCapsVersion, "sha-1")); final List<Identity> identities = new LinkedList<Identity>(ServiceDiscoveryManager.getInstanceFor(connection).getIdentities()); sdm.setNodeInformationProvider(ENTITY_NODE + '#' + currentCapsVersion, new NodeInformationProvider() { List<String> features = sdm.getFeaturesList(); List<PacketExtension> packetExtensions = sdm.getExtendedInfoAsList(); @Override public List<Item> getNodeItems() { return null; } @Override public List<String> getNodeFeatures() { return features; } @Override public List<Identity> getNodeIdentities() { return identities; } @Override public List<PacketExtension> getNodePacketExtensions() { return packetExtensions; } }); // Send an empty presence, and let the packet intercepter // add a <c/> node to it. // See http://xmpp.org/extensions/xep-0115.html#advertise // We only send a presence packet if there was already one send // to respect ConnectionConfiguration.isSendPresence() if (connection != null && connection.isAuthenticated() && presenceSend) { Presence presence = new Presence(Presence.Type.available); connection.sendPacket(presence); } }
/** * Returns a list of JIDs of SOCKS5 proxies by querying the XMPP server. The * SOCKS5 proxies are in the same order as returned by the XMPP server. * * @return list of JIDs of SOCKS5 proxies * @throws XMPPException * if there was an error querying the XMPP server for SOCKS5 * proxies */ private List<String> determineProxies() throws XMPPException { ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager .getInstanceFor(this.connection); List<String> proxies = new ArrayList<String>(); // get all items form XMPP server DiscoverItems discoverItems = serviceDiscoveryManager .discoverItems(this.connection.getServiceName()); Iterator<Item> itemIterator = discoverItems.getItems(); // query all items if they are SOCKS5 proxies while (itemIterator.hasNext()) { Item item = itemIterator.next(); // skip blacklisted servers if (this.proxyBlacklist.contains(item.getEntityID())) { continue; } try { DiscoverInfo proxyInfo; proxyInfo = serviceDiscoveryManager.discoverInfo(item .getEntityID()); Iterator<Identity> identities = proxyInfo.getIdentities(); // item must have category "proxy" and type "bytestream" while (identities.hasNext()) { Identity identity = identities.next(); if ("proxy".equalsIgnoreCase(identity.getCategory()) && "bytestreams".equalsIgnoreCase(identity .getType())) { proxies.add(item.getEntityID()); break; } /* * server is not a SOCKS5 proxy, blacklist server to skip * next time a Socks5 bytestream should be established */ this.proxyBlacklist.add(item.getEntityID()); } } catch (XMPPException e) { // blacklist errornous server this.proxyBlacklist.add(item.getEntityID()); } } return proxies; }
/** * Updates the local user Entity Caps information with the data provided * * If we are connected and there was already a presence send, another * presence is send to inform others about your new Entity Caps node string. * * @param discoverInfo * the local users discover info (mostly the service discovery * features) * @param identityType * the local users identity type * @param identityName * the local users identity name * @param extendedInfo * the local users extended info */ public void updateLocalEntityCaps() { Connection connection = weakRefConnection.get(); DiscoverInfo discoverInfo = new DiscoverInfo(); discoverInfo.setType(IQ.Type.RESULT); discoverInfo.setNode(getLocalNodeVer()); if (connection != null) discoverInfo.setFrom(connection.getUser()); sdm.addDiscoverInfoTo(discoverInfo); currentCapsVersion = generateVerificationString(discoverInfo, "sha-1"); addDiscoverInfoByNode(ENTITY_NODE + '#' + currentCapsVersion, discoverInfo); if (lastLocalCapsVersions.size() > 10) { String oldCapsVersion = lastLocalCapsVersions.poll(); sdm.removeNodeInformationProvider(ENTITY_NODE + '#' + oldCapsVersion); } lastLocalCapsVersions.add(currentCapsVersion); caps.put(currentCapsVersion, discoverInfo); if (connection != null) jidCaps.put(connection.getUser(), new NodeVerHash(ENTITY_NODE, currentCapsVersion, "sha-1")); sdm.setNodeInformationProvider(ENTITY_NODE + '#' + currentCapsVersion, new NodeInformationProvider() { List<String> features = sdm.getFeaturesList(); List<Identity> identities = new LinkedList<Identity>(ServiceDiscoveryManager.getIdentities()); List<PacketExtension> packetExtensions = sdm.getExtendedInfoAsList(); @Override public List<Item> getNodeItems() { return null; } @Override public List<String> getNodeFeatures() { return features; } @Override public List<Identity> getNodeIdentities() { return identities; } @Override public List<PacketExtension> getNodePacketExtensions() { return packetExtensions; } }); // Send an empty presence, and let the packet intercepter // add a <c/> node to it. // See http://xmpp.org/extensions/xep-0115.html#advertise // We only send a presence packet if there was already one send // to respect ConnectionConfiguration.isSendPresence() if (connection != null && connection.isAuthenticated() && presenceSend) { Presence presence = new Presence(Presence.Type.available); connection.sendPacket(presence); } }