cgi_register_parse_cb(3)
β¨ cgi_register_parse_cb(3) β¨
okay bestie, so this one lives in cgi/cgi.h and it's giving "let me handle my own HTTP data, thanks" π
πΈ NAME πΈ
cgi_register_parse_cb β register a parse callback π
π¦ SYNOPSIS π¦
#include <cgi/cgi.h>
NEOERR *cgi_register_parse_cb(CGI *cgi, const char *method, const char *ctype,
void *rock, CGI_PARSE_CB parse_cb);
π ARGUMENTS π
cgiβ aCGIstruct, the main character π«Άmethodβ the HTTP method you wanna handle, or*for all of them (yes, literally all) β¨ctypeβ the HTTP Content-Type you wanna handle, or*for all π«rockβ opaque data that we'll pass to your call back. it's your little secret lil package, we don't look inside π
π DESCRIPTION π
so the ClearSilver CGI Kit already comes with built-in functionality to handle these methods, no cap:
GETβ doesn't have any data except the query string, which is processed for all methods π₯POSTw/application/x-www-form-urlencodedPOSTw/multipart/form-dataβ processed as RFC2388 data into files and HDF (peepcgi_filehandle())PUT(any type) β the entire data chunk is stored as a file, with meta data in HDF (similar to single files in RFC2388). the data is accessible viacgi_filehandlewithNULLfor name π
to handle other methods/content types, you have to register your own parse function. this isn't necessary if you aren't expecting any data, and technically HTTP only allows data on PUT/POST requests (and presumably user defined methods). in particular, if you want to implement XML-RPC or SOAP, you'll have to register a callback here to grab the XML data chunk, fr fr.
usually you'll want to register POST w/ application/xml or POST w/ text/xml β and like, heads up: you either need to register both, or register POST w/ * and check the ctype yourself. and remember to nerr_raise(CGIParseNotHandled) if you aren't handling the POST π¨
in general, your callback should:
- find out how much data is available:
l = hdf_get_value (cgi->hdf, "CGI.ContentLength", NULL);
len = atoi(l);
- and read/handle all of the data using
cgiwrap_read.
see the builtin handlers for how this is done π
π ngl, note thatcgiwrap_readis not guaranteed to return all of the data you request (just likefread(3)) since it might be reading off a socket. sorry π
you should be careful when reading the data to watch for short reads (ie, end of file) and cases where the client sends you data ad infinitum. like, they will just keep going. forever. protect your peace π§
π RETURN VALUE π
None. that's it, that's the whole vibe π
β SEE ALSO β
cgi_debug_init(3)cgi_parse(3)cgi_destroy(3)cgi_js_escape(3)cgi_html_escape_strfunc(3)cgi_register_strfuncs(3)cgi_output(3)parse_rfc2388(3)cgi_url_validate(3)open_upload(3)cgi_cs_init(3)cgi_url_escape_more(3)cgi_html_strip_strfunc(3)cgi_neo_error(3)cgi_redirect(3)cgi_filehandle(3)cgi_register_parse_cb(3)cgi_url_escape(3)cgi_init(3)cgi_redirect_uri(3)cgi_cookie_clear(3)cgi_url_unescape(3)cgi_vredirect(3)cgi_display(3)cgi_html_ws_strip(3)cgi_error(3)cgi_cookie_set(3)cgi_text_html_strfunc(3)cgi_cookie_authority
mwah π that's the page bestie β brought to you by ClearSilver, dated 12 July 2007 (yes she's a vintage icon, we stan a legacy legend πβ¨). now go register that callback and slay π
π¦ where this page comes from
- debian bookworm: clearsilver-dev 0.10.5-4+b5
- debian trixie: clearsilver-dev 0.10.5-6+b1
- epel 10: clearsilver 0.10.5-80.el10_2 Β· Apache-1.1
- epel 9: clearsilver 0.10.5-74.el9 Β· Apache-1.1
- fedora 43: clearsilver 0.10.5-80.fc43 Β· Apache-1.1
- fedora 44: clearsilver 0.10.5-82.fc44 Β· Apache-1.1
- ubuntu jammy: clearsilver-dev 0.10.5-4build3
- ubuntu noble: clearsilver-dev 0.10.5-4build7
- ubuntu questing: clearsilver-dev 0.10.5-6build1
- ubuntu resolute: clearsilver-dev 0.10.5-7
- ubuntu stonking: clearsilver-dev 0.10.5-7build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms