| | @@ -28,56 +28,11 @@ |
| 28 | 28 | #include <assert.h> |
| 29 | 29 | #include <time.h> |
| 30 | 30 | |
| 31 | 31 | #if INTERFACE |
| 32 | 32 | #include "cson_amalgamation.h" |
| 33 | | -/* |
| 34 | | -** The "official" list of Fossil/JSON error codes. |
| 35 | | -** Their values might very well change during initial |
| 36 | | -** development but after their first public release |
| 37 | | -** they must stay stable. |
| 38 | | -** Values must be in the range 1..9999 |
| 39 | | -** |
| 40 | | -** Numbers evenly dividable by 100 are "categories", |
| 41 | | -** and error codes for a given category have their |
| 42 | | -** high bits set to the category value. |
| 43 | | -** |
| 44 | | -*/ |
| 45 | | -enum FossilJsonCodes { |
| 46 | | - |
| 47 | | -FSL_JSON_E_GENERIC = 1000, |
| 48 | | -FSL_JSON_E_GENERIC_SUB1 = FSL_JSON_E_GENERIC + 100, |
| 49 | | -FSL_JSON_E_INVALID_REQUEST = FSL_JSON_E_GENERIC_SUB1 + 1, |
| 50 | | -FSL_JSON_E_UNKNOWN_COMMAND = FSL_JSON_E_GENERIC_SUB1 + 2, |
| 51 | | -FSL_JSON_E_UNKNOWN = FSL_JSON_E_GENERIC_SUB1 + 3, |
| 52 | | -FSL_JSON_E_RESOURCE_NOT_FOUND = FSL_JSON_E_GENERIC_SUB1 + 4, |
| 53 | | -FSL_JSON_E_TIMEOUT = FSL_JSON_E_GENERIC_SUB1 + 5, |
| 54 | | -FSL_JSON_E_ASSERT = FSL_JSON_E_GENERIC_SUB1 + 6, |
| 55 | | -FSL_JSON_E_ALLOC = FSL_JSON_E_GENERIC_SUB1 + 7, |
| 56 | | -FSL_JSON_E_NYI = FSL_JSON_E_GENERIC_SUB1 + 8, |
| 57 | | - |
| 58 | | -FSL_JSON_E_AUTH = 2000, |
| 59 | | -/* #2001: re-use */ |
| 60 | | -FSL_JSON_E_MISSING_AUTH = FSL_JSON_E_AUTH + 2, |
| 61 | | -FSL_JSON_E_DENIED = FSL_JSON_E_AUTH + 3, |
| 62 | | -FSL_JSON_E_WRONG_MODE = FSL_JSON_E_AUTH + 4, |
| 63 | | - |
| 64 | | -FSL_JSON_E_LOGIN_FAILED = FSL_JSON_E_AUTH + 100, |
| 65 | | -FSL_JSON_E_LOGIN_FAILED_NONAME = FSL_JSON_E_LOGIN_FAILED + 1, |
| 66 | | -FSL_JSON_E_LOGIN_FAILED_NOPW = FSL_JSON_E_LOGIN_FAILED + 2, |
| 67 | | -FSL_JSON_E_LOGIN_FAILED_NOTFOUND = FSL_JSON_E_LOGIN_FAILED + 3, |
| 68 | | - |
| 69 | | -FSL_JSON_E_USAGE = 3000, |
| 70 | | -FSL_JSON_E_INVALID_ARGS = FSL_JSON_E_USAGE + 1, |
| 71 | | -FSL_JSON_E_MISSING_ARGS = FSL_JSON_E_USAGE + 2, |
| 72 | | - |
| 73 | | -FSL_JSON_E_DB = 4000, |
| 74 | | -FSL_JSON_E_STMT_PREP = FSL_JSON_E_DB + 1, |
| 75 | | -FSL_JSON_E_STMT_BIND = FSL_JSON_E_DB + 2, |
| 76 | | -FSL_JSON_E_STMT_EXEC = FSL_JSON_E_DB + 3, |
| 77 | | -FSL_JSON_E_DB_LOCKED = FSL_JSON_E_DB + 4 |
| 78 | | -}; |
| 33 | +#include "json_detail.h" /* workaround for apparent enum limitation in makeheaders */ |
| 79 | 34 | #endif |
| 80 | 35 | |
| 81 | 36 | /* |
| 82 | 37 | ** Holds keys used for various JSON API properties. |
| 83 | 38 | */ |
| | @@ -638,12 +593,12 @@ |
| 638 | 593 | ** |
| 639 | 594 | ** If g.isCGI then the generated error object replaces any currently |
| 640 | 595 | ** buffered page output. |
| 641 | 596 | ** |
| 642 | 597 | ** If alsoOutput is true AND g.isCGI then the cgi_reply() is called to |
| 643 | | -** flush the output (and headers). Generally only do this if you are about |
| 644 | | -** to call exit(). |
| 598 | +** flush the output (and headers). Generally only do this if you are |
| 599 | +** about to call exit(). |
| 645 | 600 | ** |
| 646 | 601 | ** !g.isCGI then alsoOutput is ignored and all output is sent to |
| 647 | 602 | ** stdout immediately. |
| 648 | 603 | ** |
| 649 | 604 | ** This clears any previously buffered CGI content, replacing it with |
| | @@ -690,10 +645,12 @@ |
| 690 | 645 | FSET(MANIFEST_YEAR,"manifestYear"); |
| 691 | 646 | FSET(RELEASE_VERSION,"releaseVersion"); |
| 692 | 647 | #undef FSET |
| 693 | 648 | cson_object_set( jobj, "releaseVersionNumber", |
| 694 | 649 | cson_value_new_integer(RELEASE_VERSION_NUMBER) ); |
| 650 | + cson_object_set( jobj, "resultCodeParanoiaLevel", |
| 651 | + cson_value_new_integer(g.json.errorDetailParanoia) ); |
| 695 | 652 | return jval; |
| 696 | 653 | } |
| 697 | 654 | |
| 698 | 655 | #if 0 |
| 699 | 656 | /* we have a disconnect here between fossil's server-mode QUERY_STRING |
| | @@ -1080,22 +1037,20 @@ |
| 1080 | 1037 | ** ... |
| 1081 | 1038 | ** |
| 1082 | 1039 | */ |
| 1083 | 1040 | void json_cmd_top(void){ |
| 1084 | 1041 | char const * cmd = NULL; |
| 1085 | | - unsigned int n; |
| 1086 | 1042 | int rc = 1002; |
| 1087 | 1043 | cson_value * payload = NULL; |
| 1088 | 1044 | JsonPageDef const * pageDef; |
| 1089 | 1045 | json_mode_bootstrap(); |
| 1090 | 1046 | if( g.argc<3 ){ |
| 1091 | 1047 | goto usage; |
| 1092 | 1048 | } |
| 1093 | 1049 | db_find_and_open_repository(0, 0); |
| 1094 | 1050 | cmd = json_command_arg(1); |
| 1095 | | - n = cmd ? strlen(cmd) : 0; |
| 1096 | | - if( n==0 ){ |
| 1051 | + if( !cmd || !*cmd ){ |
| 1097 | 1052 | goto usage; |
| 1098 | 1053 | } |
| 1099 | 1054 | cgi_set_content_type( cson_cgi_guess_content_type(&g.json.cgiCx) ); |
| 1100 | 1055 | pageDef = json_handler_for_name(cmd,&JsonPageDefs[0]); |
| 1101 | 1056 | if( ! pageDef ){ |
| | @@ -1116,12 +1071,12 @@ |
| 1116 | 1071 | if((0 != rc) && !g.isCGI){ |
| 1117 | 1072 | /* FIXME: we need a way of passing this error back |
| 1118 | 1073 | up to the routine which called this callback. |
| 1119 | 1074 | e.g. add g.errCode. |
| 1120 | 1075 | */ |
| 1121 | | - exit(1); |
| 1076 | + fossil_exit(1); |
| 1122 | 1077 | } |
| 1123 | 1078 | } |
| 1124 | 1079 | return; |
| 1125 | 1080 | usage: |
| 1126 | 1081 | usage("subcommand"); |
| 1127 | 1082 | } |
| 1128 | 1083 | |
| 1129 | 1084 | ADDED src/json_detail.h |