| | @@ -27,17 +27,21 @@ |
| 27 | 27 | #include "url.h" |
| 28 | 28 | |
| 29 | 29 | /* |
| 30 | 30 | ** Parse the given URL. Populate variables in the global "g" structure. |
| 31 | 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. |
| 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. |
| 36 | 39 | ** g.urlUser Userid. |
| 37 | 40 | ** 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 |
| 39 | 43 | ** |
| 40 | 44 | ** HTTP url format is: |
| 41 | 45 | ** |
| 42 | 46 | ** http://userid:password@host:port/path?query#fragment |
| 43 | 47 | ** |
| | @@ -159,32 +163,38 @@ |
| 159 | 163 | } |
| 160 | 164 | } |
| 161 | 165 | } |
| 162 | 166 | |
| 163 | 167 | /* |
| 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. |
| 165 | 171 | */ |
| 166 | 172 | static const char *zProxyOpt = 0; |
| 167 | 173 | |
| 168 | 174 | /* |
| 169 | | -** Extra any proxy options from the command-line. |
| 175 | +** Extract any proxy options from the command-line. |
| 170 | 176 | ** |
| 171 | 177 | ** --proxy URL|off |
| 172 | 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. |
| 173 | 182 | */ |
| 174 | 183 | void url_proxy_options(void){ |
| 175 | 184 | zProxyOpt = find_option("proxy", 0, 1); |
| 176 | 185 | if( find_option("nosync",0,0) ) g.fNoSync = 1; |
| 177 | 186 | } |
| 178 | 187 | |
| 179 | 188 | /* |
| 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. |
| 182 | 193 | ** |
| 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). |
| 186 | 196 | */ |
| 187 | 197 | void url_enable_proxy(const char *zMsg){ |
| 188 | 198 | const char *zProxy; |
| 189 | 199 | zProxy = zProxyOpt; |
| 190 | 200 | if( zProxy==0 ){ |
| | @@ -194,14 +204,26 @@ |
| 194 | 204 | } |
| 195 | 205 | } |
| 196 | 206 | if( zProxy && zProxy[0] && !is_false(zProxy) ){ |
| 197 | 207 | char *zOriginalUrl = g.urlCanonical; |
| 198 | 208 | 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 = ""; |
| 200 | 213 | url_parse(zProxy); |
| 214 | + if( zMsg ) printf("%s%s\n", zMsg, g.urlCanonical); |
| 201 | 215 | g.urlPath = zOriginalUrl; |
| 202 | 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; |
| 203 | 225 | } |
| 204 | 226 | } |
| 205 | 227 | |
| 206 | 228 | #if INTERFACE |
| 207 | 229 | /* |
| 208 | 230 | |