c-icap-doc  0.1
Functions
API for HTTP object manipulation

Macros, functions and structures used for manipulating the encupsulated HTTP objects (HTTP requests or HTTP responses). More...

Functions

ci_headers_list_tci_http_response_headers (ci_request_t *req)
 Returns the HTTP response headers. More...
 
ci_headers_list_tci_http_request_headers (ci_request_t *req)
 Returns the HTTP request headers. More...
 
const char * ci_http_response_add_header (ci_request_t *req, const char *header)
 Add a custom header to the HTTP response headers. More...
 
const char * ci_http_request_add_header (ci_request_t *req, const char *header)
 Add a custom header to the HTTP request headers. More...
 
int ci_http_response_remove_header (ci_request_t *req, const char *header)
 Remove a header from the HTTP response headers. More...
 
int ci_http_request_remove_header (ci_request_t *req, const char *header)
 Remove a header from the HTTP request headers. More...
 
const char * ci_http_response_get_header (ci_request_t *req, const char *head_name)
 Get the value of the requested header from the HTTP response headers. More...
 
const char * ci_http_request_get_header (ci_request_t *req, const char *head_name)
 Get the value of the requested header from the HTTP request headers. More...
 
int ci_http_response_reset_headers (ci_request_t *req)
 Completelly erase and initialize the HTTP response headers. More...
 
int ci_http_request_reset_headers (ci_request_t *req)
 Completelly erase and initialize the HTTP request headers. More...
 
int ci_http_response_create (ci_request_t *req, int has_reshdr, int has_body)
 Creates a new HTTP response. More...
 
int ci_http_request_create (ci_request_t *req, int has_body)
 Creates a new HTTP request. More...
 
ci_off_t ci_http_content_length (ci_request_t *req)
 Returns the value of the Content-Length header of the HTTP response or HTTP request for a response modification or request modification ICAP requests respectively. More...
 
const char * ci_http_request (ci_request_t *req)
 Returns the request line (e.g "GET /index.html HTTP 1.0") from http request headers. More...
 
int ci_http_request_url (ci_request_t *req, char *buf, int buf_size)
 Returns the URL (e.g "http://www.chtsanti.net") from http request. More...
 
const ci_ip_t * ci_http_client_ip (ci_request_t *req)
 Return the http client ip address if this information is available. More...
 

Detailed Description

Macros, functions and structures used for manipulating the encupsulated HTTP objects (HTTP requests or HTTP responses).

Function Documentation

const ci_ip_t* ci_http_client_ip ( ci_request_t req)

Return the http client ip address if this information is available.

Parameters
reqis a pointer to the current ICAP request object.
Returns
A const pointer to a ci_ip_t object contain the client ip address or NULL
ci_off_t ci_http_content_length ( ci_request_t req)

Returns the value of the Content-Length header of the HTTP response or HTTP request for a response modification or request modification ICAP requests respectively.

If the header Content-Length is not included in HTTP response It can be used with both request and response modification ICAP requests.

Parameters
reqis a pointer to the current ICAP request object.
Returns
The content length on success or a negative number otherwise
Examples:
services/echo/srv_echo.c.
const char* ci_http_request ( ci_request_t req)

Returns the request line (e.g "GET /index.html HTTP 1.0") from http request headers.

It can be used with both request and response modification ICAP requests.

Parameters
reqis a pointer to the current ICAP request object.
Returns
The request line in success or NULL otherwise
const char* ci_http_request_add_header ( ci_request_t req,
const char *  header 
)

Add a custom header to the HTTP request headers.

This function can used to add custom headers to the HTTP request and can be used only for request modification ICAP requests

Parameters
reqis a pointer to the current ICAP request object.
headeris a string contains the header in the form "Header: value"
Returns
Pointer to the header or NULL if fails.
int ci_http_request_create ( ci_request_t req,
int  has_body 
)

Creates a new HTTP request.

This function is usefull to develop icap clients

Parameters
reqis a pointer to the current ICAP request object.
has_bodyif it is non zero the HTTP request contains HTTP body data
Returns
non zero on success zero otherwise
const char* ci_http_request_get_header ( ci_request_t req,
const char *  head_name 
)

Get the value of the requested header from the HTTP request headers.

