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.
Commit
3652b4d6bb77aea5c09491ef9f487b777b4c70505b612d05e6eec750b36c280f
Parent
86db2d94c60e238…
1 file changed
+14
-11
+14
-11
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -307,11 +307,11 @@ | ||
| 307 | 307 | if(!g.isHTTP) return /* e.g. JSON CLI mode, where g.zTop is not set */; |
| 308 | 308 | else if( zPath==0 ){ |
| 309 | 309 | zPath = g.zTop; |
| 310 | 310 | if( zPath[0]==0 ) zPath = "/"; |
| 311 | 311 | } |
| 312 | - if( g.zBaseURL!=0 && strncmp(g.zBaseURL, "https:", 6)==0 ){ | |
| 312 | + if( g.zBaseURL!=0 && fossil_strncmp(g.zBaseURL, "https:", 6)==0 ){ | |
| 313 | 313 | zSecure = " secure;"; |
| 314 | 314 | } |
| 315 | 315 | if( lifetime!=0 ){ |
| 316 | 316 | blob_appendf(&extraHeader, |
| 317 | 317 | "Set-Cookie: %s=%t; Path=%s; max-age=%d; HttpOnly; " |
| @@ -335,11 +335,11 @@ | ||
| 335 | 335 | /* Maintenance note: this oddball structure is intended to make |
| 336 | 336 | ** adding new mimetypes to this list less of a performance hit than |
| 337 | 337 | ** doing a strcmp/glob over a growing set of compressible types. */ |
| 338 | 338 | switch(zContentType ? *zContentType : 0){ |
| 339 | 339 | case (int)'a': |
| 340 | - if(0==strncmp("application/",zContentType,12)){ | |
| 340 | + if(0==fossil_strncmp("application/",zContentType,12)){ | |
| 341 | 341 | const char * z = &zContentType[12]; |
| 342 | 342 | switch(*z){ |
| 343 | 343 | case (int)'j': |
| 344 | 344 | return fossil_strcmp("javascript", z)==0 |
| 345 | 345 | || fossil_strcmp("json", z)==0; |
| @@ -351,11 +351,12 @@ | ||
| 351 | 351 | return sqlite3_strglob("*xml", z)==0; |
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | break; |
| 355 | 355 | 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; | |
| 357 | 358 | case (int)'t': |
| 358 | 359 | return fossil_strncmp(zContentType, "text/", 5)==0; |
| 359 | 360 | } |
| 360 | 361 | return 0; |
| 361 | 362 | } |
| @@ -456,12 +457,12 @@ | ||
| 456 | 457 | ** charset. Also, adding a charset is not strictly appropriate for |
| 457 | 458 | ** most types (and not required for many others which may ostensibly |
| 458 | 459 | ** benefit from one, as detailed in that forum post). |
| 459 | 460 | */ |
| 460 | 461 | 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"; | |
| 463 | 464 | } |
| 464 | 465 | return ""; |
| 465 | 466 | } |
| 466 | 467 | |
| 467 | 468 | /* |
| @@ -612,11 +613,12 @@ | ||
| 612 | 613 | int iStat, |
| 613 | 614 | const char *zStat |
| 614 | 615 | ){ |
| 615 | 616 | char *zLocation; |
| 616 | 617 | 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 ){ | |
| 618 | 620 | zLocation = mprintf("Location: %s\r\n", zURL); |
| 619 | 621 | }else if( *zURL=='/' ){ |
| 620 | 622 | int n1 = (int)strlen(g.zBaseURL); |
| 621 | 623 | int n2 = (int)strlen(g.zTop); |
| 622 | 624 | if( g.zBaseURL[n1-1]=='/' ) zURL++; |
| @@ -696,11 +698,11 @@ | ||
| 696 | 698 | const char *zMethod = P("REQUEST_METHOD"); |
| 697 | 699 | if( zMethod==0 ) return 0; |
| 698 | 700 | if( strcmp(zMethod,"POST")!=0 ) return 0; |
| 699 | 701 | } |
| 700 | 702 | 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; | |
| 702 | 704 | if( zRef[nBase]!=0 && zRef[nBase]!='/' ) return 0; |
| 703 | 705 | return 1; |
| 704 | 706 | } |
| 705 | 707 | |
| 706 | 708 | /* |
| @@ -963,11 +965,12 @@ | ||
| 963 | 965 | int len = *pLen; |
| 964 | 966 | int i; |
| 965 | 967 | int nBoundary = strlen(zBoundary); |
| 966 | 968 | *pnContent = len; |
| 967 | 969 | 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 ){ | |
| 969 | 972 | if( i>0 && z[i-1]=='\r' ) i--; |
| 970 | 973 | z[i] = 0; |
| 971 | 974 | *pnContent = i; |
| 972 | 975 | i += nBoundary; |
| 973 | 976 | break; |
| @@ -1391,11 +1394,11 @@ | ||
| 1391 | 1394 | */ |
| 1392 | 1395 | void cgi_decode_post_parameters(void){ |
| 1393 | 1396 | int len = blob_size(&g.cgiIn); |
| 1394 | 1397 | if( len==0 ) return; |
| 1395 | 1398 | 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 | |
| 1397 | 1400 | ){ |
| 1398 | 1401 | char *z = blob_str(&g.cgiIn); |
| 1399 | 1402 | cgi_trace(z); |
| 1400 | 1403 | if( g.zContentType[0]=='a' ){ |
| 1401 | 1404 | add_param_list(z, '&'); |
| @@ -2369,11 +2372,11 @@ | ||
| 2369 | 2372 | if( zBrowser ){ |
| 2370 | 2373 | assert( strstr(zBrowser,"%d")!=0 ); |
| 2371 | 2374 | zBrowser = mprintf(zBrowser /*works-like:"%d"*/, iPort); |
| 2372 | 2375 | #if defined(__CYGWIN__) |
| 2373 | 2376 | /* On Cygwin, we can do better than "echo" */ |
| 2374 | - if( strncmp(zBrowser, "echo ", 5)==0 ){ | |
| 2377 | + if( fossil_strncmp(zBrowser, "echo ", 5)==0 ){ | |
| 2375 | 2378 | wchar_t *wUrl = fossil_utf8_to_unicode(zBrowser+5); |
| 2376 | 2379 | wUrl[wcslen(wUrl)-2] = 0; /* Strip terminating " &" */ |
| 2377 | 2380 | if( (size_t)ShellExecuteW(0, L"open", wUrl, 0, 0, 1)<33 ){ |
| 2378 | 2381 | fossil_warning("cannot start browser\n"); |
| 2379 | 2382 | } |
| @@ -2529,11 +2532,11 @@ | ||
| 2529 | 2532 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 0}; |
| 2530 | 2533 | if( 7==sscanf(zDate, "%3[A-Za-z], %d %3[A-Za-z] %d %d:%d:%d", zIgnore, |
| 2531 | 2534 | &mday, zMonth, &year, &hour, &min, &sec)){ |
| 2532 | 2535 | if( year > 1900 ) year -= 1900; |
| 2533 | 2536 | for(mon=0; azMonths[mon]; mon++){ |
| 2534 | - if( !strncmp( azMonths[mon], zMonth, 3 )){ | |
| 2537 | + if( !fossil_strncmp( azMonths[mon], zMonth, 3 )){ | |
| 2535 | 2538 | int nDay; |
| 2536 | 2539 | int isLeapYr; |
| 2537 | 2540 | static int priorDays[] = |
| 2538 | 2541 | { 0, 31, 59, 90,120,151,181,212,243,273,304,334 }; |
| 2539 | 2542 | if( mon<0 ){ |
| 2540 | 2543 |
| --- 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 |