Fossil SCM
Added /json/user/xyz to ajax demo. /json/user/get/USERNAME now works as an alias for ?name=USERNAME.
Commit
585be130f33f54ea905c3c700a5be6bc72596023
Parent
821830d2fbc1133…
2 files changed
+2
+11
-4
+2
| --- ajax/index.html | ||
| +++ ajax/index.html | ||
| @@ -211,10 +211,12 @@ | ||
| 211 | 211 | <input type='button' value='timeline/ci' onclick='TheApp.cgi.sendCommand("/json/timeline/ci")' /> |
| 212 | 212 | <input type='button' value='timeline/wiki' onclick='TheApp.cgi.sendCommand("/json/timeline/wiki")' /> |
| 213 | 213 | <input type='button' value='timeline/ticket' onclick='TheApp.cgi.sendCommand("/json/timeline/ticket")' /> |
| 214 | 214 | <input type='button' value='wiki/list' onclick='TheApp.cgi.sendCommand("/json/wiki/list")' /> |
| 215 | 215 | <input type='button' value='wiki/get Fossil' onclick='TheApp.cgi.sendCommand("/json/wiki/get",{"page":"Fossil"})' /> |
| 216 | +<input type='button' value='user/list' onclick='TheApp.cgi.sendCommand("/json/user/list")' /> | |
| 217 | +<input type='button' value='user/get' onclick='TheApp.cgi.sendCommand("/json/user/get?name=anonymous")' /> | |
| 216 | 218 | |
| 217 | 219 | <!-- |
| 218 | 220 | <input type='button' value='get whiki' onclick='TheApp.cgi.getPages("whiki")' /> |
| 219 | 221 | <input type='button' value='get more' onclick='TheApp.cgi.getPages("HelloWorld/WhikiNews")' /> |
| 220 | 222 | <input type='button' value='get client data' onclick='TheApp.cgi.getPageClientData("HelloWorld/whiki/WhikiCommands")' /> |
| 221 | 223 |
| --- ajax/index.html | |
| +++ ajax/index.html | |
| @@ -211,10 +211,12 @@ | |
| 211 | <input type='button' value='timeline/ci' onclick='TheApp.cgi.sendCommand("/json/timeline/ci")' /> |
| 212 | <input type='button' value='timeline/wiki' onclick='TheApp.cgi.sendCommand("/json/timeline/wiki")' /> |
| 213 | <input type='button' value='timeline/ticket' onclick='TheApp.cgi.sendCommand("/json/timeline/ticket")' /> |
| 214 | <input type='button' value='wiki/list' onclick='TheApp.cgi.sendCommand("/json/wiki/list")' /> |
| 215 | <input type='button' value='wiki/get Fossil' onclick='TheApp.cgi.sendCommand("/json/wiki/get",{"page":"Fossil"})' /> |
| 216 | |
| 217 | <!-- |
| 218 | <input type='button' value='get whiki' onclick='TheApp.cgi.getPages("whiki")' /> |
| 219 | <input type='button' value='get more' onclick='TheApp.cgi.getPages("HelloWorld/WhikiNews")' /> |
| 220 | <input type='button' value='get client data' onclick='TheApp.cgi.getPageClientData("HelloWorld/whiki/WhikiCommands")' /> |
| 221 |
| --- ajax/index.html | |
| +++ ajax/index.html | |
| @@ -211,10 +211,12 @@ | |
| 211 | <input type='button' value='timeline/ci' onclick='TheApp.cgi.sendCommand("/json/timeline/ci")' /> |
| 212 | <input type='button' value='timeline/wiki' onclick='TheApp.cgi.sendCommand("/json/timeline/wiki")' /> |
| 213 | <input type='button' value='timeline/ticket' onclick='TheApp.cgi.sendCommand("/json/timeline/ticket")' /> |
| 214 | <input type='button' value='wiki/list' onclick='TheApp.cgi.sendCommand("/json/wiki/list")' /> |
| 215 | <input type='button' value='wiki/get Fossil' onclick='TheApp.cgi.sendCommand("/json/wiki/get",{"page":"Fossil"})' /> |
| 216 | <input type='button' value='user/list' onclick='TheApp.cgi.sendCommand("/json/user/list")' /> |
| 217 | <input type='button' value='user/get' onclick='TheApp.cgi.sendCommand("/json/user/get?name=anonymous")' /> |
| 218 | |
| 219 | <!-- |
| 220 | <input type='button' value='get whiki' onclick='TheApp.cgi.getPages("whiki")' /> |
| 221 | <input type='button' value='get more' onclick='TheApp.cgi.getPages("HelloWorld/WhikiNews")' /> |
| 222 | <input type='button' value='get client data' onclick='TheApp.cgi.getPageClientData("HelloWorld/whiki/WhikiCommands")' /> |
| 223 |
+11
-4
| --- src/json.c | ||
| +++ src/json.c | ||
| @@ -815,10 +815,14 @@ | ||
| 815 | 815 | ** of bounds or there is no "json" path element. |
| 816 | 816 | ** |
| 817 | 817 | ** In CLI mode the "path" is the list of arguments (skipping argv[0]). |
| 818 | 818 | ** In server/CGI modes the path is taken from PATH_INFO. |
| 819 | 819 | ** |
| 820 | +** The returned bytes are owned by g.json.cmd.v and _may_ be | |
| 821 | +** invalidated if that object is modified (depending on how it is | |
| 822 | +** modified). | |
| 823 | +** | |
| 820 | 824 | */ |
| 821 | 825 | char const * json_command_arg(unsigned char ndx){ |
| 822 | 826 | cson_array * ar = g.json.cmd.a; |
| 823 | 827 | assert((NULL!=ar) && "Internal error. Was json_mode_bootstrap() called?"); |
| 824 | 828 | assert((g.argc>1) && "Internal error - we never should have gotten this far."); |
| @@ -1511,14 +1515,17 @@ | ||
| 1511 | 1515 | Stmt q; |
| 1512 | 1516 | if(!g.perm.Admin){ |
| 1513 | 1517 | g.json.resultCode = FSL_JSON_E_DENIED; |
| 1514 | 1518 | return NULL; |
| 1515 | 1519 | } |
| 1516 | - if( g.isHTTP ){ | |
| 1517 | - pUser = json_getenv_cstr("name"); | |
| 1518 | - }else{ | |
| 1519 | - pUser = json_command_arg(g.json.dispatchDepth+1); | |
| 1520 | + pUser = json_command_arg(g.json.dispatchDepth+1); | |
| 1521 | + if( g.isHTTP && (!pUser || !*pUser) ){ | |
| 1522 | + pUser = json_getenv_cstr("name") | |
| 1523 | + /* ACHTUNG: fossil apparently internally sets name=user/get/XYZ | |
| 1524 | + if we pass the name as part of the path, so we check the path | |
| 1525 | + _before_ checking for name=XYZ. | |
| 1526 | + */; | |
| 1520 | 1527 | } |
| 1521 | 1528 | if(!pUser || !*pUser){ |
| 1522 | 1529 | g.json.resultCode = FSL_JSON_E_MISSING_ARGS; |
| 1523 | 1530 | return NULL; |
| 1524 | 1531 | } |
| 1525 | 1532 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -815,10 +815,14 @@ | |
| 815 | ** of bounds or there is no "json" path element. |
| 816 | ** |
| 817 | ** In CLI mode the "path" is the list of arguments (skipping argv[0]). |
| 818 | ** In server/CGI modes the path is taken from PATH_INFO. |
| 819 | ** |
| 820 | */ |
| 821 | char const * json_command_arg(unsigned char ndx){ |
| 822 | cson_array * ar = g.json.cmd.a; |
| 823 | assert((NULL!=ar) && "Internal error. Was json_mode_bootstrap() called?"); |
| 824 | assert((g.argc>1) && "Internal error - we never should have gotten this far."); |
| @@ -1511,14 +1515,17 @@ | |
| 1511 | Stmt q; |
| 1512 | if(!g.perm.Admin){ |
| 1513 | g.json.resultCode = FSL_JSON_E_DENIED; |
| 1514 | return NULL; |
| 1515 | } |
| 1516 | if( g.isHTTP ){ |
| 1517 | pUser = json_getenv_cstr("name"); |
| 1518 | }else{ |
| 1519 | pUser = json_command_arg(g.json.dispatchDepth+1); |
| 1520 | } |
| 1521 | if(!pUser || !*pUser){ |
| 1522 | g.json.resultCode = FSL_JSON_E_MISSING_ARGS; |
| 1523 | return NULL; |
| 1524 | } |
| 1525 |
| --- src/json.c | |
| +++ src/json.c | |
| @@ -815,10 +815,14 @@ | |
| 815 | ** of bounds or there is no "json" path element. |
| 816 | ** |
| 817 | ** In CLI mode the "path" is the list of arguments (skipping argv[0]). |
| 818 | ** In server/CGI modes the path is taken from PATH_INFO. |
| 819 | ** |
| 820 | ** The returned bytes are owned by g.json.cmd.v and _may_ be |
| 821 | ** invalidated if that object is modified (depending on how it is |
| 822 | ** modified). |
| 823 | ** |
| 824 | */ |
| 825 | char const * json_command_arg(unsigned char ndx){ |
| 826 | cson_array * ar = g.json.cmd.a; |
| 827 | assert((NULL!=ar) && "Internal error. Was json_mode_bootstrap() called?"); |
| 828 | assert((g.argc>1) && "Internal error - we never should have gotten this far."); |
| @@ -1511,14 +1515,17 @@ | |
| 1515 | Stmt q; |
| 1516 | if(!g.perm.Admin){ |
| 1517 | g.json.resultCode = FSL_JSON_E_DENIED; |
| 1518 | return NULL; |
| 1519 | } |
| 1520 | pUser = json_command_arg(g.json.dispatchDepth+1); |
| 1521 | if( g.isHTTP && (!pUser || !*pUser) ){ |
| 1522 | pUser = json_getenv_cstr("name") |
| 1523 | /* ACHTUNG: fossil apparently internally sets name=user/get/XYZ |
| 1524 | if we pass the name as part of the path, so we check the path |
| 1525 | _before_ checking for name=XYZ. |
| 1526 | */; |
| 1527 | } |
| 1528 | if(!pUser || !*pUser){ |
| 1529 | g.json.resultCode = FSL_JSON_E_MISSING_ARGS; |
| 1530 | return NULL; |
| 1531 | } |
| 1532 |