Fossil

Check-in [30e4ebaa]
Login

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

Overview
Comment:JSON CLI mode now accepts --indent|-I N to set JSON indention level (uses cson_output_opt::indentation semantics). Default for CLI mode is 1 (0 for HTTP mode).
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | json
Files: files | file ages | folders
SHA1: 30e4ebaa199af338c86f50421935f02e74dc129a
User & Date: stephan 2011-09-28 21:36:15.726
Context
2011-09-28
22:04
Added createIfNotExists bool option to /json/wiki/save. ... (check-in: 73e28dd7 user: stephan tags: json)
21:36
JSON CLI mode now accepts --indent|-I N to set JSON indention level (uses cson_output_opt::indentation semantics). Default for CLI mode is 1 (0 for HTTP mode). ... (check-in: 30e4ebaa user: stephan tags: json)
12:09
merged in trunk [3e141b792c]. ... (check-in: 033e2eb1 user: stephan tags: json)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ajax/index.html.
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
        TheApp.jqe.taRequest.val( val );
        TheApp.jqe.taRequestOpt.val( opt ? WhAjaj.stringify(opt) : '' );
        TheApp.startAjaxNotif();
    };
    opt.afterSend = function(req,opt) {
        TheApp.timer.end();
        TheApp.endAjaxNotif();
        TheApp.jqe.timer.text( "(Round-trip time: "+TheApp.timer.duration+'ms)' );
    };
    opt.onResponse = function(resp,req) {
        var val;
        try {
            val = WhAjaj.stringify(resp);
        }
        catch(e) {







|







146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
        TheApp.jqe.taRequest.val( val );
        TheApp.jqe.taRequestOpt.val( opt ? WhAjaj.stringify(opt) : '' );
        TheApp.startAjaxNotif();
    };
    opt.afterSend = function(req,opt) {
        TheApp.timer.end();
        TheApp.endAjaxNotif();
        TheApp.jqe.timer.text( "(Round-trip time (incl. JS overhead): "+TheApp.timer.duration+'ms)' );
    };
    opt.onResponse = function(resp,req) {
        var val;
        try {
            val = WhAjaj.stringify(resp);
        }
        catch(e) {
Changes to src/json.c.
389
390
391
392
393
394
395




396
397
398
399
400
401












402
403

404
405
406
407
408
409
410
  }
  rc = cson_object_get( g.json.post.o, zKey );
  if(rc){
    return rc;
  }else{
    char const * cv = PD(zKey,NULL);
    if(!cv){




      cv = getenv(zKey);
    }
    if(cv){/*transform it to JSON for later use.*/
      /* TODO: use sscanf() to figure out if it's an int,
         and transform it to JSON int if it is.
      */












      rc = cson_value_new_string(cv,strlen(cv));
      json_setenv( zKey, rc );

      return rc;
    }
  }
  return NULL;
}

/*







>
>
>
>



|


>
>
>
>
>
>
>
>
>
>
>
>
|
|
>







389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
  }
  rc = cson_object_get( g.json.post.o, zKey );
  if(rc){
    return rc;
  }else{
    char const * cv = PD(zKey,NULL);
    if(!cv){
      /* reminder to self: in CLI mode i'd like to try
         find_option(zKey,NULL,XYZ) here, but we don't have a sane
         default for the XYZ param here.
      */
      cv = getenv(zKey);
    }
    if(cv){/*transform it to JSON for later use.*/
      /* use sscanf() to figure out if it's an int,
         and transform it to JSON int if it is.
      */
      int intVal = -1;
      char endOfIntCheck;
      int const scanRc = sscanf(cv,"%d%c",&intVal, &endOfIntCheck)
        /* The %c bit there is to make sure that we don't accept 123x
          as a number. sscanf() returns the number of tokens
          successfully parsed, so an RC of 1 will be correct for "123"
          but "123x" will have RC==2.
        */
        ;
      if(1==scanRc){
        json_setenv( zKey, cson_value_new_integer(intVal) );
      }else{
        rc = cson_value_new_string(cv,strlen(cv));
        json_setenv( zKey, rc );
      }
      return rc;
    }
  }
  return NULL;
}

