Initial revision
[rrdtool.git] / libraries / cgilib-0.4 / cgitest.c
1 /*
2     cgitest.c - Testprogram for cgi.o
3     Copyright (c) 1998  Martin Schulze <joey@infodrom.north.de>
4
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.
9
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.
14
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.
18  */
19
20 /*
21  * Compile with: cc -o cgitest cgitest.c -lcgi
22  */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <cgi.h>
27
28 s_cgi **cgi;
29
30 void print_form()
31 {
32     printf ("<h1>Test-Form</h1>\n");
33     printf ("<form action=\"/cgi-bin/cgitest/insertdata\" method=post>\n");
34     printf ("Input: <input name=string size=50>\n<br>");
35     printf ("<select name=select multiple>\n<option>Nr. 1\n<option>Nr. 2\n<option>Nr. 3\n<option>Nr. 4\n</select>\n");
36     printf ("Text: <textarea name=text cols=50>\n</textarea>\n");
37     printf ("<center><input type=submit value=Submit> ");
38     printf ("<input type=reset value=Reset></center>\n");
39     printf ("</form>\n");
40 }
41
42 void eval_cgi()
43 {
44     printf ("<h1>Results</h1>\n\n");
45     printf ("<b>string</b>: %s<p>\n", cgiGetValue(cgi, "string"));
46     printf ("<b>text</b>: %s<p>\n", cgiGetValue(cgi, "text"));
47     printf ("<b>select</b>: %s<p>\n", cgiGetValue(cgi, "select"));
48 }
49
50
51 void main ()
52 {
53     char *path_info = NULL;
54
55     cgiDebug(0, 0);
56     cgi = cgiInit();
57
58     path_info = getenv("PATH_INFO");
59     if (path_info) {
60         if (!strcmp(path_info, "/redirect")) {
61             cgiRedirect("http://www.infodrom.north.de/");
62             exit (0);
63         } else {
64             cgiHeader();
65             printf ("<html>\n<head><title>cgilib</title></title>\n\n<body>\n");
66             printf ("<h1>cgilib</h1>\n");
67             printf ("path_info: %s<br>\n", path_info);
68             if (!strcmp(path_info, "/insertdata")) {
69                 eval_cgi();
70             } else
71                 print_form();
72         }
73     } else {
74         cgiHeader();
75         printf ("<html>\n<head><title>cgilib</title></title>\n\n<body>\n");
76         printf ("<h1>cgilib</h1>\n");
77         print_form();
78     }
79
80     printf ("\n<hr>\n</body>\n</html>\n");
81 }
82
83 /*
84  * Local variables:
85  *  c-indent-level: 4
86  *  c-basic-offset: 4
87  *  tab-width: 8
88  * End:
89  */