diff options
author | elektm93 <elektm93@users.noreply.github.com> | 2017-02-28 18:49:53 +0100 |
---|---|---|
committer | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2017-02-28 18:49:53 +0100 |
commit | 6da598ec12269cd7eced0fa13fdf1bf0a2efb496 (patch) | |
tree | 96e8a30f0183d6413557705480532cd949ed7097 | |
parent | 26e76be5bf8eae2b2d46cb8be0c1a9abd3a4187f (diff) |
enabled long commands on httpd module (#213)
* [WIP] enabled long commands on httpd module
changed the parsing of the command that an '%20' in an url is equivalent
to an space.
* [WIP] moved unescaping of uri to httpd module
* [WIP] removed warining of ommiting const
* [FIX] ISOC90 mixed decleration error
-rw-r--r-- | modules/httpd/httpd.c | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/modules/httpd/httpd.c b/modules/httpd/httpd.c index fcf7d9e..8348a43 100644 --- a/modules/httpd/httpd.c +++ b/modules/httpd/httpd.c @@ -37,16 +37,16 @@ static int html_print_head(struct re_printf *pf, void *unused) } -static int html_print_cmd(struct re_printf *pf, const struct http_msg *req) +static int html_print_cmd(struct re_printf *pf, const struct pl *prm) { struct pl params; - if (!pf || !req) + if (!pf || !prm) return EINVAL; - if (pl_isset(&req->prm)) { - params.p = req->prm.p + 1; - params.l = req->prm.l - 1; + if (pl_isset(prm)) { + params.p = prm->p + 1; + params.l = prm->l - 1; } else { params.p = "h"; @@ -66,16 +66,16 @@ static int html_print_cmd(struct re_printf *pf, const struct http_msg *req) } -static int html_print_raw(struct re_printf *pf, const struct http_msg *req) +static int html_print_raw(struct re_printf *pf, const struct pl *prm) { struct pl params; - if (!pf || !req) + if (!pf || !prm) return EINVAL; - if (pl_isset(&req->prm)) { - params.p = req->prm.p + 1; - params.l = req->prm.l - 1; + if (pl_isset(prm)) { + params.p = prm->p + 1; + params.l = prm->l - 1; } else { params.p = "h"; @@ -90,23 +90,40 @@ static int html_print_raw(struct re_printf *pf, const struct http_msg *req) static void http_req_handler(struct http_conn *conn, const struct http_msg *msg, void *arg) { + int err; + char *buf; + struct pl nprm; (void)arg; + err = re_sdprintf(&buf, "%H", uri_header_unescape, &msg->prm); + if (err) + goto error; + + pl_set_str(&nprm, buf); + if (0 == pl_strcasecmp(&msg->path, "/")) { http_creply(conn, 200, "OK", "text/html;charset=UTF-8", - "%H", html_print_cmd, msg); + "%H", html_print_cmd, &nprm); } else if (0 == pl_strcasecmp(&msg->path, "/raw/")) { http_creply(conn, 200, "OK", "text/plain;charset=UTF-8", - "%H", html_print_raw, msg); + "%H", html_print_raw, &nprm); } else { - http_ereply(conn, 404, "Not Found"); + goto error; } + mem_deref(buf); + + return; + + error: + mem_deref(buf); + http_ereply(conn, 404, "Not Found"); + } |