libonion
|
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_request * | onion_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_request * | onion_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_dict * | onion_request_t::onion_request_get_header_dict (onion_request *req) |
Gets the header header data dict. | |
const onion_dict * | onion_request_t::onion_request_get_query_dict (onion_request *req) |
Gets request query dict. | |
const onion_dict * | onion_request_t::onion_request_get_post_dict (onion_request *req) |
Gets post data dict. | |
const onion_dict * | onion_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_dict * | onion_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_block * | onion_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_dict * | onion_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] |
Flags about the petition, including method, error status, http version.
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 | ) |
Cleans a request object to reuse it.
References onion_request_t::cli_info, onion_request_t::connection, onion_request_t::cookies, onion_request_t::data, onion_request_t::FILES, onion_request_t::flags, onion_request_t::free_list, onion_request_t::fullpath, onion_request_t::GET, onion_request_t::headers, onion_request_t::listen_point, OD_ICASE, onion_block_t::onion_block_free(), ONION_DEBUG0, onion_dict_t::onion_dict_count(), onion_dict_t::onion_dict_free(), onion_dict_t::onion_dict_new(), onion_dict_t::onion_dict_preorder(), onion_dict_t::onion_dict_set_flags(), onion_low_free(), onion_ptr_list_foreach(), onion_ptr_list_free(), onion_request_parser_data_free(), onion_request_t::onion_request_session_free(), onion_sessions_save(), OR_NO_KEEP_ALIVE, onion_request_t::parser_data, onion_request_t::path, onion_request_t::POST, onion_listen_point_t::server, onion_request_t::session, onion_request_t::session_id, onion_t::sessions, and onion_request_t::unlink_files().
Referenced by onion_request_process().
void onion_request_free | ( | onion_request * | req | ) |
Deletes a request and all its data.
References onion_request_t::cli_info, onion_listen_point_t::close, onion_request_t::connection, onion_request_t::cookies, onion_request_t::data, onion_request_t::FILES, onion_request_t::free_list, onion_request_t::fullpath, onion_request_t::GET, onion_request_t::headers, onion_request_t::listen_point, onion_block_t::onion_block_free(), ONION_DEBUG0, onion_dict_t::onion_dict_count(), onion_dict_t::onion_dict_free(), onion_dict_t::onion_dict_preorder(), onion_low_free(), onion_ptr_list_foreach(), onion_ptr_list_free(), onion_request_parser_data_free(), onion_request_t::onion_request_session_free(), onion_sessions_save(), onion_websocket_t::onion_websocket_free(), onion_request_t::parser_data, onion_request_t::POST, onion_listen_point_t::server, onion_request_t::session, onion_request_t::session_id, onion_t::sessions, onion_request_t::unlink_files(), and onion_request_t::websocket.
Referenced by onion_listen(), onion_listen_point_t::onion_listen_point_accept(), and onion_request_t::onion_request_new().
const char * onion_request_get_client_description | ( | onion_request * | req | ) |
Returns a string with the client's 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.
req | Reqeust to get the cookie from |
cookiename | Name of the cookie |
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.
req | Request to get the cookies from |
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 | ||
) |
Gets a header data.
References onion_request_t::headers, and onion_dict_t::onion_dict_get().
Referenced by onion_handler_auth_pam_handler(), onion_request_t::onion_request_get_cookies_dict(), onion_request_t::onion_request_keep_alive(), onion_shortcut_response_file(), onion_webdav_move(), onion_webdav_propfind(), and onion_websocket_t::onion_websocket_new().
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.
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 | ||
) |
Gets a query data.
References onion_request_t::GET, and onion_dict_t::onion_dict_get().
Referenced by onion_request_t::onion_request_get_queryd().
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 | ||
) |
Gets session data.
References onion_dict_t::onion_dict_get(), and onion_request_t::onion_request_get_session_dict().
Referenced by onion_handler_auth_pam_handler().
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.
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().
|
read |
Returns the sockaddr_storage pointer to the data client data as stored here.
req | Request to get data from |
client_len | The lenght of the returned 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 | ) |
Gets the sessionid cookie, if any, and sets it to req->session_id.
References onion_request_t::connection, onion_request_t::headers, onion_request_t::listen_point, ONION_DEBUG, ONION_DEBUG0, onion_dict_t::onion_dict_get(), onion_low_free(), onion_low_strdup(), onion_sessions_t::onion_sessions_get(), 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_get_session_dict(), and onion_request_t::onion_request_session_free().
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 | ) |
Creates a request object.
op | Listen point this request is listening to, to be able to read and write data |
References onion_request_t::connection, onion_request_t::fd, onion_request_t::headers, onion_request_t::listen_point, OD_ICASE, ONION_DEBUG, ONION_DEBUG0, onion_dict_t::onion_dict_new(), onion_dict_t::onion_dict_set_flags(), onion_listen_point_t::onion_listen_point_request_init_from_socket(), onion_low_calloc(), onion_request_t::onion_request_free(), and onion_listen_point_t::request_init.
Referenced by onion_listen(), onion_listen_point_t::onion_listen_point_accept(), and onion_request_new_from_socket().
onion_request* onion_request_new_from_socket | ( | onion_listen_point * | con, |
int | fd, | ||
struct sockaddr_storage * | cli_addr, | ||
socklen_t | cli_len | ||
) |
Creates a request, with socket info.
References onion_request_t::cli_addr, onion_request_t::cli_len, onion_request_t::connection, onion_request_t::fd, and onion_request_t::onion_request_new().
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.
req | The 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 | ) |
Launches one handler for the given requestOnce the request is ready, launch it.
Executes the handler required for this request.
References onion_request_t::connection, onion_request_t::fd, onion_request_t::flags, onion_t::internal_error_handler, onion_request_t::listen_point, OCS_FORBIDDEN, OCS_INTERNAL_ERROR, OCS_KEEP_ALIVE, OCS_NOT_IMPLEMENTED, OCS_NOT_PROCESSED, OCS_YIELD, onion_get_poller(), onion_handler_t::onion_handler_handle(), onion_poller_get(), onion_poller_slot_t::onion_poller_slot_set_shutdown(), onion_request_t::onion_request_clean(), onion_request_t::onion_request_polish(), onion_response_t::onion_response_free(), onion_response_t::onion_response_new(), OR_FORBIDDEN, OR_INTERNAL_ERROR, OR_NOT_FOUND, OR_NOT_IMPLEMENTED, onion_request_t::path, onion_t::root_handler, and onion_listen_point_t::server.
Referenced by onion_http_t::onion_http_read_ready().
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().
const char* onion_request_methods[16] |
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().