Fossil SCM

more minor internal cleanups. s/g.isCGI/g.isHTTP/ to avoid confusion later on.

stephan 2011-09-20 16:45 UTC json
Commit 9adc95c47600c561e307fe2f9d7ff3a2107120c6
4 files changed +2 -2 +1 -1 +29 -24 +5 -5
+2 -2
--- src/cgi.c
+++ src/cgi.c
@@ -765,11 +765,11 @@
765765
void cgi_init(void){
766766
char *z;
767767
const char *zType;
768768
int len;
769769
json_main_bootstrap();
770
- g.isCGI = 1;
770
+ g.isHTTP = 1;
771771
cgi_destination(CGI_BODY);
772772
773773
z = (char*)P("HTTP_COOKIE");
774774
if( z ){
775775
z = mprintf("%s",z);
@@ -1053,11 +1053,11 @@
10531053
va_start(ap, zFormat);
10541054
zMsg = vmprintf(zFormat,ap);
10551055
va_end(ap);
10561056
json_err( FSL_JSON_E_PANIC, zMsg, 1 );
10571057
free(zMsg);
1058
- fossil_exit( g.isCGI ? 0 : 1 );
1058
+ fossil_exit( g.isHTTP ? 0 : 1 );
10591059
}else{
10601060
cgi_set_status(500, "Internal Server Error");
10611061
cgi_printf(
10621062
"<html><body><h1>Internal Server Error</h1>\n"
10631063
"<plaintext>"
10641064
--- src/cgi.c
+++ src/cgi.c
@@ -765,11 +765,11 @@
765 void cgi_init(void){
766 char *z;
767 const char *zType;
768 int len;
769 json_main_bootstrap();
770 g.isCGI = 1;
771 cgi_destination(CGI_BODY);
772
773 z = (char*)P("HTTP_COOKIE");
774 if( z ){
775 z = mprintf("%s",z);
@@ -1053,11 +1053,11 @@
1053 va_start(ap, zFormat);
1054 zMsg = vmprintf(zFormat,ap);
1055 va_end(ap);
1056 json_err( FSL_JSON_E_PANIC, zMsg, 1 );
1057 free(zMsg);
1058 fossil_exit( g.isCGI ? 0 : 1 );
1059 }else{
1060 cgi_set_status(500, "Internal Server Error");
1061 cgi_printf(
1062 "<html><body><h1>Internal Server Error</h1>\n"
1063 "<plaintext>"
1064
--- src/cgi.c
+++ src/cgi.c
@@ -765,11 +765,11 @@
765 void cgi_init(void){
766 char *z;
767 const char *zType;
768 int len;
769 json_main_bootstrap();
770 g.isHTTP = 1;
771 cgi_destination(CGI_BODY);
772
773 z = (char*)P("HTTP_COOKIE");
774 if( z ){
775 z = mprintf("%s",z);
@@ -1053,11 +1053,11 @@
1053 va_start(ap, zFormat);
1054 zMsg = vmprintf(zFormat,ap);
1055 va_end(ap);
1056 json_err( FSL_JSON_E_PANIC, zMsg, 1 );
1057 free(zMsg);
1058 fossil_exit( g.isHTTP ? 0 : 1 );
1059 }else{
1060 cgi_set_status(500, "Internal Server Error");
1061 cgi_printf(
1062 "<html><body><h1>Internal Server Error</h1>\n"
1063 "<plaintext>"
1064
+1 -1
--- src/db.c
+++ src/db.c
@@ -66,11 +66,11 @@
6666
va_start(ap, zFormat);
6767
z = vmprintf(zFormat, ap);
6868
va_end(ap);
6969
if( g.json.isJsonMode ){
7070
json_err( 0, z, 1 );
71
- if( g.isCGI ){
71
+ if( g.isHTTP ){
7272
rc = 0 /* avoid HTTP 500 */;
7373
}
7474
}else{
7575
if( g.xferPanic ){
7676
cgi_reset_content();
7777
--- src/db.c
+++ src/db.c
@@ -66,11 +66,11 @@
66 va_start(ap, zFormat);
67 z = vmprintf(zFormat, ap);
68 va_end(ap);
69 if( g.json.isJsonMode ){
70 json_err( 0, z, 1 );
71 if( g.isCGI ){
72 rc = 0 /* avoid HTTP 500 */;
73 }
74 }else{
75 if( g.xferPanic ){
76 cgi_reset_content();
77
--- src/db.c
+++ src/db.c
@@ -66,11 +66,11 @@
66 va_start(ap, zFormat);
67 z = vmprintf(zFormat, ap);
68 va_end(ap);
69 if( g.json.isJsonMode ){
70 json_err( 0, z, 1 );
71 if( g.isHTTP ){
72 rc = 0 /* avoid HTTP 500 */;
73 }
74 }else{
75 if( g.xferPanic ){
76 cgi_reset_content();
77
+29 -24
--- src/json.c
+++ src/json.c
@@ -407,11 +407,11 @@
407407
408408
Then again, the hardened cookie value helps ensure that
409409
only a proper key/value match is valid.
410410
*/
411411
cgi_replace_parameter( login_cookie_name(), cson_value_get_cstr(g.json.authToken) );
412
- }else if( g.isCGI ){
412
+ }else if( g.isHTTP ){
413413
/* try fossil's conventional cookie. */
414414
/* Reminder: chicken/egg scenario regarding db access in CLI
415415
mode because login_cookie_name() needs the db. CLI
416416
mode does not use any authentication, so we don't need
417417
to support it here.
@@ -490,13 +490,13 @@
490490
once = 1;
491491
}
492492
g.json.isJsonMode = 1;
493493
g.json.resultCode = 0;
494494
g.json.cmd.offset = -1;
495
- if( !g.isCGI && g.fullHttpReply ){
495
+ if( !g.isHTTP && g.fullHttpReply ){
496496
/* workaround for server mode, so we see it as CGI mode. */
497
- g.isCGI = 1;
497
+ g.isHTTP = 1;
498498
}
499499
if(! g.json.post.v ){
500500
/* If cgi_init() reads POSTed JSON then it sets the content type.
501501
If it did not then we need to set it.
502502
*/
@@ -522,26 +522,31 @@
522522
*/
523523
if( zPath ){/* Either CGI or server mode... */
524524
/* Translate PATH_INFO into JSON for later convenience. */
525525
char const * p = zPath /* current byte */;
526526
char const * head = p /* current start-of-token */;
527
- unsigned int len = 0 /* current token's lengh */;
528
- assert( g.isCGI && "g.isCGI should have been set by now." );
527
+ unsigned int len = 0 /* current token's length */;
528
+ assert( g.isHTTP && "g.isHTTP should have been set by now." );
529529
for( ; ; ++p){
530530
if( !*p || ('/' == *p) ){
531
- if( len ){
532
- cson_value * part;
533
- char * zPart;
531
+ if( len ){/* append head..(head+len) as next array
532
+ element. */
533
+ cson_value * part = NULL;
534
+ char * zPart = NULL;
534535
assert( head != p );
535536
zPart = (char*)malloc(len+1);
536
- assert( zPart != NULL );
537
+ assert( (zPart != NULL) && "malloc failure" );
537538
memcpy(zPart, head, len);
538539
zPart[len] = 0;
539540
dehttpize(zPart);
540
- part = cson_value_new_string(zPart, strlen(zPart));
541
+ if( *zPart ){ /* should only fail if someone manages to url-encoded a NUL byte */
542
+ part = cson_value_new_string(zPart, strlen(zPart));
543
+ cson_array_append( g.json.cmd.a, part );
544
+ }else{
545
+ assert(0 && "i didn't think this was possible!");
546
+ }
541547
free(zPart);
542
- cson_array_append( g.json.cmd.a, part );
543548
len = 0;
544549
}
545550
if( !*p ){
546551
break;
547552
}
@@ -575,11 +580,11 @@
575580
g.json.reqPayload.v is-not-a Object.
576581
*/;
577582
}
578583
579584
{/* set up JSON output formatting options. */
580
- unsigned char indent = g.isCGI ? 0 : 1;
585
+ unsigned char indent = g.isHTTP ? 0 : 1;
581586
cson_value const * indentV = json_getenv("indent");
582587
if(indentV){
583588
if(cson_value_is_string(indentV)){
584589
int const n = atoi(cson_string_cstr(cson_value_get_string(indentV)));
585590
indent = (n>0)
@@ -589,14 +594,14 @@
589594
cson_int_t const n = cson_value_get_integer(indentV);
590595
indent = (n>0) ? (unsigned char)n : 0;
591596
}
592597
}
593598
g.json.outOpt.indentation = indent;
594
- g.json.outOpt.addNewline = g.isCGI ? 0 : 1;
599
+ g.json.outOpt.addNewline = g.isHTTP ? 0 : 1;
595600
}
596601
597
- if( g.isCGI ){
602
+ if( g.isHTTP ){
598603
json_auth_token()/* will copy our auth token, if any, to fossil's
599604
core, which we need before we call
600605
login_check_credentials(). */;
601606
login_check_credentials()/* populates g.perm */;
602607
}
@@ -625,11 +630,11 @@
625630
cson_value_get_string( \
626631
cson_array_get(ar,i) \
627632
))
628633
char const * tok = NEXT;
629634
while( tok ){
630
- if( !g.isCGI/*workaround for "abbreviated name" in CLI mode*/
635
+ if( !g.isHTTP/*workaround for "abbreviated name" in CLI mode*/
631636
? (0==strcmp(g.argv[1],tok))
632637
: (0==strncmp("json",tok,4))
633638
){
634639
g.json.cmd.offset = i;
635640
break;
@@ -835,11 +840,11 @@
835840
SET("$params");
836841
}
837842
if(0){/*Only for debuggering, add some info to the response.*/
838843
tmp = cson_value_new_integer( g.json.cmd.offset );
839844
cson_object_set( o, "cmd.offset", tmp );
840
- cson_object_set( o, "isCGI", cson_value_new_bool( g.isCGI ) );
845
+ cson_object_set( o, "isCGI", cson_value_new_bool( g.isHTTP ) );
841846
}
842847
}
843848
844849
/* Only add the payload to SUCCESS responses. Else delete it. */
845850
if( NULL != payload ){
@@ -865,20 +870,20 @@
865870
** Outputs a JSON error response to either the cgi_xxx() family of
866871
** buffers (in CGI/server mode) or stdout (in CLI mode). If rc is 0
867872
** then g.json.resultCode is used. If that is also 0 then the "Unknown
868873
** Error" code is used.
869874
**
870
-** If g.isCGI then the generated JSON error response object replaces
875
+** If g.isHTTP then the generated JSON error response object replaces
871876
** any currently buffered page output. Because the output goes via
872877
** the cgi_xxx() family of functions, this function inherits any
873878
** compression which fossil does for its output.
874879
**
875
-** If alsoOutput is true AND g.isCGI then cgi_reply() is called to
880
+** If alsoOutput is true AND g.isHTTP then cgi_reply() is called to
876881
** flush the output (and headers). Generally only do this if you are
877882
** about to call exit().
878883
**
879
-** !g.isCGI then alsoOutput is ignored and all output is sent to
884
+** !g.isHTTP then alsoOutput is ignored and all output is sent to
880885
** stdout immediately.
881886
**
882887
*/
883888
void json_err( int code, char const * msg, char alsoOutput ){
884889
int rc = code ? code : (g.json.resultCode
@@ -896,11 +901,11 @@
896901
*/
897902
fprintf(stderr, "%s: Fatal error: could not allocate "
898903
"response object.\n", fossil_nameofexe());
899904
fossil_exit(1);
900905
}
901
- if( g.isCGI ){
906
+ if( g.isHTTP ){
902907
Blob buf = empty_blob;
903908
cgi_reset_content();
904909
cson_output_Blob( resp, &buf, &g.json.outOpt );
905910
cgi_set_content(&buf);
906911
if( alsoOutput ){
@@ -1133,13 +1138,13 @@
11331138
** Impl of /json/logout.
11341139
**
11351140
*/
11361141
cson_value * json_page_logout(unsigned int depth){
11371142
cson_value const *token = g.json.authToken;
1138
- /* Remember that json_bootstrap() replaces the login cookie with
1139
- the JSON auth token if the request contains it. If the reqest
1140
- is missing the auth token then this will fetch fossil's
1143
+ /* Remember that json_mode_bootstrap() replaces the login cookie
1144
+ with the JSON auth token if the request contains it. If the
1145
+ reqest is missing the auth token then this will fetch fossil's
11411146
original cookie. Either way, it's what we want :).
11421147
11431148
We require the auth token to avoid someone maliciously
11441149
trying to log someone else out (not 100% sure if that
11451150
would be possible, given fossil's hardened cookie, but
@@ -1508,11 +1513,11 @@
15081513
json_err(g.json.resultCode, NULL, 1);
15091514
}else{
15101515
payload = json_create_response(rc, payload, NULL);
15111516
cson_output_FILE( payload, stdout, &g.json.outOpt );
15121517
cson_value_free( payload );
1513
- if((0 != rc) && !g.isCGI){
1518
+ if((0 != rc) && !g.isHTTP){
15141519
/* FIXME: we need a way of passing this error back
15151520
up to the routine which called this callback.
15161521
e.g. add g.errCode.
15171522
*/
15181523
fossil_exit(1);
15191524
--- src/json.c
+++ src/json.c
@@ -407,11 +407,11 @@
407
408 Then again, the hardened cookie value helps ensure that
409 only a proper key/value match is valid.
410 */
411 cgi_replace_parameter( login_cookie_name(), cson_value_get_cstr(g.json.authToken) );
412 }else if( g.isCGI ){
413 /* try fossil's conventional cookie. */
414 /* Reminder: chicken/egg scenario regarding db access in CLI
415 mode because login_cookie_name() needs the db. CLI
416 mode does not use any authentication, so we don't need
417 to support it here.
@@ -490,13 +490,13 @@
490 once = 1;
491 }
492 g.json.isJsonMode = 1;
493 g.json.resultCode = 0;
494 g.json.cmd.offset = -1;
495 if( !g.isCGI && g.fullHttpReply ){
496 /* workaround for server mode, so we see it as CGI mode. */
497 g.isCGI = 1;
498 }
499 if(! g.json.post.v ){
500 /* If cgi_init() reads POSTed JSON then it sets the content type.
501 If it did not then we need to set it.
502 */
@@ -522,26 +522,31 @@
522 */
523 if( zPath ){/* Either CGI or server mode... */
524 /* Translate PATH_INFO into JSON for later convenience. */
525 char const * p = zPath /* current byte */;
526 char const * head = p /* current start-of-token */;
527 unsigned int len = 0 /* current token's lengh */;
528 assert( g.isCGI && "g.isCGI should have been set by now." );
529 for( ; ; ++p){
530 if( !*p || ('/' == *p) ){
531 if( len ){
532 cson_value * part;
533 char * zPart;
 
534 assert( head != p );
535 zPart = (char*)malloc(len+1);
536 assert( zPart != NULL );
537 memcpy(zPart, head, len);
538 zPart[len] = 0;
539 dehttpize(zPart);
540 part = cson_value_new_string(zPart, strlen(zPart));
 
 
 
 
 
541 free(zPart);
542 cson_array_append( g.json.cmd.a, part );
543 len = 0;
544 }
545 if( !*p ){
546 break;
547 }
@@ -575,11 +580,11 @@
575 g.json.reqPayload.v is-not-a Object.
576 */;
577 }
578
579 {/* set up JSON output formatting options. */
580 unsigned char indent = g.isCGI ? 0 : 1;
581 cson_value const * indentV = json_getenv("indent");
582 if(indentV){
583 if(cson_value_is_string(indentV)){
584 int const n = atoi(cson_string_cstr(cson_value_get_string(indentV)));
585 indent = (n>0)
@@ -589,14 +594,14 @@
589 cson_int_t const n = cson_value_get_integer(indentV);
590 indent = (n>0) ? (unsigned char)n : 0;
591 }
592 }
593 g.json.outOpt.indentation = indent;
594 g.json.outOpt.addNewline = g.isCGI ? 0 : 1;
595 }
596
597 if( g.isCGI ){
598 json_auth_token()/* will copy our auth token, if any, to fossil's
599 core, which we need before we call
600 login_check_credentials(). */;
601 login_check_credentials()/* populates g.perm */;
602 }
@@ -625,11 +630,11 @@
625 cson_value_get_string( \
626 cson_array_get(ar,i) \
627 ))
628 char const * tok = NEXT;
629 while( tok ){
630 if( !g.isCGI/*workaround for "abbreviated name" in CLI mode*/
631 ? (0==strcmp(g.argv[1],tok))
632 : (0==strncmp("json",tok,4))
633 ){
634 g.json.cmd.offset = i;
635 break;
@@ -835,11 +840,11 @@
835 SET("$params");
836 }
837 if(0){/*Only for debuggering, add some info to the response.*/
838 tmp = cson_value_new_integer( g.json.cmd.offset );
839 cson_object_set( o, "cmd.offset", tmp );
840 cson_object_set( o, "isCGI", cson_value_new_bool( g.isCGI ) );
841 }
842 }
843
844 /* Only add the payload to SUCCESS responses. Else delete it. */
845 if( NULL != payload ){
@@ -865,20 +870,20 @@
865 ** Outputs a JSON error response to either the cgi_xxx() family of
866 ** buffers (in CGI/server mode) or stdout (in CLI mode). If rc is 0
867 ** then g.json.resultCode is used. If that is also 0 then the "Unknown
868 ** Error" code is used.
869 **
870 ** If g.isCGI then the generated JSON error response object replaces
871 ** any currently buffered page output. Because the output goes via
872 ** the cgi_xxx() family of functions, this function inherits any
873 ** compression which fossil does for its output.
874 **
875 ** If alsoOutput is true AND g.isCGI then cgi_reply() is called to
876 ** flush the output (and headers). Generally only do this if you are
877 ** about to call exit().
878 **
879 ** !g.isCGI then alsoOutput is ignored and all output is sent to
880 ** stdout immediately.
881 **
882 */
883 void json_err( int code, char const * msg, char alsoOutput ){
884 int rc = code ? code : (g.json.resultCode
@@ -896,11 +901,11 @@
896 */
897 fprintf(stderr, "%s: Fatal error: could not allocate "
898 "response object.\n", fossil_nameofexe());
899 fossil_exit(1);
900 }
901 if( g.isCGI ){
902 Blob buf = empty_blob;
903 cgi_reset_content();
904 cson_output_Blob( resp, &buf, &g.json.outOpt );
905 cgi_set_content(&buf);
906 if( alsoOutput ){
@@ -1133,13 +1138,13 @@
1133 ** Impl of /json/logout.
1134 **
1135 */
1136 cson_value * json_page_logout(unsigned int depth){
1137 cson_value const *token = g.json.authToken;
1138 /* Remember that json_bootstrap() replaces the login cookie with
1139 the JSON auth token if the request contains it. If the reqest
1140 is missing the auth token then this will fetch fossil's
1141 original cookie. Either way, it's what we want :).
1142
1143 We require the auth token to avoid someone maliciously
1144 trying to log someone else out (not 100% sure if that
1145 would be possible, given fossil's hardened cookie, but
@@ -1508,11 +1513,11 @@
1508 json_err(g.json.resultCode, NULL, 1);
1509 }else{
1510 payload = json_create_response(rc, payload, NULL);
1511 cson_output_FILE( payload, stdout, &g.json.outOpt );
1512 cson_value_free( payload );
1513 if((0 != rc) && !g.isCGI){
1514 /* FIXME: we need a way of passing this error back
1515 up to the routine which called this callback.
1516 e.g. add g.errCode.
1517 */
1518 fossil_exit(1);
1519
--- src/json.c
+++ src/json.c
@@ -407,11 +407,11 @@
407
408 Then again, the hardened cookie value helps ensure that
409 only a proper key/value match is valid.
410 */
411 cgi_replace_parameter( login_cookie_name(), cson_value_get_cstr(g.json.authToken) );
412 }else if( g.isHTTP ){
413 /* try fossil's conventional cookie. */
414 /* Reminder: chicken/egg scenario regarding db access in CLI
415 mode because login_cookie_name() needs the db. CLI
416 mode does not use any authentication, so we don't need
417 to support it here.
@@ -490,13 +490,13 @@
490 once = 1;
491 }
492 g.json.isJsonMode = 1;
493 g.json.resultCode = 0;
494 g.json.cmd.offset = -1;
495 if( !g.isHTTP && g.fullHttpReply ){
496 /* workaround for server mode, so we see it as CGI mode. */
497 g.isHTTP = 1;
498 }
499 if(! g.json.post.v ){
500 /* If cgi_init() reads POSTed JSON then it sets the content type.
501 If it did not then we need to set it.
502 */
@@ -522,26 +522,31 @@
522 */
523 if( zPath ){/* Either CGI or server mode... */
524 /* Translate PATH_INFO into JSON for later convenience. */
525 char const * p = zPath /* current byte */;
526 char const * head = p /* current start-of-token */;
527 unsigned int len = 0 /* current token's length */;
528 assert( g.isHTTP && "g.isHTTP should have been set by now." );
529 for( ; ; ++p){
530 if( !*p || ('/' == *p) ){
531 if( len ){/* append head..(head+len) as next array
532 element. */
533 cson_value * part = NULL;
534 char * zPart = NULL;
535 assert( head != p );
536 zPart = (char*)malloc(len+1);
537 assert( (zPart != NULL) && "malloc failure" );
538 memcpy(zPart, head, len);
539 zPart[len] = 0;
540 dehttpize(zPart);
541 if( *zPart ){ /* should only fail if someone manages to url-encoded a NUL byte */
542 part = cson_value_new_string(zPart, strlen(zPart));
543 cson_array_append( g.json.cmd.a, part );
544 }else{
545 assert(0 && "i didn't think this was possible!");
546 }
547 free(zPart);
 
548 len = 0;
549 }
550 if( !*p ){
551 break;
552 }
@@ -575,11 +580,11 @@
580 g.json.reqPayload.v is-not-a Object.
581 */;
582 }
583
584 {/* set up JSON output formatting options. */
585 unsigned char indent = g.isHTTP ? 0 : 1;
586 cson_value const * indentV = json_getenv("indent");
587 if(indentV){
588 if(cson_value_is_string(indentV)){
589 int const n = atoi(cson_string_cstr(cson_value_get_string(indentV)));
590 indent = (n>0)
@@ -589,14 +594,14 @@
594 cson_int_t const n = cson_value_get_integer(indentV);
595 indent = (n>0) ? (unsigned char)n : 0;
596 }
597 }
598 g.json.outOpt.indentation = indent;
599 g.json.outOpt.addNewline = g.isHTTP ? 0 : 1;
600 }
601
602 if( g.isHTTP ){
603 json_auth_token()/* will copy our auth token, if any, to fossil's
604 core, which we need before we call
605 login_check_credentials(). */;
606 login_check_credentials()/* populates g.perm */;
607 }
@@ -625,11 +630,11 @@
630 cson_value_get_string( \
631 cson_array_get(ar,i) \
632 ))
633 char const * tok = NEXT;
634 while( tok ){
635 if( !g.isHTTP/*workaround for "abbreviated name" in CLI mode*/
636 ? (0==strcmp(g.argv[1],tok))
637 : (0==strncmp("json",tok,4))
638 ){
639 g.json.cmd.offset = i;
640 break;
@@ -835,11 +840,11 @@
840 SET("$params");
841 }
842 if(0){/*Only for debuggering, add some info to the response.*/
843 tmp = cson_value_new_integer( g.json.cmd.offset );
844 cson_object_set( o, "cmd.offset", tmp );
845 cson_object_set( o, "isCGI", cson_value_new_bool( g.isHTTP ) );
846 }
847 }
848
849 /* Only add the payload to SUCCESS responses. Else delete it. */
850 if( NULL != payload ){
@@ -865,20 +870,20 @@
870 ** Outputs a JSON error response to either the cgi_xxx() family of
871 ** buffers (in CGI/server mode) or stdout (in CLI mode). If rc is 0
872 ** then g.json.resultCode is used. If that is also 0 then the "Unknown
873 ** Error" code is used.
874 **
875 ** If g.isHTTP then the generated JSON error response object replaces
876 ** any currently buffered page output. Because the output goes via
877 ** the cgi_xxx() family of functions, this function inherits any
878 ** compression which fossil does for its output.
879 **
880 ** If alsoOutput is true AND g.isHTTP then cgi_reply() is called to
881 ** flush the output (and headers). Generally only do this if you are
882 ** about to call exit().
883 **
884 ** !g.isHTTP then alsoOutput is ignored and all output is sent to
885 ** stdout immediately.
886 **
887 */
888 void json_err( int code, char const * msg, char alsoOutput ){
889 int rc = code ? code : (g.json.resultCode
@@ -896,11 +901,11 @@
901 */
902 fprintf(stderr, "%s: Fatal error: could not allocate "
903 "response object.\n", fossil_nameofexe());
904 fossil_exit(1);
905 }
906 if( g.isHTTP ){
907 Blob buf = empty_blob;
908 cgi_reset_content();
909 cson_output_Blob( resp, &buf, &g.json.outOpt );
910 cgi_set_content(&buf);
911 if( alsoOutput ){
@@ -1133,13 +1138,13 @@
1138 ** Impl of /json/logout.
1139 **
1140 */
1141 cson_value * json_page_logout(unsigned int depth){
1142 cson_value const *token = g.json.authToken;
1143 /* Remember that json_mode_bootstrap() replaces the login cookie
1144 with the JSON auth token if the request contains it. If the
1145 reqest is missing the auth token then this will fetch fossil's
1146 original cookie. Either way, it's what we want :).
1147
1148 We require the auth token to avoid someone maliciously
1149 trying to log someone else out (not 100% sure if that
1150 would be possible, given fossil's hardened cookie, but
@@ -1508,11 +1513,11 @@
1513 json_err(g.json.resultCode, NULL, 1);
1514 }else{
1515 payload = json_create_response(rc, payload, NULL);
1516 cson_output_FILE( payload, stdout, &g.json.outOpt );
1517 cson_value_free( payload );
1518 if((0 != rc) && !g.isHTTP){
1519 /* FIXME: we need a way of passing this error back
1520 up to the routine which called this callback.
1521 e.g. add g.errCode.
1522 */
1523 fossil_exit(1);
1524
+5 -5
--- src/main.c
+++ src/main.c
@@ -116,11 +116,11 @@
116116
int xlinkClusterOnly; /* Set when cloning. Only process clusters */
117117
int fTimeFormat; /* 1 for UTC. 2 for localtime. 0 not yet selected */
118118
int *aCommitFile; /* Array of files to be committed */
119119
int markPrivate; /* All new artifacts are private if true */
120120
int clockSkewSeen; /* True if clocks on client and server out of sync */
121
- int isCGI; /* True if running in server/CGI modes, else assume CLI. */
121
+ int isHTTP; /* True if running in server/CGI modes, else assume CLI. */
122122
123123
int urlIsFile; /* True if a "file:" url */
124124
int urlIsHttps; /* True if a "https:" url */
125125
int urlIsSsh; /* True if an "ssh:" url */
126126
char *urlName; /* Hostname for http: or filename for file: */
@@ -314,18 +314,18 @@
314314
g.json.outOpt.addNewline = 1;
315315
g.json.outOpt.indentation = 1 /* in CGI/server mode this can be configured */;
316316
for(i=0; i<argc; i++) g.argv[i] = fossil_mbcs_to_utf8(argv[i]);
317317
if( getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
318318
zCmdName = "cgi";
319
- g.isCGI = 1;
319
+ g.isHTTP = 1;
320320
}else if( argc<2 ){
321321
fossil_fatal("Usage: %s COMMAND ...\n"
322322
"\"%s help\" for a list of available commands\n"
323323
"\"%s help COMMAND\" for specific details\n",
324324
argv[0], argv[0], argv[0]);
325325
}else{
326
- g.isCGI = 0;
326
+ g.isHTTP = 0;
327327
g.fQuiet = find_option("quiet", 0, 0)!=0;
328328
g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
329329
g.fSqlStats = find_option("sqlstats", 0, 0)!=0;
330330
g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
331331
if( g.fSqlTrace ) g.fSqlStats = 1;
@@ -418,11 +418,11 @@
418418
va_start(ap, zFormat);
419419
z = vmprintf(zFormat, ap);
420420
va_end(ap);
421421
if( g.json.isJsonMode ){
422422
json_err( 0, z, 1 );
423
- if( g.isCGI ){
423
+ if( g.isHTTP ){
424424
rc = 0 /* avoid HTTP 500 */;
425425
}
426426
}else if( g.cgiOutput && once ){
427427
once = 0;
428428
cgi_printf("<p class=\"generalError\">%h</p>", z);
@@ -444,11 +444,11 @@
444444
va_start(ap, zFormat);
445445
z = vmprintf(zFormat, ap);
446446
va_end(ap);
447447
if( g.json.isJsonMode ){
448448
json_err( g.json.resultCode, z, 1 );
449
- if( g.isCGI ){
449
+ if( g.isHTTP ){
450450
rc = 0 /* avoid HTTP 500 */;
451451
}
452452
}
453453
else if( g.cgiOutput ){
454454
g.cgiOutput = 0;
455455
--- src/main.c
+++ src/main.c
@@ -116,11 +116,11 @@
116 int xlinkClusterOnly; /* Set when cloning. Only process clusters */
117 int fTimeFormat; /* 1 for UTC. 2 for localtime. 0 not yet selected */
118 int *aCommitFile; /* Array of files to be committed */
119 int markPrivate; /* All new artifacts are private if true */
120 int clockSkewSeen; /* True if clocks on client and server out of sync */
121 int isCGI; /* True if running in server/CGI modes, else assume CLI. */
122
123 int urlIsFile; /* True if a "file:" url */
124 int urlIsHttps; /* True if a "https:" url */
125 int urlIsSsh; /* True if an "ssh:" url */
126 char *urlName; /* Hostname for http: or filename for file: */
@@ -314,18 +314,18 @@
314 g.json.outOpt.addNewline = 1;
315 g.json.outOpt.indentation = 1 /* in CGI/server mode this can be configured */;
316 for(i=0; i<argc; i++) g.argv[i] = fossil_mbcs_to_utf8(argv[i]);
317 if( getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
318 zCmdName = "cgi";
319 g.isCGI = 1;
320 }else if( argc<2 ){
321 fossil_fatal("Usage: %s COMMAND ...\n"
322 "\"%s help\" for a list of available commands\n"
323 "\"%s help COMMAND\" for specific details\n",
324 argv[0], argv[0], argv[0]);
325 }else{
326 g.isCGI = 0;
327 g.fQuiet = find_option("quiet", 0, 0)!=0;
328 g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
329 g.fSqlStats = find_option("sqlstats", 0, 0)!=0;
330 g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
331 if( g.fSqlTrace ) g.fSqlStats = 1;
@@ -418,11 +418,11 @@
418 va_start(ap, zFormat);
419 z = vmprintf(zFormat, ap);
420 va_end(ap);
421 if( g.json.isJsonMode ){
422 json_err( 0, z, 1 );
423 if( g.isCGI ){
424 rc = 0 /* avoid HTTP 500 */;
425 }
426 }else if( g.cgiOutput && once ){
427 once = 0;
428 cgi_printf("<p class=\"generalError\">%h</p>", z);
@@ -444,11 +444,11 @@
444 va_start(ap, zFormat);
445 z = vmprintf(zFormat, ap);
446 va_end(ap);
447 if( g.json.isJsonMode ){
448 json_err( g.json.resultCode, z, 1 );
449 if( g.isCGI ){
450 rc = 0 /* avoid HTTP 500 */;
451 }
452 }
453 else if( g.cgiOutput ){
454 g.cgiOutput = 0;
455
--- src/main.c
+++ src/main.c
@@ -116,11 +116,11 @@
116 int xlinkClusterOnly; /* Set when cloning. Only process clusters */
117 int fTimeFormat; /* 1 for UTC. 2 for localtime. 0 not yet selected */
118 int *aCommitFile; /* Array of files to be committed */
119 int markPrivate; /* All new artifacts are private if true */
120 int clockSkewSeen; /* True if clocks on client and server out of sync */
121 int isHTTP; /* True if running in server/CGI modes, else assume CLI. */
122
123 int urlIsFile; /* True if a "file:" url */
124 int urlIsHttps; /* True if a "https:" url */
125 int urlIsSsh; /* True if an "ssh:" url */
126 char *urlName; /* Hostname for http: or filename for file: */
@@ -314,18 +314,18 @@
314 g.json.outOpt.addNewline = 1;
315 g.json.outOpt.indentation = 1 /* in CGI/server mode this can be configured */;
316 for(i=0; i<argc; i++) g.argv[i] = fossil_mbcs_to_utf8(argv[i]);
317 if( getenv("GATEWAY_INTERFACE")!=0 && !find_option("nocgi", 0, 0)){
318 zCmdName = "cgi";
319 g.isHTTP = 1;
320 }else if( argc<2 ){
321 fossil_fatal("Usage: %s COMMAND ...\n"
322 "\"%s help\" for a list of available commands\n"
323 "\"%s help COMMAND\" for specific details\n",
324 argv[0], argv[0], argv[0]);
325 }else{
326 g.isHTTP = 0;
327 g.fQuiet = find_option("quiet", 0, 0)!=0;
328 g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
329 g.fSqlStats = find_option("sqlstats", 0, 0)!=0;
330 g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
331 if( g.fSqlTrace ) g.fSqlStats = 1;
@@ -418,11 +418,11 @@
418 va_start(ap, zFormat);
419 z = vmprintf(zFormat, ap);
420 va_end(ap);
421 if( g.json.isJsonMode ){
422 json_err( 0, z, 1 );
423 if( g.isHTTP ){
424 rc = 0 /* avoid HTTP 500 */;
425 }
426 }else if( g.cgiOutput && once ){
427 once = 0;
428 cgi_printf("<p class=\"generalError\">%h</p>", z);
@@ -444,11 +444,11 @@
444 va_start(ap, zFormat);
445 z = vmprintf(zFormat, ap);
446 va_end(ap);
447 if( g.json.isJsonMode ){
448 json_err( g.json.resultCode, z, 1 );
449 if( g.isHTTP ){
450 rc = 0 /* avoid HTTP 500 */;
451 }
452 }
453 else if( g.cgiOutput ){
454 g.cgiOutput = 0;
455

Keyboard Shortcuts

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