Fossil SCM

Update the proxy handler so that it supports basic authorization.

drh 2009-09-12 21:53 trunk
Commit 9e274a2e7bc97635edb085425cd8548a8b72df45
3 files changed +3 +1 +35 -13
+3
--- src/http.c
+++ src/http.c
@@ -90,10 +90,13 @@
9090
zSep = "";
9191
}else{
9292
zSep = "/";
9393
}
9494
blob_appendf(pHdr, "POST %s%sxfer HTTP/1.1\r\n", g.urlPath, zSep);
95
+ if( g.urlProxyAuth ){
96
+ blob_appendf(pHdr, "Proxy-Authorization: %s\n", g.urlProxyAuth);
97
+ }
9598
blob_appendf(pHdr, "Host: %s\r\n", g.urlHostname);
9699
blob_appendf(pHdr, "User-Agent: Fossil/" MANIFEST_VERSION "\r\n");
97100
if( g.fHttpTrace ){
98101
blob_appendf(pHdr, "Content-Type: application/x-fossil-debug\r\n");
99102
}else{
100103
--- src/http.c
+++ src/http.c
@@ -90,10 +90,13 @@
90 zSep = "";
91 }else{
92 zSep = "/";
93 }
94 blob_appendf(pHdr, "POST %s%sxfer HTTP/1.1\r\n", g.urlPath, zSep);
 
 
 
