aboutsummaryrefslogtreecommitdiff
path: root/src/ctl.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-12-31 13:59:18 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2015-12-31 15:58:17 +0200
commit00e6c3c3ed06a258a02943fc49fa7c528025d747 (patch)
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')
-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
@@ -18,14 +18,12 @@
#include "prog.h"
#include "xvasprintf.h"
#include "identity.h"
#include "base64.h"
#include "json.h"
-#define DEFAULT_CONTROL_URL "unix:///tmp/%s.ctl"
-
struct control control;
pies_identity_t identity;
struct ctlbuf
@@ -168,13 +166,13 @@ struct http_header
};
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
http_header_compare (void const *data1, void const *data2)
{
const struct http_header *p1 = data1;
@@ -217,15 +215,12 @@ struct input
enum input_state input_state;
char *input_method;
char *input_uri;
char *input_proto;
struct grecs_symtab *headers;
size_t input_content_length;
-
- struct wordsplit ws;
- int wsflags;
};
static char const *
http_get_header (struct grecs_symtab *headers, char const *name)
{
struct http_header key, *ret;
@@ -246,27 +241,19 @@ input_init (struct input *inp)
NULL,
http_header_free);
inp->input_method = NULL;
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
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
input_reset (struct input *inp)
{
inp->input_state = is_initial;
@@ -284,29 +271,29 @@ input_append (struct input *inp, char c)
switch (inp->input_state)
{
case is_initial:
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;
}
ctlbuf_flush (&inp->ibuf);
inp->input_state = is_headers;
@@ -376,12 +363,16 @@ input_append (struct input *inp, char c)
break;
case is_content:
ctlbuf_write (&inp->ibuf, &c, 1);
if (ctlbuf_rdsize (&inp->ibuf) == inp->input_content_length)
return 200;
+ break;
+
+ case is_end:
+ break;
}
return 0;
}
struct output
{
@@ -663,13 +654,13 @@ ctlio_finalize_reply (struct ctlio *io)
size_t size;
char const *val;
struct ctlbuf tmpbuf;
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)
{
if (strcasecmp (val, "keep-alive") == 0)
/* nothing */;

Return to:

Send suggestions and report system problems to the System administrator.