private final void setPrivacyList(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { List<PrivacyItem> list = new ArrayList<PrivacyItem>(PRIVACY_LIST.size() + 10); list.addAll(PRIVACY_LIST); // Whitelist all JIDs of the own service, e.g. conference.service.com, proxy.service.com for (Item i : ServiceDiscoveryManager.getInstanceFor(connection) .discoverItems(connection.getServiceName()).getItems()) { PrivacyItem allow = new PrivacyItem(Type.jid, i.getEntityID(), true, list.size() + 1); list.add(allow); } // This is an ugly workaround for XMPP servers that apply privacy lists also to stanzas // originating from themselves. For example http://issues.igniterealtime.org/browse/OF-724 // Because there are such services in the wild and XEP-0016 is not clear on that topic, we // explicitly have to add a JID rule that allows stanzas from the service PrivacyItem allowService = new PrivacyItem(Type.jid, connection.getServiceName(), true, list.size() + 1); list.add(allowService); mPrivacyListManager.createPrivacyList(PRIVACY_LIST_NAME, list); mPrivacyListManager.setDefaultListName(PRIVACY_LIST_NAME); }
/** * 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 XMPPErrorException if there was an error querying the XMPP server for SOCKS5 proxies * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException */ private List<String> determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException { XMPPConnection connection = connection(); ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); List<String> proxies = new ArrayList<String>(); // get all items from XMPP server DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(connection.getServiceName()); // query all items if they are SOCKS5 proxies for (Item item : discoverItems.getItems()) { // skip blacklisted servers if (this.proxyBlacklist.contains(item.getEntityID())) { continue; } DiscoverInfo proxyInfo; try { proxyInfo = serviceDiscoveryManager.discoverInfo(item.getEntityID()); } catch (NoResponseException|XMPPErrorException e) { // blacklist errornous server proxyBlacklist.add(item.getEntityID()); continue; } if (proxyInfo.hasIdentity("proxy", "bytestreams")) { proxies.add(item.getEntityID()); } else { /* * server is not a SOCKS5 proxy, blacklist server to skip next time a Socks5 * bytestream should be established */ this.proxyBlacklist.add(item.getEntityID()); } } return proxies; }
private void discover() throws XMPPErrorException, URISyntaxException, SmackException, XmlException { System.out.println("discover root services"); // Obtain the ServiceDiscoveryManager associated with my XMPPConnection ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); // Get the items of a given XMPP entity // This gets the items associated with online catalog service DiscoverItems discoItems = discoManager.discoverItems(TEST_DOMAIN); // Get the discovered items of the queried XMPP entity List<Item> items = discoItems.getItems(); // set exchange and root server for(Item item : items) { System.out.println(item.getEntityID()); if(ServiceNames.RootComponentName.equals(item.getName())) rootURI = item.getEntityID(); else if(ServiceNames.ExchangeComponentName.equals(item.getName())) exchangeURI = item.getEntityID(); } // discover root features if(rootURI != null) { checkFeatures(discoManager, rootURI); } // discover exchange features if(exchangeURI != null) { checkFeatures(discoManager, exchangeURI); } }