aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ctl.c100
-rw-r--r--src/piesctl.c8
2 files changed, 32 insertions, 76 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);
+}
diff --git a/src/piesctl.c b/src/piesctl.c
index da2e621..301e7ac 100644
--- a/src/piesctl.c
+++ b/src/piesctl.c
@@ -1449,7 +1449,7 @@ parse_condition_to_uri (char const *base, int argc, char **argv, int mandatory)
static void
com_list (struct shttp_connection *conn, int argc, char **argv)
{
- char *uri = parse_condition_to_uri ("/programs/select", argc, argv, 0);
+ char *uri = parse_condition_to_uri ("/programs", argc, argv, 0);
shttp_io_init (&conn->req);
shttp_process (conn, METH_GET, uri);
@@ -1532,7 +1532,7 @@ shttp_print_response_status (struct shttp_connection *conn)
static void
com_stop (struct shttp_connection *conn, int argc, char **argv)
{
- char *uri = parse_condition_to_uri ("/programs/select", argc, argv, 1);
+ char *uri = parse_condition_to_uri ("/programs", argc, argv, 1);
shttp_io_init (&conn->req);
shttp_process (conn, METH_DELETE, uri);
@@ -1543,7 +1543,7 @@ com_stop (struct shttp_connection *conn, int argc, char **argv)
static void
com_start (struct shttp_connection *conn, int argc, char **argv)
{
- char *uri = parse_condition_to_uri ("/programs/select", argc, argv, 1);
+ char *uri = parse_condition_to_uri ("/programs", argc, argv, 1);
shttp_io_init (&conn->req);
shttp_process (conn, METH_PUT, uri);
@@ -1557,7 +1557,7 @@ com_restart (struct shttp_connection *conn, int argc, char **argv)
shttp_io_init (&conn->req);
conn->req.content = parse_condition_to_uri (NULL, argc, argv, 1);
conn->req.content_length = strlen (conn->req.content);
- shttp_process (conn, METH_POST, "/programs/select");
+ shttp_process (conn, METH_POST, "/programs");
shttp_print_response_status (conn);
}

Return to:

Send suggestions and report system problems to the System administrator.