Search in sources :

Example 1 with EmptyResultIQ

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();
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) EmptyResultIQ(org.jivesoftware.smack.packet.EmptyResultIQ) ErrorIQ(org.jivesoftware.smack.packet.ErrorIQ) IQ(org.jivesoftware.smack.packet.IQ) EmptyResultIQ(org.jivesoftware.smack.packet.EmptyResultIQ) Bytestream(org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream) StreamHost(org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost) Socket(java.net.Socket) Test(org.junit.Test)

Example 2 with EmptyResultIQ

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;
}
Also used : EmptyResultIQ(org.jivesoftware.smack.packet.EmptyResultIQ) IQ(org.jivesoftware.smack.packet.IQ) EmptyResultIQ(org.jivesoftware.smack.packet.EmptyResultIQ)

Example 3 with EmptyResultIQ

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;
}
Also used : ErrorIQ(org.jivesoftware.smack.packet.ErrorIQ) EmptyResultIQ(org.jivesoftware.smack.packet.EmptyResultIQ) IQ(org.jivesoftware.smack.packet.IQ) EmptyResultIQ(org.jivesoftware.smack.packet.EmptyResultIQ)

Example 4 with EmptyResultIQ

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;
}
Also used : ErrorIQ(org.jivesoftware.smack.packet.ErrorIQ) Jid(org.jxmpp.jid.Jid) UnparsedIQ(org.jivesoftware.smack.packet.UnparsedIQ) EmptyResultIQ(org.jivesoftware.smack.packet.EmptyResultIQ) ErrorIQ(org.jivesoftware.smack.packet.ErrorIQ) UnparsedIQ(org.jivesoftware.smack.packet.UnparsedIQ) IQ(org.jivesoftware.smack.packet.IQ) EmptyResultIQ(org.jivesoftware.smack.packet.EmptyResultIQ) XMPPError(org.jivesoftware.smack.packet.XMPPError) IQProvider(org.jivesoftware.smack.provider.IQProvider)

Aggregations

EmptyResultIQ (org.jivesoftware.smack.packet.EmptyResultIQ)4 IQ (org.jivesoftware.smack.packet.IQ)4 ErrorIQ (org.jivesoftware.smack.packet.ErrorIQ)3 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Socket (java.net.Socket)1 UnparsedIQ (org.jivesoftware.smack.packet.UnparsedIQ)1 XMPPError (org.jivesoftware.smack.packet.XMPPError)1 IQProvider (org.jivesoftware.smack.provider.IQProvider)1 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)1 StreamHost (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost)1 Test (org.junit.Test)1 Jid (org.jxmpp.jid.Jid)1