2 cgitest.c - Testprogram for cgi.o
3 Copyright (c) 1998,9 by Martin Schulze <joey@infodrom.north.de>
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
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 * Compile with: cc -o cgitest cgitest.c -lcgi
31 #define URL "http://www.infodrom.north.de/cgilib/"
35 printf ("<h1>Test-Form</h1>\n");
36 printf ("<form action=\"/cgi-bin/cgitest/insertdata\" method=post>\n");
37 printf ("Input: <input name=string size=50>\n<br>");
38 printf ("<select name=select multiple>\n<option>Nr. 1\n<option>Nr. 2\n<option>Nr. 3\n<option>Nr. 4\n</select>\n");
39 printf ("Text: <textarea name=text cols=50>\n</textarea>\n");
40 printf ("<center><input type=submit value=Submit> ");
41 printf ("<input type=reset value=Reset></center>\n");
43 printf ("<hr width=50%%><form action=\"/cgi-bin/cgitest/listall\" method=post>\n");
44 printf ("Input: <input name=string size=50>\n<br>");
45 printf ("<select name=select multiple>\n<option>Nr. 1\n<option>Nr. 2\n<option>Nr. 3\n<option>Nr. 4\n</select>\n");
46 printf ("Text: <textarea name=text cols=50>\n</textarea>\n");
47 printf ("<center><input type=submit value=Show> ");
48 printf ("<input type=reset value=Reset></center>\n");
50 printf ("<p><br><p><br><a href=\"/cgi-bin/cgitest/redirect\">Redirect</a><p>\n");
51 printf ("<p><br><p><br><a href=\"/cgi-bin/cgitest/listall\">List Everything</a><p>\n");
52 printf ("<p><br><p><br><a href=\"/cgi-bin/cgitest/setcookie\">Set Cookie</a><p>\n");
57 printf ("<h1>Results</h1>\n\n");
58 printf ("<b>string</b>: %s<p>\n", cgiGetValue(cgi, "string"));
59 printf ("<b>text</b>: %s<p>\n", cgiGetValue(cgi, "text"));
60 printf ("<b>select</b>: %s<p>\n", cgiGetValue(cgi, "select"));
63 void listall (char **env)
70 printf ("<h3>Environment Variables</h3>\n<pre>\n");
71 for (i=0; env[i]; i++)
72 printf ("%s\n", env[i]);
74 printf ("</pre>\n<h3>CGI Variables</h3>\n<pre>\n");
76 vars = cgiGetVariables (cgi);
78 for (i=0; vars[i] != NULL; i++) {
79 val = cgiGetValue (cgi, vars[i]);
80 printf ("%s=%s\n", vars[i], val?val:"");
82 for (i=0; vars[i] != NULL; i++)
86 printf ("</pre>\n<h3>Cookies</h3>\n<pre>\n");
88 vars = cgiGetCookies (cgi);
90 for (i=0; vars[i] != NULL; i++) {
91 cookie = cgiGetCookie (cgi, vars[i]);
92 printf ("%s=%s\n", vars[i], cookie?cookie->value:"");
94 for (i=0; vars[i] != NULL; i++)
100 int main (int argc, char **argv, char **env)
102 char *path_info = NULL;
107 path_info = getenv("PATH_INFO");
109 if (!strcmp(path_info, "/redirect")) {
110 cgiRedirect("http://www.infodrom.north.de/");
112 } else if (!strcmp(path_info, "/setcookie")) {
113 cgiSetHeader ("Set-Cookie", "Version=1; Library=cgilib; Path=/");
115 printf ("<html>\n<head><title>cgilib</title></title>\n\n<body bgcolor=\"#ffffff\">\n");
116 printf ("<h1><a href=\"%s\">cgilib</a></h1>\n", URL);
117 printf ("<h3>Cookie Library set</h3>\n");
118 printf ("<p><br><p><br><a href=\"/cgi-bin/cgitest\">Test</a><p>\n");
119 printf ("<p><br><p><br><a href=\"/cgi-bin/cgitest/redirect\">Redirect</a><p>\n");
120 printf ("<p><br><p><br><a href=\"/cgi-bin/cgitest/listall\">List Everything</a><p>\n");
121 } else if (!strcmp(path_info, "/listall")) {
123 printf ("<html>\n<head><title>cgilib</title></title>\n\n<body bgcolor=\"#ffffff\">\n");
124 printf ("<h1><a href=\"%s\">cgilib</a></h1>\n", URL);
128 printf ("<html>\n<head><title>cgilib</title></title>\n\n<body bgcolor=\"#ffffff\">\n");
129 printf ("<h1><a href=\"%s\">cgilib</a></h1>\n", URL);
130 if (strlen (path_info))
131 printf ("path_info: %s<br>\n", path_info);
132 if (!strcmp(path_info, "/insertdata")) {
139 printf ("<html>\n<head><title>cgilib</title></title>\n\n<body bgcolor=\"#ffffff\">\n");
140 printf ("<h1><a href=\"%s\">cgilib</a></h1>\n", URL);
144 printf ("\n<hr>\n</body>\n</html>\n");