diff --git a/src/api/api_idnode.c b/src/api/api_idnode.c index 9ba3eccb..42a5f1c8 100644 --- a/src/api/api_idnode.c +++ b/src/api/api_idnode.c @@ -187,7 +187,7 @@ api_idnode_load { int err = 0; idnode_t *in; - htsmsg_t *t, *l = NULL; + htsmsg_t *uuids, *l = NULL; htsmsg_field_t *f; const char *uuid, *class; @@ -195,35 +195,32 @@ api_idnode_load if ((class = htsmsg_get_str(args, "class"))) return api_idnode_load_by_class(class, args, resp); - /* ID based */ + /* UUIDs */ if (!(f = htsmsg_field_find(args, "uuid"))) return EINVAL; + if (!(uuids = htsmsg_field_get_list(f))) + if (!(uuid = htsmsg_field_get_str(f))) + return EINVAL; pthread_mutex_lock(&global_lock); - /* Single */ - if (f->hmf_type == HMF_STR) { - uuid = htsmsg_field_get_string(f); - in = idnode_find(uuid, NULL); - if (in) { - l = htsmsg_create_list(); - htsmsg_add_msg(l, NULL, idnode_serialize(in)); - } else - err = ENOENT; - /* Multiple */ - } else if (f->hmf_type == HMF_LIST) { - t = htsmsg_get_list_by_field(f); + if (uuids) { l = htsmsg_create_list(); - HTSMSG_FOREACH(f, t) { - if (!(uuid = htsmsg_field_get_string(f))) continue; + HTSMSG_FOREACH(f, uuids) { + if (!(uuid = htsmsg_field_get_str(f))) continue; if (!(in = idnode_find(uuid, NULL))) continue; htsmsg_add_msg(l, NULL, idnode_serialize(in)); } - /* Invalid */ + /* Single */ } else { - err = EINVAL; + if (!(in = idnode_find(uuid, NULL))) + err = ENOENT; + else { + l = htsmsg_create_list(); + htsmsg_add_msg(l, NULL, idnode_serialize(in)); + } } if (l) { @@ -242,30 +239,31 @@ api_idnode_save { int err = EINVAL; idnode_t *in; - htsmsg_t *conf, *l; + htsmsg_t *msg, *conf; htsmsg_field_t *f; const char *uuid; if (!(f = htsmsg_field_find(args, "node"))) return EINVAL; + if (!(msg = htsmsg_field_get_list(f))) + if (!(msg = htsmsg_field_get_map(f))) + return EINVAL; pthread_mutex_lock(&global_lock); /* Single */ - if (f->hmf_type == HMF_MAP) { - conf = htsmsg_get_map_by_field(f); - if (!(uuid = htsmsg_get_str(conf, "uuid"))) + if (!msg->hm_islist) { + if (!(uuid = htsmsg_get_str(msg, "uuid"))) goto exit; if (!(in = idnode_find(uuid, NULL))) goto exit; - idnode_update(in, conf); + idnode_update(in, msg); err = 0; /* Multiple */ - } else if (f->hmf_type == HMF_LIST) { - l = htsmsg_get_list_by_field(f); - HTSMSG_FOREACH(f, l) { - if (!(conf = htsmsg_get_map_by_field(f))) + } else { + HTSMSG_FOREACH(f, msg) { + if (!(conf = htsmsg_field_get_map(f))) continue; if (!(uuid = htsmsg_get_str(conf, "uuid"))) continue; @@ -274,10 +272,6 @@ api_idnode_save idnode_update(in, conf); } err = 0; - - /* Invalid */ - } else { - err = EINVAL; } // TODO: return updated UUIDs? @@ -382,39 +376,36 @@ api_idnode_delete { int err = 0; idnode_t *in; - htsmsg_t *l; + htsmsg_t *uuids; htsmsg_field_t *f; const char *uuid; /* ID based */ if (!(f = htsmsg_field_find(args, "uuid"))) return EINVAL; + if (!(uuids = htsmsg_field_get_list(f))) + if (!(uuid = htsmsg_field_get_str(f))) + return EINVAL; pthread_mutex_lock(&global_lock); - /* Single */ - if (f->hmf_type == HMF_STR) { - uuid = htsmsg_field_get_string(f); - in = idnode_find(uuid, NULL); - if (in) { - idnode_delete(in); - } else - err = ENOENT; - /* Multiple */ - } else if (f->hmf_type == HMF_LIST) { - l = htsmsg_get_list_by_field(f); - HTSMSG_FOREACH(f, l) { + if (uuids) { + HTSMSG_FOREACH(f, uuids) { if (!(uuid = htsmsg_field_get_string(f))) continue; if (!(in = idnode_find(uuid, NULL))) continue; idnode_delete(in); } + + /* Single */ + } else { + uuid = htsmsg_field_get_string(f); + if (!(in = idnode_find(uuid, NULL))) + err = ENOENT; + else + idnode_delete(in); } - // TODO: should we return the UUIDs that are deleted? - if (!err) - *resp = htsmsg_create_map(); - pthread_mutex_unlock(&global_lock); return err; diff --git a/src/api/api_mpegts.c b/src/api/api_mpegts.c index a20e6ae3..b75fe6e7 100644 --- a/src/api/api_mpegts.c +++ b/src/api/api_mpegts.c @@ -117,9 +117,9 @@ api_mpegts_network_create mpegts_network_t *mn; if (!(class = htsmsg_get_str(args, "class"))) - return -EINVAL; + return EINVAL; if (!(conf = htsmsg_get_map(args, "conf"))) - return -EINVAL; + return EINVAL; pthread_mutex_lock(&global_lock); mn = mpegts_network_build(class, conf); @@ -128,7 +128,7 @@ api_mpegts_network_create *resp = htsmsg_create_map(); mn->mn_config_save(mn); } else { - err = -EINVAL; + err = EINVAL; } pthread_mutex_unlock(&global_lock); diff --git a/src/webui/static/app/idnode.js b/src/webui/static/app/idnode.js index 8c9cb88a..b339f11c 100644 --- a/src/webui/static/app/idnode.js +++ b/src/webui/static/app/idnode.js @@ -210,7 +210,7 @@ tvheadend.idnode_editor = function(item, conf) Ext.Ajax.request({ url : 'api/idnode/save', params : { - args : Ext.encode({node: node}) + node: Ext.encode(node) }, success : function(d) { } @@ -258,12 +258,10 @@ tvheadend.idnode_create = function(conf) params['uuid'] = puuid; if (pclass) params['class'] = pclass - params['conf'] = panel.getForm().getFieldValues(); + params['conf'] = Ext.encode(panel.getForm().getFieldValues()); Ext.Ajax.request({ url : conf.create.url || conf.url + '/create', - params : { - args : Ext.util.JSON.encode(params) - }, + params : params, success : function(d) { win.close(); } @@ -507,7 +505,7 @@ tvheadend.idnode_grid = function(panel, conf) Ext.Ajax.request({ url : 'api/idnode/save', params : { - args : Ext.encode({node : out}) + node: Ext.encode(out) }, success : function(d) { @@ -554,7 +552,7 @@ tvheadend.idnode_grid = function(panel, conf) Ext.Ajax.request({ url : 'api/idnode/delete', params : { - args : Ext.util.JSON.encode({ uuid: uuids}) + uuid: Ext.encode(uuids) }, success : function(d) { diff --git a/src/webui/webui_api.c b/src/webui/webui_api.c index db5a8f7b..7db94a20 100644 --- a/src/webui/webui_api.c +++ b/src/webui/webui_api.c @@ -32,36 +32,16 @@ webui_api_handler int r; http_arg_t *ha; htsmsg_t *args, *resp = NULL; - const char *a = http_arg_get(&hc->hc_req_args, "args"); - const char *op = http_arg_get(&hc->hc_req_args, "method"); - - // Compat - if (!op) - op = http_arg_get(&hc->hc_req_args, "op"); - /* Parse arguments */ - if (a) - args = htsmsg_json_deserialize(a); - else - args = htsmsg_create_map(); - if (!args) - return HTTP_STATUS_BAD_REQUEST; - - /* Add HTTP arguments?? */ + /* Build arguments */ + args = htsmsg_create_map(); TAILQ_FOREACH(ha, &hc->hc_req_args, link) { - // Ignore obvious keys - if (strcmp("op", ha->key) && - strcmp("method", ha->key) && - strcmp("args", ha->key)) - htsmsg_add_str(args, ha->key, ha->val); + htsmsg_add_str(args, ha->key, ha->val); } - /* Add operation */ - if (!htsmsg_get_str(args, "method") && op) - htsmsg_add_str(args, "method", op); - /* Call */ r = api_exec(remain, args, &resp); + htsmsg_destroy(args); /* Convert error */ if (r) {