libonion
|
Stored common data for each listen point: address, port, protocol status data... More...
#include <types.h>
Public Member Functions | |
onion_listen_point * | onion_listen_point_new () |
Creates an empty listen point. | |
void | onion_listen_point_free (onion_listen_point *op) |
Free and closes the listen point. | |
int | onion_listen_point_accept (onion_listen_point *op) |
Called when a new connection appears on the listenfd. | |
void | onion_listen_point_listen_stop (onion_listen_point *op) |
Stops listening the listen point. | |
int | onion_listen_point_listen (onion_listen_point *op) |
Starts the listening phase for this listen point for sockets. | |
static int | onion_listen_point_read_ready (onion_request *req) |
This listen point has data ready to read; calls the listen_point read_ready. | |
int | onion_listen_point_request_init_from_socket (onion_request *req) |
Default implementation that initializes the request from a socket. | |
void | onion_listen_point_request_close_socket (onion_request *oc) |
Default implementation that just closes the connection. |
Data Fields | |
onion * | server |
Onion server. | |
char * | hostname |
Stated hostname, as a string. If NULL tries to attach to any hostname, normally 0.0.0.0 (ipv4 and ipv6) | |
char * | port |
Stated port, if none then 8080. | |
int | listenfd |
For socket listening listen points, the listen fd. For others may be -1 as not used, or an fd to watch and when changed calls the request_init with a new request. | |
bool | secure |
Is this listen point secure? | |
void * | user_data |
Internal data used by the listen point, for example in HTTPS is the certificate loaded data. | |
void(* | free_user_data )(onion_listen_point *lp) |
Method to call to free the user data. | |
void(* | listen )(onion_listen_point *lp) |
How to start the listening phase. | |
void(* | listen_stop )(onion_listen_point *lp) |
Frees internal data and state of listen point, but not listen point itself. | |
To be used by requests, but as these methods are shared by protocol, done here. | |
int(* | request_init )(onion_request *req) |
Initialize the request object. Data is already malloc'd but specific listen protocols may need custom data. | |
int(* | read_ready )(onion_request *req) |
When poller detects data is ready to be read. Might be diferent in diferent parts of the processing. | |
ssize_t(* | write )(onion_request *req, const char *data, size_t len) |
Write data to the given request. | |
ssize_t(* | read )(onion_request *req, char *data, size_t len) |
Read data from the given request and write it in data. | |
void(* | close )(onion_request *req) |
Stored common data for each listen point: address, port, protocol status data...
Stored information about the listen points; where they are listenting, and how to handle a new connection. Each listen point can understand a protocol and associated data.
A protocol is HTTP, HTTPS, SPDY... each may do the request parsing in adiferent way, and the response write too.
A listen point A can be HTTPS with one certificate, and B with another, with C using SPDY.
void(* onion_listen_point_t::close)(onion_request *req) |
Closes the connection and frees listen point user data. Request itself it left. It is called from onion_request_free ONLY.
Referenced by onion_http_t::onion_http_new(), onion_https_t::onion_https_new(), and onion_request_t::onion_request_free().
void(* onion_listen_point_t::free_user_data)(onion_listen_point *lp) |
Method to call to free the user data.
Referenced by onion_https_t::onion_https_new(), and onion_listen_point_free().
char* onion_listen_point_t::hostname |
Stated hostname, as a string. If NULL tries to attach to any hostname, normally 0.0.0.0 (ipv4 and ipv6)
Referenced by onion_add_listen_point(), onion_https_t::onion_https_free_user_data(), onion_https_t::onion_https_listen_stop(), onion_listen_point_free(), onion_listen_point_listen(), onion_set_certificate_va(), and onion_set_hostname().
void(* onion_listen_point_t::listen)(onion_listen_point *lp) |
How to start the listening phase.
Normally NULL means socket listening.
Must set at listenfd a file descriptor that will be polled, and when data arrives, it will call the request_init with a new request object.
Referenced by onion_listen_point_listen().
void(* onion_listen_point_t::listen_stop)(onion_listen_point *lp) |
Frees internal data and state of listen point, but not listen point itself.
If NULL means socket listen, and should be closed calling onion_listen_point_listen_stop. If a port is open must be closed. Its the exact oposite of listen.
May be called in a loop: listen -> ... -> listen_stop -> ... -> listen.
It also may be called two succesive times, and should do nothing on second.
Referenced by onion_https_t::onion_https_new(), and onion_listen_point_listen_stop().
int onion_listen_point_t::listenfd |
For socket listening listen points, the listen fd. For others may be -1 as not used, or an fd to watch and when changed calls the request_init with a new request.
Referenced by onion_https_t::onion_https_listen_stop(), onion_listen(), onion_listen_point_free(), onion_listen_point_listen(), onion_listen_point_listen_stop(), and onion_listen_point_request_init_from_socket().
char* onion_listen_point_t::port |
Stated port, if none then 8080.
Referenced by onion_add_listen_point(), onion_https_t::onion_https_free_user_data(), onion_https_t::onion_https_listen_stop(), onion_listen_point_free(), onion_listen_point_listen(), onion_set_certificate_va(), and onion_set_port().
ssize_t(* onion_listen_point_t::read)(onion_request *req, char *data, size_t len) |
Read data from the given request and write it in data.
Referenced by onion_http_t::onion_http_new(), onion_http_t::onion_http_read_ready(), onion_https_t::onion_https_new(), and onion_websocket_t::onion_websocket_read().
int(* onion_listen_point_t::read_ready)(onion_request *req) |
When poller detects data is ready to be read. Might be diferent in diferent parts of the processing.
Referenced by onion_http_t::onion_http_new(), onion_https_t::onion_https_new(), onion_listen(), and onion_listen_point_read_ready().
int(* onion_listen_point_t::request_init)(onion_request *req) |
Initialize the request object. Data is already malloc'd but specific listen protocols may need custom data.
Has default implementation that do the socket accept and set of default params. On some protocols may be reimplemented to do non socket-petition accept.
Referenced by onion_https_t::onion_https_new(), and onion_request_t::onion_request_new().
bool onion_listen_point_t::secure |
Is this listen point secure?
Referenced by onion_http_t::onion_http_new(), onion_https_t::onion_https_new(), and onion_request_is_secure().
onion* onion_listen_point_t::server |
Onion server.
Referenced by onion_add_listen_point(), onion_listen_point_accept(), onion_listen_point_listen(), onion_listen_point_request_init_from_socket(), onion_request_t::onion_request_clean(), onion_request_t::onion_request_free(), onion_request_t::onion_request_get_session_dict(), onion_request_t::onion_request_guess_session_id(), onion_request_process(), onion_request_t::onion_request_session_free(), onion_set_certificate_va(), and onion_shortcut_internal_redirect().
void* onion_listen_point_t::user_data |
Internal data used by the listen point, for example in HTTPS is the certificate loaded data.
Referenced by onion_https_t::onion_https_free_user_data(), onion_https_t::onion_https_new(), onion_https_t::onion_https_request_init(), and onion_https_t::onion_https_set_certificate_argv().
ssize_t(* onion_listen_point_t::write)(onion_request *req, const char *data, size_t len) |
Write data to the given request.
Referenced by onion_http_t::onion_http_new(), onion_https_t::onion_https_new(), onion_https_t::onion_https_set_certificate_argv(), onion_response_flush(), onion_response_t::onion_response_free(), onion_set_certificate_va(), onion_shortcut_response_file(), and onion_websocket_t::onion_websocket_write().