Ulfius
HTTP Framework for REST Applications in C
Functions
struct _u_request, struct _u_response and struct _u_cookie

Functions

int ulfius_init_request (struct _u_request *request)
 
int ulfius_clean_request (struct _u_request *request)
 
int ulfius_clean_request_full (struct _u_request *request)
 
int ulfius_copy_request (struct _u_request *dest, const struct _u_request *source)
 
int ulfius_set_request_properties (struct _u_request *request,...)
 
struct _u_requestulfius_duplicate_request (const struct _u_request *request)
 
char * ulfius_export_request_http (const struct _u_request *request)
 
int ulfius_init_response (struct _u_response *response)
 
int ulfius_clean_response (struct _u_response *response)
 
int ulfius_clean_response_full (struct _u_response *response)
 
int ulfius_copy_response (struct _u_response *dest, const struct _u_response *source)
 
int ulfius_clean_cookie (struct _u_cookie *cookie)
 
int ulfius_copy_cookie (struct _u_cookie *dest, const struct _u_cookie *source)
 
struct _u_responseulfius_duplicate_response (const struct _u_response *response)
 
int ulfius_set_response_properties (struct _u_response *response,...)
 
int ulfius_set_response_shared_data (struct _u_response *response, void *shared_data, void(*free_shared_data)(void *shared_data))
 
char * ulfius_export_response_http (const struct _u_response *response)
 
json_t * ulfius_get_json_body_request (const struct _u_request *request, json_error_t *json_error)
 
int ulfius_set_json_body_request (struct _u_request *request, json_t *j_body)
 
json_t * ulfius_get_json_body_response (struct _u_response *response, json_error_t *json_error)
 
int ulfius_set_json_body_response (struct _u_response *response, const unsigned int status, const json_t *j_body)
 

Detailed Description

struct _u_request, struct _u_response and struct _u_cookie management functions

Function Documentation

◆ ulfius_init_request()

int ulfius_init_request ( struct _u_request request)

ulfius_init_request Initialize a request structure by allocating inner elements

Parameters
requestthe request to initialize
Returns
U_OK on success

ulfius_init_request Initialize a request structure by allocating inner elements return U_OK on success

◆ ulfius_clean_request()

int ulfius_clean_request ( struct _u_request request)

ulfius_clean_request clean the specified request's inner elements user must free the parent pointer if needed after clean or use ulfius_clean_request_full

Parameters
requestthe request to cleanup
Returns
U_OK on success

ulfius_clean_request clean the specified request's inner elements user must free the parent pointer if needed after clean or use ulfius_clean_request_full return U_OK on success

◆ ulfius_clean_request_full()

int ulfius_clean_request_full ( struct _u_request request)

ulfius_clean_request_full clean the specified request and all its elements

Parameters
requestthe request to cleanup
Returns
U_OK on success

ulfius_clean_request_full clean the specified request and all its elements return U_OK on success

◆ ulfius_copy_request()

int ulfius_copy_request ( struct _u_request dest,
const struct _u_request source 
)

ulfius_copy_request Copy the source request elements into the dest request

Parameters
destthe request to receive the copied data
sourcethe source request to copy
Returns
U_OK on success

ulfius_copy_request Copy the source request elements into the dest request return U_OK on success

◆ ulfius_set_request_properties()

int ulfius_set_request_properties ( struct _u_request request,
  ... 
)

ulfius_set_request_properties Set a list of properties to a request return U_OK on success

◆ ulfius_duplicate_request()

struct _u_request* ulfius_duplicate_request ( const struct _u_request request)

create a new request based on the source elements returned value must be u_free'd after use

Parameters
requestthe request to duplicate
Returns
a heap-allocated request

create a new request based on the source elements returned value must be free'd after use

◆ ulfius_export_request_http()

char* ulfius_export_request_http ( const struct _u_request request)

Exports a struct _u_request * into a readable HTTP request This function is for debug or educational purpose And the output is probably incomplete for some edge cases So don't think this is the right way. Example:
PUT /api/write HTTP/1.1
Host: domain.tld
Accept: gzip
Content-Type: application/x-www-form-urlencoded
Content-length: 432

key1=value1&key2=value2[...]

Parameters
requestthe request to export returned value must be u_free'd after use

◆ ulfius_init_response()

int ulfius_init_response ( struct _u_response response)

Initialize a response structure by allocating inner elements

Parameters
responsethe response to initialize
Returns
U_OK on success

◆ ulfius_clean_response()

int ulfius_clean_response ( struct _u_response response)

ulfius_clean_response clean the specified response's inner elements user must free the parent pointer if needed after clean or use ulfius_clean_response_full

