c-icap-doc  0.1
Typedefs | Functions
Headers related API


Headers manipulation related API. More...

Typedefs

typedef struct ci_headers_list ci_headers_list_t
 
This is a struct which can store a set of headers. More...
 

Functions

ci_headers_list_tci_headers_create ()
 
Allocate memory for a ci_headers_list_t object and initialize it. More...
 
void ci_headers_destroy (ci_headers_list_t *heads)
 
Destroy a ci_headers_list_t object More...
 
void ci_headers_reset (ci_headers_list_t *heads)
 
Resets and initialize a ci_headers_list_t object More...
 
const char * ci_headers_add (ci_headers_list_t *heads, const char *header)
 
Add a header to a ci_headers_list_t object More...
 
int ci_headers_addheaders (ci_headers_list_t *heads, const ci_headers_list_t *someheaders)
 
Append a headers list object to an other headers list More...
 
int ci_headers_remove (ci_headers_list_t *heads, const char *header)
 
Removes a header from a header list More...
 
const char * ci_headers_search (ci_headers_list_t *heads, const char *header)
 
Search for a header in a header list More...
 
const char * ci_headers_search2 (ci_headers_list_t *h, const char *header, size_t *return_size)
 
Similar to ci_headers_search but also sets to a parameter the size of returned header
 
const char * ci_headers_value (ci_headers_list_t *heads, const char *header)
 
Search for a header in a header list and return the value of the first occurrence of this header More...
 
const char * ci_headers_value2 (ci_headers_list_t *h, const char *header, size_t *return_size)
 
Similar to ci_headers_search but also sets to a parameter the size of returned header value
 
const char * ci_headers_copy_value (ci_headers_list_t *heads, const char *header, char *buf, size_t len)
 
Search for a header in a header list and copy the value to a buffer if exist More...
 
int ci_headers_iterate (ci_headers_list_t *heads, void *data, void(*fn)(void *data, const char *header_name, const char *header_value))
 
Run the given function for each header name/value pair More...
 
size_t ci_headers_pack_to_buffer (ci_headers_list_t *heads, char *buf, size_t size)
 
Copy the headers to a buffer in a form they can be transmitted to the network. More...
 
const char * ci_headers_first_line (ci_headers_list_t *heads)
 
Get the first line of headers More...
 
const char * ci_headers_first_line2 (ci_headers_list_t *heads, size_t *return_size)
 
Get the first line of headers and its size More...
 

Detailed Description


Headers manipulation related API.

Typedef Documentation

◆ ci_headers_list_t


This is a struct which can store a set of headers.

The developers should not touch ci_headers_list_t objects directly but they should use the documented macros and functions

Function Documentation

◆ ci_headers_add()

const char* ci_headers_add ( ci_headers_list_t heads,
const char *  header 
)


Add a header to a ci_headers_list_t object

Parameters
headsis a pointer to the ci_headers_list_t object in which the header will be added
headeris the header to be added
Returns
Pointer to the newly add header on success, NULL otherwise

example usage:

ci_headers_add(heads,"Content-Length: 1025")

◆ ci_headers_addheaders()

int ci_headers_addheaders ( ci_headers_list_t heads,
const ci_headers_list_t someheaders 
)


Append a headers list object to an other headers list

Parameters
headsis a pointer to the ci_headers_list_t object in which the headers will be added
someheadersis a ci_headers_list_t object which contains the headers will be added to the heads
Returns
non zero on success zero otherwise

◆ ci_headers_copy_value()

const char* ci_headers_copy_value ( ci_headers_list_t heads,
const char *  header,
char *  buf,
size_t  len 
)


Search for a header in a header list and copy the value to a buffer if exist

Parameters
headsis a pointer to the ci_headers_list_t object
headeris the name of the header
bufis the buffer to store header value
lenis the size of the buffer buf
Returns
a pointer to the buf on success, NULL otherwise

example usage:

char *headval;
char buf[1024];
int content_length;
headval = ci_headers_copy_value(heads, "Content-Length", buf, sizeof(buf));
if (headval)
printf("Content-Length: %s\n", buf);

◆ ci_headers_create()

ci_headers_list_t* ci_headers_create ( )


Allocate memory for a ci_headers_list_t object and initialize it.

Returns
the allocated object on success, NULL otherwise.

◆ ci_headers_destroy()

void ci_headers_destroy ( ci_headers_list_t heads)


Destroy a ci_headers_list_t object

Parameters
headsis a pointer to the ci_headers_list_t object to be destroyed

◆ ci_headers_first_line()

const char* ci_headers_first_line ( ci_headers_list_t heads)


Get the first line of headers

Parameters
headsis a pointer to the ci_headers_list_t object
Returns
the first line on success, NULL otherwise

◆ ci_headers_first_line2()

const char* ci_headers_first_line2 ( ci_headers_list_t heads,
size_t *  return_size 
)


Get the first line of headers and its size

Parameters
headsis a pointer to the ci_headers_list_t object
return_sizewhere to store the size of first line in bytes
Returns
the first line on success, NULL otherwise

◆ ci_headers_iterate()

int ci_headers_iterate ( ci_headers_list_t heads,
void *  data,
void(*)(void *data, const char *header_name, const char *header_value)  fn 
)


Run the given function for each header name/value pair

Parameters
headsis a pointer to the ci_headers_list_t object
datais a pointer to data which will passed as first argument to the fn function
fnis a pointer to a function which will run for each header name/value pair.
Returns
non zero on success, zero otherwise

◆ ci_headers_pack_to_buffer()

size_t ci_headers_pack_to_buffer ( ci_headers_list_t heads,
char *  buf,
size_t  size 
)


Copy the headers to a buffer in a form they can be transmitted to the network.

WARNING: It produces an non-NULL-terminated string.

Parameters
headsis a pointer to the ci_headers_list_t object
bufthe buffer to store data.
sizethe size of buffer.
Returns
the size of written data, or zero if the headers does not fit to buffer.

◆ ci_headers_remove()

int ci_headers_remove ( ci_headers_list_t heads,
const char *  header 
)


Removes a header from a header list

Parameters
headsis a pointer to the ci_headers_list_t object
headeris the name of the header to be removed
Returns
non zero on success, zero otherwise

example usage:

ci_headers_remove(heads,"Content-Length")

◆ ci_headers_reset()

void ci_headers_reset ( ci_headers_list_t heads)


Resets and initialize a ci_headers_list_t object

Parameters
headspointer to the ci_headers_list_t object to be reset

◆ ci_headers_search()

const char* ci_headers_search ( ci_headers_list_t heads,
const char *  header 
)


Search for a header in a header list

Parameters
headsis a pointer to the ci_headers_list_t object
headeris the name of the header
Returns
a pointer to the start of the first occurrence of the header on success, NULL otherwise

example usage:

char *head;
head = ci_headers_search(heads,"Content-Length")

In this example on success the head pointer will point to a "Content-Lenght: 1025" string

◆ ci_headers_value()

const char* ci_headers_value ( ci_headers_list_t heads,
const char *  header 
)


Search for a header in a header list and return the value of the first occurrence of this header

Parameters
headsis a pointer to the ci_headers_list_t object
headeris the name of the header
Returns
a pointer to the start of the header on success, NULL otherwise

example usage:

char *headval;
int content_length;
headval = ci_headers_value(heads,"Content-Length");
content_length = strtol(headval,NULL,10);