Fossil SCM
experimentally added "command" property to all responses to simplify response handler dispatching in some experimental Java client code.
Commit
8f12ac9896a9cad6e163632d69a83b99c079abbf
Parent
2dac80dd9f86b95…
1 file changed
+30
-1
+30
-1
| --- src/json.c | ||
| +++ src/json.c | ||
| @@ -1277,10 +1277,37 @@ | ||
| 1277 | 1277 | ** the time, else timeVal is used as-is |
| 1278 | 1278 | */ |
| 1279 | 1279 | cson_value * json_new_timestamp(cson_int_t timeVal){ |
| 1280 | 1280 | return cson_value_new_integer((timeVal<0) ? (cson_int_t)time(0) : timeVal); |
| 1281 | 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 | +} | |
| 1282 | 1309 | |
| 1283 | 1310 | /* |
| 1284 | 1311 | ** Creates a new Fossil/JSON response envelope skeleton. It is owned |
| 1285 | 1312 | ** by the caller, who must eventually free it using cson_value_free(), |
| 1286 | 1313 | ** or add it to a cson container to transfer ownership. Returns NULL |
| @@ -1343,12 +1370,14 @@ | ||
| 1343 | 1370 | SET(FossilJsonKeys.resultText); |
| 1344 | 1371 | } |
| 1345 | 1372 | |
| 1346 | 1373 | if(g.json.cmd.commandStr){ |
| 1347 | 1374 | tmp = json_new_string(g.json.cmd.commandStr); |
| 1348 | - SET("command"); | |
| 1375 | + }else{ | |
| 1376 | + tmp = json_response_command_path(); | |
| 1349 | 1377 | } |
| 1378 | + SET("command"); | |
| 1350 | 1379 | |
| 1351 | 1380 | tmp = json_getenv(FossilJsonKeys.requestId); |
| 1352 | 1381 | if( tmp ) cson_object_set( o, FossilJsonKeys.requestId, tmp ); |
| 1353 | 1382 | |
| 1354 | 1383 | if(0){/* these are only intended for my own testing...*/ |
| 1355 | 1384 |
| --- 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 |