libonion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Enumerations | Functions | Variables
Request. Access all information from client request: path, GET, POST, cookies, session...

Data Structures

struct  onion_request_t
 Basic information about a request. More...

Enumerations

enum  onion_request_flags_e {
  OR_METHODS = 0x0F, OR_GET = 0, OR_POST = 1, OR_HEAD = 2,
  OR_OPTIONS = 3, OR_PROPFIND = 4, OR_PUT = 5, OR_DELETE = 6,
  OR_MOVE = 7, OR_MKCOL = 8, OR_PROPPATCH = 9, OR_PATCH = 10,
  OR_HTTP11 = 0x10, OR_POST_MULTIPART = 0x20, OR_POST_URLENCODED = 0x40, OR_NO_KEEP_ALIVE = 0x0100,
  OR_HEADER_SENT_ = 0x0200, OR_INTERNAL_ERROR = 0x01000, OR_NOT_IMPLEMENTED = 0x02000, OR_NOT_FOUND = 0x03000,
  OR_FORBIDDEN = 0x04000
}
 Flags about the petition, including method, error status, http version. More...

Functions

onion_requestonion_request_new_from_socket (onion_listen_point *con, int fd, struct sockaddr_storage *cli_addr, socklen_t cli_len)
onion_connection_status onion_request_process (onion_request *req)
 Launches one handler for the given requestOnce the request is ready, launch it.
bool onion_request_is_secure (onion_request *req)
 Determine if the request was sent over a secure listen point.
onion_requestonion_request_t::onion_request_new (onion_listen_point *op)
 Creates a request object.
static void onion_request_t::unlink_files (void *p, const char *key, const char *value, int flags)
 Helper to remove temporal files from req->files.
void onion_request_t::onion_request_free (onion_request *req)
 Deletes a request and all its data.
void onion_request_t::onion_request_clean (onion_request *req)
 Cleans a request object to reuse it.
const char * onion_request_t::onion_request_get_path (onion_request *req)
 Returns a pointer to the string with the current path. Its a const and should not be trusted for long time.
const char * onion_request_t::onion_request_get_fullpath (onion_request *req)
 Returns a pointer to the string with the full path. Its a const and should not be trusted for long time.
onion_request_flags onion_request_t::onion_request_get_flags (onion_request *req)
 Gets the current flags, as in onion_request_flags_e.
void onion_request_t::onion_request_advance_path (onion_request *req, off_t addtopos)
 Moves the pointer inside fullpath to this new position, relative to current path.
const char * onion_request_t::onion_request_get_header (onion_request *req, const char *header)
 Gets a header data.
const char * onion_request_t::onion_request_get_query (onion_request *req, const char *query)
 Gets a query data.
const char * onion_request_t::onion_request_get_queryd (onion_request *req, const char *key, const char *def)
 Gets a query data, but has a default value if the key is not there.
const char * onion_request_t::onion_request_get_post (onion_request *req, const char *query)
 Gets a post data.
const char * onion_request_t::onion_request_get_file (onion_request *req, const char *query)
 Gets file data.
const char * onion_request_t::onion_request_get_session (onion_request *req, const char *key)
 Gets session data.
const onion_dictonion_request_t::onion_request_get_header_dict (onion_request *req)
 Gets the header header data dict.
const onion_dictonion_request_t::onion_request_get_query_dict (onion_request *req)
 Gets request query dict.
const onion_dictonion_request_t::onion_request_get_post_dict (onion_request *req)
 Gets post data dict.
const onion_dictonion_request_t::onion_request_get_file_dict (onion_request *req)
 Gets files data dict.
void onion_request_t::onion_request_guess_session_id (onion_request *req)
 Gets the sessionid cookie, if any, and sets it to req->session_id.
onion_dictonion_request_t::onion_request_get_session_dict (onion_request *req)
 Returns the session dict.
void onion_request_t::onion_request_set_no_keep_alive (onion_request *req)
 Forces the request to process only one request, not doing the keep alive.
int onion_request_t::onion_request_keep_alive (onion_request *req)
 Returns if current request wants to keep alive.
void onion_request_t::onion_request_session_free (onion_request *req)
 Frees the session dictionary.
const char * onion_request_t::onion_request_get_language_code (onion_request *req)
 Returns the language code of the current request.
const onion_blockonion_request_t::onion_request_get_data (onion_request *req)
 Some extra data, normally when the petition is propfind or POST with non-form data.
void onion_request_t::onion_request_polish (onion_request *req)
 Performs the final touches do the request is ready to be handled.
const char * onion_request_t::onion_request_get_client_description (onion_request *req)
 Returns a string with the client's description.
struct sockaddr_storage * onion_request_t::onion_request_get_sockadd_storage (onion_request *req, socklen_t *client_len)
 Returns the sockaddr_storage pointer to the data client data as stored here.
onion_dictonion_request_t::onion_request_get_cookies_dict (onion_request *req)
 Gets the dict with the cookies.
