// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) braces deadcode fieldsfirst 
// Source File Name:   TcpTunnelGui.java
// Class Version:      45.3

package org.apache.soap.util.net;

import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;

// Referenced classes of package org.apache.soap.util.net:
//            Relay

// flag ACC_SUPER is set
public class TcpTunnelGui extends Frame
{
    // Constants:          209
    // Interfaces:         0
    // Fields:             8
    // Methods:            8
    // Class Attributes:   2


    int listenPort;
    String tunnelHost;
    int tunnelPort;
    TextArea listenText;
    TextArea tunnelText;
    Label status;
    Relay inRelay;
    Relay outRelay;

    // Decompiling method: <init>  Signature: (ILjava/lang/String;I)V
    // Max stack: 7, #locals: 10, #params: 4
    // Code length: 408 bytes, Code offset: 2482
    // Line Number Table found: 39 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/util/net/TcpTunnelGui; At 0 408 Range 0 407 Init 0 fixed
    // Parameter  1 added: Name i Type I At 0 408 Range 0 407 Init 0
    // Parameter  2 added: Name s Type Ljava/lang/String; At 0 408 Range 0 407 Init 0
    // Parameter  3 added: Name j Type I At 0 408 Range 0 407 Init 0
    // RetValue  10 added: Name <returnValue> Type V At 0 408 Range 0 407 Init 0 fixed
    // LocalVar   4 added: Name panel Type Ljava/awt/Panel; At 75 98 Range 75 172 Init 75
    // LocalVar   5 added: Name label Type Ljava/awt/Label; At 118 245 Range 118 362 Init 118
    // LocalVar   6 added: Name label1 Type Ljava/awt/Label; At 162 224 Range 162 385 Init 162
    // LocalVar   4 added: Name panel1 Type Ljava/awt/Panel; At 184 57 Range 184 240 Init 184
    // LocalVar   7 added: Name panel2 Type Ljava/awt/Panel; At 252 90 Range 252 341 Init 252
    // LocalVar   4 added: Name panel3 Type Ljava/awt/Panel; At 273 40 Range 273 312 Init 273
    // LocalVar   8 added: Name button Type Ljava/awt/Button; At 284 19 Range 284 302 Init 284
    // LocalVar   9 added: Name font Type Ljava/awt/Font; At 359 39 Range 359 397 Init 359
    // LocalVar   4 name panel1(Ljava/awt/Panel;) merged out into panel(Ljava/awt/Panel;)
    // LocalVar   4 name panel3(Ljava/awt/Panel;) merged out into panel(Ljava/awt/Panel;)
    public TcpTunnelGui(int i, String s, int j)
    {
        super();
        listenPort = i;
        tunnelHost = s;
        tunnelPort = j;
        addWindowListener(new WindowAdapter() {
            // Constants:          23
            // Interfaces:         0
            // Fields:             0
            // Methods:            2
            // Class Attributes:   2

            // Parameter  0 added: Name this Type Lorg/apache/soap/util/net/TcpTunnelGui$1; At 0 5 Range 0 4 Init 0 fixed
            // RetValue   1 added: Name <returnValue> Type V At 0 5 Range 0 4 Init 0 fixed

            // Decompiling method: windowClosing  Signature: (Ljava/awt/event/WindowEvent;)V
            // Max stack: 1, #locals: 2, #params: 2
            // Code length: 5 bytes, Code offset: 378
            // Line Number Table found: 2 entries
            // Parameter  0 added: Name this Type Lorg/apache/soap/util/net/TcpTunnelGui$1; At 0 5 Range 0 4 Init 0 fixed
            // Parameter  1 added: Name windowevent Type Ljava/awt/event/WindowEvent; At 0 5 Range 0 4 Init 0
            // RetValue   2 added: Name <returnValue> Type V At 0 5 Range 0 4 Init 0 fixed
            public void windowClosing(WindowEvent windowevent)
            {
                System.exit(0);
                return;
            }

            // Decompiling method: <init>  Signature: ()V
            // Max stack: 1, #locals: 1, #params: 1
            // Code length: 5 bytes, Code offset: 329
            // Line Number Table found: 1 entries
            
            {
                super();
                return;
            }
        });
        setTitle("TCP Tunnel/Monitor: Tunneling localhost:" + i + " to " + s + ":" + j);
        Panel panel = new Panel();
        panel.setLayout(new BorderLayout());
        Label label;
        panel.add("West", label = new Label("From localhost:" + i, 1));
        Label label1;
        panel.add("East", label1 = new Label("From " + s + ":" + j, 1));
        add("North", panel);
        panel = new Panel();
        panel.setLayout(new GridLayout(-1, 2));
        panel.add(listenText = new TextArea());
        panel.add(tunnelText = new TextArea());
        add("Center", panel);
        Panel panel1 = new Panel();
        panel1.setLayout(new BorderLayout());
        panel = new Panel();
        Button button = new Button("Clear");
        button.addActionListener(new ActionListener() {
            // Constants:          41
            // Interfaces:         1
            // Fields:             1
            // Methods:            2
            // Class Attributes:   2


            /* private final TcpTunnelGui this$0; */ /* synthetic field */
            // Parameter  0 added: Name this Type Lorg/apache/soap/util/net/TcpTunnelGui$2; At 0 10 Range 0 9 Init 0 fixed
            // Parameter  1 added: Name tcptunnelgui Type Lorg/apache/soap/util/net/TcpTunnelGui; At 0 10 Range 0 9 Init 0
            // RetValue   2 added: Name <returnValue> Type V At 0 10 Range 0 9 Init 0 fixed

            // Decompiling method: actionPerformed  Signature: (Ljava/awt/event/ActionEvent;)V
            // Max stack: 2, #locals: 2, #params: 2
            // Code length: 25 bytes, Code offset: 673
            // Line Number Table found: 3 entries
            // Parameter  0 added: Name this Type Lorg/apache/soap/util/net/TcpTunnelGui$2; At 0 25 Range 0 24 Init 0 fixed
            // Parameter  1 added: Name actionevent Type Ljava/awt/event/ActionEvent; At 0 25 Range 0 24 Init 0
            // RetValue   2 added: Name <returnValue> Type V At 0 25 Range 0 24 Init 0 fixed
            public void actionPerformed(ActionEvent actionevent)
            {
                listenText.setText("");
                tunnelText.setText("");
                return;
            }

            // Decompiling method: <init>  Signature: (Lorg/apache/soap/util/net/TcpTunnelGui;)V
            // Max stack: 2, #locals: 2, #params: 2
            // Code length: 10 bytes, Code offset: 619
            // Line Number Table found: 1 entries
            
            {
                super();
                /* this$0 = tcptunnelgui; */
                return;
            }
        });
        panel.add(button);
        panel1.add("Center", panel);
        panel1.add("South", status = new Label());
        add("South", panel1);
        pack();
        show();
        Font font = label.getFont();
        label.setFont(new Font(font.getName(), 1, font.getSize()));
        label1.setFont(new Font(font.getName(), 1, font.getSize()));
        return;
    }

