libasyncd
ad_server.c File Reference

Main core logic of the server implementation. More...

Go to the source code of this file.

Functions

enum ad_log_e ad_log_level (enum ad_log_e log_level)
 Set debug output level. More...
 
ad_server_tad_server_new (void)
 Create a server object. More...
 
int ad_server_start (ad_server_t *server)
 Start server. More...
 
void ad_server_stop (ad_server_t *server)
 Stop server. More...
 
void ad_server_free (ad_server_t *server)
 Release server object and all the resources. More...
 
void ad_server_global_free (void)
 Clean up all the global objects. More...
 
void ad_server_set_option (ad_server_t *server, const char *key, const char *value)
 Set server option. More...
 
char * ad_server_get_option (ad_server_t *server, const char *key)
 Retrieve server option. More...
 
int ad_server_get_option_int (ad_server_t *server, const char *key)
 Retrieve server option in integer format. More...
 
SSL_CTX * ad_server_ssl_ctx_create_simple (const char *cert_path, const char *pkey_path)
 Helper method for creating minimal OpenSSL SSL_CTX object. More...
 
void ad_server_set_ssl_ctx (ad_server_t *server, SSL_CTX *sslctx)
 Attach OpenSSL SSL_CTX to the server. More...
 
SSL_CTX * ad_server_get_ssl_ctx (ad_server_t *server)
 Get OpenSSL SSL_CTX object. More...
 
qhashtbl_t * ad_server_get_stats (ad_server_t *server, const char *key)
 Return internal statistic counter map. More...
 
void ad_server_register_hook (ad_server_t *server, ad_callback cb, void *userdata)
 Register user hook. More...
 
void ad_server_register_hook_on_method (ad_server_t *server, const char *method, ad_callback cb, void *userdata)
 Register user hook on method name. More...
 
void * ad_conn_set_userdata (ad_conn_t *conn, const void *userdata, ad_userdata_free_cb free_cb)
 Attach userdata into the connection. More...
 
void * ad_conn_get_userdata (ad_conn_t *conn)
 Get userdata attached in the connection. More...
 
void * ad_conn_set_extra (ad_conn_t *conn, const void *extra, ad_userdata_free_cb free_cb)
 Set extra userdata into the connection. More...
 
void * ad_conn_get_extra (ad_conn_t *conn)
 Get extra userdata attached in this connection. More...
 
void ad_conn_set_method (ad_conn_t *conn, char *method)
 Set method name on this connection. More...
 
int ad_conn_get_socket (ad_conn_t *conn)
 Return socket file descriptor associated with a connection. More...
 

Variables

int _ad_log_level = AD_LOG_WARN
 

Detailed Description

Main core logic of the server implementation.

Definition in file ad_server.c.

Function Documentation

enum ad_log_e ad_log_level ( enum ad_log_e  log_level)

Set debug output level.

Parameters
debug_leveldebug output level. 0 to disable.
Returns
previous debug level.
Note
debug_level: AD_LOG_DISABLE AD_LOG_ERROR AD_LOG_WARN (default) AD_LOG_INFO AD_LOG_DEBUG AD_LOG_DEBUG2

Definition at line 126 of file ad_server.c.

ad_server_t* ad_server_new ( void  )

Create a server object.

Definition at line 135 of file ad_server.c.

int ad_server_start ( ad_server_t server)

Start server.

Returns
0 if successful, otherwise -1.

Definition at line 164 of file ad_server.c.

void ad_server_stop ( ad_server_t server)

Stop server.

This call is be used to stop a server from different thread.

Returns
0 if successful, otherwise -1.

Definition at line 287 of file ad_server.c.

void ad_server_free ( ad_server_t server)

Release server object and all the resources.

Definition at line 303 of file ad_server.c.

void ad_server_global_free ( void  )

Clean up all the global objects.

This will make memory-leak checkers happy. There are globally shared resources in libevent and openssl and it's usually not a problem since they don't grow but having these can confuse some debugging tools into thinking as memory leak. If you need to make sure that libasyncd has released all internal library-global data structures, call this.

Definition at line 352 of file ad_server.c.

void ad_server_set_option ( ad_server_t server,
const char *  key,
const char *  value 
)

