diff options
Diffstat (limited to 'src/ctl.c')
-rw-r--r-- | src/ctl.c | 71 |
1 files changed, 60 insertions, 11 deletions
@@ -662,7 +662,6 @@ ctlio_finalize_reply (struct ctlio *io) /* 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) @@ -840,7 +839,8 @@ ctlio_authenticate (struct ctlio *io) 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; @@ -957,6 +957,62 @@ delim_count (char const *str, int delim) 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) { @@ -984,14 +1040,8 @@ ctlio_do_command (struct ctlio *io) } } -#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) @@ -1043,7 +1093,6 @@ ctlio_do_command (struct ctlio *io) if (!json) { ctlio_reply (io, 400, "JSON error: %s", json_err_diag); - //FIXME: Reply json return; } } |