Fossil SCM
When --httptrace is used with "fossil ui" or "fossil server", create log files containing the text of each HTTP request.
Commit
6f3d328fbf91fdee2291d1ce556bfb1947543193
Parent
48cf099427aab8e…
1 file changed
+32
-1
+32
-1
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -783,10 +783,38 @@ | ||
| 783 | 783 | } |
| 784 | 784 | fossil_exit( g.isHTTP ? 0 : 1); |
| 785 | 785 | } |
| 786 | 786 | #endif /* FOSSIL_ENABLE_JSON */ |
| 787 | 787 | |
| 788 | +/* | |
| 789 | +** Log HTTP traffic to a file. Begin the log on first use. Close the log | |
| 790 | +** when the argument is NULL. | |
| 791 | +*/ | |
| 792 | +void cgi_trace(const char *z){ | |
| 793 | + static FILE *pLog = 0; | |
| 794 | + if( g.fHttpTrace==0 ) return; | |
| 795 | + if( z==0 ){ | |
| 796 | + if( pLog ) fclose(pLog); | |
| 797 | + pLog = 0; | |
| 798 | + return; | |
| 799 | + } | |
| 800 | + if( pLog==0 ){ | |
| 801 | + char zFile[50]; | |
| 802 | + unsigned r; | |
| 803 | + sqlite3_randomness(sizeof(r), &r); | |
| 804 | + sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%08x.txt", r); | |
| 805 | + pLog = fopen(zFile, "w"); | |
| 806 | + if( pLog ){ | |
| 807 | + fprintf(stderr, "# open log on %s\n", zFile); | |
| 808 | + }else{ | |
| 809 | + fprintf(stderr, "# failed to open %s\n", zFile); | |
| 810 | + return; | |
| 811 | + } | |
| 812 | + } | |
| 813 | + fputs(z, pLog); | |
| 814 | +} | |
| 815 | + | |
| 788 | 816 | |
| 789 | 817 | /* |
| 790 | 818 | ** Initialize the query parameter database. Information is pulled from |
| 791 | 819 | ** the QUERY_STRING environment variable (if it exists), from standard |
| 792 | 820 | ** input if there is POST data, and from HTTP_COOKIE. |
| @@ -825,10 +853,11 @@ | ||
| 825 | 853 | if( fossil_strcmp(zType,"application/x-www-form-urlencoded")==0 |
| 826 | 854 | || strncmp(zType,"multipart/form-data",19)==0 ){ |
| 827 | 855 | z = fossil_malloc( len+1 ); |
| 828 | 856 | len = fread(z, 1, len, g.httpIn); |
| 829 | 857 | z[len] = 0; |
| 858 | + cgi_trace(z); | |
| 830 | 859 | if( zType[0]=='a' ){ |
| 831 | 860 | add_param_list(z, '&'); |
| 832 | 861 | }else{ |
| 833 | 862 | process_multipart_form_data(z, len); |
| 834 | 863 | } |
| @@ -1145,10 +1174,11 @@ | ||
| 1145 | 1174 | char zLine[2000]; /* A single line of input. */ |
| 1146 | 1175 | g.fullHttpReply = 1; |
| 1147 | 1176 | if( fgets(zLine, sizeof(zLine),g.httpIn)==0 ){ |
| 1148 | 1177 | malformed_request(); |
| 1149 | 1178 | } |
| 1179 | + cgi_trace(zLine); | |
| 1150 | 1180 | zToken = extract_token(zLine, &z); |
| 1151 | 1181 | if( zToken==0 ){ |
| 1152 | 1182 | malformed_request(); |
| 1153 | 1183 | } |
| 1154 | 1184 | if( fossil_strcmp(zToken,"GET")!=0 && fossil_strcmp(zToken,"POST")!=0 |
| @@ -1181,10 +1211,11 @@ | ||
| 1181 | 1211 | */ |
| 1182 | 1212 | while( fgets(zLine,sizeof(zLine),g.httpIn) ){ |
| 1183 | 1213 | char *zFieldName; |
| 1184 | 1214 | char *zVal; |
| 1185 | 1215 | |
| 1216 | + cgi_trace(zLine); | |
| 1186 | 1217 | zFieldName = extract_token(zLine,&zVal); |
| 1187 | 1218 | if( zFieldName==0 || *zFieldName==0 ) break; |
| 1188 | 1219 | while( fossil_isspace(*zVal) ){ zVal++; } |
| 1189 | 1220 | i = strlen(zVal); |
| 1190 | 1221 | while( i>0 && fossil_isspace(zVal[i-1]) ){ i--; } |
| @@ -1212,12 +1243,12 @@ | ||
| 1212 | 1243 | #endif |
| 1213 | 1244 | }else if( fossil_strcmp(zFieldName,"user-agent:")==0 ){ |
| 1214 | 1245 | cgi_setenv("HTTP_USER_AGENT", zVal); |
| 1215 | 1246 | } |
| 1216 | 1247 | } |
| 1217 | - | |
| 1218 | 1248 | cgi_init(); |
| 1249 | + cgi_trace(0); | |
| 1219 | 1250 | } |
| 1220 | 1251 | |
| 1221 | 1252 | #if INTERFACE |
| 1222 | 1253 | /* |
| 1223 | 1254 | ** Bitmap values for the flags parameter to cgi_http_server(). |
| 1224 | 1255 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -783,10 +783,38 @@ | |
| 783 | } |
| 784 | fossil_exit( g.isHTTP ? 0 : 1); |
| 785 | } |
| 786 | #endif /* FOSSIL_ENABLE_JSON */ |
| 787 | |
| 788 | |
| 789 | /* |
| 790 | ** Initialize the query parameter database. Information is pulled from |
| 791 | ** the QUERY_STRING environment variable (if it exists), from standard |
| 792 | ** input if there is POST data, and from HTTP_COOKIE. |
| @@ -825,10 +853,11 @@ | |
| 825 | if( fossil_strcmp(zType,"application/x-www-form-urlencoded")==0 |
| 826 | || strncmp(zType,"multipart/form-data",19)==0 ){ |
| 827 | z = fossil_malloc( len+1 ); |
| 828 | len = fread(z, 1, len, g.httpIn); |
| 829 | z[len] = 0; |
| 830 | if( zType[0]=='a' ){ |
| 831 | add_param_list(z, '&'); |
| 832 | }else{ |
| 833 | process_multipart_form_data(z, len); |
| 834 | } |
| @@ -1145,10 +1174,11 @@ | |
| 1145 | char zLine[2000]; /* A single line of input. */ |
| 1146 | g.fullHttpReply = 1; |
| 1147 | if( fgets(zLine, sizeof(zLine),g.httpIn)==0 ){ |
| 1148 | malformed_request(); |
| 1149 | } |
| 1150 | zToken = extract_token(zLine, &z); |
| 1151 | if( zToken==0 ){ |
| 1152 | malformed_request(); |
| 1153 | } |
| 1154 | if( fossil_strcmp(zToken,"GET")!=0 && fossil_strcmp(zToken,"POST")!=0 |
| @@ -1181,10 +1211,11 @@ | |
| 1181 | */ |
| 1182 | while( fgets(zLine,sizeof(zLine),g.httpIn) ){ |
| 1183 | char *zFieldName; |
| 1184 | char *zVal; |
| 1185 | |
| 1186 | zFieldName = extract_token(zLine,&zVal); |
| 1187 | if( zFieldName==0 || *zFieldName==0 ) break; |
| 1188 | while( fossil_isspace(*zVal) ){ zVal++; } |
| 1189 | i = strlen(zVal); |
| 1190 | while( i>0 && fossil_isspace(zVal[i-1]) ){ i--; } |
| @@ -1212,12 +1243,12 @@ | |
| 1212 | #endif |
| 1213 | }else if( fossil_strcmp(zFieldName,"user-agent:")==0 ){ |
| 1214 | cgi_setenv("HTTP_USER_AGENT", zVal); |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | cgi_init(); |
| 1219 | } |
| 1220 | |
| 1221 | #if INTERFACE |
| 1222 | /* |
| 1223 | ** Bitmap values for the flags parameter to cgi_http_server(). |
| 1224 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -783,10 +783,38 @@ | |
| 783 | } |
| 784 | fossil_exit( g.isHTTP ? 0 : 1); |
| 785 | } |
| 786 | #endif /* FOSSIL_ENABLE_JSON */ |
| 787 | |
| 788 | /* |
| 789 | ** Log HTTP traffic to a file. Begin the log on first use. Close the log |
| 790 | ** when the argument is NULL. |
| 791 | */ |
| 792 | void cgi_trace(const char *z){ |
| 793 | static FILE *pLog = 0; |
| 794 | if( g.fHttpTrace==0 ) return; |
| 795 | if( z==0 ){ |
| 796 | if( pLog ) fclose(pLog); |
| 797 | pLog = 0; |
| 798 | return; |
| 799 | } |
| 800 | if( pLog==0 ){ |
| 801 | char zFile[50]; |
| 802 | unsigned r; |
| 803 | sqlite3_randomness(sizeof(r), &r); |
| 804 | sqlite3_snprintf(sizeof(zFile), zFile, "httplog-%08x.txt", r); |
| 805 | pLog = fopen(zFile, "w"); |
| 806 | if( pLog ){ |
| 807 | fprintf(stderr, "# open log on %s\n", zFile); |
| 808 | }else{ |
| 809 | fprintf(stderr, "# failed to open %s\n", zFile); |
| 810 | return; |
| 811 | } |
| 812 | } |
| 813 | fputs(z, pLog); |
| 814 | } |
| 815 | |
| 816 | |
| 817 | /* |
| 818 | ** Initialize the query parameter database. Information is pulled from |
| 819 | ** the QUERY_STRING environment variable (if it exists), from standard |
| 820 | ** input if there is POST data, and from HTTP_COOKIE. |
| @@ -825,10 +853,11 @@ | |
| 853 | if( fossil_strcmp(zType,"application/x-www-form-urlencoded")==0 |
| 854 | || strncmp(zType,"multipart/form-data",19)==0 ){ |
| 855 | z = fossil_malloc( len+1 ); |
| 856 | len = fread(z, 1, len, g.httpIn); |
| 857 | z[len] = 0; |
| 858 | cgi_trace(z); |
| 859 | if( zType[0]=='a' ){ |
| 860 | add_param_list(z, '&'); |
| 861 | }else{ |
| 862 | process_multipart_form_data(z, len); |
| 863 | } |
| @@ -1145,10 +1174,11 @@ | |
| 1174 | char zLine[2000]; /* A single line of input. */ |
| 1175 | g.fullHttpReply = 1; |
| 1176 | if( fgets(zLine, sizeof(zLine),g.httpIn)==0 ){ |
| 1177 | malformed_request(); |
| 1178 | } |
| 1179 | cgi_trace(zLine); |
| 1180 | zToken = extract_token(zLine, &z); |
| 1181 | if( zToken==0 ){ |
| 1182 | malformed_request(); |
| 1183 | } |
| 1184 | if( fossil_strcmp(zToken,"GET")!=0 && fossil_strcmp(zToken,"POST")!=0 |
| @@ -1181,10 +1211,11 @@ | |
| 1211 | */ |
| 1212 | while( fgets(zLine,sizeof(zLine),g.httpIn) ){ |
| 1213 | char *zFieldName; |
| 1214 | char *zVal; |
| 1215 | |
| 1216 | cgi_trace(zLine); |
| 1217 | zFieldName = extract_token(zLine,&zVal); |
| 1218 | if( zFieldName==0 || *zFieldName==0 ) break; |
| 1219 | while( fossil_isspace(*zVal) ){ zVal++; } |
| 1220 | i = strlen(zVal); |
| 1221 | while( i>0 && fossil_isspace(zVal[i-1]) ){ i--; } |
| @@ -1212,12 +1243,12 @@ | |
| 1243 | #endif |
| 1244 | }else if( fossil_strcmp(zFieldName,"user-agent:")==0 ){ |
| 1245 | cgi_setenv("HTTP_USER_AGENT", zVal); |
| 1246 | } |
| 1247 | } |
| 1248 | cgi_init(); |
| 1249 | cgi_trace(0); |
| 1250 | } |
| 1251 | |
| 1252 | #if INTERFACE |
| 1253 | /* |
| 1254 | ** Bitmap values for the flags parameter to cgi_http_server(). |
| 1255 |