summaryrefslogtreecommitdiffabout
path: root/src/ctl.c
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-05 14:17:38 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-01-05 14:20:24 (GMT)
commit6ac0f1e8e19922c63a1542740a7c88116989bb7c (patch) (side-by-side diff)
tree6124aaa6dbd729deab5de7550f6603056e39b4b3 /src/ctl.c
parentf937fa90807400e87aa64cd03f2c8470093129d7 (diff)
downloadpies-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') (more/less context) (ignore whitespace changes)
-rw-r--r--src/ctl.c71
1 files changed, 60 insertions, 11 deletions
diff --git a/src/ctl.c b/src/ctl.c
index 6145d39..cdb9b6c 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -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;
}
}

Return to:

Send suggestions and report system problems to the System administrator.