chiark / gitweb /
Update VERSION
[userv-utils] / www-cgi / ucgicommon.c
CommitLineData
39c4ee86 1/*
2 * Copyright (C) 1998-1999 Ian Jackson
3 *
4 * This is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with userv-utils; if not, write to the Free Software
16 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * $Id: ucgicommon.c,v 1.3 1999/11/09 23:04:32 ian Exp $
19 */
6a580c17 20
21#include <stdio.h>
22#include <string.h>
6aaa2ce3 23#include <errno.h>
6a580c17 24
25#include "ucgi.h"
26
27const char *const envok[]= {
28 "CONTENT_LENGTH",
29 "CONTENT_TYPE",
30 "DOCUMENT_ROOT",
31 "GATEWAY_INTERFACE",
32 "HTTP_ACCEPT",
33 "HTTP_ACCEPT_ENCODING",
34 "HTTP_ACCEPT_LANGUAGE",
35 "HTTP_CACHE_CONTROL",
36 "HTTP_HOST",
37 "HTTP_NEGOTIATE",
38 "HTTP_PRAGMA",
39 "HTTP_USER_AGENT",
40 "PATH_INFO",
41 "PATH_TRANSLATED",
42 "QUERY_STRING",
43 "REMOTE_ADDR",
44 "REMOTE_HOST",
45 "REMOTE_USER",
46 "REMOTE_IDENT",
47 "REQUEST_METHOD",
48 "SCRIPT_FILENAME",
49 "SCRIPT_NAME",
50 "SCRIPT_URI",
51 "SCRIPT_URL",
52 "SERVER_ADMIN",
53 "SERVER_NAME",
54 "SERVER_PORT",
55 "SERVER_PROTOCOL",
56 "SERVER_SOFTWARE",
57 0
58};
59const int nenvok= sizeof(envok)/sizeof(envok[0]);
60
61int debugmode= 0;
62
63static void outerror(void) {
64 perror("stdout");
65 exit(debugmode ? 0 : -1);
66}
67
68void syserror(const char *m) {
69 if (printf("Content-Type: text/plain\n\n"
70 "ucgi: system call error:\n"
71 "%s: %s\n",
72 m,strerror(errno))==EOF || fflush(stdout)) outerror();
73 exit(0);
74}
75
76void error(const char *m) {
77 if (printf("Content-Type: text/plain\n\n"
78 "ucgi: error:\n"
79 "%s\n",
80 m)==EOF || fflush(stdout)) outerror();
81 exit(0);
82}
83
84void *xmalloc(size_t sz) {
85 void *r;
86
87 r= malloc(sz);
88 if (!r) syserror("malloc failed");
89 return r;
90}
91
92void xsetenv(const char *en, const char *ev, int overwrite) {
93 if (setenv(en,ev,overwrite)) syserror("setenv");
94}