LIBCGI_CGI(3)
β¨ NAME β¨
CGI manipulation β it's from the Library Functions Manual, bestie, and it's literally the whole toolkit for making your C program talk to the web like a main character. π¦
π Functions π
okay so here's the whole cast list, no cap:
formvars * cgi_process_form ()β handles your HTML form data or your URL data, whichever one shows up πvoid cgi_fatal (const char *msg)β straight up kills the app, but politely, with a messageint cgi_include (const char *filename)β pulls in static files, periodtvoid cgi_init_headers ()β sets up your HTML headers, iconic behaviourchar * cgi_param_multiple (const char *name)β gimme every single value that got sent under the same name, all of them π«Άvoid cgi_redirect (char *url)β Recirects to the specified url (yes, that's the spelling in the source, iykyk π)int cgi_init ()β the main cgi function, the moment, the whole vibevoid cgi_end ()β does the cgi clean ups so nothing lingerschar * cgi_unescape_special_chars (char *str)β Transforms' URL special chars back into their real selveschar * cgi_escape_special_chars (char *str)β Transforms' special characters into hexadecimal form (%E1) πchar * cgi_param (const char *var_name)β Gets the of HTML or URL variable indicated by 'name'void cgi_send_header (const char *header)β Sends a specific header, one at a time, like a queen πΈ
π§ Function Documentation π§
π void cgi_end ()
Performs cgi clean ups. It Provides some methods to clean memory or any other job that need to be done before the end of the application. basically it's the tidy-up-before-you-leave moment, so nothing gets left lying around π
See also: cgi_init
π char* cgi_escape_special_chars (char * str)
Transforms' special characters into hexadecimal form ( %E1 ). the glow-up where your weird lil characters become official hex codes β¨
Parameters:
strβ String to parse
Returns: The new string
See also: cgi_unescape_special_chars
π void cgi_fatal (const char * msg)
Kills the application with a message. Writes msg and terminate. it's giving dramatic exit, but make it informative π
Parameters:
msgβ Message to send to the browser before killing
π int cgi_include (const char * filename)
Include static files. Function used to include static data ( normaly html files ). File contents will never be processed. Note that I don't scan for any special character. The reason I did it is, if the you are using this library, you have a shell where you can compile the cgi program. And can do much more ;-) β so like, it trusts you fr fr π«Ά
Parameters:
filenameβ Filename with full path to include
Returns: If an error occurs and libcgi_debug is true, then a warning message is showed.
See also: libcgi_debug
cgi_include('top_bar.htm');
π int cgi_init ()
Main cgi function. Configures all (most?) we need to get cgi library working correctly. It MUST be called before any other cgi function. no skipping, bestie, it's the first domino π
See also: cgi_end, cgi_process_form, cgi_init_headers
π void cgi_init_headers ()
Initialize HTML headers. You need to call this function before that any content is send to the brosert (yes, the "brosert" β I love them π), otherwise you'll get an error (Error 500). so like, headers first, content second, that's the order periodt
See also: cgi_init
π char* cgi_param (const char * var_name)
Gets the of HTML or URL variable indicated by 'name'.
Parameters:
nameβ Form Variable name
See also: cgi_param_multiple, cgi_process_form, cgi_init
// ...
char *contents;
cgi_init();
cgi_process_form();
cgi_init_headers();
contents = cgi_param('foo');
puts(contents);
// ...
π char* cgi_param_multiple (const char * name)
Return all values with the same name sent by a form. like when your checkbox has siblings and you need every single one π
Parameters:
nameβ Form variable name
Returns: Form variable contents
See also: cgi_param
Example: For example, if in your HTML you have something like
'What do you like??'
Computers : <input type='checkbox' name='like' value='computers'><br>
Internet : <input type='checkbox' name='like' value='net'><br>
games : <input type='checkbox' name='like' 'value='games''><br>
then, to retrieve all values, you can make a code like
// ...
char *data;
\ ...
while ((data = cgi_param_multiple('like')) != NULL)
puts(data);
\ ...
π formvars* cgi_process_form ()
Process HTML form or URL data. Used to retrieve GET or POST data. It handles automaticaly the correct REQUEST_METHOD, so you don't need to afraid about it. (the original really said "don't need to afraid about it" and honestly? mood π)
Returns: Returns the contents of URL or FORM into a formvars variable, or NULL if FALSE. Most of time, you don't need any variable to store the form data, because is used an internal variable to manipulate the contents.
See also: cgi_init, cgi_init_headers
π void cgi_redirect (char * url)
Recirects to the specified url. Remember that you cannot send any header before this function, or it will not work. like, do not test me on this one π¨
Note: LibCGI does not implement RFC 2396 to make the lib simple and quick. You should be sure to pass a correct URI to this function.
Parameters:
urlβ url to redirect the browser
cgi_redirect('http://wwww.linux.org');
π void cgi_send_header (const char * header)
Sends a specific header. Sends a specific HTTP header. You won't need to add '\n\n' chars. she handles that for you, slay π
Parameters:
headerβ HTTP header to send, without new line characteres
Returns: True
See also: cgi_init_headers
π char* cgi_unescape_special_chars (char * str)
Transforms' URL special chars. Search for special chars ( like %E1 ) in str, converting them to the ascii character correspondent. the reverse glow-up, we love a comeback story π¦
Parameters:
strβ String containing data to parse
Returns: The new string
See also: cgi_escape_special_chars
and that's the whole page, bestie π this one's LibCGI, dated 13 Mar 2003, and it ate. now go call cgi_init() first like I told you πβ¨
π¦ where this page comes from
- fedora 43: libcgi-devel 1.0-43.fc43 Β· LicenseRef-Callaway-LGPLv2+
- fedora 43: libcgi-devel 1.0-43.fc43 Β· LicenseRef-Callaway-LGPLv2+
- fedora 44: libcgi-devel 1.0-44.fc44 Β· LicenseRef-Callaway-LGPLv2+
- fedora 44: libcgi-devel 1.0-44.fc44 Β· LicenseRef-Callaway-LGPLv2+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms