Fossil SCM

experimentally added "command" property to all responses to simplify response handler dispatching in some experimental Java client code.

stephan 2011-10-05 12:04 UTC json-multitag-test
Commit 8f12ac9896a9cad6e163632d69a83b99c079abbf
1 file changed +30 -1
+30 -1
--- src/json.c
+++ src/json.c
@@ -1277,10 +1277,37 @@
12771277
** the time, else timeVal is used as-is
12781278
*/
12791279
cson_value * json_new_timestamp(cson_int_t timeVal){
12801280
return cson_value_new_integer((timeVal<0) ? (cson_int_t)time(0) : timeVal);
12811281
}
1282
+
1283
+/*
1284
+** Internal helper for json_create_response(). Appends all elements of
1285
+** g.json.cmd.a, except the first one, to a string and returns that
1286
+** string value (which is owned by the caller).
1287
+*/
1288
+static cson_value * json_response_command_path(){
1289
+ if(!g.json.cmd.a){
1290
+ return NULL;
1291
+ }else{
1292
+ cson_value * rc = NULL;
1293
+ Blob path = empty_blob;
1294
+ char const * part;
1295
+ unsigned int aLen = cson_array_length_get(g.json.cmd.a);
1296
+ unsigned int i = 1;
1297
+ for( ; i < aLen; ++i ){
1298
+ char const * part = cson_string_cstr(cson_value_get_string(cson_array_get(g.json.cmd.a, i)));
1299
+ blob_append(&path,part,-1);
1300
+ if(i < (aLen-1)){
1301
+ blob_append(&path,"/",1);
1302
+ }
1303
+ }
1304
+ rc = json_new_string(blob_buffer(&path));
1305
+ blob_reset(&path);
1306
+ return rc;
1307
+ }
1308
+}
12821309
12831310
/*
12841311
** Creates a new Fossil/JSON response envelope skeleton. It is owned
12851312
** by the caller, who must eventually free it using cson_value_free(),
12861313
** or add it to a cson container to transfer ownership. Returns NULL
@@ -1343,12 +1370,14 @@
13431370
SET(FossilJsonKeys.resultText);
13441371
}
13451372
13461373
if(g.json.cmd.commandStr){
13471374
tmp = json_new_string(g.json.cmd.commandStr);
1348
- SET("command");
1375
+ }else{
1376
+ tmp = json_response_command_path();
13491377
}
1378
+ SET("command");
13501379
13511380
tmp = json_getenv(FossilJsonKeys.requestId);
13521381
if( tmp ) cson_object_set( o, FossilJsonKeys.requestId, tmp );
13531382
13541383
if(0){/* these are only intended for my own testing...*/
13551384
--- src/json.c
+++ src/json.c
@@ -1277,10 +1277,37 @@
1277 ** the time, else timeVal is used as-is
1278 */
1279 cson_value * json_new_timestamp(cson_int_t timeVal){
1280 return cson_value_new_integer((timeVal<0) ? (cson_int_t)time(0) : timeVal);
1281 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1282
1283 /*
1284 ** Creates a new Fossil/JSON response envelope skeleton. It is owned
1285 ** by the caller, who must eventually free it using cson_value_free(),
1286 ** or add it to a cson container to transfer ownership. Returns NULL
@@ -1343,12 +1370,14 @@
1343 SET(FossilJsonKeys.resultText);
1344 }
1345
1346 if(g.json.cmd.commandStr){
1347 tmp = json_new_string(g.json.cmd.commandStr);
1348 SET("command");
 
1349 }
 
1350
1351 tmp = json_getenv(FossilJsonKeys.requestId);
1352 if( tmp ) cson_object_set( o, FossilJsonKeys.requestId, tmp );
1353
1354 if(0){/* these are only intended for my own testing...*/
1355
--- src/json.c
+++ src/json.c
@@ -1277,10 +1277,37 @@
1277 ** the time, else timeVal is used as-is
1278 */
1279 cson_value * json_new_timestamp(cson_int_t timeVal){
1280 return cson_value_new_integer((timeVal<0) ? (cson_int_t)time(0) : timeVal);
1281 }
1282
1283 /*
1284 ** Internal helper for json_create_response(). Appends all elements of
1285 ** g.json.cmd.a, except the first one, to a string and returns that
1286 ** string value (which is owned by the caller).
1287 */
1288 static cson_value * json_response_command_path(){
1289 if(!g.json.cmd.a){
1290 return NULL;
1291 }else{
1292 cson_value * rc = NULL;
1293 Blob path = empty_blob;
1294 char const * part;
1295 unsigned int aLen = cson_array_length_get(g.json.cmd.a);
1296 unsigned int i = 1;
1297 for( ; i < aLen; ++i ){
1298 char const * part = cson_string_cstr(cson_value_get_string(cson_array_get(g.json.cmd.a, i)));
1299 blob_append(&path,part,-1);
1300 if(i < (aLen-1)){
1301 blob_append(&path,"/",1);
1302 }
1303 }
1304 rc = json_new_string(blob_buffer(&path));
1305 blob_reset(&path);
1306 return rc;
1307 }
1308 }
1309
1310 /*
1311 ** Creates a new Fossil/JSON response envelope skeleton. It is owned
1312 ** by the caller, who must eventually free it using cson_value_free(),
1313 ** or add it to a cson container to transfer ownership. Returns NULL
@@ -1343,12 +1370,14 @@
1370 SET(FossilJsonKeys.resultText);
1371 }
1372
1373 if(g.json.cmd.commandStr){
1374 tmp = json_new_string(g.json.cmd.commandStr);
1375 }else{
1376 tmp = json_response_command_path();
1377 }
1378 SET("command");
1379
1380 tmp = json_getenv(FossilJsonKeys.requestId);
1381 if( tmp ) cson_object_set( o, FossilJsonKeys.requestId, tmp );
1382
1383 if(0){/* these are only intended for my own testing...*/
1384

Keyboard Shortcuts

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