-
- /* nothing appropriate */
- bad_request(req);
- return 0;
-}
-
-/*
- * retrieves the 'runid' in parameters received with the
- * request 'req'.
- *
- * Returns 1 in case of success.
- * Otherwise, if the 'runid' can't be retrieved, an error stating
- * the bad request is replied for 'req' and 0 is returned.
- */
-static int onrunid(afb_req_t req, int *runid)
-{
- struct json_object *json;
- const char *appid;
-
- /* get the paramaters of the request */
- json = afb_req_json(req);
-
- /* get the runid if any */
- if (!wrap_json_unpack(json, "i", runid)
- || !wrap_json_unpack(json, "{si}", _runid_, runid)) {
- INFO("method %s called for %d", afb_req_get_called_verb(req), *runid);
- return 1;
+
+ /* args is a string value: either an ID or a widget path */
+ else if (json_object_is_type(args, json_type_string)) {
+ if (expected & (Param_Id | Param_RunId)) {
+ params->id = json_object_get_string(args);
+ found |= Param_Id;
+ }
+ else if (expected & Param_WGT) {
+ params->wgt = json_object_get_string(args);
+ found |= Param_WGT;
+ }
+ }
+
+ /* args is a object value: inspect it */
+ else if (json_object_is_type(args, json_type_object)) {
+ /* get UID */
+ if (json_object_object_get_ex(args, _uid_, &obj)) {
+ if (!json_object_is_type(obj, json_type_int))
+ error = 1;
+ else {
+ id = json_object_get_int(obj);
+ if (id < 0)
+ error = error_bad_request;
+ else if (params->uid != id) {
+ if (!afb_req_has_permission(req, auth_perm_set_uid.text))
+ error = error_forbidden;
+ else {
+ params->uid = id;
+ }
+ }
+ }
+ }
+
+ /* get all */
+ if ((expected & Param_All)
+ && json_object_object_get_ex(args, _all_, &obj)) {
+ params->all = json_object_get_boolean(obj);
+ if (params->all && !has_auth(req, &auth_view_all))
+ error = error_forbidden;
+ else
+ found |= Param_All;
+ }
+
+ /* get force */
+ if ((expected & Param_Force)
+ && json_object_object_get_ex(args, _force_, &obj)) {
+ params->force = json_object_get_boolean(obj);
+ found |= Param_Force;
+ }
+
+ /* get reload */
+ if ((expected & Param_Reload)
+ && json_object_object_get_ex(args, _reload_, &obj)) {
+ params->reload = json_object_get_boolean(obj);
+ found |= Param_Reload;
+ }
+
+ /* get languages */
+ if ((expected & Param_Lang)
+ && json_object_object_get_ex(args, _lang_, &obj)) {
+ params->lang = json_object_get_string(obj);
+ found |= Param_Lang;
+ }
+
+ /* get root */
+ if ((expected & Param_Root)
+ && json_object_object_get_ex(args, _root_, &obj)) {
+ params->root = json_object_get_string(obj);
+ found |= Param_Root;
+ }
+
+ /* get WGT */
+ if (expected & Param_WGT) {
+ if (json_object_object_get_ex(args, _wgt_, &obj)) {
+ params->wgt = json_object_get_string(obj);
+ found |= Param_WGT;
+ }
+ }
+
+ /* get appid */
+ if (expected & (Param_Id | Param_RunId)) {
+ if (json_object_object_get_ex(args, _id_, &obj)) {
+ params->id = json_object_get_string(obj);
+ found |= Param_Id;
+ }
+ }
+
+ /* get runid */
+ if (expected & Param_RunId) {
+ if (json_object_object_get_ex(args, _runid_, &obj)) {
+ if (json_object_is_type(obj, json_type_int))
+ error = error_bad_request;
+ else {
+ params->runid = json_object_get_int(obj);
+ found |= Param_RunId;
+ }
+ }
+ }