diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-12-31 13:59:18 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-12-31 15:58:17 +0200 |
commit | 00e6c3c3ed06a258a02943fc49fa7c528025d747 (patch) | |
tree | 52530660be48fb5f4611bcc9393886bab8a70b72 /src/ctl.c | |
parent | 7f204cc788de3e03a51087b1273deb5b59288cf2 (diff) | |
download | pies-00e6c3c3ed06a258a02943fc49fa7c528025d747.tar.gz pies-00e6c3c3ed06a258a02943fc49fa7c528025d747.tar.bz2 |
Command-line control interface.
* configure.ac (DEFAULT_CONTROL_URL): New subst variable.
* grecs: Upgrade.
* ident/pam.c (overwrite_and_free): Free ptr.
* lib/Makefile.am: Add new sources.
* src/addrfmt.c: Move to lib/addrfmt.c
* lib/grecsasrt.c: New file.
* lib/grecsasrt.h: New file.
* lib/mkfilename.c: New file.
* lib/netrc.c: New file.
* lib/pp.c: New file.
* lib/split3.c: New file.
* src/url.c: Move from lib/url.c
(pies_url_free_user, pies_url_free_passwd): New finctions.
* lib/libpies.h (strsplit3): New proto.
(pies_url_create, pies_url_destroy)
(pies_url_get_arg, pies_url_copy)
(pies_url_free_user, pies_url_free_passwd)
(netrc_scan)
(pp_add_option, pp_command_line, mkfilename)
(sockaddr_to_str, sockaddr_to_astr): New protos
* src/Makefile.am (bin_PROGRAMS): New program: piesctl
(pies_SOURCES): Remove addrfmt.c and url.c.
(noinst_HEADERS, BUILT_SOURCES): Add piesctl-cl.h
* src/cmdline.opt: Use pp_* function family to build
preprocessor command line.
* src/ctl.c (http_header_hash): Use case-insensitive hashing.
(ctlio_finalize_reply): Don't close connection after sending 401
response.
(input): Remove ws and wsflags. All uses changed.
(input_append): Use strsplit3 to parse the request line.
* src/pies.c: Use pp_* function family to build
preprocessor command line.
Move assert_, mkfilename and _cb+_url functions into libpies.
* src/pies.h (pies_sockaddr_storage): Move to libpies.h
* src/piesctl.c: New file.
* src/piesctl-cl.opt: New file.
Diffstat (limited to 'src/ctl.c')
-rw-r--r-- | src/ctl.c | 43 |
1 files changed, 17 insertions, 26 deletions
@@ -21,8 +21,6 @@ | |||
21 | #include "base64.h" | 21 | #include "base64.h" |
22 | #include "json.h" | 22 | #include "json.h" |
23 | 23 | ||
24 | #define DEFAULT_CONTROL_URL "unix:///tmp/%s.ctl" | ||
25 | |||
26 | struct control control; | 24 | struct control control; |
27 | 25 | ||
28 | pies_identity_t identity; | 26 | pies_identity_t identity; |
@@ -171,7 +169,7 @@ static unsigned | |||
171 | http_header_hash (void *data, unsigned long n_buckets) | 169 | http_header_hash (void *data, unsigned long n_buckets) |
172 | { | 170 | { |
173 | const struct http_header *p = data; | 171 | const struct http_header *p = data; |
174 | return grecs_hash_string (p->name, n_buckets); | 172 | return grecs_hash_string_ci (p->name, n_buckets); |
175 | } | 173 | } |
176 | 174 | ||
177 | static int | 175 | static int |
@@ -220,9 +218,6 @@ struct input | |||
220 | char *input_proto; | 218 | char *input_proto; |
221 | struct grecs_symtab *headers; | 219 | struct grecs_symtab *headers; |
222 | size_t input_content_length; | 220 | size_t input_content_length; |
223 | |||
224 | struct wordsplit ws; | ||
225 | int wsflags; | ||
226 | }; | 221 | }; |
227 | 222 | ||
228 | static char const * | 223 | static char const * |
@@ -249,12 +244,6 @@ input_init (struct input *inp) | |||
249 | inp->input_uri = NULL; | 244 | inp->input_uri = NULL; |
250 | inp->input_proto = NULL; | 245 | inp->input_proto = NULL; |
251 | inp->input_content_length = 0; | 246 | inp->input_content_length = 0; |
252 | |||
253 | inp->ws.ws_delim = " \t()"; | ||
254 | inp->wsflags = WRDSF_DELIM | | ||
255 | WRDSF_NOVAR | WRDSF_NOCMD | | ||
256 | WRDSF_QUOTE | WRDSF_RETURN_DELIMS | | ||
257 | WRDSF_WS; | ||
258 | } | 247 | } |
259 | 248 | ||
260 | static void | 249 | static void |
@@ -262,8 +251,6 @@ input_destroy (struct input *inp) | |||
262 | { | 251 | { |
263 | ctlbuf_free (&inp->ibuf); | 252 | ctlbuf_free (&inp->ibuf); |
264 | grecs_symtab_free (inp->headers); | 253 | grecs_symtab_free (inp->headers); |
265 | if (inp->wsflags & WRDSF_REUSE) | ||
266 | wordsplit_free (&inp->ws); | ||
267 | } | 254 | } |
268 | 255 | ||
269 | static void | 256 | static void |
@@ -287,23 +274,23 @@ input_append (struct input *inp, char c) | |||
287 | if (c == '\n') | 274 | if (c == '\n') |
288 | { | 275 | { |
289 | int rc; | 276 | int rc; |
277 | char *reqline[3]; | ||
290 | 278 | ||
291 | ctlbuf_chomp (&inp->ibuf); | 279 | ctlbuf_chomp (&inp->ibuf); |
292 | rc = wordsplit (inp->ibuf.base, &inp->ws, inp->wsflags); | 280 | rc = strsplit3 (inp->ibuf.base, reqline, 1); |
293 | inp->wsflags |= WRDSF_REUSE; | 281 | if (rc == 0) |
294 | if (rc) | ||
295 | { | 282 | { |
296 | logmsg (LOG_ERR, _("can't parse input line: %s"), | 283 | inp->input_method = reqline[0]; |
297 | wordsplit_strerror (&inp->ws)); | 284 | inp->input_uri = reqline[1]; |
298 | return 500; | 285 | inp->input_proto = reqline[2]; |
299 | } | 286 | } |
300 | if (inp->ws.ws_wordc == 3) | 287 | else if (rc == -1) |
301 | { | 288 | { |
302 | inp->input_method = inp->ws.ws_wordv[0]; | 289 | logmsg (LOG_ERR, _("can't parse input line: %s"), |
303 | inp->input_uri = inp->ws.ws_wordv[1]; | 290 | strerror (errno)); |
304 | inp->input_proto = inp->ws.ws_wordv[2]; | 291 | return 500; |
305 | } | 292 | } |
306 | else | 293 | else |
307 | { | 294 | { |
308 | logmsg (LOG_ERR, _("protocol error")); | 295 | logmsg (LOG_ERR, _("protocol error")); |
309 | return 400; | 296 | return 400; |
@@ -379,6 +366,10 @@ input_append (struct input *inp, char c) | |||
379 | ctlbuf_write (&inp->ibuf, &c, 1); | 366 | ctlbuf_write (&inp->ibuf, &c, 1); |
380 | if (ctlbuf_rdsize (&inp->ibuf) == inp->input_content_length) | 367 | if (ctlbuf_rdsize (&inp->ibuf) == inp->input_content_length) |
381 | return 200; | 368 | return 200; |
369 | break; | ||
370 | |||
371 | case is_end: | ||
372 | break; | ||
382 | } | 373 | } |
383 | return 0; | 374 | return 0; |
384 | } | 375 | } |
@@ -666,7 +657,7 @@ ctlio_finalize_reply (struct ctlio *io) | |||
666 | 657 | ||
667 | if (io->state & (CTL_INITIAL_STATE|CTL_AUTHENTICATED_STATE)) | 658 | if (io->state & (CTL_INITIAL_STATE|CTL_AUTHENTICATED_STATE)) |
668 | { | 659 | { |
669 | if (io->code / 100 == 2) | 660 | if (io->code / 100 == 2 || io->code == 401) |
670 | { | 661 | { |
671 | val = http_get_header (io->input.headers, "connection"); | 662 | val = http_get_header (io->input.headers, "connection"); |
672 | if (val) | 663 | if (val) |