Fossil SCM

Added /json/resultCodes.

stephan 2011-10-06 17:12 UTC json-multitag-test
Commit 71a1d4483f71aeb4e7943f6a65a567a45db0a6e6
2 files changed +1 +72 -10
--- ajax/index.html
+++ ajax/index.html
@@ -232,10 +232,11 @@
232232
<input type='button' value='timeline/ticket' onclick='TheApp.cgi.sendCommand("/json/timeline/ticket")' />
233233
<input type='button' value='wiki/list' onclick='TheApp.cgi.sendCommand("/json/wiki/list")' />
234234
<input type='button' value='wiki/get Fossil' onclick='TheApp.cgi.sendCommand("/json/wiki/get",{page:"Fossil"})' />
235235
<input type='button' value='user/list' onclick='TheApp.cgi.sendCommand("/json/user/list")' />
236236
<input type='button' value='user/get' onclick='TheApp.cgi.sendCommand("/json/user/get?name=anonymous")' />
237
+<input type='button' value='resultCodes' onclick='TheApp.cgi.sendCommand("/json/resultCodes")' />
237238
<!-- not yet ready...
238239
<input type='button' value='artifact/XYZ' onclick='TheApp.cgi.sendCommand("/json/artifact?uuid=json")' />
239240
-->
240241
241242
<!--
242243
--- ajax/index.html
+++ ajax/index.html
@@ -232,10 +232,11 @@
232 <input type='button' value='timeline/ticket' onclick='TheApp.cgi.sendCommand("/json/timeline/ticket")' />
233 <input type='button' value='wiki/list' onclick='TheApp.cgi.sendCommand("/json/wiki/list")' />
234 <input type='button' value='wiki/get Fossil' onclick='TheApp.cgi.sendCommand("/json/wiki/get",{page:"Fossil"})' />
235 <input type='button' value='user/list' onclick='TheApp.cgi.sendCommand("/json/user/list")' />
236 <input type='button' value='user/get' onclick='TheApp.cgi.sendCommand("/json/user/get?name=anonymous")' />
 
