use of org.jivesoftware.smack.packet.EmptyResultIQ in project Smack by igniterealtime.
the class Socks5ClientForInitiatorTest method shouldSuccessfullyEstablishConnectionAndActivateSocks5Proxy.
/**
* Target and initiator should successfully connect to a "remote" SOCKS5 proxy and the initiator
* activates the bytestream.
*
* @throws Exception should not happen
*/
@Test
public void shouldSuccessfullyEstablishConnectionAndActivateSocks5Proxy() throws Exception {
// build activation confirmation response
IQ activationResponse = new EmptyResultIQ();
activationResponse.setFrom(proxyJID);
activationResponse.setTo(initiatorJID);
protocol.addResponse(activationResponse, Verification.correspondingSenderReceiver, Verification.requestTypeSET, new Verification<Bytestream, IQ>() {
@Override
public void verify(Bytestream request, IQ response) {
// verify that the correct stream should be activated
assertNotNull(request.getToActivate());
assertEquals(targetJID, request.getToActivate().getTarget());
}
});
// start a local SOCKS5 proxy
Socks5TestProxy socks5Proxy = Socks5TestProxy.getProxy(proxyPort);
socks5Proxy.start();
StreamHost streamHost = new StreamHost(proxyJID, loopbackAddress, socks5Proxy.getPort());
// create digest to get the socket opened by target
String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID);
Socks5ClientForInitiator socks5Client = new Socks5ClientForInitiator(streamHost, digest, connection, sessionID, targetJID);
Socket initiatorSocket = socks5Client.getSocket(10000);
InputStream in = initiatorSocket.getInputStream();
Socket targetSocket = socks5Proxy.getSocket(digest);
OutputStream out = targetSocket.getOutputStream();
// verify test data
for (int i = 0; i < 10; i++) {
out.write(i);
assertEquals(i, in.read());
}
protocol.verifyAll();
initiatorSocket.close();
targetSocket.close();
socks5Proxy.stop();
}
use of org.jivesoftware.smack.packet.EmptyResultIQ in project Smack by igniterealtime.
the class Socks5PacketUtils method createActivationConfirmation.
/**
* Returns a response IQ for a activation request to the proxy.
*
* @param from JID of the proxy
* @param to JID of the client who wants to activate the SOCKS5 Bytestream
* @return response IQ for a activation request to the proxy
*/
public static IQ createActivationConfirmation(Jid from, Jid to) {
IQ response = new EmptyResultIQ();
response.setFrom(from);
response.setTo(to);
return response;
}
use of org.jivesoftware.smack.packet.EmptyResultIQ in project Smack by igniterealtime.
the class IBBPacketUtils method createResultIQ.
/**
* Returns a result IQ.
*
* @param from the senders JID
* @param to the recipients JID
* @return a result IQ
*/
public static IQ createResultIQ(Jid from, Jid to) {
IQ result = new EmptyResultIQ();
result.setType(IQ.Type.result);
result.setFrom(from);
result.setTo(to);
return result;
}
use of org.jivesoftware.smack.packet.EmptyResultIQ in project Smack by igniterealtime.
the class PacketParserUtils method parseIQ.
/**
* Parses an IQ packet.
*
* @param parser the XML parser, positioned at the start of an IQ packet.
* @return an IQ object.
* @throws Exception
*/
public static IQ parseIQ(XmlPullParser parser) throws Exception {
ParserUtils.assertAtStartTag(parser);
final int initialDepth = parser.getDepth();
IQ iqPacket = null;
XMPPError.Builder error = null;
final String id = parser.getAttributeValue("", "id");
final Jid to = ParserUtils.getJidAttribute(parser, "to");
final Jid from = ParserUtils.getJidAttribute(parser, "from");
final IQ.Type type = IQ.Type.fromString(parser.getAttributeValue("", "type"));
outerloop: while (true) {
int eventType = parser.next();
switch(eventType) {
case XmlPullParser.START_TAG:
String elementName = parser.getName();
String namespace = parser.getNamespace();
switch(elementName) {
case "error":
error = PacketParserUtils.parseError(parser);
break;
// this element name and namespace.
default:
IQProvider<IQ> provider = ProviderManager.getIQProvider(elementName, namespace);
if (provider != null) {
iqPacket = provider.parse(parser);
} else // Note that if we reach this code, it is guranteed that the result IQ contained a child element
// (RFC 6120 ยง 8.2.3 6) because otherwhise we would have reached the END_TAG first.
{
// No Provider found for the IQ stanza, parse it to an UnparsedIQ instance
// so that the content of the IQ can be examined later on
iqPacket = new UnparsedIQ(elementName, namespace, parseElement(parser));
}
break;
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
// Decide what to do when an IQ packet was not understood
if (iqPacket == null) {
switch(type) {
case error:
// If an IQ packet wasn't created above, create an empty error IQ packet.
iqPacket = new ErrorIQ(error);
break;
case result:
iqPacket = new EmptyResultIQ();
break;
default:
break;
}
}
// Set basic values on the iq packet.
iqPacket.setStanzaId(id);
iqPacket.setTo(to);
iqPacket.setFrom(from);
iqPacket.setType(type);
iqPacket.setError(error);
return iqPacket;
}
Aggregations