Fossil

Check-in [45cd04f8]
Login

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

Overview
Comment:style conformance touch-ups.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | json
Files: files | file ages | folders
SHA1: 45cd04f8c1bf78ceee2235c9f76644d8a87cb1eb
User & Date: stephan 2011-09-16 18:55:42
Context
2011-09-16
18:57
Merged trunk [693ab93b7d] to quiet down -Wall. Removed a trailing comma from an enum (-Wall mode). check-in: 98cdd410 user: stephan tags: json
18:55
style conformance touch-ups. check-in: 45cd04f8 user: stephan tags: json
18:39
Refactored the special-case CLI-mode arg/path handling in the CGI/server-mode mechanism. Fixed: server-mode response timestamp was always the time the server process started. check-in: 0bb82303 user: stephan tags: json
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/json.c.

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
...
264
265
266
267
268
269
270
271


272

273
274
275
276
277
278
279
...
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328


329
330
331
332
333
334
335
336
337
338
339
340
341
342


343
344
345
346
347
348
349
...
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
...
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
...
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
      /* tell fossil to use this login info.
         
         FIXME: because the JSON bits don't carry around login_cookie_name(),
         there is a login hijacking window here. We need to change the
         JSON auth token to be in the form: login_cookie_name()=...
      */
      cgi_replace_parameter( login_cookie_name(), cson_value_get_cstr(g.json.authToken) );
    }
    else if( g.isCGI ){
      /* try fossil's conventional cookie. */
      /* Reminder: chicken/egg scenario regarding db access in CLI
         mode because login_cookie_name() needs the db. */
      char const * zCookie = P(login_cookie_name());
      if( zCookie && *zCookie ){
        /* Transfer fossil's cookie to JSON for downstream convenience... */
        cson_value * v = cson_value_new_string(zCookie, strlen(zCookie));
................................................................................
*/
static void json_mode_bootstrap(){
  static char once = 0  /* guard against multiple runs */;
  char const * zPath = P("PATH_INFO");
  cson_value * pathSplit =
    cson_cgi_getenv(&g.json.cgiCx,"e","PATH_INFO_SPLIT");
  assert( (0==once) && "json_mode_bootstrap() called too many times!");
  if( once ) return;


  else once = 1;

  g.json.isJsonMode = 1;
  g.json.resultCode = 0;
  g.json.cmdOffset = -1;
  if( !g.isCGI && g.fullHttpReply ){
    /* workaround for server mode, so we see it as CGI mode. */
    g.isCGI = 1;
  }
................................................................................
      */
      char const * p = zPath /* current byte */;
      char const * head = p  /* current start-of-token */;
      unsigned int len = 0   /* current token's lengh */;
      assert( g.isCGI && "g.isCGI should have been set by now." );
      for( ;*p!='?'; ++p){
        if( !*p || ('/' == *p) ){
          if( len ) {
            cson_value * part;
            assert( head != p );
            part = cson_value_new_string(head, len);
            cson_array_append( ar, part );
            len = 0;
          }
          if( !*p ) break;


          head = p+1;
          continue;
        }
        ++len;
      }
    }else{
      /* assume CLI mode */
      int i;
      char const * arg;
      cson_value * part;
      assert( (!g.isCGI) && "g.isCGI set and we do not expect that to be the case here." );
      for(i = 1/*skip argv[0]*/; i < g.argc; ++i ){
        arg = g.argv[i];
        if( !arg || !*arg ) continue;


        part = cson_value_new_string(arg,strlen(arg));
        cson_array_append(ar, part);
      }
    }
  }
  /* g.json.reqPayload exists only to simplify some of our access to
     the request payload. We currently only use this in the context of
................................................................................
    : NULL;
}


/* Returns the C-string form of json_auth_token(), or NULL
** if json_auth_token() returns NULL.
*/
char const * json_auth_token_cstr() {
  return cson_value_get_cstr( json_auth_token() );
}

/*
** Holds name-to-function mappings for JSON page/command dispatching.
**
*/
................................................................................
  json_mode_bootstrap();
  cmd = json_command_arg(1);
  /*cgi_printf("{\"cmd\":\"%s\"}\n",cmd); return;*/
  pageDef = json_handler_for_name(cmd,&JsonPageDefs[0]);
  if( ! pageDef ){
    json_err( FSL_JSON_E_UNKNOWN_COMMAND, cmd, 0 );
    return;
  }else if( pageDef->runMode < 0 /*CLI only*/) {
    rc = FSL_JSON_E_WRONG_MODE;
  }else{
    rc = 0;
    payload = (*pageDef->func)();
  }
  if( g.json.resultCode ){
    json_err(g.json.resultCode, NULL, 0);
................................................................................
    goto usage;
  }
  cgi_set_content_type( cson_cgi_guess_content_type(&g.json.cgiCx) );
  pageDef = json_handler_for_name(cmd,&JsonPageDefs[0]);
  if( ! pageDef ){
    json_err( FSL_JSON_E_UNKNOWN_COMMAND, NULL, 1 );
    return;
  }else if( pageDef->runMode > 0 /*HTTP only*/) {
    rc = FSL_JSON_E_WRONG_MODE;
  }else{
    rc = 0;
    payload = (pageDef->func)();
  }
  if( g.json.resultCode ){
    json_err(g.json.resultCode, NULL, 1);







<
|







 







|
>
>
|
>







 







|






|
>
>













|
>
>







 







|







 







|







 







|







229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
...
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
...
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
...
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
...
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
...
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
      /* tell fossil to use this login info.
         
         FIXME: because the JSON bits don't carry around login_cookie_name(),
         there is a login hijacking window here. We need to change the
         JSON auth token to be in the form: login_cookie_name()=...
      */
      cgi_replace_parameter( login_cookie_name(), cson_value_get_cstr(g.json.authToken) );

    }else if( g.isCGI ){
      /* try fossil's conventional cookie. */
      /* Reminder: chicken/egg scenario regarding db access in CLI
         mode because login_cookie_name() needs the db. */
      char const * zCookie = P(login_cookie_name());
      if( zCookie && *zCookie ){
        /* Transfer fossil's cookie to JSON for downstream convenience... */
        cson_value * v = cson_value_new_string(zCookie, strlen(zCookie));
................................................................................
*/
static void json_mode_bootstrap(){
  static char once = 0  /* guard against multiple runs */;
  char const * zPath = P("PATH_INFO");
  cson_value * pathSplit =
    cson_cgi_getenv(&g.json.cgiCx,"e","PATH_INFO_SPLIT");
  assert( (0==once) && "json_mode_bootstrap() called too many times!");
  if( once ){
    return;
  }else{
    once = 1;
  }
  g.json.isJsonMode = 1;
  g.json.resultCode = 0;
  g.json.cmdOffset = -1;
  if( !g.isCGI && g.fullHttpReply ){
    /* workaround for server mode, so we see it as CGI mode. */
    g.isCGI = 1;
  }
................................................................................
      */
      char const * p = zPath /* current byte */;
      char const * head = p  /* current start-of-token */;
      unsigned int len = 0   /* current token's lengh */;
      assert( g.isCGI && "g.isCGI should have been set by now." );
      for( ;*p!='?'; ++p){
        if( !*p || ('/' == *p) ){
          if( len ){
            cson_value * part;
            assert( head != p );
            part = cson_value_new_string(head, len);
            cson_array_append( ar, part );
            len = 0;
          }
          if( !*p ){
            break;
          }
          head = p+1;
          continue;
        }
        ++len;
      }
    }else{
      /* assume CLI mode */
      int i;
      char const * arg;
      cson_value * part;
      assert( (!g.isCGI) && "g.isCGI set and we do not expect that to be the case here." );
      for(i = 1/*skip argv[0]*/; i < g.argc; ++i ){
        arg = g.argv[i];
        if( !arg || !*arg ){
          continue;
        }
        part = cson_value_new_string(arg,strlen(arg));
        cson_array_append(ar, part);
      }
    }
  }
  /* g.json.reqPayload exists only to simplify some of our access to
     the request payload. We currently only use this in the context of
................................................................................
    : NULL;
}


/* Returns the C-string form of json_auth_token(), or NULL
** if json_auth_token() returns NULL.
*/
char const * json_auth_token_cstr(){
  return cson_value_get_cstr( json_auth_token() );
}

/*
** Holds name-to-function mappings for JSON page/command dispatching.
**
*/
................................................................................
  json_mode_bootstrap();
  cmd = json_command_arg(1);
  /*cgi_printf("{\"cmd\":\"%s\"}\n",cmd); return;*/
  pageDef = json_handler_for_name(cmd,&JsonPageDefs[0]);
  if( ! pageDef ){
    json_err( FSL_JSON_E_UNKNOWN_COMMAND, cmd, 0 );
    return;
  }else if( pageDef->runMode < 0 /*CLI only*/){
    rc = FSL_JSON_E_WRONG_MODE;
  }else{
    rc = 0;
    payload = (*pageDef->func)();
  }
  if( g.json.resultCode ){
    json_err(g.json.resultCode, NULL, 0);
................................................................................
    goto usage;
  }
  cgi_set_content_type( cson_cgi_guess_content_type(&g.json.cgiCx) );
  pageDef = json_handler_for_name(cmd,&JsonPageDefs[0]);
  if( ! pageDef ){
    json_err( FSL_JSON_E_UNKNOWN_COMMAND, NULL, 1 );
    return;
  }else if( pageDef->runMode > 0 /*HTTP only*/){
    rc = FSL_JSON_E_WRONG_MODE;
  }else{
    rc = 0;
    payload = (pageDef->func)();
  }
  if( g.json.resultCode ){
    json_err(g.json.resultCode, NULL, 1);