Fossil

Check-in [76d0fa2b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | json
Files: files | file ages | folders
SHA1:76d0fa2bb0c561c1c667563227cec4f512adcf95
User & Date: stephan 2011-09-20 16:00:37
Context
2011-09-20
16:27
minor internal cleanups and doc additions. check-in: 2f3e4385 user: stephan tags: json
16:00
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. check-in: 76d0fa2b user: stephan tags: json
15:48
Refactored page/command callback to take on argument to simplify certain dispatching ops. json_getenv() now falls back to getenv() if neither the POST data nor cgi_parameter() contains the requested value, but this is basically a workaround for my current inability to add --opt support in CLI mode (due to how HTTP/CLI command handling is consolidated). check-in: 206908fa user: stephan tags: json
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/json.c.

591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606

607
608
609
610
611
612
613
614
615


616

617
618
619
620
621
622
623
....
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
** Returns the ndx'th item in the "command path", where index 0 is the
** position of the "json" part of the path. Returns NULL if ndx is out
** of bounds or there is no "json" path element.
**
** In CLI mode the "path" is the list of arguments (skipping argv[0]).
** In server/CGI modes the path is taken from PATH_INFO.
**
**
** Reminder to self: this breaks in CLI mode when called with an
** abbreviated name because we rely on the full name "json" here. The
** g object probably has the short form which we can use for our
** purposes, but i haven't yet looked for it.
*/
static char const * json_command_arg(unsigned char ndx){
  cson_array * ar = g.json.cmd.a;
  assert((NULL!=ar) && "Internal error. Was json_mode_bootstrap() called?");

  if( g.json.cmd.offset < 0 ){
    /* first-time setup. */
    short i = 0;
#define NEXT cson_string_cstr(          \
                 cson_value_get_string( \
                   cson_array_get(ar,i) \
                   ))
    char const * tok = NEXT;
    while( tok ){


      if( 0==strncmp("json",tok,4) ){

        g.json.cmd.offset = i;
        break;
      }
      ++i;
      tok = NEXT;
    }
  }
................................................................................
** complete.
**
*/
static cson_value * json_page_wiki(unsigned int depth){
  JsonPageDef const * def;
  char const * cmd = json_command_arg(1+depth);
  if( ! cmd ){
    g.json.resultCode = FSL_JSON_E_MISSING_AUTH;
    return NULL;
  }
  def = json_handler_for_name( cmd, &JsonPageDefs_Wiki[0] );
  if(!def){
    g.json.resultCode = FSL_JSON_E_UNKNOWN_COMMAND;
    return NULL;
  }







<
<
<
<
<




>









>
>
|
>







 







|







591
592
593
594
595
596
597





598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
....
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
** Returns the ndx'th item in the "command path", where index 0 is the
** position of the "json" part of the path. Returns NULL if ndx is out
** of bounds or there is no "json" path element.
**
** In CLI mode the "path" is the list of arguments (skipping argv[0]).
** In server/CGI modes the path is taken from PATH_INFO.
**





*/
static char const * json_command_arg(unsigned char ndx){
  cson_array * ar = g.json.cmd.a;
  assert((NULL!=ar) && "Internal error. Was json_mode_bootstrap() called?");
  assert((g.argc>1) && "Internal error - we never should have gotten this far.");
  if( g.json.cmd.offset < 0 ){
    /* first-time setup. */
    short i = 0;
#define NEXT cson_string_cstr(          \
                 cson_value_get_string( \
                   cson_array_get(ar,i) \
                   ))
    char const * tok = NEXT;
    while( tok ){
      if( !g.isCGI/*workaround for "abbreviated name" in CLI mode*/
          ? (0==strcmp(g.argv[1],tok))
          : (0==strncmp("json",tok,4))
          ){
        g.json.cmd.offset = i;
        break;
      }
      ++i;
      tok = NEXT;
    }
  }
................................................................................
** complete.
**
*/
static cson_value * json_page_wiki(unsigned int depth){
  JsonPageDef const * def;
  char const * cmd = json_command_arg(1+depth);
  if( ! cmd ){
    g.json.resultCode = FSL_JSON_E_MISSING_ARGS;
    return NULL;
  }
  def = json_handler_for_name( cmd, &JsonPageDefs_Wiki[0] );
  if(!def){
    g.json.resultCode = FSL_JSON_E_UNKNOWN_COMMAND;
    return NULL;
  }