/*
932
933
934
935
936
937
938
939




940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
        /* g.json.reqPayload.o may legally be NULL, which means only that
           g.json.reqPayload.v is-not-a Object.
        */;
  }

  {/* set up JSON output formatting options. */
    unsigned char indent = g.isHTTP ? 0 : 1;
    cson_value const * indentV = json_getenv("indent");




    if(indentV){
      if(cson_value_is_string(indentV)){
        int const n = atoi(cson_string_cstr(cson_value_get_string(indentV)));
        indent = (n>0)
          ? (unsigned char)n
          : 0;
      }else if(cson_value_is_number(indentV)){
        cson_int_t const n = cson_value_get_integer(indentV);
        indent = (n>0) ? (unsigned char)n : 0;
      }
    }
    g.json.outOpt.indentation = indent;
    g.json.outOpt.addNewline = g.isHTTP
      ? 0
      : (g.json.jsonp ? 0 : 1);
  }







|
>
>
>
>
|
<
|



<
<
<







949
950
951
952
953
954
955
956
957
958
959
960
961

962
963
964
965



966
967
968
969
970
971
972
        /* g.json.reqPayload.o may legally be NULL, which means only that
           g.json.reqPayload.v is-not-a Object.
        */;
  }

  {/* set up JSON output formatting options. */
    unsigned char indent = g.isHTTP ? 0 : 1;
    char const * indentStr = NULL;
    if( g.isHTTP ){
      indent = (unsigned char)json_getenv_int("indent",(int)indent);
    }else{/*CLI mode*/
      indentStr = find_option("indent","I",1);
      if(indentStr){

        int const n = atoi(indentStr);
        indent = (n>0)
          ? (unsigned char)n
          : 0;



      }
    }
    g.json.outOpt.indentation = indent;
    g.json.outOpt.addNewline = g.isHTTP
      ? 0
      : (g.json.jsonp ? 0 : 1);
  }
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
                       cson_value_new_string(str,strlen(str)) );
    }
  }
  db_finalize(&q);
  cson_object_set( obj, "permissionFlags", sub );
  obj = cson_value_get_object(sub);

#define ADD(X) cson_object_set(obj, #X, cson_value_new_bool(g.perm.X))
  ADD(Setup);
  ADD(Admin);
  ADD(Delete);
  ADD(Password);
  ADD(Query);
  ADD(Write);
  ADD(Read);
  ADD(History);
  ADD(Clone);
  ADD(RdWiki);
  ADD(NewWiki);
  ADD(ApndWiki);
  ADD(WrWiki);
  ADD(RdTkt);
  ADD(NewTkt);
  ADD(ApndTkt);
  ADD(WrTkt);
  ADD(Attach);
  ADD(TktFmt);
  ADD(RdAddr);
  ADD(Zip);
  ADD(Private);
#undef ADD
  return payload;
}

/*
** Implementation of the /json/stat page/command.
**







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|







1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
                       cson_value_new_string(str,strlen(str)) );
    }
  }
  db_finalize(&q);
  cson_object_set( obj, "permissionFlags", sub );
  obj = cson_value_get_object(sub);

#define ADD(X,K) cson_object_set(obj, K, cson_value_new_bool(g.perm.X))
  ADD(Setup,"setup");
  ADD(Admin,"admin");
  ADD(Delete,"delete");
  ADD(Password,"password");
  ADD(Query,"query"); /* don't think this one is actually used */
  ADD(Write,"checkin");
  ADD(Read,"checkout");
  ADD(History,"history");
  ADD(Clone,"clone");
  ADD(RdWiki,"readWiki");
  ADD(NewWiki,"createWiki");
  ADD(ApndWiki,"appendWiki");
  ADD(WrWiki,"editWiki");
  ADD(RdTkt,"readTicket");
  ADD(NewTkt,"createTicket");
  ADD(ApndTkt,"appendTicket");
  ADD(WrTkt,"editTicket");
  ADD(Attach,"attachFile");
  ADD(TktFmt,"createTicketReport");
  ADD(RdAddr,"readPrivate");
  ADD(Zip,"zip");
  ADD(Private,"xferPrivate");
#undef ADD
  return payload;
}

/*
** Implementation of the /json/stat page/command.
**