2 aux.c - Auxilliary code for CGI library
3 Copyright (C) 2007,8 by Martin Schulze <joey@infodrom.org>
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 2 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, write to the Free Software Foundation
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 int cgiDebugLevel = 0;
29 char *cgiEscape (char *string)
35 for (cp=string, len=0; *cp; cp++) {
50 if (len == strlen(string))
51 return strdup(string);
53 if ((buf = (char *)malloc(len+1)) == NULL)
56 for (cp=string, np=buf; *cp; cp++) {
87 void cgiDebugOutput (int level, char *format, ...)
91 if (level <= cgiDebugLevel) {
93 va_start (args, format);
95 switch (cgiDebugType) {
98 vprintf (format, args);
99 printf ("\n</pre>\n");
102 vfprintf (stderr, format, args);
106 vsyslog (LOG_DEBUG, format, args);
116 char *cgiGetLine (FILE *stream)
118 static char *line = NULL;
119 static size_t size = 0;
125 if ((line = (char *)malloc (BUFSIZE)) == NULL)
131 while (!feof (stream)) {
132 if ((cp = fgets (buf, sizeof (buf), stream)) == NULL)
139 if (strlen(line)+strlen(buf)+1 > size) {
140 if ((cp = (char *)realloc (line, size + BUFSIZE)) == NULL)
149 if (len && line[len-1] == '\n') {
152 if (len && line[len-1] == '\r')
154 cgiDebugOutput (4, "Read line '%s'", line);