Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
afl Use proper template function. Apr 19, 2018
man Note that -lm is required for Linux. Jun 19, 2018
regress Remove arc4random depends. (Just use random(), otherwise.) Jun 19, 2018
GNUmakefile Move seccomp debug option into linux-only area. Jun 19, 2018
LICENSE.md
README.md
archive.css
archive.xml Unify subtitle. Apr 8, 2018
atom-template.xml Adding atom feed. Jan 9, 2018
auth.c Fix RFC 2617 ("auth-int" digest authorisation) as patched by Charles … Mar 22, 2018
child.c Const-ify and fix a check for "buf" when it should have been "b". Apr 10, 2018
compats.c Bring up to date with oconfigure. Apr 19, 2018
configure
datetime.c Copyright year. Jan 4, 2018
extending01-a.dot Adding extension documentation. Mar 15, 2016
extending01-b.dot Adding extension documentation. Mar 15, 2016
extending01-c.dot Adding extension documentation. Mar 15, 2016
extending01-d.dot Adding extension documentation. Mar 15, 2016
extending01.xml More http -> https. Jan 18, 2018
extern.h Required for fcgi.c now. Apr 9, 2018
fcgi.c Clean up kreq on failure. Apr 9, 2018
figure1.dot Lots of documentation improvements, especially in www. May 13, 2015
figure2-cgi-naked.tsv
figure2-cgi.tsv Add new performance measurements. Aug 6, 2015
figure2-fcgi.tsv
figure2-static.tsv
figure2.gnuplot
figure4.dot Regress PHONY (thanks to Baptiste Daroussin) and some documentation. Jul 19, 2015
functions.xml
genindex.sh Add a function index. Oct 12, 2016
httpauth.c Accept hex nc's, inspired by #42. Jun 18, 2018
index.css Add PSA regarding Mac OS X and kcgi, and while here note that systrac… Jun 14, 2018
index.xml Remove reference to libbsd: it's no longer needed. Jun 19, 2018
kcgi.c
kcgi.h
kcgihtml.c Make sure to free writer memory on close. Jan 13, 2018
kcgihtml.h
kcgijson.c Rename putnumberp (as suggested by schwarze@) and simplify some other… Mar 6, 2018
kcgijson.h Return an error code from kjson_open and use kcgi_writer interface. Jan 12, 2018
kcgiregress.c
kcgiregress.h Portability: Linux systems don't (always?) have __BEGIN_DECLS defined… Mar 10, 2016
kcgixml.c
kcgixml.h Split prologue-output into kxml_prologue() to allow calling kxml_open at Jan 12, 2018
kfcgi.c ifndef -> if Oct 18, 2017
logging.c
mandoc.css Add CSS. Jun 15, 2016
output.c Don't make khttp_write functions assert on KSTATE_BODY. It's too easy… Apr 9, 2018
parent.c Full switch to oconfigure instead of current system, so remove all of… Oct 18, 2017
prettify.css Adding prettify locally. Apr 10, 2018
prettify.js Adding prettify locally. Apr 10, 2018
sample-cgi.c Clean up the sample CGI source. Mar 15, 2016
sample-fcgi.c No need to do error checking for HUP and don't include stdlib. Apr 10, 2018
sample.c Merge #37, thanks! Jun 9, 2018
samplepp.cc License. Mar 24, 2018
sandbox-capsicum.c
sandbox-darwin.c Full switch to oconfigure instead of current system, so remove all of… Oct 18, 2017
sandbox-pledge.c Full switch to oconfigure instead of current system, so remove all of… Oct 18, 2017
sandbox-seccomp-filter.c
sandbox-systrace.c
sandbox.c More ifndef -> if. Oct 18, 2017
template.c Add a fast-track for printing non-delimeter content. Apr 19, 2018
template.xml
tests.c
tutorial.css Lots of polish. Apr 10, 2018
tutorial.xml Use local prettify, simplify example, fix copyrights, don't use perml… Apr 10, 2018
tutorial0.xml Flip logic for r.mime. Apr 10, 2018
tutorial1.xml
tutorial2.xml
tutorial3.xml Don't use EXIT_xxxx macros, apply style(9), make sure r.mime is checked. Apr 10, 2018
tutorial4.xml Don't use EXIT_xxxx macros, apply style(9), make sure r.mime is checked. Apr 10, 2018
tutorial5.xml
tutorial6.dot
tutorial6.xml Add in FastCGI pledging. Apr 10, 2018
versions.xml Document -lm and -lbsd on Linux. Jun 19, 2018
wrappers.c

README.md

Synopsis

kcgi is an open source CGI and FastCGI library for C/C++ web applications. It is minimal, secure, and auditable; and fits within your BCHS software stack.

This repository consists of bleeding-edge code between versions: to keep up to date with the current stable release of kcgi, visit the kcgi website. The website also contains canonical installation, deployment, and usage documentation. This page describes using the bleeding-edge version of the system.

Example

Implementing a CGI or FastCGI application with kcgi is easy (for values of easy strictly greater than "knows C/C++"). Specify the pages recognised by the application and the known HTML form inputs. kcgi parses the request and can manage output.

#include <sys/types.h> /* size_t, ssize_t */
#include <stdarg.h> /* va_list */
#include <stddef.h> /* NULL */
#include <stdint.h> /* int64_t */
#include <kcgi.h>
 
int main(void) {
  struct kreq r;
  const char *page = "index";
  if (KCGI_OK != khttp_parse(&r, NULL, 0, &page, 1, 0))
	return 0;
  khttp_head(&r, kresps[KRESP_STATUS],
	"%s", khttps[KHTTP_200]);
  khttp_head(&r, kresps[KRESP_CONTENT_TYPE], 
	"%s", kmimetypes[KMIME_TEXT_PLAIN]);
  khttp_body(&r);
  khttp_puts(&r, "Hello, world!\n");
  khttp_free(&r);
  return 0;
}

For a fuller example reflecting the repository sources, see sample.c or, for C++, samplepp.cc.

Installation

To use the bleeding-edge version of kcgi (instead of from your system's packages or a stable version), the process it the similar as for source releases.

Begin by cloning or downloading. Then configure with ./configure, compile with make (GNU make, so it may be gmake on your system), then sudo make install (or using doas). To install in an alternative directory to /usr/local, set the PREFIX variable when you run configure. (See the configure script for details.)

./configure
make
doas make install

You can also change the default value in the GNUmakefile.

API Reference

For the repository version of kcgi, the locally-installed manpages are the canonical source of information. (The web-site reflects the latest release, which may be older than what you have.)

man kcgi
apropos kcgi

This assumes that kcgi has been installed in a path recognised by your manpage reader. If you're using an alternative installation path, you may need to edit /etc/man.conf or other configuration file appropriate to your system.

Tests

It's useful to run the installed regression tests on the bleeding edge sources. (Again, this uses GNU make, so it may be gmake on your system.)

make regress

The system contains a full regression suite and is also built to work with AFL. To run some of the bundled tests, use the binaries compiled into the afl directory. (Again, this uses GNU make, so it may be gmake on your system.)

make afl
cd afl
afl-fuzz -i in/urlencoded -o out -- ./afl-urlencoded

License

All sources use the ISC (like OpenBSD) license. See the LICENSE.md file for details.