2 ashd - A Sane HTTP Daemon
3 Copyright (C) 2008 Fredrik Tolf <fredrik@dolda2000.com>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 char *htmlquote(char *text)
35 for(; *text; text++) {
37 bufcatstr(buf, "<");
39 bufcatstr(buf, ">");
41 bufcatstr(buf, "&");
49 void simpleerror(int fd, int code, char *msg, char *fmt, ...)
57 tmp1 = vsprintf2(fmt, args);
59 tmp2 = htmlquote(tmp1);
62 bufcatstr(buf, "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>\r\n");
63 bufcatstr(buf, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n");
64 bufcatstr(buf, "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en-US\" xml:lang=\"en-US\">\r\n");
65 bufcatstr(buf, "<head>\r\n");
66 bprintf(&buf, "<title>%s</title>\r\n", msg);
67 bufcatstr(buf, "</head>\r\n");
68 bufcatstr(buf, "<body>\r\n");
69 bprintf(&buf, "<h1>%s</h1>\r\n", msg);
70 bprintf(&buf, "<p>%s</p>\r\n", tmp2);
71 bufcatstr(buf, "</body>\r\n");
72 bufcatstr(buf, "</html>\r\n");
74 out = fdopen(fd, "w");
75 fprintf(out, "HTTP/1.1 %i %s\r\n", code, msg);
76 fprintf(out, "Content-Type: text/html\r\n");
77 fprintf(out, "Content-Length: %i\r\n", buf.d);
79 fwrite(buf.b, 1, buf.d, out);