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.

stephan 2011-09-20 16:00 UTC json
Commit 76d0fa2bb0c561c1c667563227cec4f512adcf95
1 file changed +6 -7
+6 -7
--- src/json.c
+++ src/json.c
@@ -593,29 +593,28 @@
593593
** of bounds or there is no "json" path element.
594594
**
595595
** In CLI mode the "path" is the list of arguments (skipping argv[0]).
596596
** In server/CGI modes the path is taken from PATH_INFO.
597597
**
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.
603598
*/
604599
static char const * json_command_arg(unsigned char ndx){
605600
cson_array * ar = g.json.cmd.a;
606601
assert((NULL!=ar) && "Internal error. Was json_mode_bootstrap() called?");
602
+ assert((g.argc>1) && "Internal error - we never should have gotten this far.");
607603
if( g.json.cmd.offset < 0 ){
608604
/* first-time setup. */
609605
short i = 0;
610606
#define NEXT cson_string_cstr( \
611607
cson_value_get_string( \
612608
cson_array_get(ar,i) \
613609
))
614610
char const * tok = NEXT;
615611
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
+ ){
617616
g.json.cmd.offset = i;
618617
break;
619618
}
620619
++i;
621620
tok = NEXT;
@@ -1275,11 +1274,11 @@
12751274
*/
12761275
static cson_value * json_page_wiki(unsigned int depth){
12771276
JsonPageDef const * def;
12781277
char const * cmd = json_command_arg(1+depth);
12791278
if( ! cmd ){
1280
- g.json.resultCode = FSL_JSON_E_MISSING_AUTH;
1279
+ g.json.resultCode = FSL_JSON_E_MISSING_ARGS;
12811280
return NULL;
12821281
}
12831282
def = json_handler_for_name( cmd, &JsonPageDefs_Wiki[0] );
12841283
if(!def){
12851284
g.json.resultCode = FSL_JSON_E_UNKNOWN_COMMAND;
12861285
--- 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

Keyboard Shortcuts

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