| ︙ | | |
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
-
+
|
){
char const *zSecure = "";
if(!g.isHTTP) return /* e.g. JSON CLI mode, where g.zTop is not set */;
else if( zPath==0 ){
zPath = g.zTop;
if( zPath[0]==0 ) zPath = "/";
}
if( g.zBaseURL!=0 && strncmp(g.zBaseURL, "https:", 6)==0 ){
if( g.zBaseURL!=0 && fossil_strncmp(g.zBaseURL, "https:", 6)==0 ){
zSecure = " secure;";
}
if( lifetime!=0 ){
blob_appendf(&extraHeader,
"Set-Cookie: %s=%t; Path=%s; max-age=%d; HttpOnly; "
"%s Version=1\r\n",
zName, lifetime>0 ? zValue : "null", zPath, lifetime, zSecure);
|
| ︙ | | |
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
-
+
-
+
+
|
if( g.fNoHttpCompress ) return 0;
if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;
/* Maintenance note: this oddball structure is intended to make
** adding new mimetypes to this list less of a performance hit than
** doing a strcmp/glob over a growing set of compressible types. */
switch(zContentType ? *zContentType : 0){
case (int)'a':
if(0==strncmp("application/",zContentType,12)){
if(0==fossil_strncmp("application/",zContentType,12)){
const char * z = &zContentType[12];
switch(*z){
case (int)'j':
return fossil_strcmp("javascript", z)==0
|| fossil_strcmp("json", z)==0;
case (int)'w': return fossil_strcmp("wasm", z)==0;
case (int)'x':
return fossil_strcmp("x-tcl", z)==0
|| fossil_strcmp("x-tar", z)==0;
default:
return sqlite3_strglob("*xml", z)==0;
}
}
break;
case (int)'i':
return fossil_strcmp(zContentType, "image/svg+xml")==0;
return fossil_strcmp(zContentType, "image/svg+xml")==0
|| fossil_strcmp(zContentType, "image/vnd.microsoft.icon")==0;
case (int)'t':
return fossil_strncmp(zContentType, "text/", 5)==0;
}
return 0;
}
|
| ︙ | | |
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
|
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
|
-
-
+
+
|
** this. Previously we always appended the charset, but WASM loaders
** are pedantic and refuse to load any responses which have a
** charset. Also, adding a charset is not strictly appropriate for
** most types (and not required for many others which may ostensibly
** benefit from one, as detailed in that forum post).
*/
static const char * content_type_charset(const char *zContentType){
if(zContentType!=0){
if(0==strncmp(zContentType,"text/",5)) return "; charset=utf-8";
if(0==fossil_strncmp(zContentType,"text/",5)){
return "; charset=utf-8";
}
return "";
}
/*
** Generate the reply to a web request. The output might be an
** full HTTP response, or a CGI response, depending on how things have
|
| ︙ | | |
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
|
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
|
+
-
+
|
NORETURN void cgi_redirect_with_status(
const char *zURL,
int iStat,
const char *zStat
){
char *zLocation;
CGIDEBUG(("redirect to %s\n", zURL));
if( fossil_strncmp(zURL,"http:",5)==0
if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 ){
|| fossil_strncmp(zURL,"https:",6)==0 ){
zLocation = mprintf("Location: %s\r\n", zURL);
}else if( *zURL=='/' ){
int n1 = (int)strlen(g.zBaseURL);
int n2 = (int)strlen(g.zTop);
if( g.zBaseURL[n1-1]=='/' ) zURL++;
zLocation = mprintf("Location: %.*s%s\r\n", n1-n2, g.zBaseURL, zURL);
}else{
|
| ︙ | | |
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
|
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
|
-
+
|
if( zRef==0 ) return 0;
if( requirePost ){
const char *zMethod = P("REQUEST_METHOD");
if( zMethod==0 ) return 0;
if( strcmp(zMethod,"POST")!=0 ) return 0;
}
nBase = (int)strlen(g.zBaseURL);
if( strncmp(g.zBaseURL,zRef,nBase)!=0 ) return 0;
if( fossil_strncmp(g.zBaseURL,zRef,nBase)!=0 ) return 0;
if( zRef[nBase]!=0 && zRef[nBase]!='/' ) return 0;
return 1;
}
/*
** Information about all query parameters, post parameter, cookies and
** CGI environment variables are stored in a hash table as follows:
|
| ︙ | | |
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
|
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
|
-
+
+
|
){
char *z = *pz;
int len = *pLen;
int i;
int nBoundary = strlen(zBoundary);
*pnContent = len;
for(i=0; i<len; i++){
if( z[i]=='\n' && strncmp(zBoundary, &z[i+1], nBoundary)==0 ){
if( z[i]=='\n' && fossil_strncmp(zBoundary, &z[i+1],
nBoundary)==0 ){
if( i>0 && z[i-1]=='\r' ) i--;
z[i] = 0;
*pnContent = i;
i += nBoundary;
break;
}
}
|
| ︙ | | |
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
|
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
|
-
+
|
/*
** Decode POST parameter information in the cgiIn content, if any.
*/
void cgi_decode_post_parameters(void){
int len = blob_size(&g.cgiIn);
if( len==0 ) return;
if( fossil_strcmp(g.zContentType,"application/x-www-form-urlencoded")==0
|| strncmp(g.zContentType,"multipart/form-data",19)==0
|| fossil_strncmp(g.zContentType,"multipart/form-data",19)==0
){
char *z = blob_str(&g.cgiIn);
cgi_trace(z);
if( g.zContentType[0]=='a' ){
add_param_list(z, '&');
}else{
process_multipart_form_data(z, len);
|
| ︙ | | |
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
|
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
|
-
+
|
g.httpUseSSL?"TLS-encrypted HTTPS":"HTTP", iPort);
fflush(stdout);
if( zBrowser ){
assert( strstr(zBrowser,"%d")!=0 );
zBrowser = mprintf(zBrowser /*works-like:"%d"*/, iPort);
#if defined(__CYGWIN__)
/* On Cygwin, we can do better than "echo" */
if( strncmp(zBrowser, "echo ", 5)==0 ){
if( fossil_strncmp(zBrowser, "echo ", 5)==0 ){
wchar_t *wUrl = fossil_utf8_to_unicode(zBrowser+5);
wUrl[wcslen(wUrl)-2] = 0; /* Strip terminating " &" */
if( (size_t)ShellExecuteW(0, L"open", wUrl, 0, 0, 1)<33 ){
fossil_warning("cannot start browser\n");
}
}else
#endif
|
| ︙ | | |
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
|
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
|
-
+
|
static const char *const azMonths[] =
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 0};
if( 7==sscanf(zDate, "%3[A-Za-z], %d %3[A-Za-z] %d %d:%d:%d", zIgnore,
&mday, zMonth, &year, &hour, &min, &sec)){
if( year > 1900 ) year -= 1900;
for(mon=0; azMonths[mon]; mon++){
if( !strncmp( azMonths[mon], zMonth, 3 )){
if( !fossil_strncmp( azMonths[mon], zMonth, 3 )){
int nDay;
int isLeapYr;
static int priorDays[] =
{ 0, 31, 59, 90,120,151,181,212,243,273,304,334 };
if( mon<0 ){
int nYear = (11 - mon)/12;
year -= nYear;
|
| ︙ | | |