diff options
-rw-r--r-- | lib/arraymember.c | 17 | ||||
-rw-r--r-- | lib/libpies.h | 3 | ||||
-rw-r--r-- | src/cmdline.opt | 4 | ||||
-rw-r--r-- | src/ctl.c | 442 | ||||
-rw-r--r-- | src/pies.c | 161 | ||||
-rw-r--r-- | src/pies.h | 6 | ||||
-rw-r--r-- | src/piesctl-cl.opt | 2 | ||||
-rw-r--r-- | src/piesctl.c | 247 | ||||
-rw-r--r-- | src/progman.c | 136 |
9 files changed, 703 insertions, 315 deletions
diff --git a/lib/arraymember.c b/lib/arraymember.c index 14ace99..010f4a1 100644 --- a/lib/arraymember.c +++ b/lib/arraymember.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* This file is part of GNU Pies. | 1 | /* This file is part of GNU Pies. |
2 | Copyright (C) 2007, 2008, 2009, 2010, 2013 Sergey Poznyakoff | 2 | Copyright (C) 2015, 2016 Sergey Poznyakoff |
3 | 3 | ||
4 | GNU Pies is free software; you can redistribute it and/or modify | 4 | GNU Pies is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
@@ -21,7 +21,7 @@ | |||
21 | #include "libpies.h" | 21 | #include "libpies.h" |
22 | 22 | ||
23 | int | 23 | int |
24 | is_array_member (char * const * ar, char const *str) | 24 | is_array_member (char * const *ar, char const *str) |
25 | { | 25 | { |
26 | for (; *ar; ++ar) | 26 | for (; *ar; ++ar) |
27 | { | 27 | { |
@@ -31,3 +31,16 @@ is_array_member (char * const * ar, char const *str) | |||
31 | return 0; | 31 | return 0; |
32 | } | 32 | } |
33 | 33 | ||
34 | int | ||
35 | array_index (char * const *ar, char const *str) | ||
36 | { | ||
37 | int i; | ||
38 | |||
39 | for (i = 0; ar[i]; i++) | ||
40 | { | ||
41 | if (strcmp (ar[i], str) == 0) | ||
42 | return i; | ||
43 | } | ||
44 | return -1; | ||
45 | } | ||
46 | |||
diff --git a/lib/libpies.h b/lib/libpies.h index dab36df..b04182e 100644 --- a/lib/libpies.h +++ b/lib/libpies.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* This file is part of GNU Pies. | 1 | /* This file is part of GNU Pies. |
2 | Copyright (C) 2009, 2010, 2011, 2013, 2015 Sergey Poznyakoff | 2 | Copyright (C) 2009-2011, 2013, 2015, 2016 Sergey Poznyakoff |
3 | 3 | ||
4 | GNU Pies is free software; you can redistribute it and/or modify | 4 | GNU Pies is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
@@ -51,6 +51,7 @@ int strtotok_ci (struct tokendef *tab, const char *str, int *pres); | |||
51 | int toktostr (struct tokendef *tab, int tok, const char **pres); | 51 | int toktostr (struct tokendef *tab, int tok, const char **pres); |
52 | 52 | ||
53 | int is_array_member (char * const * ar, char const *str); | 53 | int is_array_member (char * const * ar, char const *str); |
54 | int array_index (char * const *ar, char const *str); | ||
54 | int strsplit3 (const char *input, char *result[3], int flag); | 55 | int strsplit3 (const char *input, char *result[3], int flag); |
55 | 56 | ||
56 | /* url.c */ | 57 | /* url.c */ |
diff --git a/src/cmdline.opt b/src/cmdline.opt index 18791b6..e425518 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt | |||
@@ -1,5 +1,5 @@ | |||
1 | /* This file is part of GNU Pies. -*- c -*- | 1 | /* This file is part of GNU Pies. -*- c -*- |
2 | Copyright (C) 2008-2014 Sergey Poznyakoff | 2 | Copyright (C) 2008-2016 Sergey Poznyakoff |
3 | 3 | ||
4 | GNU Pies is free software; you can redistribute it and/or modify | 4 | GNU Pies is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
@@ -18,7 +18,7 @@ OPTIONS_BEGIN("pies", | |||
18 | [<process invocation and execution supervisor>], | 18 | [<process invocation and execution supervisor>], |
19 | [<>], | 19 | [<>], |
20 | [<gnu>], | 20 | [<gnu>], |
21 | [<copyright_year=2008-2014>], | 21 | [<copyright_year=2008-2016>], |
22 | [<copyright_holder=Sergey Poznyakoff>]) | 22 | [<copyright_holder=Sergey Poznyakoff>]) |
23 | 23 | ||
24 | GROUP(Operation Mode) | 24 | GROUP(Operation Mode) |
@@ -1000,8 +1000,20 @@ ctlio_do_command (struct ctlio *io, struct wordsplit *uri) | |||
1000 | //FIXME: Reply json | 1000 | //FIXME: Reply json |
1001 | } | 1001 | } |
1002 | } | 1002 | } |
1003 | else if (method != METH_POST | ||
1004 | && uri->ws_wordc > 1 | ||
1005 | && strchr ("\"{[", uri->ws_wordv[uri->ws_wordc-1][0])) | ||
1006 | { | ||
1007 | json = json_parse_string (uri->ws_wordv[uri->ws_wordc-1], | ||
1008 | strlen (uri->ws_wordv[uri->ws_wordc-1])); | ||
1009 | if (!json) | ||
1010 | ctlio_reply (io, 400, NULL); | ||
1011 | free (uri->ws_wordv[uri->ws_wordc-1]); | ||
1012 | uri->ws_wordv[uri->ws_wordc-1] = NULL; | ||
1013 | uri->ws_wordc--; | ||
1014 | } | ||
1003 | else | 1015 | else |
1004 | json = json_value_create (json_null); | 1016 | json = json_new_bool (1); |
1005 | 1017 | ||
1006 | res->handler (io, method, uri->ws_wordc, uri->ws_wordv, json); | 1018 | res->handler (io, method, uri->ws_wordc, uri->ws_wordv, json); |
1007 | json_value_free (json); | 1019 | json_value_free (json); |
@@ -1138,11 +1150,9 @@ ctl_accept (int socket, void *data) | |||
1138 | return 0; | 1150 | return 0; |
1139 | } | 1151 | } |
1140 | 1152 | ||
1141 | void | 1153 | char const * |
1142 | ctl_open () | 1154 | pies_control_url (void) |
1143 | { | 1155 | { |
1144 | int fd; | ||
1145 | |||
1146 | if (!control.url) | 1156 | if (!control.url) |
1147 | { | 1157 | { |
1148 | char *str = xasprintf (DEFAULT_CONTROL_URL, instance); | 1158 | char *str = xasprintf (DEFAULT_CONTROL_URL, instance); |
@@ -1150,11 +1160,19 @@ ctl_open () | |||
1150 | { | 1160 | { |
1151 | logmsg (LOG_CRIT, _("%s: cannot create URL: %s"), | 1161 | logmsg (LOG_CRIT, _("%s: cannot create URL: %s"), |
1152 | str, strerror (errno)); | 1162 | str, strerror (errno)); |
1153 | return; | 1163 | exit (EX_OSERR); |
1154 | } | 1164 | } |
1155 | free (str); | 1165 | free (str); |
1156 | } | 1166 | } |
1157 | 1167 | return control.url->string; | |
1168 | } | ||
1169 | |||
1170 | void | ||
1171 | ctl_open () | ||
1172 | { | ||
1173 | int fd; | ||
1174 | |||
1175 | pies_control_url (); | ||
1158 | fd = create_socket (control.url, SOCK_STREAM, NULL, 077); | 1176 | fd = create_socket (control.url, SOCK_STREAM, NULL, 077); |
1159 | if (fd == -1) | 1177 | if (fd == -1) |
1160 | { | 1178 | { |
@@ -1271,7 +1289,8 @@ res_instance (struct ctlio *io, enum http_method meth, | |||
1271 | struct eval_env | 1289 | struct eval_env |
1272 | { | 1290 | { |
1273 | struct ctlio *io; | 1291 | struct ctlio *io; |
1274 | struct json_value *json; | 1292 | struct pcond_node *cond; |
1293 | struct json_value *result; | ||
1275 | }; | 1294 | }; |
1276 | 1295 | ||
1277 | static int | 1296 | static int |
@@ -1299,26 +1318,14 @@ auth_prog (struct prog *prog, struct ctlio *io) | |||
1299 | } | 1318 | } |
1300 | return 0; | 1319 | return 0; |
1301 | } | 1320 | } |
1302 | |||
1303 | static struct json_value *prog_serialize (struct prog *prog); | ||
1304 | |||
1305 | static int | ||
1306 | selector (struct prog *prog, void *data) | ||
1307 | { | ||
1308 | struct eval_env *env = data; | ||
1309 | |||
1310 | if (auth_prog (prog, env->io)) | ||
1311 | json_array_append (env->json, prog_serialize (prog)); | ||
1312 | return 0; | ||
1313 | } | ||
1314 | 1321 | ||
1315 | static char const *pies_type_str[] = { | 1322 | static char * const pies_type_str[] = { |
1316 | [TYPE_COMPONENT] = "component", | 1323 | [TYPE_COMPONENT] = "component", |
1317 | [TYPE_REDIRECTOR] = "redirector", | 1324 | [TYPE_REDIRECTOR] = "redirector", |
1318 | [TYPE_COMMAND] = "command" | 1325 | [TYPE_COMMAND] = "command" |
1319 | }; | 1326 | }; |
1320 | 1327 | ||
1321 | static char const *pies_comp_mode_str[] = { | 1328 | static char * const pies_comp_mode_str[] = { |
1322 | [pies_comp_exec] = "exec", | 1329 | [pies_comp_exec] = "exec", |
1323 | [pies_comp_accept] = "accept", | 1330 | [pies_comp_accept] = "accept", |
1324 | [pies_comp_inetd] = "inetd", | 1331 | [pies_comp_inetd] = "inetd", |
@@ -1337,7 +1344,7 @@ static char const *pies_comp_mode_str[] = { | |||
1337 | [pies_comp_kbrequest] = "kbrequest" | 1344 | [pies_comp_kbrequest] = "kbrequest" |
1338 | }; | 1345 | }; |
1339 | 1346 | ||
1340 | static char const *status_str[] = { | 1347 | static char * const pies_status_str[] = { |
1341 | [status_enabled] = "enabled", | 1348 | [status_enabled] = "enabled", |
1342 | [status_disabled] = "disabled", | 1349 | [status_disabled] = "disabled", |
1343 | [status_listener] = "listener", | 1350 | [status_listener] = "listener", |
@@ -1348,7 +1355,7 @@ static char const *status_str[] = { | |||
1348 | 1355 | ||
1349 | static void | 1356 | static void |
1350 | format_idx (struct json_value *obj, const char *name, unsigned i, | 1357 | format_idx (struct json_value *obj, const char *name, unsigned i, |
1351 | char const **a, size_t s) | 1358 | char * const *a, size_t s) |
1352 | { | 1359 | { |
1353 | if (i < s && a[i]) | 1360 | if (i < s && a[i]) |
1354 | json_object_set (obj, name, json_new_string (a[i])); | 1361 | json_object_set (obj, name, json_new_string (a[i])); |
@@ -1356,7 +1363,318 @@ format_idx (struct json_value *obj, const char *name, unsigned i, | |||
1356 | 1363 | ||
1357 | #define FORMAT_IDX(io,n,a,i) \ | 1364 | #define FORMAT_IDX(io,n,a,i) \ |
1358 | format_idx (io, n, i, a, sizeof(a)/sizeof(a[0])) | 1365 | format_idx (io, n, i, a, sizeof(a)/sizeof(a[0])) |
1366 | |||
1367 | enum pcond_type | ||
1368 | { | ||
1369 | pcond_true, | ||
1370 | pcond_component, | ||
1371 | pcond_type, | ||
1372 | pcond_mode, | ||
1373 | pcond_status, | ||
1374 | pcond_not, | ||
1375 | pcond_and, | ||
1376 | pcond_or | ||
1377 | }; | ||
1378 | |||
1379 | struct pcond_node | ||
1380 | { | ||
1381 | enum pcond_type type; | ||
1382 | union | ||
1383 | { | ||
1384 | char *tag; | ||