Parameters
responsethe response to cleanup
Returns
U_OK on success

◆ ulfius_clean_response_full()

int ulfius_clean_response_full ( struct _u_response response)

clean the specified response and all its elements

Parameters
responsethe response to cleanup
Returns
U_OK on success

◆ ulfius_copy_response()

int ulfius_copy_response ( struct _u_response dest,
const struct _u_response source 
)

Copy the source response elements into the dest response

Parameters
destthe response to receive the copied data
sourcethe source response to copy
Returns
U_OK on success

◆ ulfius_clean_cookie()

int ulfius_clean_cookie ( struct _u_cookie cookie)

ulfius_clean_cookie clean the cookie's elements

Parameters
cookiethe cookie structure to cleanup
Returns
U_OK on success

◆ ulfius_copy_cookie()

int ulfius_copy_cookie ( struct _u_cookie dest,
const struct _u_cookie source 
)

Copy the cookie source elements into dest elements

Parameters
destthe cookie to receive the copied data
sourcethe cookie response to copy
Returns
U_OK on success

◆ ulfius_duplicate_response()

struct _u_response* ulfius_duplicate_response ( const struct _u_response response)

create a new response based on the source elements return value must be cleaned after use

Parameters
responsethe response to duplicate
Returns
a heap-allocated response

◆ ulfius_set_response_properties()

int ulfius_set_response_properties ( struct _u_response response,
  ... 
)

Set a list of properties to a response

Parameters
responsethe response to set values to
Returns
U_OK on success

◆ ulfius_set_response_shared_data()

int ulfius_set_response_shared_data ( struct _u_response response,
void *  shared_data,
void(*)(void *shared_data)  free_shared_data 
)

Adds a shared_data pointer to the response and the function to free the shared_data at the end of the callback list

Parameters
responsethe response to set values to
shared_dataa pointer that will be transmitted to every callback
free_shared_dataa pointer to a function that will free shared_data at the end of the callback list
Returns
U_OK on success

◆ ulfius_export_response_http()

char* ulfius_export_response_http ( const struct _u_response response)

Exports a struct _u_response * into a readable HTTP response This function is for debug or educational purpose And the output is probably incomplete for some edge cases So don't think this is the right way. Example:
HTTP/1.1 200 OK
Content-type: text/html; charset=utf-8
Set-Cookie: cookieXyz1234...
Content-length: 1234

<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h2>Welcome</h2>
....

Parameters
responsethe response to export returned value must be u_free'd after use

◆ ulfius_get_json_body_request()

json_t* ulfius_get_json_body_request ( const struct _u_request request,
json_error_t *  json_error 
)

ulfius_get_json_body_request Get JSON structure from the request body if the request is valid In case of an error in getting or parsing JSON data in the request, the structure json_error_t * json_error will be filled with an error message if json_error is not NULL

Parameters
requestthe request to retrieve the JSON data
json_errora json_error_t reference that will contain decoding errors if any, may be NULL
Returns
a json_t * containing the JSON decoded, NULL on error

ulfius_get_json_body_request Get JSON structure from the request body if the request is valid request: struct _u_request used json_error: structure to store json_error_t if specified

◆ ulfius_set_json_body_request()

int ulfius_set_json_body_request ( struct _u_request request,
json_t *  j_body 
)

ulfius_set_json_body_request Add a json_t j_body to a request

Parameters
requestthe request to retrieve the JSON data
j_bodya json_t to stringify in the body
Returns
U_OK on success

ulfius_set_json_body_request Add a json_t j_body to a response return U_OK on success

◆ ulfius_get_json_body_response()

json_t* ulfius_get_json_body_response ( struct _u_response response,
json_error_t *  json_error 
)

ulfius_get_json_body_response Get JSON structure from the response body if the response is valid In case of an error in getting or parsing JSON data in the response, the structure json_error_t * json_error will be filled with an error message if json_error is not NULL

Parameters
responsethe response to retrieve the JSON data
json_errora json_error_t reference that will contain decoding errors if any, may be NULL
Returns
a json_t * containing the JSON decoded, NULL on error

ulfius_get_json_body_response Get JSON structure from the request body if the request is valid request: struct _u_request used json_error: structure to store json_error_t if specified

◆ ulfius_set_json_body_response()

int ulfius_set_json_body_response ( struct _u_response response,
const unsigned int  status,
const json_t *  j_body 
)

ulfius_set_json_body_response Add a json_t j_body to a response

Parameters
responsethe response to retrieve the JSON data
statusthe HTTP status for the response
j_bodya json_t to stringify in the body
Returns
U_OK on success

ulfius_set_json_body_response Add a json_t j_body to a response return U_OK on success