summaryrefslogtreecommitdiffabout
path: root/src/ctl.c
authorSergey Poznyakoff <gray@gnu.org.ua>2015-12-31 11:59:18 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2015-12-31 13:58:17 (GMT)
commit00e6c3c3ed06a258a02943fc49fa7c528025d747 (patch) (side-by-side diff)
tree52530660be48fb5f4611bcc9393886bab8a70b72 /src/ctl.c
parent7f204cc788de3e03a51087b1273deb5b59288cf2 (diff)
downloadpies-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') (more/less context) (ignore whitespace changes)
-rw-r--r--src/ctl.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/src/ctl.c b/src/ctl.c
index 1da1370..ce13dab 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -21,8 +21,6 @@
#include "base64.h"
#include "json.h"
-#define DEFAULT_CONTROL_URL "unix:///tmp/%s.ctl"
-
struct control control;
pies_identity_t identity;
@@ -171,7 +169,7 @@ static unsigned
http_header_hash (void *data, unsigned long n_buckets)
{
const struct http_header *p = data;
- return grecs_hash_string (p->name, n_buckets);
+ return grecs_hash_string_ci (p->name, n_buckets);
}
static int
@@ -220,9 +218,6 @@ struct input
char *input_proto;
struct grecs_symtab *headers;
size_t input_content_length;
-
- struct wordsplit ws;
- int wsflags;
};
static char const *
@@ -249,12 +244,6 @@ input_init (struct input *inp)
inp->input_uri = NULL;
inp->input_proto = NULL;
inp->input_content_length = 0;
-
- inp->ws.ws_delim = " \t()";
- inp->wsflags = WRDSF_DELIM |
- WRDSF_NOVAR | WRDSF_NOCMD |
- WRDSF_QUOTE | WRDSF_RETURN_DELIMS |
- WRDSF_WS;
}
static void
@@ -262,8 +251,6 @@ input_destroy (struct input *inp)
{
ctlbuf_free (&inp->ibuf);
grecs_symtab_free (inp->headers);
- if (inp->wsflags & WRDSF_REUSE)
- wordsplit_free (&inp->ws);
}
static void
@@ -287,23 +274,23 @@ input_append (struct input *inp, char c)
if (c == '\n')
{
int rc;
+ char *reqline[3];
ctlbuf_chomp (&inp->ibuf);
- rc = wordsplit (inp->ibuf.base, &inp->ws, inp->wsflags);
- inp->wsflags |= WRDSF_REUSE;
- if (rc)
+ rc = strsplit3 (inp->ibuf.base, reqline, 1);
+ if (rc == 0)
{
- logmsg (LOG_ERR, _("can't parse input line: %s"),
- wordsplit_strerror (&inp->ws));
- return 500;
+ inp->input_method = reqline[0];
+ inp->input_uri = reqline[1];
+ inp->input_proto = reqline[2];
}
- if (inp->ws.ws_wordc == 3)
+ else if (rc == -1)
{
- inp->input_method = inp->ws.ws_wordv[0];
- inp->input_uri = inp->ws.ws_wordv[1];
- inp->input_proto = inp->ws.ws_wordv[2];
+ logmsg (LOG_ERR, _("can't parse input line: %s"),
+ strerror (errno));
+ return 500;
}
- else
+ else
{
logmsg (LOG_ERR, _("protocol error"));
return 400;
@@ -379,6 +366,10 @@ input_append (struct input *inp, char c)
ctlbuf_write (&inp->ibuf, &c, 1);
if (ctlbuf_rdsize (&inp->ibuf) == inp->input_content_length)
return 200;
+ break;
+
+ case is_end:
+ break;
}
return 0;
}
@@ -666,7 +657,7 @@ ctlio_finalize_reply (struct ctlio *io)
if (io->state & (CTL_INITIAL_STATE|CTL_AUTHENTICATED_STATE))
{
- if (io->code / 100 == 2)
+ if (io->code / 100 == 2 || io->code == 401)
{
val = http_get_header (io->input.headers, "connection");
if (val)

Return to:

Send suggestions and report system problems to the System administrator.