=================================================================== RCS file: /cvs/mandoc/cgi.c,v retrieving revision 1.59 retrieving revision 1.64 diff -u -p -r1.59 -r1.64 --- mandoc/cgi.c 2014/07/09 16:23:01 1.59 +++ mandoc/cgi.c 2014/07/12 01:55:30 1.64 @@ -1,4 +1,4 @@ -/* $Id: cgi.c,v 1.59 2014/07/09 16:23:01 schwarze Exp $ */ +/* $Id: cgi.c,v 1.64 2014/07/12 01:55:30 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2014 Ingo Schwarze @@ -165,7 +165,7 @@ html_printquery(const struct req *req) } if (NULL != req->q.expr) { printf("&expr="); - html_print(req->q.expr ? req->q.expr : ""); + html_print(req->q.expr); } } @@ -284,11 +284,13 @@ static int http_decode(char *p) { char hex[3]; + char *q; int c; hex[2] = '\0'; - for ( ; '\0' != *p; p++) { + q = p; + for ( ; '\0' != *p; p++, q++) { if ('%' == *p) { if ('\0' == (hex[0] = *(p + 1))) return(0); @@ -299,13 +301,13 @@ http_decode(char *p) if ('\0' == c) return(0); - *p = (char)c; - memmove(p + 1, p + 3, strlen(p + 3) + 1); + *q = (char)c; + p += 2; } else - *p = '+' == *p ? ' ' : *p; + *q = '+' == *p ? ' ' : *p; } - *p = '\0'; + *q = '\0'; return(1); } @@ -314,12 +316,12 @@ resp_begin_http(int code, const char *msg) { if (200 != code) - printf("Status: %d %s\n", code, msg); + printf("Status: %d %s\r\n", code, msg); - puts("Content-Type: text/html; charset=utf-8\n" - "Cache-Control: no-cache\n" - "Pragma: no-cache\n" - ""); + printf("Content-Type: text/html; charset=utf-8\r\n" + "Cache-Control: no-cache\r\n" + "Pragma: no-cache\r\n" + "\r\n"); fflush(stdout); } @@ -367,7 +369,7 @@ resp_searchform(const struct req *req) "
\n" "Search Parameters\n" " for manuals satisfying \n" + " VALUE=\"Search\"> for manuals matching \n" "q.expr ? req->q.expr : ""); @@ -381,7 +383,7 @@ resp_searchform(const struct req *req) html_print(req->q.arch ? req->q.arch : ""); printf("\">"); if (req->psz > 1) { - puts(", "); for (i = 0; i < (int)req->psz; i++) { printf("
\n" "\n" @@ -408,7 +410,19 @@ resp_index(const struct req *req) { resp_begin_html(200, NULL); + puts("

\n" + "Online manuals with " + "mandoc\n" + "

"); resp_searchform(req); + printf("

\n" + "This web interface is documented in the " + "" + "man.cgi manual, and the " + "" + "apropos manual explains the query syntax.\n" + "

\n", + scriptname, scriptname); resp_end_html(); } @@ -473,12 +487,13 @@ resp_search(const struct req *req, struct manpage *r, * If we have just one result, then jump there now * without any delay. */ - puts("Status: 303 See Other"); + printf("Status: 303 See Other\r\n"); printf("Location: http://%s%s/show/%s/%s?", httphost, scriptname, req->q.manpath, r[0].file); http_printquery(req); - puts("\n" - "Content-Type: text/html; charset=utf-8\n"); + printf("\r\n" + "Content-Type: text/html; charset=utf-8\r\n" + "\r\n"); return; }