1
0
Fork 0
forked from fun/fun

Added some basic CGI support using kcgi plus a lot of fixes and content updates. (0.41.9)

This commit is contained in:
Johannes Findeisen 2026-05-09 10:47:33 +02:00
commit 604c415c0c
25 changed files with 407 additions and 13 deletions

View file

@ -47,6 +47,7 @@ This section documents Fun's optional, build-time selectable extensions. Each pa
- [PCRE2 (Perl-compatible regex)](./pcre2/)
- [PC/SC (Smart cards)](./pcsc/)
- [OpenSSL](./openssl/)
- [kcgi](./kcgi/)
## Notes:

View file

@ -16,7 +16,6 @@ tags:
- optional
---
- CMake option: FUN_WITH_INI=ON
- Purpose: Read/write simple INI configuration files.
- Homepage: [https://github.com/ndevilla/iniparser](https://github.com/ndevilla/iniparser){:class="ext"}

View file

@ -15,7 +15,6 @@ tags:
- optional
---
- CMake option: FUN_WITH_JSON=ON
- Purpose: JSON parse/stringify and file helpers via json-c.
- Homepage: [https://json-c.github.io/json-c/](https://json-c.github.io/json-c/){:class="ext"}

View file

@ -0,0 +1,49 @@
layout: page
published: true
noToc: false
noComments: false
noDate: false
title: Fun - KCGI extension (optional)
subtitle: Documentation for KCGI (kcgi) extension (optional)
description: Documentation for KCGI (kcgi) extension (optional)
permalink: /documentation/extensions/kcgi/
lang: en
tags:
- extension
- kcgi
- optional
---
- CMake option: FUN_WITH_KCGI=ON
- Purpose: integrate the kcgi (CGI/FastCGI) C library; provide request parsing and response helpers for building CGI apps in Fun.
- Homepage: [https://kristaps.bsd.lv/kcgi/](https://kristaps.bsd.lv/kcgi/){:class="ext"}
## Build notes:
- Requires system kcgi development headers and libraries (pkg-config name: kcgi).
- If pkg-config is not available, build falls back to linking against libkcgi and zlib (as configured in cmake/Extensions/KCGI.cmake).
## Provided helper/opcodes:
- Function: kcgi_parse(data: none) -> Map | Nil. Parses the current CGI/FastCGI request via kcgi and returns a Map with keys like method, scheme, host, port, path, suffix, query, and fields (GET/POST map). Returns Nil on failure or when the extension is disabled.
- Function: kcgi_reply_start(code:int, content_type:string) -> 1/0. Starts the HTTP reply (sets Content-Type and opens the body).
- Function: kcgi_write(text:string) -> 1/0. Writes a chunk to the response body.
- Function: kcgi_end() -> 1/0. Finalizes the response and frees request resources.
- Opcodes: OP_KCGI_PARSE, OP_KCGI_REPLY_START, OP_KCGI_WRITE, OP_KCGI_END (internal mappings for the functions above).
## Quickstart:
- Configure: cmake -S . -B build -DFUN_WITH_KCGI=ON
- Build: cmake --build build --target fun
- Run example:
- FUN_LIB_DIR="$(pwd)/lib" ./build/fun examples/cgi/hello_kcgi.fun
## Example output:
- Content-Type: text/html; charset=utf-8
- <h1>Hello, Fun!</h1>
## Notes:
- Running outside a real CGI/FastCGI environment may emit RFC warnings (e.g., missing REMOTE_ADDR); these are benign for local testing.
- When FUN_WITH_KCGI is OFF, the helpers behave as no-ops (returning Nil/0) to keep scripts portable.

View file

@ -15,7 +15,6 @@ tags:
- optional
---
- CMake option: FUN_WITH_OPENSSL=ON
- Purpose: provide small crypto helpers backed by OpenSSL. Includes md5, sha256, sha512, ripemd160 helpers.
- Homepage: [https://www.openssl.org/](https://www.openssl.org/){:class="ext"}

View file

@ -18,7 +18,6 @@ tags:
- regex
---
- CMake option: FUN_WITH_PCRE2=ON
- Purpose: Advanced regular expressions via PCRE2.
- Homepage: [https://www.pcre.org/](https://www.pcre.org/){:class="ext"}

View file

@ -16,7 +16,6 @@ tags:
- smart
---
- CMake option: FUN_WITH_PCSC=ON
- Purpose: Access smart card readers/cards via PC/SC (pcsclite).
- Homepage: [https://pcsclite.apdu.fr/](https://pcsclite.apdu.fr/){:class="ext"}

View file

@ -15,7 +15,6 @@ tags:
- sqlite
---
- CMake option: FUN_WITH_SQLITE=ON
- Purpose: Access SQLite databases via the native C API.
- Homepage: [https://www.sqlite.org/](https://www.sqlite.org/){:class="ext"}

View file

@ -16,7 +16,6 @@ tags:
- xml
---
- CMake option: FUN_WITH_XML2=ON
- Purpose: Minimal XML parsing helpers using libxml2.
- Homepage: [http://xmlsoft.org/](http://xmlsoft.org/){:class="ext"}