1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 20:42:06 +01:00

Add proxy discovery method

This commit is contained in:
vanitasvitae 2017-06-08 14:59:49 +02:00
parent 1775c691af
commit 135f1ed77b
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -17,8 +17,18 @@
package org.jivesoftware.smackx.jingle_s5b; package org.jivesoftware.smackx.jingle_s5b;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.jingle.AbstractJingleContentTransportManager; import org.jivesoftware.smackx.jingle.AbstractJingleContentTransportManager;
import org.jivesoftware.smackx.jingle.JingleTransportInputStreamCallback; import org.jivesoftware.smackx.jingle.JingleTransportInputStreamCallback;
import org.jivesoftware.smackx.jingle.element.Jingle; import org.jivesoftware.smackx.jingle.element.Jingle;
@ -35,6 +45,36 @@ public final class JingleSocks5BytestreamTransportManager extends AbstractJingle
super(connection); super(connection);
} }
public ArrayList<Bytestream.StreamHost> getProxyIdentities() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
final ArrayList<Bytestream.StreamHost> streamHosts = new ArrayList<>();
DiscoverInfo.Feature bytestreams = new DiscoverInfo.Feature(Bytestream.NAMESPACE);
ServiceDiscoveryManager dm = ServiceDiscoveryManager.getInstanceFor(connection());
DiscoverItems disco = dm.discoverItems(connection().getXMPPServiceDomain());
for (DiscoverItems.Item item : disco.getItems()) {
DiscoverInfo info = dm.discoverInfo(item.getEntityID());
if (!info.getFeatures().contains(bytestreams)) {
continue;
}
List<DiscoverInfo.Identity> identities = info.getIdentities("proxy", "bytestreams");
if (identities.isEmpty()) {
continue;
}
Bytestream b = new Bytestream();
b.setTo(item.getEntityID());
connection().sendIqWithResponseCallback(b, new StanzaListener() {
@Override
public void processStanza(Stanza packet) throws SmackException.NotConnectedException, InterruptedException {
Bytestream result = (Bytestream) packet;
if (result != null) {
streamHosts.addAll(result.getStreamHosts());
}
}
});
}
return streamHosts;
}
@Override @Override
protected JingleContentTransportProvider<JingleSocks5BytestreamTransport> createJingleContentTransportProvider() { protected JingleContentTransportProvider<JingleSocks5BytestreamTransport> createJingleContentTransportProvider() {
return new JingleSocks5BytestreamTransportProvider(); return new JingleSocks5BytestreamTransportProvider();