const char * onion_request_t::onion_request_get_cookie (onion_request *req, const char *cookiename)
 Gets a Cookie value by name.

Variables

const char * onion_request_t::onion_request_methods [16]

Detailed Description

Enumeration Type Documentation

Flags about the petition, including method, error status, http version.

Enumerator:
OR_METHODS 

First 4 bytes are the method. Then as flags.

OR_GET 
OR_POST 
OR_HEAD 
OR_OPTIONS 
OR_PROPFIND 
OR_PUT 
OR_DELETE 
OR_MOVE 
OR_MKCOL 
OR_PROPPATCH 
OR_PATCH 
OR_HTTP11 

Some flags at 0x0F0.

OR_POST_MULTIPART 
OR_POST_URLENCODED 
OR_NO_KEEP_ALIVE 

Server flags are at 0x0F00.

OR_HEADER_SENT_ 

Dup name from onion_response_flags, same meaning.

OR_INTERNAL_ERROR 

Errors at 0x0F000.

OR_NOT_IMPLEMENTED 
OR_NOT_FOUND 
OR_FORBIDDEN 

Function Documentation

void onion_request_advance_path ( onion_request req,
off_t  addtopos 
)

Moves the pointer inside fullpath to this new position, relative to current path.

References onion_request_t::fullpath, and onion_request_t::path.

Referenced by onion_handler_path_handler(), and onion_url_handler().

void onion_request_clean ( onion_request req)
void onion_request_free ( onion_request req)
const char * onion_request_get_client_description ( onion_request req)

Returns a string with the client's description.

Returns
A const char * with the client description

References onion_request_t::cli_addr, onion_request_t::cli_info, onion_request_t::cli_len, onion_request_t::connection, and onion_low_strdup().

Referenced by onion_response_t::onion_response_free().

const char * onion_request_get_cookie ( onion_request req,
const char *  cookiename 
)

Gets a Cookie value by name.

Parameters
reqReqeust to get the cookie from
cookienameName of the cookie
Returns
The cookie value, or NULL

References onion_dict_t::onion_dict_get(), and onion_request_t::onion_request_get_cookies_dict().

onion_dict * onion_request_get_cookies_dict ( onion_request req)

Gets the dict with the cookies.

Parameters
reqRequest to get the cookies from
Returns
A dict with all the cookies. It might be empty.

First call it generates the dict.

Can use as static data as will be freed at first cookie free

References onion_request_t::cookies, OD_FREE_KEY, ONION_DEBUG0, onion_dict_t::onion_dict_add(), onion_dict_t::onion_dict_new(), onion_low_strdup(), and onion_request_t::onion_request_get_header().

Referenced by onion_request_t::onion_request_get_cookie().

const onion_block * onion_request_get_data ( onion_request req)

Some extra data, normally when the petition is propfind or POST with non-form data.

References onion_request_t::data.

Referenced by onion_webdav_handler(), onion_webdav_propfind(), onion_webdav_proppatch(), and onion_webdav_put().

const char * onion_request_get_file ( onion_request req,
const char *  query 
)

Gets file data.

References onion_request_t::FILES, and onion_dict_t::onion_dict_get().

const onion_dict * onion_request_get_file_dict ( onion_request req)

Gets files data dict.

References onion_request_t::FILES.

onion_request_flags onion_request_get_flags ( onion_request req)

Gets the current flags, as in onion_request_flags_e.

References onion_request_t::flags.

Referenced by onion_shortcut_response_file(), and onion_webdav_handler().

const char * onion_request_get_fullpath ( onion_request req)

Returns a pointer to the string with the full path. Its a const and should not be trusted for long time.

References onion_request_t::fullpath.

Referenced by onion_webdav_move(), and onion_webdav_propfind().

const char * onion_request_get_header ( onion_request req,
const char *  header 
)
const onion_dict * onion_request_get_header_dict ( onion_request req)

Gets the header header data dict.

References onion_request_t::headers.

const char * onion_request_get_language_code ( onion_request req)

Returns the language code of the current request.

Returns the language code for the current request, from the header. If none the returns "C".

Language code is short code. No localization by the moment.

Returns
The language code for this request or C. Data must be freed.

References onion_request_t::headers, onion_dict_t::onion_dict_get(), and onion_low_strdup().

const char * onion_request_get_path ( onion_request req)

Returns a pointer to the string with the current path. Its a const and should not be trusted for long time.

References onion_request_t::path.

Referenced by onion_handler_export_local_handler(), onion_handler_opack_handler(), onion_handler_path_handler(), onion_url_handler(), onion_webdav_handler(), onion_webdav_move(), and onion_webdav_propfind().

const char * onion_request_get_post ( onion_request req,
const char *  query 
)

Gets a post data.

References onion_dict_t::onion_dict_get(), and onion_request_t::POST.

const onion_dict * onion_request_get_post_dict ( onion_request req)

Gets post data dict.

References onion_request_t::POST.

