Fossil SCM

Added /json/user/xyz to ajax demo. /json/user/get/USERNAME now works as an alias for ?name=USERNAME.

stephan 2011-09-27 01:32 UTC json
Commit 585be130f33f54ea905c3c700a5be6bc72596023
2 files changed +2 +11 -4
--- ajax/index.html
+++ ajax/index.html
@@ -211,10 +211,12 @@
211211
<input type='button' value='timeline/ci' onclick='TheApp.cgi.sendCommand("/json/timeline/ci")' />
212212
<input type='button' value='timeline/wiki' onclick='TheApp.cgi.sendCommand("/json/timeline/wiki")' />
213213
<input type='button' value='timeline/ticket' onclick='TheApp.cgi.sendCommand("/json/timeline/ticket")' />
214214
<input type='button' value='wiki/list' onclick='TheApp.cgi.sendCommand("/json/wiki/list")' />
215215
<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")' />
216218
217219
<!--
218220
<input type='button' value='get whiki' onclick='TheApp.cgi.getPages("whiki")' />
219221
<input type='button' value='get more' onclick='TheApp.cgi.getPages("HelloWorld/WhikiNews")' />
220222
<input type='button' value='get client data' onclick='TheApp.cgi.getPageClientData("HelloWorld/whiki/WhikiCommands")' />
221223
--- 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 @@
815815
** of bounds or there is no "json" path element.
816816
**
817817
** In CLI mode the "path" is the list of arguments (skipping argv[0]).
818818
** In server/CGI modes the path is taken from PATH_INFO.
819819
**
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
+**
820824
*/
821825
char const * json_command_arg(unsigned char ndx){
822826
cson_array * ar = g.json.cmd.a;
823827
assert((NULL!=ar) && "Internal error. Was json_mode_bootstrap() called?");
824828
assert((g.argc>1) && "Internal error - we never should have gotten this far.");
@@ -1511,14 +1515,17 @@
15111515
Stmt q;
15121516
if(!g.perm.Admin){
15131517
g.json.resultCode = FSL_JSON_E_DENIED;
15141518
return NULL;
15151519
}
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
+ */;
15201527
}
15211528
if(!pUser || !*pUser){
15221529
g.json.resultCode = FSL_JSON_E_MISSING_ARGS;
15231530
return NULL;
15241531
}
15251532
--- 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

Keyboard Shortcuts

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