---
name: "libcgi_cgi"
section: "3"
platform: "linux"
package: "libcgi-dev"
version: "1.0-6"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/libcgi_cgi"
---

# libcgi\_cgi(3)

## NAME

CGI manipulation -

### Functions

formvars \* **cgi\_process\_form** ()\
 *Process HTML form or URL data.* void **cgi\_fatal** (const char \*msg)\
 *Kills the application with a message.* int **cgi\_include** (const char \*filename)\
 *Include static files.* void **cgi\_init\_headers** ()\
 *Initialize HTML headers.* char \* **cgi\_param\_multiple** (const char \*name)\
 *Return all values with the same name sent by a form.* void **cgi\_redirect** (char \*url)\
 *Recirects to the specified url.* int **cgi\_init** ()\
 *Main cgi function.* void **cgi\_end** ()\
 *Performs cgi clean ups.* char \* **cgi\_unescape\_special\_chars** (char \*str)\
 *Transforms' URL special chars.* 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.*

## Function Documentation

### void cgi\_end ()

Performs cgi clean ups.Provides some methods to clean memory or any other job that need to be done before the end of the application.

**See also:**

**cgi\_init**

### char\* cgi\_escape\_special\_chars (char \* str)

Transforms' special characters into hexadecimal form ( %E1 ).**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

**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 ;-)

**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.

**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, otherwise you'll get an error (Error 500).

**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.**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.

**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. **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.

**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.

**Parameters:**

*str* String containing data to parse

**Returns:**

The new string

**See also:**

**cgi\_escape\_special\_chars**
