Home | History | Annotate | Download | only in java-applet
      1 diff -ru vnc_javasrc/OptionsFrame.java proxy_vnc_javasrc/OptionsFrame.java
      2 --- vnc_javasrc/OptionsFrame.java	Fri Jul  5 08:17:23 2002
      3 +++ proxy_vnc_javasrc/OptionsFrame.java	Thu Aug 22 23:24:44 2002
      4 @@ -70,6 +70,12 @@
      5  
      6    Label[] labels = new Label[names.length];
      7    Choice[] choices = new Choice[names.length];
      8 +
      9 +  Label proxyHostLabel;
     10 +  TextField proxyHostEdit;
     11 +  Label proxyPortLabel;
     12 +  TextField proxyPortEdit;
     13 +  
     14    Button closeButton;
     15    VncViewer viewer;
     16  
     17 @@ -93,6 +99,9 @@
     18    boolean shareDesktop;
     19    boolean viewOnly;
     20  
     21 +  String proxyHost;
     22 +  int proxyPort;
     23 +
     24    //
     25    // Constructor.  Set up the labels and choices from the names and values
     26    // arrays.
     27 @@ -126,6 +135,32 @@
     28        }
     29      }
     30  
     31 +    // TODO: find a way to set these to defaults from browser
     32 +    proxyPort = viewer.readIntParameter("Use Proxy Port", -1);
     33 +    if(proxyPort>-1) {
     34 +      proxyHost = viewer.readParameter("Use Proxy Host", false);
     35 +      if(proxyHost == null)
     36 +	proxyHost = viewer.host;
     37 +
     38 +      proxyHostLabel = new Label("Proxy Host");
     39 +      gbc.gridwidth = 1;
     40 +      gridbag.setConstraints(proxyHostLabel,gbc);
     41 +      add(proxyHostLabel);
     42 +      proxyHostEdit = new TextField();
     43 +      gbc.gridwidth = GridBagConstraints.REMAINDER;
     44 +      gridbag.setConstraints(proxyHostEdit,gbc);
     45 +      add(proxyHostEdit);
     46 +    
     47 +      proxyPortLabel = new Label("Proxy Port");
     48 +      gbc.gridwidth = 1;
     49 +      gridbag.setConstraints(proxyPortLabel,gbc);
     50 +      add(proxyPortLabel);
     51 +      proxyPortEdit = new TextField();
     52 +      gbc.gridwidth = GridBagConstraints.REMAINDER;
     53 +      gridbag.setConstraints(proxyPortEdit,gbc);
     54 +      add(proxyPortEdit);
     55 +    }
     56 +    
     57      closeButton = new Button("Close");
     58      gbc.gridwidth = GridBagConstraints.REMAINDER;
     59      gridbag.setConstraints(closeButton, gbc);
     60 @@ -161,6 +196,11 @@
     61        }
     62      }
     63  
     64 +    if(proxyPort>-1) {
     65 +      proxyPortEdit.setText(Integer.toString(proxyPort));
     66 +      proxyHostEdit.setText(proxyHost);
     67 +    }
     68 +
     69      // Make the booleans and encodings array correspond to the state of the GUI
     70  
     71      setEncodings();
     72 @@ -361,8 +401,12 @@
     73    //
     74  
     75    public void actionPerformed(ActionEvent evt) {
     76 -    if (evt.getSource() == closeButton)
     77 +    if (evt.getSource() == closeButton) {
     78        setVisible(false);
     79 +      proxyHost = proxyHostEdit.getText();
     80 +      proxyPort = Integer.parseInt(proxyPortEdit.getText());
     81 +      System.err.println("proxy is " + proxyHost + ":" + proxyPort);
     82 +    }
     83    }
     84  
     85    //
     86 diff -ru vnc_javasrc/RfbProto.java proxy_vnc_javasrc/RfbProto.java
     87 --- vnc_javasrc/RfbProto.java	Sun Aug  4 18:39:35 2002
     88 +++ proxy_vnc_javasrc/RfbProto.java	Thu Aug 22 22:53:53 2002
     89 @@ -119,12 +119,51 @@
     90      viewer = v;
     91      host = h;
     92      port = p;
     93 -    sock = new Socket(host, port);
     94 +    if(viewer.options.proxyPort>-1)
     95 +      sock = new Socket(viewer.options.proxyHost, viewer.options.proxyPort);
     96 +    else
     97 +      sock = new Socket(host, port);
     98      is = new DataInputStream(new BufferedInputStream(sock.getInputStream(),
     99  						     16384));
    100      os = sock.getOutputStream();
    101 +    if(viewer.options.proxyPort>-1)
    102 +      negotiateProxy(host,port);
    103    }
    104  
    105 +  // this is inefficient as hell, but only used once per connection
    106 +  String readLine() {
    107 +    byte[] ba = new byte[1];
    108 +    String s = new String("");
    109 +
    110 +    ba[0]=0;
    111 +    try {
    112 +      while(ba[0] != 0xa) {
    113 +	ba[0] = (byte)is.readUnsignedByte();
    114 +	s += new String(ba);
    115 +      }
    116 +    } catch(Exception e) {
    117 +      e.printStackTrace();
    118 +    }
    119 +    return s;
    120 +  }
    121 +
    122 +  void negotiateProxy(String realHost,int realPort) throws IOException {
    123 +    String line;
    124 +
    125 +    // this would be the correct way, but we want to trick strict proxies.
    126 +    // line = "CONNECT " + realHost + ":" + realPort + " HTTP/1.1\r\nHost: " + realHost + ":" + realPort + "\r\n\r\n";
    127 +    line = "GET " + realHost + ":" + realPort + "/proxied.connection HTTP/1.0\r\nPragma: No-Cache\r\nProxy-Connection: Keep-Alive\r\n\r\n";
    128 +    os.write(line.getBytes());
    129 +
    130 +    line = readLine();
    131 +    System.err.println("Proxy said: " + line);
    132 +    if(!(line.substring(0,7)+line.substring(8,12)).equalsIgnoreCase("HTTP/1. 200")) {
    133 +      IOException e = new IOException(line);
    134 +      throw e;
    135 +    }
    136 +    while(!line.equals("\r\n") && !line.equals("\n"))
    137 +      line = readLine();
    138 +  }    
    139  
    140    void close() {
    141      try {
    142