Comparison of CGI libraries in C

This is a work-in-progress comparing the available libraries for dealing with CGI (Common Gateway Interface) in C. After having looked at the available libraries shown below for dealing with CGI in C, I actually decided to write my own. At the moment it is not ready for public release. As part of the process of preparing it for general release, I've made the following comparison.

Libraries

Library name (host)
(Links open in a new window)
Last update Author Last version Licence
Lightweight CGI Library (www.infodrom.org) 2009-02-08 Martin Schulze 0.7 GNU GPL Download
cgic (www.boutell.com) 2008 Thomas Boutrell 2.05 Advertising (see site for details) Download
libcgic (www.pavluk.org) 2008 Vladimir V. Pavluk
CGL (www.harding.motd.ca) 2005-08-18 Carson Harding 1.2 BSD-like Download
cgi-util (www.newbreedsoftware.com) 2005 Bill Kendrick, Mike Simons 2.2.1 GNU Library GPL Download
CGI-LIB (www.joeldare.com) 2004 Noel V Aguilar, Joel Dare
cgihtml (www.eekim.com) 2001-05-25 Eric E. Kim 1.69 Unspecified Download
A CGI Library for C (sourceforge.net) 1999 William L. Chatfield 1.0 GNU GPL or GNU Library GPL Download

Features

Basics

C version Documentation Automated tests
Lightweight CGI Library GNU C yes (man files) ?
cgic ANSI yes (web page) ?
libcgic Unknown × ?
CGL Unknown yes (doc/cgl.txt) ?
cgi-util Unknown yes (README.txt) ?
CGI-LIB Unknown ? ?
cgihtml Unknown ?
A CGI Library for C Unknown × ?

HTTP headers

Set content type Set encoding Set status Set error message Add arbitrary HTTP headers Print header
Lightweight CGI Library cgiSetType × × × cgiSetHeader cgiHeader
cgic cgiHeaderContentType × cgiHeaderStatus cgiHeaderStatus × ×
libcgic ? ? ? ? ? ?
CGL cgl_content_header × cgl_status_header cgl_status_header × cgl_html_header
cgi-util × × × × × ×
CGI-LIB ? ? ? ? ? ?
cgihtml mime_header × status status × http_header
A CGI Library for C × × × × × ×

Form parsing

process query string application/x-url-formencoded multipart/form-data (file upload) Multiple values for one key uri escape uri unescape
Lightweight CGI Library separated by \n × ×
cgic cgiFormStringMultiple × ×
libcgic ? ? ? ? ? ?
CGL × cgl_getvalues cgl_urlencode cgl_urldecode
cgi-util × × unescape_url
CGI-LIB ? ? ? ? ? ?
cgihtml cgi_name_multi × unescape_url
A CGI Library for C × × ×

Cookies

Read cookies Set cookies Create cookie time strings Delete cookies
Lightweight CGI Library × × ×
cgic ×
libcgic ? ? ? ?
CGL cgl_cookietime ×
cgi-util cgi_getcookie × × ×
CGI-LIB ? ? ? ?
cgihtml × ×
A CGI Library for C × × × ×

Extras

html generation compression save environment Redirects
Lightweight CGI Library × × × cgiRedirect
cgic × × cgiWriteEnvironment cgiHeaderLocation
libcgic ? ? ? ?
CGL × cgl_dumpenv ×
cgi-util × × × ×
CGI-LIB ? ? ? ?
cgihtml × print_cgi_env ×
A CGI Library for C × × × ×

Key:

×
Does not have this feature
?
Unknown or not tested
Has this feature

Reviews

"Lightweight CGI Library" by Martin Schulze

Appears to be the author's personal hack more than anything else. The use of C string functions in parsing multipart/form-data is likely to cause problems in the case of binary file uploads with bytes equal to zero.

The web page for this library claims that it supports writing cookies, but I could not see where this was implemented.

"cgic" by Thomas Boutrell

The "advertising" licence is a nuisance, and limits the library's usefulness. For some reason, this library provides a main function, and insists that the user uses something called cgiMain instead. The first thing the library does is to read every possible environment variable, but most of these it goes on to completely ignore. The library is missing some obvious features such as the ability to set the page's encoding.

"CGL" by Carson Harding

A lot of this code looks useful, but it barely seems to be robust.

Careless in the way that it relies on printf for functions like setting the HTTP headers, so there is no distinction between creating the flow of output and setting the headers. This kind of behaviour tends to make debugging difficult. The library is also missing the feature of multipart form handling (file uploads).

The extensive use of hash tables to store form name and value pairs looks a bit excessive considering the number of these things in even a fairly large HTML form.

The library also contains a facility to print headers as if it was a web server rather than a CGI library.

"cgi-util" by Bill Kendrick, Mike Simons

This library is not clearly documented, and seems to be somewhat incomplete. For example, it provides nothing to deal with HTTP headers or cookies. On the bright side, it contains a lot of error status checking. It also contains odd-bod functions like an email address validation routine.

"cgihtml" by Eric E. Kim

This library is no longer updated by its author. Its internals refer to ancient bugs of Netscape Navigator and use fairly cludgy methods to do things like detect whether the browser can accept images.

"A CGI Library for C" by William L. Chatfield

This library has no documentation. Scanning the code, it looks like the main ability is to parse HTML form data. However, it does not cope with multiple values with the same name. It does not seem to have any output parts.


Web links



Copyright © Ben Bullock 2009-2010. All rights reserved. For comments, questions, and corrections, please email Ben Bullock/ Privacy/ Disclaimer