    // Decompiling method: getListenPort  Signature: ()I
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3080
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/util/net/TcpTunnelGui; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type I At 0 5 Range 0 4 Init 0 fixed
    public int getListenPort()
    {
        return listenPort;
    }

    // Decompiling method: getListenText  Signature: ()Ljava/awt/TextArea;
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3123
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/util/net/TcpTunnelGui; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type Ljava/awt/TextArea; At 0 5 Range 0 4 Init 0 fixed
    public TextArea getListenText()
    {
        return listenText;
    }

    // Decompiling method: getStatus  Signature: ()Ljava/awt/Label;
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3166
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/util/net/TcpTunnelGui; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type Ljava/awt/Label; At 0 5 Range 0 4 Init 0 fixed
    public Label getStatus()
    {
        return status;
    }

    // Decompiling method: getTunnelHost  Signature: ()Ljava/lang/String;
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3209
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/util/net/TcpTunnelGui; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type Ljava/lang/String; At 0 5 Range 0 4 Init 0 fixed
    public String getTunnelHost()
    {
        return tunnelHost;
    }

    // Decompiling method: getTunnelPort  Signature: ()I
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3252
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/util/net/TcpTunnelGui; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type I At 0 5 Range 0 4 Init 0 fixed
    public int getTunnelPort()
    {
        return tunnelPort;
    }

    // Decompiling method: getTunnelText  Signature: ()Ljava/awt/TextArea;
    // Max stack: 1, #locals: 1, #params: 1
    // Code length: 5 bytes, Code offset: 3295
    // Line Number Table found: 1 entries
    // Parameter  0 added: Name this Type Lorg/apache/soap/util/net/TcpTunnelGui; At 0 5 Range 0 4 Init 0 fixed
    // RetValue   1 added: Name <returnValue> Type Ljava/awt/TextArea; At 0 5 Range 0 4 Init 0 fixed
    public TextArea getTunnelText()
    {
        return tunnelText;
    }

