diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-01-06 08:57:04 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-01-06 08:57:04 +0200 |
commit | b47dfe00a3658aa95c4ed6cf79a0e66e06eed0ff (patch) | |
tree | c7753f5c3e2a6bcdeff40a58961ce38c9bc0e92b /src/ctl.c | |
parent | 659ed5b33cf70a6898697c7c5886ae068a3be966 (diff) | |
download | pies-b47dfe00a3658aa95c4ed6cf79a0e66e06eed0ff.tar.gz pies-b47dfe00a3658aa95c4ed6cf79a0e66e06eed0ff.tar.bz2 |
Revert to pre-32a337f3 two endpoint system
Diffstat (limited to 'src/ctl.c')
-rw-r--r-- | src/ctl.c | 100 |
1 files changed, 28 insertions, 72 deletions
@@ -890,6 +890,4 @@ static void res_instance (struct ctlio *, enum http_method, char const *, struct json_value *); -static void res_programs_select (struct ctlio *, enum http_method, char const *, - struct json_value *); -static void res_programs_component (struct ctlio *, enum http_method, - char const *, struct json_value *); +static void res_programs (struct ctlio *, enum http_method, char const *, + struct json_value *); @@ -907,6 +905,4 @@ static struct ctlio_resource restab[] = { { S(/instance), CTL_ADMIN_STATE, res_instance }, - { S(/programs/select), CTL_ADMIN_STATE|CTL_USER_STATE, - res_programs_select }, - { S(/programs/component), CTL_ADMIN_STATE|CTL_USER_STATE, - res_programs_component }, + { S(/programs), CTL_ADMIN_STATE|CTL_USER_STATE, + res_programs }, { NULL } @@ -1966,12 +1962,7 @@ res_programs_select (struct ctlio *io, enum http_method meth, - if (uri) + if (json_to_pcond (io, json, &cond) == 0) { - ctlio_reply (io, 404, NULL); - return; + select_and_run (io, cond, meth); + pcond_node_free (cond); } - - if (json_to_pcond (io, json, &cond)) - return; - select_and_run (io, cond, meth); - pcond_node_free (cond); } @@ -1982,60 +1973,15 @@ res_programs_component (struct ctlio *io, enum http_method meth, { - struct pcond_node *node = pcond_node_alloc (pcond_type); - node->v.type = TYPE_COMPONENT; - - if (meth != METH_POST) - { - if (uri) - { - struct pcond_node *np; - np = pcond_node_alloc (pcond_and); - np->v.arg.c = 2; - np->v.arg.v = grecs_calloc (np->v.arg.c, sizeof (np->v.arg.v[0])); - np->v.arg.v[0] = node; - np->v.arg.v[1] = pcond_node_alloc (pcond_component); - np->v.arg.v[1]->v.tag = (char*) uri + 1; - node = np; - } - } - else - { - if (json->type != json_arr) - ctlio_reply (io, 400, NULL); - else - { - size_t i, n; - struct pcond_node *or_cond, *np; - - n = json_array_size (json); - or_cond = pcond_node_alloc (pcond_or); - or_cond->v.arg.v = grecs_calloc (n, sizeof (or_cond->v.arg.v[0])); - or_cond->v.arg.c = n; + struct pcond_node *np, *node; - for (i = 0; i < n; i++) - { - struct json_value *v; - if (json_array_get (json, i, &v) == 0 && v->type == json_string) - { - or_cond->v.arg.v[i] = pcond_node_alloc (pcond_component); - or_cond->v.arg.v[i]->v.tag = v->v.s; - } - else - { - ctlio_reply (io, 400, "all elements must be string"); - pcond_node_free (or_cond); - pcond_node_free (node); - return; - } - } - - np = pcond_node_alloc (pcond_and); - np->v.arg.c = 2; - np->v.arg.v = grecs_calloc (np->v.arg.c, sizeof (np->v.arg.v[0])); - np->v.arg.v[0] = node; - np->v.arg.v[1] = or_cond; - - node = np; - } - } + node = pcond_node_alloc (pcond_type); + node->v.type = TYPE_COMPONENT; + np = pcond_node_alloc (pcond_and); + np->v.arg.c = 2; + np->v.arg.v = grecs_calloc (np->v.arg.c, sizeof (np->v.arg.v[0])); + np->v.arg.v[0] = node; + np->v.arg.v[1] = pcond_node_alloc (pcond_component); + np->v.arg.v[1]->v.tag = (char*) uri + 1; + node = np; + select_and_run (io, node, meth); @@ -2043 +1989,11 @@ res_programs_component (struct ctlio *io, enum http_method meth, } + +static void +res_programs (struct ctlio *io, enum http_method meth, + char const *uri, struct json_value *json) +{ + if (uri) + res_programs_component (io, meth, uri, json); + else + res_programs_select (io, meth, uri, json); +} |