summaryrefslogtreecommitdiffabout
path: root/src/ctl.c
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-06 06:57:04 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-01-06 06:57:04 (GMT)
commitb47dfe00a3658aa95c4ed6cf79a0e66e06eed0ff (patch) (side-by-side diff)
treec7753f5c3e2a6bcdeff40a58961ce38c9bc0e92b /src/ctl.c
parent659ed5b33cf70a6898697c7c5886ae068a3be966 (diff)
downloadpies-b47dfe00a3658aa95c4ed6cf79a0e66e06eed0ff.tar.gz
pies-b47dfe00a3658aa95c4ed6cf79a0e66e06eed0ff.tar.bz2
Revert to pre-32a337f3 two endpoint system
Diffstat (limited to 'src/ctl.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/ctl.c100
1 files changed, 28 insertions, 72 deletions
diff --git a/src/ctl.c b/src/ctl.c
index 0960d54..fd32765 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -888,10 +888,8 @@ method_decode (char const *method)
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 *);
struct ctlio_resource
{
@@ -905,10 +903,8 @@ struct ctlio_resource
static struct ctlio_resource restab[] = {
#define S(s) #s, (sizeof (#s)-1)
{ 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 }
#undef S
};
@@ -1964,80 +1960,40 @@ res_programs_select (struct ctlio *io, enum http_method meth,
{
struct pcond_node *cond;
- 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);
}
static void
res_programs_component (struct ctlio *io, enum http_method meth,
char const *uri, struct json_value *json)
{
- 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);
pcond_node_free (node);
}
+
+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);
+}

Return to:

Send suggestions and report system problems to the System administrator.