Fossil SCM
Additional cleanup of the CGI handling when using SSH. Specifically the use of cgi_init() introduced some side-effects that caused Fossil to return errors when using ForceCommand to require "fossil http" interface.
Commit
088be210db8abad5cf9aec8b68c1d8113e14b707fbf9e6fc3ab08a013a68f91d
Parent
788e68b080b5c3a…
1 file changed
+9
-15
+9
-15
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -2290,12 +2290,11 @@ | ||
| 2290 | 2290 | */ |
| 2291 | 2291 | void cgi_handle_ssh_http_request(const char *zIpAddr){ |
| 2292 | 2292 | static int nCycles = 0; |
| 2293 | 2293 | static char *zCmd = 0; |
| 2294 | 2294 | char *z, *zToken; |
| 2295 | - const char *zType = 0; | |
| 2296 | - int i, content_length = 0; | |
| 2295 | + int i; | |
| 2297 | 2296 | char zLine[2000]; /* A single line of input. */ |
| 2298 | 2297 | |
| 2299 | 2298 | assert( !g.httpUseSSL ); |
| 2300 | 2299 | #ifdef FOSSIL_ENABLE_JSON |
| 2301 | 2300 | if( nCycles==0 ){ json_bootstrap_early(); } |
| @@ -2386,13 +2385,19 @@ | ||
| 2386 | 2385 | zVal[i] = 0; |
| 2387 | 2386 | for(i=0; zFieldName[i]; i++){ |
| 2388 | 2387 | zFieldName[i] = fossil_tolower(zFieldName[i]); |
| 2389 | 2388 | } |
| 2390 | 2389 | if( fossil_strcmp(zFieldName,"content-length:")==0 ){ |
| 2391 | - content_length = atoi(zVal); | |
| 2390 | + if( nCycles==0 ){ | |
| 2391 | + cgi_setenv("CONTENT_LENGTH", zVal); | |
| 2392 | + }else{ | |
| 2393 | + cgi_replace_parameter("CONTENT_LENGTH", zVal); | |
| 2394 | + } | |
| 2392 | 2395 | }else if( fossil_strcmp(zFieldName,"content-type:")==0 ){ |
| 2393 | - g.zContentType = zType = fossil_strdup(zVal); | |
| 2396 | + if( nCycles==0 ){ | |
| 2397 | + cgi_setenv("CONTENT_TYPE", zVal); | |
| 2398 | + } | |
| 2394 | 2399 | }else if( fossil_strcmp(zFieldName,"host:")==0 ){ |
| 2395 | 2400 | if( nCycles==0 ){ |
| 2396 | 2401 | cgi_setenv("HTTP_HOST", zVal); |
| 2397 | 2402 | } |
| 2398 | 2403 | }else if( fossil_strcmp(zFieldName,"user-agent:")==0 ){ |
| @@ -2419,21 +2424,10 @@ | ||
| 2419 | 2424 | } |
| 2420 | 2425 | |
| 2421 | 2426 | cgi_reset_content(); |
| 2422 | 2427 | cgi_destination(CGI_BODY); |
| 2423 | 2428 | |
| 2424 | - if( content_length>0 && zType ){ | |
| 2425 | - blob_zero(&g.cgiIn); | |
| 2426 | - if( fossil_strcmp(zType, "application/x-fossil")==0 ){ | |
| 2427 | - blob_read_from_channel(&g.cgiIn, g.httpIn, content_length); | |
| 2428 | - blob_uncompress(&g.cgiIn, &g.cgiIn); | |
| 2429 | - }else if( fossil_strcmp(zType, "application/x-fossil-debug")==0 ){ | |
| 2430 | - blob_read_from_channel(&g.cgiIn, g.httpIn, content_length); | |
| 2431 | - }else if( fossil_strcmp(zType, "application/x-fossil-uncompressed")==0 ){ | |
| 2432 | - blob_read_from_channel(&g.cgiIn, g.httpIn, content_length); | |
| 2433 | - } | |
| 2434 | - } | |
| 2435 | 2429 | cgi_init(); |
| 2436 | 2430 | cgi_trace(0); |
| 2437 | 2431 | nCycles++; |
| 2438 | 2432 | } |
| 2439 | 2433 | |
| 2440 | 2434 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -2290,12 +2290,11 @@ | |
| 2290 | */ |
| 2291 | void cgi_handle_ssh_http_request(const char *zIpAddr){ |
| 2292 | static int nCycles = 0; |
| 2293 | static char *zCmd = 0; |
| 2294 | char *z, *zToken; |
| 2295 | const char *zType = 0; |
| 2296 | int i, content_length = 0; |
| 2297 | char zLine[2000]; /* A single line of input. */ |
| 2298 | |
| 2299 | assert( !g.httpUseSSL ); |
| 2300 | #ifdef FOSSIL_ENABLE_JSON |
| 2301 | if( nCycles==0 ){ json_bootstrap_early(); } |
| @@ -2386,13 +2385,19 @@ | |
| 2386 | zVal[i] = 0; |
| 2387 | for(i=0; zFieldName[i]; i++){ |
| 2388 | zFieldName[i] = fossil_tolower(zFieldName[i]); |
| 2389 | } |
| 2390 | if( fossil_strcmp(zFieldName,"content-length:")==0 ){ |
| 2391 | content_length = atoi(zVal); |
| 2392 | }else if( fossil_strcmp(zFieldName,"content-type:")==0 ){ |
| 2393 | g.zContentType = zType = fossil_strdup(zVal); |
| 2394 | }else if( fossil_strcmp(zFieldName,"host:")==0 ){ |
| 2395 | if( nCycles==0 ){ |
| 2396 | cgi_setenv("HTTP_HOST", zVal); |
| 2397 | } |
| 2398 | }else if( fossil_strcmp(zFieldName,"user-agent:")==0 ){ |
| @@ -2419,21 +2424,10 @@ | |
| 2419 | } |
| 2420 | |
| 2421 | cgi_reset_content(); |
| 2422 | cgi_destination(CGI_BODY); |
| 2423 | |
| 2424 | if( content_length>0 && zType ){ |
| 2425 | blob_zero(&g.cgiIn); |
| 2426 | if( fossil_strcmp(zType, "application/x-fossil")==0 ){ |
| 2427 | blob_read_from_channel(&g.cgiIn, g.httpIn, content_length); |
| 2428 | blob_uncompress(&g.cgiIn, &g.cgiIn); |
| 2429 | }else if( fossil_strcmp(zType, "application/x-fossil-debug")==0 ){ |
| 2430 | blob_read_from_channel(&g.cgiIn, g.httpIn, content_length); |
| 2431 | }else if( fossil_strcmp(zType, "application/x-fossil-uncompressed")==0 ){ |
| 2432 | blob_read_from_channel(&g.cgiIn, g.httpIn, content_length); |
| 2433 | } |
| 2434 | } |
| 2435 | cgi_init(); |
| 2436 | cgi_trace(0); |
| 2437 | nCycles++; |
| 2438 | } |
| 2439 | |
| 2440 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -2290,12 +2290,11 @@ | |
| 2290 | */ |
| 2291 | void cgi_handle_ssh_http_request(const char *zIpAddr){ |
| 2292 | static int nCycles = 0; |
| 2293 | static char *zCmd = 0; |
| 2294 | char *z, *zToken; |
| 2295 | int i; |
| 2296 | char zLine[2000]; /* A single line of input. */ |
| 2297 | |
| 2298 | assert( !g.httpUseSSL ); |
| 2299 | #ifdef FOSSIL_ENABLE_JSON |
| 2300 | if( nCycles==0 ){ json_bootstrap_early(); } |
| @@ -2386,13 +2385,19 @@ | |
| 2385 | zVal[i] = 0; |
| 2386 | for(i=0; zFieldName[i]; i++){ |
| 2387 | zFieldName[i] = fossil_tolower(zFieldName[i]); |
| 2388 | } |
| 2389 | if( fossil_strcmp(zFieldName,"content-length:")==0 ){ |
| 2390 | if( nCycles==0 ){ |
| 2391 | cgi_setenv("CONTENT_LENGTH", zVal); |
| 2392 | }else{ |
| 2393 | cgi_replace_parameter("CONTENT_LENGTH", zVal); |
| 2394 | } |
| 2395 | }else if( fossil_strcmp(zFieldName,"content-type:")==0 ){ |
| 2396 | if( nCycles==0 ){ |
| 2397 | cgi_setenv("CONTENT_TYPE", zVal); |
| 2398 | } |
| 2399 | }else if( fossil_strcmp(zFieldName,"host:")==0 ){ |
| 2400 | if( nCycles==0 ){ |
| 2401 | cgi_setenv("HTTP_HOST", zVal); |
| 2402 | } |
| 2403 | }else if( fossil_strcmp(zFieldName,"user-agent:")==0 ){ |
| @@ -2419,21 +2424,10 @@ | |
| 2424 | } |
| 2425 | |
| 2426 | cgi_reset_content(); |
| 2427 | cgi_destination(CGI_BODY); |
| 2428 | |
| 2429 | cgi_init(); |
| 2430 | cgi_trace(0); |
| 2431 | nCycles++; |
| 2432 | } |
| 2433 | |
| 2434 |