HP e3000 Web Server CGI Programming (November 2008)
Now change the permissions so that it is executable by your WWW user ("chmod 755 cgitest" from
the POSIX shell).
Using your favorite web browser, load the URL http://<webserver>/cgi-bin/cgitest , where
<webserver> is the name of your webserver. If you don't see the one liner "WELCOME TO THE
WORLD OF CGI" and get an error message instead, that means that your cgi-bin/ directory hasn't
been set up correctly for your web server. Refer to your webserver manual for correcting the problem.
NOTE:
All these programs were tested on MPE/iX 5.5. It is strongly recommended that you do the
same since 5.5 contains many fixes for CGI problems (especially for CGI programs NOT written in C
or Perl). Moreover, the phonebook example
was not designed to work in a production
environment with multiple users
. Why?, because the code was written to demonstrate CGI
programming on the HP 3000 and
not to demonstrate robust coding techniques. An example where
there would be problems is the case when two users simultaneously try to add to & delete from the
phone
database. It should work fine for a single user though.The exercise of robustizing the code is
left to the reader.
Now without further ado, let's dive into the examples.
Phonebook application in C
This example consists of two files. One is the main phone application and the other contains the CGI
input parsing routines.
The phonebook application starts of by printing the standard MIME header to STDLIST :
printf("Content-type: text/plain\n\n");
It uses the environment variable CONTENT_LENGTH to determine the size of the CGI input and
reads that much from STDIN. This data is then parsed to extract the individual "name=value"
components. This extracted data is stored in an array of structures containing two fields: name and
val. As pointed to above the data from the phonebook form has three name=value components. The
last name=value component will tell us what action the user requested by clicking one of the ADD,
DELETE, or SEARCH buttons. The main program calls the appropriate phonebook routine,
(phonebook_add, phonebook_delete, or phonebook_search) based on the value in this third
name=value component.
This program could be extended to do more complicated things. For example the phonebook_add(),
phonebook_delete() and phonebook_search() functions could be modified so that they operate on a
phone (Image) database instead of a flat file. The output can also be made more attractive by adding
more HTML embelishments in the output. In the given example the output is in plain text format. Note
that if you decide to output fancy HTML pages instead of the simple text used in the example you will
need to change the MIME header to be Content-type:text/html. The MIME header tells the browser
how the text from the CGI program is to be interpreted and rendered.
Compiling and activating the phonebook
To compile these programs, the C compiler is required. Save the programs as PHONEC and
CGILIBC respectively. Use the following commands from the CI prompt to create the phonebook
application:
CCXL PHONEC, YPHONE, LPHONE; INFO = '-Aa -D_POSIX_SOURCE -DMPE'
Page
7
of
10
HP e3000 Web Server CGI Programming
11/13/2008
http://www.hp.com/cgi
-
bin/pf
-
new.cgi?IN=http://jazz.external.hp.com/papers/cgi
-
paper/c
...