Fossil SCM
CLI mode now works properly when called using an abbreviated form of "json", e.g. fossil js wiki list. Fixed an incorrect error code in /json/wiki.
Commit
76d0fa2bb0c561c1c667563227cec4f512adcf95
Parent
206908faee4c76c…
1 file changed
+6
-7
+6
-7
| --- src/json.c | ||
| +++ src/json.c | ||
| @@ -593,29 +593,28 @@ | ||
| 593 | 593 | ** of bounds or there is no "json" path element. |
| 594 | 594 | ** |
| 595 | 595 | ** In CLI mode the "path" is the list of arguments (skipping argv[0]). |
| 596 | 596 | ** In server/CGI modes the path is taken from PATH_INFO. |
| 597 | 597 | ** |
| 598 | -** | |
| 599 | -** Reminder to self: this breaks in CLI mode when called with an | |
| 600 | -** abbreviated name because we rely on the full name "json" here. The | |
| 601 | -** g object probably has the short form which we can use for our | |
| 602 | -** purposes, but i haven't yet looked for it. | |
| 603 | 598 | */ |
| 604 | 599 | static char const * json_command_arg(unsigned char ndx){ |
| 605 | 600 | cson_array * ar = g.json.cmd.a; |
| 606 | 601 | assert((NULL!=ar) && "Internal error. Was json_mode_bootstrap() called?"); |
| 602 | + assert((g.argc>1) && "Internal error - we never should have gotten this far."); | |
| 607 | 603 | if( g.json.cmd.offset < 0 ){ |
| 608 | 604 | /* first-time setup. */ |
| 609 | 605 | short i = 0; |
| 610 | 606 | #define NEXT cson_string_cstr( \ |
| 611 | 607 | cson_value_get_string( \ |
| 612 | 608 | cson_array_get(ar,i) \ |
| 613 | 609 | )) |
| 614 | 610 | char const * tok = NEXT; |
| 615 | 611 | while( tok ){ |
| 616 | - if( 0==strncmp("json",tok,4) ){ | |
| 612 | + if( !g.isCGI/*workaround for "abbreviated name" in CLI mode*/ | |
| 613 | + ? (0==strcmp(g.argv[1],tok)) | |
| 614 | + : (0==strncmp("json",tok,4)) | |
| 615 | + ){ | |
| 617 | 616 | g.json.cmd.offset = i; |
| 618 | 617 | break; |
| 619 | 618 | } |
| 620 | 619 | ++i; |
| 621 | 620 | tok = NEXT; |
| @@ -1275,11 +1274,11 @@ | ||
| 1275 | 1274 | */ |
| 1276 | 1275 | static cson_value * json_page_wiki(unsigned int depth){ |
| 1277 | 1276 | JsonPageDef const * def; |
| 1278 | 1277 | char const * cmd = json_command_arg(1+depth); |
| 1279 | 1278 | if( ! cmd ){ |
| 1280 | - g.json.resultCode = FSL_JSON_E_MISSING_AUTH; | |
| 1279 | + g.json.resultCode = FSL_JSON_E_MISSING_ARGS; | |
| 1281 | 1280 | return NULL; |
| 1282 | 1281 | } |
| 1283 | 1282 | def = json_handler_for_name( cmd, &JsonPageDefs_Wiki[0] ); |
| 1284 | 1283 | if(!def){ |
| 1285 | 1284 | g.json.resultCode = FSL_JSON_E_UNKNOWN_COMMAND; |
| 1286 | 1285 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -593,29 +593,28 @@ | |
| 593 | ** of bounds or there is no "json" path element. |
| 594 | ** |
| 595 | ** In CLI mode the "path" is the list of arguments (skipping argv[0]). |
| 596 | ** In server/CGI modes the path is taken from PATH_INFO. |
| 597 | ** |
| 598 | ** |
| 599 | ** Reminder to self: this breaks in CLI mode when called with an |
| 600 | ** abbreviated name because we rely on the full name "json" here. The |
| 601 | ** g object probably has the short form which we can use for our |
| 602 | ** purposes, but i haven't yet looked for it. |
| 603 | */ |
| 604 | static char const * json_command_arg(unsigned char ndx){ |
| 605 | cson_array * ar = g.json.cmd.a; |
| 606 | assert((NULL!=ar) && "Internal error. Was json_mode_bootstrap() called?"); |
| 607 | if( g.json.cmd.offset < 0 ){ |
| 608 | /* first-time setup. */ |
| 609 | short i = 0; |
| 610 | #define NEXT cson_string_cstr( \ |
| 611 | cson_value_get_string( \ |
| 612 | cson_array_get(ar,i) \ |
| 613 | )) |
| 614 | char const * tok = NEXT; |
| 615 | while( tok ){ |
| 616 | if( 0==strncmp("json",tok,4) ){ |
| 617 | g.json.cmd.offset = i; |
| 618 | break; |
| 619 | } |
| 620 | ++i; |
| 621 | tok = NEXT; |
| @@ -1275,11 +1274,11 @@ | |
| 1275 | */ |
| 1276 | static cson_value * json_page_wiki(unsigned int depth){ |
| 1277 | JsonPageDef const * def; |
| 1278 | char const * cmd = json_command_arg(1+depth); |
| 1279 | if( ! cmd ){ |
| 1280 | g.json.resultCode = FSL_JSON_E_MISSING_AUTH; |
| 1281 | return NULL; |
| 1282 | } |
| 1283 | def = json_handler_for_name( cmd, &JsonPageDefs_Wiki[0] ); |
| 1284 | if(!def){ |
| 1285 | g.json.resultCode = FSL_JSON_E_UNKNOWN_COMMAND; |
| 1286 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -593,29 +593,28 @@ | |
| 593 | ** of bounds or there is no "json" path element. |
| 594 | ** |
| 595 | ** In CLI mode the "path" is the list of arguments (skipping argv[0]). |
| 596 | ** In server/CGI modes the path is taken from PATH_INFO. |
| 597 | ** |
| 598 | */ |
| 599 | static char const * json_command_arg(unsigned char ndx){ |
| 600 | cson_array * ar = g.json.cmd.a; |
| 601 | assert((NULL!=ar) && "Internal error. Was json_mode_bootstrap() called?"); |
| 602 | assert((g.argc>1) && "Internal error - we never should have gotten this far."); |
| 603 | if( g.json.cmd.offset < 0 ){ |
| 604 | /* first-time setup. */ |
| 605 | short i = 0; |
| 606 | #define NEXT cson_string_cstr( \ |
| 607 | cson_value_get_string( \ |
| 608 | cson_array_get(ar,i) \ |
| 609 | )) |
| 610 | char const * tok = NEXT; |
| 611 | while( tok ){ |
| 612 | if( !g.isCGI/*workaround for "abbreviated name" in CLI mode*/ |
| 613 | ? (0==strcmp(g.argv[1],tok)) |
| 614 | : (0==strncmp("json",tok,4)) |
| 615 | ){ |
| 616 | g.json.cmd.offset = i; |
| 617 | break; |
| 618 | } |
| 619 | ++i; |
| 620 | tok = NEXT; |
| @@ -1275,11 +1274,11 @@ | |
| 1274 | */ |
| 1275 | static cson_value * json_page_wiki(unsigned int depth){ |
| 1276 | JsonPageDef const * def; |
| 1277 | char const * cmd = json_command_arg(1+depth); |
| 1278 | if( ! cmd ){ |
| 1279 | g.json.resultCode = FSL_JSON_E_MISSING_ARGS; |
| 1280 | return NULL; |
| 1281 | } |
| 1282 | def = json_handler_for_name( cmd, &JsonPageDefs_Wiki[0] ); |
| 1283 | if(!def){ |
| 1284 | g.json.resultCode = FSL_JSON_E_UNKNOWN_COMMAND; |
| 1285 |