📄 ch4.htm
字号:
<HTML>
<HEAD>
<TITLE>Chapter 4 -- Comparison of the Various CGI programming Libraries</TITLE>
<META>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910">
<H1><FONT COLOR=#FF0000>Chapter 4</FONT></H1>
<H1><B><FONT SIZE=5 COLOR=#FF0000>Comparison of the Various CGI programming Libraries </FONT></B>
</H1>
<P>
<HR WIDTH="100%"></P>
<P>
<H3 ALIGN=CENTER><FONT COLOR="#000000"><FONT SIZE=+2>CONTENTS<A NAME="CONTENTS"></A>
</FONT></FONT></H3>
<UL>
<LI><A HREF="#CGILibrariesforCProgramming" >CGI Libraries for C Programming</A>
<UL>
<LI><A HREF="#CGIc105" >CGIc 1.05</A>
<LI><A HREF="#CGIHTML121" >CGI-HTML 1.21</A>
</UL>
<LI><A HREF="#TheccGIClassLibraries" >The C++ CGI Class Libraries</A>
<UL>
<LI><A HREF="#AHTML" >AHTML</A>
<LI><A HREF="#KellyBlacksCGIcclasses" >Kelly Black's CGI C++ Classes</A>
</UL>
<LI><A HREF="#PerlLibraries" >Perl Libraries</A>
<UL>
<LI><A HREF="#CGILib" >CGI-Lib</A>
</UL>
<LI><A HREF="#Summary" >Summary</A>
</UL>
<HR>
<P>
There are many languages used for CGI programming. With each of
those different languages, there is almost always more than one
library for CGI. This chapter looks at the libraries, what they
have to offer, and rates them.
<P>
All of the short synopses of the libraries were rewritten from
information taken from the documentation of the library, which
is the property of the respective authors.
<H2><A NAME="CGILibrariesforCProgramming"><FONT SIZE=5 COLOR=#FF0000>CGI
Libraries for C Programming</FONT></A></H2>
<P>
The CGI Libraries for the C language that we will review and compare
are the following:
<UL>
<LI><FONT COLOR=#000000>CGIc 1.05</FONT>
<LI><FONT COLOR=#000000>CGIHTML 1.21</FONT>
</UL>
<P>
Of all of these CGI libraries for the C language, CGIc is the
best for three simple reasons: It is actively maintained, has
great documentation, and has good support.
<H3><A NAME="CGIc105">CGIc 1.05</A></H3>
<P>
Of the CGI libraries I tested, CGIc had the best documentation
and is the only one to offer more than one level of support. Combined
with the fact that it is moderately easy to use, this library
is the best all-around choice.
<P>
CGIc has the following features:
<UL>
<LI><FONT COLOR=#000000>Has some advanced form handling</FONT>
<LI><FONT COLOR=#000000>Can handle all of the CGI environment
variables</FONT>
<LI><FONT COLOR=#000000>Can perform automatic redirection</FONT>
<LI><FONT COLOR=#000000>Can output HTTP error/status codes instead
of a document</FONT>
<LI><FONT COLOR=#000000>Includes a safer version of the </FONT><TT><FONT FACE="Courier">system()</FONT></TT>
function
<LI><FONT COLOR=#000000>Allows capturing of CGI sessions for later
playback/debugging</FONT>
<LI><FONT COLOR=#000000>Has a full featured error handling system</FONT>
</UL>
<P>
The following lists CGIc's functions and procedures and contains
a short synopsis of each. If you want more information, see the
documentation that comes with CGIc.
<UL>
<LI><TT><FONT FACE="Courier">cgiFormString(char <I>*name</I>,char
<I>*result</I>, int <I>max</I>)</FONT></TT>. This function returns
a <TT><FONT FACE="Courier">cgiFormResultType</FONT></TT>. It is
used to copy strings from input fields. It copies <I>max</I>-1
bytes of the string in the field name to the buffer <TT><FONT FACE="Courier">result</FONT></TT>.
If the field doesn't exist, it copies a blank string to the <TT><FONT FACE="Courier">result</FONT></TT>
buffer. All newlines in this function are represented by the line
feed character.
<LI><TT><FONT FACE="Courier">cgiFormStringNoNewlines(char <I>*name</I>,
char <I>*result</I>, int <I>max</I>)</FONT></TT>. This function
returns a <TT><FONT FACE="Courier">cgiFormResultType</FONT></TT>.
It is exactly like the <TT><FONT FACE="Courier">cgiFormString</FONT></TT>
function except that all CRs and LFs are stripped out.
<LI><TT><FONT FACE="Courier">cgiFormStringSpace(char <I>*name</I>,
int <I>*length</I>)</FONT></TT>. This function returns a <TT><FONT FACE="Courier">cgiFormResultType</FONT></TT>.
It returns the <I>length</I> of the string pointed to by <TT><FONT FACE="Courier">name</FONT></TT>
and puts it in <TT><I><FONT FACE="Courier">length</FONT></I></TT>.
<LI><TT><FONT FACE="Courier">cgiFormStringMultiple(char <I>*name</I>,
char **<I>*ptrToStringArray</I>)</FONT></TT>. This function returns
a <TT><FONT FACE="Courier">cgiFormResultType</FONT></TT>. If you
have more than one input element with the same name or have elements
that contain strings that dynamically change, you might want to
use this function. It puts the values of all the input elements
with the name <TT><FONT FACE="Courier">char *name</FONT></TT>
into the <TT><FONT FACE="Courier">ptrTo<I>StringArray</I></FONT></TT>.
<LI><TT><FONT FACE="Courier">cgi<I>StringArray</I>Free(char *<I>*stringArray</I>)</FONT></TT>.
This is a procedure. It frees the memory allocated to the <TT><I><FONT FACE="Courier">stringArray</FONT></I></TT>.
<LI><TT><FONT FACE="Courier">cgiFormInteger(char <I>*name</I>,
int <I>*result</I>, int <I>defaultV</I>)</FONT></TT>. Returns
a <TT><FONT FACE="Courier">cgiFormResultType</FONT></TT>. Takes
the integer from input field and puts it in <TT><FONT FACE="Courier">result</FONT></TT>.
<LI><TT><FONT FACE="Courier">cgiFormIntegerBounder(char <I>*name</I>,
int <I>*result</I>, int <I>min</I>, int <I>max</I>, int <I>defaultV</I>)</FONT></TT>.
Returns a <TT><FONT FACE="Courier">cgiFormResultType</FONT></TT>.
Takes the integer from the input field if it is in the bounds
and puts it in <TT><FONT FACE="Courier">result</FONT></TT>.
<LI><TT><FONT FACE="Courier">cgiFormDouble(char <I>*name</I>,
double <I>*result</I>, double <I>defaultV</I>)</FONT></TT>. Returns
a <TT><FONT FACE="Courier">cgiFormResultType</FONT></TT>. Takes
a floating point value from the input field and puts it in <TT><FONT FACE="Courier">result</FONT></TT>.
<LI><TT><FONT FACE="Courier">cgiFormDoubleBounded(char <I>*name</I>,
double <I>*result</I>, double <I>min</I>, double <I>max</I>, double
<I>defaultV</I>)</FONT></TT>. Returns a <TT><FONT FACE="Courier">cgiFormResultType</FONT></TT>.
Takes a floating point value from an input field if it is in the
bounds and puts it in <TT><FONT FACE="Courier">result</FONT></TT>.
<LI><TT><FONT FACE="Courier">cgiFormSelectSingle(char <I>*name</I>,
char **choicesText, int choicesTotal, int <I>*result</I>, int
<I>defaultV</I>)</FONT></TT>. Returns a <TT><FONT FACE="Courier">cgiFormResultType</FONT></TT>.
Takes the selection box (what follows a <TT><FONT FACE="Courier"><SELECT></FONT></TT>
statement), copies the names of the choices into <TT><FONT FACE="Courier">choicesText</FONT></TT>,
copies the number of choices to <TT><FONT FACE="Courier">choicesTotal</FONT></TT>,
and copies the currently selected choice to <TT><FONT FACE="Courier">result</FONT></TT>.
<LI><TT><FONT FACE="Courier">cgiFormSelectMultiple(char <I>*name</I>,
char **choicesText, int choicesTotal, int <I>*result</I>, int
<I>defaultV</I>)</FONT></TT>. Returns a <TT><FONT FACE="Courier">cgiFormResultType</FONT></TT>.
Like <TT><FONT FACE="Courier">cgiFormSelectSingle</FONT></TT>,
only results should point to an array of integers that represent
the selected choices.
<LI><TT><FONT FACE="Courier">cgiFormCheckboxSingle(char <I>*name</I>)</FONT></TT>.
Returns a <TT><FONT FACE="Courier">cgiFormResultType</FONT></TT>.
This function returns <TT><FONT FACE="Courier">cgiFormSuccess</FONT></TT>
if the checkbox is checked and returns <TT><FONT FACE="Courier">cgiFormNotFound</FONT></TT>
if it isn't.
<LI><TT><FONT FACE="Courier">cgiFormCheckboxMultiple(char <I>*name</I>,
char *<I>*stringArray</I>, int <I>valuesTotal</I>, int <I>*result</I>,
int *invalid)</FONT></TT>. Returns a <TT><FONT FACE="Courier">cgiFormResultType</FONT></TT>.
Like <TT><FONT FACE="Courier">cgiFormCheckboxSingle</FONT></TT>
but handles multiple checkboxes with the same name instead. <TT><FONT FACE="Courier">name</FONT></TT>
points to the name of the checkbox. <TT><I><FONT FACE="Courier">stringArray</FONT></I></TT>
points to an array containing the <TT><FONT FACE="Courier"><VALUE></FONT></TT>
parameter of each checkbox. <TT><FONT FACE="Courier">valueTotal</FONT></TT>
points to the total number of checkboxes. <TT><FONT FACE="Courier">result</FONT></TT>
is an array of integers that contains a <TT><FONT FACE="Courier">1</FONT></TT>
for each checkbox checked and a <TT><FONT FACE="Courier">0</FONT></TT>
for those that aren't.
<LI><TT><FONT FACE="Courier">cgiFormRadio(char <I>*name</I>, char
*<I>*stringArray</I>, int <I>valuesTotal</I>, int <I>*result</I>,
int <I>defaultV</I>)</FONT></TT>. Returns a <TT><FONT FACE="Courier">cgiFormResultType</FONT></TT>.
This function is like <TT><FONT FACE="Courier">cgiFormCheckboxMultiple</FONT></TT>,
except that it is for radio buttons instead of checkboxes.
<LI><TT><FONT FACE="Courier">cgiHeaderLocation(char *redirectUrl)</FONT></TT>.
Does not return a value. Redirects the user to the URL specified
in <TT><FONT FACE="Courier">redirectURL</FONT></TT>.
<LI><TT><FONT FACE="Courier">cgiHeaderStatus(int status, char
*statusMessage)</FONT></TT>. Does not return a value. Outputs
the status code <TT><FONT FACE="Courier">status</FONT></TT> and
the message <TT><FONT FACE="Courier">statusMessage</FONT></TT>.
<LI><TT><FONT FACE="Courier">cgiHeaderContentType(char *mimeType)</FONT></TT>.
Does not return a value. Used to tell the browser what type of
document you are returning.
<LI><TT><FONT FACE="Courier">cgiSaferSystem(char *<I>command</I>)</FONT></TT>.
Returns an <TT><FONT FACE="Courier">int</FONT></TT>. This function
removes all shell metacharacters and then calls the <TT><FONT FACE="Courier">system</FONT></TT>
command to run the command specified by <TT><FONT FACE="Courier">command</FONT></TT>.
<LI><TT><FONT FACE="Courier">cgiWriteEnvironment(char <I>*filename</I>)</FONT></TT>.
Returns a <TT><FONT FACE="Courier">cgiEnvironmentResultType</FONT></TT>.
This function writes the current CGI environment to the file specified
by <TT><I><FONT FACE="Courier">filename</FONT></I></TT> so that
it can be used for later debugging.
<LI><TT><FONT FACE="Courier">cgiReadEnvironment(char <I>*filename</I>)</FONT></TT>.
Returns a <TT><FONT FACE="Courier">cgiEnvironmentResultType</FONT></TT>.
This function reads the CGI environment from the file specified
by <TT><FONT FACE="Courier">filename</FONT></TT> so that it can
be used for debugging.
<LI><TT><FONT FACE="Courier">cgiMain()</FONT></TT>. Returns an
<TT><FONT FACE="Courier">int</FONT></TT>. This is where the real
main program goes.
</UL>
<P>
The following is the rest of the information you need to know
about the CGIc library:
<UL>
<LI><FONT COLOR=#000000>Amount of Documentation: 21 pages; comes
in HTML and text format.</FONT>
<LI><FONT COLOR=#000000>Quality of Documentation: The documentation
for this library is very well written and provides answers to
every question you will have about the library.</FONT>
<LI><FONT COLOR=#000000>Commercial License Required/Price: Possibly;
see manual for details.</FONT>
<LI><FONT COLOR=#000000>Actively Maintained: Yes. This library
is updated periodically by Thomas Boutell.</FONT>
<LI><FONT COLOR=#000000>Level of Support: Both e-mail support
(free) and priority support (not free) are available.</FONT>
<LI><FONT COLOR=#000000>Ease of Use: Moderately easy.</FONT>
<LI><FONT COLOR=#000000>Number of sample programs: three.</FONT>
</UL>
<P>
The following is a summary of each sample program:
<UL>
<LI><TT><FONT FACE="Courier">cgictest.c</FONT></TT>. This parses
the results from testform.htm and prints them out.
<LI><TT><FONT FACE="Courier">capture.c</FONT></TT>. This saves
the CGI environment for later use and tells the user it did so.
<LI><FONT COLOR=#000000>Cross-Platform Compatibility. Should run
on any platform that has a ANSI C compiler.</FONT>
</UL>
<P>
If you would like more information about CGIc, try the following:
<UL>
<LI><FONT COLOR=#000000>Author's e-mail address: </FONT><TT><FONT FACE="Courier">boutell@boutell.com</FONT></TT>.
<LI><FONT COLOR=#000000>Author's Web page: </FONT><TT><FONT FACE="Courier"><A HREF="http://www.boutell.com">http://www.boutell.com</A></FONT></TT>.
</UL>
<H3><A NAME="CGIHTML121">CGI-HTML 1.21</A></H3>
<P>
Of the CGI libraries I tested, CGI-HTML 1.21 was the second best.
Unfortunately, it is still in major development and does not offer
priority support. On the good side, it offers source code, and
it is completely free.
<P>
Following are the features of CGI-HTML 1.21:
<UL>
<LI><FONT COLOR=#000000>Has the most advanced form handling of
any of the libraries I had a chance to test. </FONT>
<LI><FONT COLOR=#000000>Can handle all of the CGI environment
variables.</FONT>
<LI><FONT COLOR=#000000>Can perform automatic redirection.</FONT>
<LI><FONT COLOR=#000000>Can output HTTP error/status codes instead
of a document.</FONT>
</UL>
<P>
The following lists the procedures and functions of CGI-HTML 1.21
and includes a short synopsis of each. For more information, see
the documentation that comes with the library.
<UL>
<LI><TT><FONT FACE="Courier">die()</FONT></TT>. Does not return
a value. Kills the program gracefully.
<LI><TT><FONT FACE="Courier">accept_images()</FONT></TT>. Returns
a <TT><FONT FACE="Courier">short</FONT></TT>. Determines if the
browser supports images. 1 if it does; 0 if it doesn't.
<LI><TT><FONT FACE="Courier">unescape_url()</FONT></TT>. Does
not return a value. Converts the escape sequences in the URI to
real characters.
<LI><TT><FONT FACE="Courier">read_cgi_input(llist *entries)</FONT></TT>.
Returns an integer. Parses the server data and puts it into the
linked list pointed to by <TT><FONT FACE="Courier">entries</FONT></TT>.
<LI><TT><FONT FACE="Courier">cgi_val(llist l, char <I>*name</I>)</FONT></TT>.
Returns a <TT><FONT FACE="Courier">char *</FONT></TT>. Searches
list l for name <TT><FONT FACE="Courier">name</FONT></TT> and
returns it if it is found.
<LI><TT><FONT FACE="Courier">cgi_val_multi(llist l, char <I>*name</I>)</FONT></TT>.
Returns a <TT><FONT FACE="Courier">char **</FONT></TT>. <TT><FONT FACE="Courier">cgi_val</FONT></TT>
that returns multiple values.
<LI><TT><FONT FACE="Courier">print_cgi_env()</FONT></TT>. Does
not return a value. Prints the CGI environment variables.
<LI><TT><FONT FACE="Courier">print_entries(llist l)</FONT></TT>.
Does not return a value. Prints out the linked list pointed to
by <TT><FONT FACE="Courier">llist</FONT></TT>.
<LI><TT><FONT FACE="Courier">escape_input(char <I>*str</I>)</FONT></TT>.
Returns a char <TT><FONT FACE="Courier">*</FONT></TT>. Removes
shell metacharacters from the string pointed to by <TT><I><FONT FACE="Courier">str</FONT></I></TT>.
<LI><TT><FONT FACE="Courier">html_header()</FONT></TT>. Does not
return a value. Prints out the MIME header required for HTML documents.
<LI><TT><FONT FACE="Courier">mime_header(char *mime)</FONT></TT>.
Does not return a value. Like <TT><FONT FACE="Courier">html_header</FONT></TT>
except it uses the MIME string as the MIME type.
<LI><TT><FONT FACE="Courier">nph_header(char *status)</FONT></TT>.
Does not return a value. Used to send directly to the browser
(NPH stands for No Parse Header).
<LI><TT><FONT FACE="Courier">show_html_page(char <I>*loc</I>)</FONT></TT>.
Does not return a value. Used to show the HTML page pointed to
by <TT><FONT FACE="Courier">loc</FONT></TT> to the browser.
<LI><TT><FONT FACE="Courier">status(char *status)</FONT></TT>.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -