Fossil SCM

Add the ability for Debug users to trace sub-CGI responses by adding the fossil-ext-debug query parameter.

drh 2019-07-25 18:08 UTC extension-cgi
Commit cc21a4389e1c1c7075b95b51ec64824159fbcfe0a3354d05fa0204cd2f213a4c
1 file changed +27 -21
+27 -21
--- src/extcgi.c
+++ src/extcgi.c
@@ -100,11 +100,10 @@
100100
void ext_page(void){
101101
const char *zName = P("name"); /* Path information after /ext */
102102
char *zPath = 0; /* Complete path from extroot */
103103
int nRoot; /* Number of bytes in the extroot name */
104104
int nName; /* Length of zName */
105
- int nPath; /* Length of zPath */
106105
char *zScript = 0; /* Name of the CGI script */
107106
int nScript = 0; /* Bytes in the CGI script name */
108107
const char *zFailReason = "???";/* Reason for failure */
109108
int i; /* Loop counter */
110109
const char *zMime = 0; /* MIME type of the reply */
@@ -135,11 +134,10 @@
135134
goto ext_not_found;
136135
}
137136
zPath = mprintf("%s/%s", g.zExtRoot, zName);
138137
nRoot = (int)strlen(g.zExtRoot);
139138
nName = (int)strlen(zName);
140
- nPath = nRoot+nName+1;
141139
if( file_isfile(zPath, ExtFILE) ){
142140
nScript = (int)strlen(zPath);
143141
zScript = zPath;
144142
}else{
145143
for(i=nRoot+1; zPath[i]; i++){
@@ -237,29 +235,37 @@
237235
toSend -= nSent;
238236
data += nSent;
239237
}while( toSend>0 );
240238
fflush(toChild);
241239
}
242
- while( fgets(zLine,sizeof(zLine),fromChild) ){
243
- for(i=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){}
244
- zLine[i] = 0;
245
- if( i==0 ) break;
246
- if( fossil_strnicmp(zLine,"Location:",9)==0 ){
247
- fclose(fromChild);
248
- fclose(toChild);
249
- cgi_redirect(&zLine[10]); /* no return */
250
- }else if( fossil_strnicmp(zLine,"Status:",7)==0 ){
251
- int j;
252
- for(i=7; fossil_isspace(zLine[i]); i++){}
253
- for(j=i; fossil_isdigit(zLine[j]); j++){}
254
- while( fossil_isspace(zLine[j]) ){ j++; }
255
- cgi_set_status(atoi(&zLine[i]), &zLine[j]);
256
- }else if( fossil_strnicmp(zLine,"Content-Length:",15)==0 ){
257
- nContent = atoi(&zLine[15]);
258
- }else if( fossil_strnicmp(zLine,"Content-Type:",13)==0 ){
259
- for(i=13; fossil_isspace(zLine[i]); i++){}
260
- zMime = mprintf("%s", &zLine[i]);
240
+ if( g.perm.Debug && P("fossil-ext-debug")!=0 ){
241
+ /* For users with Debug privilege, if the "fossil-ext-debug" query
242
+ ** parameter exists, then show raw output from the CGI */
243
+ zMime = "text/plain";
244
+ }else{
245
+ while( fgets(zLine,sizeof(zLine),fromChild) ){
246
+ for(i=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){}
247
+ zLine[i] = 0;
248
+ if( i==0 ) break;
249
+ if( fossil_strnicmp(zLine,"Location:",9)==0 ){
250
+ fclose(fromChild);
251
+ fclose(toChild);
252
+ cgi_redirect(&zLine[10]); /* no return */
253
+ }else if( fossil_strnicmp(zLine,"Status:",7)==0 ){
254
+ int j;
255
+ for(i=7; fossil_isspace(zLine[i]); i++){}
256
+ for(j=i; fossil_isdigit(zLine[j]); j++){}
257
+ while( fossil_isspace(zLine[j]) ){ j++; }
258
+ cgi_set_status(atoi(&zLine[i]), &zLine[j]);
259
+ }else if( fossil_strnicmp(zLine,"Content-Length:",15)==0 ){
260
+ nContent = atoi(&zLine[15]);
261
+ }else if( fossil_strnicmp(zLine,"Content-Type:",13)==0 ){
262
+ int j;
263
+ for(i=13; fossil_isspace(zLine[i]); i++){}
264
+ for(j=i; zLine[j] && zLine[j]!=';'; j++){}
265
+ zMime = mprintf("%.*s", j-i, &zLine[i]);
266
+ }
261267
}
262268
}
263269
blob_read_from_channel(&reply, fromChild, nContent);
264270
zFailReason = 0; /* Indicate success */
265271
266272
--- src/extcgi.c
+++ src/extcgi.c
@@ -100,11 +100,10 @@
100 void ext_page(void){
101 const char *zName = P("name"); /* Path information after /ext */
102 char *zPath = 0; /* Complete path from extroot */
103 int nRoot; /* Number of bytes in the extroot name */
104 int nName; /* Length of zName */
105 int nPath; /* Length of zPath */
106 char *zScript = 0; /* Name of the CGI script */
107 int nScript = 0; /* Bytes in the CGI script name */
108 const char *zFailReason = "???";/* Reason for failure */
109 int i; /* Loop counter */
110 const char *zMime = 0; /* MIME type of the reply */
@@ -135,11 +134,10 @@
135 goto ext_not_found;
136 }
137 zPath = mprintf("%s/%s", g.zExtRoot, zName);
138 nRoot = (int)strlen(g.zExtRoot);
139 nName = (int)strlen(zName);
140 nPath = nRoot+nName+1;
141 if( file_isfile(zPath, ExtFILE) ){
142 nScript = (int)strlen(zPath);
143 zScript = zPath;
144 }else{
145 for(i=nRoot+1; zPath[i]; i++){
@@ -237,29 +235,37 @@
237 toSend -= nSent;
238 data += nSent;
239 }while( toSend>0 );
240 fflush(toChild);
241 }
242 while( fgets(zLine,sizeof(zLine),fromChild) ){
243 for(i=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){}
244 zLine[i] = 0;
245 if( i==0 ) break;
246 if( fossil_strnicmp(zLine,"Location:",9)==0 ){
247 fclose(fromChild);
248 fclose(toChild);
249 cgi_redirect(&zLine[10]); /* no return */
250 }else if( fossil_strnicmp(zLine,"Status:",7)==0 ){
251 int j;
252 for(i=7; fossil_isspace(zLine[i]); i++){}
253 for(j=i; fossil_isdigit(zLine[j]); j++){}
254 while( fossil_isspace(zLine[j]) ){ j++; }
255 cgi_set_status(atoi(&zLine[i]), &zLine[j]);
256 }else if( fossil_strnicmp(zLine,"Content-Length:",15)==0 ){
257 nContent = atoi(&zLine[15]);
258 }else if( fossil_strnicmp(zLine,"Content-Type:",13)==0 ){
259 for(i=13; fossil_isspace(zLine[i]); i++){}
260 zMime = mprintf("%s", &zLine[i]);
 
 
 
 
 
 
 
 
261 }
262 }
263 blob_read_from_channel(&reply, fromChild, nContent);
264 zFailReason = 0; /* Indicate success */
265
266
--- src/extcgi.c
+++ src/extcgi.c
@@ -100,11 +100,10 @@
100 void ext_page(void){
101 const char *zName = P("name"); /* Path information after /ext */
102 char *zPath = 0; /* Complete path from extroot */
103 int nRoot; /* Number of bytes in the extroot name */
104 int nName; /* Length of zName */
 
105 char *zScript = 0; /* Name of the CGI script */
106 int nScript = 0; /* Bytes in the CGI script name */
107 const char *zFailReason = "???";/* Reason for failure */
108 int i; /* Loop counter */
109 const char *zMime = 0; /* MIME type of the reply */
@@ -135,11 +134,10 @@
134 goto ext_not_found;
135 }
136 zPath = mprintf("%s/%s", g.zExtRoot, zName);
137 nRoot = (int)strlen(g.zExtRoot);
138 nName = (int)strlen(zName);
 
139 if( file_isfile(zPath, ExtFILE) ){
140 nScript = (int)strlen(zPath);
141 zScript = zPath;
142 }else{
143 for(i=nRoot+1; zPath[i]; i++){
@@ -237,29 +235,37 @@
235 toSend -= nSent;
236 data += nSent;
237 }while( toSend>0 );
238 fflush(toChild);
239 }
240 if( g.perm.Debug && P("fossil-ext-debug")!=0 ){
241 /* For users with Debug privilege, if the "fossil-ext-debug" query
242 ** parameter exists, then show raw output from the CGI */
243 zMime = "text/plain";
244 }else{
245 while( fgets(zLine,sizeof(zLine),fromChild) ){
246 for(i=0; zLine[i] && zLine[i]!='\r' && zLine[i]!='\n'; i++){}
247 zLine[i] = 0;
248 if( i==0 ) break;
249 if( fossil_strnicmp(zLine,"Location:",9)==0 ){
250 fclose(fromChild);
251 fclose(toChild);
252 cgi_redirect(&zLine[10]); /* no return */
253 }else if( fossil_strnicmp(zLine,"Status:",7)==0 ){
254 int j;
255 for(i=7; fossil_isspace(zLine[i]); i++){}
256 for(j=i; fossil_isdigit(zLine[j]); j++){}
257 while( fossil_isspace(zLine[j]) ){ j++; }
258 cgi_set_status(atoi(&zLine[i]), &zLine[j]);
259 }else if( fossil_strnicmp(zLine,"Content-Length:",15)==0 ){
260 nContent = atoi(&zLine[15]);
261 }else if( fossil_strnicmp(zLine,"Content-Type:",13)==0 ){
262 int j;
263 for(i=13; fossil_isspace(zLine[i]); i++){}
264 for(j=i; zLine[j] && zLine[j]!=';'; j++){}
265 zMime = mprintf("%.*s", j-i, &zLine[i]);
266 }
267 }
268 }
269 blob_read_from_channel(&reply, fromChild, nContent);
270 zFailReason = 0; /* Indicate success */
271
272

Keyboard Shortcuts

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