const char * onion_request_get_query ( onion_request req,
const char *  query 
)
const onion_dict * onion_request_get_query_dict ( onion_request req)

Gets request query dict.

References onion_request_t::GET.

const char * onion_request_get_queryd ( onion_request req,
const char *  key,
const char *  def 
)

Gets a query data, but has a default value if the key is not there.

References onion_request_t::onion_request_get_query().

const char * onion_request_get_session ( onion_request req,
const char *  key 
)
onion_dict * onion_request_get_session_dict ( onion_request req)

Returns the session dict.

If it does not exists it creates it. If there is a cookie with a proper name it is used, even for creation.

Sessions HAVE TO be gotten before sending any header, or user may face double sessionid, ghost sessions and some other artifacts, as the cookie is not set if session is not used. If this condition happen (send headers and then ask for session) a WARNING is written.

Session is not automatically retrieved as it is a slow operation and not used normally, only on "active" handlers.

Returned dictionary can be freely managed (added new keys...) and this is the session data.

Returns
session dictionary for current request.

References onion_request_t::connection, onion_request_t::flags, onion_request_t::listen_point, onion_request_t::onion_request_guess_session_id(), onion_sessions_t::onion_sessions_create(), onion_sessions_t::onion_sessions_get(), ONION_WARNING, OR_HEADER_SENT, onion_listen_point_t::server, onion_request_t::session, onion_request_t::session_id, and onion_t::sessions.

Referenced by onion_handler_auth_pam_handler(), and onion_request_t::onion_request_get_session().

struct sockaddr_storage * onion_request_get_sockadd_storage ( onion_request req,
socklen_t *  client_len 
)
read

Returns the sockaddr_storage pointer to the data client data as stored here.

Parameters
reqRequest to get data from
client_lenThe lenght of the returned sockaddr_storage
Returns
Pointer to the stored sockaddr_storage.

References onion_request_t::cli_addr, onion_request_t::cli_len, and onion_request_t::connection.

void onion_request_guess_session_id ( onion_request req)
bool onion_request_is_secure ( onion_request req)

Determine if the request was sent over a secure listen point.

References onion_request_t::connection, onion_request_t::listen_point, and onion_listen_point_t::secure.

int onion_request_keep_alive ( onion_request req)

Returns if current request wants to keep alive.

It is a complex set of circumstances: HTTP/1.1 and no connection: close, or HTTP/1.0 and connection: keep-alive and no explicit set that no keep alive.

References onion_request_t::flags, onion_request_t::onion_request_get_header(), OR_HTTP11, and OR_NO_KEEP_ALIVE.

Referenced by onion_response_t::onion_response_free(), and onion_response_t::onion_response_write_headers().

onion_request * onion_request_new ( onion_listen_point op)
onion_request* onion_request_new_from_socket ( onion_listen_point con,
int  fd,
struct sockaddr_storage *  cli_addr,
socklen_t  cli_len 
)
void onion_request_polish ( onion_request req)

Performs the final touches do the request is ready to be handled.

After parsing the request, some final touches are needed to set the current path.

Parameters
reqThe request.

References onion_request_t::fullpath, and onion_request_t::path.

Referenced by onion_request_process().

onion_connection_status onion_request_process ( onion_request req)
void onion_request_session_free ( onion_request req)

Frees the session dictionary.

It removes the session from the sessions dictionary, so this session does not exist anymore.

If data is under onion_dict scope (just dicts into dicts and strings), all data is freed. If the user has set some custom data, THAT MEMORY IS LEAKED.

References onion_request_t::connection, onion_request_t::listen_point, ONION_DEBUG, onion_dict_t::onion_dict_free(), onion_low_free(), onion_request_t::onion_request_guess_session_id(), onion_sessions_t::onion_sessions_remove(), onion_listen_point_t::server, onion_request_t::session, onion_request_t::session_id, and onion_t::sessions.

Referenced by onion_request_t::onion_request_clean(), and onion_request_t::onion_request_free().

void onion_request_set_no_keep_alive ( onion_request req)

Forces the request to process only one request, not doing the keep alive.

This is useful on non threaded modes, as the keep alive blocks the loop.

References onion_request_t::flags, and OR_NO_KEEP_ALIVE.

Referenced by onion_listen().

static void unlink_files ( void *  p,
const char *  key,
const char *  value,
int  flags 
)

Helper to remove temporal files from req->files.

References ONION_DEBUG0.

Referenced by onion_request_t::onion_request_clean(), and onion_request_t::onion_request_free().

Variable Documentation

const char* onion_request_methods[16]
Initial value:
{
"GET", "POST", "HEAD", "OPTIONS",
"PROPFIND", "PUT", "DELETE", "MOVE",
"MKCOL", "PROPPATCH", "PATCH", NULL,
NULL, NULL, NULL, NULL }

These are the methods allowed to ask data to the server (or push or whatever). Only 16.

NULL means this space is vacant.

They are in order of probability, with GET the most common.

Referenced by onion_response_t::onion_response_free().