use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project xabber-android by redsolution.
the class ServerInfoActivity method getServerInfo.
@NonNull
List<String> getServerInfo(ServiceDiscoveryManager serviceDiscoveryManager) {
final List<String> serverInfoList = new ArrayList<>();
XMPPTCPConnection connection = accountItem.getConnection();
if (!connection.isAuthenticated()) {
serverInfoList.add(getString(R.string.NOT_CONNECTED));
return serverInfoList;
}
try {
boolean muc = !MultiUserChatManager.getInstanceFor(connection).getXMPPServiceDomains().isEmpty();
boolean pep = PEPManager.getInstanceFor(connection).isSupported();
boolean blockingCommand = BlockingCommandManager.getInstanceFor(connection).isSupportedByServer();
boolean sm = connection.isSmAvailable();
boolean rosterVersioning = Roster.getInstanceFor(connection).isRosterVersioningSupported();
boolean carbons = org.jivesoftware.smackx.carbons.CarbonManager.getInstanceFor(connection).isSupportedByServer();
boolean mam = MamManager.getInstanceFor(connection).isSupportedByServer();
boolean csi = ClientStateIndicationManager.isSupported(connection);
boolean push = PushNotificationsManager.getInstanceFor(connection).isSupportedByServer();
boolean fileUpload = HttpFileUploadManager.getInstance().isFileUploadSupported(accountItem.getAccount());
boolean mucLight = !MultiUserChatLightManager.getInstanceFor(connection).getLocalServices().isEmpty();
boolean bookmarks = BookmarksManager.getInstance().isSupported(accountItem.getAccount());
serverInfoList.add(getString(R.string.xep_0045_muc) + " " + getCheckOrCross(muc));
serverInfoList.add(getString(R.string.xep_0163_pep) + " " + getCheckOrCross(pep));
serverInfoList.add(getString(R.string.xep_0191_blocking) + " " + getCheckOrCross(blockingCommand));
serverInfoList.add(getString(R.string.xep_0198_sm) + " " + getCheckOrCross(sm));
serverInfoList.add(getString(R.string.xep_0237_roster_ver) + " " + getCheckOrCross(rosterVersioning));
serverInfoList.add(getString(R.string.xep_0280_carbons) + " " + getCheckOrCross(carbons));
serverInfoList.add(getString(R.string.xep_0313_mam) + " " + getCheckOrCross(mam));
serverInfoList.add(getString(R.string.xep_0352_csi) + " " + getCheckOrCross(csi));
serverInfoList.add(getString(R.string.xep_0357_push) + " " + getCheckOrCross(push));
serverInfoList.add(getString(R.string.xep_0363_file_upload) + " " + getCheckOrCross(fileUpload));
serverInfoList.add(getString(R.string.xep_xxxx_muc_light) + " " + getCheckOrCross(mucLight));
serverInfoList.add(getString(R.string.xep_0048_bookmarks) + " " + getCheckOrCross(bookmarks));
serverInfoList.add("");
} catch (InterruptedException | SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException e) {
LogManager.exception(LOG_TAG, e);
}
DomainBareJid xmppServiceDomain = connection.getXMPPServiceDomain();
try {
DiscoverInfo discoverInfo = serviceDiscoveryManager.discoverInfo(xmppServiceDomain);
List<DiscoverInfo.Identity> identities = discoverInfo.getIdentities();
if (!identities.isEmpty()) {
serverInfoList.add(getString(R.string.identities));
for (DiscoverInfo.Identity identity : identities) {
serverInfoList.add(identity.getCategory() + " " + identity.getType() + " " + identity.getName());
}
serverInfoList.add("");
}
if (!discoverInfo.getFeatures().isEmpty()) {
serverInfoList.add(getString(R.string.features));
for (DiscoverInfo.Feature feature : discoverInfo.getFeatures()) {
serverInfoList.add(feature.getVar());
}
serverInfoList.add("");
}
DiscoverItems items = serviceDiscoveryManager.discoverItems(xmppServiceDomain);
if (!items.getItems().isEmpty()) {
serverInfoList.add(getString(R.string.items));
for (DiscoverItems.Item item : items.getItems()) {
serverInfoList.add(item.getEntityID().toString());
}
}
} catch (InterruptedException | SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException e) {
LogManager.exception(LOG_TAG, e);
}
if (serverInfoList.isEmpty()) {
serverInfoList.add(getString(R.string.SERVER_INFO_ERROR));
}
return serverInfoList;
}
use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project Smack by igniterealtime.
the class MultiUserChatLightManager method getOccupiedRooms.
/**
* Returns a List of the rooms the user occupies.
*
* @param mucLightService
* @return a List of the rooms the user occupies.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Jid> getOccupiedRooms(DomainBareJid mucLightService) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(mucLightService);
List<DiscoverItems.Item> items = result.getItems();
List<Jid> answer = new ArrayList<>(items.size());
for (DiscoverItems.Item item : items) {
Jid mucLight = item.getEntityID();
answer.add(mucLight);
}
return answer;
}
use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project Smack by igniterealtime.
the class ServiceDiscoveryManager method discoverItems.
/**
* Returns the discovered items of a given XMPP entity addressed by its JID and
* note attribute. Use this message only when trying to query information which is not
* directly addressable.
*
* @param entityID the address of the XMPP entity.
* @param node the optional attribute that supplements the 'jid' attribute.
* @return the discovered items.
* @throws XMPPErrorException if the operation failed for some reason.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverItems discoverItems(Jid entityID, String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
// Discover the entity's items
DiscoverItems disco = new DiscoverItems();
disco.setType(IQ.Type.get);
disco.setTo(entityID);
disco.setNode(node);
Stanza result = connection().createStanzaCollectorAndSend(disco).nextResultOrThrow();
return (DiscoverItems) result;
}
use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project Smack by igniterealtime.
the class Socks5BytestreamManager method determineProxies.
/**
* 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
* @throws InterruptedException
*/
private List<Jid> determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
XMPPConnection connection = connection();
ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
List<Jid> proxies = new ArrayList<>();
// get all items from XMPP server
DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(connection.getXMPPServiceDomain());
// 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;
}
use of org.jivesoftware.smackx.disco.packet.DiscoverItems in project Smack by igniterealtime.
the class Socks5ByteStreamManagerTest method shouldFailIfNoSocks5ProxyFound1.
/**
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if XMPP
* server doesn't return any proxies.
*/
@Test
public void shouldFailIfNoSocks5ProxyFound1() {
// disable clients local SOCKS5 proxy
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
// get Socks5ByteStreamManager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
/**
* create responses in the order they should be queried specified by the XEP-0065
* specification
*/
// build discover info that supports the SOCKS5 feature
DiscoverInfo discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Bytestream.NAMESPACE);
// return that SOCKS5 is supported if target is queried
protocol.addResponse(discoverInfo, Verification.correspondingSenderReceiver, Verification.requestTypeGET);
// build discover items with no proxy items
DiscoverItems discoverItems = Socks5PacketUtils.createDiscoverItems(xmppServer, initiatorJID);
// return the item with no proxy if XMPP server is queried
protocol.addResponse(discoverItems, Verification.correspondingSenderReceiver, Verification.requestTypeGET);
try {
// start SOCKS5 Bytestream
byteStreamManager.establishSession(targetJID, sessionID);
fail("exception should be thrown");
} catch (SmackException e) {
protocol.verifyAll();
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
} catch (Exception e) {
fail(e.getMessage());
}
}
Aggregations