Commit | Line | Data |
---|---|---|
a33962ba | 1 | /* |
9028e234 IJ |
2 | * Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk> |
3 | * Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk> | |
4 | * Copyright 1999,2003 | |
5 | * Chancellor Masters and Scholars of the University of Cambridge | |
6 | * Copyright 2010 Tony Finch <fanf@dotat.at> | |
a33962ba | 7 | * |
8 | * This is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by | |
9028e234 | 10 | * the Free Software Foundation; either version 3 of the License, or |
a33962ba | 11 | * (at your option) any later version. |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
9028e234 | 19 | * along with userv-utils; if not, see http://www.gnu.org/licenses/. |
a33962ba | 20 | */ |
6a580c17 | 21 | |
22 | #include <stdio.h> | |
23 | #include <string.h> | |
6aaa2ce3 | 24 | #include <errno.h> |
6a580c17 | 25 | |
26 | #include "ucgi.h" | |
27 | ||
28 | const char *const envok[]= { | |
957b3b21 | 29 | "AUTH_TYPE", |
6a580c17 | 30 | "CONTENT_LENGTH", |
31 | "CONTENT_TYPE", | |
32 | "DOCUMENT_ROOT", | |
33 | "GATEWAY_INTERFACE", | |
34 | "HTTP_ACCEPT", | |
957b3b21 | 35 | "HTTP_ACCEPT_CHARSET", |
6a580c17 | 36 | "HTTP_ACCEPT_ENCODING", |
37 | "HTTP_ACCEPT_LANGUAGE", | |
38 | "HTTP_CACHE_CONTROL", | |
957b3b21 IJ |
39 | "HTTP_CONNECTION", |
40 | "HTTP_CONTENT_ENCODING", | |
05aecda5 | 41 | "HTTP_COOKIE", |
957b3b21 | 42 | "HTTP_DNT", |
6a580c17 | 43 | "HTTP_HOST", |
957b3b21 | 44 | "HTTP_KEEP_ALIVE", |
6a580c17 | 45 | "HTTP_NEGOTIATE", |
46 | "HTTP_PRAGMA", | |
50689b02 | 47 | "HTTP_REFERER", |
6a580c17 | 48 | "HTTP_USER_AGENT", |
957b3b21 IJ |
49 | "HTTP_VIA", |
50 | "HTTP_X_FORWARDED_FOR", | |
51 | "HTTPS", | |
6a580c17 | 52 | "PATH_INFO", |
53 | "PATH_TRANSLATED", | |
54 | "QUERY_STRING", | |
55 | "REMOTE_ADDR", | |
56 | "REMOTE_HOST", | |
57 | "REMOTE_USER", | |
58 | "REMOTE_IDENT", | |
59 | "REQUEST_METHOD", | |
957b3b21 | 60 | "REQUEST_URI", |
6a580c17 | 61 | "SCRIPT_FILENAME", |
62 | "SCRIPT_NAME", | |
63 | "SCRIPT_URI", | |
64 | "SCRIPT_URL", | |
957b3b21 | 65 | "SERVER_ADDR", |
6a580c17 | 66 | "SERVER_ADMIN", |
67 | "SERVER_NAME", | |
68 | "SERVER_PORT", | |
69 | "SERVER_PROTOCOL", | |
957b3b21 | 70 | "SERVER_SIGNATURE", |
6a580c17 | 71 | "SERVER_SOFTWARE", |
72 | 0 | |
73 | }; | |
74 | const int nenvok= sizeof(envok)/sizeof(envok[0]); | |
75 | ||
76 | int debugmode= 0; | |
77 | ||
78 | static void outerror(void) { | |
79 | perror("stdout"); | |
80 | exit(debugmode ? 0 : -1); | |
81 | } | |
82 | ||
83 | void syserror(const char *m) { | |
84 | if (printf("Content-Type: text/plain\n\n" | |
85 | "ucgi: system call error:\n" | |
86 | "%s: %s\n", | |
87 | m,strerror(errno))==EOF || fflush(stdout)) outerror(); | |
88 | exit(0); | |
89 | } | |
90 | ||
91 | void error(const char *m) { | |
92 | if (printf("Content-Type: text/plain\n\n" | |
93 | "ucgi: error:\n" | |
94 | "%s\n", | |
95 | m)==EOF || fflush(stdout)) outerror(); | |
96 | exit(0); | |
97 | } | |
98 | ||
99 | void *xmalloc(size_t sz) { | |
100 | void *r; | |
101 | ||
102 | r= malloc(sz); | |
103 | if (!r) syserror("malloc failed"); | |
104 | return r; | |
105 | } | |
106 | ||
107 | void xsetenv(const char *en, const char *ev, int overwrite) { | |
108 | if (setenv(en,ev,overwrite)) syserror("setenv"); | |
109 | } |