95 blob_appendf(pHdr, "Host: %s\r\n", g.urlHostname);
96 blob_appendf(pHdr, "User-Agent: Fossil/" MANIFEST_VERSION "\r\n");
97 if( g.fHttpTrace ){
98 blob_appendf(pHdr, "Content-Type: application/x-fossil-debug\r\n");
99 }else{
100
--- src/http.c
+++ src/http.c
@@ -90,10 +90,13 @@
90 zSep = "";
91 }else{
92 zSep = "/";
93 }
94 blob_appendf(pHdr, "POST %s%sxfer HTTP/1.1\r\n", g.urlPath, zSep);
95 if( g.urlProxyAuth ){
96 blob_appendf(pHdr, "Proxy-Authorization: %s\n", g.urlProxyAuth);
97 }
98 blob_appendf(pHdr, "Host: %s\r\n", g.urlHostname);
99 blob_appendf(pHdr, "User-Agent: Fossil/" MANIFEST_VERSION "\r\n");
100 if( g.fHttpTrace ){
101 blob_appendf(pHdr, "Content-Type: application/x-fossil-debug\r\n");
102 }else{
103
+1
--- src/main.c
+++ src/main.c
@@ -98,10 +98,11 @@
9898
int urlDfltPort; /* The default port for the given protocol */
9999
char *urlPath; /* Pathname for http: */
100100
char *urlUser; /* User id for http: */
101101
char *urlPasswd; /* Password for http: */
102102
char *urlCanonical; /* Canonical representation of the URL */
103
+ char *urlProxyAuth; /* Proxy-Authorizer: string */
103104
104105
const char *zLogin; /* Login name. "" if not logged in. */
105106
int noPswd; /* Logged in without password (on 127.0.0.1) */
106107
int userUid; /* Integer user id */
107108
108109
--- src/main.c
+++ src/main.c
@@ -98,10 +98,11 @@
98 int urlDfltPort; /* The default port for the given protocol */
99 char *urlPath; /* Pathname for http: */
100 char *urlUser; /* User id for http: */
101 char *urlPasswd; /* Password for http: */
102 char *urlCanonical; /* Canonical representation of the URL */
 
103
104 const char *zLogin; /* Login name. "" if not logged in. */
105 int noPswd; /* Logged in without password (on 127.0.0.1) */
106 int userUid; /* Integer user id */
107
108
--- src/main.c
+++ src/main.c
@@ -98,10 +98,11 @@
98 int urlDfltPort; /* The default port for the given protocol */
99 char *urlPath; /* Pathname for http: */
100 char *urlUser; /* User id for http: */
101 char *urlPasswd; /* Password for http: */
102 char *urlCanonical; /* Canonical representation of the URL */
103 char *urlProxyAuth; /* Proxy-Authorizer: string */
104
105 const char *zLogin; /* Login name. "" if not logged in. */
106 int noPswd; /* Logged in without password (on 127.0.0.1) */
107 int userUid; /* Integer user id */
108
109
+35 -13
--- src/url.c
+++ src/url.c
@@ -27,17 +27,21 @@
2727
#include "url.h"
2828
2929
/*
3030
** Parse the given URL. Populate variables in the global "g" structure.
3131
**
32
-** g.urlIsFile True if this is a file URL
33
-** g.urlName Hostname for HTTP:. Filename for FILE:
34
-** g.urlPort Port name for HTTP.
35
-** g.urlPath Path name for HTTP.
32
+** g.urlIsFile True if FILE:
33
+** g.urlIsHttps True if HTTPS:
34
+** g.urlProtocol "http" or "https" or "file"
35
+** g.urlName Hostname for HTTP: or HTTPS:. Filename for FILE:
36
+** g.urlPort TCP port number for HTTP or HTTPS.
37
+** g.urlDfltPort Default TCP port number (80 or 443).
38
+** g.urlPath Path name for HTTP or HTTPS.
3639
** g.urlUser Userid.
3740
** g.urlPasswd Password.
38
-** g.urlCanonical The URL in canonical form
41
+** g.urlHostname HOST:PORT or just HOST if port is the default.
42
+** g.urlCanonical The URL in canonical form, omitting userid/password
3943
**
4044
** HTTP url format is:
4145
**
4246
** http://userid:password@host:port/path?query#fragment
4347
**
@@ -159,32 +163,38 @@
159163
}
160164
}
161165
}
162166
163167
/*
164
-** Proxy specified on the command-line.
168
+** Proxy specified on the command-line using the --proxy option.
169
+** If there is no --proxy option on the command-line then this
170
+** variable holds a NULL pointer.
165171
*/
166172
static const char *zProxyOpt = 0;
167173
168174
/*
169
-** Extra any proxy options from the command-line.
175
+** Extract any proxy options from the command-line.
170176
**
171177
** --proxy URL|off
172178
**
179
+** This also happens to be a convenient function to use to look for
180
+** the --nosync option that will temporarily disable the "autosync"
181
+** feature.
173182
*/
174183
void url_proxy_options(void){
175184
zProxyOpt = find_option("proxy", 0, 1);
176185
if( find_option("nosync",0,0) ) g.fNoSync = 1;
177186
}
178187
179188
/*
180
-** If the "proxy" setting is defined, then change the URL to refer
181
-** to the proxy server.
189
+** If the "proxy" setting is defined, then change the URL settings
190
+** (initialized by a prior call to url_parse()) so that the HTTP
191
+** header will be appropriate for the proxy and so that the TCP/IP
192
+** connection will be opened to the proxy rather than to the server.
182193
**
183
-** If the protocol is "https://" then start stunnel to handle the SSL
184
-** and make the url setting refer to stunnel rather than the original
185
-** destination.
194
+** If zMsg is not NULL and a proxy is used, then print zMsg followed
195
+** by the canonical name of the proxy (with userid and password suppressed).
186196
*/
187197
void url_enable_proxy(const char *zMsg){
188198
const char *zProxy;
189199
zProxy = zProxyOpt;
190200
if( zProxy==0 ){
@@ -194,14 +204,26 @@
194204
}
195205
}
196206
if( zProxy && zProxy[0] && !is_false(zProxy) ){
197207
char *zOriginalUrl = g.urlCanonical;
198208
char *zOriginalHost = g.urlHostname;
199
- if( zMsg ) printf("%s%s\n", zMsg, zProxy);
209
+ char *zOriginalUser = g.urlUser;
210
+ char *zOriginalPasswd = g.urlPasswd;
211
+ g.urlUser = 0;
212
+ g.urlPasswd = "";
200213
url_parse(zProxy);
214
+ if( zMsg ) printf("%s%s\n", zMsg, g.urlCanonical);
201215
g.urlPath = zOriginalUrl;
202216
g.urlHostname = zOriginalHost;
217
+ if( g.urlUser ){
218
+ char *zCredentials1 = mprintf("%s:%s", g.urlUser, g.urlPasswd);
219
+ char *zCredentials2 = encode64(zCredentials1, -1);
220
+ g.urlProxyAuth = mprintf("Basic %z", zCredentials2);
221
+ free(zCredentials1);
222
+ }
223
+ g.urlUser = zOriginalUser;
224
+ g.urlPasswd = zOriginalPasswd;
203225
}
204226
}
205227
206228
#if INTERFACE
207229
/*
208230
--- src/url.c
+++ src/url.c
@@ -27,17 +27,21 @@
27 #include "url.h"
28
29 /*
30 ** Parse the given URL. Populate variables in the global "g" structure.
31 **
32 ** g.urlIsFile True if this is a file URL
33 ** g.urlName Hostname for HTTP:. Filename for FILE:
34 ** g.urlPort Port name for HTTP.
35 ** g.urlPath Path name for HTTP.
 
 
 
36 ** g.urlUser Userid.
37 ** g.urlPasswd Password.
38 ** g.urlCanonical The URL in canonical form
 
39 **
40 ** HTTP url format is:
41 **
42 ** http://userid:password@host:port/path?query#fragment
43 **
@@ -159,32 +163,38 @@
159 }
160 }
161 }
162
163 /*
164 ** Proxy specified on the command-line.
 
 
165 */
166 static const char *zProxyOpt = 0;
167
168 /*
169 ** Extra any proxy options from the command-line.
170 **
171 ** --proxy URL|off
172 **
 
 
 
173 */
174 void url_proxy_options(void){
175 zProxyOpt = find_option("proxy", 0, 1);
176 if( find_option("nosync",0,0) ) g.fNoSync = 1;
177 }
178
179 /*
180 ** If the "proxy" setting is defined, then change the URL to refer
181 ** to the proxy server.
 
 
182 **
183 ** If the protocol is "https://" then start stunnel to handle the SSL
184 ** and make the url setting refer to stunnel rather than the original
185 ** destination.
186 */
187 void url_enable_proxy(const char *zMsg){
188 const char *zProxy;
189 zProxy = zProxyOpt;
190 if( zProxy==0 ){
@@ -194,14 +204,26 @@
194 }
195 }
196 if( zProxy && zProxy[0] && !is_false(zProxy) ){
197 char *zOriginalUrl = g.urlCanonical;
198 char *zOriginalHost = g.urlHostname;
199 if( zMsg ) printf("%s%s\n", zMsg, zProxy);
 
 
 
200 url_parse(zProxy);
 
201 g.urlPath = zOriginalUrl;
202 g.urlHostname = zOriginalHost;
 
 
 
 
 
 
 
 
203 }
204 }
205
206 #if INTERFACE
207 /*
208
--- src/url.c
+++ src/url.c
@@ -27,17 +27,21 @@
27 #include "url.h"
28
29 /*
30 ** Parse the given URL. Populate variables in the global "g" structure.
31 **
32 ** g.urlIsFile True if FILE:
33 ** g.urlIsHttps True if HTTPS:
34 ** g.urlProtocol "http" or "https" or "file"
35 ** g.urlName Hostname for HTTP: or HTTPS:. Filename for FILE:
36 ** g.urlPort TCP port number for HTTP or HTTPS.
37 ** g.urlDfltPort Default TCP port number (80 or 443).
38 ** g.urlPath Path name for HTTP or HTTPS.
39 ** g.urlUser Userid.
40 ** g.urlPasswd Password.
41 ** g.urlHostname HOST:PORT or just HOST if port is the default.
42 ** g.urlCanonical The URL in canonical form, omitting userid/password
43 **
44 ** HTTP url format is:
45 **
46 ** http://userid:password@host:port/path?query#fragment
47 **
@@ -159,32 +163,38 @@
163 }
164 }
165 }
166
167 /*
168 ** Proxy specified on the command-line using the --proxy option.
169 ** If there is no --proxy option on the command-line then this
170 ** variable holds a NULL pointer.
171 */
172 static const char *zProxyOpt = 0;
173
174 /*
175 ** Extract any proxy options from the command-line.
176 **
177 ** --proxy URL|off
178 **
179 ** This also happens to be a convenient function to use to look for
180 ** the --nosync option that will temporarily disable the "autosync"
181 ** feature.
182 */
183 void url_proxy_options(void){
184 zProxyOpt = find_option("proxy", 0, 1);
185 if( find_option("nosync",0,0) ) g.fNoSync = 1;
186 }
187
188 /*
189 ** If the "proxy" setting is defined, then change the URL settings
190 ** (initialized by a prior call to url_parse()) so that the HTTP
191 ** header will be appropriate for the proxy and so that the TCP/IP
192 ** connection will be opened to the proxy rather than to the server.
193 **
194 ** If zMsg is not NULL and a proxy is used, then print zMsg followed
195 ** by the canonical name of the proxy (with userid and password suppressed).
 
196 */
197 void url_enable_proxy(const char *zMsg){
198 const char *zProxy;
199 zProxy = zProxyOpt;
200 if( zProxy==0 ){
@@ -194,14 +204,26 @@
204 }
205 }
206 if( zProxy && zProxy[0] && !is_false(zProxy) ){
207 char *zOriginalUrl = g.urlCanonical;
208 char *zOriginalHost = g.urlHostname;
209 char *zOriginalUser = g.urlUser;
210 char *zOriginalPasswd = g.urlPasswd;
211 g.urlUser = 0;
212 g.urlPasswd = "";
213 url_parse(zProxy);
214 if( zMsg ) printf("%s%s\n", zMsg, g.urlCanonical);
215 g.urlPath = zOriginalUrl;
216 g.urlHostname = zOriginalHost;
217 if( g.urlUser ){
218 char *zCredentials1 = mprintf("%s:%s", g.urlUser, g.urlPasswd);
219 char *zCredentials2 = encode64(zCredentials1, -1);
220 g.urlProxyAuth = mprintf("Basic %z", zCredentials2);
221 free(zCredentials1);
222 }
223 g.urlUser = zOriginalUser;
224 g.urlPasswd = zOriginalPasswd;
225 }
226 }
227
228 #if INTERFACE
229 /*
230

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button