Set server option.

See Also
AD_SERVER_OPTIONS

Definition at line 370 of file ad_server.c.

char* ad_server_get_option ( ad_server_t server,
const char *  key 
)

Retrieve server option.

Definition at line 377 of file ad_server.c.

int ad_server_get_option_int ( ad_server_t server,
const char *  key 
)

Retrieve server option in integer format.

Definition at line 384 of file ad_server.c.

SSL_CTX* ad_server_ssl_ctx_create_simple ( const char *  cert_path,
const char *  pkey_path 
)

Helper method for creating minimal OpenSSL SSL_CTX object.

Parameters
cert_pathpath to a PEM encoded certificate file
pkey_pathpath to a PEM encoded private key file
Returns
newly allocated SSL_CTX object or NULL on failure
Note
This function initializes SSL_CTX with minimum default with "SSLv23_server_method" which will make the server understand SSLv2, SSLv3, and TLSv1 protocol.
See Also
ad_server_set_ssl_ctx()

Definition at line 404 of file ad_server.c.

void ad_server_set_ssl_ctx ( ad_server_t server,
SSL_CTX *  sslctx 
)

Attach OpenSSL SSL_CTX to the server.

Parameters
servera valid server instance
sslctxallocated and configured SSL_CTX object
Note
This function attached SSL_CTX object to the server causing it to communicate over SSL. Use ad_server_ssl_ctx_create_simple() to quickly create a simple SSL_CTX object or make your own with OpenSSL directly. This function must never be called when ad_server is running.
See Also
ad_server_ssl_ctx_create_simple()

Definition at line 434 of file ad_server.c.

SSL_CTX* ad_server_get_ssl_ctx ( ad_server_t server)

Get OpenSSL SSL_CTX object.

Parameters
servera valid server instance
Returns
SSL_CTX object, NULL if not enabled.
Note
As a general rule the returned SSL_CTX object must not be modified while server is running as it may cause unpredictable results. However, it is safe to use it for reading SSL statistics.

Definition at line 454 of file ad_server.c.

qhashtbl_t* ad_server_get_stats ( ad_server_t server,
const char *  key 
)

Return internal statistic counter map.

Definition at line 461 of file ad_server.c.

void ad_server_register_hook ( ad_server_t server,
ad_callback  cb,
void *  userdata 
)

Register user hook.

Definition at line 468 of file ad_server.c.

void ad_server_register_hook_on_method ( ad_server_t server,
const char *  method,
ad_callback  cb,
void *  userdata 
)

Register user hook on method name.

Definition at line 475 of file ad_server.c.

void* ad_conn_set_userdata ( ad_conn_t conn,
const void *  userdata,
ad_userdata_free_cb  free_cb 
)

Attach userdata into the connection.

Returns
previous userdata;

Definition at line 490 of file ad_server.c.

void* ad_conn_get_userdata ( ad_conn_t conn)

Get userdata attached in the connection.

Returns
previous userdata;

Definition at line 499 of file ad_server.c.

void* ad_conn_set_extra ( ad_conn_t conn,
const void *  extra,
ad_userdata_free_cb  free_cb 
)

Set extra userdata into the connection.

Returns
previous userdata;
Note
Extra userdata is for default protocol handler such as ad_http_handler to provide higher abstraction. End users should always use only ad_conn_set_userdata() to avoid any conflict with default handlers.

Definition at line 513 of file ad_server.c.

void* ad_conn_get_extra ( ad_conn_t conn)

Get extra userdata attached in this connection.

Definition at line 520 of file ad_server.c.

void ad_conn_set_method ( ad_conn_t conn,
char *  method 
)

Set method name on this connection.

Once the method name is set, hooks registered by ad_server_register_hook_on_method() will be called if method name matches with the registered name.

See Also
ad_server_register_hook_on_method()

Definition at line 532 of file ad_server.c.

int ad_conn_get_socket ( ad_conn_t conn)

Return socket file descriptor associated with a connection.

Definition at line 543 of file ad_server.c.

Variable Documentation

int _ad_log_level = AD_LOG_WARN

Definition at line 108 of file ad_server.c.