LIBCGI_CGI(3)

πŸ“¦ version 1.0, in fedora 43, fedora 44

✨ 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 message
  • int cgi_include (const char *filename) β€” pulls in static files, periodt
  • void cgi_init_headers () β€” sets up your HTML headers, iconic behaviour
  • char * 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 vibe
  • void cgi_end () β€” does the cgi clean ups so nothing lingers
  • char * cgi_unescape_special_chars (char *str) β€” Transforms' URL special chars back into their real selves
  • char * 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