Fossil SCM
Added userName to /json/stat output for the nobody user (it was previously not set in that case). Renamed captcha to password in /json/anonymousPassword. Added NYI (not yet implemented) placeholders for several planned request types.
Commit
13cc3b823ffbb0d244bfacff022afda4fee3a547
Parent
cebf9919f87c667…
1 file changed
+38
-17
+38
-17
| --- src/json.c | ||
| +++ src/json.c | ||
| @@ -845,20 +845,24 @@ | ||
| 845 | 845 | cson_value * payload = cson_value_new_object(); |
| 846 | 846 | cson_value * sub = cson_value_new_object(); |
| 847 | 847 | char * zCap; |
| 848 | 848 | Stmt q; |
| 849 | 849 | cson_object * obj = cson_value_get_object(payload); |
| 850 | - if( g.zLogin ){ | |
| 851 | - cson_object_set( obj, "userName", | |
| 852 | - cson_value_new_string(g.zLogin,strlen(g.zLogin)) ); | |
| 853 | - } | |
| 854 | - db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid); | |
| 850 | + db_prepare(&q, "SELECT login, cap FROM user WHERE uid=%d", g.userUid); | |
| 855 | 851 | if( db_step(&q)==SQLITE_ROW ){ |
| 856 | - char const * zCap = (char const *)sqlite3_column_text(q.pStmt,0); | |
| 857 | - if( zCap ){ | |
| 852 | + /* reminder: we don't use g.zLogin because it's 0 for the guest | |
| 853 | + user and the HTML UI appears to currently allow the name to be | |
| 854 | + changed (but doing so would break other code). */ | |
| 855 | + char const * str = (char const *)sqlite3_column_text(q.pStmt,0); | |
| 856 | + if( str ){ | |
| 857 | + cson_object_set( obj, "userName", | |
| 858 | + cson_value_new_string(str,strlen(str)) ); | |
| 859 | + } | |
| 860 | + str = (char const *)sqlite3_column_text(q.pStmt,1); | |
| 861 | + if( str ){ | |
| 858 | 862 | cson_object_set( obj, "capabilities", |
| 859 | - cson_value_new_string(zCap,strlen(zCap)) ); | |
| 863 | + cson_value_new_string(str,strlen(str)) ); | |
| 860 | 864 | } |
| 861 | 865 | } |
| 862 | 866 | db_finalize(&q); |
| 863 | 867 | cson_object_set( obj, "permissionFlags", sub ); |
| 864 | 868 | obj = cson_value_get_object(sub); |
| @@ -1062,11 +1066,11 @@ | ||
| 1062 | 1066 | unsigned const int seed = captcha_seed(); |
| 1063 | 1067 | char const * zCaptcha = captcha_decode(seed); |
| 1064 | 1068 | cson_object_set(o, "seed", |
| 1065 | 1069 | cson_value_new_integer( (cson_int_t)seed ) |
| 1066 | 1070 | ); |
| 1067 | - cson_object_set(o, "captcha", | |
| 1071 | + cson_object_set(o, "password", | |
| 1068 | 1072 | cson_value_new_string( zCaptcha, strlen(zCaptcha) ) |
| 1069 | 1073 | ); |
| 1070 | 1074 | return v; |
| 1071 | 1075 | } |
| 1072 | 1076 | |
| @@ -1185,27 +1189,41 @@ | ||
| 1185 | 1189 | rows = cson_object_take( cson_value_get_object(jlist), "rows" ); |
| 1186 | 1190 | assert( NULL != rows ); |
| 1187 | 1191 | cson_value_free( jlist ); |
| 1188 | 1192 | return rows; |
| 1189 | 1193 | } |
| 1194 | + | |
| 1195 | +/* | |
| 1196 | +** Placeholder /json/XXX page impl for NYI (Not Yet Implemented) | |
| 1197 | +** (but planned) pages/commands. | |
| 1198 | +*/ | |
| 1199 | +static cson_value * json_page_nyi(void){ | |
| 1200 | + g.json.resultCode = FSL_JSON_E_NYI; | |
| 1201 | + return NULL; | |
| 1202 | +} | |
| 1203 | + | |
| 1190 | 1204 | |
| 1191 | 1205 | /* |
| 1192 | 1206 | ** Mapping of names to JSON pages/commands. Each name is a subpath of |
| 1193 | 1207 | ** /json (in CGI mode) or a subcommand of the json command in CLI mode |
| 1194 | 1208 | */ |
| 1195 | 1209 | static const JsonPageDef JsonPageDefs[] = { |
| 1196 | 1210 | /* please keep alphabetically sorted (case-insensitive) for maintenance reasons. */ |
| 1197 | -{"anonymousPassword", json_page_anon_password, 1}, | |
| 1211 | +{"anonymousPassword",json_page_anon_password, 1}, | |
| 1212 | +{"branch", json_page_nyi,0}, | |
| 1198 | 1213 | {"cap", json_page_cap, 0}, |
| 1199 | 1214 | {"HAI",json_page_version,0}, |
| 1200 | -{"login",json_page_login,1/*should be >0. Only 0 for dev/testing purposes.*/}, | |
| 1201 | -{"logout",json_page_logout,1/*should be >0. Only 0 for dev/testing purposes.*/}, | |
| 1215 | +{"login",json_page_login,1}, | |
| 1216 | +{"logout",json_page_logout,1}, | |
| 1202 | 1217 | {"stat",json_page_stat,0}, |
| 1218 | +{"tag", json_page_nyi,0}, | |
| 1219 | +{"ticket", json_page_nyi,0}, | |
| 1220 | +{"user", json_page_nyi,0}, | |
| 1203 | 1221 | {"version",json_page_version,0}, |
| 1204 | 1222 | {"wiki",json_page_wiki,0}, |
| 1205 | 1223 | /* Last entry MUST have a NULL name. */ |
| 1206 | -{NULL,NULL} | |
| 1224 | +{NULL,NULL,0} | |
| 1207 | 1225 | }; |
| 1208 | 1226 | |
| 1209 | 1227 | /* |
| 1210 | 1228 | ** WEBPAGE: json |
| 1211 | 1229 | ** |
| @@ -1221,11 +1239,11 @@ | ||
| 1221 | 1239 | json_mode_bootstrap(); |
| 1222 | 1240 | cmd = json_command_arg(1); |
| 1223 | 1241 | /*cgi_printf("{\"cmd\":\"%s\"}\n",cmd); return;*/ |
| 1224 | 1242 | pageDef = json_handler_for_name(cmd,&JsonPageDefs[0]); |
| 1225 | 1243 | if( ! pageDef ){ |
| 1226 | - json_err( FSL_JSON_E_UNKNOWN_COMMAND, cmd, 0 ); | |
| 1244 | + json_err( FSL_JSON_E_UNKNOWN_COMMAND, NULL, 0 ); | |
| 1227 | 1245 | return; |
| 1228 | 1246 | }else if( pageDef->runMode < 0 /*CLI only*/){ |
| 1229 | 1247 | rc = FSL_JSON_E_WRONG_MODE; |
| 1230 | 1248 | }else{ |
| 1231 | 1249 | rc = 0; |
| @@ -1243,23 +1261,26 @@ | ||
| 1243 | 1261 | } |
| 1244 | 1262 | |
| 1245 | 1263 | /* |
| 1246 | 1264 | ** COMMAND: json |
| 1247 | 1265 | ** |
| 1248 | -** Usage: %fossil json subcommand | |
| 1266 | +** Usage: %fossil json SUBCOMMAND | |
| 1249 | 1267 | ** |
| 1250 | 1268 | ** The commands include: |
| 1251 | 1269 | ** |
| 1270 | +** cap | |
| 1252 | 1271 | ** stat |
| 1253 | 1272 | ** version (alias: HAI) |
| 1254 | 1273 | ** |
| 1255 | 1274 | ** |
| 1256 | 1275 | ** TODOs: |
| 1257 | 1276 | ** |
| 1258 | -** wiki | |
| 1277 | +** branch | |
| 1278 | +** tag | |
| 1279 | +** ticket | |
| 1259 | 1280 | ** timeline |
| 1260 | -** tickets | |
| 1281 | +** wiki | |
| 1261 | 1282 | ** ... |
| 1262 | 1283 | ** |
| 1263 | 1284 | */ |
| 1264 | 1285 | void json_cmd_top(void){ |
| 1265 | 1286 | char const * cmd = NULL; |
| 1266 | 1287 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -845,20 +845,24 @@ | |
| 845 | cson_value * payload = cson_value_new_object(); |
| 846 | cson_value * sub = cson_value_new_object(); |
| 847 | char * zCap; |
| 848 | Stmt q; |
| 849 | cson_object * obj = cson_value_get_object(payload); |
| 850 | if( g.zLogin ){ |
| 851 | cson_object_set( obj, "userName", |
| 852 | cson_value_new_string(g.zLogin,strlen(g.zLogin)) ); |
| 853 | } |
| 854 | db_prepare(&q, "SELECT cap FROM user WHERE uid=%d", g.userUid); |
| 855 | if( db_step(&q)==SQLITE_ROW ){ |
| 856 | char const * zCap = (char const *)sqlite3_column_text(q.pStmt,0); |
| 857 | if( zCap ){ |
| 858 | cson_object_set( obj, "capabilities", |
| 859 | cson_value_new_string(zCap,strlen(zCap)) ); |
| 860 | } |
| 861 | } |
| 862 | db_finalize(&q); |
| 863 | cson_object_set( obj, "permissionFlags", sub ); |
| 864 | obj = cson_value_get_object(sub); |
| @@ -1062,11 +1066,11 @@ | |
| 1062 | unsigned const int seed = captcha_seed(); |
| 1063 | char const * zCaptcha = captcha_decode(seed); |
| 1064 | cson_object_set(o, "seed", |
| 1065 | cson_value_new_integer( (cson_int_t)seed ) |
| 1066 | ); |
| 1067 | cson_object_set(o, "captcha", |
| 1068 | cson_value_new_string( zCaptcha, strlen(zCaptcha) ) |
| 1069 | ); |
| 1070 | return v; |
| 1071 | } |
| 1072 | |
| @@ -1185,27 +1189,41 @@ | |
| 1185 | rows = cson_object_take( cson_value_get_object(jlist), "rows" ); |
| 1186 | assert( NULL != rows ); |
| 1187 | cson_value_free( jlist ); |
| 1188 | return rows; |
| 1189 | } |
| 1190 | |
| 1191 | /* |
| 1192 | ** Mapping of names to JSON pages/commands. Each name is a subpath of |
| 1193 | ** /json (in CGI mode) or a subcommand of the json command in CLI mode |
| 1194 | */ |
| 1195 | static const JsonPageDef JsonPageDefs[] = { |
| 1196 | /* please keep alphabetically sorted (case-insensitive) for maintenance reasons. */ |
| 1197 | {"anonymousPassword", json_page_anon_password, 1}, |
| 1198 | {"cap", json_page_cap, 0}, |
| 1199 | {"HAI",json_page_version,0}, |
| 1200 | {"login",json_page_login,1/*should be >0. Only 0 for dev/testing purposes.*/}, |
| 1201 | {"logout",json_page_logout,1/*should be >0. Only 0 for dev/testing purposes.*/}, |
| 1202 | {"stat",json_page_stat,0}, |
| 1203 | {"version",json_page_version,0}, |
| 1204 | {"wiki",json_page_wiki,0}, |
| 1205 | /* Last entry MUST have a NULL name. */ |
| 1206 | {NULL,NULL} |
| 1207 | }; |
| 1208 | |
| 1209 | /* |
| 1210 | ** WEBPAGE: json |
| 1211 | ** |
| @@ -1221,11 +1239,11 @@ | |
| 1221 | json_mode_bootstrap(); |
| 1222 | cmd = json_command_arg(1); |
| 1223 | /*cgi_printf("{\"cmd\":\"%s\"}\n",cmd); return;*/ |
| 1224 | pageDef = json_handler_for_name(cmd,&JsonPageDefs[0]); |
| 1225 | if( ! pageDef ){ |
| 1226 | json_err( FSL_JSON_E_UNKNOWN_COMMAND, cmd, 0 ); |
| 1227 | return; |
| 1228 | }else if( pageDef->runMode < 0 /*CLI only*/){ |
| 1229 | rc = FSL_JSON_E_WRONG_MODE; |
| 1230 | }else{ |
| 1231 | rc = 0; |
| @@ -1243,23 +1261,26 @@ | |
| 1243 | } |
| 1244 | |
| 1245 | /* |
| 1246 | ** COMMAND: json |
| 1247 | ** |
| 1248 | ** Usage: %fossil json subcommand |
| 1249 | ** |
| 1250 | ** The commands include: |
| 1251 | ** |
| 1252 | ** stat |
| 1253 | ** version (alias: HAI) |
| 1254 | ** |
| 1255 | ** |
| 1256 | ** TODOs: |
| 1257 | ** |
| 1258 | ** wiki |
| 1259 | ** timeline |
| 1260 | ** tickets |
| 1261 | ** ... |
| 1262 | ** |
| 1263 | */ |
| 1264 | void json_cmd_top(void){ |
| 1265 | char const * cmd = NULL; |
| 1266 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -845,20 +845,24 @@ | |
| 845 | cson_value * payload = cson_value_new_object(); |
| 846 | cson_value * sub = cson_value_new_object(); |
| 847 | char * zCap; |
| 848 | Stmt q; |
| 849 | cson_object * obj = cson_value_get_object(payload); |
| 850 | db_prepare(&q, "SELECT login, cap FROM user WHERE uid=%d", g.userUid); |
| 851 | if( db_step(&q)==SQLITE_ROW ){ |
| 852 | /* reminder: we don't use g.zLogin because it's 0 for the guest |
| 853 | user and the HTML UI appears to currently allow the name to be |
| 854 | changed (but doing so would break other code). */ |
| 855 | char const * str = (char const *)sqlite3_column_text(q.pStmt,0); |
| 856 | if( str ){ |
| 857 | cson_object_set( obj, "userName", |
| 858 | cson_value_new_string(str,strlen(str)) ); |
| 859 | } |
| 860 | str = (char const *)sqlite3_column_text(q.pStmt,1); |
| 861 | if( str ){ |
| 862 | cson_object_set( obj, "capabilities", |
| 863 | cson_value_new_string(str,strlen(str)) ); |
| 864 | } |
| 865 | } |
| 866 | db_finalize(&q); |
| 867 | cson_object_set( obj, "permissionFlags", sub ); |
| 868 | obj = cson_value_get_object(sub); |
| @@ -1062,11 +1066,11 @@ | |
| 1066 | unsigned const int seed = captcha_seed(); |
| 1067 | char const * zCaptcha = captcha_decode(seed); |
| 1068 | cson_object_set(o, "seed", |
| 1069 | cson_value_new_integer( (cson_int_t)seed ) |
| 1070 | ); |
| 1071 | cson_object_set(o, "password", |
| 1072 | cson_value_new_string( zCaptcha, strlen(zCaptcha) ) |
| 1073 | ); |
| 1074 | return v; |
| 1075 | } |
| 1076 | |
| @@ -1185,27 +1189,41 @@ | |
| 1189 | rows = cson_object_take( cson_value_get_object(jlist), "rows" ); |
| 1190 | assert( NULL != rows ); |
| 1191 | cson_value_free( jlist ); |
| 1192 | return rows; |
| 1193 | } |
| 1194 | |
| 1195 | /* |
| 1196 | ** Placeholder /json/XXX page impl for NYI (Not Yet Implemented) |
| 1197 | ** (but planned) pages/commands. |
| 1198 | */ |
| 1199 | static cson_value * json_page_nyi(void){ |
| 1200 | g.json.resultCode = FSL_JSON_E_NYI; |
| 1201 | return NULL; |
| 1202 | } |
| 1203 | |
| 1204 | |
| 1205 | /* |
| 1206 | ** Mapping of names to JSON pages/commands. Each name is a subpath of |
| 1207 | ** /json (in CGI mode) or a subcommand of the json command in CLI mode |
| 1208 | */ |
| 1209 | static const JsonPageDef JsonPageDefs[] = { |
| 1210 | /* please keep alphabetically sorted (case-insensitive) for maintenance reasons. */ |
| 1211 | {"anonymousPassword",json_page_anon_password, 1}, |
| 1212 | {"branch", json_page_nyi,0}, |
| 1213 | {"cap", json_page_cap, 0}, |
| 1214 | {"HAI",json_page_version,0}, |
| 1215 | {"login",json_page_login,1}, |
| 1216 | {"logout",json_page_logout,1}, |
| 1217 | {"stat",json_page_stat,0}, |
| 1218 | {"tag", json_page_nyi,0}, |
| 1219 | {"ticket", json_page_nyi,0}, |
| 1220 | {"user", json_page_nyi,0}, |
| 1221 | {"version",json_page_version,0}, |
| 1222 | {"wiki",json_page_wiki,0}, |
| 1223 | /* Last entry MUST have a NULL name. */ |
| 1224 | {NULL,NULL,0} |
| 1225 | }; |
| 1226 | |
| 1227 | /* |
| 1228 | ** WEBPAGE: json |
| 1229 | ** |
| @@ -1221,11 +1239,11 @@ | |
| 1239 | json_mode_bootstrap(); |
| 1240 | cmd = json_command_arg(1); |
| 1241 | /*cgi_printf("{\"cmd\":\"%s\"}\n",cmd); return;*/ |
| 1242 | pageDef = json_handler_for_name(cmd,&JsonPageDefs[0]); |
| 1243 | if( ! pageDef ){ |
| 1244 | json_err( FSL_JSON_E_UNKNOWN_COMMAND, NULL, 0 ); |
| 1245 | return; |
| 1246 | }else if( pageDef->runMode < 0 /*CLI only*/){ |
| 1247 | rc = FSL_JSON_E_WRONG_MODE; |
| 1248 | }else{ |
| 1249 | rc = 0; |
| @@ -1243,23 +1261,26 @@ | |
| 1261 | } |
| 1262 | |
| 1263 | /* |
| 1264 | ** COMMAND: json |
| 1265 | ** |
| 1266 | ** Usage: %fossil json SUBCOMMAND |
| 1267 | ** |
| 1268 | ** The commands include: |
| 1269 | ** |
| 1270 | ** cap |
| 1271 | ** stat |
| 1272 | ** version (alias: HAI) |
| 1273 | ** |
| 1274 | ** |
| 1275 | ** TODOs: |
| 1276 | ** |
| 1277 | ** branch |
| 1278 | ** tag |
| 1279 | ** ticket |
| 1280 | ** timeline |
| 1281 | ** wiki |
| 1282 | ** ... |
| 1283 | ** |
| 1284 | */ |
| 1285 | void json_cmd_top(void){ |
| 1286 | char const * cmd = NULL; |
| 1287 |