Comparison of CGI libraries in C

locust

This is a comparison of publicly available libraries in the C programming language which help to program with CGI, the "common gateway interface" for the world wide web. For more information on the common gateway interface, please see A simple guide to the common gateway interface.

Some of the fields in the following tables are marked as "unknown", "maybe", or given a question mark because I have not had time to evaluate whether the library provides that particular feature. I apologise for the incompleteness of this list and hope that the incomplete list still has some value.

Libraries

The following list of CGI libraries written in C is ordered by the date of the most recent release.

Library name (host)
(Links open in a new window)
Last update Last version Licence Authors Download
kcgi (kristaps.bsd.lv) 2017-03-12 0.9.4 BSD-like Kristaps Dzonsons Download
qDecoder (wolkykim.github.io) 2017-01-23 12.0.6 Public domain Seungyoung Kim Download
cgic (www.boutell.com) 2016-02-29 2.07 Advertising (see site for details) Thomas Boutrell Download
Lightweight CGI Library (www.infodrom.org) 2009-02-08 0.7 GNU GPL Martin Schulze Download
cgi-util (www.newbreedsoftware.com) 2005 2.2.1 GNU Library GPL Bill Kendrick
Mike Simons
Download
CGI-LIB (www.joeldare.com) 2004 2.0 GNU GPL Noel V Aguilar
Joel Dare
Download
Un-CGI (www.midwinter.com) 2003-11-01 1.11 Gnu-like, see source code. Steven Grimm Download
cgihtml (www.eekim.com) 2001-05-25 1.69 Unspecified Eric E. Kim Download
(Not working)
A CGI Library for C (sourceforge.net) 1999 1.0 GNU GPL or GNU Library GPL William L. Chatfield Download

Features

Basics

C version Documentation Automated tests
kcgi Unknown yes (manual pages, web pages) Maybe
qDecoder Unknown yes (web page/doxygen) no
cgic ANSI yes (web page) Maybe
Lightweight CGI Library GNU C yes (man files) Maybe
cgi-util Unknown yes (README.txt) Maybe
CGI-LIB Unknown Maybe Maybe
Un-CGI Unknown Maybe Maybe
cgihtml Unknown yes Maybe
A CGI Library for C Unknown no Maybe

HTTP headers

Set content type Set charset Set status Set error message Add arbitrary HTTP headers Print header
kcgi Maybe Maybe Maybe Maybe khttp_head Maybe
qDecoder qcgires_SetContentType no no no no no
cgic cgiHeaderContentType no cgiHeaderStatus cgiHeaderStatus no no
Lightweight CGI Library cgiSetType no no no cgiSetHeader cgiHeader
cgi-util no no no no no no
CGI-LIB Maybe Maybe Maybe Maybe Maybe Maybe
Un-CGI Maybe Maybe Maybe Maybe Maybe Maybe
cgihtml mime_header no status status no http_header
A CGI Library for C no no no no no no

Form parsing

process query string application/x-url-formencoded multipart/form-data (file upload) Multiple values for one key uri escape uri unescape
kcgi Maybe Maybe Maybe Maybe kutil_urlencode Maybe
qDecoder yes yes yes Maybe yes (in qLibc) yes (in qLibc)
cgic yes yes yes cgiFormStringMultiple no no
Lightweight CGI Library yes yes yes separated by \n no no
cgi-util yes yes yes no no unescape_url
CGI-LIB Maybe Maybe Maybe Maybe Maybe Maybe
Un-CGI Maybe Maybe Maybe Maybe Maybe Maybe
cgihtml yes yes yes cgi_name_multi no unescape_url
A CGI Library for C yes yes yes no no no

Cookies

Read cookies Set cookies Create cookie time strings Delete cookies
kcgi Maybe Maybe Maybe Maybe
qDecoder yes qcgires_setcookie Maybe qcgires_removecookie
cgic yes yes yes no
Lightweight CGI Library yes no no no
cgi-util cgi_getcookie no no no
CGI-LIB Maybe Maybe Maybe Maybe
Un-CGI Maybe Maybe Maybe Maybe
cgihtml yes yes no no
A CGI Library for C no no no no

Extras

html generation compression save environment Redirects
kcgi yes khttp_body_compress Maybe Maybe
qDecoder no no no qcgires_redirect
cgic no no cgiWriteEnvironment cgiHeaderLocation
Lightweight CGI Library no no no cgiRedirect
cgi-util no no no no
CGI-LIB Maybe Maybe Maybe Maybe
Un-CGI Maybe Maybe Maybe Maybe
cgihtml yes no print_cgi_env no
A CGI Library for C no no no no

Key to the tables

No Does not have this feature
Maybe Unknown or not tested
Yes Has this feature

Reviews

These reviews are meant to supplement the tabular information listed above. Most of the CGI libraries listed on this page suffer from very similar problems; none of them has an automated test, almost all of them don't handle HTTP headers fully, and none of them except kcgi handles compression at all.

"kcgi" by Kristaps Dzonsons

Has documentation including tutorials. Also supports FastCGI protocol. Supports compression. Also has base 64 encoding and MD5 checksums built in.

There are some files called "test*" in the distribution but it's not clear how the tests are run.

The author, Kristaps Dzonsons, has strong opinions about various topics, and using this system involves buying in to the author's opinions.

"qDecoder" by Seungyoung Kim

Has basic CGI library features including parsing forms and setting and deleting cookies. The examples on the web page are written in C++ but the code itself is C. Lacks ways to set the HTTP status or the character set of the page.

One unusual feature is a way to force a download using a Content-Disposition: header.

"cgic" by Thomas Boutrell

★★★☆☆

This library has been around since the 1990s. It is carefully programmed to avoid problems such as memory leaks. It has a lot of documentation for each function. It also comes with example code and a debugging helper to capture the CGI environment.

Its licence requires users to either pay a fee or include advertising for it in output. The library provides its own main function, and users must use something called cgiMain instead.

The C programming is a bit questionable. The first thing the library does is to read every possible environment variable into global variables, but most of these it goes on to completely ignore.

"Lightweight CGI Library" by Martin Schulze

This library appears to be quite difficult to use. 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.

"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 uses cludges to do things like detect whether the browser can accept images. The download no longer works.

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

This library has no documentation. From looking at the code, the main ability seems to be to parse HTML form data. It does not seem to have any output parts.

Web links


Copyright © Ben Bullock 2009-2017. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com). / Privacy / Disclaimer