Fossil SCM

Added mimetype image/vnd.microsoft.icon to the is-compressible list, per forum feedback. Consolidated strncmp() vs fossil_strncmp() into fossil_strncmp() in cgi.c for consistency's sake.

stephan 2022-06-08 07:54 pikchrshow-wasm
Commit 3652b4d6bb77aea5c09491ef9f487b777b4c70505b612d05e6eec750b36c280f
1 file changed +14 -11
+14 -11
--- src/cgi.c
+++ src/cgi.c
@@ -307,11 +307,11 @@
307307
if(!g.isHTTP) return /* e.g. JSON CLI mode, where g.zTop is not set */;
308308
else if( zPath==0 ){
309309
zPath = g.zTop;
310310
if( zPath[0]==0 ) zPath = "/";
311311
}
312
- if( g.zBaseURL!=0 && strncmp(g.zBaseURL, "https:", 6)==0 ){
312
+ if( g.zBaseURL!=0 && fossil_strncmp(g.zBaseURL, "https:", 6)==0 ){
313313
zSecure = " secure;";
314314
}
315315
if( lifetime!=0 ){
316316
blob_appendf(&extraHeader,
317317
"Set-Cookie: %s=%t; Path=%s; max-age=%d; HttpOnly; "
@@ -335,11 +335,11 @@
335335
/* Maintenance note: this oddball structure is intended to make
336336
** adding new mimetypes to this list less of a performance hit than
337337
** doing a strcmp/glob over a growing set of compressible types. */
338338
switch(zContentType ? *zContentType : 0){
339339
case (int)'a':
340
- if(0==strncmp("application/",zContentType,12)){
340
+ if(0==fossil_strncmp("application/",zContentType,12)){
341341
const char * z = &zContentType[12];
342342
switch(*z){
343343
case (int)'j':
344344
return fossil_strcmp("javascript", z)==0
345345
|| fossil_strcmp("json", z)==0;
@@ -351,11 +351,12 @@
351351
return sqlite3_strglob("*xml", z)==0;
352352
}
353353
}
354354
break;
355355
case (int)'i':
356
- return fossil_strcmp(zContentType, "image/svg+xml")==0;
356
+ return fossil_strcmp(zContentType, "image/svg+xml")==0
357
+ || fossil_strcmp(zContentType, "image/vnd.microsoft.icon")==0;
357358
case (int)'t':
358359
return fossil_strncmp(zContentType, "text/", 5)==0;
359360
}
360361
return 0;
361362
}
@@ -456,12 +457,12 @@
456457
** charset. Also, adding a charset is not strictly appropriate for
457458
** most types (and not required for many others which may ostensibly
458459
** benefit from one, as detailed in that forum post).
459460
*/
460461
static const char * content_type_charset(const char *zContentType){
461
- if(zContentType!=0){
462
- if(0==strncmp(zContentType,"text/",5)) return "; charset=utf-8";
462
+ if(0==fossil_strncmp(zContentType,"text/",5)){
463
+ return "; charset=utf-8";
463464
}
464465
return "";
465466
}
466467
467468
/*
@@ -612,11 +613,12 @@
612613
int iStat,
613614
const char *zStat
614615
){
615616
char *zLocation;
616617
CGIDEBUG(("redirect to %s\n", zURL));
617
- if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 ){
618
+ if( fossil_strncmp(zURL,"http:",5)==0
619
+ || fossil_strncmp(zURL,"https:",6)==0 ){
618620
zLocation = mprintf("Location: %s\r\n", zURL);
619621
}else if( *zURL=='/' ){
620622
int n1 = (int)strlen(g.zBaseURL);
621623
int n2 = (int)strlen(g.zTop);
622624
if( g.zBaseURL[n1-1]=='/' ) zURL++;
@@ -696,11 +698,11 @@
696698
const char *zMethod = P("REQUEST_METHOD");
697699
if( zMethod==0 ) return 0;
698700
if( strcmp(zMethod,"POST")!=0 ) return 0;
699701
}
700702
nBase = (int)strlen(g.zBaseURL);
701
- if( strncmp(g.zBaseURL,zRef,nBase)!=0 ) return 0;
703
+ if( fossil_strncmp(g.zBaseURL,zRef,nBase)!=0 ) return 0;
702704
if( zRef[nBase]!=0 && zRef[nBase]!='/' ) return 0;
703705
return 1;
704706
}
705707
706708
/*
@@ -963,11 +965,12 @@
963965
int len = *pLen;
964966
int i;
965967
int nBoundary = strlen(zBoundary);
966968
*pnContent = len;
967969
for(i=0; i<len; i++){
968
- if( z[i]=='\n' && strncmp(zBoundary, &z[i+1], nBoundary)==0 ){
970
+ if( z[i]=='\n' && fossil_strncmp(zBoundary, &z[i+1],
971
+ nBoundary)==0 ){
969972
if( i>0 && z[i-1]=='\r' ) i--;
970973
z[i] = 0;
971974
*pnContent = i;
972975
i += nBoundary;
973976
break;
@@ -1391,11 +1394,11 @@
13911394
*/
13921395
void cgi_decode_post_parameters(void){
13931396
int len = blob_size(&g.cgiIn);
13941397
if( len==0 ) return;
13951398
if( fossil_strcmp(g.zContentType,"application/x-www-form-urlencoded")==0
1396
- || strncmp(g.zContentType,"multipart/form-data",19)==0
1399
+ || fossil_strncmp(g.zContentType,"multipart/form-data",19)==0
13971400
){
13981401
char *z = blob_str(&g.cgiIn);
13991402
cgi_trace(z);
14001403
if( g.zContentType[0]=='a' ){
14011404
add_param_list(z, '&');
@@ -2369,11 +2372,11 @@
23692372
if( zBrowser ){
23702373
assert( strstr(zBrowser,"%d")!=0 );
23712374
zBrowser = mprintf(zBrowser /*works-like:"%d"*/, iPort);
23722375
#if defined(__CYGWIN__)
23732376
/* On Cygwin, we can do better than "echo" */
2374
- if( strncmp(zBrowser, "echo ", 5)==0 ){
2377
+ if( fossil_strncmp(zBrowser, "echo ", 5)==0 ){
23752378
wchar_t *wUrl = fossil_utf8_to_unicode(zBrowser+5);
23762379
wUrl[wcslen(wUrl)-2] = 0; /* Strip terminating " &" */
23772380
if( (size_t)ShellExecuteW(0, L"open", wUrl, 0, 0, 1)<33 ){
23782381
fossil_warning("cannot start browser\n");
23792382
}
@@ -2529,11 +2532,11 @@
25292532
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 0};
25302533
if( 7==sscanf(zDate, "%3[A-Za-z], %d %3[A-Za-z] %d %d:%d:%d", zIgnore,
25312534
&mday, zMonth, &year, &hour, &min, &sec)){
25322535
if( year > 1900 ) year -= 1900;
25332536
for(mon=0; azMonths[mon]; mon++){
2534
- if( !strncmp( azMonths[mon], zMonth, 3 )){
2537
+ if( !fossil_strncmp( azMonths[mon], zMonth, 3 )){
25352538
int nDay;
25362539
int isLeapYr;
25372540
static int priorDays[] =
25382541
{ 0, 31, 59, 90,120,151,181,212,243,273,304,334 };
25392542
if( mon<0 ){
25402543
--- src/cgi.c
+++ src/cgi.c
@@ -307,11 +307,11 @@
307 if(!g.isHTTP) return /* e.g. JSON CLI mode, where g.zTop is not set */;
308 else if( zPath==0 ){
309 zPath = g.zTop;
310 if( zPath[0]==0 ) zPath = "/";
311 }
312 if( g.zBaseURL!=0 && strncmp(g.zBaseURL, "https:", 6)==0 ){
313 zSecure = " secure;";
314 }
315 if( lifetime!=0 ){
316 blob_appendf(&extraHeader,
317 "Set-Cookie: %s=%t; Path=%s; max-age=%d; HttpOnly; "
@@ -335,11 +335,11 @@
335 /* Maintenance note: this oddball structure is intended to make
336 ** adding new mimetypes to this list less of a performance hit than
337 ** doing a strcmp/glob over a growing set of compressible types. */
338 switch(zContentType ? *zContentType : 0){
339 case (int)'a':
340 if(0==strncmp("application/",zContentType,12)){
341 const char * z = &zContentType[12];
342 switch(*z){
343 case (int)'j':
344 return fossil_strcmp("javascript", z)==0
345 || fossil_strcmp("json", z)==0;
@@ -351,11 +351,12 @@
351 return sqlite3_strglob("*xml", z)==0;
352 }
353 }
354 break;
355 case (int)'i':
356 return fossil_strcmp(zContentType, "image/svg+xml")==0;
 
357 case (int)'t':
358 return fossil_strncmp(zContentType, "text/", 5)==0;
359 }
360 return 0;
361 }
@@ -456,12 +457,12 @@
456 ** charset. Also, adding a charset is not strictly appropriate for
457 ** most types (and not required for many others which may ostensibly
458 ** benefit from one, as detailed in that forum post).
459 */
460 static const char * content_type_charset(const char *zContentType){
461 if(zContentType!=0){
462 if(0==strncmp(zContentType,"text/",5)) return "; charset=utf-8";
463 }
464 return "";
465 }
466
467 /*
@@ -612,11 +613,12 @@
612 int iStat,
613 const char *zStat
614 ){
615 char *zLocation;
616 CGIDEBUG(("redirect to %s\n", zURL));
617 if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 ){
 
618 zLocation = mprintf("Location: %s\r\n", zURL);
619 }else if( *zURL=='/' ){
620 int n1 = (int)strlen(g.zBaseURL);
621 int n2 = (int)strlen(g.zTop);
622 if( g.zBaseURL[n1-1]=='/' ) zURL++;
@@ -696,11 +698,11 @@
696 const char *zMethod = P("REQUEST_METHOD");
697 if( zMethod==0 ) return 0;
698 if( strcmp(zMethod,"POST")!=0 ) return 0;
699 }
700 nBase = (int)strlen(g.zBaseURL);
701 if( strncmp(g.zBaseURL,zRef,nBase)!=0 ) return 0;
702 if( zRef[nBase]!=0 && zRef[nBase]!='/' ) return 0;
703 return 1;
704 }
705
706 /*
@@ -963,11 +965,12 @@
963 int len = *pLen;
964 int i;
965 int nBoundary = strlen(zBoundary);
966 *pnContent = len;
967 for(i=0; i<len; i++){
968 if( z[i]=='\n' && strncmp(zBoundary, &z[i+1], nBoundary)==0 ){
 
969 if( i>0 && z[i-1]=='\r' ) i--;
970 z[i] = 0;
971 *pnContent = i;
972 i += nBoundary;
973 break;
@@ -1391,11 +1394,11 @@
1391 */
1392 void cgi_decode_post_parameters(void){
1393 int len = blob_size(&g.cgiIn);
1394 if( len==0 ) return;
1395 if( fossil_strcmp(g.zContentType,"application/x-www-form-urlencoded")==0
1396 || strncmp(g.zContentType,"multipart/form-data",19)==0
1397 ){
1398 char *z = blob_str(&g.cgiIn);
1399 cgi_trace(z);
1400 if( g.zContentType[0]=='a' ){
1401 add_param_list(z, '&');
@@ -2369,11 +2372,11 @@
2369 if( zBrowser ){
2370 assert( strstr(zBrowser,"%d")!=0 );
2371 zBrowser = mprintf(zBrowser /*works-like:"%d"*/, iPort);
2372 #if defined(__CYGWIN__)
2373 /* On Cygwin, we can do better than "echo" */
2374 if( strncmp(zBrowser, "echo ", 5)==0 ){
2375 wchar_t *wUrl = fossil_utf8_to_unicode(zBrowser+5);
2376 wUrl[wcslen(wUrl)-2] = 0; /* Strip terminating " &" */
2377 if( (size_t)ShellExecuteW(0, L"open", wUrl, 0, 0, 1)<33 ){
2378 fossil_warning("cannot start browser\n");
2379 }
@@ -2529,11 +2532,11 @@
2529 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 0};
2530 if( 7==sscanf(zDate, "%3[A-Za-z], %d %3[A-Za-z] %d %d:%d:%d", zIgnore,
2531 &mday, zMonth, &year, &hour, &min, &sec)){
2532 if( year > 1900 ) year -= 1900;
2533 for(mon=0; azMonths[mon]; mon++){
2534 if( !strncmp( azMonths[mon], zMonth, 3 )){
2535 int nDay;
2536 int isLeapYr;
2537 static int priorDays[] =
2538 { 0, 31, 59, 90,120,151,181,212,243,273,304,334 };
2539 if( mon<0 ){
2540
--- src/cgi.c
+++ src/cgi.c
@@ -307,11 +307,11 @@
307 if(!g.isHTTP) return /* e.g. JSON CLI mode, where g.zTop is not set */;
308 else if( zPath==0 ){
309 zPath = g.zTop;
310 if( zPath[0]==0 ) zPath = "/";
311 }
312 if( g.zBaseURL!=0 && fossil_strncmp(g.zBaseURL, "https:", 6)==0 ){
313 zSecure = " secure;";
314 }
315 if( lifetime!=0 ){
316 blob_appendf(&extraHeader,
317 "Set-Cookie: %s=%t; Path=%s; max-age=%d; HttpOnly; "
@@ -335,11 +335,11 @@
335 /* Maintenance note: this oddball structure is intended to make
336 ** adding new mimetypes to this list less of a performance hit than
337 ** doing a strcmp/glob over a growing set of compressible types. */
338 switch(zContentType ? *zContentType : 0){
339 case (int)'a':
340 if(0==fossil_strncmp("application/",zContentType,12)){
341 const char * z = &zContentType[12];
342 switch(*z){
343 case (int)'j':
344 return fossil_strcmp("javascript", z)==0
345 || fossil_strcmp("json", z)==0;
@@ -351,11 +351,12 @@
351 return sqlite3_strglob("*xml", z)==0;
352 }
353 }
354 break;
355 case (int)'i':
356 return fossil_strcmp(zContentType, "image/svg+xml")==0
357 || fossil_strcmp(zContentType, "image/vnd.microsoft.icon")==0;
358 case (int)'t':
359 return fossil_strncmp(zContentType, "text/", 5)==0;
360 }
361 return 0;
362 }
@@ -456,12 +457,12 @@
457 ** charset. Also, adding a charset is not strictly appropriate for
458 ** most types (and not required for many others which may ostensibly
459 ** benefit from one, as detailed in that forum post).
460 */
461 static const char * content_type_charset(const char *zContentType){
462 if(0==fossil_strncmp(zContentType,"text/",5)){
463 return "; charset=utf-8";
464 }
465 return "";
466 }
467
468 /*
@@ -612,11 +613,12 @@
613 int iStat,
614 const char *zStat
615 ){
616 char *zLocation;
617 CGIDEBUG(("redirect to %s\n", zURL));
618 if( fossil_strncmp(zURL,"http:",5)==0
619 || fossil_strncmp(zURL,"https:",6)==0 ){
620 zLocation = mprintf("Location: %s\r\n", zURL);
621 }else if( *zURL=='/' ){
622 int n1 = (int)strlen(g.zBaseURL);
623 int n2 = (int)strlen(g.zTop);
624 if( g.zBaseURL[n1-1]=='/' ) zURL++;
@@ -696,11 +698,11 @@
698 const char *zMethod = P("REQUEST_METHOD");
699 if( zMethod==0 ) return 0;
700 if( strcmp(zMethod,"POST")!=0 ) return 0;
701 }
702 nBase = (int)strlen(g.zBaseURL);
703 if( fossil_strncmp(g.zBaseURL,zRef,nBase)!=0 ) return 0;
704 if( zRef[nBase]!=0 && zRef[nBase]!='/' ) return 0;
705 return 1;
706 }
707
708 /*
@@ -963,11 +965,12 @@
965 int len = *pLen;
966 int i;
967 int nBoundary = strlen(zBoundary);
968 *pnContent = len;
969 for(i=0; i<len; i++){
970 if( z[i]=='\n' && fossil_strncmp(zBoundary, &z[i+1],
971 nBoundary)==0 ){
972 if( i>0 && z[i-1]=='\r' ) i--;
973 z[i] = 0;
974 *pnContent = i;
975 i += nBoundary;
976 break;
@@ -1391,11 +1394,11 @@
1394 */
1395 void cgi_decode_post_parameters(void){
1396 int len = blob_size(&g.cgiIn);
1397 if( len==0 ) return;
1398 if( fossil_strcmp(g.zContentType,"application/x-www-form-urlencoded")==0
1399 || fossil_strncmp(g.zContentType,"multipart/form-data",19)==0
1400 ){
1401 char *z = blob_str(&g.cgiIn);
1402 cgi_trace(z);
1403 if( g.zContentType[0]=='a' ){
1404 add_param_list(z, '&');
@@ -2369,11 +2372,11 @@
2372 if( zBrowser ){
2373 assert( strstr(zBrowser,"%d")!=0 );
2374 zBrowser = mprintf(zBrowser /*works-like:"%d"*/, iPort);
2375 #if defined(__CYGWIN__)
2376 /* On Cygwin, we can do better than "echo" */
2377 if( fossil_strncmp(zBrowser, "echo ", 5)==0 ){
2378 wchar_t *wUrl = fossil_utf8_to_unicode(zBrowser+5);
2379 wUrl[wcslen(wUrl)-2] = 0; /* Strip terminating " &" */
2380 if( (size_t)ShellExecuteW(0, L"open", wUrl, 0, 0, 1)<33 ){
2381 fossil_warning("cannot start browser\n");
2382 }
@@ -2529,11 +2532,11 @@
2532 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 0};
2533 if( 7==sscanf(zDate, "%3[A-Za-z], %d %3[A-Za-z] %d %d:%d:%d", zIgnore,
2534 &mday, zMonth, &year, &hour, &min, &sec)){
2535 if( year > 1900 ) year -= 1900;
2536 for(mon=0; azMonths[mon]; mon++){
2537 if( !fossil_strncmp( azMonths[mon], zMonth, 3 )){
2538 int nDay;
2539 int isLeapYr;
2540 static int priorDays[] =
2541 { 0, 31, 59, 90,120,151,181,212,243,273,304,334 };
2542 if( mon<0 ){
2543

Keyboard Shortcuts

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