Fossil SCM

/json/user/save now accepts its params from _either_ POST.payload _or_ GET/CLI, but does not allow a mixture of inputs.

stephan 2011-11-04 16:43 json-multitag-test
Commit bd9c3b3acabc78a681a4d656314587981e924562
1 file changed +27 -5
+27 -5
--- src/json_user.c
+++ src/json_user.c
@@ -278,14 +278,36 @@
278278
**
279279
** - Return something useful in the payload (at least the id of the
280280
** modified/created user).
281281
*/
282282
static cson_value * json_user_save(){
283
- if(! g.json.reqPayload.o ){
284
- json_set_err(FSL_JSON_E_MISSING_ARGS,
285
- "User data must be contained in the request payload.");
286
- return NULL;
283
+ if( g.json.reqPayload.o ){
284
+ json_user_update_from_json( g.json.reqPayload.o );
285
+ }else{
286
+ /* try to get user info from GET/CLI args and construct
287
+ a JSON form of it... */
288
+ cson_object * u = cson_new_object();
289
+ char const * str = NULL;
290
+ char b = -1;
291
+ int i = -1;
292
+#define PROP(LK) str = json_find_option_cstr(LK,NULL,NULL); \
293
+ if(str){ cson_object_set(u, LK, json_new_string(str)); } (void)0
294
+ PROP("name");
295
+ PROP("password");
296
+ PROP("info");
297
+ PROP("capabilities");
298
+#undef PROP
299
+
300
+#define PROP(LK) b = json_find_option_bool(LK,NULL,NULL,-1); \
301
+ if(b>=0){ cson_object_set(u, LK, cson_value_new_bool(b)); } (void)0
302
+ PROP("forceLogout");
303
+#undef PROP
287304
305
+#define PROP(LK) i = json_find_option_int(LK,NULL,NULL,-1); \
306
+ if(i>=0){ cson_object_set(u, LK, cson_value_new_integer(i)); } (void)0
307
+ PROP("uid");
308
+#undef PROP
309
+ json_user_update_from_json( u );
310
+ cson_free_object(u);
288311
}
289
- json_user_update_from_json( g.json.reqPayload.o );
290312
return NULL;
291313
}
292314
--- src/json_user.c
+++ src/json_user.c
@@ -278,14 +278,36 @@
278 **
279 ** - Return something useful in the payload (at least the id of the
280 ** modified/created user).
281 */
282 static cson_value * json_user_save(){
283 if(! g.json.reqPayload.o ){
284 json_set_err(FSL_JSON_E_MISSING_ARGS,
285 "User data must be contained in the request payload.");
286 return NULL;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
 
 
 
 
 
 
288 }
289 json_user_update_from_json( g.json.reqPayload.o );
290 return NULL;
291 }
292
--- src/json_user.c
+++ src/json_user.c
@@ -278,14 +278,36 @@
278 **
279 ** - Return something useful in the payload (at least the id of the
280 ** modified/created user).
281 */
282 static cson_value * json_user_save(){
283 if( g.json.reqPayload.o ){
284 json_user_update_from_json( g.json.reqPayload.o );
285 }else{
286 /* try to get user info from GET/CLI args and construct
287 a JSON form of it... */
288 cson_object * u = cson_new_object();
289 char const * str = NULL;
290 char b = -1;
291 int i = -1;
292 #define PROP(LK) str = json_find_option_cstr(LK,NULL,NULL); \
293 if(str){ cson_object_set(u, LK, json_new_string(str)); } (void)0
294 PROP("name");
295 PROP("password");
296 PROP("info");
297 PROP("capabilities");
298 #undef PROP
299
300 #define PROP(LK) b = json_find_option_bool(LK,NULL,NULL,-1); \
301 if(b>=0){ cson_object_set(u, LK, cson_value_new_bool(b)); } (void)0
302 PROP("forceLogout");
303 #undef PROP
304
305 #define PROP(LK) i = json_find_option_int(LK,NULL,NULL,-1); \
306 if(i>=0){ cson_object_set(u, LK, cson_value_new_integer(i)); } (void)0
307 PROP("uid");
308 #undef PROP
309 json_user_update_from_json( u );
310 cson_free_object(u);
311 }
 
312 return NULL;
313 }
314

Keyboard Shortcuts

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