This function can used to get the value of a header from the HTTP request headers. It can be used on both request and response modification ICAP requests.

Parameters
reqis a pointer to the current ICAP request object.
head_nameis a string contains the header name
Returns
A string with the header value on success NULL otherwise
ci_headers_list_t* ci_http_request_headers ( ci_request_t req)

Returns the HTTP request headers.

This function can used for an responce or request modification ICAP request to get the HTTP request headers

Parameters
reqis a pointer to the current ICAP request object.
Returns
Pointer to the HTTP request headers or NULL if fails.
int ci_http_request_remove_header ( ci_request_t req,
const char *  header 
)

Remove a header from the HTTP request headers.

This function can used to remove a header from the HTTP request and can be used only for request modification ICAP requests

Parameters
reqis a pointer to the current ICAP request object.
headeris a string contains the header name
Returns
Non zero if success or zero otherwise
int ci_http_request_reset_headers ( ci_request_t req)

Completelly erase and initialize the HTTP request headers.

This function is usefull when an HTTP request required should replaced by an other.After this function called, the HTTP request should filled with new HTTP headers, before send back to the ICAP client. An example use is to implement an HTTP redirector. It can be used with request modification ICAP requests.

Parameters
reqis a pointer to the current ICAP request object.
Returns
non zero on success zero otherwise
int ci_http_request_url ( ci_request_t req,
char *  buf,
int  buf_size 
)

Returns the URL (e.g "http://www.chtsanti.net") from http request.

It can be used with both request and response modification ICAP requests.

Parameters
reqis a pointer to the current ICAP request object.
bufa buffer to store the url
buf_sizethe "buf" buffer size
Returns
The bytes written to the "buf" buffer
const char* ci_http_response_add_header ( ci_request_t req,
const char *  header 
)

Add a custom header to the HTTP response headers.

This function can used to add custom headers to the HTTP response and can be used only for response modification ICAP requests

Parameters
reqis a pointer to the current ICAP request object.
headeris a string contains the header in the form "Header: value"
Returns
Pointer to the header or NULL if fails.
int ci_http_response_create ( ci_request_t req,
int  has_reshdr,
int  has_body 
)

Creates a new HTTP response.

This function is usefull when the service wants to respond with a self created message to a response or request modification ICAP request. It can be used with both request and response modification ICAP requests.

Parameters
reqis a pointer to the current ICAP request object.
has_reshdrif it is non zero the HTTP response contrains HTTP headers (a non HTTP 0.9 response)
has_bodyif it is non zero the HTTP response contains HTTP body data
Returns
non zero on success zero otherwise
const char* ci_http_response_get_header ( ci_request_t req,
const char *  head_name 
)

Get the value of the requested header from the HTTP response headers.

This function can used to get the value of a header from the HTTP response headers. It can be used only for response modification ICAP requests

Parameters
reqis a pointer to the current ICAP request object.
head_nameis a string contains the header name
Returns
A string with the header value on success NULL otherwise
ci_headers_list_t* ci_http_response_headers ( ci_request_t req)

Returns the HTTP response headers.

This function is only valid for an ICAP responce modification request. If the ICAP request is not responce modification ICAP request or there are not response headers (HTTP 0.9) the function returns NULL.

Parameters
reqA pointer to the current ICAP request object.
Returns
Pointer to the HTTP response headers or NULL.
int ci_http_response_remove_header ( ci_request_t req,
const char *  header 
)

Remove a header from the HTTP response headers.

This function can used to remove a header from the HTTP response and can be used only for response modification ICAP requests

Parameters
reqis a pointer to the current ICAP request object.
headeris a string contains the header name
Returns
Non zero if success or zero otherwise
int ci_http_response_reset_headers ( ci_request_t req)

Completelly erase and initialize the HTTP response headers.

This function is usefull when the full rewrite of the HTTP response is required. After this function called, the HTTP response should be filled with new HTTP headers, before send back to the ICAP client. An example of usage of this function is in antivirus service when a virus detected in HTTP response, so the service blocks the response and sends a new HTTP object (a new html page, with HTTP headers) informing the user about the virus. It can be used with response modification ICAP requests.

Parameters
reqis a pointer to the current ICAP request object.
Returns
non zero on success zero otherwise