libcgi 0.1

Jay C. Weber (weber@eit.COM)
Fri, 8 Jul 94 18:38:41 PDT


--***

EIT is releasing, for your programming pleasure, a freeware
library of functions that aid CGI-program creation in C
(or another language that can use C libraries). Look at

http://wsk.eit.com/wsk/dist/doc/libcgi/libcgi.html

for documentation and pointers to the distributions, including
source. Compiled libraries are there for SunOS 4.1.3, Solaris 2.3,
IRIX 5.2, and OSF/1 V2.0.

These are functions we found useful, especially for programs that
process forms. The get_form_entries function, for example, handles
parameter names and values of arbitrary length with exponential
allocation. It is also more efficient than a lot of the other parsing
code we've seen.

I've attached a template program that uses libcgi so you can
see basically what it does for you.

Isn't it time we started calling them "CGI programs" instead of
"CGI scripts"? ;-)

Jay

--
Jay C. Weber					weber@eit.com
Enterprise Integration Technologies		weber@cis.stanford.edu
800 El Camino Real				(415)617-8002
Menlo Park, CA 94025				fax: (415)617-8019
http://www.eit.com/people/weber.html

--***

/* * This file is part of the LIBCGI library * * Copyright 1994 by Enterprise Integration Technologies Corporation * * This is freeware with commercialization rights reserved; see the * LICENSE included in the distribution for specifics. */

#include<stdio.h> #include "cgi.h"

cgi_main(cgi_info *ci) { char *parmval(form_entry *, char *); form_entry *parms, *p; form_entry *get_form_entries(cgi_info *); char *foo, *bar;

print_mimeheader("text/html");

puts("<title>Your Title Here</title>"); puts("<h1>Your heading here</h1>");

parms = get_form_entries(ci); if (parms) { /* extract specific form parameters */ for(p=parms; p; p = p->next) { if (strcasecmp(p->name, "foo")) foo = p->val; else if (strcasecmp(p->name, "bar")) bar = p->val; } }

switch(mcode(ci)) {

case MCODE_HEAD: return;

case MCODE_GET: puts("Your GET response here"); printf("based on foo=%s and bar=%s.\n", foo, bar); break;

case MCODE_POST: puts("Your POST response here"); printf("based on foo=%s and bar=%s.\n", foo, bar); break;

default: printf("Unrecognized method '%s'.\n", ci->request_method); }

free_form_entries(parms); }

--***--