    // Decompiling method: main  Signature: ([Ljava/lang/String;)V
    // Max stack: 5, #locals: 6, #params: 1
    // Code length: 65 bytes, Code offset: 3338
    // Line Number Table found: 11 entries
    // Parameter  0 added: Name args Type [Ljava/lang/String; At 0 65 Range 0 64 Init 0
    // RetValue   6 added: Name <returnValue> Type V At 0 65 Range 0 64 Init 0 fixed
    // LocalVar   1 added: Name i Type I At 24 17 Range 24 40 Init 24
    // LocalVar   2 added: Name s Type Ljava/lang/String; At 28 14 Range 28 41 Init 28
    // LocalVar   3 added: Name j Type I At 35 8 Range 35 42 Init 35
    // LocalVar   4 added: Name tcptunnelgui Type Lorg/apache/soap/util/net/TcpTunnelGui; At 46 8 Range 46 53 Init 46
    // LocalVar   5 added: Name thread Type Ljava.lang.Thread; At 57 4 Range 57 60 Init 57
    public static void main(String args[])
        throws IOException
    {
        if(args.length != 3)
        {
            System.err.println("Usage: java TcpTunnelGui listenport tunnelhost tunnelport");
            System.exit(1);
        }
        int i = Integer.parseInt(args[0]);
        String s = args[1];
        int j = Integer.parseInt(args[2]);
        final TcpTunnelGui ttg = new TcpTunnelGui(i, s, j);
        Thread thread = new Thread() {
            // Constants:          122
            // Interfaces:         0
            // Fields:             1
            // Methods:            2
            // Class Attributes:   2


            /* private final TcpTunnelGui val$ttg; */ /* synthetic field */
            // Parameter  0 added: Name this Type Lorg/apache/soap/util/net/TcpTunnelGui$3; At 0 10 Range 0 9 Init 0 fixed
            // Parameter  1 added: Name tcptunnelgui Type Lorg/apache/soap/util/net/TcpTunnelGui; At 0 10 Range 0 9 Init 0
            // RetValue   2 added: Name <returnValue> Type V At 0 10 Range 0 9 Init 0 fixed

            // Decompiling method: run  Signature: ()V
            // Max stack: 5, #locals: 5, #params: 1
            // Code length: 246 bytes, Code offset: 1562
            // Exception table: 2 entries
            //           start  10 end 25 handler 28 type Exception
            //           start  40 end 212 handler 215 type Exception
            // Line Number Table found: 36 entries
            // Parameter  0 added: Name this Type Lorg/apache/soap/util/net/TcpTunnelGui$3; At 0 246 Range 0 245 Init 0 fixed
            // RetValue   5 added: Name <returnValue> Type V At 0 246 Range 0 245 Init 0 fixed
            // LocalVar   1 added: Name obj Type A At 1 71 Range 1 71 Init 1
            // LocalVar   2 added: Name label Type Ljava/awt/Label; At 9 208 Range 9 216 Init 9
            // LocalVar   1 chged: Name serversocket Oname obj Type Ljava/net/ServerSocket; At 24 48 Range 1 71 Init 1
            // LocalVar   3 added: Name socket Type Ljava/net/Socket; At 75 121 Range 75 195 Init 75
            // LocalVar   4 added: Name socket1 Type Ljava/net/Socket; At 97 95 Range 97 191 Init 97
            // LocalVar   3 added: Name exception Type Ljava/lang/Exception; At 28 2 Range 28 29 Init 28
            // LocalVar   3 added: Name exception1 Type Ljava/lang/Exception; At 215 25 Range 215 239 Init 215
            public void run()
            {
                ServerSocket serversocket = null;
                Label label = ttg.getStatus();
                try
                {
                    serversocket = new ServerSocket(ttg.getListenPort());
                }
                catch(Exception exception)
                {
                    exception.printStackTrace();
                    System.exit(1);
                }
                do
                {
                    try
                    {
                        do
                        {
                            label.setText("Listening for connections on port " + ttg.getListenPort() + " ...");
                            Socket socket = serversocket.accept();
                            Socket socket1 = new Socket(ttg.getTunnelHost(), ttg.getTunnelPort());
                            label.setText("Tunnelling port " + ttg.getListenPort() + " to port " + ttg.getTunnelPort() + " on host " + ttg.getTunnelHost() + " ...");
                            (new Relay(socket.getInputStream(), socket1.getOutputStream(), ttg.getListenText())).start();
                            (new Relay(socket1.getInputStream(), socket.getOutputStream(), ttg.getTunnelText())).start();
                        } while(true);
                        /* return; */
                    }
                    catch(Exception exception1)
                    {
                        label.setText("Ouch! [See console for details]: " + exception1.getMessage());
                        exception1.printStackTrace();
                    }
                } while(true);
            }

            // Decompiling method: <init>  Signature: (Lorg/apache/soap/util/net/TcpTunnelGui;)V
            // Max stack: 2, #locals: 2, #params: 2
            // Code length: 10 bytes, Code offset: 1508
            // Line Number Table found: 1 entries
            
            {
                super();
                /* ttg = tcptunnelgui; */
                return;
            }
        };
        thread.start();
        return;
    }
}
