38 #include <event2/event.h>
39 #include <event2/buffer.h>
40 #include <event2/bufferevent.h>
41 #include <openssl/ssl.h>
42 #include "qlibc/qlibc.h"
58 #define AD_TAKEOVER (1)
81 #define AD_SERVER_OPTIONS { \
82 { "server.port", "8888" }, \
85 { "server.addr", "0.0.0.0" }, \
87 { "server.backlog", "128" }, \
90 { "server.timeout", "0" }, \
93 { "server.enable_ssl", "0" }, \
94 { "server.ssl_cert", "/usr/local/etc/ad_server/ad_server.crt" }, \
95 { "server.ssl_pkey", "/usr/local/etc/ad_server/ad_server.key" }, \
98 { "server.request_pipelining", "1" }, \
101 { "server.thread", "0" }, \
104 { "server.free_on_stop", "1" }, \
123 #define AD_EVENT_INIT (1)
124 #define AD_EVENT_READ (1 << 1)
125 #define AD_EVENT_WRITE (1 << 2)
126 #define AD_EVENT_CLOSE (1 << 3)
127 #define AD_EVENT_TIMEOUT (1 << 4)
128 #define AD_EVENT_SHUTDOWN (1 << 5)
133 #define AD_NUM_USERDATA (2)
204 #ifndef _DOXYGEN_SKIP
void ad_server_set_ssl_ctx(ad_server_t *server, SSL_CTX *sslctx)
Attach OpenSSL SSL_CTX to the server.
int ad_conn_get_socket(ad_conn_t *conn)
Return socket file descriptor associated with a connection.
enum ad_log_e ad_log_level(enum ad_log_e log_level)
Set debug output level.
ad_server_t * ad_server_new(void)
Create a server object.
struct bufferevent * notify_buffer
void * ad_conn_get_extra(ad_conn_t *conn)
Get extra userdata attached in this connection.
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.
void * ad_conn_set_userdata(ad_conn_t *conn, const void *userdata, ad_userdata_free_cb free_cb)
Attach userdata into the connection.
qhashtbl_t * ad_server_get_stats(ad_server_t *server, const char *key)
Return internal statistic counter map.
int ad_server_get_option_int(ad_server_t *server, const char *key)
Retrieve server option in integer format.
struct bufferevent * buffer
void ad_server_stop(ad_server_t *server)
Stop server.
struct evconnlistener * listener
void ad_server_free(ad_server_t *server)
Release server object and all the resources.
void * ad_conn_set_extra(ad_conn_t *conn, const void *extra, ad_userdata_free_cb free_cb)
Set extra userdata into the connection.
ad_userdata_free_cb userdata_free_cb[2]
void ad_server_global_free(void)
Clean up all the global objects.
void(* ad_userdata_free_cb)(ad_conn_t *conn, void *userdata)
char * ad_server_get_option(ad_server_t *server, const char *key)
Retrieve server option.
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.
void ad_server_register_hook(ad_server_t *server, ad_callback cb, void *userdata)
Register user hook.
void * ad_conn_get_userdata(ad_conn_t *conn)
Get userdata attached in the connection.
SSL_CTX * ad_server_get_ssl_ctx(ad_server_t *server)
Get OpenSSL SSL_CTX object.
void ad_server_set_option(ad_server_t *server, const char *key, const char *value)
Set server option.
void ad_conn_set_method(ad_conn_t *conn, char *method)
Set method name on this connection.
int(* ad_callback)(short event, ad_conn_t *conn, void *userdata)
User callback(hook) prototype.
int ad_server_start(ad_server_t *server)
Start server.
struct event_base * evbase