X-Git-Url: https://git.cameronkatri.com/mandoc.git/blobdiff_plain/05d454ea5afdeb274e3fb040ef46da4a92af0826..67dcc2e5b969bc3dc00fcdd852cb6fd4ed9a2107:/cgi.c?ds=inline diff --git a/cgi.c b/cgi.c index ddbc52bb..4762f819 100644 --- a/cgi.c +++ b/cgi.c @@ -1,7 +1,7 @@ -/* $Id: cgi.c,v 1.157 2018/05/18 14:23:00 schwarze Exp $ */ +/* $Id: cgi.c,v 1.167 2019/07/10 12:49:20 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons - * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze + * Copyright (c) 2014, 2015, 2016, 2017, 2018 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -38,6 +38,7 @@ #include "roff.h" #include "mdoc.h" #include "man.h" +#include "mandoc_parse.h" #include "main.h" #include "manconf.h" #include "mansearch.h" @@ -69,6 +70,7 @@ enum focus { static void html_print(const char *); static void html_putchar(char); static int http_decode(char *); +static void http_encode(const char *p); static void parse_manpath_conf(struct req *); static void parse_path_info(struct req *req, const char *path); static void parse_query_string(struct req *, const char *); @@ -90,6 +92,7 @@ static void resp_format(const struct req *, const char *); static void resp_searchform(const struct req *, enum focus); static void resp_show(const struct req *, const char *); static void set_query_attr(char **, char **); +static int validate_arch(const char *); static int validate_filename(const char *); static int validate_manpath(const struct req *, const char *); static int validate_urifrag(const char *); @@ -315,6 +318,18 @@ http_decode(char *p) return 1; } +static void +http_encode(const char *p) +{ + for (; *p != '\0'; p++) { + if (isalnum((unsigned char)*p) == 0 && + strchr("-._~", *p) == NULL) + printf("%%%2.2X", (unsigned char)*p); + else + putchar(*p); + } +} + static void resp_begin_http(int code, const char *msg) { @@ -400,7 +415,7 @@ resp_searchform(const struct req *req, enum focus focus) /* Write query input box. */ - printf(" q.query != NULL) html_print(req->q.query); printf( "\" size=\"40\""); @@ -436,7 +451,7 @@ resp_searchform(const struct req *req, enum focus focus) printf(" selected=\"selected\""); puts(">All Architectures"); for (i = 0; i < arch_MAX; i++) { - printf("