Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/org/adblockplus/brazil/SSLConnectionHandler.java

Issue 8484110: ABP/Android proxy service (Closed)
Left Patch Set: Created Oct. 5, 2012, 9:28 a.m.
Right Patch Set: ABP/Android proxy service Created Nov. 12, 2012, 8:53 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 package org.adblockplus.brazil; 1 package org.adblockplus.brazil;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 import java.io.InputStream; 4 import java.io.InputStream;
5 import java.io.OutputStream; 5 import java.io.OutputStream;
6 import java.net.InetAddress; 6 import java.net.InetAddress;
7 import java.net.Socket; 7 import java.net.Socket;
8 import java.util.Properties;
9 8
10 import sunlabs.brazil.server.Handler;
11 import sunlabs.brazil.server.Request; 9 import sunlabs.brazil.server.Request;
12 import sunlabs.brazil.server.Server; 10 import sunlabs.brazil.server.Server;
13 import sunlabs.brazil.util.MatchString; 11 import sunlabs.brazil.util.MatchString;
14 import android.util.Log;
15 12
16 /** 13 /**
17 * <code>RequestHandler</code> implements a SSL tunnel. 14 * <code>RequestHandler</code> implements a SSL tunnel.
18 * 15 *
19 * The following configuration parameters are used to initialize this 16 * The following configuration parameters are used to initialize this
20 * <code>Handler</code>: 17 * <code>Handler</code>:
21 * <dl class=props> 18 * <dl class=props>
22 * 19 *
23 * <dt>prefix, suffix, glob, match 20 * <dt>prefix, suffix, glob, match
24 * <dd>Specify the URL that triggers this handler. (See {@link MatchString}). 21 * <dd>Specify the URL that triggers this handler. (See {@link MatchString}).
(...skipping 14 matching lines...) Expand all
39 * handler=https 36 * handler=https
40 * https.class=org.adblockplus.brazil.SSLConnectionHandler 37 * https.class=org.adblockplus.brazil.SSLConnectionHandler
41 * </pre> 38 * </pre>
42 * 39 *
43 * See the description under {@link sunlabs.brazil.server.Handler#respond 40 * See the description under {@link sunlabs.brazil.server.Handler#respond
44 * respond} for a more detailed explanation. 41 * respond} for a more detailed explanation.
45 * 42 *
46 * Original source by Jochen Luell, PAW (http://paw-project.sourceforge.net/) 43 * Original source by Jochen Luell, PAW (http://paw-project.sourceforge.net/)
47 */ 44 */
48 45
49 public class SSLConnectionHandler implements Handler 46 public class SSLConnectionHandler extends BaseRequestHandler
50 { 47 {
51 public static final String PROXY_HOST = "proxyHost";
52 public static final String PROXY_PORT = "proxyPort";
53 public static final String AUTH = "auth";
54
55 private String prefix;
56
57 private String proxyHost;
58 private int proxyPort = 80;
59 private String auth;
60
61 @Override
62 public boolean init(Server server, String prefix)
63 {
64 this.prefix = prefix;
65
66 Properties props = server.props;
67
68 proxyHost = props.getProperty(prefix + PROXY_HOST);
69
70 String s = props.getProperty(prefix + PROXY_PORT);
71 try
72 {
73 proxyPort = Integer.decode(s).intValue();
74 }
75 catch (Exception e)
76 {
77 }
78
79 auth = props.getProperty(prefix + AUTH);
80
81 return true;
82 }
83
84 @Override 48 @Override
85 public boolean respond(Request request) throws IOException 49 public boolean respond(Request request) throws IOException
86 { 50 {
87 if (!request.method.equals("CONNECT")) 51 if (!request.method.equals("CONNECT"))
88 return false; 52 return false;
89 53
90 request.log(Server.LOG_LOG, prefix, "SSL connection to " + reque st.url); 54 request.log(Server.LOG_LOG, prefix, "SSL connection to " + reque st.url);
91 55
92 String host = null; 56 String host = null;
93 int port = 0; 57 int port = 0;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 ConnectionHandler server = new ConnectionHandler(serverS ocket, request.sock); 109 ConnectionHandler server = new ConnectionHandler(serverS ocket, request.sock);
146 client.start(); 110 client.start();
147 server.start(); 111 server.start();
148 112
149 // Wait for connections to close 113 // Wait for connections to close
150 client.join(); 114 client.join();
151 server.join(); 115 server.join();
152 } 116 }
153 catch (InterruptedException e) 117 catch (InterruptedException e)
154 { 118 {
155 » » » Log.e(prefix, "Data exchange error", e); 119 » » request.log(Server.LOG_ERROR, prefix, "Data exchange error: " + e.getMessage());
156 } 120 }
157 121
158 // Close connection 122 // Close connection
159 serverSocket.close(); 123 serverSocket.close();
160 request.log(Server.LOG_LOG, prefix, "SSL connection closed"); 124 request.log(Server.LOG_LOG, prefix, "SSL connection closed");
161 125
162 return true; 126 return true;
163 } 127 }
164 128
165 private class ConnectionHandler extends Thread 129 private class ConnectionHandler extends Thread
(...skipping 21 matching lines...) Expand all
187 } 151 }
188 out.flush(); 152 out.flush();
189 } 153 }
190 catch (IOException e) 154 catch (IOException e)
191 { 155 {
192 e.printStackTrace(); 156 e.printStackTrace();
193 } 157 }
194 } 158 }
195 } 159 }
196 } 160 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld