| | @@ -407,11 +407,11 @@ |
| 407 | 407 | |
| 408 | 408 | Then again, the hardened cookie value helps ensure that |
| 409 | 409 | only a proper key/value match is valid. |
| 410 | 410 | */ |
| 411 | 411 | cgi_replace_parameter( login_cookie_name(), cson_value_get_cstr(g.json.authToken) ); |
| 412 | | - }else if( g.isCGI ){ |
| 412 | + }else if( g.isHTTP ){ |
| 413 | 413 | /* try fossil's conventional cookie. */ |
| 414 | 414 | /* Reminder: chicken/egg scenario regarding db access in CLI |
| 415 | 415 | mode because login_cookie_name() needs the db. CLI |
| 416 | 416 | mode does not use any authentication, so we don't need |
| 417 | 417 | to support it here. |
| | @@ -490,13 +490,13 @@ |
| 490 | 490 | once = 1; |
| 491 | 491 | } |
| 492 | 492 | g.json.isJsonMode = 1; |
| 493 | 493 | g.json.resultCode = 0; |
| 494 | 494 | g.json.cmd.offset = -1; |
| 495 | | - if( !g.isCGI && g.fullHttpReply ){ |
| 495 | + if( !g.isHTTP && g.fullHttpReply ){ |
| 496 | 496 | /* workaround for server mode, so we see it as CGI mode. */ |
| 497 | | - g.isCGI = 1; |
| 497 | + g.isHTTP = 1; |
| 498 | 498 | } |
| 499 | 499 | if(! g.json.post.v ){ |
| 500 | 500 | /* If cgi_init() reads POSTed JSON then it sets the content type. |
| 501 | 501 | If it did not then we need to set it. |
| 502 | 502 | */ |
| | @@ -522,26 +522,31 @@ |
| 522 | 522 | */ |
| 523 | 523 | if( zPath ){/* Either CGI or server mode... */ |
| 524 | 524 | /* Translate PATH_INFO into JSON for later convenience. */ |
| 525 | 525 | char const * p = zPath /* current byte */; |
| 526 | 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." ); |
| 527 | + unsigned int len = 0 /* current token's length */; |
| 528 | + assert( g.isHTTP && "g.isHTTP should have been set by now." ); |
| 529 | 529 | for( ; ; ++p){ |
| 530 | 530 | 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; |
| 534 | 535 | assert( head != p ); |
| 535 | 536 | zPart = (char*)malloc(len+1); |
| 536 | | - assert( zPart != NULL ); |
| 537 | + assert( (zPart != NULL) && "malloc failure" ); |
| 537 | 538 | memcpy(zPart, head, len); |
| 538 | 539 | zPart[len] = 0; |
| 539 | 540 | 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 | + } |
| 541 | 547 | free(zPart); |
| 542 | | - cson_array_append( g.json.cmd.a, part ); |
| 543 | 548 | len = 0; |
| 544 | 549 | } |
| 545 | 550 | if( !*p ){ |
| 546 | 551 | break; |
| 547 | 552 | } |
| | @@ -575,11 +580,11 @@ |
| 575 | 580 | g.json.reqPayload.v is-not-a Object. |
| 576 | 581 | */; |
| 577 | 582 | } |
| 578 | 583 | |
| 579 | 584 | {/* set up JSON output formatting options. */ |
| 580 | | - unsigned char indent = g.isCGI ? 0 : 1; |
| 585 | + unsigned char indent = g.isHTTP ? 0 : 1; |
| 581 | 586 | cson_value const * indentV = json_getenv("indent"); |
| 582 | 587 | if(indentV){ |
| 583 | 588 | if(cson_value_is_string(indentV)){ |
| 584 | 589 | int const n = atoi(cson_string_cstr(cson_value_get_string(indentV))); |
| 585 | 590 | indent = (n>0) |
| | @@ -589,14 +594,14 @@ |
| 589 | 594 | cson_int_t const n = cson_value_get_integer(indentV); |
| 590 | 595 | indent = (n>0) ? (unsigned char)n : 0; |
| 591 | 596 | } |
| 592 | 597 | } |
| 593 | 598 | g.json.outOpt.indentation = indent; |
| 594 | | - g.json.outOpt.addNewline = g.isCGI ? 0 : 1; |
| 599 | + g.json.outOpt.addNewline = g.isHTTP ? 0 : 1; |
| 595 | 600 | } |
| 596 | 601 | |
| 597 | | - if( g.isCGI ){ |
| 602 | + if( g.isHTTP ){ |
| 598 | 603 | json_auth_token()/* will copy our auth token, if any, to fossil's |
| 599 | 604 | core, which we need before we call |
| 600 | 605 | login_check_credentials(). */; |
| 601 | 606 | login_check_credentials()/* populates g.perm */; |
| 602 | 607 | } |
| | @@ -625,11 +630,11 @@ |
| 625 | 630 | cson_value_get_string( \ |
| 626 | 631 | cson_array_get(ar,i) \ |
| 627 | 632 | )) |
| 628 | 633 | char const * tok = NEXT; |
| 629 | 634 | while( tok ){ |
| 630 | | - if( !g.isCGI/*workaround for "abbreviated name" in CLI mode*/ |
| 635 | + if( !g.isHTTP/*workaround for "abbreviated name" in CLI mode*/ |
| 631 | 636 | ? (0==strcmp(g.argv[1],tok)) |
| 632 | 637 | : (0==strncmp("json",tok,4)) |
| 633 | 638 | ){ |
| 634 | 639 | g.json.cmd.offset = i; |
| 635 | 640 | break; |
| | @@ -835,11 +840,11 @@ |
| 835 | 840 | SET("$params"); |
| 836 | 841 | } |
| 837 | 842 | if(0){/*Only for debuggering, add some info to the response.*/ |
| 838 | 843 | tmp = cson_value_new_integer( g.json.cmd.offset ); |
| 839 | 844 | 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 ) ); |
| 841 | 846 | } |
| 842 | 847 | } |
| 843 | 848 | |
| 844 | 849 | /* Only add the payload to SUCCESS responses. Else delete it. */ |
| 845 | 850 | if( NULL != payload ){ |
| | @@ -865,20 +870,20 @@ |
| 865 | 870 | ** Outputs a JSON error response to either the cgi_xxx() family of |
| 866 | 871 | ** buffers (in CGI/server mode) or stdout (in CLI mode). If rc is 0 |
| 867 | 872 | ** then g.json.resultCode is used. If that is also 0 then the "Unknown |
| 868 | 873 | ** Error" code is used. |
| 869 | 874 | ** |
| 870 | | -** If g.isCGI then the generated JSON error response object replaces |
| 875 | +** If g.isHTTP then the generated JSON error response object replaces |
| 871 | 876 | ** any currently buffered page output. Because the output goes via |
| 872 | 877 | ** the cgi_xxx() family of functions, this function inherits any |
| 873 | 878 | ** compression which fossil does for its output. |
| 874 | 879 | ** |
| 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 |
| 876 | 881 | ** flush the output (and headers). Generally only do this if you are |
| 877 | 882 | ** about to call exit(). |
| 878 | 883 | ** |
| 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 |
| 880 | 885 | ** stdout immediately. |
| 881 | 886 | ** |
| 882 | 887 | */ |
| 883 | 888 | void json_err( int code, char const * msg, char alsoOutput ){ |
| 884 | 889 | int rc = code ? code : (g.json.resultCode |
| | @@ -896,11 +901,11 @@ |
| 896 | 901 | */ |
| 897 | 902 | fprintf(stderr, "%s: Fatal error: could not allocate " |
| 898 | 903 | "response object.\n", fossil_nameofexe()); |
| 899 | 904 | fossil_exit(1); |
| 900 | 905 | } |
| 901 | | - if( g.isCGI ){ |
| 906 | + if( g.isHTTP ){ |
| 902 | 907 | Blob buf = empty_blob; |
| 903 | 908 | cgi_reset_content(); |
| 904 | 909 | cson_output_Blob( resp, &buf, &g.json.outOpt ); |
| 905 | 910 | cgi_set_content(&buf); |
| 906 | 911 | if( alsoOutput ){ |
| | @@ -1133,13 +1138,13 @@ |
| 1133 | 1138 | ** Impl of /json/logout. |
| 1134 | 1139 | ** |
| 1135 | 1140 | */ |
| 1136 | 1141 | cson_value * json_page_logout(unsigned int depth){ |
| 1137 | 1142 | 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 |
| 1141 | 1146 | original cookie. Either way, it's what we want :). |
| 1142 | 1147 | |
| 1143 | 1148 | We require the auth token to avoid someone maliciously |
| 1144 | 1149 | trying to log someone else out (not 100% sure if that |
| 1145 | 1150 | would be possible, given fossil's hardened cookie, but |
| | @@ -1508,11 +1513,11 @@ |
| 1508 | 1513 | json_err(g.json.resultCode, NULL, 1); |
| 1509 | 1514 | }else{ |
| 1510 | 1515 | payload = json_create_response(rc, payload, NULL); |
| 1511 | 1516 | cson_output_FILE( payload, stdout, &g.json.outOpt ); |
| 1512 | 1517 | cson_value_free( payload ); |
| 1513 | | - if((0 != rc) && !g.isCGI){ |
| 1518 | + if((0 != rc) && !g.isHTTP){ |
| 1514 | 1519 | /* FIXME: we need a way of passing this error back |
| 1515 | 1520 | up to the routine which called this callback. |
| 1516 | 1521 | e.g. add g.errCode. |
| 1517 | 1522 | */ |
| 1518 | 1523 | fossil_exit(1); |
| 1519 | 1524 | |