/* cgitest.c - Testprogram for cgi.o Copyright (c) 1998,9 by Martin Schulze This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ /* * Compile with: cc -o cgitest cgitest.c -lcgi */ #include #include #include s_cgi *cgi; #define URL "http://www.infodrom.north.de/cgilib/" void print_form() { printf ("

Test-Form

\n"); printf ("
\n"); printf ("Input: \n
"); printf ("\n"); printf ("Text: \n"); printf ("
"); printf ("
\n"); printf ("
\n"); printf ("
\n"); printf ("Input: \n
"); printf ("\n"); printf ("Text: \n"); printf ("
"); printf ("
\n"); printf ("
\n"); printf ("



Redirect

\n"); printf ("



List Everything

\n"); printf ("



Set Cookie

\n"); } void eval_cgi() { printf ("

Results

\n\n"); printf ("string: %s

\n", cgiGetValue(cgi, "string")); printf ("text: %s

\n", cgiGetValue(cgi, "text")); printf ("select: %s

\n", cgiGetValue(cgi, "select")); } void listall (char **env) { char **vars; char *val; s_cookie *cookie; int i; printf ("

Environment Variables

\n
\n");
  for (i=0; env[i]; i++)
    printf ("%s\n", env[i]);
  
  printf ("
\n

CGI Variables

\n
\n");

  vars = cgiGetVariables (cgi);
  if (vars) {
      for (i=0; vars[i] != NULL; i++) {
	  val = cgiGetValue (cgi, vars[i]);
	  printf ("%s=%s\n", vars[i], val?val:"");
      }
      for (i=0; vars[i] != NULL; i++)
	  free (vars[i]);
  }

  printf ("
\n

Cookies

\n
\n");

  vars = cgiGetCookies (cgi);
  if (vars) {
      for (i=0; vars[i] != NULL; i++) {
	  cookie = cgiGetCookie (cgi, vars[i]);
	  printf ("%s=%s\n", vars[i], cookie?cookie->value:"");
      }
      for (i=0; vars[i] != NULL; i++)
	  free (vars[i]);
  }
  printf ("
\n"); } int main (int argc, char **argv, char **env) { char *path_info = NULL; cgiDebug(0, 0); cgi = cgiInit(); path_info = getenv("PATH_INFO"); if (path_info) { if (!strcmp(path_info, "/redirect")) { cgiRedirect("http://www.infodrom.north.de/"); exit (0); } else if (!strcmp(path_info, "/setcookie")) { cgiSetHeader ("Set-Cookie", "Version=1; Library=cgilib; Path=/"); cgiHeader(); printf ("\ncgilib\n\n\n"); printf ("

cgilib

\n", URL); printf ("

Cookie "Library" set

\n"); printf ("



Test

\n"); printf ("



Redirect

\n"); printf ("



List Everything

\n"); } else if (!strcmp(path_info, "/listall")) { cgiHeader(); printf ("\ncgilib\n\n\n"); printf ("

cgilib

\n", URL); listall (env); } else { cgiHeader(); printf ("\ncgilib\n\n\n"); printf ("

cgilib

\n", URL); if (strlen (path_info)) printf ("path_info: %s
\n", path_info); if (!strcmp(path_info, "/insertdata")) { eval_cgi(); } else print_form(); } } else { cgiHeader(); printf ("\ncgilib\n\n\n"); printf ("

cgilib

\n", URL); print_form(); } printf ("\n
\n\n\n"); return 0; } /* * Local variables: * c-indent-level: 4 * c-basic-offset: 4 * tab-width: 8 * End: */