aboutsummaryrefslogtreecommitdiff
path: root/src/ctl.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-06 08:57:04 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-01-06 08:57:04 +0200
commitb47dfe00a3658aa95c4ed6cf79a0e66e06eed0ff (patch)
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')
-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)
888 888
889static void res_instance (struct ctlio *, enum http_method, char const *, 889static void res_instance (struct ctlio *, enum http_method, char const *,
890 struct json_value *); 890 struct json_value *);
891static void res_programs_select (struct ctlio *, enum http_method, char const *, 891static void res_programs (struct ctlio *, enum http_method, char const *,
892 struct json_value *); 892 struct json_value *);
893static void res_programs_component (struct ctlio *, enum http_method,
894 char const *, struct json_value *);
895 893
896struct ctlio_resource 894struct ctlio_resource
897{ 895{
@@ -905,10 +903,8 @@ struct ctlio_resource
905static struct ctlio_resource restab[] = { 903static struct ctlio_resource restab[] = {
906#define S(s) #s, (sizeof (#s)-1) 904#define S(s) #s, (sizeof (#s)-1)
907 { S(/instance), CTL_ADMIN_STATE, res_instance }, 905 { S(/instance), CTL_ADMIN_STATE, res_instance },
908 { S(/programs/select), CTL_ADMIN_STATE|CTL_USER_STATE, 906 { S(/programs), CTL_ADMIN_STATE|CTL_USER_STATE,
909 res_programs_select }, 907 res_programs },
910 { S(/programs/component), CTL_ADMIN_STATE|CTL_USER_STATE,
911 res_programs_component },
912 { NULL } 908 { NULL }
913#undef S 909#undef S
914}; 910};
@@ -1964,80 +1960,40 @@ res_programs_select (struct ctlio *io, enum http_method meth,
1964{ 1960{
1965 struct pcond_node *cond; 1961 struct pcond_node *cond;
1966 1962
1967 if (uri) 1963 if (json_to_pcond (io, json, &cond) == 0)
1968 { 1964 {
1969 ctlio_reply (io, 404, NULL); 1965 select_and_run (io, cond, meth);
1970 return; 1966 pcond_node_free (cond);
1971 } 1967 }
1972
1973 if (json_to_pcond (io, json, &cond))
1974 return;
1975 select_and_run (io, cond, meth);
1976 pcond_node_free (cond);
1977} 1968}
1978 1969
1979static void 1970static void
1980res_programs_component (struct ctlio *io, enum http_method meth, 1971res_programs_component (struct ctlio *io, enum http_method meth,
1981 char const *uri, struct json_value *json) 1972 char const *uri, struct json_value *json)
1982{ 1973{
1983 struct pcond_node *node = pcond_node_alloc (pcond_type); 1974 struct pcond_node *np, *node;
1984 node->v.type = TYPE_COMPONENT;
1985
1986 if (meth != METH_POST)
1987 {
1988 if (uri)
1989 {
1990 struct pcond_node *np;
1991 np = pcond_node_alloc (pcond_and);
1992 np->v.arg.c = 2;
1993 np->v.arg.v = grecs_calloc (np->v.arg.c, sizeof (np->v.arg.v[0]));
1994 np->v.arg.v[0] = node;
1995 np->v.arg.v[1] = pcond_node_alloc (pcond_component);
1996 np->v.arg.v[1]->v.tag = (char*) uri + 1;
1997 node = np;
1998 }
1999 }
2000 else
2001 {
2002 if (json->type != json_arr)
2003 ctlio_reply (io, 400, NULL);
2004 else
2005 {
2006 size_t i, n;
2007 struct pcond_node *or_cond, *np;
2008
2009 n = json_array_size (json);
2010 or_cond = pcond_node_alloc (pcond_or);
2011 or_cond->v.arg.v = grecs_calloc (n, sizeof (or_cond->v.arg.v[0]));
2012 or_cond->v.arg.c = n;
2013 1975
2014 for (i = 0; i < n; i++) 1976 node = pcond_node_alloc (pcond_type);
2015 { 1977 node->v.type = TYPE_COMPONENT;
2016 struct json_value *v;
2017 if (json_array_get (json, i, &v) == 0 && v->type == json_string)
2018 {
2019 or_cond->v.arg.v[i] = pcond_node_alloc (pcond_component);
2020 or_cond->v.arg.v[i]->v.tag = v->v.s;
2021 }
2022 else
2023 {
2024 ctlio_reply (io, 400, "all elements must be string");
2025 pcond_node_free (or_cond);
2026 pcond_node_free (node);
2027 return;
2028 }
2029 }
2030
2031 np = pcond_node_alloc (pcond_and);
2032 np->v.arg.c = 2;
2033 np->v.arg.v = grecs_calloc (np->v.arg.c, sizeof (np->v.arg.v[0]));
2034 np->v.arg.v[0] = node;
2035 np->v.arg.v[1] = or_cond;
2036
2037 node = np;
2038 }
2039 }
2040 1978
1979 np = pcond_node_alloc (pcond_and);
1980 np->v.arg.c = 2;
1981 np->v.arg.v = grecs_calloc (np->v.arg.c, sizeof (np->v.arg.v[0]));
1982 np->v.arg.v[0] = node;
1983 np->v.arg.v[1] = pcond_node_alloc (pcond_component);
1984 np->v.arg.v[1]->v.tag = (char*) uri + 1;
1985 node = np;
1986
2041 select_and_run (io, node, meth); 1987 select_and_run (io, node, meth);
2042 pcond_node_free (node); 1988 pcond_node_free (node);
2043} 1989}
1990
1991static void
1992res_programs (struct ctlio *io, enum http_method meth,
1993 char const *uri, struct json_value *json)
1994{
1995 if (uri)
1996 res_programs_component (io, meth, uri, json);
1997 else
1998 res_programs_select (io, meth, uri, json);
1999}

Return to:

Send suggestions and report system problems to the System administrator.