diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-01-05 16:17:38 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-01-05 16:20:24 +0200 |
commit | 6ac0f1e8e19922c63a1542740a7c88116989bb7c (patch) | |
tree | 6124aaa6dbd729deab5de7550f6603056e39b4b3 /src/ctl.c | |
parent | f937fa90807400e87aa64cd03f2c8470093129d7 (diff) | |
download | pies-6ac0f1e8e19922c63a1542740a7c88116989bb7c.tar.gz pies-6ac0f1e8e19922c63a1542740a7c88116989bb7c.tar.bz2 |
Minor changes.
* src/ctl.c (ctlio_authenticate): Configurable realm name.
(ctlio_do_command): Check the Accept header.
* src/inetd.c (inetd_conf_file): Change line_no type.
* src/pies.c (control_keywords): New keyword: realm.
* src/pies.h (control) <realm>: New member.
Diffstat (limited to 'src/ctl.c')
-rw-r--r-- | src/ctl.c | 71 |
1 files changed, 60 insertions, 11 deletions
@@ -659,13 +659,12 @@ ctlio_finalize_reply (struct ctlio *io) if (val) { if (strcasecmp (val, "keep-alive") == 0) /* nothing */; else if (strcasecmp (val, "close") == 0) io->state = CTL_END_STATE; - //FIXME: else? } if (io->state == CTL_END_STATE || io->state == CTL_ACTION_STATE) output_set_header (&io->output, "Connection", "close"); ctlbuf_init (&tmpbuf); @@ -837,13 +836,14 @@ ctlio_authenticate (struct ctlio *io) } ctlio_reply (io, 403, NULL); } else { output_set_header (&io->output, "WWW-Authenticate", - "Basic realm=\"%s\"", "pies"); //FIXME: Configurable realm + "Basic realm=\"%s\"", + control.realm ? control.realm : "pies"); ctlio_reply (io, 401, NULL); } return 1; } enum http_method @@ -954,12 +954,68 @@ delim_count (char const *str, int delim) for (; *str; str++) if (*str == delim) ++i; return i; } +static int +check_accepted_media (struct ctlio *io, char const *type, char const *subtype) +{ + char const *val; + struct wordsplit ws; + int rc = 1; + size_t i; + + val = http_get_header (io->input.headers, "Accept"); + if (!val) + return 0; + + ws.ws_delim = ","; + if (wordsplit (val, &ws, + WRDSF_NOCMD | WRDSF_NOVAR | WRDSF_DELIM | WRDSF_WS + | WRDSF_DQUOTE)) + { + logmsg (LOG_ERR, "wordsplit: %s", wordsplit_strerror (&ws)); + ctlio_reply (io, 500, NULL); + return -1; + } + + for (i = 0; i < ws.ws_wordc; i++) + { + char *p = strchr (ws.ws_wordv[i], ';'); + if (p) + { + while (p > ws.ws_wordv[i] && ISWS (p[-1])) + --p; + *p = 0; + } + + p = strchr (ws.ws_wordv[i], '/'); + if (!p) + continue; + + *p++ = 0; + + if ((strcmp (ws.ws_wordv[i], "*") == 0 + || strcmp (ws.ws_wordv[i], type) == 0) + && (strcmp (p, "*") == 0 + || strcmp (p, subtype) == 0)) + { + rc = 0; + break; + } + } + + wordsplit_free (&ws); + + if (rc) + ctlio_reply (io, 406, NULL); + + return rc; +} + static void ctlio_do_command (struct ctlio *io) { const char *val; struct ctlio_resource *res; enum http_method method; @@ -981,20 +1037,14 @@ ctlio_do_command (struct ctlio *io) { ctlio_reply (io, 415, "Unsupported content type"); return; } } -#if 0 - FIXME - if (check_accept(io, "application/json")) - { - ctlio_reply (io, 406, NULL); - return; - } -#endif + if (check_accepted_media (io, "application", "json")) + return; method = method_decode (io->input.input_method); if (method == METH_INVALID) { ctlio_reply (io, 405, NULL); return; @@ -1040,13 +1090,12 @@ ctlio_do_command (struct ctlio *io) json = json_parse_string (ctlbuf_peek (&io->input.ibuf), ctlbuf_rdsize (&io->input.ibuf)); if (!json) { ctlio_reply (io, 400, "JSON error: %s", json_err_diag); - //FIXME: Reply json return; } } else if (json_query) { if (method == METH_POST) |