2 Unix SMB/Netbios implementation.
4 some simple CGI helper routines
5 Copyright (C) Andrew Tridgell 1997
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define MAX_VARIABLES 512
32 static struct var variables
[MAX_VARIABLES
];
33 static int num_variables
;
36 static int grab_line(int *cl
, char *line
, int maxsize
)
53 if (c
== '\r') continue;
55 if (strchr("\n&", c
)) break;
57 if (c
== '%' && (*cl
) >= 2) {
62 if (c1
== EOF
|| c2
== EOF
) break;
63 if (c1
>= '0' && c1
<= '9')
65 else if (c1
>= 'A' && c1
<= 'F')
67 else if (c1
>= 'a' && c1
<= 'f')
71 if (c2
>= '0' && c2
<= '9')
73 else if (c2
>= 'A' && c2
<= 'F')
75 else if (c2
>= 'a' && c2
<= 'f')
84 if (i
== maxsize
) break;
87 /* now unescape the line */
95 /***************************************************************************
96 load all the variables passed to the CGI program
97 ***************************************************************************/
98 void cgi_load_variables(void)
104 if (!(p
=getenv("CONTENT_LENGTH"))) return;
108 if (len
<= 0) return;
112 while (len
&& grab_line(&len
, line
, sizeof(line
)-1)) {
113 p
= strchr(line
,'=');
118 variables
[num_variables
].name
= strdup(line
);
119 variables
[num_variables
].value
= strdup(p
+1);
121 if (!variables
[num_variables
].name
||
122 !variables
[num_variables
].value
)
126 printf("%s=%s<br>\n",
127 variables
[num_variables
].name
,
128 variables
[num_variables
].value
);
132 if (num_variables
== MAX_VARIABLES
) break;
139 /***************************************************************************
140 find a variable passed via CGI
141 ***************************************************************************/
142 char *cgi_variable(char *name
)
146 for (i
=0;i
<num_variables
;i
++)
147 if (strcmp(variables
[i
].name
, name
) == 0)
148 return variables
[i
].value
;
153 /***************************************************************************
154 return the value of a CGI boolean variable.
155 ***************************************************************************/
156 int cgi_boolean(char *name
, int def
)
158 char *p
= cgi_variable(name
);
162 return strcmp(p
, "1") == 0;