Package org.jivesoftware.smackx.bytestreams.socks5.packet

Examples of org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream


public class BytestreamsProvider implements IQProvider {

    public IQ parseIQ(XmlPullParser parser) throws Exception {
        boolean done = false;

        Bytestream toReturn = new Bytestream();

        String id = parser.getAttributeValue("", "sid");
        String mode = parser.getAttributeValue("", "mode");

        // streamhost
        String JID = null;
        String host = null;
        String port = null;

        int eventType;
        String elementName;
        while (!done) {
            eventType = parser.next();
            elementName = parser.getName();
            if (eventType == XmlPullParser.START_TAG) {
                if (elementName.equals(Bytestream.StreamHost.ELEMENTNAME)) {
                    JID = parser.getAttributeValue("", "jid");
                    host = parser.getAttributeValue("", "host");
                    port = parser.getAttributeValue("", "port");
                }
                else if (elementName.equals(Bytestream.StreamHostUsed.ELEMENTNAME)) {
                    toReturn.setUsedHost(parser.getAttributeValue("", "jid"));
                }
                else if (elementName.equals(Bytestream.Activate.ELEMENTNAME)) {
                    toReturn.setToActivate(parser.getAttributeValue("", "jid"));
                }
            }
            else if (eventType == XmlPullParser.END_TAG) {
                if (elementName.equals("streamhost")) {
                    if (port == null) {
                        toReturn.addStreamHost(JID, host);
                    }
                    else {
                        toReturn.addStreamHost(JID, host, Integer.parseInt(port));
                    }
                    JID = null;
                    host = null;
                    port = null;
                }
                else if (elementName.equals("query")) {
                    done = true;
                }
            }
        }

        toReturn.setMode((Bytestream.Mode.fromName(mode)));
        toReturn.setSessionID(id);
        return toReturn;
    }
View Full Code Here


        }

        @Override
        public boolean accept(Packet packet) {
            if (super.accept(packet)) {
                Bytestream bytestream = (Bytestream) packet;

                // packet must by of type SET and contains the given session ID
                return this.sessionID.equals(bytestream.getSessionID())
                                && IQ.Type.SET.equals(bytestream.getType());
            }
            return false;
        }
View Full Code Here

            // add transfer digest to local proxy to make transfer valid
            socks5Proxy.addTransfer(digest);

            // create initiation packet
            Bytestream initiation = createBytestreamInitiation(sessionID, targetJID, streamHosts);

            // send initiation packet
            Packet response = SyncPacketSend.getReply(this.connection, initiation,
                            getTargetResponseTimeout());

            // extract used stream host from response
            StreamHostUsed streamHostUsed = ((Bytestream) response).getUsedHost();
            StreamHost usedStreamHost = initiation.getStreamHost(streamHostUsed.getJID());

            if (usedStreamHost == null) {
                throw new XMPPException("Remote user responded with unknown host");
            }
View Full Code Here

            streamHosts.addAll(localProxies);
        }

        // query SOCKS5 proxies for network settings
        for (String proxy : proxies) {
            Bytestream streamHostRequest = createStreamHostRequest(proxy);
            try {
                Bytestream response = (Bytestream) SyncPacketSend.getReply(this.connection,
                                streamHostRequest);
                streamHosts.addAll(response.getStreamHosts());
            }
            catch (XMPPException e) {
                // blacklist errornous proxies
                this.proxyBlacklist.add(proxy);
            }
View Full Code Here

     *
     * @param proxy the proxy to query
     * @return IQ packet to query a SOCKS5 proxy its network settings
     */
    private Bytestream createStreamHostRequest(String proxy) {
        Bytestream request = new Bytestream();
        request.setType(IQ.Type.GET);
        request.setTo(proxy);
        return request;
    }
View Full Code Here

     * @param streamHosts a list of SOCKS5 proxies the target should connect to
     * @return a SOCKS5 Bytestream initialization request packet
     */
    private Bytestream createBytestreamInitiation(String sessionID, String targetJID,
                    List<StreamHost> streamHosts) {
        Bytestream initiation = new Bytestream(sessionID);

        // add all stream hosts
        for (StreamHost streamHost : streamHosts) {
            initiation.addStreamHost(streamHost);
        }

        initiation.setType(IQ.Type.SET);
        initiation.setTo(targetJID);

        return initiation;
    }
View Full Code Here

        // start thread to connect to SOCKS5 proxy
        Thread serverThread = new Thread() {

            @Override
            public void run() {
                StreamHost streamHost = new StreamHost(proxyJID, serverAddress);
                streamHost.setPort(serverPort);

                Socks5Client socks5Client = new Socks5Client(streamHost, digest);

                try {
View Full Code Here

        // start thread to connect to SOCKS5 proxy
        Thread serverThread = new Thread() {

            @Override
            public void run() {
                StreamHost streamHost = new StreamHost(proxyJID, serverAddress);
                streamHost.setPort(serverPort);

                Socks5Client socks5Client = new Socks5Client(streamHost, digest);
                try {
                    socks5Client.getSocket(10000);
View Full Code Here

        // start thread to connect to SOCKS5 proxy
        Thread serverThread = new Thread() {

            @Override
            public void run() {
                StreamHost streamHost = new StreamHost(proxyJID, serverAddress);
                streamHost.setPort(serverPort);

                Socks5Client socks5Client = new Socks5Client(streamHost, digest);
                try {
                    socks5Client.getSocket(10000);
View Full Code Here

        // start thread to connect to SOCKS5 proxy
        Thread serverThread = new Thread() {

            @Override
            public void run() {
                StreamHost streamHost = new StreamHost(proxyJID, serverAddress);
                streamHost.setPort(serverPort);

                Socks5Client socks5Client = new Socks5Client(streamHost, digest);

                try {
                    Socket socket = socks5Client.getSocket(10000);
View Full Code Here

TOP

Related Classes of org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.