237 <!-- not yet ready...
238 <input type='button' value='artifact/XYZ' onclick='TheApp.cgi.sendCommand("/json/artifact?uuid=json")' />
239 -->
240
241 <!--
242
--- ajax/index.html
+++ ajax/index.html
@@ -232,10 +232,11 @@
232 <input type='button' value='timeline/ticket' onclick='TheApp.cgi.sendCommand("/json/timeline/ticket")' />
233 <input type='button' value='wiki/list' onclick='TheApp.cgi.sendCommand("/json/wiki/list")' />
234 <input type='button' value='wiki/get Fossil' onclick='TheApp.cgi.sendCommand("/json/wiki/get",{page:"Fossil"})' />
235 <input type='button' value='user/list' onclick='TheApp.cgi.sendCommand("/json/user/list")' />
236 <input type='button' value='user/get' onclick='TheApp.cgi.sendCommand("/json/user/get?name=anonymous")' />
237 <input type='button' value='resultCodes' onclick='TheApp.cgi.sendCommand("/json/resultCodes")' />
238 <!-- not yet ready...
239 <input type='button' value='artifact/XYZ' onclick='TheApp.cgi.sendCommand("/json/artifact?uuid=json")' />
240 -->
241
242 <!--
243
+72 -10
--- src/json.c
+++ src/json.c
@@ -214,14 +214,14 @@
214214
return NULL;
215215
}
216216
217217
/*
218218
** Given a FossilJsonCodes value, it returns a string suitable for use
219
-** as a resultText string. Returns some unspecified string if errCode
220
-** is not one of the FossilJsonCodes values.
219
+** as a resultCode string. Returns some unspecified non-empty string
220
+** if errCode is not one of the FossilJsonCodes values.
221221
*/
222
-char const * json_err_str( int errCode ){
222
+static char const * json_err_cstr( int errCode ){
223223
switch( errCode ){
224224
case 0: return "Success";
225225
#define C(X,V) case FSL_JSON_E_ ## X: return V
226226
227227
C(GENERIC,"Generic error");
@@ -231,12 +231,12 @@
231231
C(TIMEOUT,"Timeout reached");
232232
C(ASSERT,"Assertion failed");
233233
C(ALLOC,"Resource allocation failed");
234234
C(NYI,"Not yet implemented");
235235
C(PANIC,"x");
236
- C(MANIFEST_READ_FAILED,"Reading artifact manifest failed.");
237
- C(FILE_OPEN_FAILED,"Opening file failed.");
236
+ C(MANIFEST_READ_FAILED,"Reading artifact manifest failed");
237
+ C(FILE_OPEN_FAILED,"Opening file failed");
238238
239239
C(AUTH,"Authentication error");
240240
C(MISSING_AUTH,"Authentication info missing from request");
241241
C(DENIED,"Access denied");
242242
C(WRONG_MODE,"Request not allowed (wrong operation mode)");
@@ -1322,11 +1322,11 @@
13221322
** response. In either case, onwership of payload is transfered to
13231323
** this function.
13241324
**
13251325
** pMsg is an optional message string property (resultText) of the
13261326
** response. If resultCode is non-0 and pMsg is NULL then
1327
-** json_err_str() is used to get the error string. The caller may
1327
+** json_err_cstr() is used to get the error string. The caller may
13281328
** provide his own or may use an empty string to suppress the
13291329
** resultText property.
13301330
**
13311331
*/
13321332
cson_value * json_create_response( int resultCode,
@@ -1358,11 +1358,11 @@
13581358
13591359
if( 0 != resultCode ){
13601360
if( ! pMsg ){
13611361
pMsg = g.zErrMsg;
13621362
if(!pMsg){
1363
- pMsg = json_err_str(resultCode);
1363
+ pMsg = json_err_cstr(resultCode);
13641364
}
13651365
}
13661366
tmp = json_new_string(json_rc_cstr(resultCode));
13671367
SET(FossilJsonKeys.resultCode);
13681368
}
@@ -1454,11 +1454,11 @@
14541454
** !g.isHTTP then alsoOutput is ignored and all output is sent to
14551455
** stdout immediately.
14561456
**
14571457
** For generating the resultText property: if msg is not NULL then it
14581458
** is used as-is. If it is NULL then g.zErrMsg is checked, and if that
1459
-** is NULL then json_err_str(code) is used.
1459
+** is NULL then json_err_cstr(code) is used.
14601460
*/
14611461
void json_err( int code, char const * msg, char alsoOutput ){
14621462
int rc = code ? code : (g.json.resultCode
14631463
? g.json.resultCode
14641464
: FSL_JSON_E_UNKNOWN);
@@ -1465,11 +1465,11 @@
14651465
cson_value * resp = NULL;
14661466
rc = json_dumbdown_rc(rc);
14671467
if( rc && !msg ){
14681468
msg = g.zErrMsg;
14691469
if(!msg){
1470
- msg = json_err_str(rc);
1470
+ msg = json_err_cstr(rc);
14711471
}
14721472
}
14731473
resp = json_create_response(rc, msg, NULL);
14741474
if(!resp){
14751475
/* about the only error case here is out-of-memory. DO NOT
@@ -1508,11 +1508,11 @@
15081508
int json_set_err( int code, char const * fmt, ... ){
15091509
assert( (code>=1000) && (code<=9999) );
15101510
free(g.zErrMsg);
15111511
g.json.resultCode = code;
15121512
if(!fmt || !*fmt){
1513
- g.zErrMsg = mprintf("%s", json_err_str(code));
1513
+ g.zErrMsg = mprintf("%s", json_err_cstr(code));
15141514
}else{
15151515
va_list vargs;
15161516
va_start(vargs,fmt);
15171517
char * msg = vmprintf(fmt, vargs);
15181518
va_end(vargs);
@@ -1567,10 +1567,71 @@
15671567
}
15681568
free(tags);
15691569
}
15701570
return v;
15711571
}
1572
+
1573
+/*
1574
+** Impl of /json/resultCodes
1575
+**
1576
+*/
1577
+cson_value * json_page_resultCodes(){
1578
+ cson_value * listV = cson_value_new_array();
1579
+ cson_array * list = cson_value_get_array(listV);
1580
+ cson_value * objV = NULL;
1581
+ cson_object * obj = NULL;
1582
+ int rc = cson_array_reserve( list, 35 );
1583
+ if(rc){
1584
+ assert( 0 && "Allocation error.");
1585
+ exit(1);
1586
+ }
1587
+#define C(K) objV = cson_value_new_object(); obj = cson_value_get_object(objV); \
1588
+ cson_object_set(obj, "resultCode", json_new_string(json_rc_cstr(FSL_JSON_E_##K)) ); \
1589
+ cson_object_set(obj, "cSymbol", json_new_string("FSL_JSON_E_"#K) ); \
1590
+ cson_object_set(obj, "number", cson_value_new_integer(FSL_JSON_E_##K) ); \
1591
+ cson_object_set(obj, "description", json_new_string(json_err_cstr(FSL_JSON_E_##K))); \
1592
+ cson_array_append( list, objV ); obj = NULL; objV = NULL
1593
+
1594
+ C(GENERIC);
1595
+ C(INVALID_REQUEST);
1596
+ C(UNKNOWN_COMMAND);
1597
+ C(UNKNOWN);
1598
+ C(TIMEOUT);
1599
+ C(ASSERT);
1600
+ C(ALLOC);
1601
+ C(NYI);
1602
+ C(PANIC);
1603
+ C(MANIFEST_READ_FAILED);
1604
+ C(FILE_OPEN_FAILED);
1605
+
1606
+ C(AUTH);
1607
+ C(MISSING_AUTH);
1608
+ C(DENIED);
1609
+ C(WRONG_MODE);
1610
+ C(LOGIN_FAILED);
1611
+ C(LOGIN_FAILED_NOSEED);
1612
+ C(LOGIN_FAILED_NONAME);
1613
+ C(LOGIN_FAILED_NOPW);
1614
+ C(LOGIN_FAILED_NOTFOUND);
1615
+
1616
+ C(USAGE);
1617
+ C(INVALID_ARGS);
1618
+ C(MISSING_ARGS);
1619
+ C(AMBIGUOUS_UUID);
1620
+ C(UNRESOLVED_UUID);
1621
+ C(RESOURCE_ALREADY_EXISTS);
1622
+ C(RESOURCE_NOT_FOUND);
1623
+
1624
+ C(DB);
1625
+ C(STMT_PREP);
1626
+ C(STMT_BIND);
1627
+ C(STMT_EXEC);
1628
+ C(DB_LOCKED);
1629
+ C(DB_NEEDS_REBUILD);
1630
+#undef C
1631
+ return listV;
1632
+}
15721633
15731634
15741635
/*
15751636
** /json/version implementation.
15761637
**
@@ -1928,10 +1989,11 @@
19281989
{"dir", json_page_nyi, 0},
19291990
{"HAI",json_page_version,0},
19301991
{"login",json_page_login,1},
19311992
{"logout",json_page_logout,1},
19321993
{"rebuild",json_page_rebuild,0},
1994
+{"resultCodes", json_page_resultCodes,0},
19331995
{"stat",json_page_stat,0},
19341996
{"tag", json_page_nyi,0},
19351997
{"ticket", json_page_nyi,0},
19361998
{"timeline", json_page_timeline,0},
19371999
{"user",json_page_user,0},
19382000
--- src/json.c
+++ src/json.c
@@ -214,14 +214,14 @@
214 return NULL;
215 }
216
217 /*
218 ** Given a FossilJsonCodes value, it returns a string suitable for use
219 ** as a resultText string. Returns some unspecified string if errCode
220 ** is not one of the FossilJsonCodes values.
221 */
222 char const * json_err_str( int errCode ){
223 switch( errCode ){
224 case 0: return "Success";
225 #define C(X,V) case FSL_JSON_E_ ## X: return V
226
227 C(GENERIC,"Generic error");
@@ -231,12 +231,12 @@
231 C(TIMEOUT,"Timeout reached");
232 C(ASSERT,"Assertion failed");
233 C(ALLOC,"Resource allocation failed");
234 C(NYI,"Not yet implemented");
235 C(PANIC,"x");
236 C(MANIFEST_READ_FAILED,"Reading artifact manifest failed.");
237 C(FILE_OPEN_FAILED,"Opening file failed.");
238
239 C(AUTH,"Authentication error");
240 C(MISSING_AUTH,"Authentication info missing from request");
241 C(DENIED,"Access denied");
242 C(WRONG_MODE,"Request not allowed (wrong operation mode)");
@@ -1322,11 +1322,11 @@
1322 ** response. In either case, onwership of payload is transfered to
1323 ** this function.
1324 **
1325 ** pMsg is an optional message string property (resultText) of the
1326 ** response. If resultCode is non-0 and pMsg is NULL then
1327 ** json_err_str() is used to get the error string. The caller may
1328 ** provide his own or may use an empty string to suppress the
1329 ** resultText property.
1330 **
1331 */
1332 cson_value * json_create_response( int resultCode,
@@ -1358,11 +1358,11 @@
1358
1359 if( 0 != resultCode ){
1360 if( ! pMsg ){
1361 pMsg = g.zErrMsg;
1362 if(!pMsg){
1363 pMsg = json_err_str(resultCode);
1364 }
1365 }
1366 tmp = json_new_string(json_rc_cstr(resultCode));
1367 SET(FossilJsonKeys.resultCode);
1368 }
@@ -1454,11 +1454,11 @@
1454 ** !g.isHTTP then alsoOutput is ignored and all output is sent to
1455 ** stdout immediately.
1456 **
1457 ** For generating the resultText property: if msg is not NULL then it
1458 ** is used as-is. If it is NULL then g.zErrMsg is checked, and if that
1459 ** is NULL then json_err_str(code) is used.
1460 */
1461 void json_err( int code, char const * msg, char alsoOutput ){
1462 int rc = code ? code : (g.json.resultCode
1463 ? g.json.resultCode
1464 : FSL_JSON_E_UNKNOWN);
@@ -1465,11 +1465,11 @@
1465 cson_value * resp = NULL;
1466 rc = json_dumbdown_rc(rc);
1467 if( rc && !msg ){
1468 msg = g.zErrMsg;
1469 if(!msg){
1470 msg = json_err_str(rc);
1471 }
1472 }
1473 resp = json_create_response(rc, msg, NULL);
1474 if(!resp){
1475 /* about the only error case here is out-of-memory. DO NOT
@@ -1508,11 +1508,11 @@
1508 int json_set_err( int code, char const * fmt, ... ){
1509 assert( (code>=1000) && (code<=9999) );
1510 free(g.zErrMsg);
1511 g.json.resultCode = code;
1512 if(!fmt || !*fmt){
1513 g.zErrMsg = mprintf("%s", json_err_str(code));
1514 }else{
1515 va_list vargs;
1516 va_start(vargs,fmt);
1517 char * msg = vmprintf(fmt, vargs);
1518 va_end(vargs);
@@ -1567,10 +1567,71 @@
1567 }
1568 free(tags);
1569 }
1570 return v;
1571 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1572
1573
1574 /*
1575 ** /json/version implementation.
1576 **
@@ -1928,10 +1989,11 @@
1928 {"dir", json_page_nyi, 0},
1929 {"HAI",json_page_version,0},
1930 {"login",json_page_login,1},
1931 {"logout",json_page_logout,1},
1932 {"rebuild",json_page_rebuild,0},
 
1933 {"stat",json_page_stat,0},
1934 {"tag", json_page_nyi,0},
1935 {"ticket", json_page_nyi,0},
1936 {"timeline", json_page_timeline,0},
1937 {"user",json_page_user,0},
1938
--- src/json.c
+++ src/json.c
@@ -214,14 +214,14 @@
214 return NULL;
215 }
216
217 /*
218 ** Given a FossilJsonCodes value, it returns a string suitable for use
219 ** as a resultCode string. Returns some unspecified non-empty string
220 ** if errCode is not one of the FossilJsonCodes values.
221 */
222 static char const * json_err_cstr( int errCode ){
223 switch( errCode ){
224 case 0: return "Success";
225 #define C(X,V) case FSL_JSON_E_ ## X: return V
226
227 C(GENERIC,"Generic error");
@@ -231,12 +231,12 @@
231 C(TIMEOUT,"Timeout reached");
232 C(ASSERT,"Assertion failed");
233 C(ALLOC,"Resource allocation failed");
234 C(NYI,"Not yet implemented");
235 C(PANIC,"x");
236 C(MANIFEST_READ_FAILED,"Reading artifact manifest failed");
237 C(FILE_OPEN_FAILED,"Opening file failed");
238
239 C(AUTH,"Authentication error");
240 C(MISSING_AUTH,"Authentication info missing from request");
241 C(DENIED,"Access denied");
242 C(WRONG_MODE,"Request not allowed (wrong operation mode)");
@@ -1322,11 +1322,11 @@
1322 ** response. In either case, onwership of payload is transfered to
1323 ** this function.
1324 **
1325 ** pMsg is an optional message string property (resultText) of the
1326 ** response. If resultCode is non-0 and pMsg is NULL then
1327 ** json_err_cstr() is used to get the error string. The caller may
1328 ** provide his own or may use an empty string to suppress the
1329 ** resultText property.
1330 **
1331 */
1332 cson_value * json_create_response( int resultCode,
@@ -1358,11 +1358,11 @@
1358
1359 if( 0 != resultCode ){
1360 if( ! pMsg ){
1361 pMsg = g.zErrMsg;
1362 if(!pMsg){
1363 pMsg = json_err_cstr(resultCode);
1364 }
1365 }
1366 tmp = json_new_string(json_rc_cstr(resultCode));
1367 SET(FossilJsonKeys.resultCode);
1368 }
@@ -1454,11 +1454,11 @@
1454 ** !g.isHTTP then alsoOutput is ignored and all output is sent to
1455 ** stdout immediately.
1456 **
1457 ** For generating the resultText property: if msg is not NULL then it
1458 ** is used as-is. If it is NULL then g.zErrMsg is checked, and if that
1459 ** is NULL then json_err_cstr(code) is used.
1460 */
1461 void json_err( int code, char const * msg, char alsoOutput ){
1462 int rc = code ? code : (g.json.resultCode
1463 ? g.json.resultCode
1464 : FSL_JSON_E_UNKNOWN);
@@ -1465,11 +1465,11 @@
1465 cson_value * resp = NULL;
1466 rc = json_dumbdown_rc(rc);
1467 if( rc && !msg ){
1468 msg = g.zErrMsg;
1469 if(!msg){
1470 msg = json_err_cstr(rc);
1471 }
1472 }
1473 resp = json_create_response(rc, msg, NULL);
1474 if(!resp){
1475 /* about the only error case here is out-of-memory. DO NOT
@@ -1508,11 +1508,11 @@
1508 int json_set_err( int code, char const * fmt, ... ){
1509 assert( (code>=1000) && (code<=9999) );
1510 free(g.zErrMsg);
1511 g.json.resultCode = code;
1512 if(!fmt || !*fmt){
1513 g.zErrMsg = mprintf("%s", json_err_cstr(code));
1514 }else{
1515 va_list vargs;
1516 va_start(vargs,fmt);
1517 char * msg = vmprintf(fmt, vargs);
1518 va_end(vargs);
@@ -1567,10 +1567,71 @@
1567 }
1568 free(tags);
1569 }
1570 return v;
1571 }
1572
1573 /*
1574 ** Impl of /json/resultCodes
1575 **
1576 */
1577 cson_value * json_page_resultCodes(){
1578 cson_value * listV = cson_value_new_array();
1579 cson_array * list = cson_value_get_array(listV);
1580 cson_value * objV = NULL;
1581 cson_object * obj = NULL;
1582 int rc = cson_array_reserve( list, 35 );
1583 if(rc){
1584 assert( 0 && "Allocation error.");
1585 exit(1);
1586 }
1587 #define C(K) objV = cson_value_new_object(); obj = cson_value_get_object(objV); \
1588 cson_object_set(obj, "resultCode", json_new_string(json_rc_cstr(FSL_JSON_E_##K)) ); \
1589 cson_object_set(obj, "cSymbol", json_new_string("FSL_JSON_E_"#K) ); \
1590 cson_object_set(obj, "number", cson_value_new_integer(FSL_JSON_E_##K) ); \
1591 cson_object_set(obj, "description", json_new_string(json_err_cstr(FSL_JSON_E_##K))); \
1592 cson_array_append( list, objV ); obj = NULL; objV = NULL
1593
1594 C(GENERIC);
1595 C(INVALID_REQUEST);
1596 C(UNKNOWN_COMMAND);
1597 C(UNKNOWN);
1598 C(TIMEOUT);
1599 C(ASSERT);
1600 C(ALLOC);
1601 C(NYI);
1602 C(PANIC);
1603 C(MANIFEST_READ_FAILED);
1604 C(FILE_OPEN_FAILED);
1605
1606 C(AUTH);
1607 C(MISSING_AUTH);
1608 C(DENIED);
1609 C(WRONG_MODE);
1610 C(LOGIN_FAILED);
1611 C(LOGIN_FAILED_NOSEED);
1612 C(LOGIN_FAILED_NONAME);
1613 C(LOGIN_FAILED_NOPW);
1614 C(LOGIN_FAILED_NOTFOUND);
1615
1616 C(USAGE);
1617 C(INVALID_ARGS);
1618 C(MISSING_ARGS);
1619 C(AMBIGUOUS_UUID);
1620 C(UNRESOLVED_UUID);
1621 C(RESOURCE_ALREADY_EXISTS);
1622 C(RESOURCE_NOT_FOUND);
1623
1624 C(DB);
1625 C(STMT_PREP);
1626 C(STMT_BIND);
1627 C(STMT_EXEC);
1628 C(DB_LOCKED);
1629 C(DB_NEEDS_REBUILD);
1630 #undef C
1631 return listV;
1632 }
1633
1634
1635 /*
1636 ** /json/version implementation.
1637 **
@@ -1928,10 +1989,11 @@
1989 {"dir", json_page_nyi, 0},
1990 {"HAI",json_page_version,0},
1991 {"login",json_page_login,1},
1992 {"logout",json_page_logout,1},
1993 {"rebuild",json_page_rebuild,0},
1994 {"resultCodes", json_page_resultCodes,0},
1995 {"stat",json_page_stat,0},
1996 {"tag", json_page_nyi,0},
1997 {"ticket", json_page_nyi,0},
1998 {"timeline", json_page_timeline,0},
1999 {"user",json_page_user,0},
2000

Keyboard Shortcuts

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