From 99b203e3d8e3fa5ae43763a64bf0afe3a3776ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Wed, 8 Jul 2009 21:06:07 +0200 Subject: [PATCH] Prefix typenames, enums and some macros with "li" and "LI_"; CamelCase TypeNames --- include/lighttpd/actions.h | 102 +++-- include/lighttpd/actions_lua.h | 4 +- include/lighttpd/angel.h | 10 +- include/lighttpd/angel_base.h | 11 +- include/lighttpd/angel_config_parser.h | 8 +- include/lighttpd/angel_connection.h | 66 ++-- include/lighttpd/angel_data.h | 27 +- include/lighttpd/angel_log.h | 71 ++-- include/lighttpd/angel_plugin.h | 70 ++-- include/lighttpd/angel_plugin_core.h | 13 +- include/lighttpd/angel_server.h | 56 +-- include/lighttpd/angel_value.h | 54 ++- include/lighttpd/base.h | 1 - include/lighttpd/chunk.h | 106 +++--- include/lighttpd/chunk_parser.h | 30 +- include/lighttpd/collect.h | 26 +- include/lighttpd/condition.h | 121 +++--- include/lighttpd/condition_lua.h | 6 +- include/lighttpd/config_lua.h | 2 +- include/lighttpd/config_parser.h | 33 +- include/lighttpd/connection.h | 60 +-- include/lighttpd/encoding.h | 4 +- include/lighttpd/environment.h | 32 +- include/lighttpd/etag.h | 8 +- include/lighttpd/filter_chunked.h | 4 +- include/lighttpd/http_headers.h | 32 +- include/lighttpd/http_request_parser.h | 19 +- include/lighttpd/http_response_parser.h | 19 +- include/lighttpd/idlist.h | 14 +- include/lighttpd/lighttpd-glue.h | 6 +- include/lighttpd/log.h | 103 ++--- include/lighttpd/module.h | 30 +- include/lighttpd/network.h | 32 +- include/lighttpd/options.h | 20 +- include/lighttpd/plugin.h | 100 ++--- include/lighttpd/plugin_core.h | 26 +- include/lighttpd/profiler.h | 5 +- include/lighttpd/radix.h | 55 ++- include/lighttpd/request.h | 28 +- include/lighttpd/response.h | 16 +- include/lighttpd/server.h | 54 +-- include/lighttpd/stat_cache.h | 24 +- include/lighttpd/sys-socket.h | 12 +- include/lighttpd/throttle.h | 9 +- include/lighttpd/typedefs.h | 275 +++++++------- include/lighttpd/url_parser.h | 4 +- include/lighttpd/utils.h | 14 +- include/lighttpd/value.h | 38 +- include/lighttpd/value_lua.h | 2 +- include/lighttpd/virtualrequest.h | 126 +++--- include/lighttpd/waitqueue.h | 36 +- include/lighttpd/worker.h | 40 +- src/actions.c | 119 +++--- src/actions_lua.c | 16 +- src/angel.c | 20 +- src/angel_config_parser.rl | 28 +- src/angel_connection.c | 98 ++--- src/angel_data.c | 26 +- src/angel_fake.c | 4 +- src/angel_log.c | 22 +- src/angel_main.c | 2 +- src/angel_plugin.c | 80 ++-- src/angel_plugin_core.c | 54 +-- src/angel_server.c | 124 +++--- src/angel_value.c | 118 +++--- src/chunk.c | 174 ++++----- src/chunk_parser.c | 38 +- src/collect.c | 50 ++- src/condition.c | 484 ++++++++++++------------ src/condition_lua.c | 104 ++--- src/config_lua.c | 38 +- src/config_parser.rl | 226 +++++------ src/connection.c | 174 ++++----- src/encoding.c | 3 +- src/environment.c | 26 +- src/etag.c | 24 +- src/filter_chunked.c | 12 +- src/http_headers.c | 68 ++-- src/http_request_parser.rl | 78 ++-- src/http_response_parser.rl | 32 +- src/idlist.c | 14 +- src/lighttpd-glue.c | 68 ++-- src/lighttpd.c | 10 +- src/log.c | 180 ++++----- src/module.c | 50 +-- src/modules/mod_access.c | 68 ++-- src/modules/mod_accesslog.c | 54 +-- src/modules/mod_balancer.c | 52 +-- src/modules/mod_cache_disk_etag.c | 93 +++-- src/modules/mod_debug.c | 54 +-- src/modules/mod_dirlist.c | 109 +++--- src/modules/mod_expire.c | 38 +- src/modules/mod_fastcgi.c | 135 ++++--- src/modules/mod_fortune.c | 39 +- src/modules/mod_rewrite.c | 85 +++-- src/modules/mod_status.c | 62 +-- src/modules/mod_vhost.c | 74 ++-- src/network.c | 18 +- src/network_sendfile.c | 58 +-- src/network_write.c | 22 +- src/network_writev.c | 36 +- src/options.c | 34 +- src/plugin.c | 172 ++++----- src/plugin_core.c | 480 +++++++++++------------ src/profiler.c | 8 +- src/radix.c | 54 +-- src/request.c | 58 +-- src/response.c | 34 +- src/server.c | 112 +++--- src/stat_cache.c | 88 ++--- src/tests.c | 14 +- src/throttle.c | 22 +- src/url_parser.rl | 4 +- src/utils.c | 30 +- src/value.c | 142 +++---- src/value_lua.c | 14 +- src/virtualrequest.c | 226 +++++------ src/waitqueue.c | 24 +- src/worker.c | 118 +++--- 119 files changed, 3590 insertions(+), 3669 deletions(-) diff --git a/include/lighttpd/actions.h b/include/lighttpd/actions.h index 1022303..328be0e 100644 --- a/include/lighttpd/actions.h +++ b/include/lighttpd/actions.h @@ -5,31 +5,16 @@ #error Please include instead of this file #endif -/* action type */ -typedef enum { - ACTION_TSETTING, - ACTION_TFUNCTION, - ACTION_TCONDITION, - ACTION_TLIST, - ACTION_TBALANCER -} action_type; - -typedef enum { - BACKEND_OVERLOAD, - BACKEND_DEAD -} backend_error; - -struct action_regex_stack_element { +struct liActionRegexStackElement { GString *string; GMatchInfo *match_info; }; -typedef struct action_regex_stack_element action_regex_stack_element; -struct action_stack { +struct liActionStack { GArray* stack; GArray* regex_stack; gboolean backend_failed; - backend_error backend_error; + liBackendError backend_error; }; /* param is the param registered with the callbacks; @@ -38,72 +23,71 @@ struct action_stack { * the cleanup callback gets called. * you should not use *context without a cleanup callback!!! */ -typedef handler_t (*ActionFunc)(vrequest *vr, gpointer param, gpointer *context); -typedef handler_t (*ActionCleanup)(vrequest *vr, gpointer param, gpointer context); -typedef void (*ActionFree)(server *srv, gpointer param); - -struct action_func { - ActionFunc func; - ActionCleanup cleanup; - ActionFree free; +typedef liHandlerResult (*liActionFuncCB)(liVRequest *vr, gpointer param, gpointer *context); +typedef liHandlerResult (*liActionCleanupCB)(liVRequest *vr, gpointer param, gpointer context); +typedef void (*liActionFreeCB)(liServer *srv, gpointer param); + +struct liActionFunc { + liActionFuncCB func; + liActionCleanupCB cleanup; + liActionFreeCB free; gpointer param; }; -typedef struct action_func action_func; - - -typedef handler_t (*BackendSelect)(vrequest *vr, gboolean backlog_provided, gpointer param, gpointer *context); -typedef handler_t (*BackendFallback)(vrequest *vr, gboolean backlog_provided, gpointer param, gpointer *context, backend_error error); -typedef handler_t (*BackendFinished)(vrequest *vr, gpointer param, gpointer context); -typedef void (*BalancerFree)(server *srv, gpointer param); -struct balancer_func { - BackendSelect select; - BackendFallback fallback; - BackendFinished finished; - BalancerFree free; + + +typedef liHandlerResult (*liBackendSelectCB)(liVRequest *vr, gboolean backlog_provided, gpointer param, gpointer *context); +typedef liHandlerResult (*liBackendFallbackCB)(liVRequest *vr, gboolean backlog_provided, gpointer param, gpointer *context, liBackendError error); +typedef liHandlerResult (*liBackendFinishedCB)(liVRequest *vr, gpointer param, gpointer context); +typedef void (*liBalancerFreeCB)(liServer *srv, gpointer param); + +struct liBalancerFunc { + liBackendSelectCB select; + liBackendFallbackCB fallback; + liBackendFinishedCB finished; + liBalancerFreeCB free; gpointer param; gboolean provide_backlog; }; -typedef struct balancer_func balancer_func; -struct action { +struct liAction { gint refcount; - action_type type; + liActionType type; union { - option_set setting; + liOptionSet setting; struct { - condition *cond; - action *target; /** action target to jump to if condition is fulfilled */ - action *target_else; /** like above but if condition is not fulfilled */ + liCondition *cond; + liAction *target; /** action target to jump to if condition is fulfilled */ + liAction *target_else; /** like above but if condition is not fulfilled */ } condition; - action_func function; + liActionFunc function; GArray* list; /** array of (action*) */ - balancer_func balancer; + liBalancerFunc balancer; } data; }; /* no new/free function, so just use the struct direct (i.e. not a pointer) */ -LI_API void action_stack_init(action_stack *as); -LI_API void action_stack_reset(vrequest *vr, action_stack *as); -LI_API void action_stack_clear(vrequest *vr, action_stack *as); +LI_API void action_stack_init(liActionStack *as); +LI_API void action_stack_reset(liVRequest *vr, liActionStack *as); +LI_API void action_stack_clear(liVRequest *vr, liActionStack *as); /** handle sublist now, remember current position (stack) */ -LI_API void action_enter(struct vrequest *vr, action *a); -LI_API handler_t action_execute(struct vrequest *vr); +LI_API void action_enter(liVRequest *vr, liAction *a); +LI_API liHandlerResult action_execute(liVRequest *vr); -LI_API void action_release(server *srv, action *a); -LI_API void action_acquire(action *a); +LI_API void action_release(liServer *srv, liAction *a); +LI_API void action_acquire(liAction *a); /* create new action */ -LI_API action *action_new_setting(option_set setting); -LI_API action *action_new_function(ActionFunc func, ActionCleanup fcleanup, ActionFree ffree, gpointer param); -LI_API action *action_new_list(); -LI_API action *action_new_condition(condition *cond, action *target, action *target_else); -LI_API action *action_new_balancer(BackendSelect bselect, BackendFallback bfallback, BackendFinished bfinished, BalancerFree bfree, gpointer param, gboolean provide_backlog); +LI_API liAction *action_new_setting(liOptionSet setting); +LI_API liAction *action_new_function(liActionFuncCB func, liActionCleanupCB fcleanup, liActionFreeCB ffree, gpointer param); +LI_API liAction *action_new_list(); +LI_API liAction *action_new_condition(liCondition *cond, liAction *target, liAction *target_else); +LI_API liAction *action_new_balancer(liBackendSelectCB bselect, liBackendFallbackCB bfallback, liBackendFinishedCB bfinished, liBalancerFreeCB bfree, gpointer param, gboolean provide_backlog); #endif diff --git a/include/lighttpd/actions_lua.h b/include/lighttpd/actions_lua.h index 7c8abc5..d87f0ec 100644 --- a/include/lighttpd/actions_lua.h +++ b/include/lighttpd/actions_lua.h @@ -4,7 +4,7 @@ #include #include -action* lua_get_action(lua_State *L, int ndx); -int lua_push_action(server *srv, lua_State *L, action *a); +liAction* lua_get_action(lua_State *L, int ndx); +int lua_push_action(liServer *srv, lua_State *L, liAction *a); #endif diff --git a/include/lighttpd/angel.h b/include/lighttpd/angel.h index a52f27d..2c6528c 100644 --- a/include/lighttpd/angel.h +++ b/include/lighttpd/angel.h @@ -2,17 +2,17 @@ #define _LIGHTTPD_ANGEL_H_ /* interface to the angel; implementation needs to work without angel too */ -LI_API void angel_setup(server *srv); +LI_API void angel_setup(liServer *srv); /* listen to a socket */ -LI_API void angel_listen(server *srv, GString *str); +LI_API void angel_listen(liServer *srv, GString *str); /* send log messages during startup to angel, frees the string */ -LI_API void angel_log(server *srv, GString *str); +LI_API void angel_log(liServer *srv, GString *str); /* angle_fake definitions, only for internal use */ -int angel_fake_listen(server *srv, GString *str); -gboolean angel_fake_log(server *srv, GString *str); +int angel_fake_listen(liServer *srv, GString *str); +gboolean angel_fake_log(liServer *srv, GString *str); #endif diff --git a/include/lighttpd/angel_base.h b/include/lighttpd/angel_base.h index db0b6c9..5023a59 100644 --- a/include/lighttpd/angel_base.h +++ b/include/lighttpd/angel_base.h @@ -11,14 +11,9 @@ /* angel_server.h */ -struct server; -typedef struct server server; - -struct instance; -typedef struct instance instance; - -struct instance_conf; -typedef struct instance_conf instance_conf; +typedef struct liServer liServer; +typedef struct liInstance liInstance; +typedef struct liInstanceConf liInstanceConf; #include diff --git a/include/lighttpd/angel_config_parser.h b/include/lighttpd/angel_config_parser.h index ee01a27..14be0ca 100644 --- a/include/lighttpd/angel_config_parser.h +++ b/include/lighttpd/angel_config_parser.h @@ -2,13 +2,13 @@ #define _LIGHTTPD_ANGEL_CONIG_PARSER_H_ /* error handling */ -#define ANGEL_CONFIG_PARSER_ERROR angel_config_parser_error_quark() +#define LI_ANGEL_CONFIG_PARSER_ERROR angel_config_parser_error_quark() LI_API GQuark angel_config_parser_error_quark(); typedef enum { - ANGEL_CONFIG_PARSER_ERROR_PARSE, /* parse error */ -} AngelConfigParserError; + LI_ANGEL_CONFIG_PARSER_ERROR_PARSE, /* parse error */ +} liAngelConfigParserError; -LI_API gboolean angel_config_parse_file(server *srv, const gchar *filename, GError **err); +LI_API gboolean angel_config_parse_file(liServer *srv, const gchar *filename, GError **err); #endif diff --git a/include/lighttpd/angel_connection.h b/include/lighttpd/angel_connection.h index 2225cca..9a625f9 100644 --- a/include/lighttpd/angel_connection.h +++ b/include/lighttpd/angel_connection.h @@ -5,37 +5,35 @@ #define ANGEL_CALL_MAX_STR_LEN (64*1024) /* must fit into a gint32 */ -struct angel_connection; -typedef struct angel_connection angel_connection; +typedef struct liAngelConnection liAngelConnection; -struct angel_call; -typedef struct angel_call angel_call; +typedef struct liAngelCall liAngelCall; /* error, data and fds-array will be freed/closed by the angel api itself; if you want to use the fds set the array size to 0 */ -typedef void (*AngelCallback)(angel_call *acall, gpointer ctx, gboolean timeout, GString *error, GString *data, GArray *fds); +typedef void (*liAngelCallCB)(liAngelCall *acall, gpointer ctx, gboolean timeout, GString *error, GString *data, GArray *fds); -typedef void (*AngelReceiveCall)(angel_connection *acon, +typedef void (*liAngelReceiveCallCB)(liAngelConnection *acon, const gchar *mod, gsize mod_len, const gchar *action, gsize action_len, gint32 id, GString *data); /* gets called after read/write errors */ -typedef void (*AngelCloseCallback)(angel_connection *acon, GError *err); +typedef void (*liAngelCloseCB)(liAngelConnection *acon, GError *err); -struct angel_connection { +struct liAngelConnection { gpointer data; GMutex *mutex; struct ev_loop *loop; int fd; - idlist *call_id_list; + liIDList *call_id_list; GPtrArray *call_table; ev_io fd_watcher; ev_async out_notify_watcher; GQueue *out; - angel_buffer in; + liAngelBuffer in; - AngelReceiveCall recv_call; - AngelCloseCallback close_cb; + liAngelReceiveCallCB recv_call; + liAngelCloseCB close_cb; /* parse input */ struct { @@ -51,67 +49,67 @@ struct angel_connection { /* with multi-threading you should protect the structure * containing the angel_call with a lock */ -struct angel_call { +struct liAngelCall { gpointer context; - AngelCallback callback; + liAngelCallCB callback; /* internal data */ gint32 id; /* id is -1 if there is no call pending (the callback may still be running) */ - angel_connection *acon; + liAngelConnection *acon; ev_timer timeout_watcher; }; /* error handling */ -#define ANGEL_CALL_ERROR angel_call_error_quark() +#define LI_ANGEL_CALL_ERROR angel_call_error_quark() LI_API GQuark angel_call_error_quark(); -#define ANGEL_CONNECTION_ERROR angel_connection_error_quark() +#define LI_ANGEL_CONNECTION_ERROR angel_connection_error_quark() LI_API GQuark angel_connection_error_quark(); typedef enum { - ANGEL_CALL_ALREADY_RUNNING, /* the angel_call struct is already in use for a call */ - ANGEL_CALL_OUT_OF_CALL_IDS, /* too many calls already pending */ - ANGEL_CALL_INVALID /* invalid params */ -} AngelCallError; + LI_ANGEL_CALL_ALREADY_RUNNING, /* the angel_call struct is already in use for a call */ + LI_ANGEL_CALL_OUT_OF_CALL_IDS, /* too many calls already pending */ + LI_ANGEL_CALL_INVALID /* invalid params */ +} liAngelCallError; typedef enum { - ANGEL_CONNECTION_CLOSED, /* error on socket */ - ANGEL_CONNECTION_INVALID_DATA /* invalid data from stream */ -} AngelConnectionError; + LI_ANGEL_CONNECTION_CLOSED, /* error on socket */ + LI_ANGEL_CONNECTION_INVALID_DATA /* invalid data from stream */ +} liAngelConnectionError; /* create connection */ -LI_API angel_connection* angel_connection_new( +LI_API liAngelConnection* angel_connection_new( struct ev_loop *loop, int fd, gpointer data, - AngelReceiveCall recv_call, AngelCloseCallback close_cb); -LI_API void angel_connection_free(angel_connection *acon); + liAngelReceiveCallCB recv_call, liAngelCloseCB close_cb); +LI_API void angel_connection_free(liAngelConnection *acon); -LI_API angel_call *angel_call_new(AngelCallback callback, ev_tstamp timeout); +LI_API liAngelCall *angel_call_new(liAngelCallCB callback, ev_tstamp timeout); /* returns TRUE if a call was cancelled; make sure you don't call free while you're calling send_call */ -LI_API gboolean angel_call_free(angel_call *call); +LI_API gboolean angel_call_free(liAngelCall *call); /* calls */ /* the GString* parameters get stolen by the angel call (moved to chunkqueue) */ LI_API gboolean angel_send_simple_call( - angel_connection *acon, + liAngelConnection *acon, const gchar *mod, gsize mod_len, const gchar *action, gsize action_len, GString *data, GError **err); LI_API gboolean angel_send_call( - angel_connection *acon, + liAngelConnection *acon, const gchar *mod, gsize mod_len, const gchar *action, gsize action_len, - angel_call *call, + liAngelCall *call, GString *data, GError **err); LI_API gboolean angel_send_result( - angel_connection *acon, + liAngelConnection *acon, gint32 id, GString *error, GString *data, GArray *fds, GError **err); /* free temporary needed memroy; call this once in while after some activity */ -LI_API void angel_cleanup_tables(angel_connection *acon); +LI_API void angel_cleanup_tables(liAngelConnection *acon); /* Usage */ #if 0 diff --git a/include/lighttpd/angel_data.h b/include/lighttpd/angel_data.h index 9f388e7..0f1bfaf 100644 --- a/include/lighttpd/angel_data.h +++ b/include/lighttpd/angel_data.h @@ -17,25 +17,24 @@ /* The buffer may be bigger of course, but a single string should not * exceed this length: */ -#define ANGEL_DATA_MAX_STR_LEN 1024 /* must fit into a gint32 */ +#define LI_ANGEL_DATA_MAX_STR_LEN 1024 /* must fit into a gint32 */ /* Needed for reading data */ -struct angel_buffer; -typedef struct angel_buffer angel_buffer; -struct angel_buffer { +typedef struct liAngelBuffer liAngelBuffer; +struct liAngelBuffer { GString *data; gsize pos; }; /* error handling */ -#define ANGEL_DATA_ERROR angel_data_error_quark() +#define LI_ANGEL_DATA_ERROR angel_data_error_quark() LI_API GQuark angel_data_error_quark(); typedef enum { - ANGEL_DATA_ERROR_EOF, /* not enough data to read value */ - ANGEL_DATA_ERROR_INVALID_STRING_LENGTH, /* invalid string length read from buffer (< 0 || > max-str-len) */ - ANGEL_DATA_ERROR_STRING_TOO_LONG /* string too long (len > max-str-len) */ -} AngelDataError; + LI_ANGEL_DATA_ERROR_EOF, /* not enough data to read value */ + LI_ANGEL_DATA_ERROR_INVALID_STRING_LENGTH, /* invalid string length read from buffer (< 0 || > max-str-len) */ + LI_ANGEL_DATA_ERROR_STRING_TOO_LONG /* string too long (len > max-str-len) */ +} liAngelDataError; /* write */ LI_API gboolean angel_data_write_int32(GString *buf, gint32 i, GError **err); @@ -50,10 +49,10 @@ LI_API gboolean angel_data_write_cstr (GString *buf, const gchar *str, gsize len * otherwise a new GString* will be created * - *val will only be modified if no error is returned */ -LI_API gboolean angel_data_read_int32(angel_buffer *buf, gint32 *val, GError **err); -LI_API gboolean angel_data_read_int64(angel_buffer *buf, gint64 *val, GError **err); -LI_API gboolean angel_data_read_char (angel_buffer *buf, gchar *val, GError **err); -LI_API gboolean angel_data_read_str (angel_buffer *buf, GString **val, GError **err); -LI_API gboolean angel_data_read_mem (angel_buffer *buf, GString **val, gsize len, GError **err); +LI_API gboolean angel_data_read_int32(liAngelBuffer *buf, gint32 *val, GError **err); +LI_API gboolean angel_data_read_int64(liAngelBuffer *buf, gint64 *val, GError **err); +LI_API gboolean angel_data_read_char (liAngelBuffer *buf, gchar *val, GError **err); +LI_API gboolean angel_data_read_str (liAngelBuffer *buf, GString **val, GError **err); +LI_API gboolean angel_data_read_mem (liAngelBuffer *buf, GString **val, gsize len, GError **err); #endif diff --git a/include/lighttpd/angel_log.h b/include/lighttpd/angel_log.h index 920cf22..a967110 100644 --- a/include/lighttpd/angel_log.h +++ b/include/lighttpd/angel_log.h @@ -7,64 +7,63 @@ /* #include */ -#define REMOVE_PATH_FROM_FILE 1 -#if REMOVE_PATH_FROM_FILE +#define LI_REMOVE_PATH_FROM_FILE 1 +#if LI_REMOVE_PATH_FROM_FILE LI_API const char *remove_path(const char *path); -#define REMOVE_PATH(file) remove_path(file) +#define LI_REMOVE_PATH(file) remove_path(file) #else -#define REMOVE_PATH(file) file +#define LI_REMOVE_PATH(file) file #endif #define SEGFAULT(srv, fmt, ...) \ do { \ - log_write_(srv, LOG_LEVEL_ABORT, LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \ + log_write_(srv, LI_LOG_LEVEL_ABORT, LI_LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \ /* VALGRIND_PRINTF_BACKTRACE(fmt, __VA_ARGS__); */\ abort();\ } while(0) #define ERROR(srv, fmt, ...) \ - log_write(srv, LOG_LEVEL_ERROR, LOG_FLAG_TIMESTAMP, "error (%s:%d): "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + log_write(srv, LI_LOG_LEVEL_ERROR, LI_LOG_FLAG_TIMESTAMP, "error (%s:%d): "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define WARNING(srv, fmt, ...) \ - log_write(srv, LOG_LEVEL_WARNING, LOG_FLAG_TIMESTAMP, "warning (%s:%d): "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + log_write(srv, LI_LOG_LEVEL_WARNING, LI_LOG_FLAG_TIMESTAMP, "warning (%s:%d): "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define INFO(srv, fmt, ...) \ - log_write(srv, LOG_LEVEL_INFO, LOG_FLAG_TIMESTAMP, "info (%s:%d): "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + log_write(srv, LI_LOG_LEVEL_INFO, LI_LOG_FLAG_TIMESTAMP, "info (%s:%d): "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define DEBUG(srv, fmt, ...) \ - log_write(srv, LOG_LEVEL_DEBUG, LOG_FLAG_TIMESTAMP, "debug (%s:%d): "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + log_write(srv, LI_LOG_LEVEL_DEBUG, LI_LOG_FLAG_TIMESTAMP, "debug (%s:%d): "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) /* log messages from lighty always as ERROR */ #define INSTANCE(srv, inst, msg) \ - log_write(srv, LOG_LEVEL_ERROR, LOG_FLAG_NONE, "lighttpd[%d]: %s", (int) inst->pid, msg) + log_write(srv, LI_LOG_LEVEL_ERROR, LI_LOG_FLAG_NONE, "lighttpd[%d]: %s", (int) inst->pid, msg) typedef enum { - LOG_LEVEL_DEBUG, - LOG_LEVEL_INFO, - LOG_LEVEL_WARNING, - LOG_LEVEL_ERROR, - LOG_LEVEL_ABORT -} log_level_t; + LI_LOG_LEVEL_DEBUG, + LI_LOG_LEVEL_INFO, + LI_LOG_LEVEL_WARNING, + LI_LOG_LEVEL_ERROR, + LI_LOG_LEVEL_ABORT +} liLogLevel; -#define LOG_LEVEL_COUNT (LOG_LEVEL_ABORT+1) +#define LI_LOG_LEVEL_COUNT (LI_LOG_LEVEL_ABORT+1) typedef enum { - LOG_TYPE_STDERR, - LOG_TYPE_FILE, - LOG_TYPE_PIPE, - LOG_TYPE_SYSLOG, - LOG_TYPE_NONE -} log_type_t; - -#define LOG_FLAG_NONE (0x0) /* default flag */ -#define LOG_FLAG_TIMESTAMP (0x1) /* prepend a timestamp to the log message */ - -struct log_t; -typedef struct log_t log_t; - -struct log_t { - log_type_t type; - gboolean levels[LOG_LEVEL_COUNT]; + LI_LOG_TYPE_STDERR, + LI_LOG_TYPE_FILE, + LI_LOG_TYPE_PIPE, + LI_LOG_TYPE_SYSLOG, + LI_LOG_TYPE_NONE +} liLogType; + +#define LI_LOG_FLAG_NONE (0x0) /* default flag */ +#define LI_LOG_FLAG_TIMESTAMP (0x1) /* prepend a timestamp to the log message */ + +typedef struct liLog liLog; + +struct liLog { + liLogType type; + gboolean levels[LI_LOG_LEVEL_COUNT]; GString *path; gint fd; @@ -74,9 +73,9 @@ struct log_t { GString *log_line; }; -void log_init(server *srv); -void log_clean(server *srv); +void log_init(liServer *srv); +void log_clean(liServer *srv); -LI_API void log_write(server *srv, log_level_t log_level, guint flags, const gchar *fmt, ...) G_GNUC_PRINTF(4, 5); +LI_API void log_write(liServer *srv, liLogLevel log_level, guint flags, const gchar *fmt, ...) G_GNUC_PRINTF(4, 5); #endif diff --git a/include/lighttpd/angel_plugin.h b/include/lighttpd/angel_plugin.h index 5892857..17ac488 100644 --- a/include/lighttpd/angel_plugin.h +++ b/include/lighttpd/angel_plugin.h @@ -5,60 +5,60 @@ #error Please include instead of this file #endif -typedef struct plugin_item plugin_item; -typedef struct plugin_item_option plugin_item_option; -typedef struct plugin plugin; -typedef struct Plugins Plugins; +typedef struct liPluginItem liPluginItem; +typedef struct liPluginItemOption liPluginItemOption; +typedef struct liPlugin liPlugin; +typedef struct liPlugins liPlugins; -typedef gboolean (*PluginInit) (server *srv, plugin *p); -typedef void (*PluginFree) (server *srv, plugin *p); +typedef gboolean (*liPluginInitCB) (liServer *srv, liPlugin *p); +typedef void (*liPluginFreeCB) (liServer *srv, liPlugin *p); -typedef void (*PluginCleanConfig) (server *srv, plugin *p); -typedef gboolean (*PluginCheckConfig) (server *srv, plugin *p); -typedef void (*PluginActivateConfig)(server *srv, plugin *p); -typedef void (*PluginParseItem) (server *srv, plugin *p, value **options); +typedef void (*liPluginCleanConfigCB) (liServer *srv, liPlugin *p); +typedef gboolean (*liPluginCheckConfigCB) (liServer *srv, liPlugin *p); +typedef void (*liPluginActivateConfigCB)(liServer *srv, liPlugin *p); +typedef void (*liPluginParseItemCB) (liServer *srv, liPlugin *p, liValue **options); -typedef void (*PluginHandleCall) (server *srv, instance *i, plugin *p, gint32 id, GString *data); +typedef void (*liPluginHandleCallCB) (liServer *srv, liInstance *i, liPlugin *p, gint32 id, GString *data); typedef enum { - PLUGIN_ITEM_OPTION_MANDATORY = 1 -} plugin_item_option_flags; + LI_PLUGIN_ITEM_OPTION_MANDATORY = 1 +} liPluginItemOptionFlags; -struct plugin_item_option { +struct liPluginItemOption { const gchar *name; /**< name of the option */ - value_type type; /**< type of the option; may be VALUE_NONE to accept anything */ - plugin_item_option_flags flags; /**< flags of the option */ + liValueType type; /**< type of the option; may be LI_VALUE_NONE to accept anything */ + liPluginItemOptionFlags flags; /**< flags of the option */ }; -struct plugin_item { +struct liPluginItem { const gchar *name; - PluginParseItem handle_parse_item; + liPluginParseItemCB handle_parse_item; - const plugin_item_option *options; + const liPluginItemOption *options; }; -struct plugin { +struct liPlugin { size_t version; const gchar *name; /**< name of the plugin */ gpointer data; /**< private plugin data */ - const plugin_item *items; - GHashTable *angel_callbacks; /**< map (const gchar*) -> PluginHandleCall */ + const liPluginItem *items; + GHashTable *angel_callbacks; /**< map (const gchar*) -> liPluginHandleCallCB */ - PluginFree handle_free; /**< called before plugin is unloaded */ + liPluginFreeCB handle_free; /**< called before plugin is unloaded */ - PluginCleanConfig handle_clean_config; /**< called before the reloading of the config is started or after the reloading failed */ - PluginCheckConfig handle_check_config; /**< called before activating a config to ensure everything works */ - PluginActivateConfig handle_activate_config; /**< called to activate a config after successful loading it. this cannot fail */ + liPluginCleanConfigCB handle_clean_config; /**< called before the reloading of the config is started or after the reloading failed */ + liPluginCheckConfigCB handle_check_config; /**< called before activating a config to ensure everything works */ + liPluginActivateConfigCB handle_activate_config; /**< called to activate a config after successful loading it. this cannot fail */ }; -struct Plugins { +struct liPlugins { GString *config_filename; GHashTable *items, *load_items; /**< gchar* -> server_item */ - struct modules *modules; + liModules *modules; GHashTable *module_refs, *load_module_refs; /** gchar* -> server_module */ GHashTable *ht_plugins, *load_ht_plugins; @@ -66,17 +66,17 @@ struct Plugins { GPtrArray *plugins, *load_plugins; /* plugin* */ }; -void plugins_init(server *srv, const gchar *module_dir); -void plugins_clear(server *srv); +void plugins_init(liServer *srv, const gchar *module_dir); +void plugins_clear(liServer *srv); -void plugins_config_clean(server *srv); -gboolean plugins_config_load(server *srv, const gchar *filename); +void plugins_config_clean(liServer *srv); +gboolean plugins_config_load(liServer *srv, const gchar *filename); -void plugins_handle_item(server *srv, GString *itemname, value *hash); +void plugins_handle_item(liServer *srv, GString *itemname, liValue *hash); /* "core" is a reserved module name for interal use */ -gboolean plugins_load_module(server *srv, const gchar *name); +gboolean plugins_load_module(liServer *srv, const gchar *name); /* Needed by modules to register their plugin(s) */ -LI_API plugin *angel_plugin_register(server *srv, module *mod, const gchar *name, PluginInit init); +LI_API liPlugin *angel_plugin_register(liServer *srv, liModule *mod, const gchar *name, liPluginInitCB init); #endif diff --git a/include/lighttpd/angel_plugin_core.h b/include/lighttpd/angel_plugin_core.h index 666a313..fd541c3 100644 --- a/include/lighttpd/angel_plugin_core.h +++ b/include/lighttpd/angel_plugin_core.h @@ -3,16 +3,17 @@ #include -typedef struct { +typedef struct liPluginCoreConfig liPluginCoreConfig; +struct liPluginCoreConfig { /* Load */ - instance_conf *load_instconf; + liInstanceConf *load_instconf; gboolean load_failed; /* Running */ - instance_conf *instconf; - instance *inst; -} plugin_core_config_t; + liInstanceConf *instconf; + liInstance *inst; +}; -gboolean plugin_core_init(server *srv); +gboolean plugin_core_init(liServer *srv); #endif diff --git a/include/lighttpd/angel_server.h b/include/lighttpd/angel_server.h index 91f2242..e29153e 100644 --- a/include/lighttpd/angel_server.h +++ b/include/lighttpd/angel_server.h @@ -10,14 +10,14 @@ #endif typedef enum { - INSTANCE_DOWN, /* not running */ - INSTANCE_LOADING, /* startup */ - INSTANCE_WARMUP, /* running, but logging to files disabled */ - INSTANCE_ACTIVE, /* everything running */ - INSTANCE_SUSPEND /* handle remaining connections, suspend logs+accept() */ -} instance_state_t; - -struct instance_conf { + LI_INSTANCE_DOWN, /* not running */ + LI_INSTANCE_LOADING, /* startup */ + LI_INSTANCE_WARMUP, /* running, but logging to files disabled */ + LI_INSTANCE_ACTIVE, /* everything running */ + LI_INSTANCE_SUSPEND /* handle remaining connections, suspend logs+accept() */ +} liInstanceState; + +struct liInstanceConf { gint refcount; gchar **cmd; @@ -26,24 +26,24 @@ struct instance_conf { gid_t gid; }; -struct instance { +struct liInstance { gint refcount; - server *srv; - instance_conf *ic; + liServer *srv; + liInstanceConf *ic; pid_t pid; ev_child child_watcher; - instance_state_t s_cur, s_dest; + liInstanceState s_cur, s_dest; - instance *replace, *replace_by; + liInstance *replace, *replace_by; - angel_connection *acon; + liAngelConnection *acon; gboolean in_jobqueue; }; -struct server { +struct liServer { guint32 magic; /** server magic version, check against LIGHTTPD_ANGEL_MAGIC in plugins */ struct ev_loop *loop; @@ -55,25 +55,25 @@ struct server { GQueue job_queue; ev_async job_watcher; - Plugins plugins; + liPlugins plugins; - log_t log; + liLog log; }; -LI_API server* server_new(const gchar *module_dir); -LI_API void server_free(server* srv); +LI_API liServer* server_new(const gchar *module_dir); +LI_API void server_free(liServer* srv); -LI_API instance* server_new_instance(server *srv, instance_conf *ic); -LI_API void instance_replace(instance *oldi, instance *newi); -LI_API void instance_set_state(instance *i, instance_state_t s); +LI_API liInstance* server_new_instance(liServer *srv, liInstanceConf *ic); +LI_API void instance_replace(liInstance *oldi, liInstance *newi); +LI_API void instance_set_state(liInstance *i, liInstanceState s); -LI_API instance_conf* instance_conf_new(gchar **cmd, GString *username, uid_t uid, gid_t gid); -LI_API void instance_conf_release(instance_conf *ic); -LI_API void instance_conf_acquire(instance_conf *ic); +LI_API liInstanceConf* instance_conf_new(gchar **cmd, GString *username, uid_t uid, gid_t gid); +LI_API void instance_conf_release(liInstanceConf *ic); +LI_API void instance_conf_acquire(liInstanceConf *ic); -LI_API void instance_release(instance *i); -LI_API void instance_acquire(instance *i); +LI_API void instance_release(liInstance *i); +LI_API void instance_acquire(liInstance *i); -LI_API void instance_job_append(instance *i); +LI_API void instance_job_append(liInstance *i); #endif diff --git a/include/lighttpd/angel_value.h b/include/lighttpd/angel_value.h index e837a0b..f9c954c 100644 --- a/include/lighttpd/angel_value.h +++ b/include/lighttpd/angel_value.h @@ -5,56 +5,54 @@ #error Please include instead of this file #endif -struct value; -typedef struct value value; +typedef struct liValue liValue; -struct value_range; -typedef struct value_range value_range; +typedef struct liValueRange liValueRange; typedef enum { - VALUE_NONE, + LI_VALUE_NONE, /* primitive types */ - VALUE_BOOLEAN, - VALUE_NUMBER, - VALUE_STRING, - VALUE_RANGE, + LI_VALUE_BOOLEAN, + LI_VALUE_NUMBER, + LI_VALUE_STRING, + LI_VALUE_RANGE, /* container */ - VALUE_LIST, - VALUE_HASH -} value_type; + LI_VALUE_LIST, + LI_VALUE_HASH +} liValueType; -struct value_range { +struct liValueRange { guint64 from, to; }; -struct value { - value_type type; +struct liValue { + liValueType type; union { gboolean boolean; gint64 number; GString *string; - value_range range; - /* array of (value*) */ + liValueRange range; + /* array of (liValue*) */ GPtrArray *list; /* hash GString => value */ GHashTable *hash; } data; }; -LI_API value* value_new_none(); -LI_API value* value_new_bool(gboolean val); -LI_API value* value_new_number(gint64 val); -LI_API value* value_new_string(GString *val); -LI_API value* value_new_range(value_range val); -LI_API value* value_new_list(); -LI_API value* value_new_hash(); +LI_API liValue* value_new_none(); +LI_API liValue* value_new_bool(gboolean val); +LI_API liValue* value_new_number(gint64 val); +LI_API liValue* value_new_string(GString *val); +LI_API liValue* value_new_range(liValueRange val); +LI_API liValue* value_new_list(); +LI_API liValue* value_new_hash(); -LI_API value* value_copy(value* val); -LI_API void value_free(value* val); +LI_API liValue* value_copy(liValue* val); +LI_API void value_free(liValue* val); -LI_API const char* value_type_string(value_type type); +LI_API const char* value_type_string(liValueType type); -LI_API GString *value_to_string(value *val); +LI_API GString *value_to_string(liValue *val); #endif diff --git a/include/lighttpd/base.h b/include/lighttpd/base.h index bde73b6..ff8663c 100644 --- a/include/lighttpd/base.h +++ b/include/lighttpd/base.h @@ -60,7 +60,6 @@ #include #include #include -#include #include #include #include diff --git a/include/lighttpd/chunk.h b/include/lighttpd/chunk.h index aa7c1d8..8228670 100644 --- a/include/lighttpd/chunk.h +++ b/include/lighttpd/chunk.h @@ -9,7 +9,7 @@ * as a file may get split into many chunks, we * use this struct to keep track of the usage */ -struct chunkfile { +struct liChunkFile { gint refcount; GString *name; /* name of the file */ @@ -17,7 +17,7 @@ struct chunkfile { gboolean is_temp; /* file is temporary and will be deleted on cleanup */ }; -struct chunk { +struct liChunk { enum { UNUSED_CHUNK, STRING_CHUNK, MEM_CHUNK, FILE_CHUNK } type; goffset offset; @@ -29,7 +29,7 @@ struct chunk { GByteArray *mem; struct { - chunkfile *file; + liChunkFile *file; off_t start; /* starting offset in the file */ off_t length; /* octets to send from the starting offset */ @@ -41,31 +41,31 @@ struct chunk { } file; }; -typedef void (*cqlimit_notify)(vrequest *vr, gpointer context, gboolean locked); -struct cqlimit { +typedef void (*liCQLimitNnotifyCB)(liVRequest *vr, gpointer context, gboolean locked); +struct liCQLimit { gint refcount; - vrequest *vr; + liVRequest *vr; goffset limit, current; gboolean locked; ev_io *io_watcher; - cqlimit_notify notify; /* callback to reactivate input */ + liCQLimitNnotifyCB notify; /* callback to reactivate input */ gpointer context; }; -struct chunkqueue { +struct liChunkQueue { /* public */ gboolean is_closed; /* read only */ goffset bytes_in, bytes_out, length, mem_usage; - cqlimit *limit; /* limit is the sum of all { c->mem->len | c->type == STRING_CHUNK } */ + liCQLimit *limit; /* limit is the sum of all { c->mem->len | c->type == STRING_CHUNK } */ /* private */ GQueue *queue; }; -struct chunkiter { +struct liChunkIter { /* private */ GList *element; }; @@ -77,127 +77,127 @@ struct chunkiter { /* open the file cf->name if it is not already opened for reading * may return HANDLER_GO_ON, HANDLER_ERROR */ -LI_API handler_t chunkfile_open(struct vrequest *vr, chunkfile *cf); +LI_API liHandlerResult chunkfile_open(liVRequest *vr, liChunkFile *cf); /****************** * chunk iterator * ******************/ -INLINE chunk* chunkiter_chunk(chunkiter iter); -INLINE gboolean chunkiter_next(chunkiter *iter); -INLINE goffset chunkiter_length(chunkiter iter); +INLINE liChunk* chunkiter_chunk(liChunkIter iter); +INLINE gboolean chunkiter_next(liChunkIter *iter); +INLINE goffset chunkiter_length(liChunkIter iter); /* get the data from a chunk; easy in case of a STRING_CHUNK, * but needs to do io in case of FILE_CHUNK; the data is _not_ marked as "done" * may return HANDLER_GO_ON, HANDLER_ERROR */ -LI_API handler_t chunkiter_read(struct vrequest *vr, chunkiter iter, off_t start, off_t length, char **data_start, off_t *data_len); +LI_API liHandlerResult chunkiter_read(liVRequest *vr, liChunkIter iter, off_t start, off_t length, char **data_start, off_t *data_len); /* same as chunkiter_read, but tries mmap() first and falls back to read(); * as accessing mmap()-ed areas may result in SIGBUS, you have to handle that signal somehow. */ -LI_API handler_t chunkiter_read_mmap(struct vrequest *vr, chunkiter iter, off_t start, off_t length, char **data_start, off_t *data_len); +LI_API liHandlerResult chunkiter_read_mmap(liVRequest *vr, liChunkIter iter, off_t start, off_t length, char **data_start, off_t *data_len); /****************** * chunk * ******************/ -INLINE goffset chunk_length(chunk *c); +INLINE goffset chunk_length(liChunk *c); /****************** * cqlimit * ******************/ -LI_API cqlimit* cqlimit_new(vrequest *vr); -LI_API void cqlimit_reset(cqlimit *cql); -LI_API void cqlimit_acquire(cqlimit *cql); -LI_API void cqlimit_release(cqlimit *cql); -LI_API void cqlimit_set_limit(cqlimit *cql, goffset limit); +LI_API liCQLimit* cqlimit_new(liVRequest *vr); +LI_API void cqlimit_reset(liCQLimit *cql); +LI_API void cqlimit_acquire(liCQLimit *cql); +LI_API void cqlimit_release(liCQLimit *cql); +LI_API void cqlimit_set_limit(liCQLimit *cql, goffset limit); /****************** * chunkqueue * ******************/ -LI_API chunkqueue* chunkqueue_new(); -LI_API void chunkqueue_reset(chunkqueue *cq); -LI_API void chunkqueue_free(chunkqueue *cq); +LI_API liChunkQueue* chunkqueue_new(); +LI_API void chunkqueue_reset(liChunkQueue *cq); +LI_API void chunkqueue_free(liChunkQueue *cq); -LI_API void chunkqueue_use_limit(chunkqueue *cq, vrequest *vr); -LI_API void chunkqueue_set_limit(chunkqueue *cq, cqlimit* cql); +LI_API void chunkqueue_use_limit(liChunkQueue *cq, liVRequest *vr); +LI_API void chunkqueue_set_limit(liChunkQueue *cq, liCQLimit* cql); /* return -1 for unlimited, 0 for full and n > 0 for n bytes free */ -LI_API goffset chunkqueue_limit_available(chunkqueue *cq); +LI_API goffset chunkqueue_limit_available(liChunkQueue *cq); /* pass ownership of str to chunkqueue, do not free/modify it afterwards * you may modify the data (not the length) if you are sure it isn't sent before. * if the length is NULL, str is destroyed immediately */ -LI_API void chunkqueue_append_string(chunkqueue *cq, GString *str); +LI_API void chunkqueue_append_string(liChunkQueue *cq, GString *str); /* pass ownership of mem to chunkqueue, do not free/modify it afterwards * you may modify the data (not the length) if you are sure it isn't sent before. * if the length is NULL, mem is destroyed immediately */ -LI_API void chunkqueue_append_bytearr(chunkqueue *cq, GByteArray *mem); +LI_API void chunkqueue_append_bytearr(liChunkQueue *cq, GByteArray *mem); /* memory gets copied */ -LI_API void chunkqueue_append_mem(chunkqueue *cq, const void *mem, gssize len); +LI_API void chunkqueue_append_mem(liChunkQueue *cq, const void *mem, gssize len); /* pass ownership of filename, do not free it */ -LI_API void chunkqueue_append_file(chunkqueue *cq, GString *filename, off_t start, off_t length); +LI_API void chunkqueue_append_file(liChunkQueue *cq, GString *filename, off_t start, off_t length); /* if you already opened the file, you can pass the fd here - do not close it */ -LI_API void chunkqueue_append_file_fd(chunkqueue *cq, GString *filename, off_t start, off_t length, int fd); +LI_API void chunkqueue_append_file_fd(liChunkQueue *cq, GString *filename, off_t start, off_t length, int fd); /* temp files get deleted after usage */ /* pass ownership of filename, do not free it */ -LI_API void chunkqueue_append_tempfile(chunkqueue *cq, GString *filename, off_t start, off_t length); +LI_API void chunkqueue_append_tempfile(liChunkQueue *cq, GString *filename, off_t start, off_t length); /* if you already opened the file, you can pass the fd here - do not close it */ -LI_API void chunkqueue_append_tempfile_fd(chunkqueue *cq, GString *filename, off_t start, off_t length, int fd); +LI_API void chunkqueue_append_tempfile_fd(liChunkQueue *cq, GString *filename, off_t start, off_t length, int fd); /* steal up to length bytes from in and put them into out, return number of bytes stolen */ -LI_API goffset chunkqueue_steal_len(chunkqueue *out, chunkqueue *in, goffset length); +LI_API goffset chunkqueue_steal_len(liChunkQueue *out, liChunkQueue *in, goffset length); /* steal all chunks from in and put them into out, return number of bytes stolen */ -LI_API goffset chunkqueue_steal_all(chunkqueue *out, chunkqueue *in); +LI_API goffset chunkqueue_steal_all(liChunkQueue *out, liChunkQueue *in); /* steal the first chunk from in and append it to out, return number of bytes stolen */ -LI_API goffset chunkqueue_steal_chunk(chunkqueue *out, chunkqueue *in); +LI_API goffset chunkqueue_steal_chunk(liChunkQueue *out, liChunkQueue *in); /* skip up to length bytes in a chunkqueue, return number of bytes skipped */ -LI_API goffset chunkqueue_skip(chunkqueue *cq, goffset length); +LI_API goffset chunkqueue_skip(liChunkQueue *cq, goffset length); /* skip all chunks in a queue (similar to reset, but keeps stats) */ -LI_API goffset chunkqueue_skip_all(chunkqueue *cq); +LI_API goffset chunkqueue_skip_all(liChunkQueue *cq); /* if the chunk an iterator refers gets stolen/skipped/..., * the iterator isn't valid anymore */ -INLINE chunkiter chunkqueue_iter(chunkqueue *cq); +INLINE liChunkIter chunkqueue_iter(liChunkQueue *cq); -INLINE chunk* chunkqueue_first_chunk(chunkqueue *cq); +INLINE liChunk* chunkqueue_first_chunk(liChunkQueue *cq); -LI_API gboolean chunkqueue_extract_to(vrequest *vr, chunkqueue *cq, goffset len, GString *dest); -LI_API gboolean chunkqueue_extract_to_bytearr(vrequest *vr, chunkqueue *cq, goffset len, GByteArray *dest); +LI_API gboolean chunkqueue_extract_to(liVRequest *vr, liChunkQueue *cq, goffset len, GString *dest); +LI_API gboolean chunkqueue_extract_to_bytearr(liVRequest *vr, liChunkQueue *cq, goffset len, GByteArray *dest); /******************** * Inline functions * ********************/ -INLINE chunk* chunkiter_chunk(chunkiter iter) { +INLINE liChunk* chunkiter_chunk(liChunkIter iter) { if (!iter.element) return NULL; - return (chunk*) iter.element->data; + return (liChunk*) iter.element->data; } -INLINE gboolean chunkiter_next(chunkiter *iter) { +INLINE gboolean chunkiter_next(liChunkIter *iter) { if (!iter || !iter->element) return FALSE; return NULL != (iter->element = g_list_next(iter->element)); } -INLINE goffset chunkiter_length(chunkiter iter) { +INLINE goffset chunkiter_length(liChunkIter iter) { return chunk_length(chunkiter_chunk(iter)); } -INLINE goffset chunk_length(chunk *c) { +INLINE goffset chunk_length(liChunk *c) { if (!c) return 0; switch (c->type) { case UNUSED_CHUNK: @@ -212,14 +212,14 @@ INLINE goffset chunk_length(chunk *c) { return 0; } -INLINE chunkiter chunkqueue_iter(chunkqueue *cq) { - chunkiter i; +INLINE liChunkIter chunkqueue_iter(liChunkQueue *cq) { + liChunkIter i; i.element = g_queue_peek_head_link(cq->queue); return i; } -INLINE chunk* chunkqueue_first_chunk(chunkqueue *cq) { - return (chunk*) g_queue_peek_head(cq->queue); +INLINE liChunk* chunkqueue_first_chunk(liChunkQueue *cq) { + return (liChunk*) g_queue_peek_head(cq->queue); } #endif diff --git a/include/lighttpd/chunk_parser.h b/include/lighttpd/chunk_parser.h index e68b1d8..c0c2ffe 100644 --- a/include/lighttpd/chunk_parser.h +++ b/include/lighttpd/chunk_parser.h @@ -5,43 +5,43 @@ #error Please include instead of this file #endif -struct chunk_parser_ctx { - chunkqueue *cq; +struct liChunkParserCtx { + liChunkQueue *cq; goffset bytes_in; /* current position * buf is curi[start..start+length) */ - chunkiter curi; + liChunkIter curi; off_t start, length; char *buf; int cs; }; -struct chunk_parser_mark { - chunkiter ci; +struct liChunkParserMark { + liChunkIter ci; off_t pos; }; -LI_API void chunk_parser_init(chunk_parser_ctx *ctx, chunkqueue *cq); -LI_API void chunk_parser_reset(chunk_parser_ctx *ctx); -LI_API handler_t chunk_parser_prepare(chunk_parser_ctx *ctx); -LI_API handler_t chunk_parser_next(struct vrequest *vr, chunk_parser_ctx *ctx, char **p, char **pe); -LI_API void chunk_parser_done(chunk_parser_ctx *ctx, goffset len); +LI_API void chunk_parser_init(liChunkParserCtx *ctx, liChunkQueue *cq); +LI_API void chunk_parser_reset(liChunkParserCtx *ctx); +LI_API liHandlerResult chunk_parser_prepare(liChunkParserCtx *ctx); +LI_API liHandlerResult chunk_parser_next(liVRequest *vr, liChunkParserCtx *ctx, char **p, char **pe); +LI_API void chunk_parser_done(liChunkParserCtx *ctx, goffset len); -LI_API gboolean chunk_extract_to(struct vrequest *vr, chunk_parser_mark from, chunk_parser_mark to, GString *dest); -LI_API GString* chunk_extract(struct vrequest *vr, chunk_parser_mark from, chunk_parser_mark to); +LI_API gboolean chunk_extract_to(liVRequest *vr, liChunkParserMark from, liChunkParserMark to, GString *dest); +LI_API GString* chunk_extract(liVRequest *vr, liChunkParserMark from, liChunkParserMark to); -INLINE chunk_parser_mark chunk_parser_getmark(chunk_parser_ctx *ctx, const char *fpc); +INLINE liChunkParserMark chunk_parser_getmark(liChunkParserCtx *ctx, const char *fpc); /******************** * Inline functions * ********************/ -INLINE chunk_parser_mark chunk_parser_getmark(chunk_parser_ctx *ctx, const char *fpc) { - chunk_parser_mark m; +INLINE liChunkParserMark chunk_parser_getmark(liChunkParserCtx *ctx, const char *fpc) { + liChunkParserMark m; m.ci = ctx->curi; m.pos = ctx->start + fpc - ctx->buf; return m; diff --git a/include/lighttpd/collect.h b/include/lighttpd/collect.h index 9fa4d41..6b3af75 100644 --- a/include/lighttpd/collect.h +++ b/include/lighttpd/collect.h @@ -12,7 +12,7 @@ * - fdata: optional user data * the return value will be placed in the GArray */ -typedef gpointer (*CollectFunc)(worker *wrk, gpointer fdata); +typedef gpointer (*liCollectFuncCB)(liWorker *wrk, gpointer fdata); /** CollectCallback: the type of functions to call after a function was called in each workers context * - cbdata: optional callback data @@ -22,29 +22,13 @@ typedef gpointer (*CollectFunc)(worker *wrk, gpointer fdata); * - complete: determines if cbdata is still valid * if this is FALSE, it may be called from another context than collect_start was called */ -typedef void (*CollectCallback)(gpointer cbdata, gpointer fdata, GPtrArray *result, gboolean complete); +typedef void (*liCollectCB)(gpointer cbdata, gpointer fdata, GPtrArray *result, gboolean complete); -struct collect_info; -typedef struct collect_info collect_info; - -/* internal structure */ -struct collect_info { - worker *wrk; - gint counter; - gboolean stopped; - - CollectFunc func; - gpointer fdata; - - CollectCallback cb; - gpointer cbdata; - - GPtrArray *results; -}; +typedef struct liCollectInfo liCollectInfo; /** collect_start returns NULL if the callback was called directly (e.g. for only one worker and ctx = wrk) */ -LI_API collect_info* collect_start(worker *ctx, CollectFunc func, gpointer fdata, CollectCallback cb, gpointer cbdata); -LI_API void collect_break(collect_info* ci); /** this will result in complete == FALSE in the callback; call it if cbdata gets invalid */ +LI_API liCollectInfo* collect_start(liWorker *ctx, liCollectFuncCB func, gpointer fdata, liCollectCB cb, gpointer cbdata); +LI_API void collect_break(liCollectInfo* ci); /** this will result in complete == FALSE in the callback; call it if cbdata gets invalid */ /* internal functions */ LI_API void collect_watcher_cb(struct ev_loop *loop, ev_async *w, int revents); diff --git a/include/lighttpd/condition.h b/include/lighttpd/condition.h index 009d56d..0f91252 100644 --- a/include/lighttpd/condition.h +++ b/include/lighttpd/condition.h @@ -10,76 +10,76 @@ */ typedef enum { /* everything */ - CONFIG_COND_EQ, /** == */ - CONFIG_COND_NE, /** != */ + LI_CONFIG_COND_EQ, /** == */ + LI_CONFIG_COND_NE, /** != */ /* only with string */ - CONFIG_COND_PREFIX, /** =^ */ - CONFIG_COND_NOPREFIX,/** !^ */ - CONFIG_COND_SUFFIX, /** =$ */ - CONFIG_COND_NOSUFFIX,/** !$ */ + LI_CONFIG_COND_PREFIX, /** =^ */ + LI_CONFIG_COND_NOPREFIX,/** !^ */ + LI_CONFIG_COND_SUFFIX, /** =$ */ + LI_CONFIG_COND_NOSUFFIX,/** !$ */ /* only usable with pcre */ - CONFIG_COND_MATCH, /** =~ */ - CONFIG_COND_NOMATCH, /** !~ */ + LI_CONFIG_COND_MATCH, /** =~ */ + LI_CONFIG_COND_NOMATCH, /** !~ */ - CONFIG_COND_IP, - CONFIG_COND_NOTIP, + LI_CONFIG_COND_IP, + LI_CONFIG_COND_NOTIP, /* only with int */ - CONFIG_COND_GT, /** > */ - CONFIG_COND_GE, /** >= */ - CONFIG_COND_LT, /** < */ - CONFIG_COND_LE /** <= */ -} comp_operator_t; + LI_CONFIG_COND_GT, /** > */ + LI_CONFIG_COND_GE, /** >= */ + LI_CONFIG_COND_LT, /** < */ + LI_CONFIG_COND_LE /** <= */ +} liCompOperator; /** * possible fields to match against */ typedef enum { - COMP_REQUEST_LOCALIP, - COMP_REQUEST_REMOTEIP, - COMP_REQUEST_PATH, - COMP_REQUEST_HOST, - COMP_REQUEST_SCHEME, - COMP_REQUEST_QUERY_STRING, - COMP_REQUEST_METHOD, - COMP_REQUEST_CONTENT_LENGTH, - COMP_PHYSICAL_PATH, - COMP_PHYSICAL_PATH_EXISTS, - COMP_PHYSICAL_SIZE, - COMP_PHYSICAL_ISDIR, - COMP_PHYSICAL_ISFILE, + LI_COMP_REQUEST_LOCALIP, + LI_COMP_REQUEST_REMOTEIP, + LI_COMP_REQUEST_PATH, + LI_COMP_REQUEST_HOST, + LI_COMP_REQUEST_SCHEME, + LI_COMP_REQUEST_QUERY_STRING, + LI_COMP_REQUEST_METHOD, + LI_COMP_REQUEST_CONTENT_LENGTH, + LI_COMP_PHYSICAL_PATH, + LI_COMP_PHYSICAL_PATH_EXISTS, + LI_COMP_PHYSICAL_SIZE, + LI_COMP_PHYSICAL_ISDIR, + LI_COMP_PHYSICAL_ISFILE, /* needs a key */ - COMP_REQUEST_HEADER, /**< needs lowercase key, enforced by condition_lvalue_new */ + LI_COMP_REQUEST_HEADER, /**< needs lowercase key, enforced by condition_lvalue_new */ - COMP_UNKNOWN -} cond_lvalue_t; + LI_COMP_UNKNOWN +} liCondLValue; -#define COND_LVALUE_FIRST_WITH_KEY COMP_REQUEST_HEADER -#define COND_LVALUE_END (1+COMP_REQUEST_HEADER) +#define LI_COND_LVALUE_FIRST_WITH_KEY LI_COMP_REQUEST_HEADER +#define LI_COND_LVALUE_END (1+LI_COMP_REQUEST_HEADER) -struct condition_lvalue { +struct liConditionLValue { int refcount; - cond_lvalue_t type; + liCondLValue type; GString *key; }; typedef enum { - COND_VALUE_BOOL, - COND_VALUE_NUMBER, - COND_VALUE_STRING, + LI_COND_VALUE_BOOL, + LI_COND_VALUE_NUMBER, + LI_COND_VALUE_STRING, #ifdef HAVE_PCRE_H - COND_VALUE_REGEXP, + LI_COND_VALUE_REGEXP, #endif - COND_VALUE_SOCKET_IPV4, /** only match ip/netmask */ - COND_VALUE_SOCKET_IPV6 /** only match ip/netmask */ -} cond_rvalue_t; + LI_COND_VALUE_SOCKET_IPV4, /** only match ip/netmask */ + LI_COND_VALUE_SOCKET_IPV6 /** only match ip/netmask */ +} liCondRValue; -struct condition_rvalue { - cond_rvalue_t type; +struct liConditionRValue { + liCondRValue type; gboolean b; GString *string; @@ -97,31 +97,30 @@ struct condition_rvalue { #include -struct condition { +struct liCondition { int refcount; - comp_operator_t op; - condition_lvalue *lvalue; - condition_rvalue rvalue; + liCompOperator op; + liConditionLValue *lvalue; + liConditionRValue rvalue; }; /* lvalue */ -LI_API condition_lvalue* condition_lvalue_new(cond_lvalue_t type, GString *key); -LI_API void condition_lvalue_acquire(condition_lvalue *lvalue); -LI_API void condition_lvalue_release(condition_lvalue *lvalue); +LI_API liConditionLValue* condition_lvalue_new(liCondLValue type, GString *key); +LI_API void condition_lvalue_acquire(liConditionLValue *lvalue); +LI_API void condition_lvalue_release(liConditionLValue *lvalue); -LI_API condition* condition_new_bool(server *srv, condition_lvalue *lvalue, gboolean b); -LI_API condition* condition_new_string(server *srv, comp_operator_t op, condition_lvalue *lvalue, GString *str); -LI_API condition* condition_new_int(server *srv, comp_operator_t op, condition_lvalue *lvalue, gint64 i); +LI_API liCondition* condition_new_bool(liServer *srv, liConditionLValue *lvalue, gboolean b); +LI_API liCondition* condition_new_string(liServer *srv, liCompOperator op, liConditionLValue *lvalue, GString *str); +LI_API liCondition* condition_new_int(liServer *srv, liCompOperator op, liConditionLValue *lvalue, gint64 i); -LI_API void condition_acquire(condition *c); -LI_API void condition_release(server *srv, condition* c); +LI_API void condition_acquire(liCondition *c); +LI_API void condition_release(liServer *srv, liCondition* c); -LI_API const char* comp_op_to_string(comp_operator_t op); -LI_API const char* cond_lvalue_to_string(cond_lvalue_t t); -LI_API cond_lvalue_t cond_lvalue_from_string(const gchar *str, guint len); +LI_API const char* comp_op_to_string(liCompOperator op); +LI_API const char* cond_lvalue_to_string(liCondLValue t); +LI_API liCondLValue cond_lvalue_from_string(const gchar *str, guint len); -struct vrequest; -LI_API handler_t condition_check(struct vrequest *vr, condition *cond, gboolean *result); +LI_API liHandlerResult condition_check(liVRequest *vr, liCondition *cond, gboolean *result); #endif diff --git a/include/lighttpd/condition_lua.h b/include/lighttpd/condition_lua.h index dd37286..cb14da2 100644 --- a/include/lighttpd/condition_lua.h +++ b/include/lighttpd/condition_lua.h @@ -4,9 +4,9 @@ #include #include -condition* lua_get_condition(lua_State *L, int ndx); -int lua_push_condition(server *srv, lua_State *L, condition *c); +liCondition* lua_get_condition(lua_State *L, int ndx); +int lua_push_condition(liServer *srv, lua_State *L, liCondition *c); -void lua_push_lvalues_dict(server *srv, lua_State *L); +void lua_push_lvalues_dict(liServer *srv, lua_State *L); #endif diff --git a/include/lighttpd/config_lua.h b/include/lighttpd/config_lua.h index f0ea28f..a36c281 100644 --- a/include/lighttpd/config_lua.h +++ b/include/lighttpd/config_lua.h @@ -3,6 +3,6 @@ #include -LI_API gboolean config_lua_load(server *srv, const gchar *filename); +LI_API gboolean config_lua_load(liServer *srv, const gchar *filename); #endif diff --git a/include/lighttpd/config_parser.h b/include/lighttpd/config_parser.h index 2b9586f..a88d510 100644 --- a/include/lighttpd/config_parser.h +++ b/include/lighttpd/config_parser.h @@ -3,31 +3,30 @@ #include -struct config_parser_context_t; -typedef struct config_parser_context_t config_parser_context_t; +typedef struct liConfigParserContext liConfigParserContext; /* returns a new config parser stack with the first context in it */ -GList *config_parser_init(server *srv); -void config_parser_finish(server *srv, GList *ctx_stack, gboolean free_all); +GList *config_parser_init(liServer *srv); +void config_parser_finish(liServer *srv, GList *ctx_stack, gboolean free_all); /* loads a file into memory and parses it */ -gboolean config_parser_file(server *srv, GList *ctx_stack, const gchar *path); +gboolean config_parser_file(liServer *srv, GList *ctx_stack, const gchar *path); /* launched a command through the shell and parses the stdout it returns */ -gboolean config_parser_shell(server *srv,GList *ctx_stack, const gchar *command); +gboolean config_parser_shell(liServer *srv,GList *ctx_stack, const gchar *command); /* parses a buffer pointed to by the previously allocated config_parser_data struct */ -gboolean config_parser_buffer(server *srv, GList *ctx_stack); +gboolean config_parser_buffer(liServer *srv, GList *ctx_stack); -config_parser_context_t *config_parser_context_new(server *srv, GList *ctx_stack); -void config_parser_context_free(server *srv, config_parser_context_t *ctx, gboolean free_queues); +liConfigParserContext *config_parser_context_new(liServer *srv, GList *ctx_stack); +void config_parser_context_free(liServer *srv, liConfigParserContext *ctx, gboolean free_queues); typedef enum { - CFG_PARSER_CAST_NONE, - CFG_PARSER_CAST_INT, - CFG_PARSER_CAST_STR -} cast_type; + LI_CFG_PARSER_CAST_NONE, + LI_CFG_PARSER_CAST_INT, + LI_CFG_PARSER_CAST_STR +} liCastType; -struct config_parser_context_t { +struct liConfigParserContext { /* ragel vars */ int cs; int *stack; @@ -43,16 +42,16 @@ struct config_parser_context_t { gboolean condition_nonbool; gboolean condition_negated; - comp_operator_t op; + liCompOperator op; gchar value_op; - cast_type cast; + liCastType cast; GHashTable *action_blocks; /* foo { } */ GHashTable *uservars; /* var.foo */ GQueue *action_list_stack; /* first entry is current action list */ - GQueue *option_stack; /* stack of value* */ + GQueue *option_stack; /* stack of liValue* */ GQueue *condition_stack; /* stack of condition* */ /* information about currenty parsed file */ diff --git a/include/lighttpd/connection.h b/include/lighttpd/connection.h index 409657a..fb4e974 100644 --- a/include/lighttpd/connection.h +++ b/include/lighttpd/connection.h @@ -7,43 +7,43 @@ typedef enum { /** unused */ - CON_STATE_DEAD, + LI_CON_STATE_DEAD, /** waiting for new input after first request */ - CON_STATE_KEEP_ALIVE, + LI_CON_STATE_KEEP_ALIVE, /** after the connect, the request is initialized */ - CON_STATE_REQUEST_START, + LI_CON_STATE_REQUEST_START, /** loop in the read-request-header until the full header is received */ - CON_STATE_READ_REQUEST_HEADER, + LI_CON_STATE_READ_REQUEST_HEADER, /** handle in main virtual request */ - CON_STATE_HANDLE_MAINVR, + LI_CON_STATE_HANDLE_MAINVR, /** write remaining bytes from raw_out, mainvr finished (or not started) */ - CON_STATE_WRITE, -} connection_state_t; + LI_CON_STATE_WRITE, +} liConnectionState; -struct connection { +struct liConnection { guint idx; /** index in connection table */ - server *srv; - worker *wrk; - server_socket *srv_sock; + liServer *srv; + liWorker *wrk; + liServerSocket *srv_sock; - connection_state_t state; + liConnectionState state; gboolean response_headers_sent, expect_100_cont; - chunkqueue *raw_in, *raw_out; - chunkqueue *in, *out; /* link to mainvr->in/out */ + liChunkQueue *raw_in, *raw_out; + liChunkQueue *in, *out; /* link to mainvr->in/out */ ev_io sock_watcher; - sockaddr_t remote_addr; + liSocketAddress remote_addr; GString *remote_addr_str; gboolean is_ssl, keep_alive; - vrequest *mainvr; - http_request_ctx req_parser_ctx; + liVRequest *mainvr; + liHttpRequestCtx req_parser_ctx; /* Keep alive timeout data */ struct { @@ -55,19 +55,19 @@ struct connection { guint keep_alive_requests; /* I/O timeout data */ - waitqueue_elem io_timeout_elem; + liWaitQueueElem io_timeout_elem; /* I/O throttling */ gboolean throttled; /* TRUE if connection is throttled */ struct { struct { - throttle_pool_t *ptr; /* NULL if not in any throttling pool */ + liThrottlePool *ptr; /* NULL if not in any throttling pool */ GList lnk; gboolean queued; gint magazine; } pool; struct { - throttle_pool_t *ptr; /* pool for per-ip throttling, NULL if not limited by ip */ + liThrottlePool *ptr; /* pool for per-ip throttling, NULL if not limited by ip */ GList lnk; gboolean queued; gint magazine; @@ -77,7 +77,7 @@ struct connection { gint magazine; ev_tstamp last_update; } con; - waitqueue_elem wqueue_elem; + liWaitQueueElem wqueue_elem; } throttle; ev_tstamp ts; @@ -93,17 +93,17 @@ struct connection { } stats; }; -LI_API connection* connection_new(worker *wrk); -LI_API void connection_reset(connection *con); -LI_API void connection_reset_keep_alive(connection *con); -LI_API void connection_free(connection *con); +LI_API liConnection* connection_new(liWorker *wrk); +LI_API void connection_reset(liConnection *con); +LI_API void connection_reset_keep_alive(liConnection *con); +LI_API void connection_free(liConnection *con); -LI_API void connection_error(connection *con); -LI_API void connection_internal_error(connection *con); +LI_API void connection_error(liConnection *con); +LI_API void connection_internal_error(liConnection *con); -LI_API void connection_handle_direct(connection *con); -LI_API void connection_handle_indirect(connection *con, plugin *p); +LI_API void connection_handle_direct(liConnection *con); +LI_API void connection_handle_indirect(liConnection *con, liPlugin *p); -LI_API gchar *connection_state_str(connection_state_t state); +LI_API gchar *connection_state_str(liConnectionState state); #endif diff --git a/include/lighttpd/encoding.h b/include/lighttpd/encoding.h index 3ab8864..a0dc8b7 100644 --- a/include/lighttpd/encoding.h +++ b/include/lighttpd/encoding.h @@ -1,9 +1,7 @@ #ifndef _LIGHTTPD_ENCODING_H_ #define _LIGHTTPD_ENCODING_H_ -#ifndef _LIGHTTPD_BASE_H_ -#error Please include instead of this file -#endif +#include typedef enum { ENCODING_HEX, /* a => 61 */ diff --git a/include/lighttpd/environment.h b/include/lighttpd/environment.h index 28591cf..cf41dc5 100644 --- a/include/lighttpd/environment.h +++ b/include/lighttpd/environment.h @@ -1,39 +1,41 @@ #ifndef _LIGHTTPD_ENVIRONMENT_H_ #define _LIGHTTPD_ENVIRONMENT_H_ -#ifndef _LIGHTTPD_BASE_H_ -#error Please include instead of this file -#endif +#include + +typedef struct liEnvironment liEnvironment; + +typedef struct liEnvironmentDup liEnvironmentDup; -struct environment { +struct liEnvironment { GHashTable *table; }; /* read only duplicate of a real environment: use it to remember which env vars you already sent (mod_fastcgi) */ -struct environment_dup { +struct liEnvironmentDup { GHashTable *table; }; -LI_API void environment_init(environment *env); -LI_API void environment_reset(environment *env); -LI_API void environment_clear(environment *env); +LI_API void environment_init(liEnvironment *env); +LI_API void environment_reset(liEnvironment *env); +LI_API void environment_clear(liEnvironment *env); /* overwrite previous value */ -LI_API void environment_set(environment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); +LI_API void environment_set(liEnvironment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); /* do not overwrite */ -LI_API void environment_insert(environment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); -LI_API void environment_remove(environment *env, const gchar *key, size_t keylen); -LI_API GString* environment_get(environment *env, const gchar *key, size_t keylen); +LI_API void environment_insert(liEnvironment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); +LI_API void environment_remove(liEnvironment *env, const gchar *key, size_t keylen); +LI_API GString* environment_get(liEnvironment *env, const gchar *key, size_t keylen); /* create (data) read only copy of a environment; don't modify the real environment while using the duplicate */ -LI_API environment_dup* environment_make_dup(environment *env); -LI_API void environment_dup_free(environment_dup *envdup); +LI_API liEnvironmentDup* environment_make_dup(liEnvironment *env); +LI_API void environment_dup_free(liEnvironmentDup *envdup); /* remove an entry (this is allowed - it doesn't modify anything in the original environment); you must not modify the returned GString */ -LI_API GString* environment_dup_pop(environment_dup *envdup, const gchar *key, size_t keylen); +LI_API GString* environment_dup_pop(liEnvironmentDup *envdup, const gchar *key, size_t keylen); #endif diff --git a/include/lighttpd/etag.h b/include/lighttpd/etag.h index 34bc603..31ce2d4 100644 --- a/include/lighttpd/etag.h +++ b/include/lighttpd/etag.h @@ -5,13 +5,11 @@ #error Please include instead of this file #endif -typedef enum { TRI_FALSE, TRI_MAYBE, TRI_TRUE } tristate_t; - -LI_API tristate_t http_response_handle_cachable_etag(vrequest *vr, GString *etag); -LI_API tristate_t http_response_handle_cachable_modified(vrequest *vr, GString *last_modified); +LI_API tristate_t http_response_handle_cachable_etag(liVRequest *vr, GString *etag); +LI_API tristate_t http_response_handle_cachable_modified(liVRequest *vr, GString *last_modified); /* mut maybe the same as etag */ LI_API void etag_mutate(GString *mut, GString *etag); -LI_API void etag_set_header(vrequest *vr, struct stat *st, gboolean *cachable); +LI_API void etag_set_header(liVRequest *vr, struct stat *st, gboolean *cachable); #endif diff --git a/include/lighttpd/filter_chunked.h b/include/lighttpd/filter_chunked.h index ee071d3..77cd850 100644 --- a/include/lighttpd/filter_chunked.h +++ b/include/lighttpd/filter_chunked.h @@ -3,7 +3,7 @@ #include -LI_API handler_t filter_chunked_encode(connection *con, chunkqueue *out, chunkqueue *in); -LI_API handler_t filter_chunked_decode(connection *con, chunkqueue *out, chunkqueue *in); +LI_API liHandlerResult filter_chunked_encode(liConnection *con, liChunkQueue *out, liChunkQueue *in); +LI_API liHandlerResult filter_chunked_decode(liConnection *con, liChunkQueue *out, liChunkQueue *in); #endif diff --git a/include/lighttpd/http_headers.h b/include/lighttpd/http_headers.h index 8504838..da55fdf 100644 --- a/include/lighttpd/http_headers.h +++ b/include/lighttpd/http_headers.h @@ -11,43 +11,43 @@ #define HEADER_VALUE_LEN(h) \ (&(h)->data->str[h->keylen + 2]), ((h)->data->len - (h->keylen + 2)) -struct http_header { +struct liHttpHeader { guint keylen; /** length of "headername" in data */ GString *data; /** "headername: value" */ }; -struct http_headers { +struct liHttpHeaders { GQueue entries; }; /* strings alweays get copied, so you should free key and value yourself */ -LI_API http_headers* http_headers_new(); -LI_API void http_headers_reset(http_headers* headers); -LI_API void http_headers_free(http_headers* headers); +LI_API liHttpHeaders* http_headers_new(); +LI_API void http_headers_reset(liHttpHeaders* headers); +LI_API void http_headers_free(liHttpHeaders* headers); /** If header does not exist, just insert normal header. If it exists, append (", %s", value) */ -LI_API void http_header_append(http_headers *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); +LI_API void http_header_append(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); /** If header does not exist, just insert normal header. If it exists, append ("\r\n%s: %s", key, value) */ -LI_API void http_header_insert(http_headers *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); +LI_API void http_header_insert(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); /** If header does not exist, just insert normal header. If it exists, overwrite the value */ -LI_API void http_header_overwrite(http_headers *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); -LI_API gboolean http_header_remove(http_headers *headers, const gchar *key, size_t keylen); -LI_API void http_header_remove_link(http_headers *headers, GList *l); +LI_API void http_header_overwrite(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); +LI_API gboolean http_header_remove(liHttpHeaders *headers, const gchar *key, size_t keylen); +LI_API void http_header_remove_link(liHttpHeaders *headers, GList *l); -LI_API http_header* http_header_lookup(http_headers *headers, const gchar *key, size_t keylen); +LI_API liHttpHeader* http_header_lookup(liHttpHeaders *headers, const gchar *key, size_t keylen); -LI_API GList* http_header_find_first(http_headers *headers, const gchar *key, size_t keylen); +LI_API GList* http_header_find_first(liHttpHeaders *headers, const gchar *key, size_t keylen); LI_API GList* http_header_find_next(GList *l, const gchar *key, size_t keylen); -LI_API GList* http_header_find_last(http_headers *headers, const gchar *key, size_t keylen); +LI_API GList* http_header_find_last(liHttpHeaders *headers, const gchar *key, size_t keylen); /** Use lowercase keys! values are compared case-insensitive */ -LI_API gboolean http_header_is(http_headers *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); +LI_API gboolean http_header_is(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); /** concats all headers with key with ', ' - empty if no header exists - use lowercase key*/ -LI_API void http_header_get_fast(GString *dest, http_headers *headers, const gchar *key, size_t keylen); +LI_API void http_header_get_fast(GString *dest, liHttpHeaders *headers, const gchar *key, size_t keylen); -INLINE gboolean http_header_key_is(http_header *h, const gchar *key, size_t keylen) { +INLINE gboolean http_header_key_is(liHttpHeader *h, const gchar *key, size_t keylen) { return (h->keylen == keylen && 0 == g_ascii_strncasecmp(key, h->data->str, keylen)); } diff --git a/include/lighttpd/http_request_parser.h b/include/lighttpd/http_request_parser.h index fb99122..b917b2a 100644 --- a/include/lighttpd/http_request_parser.h +++ b/include/lighttpd/http_request_parser.h @@ -5,22 +5,19 @@ #error Please include instead of this file #endif -struct http_request_ctx; -typedef struct http_request_ctx http_request_ctx; +struct liHttpRequestCtx { + liChunkParserCtx chunk_ctx; + liRequest *request; -struct http_request_ctx { - chunk_parser_ctx chunk_ctx; - struct request *request; - - chunk_parser_mark mark; + liChunkParserMark mark; GString *h_key, *h_value; }; -LI_API void http_request_parser_init(http_request_ctx* ctx, request *req, chunkqueue *cq); -LI_API void http_request_parser_reset(http_request_ctx* ctx); -LI_API void http_request_parser_clear(http_request_ctx *ctx); +LI_API void http_request_parser_init(liHttpRequestCtx* ctx, liRequest *req, liChunkQueue *cq); +LI_API void http_request_parser_reset(liHttpRequestCtx* ctx); +LI_API void http_request_parser_clear(liHttpRequestCtx *ctx); -LI_API handler_t http_request_parse(vrequest *vr, http_request_ctx *ctx); +LI_API liHandlerResult http_request_parse(liVRequest *vr, liHttpRequestCtx *ctx); #endif diff --git a/include/lighttpd/http_response_parser.h b/include/lighttpd/http_response_parser.h index b8f88d6..dc2dbcf 100644 --- a/include/lighttpd/http_response_parser.h +++ b/include/lighttpd/http_response_parser.h @@ -5,24 +5,21 @@ #error Please include instead of this file #endif -struct http_response_ctx; -typedef struct http_response_ctx http_response_ctx; - -struct http_response_ctx { - chunk_parser_ctx chunk_ctx; - struct response *response; +struct liHttpResponseCtx { + liChunkParserCtx chunk_ctx; + liResponse *response; gboolean accept_cgi, accept_nph; - chunk_parser_mark mark; + liChunkParserMark mark; GString *h_key, *h_value; }; -LI_API void http_response_parser_init(http_response_ctx* ctx, response *req, chunkqueue *cq, gboolean accept_cgi, gboolean accept_nph); -LI_API void http_response_parser_reset(http_response_ctx* ctx); -LI_API void http_response_parser_clear(http_response_ctx *ctx); +LI_API void http_response_parser_init(liHttpResponseCtx* ctx, liResponse *req, liChunkQueue *cq, gboolean accept_cgi, gboolean accept_nph); +LI_API void http_response_parser_reset(liHttpResponseCtx* ctx); +LI_API void http_response_parser_clear(liHttpResponseCtx *ctx); -LI_API handler_t http_response_parse(vrequest *vr, http_response_ctx *ctx); +LI_API liHandlerResult http_response_parse(liVRequest *vr, liHttpResponseCtx *ctx); #endif diff --git a/include/lighttpd/idlist.h b/include/lighttpd/idlist.h index ee25ee6..25ab09c 100644 --- a/include/lighttpd/idlist.h +++ b/include/lighttpd/idlist.h @@ -3,9 +3,9 @@ #include -typedef struct idlist idlist; +typedef struct liIDList liIDList; -struct idlist { +struct liIDList { /* used ids are marked with a "1" in the bitvector (represented as array of gulong) */ GArray *bitvector; @@ -24,18 +24,18 @@ struct idlist { }; /* create new idlist; the parameter max_ids is "signed" on purpose */ -LI_API idlist* idlist_new(gint max_ids); +LI_API liIDList* idlist_new(gint max_ids); /* free idlist */ -LI_API void idlist_free(idlist *l); +LI_API void idlist_free(liIDList *l); /* request new id; return -1 if no id is available, valid ids are always > 0 */ -LI_API gint idlist_get(idlist *l); +LI_API gint idlist_get(liIDList *l); /* check whether an id is in use and can be "_put" */ -LI_API gboolean idlist_is_used(idlist *l, gint id); +LI_API gboolean idlist_is_used(liIDList *l, gint id); /* release id. never release an id more than once! */ -LI_API void idlist_put(idlist *l, gint id); +LI_API void idlist_put(liIDList *l, gint id); #endif diff --git a/include/lighttpd/lighttpd-glue.h b/include/lighttpd/lighttpd-glue.h index 3f9ad7c..44a54ef 100644 --- a/include/lighttpd/lighttpd-glue.h +++ b/include/lighttpd/lighttpd-glue.h @@ -8,13 +8,13 @@ /* returns the description for a given http status code and sets the len to the length of the returned string */ LI_API gchar *http_status_string(guint status_code, guint *len); /* returns the http method as a string and sets len to the length of the returned string */ -LI_API gchar *http_method_string(http_method_t method, guint *len); +LI_API gchar *http_method_string(liHttpMethod method, guint *len); /* returns the http version as a string and sets len to the length of the returned string */ -LI_API gchar *http_version_string(http_version_t method, guint *len); +LI_API gchar *http_version_string(liHttpVersion method, guint *len); /* converts a given 3 digit http status code to a gchar[3] string. e.g. 403 to {'4','0','3'} */ LI_API void http_status_to_str(gint status_code, gchar status_str[]); /* looks up the mimetype for a filename by comparing suffixes. first match is returned. do not free the result */ -LI_API GString *mimetype_get(vrequest *vr, GString *filename); +LI_API GString *mimetype_get(liVRequest *vr, GString *filename); #endif diff --git a/include/lighttpd/log.h b/include/lighttpd/log.h index 3589e2a..f76009f 100644 --- a/include/lighttpd/log.h +++ b/include/lighttpd/log.h @@ -17,27 +17,27 @@ LI_API const char *remove_path(const char *path); #define _SEGFAULT(srv, vr, fmt, ...) \ do { \ - log_write_(srv, NULL, LOG_LEVEL_ABORT, LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \ + log_write_(srv, NULL, LI_LOG_LEVEL_ABORT, LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \ /* VALGRIND_PRINTF_BACKTRACE(fmt, __VA_ARGS__); */\ abort();\ } while(0) #define _ERROR(srv, vr, fmt, ...) \ - log_write_(srv, vr, LOG_LEVEL_ERROR, LOG_FLAG_TIMESTAMP, "(error) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + log_write_(srv, vr, LI_LOG_LEVEL_ERROR, LOG_FLAG_TIMESTAMP, "(error) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define _WARNING(srv, vr, fmt, ...) \ - log_write_(srv, vr, LOG_LEVEL_WARNING, LOG_FLAG_TIMESTAMP, "(warning) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + log_write_(srv, vr, LI_LOG_LEVEL_WARNING, LOG_FLAG_TIMESTAMP, "(warning) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define _INFO(srv, vr, fmt, ...) \ - log_write_(srv, vr, LOG_LEVEL_INFO, LOG_FLAG_TIMESTAMP, "(info) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + log_write_(srv, vr, LI_LOG_LEVEL_INFO, LOG_FLAG_TIMESTAMP, "(info) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define _DEBUG(srv, vr, fmt, ...) \ - log_write_(srv, vr, LOG_LEVEL_DEBUG, LOG_FLAG_TIMESTAMP, "(debug) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + log_write_(srv, vr, LI_LOG_LEVEL_DEBUG, LOG_FLAG_TIMESTAMP, "(debug) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define _BACKEND(srv, vr, fmt, ...) \ - log_write_(srv, vr, LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, "(backend) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + log_write_(srv, vr, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, "(backend) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define _BACKEND_LINES(srv, vr, txt, fmt, ...) \ - log_split_lines_(srv, vr, LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, txt, "(backend) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + log_split_lines_(srv, vr, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, txt, "(backend) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define VR_SEGFAULT(vr, fmt, ...) _SEGFAULT(vr->wrk->srv, vr, fmt, __VA_ARGS__) @@ -55,41 +55,14 @@ LI_API const char *remove_path(const char *path); #define DEBUG(srv, fmt, ...) _DEBUG(srv, NULL, fmt, __VA_ARGS__) #define BACKEND(srv, fmt, ...) _BACKEND(srv, NULL, fmt, __VA_ARGS__) - -struct log_t; -typedef struct log_t log_t; - -struct log_entry_t; -typedef struct log_entry_t log_entry_t; - -struct log_timestamp_t; -typedef struct log_timestamp_t log_timestamp_t; - -typedef enum { - LOG_LEVEL_DEBUG, - LOG_LEVEL_INFO, - LOG_LEVEL_WARNING, - LOG_LEVEL_ERROR, - LOG_LEVEL_ABORT, - LOG_LEVEL_BACKEND -} log_level_t; - -typedef enum { - LOG_TYPE_STDERR, - LOG_TYPE_FILE, - LOG_TYPE_PIPE, - LOG_TYPE_SYSLOG, - LOG_TYPE_NONE -} log_type_t; - /* flags for log_write */ #define LOG_FLAG_NONE (0x0) /* default flag */ #define LOG_FLAG_TIMESTAMP (0x1) /* prepend a timestamp to the log message */ #define LOG_FLAG_NOLOCK (0x1 << 1) /* for internal use only */ #define LOG_FLAG_ALLOW_REPEAT (0x1 << 2) /* allow writing of multiple equal entries after each other */ -struct log_t { - log_type_t type; +struct liLog { + liLogType type; GString *path; gint refcount; gint fd; @@ -100,62 +73,62 @@ struct log_t { GMutex *mutex; }; -struct log_timestamp_t { +struct liLogTimestamp { gint refcount; ev_tstamp last_ts; GString *format; GString *cached; }; -struct log_entry_t { - log_t *log; - log_level_t level; +struct liLogEntry { + liLog *log; + liLogLevel level; GString *msg; }; /* determines the type of a log target by the path given. /absolute/path = file; |app = pipe; stderr = stderr; syslog = syslog */ -log_type_t log_type_from_path(GString *path); +liLogType log_type_from_path(GString *path); -log_level_t log_level_from_string(GString *str); -gchar* log_level_str(log_level_t log_level); +liLogLevel log_level_from_string(GString *str); +gchar* log_level_str(liLogLevel log_level); /* log_new is used to create a new log target, if a log with the same path already exists, it is referenced instead */ -log_t *log_new(server *srv, log_type_t type, GString *path); +liLog *log_new(liServer *srv, liLogType type, GString *path); /* avoid calling log_free directly. instead use log_unref which calls log_free if refcount has reached zero */ -void log_free(server *srv, log_t *log); -void log_free_unlocked(server *srv, log_t *log); +void log_free(liServer *srv, liLog *log); +void log_free_unlocked(liServer *srv, liLog *log); -void log_ref(server *srv, log_t *log); -void log_unref(server *srv, log_t *log); +void log_ref(liServer *srv, liLog *log); +void log_unref(liServer *srv, liLog *log); -void log_lock(log_t *log); -void log_unlock(log_t *log); +void log_lock(liLog *log); +void log_unlock(liLog *log); /* do not call directly, use log_rotate_logs instead */ -void log_rotate(gchar *path, log_t *log, server *srv); +void log_rotate(gchar *path, liLog *log, liServer *srv); -void log_rotate_logs(server *srv); +void log_rotate_logs(liServer *srv); -gpointer log_thread(server *srv); -void log_thread_start(server *srv); -void log_thread_stop(server *srv); -void log_thread_finish(server *srv); -void log_thread_wakeup(server *srv); +gpointer log_thread(liServer *srv); +void log_thread_start(liServer *srv); +void log_thread_stop(liServer *srv); +void log_thread_finish(liServer *srv); +void log_thread_wakeup(liServer *srv); -void log_init(server *srv); -void log_cleanup(server *srv); +void log_init(liServer *srv); +void log_cleanup(liServer *srv); /* log_write is used to directly write a message to a log target */ -LI_API void log_write(server *srv, log_t *log, GString *msg); +LI_API void log_write(liServer *srv, liLog *log, GString *msg); /* log_write_ is used to write to the errorlog */ -LI_API gboolean log_write_(server *srv, vrequest *vr, log_level_t log_level, guint flags, const gchar *fmt, ...) G_GNUC_PRINTF(5, 6); +LI_API gboolean log_write_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, const gchar *fmt, ...) G_GNUC_PRINTF(5, 6); -LI_API log_timestamp_t *log_timestamp_new(server *srv, GString *format); -LI_API gboolean log_timestamp_free(server *srv, log_timestamp_t *ts); +LI_API liLogTimestamp *log_timestamp_new(liServer *srv, GString *format); +LI_API gboolean log_timestamp_free(liServer *srv, liLogTimestamp *ts); /* replaces '\r' and '\n' with '\0' */ -LI_API void log_split_lines(server *srv, vrequest *vr, log_level_t log_level, guint flags, gchar *txt, const gchar *prefix); -LI_API void log_split_lines_(server *srv, vrequest *vr, log_level_t log_level, guint flags, gchar *txt, const gchar *fmt, ...) G_GNUC_PRINTF(6, 7); +LI_API void log_split_lines(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, gchar *txt, const gchar *prefix); +LI_API void log_split_lines_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, gchar *txt, const gchar *fmt, ...) G_GNUC_PRINTF(6, 7); #endif diff --git a/include/lighttpd/module.h b/include/lighttpd/module.h index 2e780aa..e09e7bc 100644 --- a/include/lighttpd/module.h +++ b/include/lighttpd/module.h @@ -22,27 +22,25 @@ return FALSE; \ } } while(0) -struct module; -typedef struct module module; +typedef struct liModule liModule; -struct modules; -typedef struct modules modules; +typedef struct liModules liModules; /** Type of plugin_init function in modules */ -typedef gboolean (*ModuleInit)(modules *mods, module *mod); -typedef gboolean (*ModuleFree)(modules *mods, module *mod); +typedef gboolean (*liModuleInitCB)(liModules *mods, liModule *mod); +typedef gboolean (*liModuleFreeCB)(liModules *mods, liModule *mod); -struct module { +struct liModule { gint refcount; /**< count how often module is used. module gets unloaded if refcount reaches zero. */ GString *name; /**< name of module, can be set my plugin_init */ GModule *module; /**< glib handle */ gchar *path; /**< path to the module file */ gpointer config; /**< private module data */ - ModuleFree free; /**< if set by plugin_init it gets called before module is unloaded */ + liModuleFreeCB free; /**< if set by plugin_init it gets called before module is unloaded */ }; -struct modules { +struct liModules { guint version; /**< api version */ gpointer main; /**< pointer to a application specific main structure, e.g. server */ @@ -52,20 +50,20 @@ struct modules { guint8 sizeof_off_t; /** holds the value of sizeof(off_t) to check if loaded module was compiled with the same flags */ }; -LI_API modules* modules_new(gpointer main, const gchar *module_dir); -LI_API void modules_free(modules *mods); +LI_API liModules* modules_new(gpointer main, const gchar *module_dir); +LI_API void modules_free(liModules *mods); /** Loads a module if not loaded yet and returns the module struct for it (after increasing refcount) * returns NULL if it couldn't load the module. * * You should release modules after you used them with module_release or module_release_name */ -LI_API module* module_load(modules *mods, const gchar* name); +LI_API liModule* module_load(liModules *mods, const gchar* name); /* find module by name */ -LI_API module *module_lookup(modules *mods, const gchar *name); +LI_API liModule *module_lookup(liModules *mods, const gchar *name); -LI_API void module_acquire(module *mod); -LI_API void module_release(modules *mods, module *mod); -LI_API void module_release_name(modules *mods, const gchar* name); +LI_API void module_acquire(liModule *mod); +LI_API void module_release(liModules *mods, liModule *mod); +LI_API void module_release_name(liModules *mods, const gchar* name); #endif diff --git a/include/lighttpd/network.h b/include/lighttpd/network.h index bc60811..23c6aab 100644 --- a/include/lighttpd/network.h +++ b/include/lighttpd/network.h @@ -10,13 +10,13 @@ #endif typedef enum { - NETWORK_STATUS_SUCCESS, /**< some IO was actually done (read/write) or cq was empty for write */ - NETWORK_STATUS_FATAL_ERROR, - NETWORK_STATUS_CONNECTION_CLOSE, - NETWORK_STATUS_WAIT_FOR_EVENT, /**< read/write returned -1 with errno=EAGAIN/EWOULDBLOCK; no real IO was done - internal: some io may be done */ - NETWORK_STATUS_WAIT_FOR_AIO_EVENT /**< nothing done yet, read/write will be done somewhere else */ -} network_status_t; + LI_NETWORK_STATUS_SUCCESS, /**< some IO was actually done (read/write) or cq was empty for write */ + LI_NETWORK_STATUS_FATAL_ERROR, + LI_NETWORK_STATUS_CONNECTION_CLOSE, + LI_NETWORK_STATUS_WAIT_FOR_EVENT, /**< read/write returned -1 with errno=EAGAIN/EWOULDBLOCK; no real IO was done + internal: some io may be done */ + LI_NETWORK_STATUS_WAIT_FOR_AIO_EVENT /**< nothing done yet, read/write will be done somewhere else */ +} liNetworkStatus; /** repeats write after EINTR */ LI_API ssize_t net_write(int fd, void *buf, ssize_t nbyte); @@ -24,25 +24,25 @@ LI_API ssize_t net_write(int fd, void *buf, ssize_t nbyte); /** repeats read after EINTR */ LI_API ssize_t net_read(int fd, void *buf, ssize_t nbyte); -LI_API network_status_t network_write(vrequest *vr, int fd, chunkqueue *cq, goffset write_max); -LI_API network_status_t network_read(vrequest *vr, int fd, chunkqueue *cq); +LI_API liNetworkStatus network_write(liVRequest *vr, int fd, liChunkQueue *cq, goffset write_max); +LI_API liNetworkStatus network_read(liVRequest *vr, int fd, liChunkQueue *cq); /* use writev for mem chunks, buffered read/write for files */ -LI_API network_status_t network_write_writev(vrequest *vr, int fd, chunkqueue *cq, goffset *write_max); +LI_API liNetworkStatus network_write_writev(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max); #ifdef USE_SENDFILE /* use sendfile for files, writev for mem chunks */ -LI_API network_status_t network_write_sendfile(vrequest *vr, int fd, chunkqueue *cq, goffset *write_max); +LI_API liNetworkStatus network_write_sendfile(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max); #endif /* write backends */ -LI_API network_status_t network_backend_write(vrequest *vr, int fd, chunkqueue *cq, goffset *write_max); -LI_API network_status_t network_backend_writev(vrequest *vr, int fd, chunkqueue *cq, goffset *write_max); +LI_API liNetworkStatus network_backend_write(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max); +LI_API liNetworkStatus network_backend_writev(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max); -#define NETWORK_FALLBACK(f, write_max) do { \ - network_status_t res; \ +#define LI_NETWORK_FALLBACK(f, write_max) do { \ + liNetworkStatus res; \ switch(res = f(vr, fd, cq, write_max)) { \ - case NETWORK_STATUS_SUCCESS: \ + case LI_NETWORK_STATUS_SUCCESS: \ break; \ default: \ return res; \ diff --git a/include/lighttpd/options.h b/include/lighttpd/options.h index e5fac32..c17a343 100644 --- a/include/lighttpd/options.h +++ b/include/lighttpd/options.h @@ -5,7 +5,7 @@ #error Please include instead of this file #endif -union option_value { +union liOptionValue { gpointer ptr; gint64 number; gboolean boolean; @@ -14,21 +14,21 @@ union option_value { GString *string; GArray *list; GHashTable *hash; - action *action; - condition *cond; + liAction *action; + liCondition *cond; }; -struct option_set { +struct liOptionSet { size_t ndx; - option_value value; - server_option *sopt; + liOptionValue value; + liServerOption *sopt; }; /* Extract content from value, value set to none */ -LI_API option_value value_extract(value *val); +LI_API liOptionValue value_extract(liValue *val); -LI_API gpointer value_extract_ptr(value *val); -LI_API gint64 value_extract_number(value *val); -LI_API gboolean value_extract_bool(value *val); +LI_API gpointer value_extract_ptr(liValue *val); +LI_API gint64 value_extract_number(liValue *val); +LI_API gboolean value_extract_bool(liValue *val); #endif diff --git a/include/lighttpd/plugin.h b/include/lighttpd/plugin.h index 9515f17..f6a8ec6 100644 --- a/include/lighttpd/plugin.h +++ b/include/lighttpd/plugin.h @@ -12,18 +12,18 @@ size_t id; \ ssize_t option_base_ndx -typedef void (*PluginInit) (server *srv, plugin *p); -typedef void (*PluginFree) (server *srv, plugin *p); -typedef gboolean (*PluginParseOption) (server *srv, plugin *p, size_t ndx, value *val, option_value *oval); -typedef void (*PluginFreeOption) (server *srv, plugin *p, size_t ndx, option_value oval); -typedef action* (*PluginCreateAction) (server *srv, plugin *p, value *val); -typedef gboolean (*PluginSetup) (server *srv, plugin *p, value *val); - -typedef void (*PluginHandleClose) (connection *con, plugin *p); -typedef handler_t(*PluginHandleVRequest)(vrequest *vr, plugin *p); -typedef void (*PluginHandleVRClose) (vrequest *vr, plugin *p); - -struct plugin { +typedef void (*liPluginInitCB) (liServer *srv, liPlugin *p); +typedef void (*liPluginFreeCB) (liServer *srv, liPlugin *p); +typedef gboolean (*liPluginParseOptionCB) (liServer *srv, liPlugin *p, size_t ndx, liValue *val, liOptionValue *oval); +typedef void (*liPluginFreeOptionCB) (liServer *srv, liPlugin *p, size_t ndx, liOptionValue oval); +typedef liAction*(*liPluginCreateActionCB) (liServer *srv, liPlugin *p, liValue *val); +typedef gboolean (*liPluginSetupCB) (liServer *srv, liPlugin *p, liValue *val); + +typedef void (*liPluginHandleCloseCB) (liConnection *con, liPlugin *p); +typedef liHandlerResult(*liPluginHandleVRequestCB)(liVRequest *vr, liPlugin *p); +typedef void (*liPluginHandleVRCloseCB) (liVRequest *vr, liPlugin *p); + +struct liPlugin { size_t version; const gchar *name; /**< name of the plugin */ guint id; /**< index in some plugin arrays */ @@ -32,45 +32,45 @@ struct plugin { size_t opt_base_index; - PluginFree free; /**< called before plugin is unloaded */ + liPluginFreeCB free; /**< called before plugin is unloaded */ - PluginHandleVRequest handle_request_body; + liPluginHandleVRequestCB handle_request_body; /** called for every plugin after connection got closed (response end, reset by peer, error) * the plugins code must not depend on any order of plugins loaded */ - PluginHandleClose handle_close; + liPluginHandleCloseCB handle_close; /** called for every plugin after vrequest got reset */ - PluginHandleVRClose handle_vrclose; + liPluginHandleVRCloseCB handle_vrclose; - const plugin_option *options; - const plugin_action *actions; - const plugin_setup *setups; + const liPluginOption *options; + const liPluginAction *actions; + const liliPluginSetupCB *setups; }; -struct plugin_option { +struct liPluginOption { const gchar *name; - value_type type; + liValueType type; gpointer default_value; - PluginParseOption parse_option; - PluginFreeOption free_option; + liPluginParseOptionCB parse_option; + liPluginFreeOptionCB free_option; }; -struct plugin_action { +struct liPluginAction { const gchar *name; - PluginCreateAction create_action; + liPluginCreateActionCB create_action; }; -struct plugin_setup { +struct liliPluginSetupCB { const gchar *name; - PluginSetup setup; + liPluginSetupCB setup; }; /* Internal structures */ -struct server_option { - plugin *p; +struct liServerOption { + liPlugin *p; /** the value is freed with value_free after the parse call, so you * probably want to extract the content via value_extract* @@ -79,13 +79,13 @@ struct server_option { * * Default behaviour (NULL) is to extract the inner value from val */ - PluginParseOption parse_option; + liPluginParseOptionCB parse_option; /** the free_option handler has to free all allocated resources; * it may get called with 0 initialized options, so you have to * check the value. */ - PluginFreeOption free_option; + liPluginFreeOptionCB free_option; /** if parse_option is NULL, the default_value is used; it is only used * for the following value types: @@ -96,46 +96,46 @@ struct server_option { gpointer default_value; size_t index, module_index; - value_type type; + liValueType type; }; -struct server_action { - plugin *p; - PluginCreateAction create_action; +struct liServerAction { + liPlugin *p; + liPluginCreateActionCB create_action; }; -struct server_setup { - plugin *p; - PluginSetup setup; +struct liServerSetup { + liPlugin *p; + liPluginSetupCB setup; }; /* Needed by modules to register their plugin(s) */ -LI_API plugin *plugin_register(server *srv, const gchar *name, PluginInit init); +LI_API liPlugin *plugin_register(liServer *srv, const gchar *name, liPluginInitCB init); /* Internal needed functions */ -LI_API void plugin_free(server *srv, plugin *p); -LI_API void server_plugins_free(server *srv); +LI_API void plugin_free(liServer *srv, liPlugin *p); +LI_API void server_plugins_free(liServer *srv); /** free val after call (val may be modified by parser) */ -LI_API gboolean parse_option(server *srv, const char *name, value *val, option_set *mark); -LI_API void release_option(server *srv, option_set *mark); /**< Does not free the option_set memory */ +LI_API gboolean parse_option(liServer *srv, const char *name, liValue *val, liOptionSet *mark); +LI_API void release_option(liServer *srv, liOptionSet *mark); /**< Does not free the option_set memory */ -LI_API void plugins_prepare_callbacks(server *srv); -LI_API void plugins_handle_close(connection *con); -LI_API void plugins_handle_vrclose(vrequest *vr); +LI_API void plugins_prepare_callbacks(liServer *srv); +LI_API void plugins_handle_close(liConnection *con); +LI_API void plugins_handle_vrclose(liVRequest *vr); /* Needed for config frontends */ /** For parsing 'somemod.option = "somevalue"', free value after call */ -LI_API action* option_action(server *srv, const gchar *name, value *val); +LI_API liAction* option_action(liServer *srv, const gchar *name, liValue *val); /** For parsing 'somemod.action value', e.g. 'rewrite "/url" => "/destination"' * free value after call */ -LI_API action* create_action(server *srv, const gchar *name, value *val); +LI_API liAction* create_action(liServer *srv, const gchar *name, liValue *val); /** For setup function, e.g. 'listen "127.0.0.1:8080"'; free value after call */ -LI_API gboolean call_setup(server *srv, const char *name, value *val); +LI_API gboolean call_setup(liServer *srv, const char *name, liValue *val); /** free val after call */ -LI_API gboolean plugin_set_default_option(server *srv, const gchar* name, value *val); +LI_API gboolean plugin_set_default_option(liServer *srv, const gchar* name, liValue *val); /* needs vrequest *vr and plugin *p */ #define OPTION(idx) _OPTION(vr, p, idx) diff --git a/include/lighttpd/plugin_core.h b/include/lighttpd/plugin_core.h index b645da0..f3d801e 100644 --- a/include/lighttpd/plugin_core.h +++ b/include/lighttpd/plugin_core.h @@ -3,26 +3,26 @@ #include -typedef enum { ETAG_USE_INODE = 1, ETAG_USE_MTIME = 2, ETAG_USE_SIZE = 4 } etag_flags_t; +typedef enum { LI_ETAG_USE_INODE = 1, LI_ETAG_USE_MTIME = 2, LI_ETAG_USE_SIZE = 4 } liETagFlags; -enum core_options_t { - CORE_OPTION_DEBUG_REQUEST_HANDLING = 0, +enum liCoreOptions { + LI_CORE_OPTION_DEBUG_REQUEST_HANDLING = 0, - CORE_OPTION_LOG_TS_FORMAT, - CORE_OPTION_LOG, + LI_CORE_OPTION_LOG_TS_FORMAT, + LI_CORE_OPTION_LOG, - CORE_OPTION_STATIC_FILE_EXCLUDE, + LI_CORE_OPTION_STATIC_FILE_EXCLUDE, - CORE_OPTION_SERVER_NAME, - CORE_OPTION_SERVER_TAG, - CORE_OPTION_MAX_KEEP_ALIVE_IDLE, - CORE_OPTION_MAX_KEEP_ALIVE_REQUESTS, + LI_CORE_OPTION_SERVER_NAME, + LI_CORE_OPTION_SERVER_TAG, + LI_CORE_OPTION_MAX_KEEP_ALIVE_IDLE, + LI_CORE_OPTION_MAX_KEEP_ALIVE_REQUESTS, - CORE_OPTION_MIME_TYPES, + LI_CORE_OPTION_MIME_TYPES, - CORE_OPTION_THROTTLE, + LI_CORE_OPTION_THROTTLE, - CORE_OPTION_ETAG_FLAGS + LI_CORE_OPTION_ETAG_FLAGS }; /* the core plugin always has base index 0, as it is the first plugin loaded */ diff --git a/include/lighttpd/profiler.h b/include/lighttpd/profiler.h index e2aca65..f872b22 100644 --- a/include/lighttpd/profiler.h +++ b/include/lighttpd/profiler.h @@ -1,10 +1,9 @@ #ifndef _LIGHTTPD_PROFILER_H_ #define _LIGHTTPD_PROFILER_H_ -struct profiler_mem; -typedef struct profiler_mem profiler_mem; +typedef struct liProfilerMem liProfilerMem; -struct profiler_mem { +struct liProfilerMem { guint64 inuse_bytes; guint64 alloc_times; guint64 alloc_bytes; diff --git a/include/lighttpd/radix.h b/include/lighttpd/radix.h index 2768ab7..03dfb94 100644 --- a/include/lighttpd/radix.h +++ b/include/lighttpd/radix.h @@ -8,64 +8,63 @@ * This is where the bit magic happens. */ -struct RadixNode32 { +typedef struct liRadixNode32 liRadixNode32; +struct liRadixNode32 { guint32 key; guint32 mask; gpointer data; - struct RadixNode32 *parent; - struct RadixNode32 *right; - struct RadixNode32 *left; + liRadixNode32 *parent; + liRadixNode32 *right; + liRadixNode32 *left; }; -typedef struct RadixNode32 RadixNode32; - -struct RadixTree32 { - RadixNode32 **root; +typedef struct liRadixTree32 liRadixTree32; +struct liRadixTree32 { + liRadixNode32 **root; guint32 size; guint32 root_width; guint32 root_mask; }; -typedef struct RadixTree32 RadixTree32; -LI_API RadixTree32 *radixtree32_new(guint32 root_width); -LI_API guint32 radixtree32_free(RadixTree32 *tree); +LI_API liRadixTree32 *radixtree32_new(guint32 root_width); +LI_API guint32 radixtree32_free(liRadixTree32 *tree); -LI_API void radixtree32_insert(RadixTree32 *tree, guint32 key, guint32 mask, gpointer data); -LI_API gboolean radixtree32_remove(RadixTree32 *tree, guint32 key, guint32 mask); +LI_API void radixtree32_insert(liRadixTree32 *tree, guint32 key, guint32 mask, gpointer data); +LI_API gboolean radixtree32_remove(liRadixTree32 *tree, guint32 key, guint32 mask); /* lookup tree node (best match) */ -LI_API RadixNode32 *radixtree32_lookup_node(RadixTree32 *tree, guint32 key); +LI_API liRadixNode32 *radixtree32_lookup_node(liRadixTree32 *tree, guint32 key); /* lookup data pointer (best match) */ -LI_API gpointer radixtree32_lookup(RadixTree32 *tree, guint32 key); +LI_API gpointer radixtree32_lookup(liRadixTree32 *tree, guint32 key); /* lookup data pointer (exact match) */ -LI_API gpointer radixtree32_lookup_exact(RadixTree32 *tree, guint32 key); +LI_API gpointer radixtree32_lookup_exact(liRadixTree32 *tree, guint32 key); /* -struct RadixNode128 { +typedef struct liRadixNode128 liRadixNode128; +struct liRadixNode128 { guint32 key[4]; guint32 mask[3]; gpointer data; - struct RadixNode128 *parent; - struct RadixNode128 *right; - struct RadixNode128 *left; + liRadixNode128 *parent; + liRadixNode128 *right; + liRadixNode128 *left; }; -typedef struct RadixNode128 RadixNode128; -struct RadixTree128 { - RadixNode128 **root; +struct liRadixTree128 { + liRadixNode128 **root; guint64 size; guint32 root_width; guint32 root_mask; } -LI_api RadixTree128 *radixtree128_new(guint32 root_width); -LI_API guint radixtree128_free(RadixTree128 *tree); +LI_api liRadixTree128 *radixtree128_new(guint32 root_width); +LI_API guint radixtree128_free(liRadixTree128 *tree); -LI_API void radixtree128_insert(RadixTree128 *tree, guint32 *key, guint32 *mask, gpointer data); -LI_API gboolean radixtree128_remove(RadixTree128 *tree, guint32 *key, guint32 *mask); -LI_API gpointer radixtree128_lookup(RadixTree128 *tree, guint32 *key); +LI_API void radixtree128_insert(liRadixTree128 *tree, guint32 *key, guint32 *mask, gpointer data); +LI_API gboolean radixtree128_remove(liRadixTree128 *tree, guint32 *key, guint32 *mask); +LI_API gpointer radixtree128_lookup(liRadixTree128 *tree, guint32 *key); */ #endif diff --git a/include/lighttpd/request.h b/include/lighttpd/request.h index ddaceab..0c3e4bc 100644 --- a/include/lighttpd/request.h +++ b/include/lighttpd/request.h @@ -5,7 +5,7 @@ #error Please include instead of this file #endif -struct request_uri { +struct liRequestUri { GString *raw; GString *scheme; @@ -16,7 +16,7 @@ struct request_uri { GString *host; /* without userinfo and port */ }; -struct physical { +struct liPhysical { GString *path; GString *basedir; @@ -31,26 +31,26 @@ struct physical { struct stat stat; /* contains valid data only if have_stat is true */ }; -struct request { - http_method_t http_method; +struct liRequest { + liHttpMethod http_method; GString *http_method_str; - http_version_t http_version; + liHttpVersion http_version; - request_uri uri; + liRequestUri uri; - http_headers *headers; + liHttpHeaders *headers; /* Parsed headers: */ goffset content_length; }; -LI_API void request_init(request *req); -LI_API void request_reset(request *req); -LI_API void request_clear(request *req); +LI_API void request_init(liRequest *req); +LI_API void request_reset(liRequest *req); +LI_API void request_clear(liRequest *req); -LI_API gboolean request_validate_header(connection *con); +LI_API gboolean request_validate_header(liConnection *con); -LI_API void physical_init(physical *phys); -LI_API void physical_reset(physical *phys); -LI_API void physical_clear(physical *phys); +LI_API void physical_init(liPhysical *phys); +LI_API void physical_reset(liPhysical *phys); +LI_API void physical_clear(liPhysical *phys); #endif diff --git a/include/lighttpd/response.h b/include/lighttpd/response.h index b2fff58..8d7a81f 100644 --- a/include/lighttpd/response.h +++ b/include/lighttpd/response.h @@ -5,17 +5,17 @@ #error Please include instead of this file #endif -struct response { - http_headers *headers; +struct liResponse { + liHttpHeaders *headers; gint http_status; - transfer_encoding_t transfer_encoding; + liTransferEncoding transfer_encoding; }; -LI_API void response_init(response *resp); -LI_API void response_reset(response *resp); -LI_API void response_clear(response *resp); +LI_API void response_init(liResponse *resp); +LI_API void response_reset(liResponse *resp); +LI_API void response_clear(liResponse *resp); -LI_API void response_send_headers(connection *con); -LI_API void response_send_error_page(connection *con); +LI_API void response_send_headers(liConnection *con); +LI_API void response_send_error_page(liConnection *con); #endif diff --git a/include/lighttpd/server.h b/include/lighttpd/server.h index b2033a6..6f13098 100644 --- a/include/lighttpd/server.h +++ b/include/lighttpd/server.h @@ -6,25 +6,25 @@ #endif typedef enum { - SERVER_STARTING, /** start up: don't write log files, don't accept connections */ - SERVER_RUNNING, /** running: write logs, accept connections */ - SERVER_STOPPING /** stopping: flush logs, don't accept new connections */ -} server_state; + LI_SERVER_STARTING, /** start up: don't write log files, don't accept connections */ + LI_SERVER_RUNNING, /** running: write logs, accept connections */ + LI_SERVER_STOPPING /** stopping: flush logs, don't accept new connections */ +} liServerState; -struct server_socket { +struct liServerSocket { gint refcount; - server *srv; + liServer *srv; ev_io watcher; - sockaddr_t local_addr; + liSocketAddress local_addr; GString *local_addr_str; }; -struct server { +struct liServer { guint32 magic; /** server magic version, check against LIGHTTPD_SERVER_MAGIC in plugins */ - server_state state; /** atomic access */ - angel_connection *acon; + liServerState state; /** atomic access */ + liAngelConnection *acon; - struct worker *main_worker; + liWorker *main_worker; guint worker_count; GArray *workers; GArray *ts_formats; /** array of (GString*), add with server_ts_format_add() */ @@ -40,10 +40,10 @@ struct server { GPtrArray *sockets; /** array of (server_socket*) */ - struct modules *modules; + liModules *modules; GHashTable *plugins; /**< const gchar* => (plugin*) */ - struct plugin *core_plugin; + liPlugin *core_plugin; /* registered by plugins */ GHashTable *options; /**< const gchar* => (server_option*) */ @@ -54,7 +54,7 @@ struct server { GArray *plugins_handle_vrclose; /** list of handle_vrclose callbacks */ GArray *option_def_values;/** array of option_value */ - struct action *mainaction; + liAction *mainaction; gboolean exiting; /** atomic access */ @@ -67,7 +67,7 @@ struct server { gboolean thread_stop; /** stop thread immediately; access with atomic functions */ gboolean thread_alive; /** access with atomic functions */ GArray *timestamps; /** array of log_timestamp_t */ - struct log_t *stderr; + liLog *stderr; } logs; ev_tstamp started; @@ -84,27 +84,27 @@ struct server { }; -LI_API server* server_new(const gchar *module_dir); -LI_API void server_free(server* srv); -LI_API gboolean server_loop_init(server *srv); -LI_API gboolean server_worker_init(server *srv); +LI_API liServer* server_new(const gchar *module_dir); +LI_API void server_free(liServer* srv); +LI_API gboolean server_loop_init(liServer *srv); +LI_API gboolean server_worker_init(liServer *srv); -LI_API void server_listen(server *srv, int fd); +LI_API void server_listen(liServer *srv, int fd); /* Start accepting connection, use log files, no new plugins after that */ -LI_API void server_start(server *srv); +LI_API void server_start(liServer *srv); /* stop accepting connections, turn keep-alive off, close all shutdown sockets, set exiting = TRUE */ -LI_API void server_stop(server *srv); +LI_API void server_stop(liServer *srv); /* exit asap with cleanup */ -LI_API void server_exit(server *srv); +LI_API void server_exit(liServer *srv); LI_API GString *server_current_timestamp(); -LI_API void server_out_of_fds(server *srv); +LI_API void server_out_of_fds(liServer *srv); -LI_API guint server_ts_format_add(server *srv, GString* format); +LI_API guint server_ts_format_add(liServer *srv, GString* format); -LI_API void server_socket_release(server_socket* sock); -LI_API void server_socket_acquire(server_socket* sock); +LI_API void server_socket_release(liServerSocket* sock); +LI_API void server_socket_acquire(liServerSocket* sock); #endif diff --git a/include/lighttpd/stat_cache.h b/include/lighttpd/stat_cache.h index 731af38..8c58ccd 100644 --- a/include/lighttpd/stat_cache.h +++ b/include/lighttpd/stat_cache.h @@ -39,7 +39,7 @@ #error Please include instead of this file #endif -struct stat_cache_entry_data { +struct liStatCacheEntryData { GString *path; GString *etag; GString *content_type; @@ -48,7 +48,7 @@ struct stat_cache_entry_data { gint err; }; -struct stat_cache_entry { +struct liStatCacheEntry { enum { STAT_CACHE_ENTRY_SINGLE, /* single file, this is the default or "normal" */ STAT_CACHE_ENTRY_DIR /* get a directory listing (with stat info) */ @@ -59,21 +59,21 @@ struct stat_cache_entry { STAT_CACHE_ENTRY_FINISHED, /* stat() done, info available */ } state; - stat_cache_entry_data data; + liStatCacheEntryData data; GArray *dirlist; /* array of stat_cache_entry_data, used together with STAT_CACHE_ENTRY_DIR */ GPtrArray *vrequests; /* vrequests waiting for this info */ guint refcount; - waitqueue_elem queue_elem; /* queue element for the delete_queue */ + liWaitQueueElem queue_elem; /* queue element for the delete_queue */ gboolean cached; }; -struct stat_cache { +struct liStatCache { GHashTable *dirlists; GHashTable *entries; GAsyncQueue *job_queue_out; /* elements waiting for stat */ GAsyncQueue *job_queue_in; /* elements with finished stat */ - waitqueue delete_queue; + liWaitQueue delete_queue; GThread *thread; ev_async job_watcher; gdouble ttl; @@ -83,24 +83,24 @@ struct stat_cache { guint64 errors; }; -void stat_cache_new(worker *wrk, gdouble ttl); -void stat_cache_free(stat_cache *sc); +void stat_cache_new(liWorker *wrk, gdouble ttl); +void stat_cache_free(liStatCache *sc); /* gets a stat_cache_entry for a specified path if fd is set, a new fd is acquired via open() and stat info via fstat(), otherwise only a stat() is performed returns HANDLER_WAIT_FOR_EVENT in case of a cache MISS, HANDLER_GO_ON in case of a hit and HANDLER_ERROR in case of an error */ -LI_API handler_t stat_cache_get(vrequest *vr, GString *path, struct stat *st, int *err, int *fd); +LI_API liHandlerResult stat_cache_get(liVRequest *vr, GString *path, struct stat *st, int *err, int *fd); /* sce->dirlist will contain a list of stat_cache_entry_data upon success returns HANDLER_WAIT_FOR_EVENT in case of a cache MISS, HANDLER_GO_ON in case of a hit and HANDLER_ERROR in case of an error */ -LI_API handler_t stat_cache_get_dirlist(vrequest *vr, GString *path, stat_cache_entry **result); +LI_API liHandlerResult stat_cache_get_dirlist(liVRequest *vr, GString *path, liStatCacheEntry **result); -LI_API void stat_cache_entry_acquire(vrequest *vr, stat_cache_entry *sce); +LI_API void stat_cache_entry_acquire(liVRequest *vr, liStatCacheEntry *sce); /* release a stat_cache_entry so it can be cleaned up */ -LI_API void stat_cache_entry_release(vrequest *vr, stat_cache_entry *sce); +LI_API void stat_cache_entry_release(liVRequest *vr, liStatCacheEntry *sce); #endif \ No newline at end of file diff --git a/include/lighttpd/sys-socket.h b/include/lighttpd/sys-socket.h index a8474e9..0171635 100644 --- a/include/lighttpd/sys-socket.h +++ b/include/lighttpd/sys-socket.h @@ -66,7 +66,8 @@ int inet_aton(const char *cp, struct in_addr *inp); #endif /* HAVE_IPV6 */ #endif /* HAVE_INET_NTOP */ -typedef union { +typedef union liSockAddr liSockAddr; +union liSockAddr { #ifdef HAVE_IPV6 struct sockaddr_in6 ipv6; #endif @@ -75,11 +76,12 @@ typedef union { struct sockaddr_un un; #endif struct sockaddr plain; -} sock_addr; +}; -typedef struct sockaddr_t { +typedef struct liSocketAddress liSocketAddress; +struct liSocketAddress { socklen_t len; - sock_addr *addr; -} sockaddr_t; + liSockAddr *addr; +}; #endif diff --git a/include/lighttpd/throttle.h b/include/lighttpd/throttle.h index aaac446..887b9aa 100644 --- a/include/lighttpd/throttle.h +++ b/include/lighttpd/throttle.h @@ -3,7 +3,8 @@ #define THROTTLE_GRANULARITY 0.2 /* defines how frequently a magazine is refilled. should be 0.1 <= x <= 1.0 */ -struct throttle_pool_t { +typedef struct liThrottlePool liThrottlePool; +struct liThrottlePool { GString *name; guint rate; /** bytes/s */ gint magazine; @@ -16,11 +17,9 @@ struct throttle_pool_t { ev_tstamp *last_con_rearm; }; -typedef struct throttle_pool_t throttle_pool_t; - void throttle_cb(struct ev_loop *loop, ev_timer *w, int revents); -throttle_pool_t *throttle_pool_new(server *srv, GString *name, guint rate); -void throttle_pool_free(server *srv, throttle_pool_t *pool); +liThrottlePool *throttle_pool_new(liServer *srv, GString *name, guint rate); +void throttle_pool_free(liServer *srv, liThrottlePool *pool); #endif diff --git a/include/lighttpd/typedefs.h b/include/lighttpd/typedefs.h index 64b1f99..9478c38 100644 --- a/include/lighttpd/typedefs.h +++ b/include/lighttpd/typedefs.h @@ -2,219 +2,216 @@ #define _LIGHTTPD_TYPEDEFS_H_ typedef enum { - HTTP_TRANSFER_ENCODING_IDENTITY, - HTTP_TRANSFER_ENCODING_CHUNKED -} transfer_encoding_t; + LI_HTTP_TRANSFER_ENCODING_IDENTITY, + LI_HTTP_TRANSFER_ENCODING_CHUNKED +} liTransferEncoding; typedef enum { - HANDLER_GO_ON, - HANDLER_COMEBACK, - HANDLER_WAIT_FOR_EVENT, - HANDLER_ERROR -} handler_t; + LI_HANDLER_GO_ON, + LI_HANDLER_COMEBACK, + LI_HANDLER_WAIT_FOR_EVENT, + LI_HANDLER_ERROR +} liHandlerResult; + +typedef enum { TRI_FALSE, TRI_MAYBE, TRI_TRUE } tristate_t; /* structs from headers, in alphabetic order */ /* actions.h */ -struct action; -typedef struct action action; +typedef struct liAction liAction; + +typedef struct liActionStack liActionStack; + +typedef struct liActionRegexStackElement liActionRegexStackElement; + +typedef struct liActionFunc liActionFunc; + +typedef struct liBalancerFunc liBalancerFunc; + +typedef enum { + ACTION_TSETTING, + ACTION_TFUNCTION, + ACTION_TCONDITION, + ACTION_TLIST, + ACTION_TBALANCER +} liActionType; + +typedef enum { + BACKEND_OVERLOAD, + BACKEND_DEAD +} liBackendError; -struct action_stack; -typedef struct action_stack action_stack; /* chunk.h */ -struct chunkfile; -typedef struct chunkfile chunkfile; +typedef struct liChunkFile liChunkFile; -struct chunk; -typedef struct chunk chunk; +typedef struct liChunk liChunk; -struct cqlimit; -typedef struct cqlimit cqlimit; +typedef struct liCQLimit liCQLimit; -struct chunkqueue; -typedef struct chunkqueue chunkqueue; +typedef struct liChunkQueue liChunkQueue; -struct chunkiter; -typedef struct chunkiter chunkiter; +typedef struct liChunkIter liChunkIter; /* chunk_parser.h */ -struct chunk_parser_ctx; -typedef struct chunk_parser_ctx chunk_parser_ctx; +typedef struct liChunkParserCtx liChunkParserCtx; -struct chunk_parser_mark; -typedef struct chunk_parser_mark chunk_parser_mark; +typedef struct liChunkParserMark liChunkParserMark; /* condition.h */ -struct condition_rvalue; -typedef struct condition_rvalue condition_rvalue; +typedef struct liConditionRValue liConditionRValue; -struct condition_lvalue; -typedef struct condition_lvalue condition_lvalue; +typedef struct liConditionLValue liConditionLValue; -struct condition; -typedef struct condition condition; +typedef struct liCondition liCondition; /* connection.h */ -struct connection; -typedef struct connection connection; +typedef struct liConnection liConnection; + +/* http_headers.h */ + +typedef struct liHttpHeader liHttpHeader; -/* environment.h */ -struct environment; -typedef struct environment environment; +typedef struct liHttpHeaders liHttpHeaders; -struct environment_dup; -typedef struct environment_dup environment_dup; +/* http_request_parser.h */ -/* hhtp_headers.h */ +typedef struct liHttpRequestCtx liHttpRequestCtx; -struct http_header; -typedef struct http_header http_header; +/* http_response_parser.h */ -struct http_headers; -typedef struct http_headers http_headers; +typedef struct liHttpResponseCtx liHttpResponseCtx; + +/* log.h */ + +typedef struct liLog liLog; +typedef struct liLogEntry liLogEntry; +typedef struct liLogTimestamp liLogTimestamp; + +typedef enum { + LI_LOG_LEVEL_DEBUG, + LI_LOG_LEVEL_INFO, + LI_LOG_LEVEL_WARNING, + LI_LOG_LEVEL_ERROR, + LI_LOG_LEVEL_ABORT, + LI_LOG_LEVEL_BACKEND +} liLogLevel; + +typedef enum { + LI_LOG_TYPE_STDERR, + LI_LOG_TYPE_FILE, + LI_LOG_TYPE_PIPE, + LI_LOG_TYPE_SYSLOG, + LI_LOG_TYPE_NONE +} liLogType; /* options.h */ -struct option_set; -typedef struct option_set option_set; +typedef struct liOptionSet liOptionSet; -union option_value; -typedef union option_value option_value; +typedef union liOptionValue liOptionValue; /* plugin.h */ -struct plugin; -typedef struct plugin plugin; +typedef struct liPlugin liPlugin; -struct plugin_option; -typedef struct plugin_option plugin_option; +typedef struct liPluginOption liPluginOption; -struct server_option; -typedef struct server_option server_option; +typedef struct liServerOption liServerOption; -struct plugin_action; -typedef struct plugin_action plugin_action; +typedef struct liPluginAction liPluginAction; -struct server_action; -typedef struct server_action server_action; +typedef struct liServerAction liServerAction; -struct plugin_setup; -typedef struct plugin_setup plugin_setup; +typedef struct liliPluginSetupCB liliPluginSetupCB; -struct server_setup; -typedef struct server_setup server_setup; +typedef struct liServerSetup liServerSetup; /* request.h */ typedef enum { - HTTP_METHOD_UNSET = -1, - HTTP_METHOD_GET, - HTTP_METHOD_POST, - HTTP_METHOD_HEAD, - HTTP_METHOD_OPTIONS, - HTTP_METHOD_PROPFIND, /* WebDAV */ - HTTP_METHOD_MKCOL, - HTTP_METHOD_PUT, - HTTP_METHOD_DELETE, - HTTP_METHOD_COPY, - HTTP_METHOD_MOVE, - HTTP_METHOD_PROPPATCH, - HTTP_METHOD_REPORT, /* DeltaV */ - HTTP_METHOD_CHECKOUT, - HTTP_METHOD_CHECKIN, - HTTP_METHOD_VERSION_CONTROL, - HTTP_METHOD_UNCHECKOUT, - HTTP_METHOD_MKACTIVITY, - HTTP_METHOD_MERGE, - HTTP_METHOD_LOCK, - HTTP_METHOD_UNLOCK, - HTTP_METHOD_LABEL, - HTTP_METHOD_CONNECT -} http_method_t; + LI_HTTP_METHOD_UNSET = -1, + LI_HTTP_METHOD_GET, + LI_HTTP_METHOD_POST, + LI_HTTP_METHOD_HEAD, + LI_HTTP_METHOD_OPTIONS, + LI_HTTP_METHOD_PROPFIND, /* WebDAV */ + LI_HTTP_METHOD_MKCOL, + LI_HTTP_METHOD_PUT, + LI_HTTP_METHOD_DELETE, + LI_HTTP_METHOD_COPY, + LI_HTTP_METHOD_MOVE, + LI_HTTP_METHOD_PROPPATCH, + LI_HTTP_METHOD_REPORT, /* DeltaV */ + LI_HTTP_METHOD_CHECKOUT, + LI_HTTP_METHOD_CHECKIN, + LI_HTTP_METHOD_VERSION_CONTROL, + LI_HTTP_METHOD_UNCHECKOUT, + LI_HTTP_METHOD_MKACTIVITY, + LI_HTTP_METHOD_MERGE, + LI_HTTP_METHOD_LOCK, + LI_HTTP_METHOD_UNLOCK, + LI_HTTP_METHOD_LABEL, + LI_HTTP_METHOD_CONNECT +} liHttpMethod; typedef enum { - HTTP_VERSION_UNSET = -1, - HTTP_VERSION_1_0, - HTTP_VERSION_1_1 -} http_version_t; + LI_HTTP_VERSION_UNSET = -1, + LI_HTTP_VERSION_1_0, + LI_HTTP_VERSION_1_1 +} liHttpVersion; -struct request; -typedef struct request request; +typedef struct liRequest liRequest; -struct request_uri; -typedef struct request_uri request_uri; +typedef struct liRequestUri liRequestUri; -struct physical; -typedef struct physical physical; +typedef struct liPhysical liPhysical; /* respone.h */ -struct response; -typedef struct response response; +typedef struct liResponse liResponse; /* server.h */ -struct server; -typedef struct server server; - -struct server_socket; -typedef struct server_socket server_socket; - -/* utils.h */ - -struct waitqueue_elem; -typedef struct waitqueue_elem waitqueue_elem; - -struct waitqueue; -typedef struct waitqueue waitqueue; +typedef struct liServer liServer; -typedef void (*waitqueue_cb) (struct ev_loop *loop, struct ev_timer *w, int revents); +typedef struct liServerSocket liServerSocket; /* value.h */ -struct value; -typedef struct value value; +typedef struct liValue liValue; typedef enum { - VALUE_NONE, - VALUE_BOOLEAN, - VALUE_NUMBER, - VALUE_STRING, - VALUE_LIST, - VALUE_HASH, - VALUE_ACTION, /**< shouldn't be used for options, but may be needed for constructing actions */ - VALUE_CONDITION /**< shouldn't be used for options, but may be needed for constructing actions */ -} value_type; + LI_VALUE_NONE, + LI_VALUE_BOOLEAN, + LI_VALUE_NUMBER, + LI_VALUE_STRING, + LI_VALUE_LIST, + LI_VALUE_HASH, + LI_VALUE_ACTION, /**< shouldn't be used for options, but may be needed for constructing actions */ + LI_VALUE_CONDITION /**< shouldn't be used for options, but may be needed for constructing actions */ +} liValueType; /* virtualrequest.h */ -struct vrequest; -typedef struct vrequest vrequest; +typedef struct liVRequest liVRequest; -struct vrequest_ref; -typedef struct vrequest_ref vrequest_ref; +typedef struct liVRequestRef liVRequestRef; -struct filter; -typedef struct filter filter; +typedef struct liFilter liFilter; -struct filters; -typedef struct filters filters; +typedef struct liFilters liFilters; /* worker.h */ -struct worker; -typedef struct worker worker; +typedef struct liWorker liWorker; -struct stat_cache_entry_data; -typedef struct stat_cache_entry_data stat_cache_entry_data; -struct stat_cache_entry; -typedef struct stat_cache_entry stat_cache_entry; -struct stat_cache; -typedef struct stat_cache stat_cache; +typedef struct liStatCacheEntryData liStatCacheEntryData; +typedef struct liStatCacheEntry liStatCacheEntry; +typedef struct liStatCache liStatCache; #endif diff --git a/include/lighttpd/url_parser.h b/include/lighttpd/url_parser.h index 412080e..48043dc 100644 --- a/include/lighttpd/url_parser.h +++ b/include/lighttpd/url_parser.h @@ -3,7 +3,7 @@ #include -LI_API gboolean parse_raw_url(request_uri *uri); -LI_API gboolean parse_hostname(request_uri *uri); +LI_API gboolean parse_raw_url(liRequestUri *uri); +LI_API gboolean parse_hostname(liRequestUri *uri); #endif diff --git a/include/lighttpd/utils.h b/include/lighttpd/utils.h index 8f2ea84..a7074a1 100644 --- a/include/lighttpd/utils.h +++ b/include/lighttpd/utils.h @@ -7,7 +7,7 @@ typedef enum { COUNTER_TIME, COUNTER_BYTES, COUNTER_UNITS -} counter_type; +} liCounterType; @@ -35,7 +35,7 @@ LI_API void url_decode(GString *path); LI_API void path_simplify(GString *path); /* formats a given guint64 for output. if dest is NULL, a new string is allocated */ -LI_API GString *counter_format(guint64 count, counter_type t, GString *dest); +LI_API GString *counter_format(guint64 count, liCounterType t, GString *dest); LI_API gchar *ev_backend_string(guint backend); @@ -47,12 +47,12 @@ LI_API guint hash_ipv4(gconstpointer key); LI_API guint hash_ipv6(gconstpointer key); /* converts a sock_addr to a human readable string. ipv4 and ipv6 supported. if dest is NULL, a new string will be allocated */ -LI_API GString *sockaddr_to_string(sockaddr_t addr, GString *dest, gboolean showport); +LI_API GString *sockaddr_to_string(liSocketAddress addr, GString *dest, gboolean showport); -LI_API sockaddr_t sockaddr_from_string(GString *str, guint tcp_default_port); -LI_API sockaddr_t sockaddr_local_from_socket(gint fd); -LI_API sockaddr_t sockaddr_remote_from_socket(gint fd); -LI_API void sockaddr_clear(sockaddr_t *saddr); +LI_API liSocketAddress sockaddr_from_string(GString *str, guint tcp_default_port); +LI_API liSocketAddress sockaddr_local_from_socket(gint fd); +LI_API liSocketAddress sockaddr_remote_from_socket(gint fd); +LI_API void sockaddr_clear(liSocketAddress *saddr); LI_API void gstring_replace_char_with_str_len(GString *gstr, gchar c, gchar *str, guint len); diff --git a/include/lighttpd/value.h b/include/lighttpd/value.h index 0746ca9..226b839 100644 --- a/include/lighttpd/value.h +++ b/include/lighttpd/value.h @@ -5,42 +5,42 @@ #error Please include instead of this file #endif -struct value { - value_type type; +struct liValue { + liValueType type; union { gboolean boolean; gint64 number; GString *string; - /* array of (value*) */ + /* array of (liValue*) */ GArray *list; /* hash GString => value */ GHashTable *hash; struct { - server *srv; /* needed for destruction */ - action *action; + liServer *srv; /* needed for destruction */ + liAction *action; } val_action; struct { - server *srv; /* needed for destruction */ - condition *cond; + liServer *srv; /* needed for destruction */ + liCondition *cond; } val_cond; } data; }; -LI_API value* value_new_none(); -LI_API value* value_new_bool(gboolean val); -LI_API value* value_new_number(gint64 val); -LI_API value* value_new_string(GString *val); -LI_API value* value_new_list(); -LI_API value* value_new_hash(); -LI_API value* value_new_action(server *srv, action *a); -LI_API value* value_new_condition(server *srv, condition *c); +LI_API liValue* value_new_none(); +LI_API liValue* value_new_bool(gboolean val); +LI_API liValue* value_new_number(gint64 val); +LI_API liValue* value_new_string(GString *val); +LI_API liValue* value_new_list(); +LI_API liValue* value_new_hash(); +LI_API liValue* value_new_action(liServer *srv, liAction *a); +LI_API liValue* value_new_condition(liServer *srv, liCondition *c); -LI_API value* value_copy(value* val); -LI_API void value_free(value* val); +LI_API liValue* value_copy(liValue* val); +LI_API void value_free(liValue* val); -LI_API const char* value_type_string(value_type type); +LI_API const char* value_type_string(liValueType type); -LI_API GString *value_to_string(value *val); +LI_API GString *value_to_string(liValue *val); LI_API void value_list_free(GArray *vallist); diff --git a/include/lighttpd/value_lua.h b/include/lighttpd/value_lua.h index 4045257..90c3d32 100644 --- a/include/lighttpd/value_lua.h +++ b/include/lighttpd/value_lua.h @@ -8,7 +8,7 @@ * and pops the value * returns NULL if it couldn't convert the value (still pops it) */ -LI_API value* value_from_lua(server *srv, lua_State *L); +LI_API liValue* value_from_lua(liServer *srv, lua_State *L); LI_API GString* lua_togstring(lua_State *L, int ndx); diff --git a/include/lighttpd/virtualrequest.h b/include/lighttpd/virtualrequest.h index 5368f8e..32f5cb7 100644 --- a/include/lighttpd/virtualrequest.h +++ b/include/lighttpd/virtualrequest.h @@ -7,85 +7,85 @@ typedef enum { /* waiting for request headers */ - VRS_CLEAN, + LI_VRS_CLEAN, /* all headers received, now handling them, set up input filters * this state is set by the previous vrequest after VRS_WROTE_RESPONSE_HEADERS (or the main connection), * and the handle_request function is called (which execute the action stack by default) */ - VRS_HANDLE_REQUEST_HEADERS, + LI_VRS_HANDLE_REQUEST_HEADERS, /* request headers handled, input filters ready; now content is accepted - * this state is set via handle_indirect (handle_direct skips to VRS_HANDLE_RESPONSE_HEADERS + * this state is set via handle_indirect (handle_direct skips to LI_VRS_HANDLE_RESPONSE_HEADERS */ - VRS_READ_CONTENT, + LI_VRS_READ_CONTENT, /* all response headers written, now set up output filters */ - VRS_HANDLE_RESPONSE_HEADERS, + LI_VRS_HANDLE_RESPONSE_HEADERS, /* output filters ready, content can be written */ - VRS_WRITE_CONTENT, + LI_VRS_WRITE_CONTENT, /* request done */ /* VRS_END, */ - VRS_ERROR -} vrequest_state; + LI_VRS_ERROR +} liVRequestState; -typedef handler_t (*filter_handler)(vrequest *vr, filter *f); -typedef void (*filter_free)(vrequest *vr, filter *f); -typedef handler_t (*vrequest_handler)(vrequest *vr); -typedef handler_t (*vrequest_plugin_handler)(vrequest *vr, plugin *p); +typedef liHandlerResult (*liFilterHandlerCB)(liVRequest *vr, liFilter *f); +typedef void (*liFilterFreeCB)(liVRequest *vr, liFilter *f); +typedef liHandlerResult (*liVRequestHandlerCB)(liVRequest *vr); +typedef liHandlerResult (*liVRequestPluginHandlerCB)(liVRequest *vr, liPlugin *p); -struct filter { - chunkqueue *in, *out; - filter_handler handle_data; - filter_free handle_free; +struct liFilter { + liChunkQueue *in, *out; + liFilterHandlerCB handle_data; + liFilterFreeCB handle_free; gpointer param; }; -struct filters { +struct liFilters { GPtrArray *queue; - chunkqueue *in, *out; + liChunkQueue *in, *out; guint skip_ndx; }; -struct vrequest_ref { +struct liVRequestRef { gint refcount; - vrequest *vr; /* This is only accesible by the worker thread the vrequest belongs to, and it may be NULL if the vrequest is already reset */ + liVRequest *vr; /* This is only accesible by the worker thread the vrequest belongs to, and it may be NULL if the vrequest is already reset */ }; -struct vrequest { - connection *con; - worker *wrk; - vrequest_ref *ref; +struct liVRequest { + liConnection *con; + liWorker *wrk; + liVRequestRef *ref; - option_value *options; + liOptionValue *options; - vrequest_state state; + liVRequestState state; - vrequest_handler + liVRequestHandlerCB handle_request_headers, handle_response_headers, handle_response_body, handle_response_error; /* this is _not_ for 500 - internal error */ GPtrArray *plugin_ctx; - plugin *backend; + liPlugin *backend; - request request; - physical physical; - response response; + liRequest request; + liPhysical physical; + liResponse response; /* environment entries will be passed to the backends */ - environment env; + liEnvironment env; /* -> vr_in -> filters_in -> in -> handle -> out -> filters_out -> vr_out -> */ gboolean cq_memory_limit_hit; /* stop feeding chunkqueues with memory chunks */ - filters filters_in, filters_out; - chunkqueue *vr_in, *vr_out; - chunkqueue *in, *out; + liFilters filters_in, filters_out; + liChunkQueue *vr_in, *vr_out; + liChunkQueue *in, *out; - action_stack action_stack; + liActionStack action_stack; gboolean actions_wait_for_response; gint queued; @@ -96,52 +96,52 @@ struct vrequest { #define VREQUEST_WAIT_FOR_RESPONSE_HEADERS(vr) \ do { \ - if (vr->state == VRS_HANDLE_REQUEST_HEADERS) { \ + if (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS) { \ VR_ERROR(vr, "%s", "Cannot wait for response headers as no backend handler found - fix your config"); \ - return HANDLER_ERROR; \ - } else if (vr->state < VRS_HANDLE_RESPONSE_HEADERS) { \ - return HANDLER_WAIT_FOR_EVENT; \ + return LI_HANDLER_ERROR; \ + } else if (vr->state < LI_VRS_HANDLE_RESPONSE_HEADERS) { \ + return LI_HANDLER_WAIT_FOR_EVENT; \ } \ } while (0) -LI_API vrequest* vrequest_new(struct connection *con, vrequest_handler handle_response_headers, vrequest_handler handle_response_body, vrequest_handler handle_response_error, vrequest_handler handle_request_headers); -LI_API void vrequest_free(vrequest *vr); -LI_API void vrequest_reset(vrequest *vr); +LI_API liVRequest* vrequest_new(liConnection *con, liVRequestHandlerCB handle_response_headers, liVRequestHandlerCB handle_response_body, liVRequestHandlerCB handle_response_error, liVRequestHandlerCB handle_request_headers); +LI_API void vrequest_free(liVRequest *vr); +LI_API void vrequest_reset(liVRequest *vr); -LI_API vrequest_ref* vrequest_acquire_ref(vrequest *vr); -LI_API vrequest* vrequest_release_ref(vrequest_ref *vr_ref); +LI_API liVRequestRef* vrequest_acquire_ref(liVRequest *vr); +LI_API liVRequest* vrequest_release_ref(liVRequestRef *vr_ref); -LI_API void vrequest_add_filter_in(vrequest *vr, filter_handler handle_data, filter_free handle_free, gpointer param); -LI_API void vrequest_add_filter_out(vrequest *vr, filter_handler handle_data, filter_free handle_free, gpointer param); +LI_API void vrequest_add_filter_in(liVRequest *vr, liFilterHandlerCB handle_data, liFilterFreeCB handle_free, gpointer param); +LI_API void vrequest_add_filter_out(liVRequest *vr, liFilterHandlerCB handle_data, liFilterFreeCB handle_free, gpointer param); /* Signals an internal error; handles the error in the _next_ loop */ -LI_API void vrequest_error(vrequest *vr); +LI_API void vrequest_error(liVRequest *vr); -LI_API void vrequest_backend_overloaded(vrequest *vr); -LI_API void vrequest_backend_dead(vrequest *vr); -LI_API void vrequest_backend_error(vrequest *vr, backend_error berror); +LI_API void vrequest_backend_overloaded(liVRequest *vr); +LI_API void vrequest_backend_dead(liVRequest *vr); +LI_API void vrequest_backend_error(liVRequest *vr, liBackendError berror); /* received all request headers */ -LI_API void vrequest_handle_request_headers(vrequest *vr); +LI_API void vrequest_handle_request_headers(liVRequest *vr); /* received (partial) request content */ -LI_API void vrequest_handle_request_body(vrequest *vr); +LI_API void vrequest_handle_request_body(liVRequest *vr); /* received all response headers/status code - call once from your indirect handler */ -LI_API void vrequest_handle_response_headers(vrequest *vr); +LI_API void vrequest_handle_response_headers(liVRequest *vr); /* received (partial) response content - call from your indirect handler */ -LI_API void vrequest_handle_response_body(vrequest *vr); +LI_API void vrequest_handle_response_body(liVRequest *vr); /* response completely ready */ -LI_API gboolean vrequest_handle_direct(vrequest *vr); +LI_API gboolean vrequest_handle_direct(liVRequest *vr); /* handle request over time */ -LI_API gboolean vrequest_handle_indirect(vrequest *vr, plugin *p); -LI_API gboolean vrequest_is_handled(vrequest *vr); +LI_API gboolean vrequest_handle_indirect(liVRequest *vr, liPlugin *p); +LI_API gboolean vrequest_is_handled(liVRequest *vr); -LI_API void vrequest_state_machine(vrequest *vr); -LI_API void vrequest_joblist_append(vrequest *vr); -LI_API void vrequest_joblist_append_async(vrequest *vr); +LI_API void vrequest_state_machine(liVRequest *vr); +LI_API void vrequest_joblist_append(liVRequest *vr); +LI_API void vrequest_joblist_append_async(liVRequest *vr); -LI_API gboolean vrequest_stat(vrequest *vr); +LI_API gboolean vrequest_stat(liVRequest *vr); -LI_API gboolean vrequest_redirect(vrequest *vr, GString *uri); +LI_API gboolean vrequest_redirect(liVRequest *vr, GString *uri); #endif diff --git a/include/lighttpd/waitqueue.h b/include/lighttpd/waitqueue.h index 14dc980..499b6b6 100644 --- a/include/lighttpd/waitqueue.h +++ b/include/lighttpd/waitqueue.h @@ -1,21 +1,23 @@ #ifndef _LIGHTTPD_WAITQUEUE_H_ #define _LIGHTTPD_WAITQUEUE_H_ -#ifndef _LIGHTTPD_BASE_H_ -#error Please include instead of this file -#endif +#include + +typedef struct liWaitQueueElem liWaitQueueElem; +typedef struct liWaitQueue liWaitQueue; +typedef void (*liWaitQueueCB) (struct ev_loop *loop, struct ev_timer *w, int revents); -struct waitqueue_elem { +struct liWaitQueueElem { gboolean queued; ev_tstamp ts; - waitqueue_elem *prev; - waitqueue_elem *next; + liWaitQueueElem *prev; + liWaitQueueElem *next; gpointer data; }; -struct waitqueue { - waitqueue_elem *head; - waitqueue_elem *tail; +struct liWaitQueue { + liWaitQueueElem *head; + liWaitQueueElem *tail; ev_timer timer; struct ev_loop *loop; gdouble delay; @@ -28,27 +30,27 @@ struct waitqueue { */ /* initializes a waitqueue by creating and starting the ev_timer. precision is sub-seconds */ -LI_API void waitqueue_init(waitqueue *queue, struct ev_loop *loop, waitqueue_cb callback, gdouble delay, gpointer data); +LI_API void waitqueue_init(liWaitQueue *queue, struct ev_loop *loop, liWaitQueueCB callback, gdouble delay, gpointer data); /* stops the waitqueue. to restart it, simply call waitqueue_update */ -LI_API void waitqueue_stop(waitqueue *queue); +LI_API void waitqueue_stop(liWaitQueue *queue); /* updates the timeout of the waitqueue, you should allways call this at the end of your callback */ -LI_API void waitqueue_update(waitqueue *queue); +LI_API void waitqueue_update(liWaitQueue *queue); /* moves the element to the end of the queue if already queued, appends it to the end otherwise */ -LI_API void waitqueue_push(waitqueue *queue, waitqueue_elem *elem); +LI_API void waitqueue_push(liWaitQueue *queue, liWaitQueueElem *elem); /* pops the first ready! element from the queue or NULL if none ready yet. this should be called in your callback */ -LI_API waitqueue_elem *waitqueue_pop(waitqueue *queue); +LI_API liWaitQueueElem *waitqueue_pop(liWaitQueue *queue); /* pops all elements from the queue that are ready or NULL of none ready yet. returns number of elements pop()ed and saves old head in '*head' */ -LI_API guint waitqueue_pop_ready(waitqueue *queue, waitqueue_elem **head); +LI_API guint waitqueue_pop_ready(liWaitQueue *queue, liWaitQueueElem **head); /* removes an element from the queue */ -LI_API void waitqueue_remove(waitqueue *queue, waitqueue_elem *elem); +LI_API void waitqueue_remove(liWaitQueue *queue, liWaitQueueElem *elem); /* returns the length of the queue */ -LI_API guint waitqueue_length(waitqueue *queue); +LI_API guint waitqueue_length(liWaitQueue *queue); #endif diff --git a/include/lighttpd/worker.h b/include/lighttpd/worker.h index 70bc404..d86aded 100644 --- a/include/lighttpd/worker.h +++ b/include/lighttpd/worker.h @@ -5,10 +5,8 @@ #error Please include instead of this file #endif -struct statistics_t; -typedef struct statistics_t statistics_t; - -struct statistics_t { +typedef struct liStatistics liStatistics; +struct liStatistics { guint64 bytes_out; /** bytes transfered, outgoing */ guint64 bytes_in; /** bytes transfered, incoming */ @@ -41,14 +39,14 @@ struct statistics_t { #define WORKER_UNLOCK(srv, lock) \ if ((srv)->worker_count > 1) g_static_rec_mutex_unlock(lock) -struct worker_ts { +typedef struct liWorkerTS liWorkerTS; +struct liWorkerTS { time_t last_generated; GString *str; }; -typedef struct worker_ts worker_ts; -struct worker { - struct server *srv; +struct liWorker { + liServer *srv; GThread *thread; /* managed by server.c */ guint ndx; /* worker index */ @@ -72,9 +70,9 @@ struct worker { ev_timer keep_alive_timer; GQueue keep_alive_queue; - waitqueue io_timeout_queue; + liWaitQueue io_timeout_queue; - waitqueue throttle_queue; + liWaitQueue throttle_queue; guint connection_load; /** incremented by server_accept_cb, decremented by worker_con_put. use atomic access */ @@ -87,7 +85,7 @@ struct worker { GAsyncQueue *new_con_queue; ev_timer stats_watcher; - statistics_t stats; + liStatistics stats; /* collect framework */ ev_async collect_watcher; @@ -99,23 +97,23 @@ struct worker { GAsyncQueue *job_async_queue; ev_async job_async_queue_watcher; - stat_cache *stat_cache; + liStatCache *stat_cache; }; -LI_API worker* worker_new(struct server *srv, struct ev_loop *loop); -LI_API void worker_free(worker *wrk); +LI_API liWorker* worker_new(liServer *srv, struct ev_loop *loop); +LI_API void worker_free(liWorker *wrk); -LI_API void worker_run(worker *wrk); -LI_API void worker_stop(worker *context, worker *wrk); -LI_API void worker_exit(worker *context, worker *wrk); +LI_API void worker_run(liWorker *wrk); +LI_API void worker_stop(liWorker *context, liWorker *wrk); +LI_API void worker_exit(liWorker *context, liWorker *wrk); -LI_API void worker_new_con(worker *ctx, worker *wrk, sockaddr_t remote_addr, int s, server_socket *srv_sock); +LI_API void worker_new_con(liWorker *ctx, liWorker *wrk, liSocketAddress remote_addr, int s, liServerSocket *srv_sock); -LI_API void worker_check_keepalive(worker *wrk); +LI_API void worker_check_keepalive(liWorker *wrk); -LI_API GString* worker_current_timestamp(worker *wrk, guint format_ndx); +LI_API GString* worker_current_timestamp(liWorker *wrk, guint format_ndx); /* shutdown write and wait for eof before shutdown read and close */ -LI_API void worker_add_closing_socket(worker *wrk, int fd); +LI_API void worker_add_closing_socket(liWorker *wrk, int fd); #endif diff --git a/src/actions.c b/src/actions.c index f86603b..8485a49 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1,11 +1,10 @@ #include -struct action_stack_element; typedef struct action_stack_element action_stack_element; struct action_stack_element { - action *act; + liAction *act; union { gpointer context; guint pos; @@ -13,7 +12,7 @@ struct action_stack_element { gboolean finished, backlog_provided; }; -void action_release(server *srv, action *a) { +void action_release(liServer *srv, liAction *a) { guint i; if (!a) return; assert(g_atomic_int_get(&a->refcount) > 0); @@ -34,7 +33,7 @@ void action_release(server *srv, action *a) { break; case ACTION_TLIST: for (i = a->data.list->len; i-- > 0; ) { - action_release(srv, g_array_index(a->data.list, action*, i)); + action_release(srv, g_array_index(a->data.list, liAction*, i)); } g_array_free(a->data.list, TRUE); break; @@ -44,17 +43,17 @@ void action_release(server *srv, action *a) { } break; } - g_slice_free(action, a); + g_slice_free(liAction, a); } } -void action_acquire(action *a) { +void action_acquire(liAction *a) { assert(g_atomic_int_get(&a->refcount) > 0); g_atomic_int_inc(&a->refcount); } -action *action_new_setting(option_set setting) { - action *a = g_slice_new(action); +liAction *action_new_setting(liOptionSet setting) { + liAction *a = g_slice_new(liAction); a->refcount = 1; a->type = ACTION_TSETTING; @@ -63,10 +62,10 @@ action *action_new_setting(option_set setting) { return a; } -action *action_new_function(ActionFunc func, ActionCleanup fcleanup, ActionFree ffree, gpointer param) { - action *a; +liAction *action_new_function(liActionFuncCB func, liActionCleanupCB fcleanup, liActionFreeCB ffree, gpointer param) { + liAction *a; - a = g_slice_new(action); + a = g_slice_new(liAction); a->refcount = 1; a->type = ACTION_TFUNCTION; a->data.function.func = func; @@ -77,21 +76,21 @@ action *action_new_function(ActionFunc func, ActionCleanup fcleanup, ActionFree return a; } -action *action_new_list() { - action *a; +liAction *action_new_list() { + liAction *a; - a = g_slice_new(action); + a = g_slice_new(liAction); a->refcount = 1; a->type = ACTION_TLIST; - a->data.list = g_array_new(FALSE, TRUE, sizeof(action *)); + a->data.list = g_array_new(FALSE, TRUE, sizeof(liAction *)); return a; } -action *action_new_condition(condition *cond, action *target, action *target_else) { - action *a; +liAction *action_new_condition(liCondition *cond, liAction *target, liAction *target_else) { + liAction *a; - a = g_slice_new(action); + a = g_slice_new(liAction); a->refcount = 1; a->type = ACTION_TCONDITION; a->data.condition.cond = cond; @@ -101,10 +100,10 @@ action *action_new_condition(condition *cond, action *target, action *target_els return a; } -action *action_new_balancer(BackendSelect bselect, BackendFallback bfallback, BackendFinished bfinished, BalancerFree bfree, gpointer param, gboolean provide_backlog) { - action *a; +liAction *action_new_balancer(liBackendSelectCB bselect, liBackendFallbackCB bfallback, liBackendFinishedCB bfinished, liBalancerFreeCB bfree, gpointer param, gboolean provide_backlog) { + liAction *a; - a = g_slice_new(action); + a = g_slice_new(liAction); a->refcount = 1; a->type = ACTION_TBALANCER; a->data.balancer.select = bselect; @@ -117,8 +116,8 @@ action *action_new_balancer(BackendSelect bselect, BackendFallback bfallback, Ba return a; } -static void action_stack_element_release(server *srv, vrequest *vr, action_stack_element *ase) { - action *a = ase->act; +static void action_stack_element_release(liServer *srv, liVRequest *vr, action_stack_element *ase) { + liAction *a = ase->act; if (!ase || !a) return; @@ -131,10 +130,10 @@ static void action_stack_element_release(server *srv, vrequest *vr, action_stack } break; case ACTION_TCONDITION: - if (a->data.condition.cond->rvalue.type == COND_VALUE_REGEXP) { + if (a->data.condition.cond->rvalue.type == LI_COND_VALUE_REGEXP) { /* pop regex stack */ GArray *rs = vr->action_stack.regex_stack; - action_regex_stack_element *arse = &g_array_index(rs, action_regex_stack_element, rs->len - 1); + liActionRegexStackElement *arse = &g_array_index(rs, liActionRegexStackElement, rs->len - 1); if (arse->string) g_string_free(arse->string, TRUE); g_match_info_free(arse->match_info); @@ -153,14 +152,14 @@ static void action_stack_element_release(server *srv, vrequest *vr, action_stack ase->data.context = NULL; } -void action_stack_init(action_stack *as) { +void action_stack_init(liActionStack *as) { as->stack = g_array_sized_new(FALSE, TRUE, sizeof(action_stack_element), 15); - as->regex_stack = g_array_sized_new(FALSE, FALSE, sizeof(action_regex_stack_element), 15); + as->regex_stack = g_array_sized_new(FALSE, FALSE, sizeof(liActionRegexStackElement), 15); g_array_set_size(as->regex_stack, 0); } -void action_stack_reset(vrequest *vr, action_stack *as) { - server *srv = vr->wrk->srv; +void action_stack_reset(liVRequest *vr, liActionStack *as) { + liServer *srv = vr->wrk->srv; guint i; for (i = as->stack->len; i-- > 0; ) { action_stack_element_release(srv, vr, &g_array_index(as->stack, action_stack_element, i)); @@ -169,8 +168,8 @@ void action_stack_reset(vrequest *vr, action_stack *as) { as->backend_failed = FALSE; } -void action_stack_clear(vrequest *vr, action_stack *as) { - server *srv = vr->wrk->srv; +void action_stack_clear(liVRequest *vr, liActionStack *as) { + liServer *srv = vr->wrk->srv; guint i; for (i = as->stack->len; i-- > 0; ) { action_stack_element_release(srv, vr, &g_array_index(as->stack, action_stack_element, i)); @@ -180,13 +179,13 @@ void action_stack_clear(vrequest *vr, action_stack *as) { as->stack = NULL; } -static action_stack_element *action_stack_top(action_stack* as) { +static action_stack_element *action_stack_top(liActionStack* as) { return as->stack->len > 0 ? &g_array_index(as->stack, action_stack_element, as->stack->len - 1) : NULL; } /** handle sublist now, remember current position (stack) */ -void action_enter(vrequest *vr, action *a) { - action_stack *as = &vr->action_stack; +void action_enter(liVRequest *vr, liAction *a) { + liActionStack *as = &vr->action_stack; action_stack_element *top_ase = action_stack_top(as); action_stack_element ase = { a, { 0 }, FALSE, (top_ase ? top_ase->backlog_provided || (top_ase->act->type == ACTION_TBALANCER && top_ase->act->data.balancer.provide_backlog) : FALSE) }; @@ -194,22 +193,22 @@ void action_enter(vrequest *vr, action *a) { g_array_append_val(as->stack, ase); } -static void action_stack_pop(server *srv, vrequest *vr, action_stack *as) { +static void action_stack_pop(liServer *srv, liVRequest *vr, liActionStack *as) { action_stack_element_release(srv, vr, &g_array_index(as->stack, action_stack_element, as->stack->len - 1)); g_array_set_size(as->stack, as->stack->len - 1); } -handler_t action_execute(vrequest *vr) { - action *a; - action_stack *as = &vr->action_stack; +liHandlerResult action_execute(liVRequest *vr) { + liAction *a; + liActionStack *as = &vr->action_stack; action_stack_element *ase; - handler_t res; + liHandlerResult res; gboolean condres; - server *srv = vr->wrk->srv; + liServer *srv = vr->wrk->srv; while (NULL != (ase = action_stack_top(as))) { if (as->backend_failed) { - vr->state = VRS_HANDLE_REQUEST_HEADERS; + vr->state = LI_VRS_HANDLE_REQUEST_HEADERS; vr->backend = NULL; /* pop top action in every case (if the balancer itself failed we don't want to restart it) */ @@ -221,7 +220,7 @@ handler_t action_execute(vrequest *vr) { if (!ase) { /* no backlogging balancer found */ if (vrequest_handle_direct(vr)) vr->response.http_status = 503; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } as->backend_failed = FALSE; @@ -229,13 +228,13 @@ handler_t action_execute(vrequest *vr) { a = ase->act; res = a->data.balancer.fallback(vr, ase->backlog_provided, a->data.balancer.param, &ase->data.context, as->backend_error); switch (res) { - case HANDLER_GO_ON: + case LI_HANDLER_GO_ON: ase->finished = TRUE; break; - case HANDLER_ERROR: + case LI_HANDLER_ERROR: action_stack_reset(vr, as); - case HANDLER_COMEBACK: - case HANDLER_WAIT_FOR_EVENT: + case LI_HANDLER_COMEBACK: + case LI_HANDLER_WAIT_FOR_EVENT: return res; } continue; @@ -263,13 +262,13 @@ handler_t action_execute(vrequest *vr) { case ACTION_TFUNCTION: res = a->data.function.func(vr, a->data.function.param, &ase->data.context); switch (res) { - case HANDLER_GO_ON: + case LI_HANDLER_GO_ON: ase->finished = TRUE; break; - case HANDLER_ERROR: + case LI_HANDLER_ERROR: action_stack_reset(vr, as); - case HANDLER_COMEBACK: - case HANDLER_WAIT_FOR_EVENT: + case LI_HANDLER_COMEBACK: + case LI_HANDLER_WAIT_FOR_EVENT: return res; } break; @@ -277,7 +276,7 @@ handler_t action_execute(vrequest *vr) { condres = FALSE; res = condition_check(vr, a->data.condition.cond, &condres); switch (res) { - case HANDLER_GO_ON: + case LI_HANDLER_GO_ON: ase->finished = TRUE; if (condres) { if (a->data.condition.target) action_enter(vr, a->data.condition.target); @@ -286,10 +285,10 @@ handler_t action_execute(vrequest *vr) { action_enter(vr, a->data.condition.target_else); } break; - case HANDLER_ERROR: + case LI_HANDLER_ERROR: action_stack_reset(vr, as); - case HANDLER_COMEBACK: - case HANDLER_WAIT_FOR_EVENT: + case LI_HANDLER_COMEBACK: + case LI_HANDLER_WAIT_FOR_EVENT: return res; } break; @@ -297,20 +296,20 @@ handler_t action_execute(vrequest *vr) { if (ase->data.pos >= a->data.list->len) { action_stack_pop(srv, vr, as); } else { - action_enter(vr, g_array_index(a->data.list, action*, ase->data.pos)); + action_enter(vr, g_array_index(a->data.list, liAction*, ase->data.pos)); ase->data.pos++; } break; case ACTION_TBALANCER: res = a->data.balancer.select(vr, ase->backlog_provided, a->data.balancer.param, &ase->data.context); switch (res) { - case HANDLER_GO_ON: + case LI_HANDLER_GO_ON: ase->finished = TRUE; break; - case HANDLER_ERROR: + case LI_HANDLER_ERROR: action_stack_reset(vr, as); - case HANDLER_COMEBACK: - case HANDLER_WAIT_FOR_EVENT: + case LI_HANDLER_COMEBACK: + case LI_HANDLER_WAIT_FOR_EVENT: return res; } break; @@ -320,5 +319,5 @@ handler_t action_execute(vrequest *vr) { if (vrequest_handle_direct(vr)) vr->response.http_status = 503; } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } diff --git a/src/actions_lua.c b/src/actions_lua.c index c422224..7667eb1 100644 --- a/src/actions_lua.c +++ b/src/actions_lua.c @@ -6,7 +6,7 @@ #define LUA_ACTION "action*" -action* lua_get_action(lua_State *L, int ndx) { +liAction* lua_get_action(lua_State *L, int ndx) { if (!lua_isuserdata(L, ndx)) return NULL; if (!lua_getmetatable(L, ndx)) return NULL; luaL_getmetatable(L, LUA_ACTION); @@ -15,23 +15,23 @@ action* lua_get_action(lua_State *L, int ndx) { return NULL; } lua_pop(L, 2); - return *(action**) lua_touserdata(L, ndx); + return *(liAction**) lua_touserdata(L, ndx); } static int lua_action_gc(lua_State *L) { - server *srv; - action **a = (action**) luaL_checkudata(L, 1, LUA_ACTION); + liServer *srv; + liAction **a = (liAction**) luaL_checkudata(L, 1, LUA_ACTION); if (!a || !*a) return 0; - srv = (server*) lua_touserdata(L, lua_upvalueindex(1)); + srv = (liServer*) lua_touserdata(L, lua_upvalueindex(1)); action_release(srv, *a); return 0; } -int lua_push_action(server *srv, lua_State *L, action *a) { - action **pa; +int lua_push_action(liServer *srv, lua_State *L, liAction *a) { + liAction **pa; - pa = (action**) lua_newuserdata(L, sizeof(action*)); + pa = (liAction**) lua_newuserdata(L, sizeof(liAction*)); *pa = a; if (luaL_newmetatable(L, LUA_ACTION)) { diff --git a/src/angel.c b/src/angel.c index 5a2d302..04b4a93 100644 --- a/src/angel.c +++ b/src/angel.c @@ -2,27 +2,27 @@ #include #include -static void angel_call_cb(angel_connection *acon, +static void angel_call_cb(liAngelConnection *acon, const gchar *mod, gsize mod_len, const gchar *action, gsize action_len, gint32 id, GString *data) { - server *srv = acon->data; + liServer *srv = acon->data; ERROR(srv, "received message for %s:%s, not implemented yet", mod, action); if (-1 != id) angel_send_result(acon, id, g_string_new_len(CONST_STR_LEN("not implemented yet")), NULL, NULL, NULL); } -static void angel_close_cb(angel_connection *acon, GError *err) { - server *srv = acon->data; +static void angel_close_cb(liAngelConnection *acon, GError *err) { + liServer *srv = acon->data; ERROR(srv, "fatal: angel connection close: %s", err ? err->message : g_strerror(errno)); if (err) g_error_free(err); exit(1); } -void angel_setup(server *srv) { +void angel_setup(liServer *srv) { srv->acon = angel_connection_new(srv->loop, 0, srv, angel_call_cb, angel_close_cb); } -static void angel_listen_cb(angel_call *acall, gpointer ctx, gboolean timeout, GString *error, GString *data, GArray *fds) { - server *srv = ctx; +static void angel_listen_cb(liAngelCall *acall, gpointer ctx, gboolean timeout, GString *error, GString *data, GArray *fds) { + liServer *srv = ctx; guint i; UNUSED(data); @@ -53,9 +53,9 @@ static void angel_listen_cb(angel_call *acall, gpointer ctx, gboolean timeout, G } /* listen to a socket */ -void angel_listen(server *srv, GString *str) { +void angel_listen(liServer *srv, GString *str) { if (srv->acon) { - angel_call *acall = angel_call_new(angel_listen_cb, 3.0); + liAngelCall *acall = angel_call_new(angel_listen_cb, 3.0); GError *err = NULL; acall->context = srv; @@ -75,6 +75,6 @@ void angel_listen(server *srv, GString *str) { } /* send log messages while startup to angel */ -void angel_log(server *srv, GString *str) { +void angel_log(liServer *srv, GString *str) { angel_fake_log(srv, str); } diff --git a/src/angel_config_parser.rl b/src/angel_config_parser.rl index 6bce68b..53ea66d 100644 --- a/src/angel_config_parser.rl +++ b/src/angel_config_parser.rl @@ -19,14 +19,14 @@ typedef struct { /* item */ GString *itemname; - value *itemvalue; + liValue *itemvalue; /* every time a collection gets parsed, the collection is pushed on the stack. - * in some other cases a VALUE_STRING gets pushed (the key in hashes for example) + * in some other cases a LI_VALUE_STRING gets pushed (the key in hashes for example) * while a second value gets parsed. */ GPtrArray *valuestack; - value *curvalue; + liValue *curvalue; /* temporary buffer to format a character for logging */ gchar buf[8]; @@ -56,8 +56,8 @@ static gchar *format_char(pcontext *ctx, gchar c) { #define PARSE_ERROR_FMT(fmt, ...) do { \ g_set_error(err, \ - ANGEL_CONFIG_PARSER_ERROR, \ - ANGEL_CONFIG_PARSER_ERROR_PARSE, \ + LI_ANGEL_CONFIG_PARSER_ERROR, \ + LI_ANGEL_CONFIG_PARSER_ERROR_PARSE, \ "Parsing failed in '%s:%i,%i': " fmt, \ fctx->filename, fctx->line, fctx->column, \ __VA_ARGS__); \ @@ -211,7 +211,7 @@ static gchar *format_char(pcontext *ctx, gchar c) { } action value_range { - value_range vr = { ctx->number2, ctx->number }; + liValueRange vr = { ctx->number2, ctx->number }; ctx->curvalue = value_new_range(vr); if (ctx->number2 > ctx->number) { GString *tmp = value_to_string(ctx->curvalue); @@ -233,7 +233,7 @@ static gchar *format_char(pcontext *ctx, gchar c) { fcall value_list_sub; } action value_list_push { - value *vlist = g_ptr_array_index(ctx->valuestack, ctx->valuestack->len-1); + liValue *vlist = g_ptr_array_index(ctx->valuestack, ctx->valuestack->len-1); g_ptr_array_add(vlist->data.list, ctx->curvalue); ctx->curvalue = NULL; } @@ -255,8 +255,8 @@ static gchar *format_char(pcontext *ctx, gchar c) { } action value_hash_push_value { guint ndx = ctx->valuestack->len-1; - value *vname = g_ptr_array_index(ctx->valuestack, ndx); - value *vhash = g_ptr_array_index(ctx->valuestack, ndx-1); + liValue *vname = g_ptr_array_index(ctx->valuestack, ndx); + liValue *vhash = g_ptr_array_index(ctx->valuestack, ndx-1); g_ptr_array_set_size(ctx->valuestack, ndx); if (NULL != g_hash_table_lookup(vhash->data.hash, vname->data.string)) { UPDATE_COLUMN(); @@ -266,7 +266,7 @@ static gchar *format_char(pcontext *ctx, gchar c) { } g_hash_table_insert(vhash->data.hash, vname->data.string, ctx->curvalue); ctx->curvalue = NULL; - vname->type = VALUE_NONE; + vname->type = LI_VALUE_NONE; value_free(vname); } action value_hash_end { @@ -283,7 +283,7 @@ static gchar *format_char(pcontext *ctx, gchar c) { } action option_push { guint ndx = ctx->valuestack->len-1; - value *vname = g_ptr_array_index(ctx->valuestack, ndx); + liValue *vname = g_ptr_array_index(ctx->valuestack, ndx); g_ptr_array_set_size(ctx->valuestack, ndx); if (!ctx->curvalue) ctx->curvalue = value_new_none(); if (NULL != g_hash_table_lookup(ctx->itemvalue->data.hash, vname->data.string)) { @@ -294,7 +294,7 @@ static gchar *format_char(pcontext *ctx, gchar c) { } g_hash_table_insert(ctx->itemvalue->data.hash, vname->data.string, ctx->curvalue); ctx->curvalue = NULL; - vname->type = VALUE_NONE; + vname->type = LI_VALUE_NONE; value_free(vname); } @@ -421,7 +421,7 @@ static gboolean angel_config_parser_finalize(pcontext *ctx, filecontext *fctx, G return TRUE; } -static gboolean angel_config_parse_data(server *srv, pcontext *ctx, filecontext *fctx, gchar *data, gsize len, GError **err) { +static gboolean angel_config_parse_data(liServer *srv, pcontext *ctx, filecontext *fctx, gchar *data, gsize len, GError **err) { gchar *p = data, *pe = p+len, *eof = NULL, *linestart = p, *tokenstart = NULL; if (ctx->readingtoken) tokenstart = p; @@ -442,7 +442,7 @@ static gboolean angel_config_parse_data(server *srv, pcontext *ctx, filecontext return TRUE; } -gboolean angel_config_parse_file(server *srv, const gchar *filename, GError **err) { +gboolean angel_config_parse_file(liServer *srv, const gchar *filename, GError **err) { char *data = NULL; gsize len = 0; filecontext sfctx, *fctx = &sfctx; diff --git a/src/angel_connection.c b/src/angel_connection.c index 08b6dac..e2300b0 100644 --- a/src/angel_connection.c +++ b/src/angel_connection.c @@ -91,7 +91,7 @@ GQuark angel_connection_error_quark() { return g_quark_from_static_string("angel-connection-error-quark"); } -static gboolean angel_fill_buffer(angel_connection *acon, guint need, GError **err) { +static gboolean angel_fill_buffer(liAngelConnection *acon, guint need, GError **err) { gsize old_len; ssize_t want, r; if (acon->in.pos > 0) { @@ -116,7 +116,7 @@ static gboolean angel_fill_buffer(angel_connection *acon, guint need, GError **e g_string_set_size(acon->in.data, old_len); return TRUE; default: - g_set_error(err, ANGEL_CONNECTION_ERROR, ANGEL_CONNECTION_CLOSED, + g_set_error(err, LI_ANGEL_CONNECTION_ERROR, LI_ANGEL_CONNECTION_CLOSED, "read error: %s", g_strerror(errno)); g_string_set_size(acon->in.data, old_len); return FALSE; @@ -143,23 +143,23 @@ static void close_fd_array(GArray *fds) { g_array_set_size(fds, 0); } -static gboolean angel_dispatch(angel_connection *acon, GError **err) { +static gboolean angel_dispatch(liAngelConnection *acon, GError **err) { gint32 id = acon->parse.id, type = acon->parse.type; - angel_call *call = NULL; - AngelCallback cb = NULL; + liAngelCall *call = NULL; + liAngelCallCB cb = NULL; gpointer ctx; switch (type) { case ANGEL_CALL_SEND_SIMPLE: if (-1 != id) { - g_set_error(err, ANGEL_CONNECTION_ERROR, ANGEL_CONNECTION_INVALID_DATA, + g_set_error(err, LI_ANGEL_CONNECTION_ERROR, LI_ANGEL_CONNECTION_INVALID_DATA, "Invalid id: %i, should be -1 for simple call", (gint) id); close_fd_array(acon->parse.fds); return FALSE; } if (acon->parse.error->len > 0 || acon->parse.fds->len > 0) { - g_set_error(err, ANGEL_CONNECTION_ERROR, ANGEL_CONNECTION_INVALID_DATA, + g_set_error(err, LI_ANGEL_CONNECTION_ERROR, LI_ANGEL_CONNECTION_INVALID_DATA, "Wrong data in call"); close_fd_array(acon->parse.fds); return FALSE; @@ -169,14 +169,14 @@ static gboolean angel_dispatch(angel_connection *acon, GError **err) { break; case ANGEL_CALL_SEND_CALL: if (-1 == id) { - g_set_error(err, ANGEL_CONNECTION_ERROR, ANGEL_CONNECTION_INVALID_DATA, + g_set_error(err, LI_ANGEL_CONNECTION_ERROR, LI_ANGEL_CONNECTION_INVALID_DATA, "Invalid id: -1, should be >= 0 for call"); close_fd_array(acon->parse.fds); return FALSE; } if (acon->parse.error->len > 0 || acon->parse.fds->len > 0) { - g_set_error(err, ANGEL_CONNECTION_ERROR, ANGEL_CONNECTION_INVALID_DATA, + g_set_error(err, LI_ANGEL_CONNECTION_ERROR, LI_ANGEL_CONNECTION_INVALID_DATA, "Wrong data in call"); close_fd_array(acon->parse.fds); return FALSE; @@ -189,20 +189,20 @@ static gboolean angel_dispatch(angel_connection *acon, GError **err) { g_mutex_lock(acon->mutex); if (!idlist_is_used(acon->call_id_list, id)) { g_mutex_unlock(acon->mutex); - g_set_error(err, ANGEL_CONNECTION_ERROR, ANGEL_CONNECTION_INVALID_DATA, + g_set_error(err, LI_ANGEL_CONNECTION_ERROR, LI_ANGEL_CONNECTION_INVALID_DATA, "Invalid id: %i", (gint) id); close_fd_array(acon->parse.fds); return FALSE; } idlist_put(acon->call_id_list, id); if (type == ANGEL_CALL_SEND_RESULT && (guint) id < acon->call_table->len) { - call = (angel_call*) g_ptr_array_index(acon->call_table, id); + call = (liAngelCall*) g_ptr_array_index(acon->call_table, id); g_ptr_array_index(acon->call_table, id) = NULL; if (call) { ev_timer_stop(acon->loop, &call->timeout_watcher); ctx = call->context; if (NULL == (cb = call->callback)) { - g_slice_free(angel_call, call); + g_slice_free(liAngelCall, call); } } } @@ -214,7 +214,7 @@ static gboolean angel_dispatch(angel_connection *acon, GError **err) { close_fd_array(acon->parse.fds); break; default: - g_set_error(err, ANGEL_CONNECTION_ERROR, ANGEL_CONNECTION_INVALID_DATA, + g_set_error(err, LI_ANGEL_CONNECTION_ERROR, LI_ANGEL_CONNECTION_INVALID_DATA, "Invalid type: %i", (gint) type); close_fd_array(acon->parse.fds); return FALSE; @@ -223,7 +223,7 @@ static gboolean angel_dispatch(angel_connection *acon, GError **err) { return TRUE; } -static gboolean angel_connection_read(angel_connection *acon, GError **err) { +static gboolean angel_connection_read(liAngelConnection *acon, GError **err) { for ( ;; ) { if (!acon->parse.have_header) { gint32 magic; @@ -240,7 +240,7 @@ static gboolean angel_connection_read(angel_connection *acon, GError **err) { if (!angel_data_read_int32(&acon->in, &acon->parse.missing_fds, err)) return FALSE; if (ANGEL_MAGIC != magic) { - g_set_error(err, ANGEL_CONNECTION_ERROR, ANGEL_CONNECTION_INVALID_DATA, + g_set_error(err, LI_ANGEL_CONNECTION_ERROR, LI_ANGEL_CONNECTION_INVALID_DATA, "Invalid magic: 0x%x (should be 0x%x)", (gint) magic, (gint) ANGEL_MAGIC); return FALSE; } @@ -259,7 +259,7 @@ static gboolean angel_connection_read(angel_connection *acon, GError **err) { acon->parse.missing_fds--; break; case -1: - g_set_error(err, ANGEL_CONNECTION_ERROR, ANGEL_CONNECTION_CLOSED, + g_set_error(err, LI_ANGEL_CONNECTION_ERROR, LI_ANGEL_CONNECTION_CLOSED, "receive fd error: %s", g_strerror(errno)); return FALSE; case -2: @@ -283,7 +283,7 @@ static gboolean angel_connection_read(angel_connection *acon, GError **err) { } static void angel_connection_io_cb(struct ev_loop *loop, ev_io *w, int revents) { - angel_connection *acon = (angel_connection*) w->data; + liAngelConnection *acon = (liAngelConnection*) w->data; if (revents | EV_WRITE) { GString *out_str; @@ -374,15 +374,15 @@ write_eagain: } static void angel_connection_out_notify_cb(struct ev_loop *loop, ev_async *w, int revents) { - angel_connection *acon = (angel_connection*) w->data; + liAngelConnection *acon = (liAngelConnection*) w->data; UNUSED(revents); ev_io_add_events(loop, &acon->fd_watcher, EV_WRITE); } /* create connection */ -angel_connection* angel_connection_new(struct ev_loop *loop, int fd, gpointer data, - AngelReceiveCall recv_call, AngelCloseCallback close_cb) { - angel_connection *acon = g_slice_new0(angel_connection); +liAngelConnection* angel_connection_new(struct ev_loop *loop, int fd, gpointer data, + liAngelReceiveCallCB recv_call, liAngelCloseCB close_cb) { + liAngelConnection *acon = g_slice_new0(liAngelConnection); acon->data = data; acon->mutex = g_mutex_new(); @@ -412,7 +412,7 @@ angel_connection* angel_connection_new(struct ev_loop *loop, int fd, gpointer da return acon; } -void angel_connection_free(angel_connection *acon) { +void angel_connection_free(liAngelConnection *acon) { angel_connection_send_item_t *send_item; guint i; @@ -424,8 +424,8 @@ void angel_connection_free(angel_connection *acon) { acon->fd = -1; for (i = 0; i < acon->call_table->len; i++) { - angel_call *acall = g_ptr_array_index(acon->call_table, i); - AngelCallback cb; + liAngelCall *acall = g_ptr_array_index(acon->call_table, i); + liAngelCallCB cb; if (!acall) continue; g_ptr_array_index(acon->call_table, i) = NULL; @@ -434,7 +434,7 @@ void angel_connection_free(angel_connection *acon) { if (cb) { cb(acall, acall->context, TRUE, NULL, NULL, NULL); } else { - g_slice_free(angel_call, acall); + g_slice_free(liAngelCall, acall); } } g_ptr_array_free(acon->call_table, TRUE); @@ -453,20 +453,20 @@ void angel_connection_free(angel_connection *acon) { g_string_free(acon->in.data, TRUE); /* TODO */ - g_slice_free(angel_connection, acon); + g_slice_free(liAngelConnection, acon); } static void angel_call_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) { - angel_call* call = (angel_call*) w->data; - angel_connection *acon = call->acon; - AngelCallback cb = NULL; + liAngelCall* call = (liAngelCall*) w->data; + liAngelConnection *acon = call->acon; + liAngelCallCB cb = NULL; gpointer ctx; UNUSED(loop); UNUSED(revents); g_mutex_lock(acon->mutex); g_ptr_array_index(acon->call_table, call->id) = NULL; if (NULL == (cb = call->callback)) { - g_slice_free(angel_call, call); + g_slice_free(liAngelCall, call); } ctx = call->context; g_mutex_unlock(acon->mutex); @@ -474,8 +474,8 @@ static void angel_call_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents if (cb) cb(call, ctx, TRUE, NULL, NULL, NULL); } -angel_call *angel_call_new(AngelCallback callback, ev_tstamp timeout) { - angel_call* call = g_slice_new0(angel_call); +liAngelCall *angel_call_new(liAngelCallCB callback, ev_tstamp timeout) { + liAngelCall* call = g_slice_new0(liAngelCall); g_assert(NULL != callback); call->callback = callback; @@ -487,21 +487,21 @@ angel_call *angel_call_new(AngelCallback callback, ev_tstamp timeout) { } /* returns TRUE if a call was cancelled */ -gboolean angel_call_free(angel_call *call) { +gboolean angel_call_free(liAngelCall *call) { gboolean r = FALSE; if (call->acon) { - angel_connection *acon = call->acon; + liAngelConnection *acon = call->acon; g_mutex_lock(acon->mutex); if (-1 != call->id) { r = TRUE; call->callback = NULL; } else { - g_slice_free(angel_call, call); + g_slice_free(liAngelCall, call); } g_mutex_unlock(acon->mutex); } else { - g_slice_free(angel_call, call); + g_slice_free(liAngelCall, call); } return r; @@ -540,7 +540,7 @@ static gboolean prepare_call_header(GString **pbuf, } gboolean angel_send_simple_call( - angel_connection *acon, + liAngelConnection *acon, const gchar *mod, gsize mod_len, const gchar *action, gsize action_len, GString *data, GError **err) { @@ -550,12 +550,12 @@ gboolean angel_send_simple_call( if (err && *err) goto error; if (-1 == acon->fd) { - g_set_error(err, ANGEL_CONNECTION_ERROR, ANGEL_CONNECTION_CLOSED, "connection already closed"); + g_set_error(err, LI_ANGEL_CONNECTION_ERROR, LI_ANGEL_CONNECTION_CLOSED, "connection already closed"); goto error; } if (data->len > ANGEL_CALL_MAX_STR_LEN) { - g_set_error(err, ANGEL_CALL_ERROR, ANGEL_CALL_INVALID, "data too lang for angel call: %" G_GSIZE_FORMAT " > %i", data->len, ANGEL_CALL_MAX_STR_LEN); + g_set_error(err, LI_ANGEL_CALL_ERROR, LI_ANGEL_CALL_INVALID, "data too lang for angel call: %" G_GSIZE_FORMAT " > %i", data->len, ANGEL_CALL_MAX_STR_LEN); goto error; } @@ -579,9 +579,9 @@ error: } gboolean angel_send_call( - angel_connection *acon, + liAngelConnection *acon, const gchar *mod, gsize mod_len, const gchar *action, gsize action_len, - angel_call *call, + liAngelCall *call, GString *data, GError **err) { GString *buf = NULL; @@ -590,20 +590,20 @@ gboolean angel_send_call( if (err && *err) goto error; if (-1 == acon->fd) { - g_set_error(err, ANGEL_CONNECTION_ERROR, ANGEL_CONNECTION_CLOSED, "connection already closed"); + g_set_error(err, LI_ANGEL_CONNECTION_ERROR, LI_ANGEL_CONNECTION_CLOSED, "connection already closed"); goto error; } g_mutex_lock(acon->mutex); if (-1 != call->id) { g_mutex_unlock(acon->mutex); - g_set_error(err, ANGEL_CALL_ERROR, ANGEL_CALL_ALREADY_RUNNING, "call already running"); + g_set_error(err, LI_ANGEL_CALL_ERROR, LI_ANGEL_CALL_ALREADY_RUNNING, "call already running"); goto error_before_new_id; } if (-1 == (call->id = idlist_get(acon->call_id_list))) { g_mutex_unlock(acon->mutex); - g_set_error(err, ANGEL_CALL_ERROR, ANGEL_CALL_OUT_OF_CALL_IDS, "out of call ids"); + g_set_error(err, LI_ANGEL_CALL_ERROR, LI_ANGEL_CALL_OUT_OF_CALL_IDS, "out of call ids"); goto error; } call->acon = acon; @@ -615,7 +615,7 @@ gboolean angel_send_call( g_mutex_unlock(acon->mutex); if (data && data->len > ANGEL_CALL_MAX_STR_LEN) { - g_set_error(err, ANGEL_CALL_ERROR, ANGEL_CALL_INVALID, "data too lang for angel call: %" G_GSIZE_FORMAT " > %i", data->len, ANGEL_CALL_MAX_STR_LEN); + g_set_error(err, LI_ANGEL_CALL_ERROR, LI_ANGEL_CALL_INVALID, "data too lang for angel call: %" G_GSIZE_FORMAT " > %i", data->len, ANGEL_CALL_MAX_STR_LEN); goto error; } @@ -647,7 +647,7 @@ error_before_new_id: } gboolean angel_send_result( - angel_connection *acon, + liAngelConnection *acon, gint32 id, GString *error, GString *data, GArray *fds, GError **err) { @@ -657,12 +657,12 @@ gboolean angel_send_result( if (err && *err) goto error; if (-1 == acon->fd) { - g_set_error(err, ANGEL_CONNECTION_ERROR, ANGEL_CONNECTION_CLOSED, "connection already closed"); + g_set_error(err, LI_ANGEL_CONNECTION_ERROR, LI_ANGEL_CONNECTION_CLOSED, "connection already closed"); goto error; } if (data && data->len > ANGEL_CALL_MAX_STR_LEN) { - g_set_error(err, ANGEL_CALL_ERROR, ANGEL_CALL_INVALID, "data too lang for angel call: %" G_GSIZE_FORMAT " > %i", data->len, ANGEL_CALL_MAX_STR_LEN); + g_set_error(err, LI_ANGEL_CALL_ERROR, LI_ANGEL_CALL_INVALID, "data too lang for angel call: %" G_GSIZE_FORMAT " > %i", data->len, ANGEL_CALL_MAX_STR_LEN); goto error; } @@ -692,7 +692,7 @@ error: } /* free temporary needed memroy; call this once in while after some activity */ -void angel_cleanup_tables(angel_connection *acon) { +void angel_cleanup_tables(liAngelConnection *acon) { UNUSED(acon); /* TODO guint max_used_id = idlist_cleanup(acon->call_id_list); diff --git a/src/angel_data.c b/src/angel_data.c index 7db157a..fe9ad7d 100644 --- a/src/angel_data.c +++ b/src/angel_data.c @@ -9,8 +9,8 @@ GQuark angel_data_error_quark() { static gboolean error_eof(GError **err, const gchar *info) { g_set_error(err, - ANGEL_DATA_ERROR, - ANGEL_DATA_ERROR_EOF, + LI_ANGEL_DATA_ERROR, + LI_ANGEL_DATA_ERROR_EOF, "Not enough data to read value '%s'", info); return FALSE; } @@ -37,10 +37,10 @@ gboolean angel_data_write_char (GString *buf, gchar c, GError **err) { gboolean angel_data_write_str (GString *buf, const GString *str, GError **err) { g_return_val_if_fail(err == NULL || *err == NULL, FALSE); - if (str->len > ANGEL_DATA_MAX_STR_LEN) { + if (str->len > LI_ANGEL_DATA_MAX_STR_LEN) { g_set_error(err, - ANGEL_DATA_ERROR, - ANGEL_DATA_ERROR_STRING_TOO_LONG, + LI_ANGEL_DATA_ERROR, + LI_ANGEL_DATA_ERROR_STRING_TOO_LONG, "String too long (len: %" G_GSIZE_FORMAT "): '%s'", str->len, str->str); return FALSE; } @@ -56,7 +56,7 @@ gboolean angel_data_write_cstr (GString *buf, const gchar *str, gsize len, GErro /* read */ -gboolean angel_data_read_int32(angel_buffer *buf, gint32 *val, GError **err) { +gboolean angel_data_read_int32(liAngelBuffer *buf, gint32 *val, GError **err) { g_return_val_if_fail(err == NULL || *err == NULL, FALSE); if (buf->data->len - buf->pos < sizeof(gint32)) { return error_eof(err, "int32"); @@ -68,7 +68,7 @@ gboolean angel_data_read_int32(angel_buffer *buf, gint32 *val, GError **err) { return TRUE; } -gboolean angel_data_read_int64(angel_buffer *buf, gint64 *val, GError **err) { +gboolean angel_data_read_int64(liAngelBuffer *buf, gint64 *val, GError **err) { g_return_val_if_fail(err == NULL || *err == NULL, FALSE); if (buf->data->len - buf->pos < sizeof(gint64)) { return error_eof(err, "int64"); @@ -80,7 +80,7 @@ gboolean angel_data_read_int64(angel_buffer *buf, gint64 *val, GError **err) { return TRUE; } -gboolean angel_data_read_char (angel_buffer *buf, gchar *val, GError **err) { +gboolean angel_data_read_char (liAngelBuffer *buf, gchar *val, GError **err) { g_return_val_if_fail(err == NULL || *err == NULL, FALSE); if (buf->data->len - buf->pos < sizeof(gchar)) { return error_eof(err, "char"); @@ -92,7 +92,7 @@ gboolean angel_data_read_char (angel_buffer *buf, gchar *val, GError **err) { return TRUE; } -gboolean angel_data_read_mem (angel_buffer *buf, GString **val, gsize len, GError **err) { +gboolean angel_data_read_mem (liAngelBuffer *buf, GString **val, gsize len, GError **err) { GString *s; g_return_val_if_fail(err == NULL || *err == NULL, FALSE); @@ -110,7 +110,7 @@ gboolean angel_data_read_mem (angel_buffer *buf, GString **val, gsize len, GErr return TRUE; } -gboolean angel_data_read_str (angel_buffer *buf, GString **val, GError **err) { +gboolean angel_data_read_str (liAngelBuffer *buf, GString **val, GError **err) { gint32 ilen; g_return_val_if_fail(err == NULL || *err == NULL, FALSE); @@ -119,11 +119,11 @@ gboolean angel_data_read_str (angel_buffer *buf, GString **val, GError **err) { } memcpy(&ilen, buf->data->str + buf->pos, sizeof(ilen)); buf->pos += sizeof(gint32); - if (ilen < 0 || ilen > ANGEL_DATA_MAX_STR_LEN) { + if (ilen < 0 || ilen > LI_ANGEL_DATA_MAX_STR_LEN) { buf->pos -= sizeof(gint32); g_set_error(err, - ANGEL_DATA_ERROR, - ANGEL_DATA_ERROR_INVALID_STRING_LENGTH, + LI_ANGEL_DATA_ERROR, + LI_ANGEL_DATA_ERROR_INVALID_STRING_LENGTH, "String length in buffer invalid: %i", (gint) ilen); return FALSE; } diff --git a/src/angel_fake.c b/src/angel_fake.c index 1b6142e..a318815 100644 --- a/src/angel_fake.c +++ b/src/angel_fake.c @@ -4,7 +4,7 @@ #include /* listen to a socket */ -int angel_fake_listen(server *srv, GString *str) { +int angel_fake_listen(liServer *srv, GString *str) { guint32 ipv4; #ifdef HAVE_IPV6 guint8 ipv6[16]; @@ -92,7 +92,7 @@ int angel_fake_listen(server *srv, GString *str) { } /* print log messages during startup to stderr */ -gboolean angel_fake_log(server *srv, GString *str) { +gboolean angel_fake_log(liServer *srv, GString *str) { const char *buf; guint len; ssize_t written; diff --git a/src/angel_log.c b/src/angel_log.c index 7165d6d..bfb24de 100644 --- a/src/angel_log.c +++ b/src/angel_log.c @@ -1,7 +1,7 @@ #include -#if REMOVE_PATH_FROM_FILE +#if LI_REMOVE_PATH_FROM_FILE const char *remove_path(const char *path) { char *p = strrchr(path, DIR_SEPERATOR); if (NULL != p && *(p) != '\0') { @@ -11,27 +11,27 @@ const char *remove_path(const char *path) { } #endif -void log_init(server *srv) { - srv->log.type = LOG_TYPE_STDERR; +void log_init(liServer *srv) { + srv->log.type = LI_LOG_TYPE_STDERR; - srv->log.levels[LOG_LEVEL_ABORT] = TRUE; - srv->log.levels[LOG_LEVEL_ERROR] = TRUE; - srv->log.levels[LOG_LEVEL_WARNING] = TRUE; + srv->log.levels[LI_LOG_LEVEL_ABORT] = TRUE; + srv->log.levels[LI_LOG_LEVEL_ERROR] = TRUE; + srv->log.levels[LI_LOG_LEVEL_WARNING] = TRUE; - srv->log.levels[LOG_LEVEL_INFO] = TRUE; /* TODO: remove debug levels */ - srv->log.levels[LOG_LEVEL_DEBUG] = TRUE; + srv->log.levels[LI_LOG_LEVEL_INFO] = TRUE; /* TODO: remove debug levels */ + srv->log.levels[LI_LOG_LEVEL_DEBUG] = TRUE; srv->log.fd = -1; srv->log.ts_cache = g_string_sized_new(0); srv->log.log_line = g_string_sized_new(0); } -void log_clean(server *srv) { +void log_clean(liServer *srv) { g_string_free(srv->log.ts_cache, TRUE); g_string_free(srv->log.log_line, TRUE); } -void log_write(server *srv, log_level_t log_level, guint flags, const gchar *fmt, ...) { +void log_write(liServer *srv, liLogLevel log_level, guint flags, const gchar *fmt, ...) { va_list ap; GString *log_line = srv->log.log_line; @@ -40,7 +40,7 @@ void log_write(server *srv, log_level_t log_level, guint flags, const gchar *fmt g_string_truncate(log_line, 0); /* for normal error messages, we prepend a timestamp */ - if (flags & LOG_FLAG_TIMESTAMP) { + if (flags & LI_LOG_FLAG_TIMESTAMP) { GString *log_ts = srv->log.ts_cache; time_t cur_ts; diff --git a/src/angel_main.c b/src/angel_main.c index bab97e9..6e4d760 100644 --- a/src/angel_main.c +++ b/src/angel_main.c @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) { gboolean res; int result = 0; - server* srv = NULL; + liServer* srv = NULL; GOptionEntry entries[] = { { "config", 'c', 0, G_OPTION_ARG_FILENAME, &config_path, "filename/path of the config", "PATH" }, diff --git a/src/angel_plugin.c b/src/angel_plugin.c index 9478c18..7b22a86 100644 --- a/src/angel_plugin.c +++ b/src/angel_plugin.c @@ -7,17 +7,17 @@ typedef struct server_item server_item; struct server_item { - plugin *p; + liPlugin *p; guint option_count; - const plugin_item *p_item; + const liPluginItem *p_item; }; typedef struct server_module server_module; struct server_module { guint refcount; gchar *name; - server *srv; - module *mod; + liServer *srv; + liModule *mod; GPtrArray *plugins; /* plugin* */ }; @@ -25,9 +25,9 @@ static void _server_item_free(gpointer p) { g_slice_free(server_item, p); } -static server_item* server_item_new(plugin *p, const plugin_item *p_item) { +static server_item* server_item_new(liPlugin *p, const liPluginItem *p_item) { server_item *si = g_slice_new(server_item); - const plugin_item_option *pio; + const liPluginItemOption *pio; guint cnt; for (pio = p_item->options, cnt = 0; pio->name; pio++, cnt++) ; si->p = p; @@ -36,14 +36,14 @@ static server_item* server_item_new(plugin *p, const plugin_item *p_item) { return si; } -static void plugin_free(server *srv, plugin *p) { +static void plugin_free(liServer *srv, liPlugin *p) { if (p->handle_free) p->handle_free(srv, p); g_hash_table_destroy(p->angel_callbacks); - g_slice_free(plugin, p); + g_slice_free(liPlugin, p); } -static plugin* plugin_new(const char *name) { - plugin *p = g_slice_new0(plugin); +static liPlugin* plugin_new(const char *name) { + liPlugin *p = g_slice_new0(liPlugin); p->name = name; p->angel_callbacks = g_hash_table_new(g_str_hash, g_str_equal); return p; @@ -57,7 +57,7 @@ static void _server_module_release(gpointer d) { if (0 != --sm->refcount) return; for (i = sm->plugins->len; i-- > 0; ) { - plugin *p = g_ptr_array_index(sm->plugins, i); + liPlugin *p = g_ptr_array_index(sm->plugins, i); plugin_free(sm->srv, p); } g_ptr_array_free(sm->plugins, TRUE); @@ -71,7 +71,7 @@ static void server_module_acquire(server_module *sm) { sm->refcount++; } -static server_module* server_module_new(server *srv, const gchar *name) { /* module is set later */ +static server_module* server_module_new(liServer *srv, const gchar *name) { /* module is set later */ server_module *sm = g_slice_new0(server_module); sm->refcount = 1; sm->srv = srv; @@ -80,8 +80,8 @@ static server_module* server_module_new(server *srv, const gchar *name) { /* mod return sm; } -void plugins_init(server *srv, const gchar *module_dir) { - Plugins *ps = &srv->plugins; +void plugins_init(liServer *srv, const gchar *module_dir) { + liPlugins *ps = &srv->plugins; ps->modules = modules_new(srv, module_dir); @@ -98,8 +98,8 @@ void plugins_init(server *srv, const gchar *module_dir) { ps->load_plugins = g_ptr_array_new(); } -void plugins_clear(server *srv) { - Plugins *ps = &srv->plugins; +void plugins_clear(liServer *srv) { + liPlugins *ps = &srv->plugins; plugins_config_clean(srv); @@ -120,12 +120,12 @@ void plugins_clear(server *srv) { modules_free(ps->modules); } -void plugins_config_clean(server *srv) { - Plugins *ps = &srv->plugins; +void plugins_config_clean(liServer *srv) { + liPlugins *ps = &srv->plugins; guint i; for (i = ps->load_plugins->len; i-- > 0; ) { - plugin *p = g_ptr_array_index(ps->load_plugins, i); + liPlugin *p = g_ptr_array_index(ps->load_plugins, i); if (p->handle_clean_config) p->handle_clean_config(srv, p); } @@ -135,8 +135,8 @@ void plugins_config_clean(server *srv) { g_ptr_array_set_size(ps->load_plugins, 0); } -gboolean plugins_config_load(server *srv, const gchar *filename) { - Plugins *ps = &srv->plugins; +gboolean plugins_config_load(liServer *srv, const gchar *filename) { + liPlugins *ps = &srv->plugins; GError *error = NULL; guint i; @@ -155,7 +155,7 @@ gboolean plugins_config_load(server *srv, const gchar *filename) { /* check new config */ for (i = ps->load_plugins->len; i-- > 0; ) { - plugin *p = g_ptr_array_index(ps->load_plugins, i); + liPlugin *p = g_ptr_array_index(ps->load_plugins, i); if (p->handle_check_config) { if (!p->handle_check_config(srv, p)) { ERROR(srv, "%s", "config check failed"); @@ -169,7 +169,7 @@ gboolean plugins_config_load(server *srv, const gchar *filename) { /* activate new config */ for (i = ps->load_plugins->len; i-- > 0; ) { - plugin *p = g_ptr_array_index(ps->load_plugins, i); + liPlugin *p = g_ptr_array_index(ps->load_plugins, i); ERROR(srv, "activate: %s", p->name); if (p->handle_activate_config) { p->handle_activate_config(srv, p); @@ -201,8 +201,8 @@ gboolean plugins_config_load(server *srv, const gchar *filename) { return TRUE; } -void plugins_handle_item(server *srv, GString *itemname, value *hash) { - Plugins *ps = &srv->plugins; +void plugins_handle_item(liServer *srv, GString *itemname, liValue *hash) { + liPlugins *ps = &srv->plugins; server_item *si; #if 1 @@ -218,7 +218,7 @@ void plugins_handle_item(server *srv, GString *itemname, value *hash) { if (!si) { WARNING(srv, "Unknown item '%s' - perhaps you forgot to load the module? (ignored)", itemname->str); } else { - value **optlist = g_slice_alloc0(sizeof(value*) * si->option_count); + liValue **optlist = g_slice_alloc0(sizeof(liValue*) * si->option_count); GHashTableIter opti; gpointer k, v; guint i; @@ -240,14 +240,14 @@ void plugins_handle_item(server *srv, GString *itemname, value *hash) { /* validate options */ for (i = 0; i < si->option_count; i++) { - const plugin_item_option *pi = &si->p_item->options[i]; - if (0 != (pi->flags & PLUGIN_ITEM_OPTION_MANDATORY)) { + const liPluginItemOption *pi = &si->p_item->options[i]; + if (0 != (pi->flags & LI_PLUGIN_ITEM_OPTION_MANDATORY)) { if (!optlist[i]) { ERROR(srv, "Missing mandatory option '%s' in item '%s'", pi->name, itemname->str); valid = FALSE; } } - if (pi->type != VALUE_NONE && optlist[i] && optlist[i]->type != pi->type) { + if (pi->type != LI_VALUE_NONE && optlist[i] && optlist[i]->type != pi->type) { /* TODO: convert from string if possible */ ERROR(srv, "Invalid value type of option '%s' in item '%s', got '%s' but expected '%s'", pi->name, itemname->str, value_type_string(optlist[i]->type), value_type_string(pi->type)); @@ -260,14 +260,14 @@ void plugins_handle_item(server *srv, GString *itemname, value *hash) { si->p_item->handle_parse_item(srv, si->p, optlist); } - g_slice_free1(sizeof(value*) * si->option_count, optlist); + g_slice_free1(sizeof(liValue*) * si->option_count, optlist); } } -static gboolean plugins_activate_module(server *srv, server_module *sm) { - Plugins *ps = &srv->plugins; - plugin *p; - const plugin_item *pi; +static gboolean plugins_activate_module(liServer *srv, server_module *sm) { + liPlugins *ps = &srv->plugins; + liPlugin *p; + const liPluginItem *pi; guint i; for (i = 0; i < sm->plugins->len; i++) { @@ -312,8 +312,8 @@ item_collission: return FALSE; } -gboolean plugins_load_module(server *srv, const gchar *name) { - Plugins *ps = &srv->plugins; +gboolean plugins_load_module(liServer *srv, const gchar *name) { + liPlugins *ps = &srv->plugins; server_module *sm; const gchar* modname = name ? name : "core"; @@ -324,7 +324,7 @@ gboolean plugins_load_module(server *srv, const gchar *name) { server_module_acquire(sm); g_hash_table_insert(ps->load_module_refs, sm->name, sm); } else { /* not loaded yet */ - module *mod; + liModule *mod; sm = server_module_new(srv, modname); g_hash_table_insert(ps->load_module_refs, sm->name, sm); if (name) { @@ -351,10 +351,10 @@ gboolean plugins_load_module(server *srv, const gchar *name) { return TRUE; } -plugin *angel_plugin_register(server *srv, module *mod, const gchar *name, PluginInit init) { - Plugins *ps = &srv->plugins; +liPlugin *angel_plugin_register(liServer *srv, liModule *mod, const gchar *name, liPluginInitCB init) { + liPlugins *ps = &srv->plugins; server_module *sm; - plugin *p; + liPlugin *p; const gchar* modname = mod ? mod->name->str : "core"; sm = g_hash_table_lookup(ps->load_module_refs, modname); diff --git a/src/angel_plugin_core.c b/src/angel_plugin_core.c index 865d12a..a317f46 100644 --- a/src/angel_plugin_core.c +++ b/src/angel_plugin_core.c @@ -5,10 +5,10 @@ #include #include -static void core_instance_parse(server *srv, plugin *p, value **options) { +static void core_instance_parse(liServer *srv, liPlugin *p, liValue **options) { GPtrArray *cmd; gchar **cmdarr; - plugin_core_config_t *config = (plugin_core_config_t*) p->data; + liPluginCoreConfig *config = (liPluginCoreConfig*) p->data; uid_t uid = -1; gid_t gid = -1; GString *user = NULL; @@ -89,22 +89,22 @@ static void core_instance_parse(server *srv, plugin *p, value **options) { config->load_instconf = instance_conf_new(cmdarr, user, uid, gid); } -static const plugin_item_option core_instance_options[] = { - { "user", VALUE_STRING, 0 }, - { "group", VALUE_STRING, 0 }, - { "binary", VALUE_STRING, 0 }, - { "config", VALUE_STRING, 0 }, - { "luaconfig", VALUE_STRING, 0 }, - { "modules", VALUE_STRING, 0 }, +static const liPluginItemOption core_instance_options[] = { + { "user", LI_VALUE_STRING, 0 }, + { "group", LI_VALUE_STRING, 0 }, + { "binary", LI_VALUE_STRING, 0 }, + { "config", LI_VALUE_STRING, 0 }, + { "luaconfig", LI_VALUE_STRING, 0 }, + { "modules", LI_VALUE_STRING, 0 }, { NULL, 0, 0 } }; -static const plugin_item core_items[] = { +static const liPluginItem core_items[] = { { "instance", core_instance_parse, core_instance_options }, { NULL, NULL, NULL } }; -static int do_listen(server *srv, GString *str) { +static int do_listen(liServer *srv, GString *str) { guint32 ipv4; #ifdef HAVE_IPV6 guint8 ipv6[16]; @@ -191,7 +191,7 @@ static int do_listen(server *srv, GString *str) { } } -static void core_listen(server *srv, instance *i, plugin *p, gint32 id, GString *data) { +static void core_listen(liServer *srv, liInstance *i, liPlugin *p, gint32 id, GString *data) { GError *err = NULL; gint fd; GArray *fds; @@ -221,9 +221,9 @@ static void core_listen(server *srv, instance *i, plugin *p, gint32 id, GString } } -static void core_clean(server *srv, plugin *p); -static void core_free(server *srv, plugin *p) { - plugin_core_config_t *config = (plugin_core_config_t*) p->data; +static void core_clean(liServer *srv, liPlugin *p); +static void core_free(liServer *srv, liPlugin *p) { + liPluginCoreConfig *config = (liPluginCoreConfig*) p->data; core_clean(srv, p); @@ -233,14 +233,14 @@ static void core_free(server *srv, plugin *p) { } if (config->inst) { - instance_set_state(config->inst, INSTANCE_DOWN); + instance_set_state(config->inst, LI_INSTANCE_DOWN); instance_release(config->inst); config->inst = NULL; } } -static void core_clean(server *srv, plugin *p) { - plugin_core_config_t *config = (plugin_core_config_t*) p->data; +static void core_clean(liServer *srv, liPlugin *p) { + liPluginCoreConfig *config = (liPluginCoreConfig*) p->data; UNUSED(srv); if (config->load_instconf) { @@ -251,14 +251,14 @@ static void core_clean(server *srv, plugin *p) { config->load_failed = FALSE; } -static gboolean core_check(server *srv, plugin *p) { - plugin_core_config_t *config = (plugin_core_config_t*) p->data; +static gboolean core_check(liServer *srv, liPlugin *p) { + liPluginCoreConfig *config = (liPluginCoreConfig*) p->data; UNUSED(srv); return !config->load_failed; } -static void core_activate(server *srv, plugin *p) { - plugin_core_config_t *config = (plugin_core_config_t*) p->data; +static void core_activate(liServer *srv, liPlugin *p) { + liPluginCoreConfig *config = (liPluginCoreConfig*) p->data; if (config->instconf) { instance_conf_release(config->instconf); @@ -266,7 +266,7 @@ static void core_activate(server *srv, plugin *p) { } if (config->inst) { - instance_set_state(config->inst, INSTANCE_DOWN); + instance_set_state(config->inst, LI_INSTANCE_DOWN); instance_release(config->inst); config->inst = NULL; } @@ -276,14 +276,14 @@ static void core_activate(server *srv, plugin *p) { if (config->instconf) { config->inst = server_new_instance(srv, config->instconf); - instance_set_state(config->inst, INSTANCE_ACTIVE); + instance_set_state(config->inst, LI_INSTANCE_ACTIVE); ERROR(srv, "%s", "Starting instance"); } } -static gboolean core_init(server *srv, plugin *p) { +static gboolean core_init(liServer *srv, liPlugin *p) { UNUSED(srv); - p->data = g_slice_new0(plugin_core_config_t); + p->data = g_slice_new0(liPluginCoreConfig); p->items = core_items; p->handle_free = core_free; @@ -296,7 +296,7 @@ static gboolean core_init(server *srv, plugin *p) { return TRUE; } -gboolean plugin_core_init(server *srv) { +gboolean plugin_core_init(liServer *srv) { /* load core plugins */ return NULL != angel_plugin_register(srv, NULL, "core", core_init); } diff --git a/src/angel_server.c b/src/angel_server.c index da17765..bfef507 100644 --- a/src/angel_server.c +++ b/src/angel_server.c @@ -3,11 +3,11 @@ #include -static void instance_state_machine(instance *i); +static void instance_state_machine(liInstance *i); static void jobqueue_callback(struct ev_loop *loop, ev_async *w, int revents) { - server *srv = (server*) w->data; - instance *i; + liServer *srv = (liServer*) w->data; + liInstance *i; GQueue todo; UNUSED(loop); UNUSED(revents); @@ -22,8 +22,8 @@ static void jobqueue_callback(struct ev_loop *loop, ev_async *w, int revents) { } } -server* server_new(const gchar *module_dir) { - server *srv = g_slice_new0(server); +liServer* server_new(const gchar *module_dir) { + liServer *srv = g_slice_new0(liServer); srv->loop = ev_default_loop(0); @@ -38,23 +38,23 @@ server* server_new(const gchar *module_dir) { return srv; } -void server_free(server* srv) { +void server_free(liServer* srv) { plugins_clear(srv); log_clean(srv); - g_slice_free(server, srv); + g_slice_free(liServer, srv); } -static void instance_angel_call_cb(angel_connection *acon, +static void instance_angel_call_cb(liAngelConnection *acon, const gchar *mod, gsize mod_len, const gchar *action, gsize action_len, gint32 id, GString *data) { - instance *i = (instance*) acon->data; - server *srv = i->srv; - Plugins *ps = &srv->plugins; - plugin *p; - PluginHandleCall cb; + liInstance *i = (liInstance*) acon->data; + liServer *srv = i->srv; + liPlugins *ps = &srv->plugins; + liPlugin *p; + liPluginHandleCallCB cb; p = g_hash_table_lookup(ps->ht_plugins, mod); if (!p) { @@ -68,7 +68,7 @@ static void instance_angel_call_cb(angel_connection *acon, return; } - cb = (PluginHandleCall)(intptr_t) g_hash_table_lookup(p->angel_callbacks, action); + cb = (liPluginHandleCallCB)(intptr_t) g_hash_table_lookup(p->angel_callbacks, action); if (!cb) { GString *errstr = g_string_sized_new(0); GError *err = NULL; @@ -83,9 +83,9 @@ static void instance_angel_call_cb(angel_connection *acon, cb(srv, i, p, id, data); } -static void instance_angel_close_cb(angel_connection *acon, GError *err) { - instance *i = (instance*) acon->data; - server *srv = i->srv; +static void instance_angel_close_cb(liAngelConnection *acon, GError *err) { + liInstance *i = (liInstance*) acon->data; + liServer *srv = i->srv; ERROR(srv, "angel connection closed: %s", err ? err->message : g_strerror(errno)); if (err) g_error_free(err); @@ -95,14 +95,14 @@ static void instance_angel_close_cb(angel_connection *acon, GError *err) { } static void instance_child_cb(struct ev_loop *loop, ev_child *w, int revents) { - instance *i = (instance*) w->data; + liInstance *i = (liInstance*) w->data; - if (i->s_cur == INSTANCE_LOADING) { + if (i->s_cur == LI_INSTANCE_LOADING) { ERROR(i->srv, "spawning child %i failed, not restarting", i->pid); - i->s_dest = i->s_cur = INSTANCE_DOWN; /* TODO: retry spawn later? */ + i->s_dest = i->s_cur = LI_INSTANCE_DOWN; /* TODO: retry spawn later? */ } else { ERROR(i->srv, "child %i died", i->pid); - i->s_cur = INSTANCE_DOWN; + i->s_cur = LI_INSTANCE_DOWN; } i->pid = -1; angel_connection_free(i->acon); @@ -112,7 +112,7 @@ static void instance_child_cb(struct ev_loop *loop, ev_child *w, int revents) { instance_release(i); } -static void instance_spawn(instance *i) { +static void instance_spawn(liInstance *i) { int confd[2]; if (-1 == socketpair(AF_UNIX, SOCK_STREAM, 0, confd)) { ERROR(i->srv, "socketpair error, cannot spawn instance: %s", g_strerror(errno)); @@ -149,47 +149,47 @@ static void instance_spawn(instance *i) { close(confd[1]); ev_child_set(&i->child_watcher, i->pid, 0); ev_child_start(i->srv->loop, &i->child_watcher); - i->s_cur = INSTANCE_LOADING; + i->s_cur = LI_INSTANCE_LOADING; instance_acquire(i); ERROR(i->srv, "Instance (%i) spawned: %s", i->pid, i->ic->cmd[0]); break; } } -instance* server_new_instance(server *srv, instance_conf *ic) { - instance *i; +liInstance* server_new_instance(liServer *srv, liInstanceConf *ic) { + liInstance *i; - i = g_slice_new0(instance); + i = g_slice_new0(liInstance); i->refcount = 1; i->srv = srv; instance_conf_acquire(ic); i->ic = ic; i->pid = -1; - i->s_cur = i->s_dest = INSTANCE_DOWN; + i->s_cur = i->s_dest = LI_INSTANCE_DOWN; ev_child_init(&i->child_watcher, instance_child_cb, -1, 0); i->child_watcher.data = i; return i; } -void instance_replace(instance *oldi, instance *newi) { +void instance_replace(liInstance *oldi, liInstance *newi) { } -void instance_set_state(instance *i, instance_state_t s) { +void instance_set_state(liInstance *i, liInstanceState s) { if (i->s_dest == s) return; switch (s) { - case INSTANCE_DOWN: + case LI_INSTANCE_DOWN: break; - case INSTANCE_LOADING: - case INSTANCE_WARMUP: + case LI_INSTANCE_LOADING: + case LI_INSTANCE_WARMUP: return; /* These cannot be set */ - case INSTANCE_ACTIVE: - case INSTANCE_SUSPEND: + case LI_INSTANCE_ACTIVE: + case LI_INSTANCE_SUSPEND: break; } i->s_dest = s; - if (s == INSTANCE_DOWN) { - if (i->s_cur != INSTANCE_DOWN) { + if (s == LI_INSTANCE_DOWN) { + if (i->s_cur != LI_INSTANCE_DOWN) { kill(i->pid, SIGTERM); } } else { @@ -201,14 +201,14 @@ void instance_set_state(instance *i, instance_state_t s) { GString *buf = g_string_sized_new(0); switch (s) { - case INSTANCE_DOWN: - case INSTANCE_LOADING: - case INSTANCE_WARMUP: + case LI_INSTANCE_DOWN: + case LI_INSTANCE_LOADING: + case LI_INSTANCE_WARMUP: break; - case INSTANCE_ACTIVE: + case LI_INSTANCE_ACTIVE: angel_send_simple_call(i->acon, CONST_STR_LEN("core"), CONST_STR_LEN("run"), buf, &error); break; - case INSTANCE_SUSPEND: + case LI_INSTANCE_SUSPEND: angel_send_simple_call(i->acon, CONST_STR_LEN("core"), CONST_STR_LEN("suspend"), buf, &error); break; } @@ -216,33 +216,33 @@ void instance_set_state(instance *i, instance_state_t s) { } } -static void instance_state_machine(instance *i) { - instance_state_t olds = i->s_dest; +static void instance_state_machine(liInstance *i) { + liInstanceState olds = i->s_dest; while (i->s_cur != i->s_dest && i->s_cur != olds) { olds = i->s_cur; switch (i->s_dest) { - case INSTANCE_DOWN: + case LI_INSTANCE_DOWN: if (i->pid == (pid_t) -1) { - i->s_cur = INSTANCE_DOWN; + i->s_cur = LI_INSTANCE_DOWN; break; } kill(i->pid, SIGINT); return; - case INSTANCE_LOADING: + case LI_INSTANCE_LOADING: break; - case INSTANCE_WARMUP: + case LI_INSTANCE_WARMUP: if (i->pid == (pid_t) -1) { instance_spawn(i); return; } break; - case INSTANCE_ACTIVE: + case LI_INSTANCE_ACTIVE: if (i->pid == (pid_t) -1) { instance_spawn(i); return; } break; - case INSTANCE_SUSPEND: + case LI_INSTANCE_SUSPEND: if (i->pid == (pid_t) -1) { instance_spawn(i); return; @@ -252,9 +252,9 @@ static void instance_state_machine(instance *i) { } } -void instance_release(instance *i) { - server *srv; - instance *t; +void instance_release(liInstance *i) { + liServer *srv; + liInstance *t; if (!i) return; assert(g_atomic_int_get(&i->refcount) > 0); if (!g_atomic_int_dec_and_test(&i->refcount)) return; @@ -263,7 +263,7 @@ void instance_release(instance *i) { ev_child_stop(srv->loop, &i->child_watcher); kill(i->pid, SIGTERM); i->pid = -1; - i->s_cur = INSTANCE_DOWN; + i->s_cur = LI_INSTANCE_DOWN; angel_connection_free(i->acon); i->acon = NULL; } @@ -277,16 +277,16 @@ void instance_release(instance *i) { t = i->replace_by; i->replace_by = NULL; instance_release(t); - g_slice_free(instance, i); + g_slice_free(liInstance, i); } -void instance_acquire(instance *i) { +void instance_acquire(liInstance *i) { assert(g_atomic_int_get(&i->refcount) > 0); g_atomic_int_inc(&i->refcount); } -instance_conf* instance_conf_new(gchar **cmd, GString *username, uid_t uid, gid_t gid) { - instance_conf *ic = g_slice_new0(instance_conf); +liInstanceConf* instance_conf_new(gchar **cmd, GString *username, uid_t uid, gid_t gid) { + liInstanceConf *ic = g_slice_new0(liInstanceConf); ic->refcount = 1; ic->cmd = cmd; if (username) { @@ -297,21 +297,21 @@ instance_conf* instance_conf_new(gchar **cmd, GString *username, uid_t uid, gid_ return ic; } -void instance_conf_release(instance_conf *ic) { +void instance_conf_release(liInstanceConf *ic) { if (!ic) return; assert(g_atomic_int_get(&ic->refcount) > 0); if (!g_atomic_int_dec_and_test(&ic->refcount)) return; g_strfreev(ic->cmd); - g_slice_free(instance_conf, ic); + g_slice_free(liInstanceConf, ic); } -void instance_conf_acquire(instance_conf *ic) { +void instance_conf_acquire(liInstanceConf *ic) { assert(g_atomic_int_get(&ic->refcount) > 0); g_atomic_int_inc(&ic->refcount); } -void instance_job_append(instance *i) { - server *srv = i->srv; +void instance_job_append(liInstance *i) { + liServer *srv = i->srv; if (!i->in_jobqueue) { instance_acquire(i); i->in_jobqueue = TRUE; diff --git a/src/angel_value.c b/src/angel_value.c index acc8194..a19e869 100644 --- a/src/angel_value.c +++ b/src/angel_value.c @@ -1,43 +1,43 @@ #include -value* value_new_none() { - value *v = g_slice_new0(value); - v->type = VALUE_NONE; +liValue* value_new_none() { + liValue *v = g_slice_new0(liValue); + v->type = LI_VALUE_NONE; return v; } -value* value_new_bool(gboolean val) { - value *v = g_slice_new0(value); +liValue* value_new_bool(gboolean val) { + liValue *v = g_slice_new0(liValue); v->data.boolean = val; - v->type = VALUE_BOOLEAN; + v->type = LI_VALUE_BOOLEAN; return v; } -value* value_new_number(gint64 val) { - value *v = g_slice_new0(value); +liValue* value_new_number(gint64 val) { + liValue *v = g_slice_new0(liValue); v->data.number = val; - v->type = VALUE_NUMBER; + v->type = LI_VALUE_NUMBER; return v; } -value* value_new_string(GString *val) { - value *v = g_slice_new0(value); +liValue* value_new_string(GString *val) { + liValue *v = g_slice_new0(liValue); v->data.string = val; - v->type = VALUE_STRING; + v->type = LI_VALUE_STRING; return v; } -value* value_new_range(value_range val) { - value *v = g_slice_new0(value); +liValue* value_new_range(liValueRange val) { + liValue *v = g_slice_new0(liValue); v->data.range = val; - v->type = VALUE_RANGE; + v->type = LI_VALUE_RANGE; return v; } -value* value_new_list() { - value *v = g_slice_new0(value); +liValue* value_new_list() { + liValue *v = g_slice_new0(liValue); v->data.list = g_ptr_array_new(); - v->type = VALUE_LIST; + v->type = LI_VALUE_LIST; return v; } @@ -46,29 +46,29 @@ static void _value_hash_free_key(gpointer data) { } static void _value_hash_free_value(gpointer data) { - value_free((value*) data); + value_free((liValue*) data); } -value* value_new_hash() { - value *v = g_slice_new0(value); +liValue* value_new_hash() { + liValue *v = g_slice_new0(liValue); v->data.hash = g_hash_table_new_full( (GHashFunc) g_string_hash, (GEqualFunc) g_string_equal, _value_hash_free_key, _value_hash_free_value); - v->type = VALUE_HASH; + v->type = LI_VALUE_HASH; return v; } -value* value_copy(value* val) { - value *n; +liValue* value_copy(liValue* val) { + liValue *n; switch (val->type) { - case VALUE_NONE: n = value_new_bool(FALSE); n->type = VALUE_NONE; return n; /* hack */ - case VALUE_BOOLEAN: return value_new_bool(val->data.boolean); - case VALUE_NUMBER: return value_new_number(val->data.number); - case VALUE_STRING: return value_new_string(g_string_new_len(GSTR_LEN(val->data.string))); - case VALUE_RANGE: return value_new_range(val->data.range); + case LI_VALUE_NONE: n = value_new_bool(FALSE); n->type = LI_VALUE_NONE; return n; /* hack */ + case LI_VALUE_BOOLEAN: return value_new_bool(val->data.boolean); + case LI_VALUE_NUMBER: return value_new_number(val->data.number); + case LI_VALUE_STRING: return value_new_string(g_string_new_len(GSTR_LEN(val->data.string))); + case LI_VALUE_RANGE: return value_new_range(val->data.range); /* list: we have to copy every value in the list! */ - case VALUE_LIST: + case LI_VALUE_LIST: n = value_new_list(); g_ptr_array_set_size(n->data.list, val->data.list->len); for (guint i = 0; i < val->data.list->len; i++) { @@ -76,14 +76,14 @@ value* value_copy(value* val) { } return n; /* hash: iterate over hashtable, clone each value */ - case VALUE_HASH: + case LI_VALUE_HASH: n = value_new_hash(); { GHashTableIter iter; gpointer k, v; g_hash_table_iter_init(&iter, val->data.hash); while (g_hash_table_iter_next(&iter, &k, &v)) - g_hash_table_insert(n->data.hash, g_string_new_len(GSTR_LEN((GString*)k)), value_copy((value*)v)); + g_hash_table_insert(n->data.hash, g_string_new_len(GSTR_LEN((GString*)k)), value_copy((liValue*)v)); } return n; } @@ -98,74 +98,74 @@ static void value_list_free(GPtrArray *vallist) { g_ptr_array_free(vallist, TRUE); } -void value_free(value* val) { +void value_free(liValue* val) { if (!val) return; switch (val->type) { - case VALUE_NONE: - case VALUE_BOOLEAN: - case VALUE_NUMBER: + case LI_VALUE_NONE: + case LI_VALUE_BOOLEAN: + case LI_VALUE_NUMBER: /* Nothing to free */ break; - case VALUE_STRING: + case LI_VALUE_STRING: g_string_free(val->data.string, TRUE); break; - case VALUE_RANGE: + case LI_VALUE_RANGE: break; - case VALUE_LIST: + case LI_VALUE_LIST: value_list_free(val->data.list); break; - case VALUE_HASH: + case LI_VALUE_HASH: g_hash_table_destroy(val->data.hash); break; } - val->type = VALUE_NONE; - g_slice_free(value, val); + val->type = LI_VALUE_NONE; + g_slice_free(liValue, val); } -const char* value_type_string(value_type type) { +const char* value_type_string(liValueType type) { switch(type) { - case VALUE_NONE: + case LI_VALUE_NONE: return "none"; - case VALUE_BOOLEAN: + case LI_VALUE_BOOLEAN: return "boolean"; - case VALUE_NUMBER: + case LI_VALUE_NUMBER: return "number"; - case VALUE_STRING: + case LI_VALUE_STRING: return "string"; - case VALUE_RANGE: + case LI_VALUE_RANGE: return "range"; - case VALUE_LIST: + case LI_VALUE_LIST: return "list"; - case VALUE_HASH: + case LI_VALUE_HASH: return "hash"; } return ""; } -GString *value_to_string(value *val) { +GString *value_to_string(liValue *val) { GString *str = NULL; switch (val->type) { - case VALUE_NONE: + case LI_VALUE_NONE: return NULL; - case VALUE_BOOLEAN: + case LI_VALUE_BOOLEAN: str = g_string_new(val->data.boolean ? "true" : "false"); break; - case VALUE_NUMBER: + case LI_VALUE_NUMBER: str = g_string_sized_new(0); g_string_printf(str, "%" G_GINT64_FORMAT, val->data.number); break; - case VALUE_STRING: + case LI_VALUE_STRING: str = g_string_new_len(CONST_STR_LEN("\"")); g_string_append_len(str, GSTR_LEN(val->data.string)); g_string_append_c(str, '"'); break; - case VALUE_RANGE: + case LI_VALUE_RANGE: str = g_string_sized_new(0); g_string_printf(str, "%" G_GINT64_FORMAT "-%" G_GINT64_FORMAT, val->data.range.from, val->data.range.to); break; - case VALUE_LIST: + case LI_VALUE_LIST: str = g_string_new_len(CONST_STR_LEN("(")); if (val->data.list->len) { GString *tmp = value_to_string(g_ptr_array_index(val->data.list, 0)); @@ -180,7 +180,7 @@ GString *value_to_string(value *val) { } g_string_append_c(str, ')'); break; - case VALUE_HASH: + case LI_VALUE_HASH: { GHashTableIter iter; gpointer k, v; @@ -193,7 +193,7 @@ GString *value_to_string(value *val) { while (g_hash_table_iter_next(&iter, &k, &v)) { if (i) g_string_append_len(str, CONST_STR_LEN(", ")); - tmp = value_to_string((value*)v); + tmp = value_to_string((liValue*)v); g_string_append_len(str, GSTR_LEN((GString*)k)); g_string_append_len(str, CONST_STR_LEN(": ")); g_string_append_len(str, GSTR_LEN(tmp)); diff --git a/src/chunk.c b/src/chunk.c index 39bcb0c..ecf2588 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -8,8 +8,8 @@ * chunkfile * ******************/ -static chunkfile *chunkfile_new(GString *name, int fd, gboolean is_temp) { - chunkfile *cf = g_slice_new(chunkfile); +static liChunkFile *chunkfile_new(GString *name, int fd, gboolean is_temp) { + liChunkFile *cf = g_slice_new(liChunkFile); cf->refcount = 1; if (name) { cf->name = g_string_new_len(GSTR_LEN(name)); @@ -21,12 +21,12 @@ static chunkfile *chunkfile_new(GString *name, int fd, gboolean is_temp) { return cf; } -static void chunkfile_acquire(chunkfile *cf) { +static void chunkfile_acquire(liChunkFile *cf) { assert(g_atomic_int_get(&cf->refcount) > 0); g_atomic_int_inc(&cf->refcount); } -static void chunkfile_release(chunkfile *cf) { +static void chunkfile_release(liChunkFile *cf) { if (!cf) return; assert(g_atomic_int_get(&cf->refcount) > 0); if (g_atomic_int_dec_and_test(&cf->refcount)) { @@ -36,26 +36,26 @@ static void chunkfile_release(chunkfile *cf) { cf->is_temp = FALSE; if (cf->name) g_string_free(cf->name, TRUE); cf->name = NULL; - g_slice_free(chunkfile, cf); + g_slice_free(liChunkFile, cf); } } /* open the file cf->name if it is not already opened for reading * may return HANDLER_GO_ON, HANDLER_ERROR */ -handler_t chunkfile_open(vrequest *vr, chunkfile *cf) { - if (!cf) return HANDLER_ERROR; - if (-1 != cf->fd) return HANDLER_GO_ON; +liHandlerResult chunkfile_open(liVRequest *vr, liChunkFile *cf) { + if (!cf) return LI_HANDLER_ERROR; + if (-1 != cf->fd) return LI_HANDLER_GO_ON; if (!cf->name) { VR_ERROR(vr, "%s", "Missing filename for FILE_CHUNK"); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } if (-1 == (cf->fd = open(cf->name->str, O_RDONLY))) { if (EMFILE == errno) { server_out_of_fds(vr->wrk->srv); } VR_ERROR(vr, "Couldn't open file '%s': %s", GSTR_SAFE_STR(cf->name), g_strerror(errno)); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } #ifdef FD_CLOEXEC fcntl(cf->fd, F_SETFD, FD_CLOEXEC); @@ -68,7 +68,7 @@ handler_t chunkfile_open(vrequest *vr, chunkfile *cf) { } } #endif - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } /****************** @@ -83,20 +83,20 @@ handler_t chunkfile_open(vrequest *vr, chunkfile *cf) { * but needs to do io in case of FILE_CHUNK; the data is _not_ marked as "done" * may return HANDLER_GO_ON, HANDLER_ERROR */ -handler_t chunkiter_read(vrequest *vr, chunkiter iter, off_t start, off_t length, char **data_start, off_t *data_len) { - chunk *c = chunkiter_chunk(iter); +liHandlerResult chunkiter_read(liVRequest *vr, liChunkIter iter, off_t start, off_t length, char **data_start, off_t *data_len) { + liChunk *c = chunkiter_chunk(iter); off_t we_have, our_start; - handler_t res = HANDLER_GO_ON; + liHandlerResult res = LI_HANDLER_GO_ON; - if (!c) return HANDLER_ERROR; - if (!data_start || !data_len) return HANDLER_ERROR; + if (!c) return LI_HANDLER_ERROR; + if (!data_start || !data_len) return LI_HANDLER_ERROR; we_have = chunk_length(c) - start; if (length > we_have) length = we_have; - if (length <= 0) return HANDLER_ERROR; + if (length <= 0) return LI_HANDLER_ERROR; switch (c->type) { - case UNUSED_CHUNK: return HANDLER_ERROR; + case UNUSED_CHUNK: return LI_HANDLER_ERROR; case STRING_CHUNK: *data_start = c->str->str + c->offset + start; *data_len = length; @@ -106,7 +106,7 @@ handler_t chunkiter_read(vrequest *vr, chunkiter iter, off_t start, off_t length *data_len = length; break; case FILE_CHUNK: - if (HANDLER_GO_ON != (res = chunkfile_open(vr, c->file.file))) return res; + if (LI_HANDLER_GO_ON != (res = chunkfile_open(vr, c->file.file))) return res; if (length > MAX_MMAP_CHUNK) length = MAX_MMAP_CHUNK; @@ -124,7 +124,7 @@ handler_t chunkiter_read(vrequest *vr, chunkiter iter, off_t start, off_t length g_strerror(errno)); g_byte_array_free(c->mem, TRUE); c->mem = NULL; - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } read_chunk: if (-1 == (we_have = read(c->file.file->fd, c->mem->data, length))) { @@ -134,7 +134,7 @@ read_chunk: g_strerror(errno)); g_byte_array_free(c->mem, TRUE); c->mem = NULL; - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } else if (we_have != length) { /* may return less than requested bytes due to signals */ /* CON_TRACE(srv, "read return unexpected number of bytes"); */ @@ -143,7 +143,7 @@ read_chunk: GSTR_SAFE_STR(c->file.file->name), c->file.file->fd); g_byte_array_free(c->mem, TRUE); c->mem = NULL; - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } length = we_have; g_byte_array_set_size(c->mem, length); @@ -152,27 +152,27 @@ read_chunk: *data_len = length; break; } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } /* same as chunkiter_read, but tries mmap() first and falls back to read(); * as accessing mmap()-ed areas may result in SIGBUS, you have to handle that signal somehow. */ -handler_t chunkiter_read_mmap(struct vrequest *vr, chunkiter iter, off_t start, off_t length, char **data_start, off_t *data_len) { - chunk *c = chunkiter_chunk(iter); +liHandlerResult chunkiter_read_mmap(liVRequest *vr, liChunkIter iter, off_t start, off_t length, char **data_start, off_t *data_len) { + liChunk *c = chunkiter_chunk(iter); off_t we_want, we_have, our_start, our_offset; - handler_t res = HANDLER_GO_ON; + liHandlerResult res = LI_HANDLER_GO_ON; int mmap_errno = 0; - if (!c) return HANDLER_ERROR; - if (!data_start || !data_len) return HANDLER_ERROR; + if (!c) return LI_HANDLER_ERROR; + if (!data_start || !data_len) return LI_HANDLER_ERROR; we_have = chunk_length(c) - start; if (length > we_have) length = we_have; - if (length <= 0) return HANDLER_ERROR; + if (length <= 0) return LI_HANDLER_ERROR; switch (c->type) { - case UNUSED_CHUNK: return HANDLER_ERROR; + case UNUSED_CHUNK: return LI_HANDLER_ERROR; case STRING_CHUNK: *data_start = c->str->str + c->offset + start; *data_len = length; @@ -182,7 +182,7 @@ handler_t chunkiter_read_mmap(struct vrequest *vr, chunkiter iter, off_t start, *data_len = length; break; case FILE_CHUNK: - if (HANDLER_GO_ON != (res = chunkfile_open(vr, c->file.file))) return res; + if (LI_HANDLER_GO_ON != (res = chunkfile_open(vr, c->file.file))) return res; if (length > MAX_MMAP_CHUNK) length = MAX_MMAP_CHUNK; @@ -229,7 +229,7 @@ handler_t chunkiter_read_mmap(struct vrequest *vr, chunkiter iter, off_t start, } g_byte_array_free(c->mem, TRUE); c->mem = NULL; - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } read_chunk: if (-1 == (we_have = read(c->file.file->fd, c->mem->data, we_want))) { @@ -246,7 +246,7 @@ read_chunk: } g_byte_array_free(c->mem, TRUE); c->mem = NULL; - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } else if (we_have != we_want) { /* may return less than requested bytes due to signals */ /* CON_TRACE(srv, "read return unexpected number of bytes"); */ @@ -271,15 +271,15 @@ read_chunk: *data_len = length; break; } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } /****************** * chunk * ******************/ -static chunk* chunk_new() { - chunk *c = g_slice_new0(chunk); +static liChunk* chunk_new() { + liChunk *c = g_slice_new0(liChunk); c->file.mmap.data = MAP_FAILED; return c; } @@ -302,7 +302,7 @@ static void chunk_reset(chunk *c) { } */ -static void chunk_free(chunk *c) { +static void chunk_free(liChunk *c) { if (!c) return; c->type = UNUSED_CHUNK; if (c->str) { @@ -321,21 +321,21 @@ static void chunk_free(chunk *c) { munmap(c->file.mmap.data, c->file.mmap.length); c->file.mmap.data = MAP_FAILED; } - g_slice_free(chunk, c); + g_slice_free(liChunk, c); } /****************** * cqlimit * ******************/ -cqlimit* cqlimit_new(vrequest *vr) { - cqlimit *cql = g_slice_new0(cqlimit); +liCQLimit* cqlimit_new(liVRequest *vr) { + liCQLimit *cql = g_slice_new0(liCQLimit); cql->refcount = 1; cql->vr = vr; cql->limit = -1; return cql; } -void cqlimit_reset(cqlimit *cql) { +void cqlimit_reset(liCQLimit *cql) { assert(cql->current == 0); assert(cql->io_watcher == NULL); assert(cql->notify == NULL); @@ -345,20 +345,20 @@ void cqlimit_reset(cqlimit *cql) { cql->notify = NULL; } -void cqlimit_acquire(cqlimit *cql) { +void cqlimit_acquire(liCQLimit *cql) { assert(g_atomic_int_get(&cql->refcount) > 0); g_atomic_int_inc(&cql->refcount); } -void cqlimit_release(cqlimit *cql) { +void cqlimit_release(liCQLimit *cql) { if (!cql) return; assert(g_atomic_int_get(&cql->refcount) > 0); if (g_atomic_int_dec_and_test(&cql->refcount)) { - g_slice_free(cqlimit, cql); + g_slice_free(liCQLimit, cql); } } -static void cqlimit_lock(cqlimit *cql) { +static void cqlimit_lock(liCQLimit *cql) { cql->locked = TRUE; if (cql->io_watcher && cql->io_watcher->fd != -1) { ev_io_rem_events(cql->vr->wrk->loop, cql->io_watcher, EV_READ); @@ -368,7 +368,7 @@ static void cqlimit_lock(cqlimit *cql) { } } -static void cqlimit_unlock(cqlimit *cql) { +static void cqlimit_unlock(liCQLimit *cql) { cql->locked = FALSE; if (cql->io_watcher && cql->io_watcher->fd != -1) { ev_io_add_events(cql->vr->wrk->loop, cql->io_watcher, EV_READ); @@ -378,8 +378,8 @@ static void cqlimit_unlock(cqlimit *cql) { } } -static void cqlimit_update(chunkqueue *cq, goffset d) { - cqlimit *cql; +static void cqlimit_update(liChunkQueue *cq, goffset d) { + liCQLimit *cql; if (!cq) return; cq->mem_usage += d; @@ -402,7 +402,7 @@ static void cqlimit_update(chunkqueue *cq, goffset d) { } } -void cqlimit_set_limit(cqlimit *cql, goffset limit) { +void cqlimit_set_limit(liCQLimit *cql, goffset limit) { if (!cql) return; cql->limit = limit; @@ -422,21 +422,21 @@ void cqlimit_set_limit(cqlimit *cql, goffset limit) { * chunkqueue * ******************/ -chunkqueue* chunkqueue_new() { - chunkqueue *cq = g_slice_new0(chunkqueue); +liChunkQueue* chunkqueue_new() { + liChunkQueue *cq = g_slice_new0(liChunkQueue); cq->queue = g_queue_new(); return cq; } static void __chunk_free(gpointer _c, gpointer userdata) { - chunk *c = (chunk *)_c; - chunkqueue *cq = (chunkqueue*) userdata; + liChunk *c = (liChunk *)_c; + liChunkQueue *cq = (liChunkQueue*) userdata; if (c->type == STRING_CHUNK) cqlimit_update(cq, - (goffset)c->str->len); else if (c->type == MEM_CHUNK) cqlimit_update(cq, - (goffset)c->mem->len); chunk_free(c); } -void chunkqueue_reset(chunkqueue *cq) { +void chunkqueue_reset(liChunkQueue *cq) { if (!cq) return; cq->is_closed = FALSE; cq->bytes_in = cq->bytes_out = cq->length = 0; @@ -446,7 +446,7 @@ void chunkqueue_reset(chunkqueue *cq) { g_queue_clear(cq->queue); } -void chunkqueue_free(chunkqueue *cq) { +void chunkqueue_free(liChunkQueue *cq) { if (!cq) return; g_queue_foreach(cq->queue, __chunk_free, cq); g_queue_free(cq->queue); @@ -455,15 +455,15 @@ void chunkqueue_free(chunkqueue *cq) { cq->limit = NULL; assert(cq->mem_usage == 0); cq->mem_usage = 0; - g_slice_free(chunkqueue, cq); + g_slice_free(liChunkQueue, cq); } -void chunkqueue_use_limit(chunkqueue *cq, vrequest *vr) { +void chunkqueue_use_limit(liChunkQueue *cq, liVRequest *vr) { if (cq->limit) return; cq->limit = cqlimit_new(vr); } -void chunkqueue_set_limit(chunkqueue *cq, cqlimit* cql) { +void chunkqueue_set_limit(liChunkQueue *cq, liCQLimit* cql) { gboolean upd_limit = (cql != cq->limit); goffset memusage = cq->mem_usage; if (cql) cqlimit_acquire(cql); @@ -474,8 +474,8 @@ void chunkqueue_set_limit(chunkqueue *cq, cqlimit* cql) { } /* return -1 for unlimited, 0 for full and n > 0 for n bytes free */ -goffset chunkqueue_limit_available(chunkqueue *cq) { - cqlimit *cql = cq->limit; +goffset chunkqueue_limit_available(liChunkQueue *cq) { + liCQLimit *cql = cq->limit; goffset avail; if (!cql) return -1; if (cql->limit <= 0) return -1; @@ -488,8 +488,8 @@ goffset chunkqueue_limit_available(chunkqueue *cq) { * you may modify the data (not the length) if you are sure it isn't sent before. * if the length is NULL, str is destroyed immediately */ -void chunkqueue_append_string(chunkqueue *cq, GString *str) { - chunk *c; +void chunkqueue_append_string(liChunkQueue *cq, GString *str) { + liChunk *c; if (!str->len) { g_string_free(str, TRUE); return; @@ -507,8 +507,8 @@ void chunkqueue_append_string(chunkqueue *cq, GString *str) { * you may modify the data (not the length) if you are sure it isn't sent before. * if the length is NULL, mem is destroyed immediately */ -void chunkqueue_append_bytearr(chunkqueue *cq, GByteArray *mem) { - chunk *c; +void chunkqueue_append_bytearr(liChunkQueue *cq, GByteArray *mem) { + liChunk *c; if (!mem->len) { g_byte_array_free(mem, TRUE); return; @@ -523,8 +523,8 @@ void chunkqueue_append_bytearr(chunkqueue *cq, GByteArray *mem) { } /* memory gets copied */ -void chunkqueue_append_mem(chunkqueue *cq, const void *mem, gssize len) { - chunk *c; +void chunkqueue_append_mem(liChunkQueue *cq, const void *mem, gssize len) { + liChunk *c; if (!len) return; c = chunk_new(); c->type = MEM_CHUNK; @@ -536,8 +536,8 @@ void chunkqueue_append_mem(chunkqueue *cq, const void *mem, gssize len) { cqlimit_update(cq, c->mem->len); } -static void __chunkqueue_append_file(chunkqueue *cq, GString *filename, off_t start, off_t length, int fd, gboolean is_temp) { - chunk *c = chunk_new(); +static void __chunkqueue_append_file(liChunkQueue *cq, GString *filename, off_t start, off_t length, int fd, gboolean is_temp) { + liChunk *c = chunk_new(); c->type = FILE_CHUNK; c->file.file = chunkfile_new(filename, fd, is_temp); c->file.start = start; @@ -548,33 +548,33 @@ static void __chunkqueue_append_file(chunkqueue *cq, GString *filename, off_t st cq->bytes_in += length; } /* pass ownership of filename, do not free it */ -void chunkqueue_append_file(chunkqueue *cq, GString *filename, off_t start, off_t length) { +void chunkqueue_append_file(liChunkQueue *cq, GString *filename, off_t start, off_t length) { if (length) __chunkqueue_append_file(cq, filename, start, length, -1, FALSE); } /* if you already opened the file, you can pass the fd here - do not close it */ -void chunkqueue_append_file_fd(chunkqueue *cq, GString *filename, off_t start, off_t length, int fd) { +void chunkqueue_append_file_fd(liChunkQueue *cq, GString *filename, off_t start, off_t length, int fd) { if (length) __chunkqueue_append_file(cq, filename, start, length, fd, FALSE); } /* temp files get deleted after usage */ /* pass ownership of filename, do not free it */ -void chunkqueue_append_tempfile(chunkqueue *cq, GString *filename, off_t start, off_t length) { +void chunkqueue_append_tempfile(liChunkQueue *cq, GString *filename, off_t start, off_t length) { if (length) __chunkqueue_append_file(cq, filename, start, length, -1, TRUE); } /* if you already opened the file, you can pass the fd here - do not close it */ -void chunkqueue_append_tempfile_fd(chunkqueue *cq, GString *filename, off_t start, off_t length, int fd) { +void chunkqueue_append_tempfile_fd(liChunkQueue *cq, GString *filename, off_t start, off_t length, int fd) { if (length) __chunkqueue_append_file(cq, filename, start, length, fd, TRUE); } /* steal up to length bytes from in and put them into out, return number of bytes stolen */ -goffset chunkqueue_steal_len(chunkqueue *out, chunkqueue *in, goffset length) { - chunk *c, *cnew; +goffset chunkqueue_steal_len(liChunkQueue *out, liChunkQueue *in, goffset length) { + liChunk *c, *cnew; GList* l; goffset bytes = 0, meminbytes = 0, memoutbytes = 0; goffset we_have; @@ -647,7 +647,7 @@ goffset chunkqueue_steal_len(chunkqueue *out, chunkqueue *in, goffset length) { } /* steal all chunks from in and put them into out, return number of bytes stolen */ -goffset chunkqueue_steal_all(chunkqueue *out, chunkqueue *in) { +goffset chunkqueue_steal_all(liChunkQueue *out, liChunkQueue *in) { goffset len; /* if in->queue is empty, do nothing */ @@ -685,14 +685,14 @@ goffset chunkqueue_steal_all(chunkqueue *out, chunkqueue *in) { } /* steal the first chunk from in and append it to out, return number of bytes stolen */ -goffset chunkqueue_steal_chunk(chunkqueue *out, chunkqueue *in) { - chunk *c; +goffset chunkqueue_steal_chunk(liChunkQueue *out, liChunkQueue *in) { + liChunk *c; goffset length; GList *l = g_queue_pop_head_link(in->queue); if (!l) return 0; g_queue_push_tail_link(out->queue, l); - c = (chunk*) l->data; + c = (liChunk*) l->data; length = chunk_length(c); in->bytes_out += length; in->length -= length; @@ -711,8 +711,8 @@ goffset chunkqueue_steal_chunk(chunkqueue *out, chunkqueue *in) { } /* skip up to length bytes in a chunkqueue, return number of bytes skipped */ -goffset chunkqueue_skip(chunkqueue *cq, goffset length) { - chunk *c; +goffset chunkqueue_skip(liChunkQueue *cq, goffset length) { + liChunk *c; goffset bytes = 0; goffset we_have; @@ -737,7 +737,7 @@ goffset chunkqueue_skip(chunkqueue *cq, goffset length) { return bytes; } -goffset chunkqueue_skip_all(chunkqueue *cq) { +goffset chunkqueue_skip_all(liChunkQueue *cq) { goffset bytes = cq->length; g_queue_foreach(cq->queue, __chunk_free, cq); @@ -749,8 +749,8 @@ goffset chunkqueue_skip_all(chunkqueue *cq) { return bytes; } -gboolean chunkqueue_extract_to(vrequest *vr, chunkqueue *cq, goffset len, GString *dest) { - chunkiter ci; +gboolean chunkqueue_extract_to(liVRequest *vr, liChunkQueue *cq, goffset len, GString *dest) { + liChunkIter ci; goffset coff, clen; g_string_set_size(dest, 0); if (len > cq->length) return FALSE; @@ -765,7 +765,7 @@ gboolean chunkqueue_extract_to(vrequest *vr, chunkqueue *cq, goffset len, GStrin while (coff < clen) { gchar *buf; off_t we_have; - if (HANDLER_GO_ON != chunkiter_read(vr, ci, coff, len, &buf, &we_have)) goto error; + if (LI_HANDLER_GO_ON != chunkiter_read(vr, ci, coff, len, &buf, &we_have)) goto error; g_string_append_len(dest, buf, we_have); coff += we_have; len -= we_have; @@ -781,8 +781,8 @@ error: return FALSE; } -gboolean chunkqueue_extract_to_bytearr(vrequest *vr, chunkqueue *cq, goffset len, GByteArray *dest) { - chunkiter ci; +gboolean chunkqueue_extract_to_bytearr(liVRequest *vr, liChunkQueue *cq, goffset len, GByteArray *dest) { + liChunkIter ci; goffset coff, clen; g_byte_array_set_size(dest, 0); if (len > cq->length) return FALSE; @@ -800,7 +800,7 @@ gboolean chunkqueue_extract_to_bytearr(vrequest *vr, chunkqueue *cq, goffset len while (coff < clen) { gchar *buf; off_t we_have; - if (HANDLER_GO_ON != chunkiter_read(vr, ci, coff, len, &buf, &we_have)) goto error; + if (LI_HANDLER_GO_ON != chunkiter_read(vr, ci, coff, len, &buf, &we_have)) goto error; g_byte_array_append(dest, (guint8*) buf, we_have); coff += we_have; len -= we_have; diff --git a/src/chunk_parser.c b/src/chunk_parser.c index 19d4e41..e855962 100644 --- a/src/chunk_parser.c +++ b/src/chunk_parser.c @@ -1,12 +1,12 @@ #include -void chunk_parser_init(chunk_parser_ctx *ctx, chunkqueue *cq) { +void chunk_parser_init(liChunkParserCtx *ctx, liChunkQueue *cq) { ctx->cq = cq; chunk_parser_reset(ctx); } -void chunk_parser_reset(chunk_parser_ctx *ctx) { +void chunk_parser_reset(liChunkParserCtx *ctx) { ctx->bytes_in = 0; ctx->curi.element = NULL; ctx->start = 0; @@ -14,46 +14,46 @@ void chunk_parser_reset(chunk_parser_ctx *ctx) { ctx->buf = NULL; } -handler_t chunk_parser_prepare(chunk_parser_ctx *ctx) { +liHandlerResult chunk_parser_prepare(liChunkParserCtx *ctx) { if (NULL == ctx->curi.element) { ctx->curi = chunkqueue_iter(ctx->cq); - if (NULL == ctx->curi.element) return HANDLER_WAIT_FOR_EVENT; + if (NULL == ctx->curi.element) return LI_HANDLER_WAIT_FOR_EVENT; } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -handler_t chunk_parser_next(vrequest *vr, chunk_parser_ctx *ctx, char **p, char **pe) { +liHandlerResult chunk_parser_next(liVRequest *vr, liChunkParserCtx *ctx, char **p, char **pe) { off_t l; - handler_t res; + liHandlerResult res; - if (NULL == ctx->curi.element) return HANDLER_WAIT_FOR_EVENT; + if (NULL == ctx->curi.element) return LI_HANDLER_WAIT_FOR_EVENT; while (ctx->start >= (l = chunkiter_length(ctx->curi))) { - chunkiter i = ctx->curi; + liChunkIter i = ctx->curi; /* Wait at the end of the last chunk if it gets extended */ - if (!chunkiter_next(&i)) return HANDLER_WAIT_FOR_EVENT; + if (!chunkiter_next(&i)) return LI_HANDLER_WAIT_FOR_EVENT; ctx->curi = i; ctx->start -= l; } - if (NULL == ctx->curi.element) return HANDLER_WAIT_FOR_EVENT; + if (NULL == ctx->curi.element) return LI_HANDLER_WAIT_FOR_EVENT; - if (HANDLER_GO_ON != (res = chunkiter_read(vr, ctx->curi, ctx->start, l - ctx->start, &ctx->buf, &ctx->length))) { + if (LI_HANDLER_GO_ON != (res = chunkiter_read(vr, ctx->curi, ctx->start, l - ctx->start, &ctx->buf, &ctx->length))) { return res; } *p = ctx->buf; *pe = ctx->buf + ctx->length; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -void chunk_parser_done(chunk_parser_ctx *ctx, goffset len) { +void chunk_parser_done(liChunkParserCtx *ctx, goffset len) { ctx->bytes_in += len; ctx->start += len; } -gboolean chunk_extract_to(vrequest *vr, chunk_parser_mark from, chunk_parser_mark to, GString *dest) { - chunk_parser_mark i; +gboolean chunk_extract_to(liVRequest *vr, liChunkParserMark from, liChunkParserMark to, GString *dest) { + liChunkParserMark i; g_string_set_size(dest, 0); @@ -62,7 +62,7 @@ gboolean chunk_extract_to(vrequest *vr, chunk_parser_mark from, chunk_parser_mar while (i.pos < len) { char *buf; off_t we_have; - if (HANDLER_GO_ON != chunkiter_read(vr, i.ci, i.pos, len - i.pos, &buf, &we_have)) goto error; + if (LI_HANDLER_GO_ON != chunkiter_read(vr, i.ci, i.pos, len - i.pos, &buf, &we_have)) goto error; g_string_append_len(dest, buf, we_have); i.pos += we_have; } @@ -71,7 +71,7 @@ gboolean chunk_extract_to(vrequest *vr, chunk_parser_mark from, chunk_parser_mar while (i.pos < to.pos) { char *buf; off_t we_have; - if (HANDLER_GO_ON != chunkiter_read(vr, i.ci, i.pos, to.pos - i.pos, &buf, &we_have)) goto error; + if (LI_HANDLER_GO_ON != chunkiter_read(vr, i.ci, i.pos, to.pos - i.pos, &buf, &we_have)) goto error; g_string_append_len(dest, buf, we_have); i.pos += we_have; } @@ -83,7 +83,7 @@ error: return FALSE; } -GString* chunk_extract(vrequest *vr, chunk_parser_mark from, chunk_parser_mark to) { +GString* chunk_extract(liVRequest *vr, liChunkParserMark from, liChunkParserMark to) { GString *str = g_string_sized_new(0); if (chunk_extract_to(vr, from, to, str)) return str; g_string_free(str, TRUE); diff --git a/src/collect.c b/src/collect.c index 1f72a6e..ca3df6a 100644 --- a/src/collect.c +++ b/src/collect.c @@ -1,15 +1,29 @@ #include -struct collect_job; +/* internal structure */ +struct liCollectInfo { + liWorker *wrk; + gint counter; + gboolean stopped; + + liCollectFuncCB func; + gpointer fdata; + + liCollectCB cb; + gpointer cbdata; + + GPtrArray *results; +}; + typedef struct collect_job collect_job; struct collect_job { enum { COLLECT_FUNC, COLLECT_CB } type; - collect_info *ci; + liCollectInfo *ci; }; -static collect_info* collect_info_new(worker *ctx, CollectFunc func, gpointer fdata, CollectCallback cb, gpointer cbdata) { - collect_info *ci = g_slice_new(collect_info); +static liCollectInfo* collect_info_new(liWorker *ctx, liCollectFuncCB func, gpointer fdata, liCollectCB cb, gpointer cbdata) { + liCollectInfo *ci = g_slice_new(liCollectInfo); ci->wrk = ctx; ci->counter = ctx->srv->worker_count; ci->stopped = FALSE; @@ -22,20 +36,20 @@ static collect_info* collect_info_new(worker *ctx, CollectFunc func, gpointer fd return ci; } -static void collect_info_free(collect_info *ci) { +static void collect_info_free(liCollectInfo *ci) { g_ptr_array_free(ci->results, TRUE); - g_slice_free(collect_info, ci); + g_slice_free(liCollectInfo, ci); } /* returns true if callback was called directly */ -static gboolean collect_insert_callback(worker *ctx, collect_info *ci) { +static gboolean collect_insert_callback(liWorker *ctx, liCollectInfo *ci) { if (ctx == ci->wrk) { /* we are in the destiation context */ ci->cb(ci->cbdata, ci->fdata, ci->results, !ci->stopped); collect_info_free(ci); return TRUE; } else { - worker *wrk = ci->wrk; + liWorker *wrk = ci->wrk; collect_job *j = g_slice_new(collect_job); j->type = COLLECT_CB; j->ci = ci; @@ -46,7 +60,7 @@ static gboolean collect_insert_callback(worker *ctx, collect_info *ci) { } /* returns true if callback was called directly */ -static gboolean collect_send_result(worker *ctx, collect_info *ci) { +static gboolean collect_send_result(liWorker *ctx, liCollectInfo *ci) { if (!g_atomic_int_dec_and_test(&ci->counter)) return FALSE; /* not all workers done yet */ if (g_atomic_int_get(&ctx->srv->exiting)) { /* cleanup state, just call the callback with complete = FALSE */ @@ -60,12 +74,12 @@ static gboolean collect_send_result(worker *ctx, collect_info *ci) { } /* returns true if callback was called directly */ -static gboolean collect_insert_func(worker *ctx, collect_info *ci) { +static gboolean collect_insert_func(liWorker *ctx, liCollectInfo *ci) { guint i; - server *srv = ctx->srv; + liServer *srv = ctx->srv; for (i = 0; i < srv->worker_count; i++) { - worker *wrk; - wrk = g_array_index(srv->workers, worker*, i); + liWorker *wrk; + wrk = g_array_index(srv->workers, liWorker*, i); if (wrk == ctx) { /* we are in the destiation context */ g_ptr_array_index(ci->results, wrk->ndx) = ci->func(wrk, ci->fdata); @@ -81,24 +95,24 @@ static gboolean collect_insert_func(worker *ctx, collect_info *ci) { return FALSE; } -collect_info* collect_start(worker *ctx, CollectFunc func, gpointer fdata, CollectCallback cb, gpointer cbdata) { - collect_info *ci = collect_info_new(ctx, func, fdata, cb, cbdata); +liCollectInfo* collect_start(liWorker *ctx, liCollectFuncCB func, gpointer fdata, liCollectCB cb, gpointer cbdata) { + liCollectInfo *ci = collect_info_new(ctx, func, fdata, cb, cbdata); if (collect_insert_func(ctx, ci)) return NULL; /* collect info is invalid now */ return ci; } -void collect_break(collect_info* ci) { +void collect_break(liCollectInfo* ci) { ci->stopped = TRUE; } void collect_watcher_cb(struct ev_loop *loop, ev_async *w, int revents) { - worker *wrk = (worker*) w->data; + liWorker *wrk = (liWorker*) w->data; collect_job *j; UNUSED(loop); UNUSED(revents); while (NULL != (j = (collect_job*) g_async_queue_try_pop(wrk->collect_queue))) { - collect_info *ci = j->ci; + liCollectInfo *ci = j->ci; switch (j->type) { case COLLECT_FUNC: g_ptr_array_index(ci->results, wrk->ndx) = ci->func(wrk, ci->fdata); diff --git a/src/condition.c b/src/condition.c index 3791a94..6341821 100644 --- a/src/condition.c +++ b/src/condition.c @@ -1,41 +1,41 @@ #include -static gboolean condition_parse_ip(condition_rvalue *val, const char *txt) { +static gboolean condition_parse_ip(liConditionRValue *val, const char *txt) { if (parse_ipv4(txt, &val->ipv4.addr, NULL, NULL)) { - val->type = COND_VALUE_SOCKET_IPV4; + val->type = LI_COND_VALUE_SOCKET_IPV4; val->ipv4.networkmask = 0xFFFFFFFF; return TRUE; } if (parse_ipv6(txt, val->ipv6.addr, NULL, NULL)) { - val->type = COND_VALUE_SOCKET_IPV6; + val->type = LI_COND_VALUE_SOCKET_IPV6; val->ipv6.network = 128; return TRUE; } return FALSE; } -static gboolean condition_parse_ip_net(condition_rvalue *val, const char *txt) { +static gboolean condition_parse_ip_net(liConditionRValue *val, const char *txt) { if (parse_ipv4(txt, &val->ipv4.addr, &val->ipv4.networkmask, NULL)) { - val->type = COND_VALUE_SOCKET_IPV4; + val->type = LI_COND_VALUE_SOCKET_IPV4; return TRUE; } if (parse_ipv6(txt, val->ipv6.addr, &val->ipv6.network, NULL)) { - val->type = COND_VALUE_SOCKET_IPV6; + val->type = LI_COND_VALUE_SOCKET_IPV6; return TRUE; } return FALSE; } -static gboolean condition_ip_from_socket(condition_rvalue *val, sock_addr *addr) { +static gboolean condition_ip_from_socket(liConditionRValue *val, liSockAddr *addr) { switch (addr->plain.sa_family) { case AF_INET: - val->type = COND_VALUE_SOCKET_IPV4; + val->type = LI_COND_VALUE_SOCKET_IPV4; val->ipv4.addr = addr->ipv4.sin_addr.s_addr; val->ipv4.networkmask = 0xFFFFFFFF; return TRUE; #ifdef HAVE_IPV6 case AF_INET6: - val->type = COND_VALUE_SOCKET_IPV6; + val->type = LI_COND_VALUE_SOCKET_IPV6; memcpy(val->ipv6.addr, addr->ipv6.sin6_addr.s6_addr, 16); val->ipv6.network = 128; return TRUE; @@ -44,31 +44,31 @@ static gboolean condition_ip_from_socket(condition_rvalue *val, sock_addr *addr) return FALSE; } -condition_lvalue* condition_lvalue_new(cond_lvalue_t type, GString *key) { - condition_lvalue *lvalue = g_slice_new0(condition_lvalue); - if (type == COMP_REQUEST_HEADER) g_string_ascii_down(key); +liConditionLValue* condition_lvalue_new(liCondLValue type, GString *key) { + liConditionLValue *lvalue = g_slice_new0(liConditionLValue); + if (type == LI_COMP_REQUEST_HEADER) g_string_ascii_down(key); lvalue->type = type; lvalue->key = key; lvalue->refcount = 1; return lvalue; } -void condition_lvalue_acquire(condition_lvalue *lvalue) { +void condition_lvalue_acquire(liConditionLValue *lvalue) { assert(g_atomic_int_get(&lvalue->refcount) > 0); g_atomic_int_inc(&lvalue->refcount); } -void condition_lvalue_release(condition_lvalue *lvalue) { +void condition_lvalue_release(liConditionLValue *lvalue) { if (!lvalue) return; assert(g_atomic_int_get(&lvalue->refcount) > 0); if (g_atomic_int_dec_and_test(&lvalue->refcount)) { if (lvalue->key) g_string_free(lvalue->key, TRUE); - g_slice_free(condition_lvalue, lvalue); + g_slice_free(liConditionLValue, lvalue); } } -static condition* condition_new(comp_operator_t op, condition_lvalue *lvalue) { - condition *c = g_slice_new0(condition); +static liCondition* condition_new(liCompOperator op, liConditionLValue *lvalue) { + liCondition *c = g_slice_new0(liCondition); c->refcount = 1; c->op = op; c->lvalue = lvalue; @@ -76,17 +76,17 @@ static condition* condition_new(comp_operator_t op, condition_lvalue *lvalue) { } /* only EQ and NE */ -static condition* cond_new_string(comp_operator_t op, condition_lvalue *lvalue, GString *str) { - condition *c; +static liCondition* cond_new_string(liCompOperator op, liConditionLValue *lvalue, GString *str) { + liCondition *c; c = condition_new(op, lvalue); - c->rvalue.type = COND_VALUE_STRING; + c->rvalue.type = LI_COND_VALUE_STRING; c->rvalue.string = str; return c; } /* only MATCH and NOMATCH */ -static condition* cond_new_match(server *srv, comp_operator_t op, condition_lvalue *lvalue, GString *str) { - condition *c; +static liCondition* cond_new_match(liServer *srv, liCompOperator op, liConditionLValue *lvalue, GString *str) { + liCondition *c; GRegex *regex; GError *err = NULL; @@ -99,7 +99,7 @@ static condition* cond_new_match(server *srv, comp_operator_t op, condition_lval } c = condition_new(op, lvalue); - c->rvalue.type = COND_VALUE_REGEXP; + c->rvalue.type = LI_COND_VALUE_REGEXP; c->rvalue.regex = regex; g_string_free(str, TRUE); @@ -108,8 +108,8 @@ static condition* cond_new_match(server *srv, comp_operator_t op, condition_lval } /* only IP and NOTIP */ -static condition* cond_new_ip(server *srv, comp_operator_t op, condition_lvalue *lvalue, GString *str) { - condition *c; +static liCondition* cond_new_ip(liServer *srv, liCompOperator op, liConditionLValue *lvalue, GString *str) { + liCondition *c; c = condition_new(op, lvalue); if (!condition_parse_ip_net(&c->rvalue, str->str)) { ERROR(srv, "Invalid ip address '%s'", str->str); @@ -119,34 +119,34 @@ static condition* cond_new_ip(server *srv, comp_operator_t op, condition_lvalue return c; } -condition* condition_new_bool(server *srv, condition_lvalue *lvalue, gboolean b) { - condition *c; +liCondition* condition_new_bool(liServer *srv, liConditionLValue *lvalue, gboolean b) { + liCondition *c; UNUSED(srv); - c = condition_new(CONFIG_COND_EQ, lvalue); - c->rvalue.type = COND_VALUE_BOOL; + c = condition_new(LI_CONFIG_COND_EQ, lvalue); + c->rvalue.type = LI_COND_VALUE_BOOL; c->rvalue.b = b; return c; } -condition* condition_new_string(server *srv, comp_operator_t op, condition_lvalue *lvalue, GString *str) { +liCondition* condition_new_string(liServer *srv, liCompOperator op, liConditionLValue *lvalue, GString *str) { switch (op) { - case CONFIG_COND_EQ: - case CONFIG_COND_NE: - case CONFIG_COND_PREFIX: - case CONFIG_COND_NOPREFIX: - case CONFIG_COND_SUFFIX: - case CONFIG_COND_NOSUFFIX: + case LI_CONFIG_COND_EQ: + case LI_CONFIG_COND_NE: + case LI_CONFIG_COND_PREFIX: + case LI_CONFIG_COND_NOPREFIX: + case LI_CONFIG_COND_SUFFIX: + case LI_CONFIG_COND_NOSUFFIX: return cond_new_string(op, lvalue, str); - case CONFIG_COND_MATCH: - case CONFIG_COND_NOMATCH: + case LI_CONFIG_COND_MATCH: + case LI_CONFIG_COND_NOMATCH: return cond_new_match(srv, op, lvalue, str); - case CONFIG_COND_IP: - case CONFIG_COND_NOTIP: + case LI_CONFIG_COND_IP: + case LI_CONFIG_COND_NOTIP: return cond_new_ip(srv, op, lvalue, str); - case CONFIG_COND_GT: - case CONFIG_COND_GE: - case CONFIG_COND_LT: - case CONFIG_COND_LE: + case LI_CONFIG_COND_GT: + case LI_CONFIG_COND_GE: + case LI_CONFIG_COND_LT: + case LI_CONFIG_COND_LE: ERROR(srv, "Cannot compare strings with '%s'", comp_op_to_string(op)); return NULL; } @@ -156,27 +156,27 @@ condition* condition_new_string(server *srv, comp_operator_t op, condition_lvalu return NULL; } -condition* condition_new_int(server *srv, comp_operator_t op, condition_lvalue *lvalue, gint64 i) { - condition *c; +liCondition* condition_new_int(liServer *srv, liCompOperator op, liConditionLValue *lvalue, gint64 i) { + liCondition *c; switch (op) { - case CONFIG_COND_PREFIX: - case CONFIG_COND_NOPREFIX: - case CONFIG_COND_SUFFIX: - case CONFIG_COND_NOSUFFIX: - case CONFIG_COND_MATCH: - case CONFIG_COND_NOMATCH: - case CONFIG_COND_IP: - case CONFIG_COND_NOTIP: + case LI_CONFIG_COND_PREFIX: + case LI_CONFIG_COND_NOPREFIX: + case LI_CONFIG_COND_SUFFIX: + case LI_CONFIG_COND_NOSUFFIX: + case LI_CONFIG_COND_MATCH: + case LI_CONFIG_COND_NOMATCH: + case LI_CONFIG_COND_IP: + case LI_CONFIG_COND_NOTIP: ERROR(srv, "Cannot compare integers with '%s'", comp_op_to_string(op)); return NULL; - case CONFIG_COND_EQ: - case CONFIG_COND_NE: - case CONFIG_COND_GT: - case CONFIG_COND_GE: - case CONFIG_COND_LT: - case CONFIG_COND_LE: + case LI_CONFIG_COND_EQ: + case LI_CONFIG_COND_NE: + case LI_CONFIG_COND_GT: + case LI_CONFIG_COND_GE: + case LI_CONFIG_COND_LT: + case LI_CONFIG_COND_LE: c = condition_new(op, lvalue); - c->rvalue.type = COND_VALUE_NUMBER; + c->rvalue.type = LI_COND_VALUE_NUMBER; c->rvalue.i = i; return c; } @@ -187,33 +187,33 @@ condition* condition_new_int(server *srv, comp_operator_t op, condition_lvalue * } -static void condition_free(condition *c) { +static void condition_free(liCondition *c) { condition_lvalue_release(c->lvalue); switch (c->rvalue.type) { - case COND_VALUE_BOOL: - case COND_VALUE_NUMBER: + case LI_COND_VALUE_BOOL: + case LI_COND_VALUE_NUMBER: /* nothing to free */ break; - case COND_VALUE_STRING: + case LI_COND_VALUE_STRING: g_string_free(c->rvalue.string, TRUE); break; - case COND_VALUE_REGEXP: + case LI_COND_VALUE_REGEXP: g_regex_unref(c->rvalue.regex); break; - case COND_VALUE_SOCKET_IPV4: - case COND_VALUE_SOCKET_IPV6: + case LI_COND_VALUE_SOCKET_IPV4: + case LI_COND_VALUE_SOCKET_IPV6: /* nothing to free */ break; } - g_slice_free(condition, c); + g_slice_free(liCondition, c); } -void condition_acquire(condition *c) { +void condition_acquire(liCondition *c) { assert(g_atomic_int_get(&c->refcount) > 0); g_atomic_int_inc(&c->refcount); } -void condition_release(server *srv, condition* c) { +void condition_release(liServer *srv, liCondition* c) { UNUSED(srv); if (!c) return; assert(g_atomic_int_get(&c->refcount) > 0); @@ -222,50 +222,50 @@ void condition_release(server *srv, condition* c) { } } -const char* comp_op_to_string(comp_operator_t op) { +const char* comp_op_to_string(liCompOperator op) { switch (op) { - case CONFIG_COND_EQ: return "=="; - case CONFIG_COND_NE: return "!="; - case CONFIG_COND_PREFIX: return "=^"; - case CONFIG_COND_NOPREFIX: return "=^"; - case CONFIG_COND_SUFFIX: return "=$"; - case CONFIG_COND_NOSUFFIX: return "!$"; - case CONFIG_COND_MATCH: return "=~"; - case CONFIG_COND_NOMATCH: return "!~"; - case CONFIG_COND_IP: return "=/"; - case CONFIG_COND_NOTIP: return "!/"; - case CONFIG_COND_GT: return ">"; - case CONFIG_COND_GE: return ">="; - case CONFIG_COND_LT: return "<"; - case CONFIG_COND_LE: return "<="; + case LI_CONFIG_COND_EQ: return "=="; + case LI_CONFIG_COND_NE: return "!="; + case LI_CONFIG_COND_PREFIX: return "=^"; + case LI_CONFIG_COND_NOPREFIX: return "=^"; + case LI_CONFIG_COND_SUFFIX: return "=$"; + case LI_CONFIG_COND_NOSUFFIX: return "!$"; + case LI_CONFIG_COND_MATCH: return "=~"; + case LI_CONFIG_COND_NOMATCH: return "!~"; + case LI_CONFIG_COND_IP: return "=/"; + case LI_CONFIG_COND_NOTIP: return "!/"; + case LI_CONFIG_COND_GT: return ">"; + case LI_CONFIG_COND_GE: return ">="; + case LI_CONFIG_COND_LT: return "<"; + case LI_CONFIG_COND_LE: return "<="; } return ""; } -const char* cond_lvalue_to_string(cond_lvalue_t t) { +const char* cond_lvalue_to_string(liCondLValue t) { switch (t) { - case COMP_REQUEST_LOCALIP: return "request.localip"; - case COMP_REQUEST_REMOTEIP: return "request.remoteip"; - case COMP_REQUEST_PATH: return "request.path"; - case COMP_REQUEST_HOST: return "request.host"; - case COMP_REQUEST_SCHEME: return "request.scheme"; - case COMP_REQUEST_QUERY_STRING: return "request.query"; - case COMP_REQUEST_METHOD: return "request.method"; - case COMP_REQUEST_CONTENT_LENGTH: return "request.length"; - case COMP_PHYSICAL_PATH: return "physical.path"; - case COMP_PHYSICAL_PATH_EXISTS: return "physical.exist"; - case COMP_PHYSICAL_SIZE: return "physical.size"; - case COMP_PHYSICAL_ISDIR: return "physical.is_dir"; - case COMP_PHYSICAL_ISFILE: return "physical.is_file"; - case COMP_REQUEST_HEADER: return "request.header"; - case COMP_UNKNOWN: return ""; + case LI_COMP_REQUEST_LOCALIP: return "request.localip"; + case LI_COMP_REQUEST_REMOTEIP: return "request.remoteip"; + case LI_COMP_REQUEST_PATH: return "request.path"; + case LI_COMP_REQUEST_HOST: return "request.host"; + case LI_COMP_REQUEST_SCHEME: return "request.scheme"; + case LI_COMP_REQUEST_QUERY_STRING: return "request.query"; + case LI_COMP_REQUEST_METHOD: return "request.method"; + case LI_COMP_REQUEST_CONTENT_LENGTH: return "request.length"; + case LI_COMP_PHYSICAL_PATH: return "physical.path"; + case LI_COMP_PHYSICAL_PATH_EXISTS: return "physical.exist"; + case LI_COMP_PHYSICAL_SIZE: return "physical.size"; + case LI_COMP_PHYSICAL_ISDIR: return "physical.is_dir"; + case LI_COMP_PHYSICAL_ISFILE: return "physical.is_file"; + case LI_COMP_REQUEST_HEADER: return "request.header"; + case LI_COMP_UNKNOWN: return ""; } return ""; } -cond_lvalue_t cond_lvalue_from_string(const gchar *str, guint len) { +liCondLValue cond_lvalue_from_string(const gchar *str, guint len) { gchar *c = (gchar*)str; if (g_str_has_prefix(c, "request.")) { @@ -273,47 +273,47 @@ cond_lvalue_t cond_lvalue_from_string(const gchar *str, guint len) { len -= sizeof("request.")-1; if (strncmp(c, "localip", len) == 0) - return COMP_REQUEST_LOCALIP; + return LI_COMP_REQUEST_LOCALIP; else if (strncmp(c, "remoteip", len) == 0) - return COMP_REQUEST_REMOTEIP; + return LI_COMP_REQUEST_REMOTEIP; else if (strncmp(c, "path", len) == 0) - return COMP_REQUEST_PATH; + return LI_COMP_REQUEST_PATH; else if (strncmp(c, "host", len) == 0) - return COMP_REQUEST_HOST; + return LI_COMP_REQUEST_HOST; else if (strncmp(c, "scheme", len) == 0) - return COMP_REQUEST_SCHEME; + return LI_COMP_REQUEST_SCHEME; else if (strncmp(c, "query", len) == 0) - return COMP_REQUEST_QUERY_STRING; + return LI_COMP_REQUEST_QUERY_STRING; else if (strncmp(c, "method", len) == 0) - return COMP_REQUEST_METHOD; + return LI_COMP_REQUEST_METHOD; else if (strncmp(c, "length", len) == 0) - return COMP_REQUEST_CONTENT_LENGTH; + return LI_COMP_REQUEST_CONTENT_LENGTH; else if (strncmp(c, "header", len) == 0) - return COMP_REQUEST_HEADER; + return LI_COMP_REQUEST_HEADER; } else if (strncmp(c, "physical.", sizeof("physical.")-1) == 0) { c += sizeof("physical.")-1; len -= sizeof("physical.")-1; if (strncmp(c, "path", len) == 0) - return COMP_PHYSICAL_PATH; + return LI_COMP_PHYSICAL_PATH; else if (strncmp(c, "exists", len) == 0) - return COMP_PHYSICAL_PATH_EXISTS; + return LI_COMP_PHYSICAL_PATH_EXISTS; else if (strncmp(c, "size", len) == 0) - return COMP_PHYSICAL_SIZE; + return LI_COMP_PHYSICAL_SIZE; else if (strncmp(c, "is_file", len) == 0) - return COMP_PHYSICAL_ISFILE; + return LI_COMP_PHYSICAL_ISFILE; else if (strncmp(c, "is_dir", len) == 0) - return COMP_PHYSICAL_ISDIR; + return LI_COMP_PHYSICAL_ISDIR; } - return COMP_UNKNOWN; + return LI_COMP_UNKNOWN; } -static handler_t condition_check_eval_bool(vrequest *vr, condition *cond, gboolean *res) { +static liHandlerResult condition_check_eval_bool(liVRequest *vr, liCondition *cond, gboolean *res) { *res = FALSE; - if (cond->lvalue->type == COMP_PHYSICAL_ISDIR || - cond->lvalue->type == COMP_PHYSICAL_ISFILE) { + if (cond->lvalue->type == LI_COMP_PHYSICAL_ISDIR || + cond->lvalue->type == LI_COMP_PHYSICAL_ISFILE) { if (!vr->physical.have_stat) { if (vr->physical.have_errno || !vrequest_stat(vr)) { switch (vr->physical.stat_errno) { @@ -328,124 +328,124 @@ static handler_t condition_check_eval_bool(vrequest *vr, condition *cond, gboole default: vr->response.http_status = 500; } vrequest_handle_direct(vr); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } } } switch (cond->lvalue->type) { - case COMP_PHYSICAL_ISDIR: + case LI_COMP_PHYSICAL_ISDIR: *res = S_ISDIR(vr->physical.stat.st_mode); break; - case COMP_PHYSICAL_ISFILE: + case LI_COMP_PHYSICAL_ISFILE: *res = S_ISREG(vr->physical.stat.st_mode); break; default: VR_ERROR(vr, "invalid lvalue \"%s\" for boolean comparison", cond_lvalue_to_string(cond->lvalue->type)); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -/* COND_VALUE_STRING and COND_VALUE_REGEXP only */ -static handler_t condition_check_eval_string(vrequest *vr, condition *cond, gboolean *res) { - action_regex_stack_element arse; - connection *con = vr->con; +/* LI_COND_VALUE_STRING and LI_COND_VALUE_REGEXP only */ +static liHandlerResult condition_check_eval_string(liVRequest *vr, liCondition *cond, gboolean *res) { + liActionRegexStackElement arse; + liConnection *con = vr->con; const char *val = ""; *res = FALSE; switch (cond->lvalue->type) { - case COMP_REQUEST_LOCALIP: + case LI_COMP_REQUEST_LOCALIP: val = con->srv_sock->local_addr_str->str; break; - case COMP_REQUEST_REMOTEIP: + case LI_COMP_REQUEST_REMOTEIP: val = con->remote_addr_str->str; break; - case COMP_REQUEST_PATH: + case LI_COMP_REQUEST_PATH: val = vr->request.uri.path->str; break; - case COMP_REQUEST_HOST: + case LI_COMP_REQUEST_HOST: val = vr->request.uri.host->str; break; - case COMP_REQUEST_SCHEME: + case LI_COMP_REQUEST_SCHEME: val = con->is_ssl ? "https" : "http"; break; - case COMP_REQUEST_QUERY_STRING: + case LI_COMP_REQUEST_QUERY_STRING: val = vr->request.uri.query->str; break; - case COMP_REQUEST_METHOD: + case LI_COMP_REQUEST_METHOD: val = vr->request.http_method_str->str; break; - case COMP_PHYSICAL_PATH: + case LI_COMP_PHYSICAL_PATH: val = vr->physical.path->str; break; - case COMP_PHYSICAL_PATH_EXISTS: + case LI_COMP_PHYSICAL_PATH_EXISTS: /* TODO: physical path exists */ break; - case COMP_REQUEST_HEADER: + case LI_COMP_REQUEST_HEADER: http_header_get_fast(con->wrk->tmp_str, vr->request.headers, GSTR_LEN(cond->lvalue->key)); val = con->wrk->tmp_str->str; break; - case COMP_REQUEST_CONTENT_LENGTH: + case LI_COMP_REQUEST_CONTENT_LENGTH: g_string_printf(con->wrk->tmp_str, "%"L_GOFFSET_FORMAT, vr->request.content_length); val = con->wrk->tmp_str->str; break; default: - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } switch (cond->op) { - case CONFIG_COND_EQ: + case LI_CONFIG_COND_EQ: *res = g_str_equal(val, cond->rvalue.string->str); break; - case CONFIG_COND_NE: + case LI_CONFIG_COND_NE: *res = !g_str_equal(val, cond->rvalue.string->str); break; - case CONFIG_COND_PREFIX: + case LI_CONFIG_COND_PREFIX: *res = g_str_has_prefix(val, cond->rvalue.string->str); break; - case CONFIG_COND_NOPREFIX: + case LI_CONFIG_COND_NOPREFIX: *res = !g_str_has_prefix(val, cond->rvalue.string->str); break; - case CONFIG_COND_SUFFIX: + case LI_CONFIG_COND_SUFFIX: *res = g_str_has_suffix(val, cond->rvalue.string->str); break; - case CONFIG_COND_NOSUFFIX: + case LI_CONFIG_COND_NOSUFFIX: *res = !g_str_has_suffix(val, cond->rvalue.string->str); break; - case CONFIG_COND_MATCH: + case LI_CONFIG_COND_MATCH: *res = g_regex_match(cond->rvalue.regex, val, 0, &arse.match_info); arse.string = (*res) ? g_string_new(val) : NULL; g_array_append_val(vr->action_stack.regex_stack, arse); break; - case CONFIG_COND_NOMATCH: + case LI_CONFIG_COND_NOMATCH: *res = !g_regex_match(cond->rvalue.regex, val, 0, &arse.match_info); arse.string = NULL; g_array_append_val(vr->action_stack.regex_stack, arse); break; - case CONFIG_COND_IP: - case CONFIG_COND_NOTIP: - case CONFIG_COND_GE: - case CONFIG_COND_GT: - case CONFIG_COND_LE: - case CONFIG_COND_LT: + case LI_CONFIG_COND_IP: + case LI_CONFIG_COND_NOTIP: + case LI_CONFIG_COND_GE: + case LI_CONFIG_COND_GT: + case LI_CONFIG_COND_LE: + case LI_CONFIG_COND_LT: VR_ERROR(vr, "cannot compare string/regexp with '%s'", comp_op_to_string(cond->op)); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static handler_t condition_check_eval_int(vrequest *vr, condition *cond, gboolean *res) { +static liHandlerResult condition_check_eval_int(liVRequest *vr, liCondition *cond, gboolean *res) { gint64 val; *res = FALSE; switch (cond->lvalue->type) { - case COMP_REQUEST_CONTENT_LENGTH: + case LI_COMP_REQUEST_CONTENT_LENGTH: val = vr->request.content_length; - case COMP_PHYSICAL_SIZE: + case LI_COMP_PHYSICAL_SIZE: if (!vr->physical.have_stat) { if (vr->physical.have_errno || !vrequest_stat(vr)) { switch (vr->physical.stat_errno) { @@ -460,48 +460,48 @@ static handler_t condition_check_eval_int(vrequest *vr, condition *cond, gboolea default: vr->response.http_status = 500; } vrequest_handle_direct(vr); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } } val = (gint64)vr->physical.stat.st_size; break; default: VR_ERROR(vr, "couldn't get int value for '%s'", cond_lvalue_to_string(cond->lvalue->type)); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } switch (cond->op) { - case CONFIG_COND_EQ: /** == */ + case LI_CONFIG_COND_EQ: /** == */ *res = (val == cond->rvalue.i); break; - case CONFIG_COND_NE: /** != */ + case LI_CONFIG_COND_NE: /** != */ *res = (val != cond->rvalue.i); break; - case CONFIG_COND_LT: /** < */ + case LI_CONFIG_COND_LT: /** < */ *res = (val < cond->rvalue.i); break; - case CONFIG_COND_LE: /** <= */ + case LI_CONFIG_COND_LE: /** <= */ *res = (val <= cond->rvalue.i); break; - case CONFIG_COND_GT: /** > */ + case LI_CONFIG_COND_GT: /** > */ *res = (val > cond->rvalue.i); break; - case CONFIG_COND_GE: /** >= */ + case LI_CONFIG_COND_GE: /** >= */ *res = (val >= cond->rvalue.i); break; - case CONFIG_COND_PREFIX: - case CONFIG_COND_NOPREFIX: - case CONFIG_COND_SUFFIX: - case CONFIG_COND_NOSUFFIX: - case CONFIG_COND_MATCH: - case CONFIG_COND_NOMATCH: - case CONFIG_COND_IP: - case CONFIG_COND_NOTIP: + case LI_CONFIG_COND_PREFIX: + case LI_CONFIG_COND_NOPREFIX: + case LI_CONFIG_COND_SUFFIX: + case LI_CONFIG_COND_NOSUFFIX: + case LI_CONFIG_COND_MATCH: + case LI_CONFIG_COND_NOMATCH: + case LI_CONFIG_COND_IP: + case LI_CONFIG_COND_NOTIP: VR_ERROR(vr, "cannot compare int with '%s'", comp_op_to_string(cond->op)); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } static gboolean ipv4_in_ipv4_net(guint32 target, guint32 match, guint32 networkmask) { @@ -528,123 +528,123 @@ static gboolean ipv4_in_ipv6_net(guint32 target, const guint8 *match, guint netw return ipv6_in_ipv6_net(ipv6, match, network); } -static gboolean ip_in_net(condition_rvalue *target, condition_rvalue *network) { - if (target->type == COND_VALUE_SOCKET_IPV4) { - if (network->type == COND_VALUE_SOCKET_IPV4) { +static gboolean ip_in_net(liConditionRValue *target, liConditionRValue *network) { + if (target->type == LI_COND_VALUE_SOCKET_IPV4) { + if (network->type == LI_COND_VALUE_SOCKET_IPV4) { return ipv4_in_ipv4_net(target->ipv4.addr, network->ipv4.addr, network->ipv4.networkmask); - } else if (network->type == COND_VALUE_SOCKET_IPV6) { + } else if (network->type == LI_COND_VALUE_SOCKET_IPV6) { return ipv4_in_ipv6_net(target->ipv4.addr, network->ipv6.addr, network->ipv6.network); } - } else if (target->type == COND_VALUE_SOCKET_IPV6) { - if (network->type == COND_VALUE_SOCKET_IPV4) { + } else if (target->type == LI_COND_VALUE_SOCKET_IPV6) { + if (network->type == LI_COND_VALUE_SOCKET_IPV4) { return ipv6_in_ipv4_net(target->ipv6.addr, network->ipv4.addr, network->ipv4.networkmask); - } else if (network->type == COND_VALUE_SOCKET_IPV6) { + } else if (network->type == LI_COND_VALUE_SOCKET_IPV6) { return ipv6_in_ipv6_net(target->ipv6.addr, network->ipv6.addr, network->ipv6.network); } } return FALSE; } -/* CONFIG_COND_IP and CONFIG_COND_NOTIP only */ -static handler_t condition_check_eval_ip(vrequest *vr, condition *cond, gboolean *res) { - connection *con = vr->con; - condition_rvalue ipval; +/* LI_CONFIG_COND_IP and LI_CONFIG_COND_NOTIP only */ +static liHandlerResult condition_check_eval_ip(liVRequest *vr, liCondition *cond, gboolean *res) { + liConnection *con = vr->con; + liConditionRValue ipval; const char *val = NULL; - *res = (cond->op == CONFIG_COND_NOTIP); + *res = (cond->op == LI_CONFIG_COND_NOTIP); - ipval.type = COND_VALUE_NUMBER; + ipval.type = LI_COND_VALUE_NUMBER; switch (cond->lvalue->type) { - case COMP_REQUEST_LOCALIP: + case LI_COMP_REQUEST_LOCALIP: if (!condition_ip_from_socket(&ipval, con->srv_sock->local_addr.addr)) - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; break; - case COMP_REQUEST_REMOTEIP: + case LI_COMP_REQUEST_REMOTEIP: if (!condition_ip_from_socket(&ipval, con->remote_addr.addr)) - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; break; - case COMP_REQUEST_PATH: + case LI_COMP_REQUEST_PATH: VR_ERROR(vr, "%s", "Cannot parse request.path as ip"); - return HANDLER_ERROR; - case COMP_REQUEST_HOST: + return LI_HANDLER_ERROR; + case LI_COMP_REQUEST_HOST: val = vr->request.uri.host->str; break; - case COMP_REQUEST_SCHEME: + case LI_COMP_REQUEST_SCHEME: VR_ERROR(vr, "%s", "Cannot parse request.scheme as ip"); - return HANDLER_ERROR; - case COMP_REQUEST_QUERY_STRING: + return LI_HANDLER_ERROR; + case LI_COMP_REQUEST_QUERY_STRING: val = vr->request.uri.query->str; break; - case COMP_REQUEST_METHOD: + case LI_COMP_REQUEST_METHOD: VR_ERROR(vr, "%s", "Cannot parse request.method as ip"); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; break; - case COMP_PHYSICAL_PATH: - case COMP_PHYSICAL_PATH_EXISTS: + case LI_COMP_PHYSICAL_PATH: + case LI_COMP_PHYSICAL_PATH_EXISTS: VR_ERROR(vr, "%s", "Cannot parse physical.path(-exists) as ip"); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; break; - case COMP_REQUEST_HEADER: + case LI_COMP_REQUEST_HEADER: http_header_get_fast(con->wrk->tmp_str, vr->request.headers, GSTR_LEN(cond->lvalue->key)); val = con->wrk->tmp_str->str; break; - case COMP_PHYSICAL_SIZE: - case COMP_REQUEST_CONTENT_LENGTH: + case LI_COMP_PHYSICAL_SIZE: + case LI_COMP_REQUEST_CONTENT_LENGTH: VR_ERROR(vr, "%s", "Cannot parse integers as ip"); - return HANDLER_ERROR; - case COMP_PHYSICAL_ISDIR: - case COMP_PHYSICAL_ISFILE: + return LI_HANDLER_ERROR; + case LI_COMP_PHYSICAL_ISDIR: + case LI_COMP_PHYSICAL_ISFILE: VR_ERROR(vr, "%s", "phys.is_dir and phys.is_file are boolean conditionals"); - return HANDLER_ERROR; - case COMP_UNKNOWN: + return LI_HANDLER_ERROR; + case LI_COMP_UNKNOWN: VR_ERROR(vr, "%s", "Cannot parse unknown condition value"); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } - if (ipval.type == COND_VALUE_NUMBER) { + if (ipval.type == LI_COND_VALUE_NUMBER) { if (!val || !condition_parse_ip(&ipval, val)) - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } switch (cond->op) { - case CONFIG_COND_IP: + case LI_CONFIG_COND_IP: *res = ip_in_net(&ipval, &cond->rvalue); - case CONFIG_COND_NOTIP: + case LI_CONFIG_COND_NOTIP: *res = !ip_in_net(&ipval, &cond->rvalue); - case CONFIG_COND_PREFIX: - case CONFIG_COND_NOPREFIX: - case CONFIG_COND_SUFFIX: - case CONFIG_COND_NOSUFFIX: - case CONFIG_COND_EQ: - case CONFIG_COND_NE: - case CONFIG_COND_MATCH: - case CONFIG_COND_NOMATCH: - case CONFIG_COND_GE: - case CONFIG_COND_GT: - case CONFIG_COND_LE: - case CONFIG_COND_LT: + case LI_CONFIG_COND_PREFIX: + case LI_CONFIG_COND_NOPREFIX: + case LI_CONFIG_COND_SUFFIX: + case LI_CONFIG_COND_NOSUFFIX: + case LI_CONFIG_COND_EQ: + case LI_CONFIG_COND_NE: + case LI_CONFIG_COND_MATCH: + case LI_CONFIG_COND_NOMATCH: + case LI_CONFIG_COND_GE: + case LI_CONFIG_COND_GT: + case LI_CONFIG_COND_LE: + case LI_CONFIG_COND_LT: VR_ERROR(vr, "cannot match ips with '%s'", comp_op_to_string(cond->op)); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -handler_t condition_check(vrequest *vr, condition *cond, gboolean *res) { +liHandlerResult condition_check(liVRequest *vr, liCondition *cond, gboolean *res) { switch (cond->rvalue.type) { - case COND_VALUE_BOOL: + case LI_COND_VALUE_BOOL: return condition_check_eval_bool(vr, cond, res); - case COND_VALUE_STRING: + case LI_COND_VALUE_STRING: #ifdef HAVE_PCRE_H - case COND_VALUE_REGEXP: + case LI_COND_VALUE_REGEXP: #endif return condition_check_eval_string(vr, cond, res); - case COND_VALUE_NUMBER: + case LI_COND_VALUE_NUMBER: return condition_check_eval_int(vr, cond, res); - case COND_VALUE_SOCKET_IPV4: - case COND_VALUE_SOCKET_IPV6: + case LI_COND_VALUE_SOCKET_IPV4: + case LI_COND_VALUE_SOCKET_IPV6: return condition_check_eval_ip(vr, cond, res); } VR_ERROR(vr, "Unsupported conditional type: %i", cond->rvalue.type); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } diff --git a/src/condition_lua.c b/src/condition_lua.c index c5e3fcf..3307744 100644 --- a/src/condition_lua.c +++ b/src/condition_lua.c @@ -6,7 +6,7 @@ #include #define LUA_CONDITION "condition*" -#define LUA_COND_LVALUE "cond_lvalue*" +#define LUA_COND_LVALUE "cond_lliValue*" #define LUA_COND_LVALUE_T "cond_lvalue_t" /* helper */ @@ -55,7 +55,7 @@ static void lua_settop_in_dicts(lua_State *L, const gchar *path) { /* Get objects from lua */ -condition* lua_get_condition(lua_State *L, int ndx) { +liCondition* lua_get_condition(lua_State *L, int ndx) { if (!lua_isuserdata(L, ndx)) return NULL; if (!lua_getmetatable(L, ndx)) return NULL; luaL_getmetatable(L, LUA_CONDITION); @@ -64,10 +64,10 @@ condition* lua_get_condition(lua_State *L, int ndx) { return NULL; } lua_pop(L, 2); - return *(condition**) lua_touserdata(L, ndx); + return *(liCondition**) lua_touserdata(L, ndx); } -static condition_lvalue* lua_get_condition_lvalue(lua_State *L, int ndx) { +static liConditionLValue* lua_get_condition_lvalue(lua_State *L, int ndx) { if (!lua_isuserdata(L, ndx)) return NULL; if (!lua_getmetatable(L, ndx)) return NULL; luaL_getmetatable(L, LUA_COND_LVALUE); @@ -76,10 +76,10 @@ static condition_lvalue* lua_get_condition_lvalue(lua_State *L, int ndx) { return NULL; } lua_pop(L, 2); - return *(condition_lvalue**) lua_touserdata(L, ndx); + return *(liConditionLValue**) lua_touserdata(L, ndx); } -static cond_lvalue_t lua_get_cond_lvalue_t(lua_State *L, int ndx) { +static liCondLValue lua_get_cond_lvalue_t(lua_State *L, int ndx) { if (!lua_isuserdata(L, ndx)) return -1; if (!lua_getmetatable(L, ndx)) return -1; luaL_getmetatable(L, LUA_COND_LVALUE_T); @@ -88,23 +88,23 @@ static cond_lvalue_t lua_get_cond_lvalue_t(lua_State *L, int ndx) { return -1; } lua_pop(L, 2); - return *(cond_lvalue_t*) lua_touserdata(L, ndx); + return *(liCondLValue*) lua_touserdata(L, ndx); } /* Garbage collection */ static int lua_condition_gc(lua_State *L) { - server *srv; - condition **c = (condition**) luaL_checkudata(L, 1, LUA_CONDITION); + liServer *srv; + liCondition **c = (liCondition**) luaL_checkudata(L, 1, LUA_CONDITION); if (!c || !*c) return 0; - srv = (server*) lua_touserdata(L, lua_upvalueindex(1)); + srv = (liServer*) lua_touserdata(L, lua_upvalueindex(1)); condition_release(srv, *c); return 0; } static int lua_cond_lvalue_gc(lua_State *L) { - condition_lvalue **lvalue = (condition_lvalue**) luaL_checkudata(L, 1, LUA_COND_LVALUE); + liConditionLValue **lvalue = (liConditionLValue**) luaL_checkudata(L, 1, LUA_COND_LVALUE); if (!lvalue || !*lvalue) return 0; condition_lvalue_release(*lvalue); @@ -113,16 +113,16 @@ static int lua_cond_lvalue_gc(lua_State *L) { /* new metatables and push */ -static void lua_push_condition_metatable(server *srv, lua_State *L) { +static void lua_push_condition_metatable(liServer *srv, lua_State *L) { if (luaL_newmetatable(L, LUA_CONDITION)) { lua_mt_register_srv(srv, L, "__gc", lua_condition_gc); } } -int lua_push_condition(server *srv, lua_State *L, condition *c) { - condition **pc; +int lua_push_condition(liServer *srv, lua_State *L, liCondition *c) { + liCondition **pc; - pc = (condition**) lua_newuserdata(L, sizeof(condition*)); + pc = (liCondition**) lua_newuserdata(L, sizeof(liCondition*)); *pc = c; lua_push_condition_metatable(srv, L); @@ -136,7 +136,7 @@ int lua_push_condition(server *srv, lua_State *L, condition *c) { /* ::_tostring */ static int lua_cond_lvalue_tostring(lua_State *L) { - condition_lvalue *lvalue = lua_get_condition_lvalue(L, 1); + liConditionLValue *lvalue = lua_get_condition_lvalue(L, 1); if (!lvalue) return 0; lua_pushstring(L, cond_lvalue_to_string(lvalue->type)); if (lvalue->key) { @@ -149,15 +149,15 @@ static int lua_cond_lvalue_tostring(lua_State *L) { } static int lua_cond_lvalue_cmp(lua_State *L) { - server *srv; + liServer *srv; GString *sval; - condition *c; - condition_lvalue *lvalue; - comp_operator_t cmpop; + liCondition *c; + liConditionLValue *lvalue; + liCompOperator cmpop; lvalue = lua_get_condition_lvalue(L, 1); - srv = (server*) lua_touserdata(L, lua_upvalueindex(1)); - cmpop = (comp_operator_t) lua_tointeger(L, lua_upvalueindex(2)); + srv = (liServer*) lua_touserdata(L, lua_upvalueindex(1)); + cmpop = (liCompOperator) lua_tointeger(L, lua_upvalueindex(2)); if (NULL == (sval = lua_togstring(L, 2))) return 0; c = condition_new_string(srv, cmpop, lvalue, sval); @@ -169,35 +169,35 @@ static int lua_cond_lvalue_cmp(lua_State *L) { return 0; } -static void lua_push_cond_lvalue_metatable(server *srv, lua_State *L) { +static void lua_push_cond_lvalue_metatable(liServer *srv, lua_State *L) { if (luaL_newmetatable(L, LUA_COND_LVALUE)) { lua_mt_register(L, "__gc", lua_cond_lvalue_gc); lua_mt_register(L, "__tostring", lua_cond_lvalue_tostring); - lua_mt_register_cmp(srv, L, "eq", lua_cond_lvalue_cmp, CONFIG_COND_EQ); - lua_mt_register_cmp(srv, L, "ne", lua_cond_lvalue_cmp, CONFIG_COND_NE); - lua_mt_register_cmp(srv, L, "prefix", lua_cond_lvalue_cmp, CONFIG_COND_PREFIX); - lua_mt_register_cmp(srv, L, "notprefix", lua_cond_lvalue_cmp, CONFIG_COND_NOPREFIX); - lua_mt_register_cmp(srv, L, "suffix", lua_cond_lvalue_cmp, CONFIG_COND_SUFFIX); - lua_mt_register_cmp(srv, L, "notsuffix", lua_cond_lvalue_cmp, CONFIG_COND_NOSUFFIX); - lua_mt_register_cmp(srv, L, "match", lua_cond_lvalue_cmp, CONFIG_COND_MATCH); - lua_mt_register_cmp(srv, L, "nomatch", lua_cond_lvalue_cmp, CONFIG_COND_NOMATCH); - lua_mt_register_cmp(srv, L, "ip", lua_cond_lvalue_cmp, CONFIG_COND_IP); - lua_mt_register_cmp(srv, L, "notip", lua_cond_lvalue_cmp, CONFIG_COND_NOTIP); - lua_mt_register_cmp(srv, L, "gt", lua_cond_lvalue_cmp, CONFIG_COND_GT); - lua_mt_register_cmp(srv, L, "ge", lua_cond_lvalue_cmp, CONFIG_COND_GE); - lua_mt_register_cmp(srv, L, "lt", lua_cond_lvalue_cmp, CONFIG_COND_LT); - lua_mt_register_cmp(srv, L, "le", lua_cond_lvalue_cmp, CONFIG_COND_LE); + lua_mt_register_cmp(srv, L, "eq", lua_cond_lvalue_cmp, LI_CONFIG_COND_EQ); + lua_mt_register_cmp(srv, L, "ne", lua_cond_lvalue_cmp, LI_CONFIG_COND_NE); + lua_mt_register_cmp(srv, L, "prefix", lua_cond_lvalue_cmp, LI_CONFIG_COND_PREFIX); + lua_mt_register_cmp(srv, L, "notprefix", lua_cond_lvalue_cmp, LI_CONFIG_COND_NOPREFIX); + lua_mt_register_cmp(srv, L, "suffix", lua_cond_lvalue_cmp, LI_CONFIG_COND_SUFFIX); + lua_mt_register_cmp(srv, L, "notsuffix", lua_cond_lvalue_cmp, LI_CONFIG_COND_NOSUFFIX); + lua_mt_register_cmp(srv, L, "match", lua_cond_lvalue_cmp, LI_CONFIG_COND_MATCH); + lua_mt_register_cmp(srv, L, "nomatch", lua_cond_lvalue_cmp, LI_CONFIG_COND_NOMATCH); + lua_mt_register_cmp(srv, L, "ip", lua_cond_lvalue_cmp, LI_CONFIG_COND_IP); + lua_mt_register_cmp(srv, L, "notip", lua_cond_lvalue_cmp, LI_CONFIG_COND_NOTIP); + lua_mt_register_cmp(srv, L, "gt", lua_cond_lvalue_cmp, LI_CONFIG_COND_GT); + lua_mt_register_cmp(srv, L, "ge", lua_cond_lvalue_cmp, LI_CONFIG_COND_GE); + lua_mt_register_cmp(srv, L, "lt", lua_cond_lvalue_cmp, LI_CONFIG_COND_LT); + lua_mt_register_cmp(srv, L, "le", lua_cond_lvalue_cmp, LI_CONFIG_COND_LE); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); } } -static int lua_push_cond_lvalue(server *srv, lua_State *L, condition_lvalue *lvalue) { - condition_lvalue **pv; +static int lua_push_cond_lvalue(liServer *srv, lua_State *L, liConditionLValue *lvalue) { + liConditionLValue **pv; - pv = (condition_lvalue**) lua_newuserdata(L, sizeof(condition_lvalue*)); + pv = (liConditionLValue**) lua_newuserdata(L, sizeof(liConditionLValue*)); *pv = lvalue; lua_push_cond_lvalue_metatable(srv, L); @@ -208,24 +208,24 @@ static int lua_push_cond_lvalue(server *srv, lua_State *L, condition_lvalue *lva /* cond_lvalue_t metatable */ static int lua_cond_lvalue_t_tostring(lua_State *L) { - cond_lvalue_t t = lua_get_cond_lvalue_t(L, 1); + liCondLValue t = lua_get_cond_lvalue_t(L, 1); lua_pushstring(L, cond_lvalue_to_string(t)); return 1; } static int lua_cond_lvalue_t_index(lua_State *L) { - server *srv; + liServer *srv; GString *key; - cond_lvalue_t t = lua_get_cond_lvalue_t(L, 1); + liCondLValue t = lua_get_cond_lvalue_t(L, 1); - srv = (server*) lua_touserdata(L, lua_upvalueindex(1)); - if (t < COND_LVALUE_FIRST_WITH_KEY || t >= COND_LVALUE_END) return 0; + srv = (liServer*) lua_touserdata(L, lua_upvalueindex(1)); + if (t < LI_COND_LVALUE_FIRST_WITH_KEY || t >= LI_COND_LVALUE_END) return 0; if (NULL == (key = lua_togstring(L, 2))) return 0; lua_push_cond_lvalue(srv, L, condition_lvalue_new(t, key)); return 1; } -static void lua_push_cond_lvalue_t_metatable(server *srv, lua_State *L) { +static void lua_push_cond_lvalue_t_metatable(liServer *srv, lua_State *L) { if (luaL_newmetatable(L, LUA_COND_LVALUE_T)) { lua_mt_register(L, "__tostring", lua_cond_lvalue_t_tostring); lua_mt_register_srv(srv, L, "__index", lua_cond_lvalue_t_index); @@ -234,10 +234,10 @@ static void lua_push_cond_lvalue_t_metatable(server *srv, lua_State *L) { /* cond_lvalue_t */ -static int lua_push_cond_lvalue_t(server *srv, lua_State *L, cond_lvalue_t t) { - cond_lvalue_t *pt; +static int lua_push_cond_lvalue_t(liServer *srv, lua_State *L, liCondLValue t) { + liCondLValue *pt; - pt = (cond_lvalue_t*) lua_newuserdata(L, sizeof(cond_lvalue_t)); + pt = (liCondLValue*) lua_newuserdata(L, sizeof(liCondLValue)); *pt = t; lua_push_cond_lvalue_t_metatable(srv, L); @@ -249,15 +249,15 @@ static int lua_push_cond_lvalue_t(server *srv, lua_State *L, cond_lvalue_t t) { -void lua_push_lvalues_dict(server *srv, lua_State *L) { +void lua_push_lvalues_dict(liServer *srv, lua_State *L) { size_t i; - for (i = 0; i < COND_LVALUE_FIRST_WITH_KEY; i++) { + for (i = 0; i < LI_COND_LVALUE_FIRST_WITH_KEY; i++) { lua_push_cond_lvalue(srv, L, condition_lvalue_new(i, NULL)); lua_settop_in_dicts(L, cond_lvalue_to_string(i)); } - for ( ; i < COND_LVALUE_END; i++) { + for ( ; i < LI_COND_LVALUE_END; i++) { lua_push_cond_lvalue_t(srv, L, i); lua_settop_in_dicts(L, cond_lvalue_to_string(i)); } diff --git a/src/config_lua.c b/src/config_lua.c index 103bcf8..d0c5976 100644 --- a/src/config_lua.c +++ b/src/config_lua.c @@ -7,10 +7,10 @@ #include #include -typedef int (*LuaWrapper)(server *srv, lua_State *L, gpointer data); +typedef int (*LuaWrapper)(liServer *srv, lua_State *L, gpointer data); -static value* lua_params_to_value(server *srv, lua_State *L) { - value *val, *subval; +static liValue* lua_params_to_value(liServer *srv, lua_State *L) { + liValue *val, *subval; switch (lua_gettop(L)) { case 0: case 1: @@ -26,7 +26,7 @@ static value* lua_params_to_value(server *srv, lua_State *L) { value_free(val); return NULL; } - g_array_index(val->data.list, value*, lua_gettop(L) - 1) = subval; + g_array_index(val->data.list, liValue*, lua_gettop(L) - 1) = subval; } return val; } @@ -34,14 +34,14 @@ static value* lua_params_to_value(server *srv, lua_State *L) { } /* Creates a table on the lua stack */ -static void lua_push_publish_hash_metatable(server *srv, lua_State *L); +static void lua_push_publish_hash_metatable(liServer *srv, lua_State *L); static int lua_str_hash_index(lua_State *L) { - server *srv; + liServer *srv; GHashTable *ht; LuaWrapper wrapper; - srv = (server*) lua_touserdata(L, lua_upvalueindex(1)); + srv = (liServer*) lua_touserdata(L, lua_upvalueindex(1)); lua_pushstring(L, "__ht"); lua_rawget(L, 1); ht = (GHashTable*) lua_touserdata(L, -1); lua_pop(L, 1); lua_pushstring(L, "__wrapper"); lua_rawget(L, 1); @@ -78,13 +78,13 @@ static int lua_str_hash_index(lua_State *L) { } static int lua_str_hash_call(lua_State *L) { - server *srv; + liServer *srv; GHashTable *ht; LuaWrapper wrapper; const char *key; gpointer d; - srv = (server*) lua_touserdata(L, lua_upvalueindex(1)); + srv = (liServer*) lua_touserdata(L, lua_upvalueindex(1)); lua_pushstring(L, "__ht"); lua_rawget(L, 1); ht = (GHashTable*) lua_touserdata(L, -1); lua_pop(L, 1); lua_pushstring(L, "__wrapper"); lua_rawget(L, 1); @@ -106,7 +106,7 @@ static int lua_str_hash_call(lua_State *L) { } #define LUA_PUBLISH_HASH "GHashTable*" -static void lua_push_publish_hash_metatable(server *srv, lua_State *L) { +static void lua_push_publish_hash_metatable(liServer *srv, lua_State *L) { if (luaL_newmetatable(L, LUA_PUBLISH_HASH)) { lua_pushlightuserdata(L, srv); lua_pushcclosure(L, lua_str_hash_index, 1); @@ -118,7 +118,7 @@ static void lua_push_publish_hash_metatable(server *srv, lua_State *L) { } } -static gboolean publish_str_hash(server *srv, lua_State *L, GHashTable *ht, LuaWrapper wrapper) { +static gboolean publish_str_hash(liServer *srv, lua_State *L, GHashTable *ht, LuaWrapper wrapper) { lua_newtable(L); /* { } */ lua_pushlightuserdata(L, ht); lua_setfield(L, -2, "__ht"); @@ -131,10 +131,10 @@ static gboolean publish_str_hash(server *srv, lua_State *L, GHashTable *ht, LuaW } -static int handle_server_action(server *srv, lua_State *L, gpointer _sa) { - server_action *sa = (server_action*) _sa; - value *val; - action *a; +static int handle_server_action(liServer *srv, lua_State *L, gpointer _sa) { + liServerAction *sa = (liServerAction*) _sa; + liValue *val; + liAction *a; lua_checkstack(L, 16); val = lua_params_to_value(srv, L); @@ -151,9 +151,9 @@ static int handle_server_action(server *srv, lua_State *L, gpointer _sa) { return lua_push_action(srv, L, a); } -static int handle_server_setup(server *srv, lua_State *L, gpointer _ss) { - server_setup *ss = (server_setup*) _ss; - value *val; +static int handle_server_setup(liServer *srv, lua_State *L, gpointer _ss) { + liServerSetup *ss = (liServerSetup*) _ss; + liValue *val; lua_checkstack(L, 16); val = lua_params_to_value(srv, L); @@ -170,7 +170,7 @@ static int handle_server_setup(server *srv, lua_State *L, gpointer _ss) { return 0; } -gboolean config_lua_load(server *srv, const gchar *filename) { +gboolean config_lua_load(liServer *srv, const gchar *filename) { lua_State *L; L = luaL_newstate(); diff --git a/src/config_parser.rl b/src/config_parser.rl index 86b99e4..1e7b5a8 100644 --- a/src/config_parser.rl +++ b/src/config_parser.rl @@ -35,7 +35,7 @@ # basic types action boolean { - value *o; + liValue *o; o = value_new_bool(*ctx->mark == 't' ? TRUE : FALSE); g_queue_push_head(ctx->option_stack, o); @@ -44,7 +44,7 @@ } action integer { - value *o; + liValue *o; gint64 i = 0; for (gchar *c = ctx->mark; c < fpc; c++) @@ -58,7 +58,7 @@ } action integer_suffix { - value *o; + liValue *o; GString *str; o = g_queue_peek_head(ctx->option_stack); @@ -85,7 +85,7 @@ } action string { - value *o; + liValue *o; GString *str; gchar ch; @@ -149,7 +149,7 @@ # advanced types action list_start { - value *o; + liValue *o; /* create new list value and put it on stack, list entries are put in it by getting the previous value from the stack */ o = value_new_list(); @@ -159,13 +159,13 @@ } action list_push { - value *o, *l; + liValue *o, *l; /* pop current value from stack and append it to the new top of the stack value (the list) */ o = g_queue_pop_head(ctx->option_stack); l = g_queue_peek_head(ctx->option_stack); - assert(l->type == VALUE_LIST); + assert(l->type == LI_VALUE_LIST); g_array_append_val(l->data.list, o); @@ -177,7 +177,7 @@ } action hash_start { - value *o; + liValue *o; /* create new hash value and put it on stack, if a key-value pair is encountered, get it by walking 2 steps back the stack */ o = value_new_hash(); @@ -187,7 +187,7 @@ } action hash_push { - value *k, *v, *h; /* key value hashtable */ + liValue *k, *v, *h; /* key value hashtable */ GString *str; v = g_queue_pop_head(ctx->option_stack); @@ -223,7 +223,7 @@ } action keyvalue_end { - value *k, *v, *l; + liValue *k, *v, *l; /* we have a key and a value on the stack; convert them to a list with 2 elements */ v = g_queue_pop_head(ctx->option_stack); @@ -244,20 +244,20 @@ fret; } - action value { - value *o; + action liValue { + liValue *o; o = g_queue_peek_head(ctx->option_stack); /* check if we need to cast the value */ - if (ctx->cast != CFG_PARSER_CAST_NONE) { - if (ctx->cast == CFG_PARSER_CAST_INT) { + if (ctx->cast != LI_CFG_PARSER_CAST_NONE) { + if (ctx->cast == LI_CFG_PARSER_CAST_INT) { /* cast string to integer */ gint x = 0; guint i = 0; gboolean negative = FALSE; - if (o->type != VALUE_STRING) { + if (o->type != LI_VALUE_STRING) { ERROR(srv, "can only cast strings to integers, %s given", value_type_string(o->type)); return FALSE; } @@ -281,13 +281,13 @@ g_string_free(o->data.string, TRUE); o->data.number = x; - o->type = VALUE_NUMBER; + o->type = LI_VALUE_NUMBER; } - else if (ctx->cast == CFG_PARSER_CAST_STR) { + else if (ctx->cast == LI_CFG_PARSER_CAST_STR) { /* cast integer to string */ GString *str; - if (o->type != VALUE_NUMBER) { + if (o->type != LI_VALUE_NUMBER) { ERROR(srv, "can only cast integers to strings, %s given", value_type_string(o->type)); return FALSE; } @@ -295,10 +295,10 @@ str = g_string_sized_new(0); g_string_printf(str, "%" G_GINT64_FORMAT, o->data.number); o->data.string = str; - o->type = VALUE_STRING; + o->type = LI_VALUE_STRING; } - ctx->cast = CFG_PARSER_CAST_NONE; + ctx->cast = LI_CFG_PARSER_CAST_NONE; } _printf("value (%s) in line %zd\n", value_type_string(o->type), ctx->line); @@ -319,7 +319,7 @@ action value_statement { /* value (+|-|*|/) value */ /* compute new value out of the two */ - value *l, *r, *o; + liValue *l, *r, *o; gboolean free_l, free_r; free_l = free_r = TRUE; @@ -337,7 +337,7 @@ g_array_append_val(o->data.list, l); g_array_append_val(o->data.list, r); } - else if (l->type == VALUE_NUMBER && r->type == VALUE_NUMBER) { + else if (l->type == LI_VALUE_NUMBER && r->type == LI_VALUE_NUMBER) { switch (ctx->value_op) { case '+': o = value_new_number(l->data.number + r->data.number); break; case '-': o = value_new_number(l->data.number - r->data.number); break; @@ -345,19 +345,19 @@ case '/': o = value_new_number(l->data.number / r->data.number); break; } } - else if (l->type == VALUE_STRING) { + else if (l->type == LI_VALUE_STRING) { o = l; free_l = FALSE; - if (r->type == VALUE_STRING && ctx->value_op == '+') { + if (r->type == LI_VALUE_STRING && ctx->value_op == '+') { /* str + str */ o->data.string = g_string_append_len(o->data.string, GSTR_LEN(r->data.string)); } - else if (r->type == VALUE_NUMBER && ctx->value_op == '+') { + else if (r->type == LI_VALUE_NUMBER && ctx->value_op == '+') { /* str + int */ g_string_append_printf(o->data.string, "%" G_GINT64_FORMAT, r->data.number); } - else if (r->type == VALUE_NUMBER && ctx->value_op == '*') { + else if (r->type == LI_VALUE_NUMBER && ctx->value_op == '*') { /* str * int */ if (r->data.number < 0) { ERROR(srv, "string multiplication with negative number (%" G_GINT64_FORMAT ")?", r->data.number); @@ -377,7 +377,7 @@ else o = NULL; } - else if (l->type == VALUE_LIST) { + else if (l->type == LI_VALUE_LIST) { if (ctx->value_op == '+') { /* append r to the end of l */ free_l = FALSE; /* use l as the new o */ @@ -388,7 +388,7 @@ } else if (ctx->value_op == '*') { /* merge l and r */ - if (r->type == VALUE_LIST) { + if (r->type == LI_VALUE_LIST) { /* merge lists */ free_l = FALSE; g_array_append_vals(l->data.list, r->data.list->data, r->data.list->len); @@ -397,7 +397,7 @@ } } } - else if (l->type == VALUE_HASH && r->type == VALUE_HASH && ctx->value_op == '+') { + else if (l->type == LI_VALUE_HASH && r->type == LI_VALUE_HASH && ctx->value_op == '+') { /* merge hashtables */ GHashTableIter iter; gpointer key, val; @@ -436,7 +436,7 @@ action varname { /* varname, push it as string value onto the stack */ - value *o; + liValue *o; GString *str; str = g_string_new_len(ctx->mark, fpc - ctx->mark); @@ -446,7 +446,7 @@ action actionref { /* varname is on the stack */ - value *o, *r, *t; + liValue *o, *r, *t; o = g_queue_pop_head(ctx->option_stack); @@ -478,7 +478,7 @@ } else { /* real action, lookup hashtable and create new action value */ - action *a; + liAction *a; a = g_hash_table_lookup(ctx->action_blocks, o->data.string); if (a == NULL) { @@ -497,34 +497,34 @@ action operator { if ((fpc - ctx->mark) == 1) { switch (*ctx->mark) { - case '<': ctx->op = CONFIG_COND_LT; break; - case '>': ctx->op = CONFIG_COND_GT; break; + case '<': ctx->op = LI_CONFIG_COND_LT; break; + case '>': ctx->op = LI_CONFIG_COND_GT; break; } } else { - if (*ctx->mark == '>' && *(ctx->mark+1) == '=') ctx->op = CONFIG_COND_GE; - else if (*ctx->mark == '<' && *(ctx->mark+1) == '=') ctx->op = CONFIG_COND_LE; - else if (*ctx->mark == '=' && *(ctx->mark+1) == '=') ctx->op = CONFIG_COND_EQ; - else if (*ctx->mark == '!' && *(ctx->mark+1) == '=') ctx->op = CONFIG_COND_NE; - else if (*ctx->mark == '=' && *(ctx->mark+1) == '^') ctx->op = CONFIG_COND_PREFIX; - else if (*ctx->mark == '!' && *(ctx->mark+1) == '^') ctx->op = CONFIG_COND_NOPREFIX; - else if (*ctx->mark == '=' && *(ctx->mark+1) == '$') ctx->op = CONFIG_COND_SUFFIX; - else if (*ctx->mark == '!' && *(ctx->mark+1) == '$') ctx->op = CONFIG_COND_NOSUFFIX; - else if (*ctx->mark == '=' && *(ctx->mark+1) == '~') ctx->op = CONFIG_COND_MATCH; - else if (*ctx->mark == '!' && *(ctx->mark+1) == '~') ctx->op = CONFIG_COND_NOMATCH; + if (*ctx->mark == '>' && *(ctx->mark+1) == '=') ctx->op = LI_CONFIG_COND_GE; + else if (*ctx->mark == '<' && *(ctx->mark+1) == '=') ctx->op = LI_CONFIG_COND_LE; + else if (*ctx->mark == '=' && *(ctx->mark+1) == '=') ctx->op = LI_CONFIG_COND_EQ; + else if (*ctx->mark == '!' && *(ctx->mark+1) == '=') ctx->op = LI_CONFIG_COND_NE; + else if (*ctx->mark == '=' && *(ctx->mark+1) == '^') ctx->op = LI_CONFIG_COND_PREFIX; + else if (*ctx->mark == '!' && *(ctx->mark+1) == '^') ctx->op = LI_CONFIG_COND_NOPREFIX; + else if (*ctx->mark == '=' && *(ctx->mark+1) == '$') ctx->op = LI_CONFIG_COND_SUFFIX; + else if (*ctx->mark == '!' && *(ctx->mark+1) == '$') ctx->op = LI_CONFIG_COND_NOSUFFIX; + else if (*ctx->mark == '=' && *(ctx->mark+1) == '~') ctx->op = LI_CONFIG_COND_MATCH; + else if (*ctx->mark == '!' && *(ctx->mark+1) == '~') ctx->op = LI_CONFIG_COND_NOMATCH; } } # statements action assignment { - value *val, *name; - action *a, *al; + liValue *val, *name; + liAction *a, *al; /* top of the stack is the value, then the varname as string value */ val = g_queue_pop_head(ctx->option_stack); name = g_queue_pop_head(ctx->option_stack); - assert(name->type == VALUE_STRING); + assert(name->type == LI_VALUE_STRING); _printf("got assignment: %s = %s; in line %zd\n", name->data.string->str, value_type_string(val->type), ctx->line); @@ -573,12 +573,12 @@ } action function_noparam { - value *name; - action *a, *al; + liValue *name; + liAction *a, *al; name = g_queue_pop_head(ctx->option_stack); - assert(name->type == VALUE_STRING); + assert(name->type == LI_VALUE_STRING); _printf("got function: %s; in line %zd\n", name->data.string->str, ctx->line); @@ -612,19 +612,19 @@ action function_param { /* similar to assignment */ - value *val, *name; - action *a, *al; + liValue *val, *name; + liAction *a, *al; /* top of the stack is the value, then the varname as string value */ val = g_queue_pop_head(ctx->option_stack); name = g_queue_pop_head(ctx->option_stack); - assert(name->type == VALUE_STRING); + assert(name->type == LI_VALUE_STRING); _printf("got function: %s %s; in line %zd\n", name->data.string->str, value_type_string(val->type), ctx->line); if (g_str_equal(name->data.string->str, "include")) { - if (val->type != VALUE_STRING) { + if (val->type != LI_VALUE_STRING) { WARNING(srv, "include directive takes a string as parameter, %s given", value_type_string(val->type)); value_free(name); value_free(val); @@ -640,7 +640,7 @@ value_free(val); } else if (g_str_equal(name->data.string->str, "include_shell")) { - if (val->type != VALUE_STRING) { + if (val->type != LI_VALUE_STRING) { WARNING(srv, "include_shell directive takes a string as parameter, %s given", value_type_string(val->type)); value_free(name); value_free(val); @@ -695,10 +695,10 @@ action condition_start { /* stack: value, varname OR value, key, varname */ - value *v, *n, *k; + liValue *v, *n, *k; gchar *str; - condition *cond; - condition_lvalue *lvalue; + liCondition *cond; + liConditionLValue *lvalue; /* if condition is nonbool, then it has a value and maybe a key too on the stack */ if (ctx->condition_nonbool) { @@ -714,7 +714,7 @@ n = g_queue_pop_head(ctx->option_stack); - assert(n->type == VALUE_STRING); + assert(n->type == LI_VALUE_STRING); /*_printf("got condition: %s:%s %s %s in line %zd\n", n->data.string->str, ctx->condition_with_key ? k->data.string->str : "", comp_op_to_string(ctx->op), value_type_string(v->type), ctx->line);*/ @@ -733,21 +733,21 @@ } if (g_str_equal(str, "host")) - lvalue = condition_lvalue_new(COMP_REQUEST_HOST, NULL); + lvalue = condition_lvalue_new(LI_COMP_REQUEST_HOST, NULL); else if (g_str_equal(str, "path")) - lvalue = condition_lvalue_new(COMP_REQUEST_PATH, NULL); + lvalue = condition_lvalue_new(LI_COMP_REQUEST_PATH, NULL); else if (g_str_equal(str, "query")) - lvalue = condition_lvalue_new(COMP_REQUEST_QUERY_STRING, NULL); + lvalue = condition_lvalue_new(LI_COMP_REQUEST_QUERY_STRING, NULL); else if (g_str_equal(str, "method")) - lvalue = condition_lvalue_new(COMP_REQUEST_METHOD, NULL); + lvalue = condition_lvalue_new(LI_COMP_REQUEST_METHOD, NULL); else if (g_str_equal(str, "scheme")) - lvalue = condition_lvalue_new(COMP_REQUEST_SCHEME, NULL); + lvalue = condition_lvalue_new(LI_COMP_REQUEST_SCHEME, NULL); else if (g_str_equal(str, "header")) { if (k == NULL) { WARNING(srv, "%s", "header conditional needs a key"); return FALSE; } - lvalue = condition_lvalue_new(COMP_REQUEST_HEADER, value_extract(k).string); + lvalue = condition_lvalue_new(LI_COMP_REQUEST_HEADER, value_extract(k).string); } else { WARNING(srv, "unkown lvalue for condition: %s", n->data.string->str); @@ -766,15 +766,15 @@ } if (g_str_equal(str, "path")) - lvalue = condition_lvalue_new(COMP_PHYSICAL_PATH, NULL); + lvalue = condition_lvalue_new(LI_COMP_PHYSICAL_PATH, NULL); else if (g_str_equal(str, "exists")) - lvalue = condition_lvalue_new(COMP_PHYSICAL_PATH_EXISTS, NULL); + lvalue = condition_lvalue_new(LI_COMP_PHYSICAL_PATH_EXISTS, NULL); else if (g_str_equal(str, "size")) - lvalue = condition_lvalue_new(COMP_PHYSICAL_SIZE, NULL); + lvalue = condition_lvalue_new(LI_COMP_PHYSICAL_SIZE, NULL); else if (g_str_equal(str, "is_dir")) - lvalue = condition_lvalue_new(COMP_PHYSICAL_ISDIR, NULL); + lvalue = condition_lvalue_new(LI_COMP_PHYSICAL_ISDIR, NULL); else if (g_str_equal(str, "is_file")) - lvalue = condition_lvalue_new(COMP_PHYSICAL_ISFILE, NULL); + lvalue = condition_lvalue_new(LI_COMP_PHYSICAL_ISFILE, NULL); else { WARNING(srv, "unkown lvalue for condition: %s", n->data.string->str); return FALSE; @@ -786,10 +786,10 @@ } if (ctx->condition_nonbool) { - if (v->type == VALUE_STRING) { + if (v->type == LI_VALUE_STRING) { cond = condition_new_string(srv, ctx->op, lvalue, value_extract(v).string); } - else if (v->type == VALUE_NUMBER) + else if (v->type == LI_VALUE_NUMBER) cond = condition_new_int(srv, ctx->op, lvalue, value_extract_number(v)); else { cond = NULL; @@ -820,8 +820,8 @@ } action condition_end { - condition *cond; - action *a, *al; + liCondition *cond; + liAction *a, *al; cond = g_queue_pop_head(ctx->condition_stack); al = g_queue_pop_head(ctx->action_list_stack); @@ -849,11 +849,11 @@ - get last action from action list - put current action list as target_else of the last action */ - action *al, *target, *cond; + liAction *al, *target, *cond; target = g_queue_pop_head(ctx->action_list_stack); al = g_queue_peek_head(ctx->action_list_stack); - cond = g_array_index(al->data.list, action*, al->data.list->len - 1); /* last action in the list is our condition */ + cond = g_array_index(al->data.list, liAction*, al->data.list->len - 1); /* last action in the list is our condition */ while (cond->data.condition.target_else) { /* condition has already an else statement, try the target */ @@ -874,11 +874,11 @@ - remove current condition action from action list */ - action *prev, *cur, *al; + liAction *prev, *cur, *al; al = g_queue_peek_head(ctx->action_list_stack); - cur = g_array_index(al->data.list, action*, al->data.list->len - 1); /* last element of the action list */ - prev = g_array_index(al->data.list, action*, al->data.list->len - 2); + cur = g_array_index(al->data.list, liAction*, al->data.list->len - 1); /* last element of the action list */ + prev = g_array_index(al->data.list, liAction*, al->data.list->len - 2); assert(cur->type == ACTION_TCONDITION); assert(prev->type == ACTION_TCONDITION); @@ -895,11 +895,11 @@ } action action_block_start { - value *o; - action *al; + liValue *o; + liAction *al; o = g_queue_pop_head(ctx->option_stack); - assert(o->type == VALUE_STRING); + assert(o->type == LI_VALUE_STRING); if (ctx->in_setup_block) { ERROR(srv, "%s", "no block inside the setup block allowed"); @@ -931,7 +931,7 @@ ctx->in_setup_block = FALSE; } else { - action *al; + liAction *al; /* pop action list stack */ al = g_queue_pop_head(ctx->action_list_stack); @@ -939,7 +939,7 @@ } action action_block_noname_start { - action *al; + liAction *al; if (ctx->in_setup_block) { ERROR(srv, "%s", "no block inside the setup block allowed"); @@ -954,8 +954,8 @@ } action action_block_noname_end { - value *v; - action *a; + liValue *v; + liAction *a; /* pop action list stack */ a = g_queue_pop_head(ctx->action_list_stack); @@ -992,7 +992,7 @@ string = ( '"' ( ( any - ["\\] ) | escaped_hex | ( '\\' ( any - [x]) ) )* '"' ) %string; # casts - cast = ( 'cast(' ( 'int' %{ctx->cast = CFG_PARSER_CAST_INT;} | 'str' %{ctx->cast = CFG_PARSER_CAST_STR;} ) ')' ws* ); + cast = ( 'cast(' ( 'int' %{ctx->cast = LI_CFG_PARSER_CAST_INT;} | 'str' %{ctx->cast = LI_CFG_PARSER_CAST_STR;} ) ')' ws* ); keywords = ( 'true' | 'false' | 'if' | 'else' ); @@ -1005,7 +1005,7 @@ action_block = ( varname noise* block >action_block_start ) %action_block_end; action_block_noname = ( '$' block > action_block_noname_start ) %action_block_noname_end; - value = ( ( boolean | integer | string | list | hash | actionref | action_block_noname ) >mark ) %value; + value = ( ( boolean | integer | string | list | hash | actionref | action_block_noname ) >mark ) %liValue; value_statement_op = ( '+' | '-' | '*' | '/' | '=>' ) >mark >value_statement_op; value_statement = ( noise* cast? value (ws* value_statement_op ws* cast? value %value_statement)* noise* ); hash_elem = ( noise* string >mark noise* ':' value_statement ); @@ -1036,8 +1036,8 @@ %% write data; -GList *config_parser_init(server* srv) { - config_parser_context_t *ctx = config_parser_context_new(srv, NULL); +GList *config_parser_init(liServer* srv) { + liConfigParserContext *ctx = config_parser_context_new(srv, NULL); srv->mainaction = action_new_list(); g_queue_push_head(ctx->action_list_stack, srv->mainaction); @@ -1045,8 +1045,8 @@ GList *config_parser_init(server* srv) { return g_list_append(NULL, ctx); } -void config_parser_finish(server *srv, GList *ctx_stack, gboolean free_all) { - config_parser_context_t *ctx; +void config_parser_finish(liServer *srv, GList *ctx_stack, gboolean free_all) { + liConfigParserContext *ctx; GHashTableIter iter; gpointer key, val; GList *l; @@ -1062,7 +1062,7 @@ void config_parser_finish(server *srv, GList *ctx_stack, gboolean free_all) { } if (free_all) { - ctx = (config_parser_context_t*) ctx_stack->data; + ctx = (liConfigParserContext*) ctx_stack->data; g_hash_table_iter_init(&iter, ctx->action_blocks); @@ -1090,12 +1090,12 @@ void config_parser_finish(server *srv, GList *ctx_stack, gboolean free_all) { } } -config_parser_context_t *config_parser_context_new(server *srv, GList *ctx_stack) { - config_parser_context_t *ctx; +liConfigParserContext *config_parser_context_new(liServer *srv, GList *ctx_stack) { + liConfigParserContext *ctx; UNUSED(srv); - ctx = g_slice_new0(config_parser_context_t); + ctx = g_slice_new0(liConfigParserContext); ctx->line = 1; @@ -1105,16 +1105,16 @@ config_parser_context_t *config_parser_context_new(server *srv, GList *ctx_stack if (ctx_stack != NULL) { /* inherit old stacks */ - ctx->action_list_stack = ((config_parser_context_t*) ctx_stack->data)->action_list_stack; - ctx->option_stack = ((config_parser_context_t*) ctx_stack->data)->option_stack; - ctx->condition_stack = ((config_parser_context_t*) ctx_stack->data)->condition_stack; + ctx->action_list_stack = ((liConfigParserContext*) ctx_stack->data)->action_list_stack; + ctx->option_stack = ((liConfigParserContext*) ctx_stack->data)->option_stack; + ctx->condition_stack = ((liConfigParserContext*) ctx_stack->data)->condition_stack; - ctx->action_blocks = ((config_parser_context_t*) ctx_stack->data)->action_blocks; - ctx->uservars = ((config_parser_context_t*) ctx_stack->data)->uservars; + ctx->action_blocks = ((liConfigParserContext*) ctx_stack->data)->action_blocks; + ctx->uservars = ((liConfigParserContext*) ctx_stack->data)->uservars; } else { GString *str; - value *o; + liValue *o; ctx->action_blocks = g_hash_table_new_full((GHashFunc) g_string_hash, (GEqualFunc) g_string_equal, NULL, NULL); ctx->uservars = g_hash_table_new_full((GHashFunc) g_string_hash, (GEqualFunc) g_string_equal, NULL, NULL); @@ -1143,19 +1143,19 @@ config_parser_context_t *config_parser_context_new(server *srv, GList *ctx_stack return ctx; } -void config_parser_context_free(server *srv, config_parser_context_t *ctx, gboolean free_queues) +void config_parser_context_free(liServer *srv, liConfigParserContext *ctx, gboolean free_queues) { g_free(ctx->stack); if (free_queues) { if (g_queue_get_length(ctx->option_stack) > 0) { - value *o; + liValue *o; while ((o = g_queue_pop_head(ctx->option_stack))) value_free(o); } if (g_queue_get_length(ctx->condition_stack) > 0) { - condition *c; + liCondition *c; while ((c = g_queue_pop_head(ctx->condition_stack))) condition_release(srv, c); } @@ -1165,11 +1165,11 @@ void config_parser_context_free(server *srv, config_parser_context_t *ctx, gbool g_queue_free(ctx->condition_stack); } - g_slice_free(config_parser_context_t, ctx); + g_slice_free(liConfigParserContext, ctx); } -gboolean config_parser_file(server *srv, GList *ctx_stack, const gchar *path) { - config_parser_context_t *ctx; +gboolean config_parser_file(liServer *srv, GList *ctx_stack, const gchar *path) { + liConfigParserContext *ctx; gboolean res; GError *err = NULL; @@ -1203,13 +1203,13 @@ gboolean config_parser_file(server *srv, GList *ctx_stack, const gchar *path) { return res; } -gboolean config_parser_shell(server *srv, GList *ctx_stack, const gchar *command) +gboolean config_parser_shell(liServer *srv, GList *ctx_stack, const gchar *command) { gboolean res; gchar* _stdout; gchar* _stderr; gint status; - config_parser_context_t *ctx; + liConfigParserContext *ctx; GError *err = NULL; ctx = config_parser_context_new(srv, ctx_stack); @@ -1252,12 +1252,12 @@ gboolean config_parser_shell(server *srv, GList *ctx_stack, const gchar *command return res; } -gboolean config_parser_buffer(server *srv, GList *ctx_stack) +gboolean config_parser_buffer(liServer *srv, GList *ctx_stack) { - config_parser_context_t *ctx; + liConfigParserContext *ctx; /* get top of stack */ - ctx = (config_parser_context_t*) ctx_stack->data; + ctx = (liConfigParserContext*) ctx_stack->data; ctx->p = ctx->ptr; ctx->pe = ctx->ptr + ctx->len + 1; /* marks the end of the data to scan (+1 because of trailing \0 char) */ diff --git a/src/connection.c b/src/connection.c index c5fe65f..301574f 100644 --- a/src/connection.c +++ b/src/connection.c @@ -3,10 +3,10 @@ #include /* only call it from the worker context the con belongs to */ -void worker_con_put(connection *con); /* worker.c */ +void worker_con_put(liConnection *con); /* worker.c */ -static void parse_request_body(connection *con) { - if ((con->state > CON_STATE_HANDLE_MAINVR || con->mainvr->state >= VRS_READ_CONTENT) && !con->in->is_closed) { +static void parse_request_body(liConnection *con) { + if ((con->state > LI_CON_STATE_HANDLE_MAINVR || con->mainvr->state >= LI_VRS_READ_CONTENT) && !con->in->is_closed) { ev_io_add_events(con->wrk->loop, &con->sock_watcher, EV_READ); if (con->mainvr->request.content_length == -1) { /* TODO: parse chunked encoded request body, filters */ @@ -26,18 +26,18 @@ static void parse_request_body(connection *con) { } } -static void forward_response_body(connection *con) { - vrequest *vr = con->mainvr; - if (con->state >= CON_STATE_HANDLE_MAINVR) { +static void forward_response_body(liConnection *con) { + liVRequest *vr = con->mainvr; + if (con->state >= LI_CON_STATE_HANDLE_MAINVR) { if (!con->response_headers_sent) { con->response_headers_sent = TRUE; - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "write response headers"); } response_send_headers(con); } - if (vr->response.transfer_encoding & HTTP_TRANSFER_ENCODING_CHUNKED) { + if (vr->response.transfer_encoding & LI_HTTP_TRANSFER_ENCODING_CHUNKED) { filter_chunked_encode(con, con->raw_out, con->out); } else { chunkqueue_steal_all(con->raw_out, con->out); @@ -53,22 +53,22 @@ static void forward_response_body(connection *con) { } } -static void connection_request_done(connection *con) { - vrequest *vr = con->mainvr; - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { +static void connection_request_done(liConnection *con) { + liVRequest *vr = con->mainvr; + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(con->mainvr, "response end (keep_alive = %i)", con->keep_alive); } plugins_handle_close(con); - if (con->keep_alive && g_atomic_int_get(&con->srv->state) == SERVER_RUNNING) { + if (con->keep_alive && g_atomic_int_get(&con->srv->state) == LI_SERVER_RUNNING) { connection_reset_keep_alive(con); } else { worker_con_put(con); } } -static gboolean check_response_done(connection *con) { +static gboolean check_response_done(liConnection *con) { if (con->in->is_closed && con->raw_out->is_closed && 0 == con->raw_out->length) { connection_request_done(con); return TRUE; @@ -76,9 +76,9 @@ static gboolean check_response_done(connection *con) { return FALSE; } -static void connection_close(connection *con) { - vrequest *vr = con->mainvr; - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { +static void connection_close(liConnection *con) { + liVRequest *vr = con->mainvr; + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "connection closed"); } @@ -87,9 +87,9 @@ static void connection_close(connection *con) { worker_con_put(con); } -void connection_error(connection *con) { - vrequest *vr = con->mainvr; - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { +void connection_error(liConnection *con) { + liVRequest *vr = con->mainvr; + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "connection closed (error)"); } @@ -98,13 +98,13 @@ void connection_error(connection *con) { worker_con_put(con); } -void connection_internal_error(connection *con) { - vrequest *vr = con->mainvr; +void connection_internal_error(liConnection *con) { + liVRequest *vr = con->mainvr; if (con->response_headers_sent) { VR_ERROR(vr, "%s", "Couldn't send '500 Internal Error': headers already sent"); connection_error(con); } else { - http_version_t v; + liHttpVersion v; VR_ERROR(vr, "%s", "internal error"); /* We only need the http version from the http request */ @@ -114,7 +114,7 @@ void connection_internal_error(connection *con) { con->keep_alive = FALSE; con->mainvr->response.http_status = 500; - con->state = CON_STATE_WRITE; /* skips further vrequest handling */ + con->state = LI_CON_STATE_WRITE; /* skips further vrequest handling */ chunkqueue_reset(con->out); con->out->is_closed = TRUE; @@ -123,12 +123,12 @@ void connection_internal_error(connection *con) { } } -static gboolean connection_handle_read(connection *con) { - vrequest *vr = con->mainvr; +static gboolean connection_handle_read(liConnection *con) { + liVRequest *vr = con->mainvr; if (con->raw_in->length == 0) return TRUE; - if (con->state == CON_STATE_KEEP_ALIVE) { + if (con->state == LI_CON_STATE_KEEP_ALIVE) { /* stop keep alive timeout watchers */ if (con->keep_alive_data.link) { g_queue_delete_link(&con->wrk->keep_alive_queue, con->keep_alive_data.link); @@ -139,28 +139,28 @@ static gboolean connection_handle_read(connection *con) { con->keep_alive_requests++; /* disable keep alive if limit is reached */ - if (con->keep_alive_requests == CORE_OPTION(CORE_OPTION_MAX_KEEP_ALIVE_REQUESTS).number) + if (con->keep_alive_requests == CORE_OPTION(LI_CORE_OPTION_MAX_KEEP_ALIVE_REQUESTS).number) con->keep_alive = FALSE; - con->state = CON_STATE_READ_REQUEST_HEADER; + con->state = LI_CON_STATE_READ_REQUEST_HEADER; con->ts = CUR_TS(con->wrk); } else { - if (con->state == CON_STATE_REQUEST_START) - con->state = CON_STATE_READ_REQUEST_HEADER; + if (con->state == LI_CON_STATE_REQUEST_START) + con->state = LI_CON_STATE_READ_REQUEST_HEADER; } - if (con->state == CON_STATE_READ_REQUEST_HEADER && con->mainvr->state == VRS_CLEAN) { - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + if (con->state == LI_CON_STATE_READ_REQUEST_HEADER && con->mainvr->state == LI_VRS_CLEAN) { + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "reading request header"); } switch(http_request_parse(con->mainvr, &con->req_parser_ctx)) { - case HANDLER_GO_ON: + case LI_HANDLER_GO_ON: break; /* go on */ - case HANDLER_WAIT_FOR_EVENT: + case LI_HANDLER_WAIT_FOR_EVENT: return TRUE; - case HANDLER_ERROR: - case HANDLER_COMEBACK: /* unexpected */ + case LI_HANDLER_ERROR: + case LI_HANDLER_COMEBACK: /* unexpected */ /* unparsable header */ connection_error(con); return FALSE; @@ -169,12 +169,12 @@ static gboolean connection_handle_read(connection *con) { con->wrk->stats.requests++; /* headers ready */ - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "validating request header"); } if (!request_validate_header(con)) { /* skip mainvr handling */ - con->state = CON_STATE_WRITE; + con->state = LI_CON_STATE_WRITE; con->keep_alive = FALSE; con->in->is_closed = TRUE; forward_response_body(con); @@ -185,7 +185,7 @@ static gboolean connection_handle_read(connection *con) { * before sending it to a backend - so just send the stupid header */ if (con->expect_100_cont) { - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "send 100 Continue"); } chunkqueue_append_mem(con->raw_out, CONST_STR_LEN("HTTP/1.1 100 Continue\r\n\r\n")); @@ -193,7 +193,7 @@ static gboolean connection_handle_read(connection *con) { ev_io_add_events(con->wrk->loop, &con->sock_watcher, EV_WRITE); } - con->state = CON_STATE_HANDLE_MAINVR; + con->state = LI_CON_STATE_HANDLE_MAINVR; action_enter(con->mainvr, con->srv->mainaction); vrequest_handle_request_headers(con->mainvr); } @@ -205,10 +205,10 @@ static gboolean connection_handle_read(connection *con) { } static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) { - network_status_t res; + liNetworkStatus res; goffset write_max; goffset transferred; - connection *con = (connection*) w->data; + liConnection *con = (liConnection*) w->data; if (revents & EV_READ) { if (con->in->is_closed) { @@ -224,21 +224,21 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) { con->stats.bytes_in += transferred; switch (res) { - case NETWORK_STATUS_SUCCESS: + case LI_NETWORK_STATUS_SUCCESS: if (!connection_handle_read(con)) return; break; - case NETWORK_STATUS_FATAL_ERROR: + case LI_NETWORK_STATUS_FATAL_ERROR: _ERROR(con->srv, con->mainvr, "%s", "network read fatal error"); connection_error(con); return; - case NETWORK_STATUS_CONNECTION_CLOSE: + case LI_NETWORK_STATUS_CONNECTION_CLOSE: con->raw_in->is_closed = TRUE; shutdown(w->fd, SHUT_RD); connection_close(con); return; - case NETWORK_STATUS_WAIT_FOR_EVENT: + case LI_NETWORK_STATUS_WAIT_FOR_EVENT: break; - case NETWORK_STATUS_WAIT_FOR_AIO_EVENT: + case LI_NETWORK_STATUS_WAIT_FOR_AIO_EVENT: /* TODO: aio */ ev_io_rem_events(loop, w, EV_READ); break; @@ -264,19 +264,19 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) { con->stats.bytes_out += transferred; switch (res) { - case NETWORK_STATUS_SUCCESS: + case LI_NETWORK_STATUS_SUCCESS: vrequest_joblist_append(con->mainvr); break; - case NETWORK_STATUS_FATAL_ERROR: + case LI_NETWORK_STATUS_FATAL_ERROR: _ERROR(con->srv, con->mainvr, "%s", "network write fatal error"); connection_error(con); return; - case NETWORK_STATUS_CONNECTION_CLOSE: + case LI_NETWORK_STATUS_CONNECTION_CLOSE: connection_close(con); return; - case NETWORK_STATUS_WAIT_FOR_EVENT: + case LI_NETWORK_STATUS_WAIT_FOR_EVENT: break; - case NETWORK_STATUS_WAIT_FOR_AIO_EVENT: + case LI_NETWORK_STATUS_WAIT_FOR_AIO_EVENT: ev_io_rem_events(loop, w, EV_WRITE); _ERROR(con->srv, con->mainvr, "%s", "TODO: wait for aio"); /* TODO: aio */ @@ -304,7 +304,7 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) { } if (con->throttle.pool.ptr && con->throttle.pool.magazine <= MAX(write_max,0) && !con->throttle.pool.queued) { - throttle_pool_t *pool = con->throttle.pool.ptr; + liThrottlePool *pool = con->throttle.pool.ptr; g_atomic_int_inc(&pool->num_cons); g_queue_push_tail_link(pool->queues[con->wrk->ndx+pool->current_queue[con->wrk->ndx]], &con->throttle.pool.lnk); con->throttle.pool.queued = TRUE; @@ -323,55 +323,55 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) { } static void connection_keepalive_cb(struct ev_loop *loop, ev_timer *w, int revents) { - connection *con = (connection*) w->data; + liConnection *con = (liConnection*) w->data; UNUSED(loop); UNUSED(revents); worker_con_put(con); } -static handler_t mainvr_handle_response_headers(vrequest *vr) { - connection *con = vr->con; - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { +static liHandlerResult mainvr_handle_response_headers(liVRequest *vr) { + liConnection *con = vr->con; + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "read request/handle response header"); } parse_request_body(con); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static handler_t mainvr_handle_response_body(vrequest *vr) { - connection *con = vr->con; - if (check_response_done(con)) return HANDLER_GO_ON; +static liHandlerResult mainvr_handle_response_body(liVRequest *vr) { + liConnection *con = vr->con; + if (check_response_done(con)) return LI_HANDLER_GO_ON; - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "write response"); } parse_request_body(con); forward_response_body(con); - if (check_response_done(con)) return HANDLER_GO_ON; + if (check_response_done(con)) return LI_HANDLER_GO_ON; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static handler_t mainvr_handle_response_error(vrequest *vr) { +static liHandlerResult mainvr_handle_response_error(liVRequest *vr) { connection_internal_error(vr->con); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static handler_t mainvr_handle_request_headers(vrequest *vr) { +static liHandlerResult mainvr_handle_request_headers(liVRequest *vr) { /* start reading input */ parse_request_body(vr->con); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -connection* connection_new(worker *wrk) { - server *srv = wrk->srv; - connection *con = g_slice_new0(connection); +liConnection* connection_new(liWorker *wrk) { + liServer *srv = wrk->srv; + liConnection *con = g_slice_new0(liConnection); con->wrk = wrk; con->srv = srv; - con->state = CON_STATE_DEAD; + con->state = LI_CON_STATE_DEAD; con->response_headers_sent = FALSE; con->expect_100_cont = FALSE; @@ -416,8 +416,8 @@ connection* connection_new(worker *wrk) { return con; } -void connection_reset(connection *con) { - con->state = CON_STATE_DEAD; +void connection_reset(liConnection *con) { + con->state = LI_CON_STATE_DEAD; con->response_headers_sent = FALSE; con->expect_100_cont = FALSE; @@ -473,7 +473,7 @@ void connection_reset(connection *con) { if (con->throttle.pool.ptr) { if (con->throttle.pool.queued) { - throttle_pool_t *pool = con->throttle.pool.ptr; + liThrottlePool *pool = con->throttle.pool.ptr; g_queue_unlink(pool->queues[con->wrk->ndx+pool->current_queue[con->wrk->ndx]], &con->throttle.pool.lnk); g_atomic_int_add(&con->throttle.pool.ptr->num_cons, -1); con->throttle.pool.queued = FALSE; @@ -489,7 +489,7 @@ void connection_reset(connection *con) { if (con->throttle.ip.ptr) { if (con->throttle.ip.queued) { - throttle_pool_t *pool = con->throttle.ip.ptr; + liThrottlePool *pool = con->throttle.ip.ptr; g_queue_unlink(pool->queues[con->wrk->ndx+pool->current_queue[con->wrk->ndx]], &con->throttle.ip.lnk); g_atomic_int_add(&con->throttle.ip.ptr->num_cons, -1); con->throttle.ip.queued = FALSE; @@ -506,12 +506,12 @@ void connection_reset(connection *con) { con->throttled = FALSE; } -void server_check_keepalive(server *srv); -void connection_reset_keep_alive(connection *con) { - vrequest *vr = con->mainvr; +void server_check_keepalive(liServer *srv); +void connection_reset_keep_alive(liConnection *con) { + liVRequest *vr = con->mainvr; ev_timer_stop(con->wrk->loop, &con->keep_alive_data.watcher); { - con->keep_alive_data.max_idle = CORE_OPTION(CORE_OPTION_MAX_KEEP_ALIVE_IDLE).number; + con->keep_alive_data.max_idle = CORE_OPTION(LI_CORE_OPTION_MAX_KEEP_ALIVE_IDLE).number; if (con->keep_alive_data.max_idle == 0) { worker_con_put(con); return; @@ -530,7 +530,7 @@ void connection_reset_keep_alive(connection *con) { } } - con->state = CON_STATE_KEEP_ALIVE; + con->state = LI_CON_STATE_KEEP_ALIVE; con->response_headers_sent = FALSE; con->expect_100_cont = FALSE; @@ -560,7 +560,7 @@ void connection_reset_keep_alive(connection *con) { if (con->throttle.pool.ptr) { if (con->throttle.pool.queued) { - throttle_pool_t *pool = con->throttle.pool.ptr; + liThrottlePool *pool = con->throttle.pool.ptr; g_queue_unlink(pool->queues[con->wrk->ndx+pool->current_queue[con->wrk->ndx]], &con->throttle.pool.lnk); g_atomic_int_add(&con->throttle.pool.ptr->num_cons, -1); con->throttle.pool.queued = FALSE; @@ -576,7 +576,7 @@ void connection_reset_keep_alive(connection *con) { if (con->throttle.ip.ptr) { if (con->throttle.ip.queued) { - throttle_pool_t *pool = con->throttle.ip.ptr; + liThrottlePool *pool = con->throttle.ip.ptr; g_queue_unlink(pool->queues[con->wrk->ndx+pool->current_queue[con->wrk->ndx]], &con->throttle.ip.lnk); g_atomic_int_add(&con->throttle.ip.ptr->num_cons, -1); con->throttle.ip.queued = FALSE; @@ -593,8 +593,8 @@ void connection_reset_keep_alive(connection *con) { con->throttled = FALSE; } -void connection_free(connection *con) { - con->state = CON_STATE_DEAD; +void connection_free(liConnection *con) { + con->state = LI_CON_STATE_DEAD; con->response_headers_sent = FALSE; con->expect_100_cont = FALSE; @@ -628,10 +628,10 @@ void connection_free(connection *con) { if (con->wrk) ev_timer_stop(con->wrk->loop, &con->keep_alive_data.watcher); - g_slice_free(connection, con); + g_slice_free(liConnection, con); } -gchar *connection_state_str(connection_state_t state) { +gchar *connection_state_str(liConnectionState state) { static const gchar *states[] = { "dead", "keep-alive", diff --git a/src/encoding.c b/src/encoding.c index de7e01d..1c9d687 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -1,4 +1,5 @@ -#include + +#include static const gchar hex_chars[] = "0123456789abcdef"; diff --git a/src/environment.c b/src/environment.c index 7ca6be6..2a1ed18 100644 --- a/src/environment.c +++ b/src/environment.c @@ -1,31 +1,31 @@ -#include +#include static void _hash_free_gstring(gpointer data) { g_string_free((GString*) data, TRUE); } -void environment_init(environment *env) { +void environment_init(liEnvironment *env) { env->table = g_hash_table_new_full( (GHashFunc) g_string_hash, (GEqualFunc) g_string_equal, _hash_free_gstring, _hash_free_gstring); } -void environment_reset(environment *env) { +void environment_reset(liEnvironment *env) { g_hash_table_remove_all(env->table); } -void environment_clear(environment *env) { +void environment_clear(liEnvironment *env) { g_hash_table_destroy(env->table); } -void environment_set(environment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { +void environment_set(liEnvironment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { GString *skey = g_string_new_len(key, keylen); GString *sval = g_string_new_len(val, valuelen); g_hash_table_insert(env->table, skey, sval); } -void environment_insert(environment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { +void environment_insert(liEnvironment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { GString *sval = environment_get(env, key, keylen), *skey; if (!sval) { skey = g_string_new_len(key, keylen); @@ -34,21 +34,21 @@ void environment_insert(environment *env, const gchar *key, size_t keylen, const } } -void environment_remove(environment *env, const gchar *key, size_t keylen) { +void environment_remove(liEnvironment *env, const gchar *key, size_t keylen) { const GString skey = { (gchar*) key, keylen, 0 }; /* fake a constant GString */ g_hash_table_remove(env->table, &skey); } -GString* environment_get(environment *env, const gchar *key, size_t keylen) { +GString* environment_get(liEnvironment *env, const gchar *key, size_t keylen) { const GString skey = { (gchar*) key, keylen, 0 }; /* fake a constant GString */ return (GString*) g_hash_table_lookup(env->table, &skey); } -environment_dup* environment_make_dup(environment *env) { +liEnvironmentDup* environment_make_dup(liEnvironment *env) { GHashTableIter i; GHashTable *tdst; gpointer key, val; - environment_dup *envdup = g_slice_new0(environment_dup); + liEnvironmentDup *envdup = g_slice_new0(liEnvironmentDup); envdup->table = tdst = g_hash_table_new((GHashFunc) g_string_hash, (GEqualFunc) g_string_equal); g_hash_table_iter_init(&i, env->table); @@ -58,12 +58,12 @@ environment_dup* environment_make_dup(environment *env) { return envdup; } -void environment_dup_free(environment_dup *envdup) { +void environment_dup_free(liEnvironmentDup *envdup) { g_hash_table_destroy(envdup->table); - g_slice_free(environment_dup, envdup); + g_slice_free(liEnvironmentDup, envdup); } -GString* environment_dup_pop(environment_dup *envdup, const gchar *key, size_t keylen) { +GString* environment_dup_pop(liEnvironmentDup *envdup, const gchar *key, size_t keylen) { const GString skey = { (gchar*) key, keylen, 0 }; /* fake a constant GString */ GString *sval = (GString*) g_hash_table_lookup(envdup->table, &skey); if (sval) g_hash_table_remove(envdup->table, &skey); diff --git a/src/etag.c b/src/etag.c index 3d4dbee..ca051ae 100644 --- a/src/etag.c +++ b/src/etag.c @@ -2,13 +2,13 @@ #include #include -tristate_t http_response_handle_cachable_etag(vrequest *vr, GString *etag) { +tristate_t http_response_handle_cachable_etag(liVRequest *vr, GString *etag) { GList *l; tristate_t res = TRI_MAYBE; gchar *setag = NULL; if (!etag) { - http_header *hetag = http_header_lookup(vr->response.headers, CONST_STR_LEN("etag")); + liHttpHeader *hetag = http_header_lookup(vr->response.headers, CONST_STR_LEN("etag")); if (hetag) setag = hetag->data->str + hetag->keylen + 2; } else { setag = etag->str; @@ -18,7 +18,7 @@ tristate_t http_response_handle_cachable_etag(vrequest *vr, GString *etag) { l = http_header_find_first(vr->request.headers, CONST_STR_LEN("If-None-Match")); l; l = http_header_find_next(l, CONST_STR_LEN("If-None-Match"))) { - http_header *h = (http_header*) l->data; + liHttpHeader *h = (liHttpHeader*) l->data; res = TRI_FALSE; /* if the header was given at least once, we need a match */ if (!setag) return res; if (strstr(h->data->str + h->keylen + 2, setag)) { @@ -28,10 +28,10 @@ tristate_t http_response_handle_cachable_etag(vrequest *vr, GString *etag) { return res; } -tristate_t http_response_handle_cachable_modified(vrequest *vr, GString *last_modified) { +tristate_t http_response_handle_cachable_modified(liVRequest *vr, GString *last_modified) { GList *l; gchar *slm = NULL, *hlm; - http_header *h; + liHttpHeader *h; size_t used_len; char *semicolon; @@ -47,7 +47,7 @@ tristate_t http_response_handle_cachable_modified(vrequest *vr, GString *last_mo if (http_header_find_next(l, CONST_STR_LEN("If-Modified-Since"))) { return TRI_FALSE; /* we only check one if-modified-since header */ } - h = (http_header*) l->data; + h = (liHttpHeader*) l->data; hlm = h->data->str + h->keylen + 2; if (!slm) return TRI_FALSE; @@ -66,7 +66,7 @@ tristate_t http_response_handle_cachable_modified(vrequest *vr, GString *last_mo /* check if we can safely copy the string */ if (used_len >= sizeof(buf)) { - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "Last-Modified check failed as the received timestamp '%s' was too long (%u > %u)", hlm, (int) used_len, (int) sizeof(buf) - 1); } @@ -106,8 +106,8 @@ void etag_mutate(GString *mut, GString *etag) { g_string_append_len(mut, CONST_STR_LEN("\"")); } -void etag_set_header(vrequest *vr, struct stat *st, gboolean *cachable) { - guint flags = CORE_OPTION(CORE_OPTION_ETAG_FLAGS).number; +void etag_set_header(liVRequest *vr, struct stat *st, gboolean *cachable) { + guint flags = CORE_OPTION(LI_CORE_OPTION_ETAG_FLAGS).number; GString *tmp_str = vr->wrk->tmp_str; struct tm tm; tristate_t c_able = cachable ? TRI_MAYBE : TRI_FALSE; @@ -117,16 +117,16 @@ void etag_set_header(vrequest *vr, struct stat *st, gboolean *cachable) { } else { g_string_truncate(tmp_str, 0); - if (flags & ETAG_USE_INODE) { + if (flags & LI_ETAG_USE_INODE) { l_g_string_append_int(tmp_str, st->st_ino); } - if (flags & ETAG_USE_SIZE) { + if (flags & LI_ETAG_USE_SIZE) { if (tmp_str->len != 0) g_string_append_len(tmp_str, CONST_STR_LEN("-")); l_g_string_append_int(tmp_str, st->st_size); } - if (flags & ETAG_USE_MTIME) { + if (flags & LI_ETAG_USE_MTIME) { if (tmp_str->len != 0) g_string_append_len(tmp_str, CONST_STR_LEN("-")); l_g_string_append_int(tmp_str, st->st_mtime); } diff --git a/src/filter_chunked.c b/src/filter_chunked.c index cc79260..b8cda8f 100644 --- a/src/filter_chunked.c +++ b/src/filter_chunked.c @@ -2,7 +2,7 @@ #include /* len != 0 */ -static void http_chunk_append_len(chunkqueue *cq, size_t len) { +static void http_chunk_append_len(liChunkQueue *cq, size_t len) { size_t i, olen = len, j; GByteArray *a; @@ -25,7 +25,7 @@ static void http_chunk_append_len(chunkqueue *cq, size_t len) { } -handler_t filter_chunked_encode(connection *con, chunkqueue *out, chunkqueue *in) { +liHandlerResult filter_chunked_encode(liConnection *con, liChunkQueue *out, liChunkQueue *in) { UNUSED(con); if (in->length > 0) { @@ -38,14 +38,14 @@ handler_t filter_chunked_encode(connection *con, chunkqueue *out, chunkqueue *in chunkqueue_append_mem(out, CONST_STR_LEN("0\r\n\r\n")); out->is_closed = TRUE; } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -handler_t filter_chunked_decode(connection *con, chunkqueue *out, chunkqueue *in) { +liHandlerResult filter_chunked_decode(liConnection *con, liChunkQueue *out, liChunkQueue *in) { UNUSED(con); UNUSED(out); UNUSED(in); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } diff --git a/src/http_headers.c b/src/http_headers.c index 32f0aef..53978b6 100644 --- a/src/http_headers.c +++ b/src/http_headers.c @@ -2,13 +2,13 @@ #include static void _http_header_free(gpointer p) { - http_header *h = (http_header*) p; + liHttpHeader *h = (liHttpHeader*) p; g_string_free(h->data, TRUE); - g_slice_free(http_header, h); + g_slice_free(liHttpHeader, h); } -static http_header* _http_header_new(const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { - http_header *h = g_slice_new0(http_header); +static liHttpHeader* _http_header_new(const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { + liHttpHeader *h = g_slice_new0(liHttpHeader); h->data = g_string_sized_new(keylen + valuelen + 2); h->keylen = keylen; g_string_append_len(h->data, key, keylen); @@ -19,90 +19,90 @@ static http_header* _http_header_new(const gchar *key, size_t keylen, const gcha static void _header_queue_free(gpointer data, gpointer userdata) { UNUSED(userdata); - _http_header_free((http_header*) data); + _http_header_free((liHttpHeader*) data); } -http_headers* http_headers_new() { - http_headers* headers = g_slice_new0(http_headers); +liHttpHeaders* http_headers_new() { + liHttpHeaders* headers = g_slice_new0(liHttpHeaders); g_queue_init(&headers->entries); return headers; } -void http_headers_reset(http_headers* headers) { +void http_headers_reset(liHttpHeaders* headers) { g_queue_foreach(&headers->entries, _header_queue_free, NULL); g_queue_clear(&headers->entries); } -void http_headers_free(http_headers* headers) { +void http_headers_free(liHttpHeaders* headers) { if (!headers) return; g_queue_foreach(&headers->entries, _header_queue_free, NULL); g_queue_clear(&headers->entries); - g_slice_free(http_headers, headers); + g_slice_free(liHttpHeaders, headers); } /** just insert normal header, allow duplicates */ -void http_header_insert(http_headers *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { - http_header *h = _http_header_new(key, keylen, val, valuelen); +void http_header_insert(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { + liHttpHeader *h = _http_header_new(key, keylen, val, valuelen); g_queue_push_tail(&headers->entries, h); } -GList* http_header_find_first(http_headers *headers, const gchar *key, size_t keylen) { - http_header *h; +GList* http_header_find_first(liHttpHeaders *headers, const gchar *key, size_t keylen) { + liHttpHeader *h; GList *l; for (l = g_queue_peek_head_link(&headers->entries); l; l = g_list_next(l)) { - h = (http_header*) l->data; + h = (liHttpHeader*) l->data; if (h->keylen == keylen && 0 == g_ascii_strncasecmp(key, h->data->str, keylen)) return l; } return NULL; } GList* http_header_find_next(GList *l, const gchar *key, size_t keylen) { - http_header *h; + liHttpHeader *h; for (l = g_list_next(l); l; l = g_list_next(l)) { - h = (http_header*) l->data; + h = (liHttpHeader*) l->data; if (h->keylen == keylen && 0 == g_ascii_strncasecmp(key, h->data->str, keylen)) return l; } return NULL; } -GList* http_header_find_last(http_headers *headers, const gchar *key, size_t keylen) { - http_header *h; +GList* http_header_find_last(liHttpHeaders *headers, const gchar *key, size_t keylen) { + liHttpHeader *h; GList *l; for (l = g_queue_peek_tail_link(&headers->entries); l; l = g_list_previous(l)) { - h = (http_header*) l->data; + h = (liHttpHeader*) l->data; if (h->keylen == keylen && 0 == g_ascii_strncasecmp(key, h->data->str, keylen)) return l; } return NULL; } /** If header does not exist, just insert normal header. If it exists, append (", %s", value) to the last inserted one */ -void http_header_append(http_headers *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { +void http_header_append(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { GList *l; - http_header *h; + liHttpHeader *h; l = http_header_find_last(headers, key, keylen); if (NULL == l) { http_header_insert(headers, key, keylen, val, valuelen); } else { - h = (http_header*) l->data; + h = (liHttpHeader*) l->data; g_string_append_len(h->data, CONST_STR_LEN(", ")); g_string_append_len(h->data, val, valuelen); } } /** If header does not exist, just insert normal header. If it exists, overwrite the last occurrence */ -void http_header_overwrite(http_headers *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { +void http_header_overwrite(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { GList *l; - http_header *h; + liHttpHeader *h; l = http_header_find_last(headers, key, keylen); if (NULL == l) { http_header_insert(headers, key, keylen, val, valuelen); } else { - h = (http_header*) l->data; + h = (liHttpHeader*) l->data; g_string_truncate(h->data, 0); g_string_append_len(h->data, key, keylen); g_string_append_len(h->data, CONST_STR_LEN(": ")); @@ -110,12 +110,12 @@ void http_header_overwrite(http_headers *headers, const gchar *key, size_t keyle } } -void http_header_remove_link(http_headers *headers, GList *l) { +void http_header_remove_link(liHttpHeaders *headers, GList *l) { _http_header_free(l->data); g_queue_delete_link(&headers->entries, l); } -gboolean http_header_remove(http_headers *headers, const gchar *key, size_t keylen) { +gboolean http_header_remove(liHttpHeaders *headers, const gchar *key, size_t keylen) { GList *l, *lp = NULL; gboolean res = FALSE; @@ -135,31 +135,31 @@ gboolean http_header_remove(http_headers *headers, const gchar *key, size_t keyl return res; } -http_header* http_header_lookup(http_headers *headers, const gchar *key, size_t keylen) { +liHttpHeader* http_header_lookup(liHttpHeaders *headers, const gchar *key, size_t keylen) { GList *l; l = http_header_find_last(headers, key, keylen); - return NULL == l ? NULL : (http_header*) l->data; + return NULL == l ? NULL : (liHttpHeader*) l->data; } -gboolean http_header_is(http_headers *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { +gboolean http_header_is(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { GList *l; UNUSED(valuelen); for (l = http_header_find_first(headers, key, keylen); l; l = http_header_find_next(l, key, keylen)) { - http_header *h = (http_header*) l->data; + liHttpHeader *h = (liHttpHeader*) l->data; if (h->data->len - (h->keylen + 2) != valuelen) continue; if (0 == g_ascii_strcasecmp( &h->data->str[h->keylen+2], val )) return TRUE; } return FALSE; } -void http_header_get_fast(GString *dest, http_headers *headers, const gchar *key, size_t keylen) { +void http_header_get_fast(GString *dest, liHttpHeaders *headers, const gchar *key, size_t keylen) { GList *l; g_string_truncate(dest, 0); for (l = http_header_find_first(headers, key, keylen); l; l = http_header_find_next(l, key, keylen)) { - http_header *h = (http_header*) l->data; + liHttpHeader *h = (liHttpHeader*) l->data; if (dest->len) g_string_append_len(dest, CONST_STR_LEN(", ")); g_string_append_len(dest, &h->data->str[h->keylen+2], h->data->len - (h->keylen + 2)); } diff --git a/src/http_request_parser.rl b/src/http_request_parser.rl index b1f473b..7caf113 100644 --- a/src/http_request_parser.rl +++ b/src/http_request_parser.rl @@ -65,9 +65,9 @@ Quoted_String = DQUOTE ( QDText | Quoted_Pair )* DQUOTE; HTTP_Version = ( - "HTTP/1.0" %{ ctx->request->http_version = HTTP_VERSION_1_0; } - | "HTTP/1.1" %{ ctx->request->http_version = HTTP_VERSION_1_1; } - | "HTTP" "/" DIGIT+ "." DIGIT+ ) >{ ctx->request->http_version = HTTP_VERSION_UNSET; }; + "HTTP/1.0" %{ ctx->request->http_version = LI_HTTP_VERSION_1_0; } + | "HTTP/1.1" %{ ctx->request->http_version = LI_HTTP_VERSION_1_1; } + | "HTTP" "/" DIGIT+ "." DIGIT+ ) >{ ctx->request->http_version = LI_HTTP_VERSION_UNSET; }; #HTTP_URL = "http:" "//" Host ( ":" Port )? ( abs_path ( "?" query )? )?; # RFC 2396 @@ -82,29 +82,29 @@ Abs_Path = "/" Path_Segments; Method = ( - "GET" %{ ctx->request->http_method = HTTP_METHOD_GET; } - | "POST" %{ ctx->request->http_method = HTTP_METHOD_POST; } - | "HEAD" %{ ctx->request->http_method = HTTP_METHOD_HEAD; } - | "OPTIONS" %{ ctx->request->http_method = HTTP_METHOD_OPTIONS; } - | "PROPFIND" %{ ctx->request->http_method = HTTP_METHOD_PROPFIND; } - | "MKCOL" %{ ctx->request->http_method = HTTP_METHOD_MKCOL; } - | "PUT" %{ ctx->request->http_method = HTTP_METHOD_PUT; } - | "DELETE" %{ ctx->request->http_method = HTTP_METHOD_DELETE; } - | "COPY" %{ ctx->request->http_method = HTTP_METHOD_COPY; } - | "MOVE" %{ ctx->request->http_method = HTTP_METHOD_MOVE; } - | "PROPPATCH" %{ ctx->request->http_method = HTTP_METHOD_PROPPATCH; } - | "REPORT" %{ ctx->request->http_method = HTTP_METHOD_REPORT; } - | "CHKECOUT" %{ ctx->request->http_method = HTTP_METHOD_CHECKOUT; } - | "CHECKIN" %{ ctx->request->http_method = HTTP_METHOD_CHECKIN; } - | "VERSION-CONTROL" %{ ctx->request->http_method = HTTP_METHOD_VERSION_CONTROL; } - | "UNCHECKOUT" %{ ctx->request->http_method = HTTP_METHOD_UNCHECKOUT; } - | "MKACTIVITY" %{ ctx->request->http_method = HTTP_METHOD_MKACTIVITY; } - | "MERGE" %{ ctx->request->http_method = HTTP_METHOD_MERGE; } - | "LOCK" %{ ctx->request->http_method = HTTP_METHOD_LOCK; } - | "UNLOCK" %{ ctx->request->http_method = HTTP_METHOD_UNLOCK; } - | "LABEL" %{ ctx->request->http_method = HTTP_METHOD_LABEL; } - | "CONNECT" %{ ctx->request->http_method = HTTP_METHOD_CONNECT; } - | Token ) >mark >{ ctx->request->http_method = HTTP_METHOD_UNSET; } %method; + "GET" %{ ctx->request->http_method = LI_HTTP_METHOD_GET; } + | "POST" %{ ctx->request->http_method = LI_HTTP_METHOD_POST; } + | "HEAD" %{ ctx->request->http_method = LI_HTTP_METHOD_HEAD; } + | "OPTIONS" %{ ctx->request->http_method = LI_HTTP_METHOD_OPTIONS; } + | "PROPFIND" %{ ctx->request->http_method = LI_HTTP_METHOD_PROPFIND; } + | "MKCOL" %{ ctx->request->http_method = LI_HTTP_METHOD_MKCOL; } + | "PUT" %{ ctx->request->http_method = LI_HTTP_METHOD_PUT; } + | "DELETE" %{ ctx->request->http_method = LI_HTTP_METHOD_DELETE; } + | "COPY" %{ ctx->request->http_method = LI_HTTP_METHOD_COPY; } + | "MOVE" %{ ctx->request->http_method = LI_HTTP_METHOD_MOVE; } + | "PROPPATCH" %{ ctx->request->http_method = LI_HTTP_METHOD_PROPPATCH; } + | "REPORT" %{ ctx->request->http_method = LI_HTTP_METHOD_REPORT; } + | "CHKECOUT" %{ ctx->request->http_method = LI_HTTP_METHOD_CHECKOUT; } + | "CHECKIN" %{ ctx->request->http_method = LI_HTTP_METHOD_CHECKIN; } + | "VERSION-CONTROL" %{ ctx->request->http_method = LI_HTTP_METHOD_VERSION_CONTROL; } + | "UNCHECKOUT" %{ ctx->request->http_method = LI_HTTP_METHOD_UNCHECKOUT; } + | "MKACTIVITY" %{ ctx->request->http_method = LI_HTTP_METHOD_MKACTIVITY; } + | "MERGE" %{ ctx->request->http_method = LI_HTTP_METHOD_MERGE; } + | "LOCK" %{ ctx->request->http_method = LI_HTTP_METHOD_LOCK; } + | "UNLOCK" %{ ctx->request->http_method = LI_HTTP_METHOD_UNLOCK; } + | "LABEL" %{ ctx->request->http_method = LI_HTTP_METHOD_LABEL; } + | "CONNECT" %{ ctx->request->http_method = LI_HTTP_METHOD_CONNECT; } + | Token ) >mark >{ ctx->request->http_method = LI_HTTP_METHOD_UNSET; } %method; Request_URI = ("*" | ( any - CTL - SP )+) >mark %uri; Request_Line = Method " " Request_URI " " HTTP_Version CRLF; @@ -118,15 +118,15 @@ %% write data; -static int http_request_parser_has_error(http_request_ctx *ctx) { +static int http_request_parser_has_error(liHttpRequestCtx *ctx) { return ctx->chunk_ctx.cs == http_request_parser_error; } -static int http_request_parser_is_finished(http_request_ctx *ctx) { +static int http_request_parser_is_finished(liHttpRequestCtx *ctx) { return ctx->chunk_ctx.cs >= http_request_parser_first_final; } -void http_request_parser_init(http_request_ctx* ctx, request *req, chunkqueue *cq) { +void http_request_parser_init(liHttpRequestCtx* ctx, liRequest *req, liChunkQueue *cq) { chunk_parser_init(&ctx->chunk_ctx, cq); ctx->request = req; ctx->h_key = g_string_sized_new(0); @@ -135,7 +135,7 @@ void http_request_parser_init(http_request_ctx* ctx, request *req, chunkqueue *c %% write init; } -void http_request_parser_reset(http_request_ctx* ctx) { +void http_request_parser_reset(liHttpRequestCtx* ctx) { chunk_parser_reset(&ctx->chunk_ctx); g_string_truncate(ctx->h_key, 0); g_string_truncate(ctx->h_value, 0); @@ -143,32 +143,32 @@ void http_request_parser_reset(http_request_ctx* ctx) { %% write init; } -void http_request_parser_clear(http_request_ctx *ctx) { +void http_request_parser_clear(liHttpRequestCtx *ctx) { g_string_free(ctx->h_key, TRUE); g_string_free(ctx->h_value, TRUE); } -handler_t http_request_parse(vrequest *vr, http_request_ctx *ctx) { - handler_t res; +liHandlerResult http_request_parse(liVRequest *vr, liHttpRequestCtx *ctx) { + liHandlerResult res; - if (http_request_parser_is_finished(ctx)) return HANDLER_GO_ON; + if (http_request_parser_is_finished(ctx)) return LI_HANDLER_GO_ON; - if (HANDLER_GO_ON != (res = chunk_parser_prepare(&ctx->chunk_ctx))) return res; + if (LI_HANDLER_GO_ON != (res = chunk_parser_prepare(&ctx->chunk_ctx))) return res; while (!http_request_parser_has_error(ctx) && !http_request_parser_is_finished(ctx)) { char *p, *pe; - if (HANDLER_GO_ON != (res = chunk_parser_next(vr, &ctx->chunk_ctx, &p, &pe))) return res; + if (LI_HANDLER_GO_ON != (res = chunk_parser_next(vr, &ctx->chunk_ctx, &p, &pe))) return res; %% write exec; chunk_parser_done(&ctx->chunk_ctx, p - ctx->chunk_ctx.buf); } - if (http_request_parser_has_error(ctx)) return HANDLER_ERROR; + if (http_request_parser_has_error(ctx)) return LI_HANDLER_ERROR; if (http_request_parser_is_finished(ctx)) { chunkqueue_skip(ctx->chunk_ctx.cq, ctx->chunk_ctx.bytes_in); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } diff --git a/src/http_response_parser.rl b/src/http_response_parser.rl index 66816a2..89508e8 100644 --- a/src/http_response_parser.rl +++ b/src/http_response_parser.rl @@ -71,9 +71,9 @@ Quoted_String = DQUOTE ( QDText | Quoted_Pair )* DQUOTE; HTTP_Version = ( - "HTTP/1.0" %{ ctx->response->http_version = HTTP_VERSION_1_0; } - | "HTTP/1.1" %{ ctx->response->http_version = HTTP_VERSION_1_1; } - | "HTTP" "/" DIGIT+ "." DIGIT+ ) >{ ctx->response->http_version = HTTP_VERSION_UNSET; }; + "HTTP/1.0" %{ ctx->response->http_version = LI_HTTP_VERSION_1_0; } + | "HTTP/1.1" %{ ctx->response->http_version = LI_HTTP_VERSION_1_1; } + | "HTTP" "/" DIGIT+ "." DIGIT+ ) >{ ctx->response->http_version = LI_HTTP_VERSION_UNSET; }; #HTTP_URL = "http:" "//" Host ( ":" Port )? ( abs_path ( "?" query )? )?; Status = (digit digit digit) >mark %status; @@ -88,15 +88,15 @@ %% write data; -static int http_response_parser_has_error(http_response_ctx *ctx) { +static int http_response_parser_has_error(liHttpResponseCtx *ctx) { return ctx->chunk_ctx.cs == http_response_parser_error; } -static int http_response_parser_is_finished(http_response_ctx *ctx) { +static int http_response_parser_is_finished(liHttpResponseCtx *ctx) { return ctx->chunk_ctx.cs >= http_response_parser_first_final; } -void http_response_parser_init(http_response_ctx* ctx, response *req, chunkqueue *cq, gboolean accept_cgi, gboolean accept_nph) { +void http_response_parser_init(liHttpResponseCtx* ctx, liResponse *req, liChunkQueue *cq, gboolean accept_cgi, gboolean accept_nph) { chunk_parser_init(&ctx->chunk_ctx, cq); ctx->response = req; ctx->accept_cgi = accept_cgi; @@ -107,7 +107,7 @@ void http_response_parser_init(http_response_ctx* ctx, response *req, chunkqueue %% write init; } -void http_response_parser_reset(http_response_ctx* ctx) { +void http_response_parser_reset(liHttpResponseCtx* ctx) { chunk_parser_reset(&ctx->chunk_ctx); g_string_truncate(ctx->h_key, 0); g_string_truncate(ctx->h_value, 0); @@ -115,33 +115,33 @@ void http_response_parser_reset(http_response_ctx* ctx) { %% write init; } -void http_response_parser_clear(http_response_ctx *ctx) { +void http_response_parser_clear(liHttpResponseCtx *ctx) { g_string_free(ctx->h_key, TRUE); g_string_free(ctx->h_value, TRUE); } -handler_t http_response_parse(vrequest *vr, http_response_ctx *ctx) { - handler_t res; +liHandlerResult http_response_parse(liVRequest *vr, liHttpResponseCtx *ctx) { + liHandlerResult res; - if (http_response_parser_is_finished(ctx)) return HANDLER_GO_ON; + if (http_response_parser_is_finished(ctx)) return LI_HANDLER_GO_ON; - if (HANDLER_GO_ON != (res = chunk_parser_prepare(&ctx->chunk_ctx))) return res; + if (LI_HANDLER_GO_ON != (res = chunk_parser_prepare(&ctx->chunk_ctx))) return res; while (!http_response_parser_has_error(ctx) && !http_response_parser_is_finished(ctx)) { char *p, *pe; - if (HANDLER_GO_ON != (res = chunk_parser_next(vr, &ctx->chunk_ctx, &p, &pe))) return res; + if (LI_HANDLER_GO_ON != (res = chunk_parser_next(vr, &ctx->chunk_ctx, &p, &pe))) return res; %% write exec; chunk_parser_done(&ctx->chunk_ctx, p - ctx->chunk_ctx.buf); } - if (http_response_parser_has_error(ctx)) return HANDLER_ERROR; + if (http_response_parser_has_error(ctx)) return LI_HANDLER_ERROR; if (http_response_parser_is_finished(ctx)) { chunkqueue_skip(ctx->chunk_ctx.cq, ctx->chunk_ctx.bytes_in); if (ctx->response->http_status == 0) ctx->response->http_status = 200; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } diff --git a/src/idlist.c b/src/idlist.c index 9bca289..725d9a9 100644 --- a/src/idlist.c +++ b/src/idlist.c @@ -9,8 +9,8 @@ * of the form 2^n this should result in bit shifts in the executable code. */ -idlist* idlist_new(gint max_ids) { - idlist *l = g_slice_new0(idlist); +liIDList* idlist_new(gint max_ids) { + liIDList *l = g_slice_new0(liIDList); g_assert(max_ids > 0); l->bitvector = g_array_new(FALSE, TRUE, sizeof(gulong)); l->max_ids = max_ids; @@ -19,10 +19,10 @@ idlist* idlist_new(gint max_ids) { return l; } -void idlist_free(idlist *l) { +void idlist_free(liIDList *l) { if (!l) return; g_array_free(l->bitvector, TRUE); - g_slice_free(idlist, l); + g_slice_free(liIDList, l); } static void mark_bit(GArray *a, gint id) { @@ -48,7 +48,7 @@ static void idlist_reserve(GArray *a, guint id) { if (ndx >= a->len) g_array_set_size(a, ndx+1); } -gint idlist_get(idlist *l) { +gint idlist_get(liIDList *l) { guint fndx, ndx; gint newid, bndx; gulong u = -1; @@ -97,7 +97,7 @@ gint idlist_get(idlist *l) { return newid; } -gboolean idlist_is_used(idlist *l, gint id) { +gboolean idlist_is_used(liIDList *l, gint id) { GArray *a = l->bitvector; guint ndx = id / UL_BITS, bndx = id % UL_BITS; gulong bmask = 1 << bndx; @@ -106,7 +106,7 @@ gboolean idlist_is_used(idlist *l, gint id) { return (0 != (g_array_index(a, gulong, ndx) & (bmask))); } -void idlist_put(idlist *l, gint id) { +void idlist_put(liIDList *l, gint id) { clear_bit(l->bitvector, id); l->used_ids--; diff --git a/src/lighttpd-glue.c b/src/lighttpd-glue.c index 1191c3a..139625a 100644 --- a/src/lighttpd-glue.c +++ b/src/lighttpd-glue.c @@ -75,42 +75,42 @@ gchar *http_status_string(guint status_code, guint *len) { } } -gchar *http_method_string(http_method_t method, guint *len) { +gchar *http_method_string(liHttpMethod method, guint *len) { switch (method) { - case HTTP_METHOD_UNSET: SET_LEN_AND_RETURN_STR("UNKNOWN"); - case HTTP_METHOD_GET: SET_LEN_AND_RETURN_STR("GET"); - case HTTP_METHOD_POST: SET_LEN_AND_RETURN_STR("POST"); - case HTTP_METHOD_HEAD: SET_LEN_AND_RETURN_STR("HEAD"); - case HTTP_METHOD_OPTIONS: SET_LEN_AND_RETURN_STR("OPTIONS"); - case HTTP_METHOD_PROPFIND: SET_LEN_AND_RETURN_STR("PROPFIND"); - case HTTP_METHOD_MKCOL: SET_LEN_AND_RETURN_STR("MKCOL"); - case HTTP_METHOD_PUT: SET_LEN_AND_RETURN_STR("PUT"); - case HTTP_METHOD_DELETE: SET_LEN_AND_RETURN_STR("DELETE"); - case HTTP_METHOD_COPY: SET_LEN_AND_RETURN_STR("COPY"); - case HTTP_METHOD_MOVE: SET_LEN_AND_RETURN_STR("MOVE"); - case HTTP_METHOD_PROPPATCH: SET_LEN_AND_RETURN_STR("PROPPATCH"); - case HTTP_METHOD_REPORT: SET_LEN_AND_RETURN_STR("REPORT"); - case HTTP_METHOD_CHECKOUT: SET_LEN_AND_RETURN_STR("CHECKOUT"); - case HTTP_METHOD_CHECKIN: SET_LEN_AND_RETURN_STR("CHECKIN"); - case HTTP_METHOD_VERSION_CONTROL: SET_LEN_AND_RETURN_STR("VERSION_CONTROL"); - case HTTP_METHOD_UNCHECKOUT: SET_LEN_AND_RETURN_STR("UNCHECKOUT"); - case HTTP_METHOD_MKACTIVITY: SET_LEN_AND_RETURN_STR("MKACTIVITY"); - case HTTP_METHOD_MERGE: SET_LEN_AND_RETURN_STR("MERGE"); - case HTTP_METHOD_LOCK: SET_LEN_AND_RETURN_STR("LOCK"); - case HTTP_METHOD_UNLOCK: SET_LEN_AND_RETURN_STR("UNLOCK"); - case HTTP_METHOD_LABEL: SET_LEN_AND_RETURN_STR("LABEL"); - case HTTP_METHOD_CONNECT: SET_LEN_AND_RETURN_STR("CONNECT"); + case LI_HTTP_METHOD_UNSET: SET_LEN_AND_RETURN_STR("UNKNOWN"); + case LI_HTTP_METHOD_GET: SET_LEN_AND_RETURN_STR("GET"); + case LI_HTTP_METHOD_POST: SET_LEN_AND_RETURN_STR("POST"); + case LI_HTTP_METHOD_HEAD: SET_LEN_AND_RETURN_STR("HEAD"); + case LI_HTTP_METHOD_OPTIONS: SET_LEN_AND_RETURN_STR("OPTIONS"); + case LI_HTTP_METHOD_PROPFIND: SET_LEN_AND_RETURN_STR("PROPFIND"); + case LI_HTTP_METHOD_MKCOL: SET_LEN_AND_RETURN_STR("MKCOL"); + case LI_HTTP_METHOD_PUT: SET_LEN_AND_RETURN_STR("PUT"); + case LI_HTTP_METHOD_DELETE: SET_LEN_AND_RETURN_STR("DELETE"); + case LI_HTTP_METHOD_COPY: SET_LEN_AND_RETURN_STR("COPY"); + case LI_HTTP_METHOD_MOVE: SET_LEN_AND_RETURN_STR("MOVE"); + case LI_HTTP_METHOD_PROPPATCH: SET_LEN_AND_RETURN_STR("PROPPATCH"); + case LI_HTTP_METHOD_REPORT: SET_LEN_AND_RETURN_STR("REPORT"); + case LI_HTTP_METHOD_CHECKOUT: SET_LEN_AND_RETURN_STR("CHECKOUT"); + case LI_HTTP_METHOD_CHECKIN: SET_LEN_AND_RETURN_STR("CHECKIN"); + case LI_HTTP_METHOD_VERSION_CONTROL: SET_LEN_AND_RETURN_STR("VERSION_CONTROL"); + case LI_HTTP_METHOD_UNCHECKOUT: SET_LEN_AND_RETURN_STR("UNCHECKOUT"); + case LI_HTTP_METHOD_MKACTIVITY: SET_LEN_AND_RETURN_STR("MKACTIVITY"); + case LI_HTTP_METHOD_MERGE: SET_LEN_AND_RETURN_STR("MERGE"); + case LI_HTTP_METHOD_LOCK: SET_LEN_AND_RETURN_STR("LOCK"); + case LI_HTTP_METHOD_UNLOCK: SET_LEN_AND_RETURN_STR("UNLOCK"); + case LI_HTTP_METHOD_LABEL: SET_LEN_AND_RETURN_STR("LABEL"); + case LI_HTTP_METHOD_CONNECT: SET_LEN_AND_RETURN_STR("CONNECT"); } *len = 0; return NULL; } -gchar *http_version_string(http_version_t method, guint *len) { +gchar *http_version_string(liHttpVersion method, guint *len) { switch (method) { - case HTTP_VERSION_1_1: SET_LEN_AND_RETURN_STR("HTTP/1.1"); - case HTTP_VERSION_1_0: SET_LEN_AND_RETURN_STR("HTTP/1.0"); - case HTTP_VERSION_UNSET: SET_LEN_AND_RETURN_STR("HTTP/??"); + case LI_HTTP_VERSION_1_1: SET_LEN_AND_RETURN_STR("HTTP/1.1"); + case LI_HTTP_VERSION_1_0: SET_LEN_AND_RETURN_STR("HTTP/1.0"); + case LI_HTTP_VERSION_UNSET: SET_LEN_AND_RETURN_STR("HTTP/??"); } *len = 0; @@ -128,25 +128,25 @@ void http_status_to_str(gint status_code, gchar status_str[]) { } -GString *mimetype_get(vrequest *vr, GString *filename) { +GString *mimetype_get(liVRequest *vr, GString *filename) { /* search in mime_types option for the first match */ GArray *arr; if (!vr || !filename || !filename->len) return NULL; - arr = CORE_OPTION(CORE_OPTION_MIME_TYPES).list; + arr = CORE_OPTION(LI_CORE_OPTION_MIME_TYPES).list; for (guint i = 0; i < arr->len; i++) { gint k, j; - value *tuple = g_array_index(arr, value*, i); - GString *ext = g_array_index(tuple->data.list, value*, 0)->data.string; + liValue *tuple = g_array_index(arr, liValue*, i); + GString *ext = g_array_index(tuple->data.list, liValue*, 0)->data.string; if (ext->len > filename->len) continue; /* "" extension matches everything, used for default mimetype */ if (!ext->len) - return g_array_index(tuple->data.list, value*, 1)->data.string; + return g_array_index(tuple->data.list, liValue*, 1)->data.string; k = filename->len - 1; j = ext->len - 1; @@ -157,7 +157,7 @@ GString *mimetype_get(vrequest *vr, GString *filename) { } if (j == -1) - return g_array_index(tuple->data.list, value*, 1)->data.string; + return g_array_index(tuple->data.list, liValue*, 1)->data.string; } return NULL; diff --git a/src/lighttpd.c b/src/lighttpd.c index 942da4e..3579e56 100644 --- a/src/lighttpd.c +++ b/src/lighttpd.c @@ -7,12 +7,12 @@ #include #endif -void plugin_core_init(server *srv, plugin *p); +void plugin_core_init(liServer *srv, liPlugin *p); int main(int argc, char *argv[]) { GError *error = NULL; GOptionContext *context; - server *srv; + liServer *srv; gboolean res; gboolean free_config_path = TRUE; @@ -94,14 +94,14 @@ int main(int argc, char *argv[]) { GTimeVal start, end; gulong s, millis, micros; guint64 d; - action *a; - config_parser_context_t *ctx; + liAction *a; + liConfigParserContext *ctx; g_get_current_time(&start); /* standard config frontend */ ctx_stack = config_parser_init(srv); - ctx = (config_parser_context_t*) ctx_stack->data; + ctx = (liConfigParserContext*) ctx_stack->data; if (!config_parser_file(srv, ctx_stack, config_path)) { config_parser_finish(srv, ctx_stack, TRUE); log_thread_start(srv); diff --git a/src/log.c b/src/log.c index c408f2b..7831a06 100644 --- a/src/log.c +++ b/src/log.c @@ -21,44 +21,44 @@ const char *remove_path(const char *path) { } #endif -void log_write(server *srv, log_t *log, GString *msg) { - log_entry_t *log_entry; +void log_write(liServer *srv, liLog *log, GString *msg) { + liLogEntry *log_entry; - if (g_atomic_int_get(&srv->state) == SERVER_STARTING) { + if (g_atomic_int_get(&srv->state) == LI_SERVER_STARTING) { angel_log(srv, msg); return; } log_ref(srv, log); - log_entry = g_slice_new(log_entry_t); + log_entry = g_slice_new(liLogEntry); log_entry->log = log; log_entry->msg = msg; g_async_queue_push(srv->logs.queue, log_entry); } -gboolean log_write_(server *srv, vrequest *vr, log_level_t log_level, guint flags, const gchar *fmt, ...) { +gboolean log_write_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, const gchar *fmt, ...) { va_list ap; GString *log_line; - log_t *log = NULL; - log_entry_t *log_entry; - log_timestamp_t *ts = NULL; + liLog *log = NULL; + liLogEntry *log_entry; + liLogTimestamp *ts = NULL; if (vr != NULL) { if (!srv) srv = vr->wrk->srv; /* get log from connection */ - log = g_array_index(CORE_OPTION(CORE_OPTION_LOG).list, log_t*, log_level); + log = g_array_index(CORE_OPTION(LI_CORE_OPTION_LOG).list, liLog*, log_level); if (log == NULL) return TRUE; - ts = CORE_OPTION(CORE_OPTION_LOG_TS_FORMAT).ptr; + ts = CORE_OPTION(LI_CORE_OPTION_LOG_TS_FORMAT).ptr; if (!ts) - ts = g_array_index(srv->logs.timestamps, log_timestamp_t*, 0); + ts = g_array_index(srv->logs.timestamps, liLogTimestamp*, 0); } else { log = srv->logs.stderr; - ts = g_array_index(srv->logs.timestamps, log_timestamp_t*, 0); + ts = g_array_index(srv->logs.timestamps, liLogTimestamp*, 0); } log_ref(srv, log); @@ -126,12 +126,12 @@ gboolean log_write_(server *srv, vrequest *vr, log_level_t log_level, guint flag g_string_append_len(log_line, CONST_STR_LEN("\r\n")); - if (g_atomic_int_get(&srv->state) == SERVER_STARTING) { + if (g_atomic_int_get(&srv->state) == LI_SERVER_STARTING) { log_unref(srv, log); angel_log(srv, log_line); return TRUE; } - log_entry = g_slice_new(log_entry_t); + log_entry = g_slice_new(liLogEntry); log_entry->log = log; log_entry->msg = log_line; log_entry->level = log_level; @@ -139,7 +139,7 @@ gboolean log_write_(server *srv, vrequest *vr, log_level_t log_level, guint flag g_async_queue_push(srv->logs.queue, log_entry); /* on critical error, exit */ - if (log_level == LOG_LEVEL_ABORT) { + if (log_level == LI_LOG_LEVEL_ABORT) { log_thread_stop(srv); g_atomic_int_set(&srv->exiting, TRUE); } @@ -148,10 +148,10 @@ gboolean log_write_(server *srv, vrequest *vr, log_level_t log_level, guint flag } -gpointer log_thread(server *srv) { +gpointer log_thread(liServer *srv) { GAsyncQueue *queue; - log_t *log; - log_entry_t *log_entry; + liLog *log; + liLogEntry *log_entry; GString *msg; gssize bytes_written; gssize write_res; @@ -179,7 +179,7 @@ gpointer log_thread(server *srv) { /* if log_entry->log is NULL, it means that the logger thread has been woken up probably because it should exit */ if (log_entry->log == NULL) { - g_slice_free(log_entry_t, log_entry); + g_slice_free(liLogEntry, log_entry); continue; } @@ -209,17 +209,17 @@ gpointer log_thread(server *srv) { } g_string_free(msg, TRUE); - g_slice_free(log_entry_t, log_entry); + g_slice_free(liLogEntry, log_entry); log_unref(srv, log); } return NULL; } -void log_rotate(gchar * path, log_t *log, server * UNUSED_PARAM(srv)) { +void log_rotate(gchar * path, liLog *log, liServer * UNUSED_PARAM(srv)) { switch (log->type) { - case LOG_TYPE_FILE: + case LI_LOG_TYPE_FILE: close(log->fd); log->fd = open(log->path->str, O_RDWR | O_CREAT | O_APPEND, 0660); if (log->fd == -1) { @@ -227,11 +227,11 @@ void log_rotate(gchar * path, log_t *log, server * UNUSED_PARAM(srv)) { assert(NULL); /* TODO */ } break; - case LOG_TYPE_STDERR: + case LI_LOG_TYPE_STDERR: break; - case LOG_TYPE_PIPE: - case LOG_TYPE_SYSLOG: - case LOG_TYPE_NONE: + case LI_LOG_TYPE_PIPE: + case LI_LOG_TYPE_SYSLOG: + case LI_LOG_TYPE_NONE: /* TODO */ assert(NULL); } @@ -240,19 +240,19 @@ void log_rotate(gchar * path, log_t *log, server * UNUSED_PARAM(srv)) { log->lastmsg_count = 0; } -void log_rotate_logs(server *srv) { +void log_rotate_logs(liServer *srv) { UNUSED(srv); /*g_atomic_int_set(&srv->rotate_logs, TRUE);*/ } -void log_ref(server *srv, log_t *log) { +void log_ref(liServer *srv, liLog *log) { UNUSED(srv); g_atomic_int_inc(&log->refcount); } -void log_unref(server *srv, log_t *log) { +void log_unref(liServer *srv, liLog *log) { g_mutex_lock(srv->logs.mutex); if (g_atomic_int_dec_and_test(&log->refcount)) @@ -261,71 +261,71 @@ void log_unref(server *srv, log_t *log) { g_mutex_unlock(srv->logs.mutex); } -log_type_t log_type_from_path(GString *path) { +liLogType log_type_from_path(GString *path) { if (path->len == 0) - return LOG_TYPE_NONE; + return LI_LOG_TYPE_NONE; /* look for scheme:// paths */ if (g_str_has_prefix(path->str, "file://")) - return LOG_TYPE_FILE; + return LI_LOG_TYPE_FILE; if (g_str_has_prefix(path->str, "pipe://")) - return LOG_TYPE_PIPE; + return LI_LOG_TYPE_PIPE; if (g_str_has_prefix(path->str, "stderr://")) - return LOG_TYPE_STDERR; + return LI_LOG_TYPE_STDERR; if (g_str_has_prefix(path->str, "syslog://")) - return LOG_TYPE_SYSLOG; + return LI_LOG_TYPE_SYSLOG; /* targets starting with a slash are absolute paths and therefor file targets */ if (*path->str == '/') - return LOG_TYPE_FILE; + return LI_LOG_TYPE_FILE; /* targets starting with a pipe are ... pipes! */ if (*path->str == '|') - return LOG_TYPE_PIPE; + return LI_LOG_TYPE_PIPE; if (g_str_equal(path->str, "stderr")) - return LOG_TYPE_STDERR; + return LI_LOG_TYPE_STDERR; if (g_str_equal(path->str, "syslog")) - return LOG_TYPE_SYSLOG; + return LI_LOG_TYPE_SYSLOG; /* fall back to stderr */ - return LOG_TYPE_STDERR; + return LI_LOG_TYPE_STDERR; } -log_level_t log_level_from_string(GString *str) { +liLogLevel log_level_from_string(GString *str) { if (g_str_equal(str->str, "debug")) - return LOG_LEVEL_DEBUG; + return LI_LOG_LEVEL_DEBUG; if (g_str_equal(str->str, "info")) - return LOG_LEVEL_INFO; + return LI_LOG_LEVEL_INFO; if (g_str_equal(str->str, "warning")) - return LOG_LEVEL_WARNING; + return LI_LOG_LEVEL_WARNING; if (g_str_equal(str->str, "error")) - return LOG_LEVEL_ERROR; + return LI_LOG_LEVEL_ERROR; if (g_str_equal(str->str, "backend")) - return LOG_LEVEL_BACKEND; + return LI_LOG_LEVEL_BACKEND; /* fall back to debug level */ - return LOG_LEVEL_DEBUG; + return LI_LOG_LEVEL_DEBUG; } -gchar* log_level_str(log_level_t log_level) { +gchar* log_level_str(liLogLevel log_level) { switch (log_level) { - case LOG_LEVEL_DEBUG: return "debug"; - case LOG_LEVEL_INFO: return "info"; - case LOG_LEVEL_WARNING: return "warning"; - case LOG_LEVEL_ERROR: return "error"; - case LOG_LEVEL_BACKEND: return "backend"; + case LI_LOG_LEVEL_DEBUG: return "debug"; + case LI_LOG_LEVEL_INFO: return "info"; + case LI_LOG_LEVEL_WARNING: return "warning"; + case LI_LOG_LEVEL_ERROR: return "error"; + case LI_LOG_LEVEL_BACKEND: return "backend"; default: return "unknown"; } } -log_t *log_new(server *srv, log_type_t type, GString *path) { - log_t *log; +liLog *log_new(liServer *srv, liLogType type, GString *path) { + liLog *log; gint fd = -1; - if (type == LOG_TYPE_NONE) + if (type == LI_LOG_TYPE_NONE) return NULL; g_mutex_lock(srv->logs.mutex); @@ -340,15 +340,15 @@ log_t *log_new(server *srv, log_type_t type, GString *path) { } switch (type) { - case LOG_TYPE_STDERR: + case LI_LOG_TYPE_STDERR: fd = STDERR_FILENO; break; - case LOG_TYPE_FILE: + case LI_LOG_TYPE_FILE: fd = open(path->str, O_RDWR | O_CREAT | O_APPEND, 0660); break; - case LOG_TYPE_PIPE: - case LOG_TYPE_SYSLOG: - case LOG_TYPE_NONE: + case LI_LOG_TYPE_PIPE: + case LI_LOG_TYPE_SYSLOG: + case LI_LOG_TYPE_NONE: /* TODO */ fd = -1; assert(NULL); @@ -359,7 +359,7 @@ log_t *log_new(server *srv, log_type_t type, GString *path) { return NULL; } - log = g_slice_new0(log_t); + log = g_slice_new0(liLog); log->lastmsg = g_string_sized_new(0); log->fd = fd; log->path = g_string_new_len(GSTR_LEN(path)); @@ -374,15 +374,15 @@ log_t *log_new(server *srv, log_type_t type, GString *path) { } /* only call this if srv->logs.mutex is NOT locked */ -void log_free(server *srv, log_t *log) { +void log_free(liServer *srv, liLog *log) { g_mutex_lock(srv->logs.mutex); log_free_unlocked(srv, log); g_mutex_unlock(srv->logs.mutex); } /* only call this if srv->log_mutex IS locked */ -void log_free_unlocked(server *srv, log_t *log) { - if (log->type == LOG_TYPE_FILE || log->type == LOG_TYPE_PIPE) +void log_free_unlocked(liServer *srv, liLog *log) { + if (log->type == LI_LOG_TYPE_FILE || log->type == LI_LOG_TYPE_PIPE) close(log->fd); g_hash_table_remove(srv->logs.targets, log->path); @@ -391,16 +391,16 @@ void log_free_unlocked(server *srv, log_t *log) { g_mutex_free(log->mutex); - g_slice_free(log_t, log); + g_slice_free(liLog, log); } -void log_init(server *srv) { +void log_init(liServer *srv) { GString *str; srv->logs.targets = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); srv->logs.queue = g_async_queue_new(); srv->logs.mutex = g_mutex_new(); - srv->logs.timestamps = g_array_new(FALSE, FALSE, sizeof(log_timestamp_t*)); + srv->logs.timestamps = g_array_new(FALSE, FALSE, sizeof(liLogTimestamp*)); srv->logs.thread_alive = FALSE; /* first entry in srv->logs.timestamps is the default timestamp */ @@ -408,13 +408,13 @@ void log_init(server *srv) { /* first entry in srv->logs.targets is the plain good old stderr */ str = g_string_new_len(CONST_STR_LEN("stderr")); - srv->logs.stderr = log_new(srv, LOG_TYPE_STDERR, str); + srv->logs.stderr = log_new(srv, LI_LOG_TYPE_STDERR, str); g_string_free(str, TRUE); } -void log_cleanup(server *srv) { +void log_cleanup(liServer *srv) { guint i; - log_timestamp_t *ts; + liLogTimestamp *ts; /* wait for logging thread to exit */ if (g_atomic_int_get(&srv->logs.thread_alive) == TRUE) @@ -430,7 +430,7 @@ void log_cleanup(server *srv) { g_async_queue_unref(srv->logs.queue); for (i = 0; i < srv->logs.timestamps->len; i++) { - ts = g_array_index(srv->logs.timestamps, log_timestamp_t*, i); + ts = g_array_index(srv->logs.timestamps, liLogTimestamp*, i); g_print("ts #%d refcount: %d\n", i, ts->refcount); /*if (g_atomic_int_dec_and_test(&ts->refcount)) { g_string_free(ts->cached, TRUE); @@ -441,12 +441,12 @@ void log_cleanup(server *srv) { }*/ } - log_timestamp_free(srv, g_array_index(srv->logs.timestamps, log_timestamp_t*, 0)); + log_timestamp_free(srv, g_array_index(srv->logs.timestamps, liLogTimestamp*, 0)); g_array_free(srv->logs.timestamps, TRUE); } -void log_thread_start(server *srv) { +void log_thread_start(liServer *srv) { GError *err = NULL; srv->logs.thread = g_thread_create((GThreadFunc)log_thread, srv, TRUE, &err); @@ -459,46 +459,46 @@ void log_thread_start(server *srv) { } } -void log_thread_stop(server *srv) { +void log_thread_stop(liServer *srv) { if (g_atomic_int_get(&srv->logs.thread_alive) == TRUE) { g_atomic_int_set(&srv->logs.thread_stop, TRUE); log_thread_wakeup(srv); } } -void log_thread_finish(server *srv) { +void log_thread_finish(liServer *srv) { if (g_atomic_int_get(&srv->logs.thread_alive) == TRUE) { g_atomic_int_set(&srv->logs.thread_finish, TRUE); log_thread_wakeup(srv); } } -void log_thread_wakeup(server *srv) { - log_entry_t *e; +void log_thread_wakeup(liServer *srv) { + liLogEntry *e; if (!g_atomic_int_get(&srv->logs.thread_alive)) log_thread_start(srv); - e = g_slice_new0(log_entry_t); + e = g_slice_new0(liLogEntry); g_async_queue_push(srv->logs.queue, e); } -void log_lock(log_t *log) { +void log_lock(liLog *log) { g_mutex_lock(log->mutex); } -void log_unlock(log_t *log) { +void log_unlock(liLog *log) { g_mutex_unlock(log->mutex); } -log_timestamp_t *log_timestamp_new(server *srv, GString *format) { - log_timestamp_t *ts; +liLogTimestamp *log_timestamp_new(liServer *srv, GString *format) { + liLogTimestamp *ts; /* check if there already exists a timestamp entry with the same format */ for (guint i = 0; i < srv->logs.timestamps->len; i++) { - ts = g_array_index(srv->logs.timestamps, log_timestamp_t*, i); + ts = g_array_index(srv->logs.timestamps, liLogTimestamp*, i); if (g_string_equal(ts->format, format)) { g_atomic_int_inc(&(ts->refcount)); g_string_free(format, TRUE); @@ -506,7 +506,7 @@ log_timestamp_t *log_timestamp_new(server *srv, GString *format) { } } - ts = g_slice_new(log_timestamp_t); + ts = g_slice_new(liLogTimestamp); ts->cached = g_string_sized_new(0); ts->last_ts = 0; @@ -518,24 +518,24 @@ log_timestamp_t *log_timestamp_new(server *srv, GString *format) { return ts; } -gboolean log_timestamp_free(server *srv, log_timestamp_t *ts) { +gboolean log_timestamp_free(liServer *srv, liLogTimestamp *ts) { if (g_atomic_int_dec_and_test(&(ts->refcount))) { for (guint i = 0; i < srv->logs.timestamps->len; i++) { - if (g_string_equal(g_array_index(srv->logs.timestamps, log_timestamp_t*, i)->format, ts->format)) { + if (g_string_equal(g_array_index(srv->logs.timestamps, liLogTimestamp*, i)->format, ts->format)) { g_array_remove_index_fast(srv->logs.timestamps, i); break; } } g_string_free(ts->cached, TRUE); g_string_free(ts->format, TRUE); - g_slice_free(log_timestamp_t, ts); + g_slice_free(liLogTimestamp, ts); return TRUE; } return FALSE; } -void log_split_lines(server *srv, vrequest *vr, log_level_t log_level, guint flags, gchar *txt, const gchar *prefix) { +void log_split_lines(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, gchar *txt, const gchar *prefix) { gchar *start; start = txt; @@ -557,7 +557,7 @@ void log_split_lines(server *srv, vrequest *vr, log_level_t log_level, guint fla } } -void log_split_lines_(server *srv, vrequest *vr, log_level_t log_level, guint flags, gchar *txt, const gchar *fmt, ...) { +void log_split_lines_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, gchar *txt, const gchar *fmt, ...) { va_list ap; GString *prefix; diff --git a/src/module.c b/src/module.c index d049c92..a64e13c 100644 --- a/src/module.c +++ b/src/module.c @@ -1,24 +1,24 @@ #include -modules *modules_new(gpointer main, const gchar *module_dir) { - modules *m = g_slice_new(modules); +liModules *modules_new(gpointer main, const gchar *module_dir) { + liModules *m = g_slice_new(liModules); m->version = MODULE_VERSION; m->main = main; - m->mods = g_array_new(FALSE, TRUE, sizeof(module*)); + m->mods = g_array_new(FALSE, TRUE, sizeof(liModule*)); m->module_dir = g_strdup(module_dir); m->sizeof_off_t = sizeof(off_t); return m; } -module *module_lookup(modules *mods, const gchar *name) { - module *mod; +liModule *module_lookup(liModules *mods, const gchar *name) { + liModule *mod; GArray *a = mods->mods; for (guint i = 0; i < a->len; i++) { - mod = g_array_index(a, module*, i); + mod = g_array_index(a, liModule*, i); if (mod != NULL && g_str_equal(mod->name->str, name)) return mod; } @@ -26,13 +26,13 @@ module *module_lookup(modules *mods, const gchar *name) { return NULL; } -void modules_free(modules* mods) { +void modules_free(liModules* mods) { /* unload all modules */ GArray *a = mods->mods; - module *mod; + liModule *mod; for (guint i = 0; i < a->len; i++) { - mod = g_array_index(a, module*, i); + mod = g_array_index(a, liModule*, i); if (!mod) continue; module_release(mods, mod); @@ -40,13 +40,13 @@ void modules_free(modules* mods) { g_array_free(mods->mods, TRUE); g_free(mods->module_dir); - g_slice_free(modules, mods); + g_slice_free(liModules, mods); } -module* module_load(modules *mods, const gchar* name) { - module *mod; - ModuleInit m_init; +liModule* module_load(liModules *mods, const gchar* name) { + liModule *mod; + liModuleInitCB m_init; GString *m_init_str, *m_free_str; guint i; @@ -58,7 +58,7 @@ module* module_load(modules *mods, const gchar* name) { return mod; } - mod = g_slice_new0(module); + mod = g_slice_new0(liModule); mod->name = g_string_new(name); mod->refcount = 1; mod->path = g_module_build_path(mods->module_dir, name); @@ -68,7 +68,7 @@ module* module_load(modules *mods, const gchar* name) { if (!mod->module) { g_string_free(mod->name, TRUE); g_free(mod->path); - g_slice_free(module, mod); + g_slice_free(liModule, mod); return NULL; } @@ -87,7 +87,7 @@ module* module_load(modules *mods, const gchar* name) { g_string_free(m_free_str, TRUE); g_free(mod->path); g_string_free(mod->name, TRUE); - g_slice_free(module, mod); + g_slice_free(liModule, mod); return NULL; } @@ -97,15 +97,15 @@ module* module_load(modules *mods, const gchar* name) { g_string_free(m_free_str, TRUE); g_free(mod->path); g_string_free(mod->name, TRUE); - g_slice_free(module, mod); + g_slice_free(liModule, mod); return NULL; } /* insert into free slot */ for (i = 0; i < mods->mods->len; i++) { - if (!g_array_index(mods->mods, module*, i)) + if (!g_array_index(mods->mods, liModule*, i)) { - g_array_index(mods->mods, module*, i) = mod; + g_array_index(mods->mods, liModule*, i) = mod; break; } } @@ -121,16 +121,16 @@ module* module_load(modules *mods, const gchar* name) { return mod; } -void module_release(modules *mods, module *mod) { +void module_release(liModules *mods, liModule *mod) { guint i; if (--mod->refcount > 0) return; for (i = 0; i < mods->mods->len; i++) { - if (g_array_index(mods->mods, module*, i) == mod) + if (g_array_index(mods->mods, liModule*, i) == mod) { - g_array_index(mods->mods, module*, i) = NULL; + g_array_index(mods->mods, liModule*, i) = NULL; break; } } @@ -139,11 +139,11 @@ void module_release(modules *mods, module *mod) { g_module_close(mod->module); g_free(mod->path); g_string_free(mod->name, TRUE); - g_slice_free(module, mod); + g_slice_free(liModule, mod); } -void module_release_name(modules *mods, const gchar* name) { - module *mod = module_lookup(mods, name); +void module_release_name(liModules *mods, const gchar* name) { + liModule *mod = module_lookup(mods, name); if (mod) module_release(mods, mod); diff --git a/src/modules/mod_access.c b/src/modules/mod_access.c index f87b828..40e5a16 100644 --- a/src/modules/mod_access.c +++ b/src/modules/mod_access.c @@ -47,19 +47,19 @@ #include #include -LI_API gboolean mod_access_init(modules *mods, module *mod); -LI_API gboolean mod_access_free(modules *mods, module *mod); +LI_API gboolean mod_access_init(liModules *mods, liModule *mod); +LI_API gboolean mod_access_free(liModules *mods, liModule *mod); struct access_check_data { - plugin *p; - RadixTree32 *ipv4; + liPlugin *p; + liRadixTree32 *ipv4; }; typedef struct access_check_data access_check_data; -static handler_t access_check(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult access_check(liVRequest *vr, gpointer param, gpointer *context) { access_check_data *acd = param; - sock_addr *addr = vr->con->remote_addr.addr; + liSockAddr *addr = vr->con->remote_addr.addr; gboolean log_blocked = _OPTION(vr, acd->p, 0).boolean; GString *redirect_url = _OPTION(vr, acd->p, 1).string; @@ -77,16 +77,16 @@ static handler_t access_check(vrequest *vr, gpointer param, gpointer *context) { } } else if (addr->plain.sa_family == AF_INET6) { VR_ERROR(vr, "%s", "access.check doesn't support ipv6 clients yet"); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } else { VR_ERROR(vr, "%s", "access.check only supports ipv4 or ipv6 clients"); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static void access_check_free(server *srv, gpointer param) { +static void access_check_free(liServer *srv, gpointer param) { access_check_data *acd = param; UNUSED(srv); @@ -95,9 +95,9 @@ static void access_check_free(server *srv, gpointer param) { g_slice_free(access_check_data, acd); } -static action* access_check_create(server *srv, plugin* p, value *val) { +static liAction* access_check_create(liServer *srv, liPlugin* p, liValue *val) { GArray *arr; - value *v, *ip; + liValue *v, *ip; guint i, j; guint32 ipv4, netmaskv4; gboolean deny = FALSE; @@ -106,7 +106,7 @@ static action* access_check_create(server *srv, plugin* p, value *val) { UNUSED(srv); - if (!val || val->type != VALUE_LIST || (val->data.list->len != 1 && val->data.list->len != 2)) { + if (!val || val->type != LI_VALUE_LIST || (val->data.list->len != 1 && val->data.list->len != 2)) { ERROR(srv, "%s", "access_check expects a list of one or two string,list tuples as parameter"); return NULL; } @@ -118,18 +118,18 @@ static action* access_check_create(server *srv, plugin* p, value *val) { acd->ipv4 = radixtree32_new(2); for (i = 0; i < arr->len; i++) { - v = g_array_index(arr, value*, i); + v = g_array_index(arr, liValue*, i); - if (v->type != VALUE_LIST || v->data.list->len != 2) { + if (v->type != LI_VALUE_LIST || v->data.list->len != 2) { ERROR(srv, "%s", "access_check expects a list of one or two string,list tuples as parameter"); radixtree32_free(acd->ipv4); g_slice_free(access_check_data, acd); return NULL; } - v = g_array_index(v->data.list, value*, 0); + v = g_array_index(v->data.list, liValue*, 0); - if (v->type != VALUE_STRING) { + if (v->type != LI_VALUE_STRING) { ERROR(srv, "%s", "access_check expects a list of one or two string,list tuples as parameter"); radixtree32_free(acd->ipv4); g_slice_free(access_check_data, acd); @@ -148,9 +148,9 @@ static action* access_check_create(server *srv, plugin* p, value *val) { return NULL; } - v = g_array_index(g_array_index(arr, value*, i)->data.list, value*, 1); + v = g_array_index(g_array_index(arr, liValue*, i)->data.list, liValue*, 1); - if (v->type != VALUE_LIST) { + if (v->type != LI_VALUE_LIST) { ERROR(srv, "%s", "access_check expects a list of one or two string,list tuples as parameter"); radixtree32_free(acd->ipv4); g_slice_free(access_check_data, acd); @@ -158,9 +158,9 @@ static action* access_check_create(server *srv, plugin* p, value *val) { } for (j = 0; j < v->data.list->len; j++) { - ip = g_array_index(v->data.list, value*, j); + ip = g_array_index(v->data.list, liValue*, j); - if (ip->type != VALUE_STRING) { + if (ip->type != LI_VALUE_STRING) { ERROR(srv, "%s", "access_check expects a list of one or two string,list tuples as parameter"); radixtree32_free(acd->ipv4); g_slice_free(access_check_data, acd); @@ -189,9 +189,9 @@ static action* access_check_create(server *srv, plugin* p, value *val) { } -static handler_t access_deny(vrequest *vr, gpointer param, gpointer *context) { - gboolean log_blocked = _OPTION(vr, ((plugin*)param), 0).boolean; - GString *redirect_url = _OPTION(vr, ((plugin*)param), 1).string; +static liHandlerResult access_deny(liVRequest *vr, gpointer param, gpointer *context) { + gboolean log_blocked = _OPTION(vr, ((liPlugin*)param), 0).boolean; + GString *redirect_url = _OPTION(vr, ((liPlugin*)param), 1).string; UNUSED(context); UNUSED(redirect_url); @@ -203,10 +203,10 @@ static handler_t access_deny(vrequest *vr, gpointer param, gpointer *context) { VR_INFO(vr, "access.deny: blocked %s", vr->con->remote_addr_str->str); } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* access_deny_create(server *srv, plugin* p, value *val) { +static liAction* access_deny_create(liServer *srv, liPlugin* p, liValue *val) { UNUSED(srv); @@ -219,26 +219,26 @@ static action* access_deny_create(server *srv, plugin* p, value *val) { } -static const plugin_option options[] = { - { "access.log_blocked", VALUE_BOOLEAN, NULL, NULL, NULL }, - { "access.redirect_url", VALUE_STRING, NULL, NULL, NULL }, +static const liPluginOption options[] = { + { "access.log_blocked", LI_VALUE_BOOLEAN, NULL, NULL, NULL }, + { "access.redirect_url", LI_VALUE_STRING, NULL, NULL, NULL }, { NULL, 0, NULL, NULL, NULL } }; -static const plugin_action actions[] = { +static const liPluginAction actions[] = { { "access.check", access_check_create }, { "access.deny", access_deny_create }, { NULL, NULL } }; -static const plugin_setup setups[] = { +static const liliPluginSetupCB setups[] = { { NULL, NULL } }; -static void plugin_access_init(server *srv, plugin *p) { +static void plugin_access_init(liServer *srv, liPlugin *p) { UNUSED(srv); p->options = options; @@ -247,7 +247,7 @@ static void plugin_access_init(server *srv, plugin *p) { } -gboolean mod_access_init(modules *mods, module *mod) { +gboolean mod_access_init(liModules *mods, liModule *mod) { UNUSED(mod); MODULE_VERSION_CHECK(mods); @@ -257,7 +257,7 @@ gboolean mod_access_init(modules *mods, module *mod) { return mod->config != NULL; } -gboolean mod_access_free(modules *mods, module *mod) { +gboolean mod_access_free(liModules *mods, liModule *mod) { if (mod->config) plugin_free(mods->main, mod->config); diff --git a/src/modules/mod_accesslog.c b/src/modules/mod_accesslog.c index 4e82065..406e929 100644 --- a/src/modules/mod_accesslog.c +++ b/src/modules/mod_accesslog.c @@ -32,8 +32,8 @@ #include #include -LI_API gboolean mod_accesslog_init(modules *mods, module *mod); -LI_API gboolean mod_accesslog_free(modules *mods, module *mod); +LI_API gboolean mod_accesslog_init(liModules *mods, liModule *mod); +LI_API gboolean mod_accesslog_free(liModules *mods, liModule *mod); struct al_data { guint ts_ndx_gmtime; @@ -169,7 +169,7 @@ static al_format al_get_format(gchar c) { return NULL; \ } while (0) -static GArray *al_parse_format(server *srv, GString *formatstr) { +static GArray *al_parse_format(liServer *srv, GString *formatstr) { GArray *arr = g_array_new(FALSE, TRUE, sizeof(al_format_entry)); al_format_entry e; gchar *c, *k; @@ -218,12 +218,12 @@ static GArray *al_parse_format(server *srv, GString *formatstr) { return arr; } -static GString *al_format_log(connection *con, al_data *ald, GArray *format) { +static GString *al_format_log(liConnection *con, al_data *ald, GArray *format) { GString *str = g_string_sized_new(255); - vrequest *vr = con->mainvr; - response *resp = &vr->response; - request *req = &vr->request; - physical *phys = &vr->physical; + liVRequest *vr = con->mainvr; + liResponse *resp = &vr->response; + liRequest *req = &vr->request; + liPhysical *phys = &vr->physical; gchar *tmp_str = NULL; GString *tmp_gstr = g_string_sized_new(127); GString *tmp_gstr2; @@ -315,10 +315,10 @@ static GString *al_format_log(connection *con, al_data *ald, GArray *format) { g_string_append_len(str, GSTR_LEN(req->uri.path)); break; case AL_FORMAT_SERVER_NAME: - if (CORE_OPTION(CORE_OPTION_LOG).string) + if (CORE_OPTION(LI_CORE_OPTION_LOG).string) g_string_append_len(str, GSTR_LEN(req->uri.host)); else - g_string_append_len(str, GSTR_LEN(CORE_OPTION(CORE_OPTION_SERVER_NAME).string)); + g_string_append_len(str, GSTR_LEN(CORE_OPTION(LI_CORE_OPTION_SERVER_NAME).string)); break; case AL_FORMAT_HOSTNAME: if (req->uri.host->len) @@ -361,11 +361,11 @@ static GString *al_format_log(connection *con, al_data *ald, GArray *format) { return str; } -static void al_handle_close(connection *con, plugin *p) { +static void al_handle_close(liConnection *con, liPlugin *p) { /* connection closed, log it */ GString *msg; - response *resp = &con->mainvr->response; - log_t *log = _OPTION(con->mainvr, p, AL_OPTION_ACCESSLOG).ptr; + liResponse *resp = &con->mainvr->response; + liLog *log = _OPTION(con->mainvr, p, AL_OPTION_ACCESSLOG).ptr; GArray *format = _OPTION(con->mainvr, p, AL_OPTION_ACCESSLOG_FORMAT).list; UNUSED(p); @@ -382,7 +382,7 @@ static void al_handle_close(connection *con, plugin *p) { -static void al_option_accesslog_free(server *srv, plugin *p, size_t ndx, option_value oval) { +static void al_option_accesslog_free(liServer *srv, liPlugin *p, size_t ndx, liOptionValue oval) { UNUSED(p); UNUSED(ndx); @@ -391,8 +391,8 @@ static void al_option_accesslog_free(server *srv, plugin *p, size_t ndx, option_ log_free(srv, oval.ptr); } -static gboolean al_option_accesslog_parse(server *srv, plugin *p, size_t ndx, value *val, option_value *oval) { - log_t *log; +static gboolean al_option_accesslog_parse(liServer *srv, liPlugin *p, size_t ndx, liValue *val, liOptionValue *oval) { + liLog *log; UNUSED(p); UNUSED(ndx); @@ -409,7 +409,7 @@ static gboolean al_option_accesslog_parse(server *srv, plugin *p, size_t ndx, va return TRUE; } -static void al_option_accesslog_format_free(server *srv, plugin *p, size_t ndx, option_value oval) { +static void al_option_accesslog_format_free(liServer *srv, liPlugin *p, size_t ndx, liOptionValue oval) { GArray *arr; UNUSED(srv); @@ -429,7 +429,7 @@ static void al_option_accesslog_format_free(server *srv, plugin *p, size_t ndx, g_array_free(arr, TRUE); } -static gboolean al_option_accesslog_format_parse(server *srv, plugin *p, size_t ndx, value *val, option_value *oval) { +static gboolean al_option_accesslog_format_parse(liServer *srv, liPlugin *p, size_t ndx, liValue *val, liOptionValue *oval) { GArray *arr; UNUSED(p); @@ -453,29 +453,29 @@ static gboolean al_option_accesslog_format_parse(server *srv, plugin *p, size_t } -static const plugin_option options[] = { - { "accesslog", VALUE_NONE, NULL, al_option_accesslog_parse, al_option_accesslog_free }, - { "accesslog.format", VALUE_STRING, NULL, al_option_accesslog_format_parse, al_option_accesslog_format_free }, +static const liPluginOption options[] = { + { "accesslog", LI_VALUE_NONE, NULL, al_option_accesslog_parse, al_option_accesslog_free }, + { "accesslog.format", LI_VALUE_STRING, NULL, al_option_accesslog_format_parse, al_option_accesslog_format_free }, { NULL, 0, NULL, NULL, NULL } }; -static const plugin_action actions[] = { +static const liPluginAction actions[] = { { NULL, NULL } }; -static const plugin_setup setups[] = { +static const liliPluginSetupCB setups[] = { { NULL, NULL } }; -static void plugin_accesslog_free(server *srv, plugin *p) { +static void plugin_accesslog_free(liServer *srv, liPlugin *p) { UNUSED(srv); g_slice_free(al_data, p->data); } -static void plugin_accesslog_init(server *srv, plugin *p) { +static void plugin_accesslog_init(liServer *srv, liPlugin *p) { al_data *ald; UNUSED(srv); @@ -491,7 +491,7 @@ static void plugin_accesslog_init(server *srv, plugin *p) { p->data = ald; } -LI_API gboolean mod_accesslog_init(modules *mods, module *mod) { +LI_API gboolean mod_accesslog_init(liModules *mods, liModule *mod) { UNUSED(mod); MODULE_VERSION_CHECK(mods); @@ -501,7 +501,7 @@ LI_API gboolean mod_accesslog_init(modules *mods, module *mod) { return mod->config != NULL; } -LI_API gboolean mod_accesslog_free(modules *mods, module *mod) { +LI_API gboolean mod_accesslog_free(liModules *mods, liModule *mod) { UNUSED(mods); UNUSED(mod); if (mod->config) diff --git a/src/modules/mod_balancer.c b/src/modules/mod_balancer.c index 62f49ea..beea8fa 100644 --- a/src/modules/mod_balancer.c +++ b/src/modules/mod_balancer.c @@ -1,8 +1,8 @@ #include -LI_API gboolean mod_balancer_init(modules *mods, module *mod); -LI_API gboolean mod_balancer_free(modules *mods, module *mod); +LI_API gboolean mod_balancer_init(liModules *mods, liModule *mod); +LI_API gboolean mod_balancer_free(liModules *mods, liModule *mod); typedef enum { BE_ALIVE, @@ -18,7 +18,7 @@ typedef enum { } balancer_state; struct backend { - action *act; + liAction *act; guint load; backend_state state; }; @@ -37,7 +37,7 @@ static balancer* balancer_new() { return b; } -static void balancer_free(server *srv, balancer *b) { +static void balancer_free(liServer *srv, balancer *b) { guint i; if (!b) return; for (i = 0; i < b->backends->len; i++) { @@ -48,22 +48,22 @@ static void balancer_free(server *srv, balancer *b) { g_slice_free(balancer, b); } -static gboolean balancer_fill_backends(balancer *b, server *srv, value *val) { - if (val->type == VALUE_ACTION) { +static gboolean balancer_fill_backends(balancer *b, liServer *srv, liValue *val) { + if (val->type == LI_VALUE_ACTION) { backend be = { val->data.val_action.action, 0, BE_ALIVE }; assert(srv == val->data.val_action.srv); action_acquire(be.act); g_array_append_val(b->backends, be); return TRUE; - } else if (val->type == VALUE_LIST) { + } else if (val->type == LI_VALUE_LIST) { guint i; if (val->data.list->len == 0) { ERROR(srv, "%s", "expected non-empty list"); return FALSE; } for (i = 0; i < val->data.list->len; i++) { - value *oa = g_array_index(val->data.list, value*, i); - if (oa->type != VALUE_ACTION) { + liValue *oa = g_array_index(val->data.list, liValue*, i); + if (oa->type != LI_VALUE_ACTION) { ERROR(srv, "expected action at entry %u of list, got %s", i, value_type_string(oa->type)); return FALSE; } @@ -81,7 +81,7 @@ static gboolean balancer_fill_backends(balancer *b, server *srv, value *val) { } } -static handler_t balancer_act_select(vrequest *vr, gboolean backlog_provided, gpointer param, gpointer *context) { +static liHandlerResult balancer_act_select(liVRequest *vr, gboolean backlog_provided, gpointer param, gpointer *context) { balancer *b = (balancer*) param; gint be_ndx = 0; backend *be = &g_array_index(b->backends, backend, be_ndx); @@ -94,10 +94,10 @@ static handler_t balancer_act_select(vrequest *vr, gboolean backlog_provided, gp action_enter(vr, be->act); *context = GINT_TO_POINTER(be_ndx); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static handler_t balancer_act_fallback(vrequest *vr, gboolean backlog_provided, gpointer param, gpointer *context, backend_error error) { +static liHandlerResult balancer_act_fallback(liVRequest *vr, gboolean backlog_provided, gpointer param, gpointer *context, liBackendError error) { balancer *b = (balancer*) param; gint be_ndx = GPOINTER_TO_INT(*context); backend *be = &g_array_index(b->backends, backend, be_ndx); @@ -105,38 +105,38 @@ static handler_t balancer_act_fallback(vrequest *vr, gboolean backlog_provided, UNUSED(backlog_provided); UNUSED(error); - if (be_ndx < 0) return HANDLER_GO_ON; + if (be_ndx < 0) return LI_HANDLER_GO_ON; /* TODO implement fallback/backlog */ be->load--; *context = GINT_TO_POINTER(-1); vrequest_backend_error(vr, error); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static handler_t balancer_act_finished(vrequest *vr, gpointer param, gpointer context) { +static liHandlerResult balancer_act_finished(liVRequest *vr, gpointer param, gpointer context) { balancer *b = (balancer*) param; gint be_ndx = GPOINTER_TO_INT(context); backend *be = &g_array_index(b->backends, backend, be_ndx); UNUSED(vr); - if (be_ndx < 0) return HANDLER_GO_ON; + if (be_ndx < 0) return LI_HANDLER_GO_ON; /* TODO implement backlog */ be->load--; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static void balancer_act_free(server *srv, gpointer param) { +static void balancer_act_free(liServer *srv, gpointer param) { balancer_free(srv, (balancer*) param); } -static action* balancer_rr(server *srv, plugin* p, value *val) { +static liAction* balancer_rr(liServer *srv, liPlugin* p, liValue *val) { balancer *b; - action *a; + liAction *a; UNUSED(p); if (!val) { @@ -155,21 +155,21 @@ static action* balancer_rr(server *srv, plugin* p, value *val) { } -static const plugin_option options[] = { +static const liPluginOption options[] = { { NULL, 0, NULL, NULL, NULL } }; -static const plugin_action actions[] = { +static const liPluginAction actions[] = { { "balancer.rr", balancer_rr }, { NULL, NULL } }; -static const plugin_setup setups[] = { +static const liliPluginSetupCB setups[] = { { NULL, NULL } }; -static void plugin_init(server *srv, plugin *p) { +static void plugin_init(liServer *srv, liPlugin *p) { UNUSED(srv); p->options = options; @@ -178,7 +178,7 @@ static void plugin_init(server *srv, plugin *p) { } -gboolean mod_balancer_init(modules *mods, module *mod) { +gboolean mod_balancer_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); mod->config = plugin_register(mods->main, "mod_balancer", plugin_init); @@ -186,7 +186,7 @@ gboolean mod_balancer_init(modules *mods, module *mod) { return mod->config != NULL; } -gboolean mod_balancer_free(modules *mods, module *mod) { +gboolean mod_balancer_free(liModules *mods, liModule *mod) { if (mod->config) plugin_free(mods->main, mod->config); diff --git a/src/modules/mod_cache_disk_etag.c b/src/modules/mod_cache_disk_etag.c index dd988d4..5286013 100644 --- a/src/modules/mod_cache_disk_etag.c +++ b/src/modules/mod_cache_disk_etag.c @@ -31,17 +31,14 @@ #include #include -LI_API gboolean mod_cache_disk_etag_init(modules *mods, module *mod); -LI_API gboolean mod_cache_disk_etag_free(modules *mods, module *mod); +LI_API gboolean mod_cache_disk_etag_init(liModules *mods, liModule *mod); +LI_API gboolean mod_cache_disk_etag_free(liModules *mods, liModule *mod); -struct cache_etag_context; typedef struct cache_etag_context cache_etag_context; - struct cache_etag_context { GString *path; }; -struct cache_etag_file; typedef struct cache_etag_file cache_etag_file; struct cache_etag_file { GString *filename, *tmpfilename; @@ -59,7 +56,7 @@ static cache_etag_file* cache_etag_file_create(GString *filename) { return cfile; } -static gboolean mkdir_for_file(vrequest *vr, char *filename) { +static gboolean mkdir_for_file(liVRequest *vr, char *filename) { char *p = filename; if (!filename || !filename[0]) @@ -83,7 +80,7 @@ static gboolean mkdir_for_file(vrequest *vr, char *filename) { return TRUE; } -static gboolean cache_etag_file_start(vrequest *vr, cache_etag_file *cfile) { +static gboolean cache_etag_file_start(liVRequest *vr, cache_etag_file *cfile) { cfile->tmpfilename = g_string_sized_new(cfile->filename->len + 7); g_string_append_len(cfile->tmpfilename, GSTR_LEN(cfile->filename)); g_string_append_len(cfile->tmpfilename, CONST_STR_LEN("-XXXXXX")); @@ -115,7 +112,7 @@ static void cache_etag_file_free(cache_etag_file *cfile) { g_slice_free(cache_etag_file, cfile); } -static void cache_etag_file_finish(vrequest *vr, cache_etag_file *cfile) { +static void cache_etag_file_finish(liVRequest *vr, cache_etag_file *cfile) { close(cfile->fd); cfile->fd = -1; if (-1 == rename(cfile->tmpfilename->str, cfile->filename->str)) { @@ -127,18 +124,18 @@ static void cache_etag_file_finish(vrequest *vr, cache_etag_file *cfile) { /**********************************************************************************/ -static void cache_etag_filter_free(vrequest *vr, filter *f) { +static void cache_etag_filter_free(liVRequest *vr, liFilter *f) { cache_etag_file *cfile = (cache_etag_file*) f->param; UNUSED(vr); cache_etag_file_free(cfile); } -static handler_t cache_etag_filter_hit(vrequest *vr, filter *f) { +static liHandlerResult cache_etag_filter_hit(liVRequest *vr, liFilter *f) { cache_etag_file *cfile = (cache_etag_file*) f->param; UNUSED(vr); - if (!cfile) return HANDLER_GO_ON; + if (!cfile) return LI_HANDLER_GO_ON; f->in->is_closed = TRUE; @@ -149,32 +146,32 @@ static handler_t cache_etag_filter_hit(vrequest *vr, filter *f) { f->out->is_closed = TRUE; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static handler_t cache_etag_filter_miss(vrequest *vr, filter *f) { +static liHandlerResult cache_etag_filter_miss(liVRequest *vr, liFilter *f) { cache_etag_file *cfile = (cache_etag_file*) f->param; ssize_t res; gchar *buf; goffset buflen; - chunkiter citer = chunkqueue_iter(f->in); + liChunkIter citer = chunkqueue_iter(f->in); UNUSED(vr); - if (0 == f->in->length) return HANDLER_GO_ON; + if (0 == f->in->length) return LI_HANDLER_GO_ON; if (!cfile) { /* somehow we lost the file */ chunkqueue_steal_all(f->out, f->in); if (f->in->is_closed) f->out->is_closed = TRUE; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } - if (HANDLER_GO_ON != chunkiter_read(vr, citer, 0, 64*1024, &buf, &buflen)) { + if (LI_HANDLER_GO_ON != chunkiter_read(vr, citer, 0, 64*1024, &buf, &buflen)) { VR_ERROR(vr, "%s", "Couldn't read data from chunkqueue"); cache_etag_file_free(cfile); f->param = NULL; chunkqueue_steal_all(f->out, f->in); if (f->in->is_closed) f->out->is_closed = TRUE; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } res = write(cfile->fd, buf, buflen); @@ -190,7 +187,7 @@ static handler_t cache_etag_filter_miss(vrequest *vr, filter *f) { f->param = NULL; chunkqueue_steal_all(f->out, f->in); if (f->in->is_closed) f->out->is_closed = TRUE; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } } else { chunkqueue_steal_len(f->out, f->in, res); @@ -198,14 +195,14 @@ static handler_t cache_etag_filter_miss(vrequest *vr, filter *f) { cache_etag_file_finish(vr, cfile); f->param = NULL; f->out->is_closed = TRUE; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } } - return f->in->length ? HANDLER_COMEBACK : HANDLER_GO_ON; + return f->in->length ? LI_HANDLER_COMEBACK : LI_HANDLER_GO_ON; } -static GString* createFileName(vrequest *vr, GString *path, http_header *etagheader) { +static GString* createFileName(liVRequest *vr, GString *path, liHttpHeader *etagheader) { GString *file = g_string_sized_new(255); gchar* etag_base64 = g_base64_encode((guchar*) HEADER_VALUE_LEN(etagheader)); g_string_append_len(file, GSTR_LEN(path)); @@ -216,40 +213,40 @@ static GString* createFileName(vrequest *vr, GString *path, http_header *etaghea return file; } -static handler_t cache_etag_cleanup(vrequest *vr, gpointer param, gpointer context) { +static liHandlerResult cache_etag_cleanup(liVRequest *vr, gpointer param, gpointer context) { cache_etag_file *cfile = (cache_etag_file*) context; UNUSED(vr); UNUSED(param); cache_etag_file_free(cfile); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static handler_t cache_etag_handle(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult cache_etag_handle(liVRequest *vr, gpointer param, gpointer *context) { cache_etag_context *ctx = (cache_etag_context*) param; cache_etag_file *cfile = (cache_etag_file*) *context; GList *etag_entry; - http_header *etag; + liHttpHeader *etag; struct stat st; GString *tmp_str = vr->wrk->tmp_str; if (!cfile) { - if (vr->request.http_method != HTTP_METHOD_GET) return HANDLER_GO_ON; + if (vr->request.http_method != LI_HTTP_METHOD_GET) return LI_HANDLER_GO_ON; VREQUEST_WAIT_FOR_RESPONSE_HEADERS(vr); - if (vr->response.http_status != 200) return HANDLER_GO_ON; + if (vr->response.http_status != 200) return LI_HANDLER_GO_ON; /* Don't cache static files */ - if (vr->out->is_closed && 0 == vr->out->mem_usage) return HANDLER_GO_ON; + if (vr->out->is_closed && 0 == vr->out->mem_usage) return LI_HANDLER_GO_ON; etag_entry = http_header_find_first(vr->response.headers, CONST_STR_LEN("etag")); - if (!etag_entry) return HANDLER_GO_ON; /* no etag -> no caching */ + if (!etag_entry) return LI_HANDLER_GO_ON; /* no etag -> no caching */ if (http_header_find_next(etag_entry, CONST_STR_LEN("etag"))) { VR_ERROR(vr, "%s", "duplicate etag header in response, will not cache it"); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } - etag = (http_header*) etag_entry->data; + etag = (liHttpHeader*) etag_entry->data; cfile = cache_etag_file_create(createFileName(vr, ctx->path, etag)); *context = cfile; @@ -259,19 +256,19 @@ static handler_t cache_etag_handle(vrequest *vr, gpointer param, gpointer *conte if (0 == stat(cfile->filename->str, &st)) { if (!S_ISREG(st.st_mode)) { VR_ERROR(vr, "Unexpected file type for cache file '%s' (mode %o)", cfile->filename->str, (unsigned int) st.st_mode); - return HANDLER_GO_ON; /* no caching */ + return LI_HANDLER_GO_ON; /* no caching */ } if (-1 == (cfile->hit_fd = open(cfile->filename->str, O_RDONLY))) { if (EMFILE == errno) { server_out_of_fds(vr->wrk->srv); } VR_ERROR(vr, "Couldn't open cache file '%s': %s", cfile->filename->str, g_strerror(errno)); - return HANDLER_GO_ON; /* no caching */ + return LI_HANDLER_GO_ON; /* no caching */ } #ifdef FD_CLOEXEC fcntl(cfile->hit_fd, F_SETFD, FD_CLOEXEC); #endif - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "cache hit for '%s'", vr->request.uri.path->str); } cfile->hit_length = st.st_size; @@ -280,25 +277,25 @@ static handler_t cache_etag_handle(vrequest *vr, gpointer param, gpointer *conte http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Length"), GSTR_LEN(tmp_str)); vrequest_add_filter_out(vr, cache_etag_filter_hit, cache_etag_filter_free, cfile); *context = NULL; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "cache miss for '%s'", vr->request.uri.path->str); } if (!cache_etag_file_start(vr, cfile)) { cache_etag_file_free(cfile); - return HANDLER_GO_ON; /* no caching */ + return LI_HANDLER_GO_ON; /* no caching */ } vrequest_add_filter_out(vr, cache_etag_filter_miss, cache_etag_filter_free, cfile); *context = NULL; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static void cache_etag_free(server *srv, gpointer param) { +static void cache_etag_free(liServer *srv, gpointer param) { cache_etag_context *ctx = (cache_etag_context*) param; UNUSED(srv); @@ -306,11 +303,11 @@ static void cache_etag_free(server *srv, gpointer param) { g_slice_free(cache_etag_context, ctx); } -static action* cache_etag_create(server *srv, plugin* p, value *val) { +static liAction* cache_etag_create(liServer *srv, liPlugin* p, liValue *val) { cache_etag_context *ctx; UNUSED(p); - if (val->type != VALUE_STRING) { + if (val->type != LI_VALUE_STRING) { ERROR(srv, "%s", "cache.disk.etag expects a string as parameter"); return FALSE; } @@ -321,21 +318,21 @@ static action* cache_etag_create(server *srv, plugin* p, value *val) { return action_new_function(cache_etag_handle, cache_etag_cleanup, cache_etag_free, ctx); } -static const plugin_option options[] = { +static const liPluginOption options[] = { { NULL, 0, NULL, NULL, NULL } }; -static const plugin_action actions[] = { +static const liPluginAction actions[] = { { "cache.disk.etag", cache_etag_create }, { NULL, NULL } }; -static const plugin_setup setups[] = { +static const liliPluginSetupCB setups[] = { { NULL, NULL } }; -static void plugin_init(server *srv, plugin *p) { +static void plugin_init(liServer *srv, liPlugin *p) { UNUSED(srv); p->options = options; @@ -343,7 +340,7 @@ static void plugin_init(server *srv, plugin *p) { p->setups = setups; } -gboolean mod_cache_disk_etag_init(modules *mods, module *mod) { +gboolean mod_cache_disk_etag_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); mod->config = plugin_register(mods->main, "mod_cache_disk_etag", plugin_init); @@ -351,7 +348,7 @@ gboolean mod_cache_disk_etag_init(modules *mods, module *mod) { return mod->config != NULL; } -gboolean mod_cache_disk_etag_free(modules *mods, module *mod) { +gboolean mod_cache_disk_etag_free(liModules *mods, liModule *mod) { if (mod->config) plugin_free(mods->main, mod->config); diff --git a/src/modules/mod_debug.c b/src/modules/mod_debug.c index e7f92a0..4245af3 100644 --- a/src/modules/mod_debug.c +++ b/src/modules/mod_debug.c @@ -33,25 +33,25 @@ #include -LI_API gboolean mod_debug_init(modules *mods, module *mod); -LI_API gboolean mod_debug_free(modules *mods, module *mod); +LI_API gboolean mod_debug_init(liModules *mods, liModule *mod); +LI_API gboolean mod_debug_free(liModules *mods, liModule *mod); struct mod_debug_detailed_t { - connection con; + liConnection con; }; typedef struct mod_debug_detailed_t mod_debug_detailed_t; struct mod_debug_data_t { guint wrk_ndx; guint con_ndx; - connection *con; - waitqueue_elem io_timeout_elem; + liConnection *con; + liWaitQueueElem io_timeout_elem; gint fd; - connection_state_t state; + liConnectionState state; GString *remote_addr_str, *local_addr_str; gboolean is_ssl, keep_alive; GString *host, *path, *query; - http_method_t method; + liHttpMethod method; goffset request_size; goffset response_size; ev_tstamp ts; @@ -64,9 +64,9 @@ struct mod_debug_data_t { typedef struct mod_debug_data_t mod_debug_data_t; struct mod_debug_job_t { - vrequest *vr; + liVRequest *vr; gpointer *context; - plugin *p; + liPlugin *p; struct { guint wrk_ndx; guint con_ndx; @@ -77,7 +77,7 @@ struct mod_debug_job_t { typedef struct mod_debug_job_t mod_debug_job_t; /* the CollectFunc */ -static gpointer debug_collect_func(worker *wrk, gpointer fdata) { +static gpointer debug_collect_func(liWorker *wrk, gpointer fdata) { GArray *cons; mod_debug_job_t *job = fdata; @@ -86,7 +86,7 @@ static gpointer debug_collect_func(worker *wrk, gpointer fdata) { g_array_set_size(cons, wrk->connections_active); for (guint i = 0; i < wrk->connections_active; i++) { - connection *c = g_array_index(wrk->connections, connection*, i); + liConnection *c = g_array_index(wrk->connections, liConnection*, i); mod_debug_data_t *cd = &g_array_index(cons, mod_debug_data_t, i); cd->wrk_ndx = wrk->ndx; cd->con_ndx = i; @@ -152,8 +152,8 @@ static gpointer debug_collect_func(worker *wrk, gpointer fdata) { /* the CollectCallback */ static void debug_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result, gboolean complete) { mod_debug_job_t *job = cbdata; - vrequest *vr; - plugin *p; + liVRequest *vr; + liPlugin *p; GString *html; UNUSED(fdata); @@ -253,24 +253,24 @@ static void debug_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result, g_slice_free(mod_debug_job_t, job); } -static handler_t debug_show_connections_cleanup(vrequest *vr, gpointer param, gpointer context) { - collect_info *ci = (collect_info*) context; +static liHandlerResult debug_show_connections_cleanup(liVRequest *vr, gpointer param, gpointer context) { + liCollectInfo *ci = (liCollectInfo*) context; UNUSED(vr); UNUSED(param); collect_break(ci); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static handler_t debug_show_connections(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult debug_show_connections(liVRequest *vr, gpointer param, gpointer *context) { if (vrequest_handle_direct(vr)) { - collect_info *ci; + liCollectInfo *ci; mod_debug_job_t *j = g_slice_new0(mod_debug_job_t); j->vr = vr; j->context = context; - j->p = (plugin*) param; + j->p = (liPlugin*) param; if (vr->request.uri.query->len) { /* querystring = ___ */ @@ -286,10 +286,10 @@ static handler_t debug_show_connections(vrequest *vr, gpointer param, gpointer * *context = ci; /* may be NULL */ } - return (*context) ? HANDLER_WAIT_FOR_EVENT : HANDLER_GO_ON; + return (*context) ? LI_HANDLER_WAIT_FOR_EVENT : LI_HANDLER_GO_ON; } -static action* debug_show_connections_create(server *srv, plugin* p, value *val) { +static liAction* debug_show_connections_create(liServer *srv, liPlugin* p, liValue *val) { UNUSED(srv); UNUSED(p); if (val) { @@ -301,22 +301,22 @@ static action* debug_show_connections_create(server *srv, plugin* p, value *val) } -static const plugin_option options[] = { +static const liPluginOption options[] = { { NULL, 0, NULL, NULL, NULL } }; -static const plugin_action actions[] = { +static const liPluginAction actions[] = { { "debug.show_connections", debug_show_connections_create }, { NULL, NULL } }; -static const plugin_setup setups[] = { +static const liliPluginSetupCB setups[] = { { NULL, NULL } }; -static void plugin_debug_init(server *srv, plugin *p) { +static void plugin_debug_init(liServer *srv, liPlugin *p) { UNUSED(srv); p->options = options; @@ -325,7 +325,7 @@ static void plugin_debug_init(server *srv, plugin *p) { } -gboolean mod_debug_init(modules *mods, module *mod) { +gboolean mod_debug_init(liModules *mods, liModule *mod) { UNUSED(mod); MODULE_VERSION_CHECK(mods); @@ -335,7 +335,7 @@ gboolean mod_debug_init(modules *mods, module *mod) { return mod->config != NULL; } -gboolean mod_debug_free(modules *mods, module *mod) { +gboolean mod_debug_free(liModules *mods, liModule *mod) { if (mod->config) plugin_free(mods->main, mod->config); diff --git a/src/modules/mod_dirlist.c b/src/modules/mod_dirlist.c index 4a5012c..40b30dd 100644 --- a/src/modules/mod_dirlist.c +++ b/src/modules/mod_dirlist.c @@ -51,9 +51,10 @@ #include #include +#include -LI_API gboolean mod_dirlist_init(modules *mods, module *mod); -LI_API gboolean mod_dirlist_free(modules *mods, module *mod); +LI_API gboolean mod_dirlist_init(liModules *mods, liModule *mod); +LI_API gboolean mod_dirlist_free(liModules *mods, liModule *mod); /* html snippet constants */ static const gchar html_header[] = @@ -106,7 +107,7 @@ static const gchar html_css[] = "\n"; struct dirlist_data { - plugin *plugin; + liPlugin *plugin; GString *css; gboolean hide_dotfiles; gboolean hide_tildefiles; @@ -163,22 +164,22 @@ static void dirlist_format_size(gchar *buf, goffset size) { *buf++ = '\0'; } -static handler_t dirlist(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context) { GString *listing; - stat_cache_entry *sce; + liStatCacheEntry *sce; dirlist_data *dd; dirlist_plugin_data *pd; UNUSED(context); - if (vrequest_is_handled(vr)) return HANDLER_GO_ON; + if (vrequest_is_handled(vr)) return LI_HANDLER_GO_ON; - if (vr->physical.path->len == 0) return HANDLER_GO_ON; + if (vr->physical.path->len == 0) return LI_HANDLER_GO_ON; switch (stat_cache_get_dirlist(vr, vr->physical.path, &sce)) { - case HANDLER_GO_ON: break; - case HANDLER_WAIT_FOR_EVENT: return HANDLER_WAIT_FOR_EVENT; - default: return HANDLER_ERROR; + case LI_HANDLER_GO_ON: break; + case LI_HANDLER_WAIT_FOR_EVENT: return LI_HANDLER_WAIT_FOR_EVENT; + default: return LI_HANDLER_ERROR; } dd = param; @@ -190,23 +191,23 @@ static handler_t dirlist(vrequest *vr, gpointer param, gpointer *context) { switch (sce->data.err) { case ENOENT: case ENOTDIR: - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; case EACCES: - if (!vrequest_handle_direct(vr)) return HANDLER_ERROR; + if (!vrequest_handle_direct(vr)) return LI_HANDLER_ERROR; vr->response.http_status = 403; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; default: VR_ERROR(vr, "stat('%s') failed: %s", sce->data.path->str, g_strerror(sce->data.err)); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } } else if (!S_ISDIR(sce->data.st.st_mode)) { stat_cache_entry_release(vr, sce); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } else if (vr->request.uri.path->str[vr->request.uri.path->len-1] != G_DIR_SEPARATOR) { GString *host, *uri; if (!vrequest_handle_direct(vr)) { stat_cache_entry_release(vr, sce); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } /* redirect to scheme + host + path + / + querystring if directory without trailing slash */ /* TODO: local addr if HTTP 1.0 without host header, url encoding */ @@ -232,12 +233,12 @@ static handler_t dirlist(vrequest *vr, gpointer param, gpointer *context) { http_header_overwrite(vr->response.headers, CONST_STR_LEN("Location"), GSTR_LEN(uri)); g_string_free(uri, TRUE); stat_cache_entry_release(vr, sce); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } else { /* everything ok, we have the directory listing */ gboolean cachable; guint i, j; - stat_cache_entry_data *sced; + liStatCacheEntryData *sced; GString *mime_str, *encoded; GArray *directories, *files; gchar sizebuf[sizeof("999.9K")+1]; @@ -248,7 +249,7 @@ static handler_t dirlist(vrequest *vr, gpointer param, gpointer *context) { if (!vrequest_handle_direct(vr)) { stat_cache_entry_release(vr, sce); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } vr->response.http_status = 200; @@ -260,7 +261,7 @@ static handler_t dirlist(vrequest *vr, gpointer param, gpointer *context) { if (cachable) { vr->response.http_status = 304; stat_cache_entry_release(vr, sce); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } /* temporary string for encoded names */ @@ -270,7 +271,7 @@ static handler_t dirlist(vrequest *vr, gpointer param, gpointer *context) { directories = g_array_sized_new(FALSE, FALSE, sizeof(guint), 16); files = g_array_sized_new(FALSE, FALSE, sizeof(guint), sce->dirlist->len); for (i = 0; i < sce->dirlist->len; i++) { - sced = &g_array_index(sce->dirlist, stat_cache_entry_data, i); + sced = &g_array_index(sce->dirlist, liStatCacheEntryData, i); hide = FALSE; /* ingore entries where the stat() failed */ @@ -331,7 +332,7 @@ static handler_t dirlist(vrequest *vr, gpointer param, gpointer *context) { /* list directories */ if (!dd->hide_directories) { for (i = 0; i < directories->len; i++) { - sced = &g_array_index(sce->dirlist, stat_cache_entry_data, g_array_index(directories, guint, i)); + sced = &g_array_index(sce->dirlist, liStatCacheEntryData, g_array_index(directories, guint, i)); localtime_r(&(sced->st.st_mtime), &tm); datebuflen = strftime(datebuf, sizeof(datebuf), "%Y-%b-%d %H:%M:%S", &tm); @@ -357,7 +358,7 @@ static handler_t dirlist(vrequest *vr, gpointer param, gpointer *context) { /* list files */ for (i = 0; i < files->len; i++) { - sced = &g_array_index(sce->dirlist, stat_cache_entry_data, g_array_index(files, guint, i)); + sced = &g_array_index(sce->dirlist, liStatCacheEntryData, g_array_index(files, guint, i)); mime_str = mimetype_get(vr, sced->path); localtime_r(&(sced->st.st_mtime), &tm); @@ -401,7 +402,7 @@ static handler_t dirlist(vrequest *vr, gpointer param, gpointer *context) { g_string_append_len(listing, CONST_STR_LEN(html_table_end)); - g_string_append_printf(listing, html_footer, CORE_OPTION(CORE_OPTION_SERVER_TAG).string->str); + g_string_append_printf(listing, html_footer, CORE_OPTION(LI_CORE_OPTION_SERVER_TAG).string->str); chunkqueue_append_string(vr->out, listing); g_string_free(encoded, TRUE); @@ -411,10 +412,10 @@ static handler_t dirlist(vrequest *vr, gpointer param, gpointer *context) { stat_cache_entry_release(vr, sce); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static void dirlist_free(server *srv, gpointer param) { +static void dirlist_free(liServer *srv, gpointer param) { guint i; dirlist_data *data = param; @@ -436,14 +437,14 @@ static void dirlist_free(server *srv, gpointer param) { g_slice_free(dirlist_data, data); } -static action* dirlist_create(server *srv, plugin* p, value *val) { +static liAction* dirlist_create(liServer *srv, liPlugin* p, liValue *val) { dirlist_data *data; guint i; guint j; - value *v, *tmpval; + liValue *v, *tmpval; GString *k; - if (val && val->type != VALUE_LIST) { + if (val && val->type != LI_VALUE_LIST) { ERROR(srv, "%s", "dirlist expects an optional list of string-value pairs"); return NULL; } @@ -458,84 +459,84 @@ static action* dirlist_create(server *srv, plugin* p, value *val) { if (val) { for (i = 0; i < val->data.list->len; i++) { - tmpval = g_array_index(val->data.list, value*, i); - if (tmpval->type != VALUE_LIST || tmpval->data.list->len != 2 || - g_array_index(tmpval->data.list, value*, 0)->type != VALUE_STRING) { + tmpval = g_array_index(val->data.list, liValue*, i); + if (tmpval->type != LI_VALUE_LIST || tmpval->data.list->len != 2 || + g_array_index(tmpval->data.list, liValue*, 0)->type != LI_VALUE_STRING) { ERROR(srv, "%s", "dirlist expects an optional list of string-value pairs"); dirlist_free(srv, data); return NULL; } - k = g_array_index(tmpval->data.list, value*, 0)->data.string; - v = g_array_index(tmpval->data.list, value*, 1); + k = g_array_index(tmpval->data.list, liValue*, 0)->data.string; + v = g_array_index(tmpval->data.list, liValue*, 1); if (g_str_equal(k->str, "css")) { - if (v->type != VALUE_STRING) { + if (v->type != LI_VALUE_STRING) { ERROR(srv, "%s", "dirlist: css parameter must be a string"); dirlist_free(srv, data); return NULL; } data->css = g_string_new_len(GSTR_LEN(v->data.string)); } else if (g_str_equal(k->str, "hide-dotfiles")) { - if (v->type != VALUE_BOOLEAN) { + if (v->type != LI_VALUE_BOOLEAN) { ERROR(srv, "%s", "dirlist: hide-dotfiles parameter must be a boolean (true or false)"); dirlist_free(srv, data); return NULL; } data->hide_dotfiles = v->data.boolean; } else if (g_str_equal(k->str, "hide-tildefiles")) { - if (v->type != VALUE_BOOLEAN) { + if (v->type != LI_VALUE_BOOLEAN) { ERROR(srv, "%s", "dirlist: hide-tildefiles parameter must be a boolean (true or false)"); dirlist_free(srv, data); return NULL; } data->hide_tildefiles = v->data.boolean; } else if (g_str_equal(k->str, "hide-directories")) { - if (v->type != VALUE_BOOLEAN) { + if (v->type != LI_VALUE_BOOLEAN) { ERROR(srv, "%s", "dirlist: hide-directories parameter must be a boolean (true or false)"); dirlist_free(srv, data); return NULL; } data->hide_directories = v->data.boolean; } else if (g_str_equal(k->str, "exclude-suffix")) { - if (v->type != VALUE_LIST) { + if (v->type != LI_VALUE_LIST) { ERROR(srv, "%s", "dirlist: exclude-suffix parameter must be a list of strings"); dirlist_free(srv, data); return NULL; } for (j = 0; j < v->data.list->len; j++) { - if (v->type != VALUE_LIST) { + if (v->type != LI_VALUE_LIST) { ERROR(srv, "%s", "dirlist: exclude-suffix parameter must be a list of strings"); dirlist_free(srv, data); return NULL; } else { - g_ptr_array_add(data->exclude_suffix, g_string_new_len(GSTR_LEN(g_array_index(v->data.list, value*, j)->data.string))); + g_ptr_array_add(data->exclude_suffix, g_string_new_len(GSTR_LEN(g_array_index(v->data.list, liValue*, j)->data.string))); } } } else if (g_str_equal(k->str, "exclude-prefix")) { - if (v->type != VALUE_LIST) { + if (v->type != LI_VALUE_LIST) { ERROR(srv, "%s", "dirlist: exclude-prefix parameter must be a list of strings"); dirlist_free(srv, data); return NULL; } for (j = 0; j < v->data.list->len; j++) { - if (v->type != VALUE_LIST) { + if (v->type != LI_VALUE_LIST) { ERROR(srv, "%s", "dirlist: exclude-prefix parameter must be a list of strings"); dirlist_free(srv, data); return NULL; } else { - g_ptr_array_add(data->exclude_prefix, g_string_new_len(GSTR_LEN(g_array_index(v->data.list, value*, j)->data.string))); + g_ptr_array_add(data->exclude_prefix, g_string_new_len(GSTR_LEN(g_array_index(v->data.list, liValue*, j)->data.string))); } } } else if (g_str_equal(k->str, "debug")) { - if (v->type != VALUE_BOOLEAN) { + if (v->type != LI_VALUE_BOOLEAN) { ERROR(srv, "%s", "dirlist: debug parameter must be a boolean (true or false)"); dirlist_free(srv, data); return NULL; } data->debug = v->data.boolean; } else if (g_str_equal(k->str, "content-type")) { - if (v->type != VALUE_STRING) { + if (v->type != LI_VALUE_STRING) { ERROR(srv, "%s", "dirlist: content-type parameter must be a string"); dirlist_free(srv, data); return NULL; @@ -552,24 +553,24 @@ static action* dirlist_create(server *srv, plugin* p, value *val) { return action_new_function(dirlist, NULL, dirlist_free, data); } -static const plugin_option options[] = { - { "dirlist.debug", VALUE_BOOLEAN, NULL, NULL, NULL }, +static const liPluginOption options[] = { + { "dirlist.debug", LI_VALUE_BOOLEAN, NULL, NULL, NULL }, { NULL, 0, NULL, NULL, NULL } }; -static const plugin_action actions[] = { +static const liPluginAction actions[] = { { "dirlist", dirlist_create }, { NULL, NULL } }; -static const plugin_setup setups[] = { +static const liliPluginSetupCB setups[] = { { NULL, NULL } }; -static void plugin_dirlist_free(server *srv, plugin *p) { +static void plugin_dirlist_free(liServer *srv, liPlugin *p) { dirlist_plugin_data *pd; UNUSED(srv); @@ -579,7 +580,7 @@ static void plugin_dirlist_free(server *srv, plugin *p) { } -static void plugin_dirlist_init(server *srv, plugin *p) { +static void plugin_dirlist_init(liServer *srv, liPlugin *p) { dirlist_plugin_data *pd; UNUSED(srv); @@ -594,7 +595,7 @@ static void plugin_dirlist_init(server *srv, plugin *p) { } -gboolean mod_dirlist_init(modules *mods, module *mod) { +gboolean mod_dirlist_init(liModules *mods, liModule *mod) { UNUSED(mod); MODULE_VERSION_CHECK(mods); @@ -604,7 +605,7 @@ gboolean mod_dirlist_init(modules *mods, module *mod) { return mod->config != NULL; } -gboolean mod_dirlist_free(modules *mods, module *mod) { +gboolean mod_dirlist_free(liModules *mods, liModule *mod) { if (mod->config) plugin_free(mods->main, mod->config); diff --git a/src/modules/mod_expire.c b/src/modules/mod_expire.c index 4190577..59f0ccc 100644 --- a/src/modules/mod_expire.c +++ b/src/modules/mod_expire.c @@ -50,8 +50,8 @@ #include -LI_API gboolean mod_expire_init(modules *mods, module *mod); -LI_API gboolean mod_expire_free(modules *mods, module *mod); +LI_API gboolean mod_expire_init(liModules *mods, liModule *mod); +LI_API gboolean mod_expire_free(liModules *mods, liModule *mod); struct expire_rule { @@ -64,7 +64,7 @@ struct expire_rule { typedef struct expire_rule expire_rule; -static handler_t expire(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult expire(liVRequest *vr, gpointer param, gpointer *context) { struct tm tm; time_t expire_date; guint len; @@ -85,12 +85,12 @@ static handler_t expire(vrequest *vr, gpointer param, gpointer *context) { gint err; if (!vr->physical.path->len) - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; switch (stat_cache_get(vr, vr->physical.path, &st, &err, NULL)) { - case HANDLER_GO_ON: break; - case HANDLER_WAIT_FOR_EVENT: return HANDLER_WAIT_FOR_EVENT; - default: return HANDLER_GO_ON; + case LI_HANDLER_GO_ON: break; + case LI_HANDLER_WAIT_FOR_EVENT: return LI_HANDLER_WAIT_FOR_EVENT; + default: return LI_HANDLER_GO_ON; } expire_date = st.st_mtime + num; @@ -106,12 +106,12 @@ static handler_t expire(vrequest *vr, gpointer param, gpointer *context) { if (!gmtime_r(&expire_date, &tm)) { VR_ERROR(vr, "gmtime_r(%"G_GUINT64_FORMAT") failed: %s", (guint64)expire_date, g_strerror(errno)); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } len = strftime(date_str->str, date_str->allocated_len, "%a, %d %b %Y %H:%M:%S GMT", &tm); if (len == 0) - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; g_string_set_size(date_str, len); @@ -122,23 +122,23 @@ static handler_t expire(vrequest *vr, gpointer param, gpointer *context) { l_g_string_append_int(date_str, max_age); http_header_append(vr->response.headers, CONST_STR_LEN("Cache-Control"), GSTR_LEN(date_str)); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static void expire_free(server *srv, gpointer param) { +static void expire_free(liServer *srv, gpointer param) { UNUSED(srv); g_slice_free(expire_rule, param); } -static action* expire_create(server *srv, plugin* p, value *val) { +static liAction* expire_create(liServer *srv, liPlugin* p, liValue *val) { expire_rule *rule; gchar *str; UNUSED(srv); UNUSED(p); - if (!val || val->type != VALUE_STRING) { + if (!val || val->type != LI_VALUE_STRING) { ERROR(srv, "%s", "expire expects a string as parameter"); return NULL; } @@ -209,22 +209,22 @@ static action* expire_create(server *srv, plugin* p, value *val) { -static const plugin_option options[] = { +static const liPluginOption options[] = { { NULL, 0, NULL, NULL, NULL } }; -static const plugin_action actions[] = { +static const liPluginAction actions[] = { { "expire", expire_create }, { NULL, NULL } }; -static const plugin_setup setups[] = { +static const liliPluginSetupCB setups[] = { { NULL, NULL } }; -static void plugin_expire_init(server *srv, plugin *p) { +static void plugin_expire_init(liServer *srv, liPlugin *p) { UNUSED(srv); p->options = options; @@ -233,7 +233,7 @@ static void plugin_expire_init(server *srv, plugin *p) { } -gboolean mod_expire_init(modules *mods, module *mod) { +gboolean mod_expire_init(liModules *mods, liModule *mod) { UNUSED(mod); MODULE_VERSION_CHECK(mods); @@ -243,7 +243,7 @@ gboolean mod_expire_init(modules *mods, module *mod) { return mod->config != NULL; } -gboolean mod_expire_free(modules *mods, module *mod) { +gboolean mod_expire_free(liModules *mods, liModule *mod) { if (mod->config) plugin_free(mods->main, mod->config); diff --git a/src/modules/mod_fastcgi.c b/src/modules/mod_fastcgi.c index 0246ea6..b9b482c 100644 --- a/src/modules/mod_fastcgi.c +++ b/src/modules/mod_fastcgi.c @@ -37,15 +37,12 @@ enum fastcgi_options_t { #define _FASTCGI_OPTION(vr, idx) _OPTION_ABS(vr, p->opt_base_index + idx) -LI_API gboolean mod_fastcgi_init(modules *mods, module *mod); -LI_API gboolean mod_fastcgi_free(modules *mods, module *mod); +LI_API gboolean mod_fastcgi_init(liModules *mods, liModule *mod); +LI_API gboolean mod_fastcgi_free(liModules *mods, liModule *mod); -struct fastcgi_connection; typedef struct fastcgi_connection fastcgi_connection; -struct fastcgi_context; typedef struct fastcgi_context fastcgi_context; -struct FCGI_Record; typedef struct FCGI_Record FCGI_Record; @@ -71,25 +68,25 @@ struct FCGI_Record { struct fastcgi_connection { fastcgi_context *ctx; - vrequest *vr; + liVRequest *vr; fastcgi_state state; int fd; ev_io fd_watcher; - chunkqueue *fcgi_in, *fcgi_out, *stdout; + liChunkQueue *fcgi_in, *fcgi_out, *stdout; GByteArray *buf_in_record; FCGI_Record fcgi_in_record; guint16 requestid; - http_response_ctx parse_response_ctx; + liHttpResponseCtx parse_response_ctx; gboolean response_headers_finished; }; struct fastcgi_context { gint refcount; - sockaddr_t socket; + liSocketAddress socket; guint timeout; - plugin *plugin; + liPlugin *plugin; }; /* fastcgi types */ @@ -131,8 +128,8 @@ enum FCGI_ProtocolStatus { /**********************************************************************************/ -static fastcgi_context* fastcgi_context_new(server *srv, plugin *p, GString *dest_socket) { - sockaddr_t saddr; +static fastcgi_context* fastcgi_context_new(liServer *srv, liPlugin *p, GString *dest_socket) { + liSocketAddress saddr; fastcgi_context* ctx; saddr = sockaddr_from_string(dest_socket, 0); if (NULL == saddr.addr) { @@ -163,7 +160,7 @@ static void fastcgi_context_acquire(fastcgi_context *ctx) { static void fastcgi_fd_cb(struct ev_loop *loop, ev_io *w, int revents); -static fastcgi_connection* fastcgi_connection_new(vrequest *vr, fastcgi_context *ctx) { +static fastcgi_connection* fastcgi_connection_new(liVRequest *vr, fastcgi_context *ctx) { fastcgi_connection* fcon = g_slice_new0(fastcgi_connection); fastcgi_context_acquire(ctx); @@ -185,7 +182,7 @@ static fastcgi_connection* fastcgi_connection_new(vrequest *vr, fastcgi_context } static void fastcgi_connection_free(fastcgi_connection *fcon) { - vrequest *vr; + liVRequest *vr; if (!fcon) return; vr = fcon->vr; @@ -236,14 +233,14 @@ static guint8 stream_build_fcgi_record(GByteArray *buf, guint8 type, guint16 req } /* returns padding length */ -static guint8 stream_send_fcgi_record(chunkqueue *out, guint8 type, guint16 requestid, guint16 datalen) { +static guint8 stream_send_fcgi_record(liChunkQueue *out, guint8 type, guint16 requestid, guint16 datalen) { GByteArray *record = g_byte_array_sized_new(FCGI_HEADER_LEN); guint8 padlen = stream_build_fcgi_record(record, type, requestid, datalen); chunkqueue_append_bytearr(out, record); return padlen; } -static void stream_send_data(chunkqueue *out, guint8 type, guint16 requestid, const gchar *data, size_t datalen) { +static void stream_send_data(liChunkQueue *out, guint8 type, guint16 requestid, const gchar *data, size_t datalen) { while (datalen > 0) { guint16 tosend = (datalen > G_MAXUINT16) ? G_MAXUINT16 : datalen; guint8 padlen = stream_send_fcgi_record(out, type, requestid, tosend); @@ -257,7 +254,7 @@ static void stream_send_data(chunkqueue *out, guint8 type, guint16 requestid, co } /* kills the data */ -static void stream_send_bytearr(chunkqueue *out, guint8 type, guint16 requestid, GByteArray *data) { +static void stream_send_bytearr(liChunkQueue *out, guint8 type, guint16 requestid, GByteArray *data) { if (data->len > G_MAXUINT16) { stream_send_data(out, type, requestid, (const gchar*) data->data, data->len); g_byte_array_free(data, TRUE); @@ -268,7 +265,7 @@ static void stream_send_bytearr(chunkqueue *out, guint8 type, guint16 requestid, } } -static void stream_send_chunks(chunkqueue *out, guint8 type, guint16 requestid, chunkqueue *in) { +static void stream_send_chunks(liChunkQueue *out, guint8 type, guint16 requestid, liChunkQueue *in) { while (in->length > 0) { guint16 tosend = (in->length > G_MAXUINT16) ? G_MAXUINT16 : in->length; guint8 padlen = stream_send_fcgi_record(out, type, requestid, tosend); @@ -314,7 +311,7 @@ static void fastcgi_send_begin(fastcgi_connection *fcon) { chunkqueue_append_bytearr(fcon->fcgi_out, buf); } -static void fastcgi_env_add(GByteArray *buf, environment_dup *envdup, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { +static void fastcgi_env_add(GByteArray *buf, liEnvironmentDup *envdup, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { GString *sval; if (NULL != (sval = environment_dup_pop(envdup, key, keylen))) { @@ -324,11 +321,11 @@ static void fastcgi_env_add(GByteArray *buf, environment_dup *envdup, const gcha } } -static void fastcgi_env_create(vrequest *vr, environment_dup *envdup, GByteArray* buf) { - connection *con = vr->con; +static void fastcgi_env_create(liVRequest *vr, liEnvironmentDup *envdup, GByteArray* buf) { + liConnection *con = vr->con; GString *tmp = con->wrk->tmp_str; - fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_SOFTWARE"), GSTR_LEN(CORE_OPTION(CORE_OPTION_SERVER_TAG).string)); + fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_SOFTWARE"), GSTR_LEN(CORE_OPTION(LI_CORE_OPTION_SERVER_TAG).string)); fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_NAME"), GSTR_LEN(vr->request.uri.host)); fastcgi_env_add(buf, envdup, CONST_STR_LEN("GATEWAY_INTERFACE"), CONST_STR_LEN("CGI/1.1")); { @@ -392,10 +389,10 @@ static void fastcgi_env_create(vrequest *vr, environment_dup *envdup, GByteArray fastcgi_env_add(buf, envdup, CONST_STR_LEN("REQUEST_METHOD"), GSTR_LEN(vr->request.http_method_str)); fastcgi_env_add(buf, envdup, CONST_STR_LEN("REDIRECT_STATUS"), CONST_STR_LEN("200")); /* if php is compiled with --force-redirect */ switch (vr->request.http_version) { - case HTTP_VERSION_1_1: + case LI_HTTP_VERSION_1_1: fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_PROTOCOL"), CONST_STR_LEN("HTTP/1.1")); break; - case HTTP_VERSION_1_0: + case LI_HTTP_VERSION_1_0: default: fastcgi_env_add(buf, envdup, CONST_STR_LEN("SERVER_PROTOCOL"), CONST_STR_LEN("HTTP/1.0")); break; @@ -418,9 +415,9 @@ static void fix_header_name(GString *str) { } } -static void fastcgi_send_env(vrequest *vr, fastcgi_connection *fcon) { +static void fastcgi_send_env(liVRequest *vr, fastcgi_connection *fcon) { GByteArray *buf = g_byte_array_sized_new(0); - environment_dup *envdup; + liEnvironmentDup *envdup; envdup = environment_make_dup(&vr->env); fastcgi_env_create(vr, envdup, buf); @@ -430,7 +427,7 @@ static void fastcgi_send_env(vrequest *vr, fastcgi_connection *fcon) { GString *tmp = vr->wrk->tmp_str; for (i = vr->request.headers->entries.head; NULL != i; i = i->next) { - http_header *h = (http_header*) i->data; + liHttpHeader *h = (liHttpHeader*) i->data; GString hkey = { h->data->str, h->keylen, 0 }; g_string_truncate(tmp, 0); if (!l_g_strncase_equal(&hkey, CONST_STR_LEN("CONTENT-TYPE"))) { @@ -459,7 +456,7 @@ static void fastcgi_send_env(vrequest *vr, fastcgi_connection *fcon) { stream_send_fcgi_record(fcon->fcgi_out, FCGI_PARAMS, fcon->requestid, 0); } -static void fastcgi_forward_request(vrequest *vr, fastcgi_connection *fcon) { +static void fastcgi_forward_request(liVRequest *vr, fastcgi_connection *fcon) { stream_send_chunks(fcon->fcgi_out, FCGI_STDIN, fcon->requestid, vr->in); if (fcon->fcgi_out->length > 0) ev_io_add_events(vr->wrk->loop, &fcon->fd_watcher, EV_WRITE); @@ -510,8 +507,8 @@ static int fastcgi_available(fastcgi_connection *fcon) { } static gboolean fastcgi_parse_response(fastcgi_connection *fcon) { - vrequest *vr = fcon->vr; - plugin *p = fcon->ctx->plugin; + liVRequest *vr = fcon->vr; + liPlugin *p = fcon->ctx->plugin; gint len; while (fastcgi_get_packet(fcon)) { if (fcon->fcgi_in_record.version != FCGI_VERSION_1) { @@ -537,7 +534,7 @@ static gboolean fastcgi_parse_response(fastcgi_connection *fcon) { len = fastcgi_available(fcon); chunkqueue_extract_to(vr, fcon->fcgi_in, len, vr->wrk->tmp_str); if (FASTCGI_OPTION(FASTCGI_OPTION_LOG_PLAIN_ERRORS).boolean) { - log_split_lines(vr->wrk->srv, vr, LOG_LEVEL_BACKEND, 0, vr->wrk->tmp_str->str, ""); + log_split_lines(vr->wrk->srv, vr, LI_LOG_LEVEL_BACKEND, 0, vr->wrk->tmp_str->str, ""); } else { VR_BACKEND_LINES(vr, vr->wrk->tmp_str->str, "%s", "(fcgi-stderr) "); } @@ -555,13 +552,13 @@ static gboolean fastcgi_parse_response(fastcgi_connection *fcon) { /**********************************************************************************/ -static handler_t fastcgi_statemachine(vrequest *vr, fastcgi_connection *fcon); +static liHandlerResult fastcgi_statemachine(liVRequest *vr, fastcgi_connection *fcon); static void fastcgi_fd_cb(struct ev_loop *loop, ev_io *w, int revents) { fastcgi_connection *fcon = (fastcgi_connection*) w->data; if (fcon->state == FS_CONNECTING) { - if (HANDLER_GO_ON != fastcgi_statemachine(fcon->vr, fcon)) { + if (LI_HANDLER_GO_ON != fastcgi_statemachine(fcon->vr, fcon)) { vrequest_error(fcon->vr); } return; @@ -572,21 +569,21 @@ static void fastcgi_fd_cb(struct ev_loop *loop, ev_io *w, int revents) { ev_io_rem_events(loop, w, EV_READ); } else { switch (network_read(fcon->vr, w->fd, fcon->fcgi_in)) { - case NETWORK_STATUS_SUCCESS: + case LI_NETWORK_STATUS_SUCCESS: break; - case NETWORK_STATUS_FATAL_ERROR: + case LI_NETWORK_STATUS_FATAL_ERROR: VR_ERROR(fcon->vr, "%s", "network read fatal error"); vrequest_error(fcon->vr); return; - case NETWORK_STATUS_CONNECTION_CLOSE: + case LI_NETWORK_STATUS_CONNECTION_CLOSE: fcon->fcgi_in->is_closed = TRUE; ev_io_stop(loop, w); close(fcon->fd); fcon->fd = -1; break; - case NETWORK_STATUS_WAIT_FOR_EVENT: + case LI_NETWORK_STATUS_WAIT_FOR_EVENT: break; - case NETWORK_STATUS_WAIT_FOR_AIO_EVENT: + case LI_NETWORK_STATUS_WAIT_FOR_AIO_EVENT: /* TODO: aio */ ev_io_rem_events(loop, w, EV_READ); break; @@ -597,21 +594,21 @@ static void fastcgi_fd_cb(struct ev_loop *loop, ev_io *w, int revents) { if (fcon->fd != -1 && (revents & EV_WRITE)) { if (fcon->fcgi_out->length > 0) { switch (network_write(fcon->vr, w->fd, fcon->fcgi_out, 256*1024)) { - case NETWORK_STATUS_SUCCESS: + case LI_NETWORK_STATUS_SUCCESS: break; - case NETWORK_STATUS_FATAL_ERROR: + case LI_NETWORK_STATUS_FATAL_ERROR: VR_ERROR(fcon->vr, "%s", "network write fatal error"); vrequest_error(fcon->vr); return; - case NETWORK_STATUS_CONNECTION_CLOSE: + case LI_NETWORK_STATUS_CONNECTION_CLOSE: fcon->fcgi_in->is_closed = TRUE; ev_io_stop(loop, w); close(fcon->fd); fcon->fd = -1; break; - case NETWORK_STATUS_WAIT_FOR_EVENT: + case LI_NETWORK_STATUS_WAIT_FOR_EVENT: break; - case NETWORK_STATUS_WAIT_FOR_AIO_EVENT: + case LI_NETWORK_STATUS_WAIT_FOR_AIO_EVENT: ev_io_rem_events(loop, w, EV_WRITE); /* TODO: aio */ break; @@ -624,7 +621,7 @@ static void fastcgi_fd_cb(struct ev_loop *loop, ev_io *w, int revents) { if (!fastcgi_parse_response(fcon)) return; - if (!fcon->response_headers_finished && HANDLER_GO_ON == http_response_parse(fcon->vr, &fcon->parse_response_ctx)) { + if (!fcon->response_headers_finished && LI_HANDLER_GO_ON == http_response_parse(fcon->vr, &fcon->parse_response_ctx)) { fcon->response_headers_finished = TRUE; vrequest_handle_response_headers(fcon->vr); } @@ -644,17 +641,17 @@ static void fastcgi_fd_cb(struct ev_loop *loop, ev_io *w, int revents) { /**********************************************************************************/ /* state machine */ -static void fastcgi_close(vrequest *vr, plugin *p); +static void fastcgi_close(liVRequest *vr, liPlugin *p); -static handler_t fastcgi_statemachine(vrequest *vr, fastcgi_connection *fcon) { - plugin *p = fcon->ctx->plugin; +static liHandlerResult fastcgi_statemachine(liVRequest *vr, fastcgi_connection *fcon) { + liPlugin *p = fcon->ctx->plugin; switch (fcon->state) { case FS_WAIT_FOR_REQUEST: /* wait until we have either all data or the cqlimit is full */ if (-1 == vr->request.content_length || vr->request.content_length != vr->in->length) { if (0 != chunkqueue_limit_available(vr->in)) - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } fcon->state = FS_CONNECT; @@ -668,7 +665,7 @@ static handler_t fastcgi_statemachine(vrequest *vr, fastcgi_connection *fcon) { server_out_of_fds(vr->wrk->srv); } VR_ERROR(vr, "Couldn't open socket: %s", g_strerror(errno)); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } fd_init(fcon->fd); ev_io_set(&fcon->fd_watcher, fcon->fd, EV_READ | EV_WRITE); @@ -682,18 +679,18 @@ static handler_t fastcgi_statemachine(vrequest *vr, fastcgi_connection *fcon) { case EALREADY: case EINTR: fcon->state = FS_CONNECTING; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; case EAGAIN: /* backend overloaded */ fastcgi_close(vr, p); vrequest_backend_overloaded(vr); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; default: VR_ERROR(vr, "Couldn't connect to '%s': %s", sockaddr_to_string(fcon->ctx->socket, vr->wrk->tmp_str, TRUE)->str, g_strerror(errno)); fastcgi_close(vr, p); vrequest_backend_dead(vr); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } } @@ -712,21 +709,21 @@ static handler_t fastcgi_statemachine(vrequest *vr, fastcgi_connection *fcon) { break; } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } /**********************************************************************************/ -static handler_t fastcgi_handle(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult fastcgi_handle(liVRequest *vr, gpointer param, gpointer *context) { fastcgi_context *ctx = (fastcgi_context*) param; fastcgi_connection *fcon; UNUSED(context); - if (!vrequest_handle_indirect(vr, ctx->plugin)) return HANDLER_GO_ON; + if (!vrequest_handle_indirect(vr, ctx->plugin)) return LI_HANDLER_GO_ON; fcon = fastcgi_connection_new(vr, ctx); if (!fcon) { - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } g_ptr_array_index(vr->plugin_ctx, ctx->plugin->id) = fcon; @@ -739,14 +736,14 @@ static handler_t fastcgi_handle(vrequest *vr, gpointer param, gpointer *context) } -static handler_t fastcgi_handle_request_body(vrequest *vr, plugin *p) { +static liHandlerResult fastcgi_handle_request_body(liVRequest *vr, liPlugin *p) { fastcgi_connection *fcon = (fastcgi_connection*) g_ptr_array_index(vr->plugin_ctx, p->id); - if (!fcon) return HANDLER_ERROR; + if (!fcon) return LI_HANDLER_ERROR; return fastcgi_statemachine(vr, fcon); } -static void fastcgi_close(vrequest *vr, plugin *p) { +static void fastcgi_close(liVRequest *vr, liPlugin *p) { fastcgi_connection *fcon = (fastcgi_connection*) g_ptr_array_index(vr->plugin_ctx, p->id); g_ptr_array_index(vr->plugin_ctx, p->id) = NULL; if (fcon) { @@ -756,17 +753,17 @@ static void fastcgi_close(vrequest *vr, plugin *p) { } -static void fastcgi_free(server *srv, gpointer param) { +static void fastcgi_free(liServer *srv, gpointer param) { fastcgi_context *ctx = (fastcgi_context*) param; UNUSED(srv); fastcgi_context_release(ctx); } -static action* fastcgi_create(server *srv, plugin* p, value *val) { +static liAction* fastcgi_create(liServer *srv, liPlugin* p, liValue *val) { fastcgi_context *ctx; - if (val->type != VALUE_STRING) { + if (val->type != LI_VALUE_STRING) { ERROR(srv, "%s", "fastcgi expects a string as parameter"); return FALSE; } @@ -777,23 +774,23 @@ static action* fastcgi_create(server *srv, plugin* p, value *val) { return action_new_function(fastcgi_handle, NULL, fastcgi_free, ctx); } -static const plugin_option options[] = { - { "fastcgi.log_plain_errors", VALUE_BOOLEAN, GINT_TO_POINTER(FALSE), NULL, NULL }, +static const liPluginOption options[] = { + { "fastcgi.log_plain_errors", LI_VALUE_BOOLEAN, GINT_TO_POINTER(FALSE), NULL, NULL }, { NULL, 0, NULL, NULL, NULL } }; -static const plugin_action actions[] = { +static const liPluginAction actions[] = { { "fastcgi", fastcgi_create }, { NULL, NULL } }; -static const plugin_setup setups[] = { +static const liliPluginSetupCB setups[] = { { NULL, NULL } }; -static void plugin_init(server *srv, plugin *p) { +static void plugin_init(liServer *srv, liPlugin *p) { UNUSED(srv); p->options = options; @@ -805,7 +802,7 @@ static void plugin_init(server *srv, plugin *p) { } -gboolean mod_fastcgi_init(modules *mods, module *mod) { +gboolean mod_fastcgi_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); mod->config = plugin_register(mods->main, "mod_fastcgi", plugin_init); @@ -813,7 +810,7 @@ gboolean mod_fastcgi_init(modules *mods, module *mod) { return mod->config != NULL; } -gboolean mod_fastcgi_free(modules *mods, module *mod) { +gboolean mod_fastcgi_free(liModules *mods, liModule *mod) { if (mod->config) plugin_free(mods->main, mod->config); diff --git a/src/modules/mod_fortune.c b/src/modules/mod_fortune.c index d911455..aa59ff6 100644 --- a/src/modules/mod_fortune.c +++ b/src/modules/mod_fortune.c @@ -27,11 +27,10 @@ #include -LI_API gboolean mod_fortune_init(modules *mods, module *mod); -LI_API gboolean mod_fortune_free(modules *mods, module *mod); +LI_API gboolean mod_fortune_init(liModules *mods, liModule *mod); +LI_API gboolean mod_fortune_free(liModules *mods, liModule *mod); /* globals */ -struct fortune_data; typedef struct fortune_data fortune_data; struct fortune_data { @@ -44,7 +43,7 @@ static GString *fortune_rand(fortune_data *fd) { return g_ptr_array_index(fd->cookies, r); } -static handler_t fortune_header_handle(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult fortune_header_handle(liVRequest *vr, gpointer param, gpointer *context) { fortune_data *fd = param; UNUSED(context); @@ -53,21 +52,21 @@ static handler_t fortune_header_handle(vrequest *vr, gpointer param, gpointer *c GString *cookie = fortune_rand(fd); http_header_insert(vr->response.headers, CONST_STR_LEN("X-fortune"), GSTR_LEN(cookie)); } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* fortune_header(server *srv, plugin* p, value *val) { +static liAction* fortune_header(liServer *srv, liPlugin* p, liValue *val) { UNUSED(srv); UNUSED(val); return action_new_function(fortune_header_handle, NULL, NULL, p->data); } -static handler_t fortune_page_handle(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult fortune_page_handle(liVRequest *vr, gpointer param, gpointer *context) { fortune_data *fd = param; UNUSED(context); if (!vrequest_handle_direct(vr)) - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; vr->response.http_status = 200; @@ -78,15 +77,15 @@ static handler_t fortune_page_handle(vrequest *vr, gpointer param, gpointer *con chunkqueue_append_mem(vr->out, CONST_STR_LEN("no cookies in the cookie box")); } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* fortune_page(server *srv, plugin* p, value *val) { +static liAction* fortune_page(liServer *srv, liPlugin* p, liValue *val) { UNUSED(srv); UNUSED(val); return action_new_function(fortune_page_handle, NULL, NULL, p->data); } -static gboolean fortune_load(server *srv, plugin* p, value *val) { +static gboolean fortune_load(liServer *srv, liPlugin* p, liValue *val) { gchar *file; GError *err = NULL; gchar *data; @@ -94,7 +93,7 @@ static gboolean fortune_load(server *srv, plugin* p, value *val) { guint count = 0; fortune_data *fd = p->data; - if (!val || val->type != VALUE_STRING) { + if (!val || val->type != LI_VALUE_STRING) { ERROR(srv, "fortune.load takes a string as parameter, %s given", val ? value_type_string(val->type) : "none"); return FALSE; } @@ -137,25 +136,25 @@ static gboolean fortune_load(server *srv, plugin* p, value *val) { -static const plugin_option options[] = { +static const liPluginOption options[] = { { NULL, 0, NULL, NULL, NULL } }; -static const plugin_action actions[] = { +static const liPluginAction actions[] = { { "fortune.header", fortune_header }, { "fortune.page", fortune_page }, { NULL, NULL } }; -static const plugin_setup setups[] = { +static const liliPluginSetupCB setups[] = { { "fortune.load", fortune_load }, { NULL, NULL } }; -static void plugin_fortune_free(server *srv, plugin *p) { +static void plugin_fortune_free(liServer *srv, liPlugin *p) { fortune_data *fd = p->data; UNUSED(srv); @@ -169,7 +168,7 @@ static void plugin_fortune_free(server *srv, plugin *p) { g_slice_free(fortune_data, fd); } -static void plugin_fortune_init(server *srv, plugin *p) { +static void plugin_fortune_init(liServer *srv, liPlugin *p) { fortune_data *fd; UNUSED(srv); @@ -185,8 +184,8 @@ static void plugin_fortune_init(server *srv, plugin *p) { } -gboolean mod_fortune_init(modules *mods, module *mod) { - server *srv = mods->main; +gboolean mod_fortune_init(liModules *mods, liModule *mod) { + liServer *srv = mods->main; MODULE_VERSION_CHECK(mods); @@ -198,7 +197,7 @@ gboolean mod_fortune_init(modules *mods, module *mod) { return TRUE; } -gboolean mod_fortune_free(modules *mods, module *mod) { +gboolean mod_fortune_free(liModules *mods, liModule *mod) { if (mod->config) plugin_free(mods->main, mod->config); diff --git a/src/modules/mod_rewrite.c b/src/modules/mod_rewrite.c index 4ac0564..780ca10 100644 --- a/src/modules/mod_rewrite.c +++ b/src/modules/mod_rewrite.c @@ -58,9 +58,10 @@ */ #include +#include -LI_API gboolean mod_rewrite_init(modules *mods, module *mod); -LI_API gboolean mod_rewrite_free(modules *mods, module *mod); +LI_API gboolean mod_rewrite_init(liModules *mods, liModule *mod); +LI_API gboolean mod_rewrite_free(liModules *mods, liModule *mod); struct rewrite_plugin_data { GPtrArray *tmp_strings; /* array of (GString*) */ @@ -79,7 +80,7 @@ struct rewrite_part { union { GString *str; guint8 ndx; - cond_lvalue_t cond_lval; + liCondLValue cond_lval; } data; }; typedef struct rewrite_part rewrite_part; @@ -93,7 +94,7 @@ typedef struct rewrite_rule rewrite_rule; struct rewrite_data { GArray *rules; - plugin *p; + liPlugin *p; }; typedef struct rewrite_data rewrite_data; @@ -173,7 +174,7 @@ static GArray *rewrite_parts_parse(GString *str, gboolean *has_querystring) { rp.data.cond_lval = cond_lvalue_from_string(c-len, len); - if (rp.data.cond_lval == COMP_UNKNOWN) { + if (rp.data.cond_lval == LI_COMP_UNKNOWN) { /* parse error */ rewrite_parts_free(parts); return NULL; @@ -224,7 +225,7 @@ static GArray *rewrite_parts_parse(GString *str, gboolean *has_querystring) { return parts; } -static gboolean rewrite_internal(vrequest *vr, GString *dest_path, GString *dest_query, GRegex *regex, GArray *parts, gboolean raw) { +static gboolean rewrite_internal(liVRequest *vr, GString *dest_path, GString *dest_query, GRegex *regex, GArray *parts, gboolean raw) { guint i; GString *str; gchar *path; @@ -261,7 +262,7 @@ static gboolean rewrite_internal(vrequest *vr, GString *dest_path, GString *dest case REWRITE_PART_CAPTURED_PREV: if (vr->action_stack.regex_stack->len) { GArray *rs = vr->action_stack.regex_stack; - action_regex_stack_element *arse = &g_array_index(rs, action_regex_stack_element, rs->len - 1); + liActionRegexStackElement *arse = &g_array_index(rs, liActionRegexStackElement, rs->len - 1); if (arse->string && g_match_info_fetch_pos(arse->match_info, rp->data.ndx, &start_pos, &end_pos) && start_pos != -1) g_string_append_len(dest, arse->string->str + start_pos, end_pos - start_pos); @@ -273,20 +274,20 @@ static gboolean rewrite_internal(vrequest *vr, GString *dest_path, GString *dest case REWRITE_PART_VAR: switch (rp->data.cond_lval) { - case COMP_REQUEST_LOCALIP: str = vr->con->srv_sock->local_addr_str; break; - case COMP_REQUEST_REMOTEIP: str = vr->con->remote_addr_str; break; - case COMP_REQUEST_PATH: str = vr->request.uri.path; break; - case COMP_REQUEST_HOST: str = vr->request.uri.host; break; - case COMP_REQUEST_QUERY_STRING: str = vr->request.uri.query; break; - case COMP_REQUEST_METHOD: str = vr->request.http_method_str; break; - case COMP_REQUEST_CONTENT_LENGTH: + case LI_COMP_REQUEST_LOCALIP: str = vr->con->srv_sock->local_addr_str; break; + case LI_COMP_REQUEST_REMOTEIP: str = vr->con->remote_addr_str; break; + case LI_COMP_REQUEST_PATH: str = vr->request.uri.path; break; + case LI_COMP_REQUEST_HOST: str = vr->request.uri.host; break; + case LI_COMP_REQUEST_QUERY_STRING: str = vr->request.uri.query; break; + case LI_COMP_REQUEST_METHOD: str = vr->request.http_method_str; break; + case LI_COMP_REQUEST_CONTENT_LENGTH: g_string_printf(vr->con->wrk->tmp_str, "%"L_GOFFSET_FORMAT, vr->request.content_length); str = vr->con->wrk->tmp_str; break; default: str = NULL; } - if (rp->data.cond_lval == COMP_REQUEST_SCHEME) { + if (rp->data.cond_lval == LI_COMP_REQUEST_SCHEME) { if (vr->con->is_ssl) g_string_append_len(dest, CONST_STR_LEN("https")); else @@ -310,7 +311,7 @@ static gboolean rewrite_internal(vrequest *vr, GString *dest_path, GString *dest return TRUE; } -static handler_t rewrite(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult rewrite(liVRequest *vr, gpointer param, gpointer *context) { guint i; rewrite_rule *rule; rewrite_data *rd = param; @@ -336,14 +337,14 @@ static handler_t rewrite(vrequest *vr, gpointer param, gpointer *context) { } /* stop at first matching regex */ - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static void rewrite_free(server *srv, gpointer param) { +static void rewrite_free(liServer *srv, gpointer param) { guint i; rewrite_data *rd = param; @@ -360,9 +361,9 @@ static void rewrite_free(server *srv, gpointer param) { g_slice_free(rewrite_data, rd); } -static action* rewrite_create(server *srv, plugin* p, value *val) { +static liAction* rewrite_create(liServer *srv, liPlugin* p, liValue *val) { GArray *arr; - value *v; + liValue *v; guint i; rewrite_data *rd; rewrite_rule rule; @@ -372,7 +373,7 @@ static action* rewrite_create(server *srv, plugin* p, value *val) { UNUSED(srv); UNUSED(p); - if (!val || val->type != VALUE_LIST) { + if (!val || val->type != LI_VALUE_LIST) { ERROR(srv, "%s", "rewrite expects a either a tuple of strings or a list of those"); return NULL; } @@ -389,23 +390,23 @@ static action* rewrite_create(server *srv, plugin* p, value *val) { arr = val->data.list; - if (arr->len == 2 && g_array_index(arr, value*, 0)->type == VALUE_STRING && g_array_index(arr, value*, 1)->type == VALUE_STRING) { + if (arr->len == 2 && g_array_index(arr, liValue*, 0)->type == LI_VALUE_STRING && g_array_index(arr, liValue*, 1)->type == LI_VALUE_STRING) { /* only one rule */ rule.has_querystring = FALSE; - rule.parts = rewrite_parts_parse(g_array_index(arr, value*, 1)->data.string, &rule.has_querystring); + rule.parts = rewrite_parts_parse(g_array_index(arr, liValue*, 1)->data.string, &rule.has_querystring); if (!rule.parts) { rewrite_free(NULL, rd); - ERROR(srv, "rewrite: error parsing rule \"%s\"", g_array_index(arr, value*, 1)->data.string->str); + ERROR(srv, "rewrite: error parsing rule \"%s\"", g_array_index(arr, liValue*, 1)->data.string->str); return NULL; } - rule.regex = g_regex_new(g_array_index(arr, value*, 0)->data.string->str, G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, &err); + rule.regex = g_regex_new(g_array_index(arr, liValue*, 0)->data.string->str, G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, &err); if (!rule.regex || err) { rewrite_free(NULL, rd); rewrite_parts_free(rule.parts); - ERROR(srv, "rewrite: error compiling regex \"%s\": %s", g_array_index(arr, value*, 0)->data.string->str, err->message); + ERROR(srv, "rewrite: error compiling regex \"%s\": %s", g_array_index(arr, liValue*, 0)->data.string->str, err->message); return NULL; } @@ -413,10 +414,10 @@ static action* rewrite_create(server *srv, plugin* p, value *val) { } else { /* probably multiple rules */ for (i = 0; i < arr->len; i++) { - v = g_array_index(arr, value*, i); + v = g_array_index(arr, liValue*, i); - if (v->type != VALUE_LIST || v->data.list->len != 2 || - g_array_index(v->data.list, value*, 0)->type != VALUE_STRING || g_array_index(v->data.list, value*, 1)->type != VALUE_STRING) { + if (v->type != LI_VALUE_LIST || v->data.list->len != 2 || + g_array_index(v->data.list, liValue*, 0)->type != LI_VALUE_STRING || g_array_index(v->data.list, liValue*, 1)->type != LI_VALUE_STRING) { rewrite_free(NULL, rd); ERROR(srv, "%s", "rewrite expects a either a tuple of strings or a list of those"); @@ -424,20 +425,20 @@ static action* rewrite_create(server *srv, plugin* p, value *val) { } rule.has_querystring = FALSE; - rule.parts = rewrite_parts_parse(g_array_index(v->data.list, value*, 1)->data.string, &rule.has_querystring); + rule.parts = rewrite_parts_parse(g_array_index(v->data.list, liValue*, 1)->data.string, &rule.has_querystring); if (!rule.parts) { rewrite_free(NULL, rd); - ERROR(srv, "rewrite: error parsing rule \"%s\"", g_array_index(v->data.list, value*, 1)->data.string->str); + ERROR(srv, "rewrite: error parsing rule \"%s\"", g_array_index(v->data.list, liValue*, 1)->data.string->str); return NULL; } - rule.regex = g_regex_new(g_array_index(v->data.list, value*, 0)->data.string->str, G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, &err); + rule.regex = g_regex_new(g_array_index(v->data.list, liValue*, 0)->data.string->str, G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, &err); if (!rule.regex || err) { rewrite_free(NULL, rd); rewrite_parts_free(rule.parts); - ERROR(srv, "rewrite: error compiling regex \"%s\": %s", g_array_index(v->data.list, value*, 0)->data.string->str, err->message); + ERROR(srv, "rewrite: error compiling regex \"%s\": %s", g_array_index(v->data.list, liValue*, 0)->data.string->str, err->message); return NULL; } @@ -451,24 +452,24 @@ static action* rewrite_create(server *srv, plugin* p, value *val) { -static const plugin_option options[] = { - { "rewrite.debug", VALUE_BOOLEAN, NULL, NULL, NULL }, +static const liPluginOption options[] = { + { "rewrite.debug", LI_VALUE_BOOLEAN, NULL, NULL, NULL }, { NULL, 0, NULL, NULL, NULL } }; -static const plugin_action actions[] = { +static const liPluginAction actions[] = { { "rewrite", rewrite_create }, { NULL, NULL } }; -static const plugin_setup setups[] = { +static const liliPluginSetupCB setups[] = { { NULL, NULL } }; -static void plugin_rewrite_free(server *srv, plugin *p) { +static void plugin_rewrite_free(liServer *srv, liPlugin *p) { guint i; rewrite_plugin_data *data = p->data; @@ -481,7 +482,7 @@ static void plugin_rewrite_free(server *srv, plugin *p) { g_slice_free(rewrite_plugin_data, data); } -static void plugin_rewrite_init(server *srv, plugin *p) { +static void plugin_rewrite_init(liServer *srv, liPlugin *p) { UNUSED(srv); p->options = options; @@ -495,7 +496,7 @@ static void plugin_rewrite_init(server *srv, plugin *p) { } -gboolean mod_rewrite_init(modules *mods, module *mod) { +gboolean mod_rewrite_init(liModules *mods, liModule *mod) { UNUSED(mod); MODULE_VERSION_CHECK(mods); @@ -505,7 +506,7 @@ gboolean mod_rewrite_init(modules *mods, module *mod) { return mod->config != NULL; } -gboolean mod_rewrite_free(modules *mods, module *mod) { +gboolean mod_rewrite_free(liModules *mods, liModule *mod) { if (mod->config) plugin_free(mods->main, mod->config); diff --git a/src/modules/mod_status.c b/src/modules/mod_status.c index 0e2cce5..51e897e 100644 --- a/src/modules/mod_status.c +++ b/src/modules/mod_status.c @@ -31,8 +31,8 @@ #include #include -LI_API gboolean mod_status_init(modules *mods, module *mod); -LI_API gboolean mod_status_free(modules *mods, module *mod); +LI_API gboolean mod_status_init(liModules *mods, liModule *mod); +LI_API gboolean mod_status_free(liModules *mods, liModule *mod); /* html snippet constants */ static const gchar header[] = @@ -156,11 +156,11 @@ typedef struct mod_status_job mod_status_job; struct mod_status_con_data { guint worker_ndx; - connection_state_t state; + liConnectionState state; GString *remote_addr_str, *local_addr_str; gboolean is_ssl, keep_alive; GString *host, *path, *query; - http_method_t method; + liHttpMethod method; goffset request_size; goffset response_size; ev_tstamp ts; @@ -172,24 +172,24 @@ struct mod_status_con_data { struct mod_status_wrk_data { guint worker_ndx; - statistics_t stats; + liStatistics stats; GArray *connections; }; struct mod_status_job { - vrequest *vr; + liVRequest *vr; gpointer *context; - plugin *p; + liPlugin *p; }; -static gchar status_state_c(connection_state_t state) { +static gchar status_state_c(liConnectionState state) { static const gchar states[] = "dksrhw"; return states[state]; } /* the CollectFunc */ -static gpointer status_collect_func(worker *wrk, gpointer fdata) { +static gpointer status_collect_func(liWorker *wrk, gpointer fdata) { mod_status_wrk_data *sd = g_slice_new(mod_status_wrk_data); UNUSED(fdata); @@ -199,7 +199,7 @@ static gpointer status_collect_func(worker *wrk, gpointer fdata) { sd->connections = g_array_sized_new(FALSE, TRUE, sizeof(mod_status_con_data), wrk->connections_active); g_array_set_size(sd->connections, wrk->connections_active); for (guint i = 0; i < wrk->connections_active; i++) { - connection *c = g_array_index(wrk->connections, connection*, i); + liConnection *c = g_array_index(wrk->connections, liConnection*, i); mod_status_con_data *cd = &g_array_index(sd->connections, mod_status_con_data, i); cd->is_ssl = c->is_ssl; cd->keep_alive = c->keep_alive; @@ -224,8 +224,8 @@ static gpointer status_collect_func(worker *wrk, gpointer fdata) { /* the CollectCallback */ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result, gboolean complete) { mod_status_job *job = cbdata; - vrequest *vr; - plugin *p; + liVRequest *vr; + liPlugin *p; UNUSED(fdata); if (!complete) { @@ -269,7 +269,7 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result guint j; /* we got everything */ - statistics_t totals = { + liStatistics totals = { G_GUINT64_CONSTANT(0), G_GUINT64_CONSTANT(0), G_GUINT64_CONSTANT(0), G_GUINT64_CONSTANT(0), G_GUINT64_CONSTANT(0), G_GUINT64_CONSTANT(0), G_GUINT64_CONSTANT(0), G_GUINT64_CONSTANT(0), G_GUINT64_CONSTANT(0), G_GUINT64_CONSTANT(0), G_GUINT64_CONSTANT(0), @@ -500,9 +500,9 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result bytes_out->str, bytes_in_5s->str, bytes_out_5s->str, - (cd->state >= CON_STATE_HANDLE_MAINVR) ? http_method_string(cd->method, &len) : "", - (cd->state >= CON_STATE_HANDLE_MAINVR) ? req_len->str : "", - (cd->state >= CON_STATE_HANDLE_MAINVR) ? resp_len->str : "" + (cd->state >= LI_CON_STATE_HANDLE_MAINVR) ? http_method_string(cd->method, &len) : "", + (cd->state >= LI_CON_STATE_HANDLE_MAINVR) ? req_len->str : "", + (cd->state >= LI_CON_STATE_HANDLE_MAINVR) ? resp_len->str : "" ); g_string_free(cd->remote_addr_str, TRUE); @@ -554,13 +554,13 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result } } -static handler_t status_page_handle(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult status_page_handle(liVRequest *vr, gpointer param, gpointer *context) { if (vrequest_handle_direct(vr)) { - collect_info *ci; + liCollectInfo *ci; mod_status_job *j = g_slice_new(mod_status_job); j->vr = vr; j->context = context; - j->p = (plugin*) param; + j->p = (liPlugin*) param; VR_DEBUG(vr, "%s", "collecting stats..."); @@ -568,21 +568,21 @@ static handler_t status_page_handle(vrequest *vr, gpointer param, gpointer *cont *context = ci; /* may be NULL */ } - return (*context) ? HANDLER_WAIT_FOR_EVENT : HANDLER_GO_ON; + return (*context) ? LI_HANDLER_WAIT_FOR_EVENT : LI_HANDLER_GO_ON; } -static handler_t status_page_cleanup(vrequest *vr, gpointer param, gpointer context) { - collect_info *ci = (collect_info*) context; +static liHandlerResult status_page_cleanup(liVRequest *vr, gpointer param, gpointer context) { + liCollectInfo *ci = (liCollectInfo*) context; UNUSED(vr); UNUSED(param); collect_break(ci); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* status_page(server *srv, plugin* p, value *val) { +static liAction* status_page(liServer *srv, liPlugin* p, liValue *val) { UNUSED(srv); UNUSED(val); @@ -591,24 +591,24 @@ static action* status_page(server *srv, plugin* p, value *val) { -static const plugin_option options[] = { - { "status.css", VALUE_STRING, NULL, NULL, NULL }, +static const liPluginOption options[] = { + { "status.css", LI_VALUE_STRING, NULL, NULL, NULL }, { NULL, 0, NULL, NULL, NULL } }; -static const plugin_action actions[] = { +static const liPluginAction actions[] = { { "status.page", status_page }, { NULL, NULL } }; -static const plugin_setup setups[] = { +static const liliPluginSetupCB setups[] = { { NULL, NULL } }; -static void plugin_status_init(server *srv, plugin *p) { +static void plugin_status_init(liServer *srv, liPlugin *p) { UNUSED(srv); p->options = options; @@ -617,7 +617,7 @@ static void plugin_status_init(server *srv, plugin *p) { } -gboolean mod_status_init(modules *mods, module *mod) { +gboolean mod_status_init(liModules *mods, liModule *mod) { UNUSED(mod); MODULE_VERSION_CHECK(mods); @@ -627,7 +627,7 @@ gboolean mod_status_init(modules *mods, module *mod) { return mod->config != NULL; } -gboolean mod_status_free(modules *mods, module *mod) { +gboolean mod_status_free(liModules *mods, liModule *mod) { UNUSED(mods); UNUSED(mod); if (mod->config) diff --git a/src/modules/mod_vhost.c b/src/modules/mod_vhost.c index 34ea6be..43a7241 100644 --- a/src/modules/mod_vhost.c +++ b/src/modules/mod_vhost.c @@ -70,11 +70,11 @@ #include -LI_API gboolean mod_vhost_init(modules *mods, module *mod); -LI_API gboolean mod_vhost_free(modules *mods, module *mod); +LI_API gboolean mod_vhost_init(liModules *mods, liModule *mod); +LI_API gboolean mod_vhost_free(liModules *mods, liModule *mod); struct vhost_simple_data { - plugin *plugin; + liPlugin *plugin; GString *default_vhost; GString *docroot; GString *server_root; @@ -82,9 +82,9 @@ struct vhost_simple_data { typedef struct vhost_simple_data vhost_simple_data; struct vhost_map_data { - plugin *plugin; + liPlugin *plugin; GHashTable *hash; - value *default_action; + liValue *default_action; }; typedef struct vhost_map_data vhost_map_data; @@ -114,12 +114,12 @@ typedef struct vhost_pattern_hostpart vhost_pattern_hostpart; struct vhost_pattern_data { GArray *parts; guint max_idx; - plugin *plugin; + liPlugin *plugin; }; typedef struct vhost_pattern_data vhost_pattern_data; -static handler_t vhost_simple(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult vhost_simple(liVRequest *vr, gpointer param, gpointer *context) { struct stat st; gboolean debug; vhost_simple_data *sd = param; @@ -152,10 +152,10 @@ static handler_t vhost_simple(vrequest *vr, gpointer param, gpointer *context) { g_string_append_len(vr->physical.path, GSTR_LEN(vr->physical.doc_root)); g_string_append_len(vr->physical.path, GSTR_LEN(vr->request.uri.path)); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static void vhost_simple_free(server *srv, gpointer param) { +static void vhost_simple_free(liServer *srv, gpointer param) { vhost_simple_data *sd = param; UNUSED(srv); @@ -170,16 +170,16 @@ static void vhost_simple_free(server *srv, gpointer param) { g_slice_free(vhost_simple_data, sd); } -static action* vhost_simple_create(server *srv, plugin* p, value *val) { +static liAction* vhost_simple_create(liServer *srv, liPlugin* p, liValue *val) { guint i; GArray *arr; - value *k, *v; + liValue *k, *v; vhost_simple_data *sd; GString **setting; UNUSED(srv); UNUSED(p); - if (!val || val->type != VALUE_LIST) { + if (!val || val->type != LI_VALUE_LIST) { ERROR(srv, "%s", "vhost.simple expects a list if string tuples as parameter"); return NULL; } @@ -189,16 +189,16 @@ static action* vhost_simple_create(server *srv, plugin* p, value *val) { arr = val->data.list; for (i = 0; i < arr->len; i++) { - val = g_array_index(arr, value*, i); - if (val->type != VALUE_LIST || val->data.list->len != 2) { + val = g_array_index(arr, liValue*, i); + if (val->type != LI_VALUE_LIST || val->data.list->len != 2) { vhost_simple_free(srv, sd); ERROR(srv, "%s", "vhost.simple expects a list if string tuples as parameter"); return NULL; } - k = g_array_index(val->data.list, value*, 0); - v = g_array_index(val->data.list, value*, 1); - if (k->type != VALUE_STRING || v->type != VALUE_STRING) { + k = g_array_index(val->data.list, liValue*, 0); + v = g_array_index(val->data.list, liValue*, 1); + if (k->type != LI_VALUE_STRING || v->type != LI_VALUE_STRING) { vhost_simple_free(srv, sd); ERROR(srv, "%s", "vhost.simple expects a list if string tuples as parameter"); return NULL; @@ -241,8 +241,8 @@ static action* vhost_simple_create(server *srv, plugin* p, value *val) { return action_new_function(vhost_simple, NULL, vhost_simple_free, sd); } -static handler_t vhost_map(vrequest *vr, gpointer param, gpointer *context) { - value *v; +static liHandlerResult vhost_map(liVRequest *vr, gpointer param, gpointer *context) { + liValue *v; vhost_map_data *md = param; gboolean debug = _OPTION(vr, md->plugin, 0).boolean; @@ -263,10 +263,10 @@ static handler_t vhost_map(vrequest *vr, gpointer param, gpointer *context) { VR_DEBUG(vr, "vhost_map: neither host %s found in hashtable nor default action specified, doing nothing", vr->request.uri.host->str); } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static void vhost_map_free(server *srv, gpointer param) { +static void vhost_map_free(liServer *srv, gpointer param) { vhost_map_data *md = param; UNUSED(srv); @@ -276,13 +276,13 @@ static void vhost_map_free(server *srv, gpointer param) { g_slice_free(vhost_map_data, md); } -static action* vhost_map_create(server *srv, plugin* p, value *val) { +static liAction* vhost_map_create(liServer *srv, liPlugin* p, liValue *val) { GHashTableIter iter; gpointer k, v; vhost_map_data *md; GString *str; - if (!val || val->type != VALUE_HASH) { + if (!val || val->type != LI_VALUE_HASH) { ERROR(srv, "%s", "vhost.map expects a hashtable as parameter"); return NULL; } @@ -299,7 +299,7 @@ static action* vhost_map_create(server *srv, plugin* p, value *val) { while (g_hash_table_iter_next(&iter, &k, &v)) { val = v; - if (val->type != VALUE_ACTION) { + if (val->type != LI_VALUE_ACTION) { ERROR(srv, "vhost.map expects a hashtable with action values as parameter, %s value given", value_type_string(val->type)); vhost_map_free(srv, md); return NULL; @@ -311,7 +311,7 @@ static action* vhost_map_create(server *srv, plugin* p, value *val) { return action_new_function(vhost_map, NULL, vhost_map_free, md); } -static handler_t vhost_pattern(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult vhost_pattern(liVRequest *vr, gpointer param, gpointer *context) { GArray *parts = g_array_sized_new(FALSE, TRUE, sizeof(vhost_pattern_hostpart), 6); vhost_pattern_data *pattern = param; gboolean debug = _OPTION(vr, pattern->plugin, 0).boolean; @@ -324,7 +324,7 @@ static handler_t vhost_pattern(vrequest *vr, gpointer param, gpointer *context) if (!vr->request.uri.host->len) { if (debug) VR_DEBUG(vr, "%s", "vhost_pattern: no host given"); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } /* parse host. we traverse the host in reverse order */ @@ -387,10 +387,10 @@ static handler_t vhost_pattern(vrequest *vr, gpointer param, gpointer *context) g_array_free(parts, TRUE); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static void vhost_pattern_free(server *srv, gpointer param) { +static void vhost_pattern_free(liServer *srv, gpointer param) { vhost_pattern_data *pd = param; guint i; @@ -407,13 +407,13 @@ static void vhost_pattern_free(server *srv, gpointer param) { g_slice_free(vhost_pattern_data, pd); } -static action* vhost_pattern_create(server *srv, plugin* p, value *val) { +static liAction* vhost_pattern_create(liServer *srv, liPlugin* p, liValue *val) { vhost_pattern_data *pd; GString *str; gchar *c, *c_last; vhost_pattern_part part; - if (!val || val->type != VALUE_STRING) { + if (!val || val->type != LI_VALUE_STRING) { ERROR(srv, "%s", "vhost.map expects a hashtable as parameter"); return NULL; } @@ -505,13 +505,13 @@ static action* vhost_pattern_create(server *srv, plugin* p, value *val) { } -static const plugin_option options[] = { - { "vhost.debug", VALUE_BOOLEAN, NULL, NULL, NULL }, +static const liPluginOption options[] = { + { "vhost.debug", LI_VALUE_BOOLEAN, NULL, NULL, NULL }, { NULL, 0, NULL, NULL, NULL } }; -static const plugin_action actions[] = { +static const liPluginAction actions[] = { { "vhost.simple", vhost_simple_create }, { "vhost.map", vhost_map_create }, { "vhost.pattern", vhost_pattern_create }, @@ -519,12 +519,12 @@ static const plugin_action actions[] = { { NULL, NULL } }; -static const plugin_setup setups[] = { +static const liliPluginSetupCB setups[] = { { NULL, NULL } }; -static void plugin_vhost_init(server *srv, plugin *p) { +static void plugin_vhost_init(liServer *srv, liPlugin *p) { UNUSED(srv); p->options = options; @@ -533,7 +533,7 @@ static void plugin_vhost_init(server *srv, plugin *p) { } -gboolean mod_vhost_init(modules *mods, module *mod) { +gboolean mod_vhost_init(liModules *mods, liModule *mod) { UNUSED(mod); MODULE_VERSION_CHECK(mods); @@ -543,7 +543,7 @@ gboolean mod_vhost_init(modules *mods, module *mod) { return mod->config != NULL; } -gboolean mod_vhost_free(modules *mods, module *mod) { +gboolean mod_vhost_free(liModules *mods, liModule *mod) { if (mod->config) plugin_free(mods->main, mod->config); diff --git a/src/network.c b/src/network.c index 5553b12..de1cf6e 100644 --- a/src/network.c +++ b/src/network.c @@ -36,8 +36,8 @@ ssize_t net_read(int fd, void *buf, ssize_t nbyte) { return r; } -network_status_t network_write(vrequest *vr, int fd, chunkqueue *cq, goffset write_max) { - network_status_t res; +liNetworkStatus network_write(liVRequest *vr, int fd, liChunkQueue *cq, goffset write_max) { + liNetworkStatus res; #ifdef TCP_CORK int corked = 0; #endif @@ -61,7 +61,7 @@ network_status_t network_write(vrequest *vr, int fd, chunkqueue *cq, goffset wri res = network_write_writev(vr, fd, cq, &write_bytes); #endif wrote = write_max - write_bytes; - if (wrote > 0 && res == NETWORK_STATUS_WAIT_FOR_EVENT) res = NETWORK_STATUS_SUCCESS; + if (wrote > 0 && res == LI_NETWORK_STATUS_WAIT_FOR_EVENT) res = LI_NETWORK_STATUS_SUCCESS; #ifdef TCP_CORK if (corked) { @@ -73,7 +73,7 @@ network_status_t network_write(vrequest *vr, int fd, chunkqueue *cq, goffset wri return res; } -network_status_t network_read(vrequest *vr, int fd, chunkqueue *cq) { +liNetworkStatus network_read(liVRequest *vr, int fd, liChunkQueue *cq) { const ssize_t blocksize = 16*1024; /* 16k */ off_t max_read = 16 * blocksize; /* 256k */ ssize_t r; @@ -99,21 +99,21 @@ network_status_t network_read(vrequest *vr, int fd, chunkqueue *cq) { #if EWOULDBLOCK != EAGAIN case EWOULDBLOCK: #endif - return len ? NETWORK_STATUS_SUCCESS : NETWORK_STATUS_WAIT_FOR_EVENT; + return len ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_WAIT_FOR_EVENT; case ECONNRESET: - return NETWORK_STATUS_CONNECTION_CLOSE; + return LI_NETWORK_STATUS_CONNECTION_CLOSE; default: VR_ERROR(vr, "oops, read from fd=%d failed: %s", fd, g_strerror(errno) ); - return NETWORK_STATUS_FATAL_ERROR; + return LI_NETWORK_STATUS_FATAL_ERROR; } } else if (0 == r) { g_byte_array_free(buf, TRUE); - return len ? NETWORK_STATUS_SUCCESS : NETWORK_STATUS_CONNECTION_CLOSE; + return len ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_CONNECTION_CLOSE; } g_byte_array_set_size(buf, r); chunkqueue_append_bytearr(cq, buf); len += r; } while (r == blocksize && len < max_read); - return NETWORK_STATUS_SUCCESS; + return LI_NETWORK_STATUS_SUCCESS; } diff --git a/src/network_sendfile.c b/src/network_sendfile.c index d7393c7..233975e 100644 --- a/src/network_sendfile.c +++ b/src/network_sendfile.c @@ -11,11 +11,11 @@ typedef enum { NSR_FATAL_ERROR } network_sendfile_result; -static network_sendfile_result lighty_sendfile(vrequest *vr, int fd, int filefd, goffset offset, ssize_t len, ssize_t *wrote); +static network_sendfile_result lighty_sendfile(liVRequest *vr, int fd, int filefd, goffset offset, ssize_t len, ssize_t *wrote); #if defined(USE_LINUX_SENDFILE) -static network_sendfile_result lighty_sendfile(vrequest *vr, int fd, int filefd, goffset offset, ssize_t len, ssize_t *wrote) { +static network_sendfile_result lighty_sendfile(liVRequest *vr, int fd, int filefd, goffset offset, ssize_t len, ssize_t *wrote) { ssize_t r; off_t file_offset = offset; @@ -46,7 +46,7 @@ static network_sendfile_result lighty_sendfile(vrequest *vr, int fd, int filefd, #elif defined(USE_FREEBSD_SENDFILE) -static network_sendfile_result lighty_sendfile(vrequest *vr, int fd, int filefd, goffset offset, ssize_t len, ssize_t *wrote) { +static network_sendfile_result lighty_sendfile(liVRequest *vr, int fd, int filefd, goffset offset, ssize_t len, ssize_t *wrote) { off_t r = 0; while (-1 == sendfile(filefd, fd, offset, len, NULL, &r, 0)) { @@ -82,7 +82,7 @@ static network_sendfile_result lighty_sendfile(vrequest *vr, int fd, int filefd, #elif defined(USE_SOLARIS_SENDFILEV) -static network_sendfile_result lighty_sendfile(vrequest *vr, int fd, int filefd, goffset offset, ssize_t len, ssize_t *wrote) { +static network_sendfile_result lighty_sendfile(liVRequest *vr, int fd, int filefd, goffset offset, ssize_t len, ssize_t *wrote) { sendfilevec_t fvec; fvec.sfv_fd = filefd; @@ -112,7 +112,7 @@ static network_sendfile_result lighty_sendfile(vrequest *vr, int fd, int filefd, #elif defined(USE_OSX_SENDFILE) -static network_sendfile_result lighty_sendfile(vrequest *vr, int fd, int filefd, goffset offset, ssize_t len, ssize_t *wrote) { +static network_sendfile_result lighty_sendfile(liVRequest *vr, int fd, int filefd, goffset offset, ssize_t len, ssize_t *wrote) { off_t bytes = len; while (-1 == sendfile(filefd, fd, offset, &bytes, NULL, 0)) { @@ -151,27 +151,27 @@ static network_sendfile_result lighty_sendfile(vrequest *vr, int fd, int filefd, /* first chunk must be a FILE_CHUNK ! */ -static network_status_t network_backend_sendfile(vrequest *vr, int fd, chunkqueue *cq, goffset *write_max) { +static liNetworkStatus network_backend_sendfile(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max) { off_t file_offset, toSend; ssize_t r; gboolean did_write_something = FALSE; - chunkiter ci; - chunk *c; + liChunkIter ci; + liChunk *c; - if (0 == cq->length) return NETWORK_STATUS_FATAL_ERROR; + if (0 == cq->length) return LI_NETWORK_STATUS_FATAL_ERROR; do { ci = chunkqueue_iter(cq); if (FILE_CHUNK != (c = chunkiter_chunk(ci))->type) { - return did_write_something ? NETWORK_STATUS_SUCCESS : NETWORK_STATUS_FATAL_ERROR; + return did_write_something ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_FATAL_ERROR; } switch (chunkfile_open(vr, c->file.file)) { - case HANDLER_GO_ON: + case LI_HANDLER_GO_ON: break; default: - return NETWORK_STATUS_FATAL_ERROR; + return LI_NETWORK_STATUS_FATAL_ERROR; } file_offset = c->offset + c->file.start; @@ -185,58 +185,58 @@ static network_status_t network_backend_sendfile(vrequest *vr, int fd, chunkqueu *write_max -= r; break; case NSR_WAIT_FOR_EVENT: - return NETWORK_STATUS_WAIT_FOR_EVENT; + return LI_NETWORK_STATUS_WAIT_FOR_EVENT; case NSR_FALLBACK: - NETWORK_FALLBACK(network_backend_write, write_max); + LI_NETWORK_FALLBACK(network_backend_write, write_max); break; case NSR_CLOSE: - return NETWORK_STATUS_CONNECTION_CLOSE; + return LI_NETWORK_STATUS_CONNECTION_CLOSE; case NSR_FATAL_ERROR: - return NETWORK_STATUS_FATAL_ERROR; + return LI_NETWORK_STATUS_FATAL_ERROR; } if (0 == r) { /* don't care about cached stat - file is open */ struct stat st; if (-1 == fstat(fd, &st)) { VR_ERROR(vr, "Couldn't fstat file: %s", g_strerror(errno)); - return NETWORK_STATUS_FATAL_ERROR; + return LI_NETWORK_STATUS_FATAL_ERROR; } if (file_offset > st.st_size) { /* file shrinked, close the connection */ VR_ERROR(vr, "%s", "File shrinked, aborting"); - return NETWORK_STATUS_FATAL_ERROR; + return LI_NETWORK_STATUS_FATAL_ERROR; } - return NETWORK_STATUS_WAIT_FOR_EVENT; + return LI_NETWORK_STATUS_WAIT_FOR_EVENT; } did_write_something = TRUE; - if (0 == cq->length) return NETWORK_STATUS_SUCCESS; - if (r != toSend) return NETWORK_STATUS_WAIT_FOR_EVENT; + if (0 == cq->length) return LI_NETWORK_STATUS_SUCCESS; + if (r != toSend) return LI_NETWORK_STATUS_WAIT_FOR_EVENT; } while (*write_max > 0); - return NETWORK_STATUS_SUCCESS; + return LI_NETWORK_STATUS_SUCCESS; } -network_status_t network_write_sendfile(vrequest *vr, int fd, chunkqueue *cq, goffset *write_max) { - if (cq->length == 0) return NETWORK_STATUS_FATAL_ERROR; +liNetworkStatus network_write_sendfile(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max) { + if (cq->length == 0) return LI_NETWORK_STATUS_FATAL_ERROR; do { switch (chunkqueue_first_chunk(cq)->type) { case MEM_CHUNK: case STRING_CHUNK: - NETWORK_FALLBACK(network_backend_writev, write_max); + LI_NETWORK_FALLBACK(network_backend_writev, write_max); break; case FILE_CHUNK: - NETWORK_FALLBACK(network_backend_sendfile, write_max); + LI_NETWORK_FALLBACK(network_backend_sendfile, write_max); break; default: - return NETWORK_STATUS_FATAL_ERROR; + return LI_NETWORK_STATUS_FATAL_ERROR; } - if (cq->length == 0) return NETWORK_STATUS_SUCCESS; + if (cq->length == 0) return LI_NETWORK_STATUS_SUCCESS; } while (*write_max > 0); - return NETWORK_STATUS_SUCCESS; + return LI_NETWORK_STATUS_SUCCESS; } #endif diff --git a/src/network_write.c b/src/network_write.c index d8afef7..4ad60d0 100644 --- a/src/network_write.c +++ b/src/network_write.c @@ -1,26 +1,26 @@ #include -network_status_t network_backend_write(vrequest *vr, int fd, chunkqueue *cq, goffset *write_max) { +liNetworkStatus network_backend_write(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max) { const ssize_t blocksize = 16*1024; /* 16k */ char *block_data; off_t block_len; ssize_t r; gboolean did_write_something = FALSE; - chunkiter ci; + liChunkIter ci; do { if (0 == cq->length) - return did_write_something ? NETWORK_STATUS_SUCCESS : NETWORK_STATUS_FATAL_ERROR; + return did_write_something ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_FATAL_ERROR; ci = chunkqueue_iter(cq); /* TODO: handle SIGBUS */ switch (chunkiter_read_mmap(vr, ci, 0, blocksize, &block_data, &block_len)) { - case HANDLER_GO_ON: + case LI_HANDLER_GO_ON: break; - case HANDLER_ERROR: + case LI_HANDLER_ERROR: default: - return NETWORK_STATUS_FATAL_ERROR; + return LI_NETWORK_STATUS_FATAL_ERROR; } if (-1 == (r = net_write(fd, block_data, block_len))) { @@ -29,16 +29,16 @@ network_status_t network_backend_write(vrequest *vr, int fd, chunkqueue *cq, gof #if EWOULDBLOCK != EAGAIN case EWOULDBLOCK: #endif - return did_write_something ? NETWORK_STATUS_SUCCESS : NETWORK_STATUS_WAIT_FOR_EVENT; + return did_write_something ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_WAIT_FOR_EVENT; case ECONNRESET: case EPIPE: - return NETWORK_STATUS_CONNECTION_CLOSE; + return LI_NETWORK_STATUS_CONNECTION_CLOSE; default: VR_ERROR(vr, "oops, write to fd=%d failed: %s", fd, g_strerror(errno)); - return NETWORK_STATUS_FATAL_ERROR; + return LI_NETWORK_STATUS_FATAL_ERROR; } } else if (0 == r) { - return did_write_something ? NETWORK_STATUS_SUCCESS : NETWORK_STATUS_WAIT_FOR_EVENT; + return did_write_something ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_WAIT_FOR_EVENT; } chunkqueue_skip(cq, r); @@ -46,5 +46,5 @@ network_status_t network_backend_write(vrequest *vr, int fd, chunkqueue *cq, gof *write_max -= r; } while (r == block_len && *write_max > 0); - return NETWORK_STATUS_SUCCESS; + return LI_NETWORK_STATUS_SUCCESS; } diff --git a/src/network_writev.c b/src/network_writev.c index da4d25a..713a084 100644 --- a/src/network_writev.c +++ b/src/network_writev.c @@ -25,13 +25,13 @@ #endif /* first chunk must be a STRING_CHUNK ! */ -network_status_t network_backend_writev(vrequest *vr, int fd, chunkqueue *cq, goffset *write_max) { +liNetworkStatus network_backend_writev(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max) { off_t we_have; ssize_t r; gboolean did_write_something = FALSE; - chunkiter ci; - chunk *c; - network_status_t res = NETWORK_STATUS_FATAL_ERROR; + liChunkIter ci; + liChunk *c; + liNetworkStatus res = LI_NETWORK_STATUS_FATAL_ERROR; GArray *chunks = g_array_sized_new(FALSE, TRUE, sizeof(struct iovec), UIO_MAXIOV); @@ -41,7 +41,7 @@ network_status_t network_backend_writev(vrequest *vr, int fd, chunkqueue *cq, go ci = chunkqueue_iter(cq); if (STRING_CHUNK != (c = chunkiter_chunk(ci))->type && MEM_CHUNK != c->type) { - res = did_write_something ? NETWORK_STATUS_SUCCESS : NETWORK_STATUS_FATAL_ERROR; + res = did_write_something ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_FATAL_ERROR; goto cleanup; } @@ -70,11 +70,11 @@ network_status_t network_backend_writev(vrequest *vr, int fd, chunkqueue *cq, go #if EWOULDBLOCK != EAGAIN case EWOULDBLOCK: #endif - res = NETWORK_STATUS_WAIT_FOR_EVENT; + res = LI_NETWORK_STATUS_WAIT_FOR_EVENT; goto cleanup; case ECONNRESET: case EPIPE: - res = NETWORK_STATUS_CONNECTION_CLOSE; + res = LI_NETWORK_STATUS_CONNECTION_CLOSE; goto cleanup; case EINTR: break; /* try again */ @@ -84,19 +84,19 @@ network_status_t network_backend_writev(vrequest *vr, int fd, chunkqueue *cq, go } } if (0 == r) { - res = NETWORK_STATUS_WAIT_FOR_EVENT; + res = LI_NETWORK_STATUS_WAIT_FOR_EVENT; goto cleanup; } chunkqueue_skip(cq, r); *write_max -= r; if (r != we_have) { - res = NETWORK_STATUS_WAIT_FOR_EVENT; + res = LI_NETWORK_STATUS_WAIT_FOR_EVENT; goto cleanup; } if (0 == cq->length) { - res = NETWORK_STATUS_SUCCESS; + res = LI_NETWORK_STATUS_SUCCESS; goto cleanup; } @@ -104,27 +104,27 @@ network_status_t network_backend_writev(vrequest *vr, int fd, chunkqueue *cq, go g_array_set_size(chunks, 0); } while (*write_max > 0); - res = NETWORK_STATUS_SUCCESS; + res = LI_NETWORK_STATUS_SUCCESS; cleanup: g_array_free(chunks, TRUE); return res; } -network_status_t network_write_writev(vrequest *vr, int fd, chunkqueue *cq, goffset *write_max) { - if (cq->length == 0) return NETWORK_STATUS_FATAL_ERROR; +liNetworkStatus network_write_writev(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max) { + if (cq->length == 0) return LI_NETWORK_STATUS_FATAL_ERROR; do { switch (chunkqueue_first_chunk(cq)->type) { case STRING_CHUNK: - NETWORK_FALLBACK(network_backend_writev, write_max); + LI_NETWORK_FALLBACK(network_backend_writev, write_max); break; case FILE_CHUNK: - NETWORK_FALLBACK(network_backend_write, write_max); + LI_NETWORK_FALLBACK(network_backend_write, write_max); break; default: - return NETWORK_STATUS_FATAL_ERROR; + return LI_NETWORK_STATUS_FATAL_ERROR; } - if (cq->length == 0) return NETWORK_STATUS_SUCCESS; + if (cq->length == 0) return LI_NETWORK_STATUS_SUCCESS; } while (*write_max > 0); - return NETWORK_STATUS_SUCCESS; + return LI_NETWORK_STATUS_SUCCESS; } diff --git a/src/options.c b/src/options.c index 80e5ef1..bceb652 100644 --- a/src/options.c +++ b/src/options.c @@ -2,48 +2,48 @@ #include /* Extract ovalue from ovalue, ovalue set to none */ -option_value value_extract(value *val) { - option_value oval = {0}; +liOptionValue value_extract(liValue *val) { + liOptionValue oval = {0}; if (!val) return oval; switch (val->type) { - case VALUE_NONE: + case LI_VALUE_NONE: break; - case VALUE_BOOLEAN: + case LI_VALUE_BOOLEAN: oval.boolean = val->data.boolean; break; - case VALUE_NUMBER: + case LI_VALUE_NUMBER: oval.number = val->data.number; break; - case VALUE_STRING: + case LI_VALUE_STRING: oval.string = val->data.string; break; - case VALUE_LIST: + case LI_VALUE_LIST: oval.list = val->data.list; break; - case VALUE_HASH: + case LI_VALUE_HASH: oval.hash = val->data.hash; break; - case VALUE_ACTION: + case LI_VALUE_ACTION: oval.ptr = val->data.val_action.action; break; - case VALUE_CONDITION: + case LI_VALUE_CONDITION: oval.ptr = val->data.val_action.action; break; } - val->type = VALUE_NONE; + val->type = LI_VALUE_NONE; return oval; } -gpointer value_extract_ptr(value *val) { - option_value oval = value_extract(val); +gpointer value_extract_ptr(liValue *val) { + liOptionValue oval = value_extract(val); return oval.ptr; } -gint64 value_extract_number(value *val) { - option_value oval = value_extract(val); +gint64 value_extract_number(liValue *val) { + liOptionValue oval = value_extract(val); return oval.number; } -gboolean value_extract_bool(value *val) { - option_value oval = value_extract(val); +gboolean value_extract_bool(liValue *val) { + liOptionValue oval = value_extract(val); return oval.boolean; } diff --git a/src/plugin.c b/src/plugin.c index 3f8b168..942ad76 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -1,19 +1,19 @@ #include -static gboolean plugin_load_default_option(server *srv, server_option *sopt); -static void plugin_free_default_options(server *srv, plugin *p); +static gboolean plugin_load_default_option(liServer *srv, liServerOption *sopt); +static void plugin_free_default_options(liServer *srv, liPlugin *p); -static plugin* plugin_new(const gchar *name) { - plugin *p = g_slice_new0(plugin); +static liPlugin* plugin_new(const gchar *name) { + liPlugin *p = g_slice_new0(liPlugin); p->name = name; return p; } -static void plugin_free_options(server *srv, plugin *p) { +static void plugin_free_options(liServer *srv, liPlugin *p) { size_t i; - const plugin_option *po; - server_option *so; + const liPluginOption *po; + liServerOption *so; if (!p->options) return; for (i = 0; (po = &p->options[i])->name; i++) { @@ -23,10 +23,10 @@ static void plugin_free_options(server *srv, plugin *p) { } } -static void plugin_free_actions(server *srv, plugin *p) { +static void plugin_free_actions(liServer *srv, liPlugin *p) { size_t i; - const plugin_action *pa; - server_action *sa; + const liPluginAction *pa; + liServerAction *sa; if (!p->actions) return; for (i = 0; (pa = &p->actions[i])->name; i++) { @@ -36,10 +36,10 @@ static void plugin_free_actions(server *srv, plugin *p) { } } -static void plugin_free_setups(server *srv, plugin *p) { +static void plugin_free_setups(liServer *srv, liPlugin *p) { size_t i; - const plugin_setup *ps; - server_setup *ss; + const liliPluginSetupCB *ps; + liServerSetup *ss; if (!p->setups) return; for (i = 0; (ps = &p->setups[i])->name; i++) { @@ -49,10 +49,10 @@ static void plugin_free_setups(server *srv, plugin *p) { } } -void plugin_free(server *srv, plugin *p) { +void plugin_free(liServer *srv, liPlugin *p) { if (!p) return; - if (g_atomic_int_get(&srv->state) == SERVER_RUNNING) { + if (g_atomic_int_get(&srv->state) == LI_SERVER_RUNNING) { ERROR(srv, "Cannot free plugin '%s' while server is running", p->name); return; } @@ -65,27 +65,27 @@ void plugin_free(server *srv, plugin *p) { if (p->free) p->free(srv, p); - g_slice_free(plugin, p); + g_slice_free(liPlugin, p); } -void server_plugins_free(server *srv) { +void server_plugins_free(liServer *srv) { gpointer key, val; GHashTableIter i; - if (g_atomic_int_get(&srv->state) == SERVER_RUNNING) { + if (g_atomic_int_get(&srv->state) == LI_SERVER_RUNNING) { ERROR(srv, "%s", "Cannot free plugins while server is running"); return; } g_hash_table_iter_init(&i, srv->plugins); while (g_hash_table_iter_next(&i, &key, &val)) { - plugin *p = (plugin*) val; + liPlugin *p = (liPlugin*) val; plugin_free_options(srv, p); plugin_free_actions(srv, p); plugin_free_setups(srv, p); - g_slice_free(plugin, p); + g_slice_free(liPlugin, p); } g_hash_table_destroy(srv->plugins); g_hash_table_destroy(srv->options); @@ -93,15 +93,15 @@ void server_plugins_free(server *srv) { g_hash_table_destroy(srv->setups); } -plugin *plugin_register(server *srv, const gchar *name, PluginInit init) { - plugin *p; +liPlugin *plugin_register(liServer *srv, const gchar *name, liPluginInitCB init) { + liPlugin *p; if (!init) { ERROR(srv, "Module '%s' needs an init function", name); return NULL; } - if (g_atomic_int_get(&srv->state) != SERVER_STARTING) { + if (g_atomic_int_get(&srv->state) != LI_SERVER_STARTING) { ERROR(srv, "Cannot register plugin '%s' after server was started", name); return NULL; } @@ -120,11 +120,11 @@ plugin *plugin_register(server *srv, const gchar *name, PluginInit init) { if (p->options) { size_t i; - server_option *so; - const plugin_option *po; + liServerOption *so; + const liPluginOption *po; for (i = 0; (po = &p->options[i])->name; i++) { - if (NULL != (so = (server_option*)g_hash_table_lookup(srv->options, po->name))) { + if (NULL != (so = (liServerOption*)g_hash_table_lookup(srv->options, po->name))) { ERROR(srv, "Option '%s' already registered by plugin '%s', unloading '%s'", po->name, so->p ? so->p->name : "", @@ -132,7 +132,7 @@ plugin *plugin_register(server *srv, const gchar *name, PluginInit init) { plugin_free(srv, p); return NULL; } - so = g_slice_new0(server_option); + so = g_slice_new0(liServerOption); so->type = po->type; so->parse_option = po->parse_option; so->free_option = po->free_option; @@ -147,11 +147,11 @@ plugin *plugin_register(server *srv, const gchar *name, PluginInit init) { if (p->actions) { size_t i; - server_action *sa; - const plugin_action *pa; + liServerAction *sa; + const liPluginAction *pa; for (i = 0; (pa = &p->actions[i])->name; i++) { - if (NULL != (sa = (server_action*)g_hash_table_lookup(srv->actions, pa->name))) { + if (NULL != (sa = (liServerAction*)g_hash_table_lookup(srv->actions, pa->name))) { ERROR(srv, "Action '%s' already registered by plugin '%s', unloading '%s'", pa->name, sa->p ? sa->p->name : "", @@ -159,7 +159,7 @@ plugin *plugin_register(server *srv, const gchar *name, PluginInit init) { plugin_free(srv, p); return NULL; } - sa = g_slice_new0(server_action); + sa = g_slice_new0(liServerAction); sa->create_action = pa->create_action; sa->p = p; g_hash_table_insert(srv->actions, (gchar*) pa->name, sa); @@ -168,11 +168,11 @@ plugin *plugin_register(server *srv, const gchar *name, PluginInit init) { if (p->setups) { size_t i; - server_setup *ss; - const plugin_setup *ps; + liServerSetup *ss; + const liliPluginSetupCB *ps; for (i = 0; (ps = &p->setups[i])->name; i++) { - if (NULL != (ss = (server_setup*)g_hash_table_lookup(srv->setups, ps->name))) { + if (NULL != (ss = (liServerSetup*)g_hash_table_lookup(srv->setups, ps->name))) { ERROR(srv, "Setup '%s' already registered by plugin '%s', unloading '%s'", ps->name, ss->p ? ss->p->name : "", @@ -180,7 +180,7 @@ plugin *plugin_register(server *srv, const gchar *name, PluginInit init) { plugin_free(srv, p); return NULL; } - ss = g_slice_new0(server_setup); + ss = g_slice_new0(liServerSetup); ss->setup = ps->setup; ss->p = p; g_hash_table_insert(srv->setups, (gchar*) ps->name, ss); @@ -191,12 +191,12 @@ plugin *plugin_register(server *srv, const gchar *name, PluginInit init) { } -static server_option* find_option(server *srv, const char *name) { - return (server_option*) g_hash_table_lookup(srv->options, name); +static liServerOption* find_option(liServer *srv, const char *name) { + return (liServerOption*) g_hash_table_lookup(srv->options, name); } -gboolean parse_option(server *srv, const char *name, value *val, option_set *mark) { - server_option *sopt; +gboolean parse_option(liServer *srv, const char *name, liValue *val, liOptionSet *mark) { + liServerOption *sopt; if (!srv || !name || !mark) return FALSE; @@ -206,7 +206,7 @@ gboolean parse_option(server *srv, const char *name, value *val, option_set *mar return FALSE; } - if (sopt->type != val->type && sopt->type != VALUE_NONE) { + if (sopt->type != val->type && sopt->type != LI_VALUE_NONE) { ERROR(srv, "Unexpected value type '%s', expected '%s' for option %s", value_type_string(val->type), value_type_string(sopt->type), name); return FALSE; @@ -227,36 +227,36 @@ gboolean parse_option(server *srv, const char *name, value *val, option_set *mar return TRUE; } -void release_option(server *srv, option_set *mark) { /** Does not free the option_set memory */ - server_option *sopt; +void release_option(liServer *srv, liOptionSet *mark) { /** Does not free the option_set memory */ + liServerOption *sopt; if (!srv || !mark || !mark->sopt) return; sopt = mark->sopt; mark->sopt = NULL; if (!sopt->free_option) { switch (sopt->type) { - case VALUE_NONE: - case VALUE_BOOLEAN: - case VALUE_NUMBER: + case LI_VALUE_NONE: + case LI_VALUE_BOOLEAN: + case LI_VALUE_NUMBER: /* Nothing to free */ break; - case VALUE_STRING: + case LI_VALUE_STRING: if (mark->value.string) g_string_free(mark->value.string, TRUE); break; - case VALUE_LIST: + case LI_VALUE_LIST: if (mark->value.list) value_list_free(mark->value.list); break; - case VALUE_HASH: + case LI_VALUE_HASH: if (mark->value.hash) g_hash_table_destroy(mark->value.hash); break; - case VALUE_ACTION: + case LI_VALUE_ACTION: if (mark->value.action) action_release(srv, mark->value.action); break; - case VALUE_CONDITION: + case LI_VALUE_CONDITION: if (mark->value.cond) condition_release(srv, mark->value.cond); break; @@ -265,13 +265,13 @@ void release_option(server *srv, option_set *mark) { /** Does not free the optio sopt->free_option(srv, sopt->p, sopt->module_index, mark->value); } { - option_value empty = {0}; + liOptionValue empty = {0}; mark->value = empty; } } -action* option_action(server *srv, const gchar *name, value *val) { - option_set setting; +liAction* option_action(liServer *srv, const gchar *name, liValue *val) { + liOptionSet setting; if (!parse_option(srv, name, val, &setting)) { return NULL; @@ -280,11 +280,11 @@ action* option_action(server *srv, const gchar *name, value *val) { return action_new_setting(setting); } -action* create_action(server *srv, const gchar *name, value *val) { - action *a; - server_action *sa; +liAction* create_action(liServer *srv, const gchar *name, liValue *val) { + liAction *a; + liServerAction *sa; - if (NULL == (sa = (server_action*) g_hash_table_lookup(srv->actions, name))) { + if (NULL == (sa = (liServerAction*) g_hash_table_lookup(srv->actions, name))) { ERROR(srv, "Action '%s' doesn't exist", name); return NULL; } @@ -297,10 +297,10 @@ action* create_action(server *srv, const gchar *name, value *val) { return a; } -gboolean call_setup(server *srv, const char *name, value *val) { - server_setup *ss; +gboolean call_setup(liServer *srv, const char *name, liValue *val) { + liServerSetup *ss; - if (NULL == (ss = (server_setup*) g_hash_table_lookup(srv->setups, name))) { + if (NULL == (ss = (liServerSetup*) g_hash_table_lookup(srv->setups, name))) { ERROR(srv, "Setup function '%s' doesn't exist", name); return FALSE; } @@ -313,14 +313,14 @@ gboolean call_setup(server *srv, const char *name, value *val) { return TRUE; } -void plugins_prepare_callbacks(server *srv) { +void plugins_prepare_callbacks(liServer *srv) { GHashTableIter iter; - plugin *p; + liPlugin *p; gpointer v; g_hash_table_iter_init(&iter, srv->plugins); while (g_hash_table_iter_next(&iter, NULL, &v)) { - p = (plugin*) v; + p = (liPlugin*) v; if (p->handle_close) g_array_append_val(srv->plugins_handle_close, p); if (p->handle_vrclose) @@ -328,28 +328,28 @@ void plugins_prepare_callbacks(server *srv) { } } -void plugins_handle_close(connection *con) { +void plugins_handle_close(liConnection *con) { GArray *a = con->srv->plugins_handle_close; guint i, len = a->len; for (i = 0; i < len; i++) { - plugin *p = g_array_index(a, plugin*, i); + liPlugin *p = g_array_index(a, liPlugin*, i); p->handle_close(con, p); } } -void plugins_handle_vrclose(vrequest *vr) { +void plugins_handle_vrclose(liVRequest *vr) { GArray *a = vr->wrk->srv->plugins_handle_vrclose; guint i, len = a->len; for (i = 0; i < len; i++) { - plugin *p = g_array_index(a, plugin*, i); + liPlugin *p = g_array_index(a, liPlugin*, i); p->handle_vrclose(vr, p); } } -gboolean plugin_set_default_option(server *srv, const gchar* name, value *val) { - server_option *sopt; - option_set setting; - option_value v; +gboolean plugin_set_default_option(liServer *srv, const gchar* name, liValue *val) { + liServerOption *sopt; + liOptionSet setting; + liOptionValue v; sopt = find_option(srv, name); @@ -363,8 +363,8 @@ gboolean plugin_set_default_option(server *srv, const gchar* name, value *val) { return FALSE; } - v = g_array_index(srv->option_def_values, option_value, sopt->index); - g_array_index(srv->option_def_values, option_value, sopt->index) = setting.value; + v = g_array_index(srv->option_def_values, liOptionValue, sopt->index); + g_array_index(srv->option_def_values, liOptionValue, sopt->index) = setting.value; /* free old value */ setting.sopt = sopt; @@ -376,22 +376,22 @@ gboolean plugin_set_default_option(server *srv, const gchar* name, value *val) { return TRUE; } -static gboolean plugin_load_default_option(server *srv, server_option *sopt) { - option_value oval = {0}; +static gboolean plugin_load_default_option(liServer *srv, liServerOption *sopt) { + liOptionValue oval = {0}; if (!sopt) return FALSE; if (!sopt->parse_option) { switch (sopt->type) { - case VALUE_NONE: + case LI_VALUE_NONE: break; - case VALUE_BOOLEAN: + case LI_VALUE_BOOLEAN: oval.boolean = GPOINTER_TO_INT(sopt->default_value); - case VALUE_NUMBER: + case LI_VALUE_NUMBER: oval.number = GPOINTER_TO_INT(sopt->default_value); break; - case VALUE_STRING: + case LI_VALUE_STRING: oval.string = g_string_new((const char*) sopt->default_value); break; default: @@ -407,29 +407,29 @@ static gboolean plugin_load_default_option(server *srv, server_option *sopt) { if (srv->option_def_values->len <= sopt->index) g_array_set_size(srv->option_def_values, sopt->index + 1); - g_array_index(srv->option_def_values, option_value, sopt->index) = oval; + g_array_index(srv->option_def_values, liOptionValue, sopt->index) = oval; return TRUE; } -static void plugin_free_default_options(server *srv, plugin *p) { - static const option_value oempty = {0}; +static void plugin_free_default_options(liServer *srv, liPlugin *p) { + static const liOptionValue oempty = {0}; GHashTableIter iter; gpointer k, v; g_hash_table_iter_init(&iter, srv->options); while (g_hash_table_iter_next(&iter, &k, &v)) { - server_option *sopt = v; - option_set mark; + liServerOption *sopt = v; + liOptionSet mark; mark.sopt = sopt; mark.ndx = sopt->index; if (sopt->p != p) continue; - mark.value = g_array_index(srv->option_def_values, option_value, sopt->index); + mark.value = g_array_index(srv->option_def_values, liOptionValue, sopt->index); release_option(srv, &mark); - g_array_index(srv->option_def_values, option_value, sopt->index) = oempty; + g_array_index(srv->option_def_values, liOptionValue, sopt->index) = oempty; } } diff --git a/src/plugin_core.c b/src/plugin_core.c index 875db18..5db31c4 100644 --- a/src/plugin_core.c +++ b/src/plugin_core.c @@ -6,8 +6,8 @@ #include #include -static action* core_list(server *srv, plugin* p, value *val) { - action *a; +static liAction* core_list(liServer *srv, liPlugin* p, liValue *val) { + liAction *a; guint i; UNUSED(p); @@ -16,21 +16,21 @@ static action* core_list(server *srv, plugin* p, value *val) { return NULL; } - if (val->type == VALUE_ACTION) { + if (val->type == LI_VALUE_ACTION) { a = val->data.val_action.action; action_acquire(a); return a; } - if (val->type != VALUE_LIST) { + if (val->type != LI_VALUE_LIST) { ERROR(srv, "expected list, got %s", value_type_string(val->type)); return NULL; } a = action_new_list(); for (i = 0; i < val->data.list->len; i++) { - value *oa = g_array_index(val->data.list, value*, i); - if (oa->type != VALUE_ACTION) { + liValue *oa = g_array_index(val->data.list, liValue*, i); + if (oa->type != LI_VALUE_ACTION) { ERROR(srv, "expected action at entry %u of list, got %s", i, value_type_string(oa->type)); action_release(srv, a); return NULL; @@ -42,16 +42,16 @@ static action* core_list(server *srv, plugin* p, value *val) { return a; } -static action* core_when(server *srv, plugin* p, value *val) { - value *val_cond, *val_act, *val_act_else; - action *a, *act = NULL, *act_else = NULL; +static liAction* core_when(liServer *srv, liPlugin* p, liValue *val) { + liValue *val_cond, *val_act, *val_act_else; + liAction *a, *act = NULL, *act_else = NULL; UNUSED(p); if (!val) { ERROR(srv, "%s", "need parameter"); return NULL; } - if (val->type != VALUE_LIST) { + if (val->type != LI_VALUE_LIST) { ERROR(srv, "expected list, got %s", value_type_string(val->type)); return NULL; } @@ -59,30 +59,30 @@ static action* core_when(server *srv, plugin* p, value *val) { val_act_else = NULL; act_else = NULL; } else if (val->data.list->len == 3) { - val_act_else = g_array_index(val->data.list, value*, 2); + val_act_else = g_array_index(val->data.list, liValue*, 2); } else { ERROR(srv, "expected list with length 2 or 3, has length %u", val->data.list->len); return NULL; } - val_cond = g_array_index(val->data.list, value*, 0); - val_act = g_array_index(val->data.list, value*, 1); + val_cond = g_array_index(val->data.list, liValue*, 0); + val_act = g_array_index(val->data.list, liValue*, 1); - if (val_cond->type != VALUE_CONDITION) { + if (val_cond->type != LI_VALUE_CONDITION) { ERROR(srv, "expected condition as first parameter, got %s", value_type_string(val_cond->type)); return NULL; } - if (val_act->type == VALUE_NONE) { + if (val_act->type == LI_VALUE_NONE) { act = NULL; - } else if (val_act->type == VALUE_ACTION) { + } else if (val_act->type == LI_VALUE_ACTION) { act = val_act->data.val_action.action; } else { ERROR(srv, "expected action as second parameter, got %s", value_type_string(val_act->type)); return NULL; } if (val_act_else) { - if (val_act_else->type == VALUE_NONE) { + if (val_act_else->type == LI_VALUE_NONE) { act_else = NULL; - } else if (val_act_else->type == VALUE_ACTION) { + } else if (val_act_else->type == LI_VALUE_ACTION) { act_else = val_act_else->data.val_action.action; } else { ERROR(srv, "expected action as third parameter, got %s", value_type_string(val_act_else->type)); @@ -96,16 +96,16 @@ static action* core_when(server *srv, plugin* p, value *val) { return a; } -static action* core_set(server *srv, plugin* p, value *val) { - value *val_val, *val_name; - action *a; +static liAction* core_set(liServer *srv, liPlugin* p, liValue *val) { + liValue *val_val, *val_name; + liAction *a; UNUSED(p); if (!val) { ERROR(srv, "%s", "need parameter"); return NULL; } - if (val->type != VALUE_LIST) { + if (val->type != LI_VALUE_LIST) { ERROR(srv, "expected list, got %s", value_type_string(val->type)); return NULL; } @@ -113,9 +113,9 @@ static action* core_set(server *srv, plugin* p, value *val) { ERROR(srv, "expected list with length 2, has length %u", val->data.list->len); return NULL; } - val_name = g_array_index(val->data.list, value*, 0); - val_val = g_array_index(val->data.list, value*, 1); - if (val_name->type != VALUE_STRING) { + val_name = g_array_index(val->data.list, liValue*, 0); + val_val = g_array_index(val->data.list, liValue*, 1); + if (val_name->type != LI_VALUE_STRING) { ERROR(srv, "expected string as first parameter, got %s", value_type_string(val_name->type)); return NULL; } @@ -123,15 +123,15 @@ static action* core_set(server *srv, plugin* p, value *val) { return a; } -static gboolean core_setup_set(server *srv, plugin* p, value *val) { - value *val_val, *val_name; +static gboolean core_setup_set(liServer *srv, liPlugin* p, liValue *val) { + liValue *val_val, *val_name; UNUSED(p); if (!val) { ERROR(srv, "%s", "need parameter"); return FALSE; } - if (val->type != VALUE_LIST) { + if (val->type != LI_VALUE_LIST) { ERROR(srv, "expected list, got %s", value_type_string(val->type)); return FALSE; } @@ -139,16 +139,16 @@ static gboolean core_setup_set(server *srv, plugin* p, value *val) { ERROR(srv, "expected list with length 2, has length %u", val->data.list->len); return FALSE; } - val_name = g_array_index(val->data.list, value*, 0); - val_val = g_array_index(val->data.list, value*, 1); - if (val_name->type != VALUE_STRING) { + val_name = g_array_index(val->data.list, liValue*, 0); + val_val = g_array_index(val->data.list, liValue*, 1); + if (val_name->type != LI_VALUE_STRING) { ERROR(srv, "expected string as first parameter, got %s", value_type_string(val_name->type)); return FALSE; } return plugin_set_default_option(srv, val_name->data.string->str, val_val); } -static handler_t core_handle_docroot(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_docroot(liVRequest *vr, gpointer param, gpointer *context) { UNUSED(context); g_string_truncate(vr->physical.doc_root, 0); @@ -166,17 +166,17 @@ static handler_t core_handle_docroot(vrequest *vr, gpointer param, gpointer *con VR_DEBUG(vr, "physical path: %s", vr->physical.path->str); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static void core_docroot_free(server *srv, gpointer param) { +static void core_docroot_free(liServer *srv, gpointer param) { UNUSED(srv); g_string_free(param, TRUE); } -static action* core_docroot(server *srv, plugin* p, value *val) { +static liAction* core_docroot(liServer *srv, liPlugin* p, liValue *val) { UNUSED(p); - if (!val || val->type != VALUE_STRING) { + if (!val || val->type != LI_VALUE_STRING) { ERROR(srv, "%s", "docroot action expects a string parameter"); return NULL; } @@ -185,8 +185,8 @@ static action* core_docroot(server *srv, plugin* p, value *val) { } -static handler_t core_handle_index(vrequest *vr, gpointer param, gpointer *context) { - handler_t res; +static liHandlerResult core_handle_index(liVRequest *vr, gpointer param, gpointer *context) { + liHandlerResult res; guint i; struct stat st; gint err; @@ -197,21 +197,21 @@ static handler_t core_handle_index(vrequest *vr, gpointer param, gpointer *conte if (!vr->physical.doc_root->len) { VR_ERROR(vr, "%s", "no docroot specified yet but index action called"); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } res = stat_cache_get(vr, vr->physical.path, &st, &err, NULL); - if (res == HANDLER_WAIT_FOR_EVENT) - return HANDLER_WAIT_FOR_EVENT; + if (res == LI_HANDLER_WAIT_FOR_EVENT) + return LI_HANDLER_WAIT_FOR_EVENT; - if (res == HANDLER_ERROR) { + if (res == LI_HANDLER_ERROR) { /* we ignore errors here so a later action can deal with it (e.g. 'static') */ - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } if (!S_ISDIR(st.st_mode)) - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; /* we use two temporary strings here, one to append to docroot and one to append to physical path */ tmp_docroot = vr->wrk->tmp_str; @@ -221,7 +221,7 @@ static handler_t core_handle_index(vrequest *vr, gpointer param, gpointer *conte /* loop through the list to find a possible index file */ for (i = 0; i < files->len; i++) { - file = g_array_index(files, value*, i)->data.string; + file = g_array_index(files, liValue*, i)->data.string; if (file->str[0] == '/') { /* entries beginning with a slash shall be looked up directly at the docroot */ @@ -234,52 +234,52 @@ static handler_t core_handle_index(vrequest *vr, gpointer param, gpointer *conte res = stat_cache_get(vr, tmp_path, &st, &err, NULL); } - if (res == HANDLER_WAIT_FOR_EVENT) { + if (res == LI_HANDLER_WAIT_FOR_EVENT) { g_string_free(tmp_path, TRUE); - return HANDLER_WAIT_FOR_EVENT; + return LI_HANDLER_WAIT_FOR_EVENT; } - if (res == HANDLER_GO_ON) { + if (res == LI_HANDLER_GO_ON) { /* file exists. change physical path */ if (file->str[0] == '/') g_string_truncate(vr->physical.path, vr->physical.doc_root->len); g_string_append_len(vr->physical.path, GSTR_LEN(file)); - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "using index file: '%s'", file->str); } g_string_free(tmp_path, TRUE); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } } g_string_free(tmp_path, TRUE); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static void core_index_free(server *srv, gpointer param) { +static void core_index_free(liServer *srv, gpointer param) { guint i; GArray *files = param; UNUSED(srv); for (i = 0; i < files->len; i++) - value_free(g_array_index(files, value*, i)); + value_free(g_array_index(files, liValue*, i)); g_array_free(files, TRUE); } -static action* core_index(server *srv, plugin* p, value *val) { +static liAction* core_index(liServer *srv, liPlugin* p, liValue *val) { GArray *files; guint i; UNUSED(p); - if (!val || val->type != VALUE_LIST) { + if (!val || val->type != LI_VALUE_LIST) { ERROR(srv, "%s", "index action expects a list of strings as parameter"); return NULL; } @@ -287,7 +287,7 @@ static action* core_index(server *srv, plugin* p, value *val) { files = val->data.list; for (i = 0; i < files->len; i++) { - if (g_array_index(files, value*, i)->type != VALUE_STRING) { + if (g_array_index(files, liValue*, i)->type != LI_VALUE_STRING) { ERROR(srv, "%s", "index action expects a list of strings as parameter"); return NULL; } @@ -297,63 +297,63 @@ static action* core_index(server *srv, plugin* p, value *val) { } -static handler_t core_handle_static(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_static(liVRequest *vr, gpointer param, gpointer *context) { int fd; struct stat st; int err; - handler_t res; + liHandlerResult res; UNUSED(param); UNUSED(context); switch (vr->request.http_method) { - case HTTP_METHOD_GET: - case HTTP_METHOD_HEAD: + case LI_HTTP_METHOD_GET: + case LI_HTTP_METHOD_HEAD: break; default: - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } - if (vrequest_is_handled(vr)) return HANDLER_GO_ON; + if (vrequest_is_handled(vr)) return LI_HANDLER_GO_ON; - if (vr->physical.path->len == 0) return HANDLER_GO_ON; + if (vr->physical.path->len == 0) return LI_HANDLER_GO_ON; res = stat_cache_get(vr, vr->physical.path, &st, &err, &fd); - if (res == HANDLER_WAIT_FOR_EVENT) + if (res == LI_HANDLER_WAIT_FOR_EVENT) return res; - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "try serving static file: '%s'", vr->physical.path->str); } - if (res == HANDLER_ERROR) { + if (res == LI_HANDLER_ERROR) { /* open or fstat failed */ if (fd != -1) close(fd); if (!vrequest_handle_direct(vr)) { - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } switch (err) { case ENOENT: case ENOTDIR: vr->response.http_status = 404; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; case EACCES: vr->response.http_status = 403; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; default: VR_ERROR(vr, "stat() or open() for '%s' failed: %s", vr->physical.path->str, g_strerror(err)); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } } else if (S_ISDIR(st.st_mode)) { if (fd != -1) close(fd); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } else if (!S_ISREG(st.st_mode)) { - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "not a regular file: '%s'", vr->physical.path->str); } @@ -361,7 +361,7 @@ static handler_t core_handle_static(vrequest *vr, gpointer param, gpointer *cont close(fd); if (!vrequest_handle_direct(vr)) { - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } vr->response.http_status = 403; } else { @@ -373,14 +373,14 @@ static handler_t core_handle_static(vrequest *vr, gpointer param, gpointer *cont if (!vrequest_handle_direct(vr)) { close(fd); - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } etag_set_header(vr, &st, &cachable); if (cachable) { vr->response.http_status = 304; close(fd); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } mime_str = mimetype_get(vr, vr->physical.path); @@ -392,10 +392,10 @@ static handler_t core_handle_static(vrequest *vr, gpointer param, gpointer *cont chunkqueue_append_file_fd(vr->out, NULL, 0, st.st_size, fd); } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* core_static(server *srv, plugin* p, value *val) { +static liAction* core_static(liServer *srv, liPlugin* p, liValue *val) { UNUSED(p); if (val) { ERROR(srv, "%s", "static action doesn't have parameters"); @@ -406,21 +406,21 @@ static action* core_static(server *srv, plugin* p, value *val) { } -static handler_t core_handle_status(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_status(liVRequest *vr, gpointer param, gpointer *context) { UNUSED(param); UNUSED(context); vr->response.http_status = GPOINTER_TO_INT(param); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* core_status(server *srv, plugin* p, value *val) { +static liAction* core_status(liServer *srv, liPlugin* p, liValue *val) { gpointer ptr; UNUSED(p); - if (val || val->type != VALUE_NUMBER) { + if (val || val->type != LI_VALUE_NUMBER) { ERROR(srv, "%s", "status action expects a number as parameter"); return NULL; } @@ -431,24 +431,24 @@ static action* core_status(server *srv, plugin* p, value *val) { } -static void core_log_write_free(server *srv, gpointer param) { +static void core_log_write_free(liServer *srv, gpointer param) { UNUSED(srv); g_string_free(param, TRUE); } -static handler_t core_handle_log_write(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_log_write(liVRequest *vr, gpointer param, gpointer *context) { GString *msg = param; UNUSED(context); VR_INFO(vr, "%s", msg->str); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* core_log_write(server *srv, plugin* p, value *val) { +static liAction* core_log_write(liServer *srv, liPlugin* p, liValue *val) { UNUSED(p); - if (!val || val->type != VALUE_STRING) { + if (!val || val->type != LI_VALUE_STRING) { ERROR(srv, "%s", "log.write expects a string parameter"); return NULL; } @@ -457,18 +457,18 @@ static action* core_log_write(server *srv, plugin* p, value *val) { } -static handler_t core_handle_blank(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_blank(liVRequest *vr, gpointer param, gpointer *context) { UNUSED(param); UNUSED(context); - if (!vrequest_handle_direct(vr)) return HANDLER_GO_ON; + if (!vrequest_handle_direct(vr)) return LI_HANDLER_GO_ON; vr->response.http_status = 200; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* core_blank(server *srv, plugin* p, value *val) { +static liAction* core_blank(liServer *srv, liPlugin* p, liValue *val) { UNUSED(p); if (val) { @@ -479,7 +479,7 @@ static action* core_blank(server *srv, plugin* p, value *val) { return action_new_function(core_handle_blank, NULL, NULL, NULL); } -static handler_t core_handle_profile_mem(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_profile_mem(liVRequest *vr, gpointer param, gpointer *context) { UNUSED(vr); UNUSED(param); UNUSED(context); @@ -487,10 +487,10 @@ static handler_t core_handle_profile_mem(vrequest *vr, gpointer param, gpointer /*g_mem_profile();*/ profiler_dump(); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* core_profile_mem(server *srv, plugin* p, value *val) { +static liAction* core_profile_mem(liServer *srv, liPlugin* p, liValue *val) { UNUSED(p); if (val) { @@ -501,11 +501,11 @@ static action* core_profile_mem(server *srv, plugin* p, value *val) { return action_new_function(core_handle_profile_mem, NULL, NULL, NULL); } -static gboolean core_listen(server *srv, plugin* p, value *val) { +static gboolean core_listen(liServer *srv, liPlugin* p, liValue *val) { GString *ipstr; UNUSED(p); - if (val->type != VALUE_STRING) { + if (val->type != LI_VALUE_STRING) { ERROR(srv, "%s", "listen expects a string as parameter"); return FALSE; } @@ -517,12 +517,12 @@ static gboolean core_listen(server *srv, plugin* p, value *val) { } -static gboolean core_event_handler(server *srv, plugin* p, value *val) { +static gboolean core_event_handler(liServer *srv, liPlugin* p, liValue *val) { guint backend; gchar *str; UNUSED(p); - if (val->type != VALUE_STRING) { + if (val->type != LI_VALUE_STRING) { ERROR(srv, "%s", "event_handler expects a string as parameter"); return FALSE; } @@ -563,12 +563,12 @@ static gboolean core_event_handler(server *srv, plugin* p, value *val) { return TRUE; } -static gboolean core_workers(server *srv, plugin* p, value *val) { +static gboolean core_workers(liServer *srv, liPlugin* p, liValue *val) { gint workers; UNUSED(p); workers = val->data.number; - if (val->type != VALUE_NUMBER || workers < 1) { + if (val->type != LI_VALUE_NUMBER || workers < 1) { ERROR(srv, "%s", "workers expects a positive integer as parameter"); return FALSE; } @@ -580,8 +580,8 @@ static gboolean core_workers(server *srv, plugin* p, value *val) { return TRUE; } -static gboolean core_module_load(server *srv, plugin* p, value *val) { - value *mods = value_new_list(); +static gboolean core_module_load(liServer *srv, liPlugin* p, liValue *val) { + liValue *mods = value_new_list(); UNUSED(p); if (!g_module_supported()) { @@ -590,15 +590,15 @@ static gboolean core_module_load(server *srv, plugin* p, value *val) { return FALSE; } - if (val->type == VALUE_STRING) { + if (val->type == LI_VALUE_STRING) { /* load only one module */ - value *name = value_new_string(value_extract(val).string); + liValue *name = value_new_string(value_extract(val).string); g_array_append_val(mods->data.list, name); - } else if (val->type == VALUE_LIST) { + } else if (val->type == LI_VALUE_LIST) { /* load a list of modules */ for (guint i = 0; i < val->data.list->len; i++) { - value *v = g_array_index(val->data.list, value*, i); - if (v->type != VALUE_STRING) { + liValue *v = g_array_index(val->data.list, liValue*, i); + if (v->type != LI_VALUE_STRING) { ERROR(srv, "module_load takes either a string or a list of strings as parameter, list with %s entry given", value_type_string(v->type)); value_free(mods); return FALSE; @@ -613,7 +613,7 @@ static gboolean core_module_load(server *srv, plugin* p, value *val) { /* parameter types ok, load modules */ for (guint i = 0; i < mods->data.list->len; i++) { - GString *name = g_array_index(mods->data.list, value*, i)->data.string; + GString *name = g_array_index(mods->data.list, liValue*, i)->data.string; if (!module_load(srv->modules, name->str)) { ERROR(srv, "could not load module '%s': %s", name->str, g_module_error()); value_free(mods); @@ -628,10 +628,10 @@ static gboolean core_module_load(server *srv, plugin* p, value *val) { return TRUE; } -static gboolean core_io_timeout(server *srv, plugin* p, value *val) { +static gboolean core_io_timeout(liServer *srv, liPlugin* p, liValue *val) { UNUSED(p); - if (!val || val->type != VALUE_NUMBER || val->data.number < 1) { + if (!val || val->type != LI_VALUE_NUMBER || val->data.number < 1) { ERROR(srv, "%s", "io_timeout expects a positive number as parameter"); return FALSE; } @@ -641,10 +641,10 @@ static gboolean core_io_timeout(server *srv, plugin* p, value *val) { return TRUE; } -static gboolean core_stat_cache_ttl(server *srv, plugin* p, value *val) { +static gboolean core_stat_cache_ttl(liServer *srv, liPlugin* p, liValue *val) { UNUSED(p); - if (!val || val->type != VALUE_NUMBER || val->data.number < 1) { + if (!val || val->type != LI_VALUE_NUMBER || val->data.number < 1) { ERROR(srv, "%s", "stat_cache.ttl expects a positive number as parameter"); return FALSE; } @@ -658,13 +658,13 @@ static gboolean core_stat_cache_ttl(server *srv, plugin* p, value *val) { * OPTIONS */ -static gboolean core_option_log_parse(server *srv, plugin *p, size_t ndx, value *val, option_value *oval) { +static gboolean core_option_log_parse(liServer *srv, liPlugin *p, size_t ndx, liValue *val, liOptionValue *oval) { GHashTableIter iter; gpointer k, v; - log_level_t level; + liLogLevel level; GString *path; GString *level_str; - GArray *arr = g_array_sized_new(FALSE, TRUE, sizeof(log_t*), 6); + GArray *arr = g_array_sized_new(FALSE, TRUE, sizeof(liLog*), 6); UNUSED(p); UNUSED(ndx); @@ -673,49 +673,49 @@ static gboolean core_option_log_parse(server *srv, plugin *p, size_t ndx, value /* default value */ if (!val) { - /* default: log LOG_LEVEL_WARNING, LOG_LEVEL_ERROR and LOG_LEVEL_BACKEND to stderr */ - log_t *log = srv->logs.stderr; + /* default: log LI_LOG_LEVEL_WARNING, LI_LOG_LEVEL_ERROR and LI_LOG_LEVEL_BACKEND to stderr */ + liLog *log = srv->logs.stderr; log_ref(srv, log); - g_array_index(arr, log_t*, LOG_LEVEL_WARNING) = log; + g_array_index(arr, liLog*, LI_LOG_LEVEL_WARNING) = log; log_ref(srv, log); - g_array_index(arr, log_t*, LOG_LEVEL_ERROR) = log; + g_array_index(arr, liLog*, LI_LOG_LEVEL_ERROR) = log; log_ref(srv, log); - g_array_index(arr, log_t*, LOG_LEVEL_BACKEND) = log; + g_array_index(arr, liLog*, LI_LOG_LEVEL_BACKEND) = log; return TRUE; } g_hash_table_iter_init(&iter, val->data.hash); while (g_hash_table_iter_next(&iter, &k, &v)) { - if (((value*)v)->type != VALUE_STRING) { - ERROR(srv, "log expects a hashtable with string values, %s given", value_type_string(((value*)v)->type)); + if (((liValue*)v)->type != LI_VALUE_STRING) { + ERROR(srv, "log expects a hashtable with string values, %s given", value_type_string(((liValue*)v)->type)); g_array_free(arr, TRUE); return FALSE; } - path = ((value*)v)->data.string; + path = ((liValue*)v)->data.string; level_str = (GString*)k; if (g_str_equal(level_str->str, "*")) { for (guint i = 0; i < arr->len; i++) { - log_t *log; + liLog *log; - if (NULL != g_array_index(arr, log_t*, i)) + if (NULL != g_array_index(arr, liLog*, i)) continue; log = log_new(srv, log_type_from_path(path), path); - g_array_index(arr, log_t*, i) = log; + g_array_index(arr, liLog*, i) = log; } } else { - log_t *log = log_new(srv, log_type_from_path(path), path); + liLog *log = log_new(srv, log_type_from_path(path), path); level = log_level_from_string(level_str); - g_array_index(arr, log_t*, level) = log; + g_array_index(arr, liLog*, level) = log; } } return TRUE; } -static void core_option_log_free(server *srv, plugin *p, size_t ndx, option_value oval) { +static void core_option_log_free(liServer *srv, liPlugin *p, size_t ndx, liOptionValue oval) { GArray *arr = oval.list; UNUSED(p); UNUSED(ndx); @@ -723,13 +723,13 @@ static void core_option_log_free(server *srv, plugin *p, size_t ndx, option_valu if (!arr) return; for (guint i = 0; i < arr->len; i++) { - if (NULL != g_array_index(arr, log_t*, i)) - log_unref(srv, g_array_index(arr, log_t*, i)); + if (NULL != g_array_index(arr, liLog*, i)) + log_unref(srv, g_array_index(arr, liLog*, i)); } g_array_free(arr, TRUE); } -static gboolean core_option_log_timestamp_parse(server *srv, plugin *p, size_t ndx, value *val, option_value *oval) { +static gboolean core_option_log_timestamp_parse(liServer *srv, liPlugin *p, size_t ndx, liValue *val, liOptionValue *oval) { UNUSED(p); UNUSED(ndx); @@ -739,7 +739,7 @@ static gboolean core_option_log_timestamp_parse(server *srv, plugin *p, size_t n return TRUE; } -static void core_option_log_timestamp_free(server *srv, plugin *p, size_t ndx, option_value oval) { +static void core_option_log_timestamp_free(liServer *srv, liPlugin *p, size_t ndx, liOptionValue oval) { UNUSED(p); UNUSED(ndx); @@ -747,7 +747,7 @@ static void core_option_log_timestamp_free(server *srv, plugin *p, size_t ndx, o log_timestamp_free(srv, oval.ptr); } -static gboolean core_option_mime_types_parse(server *srv, plugin *p, size_t ndx, value *val, option_value *oval) { +static gboolean core_option_mime_types_parse(liServer *srv, liPlugin *p, size_t ndx, liValue *val, liOptionValue *oval) { GArray *arr; UNUSED(srv); UNUSED(p); @@ -756,16 +756,16 @@ static gboolean core_option_mime_types_parse(server *srv, plugin *p, size_t ndx, /* default value */ if (!val) { - oval->list = g_array_new(FALSE, TRUE, sizeof(value)); + oval->list = g_array_new(FALSE, TRUE, sizeof(liValue)); return TRUE; } /* check if the passed val is of type (("a", "b"), ("x", y")) */ arr = val->data.list; for (guint i = 0; i < arr->len; i++) { - value *v = g_array_index(arr, value*, i); - value *v1, *v2; - if (v->type != VALUE_LIST) { + liValue *v = g_array_index(arr, liValue*, i); + liValue *v1, *v2; + if (v->type != LI_VALUE_LIST) { ERROR(srv, "mime_types option expects a list of string tuples, entry #%u is of type %s", i, value_type_string(v->type)); return FALSE; } @@ -775,9 +775,9 @@ static gboolean core_option_mime_types_parse(server *srv, plugin *p, size_t ndx, return FALSE; } - v1 = g_array_index(v->data.list, value*, 0); - v2 = g_array_index(v->data.list, value*, 1); - if (v1->type != VALUE_STRING || v2->type != VALUE_STRING) { + v1 = g_array_index(v->data.list, liValue*, 0); + v2 = g_array_index(v->data.list, liValue*, 1); + if (v1->type != LI_VALUE_STRING || v2->type != LI_VALUE_STRING) { ERROR(srv, "mime_types option expects a list of string tuples, entry #%u is a (%s,%s) tuple", i, value_type_string(v1->type), value_type_string(v2->type)); return FALSE; } @@ -789,18 +789,18 @@ static gboolean core_option_mime_types_parse(server *srv, plugin *p, size_t ndx, return TRUE; } -static void core_option_mime_types_free(server *srv, plugin *p, size_t ndx, option_value oval) { +static void core_option_mime_types_free(liServer *srv, liPlugin *p, size_t ndx, liOptionValue oval) { UNUSED(srv); UNUSED(p); UNUSED(ndx); for (guint i = 0; i < oval.list->len; i++) - value_free(g_array_index(oval.list, value*, i)); + value_free(g_array_index(oval.list, liValue*, i)); g_array_free(oval.list, TRUE); } -static gboolean core_option_etag_use_parse(server *srv, plugin *p, size_t ndx, value *val, option_value *oval) { +static gboolean core_option_etag_use_parse(liServer *srv, liPlugin *p, size_t ndx, liValue *val, liOptionValue *oval) { GArray *arr; guint flags = 0; UNUSED(p); @@ -808,28 +808,28 @@ static gboolean core_option_etag_use_parse(server *srv, plugin *p, size_t ndx, v /* default value */ if (!val) { - oval->number = ETAG_USE_INODE | ETAG_USE_MTIME | ETAG_USE_SIZE; + oval->number = LI_ETAG_USE_INODE | LI_ETAG_USE_MTIME | LI_ETAG_USE_SIZE; return TRUE; } - if (val->type != VALUE_LIST) { + if (val->type != LI_VALUE_LIST) { ERROR(srv, "etag.use option expects a list of strings, parameter is of type %s", value_type_string(val->type)); } arr = val->data.list; for (guint i = 0; i < arr->len; i++) { - value *v = g_array_index(arr, value*, i); - if (v->type != VALUE_STRING) { + liValue *v = g_array_index(arr, liValue*, i); + if (v->type != LI_VALUE_STRING) { ERROR(srv, "etag.use option expects a list of strings, entry #%u is of type %s", i, value_type_string(v->type)); return FALSE; } if (0 == strcmp(v->data.string->str, "inode")) { - flags |= ETAG_USE_INODE; + flags |= LI_ETAG_USE_INODE; } else if (0 == strcmp(v->data.string->str, "mtime")) { - flags |= ETAG_USE_MTIME; + flags |= LI_ETAG_USE_MTIME; } else if (0 == strcmp(v->data.string->str, "size")) { - flags |= ETAG_USE_SIZE; + flags |= LI_ETAG_USE_SIZE; } else { ERROR(srv, "unknown etag.use flag: %s", v->data.string->str); return FALSE; @@ -840,28 +840,28 @@ static gboolean core_option_etag_use_parse(server *srv, plugin *p, size_t ndx, v return TRUE; } -static handler_t core_handle_header_add(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_header_add(liVRequest *vr, gpointer param, gpointer *context) { GArray *l = (GArray*)param; - GString *k = g_array_index(l, value*, 0)->data.string; - GString *v = g_array_index(l, value*, 1)->data.string; + GString *k = g_array_index(l, liValue*, 0)->data.string; + GString *v = g_array_index(l, liValue*, 1)->data.string; UNUSED(param); UNUSED(context); http_header_insert(vr->response.headers, GSTR_LEN(k), GSTR_LEN(v)); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static void core_header_free(struct server *srv, gpointer param) { +static void core_header_free(liServer *srv, gpointer param) { UNUSED(srv); value_list_free(param); } -static action* core_header_add(server *srv, plugin* p, value *val) { +static liAction* core_header_add(liServer *srv, liPlugin* p, liValue *val) { GArray *l; UNUSED(p); - if (val->type != VALUE_LIST) { + if (val->type != LI_VALUE_LIST) { ERROR(srv, "'core_header_add' action expects a string tuple as parameter, %s given", value_type_string(val->type)); return NULL; } @@ -873,7 +873,7 @@ static action* core_header_add(server *srv, plugin* p, value *val) { return NULL; } - if (g_array_index(l, value*, 0)->type != VALUE_STRING || g_array_index(l, value*, 0)->type != VALUE_STRING) { + if (g_array_index(l, liValue*, 0)->type != LI_VALUE_STRING || g_array_index(l, liValue*, 0)->type != LI_VALUE_STRING) { ERROR(srv, "%s", "'core_header_add' action expects a string tuple as parameter"); return NULL; } @@ -882,23 +882,23 @@ static action* core_header_add(server *srv, plugin* p, value *val) { } -static handler_t core_handle_header_append(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_header_append(liVRequest *vr, gpointer param, gpointer *context) { GArray *l = (GArray*)param; - GString *k = g_array_index(l, value*, 0)->data.string; - GString *v = g_array_index(l, value*, 1)->data.string; + GString *k = g_array_index(l, liValue*, 0)->data.string; + GString *v = g_array_index(l, liValue*, 1)->data.string; UNUSED(param); UNUSED(context); http_header_append(vr->response.headers, GSTR_LEN(k), GSTR_LEN(v)); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* core_header_append(server *srv, plugin* p, value *val) { +static liAction* core_header_append(liServer *srv, liPlugin* p, liValue *val) { GArray *l; UNUSED(p); - if (val->type != VALUE_LIST) { + if (val->type != LI_VALUE_LIST) { ERROR(srv, "'core_header_append' action expects a string tuple as parameter, %s given", value_type_string(val->type)); return NULL; } @@ -910,7 +910,7 @@ static action* core_header_append(server *srv, plugin* p, value *val) { return NULL; } - if (g_array_index(l, value*, 0)->type != VALUE_STRING || g_array_index(l, value*, 0)->type != VALUE_STRING) { + if (g_array_index(l, liValue*, 0)->type != LI_VALUE_STRING || g_array_index(l, liValue*, 0)->type != LI_VALUE_STRING) { ERROR(srv, "%s", "'core_header_append' action expects a string tuple as parameter"); return NULL; } @@ -919,23 +919,23 @@ static action* core_header_append(server *srv, plugin* p, value *val) { } -static handler_t core_handle_header_overwrite(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_header_overwrite(liVRequest *vr, gpointer param, gpointer *context) { GArray *l = (GArray*)param; - GString *k = g_array_index(l, value*, 0)->data.string; - GString *v = g_array_index(l, value*, 1)->data.string; + GString *k = g_array_index(l, liValue*, 0)->data.string; + GString *v = g_array_index(l, liValue*, 1)->data.string; UNUSED(param); UNUSED(context); http_header_overwrite(vr->response.headers, GSTR_LEN(k), GSTR_LEN(v)); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* core_header_overwrite(server *srv, plugin* p, value *val) { +static liAction* core_header_overwrite(liServer *srv, liPlugin* p, liValue *val) { GArray *l; UNUSED(p); - if (val->type != VALUE_LIST) { + if (val->type != LI_VALUE_LIST) { ERROR(srv, "'core_header_overwrite' action expects a string tuple as parameter, %s given", value_type_string(val->type)); return NULL; } @@ -947,7 +947,7 @@ static action* core_header_overwrite(server *srv, plugin* p, value *val) { return NULL; } - if (g_array_index(l, value*, 0)->type != VALUE_STRING || g_array_index(l, value*, 0)->type != VALUE_STRING) { + if (g_array_index(l, liValue*, 0)->type != LI_VALUE_STRING || g_array_index(l, liValue*, 0)->type != LI_VALUE_STRING) { ERROR(srv, "%s", "'core_header_overwrite' action expects a string tuple as parameter"); return NULL; } @@ -956,16 +956,16 @@ static action* core_header_overwrite(server *srv, plugin* p, value *val) { } typedef struct { - action *target_true, *target_false; + liAction *target_true, *target_false; } core_conditional; -static core_conditional* core_conditional_create(server *srv, value *val, guint idx) { +static core_conditional* core_conditional_create(liServer *srv, liValue *val, guint idx) { core_conditional *cc; - value *val_true = NULL, *val_false = NULL; - action *act_true = NULL, *act_false = NULL; + liValue *val_true = NULL, *val_false = NULL; + liAction *act_true = NULL, *act_false = NULL; GArray *l; - if (idx == 0 && val->type == VALUE_ACTION) { + if (idx == 0 && val->type == LI_VALUE_ACTION) { cc = g_slice_new0(core_conditional); act_true = val->data.val_action.action; action_acquire(act_true); @@ -973,7 +973,7 @@ static core_conditional* core_conditional_create(server *srv, value *val, guint return cc; } - if (val->type != VALUE_LIST) { + if (val->type != LI_VALUE_LIST) { ERROR(srv, "unexpected parameter of type %s, expected list", value_type_string(val->type)); return NULL; } @@ -984,21 +984,21 @@ static core_conditional* core_conditional_create(server *srv, value *val, guint ERROR(srv, "expected at least %u parameters, %u given", idx+1, l->len); } - val_true = g_array_index(l, value*, idx); - if (idx + 1 < l->len) val_false = g_array_index(l, value*, idx+1); + val_true = g_array_index(l, liValue*, idx); + if (idx + 1 < l->len) val_false = g_array_index(l, liValue*, idx+1); - if (val_true->type == VALUE_NONE) { + if (val_true->type == LI_VALUE_NONE) { act_true = NULL; - } else if (val_true->type == VALUE_ACTION) { + } else if (val_true->type == LI_VALUE_ACTION) { act_true = val_true->data.val_action.action; } else { ERROR(srv, "expected action at entry %u of list, got %s", idx, value_type_string(val_true->type)); } if (val_false) { - if (val_false->type == VALUE_NONE) { + if (val_false->type == LI_VALUE_NONE) { act_false = NULL; - } else if (val_false->type == VALUE_ACTION) { + } else if (val_false->type == LI_VALUE_ACTION) { act_false = val_false->data.val_action.action; } else { ERROR(srv, "expected action at entry %u of list, got %s", idx+1, value_type_string(val_false->type)); @@ -1015,7 +1015,7 @@ static core_conditional* core_conditional_create(server *srv, value *val, guint return cc; } -static void core_conditional_free(struct server *srv, gpointer param) { +static void core_conditional_free(liServer *srv, gpointer param) { core_conditional *cc = (core_conditional*) param; if (!cc) return; action_release(srv, cc->target_true); @@ -1023,21 +1023,21 @@ static void core_conditional_free(struct server *srv, gpointer param) { g_slice_free(core_conditional, cc); } -static handler_t core_conditional_do(vrequest *vr, gpointer param, gboolean way) { +static liHandlerResult core_conditional_do(liVRequest *vr, gpointer param, gboolean way) { core_conditional *cc = (core_conditional*)param; if (way) { if (cc->target_true) action_enter(vr, cc->target_true); } else { if (cc->target_false) action_enter(vr, cc->target_false); } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static handler_t core_handle_physical_exists(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_physical_exists(liVRequest *vr, gpointer param, gpointer *context) { UNUSED(context); if (0 == vr->physical.path->len) return core_conditional_do(vr, param, FALSE); vrequest_stat(vr); return core_conditional_do(vr, param, vr->physical.have_stat); } -static action* core_physical_exists(server *srv, plugin* p, value *val) { +static liAction* core_physical_exists(liServer *srv, liPlugin* p, liValue *val) { core_conditional *cc = core_conditional_create(srv, val, 0); UNUSED(p); if (!cc) return NULL; @@ -1045,14 +1045,14 @@ static action* core_physical_exists(server *srv, plugin* p, value *val) { return action_new_function(core_handle_physical_exists, NULL, core_conditional_free, cc); } -static handler_t core_handle_physical_is_file(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_physical_is_file(liVRequest *vr, gpointer param, gpointer *context) { UNUSED(context); if (0 == vr->physical.path->len) return core_conditional_do(vr, param, FALSE); vrequest_stat(vr); return core_conditional_do(vr, param, vr->physical.have_stat && S_ISREG(vr->physical.stat.st_mode)); } -static action* core_physical_is_file(server *srv, plugin* p, value *val) { +static liAction* core_physical_is_file(liServer *srv, liPlugin* p, liValue *val) { core_conditional *cc = core_conditional_create(srv, val, 0); UNUSED(p); if (!cc) return NULL; @@ -1060,14 +1060,14 @@ static action* core_physical_is_file(server *srv, plugin* p, value *val) { return action_new_function(core_handle_physical_is_file, NULL, core_conditional_free, cc); } -static handler_t core_handle_physical_is_dir(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_physical_is_dir(liVRequest *vr, gpointer param, gpointer *context) { UNUSED(context); if (0 == vr->physical.path->len) return core_conditional_do(vr, param, FALSE); vrequest_stat(vr); return core_conditional_do(vr, param, vr->physical.have_stat && S_ISDIR(vr->physical.stat.st_mode)); } -static action* core_physical_is_dir(server *srv, plugin* p, value *val) { +static liAction* core_physical_is_dir(liServer *srv, liPlugin* p, liValue *val) { core_conditional *cc = core_conditional_create(srv, val, 0); UNUSED(p); if (!cc) return NULL; @@ -1076,20 +1076,20 @@ static action* core_physical_is_dir(server *srv, plugin* p, value *val) { } /* chunkqueue memory limits */ -static handler_t core_handle_buffer_out(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_buffer_out(liVRequest *vr, gpointer param, gpointer *context) { gint limit = GPOINTER_TO_INT(param); UNUSED(context); cqlimit_set_limit(vr->out->limit, limit); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* core_buffer_out(server *srv, plugin* p, value *val) { +static liAction* core_buffer_out(liServer *srv, liPlugin* p, liValue *val) { gint64 limit; UNUSED(p); - if (val->type != VALUE_NUMBER) { + if (val->type != LI_VALUE_NUMBER) { ERROR(srv, "'buffer.out' action expects an integer as parameter, %s given", value_type_string(val->type)); return NULL; } @@ -1109,20 +1109,20 @@ static action* core_buffer_out(server *srv, plugin* p, value *val) { return action_new_function(core_handle_buffer_out, NULL, NULL, GINT_TO_POINTER((gint) limit)); } -static handler_t core_handle_buffer_in(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_buffer_in(liVRequest *vr, gpointer param, gpointer *context) { gint limit = GPOINTER_TO_INT(param); UNUSED(context); cqlimit_set_limit(vr->out->limit, limit); - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* core_buffer_in(server *srv, plugin* p, value *val) { +static liAction* core_buffer_in(liServer *srv, liPlugin* p, liValue *val) { gint64 limit; UNUSED(p); - if (val->type != VALUE_NUMBER) { + if (val->type != LI_VALUE_NUMBER) { ERROR(srv, "'buffer.in' action expects an integer as parameter, %s given", value_type_string(val->type)); return NULL; } @@ -1140,8 +1140,8 @@ static action* core_buffer_in(server *srv, plugin* p, value *val) { return action_new_function(core_handle_buffer_in, NULL, NULL, GINT_TO_POINTER((gint) limit)); } -static handler_t core_handle_throttle_pool(vrequest *vr, gpointer param, gpointer *context) { - throttle_pool_t *pool = param; +static liHandlerResult core_handle_throttle_pool(liVRequest *vr, gpointer param, gpointer *context) { + liThrottlePool *pool = param; gint magazine; UNUSED(context); @@ -1152,7 +1152,7 @@ static handler_t core_handle_throttle_pool(vrequest *vr, gpointer param, gpointe g_atomic_int_add(&vr->con->throttle.pool.ptr->magazine, vr->con->throttle.pool.magazine); vr->con->throttle.pool.magazine = 0; if (vr->con->throttle.pool.queued) { - throttle_pool_t *p = vr->con->throttle.pool.ptr; + liThrottlePool *p = vr->con->throttle.pool.ptr; g_queue_unlink(p->queues[vr->con->wrk->ndx+p->current_queue[vr->con->wrk->ndx]], &vr->con->throttle.ip.lnk); g_atomic_int_add(&p->num_cons, -1); } @@ -1170,33 +1170,33 @@ static handler_t core_handle_throttle_pool(vrequest *vr, gpointer param, gpointe vr->con->throttle.pool.ptr = pool; vr->con->throttled = TRUE; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* core_throttle_pool(server *srv, plugin* p, value *val) { +static liAction* core_throttle_pool(liServer *srv, liPlugin* p, liValue *val) { GString *name; guint i; - throttle_pool_t *pool = NULL; + liThrottlePool *pool = NULL; gint64 rate; UNUSED(p); - if (val->type != VALUE_STRING && val->type != VALUE_LIST) { + if (val->type != LI_VALUE_STRING && val->type != LI_VALUE_LIST) { ERROR(srv, "'throttle_pool' action expects a string or a string-number tuple as parameter, %s given", value_type_string(val->type)); return NULL; } - if (val->type == VALUE_LIST) { + if (val->type == LI_VALUE_LIST) { if (val->data.list->len != 2 - || g_array_index(val->data.list, value*, 0)->type != VALUE_STRING - || g_array_index(val->data.list, value*, 1)->type != VALUE_NUMBER) { + || g_array_index(val->data.list, liValue*, 0)->type != LI_VALUE_STRING + || g_array_index(val->data.list, liValue*, 1)->type != LI_VALUE_NUMBER) { ERROR(srv, "%s", "'throttle_pool' action expects a string or a string-number tuple as parameter"); return NULL; } - name = g_array_index(val->data.list, value*, 0)->data.string; - rate = g_array_index(val->data.list, value*, 1)->data.number; + name = g_array_index(val->data.list, liValue*, 0)->data.string; + rate = g_array_index(val->data.list, liValue*, 1)->data.number; if (rate && rate < (32*1024)) { ERROR(srv, "throttle_pool: rate %"G_GINT64_FORMAT" is too low (32kbyte/s minimum or 0 for unlimited)", rate); @@ -1213,27 +1213,27 @@ static action* core_throttle_pool(server *srv, plugin* p, value *val) { } for (i = 0; i < srv->throttle_pools->len; i++) { - if (g_string_equal(g_array_index(srv->throttle_pools, throttle_pool_t*, i)->name, name)) { + if (g_string_equal(g_array_index(srv->throttle_pools, liThrottlePool*, i)->name, name)) { /* pool already defined */ - if (val->type == VALUE_LIST && g_array_index(srv->throttle_pools, throttle_pool_t*, i)->rate != (guint)rate) { + if (val->type == LI_VALUE_LIST && g_array_index(srv->throttle_pools, liThrottlePool*, i)->rate != (guint)rate) { ERROR(srv, "throttle_pool: pool '%s' already defined but with different rate (%ukbyte/s)", name->str, - g_array_index(srv->throttle_pools, throttle_pool_t*, i)->rate); + g_array_index(srv->throttle_pools, liThrottlePool*, i)->rate); return NULL; } - pool = g_array_index(srv->throttle_pools, throttle_pool_t*, i); + pool = g_array_index(srv->throttle_pools, liThrottlePool*, i); break; } } if (!pool) { /* pool not yet defined */ - if (val->type == VALUE_STRING) { + if (val->type == LI_VALUE_STRING) { ERROR(srv, "throttle_pool: rate for pool '%s' hasn't been defined", name->str); return NULL; } - pool = throttle_pool_new(srv, value_extract(g_array_index(val->data.list, value*, 0)).string, (guint)rate); + pool = throttle_pool_new(srv, value_extract(g_array_index(val->data.list, liValue*, 0)).string, (guint)rate); g_array_append_val(srv->throttle_pools, pool); } @@ -1241,9 +1241,9 @@ static action* core_throttle_pool(server *srv, plugin* p, value *val) { } -static handler_t core_handle_throttle_connection(vrequest *vr, gpointer param, gpointer *context) { +static liHandlerResult core_handle_throttle_connection(liVRequest *vr, gpointer param, gpointer *context) { gint supply; - connection *con = vr->con; + liConnection *con = vr->con; guint rate = GPOINTER_TO_UINT(param); UNUSED(context); @@ -1257,14 +1257,14 @@ static handler_t core_handle_throttle_connection(vrequest *vr, gpointer param, g con->throttle.pool.magazine -= supply; } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -static action* core_throttle_connection(server *srv, plugin* p, value *val) { +static liAction* core_throttle_connection(liServer *srv, liPlugin* p, liValue *val) { gint64 rate; UNUSED(p); - if (val->type != VALUE_NUMBER) { + if (val->type != LI_VALUE_NUMBER) { ERROR(srv, "'throttle_connection' action expects a positiv integer as parameter, %s given", value_type_string(val->type)); return NULL; } @@ -1289,29 +1289,29 @@ static action* core_throttle_connection(server *srv, plugin* p, value *val) { } -static const plugin_option options[] = { - { "debug.log_request_handling", VALUE_BOOLEAN, GINT_TO_POINTER(FALSE), NULL, NULL }, +static const liPluginOption options[] = { + { "debug.log_request_handling", LI_VALUE_BOOLEAN, GINT_TO_POINTER(FALSE), NULL, NULL }, - { "log.timestamp", VALUE_STRING, NULL, core_option_log_timestamp_parse, core_option_log_timestamp_free }, - { "log", VALUE_HASH, NULL, core_option_log_parse, core_option_log_free }, + { "log.timestamp", LI_VALUE_STRING, NULL, core_option_log_timestamp_parse, core_option_log_timestamp_free }, + { "log", LI_VALUE_HASH, NULL, core_option_log_parse, core_option_log_free }, - { "static-file.exclude", VALUE_LIST, NULL, NULL, NULL }, + { "static-file.exclude", LI_VALUE_LIST, NULL, NULL, NULL }, - { "server.name", VALUE_STRING, NULL, NULL, NULL }, - { "server.tag", VALUE_STRING, "lighttpd-2.0~sandbox", NULL, NULL }, - { "server.max_keep_alive_idle", VALUE_NUMBER, GINT_TO_POINTER(5), NULL, NULL }, - { "server.max_keep_alive_requests", VALUE_NUMBER, GINT_TO_POINTER(15), NULL, NULL }, + { "server.name", LI_VALUE_STRING, NULL, NULL, NULL }, + { "server.tag", LI_VALUE_STRING, "lighttpd-2.0~sandbox", NULL, NULL }, + { "server.max_keep_alive_idle", LI_VALUE_NUMBER, GINT_TO_POINTER(5), NULL, NULL }, + { "server.max_keep_alive_requests", LI_VALUE_NUMBER, GINT_TO_POINTER(15), NULL, NULL }, - { "mime_types", VALUE_LIST, NULL, core_option_mime_types_parse, core_option_mime_types_free }, + { "mime_types", LI_VALUE_LIST, NULL, core_option_mime_types_parse, core_option_mime_types_free }, - { "throttle", VALUE_NUMBER, GINT_TO_POINTER(0), NULL, NULL }, + { "throttle", LI_VALUE_NUMBER, GINT_TO_POINTER(0), NULL, NULL }, - { "etag.use", VALUE_NONE, NULL, core_option_etag_use_parse, NULL }, + { "etag.use", LI_VALUE_NONE, NULL, core_option_etag_use_parse, NULL }, { NULL, 0, NULL, NULL, NULL } }; -static const plugin_action actions[] = { +static const liPluginAction actions[] = { { "list", core_list }, { "when", core_when }, { "set", core_set }, @@ -1345,7 +1345,7 @@ static const plugin_action actions[] = { { NULL, NULL } }; -static const plugin_setup setups[] = { +static const liliPluginSetupCB setups[] = { { "set_default", core_setup_set }, { "listen", core_listen }, { "event_handler", core_event_handler }, @@ -1357,8 +1357,8 @@ static const plugin_setup setups[] = { { NULL, NULL } }; -void plugin_core_init(server *srv, plugin *p); -void plugin_core_init(server *srv, plugin *p) { +void plugin_core_init(liServer *srv, liPlugin *p); +void plugin_core_init(liServer *srv, liPlugin *p) { UNUSED(srv); p->options = options; diff --git a/src/profiler.c b/src/profiler.c index 3291697..f1fb452 100644 --- a/src/profiler.c +++ b/src/profiler.c @@ -12,14 +12,14 @@ #define PROFILER_HASHTABLE_SIZE 1024 +typedef struct profiler_entry profiler_entry; struct profiler_entry { gpointer addr; gsize len; - struct profiler_entry *next; + profiler_entry *next; }; -typedef struct profiler_entry profiler_entry; -static profiler_mem stats_mem = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +static liProfilerMem stats_mem = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static GMutex *profiler_mutex = NULL; static gboolean profiler_enabled = FALSE; static profiler_entry *free_list = NULL; @@ -249,7 +249,7 @@ void profiler_finish() { } void profiler_dump() { - profiler_mem s; + liProfilerMem s; if (!profiler_enabled) return; diff --git a/src/radix.c b/src/radix.c index 90e2cd6..3235ca9 100644 --- a/src/radix.c +++ b/src/radix.c @@ -1,16 +1,16 @@ #include -RadixTree32 *radixtree32_new(guint32 root_width) { +liRadixTree32 *radixtree32_new(guint32 root_width) { guint32 i; - RadixTree32 *tree = g_slice_new(RadixTree32); + liRadixTree32 *tree = g_slice_new(liRadixTree32); if (root_width == 0) root_width = 1; else if (root_width > 8) root_width = 8; - tree->root = g_new0(RadixNode32*, 1 << root_width); + tree->root = g_new0(liRadixNode32*, 1 << root_width); tree->size = 0; tree->root_width = root_width; tree->root_mask = 0; @@ -21,9 +21,9 @@ RadixTree32 *radixtree32_new(guint32 root_width) { return tree; } -guint radixtree32_free(RadixTree32 *tree) { +guint radixtree32_free(liRadixTree32 *tree) { guint32 i; - RadixNode32 *node, *parent; + liRadixNode32 *node, *parent; guint32 n = 0; /* walk the tree and free every node */ @@ -45,7 +45,7 @@ guint radixtree32_free(RadixTree32 *tree) { parent->right = NULL; } - g_slice_free(RadixNode32, node); + g_slice_free(liRadixNode32, node); node = parent; n++; } @@ -53,18 +53,18 @@ guint radixtree32_free(RadixTree32 *tree) { } g_free(tree->root); - g_slice_free(RadixTree32, tree); + g_slice_free(liRadixTree32, tree); return n; } -void radixtree32_insert(RadixTree32 *tree, guint32 key, guint32 mask, gpointer data) { - RadixNode32 *last_node, *leaf; - RadixNode32 *node = tree->root[(key & tree->root_mask) >> (32 - tree->root_width)]; +void radixtree32_insert(liRadixTree32 *tree, guint32 key, guint32 mask, gpointer data) { + liRadixNode32 *last_node, *leaf; + liRadixNode32 *node = tree->root[(key & tree->root_mask) >> (32 - tree->root_width)]; //g_print("root: %p, %x & %x => %x\n", (void*)node, key, tree->root_mask, (key & tree->root_mask) >> (32 - tree->root_width)); if (!node) { /* no root node yet */ - node = g_slice_new(RadixNode32); + node = g_slice_new(liRadixNode32); node->key = key & mask; node->mask = mask; node->data = data; @@ -81,10 +81,10 @@ void radixtree32_insert(RadixTree32 *tree, guint32 key, guint32 mask, gpointer d if ((key & mask & node->mask) != node->key) {guint i; /* node key differs, split tree */ guint32 tmp; - RadixNode32 *new_node;i=0; + liRadixNode32 *new_node;i=0; /* the new internal node */ - new_node = g_slice_new(RadixNode32); + new_node = g_slice_new(liRadixNode32); new_node->data = NULL; new_node->parent = node->parent; new_node->mask = node->mask; @@ -93,7 +93,7 @@ void radixtree32_insert(RadixTree32 *tree, guint32 key, guint32 mask, gpointer d node->parent = new_node; /* the new leaf */ - leaf = g_slice_new(RadixNode32); + leaf = g_slice_new(liRadixNode32); leaf->key = key & mask; leaf->mask = mask; leaf->data = data; @@ -146,7 +146,7 @@ void radixtree32_insert(RadixTree32 *tree, guint32 key, guint32 mask, gpointer d } while (node); /* new leaf at end of tree */ - leaf = g_slice_new0(RadixNode32); + leaf = g_slice_new0(liRadixNode32); leaf->data = data; leaf->key = key & mask; leaf->mask = mask; @@ -161,8 +161,8 @@ void radixtree32_insert(RadixTree32 *tree, guint32 key, guint32 mask, gpointer d tree->size++; } -gboolean radixtree32_remove(RadixTree32 *tree, guint32 key, guint32 mask) { - RadixNode32 *node = tree->root[(key & tree->root_mask) >> (32 - tree->root_width)]; +gboolean radixtree32_remove(liRadixTree32 *tree, guint32 key, guint32 mask) { + liRadixNode32 *node = tree->root[(key & tree->root_mask) >> (32 - tree->root_width)]; while (node) { if (!node->data || (key & mask) != node->key) { @@ -189,7 +189,7 @@ gboolean radixtree32_remove(RadixTree32 *tree, guint32 key, guint32 mask) { return TRUE; } else { /* the parent internal node has no data, we can set our sibling as the new internal node */ - RadixNode32 *sibling = (node->parent->left == node) ? node->parent->right : node->parent->left; + liRadixNode32 *sibling = (node->parent->left == node) ? node->parent->right : node->parent->left; if (node->parent->parent) { if (node->parent->parent->left == node->parent) node->parent->parent->left = sibling; @@ -202,7 +202,7 @@ gboolean radixtree32_remove(RadixTree32 *tree, guint32 key, guint32 mask) { /* old internal node not needed anymore */ tree->size--; - g_slice_free(RadixNode32, node->parent); + g_slice_free(liRadixNode32, node->parent); } } else { /* tree root */ @@ -216,7 +216,7 @@ gboolean radixtree32_remove(RadixTree32 *tree, guint32 key, guint32 mask) { } tree->size--; - g_slice_free(RadixNode32, node); + g_slice_free(liRadixNode32, node); return TRUE; } @@ -224,9 +224,9 @@ gboolean radixtree32_remove(RadixTree32 *tree, guint32 key, guint32 mask) { return FALSE; } -RadixNode32 *radixtree32_lookup_node(RadixTree32 *tree, guint32 key) { - RadixNode32 *node = tree->root[(key & tree->root_mask) >> (32 - tree->root_width)]; - RadixNode32 *result = NULL; +liRadixNode32 *radixtree32_lookup_node(liRadixTree32 *tree, guint32 key) { + liRadixNode32 *node = tree->root[(key & tree->root_mask) >> (32 - tree->root_width)]; + liRadixNode32 *result = NULL; while (node) {//g_print("%x & %x => %x != %x\n", key, node->mask, key & node->mask, node->key); if ((key & node->mask) != node->key) @@ -246,14 +246,14 @@ RadixNode32 *radixtree32_lookup_node(RadixTree32 *tree, guint32 key) { return result; } -gpointer radixtree32_lookup(RadixTree32 *tree, guint32 key) { - RadixNode32 *node = radixtree32_lookup_node(tree, key); +gpointer radixtree32_lookup(liRadixTree32 *tree, guint32 key) { + liRadixNode32 *node = radixtree32_lookup_node(tree, key); return node ? node->data : NULL; } -gpointer radixtree32_lookup_exact(RadixTree32 *tree, guint32 key) { - RadixNode32 *node = radixtree32_lookup_node(tree, key); +gpointer radixtree32_lookup_exact(liRadixTree32 *tree, guint32 key) { + liRadixNode32 *node = radixtree32_lookup_node(tree, key); if (!node) return NULL; diff --git a/src/request.c b/src/request.c index 365c66c..2947722 100644 --- a/src/request.c +++ b/src/request.c @@ -2,10 +2,10 @@ #include #include -void request_init(request *req) { - req->http_method = HTTP_METHOD_UNSET; +void request_init(liRequest *req) { + req->http_method = LI_HTTP_METHOD_UNSET; req->http_method_str = g_string_sized_new(0); - req->http_version = HTTP_VERSION_UNSET; + req->http_version = LI_HTTP_VERSION_UNSET; req->uri.raw = g_string_sized_new(0); req->uri.scheme = g_string_sized_new(0); @@ -20,10 +20,10 @@ void request_init(request *req) { req->content_length = -1; } -void request_reset(request *req) { - req->http_method = HTTP_METHOD_UNSET; +void request_reset(liRequest *req) { + req->http_method = LI_HTTP_METHOD_UNSET; g_string_truncate(req->http_method_str, 0); - req->http_version = HTTP_VERSION_UNSET; + req->http_version = LI_HTTP_VERSION_UNSET; g_string_truncate(req->uri.raw, 0); g_string_truncate(req->uri.scheme, 0); @@ -38,10 +38,10 @@ void request_reset(request *req) { req->content_length = -1; } -void request_clear(request *req) { - req->http_method = HTTP_METHOD_UNSET; +void request_clear(liRequest *req) { + req->http_method = LI_HTTP_METHOD_UNSET; g_string_free(req->http_method_str, TRUE); - req->http_version = HTTP_VERSION_UNSET; + req->http_version = LI_HTTP_VERSION_UNSET; g_string_free(req->uri.raw, TRUE); g_string_free(req->uri.scheme, TRUE); @@ -57,14 +57,14 @@ void request_clear(request *req) { } /* closes connection after response */ -static void bad_request(connection *con, int status) { +static void bad_request(liConnection *con, int status) { con->keep_alive = FALSE; con->mainvr->response.http_status = status; vrequest_handle_direct(con->mainvr); } -static gboolean request_parse_url(vrequest *vr) { - request *req = &vr->request; +static gboolean request_parse_url(liVRequest *vr) { + liRequest *req = &vr->request; g_string_truncate(req->uri.query, 0); g_string_truncate(req->uri.path, 0); @@ -73,7 +73,7 @@ static gboolean request_parse_url(vrequest *vr) { return FALSE; /* "*" only allowed for method OPTIONS */ - if (0 == strcmp(req->uri.path->str, "*") && req->http_method != HTTP_METHOD_OPTIONS) + if (0 == strcmp(req->uri.path->str, "*") && req->http_method != LI_HTTP_METHOD_OPTIONS) return FALSE; url_decode(req->uri.path); @@ -86,21 +86,21 @@ static gboolean request_parse_url(vrequest *vr) { return TRUE; } -gboolean request_validate_header(connection *con) { - request *req = &con->mainvr->request; - http_header *hh; +gboolean request_validate_header(liConnection *con) { + liRequest *req = &con->mainvr->request; + liHttpHeader *hh; GList *l; switch (req->http_version) { - case HTTP_VERSION_1_0: + case LI_HTTP_VERSION_1_0: if (!http_header_is(req->headers, CONST_STR_LEN("connection"), CONST_STR_LEN("keep-alive"))) con->keep_alive = FALSE; break; - case HTTP_VERSION_1_1: + case LI_HTTP_VERSION_1_1: if (http_header_is(req->headers, CONST_STR_LEN("connection"), CONST_STR_LEN("close"))) con->keep_alive = FALSE; break; - case HTTP_VERSION_UNSET: + case LI_HTTP_VERSION_UNSET: bad_request(con, 505); /* Version not Supported */ return FALSE; } @@ -119,7 +119,7 @@ gboolean request_validate_header(connection *con) { return FALSE; } - hh = (http_header*) l->data; + hh = (liHttpHeader*) l->data; g_string_append_len(req->uri.authority, HEADER_VALUE_LEN(hh)); if (!parse_hostname(&req->uri)) { bad_request(con, 400); /* bad request */ @@ -128,7 +128,7 @@ gboolean request_validate_header(connection *con) { } /* Need hostname in HTTP/1.1 */ - if (req->uri.host->len == 0 && req->http_version == HTTP_VERSION_1_1) { + if (req->uri.host->len == 0 && req->http_version == LI_HTTP_VERSION_1_1) { bad_request(con, 400); /* bad request */ return FALSE; } @@ -181,7 +181,7 @@ gboolean request_validate_header(connection *con) { gboolean expect_100_cont = FALSE; for ( ; l ; l = http_header_find_next(l, CONST_STR_LEN("expect")) ) { - hh = (http_header*) l->data; + hh = (liHttpHeader*) l->data; if (0 == g_strcasecmp( HEADER_VALUE(hh), "100-continue" )) { expect_100_cont = TRUE; } else { @@ -191,7 +191,7 @@ gboolean request_validate_header(connection *con) { } } - if (expect_100_cont && req->http_version == HTTP_VERSION_1_0) { + if (expect_100_cont && req->http_version == LI_HTTP_VERSION_1_0) { /* only HTTP/1.1 clients can send us this header */ bad_request(con, 417); /* Expectation Failed */ return FALSE; @@ -206,8 +206,8 @@ gboolean request_validate_header(connection *con) { */ switch(con->mainvr->request.http_method) { - case HTTP_METHOD_GET: - case HTTP_METHOD_HEAD: + case LI_HTTP_METHOD_GET: + case LI_HTTP_METHOD_HEAD: /* content-length is forbidden for those */ if (con->mainvr->request.content_length > 0) { VR_ERROR(con->mainvr, "%s", "GET/HEAD with content-length -> 400"); @@ -217,7 +217,7 @@ gboolean request_validate_header(connection *con) { } con->mainvr->request.content_length = 0; break; - case HTTP_METHOD_POST: + case LI_HTTP_METHOD_POST: /* content-length is required for them */ if (con->mainvr->request.content_length == -1) { /* content-length is missing */ @@ -235,7 +235,7 @@ gboolean request_validate_header(connection *con) { return TRUE; } -void physical_init(physical *phys) { +void physical_init(liPhysical *phys) { phys->path = g_string_sized_new(127); phys->basedir = g_string_sized_new(63); phys->doc_root = g_string_sized_new(63); @@ -245,7 +245,7 @@ void physical_init(physical *phys) { phys->have_errno = FALSE; } -void physical_reset(physical *phys) { +void physical_reset(liPhysical *phys) { g_string_truncate(phys->path, 0); g_string_truncate(phys->basedir, 0); g_string_truncate(phys->doc_root, 0); @@ -255,7 +255,7 @@ void physical_reset(physical *phys) { phys->have_errno = FALSE; } -void physical_clear(physical *phys) { +void physical_clear(liPhysical *phys) { g_string_free(phys->path, TRUE); g_string_free(phys->basedir, TRUE); g_string_free(phys->doc_root, TRUE); diff --git a/src/response.c b/src/response.c index dad0094..409086c 100644 --- a/src/response.c +++ b/src/response.c @@ -2,27 +2,27 @@ #include #include -void response_init(response *resp) { +void response_init(liResponse *resp) { resp->headers = http_headers_new(); resp->http_status = 0; - resp->transfer_encoding = HTTP_TRANSFER_ENCODING_IDENTITY; + resp->transfer_encoding = LI_HTTP_TRANSFER_ENCODING_IDENTITY; } -void response_reset(response *resp) { +void response_reset(liResponse *resp) { http_headers_reset(resp->headers); resp->http_status = 0; - resp->transfer_encoding = HTTP_TRANSFER_ENCODING_IDENTITY; + resp->transfer_encoding = LI_HTTP_TRANSFER_ENCODING_IDENTITY; } -void response_clear(response *resp) { +void response_clear(liResponse *resp) { http_headers_free(resp->headers); resp->http_status = 0; - resp->transfer_encoding = HTTP_TRANSFER_ENCODING_IDENTITY; + resp->transfer_encoding = LI_HTTP_TRANSFER_ENCODING_IDENTITY; } -void response_send_headers(connection *con) { +void response_send_headers(liConnection *con) { GString *head; - vrequest *vr = con->mainvr; + liVRequest *vr = con->mainvr; if (vr->response.http_status < 100 || vr->response.http_status > 999) { VR_ERROR(vr, "wrong status: %i", vr->response.http_status); @@ -54,10 +54,10 @@ void response_send_headers(connection *con) { } else if (con->out->is_closed) { g_string_printf(con->wrk->tmp_str, "%"L_GOFFSET_FORMAT, con->out->length); http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Length"), GSTR_LEN(con->wrk->tmp_str)); - } else if (con->keep_alive && vr->request.http_version == HTTP_VERSION_1_1) { + } else if (con->keep_alive && vr->request.http_version == LI_HTTP_VERSION_1_1) { /* TODO: maybe someone set a content length header? */ - if (!(vr->response.transfer_encoding & HTTP_TRANSFER_ENCODING_CHUNKED)) { - vr->response.transfer_encoding |= HTTP_TRANSFER_ENCODING_CHUNKED; + if (!(vr->response.transfer_encoding & LI_HTTP_TRANSFER_ENCODING_CHUNKED)) { + vr->response.transfer_encoding |= LI_HTTP_TRANSFER_ENCODING_CHUNKED; http_header_append(vr->response.headers, CONST_STR_LEN("Transfer-Encoding"), CONST_STR_LEN("chunked")); } } else { @@ -65,14 +65,14 @@ void response_send_headers(connection *con) { con->keep_alive = FALSE; } - if (vr->request.http_method == HTTP_METHOD_HEAD) { + if (vr->request.http_method == LI_HTTP_METHOD_HEAD) { /* content-length is set, but no body */ chunkqueue_reset(con->out); con->out->is_closed = TRUE; } /* Status line */ - if (vr->request.http_version == HTTP_VERSION_1_1) { + if (vr->request.http_version == LI_HTTP_VERSION_1_1) { g_string_append_len(head, CONST_STR_LEN("HTTP/1.1 ")); if (!con->keep_alive) http_header_overwrite(vr->response.headers, CONST_STR_LEN("Connection"), CONST_STR_LEN("close")); @@ -95,12 +95,12 @@ void response_send_headers(connection *con) { /* Append headers */ { - http_header *header; + liHttpHeader *header; GList *iter; gboolean have_date = FALSE, have_server = FALSE; for (iter = g_queue_peek_head_link(&vr->response.headers->entries); iter; iter = g_list_next(iter)) { - header = (http_header*) iter->data; + header = (liHttpHeader*) iter->data; g_string_append_len(head, GSTR_LEN(header->data)); g_string_append_len(head, CONST_STR_LEN("\r\n")); if (!have_date && http_header_key_is(header, CONST_STR_LEN("date"))) have_date = TRUE; @@ -116,7 +116,7 @@ void response_send_headers(connection *con) { } if (!have_server) { - GString *tag = CORE_OPTION(CORE_OPTION_SERVER_TAG).string; + GString *tag = CORE_OPTION(LI_CORE_OPTION_SERVER_TAG).string; if (tag->len) { g_string_append_len(head, CONST_STR_LEN("Server: ")); @@ -131,7 +131,7 @@ void response_send_headers(connection *con) { } -void response_send_error_page(connection *con) { +void response_send_error_page(liConnection *con) { gchar status_str[3]; guint len; gchar *str; diff --git a/src/server.c b/src/server.c index 35f1882..09e1da5 100644 --- a/src/server.c +++ b/src/server.c @@ -4,8 +4,8 @@ static void server_listen_cb(struct ev_loop *loop, ev_io *w, int revents); -static server_socket* server_socket_new(int fd) { - server_socket *sock = g_slice_new0(server_socket); +static liServerSocket* server_socket_new(int fd) { + liServerSocket *sock = g_slice_new0(liServerSocket); sock->refcount = 1; sock->watcher.data = sock; @@ -18,31 +18,31 @@ static server_socket* server_socket_new(int fd) { return sock; } -void server_socket_release(server_socket* sock) { +void server_socket_release(liServerSocket* sock) { if (!sock) return; assert(g_atomic_int_get(&sock->refcount) > 0); if (g_atomic_int_dec_and_test(&sock->refcount)) { sockaddr_clear(&sock->local_addr); g_string_free(sock->local_addr_str, TRUE); - g_slice_free(server_socket, sock); + g_slice_free(liServerSocket, sock); } } -void server_socket_acquire(server_socket* sock) { +void server_socket_acquire(liServerSocket* sock) { assert(g_atomic_int_get(&sock->refcount) > 0); g_atomic_int_inc(&sock->refcount); } static void server_value_free(gpointer _so) { - g_slice_free(server_option, _so); + g_slice_free(liServerOption, _so); } static void server_action_free(gpointer _sa) { - g_slice_free(server_action, _sa); + g_slice_free(liServerAction, _sa); } static void server_setup_free(gpointer _ss) { - g_slice_free(server_setup, _ss); + g_slice_free(liServerSetup, _ss); } #define CATCH_SIGNAL(loop, cb, n) do {\ @@ -59,10 +59,10 @@ static void server_setup_free(gpointer _ss) { } while (0) static void sigint_cb(struct ev_loop *loop, struct ev_signal *w, int revents) { - server *srv = (server*) w->data; + liServer *srv = (liServer*) w->data; UNUSED(revents); - if (g_atomic_int_get(&srv->state) != SERVER_STOPPING) { + if (g_atomic_int_get(&srv->state) != LI_SERVER_STOPPING) { INFO(srv, "%s", "Got signal, shutdown"); server_stop(srv); } else { @@ -80,13 +80,13 @@ static void sigpipe_cb(struct ev_loop *loop, struct ev_signal *w, int revents) { UNUSED(loop); UNUSED(w); UNUSED(revents); } -server* server_new(const gchar *module_dir) { - server* srv = g_slice_new0(server); +liServer* server_new(const gchar *module_dir) { + liServer* srv = g_slice_new0(liServer); srv->magic = LIGHTTPD_SERVER_MAGIC; - srv->state = SERVER_STARTING; + srv->state = LI_SERVER_STARTING; - srv->workers = g_array_new(FALSE, TRUE, sizeof(worker*)); + srv->workers = g_array_new(FALSE, TRUE, sizeof(liWorker*)); srv->worker_count = 0; srv->sockets = g_ptr_array_new(); @@ -98,9 +98,9 @@ server* server_new(const gchar *module_dir) { srv->actions = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, server_action_free); srv->setups = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, server_setup_free); - srv->plugins_handle_close = g_array_new(FALSE, TRUE, sizeof(plugin*)); - srv->plugins_handle_vrclose = g_array_new(FALSE, TRUE, sizeof(plugin*)); - srv->option_def_values = g_array_new(FALSE, TRUE, sizeof(option_value)); + srv->plugins_handle_close = g_array_new(FALSE, TRUE, sizeof(liPlugin*)); + srv->plugins_handle_vrclose = g_array_new(FALSE, TRUE, sizeof(liPlugin*)); + srv->option_def_values = g_array_new(FALSE, TRUE, sizeof(liOptionValue)); srv->mainaction = NULL; @@ -110,7 +110,7 @@ server* server_new(const gchar *module_dir) { /* error log ts format */ server_ts_format_add(srv, g_string_new("%a, %d %b %Y %H:%M:%S GMT")); - srv->throttle_pools = g_array_new(FALSE, TRUE, sizeof(throttle_pool_t*)); + srv->throttle_pools = g_array_new(FALSE, TRUE, sizeof(liThrottlePool*)); log_init(srv); @@ -119,7 +119,7 @@ server* server_new(const gchar *module_dir) { return srv; } -void server_free(server* srv) { +void server_free(liServer* srv) { if (!srv) return; server_stop(srv); @@ -129,8 +129,8 @@ void server_free(server* srv) { { guint i; for (i = 1; i < srv->workers->len; i++) { - worker *wrk; - wrk = g_array_index(srv->workers, worker*, i); + liWorker *wrk; + wrk = g_array_index(srv->workers, liWorker*, i); worker_exit(srv->main_worker, wrk); g_thread_join(wrk->thread); } @@ -142,7 +142,7 @@ void server_free(server* srv) { { guint i; for (i = 0; i < srv->throttle_pools->len; i++) { - throttle_pool_free(srv, g_array_index(srv->throttle_pools, throttle_pool_t*, i)); + throttle_pool_free(srv, g_array_index(srv->throttle_pools, liThrottlePool*, i)); } g_array_free(srv->throttle_pools, TRUE); } @@ -151,9 +151,9 @@ void server_free(server* srv) { { guint i; for (i = 0; i < srv->workers->len; i++) { - worker *wrk; + liWorker *wrk; struct ev_loop *loop; - wrk = g_array_index(srv->workers, worker*, i); + wrk = g_array_index(srv->workers, liWorker*, i); loop = wrk->loop; worker_free(wrk); if (i == 0) { @@ -174,7 +174,7 @@ void server_free(server* srv) { { guint i; for (i = 0; i < srv->sockets->len; i++) { - server_socket *sock = g_ptr_array_index(srv->sockets, i); + liServerSocket *sock = g_ptr_array_index(srv->sockets, i); close(sock->watcher.fd); server_socket_release(sock); } @@ -196,16 +196,16 @@ void server_free(server* srv) { if (srv->started_str) g_string_free(srv->started_str, TRUE); - g_slice_free(server, srv); + g_slice_free(liServer, srv); } static gpointer server_worker_cb(gpointer data) { - worker *wrk = (worker*) data; + liWorker *wrk = (liWorker*) data; worker_run(wrk); return NULL; } -gboolean server_loop_init(server *srv) { +gboolean server_loop_init(liServer *srv) { srv->loop = ev_default_loop(srv->loop_flags); if (!srv->loop) { @@ -216,7 +216,7 @@ gboolean server_loop_init(server *srv) { return TRUE; } -gboolean server_worker_init(server *srv) { +gboolean server_worker_init(liServer *srv) { struct ev_loop *loop = srv->loop; guint i; @@ -226,16 +226,16 @@ gboolean server_worker_init(server *srv) { if (srv->worker_count < 1) srv->worker_count = 1; g_array_set_size(srv->workers, srv->worker_count); - srv->main_worker = g_array_index(srv->workers, worker*, 0) = worker_new(srv, loop); + srv->main_worker = g_array_index(srv->workers, liWorker*, 0) = worker_new(srv, loop); srv->main_worker->ndx = 0; for (i = 1; i < srv->worker_count; i++) { GError *error = NULL; - worker *wrk; + liWorker *wrk; if (NULL == (loop = ev_loop_new(srv->loop_flags))) { fatal ("could not create extra libev loops"); return FALSE; } - wrk = g_array_index(srv->workers, worker*, i) = worker_new(srv, loop); + wrk = g_array_index(srv->workers, liWorker*, i) = worker_new(srv, loop); wrk->ndx = i; if (NULL == (wrk->thread = g_thread_create(server_worker_cb, wrk, TRUE, &error))) { g_error ( "g_thread_create failed: %s", error->message ); @@ -247,17 +247,17 @@ gboolean server_worker_init(server *srv) { } static void server_listen_cb(struct ev_loop *loop, ev_io *w, int revents) { - server_socket *sock = (server_socket*) w->data; - server *srv = sock->srv; + liServerSocket *sock = (liServerSocket*) w->data; + liServer *srv = sock->srv; int s; - sockaddr_t remote_addr; + liSocketAddress remote_addr; struct sockaddr sa; socklen_t l = sizeof(sa); UNUSED(loop); UNUSED(revents); while (-1 != (s = accept(w->fd, &sa, &l))) { - worker *wrk = srv->main_worker; + liWorker *wrk = srv->main_worker; guint i, min_load = g_atomic_int_get(&wrk->connection_load), sel = 0; if (l <= sizeof(sa)) { @@ -272,7 +272,7 @@ static void server_listen_cb(struct ev_loop *loop, ev_io *w, int revents) { fd_init(s); for (i = 1; i < srv->worker_count; i++) { - worker *wt = g_array_index(srv->workers, worker*, i); + liWorker *wt = g_array_index(srv->workers, liWorker*, i); guint load = g_atomic_int_get(&wt->connection_load); if (load < min_load) { wrk = wt; @@ -312,20 +312,20 @@ static void server_listen_cb(struct ev_loop *loop, ev_io *w, int revents) { } } -void server_listen(server *srv, int fd) { - server_socket *sock = server_socket_new(fd); +void server_listen(liServer *srv, int fd) { + liServerSocket *sock = server_socket_new(fd); sock->srv = srv; g_ptr_array_add(srv->sockets, sock); - if (g_atomic_int_get(&srv->state) == SERVER_RUNNING) ev_io_start(srv->main_worker->loop, &sock->watcher); + if (g_atomic_int_get(&srv->state) == LI_SERVER_RUNNING) ev_io_start(srv->main_worker->loop, &sock->watcher); } -void server_start(server *srv) { +void server_start(liServer *srv) { guint i; - server_state srvstate = g_atomic_int_get(&srv->state); - if (srvstate == SERVER_STOPPING || srvstate == SERVER_RUNNING) return; /* no restart after stop */ - g_atomic_int_set(&srv->state, SERVER_RUNNING); + liServerState srvstate = g_atomic_int_get(&srv->state); + if (srvstate == LI_SERVER_STOPPING || srvstate == LI_SERVER_RUNNING) return; /* no restart after stop */ + g_atomic_int_set(&srv->state, LI_SERVER_RUNNING); if (!srv->mainaction) { ERROR(srv, "%s", "No action handlers defined"); @@ -338,7 +338,7 @@ void server_start(server *srv) { plugins_prepare_callbacks(srv); for (i = 0; i < srv->sockets->len; i++) { - server_socket *sock = g_ptr_array_index(srv->sockets, i); + liServerSocket *sock = g_ptr_array_index(srv->sockets, i); ev_io_start(srv->main_worker->loop, &sock->watcher); } @@ -354,22 +354,22 @@ void server_start(server *srv) { worker_run(srv->main_worker); } -void server_stop(server *srv) { +void server_stop(liServer *srv) { guint i; - if (g_atomic_int_get(&srv->state) == SERVER_STOPPING) return; - g_atomic_int_set(&srv->state, SERVER_STOPPING); + if (g_atomic_int_get(&srv->state) == LI_SERVER_STOPPING) return; + g_atomic_int_set(&srv->state, LI_SERVER_STOPPING); if (srv->main_worker) { for (i = 0; i < srv->sockets->len; i++) { - server_socket *sock = g_ptr_array_index(srv->sockets, i); + liServerSocket *sock = g_ptr_array_index(srv->sockets, i); ev_io_stop(srv->main_worker->loop, &sock->watcher); } /* stop all workers */ for (i = 0; i < srv->worker_count; i++) { - worker *wrk; - wrk = g_array_index(srv->workers, worker*, i); + liWorker *wrk; + wrk = g_array_index(srv->workers, liWorker*, i); worker_stop(srv->main_worker, wrk); } } @@ -377,7 +377,7 @@ void server_stop(server *srv) { log_thread_wakeup(srv); } -void server_exit(server *srv) { +void server_exit(liServer *srv) { server_stop(srv); g_atomic_int_set(&srv->exiting, TRUE); @@ -386,8 +386,8 @@ void server_exit(server *srv) { { guint i; for (i = 0; i < srv->worker_count; i++) { - worker *wrk; - wrk = g_array_index(srv->workers, worker*, i); + liWorker *wrk; + wrk = g_array_index(srv->workers, liWorker*, i); worker_exit(srv->main_worker, wrk); } } @@ -425,11 +425,11 @@ GString *server_current_timestamp() { return ts_str; } -void server_out_of_fds(server *srv) { +void server_out_of_fds(liServer *srv) { ERROR(srv, "%s", "Too many open files. Either raise your fd limit or use a lower connection limit."); } -guint server_ts_format_add(server *srv, GString* format) { +guint server_ts_format_add(liServer *srv, GString* format) { /* check if not already registered */ guint i; for (i = 0; i < srv->ts_formats->len; i++) { diff --git a/src/stat_cache.c b/src/stat_cache.c index b2b1bb6..5813161 100644 --- a/src/stat_cache.c +++ b/src/stat_cache.c @@ -6,17 +6,17 @@ static void stat_cache_job_cb(struct ev_loop *loop, ev_async *w, int revents); static void stat_cache_delete_cb(struct ev_loop *loop, ev_timer *w, int revents); static gpointer stat_cache_thread(gpointer data); -static void stat_cache_entry_free(stat_cache_entry *sce); +static void stat_cache_entry_free(liStatCacheEntry *sce); -void stat_cache_new(worker *wrk, gdouble ttl) { - stat_cache *sc; +void stat_cache_new(liWorker *wrk, gdouble ttl) { + liStatCache *sc; GError *err; /* ttl default 10s */ if (ttl < 1) ttl = 10.0; - sc = g_slice_new0(stat_cache); + sc = g_slice_new0(liStatCache); sc->ttl = ttl; sc->entries = g_hash_table_new_full((GHashFunc)g_string_hash, (GEqualFunc)g_string_equal, NULL, NULL); sc->dirlists = g_hash_table_new_full((GHashFunc)g_string_hash, (GEqualFunc)g_string_equal, NULL, NULL); @@ -39,16 +39,16 @@ void stat_cache_new(worker *wrk, gdouble ttl) { } } -void stat_cache_free(stat_cache *sc) { +void stat_cache_free(liStatCache *sc) { GHashTableIter iter; gpointer k, v; - stat_cache_entry *dummy; + liStatCacheEntry *dummy; /* wake up thread */ - dummy = g_slice_new0(stat_cache_entry); + dummy = g_slice_new0(liStatCacheEntry); g_async_queue_push(sc->job_queue_out, dummy); g_thread_join(sc->thread); - g_slice_free(stat_cache_entry, dummy); + g_slice_free(liStatCacheEntry, dummy); ev_async_stop(sc->delete_queue.loop, &sc->job_watcher); @@ -63,13 +63,13 @@ void stat_cache_free(stat_cache *sc) { g_async_queue_unref(sc->job_queue_out); g_hash_table_destroy(sc->entries); g_hash_table_destroy(sc->dirlists); - g_slice_free(stat_cache, sc); + g_slice_free(liStatCache, sc); } static void stat_cache_delete_cb(struct ev_loop *loop, ev_timer *w, int revents) { - stat_cache *sc = (stat_cache*) w->data; - stat_cache_entry *sce; - waitqueue_elem *wqe; + liStatCache *sc = (liStatCache*) w->data; + liStatCacheEntry *sce; + liWaitQueueElem *wqe; UNUSED(loop); UNUSED(revents); @@ -102,9 +102,9 @@ static void stat_cache_delete_cb(struct ev_loop *loop, ev_timer *w, int revents) /* called whenever an async stat job has finished */ static void stat_cache_job_cb(struct ev_loop *loop, ev_async *w, int revents) { guint i; - stat_cache_entry *sce; - stat_cache *sc = ((worker*)w->data)->stat_cache; - vrequest *vr; + liStatCacheEntry *sce; + liStatCache *sc = ((liWorker*)w->data)->stat_cache; + liVRequest *vr; UNUSED(loop); UNUSED(revents); @@ -128,7 +128,7 @@ static void stat_cache_job_cb(struct ev_loop *loop, ev_async *w, int revents) { } } -static void stat_cache_entry_free(stat_cache_entry *sce) { +static void stat_cache_entry_free(liStatCacheEntry *sce) { guint i; assert(sce->vrequests->len == 0); @@ -139,19 +139,19 @@ static void stat_cache_entry_free(stat_cache_entry *sce) { if (sce->type == STAT_CACHE_ENTRY_DIR) { for (i = 0; i < sce->dirlist->len; i++) { - g_string_free(g_array_index(sce->dirlist, stat_cache_entry_data, i).path, TRUE); + g_string_free(g_array_index(sce->dirlist, liStatCacheEntryData, i).path, TRUE); } g_array_free(sce->dirlist, TRUE); } - g_slice_free(stat_cache_entry, sce); + g_slice_free(liStatCacheEntry, sce); } static gpointer stat_cache_thread(gpointer data) { - stat_cache *sc = data; - stat_cache_entry *sce; + liStatCache *sc = data; + liStatCacheEntry *sce; while (TRUE) { sce = g_async_queue_pop(sc->job_queue_out); @@ -173,7 +173,7 @@ static gpointer stat_cache_thread(gpointer data) { struct dirent *entry; struct dirent *result; gint error; - stat_cache_entry_data sced; + liStatCacheEntryData sced; GString *str; dirp = opendir(sce->data.path->str); @@ -233,10 +233,10 @@ static gpointer stat_cache_thread(gpointer data) { return NULL; } -static stat_cache_entry *stat_cache_entry_new(GString *path) { - stat_cache_entry *sce; +static liStatCacheEntry *stat_cache_entry_new(GString *path) { + liStatCacheEntry *sce; - sce = g_slice_new0(stat_cache_entry); + sce = g_slice_new0(liStatCacheEntry); sce->data.path = g_string_new_len(GSTR_LEN(path)); sce->vrequests = g_ptr_array_sized_new(8); sce->state = STAT_CACHE_ENTRY_WAITING; @@ -247,9 +247,9 @@ static stat_cache_entry *stat_cache_entry_new(GString *path) { return sce; } -handler_t stat_cache_get_dirlist(vrequest *vr, GString *path, stat_cache_entry **result) { - stat_cache *sc; - stat_cache_entry *sce; +liHandlerResult stat_cache_get_dirlist(liVRequest *vr, GString *path, liStatCacheEntry **result) { + liStatCache *sc; + liStatCacheEntry *sce; guint i; sc = vr->wrk->stat_cache; @@ -261,34 +261,34 @@ handler_t stat_cache_get_dirlist(vrequest *vr, GString *path, stat_cache_entry * /* already waiting for it? */ for (i = 0; i < vr->stat_cache_entries->len; i++) { if (g_ptr_array_index(vr->stat_cache_entries, i) == sce) - return HANDLER_WAIT_FOR_EVENT; + return LI_HANDLER_WAIT_FOR_EVENT; } stat_cache_entry_acquire(vr, sce); - return HANDLER_WAIT_FOR_EVENT; + return LI_HANDLER_WAIT_FOR_EVENT; } sce->refcount++; g_ptr_array_add(vr->stat_cache_entries, sce); sc->hits++; *result = sce; - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } else { /* cache miss, allocate new entry */ sce = stat_cache_entry_new(path); sce->type = STAT_CACHE_ENTRY_DIR; - sce->dirlist = g_array_sized_new(FALSE, FALSE, sizeof(stat_cache_entry_data), 32); + sce->dirlist = g_array_sized_new(FALSE, FALSE, sizeof(liStatCacheEntryData), 32); stat_cache_entry_acquire(vr, sce); waitqueue_push(&sc->delete_queue, &sce->queue_elem); g_hash_table_insert(sc->dirlists, sce->data.path, sce); g_async_queue_push(sc->job_queue_out, sce); sc->misses++; - return HANDLER_WAIT_FOR_EVENT; + return LI_HANDLER_WAIT_FOR_EVENT; } } -handler_t stat_cache_get(vrequest *vr, GString *path, struct stat *st, int *err, int *fd) { - stat_cache *sc; - stat_cache_entry *sce; +liHandlerResult stat_cache_get(liVRequest *vr, GString *path, struct stat *st, int *err, int *fd) { + liStatCache *sc; + liStatCacheEntry *sce; guint i; sc = vr->wrk->stat_cache; @@ -300,10 +300,10 @@ handler_t stat_cache_get(vrequest *vr, GString *path, struct stat *st, int *err, /* already waiting for it? */ for (i = 0; i < vr->stat_cache_entries->len; i++) { if (g_ptr_array_index(vr->stat_cache_entries, i) == sce) - return HANDLER_WAIT_FOR_EVENT; + return LI_HANDLER_WAIT_FOR_EVENT; } stat_cache_entry_acquire(vr, sce); - return HANDLER_WAIT_FOR_EVENT; + return LI_HANDLER_WAIT_FOR_EVENT; } sc->hits++; @@ -316,37 +316,37 @@ handler_t stat_cache_get(vrequest *vr, GString *path, struct stat *st, int *err, g_hash_table_insert(sc->entries, sce->data.path, sce); g_async_queue_push(sc->job_queue_out, sce); sc->misses++; - return HANDLER_WAIT_FOR_EVENT; + return LI_HANDLER_WAIT_FOR_EVENT; } if (fd) { /* open + fstat */ if (-1 == (*fd = open(path->str, O_RDONLY))) { *err = errno; - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } if (-1 == fstat(*fd, st)) { *err = errno; - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } } else { /* stat */ if (-1 == stat(path->str, st)) { *err = errno; - return HANDLER_ERROR; + return LI_HANDLER_ERROR; } } - return HANDLER_GO_ON; + return LI_HANDLER_GO_ON; } -void stat_cache_entry_acquire(vrequest *vr, stat_cache_entry *sce) { +void stat_cache_entry_acquire(liVRequest *vr, liStatCacheEntry *sce) { sce->refcount++; g_ptr_array_add(vr->stat_cache_entries, sce); g_ptr_array_add(sce->vrequests, vr); } -void stat_cache_entry_release(vrequest *vr, stat_cache_entry *sce) { +void stat_cache_entry_release(liVRequest *vr, liStatCacheEntry *sce) { sce->refcount--; g_ptr_array_remove_fast(sce->vrequests, vr); g_ptr_array_remove_fast(vr->stat_cache_entries, sce); diff --git a/src/tests.c b/src/tests.c index 7765297..15e51c1 100644 --- a/src/tests.c +++ b/src/tests.c @@ -6,9 +6,9 @@ #include int request_test() { - chunkqueue *cq; - request req; - handler_t res; + liChunkQueue *cq; + liRequest req; + liHandlerResult res; cq = chunkqueue_new(); request_init(&req, cq); @@ -21,21 +21,21 @@ int request_test() { )); res = http_request_parse(NULL, NULL, &req.parser_ctx); - if (res != HANDLER_GO_ON) { + if (res != LI_HANDLER_GO_ON) { fprintf(stderr, "Parser return %i", res); } - assert(req.http_method == HTTP_METHOD_GET); + assert(req.http_method == LI_HTTP_METHOD_GET); assert(cq->length == 3); request_clear(&req); chunkqueue_free(cq); - return res == HANDLER_GO_ON ? 0 : 1; + return res == LI_HANDLER_GO_ON ? 0 : 1; } int main() { - server *srv; + liServer *srv; guint32 ip, netmask; assert(parse_ipv4("10.0.3.8/24", &ip, &netmask, NULL)); diff --git a/src/throttle.c b/src/throttle.c index f2704cd..255a9d2 100644 --- a/src/throttle.c +++ b/src/throttle.c @@ -7,14 +7,14 @@ #include -throttle_pool_t *throttle_pool_new(server *srv, GString *name, guint rate) { - throttle_pool_t *pool; +liThrottlePool *throttle_pool_new(liServer *srv, GString *name, guint rate) { + liThrottlePool *pool; guint i; guint worker_count; worker_count = srv->worker_count ? srv->worker_count : 1; - pool = g_slice_new0(throttle_pool_t); + pool = g_slice_new0(liThrottlePool); pool->rate = rate; pool->magazine = rate * THROTTLE_GRANULARITY; pool->name = name; @@ -36,7 +36,7 @@ throttle_pool_t *throttle_pool_new(server *srv, GString *name, guint rate) { return pool; } -void throttle_pool_free(server *srv, throttle_pool_t *pool) { +void throttle_pool_free(liServer *srv, liThrottlePool *pool) { guint i; guint worker_count; @@ -53,15 +53,15 @@ void throttle_pool_free(server *srv, throttle_pool_t *pool) { g_string_free(pool->name, TRUE); - g_slice_free(throttle_pool_t, pool); + g_slice_free(liThrottlePool, pool); } void throttle_cb(struct ev_loop *loop, ev_timer *w, int revents) { - waitqueue_elem *wqe; - throttle_pool_t *pool; - connection *con; - worker *wrk; + liWaitQueueElem *wqe; + liThrottlePool *pool; + liConnection *con; + liWorker *wrk; ev_tstamp now; guint magazine, supply; GQueue *queue; @@ -108,8 +108,8 @@ void throttle_cb(struct ev_loop *loop, ev_timer *w, int revents) { /* rearm connections */ for (lnk = g_queue_peek_head_link(queue); lnk != NULL; lnk = lnk_next) { - ((connection*)lnk->data)->throttle.pool.magazine += supply; - ((connection*)lnk->data)->throttle.pool.queued = FALSE; + ((liConnection*)lnk->data)->throttle.pool.magazine += supply; + ((liConnection*)lnk->data)->throttle.pool.queued = FALSE; lnk_next = lnk->next; lnk->next = NULL; lnk->prev = NULL; diff --git a/src/url_parser.rl b/src/url_parser.rl index 4931a14..455a8d7 100644 --- a/src/url_parser.rl +++ b/src/url_parser.rl @@ -77,7 +77,7 @@ write data; }%% -gboolean parse_raw_url(request_uri *uri) { +gboolean parse_raw_url(liRequestUri *uri) { const char *p, *pe, *eof; const char *mark = NULL, *host_mark = NULL; int cs; @@ -93,7 +93,7 @@ gboolean parse_raw_url(request_uri *uri) { return (cs >= url_parser_first_final); } -gboolean parse_hostname(request_uri *uri) { +gboolean parse_hostname(liRequestUri *uri) { const char *p, *pe, *eof; const char *mark = NULL, *host_mark = NULL; int cs; diff --git a/src/utils.c b/src/utils.c index 01286a0..ad32a4a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -374,7 +374,7 @@ void path_simplify(GString *path) { } -GString *counter_format(guint64 count, counter_type t, GString *dest) { +GString *counter_format(guint64 count, liCounterType t, GString *dest) { guint64 rest; if (!dest) @@ -472,13 +472,13 @@ guint hash_ipv6(gconstpointer key) { } -GString *sockaddr_to_string(sockaddr_t addr, GString *dest, gboolean showport) { +GString *sockaddr_to_string(liSocketAddress addr, GString *dest, gboolean showport) { gchar *p; guint8 len = 0; guint8 tmp; guint8 tmplen; guint8 oct; - sock_addr *saddr = addr.addr; + liSockAddr *saddr = addr.addr; switch (saddr->plain.sa_family) { case AF_INET: @@ -543,18 +543,18 @@ GString *sockaddr_to_string(sockaddr_t addr, GString *dest, gboolean showport) { return dest; } -sockaddr_t sockaddr_from_string(GString *str, guint tcp_default_port) { +liSocketAddress sockaddr_from_string(GString *str, guint tcp_default_port) { guint32 ipv4; #ifdef HAVE_IPV6 guint8 ipv6[16]; #endif guint16 port = tcp_default_port; - sockaddr_t saddr = { 0, NULL }; + liSocketAddress saddr = { 0, NULL }; #ifdef HAVE_SYS_UN_H if (0 == strncmp(str->str, "unix:/", 6)) { saddr.len = str->len + 1 - 5 + sizeof(saddr.addr->un.sun_family); - saddr.addr = (sock_addr*) g_slice_alloc0(saddr.len); + saddr.addr = (liSockAddr*) g_slice_alloc0(saddr.len); saddr.addr->un.sun_family = AF_UNIX; strcpy(saddr.addr->un.sun_path, str->str + 5); } else @@ -562,7 +562,7 @@ sockaddr_t sockaddr_from_string(GString *str, guint tcp_default_port) { if (parse_ipv4(str->str, &ipv4, NULL, &port)) { if (!port) return saddr; saddr.len = sizeof(struct sockaddr_in); - saddr.addr = (sock_addr*) g_slice_alloc0(saddr.len); + saddr.addr = (liSockAddr*) g_slice_alloc0(saddr.len); saddr.addr->ipv4.sin_family = AF_INET; saddr.addr->ipv4.sin_addr.s_addr = ipv4; saddr.addr->ipv4.sin_port = htons(port); @@ -571,7 +571,7 @@ sockaddr_t sockaddr_from_string(GString *str, guint tcp_default_port) { if (parse_ipv6(str->str, ipv6, NULL, &port)) { if (!port) return saddr; saddr.len = sizeof(struct sockaddr_in6); - saddr.addr = (sock_addr*) g_slice_alloc0(saddr.len); + saddr.addr = (liSockAddr*) g_slice_alloc0(saddr.len); saddr.addr->ipv6.sin6_family = AF_INET6; memcpy(&saddr.addr->ipv6.sin6_addr, ipv6, 16); saddr.addr->ipv6.sin6_port = htons(port); @@ -580,39 +580,39 @@ sockaddr_t sockaddr_from_string(GString *str, guint tcp_default_port) { return saddr; } -sockaddr_t sockaddr_local_from_socket(gint fd) { +liSocketAddress sockaddr_local_from_socket(gint fd) { socklen_t l = 0; static struct sockaddr sa; - struct sockaddr_t saddr = { 0, NULL }; + liSocketAddress saddr = { 0, NULL }; if (-1 == getsockname(fd, &sa, &l)) { return saddr; } - saddr.addr = (sock_addr*) g_slice_alloc0(l); + saddr.addr = (liSockAddr*) g_slice_alloc0(l); saddr.len = l; getsockname(fd, (struct sockaddr*) saddr.addr, &l); return saddr; } -sockaddr_t sockaddr_remote_from_socket(gint fd) { +liSocketAddress sockaddr_remote_from_socket(gint fd) { socklen_t l = 0; static struct sockaddr sa; - struct sockaddr_t saddr = { 0, NULL }; + liSocketAddress saddr = { 0, NULL }; if (-1 == getpeername(fd, &sa, &l)) { return saddr; } - saddr.addr = (sock_addr*) g_slice_alloc0(l); + saddr.addr = (liSockAddr*) g_slice_alloc0(l); saddr.len = l; getpeername(fd, (struct sockaddr*) saddr.addr, &l); return saddr; } -void sockaddr_clear(sockaddr_t *saddr) { +void sockaddr_clear(liSocketAddress *saddr) { if (saddr->addr) g_slice_free1(saddr->len, saddr->addr); saddr->addr = NULL; saddr->len = 0; diff --git a/src/value.c b/src/value.c index 9dd352a..783d7a4 100644 --- a/src/value.c +++ b/src/value.c @@ -1,36 +1,36 @@ #include -value* value_new_none() { - value *v = g_slice_new0(value); - v->type = VALUE_NONE; +liValue* value_new_none() { + liValue *v = g_slice_new0(liValue); + v->type = LI_VALUE_NONE; return v; } -value* value_new_bool(gboolean val) { - value *v = g_slice_new0(value); +liValue* value_new_bool(gboolean val) { + liValue *v = g_slice_new0(liValue); v->data.boolean = val; - v->type = VALUE_BOOLEAN; + v->type = LI_VALUE_BOOLEAN; return v; } -value* value_new_number(gint64 val) { - value *v = g_slice_new0(value); +liValue* value_new_number(gint64 val) { + liValue *v = g_slice_new0(liValue); v->data.number = val; - v->type = VALUE_NUMBER; + v->type = LI_VALUE_NUMBER; return v; } -value* value_new_string(GString *val) { - value *v = g_slice_new0(value); +liValue* value_new_string(GString *val) { + liValue *v = g_slice_new0(liValue); v->data.string = val; - v->type = VALUE_STRING; + v->type = LI_VALUE_STRING; return v; } -value* value_new_list() { - value *v = g_slice_new0(value); - v->data.list = g_array_new(FALSE, TRUE, sizeof(value*)); - v->type = VALUE_LIST; +liValue* value_new_list() { + liValue *v = g_slice_new0(liValue); + v->data.list = g_array_new(FALSE, TRUE, sizeof(liValue*)); + v->type = LI_VALUE_LIST; return v; } @@ -39,66 +39,66 @@ static void _value_hash_free_key(gpointer data) { } static void _value_hash_free_value(gpointer data) { - value_free((value*) data); + value_free((liValue*) data); } -value* value_new_hash() { - value *v = g_slice_new0(value); +liValue* value_new_hash() { + liValue *v = g_slice_new0(liValue); v->data.hash = g_hash_table_new_full( (GHashFunc) g_string_hash, (GEqualFunc) g_string_equal, _value_hash_free_key, _value_hash_free_value); - v->type = VALUE_HASH; + v->type = LI_VALUE_HASH; return v; } -value* value_new_action(server *srv, action *a) { - value *v = g_slice_new0(value); +liValue* value_new_action(liServer *srv, liAction *a) { + liValue *v = g_slice_new0(liValue); v->data.val_action.srv = srv; v->data.val_action.action = a; - v->type = VALUE_ACTION; + v->type = LI_VALUE_ACTION; return v; } -value* value_new_condition(server *srv, condition *c) { - value *v = g_slice_new0(value); +liValue* value_new_condition(liServer *srv, liCondition *c) { + liValue *v = g_slice_new0(liValue); v->data.val_cond.srv = srv; v->data.val_cond.cond = c; - v->type = VALUE_CONDITION; + v->type = LI_VALUE_CONDITION; return v; } -value* value_copy(value* val) { - value *n; +liValue* value_copy(liValue* val) { + liValue *n; switch (val->type) { - case VALUE_NONE: n = value_new_bool(FALSE); n->type = VALUE_NONE; return n; /* hack */ - case VALUE_BOOLEAN: return value_new_bool(val->data.boolean); - case VALUE_NUMBER: return value_new_number(val->data.number); - case VALUE_STRING: return value_new_string(g_string_new_len(GSTR_LEN(val->data.string))); + case LI_VALUE_NONE: n = value_new_bool(FALSE); n->type = LI_VALUE_NONE; return n; /* hack */ + case LI_VALUE_BOOLEAN: return value_new_bool(val->data.boolean); + case LI_VALUE_NUMBER: return value_new_number(val->data.number); + case LI_VALUE_STRING: return value_new_string(g_string_new_len(GSTR_LEN(val->data.string))); /* list: we have to copy every value in the list! */ - case VALUE_LIST: + case LI_VALUE_LIST: n = value_new_list(); g_array_set_size(n->data.list, val->data.list->len); for (guint i = 0; i < val->data.list->len; i++) { - g_array_index(n->data.list, value*, i) = value_copy(g_array_index(val->data.list, value*, i)); + g_array_index(n->data.list, liValue*, i) = value_copy(g_array_index(val->data.list, liValue*, i)); } return n; /* hash: iterate over hashtable, clone each value */ - case VALUE_HASH: + case LI_VALUE_HASH: n = value_new_hash(); { GHashTableIter iter; gpointer k, v; g_hash_table_iter_init(&iter, val->data.hash); while (g_hash_table_iter_next(&iter, &k, &v)) - g_hash_table_insert(n->data.hash, g_string_new_len(GSTR_LEN((GString*)k)), value_copy((value*)v)); + g_hash_table_insert(n->data.hash, g_string_new_len(GSTR_LEN((GString*)k)), value_copy((liValue*)v)); } return n; - case VALUE_ACTION: + case LI_VALUE_ACTION: action_acquire(val->data.val_action.action); n = value_new_action(val->data.val_action.srv, val->data.val_action.action); return n; - case VALUE_CONDITION: + case LI_VALUE_CONDITION: condition_acquire(val->data.val_cond.cond); n = value_new_condition(val->data.val_cond.srv, val->data.val_cond.cond); return n; @@ -106,52 +106,52 @@ value* value_copy(value* val) { return NULL; } -void value_free(value* val) { +void value_free(liValue* val) { if (!val) return; switch (val->type) { - case VALUE_NONE: - case VALUE_BOOLEAN: - case VALUE_NUMBER: + case LI_VALUE_NONE: + case LI_VALUE_BOOLEAN: + case LI_VALUE_NUMBER: /* Nothing to free */ break; - case VALUE_STRING: + case LI_VALUE_STRING: g_string_free(val->data.string, TRUE); break; - case VALUE_LIST: + case LI_VALUE_LIST: value_list_free(val->data.list); break; - case VALUE_HASH: + case LI_VALUE_HASH: g_hash_table_destroy(val->data.hash); break; - case VALUE_ACTION: + case LI_VALUE_ACTION: action_release(val->data.val_action.srv, val->data.val_action.action); break; - case VALUE_CONDITION: + case LI_VALUE_CONDITION: condition_release(val->data.val_cond.srv, val->data.val_cond.cond); break; } - val->type = VALUE_NONE; - g_slice_free(value, val); + val->type = LI_VALUE_NONE; + g_slice_free(liValue, val); } -const char* value_type_string(value_type type) { +const char* value_type_string(liValueType type) { switch(type) { - case VALUE_NONE: + case LI_VALUE_NONE: return "none"; - case VALUE_BOOLEAN: + case LI_VALUE_BOOLEAN: return "boolean"; - case VALUE_NUMBER: + case LI_VALUE_NUMBER: return "number"; - case VALUE_STRING: + case LI_VALUE_STRING: return "string"; - case VALUE_LIST: + case LI_VALUE_LIST: return "list"; - case VALUE_HASH: + case LI_VALUE_HASH: return "hash"; - case VALUE_ACTION: + case LI_VALUE_ACTION: return "action"; - case VALUE_CONDITION: + case LI_VALUE_CONDITION: return "condition"; } return ""; @@ -160,37 +160,37 @@ const char* value_type_string(value_type type) { void value_list_free(GArray *vallist) { if (!vallist) return; for (gsize i = 0; i < vallist->len; i++) { - value_free(g_array_index(vallist, value*, i)); + value_free(g_array_index(vallist, liValue*, i)); } g_array_free(vallist, TRUE); } -GString *value_to_string(value *val) { +GString *value_to_string(liValue *val) { GString *str; switch (val->type) { - case VALUE_NONE: + case LI_VALUE_NONE: return NULL; - case VALUE_BOOLEAN: + case LI_VALUE_BOOLEAN: str = g_string_new(val->data.boolean ? "true" : "false"); break; - case VALUE_NUMBER: + case LI_VALUE_NUMBER: str = g_string_sized_new(0); g_string_printf(str, "%" G_GINT64_FORMAT, val->data.number); break; - case VALUE_STRING: + case LI_VALUE_STRING: str = g_string_new_len(CONST_STR_LEN("\"")); g_string_append_len(str, GSTR_LEN(val->data.string)); g_string_append_c(str, '"'); break; - case VALUE_LIST: + case LI_VALUE_LIST: str = g_string_new_len(CONST_STR_LEN("(")); if (val->data.list->len) { - GString *tmp = value_to_string(g_array_index(val->data.list, value*, 0)); + GString *tmp = value_to_string(g_array_index(val->data.list, liValue*, 0)); g_string_append(str, tmp->str); g_string_free(tmp, TRUE); for (guint i = 1; i < val->data.list->len; i++) { - tmp = value_to_string(g_array_index(val->data.list, value*, i)); + tmp = value_to_string(g_array_index(val->data.list, liValue*, i)); g_string_append_len(str, CONST_STR_LEN(", ")); g_string_append(str, tmp->str); g_string_free(tmp, TRUE); @@ -198,7 +198,7 @@ GString *value_to_string(value *val) { } g_string_append_c(str, ')'); break; - case VALUE_HASH: + case LI_VALUE_HASH: { GHashTableIter iter; gpointer k, v; @@ -211,7 +211,7 @@ GString *value_to_string(value *val) { while (g_hash_table_iter_next(&iter, &k, &v)) { if (i) g_string_append_len(str, CONST_STR_LEN(", ")); - tmp = value_to_string((value*)v); + tmp = value_to_string((liValue*)v); g_string_append_len(str, GSTR_LEN((GString*)k)); g_string_append_len(str, CONST_STR_LEN(": ")); g_string_append_len(str, GSTR_LEN(tmp)); @@ -223,10 +223,10 @@ GString *value_to_string(value *val) { g_string_append_c(str, ']'); break; } - case VALUE_ACTION: + case LI_VALUE_ACTION: str = g_string_new_len(CONST_STR_LEN("")); break; - case VALUE_CONDITION: + case LI_VALUE_CONDITION: str = g_string_new_len(CONST_STR_LEN("")); break; default: diff --git a/src/value_lua.c b/src/value_lua.c index 1ebf811..0c92e7b 100644 --- a/src/value_lua.c +++ b/src/value_lua.c @@ -13,8 +13,8 @@ static int lua_fixindex(lua_State *L, int ndx) { return ndx; } -static value* value_from_lua_table(server *srv, lua_State *L, int ndx) { - value *val = NULL, *sub_option; +static liValue* value_from_lua_table(liServer *srv, lua_State *L, int ndx) { + liValue *val = NULL, *sub_option; GArray *list = NULL; GHashTable *hash = NULL; int ikey; @@ -41,7 +41,7 @@ static value* value_from_lua_table(server *srv, lua_State *L, int ndx) { if ((size_t) ikey >= list->len) { g_array_set_size(list, ikey + 1); } - g_array_index(list, value*, ikey) = sub_option; + g_array_index(list, liValue*, ikey) = sub_option; break; case LUA_TSTRING: @@ -80,8 +80,8 @@ mixerror: } -value* value_from_lua(server *srv, lua_State *L) { - value *val; +liValue* value_from_lua(liServer *srv, lua_State *L) { + liValue *val; switch (lua_type(L, -1)) { case LUA_TNIL: @@ -110,7 +110,7 @@ value* value_from_lua(server *srv, lua_State *L) { case LUA_TUSERDATA: { /* check for action */ - action *a = lua_get_action(L, -1); + liAction *a = lua_get_action(L, -1); if (a) { action_acquire(a); lua_pop(L, 1); @@ -118,7 +118,7 @@ value* value_from_lua(server *srv, lua_State *L) { } } { /* check for condition */ - condition *c = lua_get_condition(L, -1); + liCondition *c = lua_get_condition(L, -1); if (c) { condition_acquire(c); lua_pop(L, 1); diff --git a/src/virtualrequest.c b/src/virtualrequest.c index 1abdf4e..3736111 100644 --- a/src/virtualrequest.c +++ b/src/virtualrequest.c @@ -2,40 +2,40 @@ #include #include -static void filters_init(filters *fs) { +static void filters_init(liFilters *fs) { fs->queue = g_ptr_array_new(); fs->in = chunkqueue_new(); fs->out = chunkqueue_new(); } -static void filters_clean(vrequest *vr, filters *fs) { +static void filters_clean(liVRequest *vr, liFilters *fs) { guint i; for (i = 0; i < fs->queue->len; i++) { - filter *f = (filter*) g_ptr_array_index(fs->queue, i); + liFilter *f = (liFilter*) g_ptr_array_index(fs->queue, i); if (f->handle_free && f->param) f->handle_free(vr, f); if (i > 0) chunkqueue_free(fs->in); - g_slice_free(filter, f); + g_slice_free(liFilter, f); } g_ptr_array_free(fs->queue, TRUE); chunkqueue_free(fs->in); chunkqueue_free(fs->out); } -static void filters_reset(vrequest *vr, filters *fs) { +static void filters_reset(liVRequest *vr, liFilters *fs) { guint i; fs->skip_ndx = 0; for (i = 0; i < fs->queue->len; i++) { - filter *f = (filter*) g_ptr_array_index(fs->queue, i); + liFilter *f = (liFilter*) g_ptr_array_index(fs->queue, i); if (f->handle_free && f->param) f->handle_free(vr, f); if (i > 0) chunkqueue_free(fs->in); - g_slice_free(filter, f); + g_slice_free(liFilter, f); } g_ptr_array_set_size(fs->queue, 0); chunkqueue_reset(fs->in); chunkqueue_reset(fs->out); } -static gboolean filters_run(vrequest *vr, filters *fs) { +static gboolean filters_run(liVRequest *vr, liFilters *fs) { guint i; if (0 == fs->queue->len) { chunkqueue_steal_all(fs->out, fs->in); @@ -43,29 +43,29 @@ static gboolean filters_run(vrequest *vr, filters *fs) { return TRUE; } for (i = 0; i < fs->queue->len; i++) { - filter *f = (filter*) g_ptr_array_index(fs->queue, i); + liFilter *f = (liFilter*) g_ptr_array_index(fs->queue, i); switch (f->handle_data(vr, f)) { - case HANDLER_GO_ON: + case LI_HANDLER_GO_ON: break; - case HANDLER_COMEBACK: + case LI_HANDLER_COMEBACK: vrequest_joblist_append(vr); break; - case HANDLER_WAIT_FOR_EVENT: + case LI_HANDLER_WAIT_FOR_EVENT: break; /* ignore - filter has to call vrequest_joblist_append(vr); */ - case HANDLER_ERROR: + case LI_HANDLER_ERROR: return FALSE; } } if (fs->out->is_closed) { - filter *f = (filter*) g_ptr_array_index(fs->queue, fs->queue->len - 1); + liFilter *f = (liFilter*) g_ptr_array_index(fs->queue, fs->queue->len - 1); f->in->is_closed = TRUE; } for (i = fs->queue->len; i-- > fs->skip_ndx; ) { - filter *f = (filter*) g_ptr_array_index(fs->queue, i); + liFilter *f = (liFilter*) g_ptr_array_index(fs->queue, i); if (f->in->is_closed) { guint j = i; while (j-- > fs->skip_ndx) { - filter *ff = (filter*) g_ptr_array_index(fs->queue, j); + liFilter *ff = (liFilter*) g_ptr_array_index(fs->queue, j); ff->in->is_closed = TRUE; } fs->skip_ndx = i; @@ -74,8 +74,8 @@ static gboolean filters_run(vrequest *vr, filters *fs) { return TRUE; } -static void filters_add(filters *fs, filter_handler handle_data, filter_free handle_free, gpointer param) { - filter *f = g_slice_new0(filter); +static void filters_add(liFilters *fs, liFilterHandlerCB handle_data, liFilterFreeCB handle_free, gpointer param) { + liFilter *f = g_slice_new0(liFilter); f->out = fs->out; f->param = param; f->handle_data = handle_data; @@ -83,31 +83,31 @@ static void filters_add(filters *fs, filter_handler handle_data, filter_free han if (0 == fs->queue->len) { f->in = fs->in; } else { - filter *prev = (filter*) g_ptr_array_index(fs->queue, fs->queue->len - 1); + liFilter *prev = (liFilter*) g_ptr_array_index(fs->queue, fs->queue->len - 1); f->in = prev->out = chunkqueue_new(); chunkqueue_set_limit(f->in, fs->in->limit); } g_ptr_array_add(fs->queue, f); } -void vrequest_add_filter_in(vrequest *vr, filter_handler handle_data, filter_free handle_free, gpointer param) { +void vrequest_add_filter_in(liVRequest *vr, liFilterHandlerCB handle_data, liFilterFreeCB handle_free, gpointer param) { filters_add(&vr->filters_in, handle_data, handle_free, param); } -void vrequest_add_filter_out(vrequest *vr, filter_handler handle_data, filter_free handle_free, gpointer param) { +void vrequest_add_filter_out(liVRequest *vr, liFilterHandlerCB handle_data, liFilterFreeCB handle_free, gpointer param) { filters_add(&vr->filters_out, handle_data, handle_free, param); } -vrequest* vrequest_new(connection *con, vrequest_handler handle_response_headers, vrequest_handler handle_response_body, vrequest_handler handle_response_error, vrequest_handler handle_request_headers) { - server *srv = con->srv; - vrequest *vr = g_slice_new0(vrequest); +liVRequest* vrequest_new(liConnection *con, liVRequestHandlerCB handle_response_headers, liVRequestHandlerCB handle_response_body, liVRequestHandlerCB handle_response_error, liVRequestHandlerCB handle_request_headers) { + liServer *srv = con->srv; + liVRequest *vr = g_slice_new0(liVRequest); vr->con = con; vr->wrk = con->wrk; - vr->ref = g_slice_new0(vrequest_ref); + vr->ref = g_slice_new0(liVRequestRef); vr->ref->refcount = 1; vr->ref->vr = vr; - vr->state = VRS_CLEAN; + vr->state = LI_VRS_CLEAN; vr->handle_response_headers = handle_response_headers; vr->handle_response_body = handle_response_body; @@ -116,7 +116,7 @@ vrequest* vrequest_new(connection *con, vrequest_handler handle_response_headers vr->plugin_ctx = g_ptr_array_new(); g_ptr_array_set_size(vr->plugin_ctx, g_hash_table_size(srv->plugins)); - vr->options = g_slice_copy(srv->option_def_values->len * sizeof(option_value), srv->option_def_values->data); + vr->options = g_slice_copy(srv->option_def_values->len * sizeof(liOptionValue), srv->option_def_values->data); request_init(&vr->request); physical_init(&vr->physical); @@ -139,7 +139,7 @@ vrequest* vrequest_new(connection *con, vrequest_handler handle_response_headers return vr; } -void vrequest_free(vrequest* vr) { +void vrequest_free(liVRequest* vr) { guint i; action_stack_clear(vr, &vr->action_stack); @@ -159,24 +159,24 @@ void vrequest_free(vrequest* vr) { g_atomic_int_set(&vr->queued, 0); } - g_slice_free1(vr->wrk->srv->option_def_values->len * sizeof(option_value), vr->options); + g_slice_free1(vr->wrk->srv->option_def_values->len * sizeof(liOptionValue), vr->options); for (i = 0; i < vr->stat_cache_entries->len; i++) { - stat_cache_entry *sce = g_ptr_array_index(vr->stat_cache_entries, i); + liStatCacheEntry *sce = g_ptr_array_index(vr->stat_cache_entries, i); stat_cache_entry_release(vr, sce); } g_ptr_array_free(vr->stat_cache_entries, TRUE); vr->ref->vr = NULL; if (g_atomic_int_dec_and_test(&vr->ref->refcount)) { - g_slice_free(vrequest_ref, vr->ref); + g_slice_free(liVRequestRef, vr->ref); } - g_slice_free(vrequest, vr); + g_slice_free(liVRequest, vr); } -void vrequest_reset(vrequest *vr) { +void vrequest_reset(liVRequest *vr) { guint i; action_stack_reset(vr, &vr->action_stack); @@ -187,7 +187,7 @@ void vrequest_reset(vrequest *vr) { g_ptr_array_set_size(vr->plugin_ctx, len); } - vr->state = VRS_CLEAN; + vr->state = LI_VRS_CLEAN; vr->backend = NULL; @@ -205,97 +205,97 @@ void vrequest_reset(vrequest *vr) { } for (i = 0; i < vr->stat_cache_entries->len; i++) { - stat_cache_entry *sce = g_ptr_array_index(vr->stat_cache_entries, i); + liStatCacheEntry *sce = g_ptr_array_index(vr->stat_cache_entries, i); stat_cache_entry_release(vr, sce); } - memcpy(vr->options, vr->wrk->srv->option_def_values->data, vr->wrk->srv->option_def_values->len * sizeof(option_value)); + memcpy(vr->options, vr->wrk->srv->option_def_values->data, vr->wrk->srv->option_def_values->len * sizeof(liOptionValue)); if (1 != g_atomic_int_get(&vr->ref->refcount)) { /* If we are not the only user of vr->ref we have to get a new one and detach the old */ vr->ref->vr = NULL; if (g_atomic_int_dec_and_test(&vr->ref->refcount)) { - g_slice_free(vrequest_ref, vr->ref); + g_slice_free(liVRequestRef, vr->ref); } - vr->ref = g_slice_new0(vrequest_ref); + vr->ref = g_slice_new0(liVRequestRef); vr->ref->refcount = 1; vr->ref->vr = vr; } } -vrequest_ref* vrequest_acquire_ref(vrequest *vr) { - vrequest_ref* vr_ref = vr->ref; +liVRequestRef* vrequest_acquire_ref(liVRequest *vr) { + liVRequestRef* vr_ref = vr->ref; g_assert(vr_ref->refcount > 0); g_atomic_int_inc(&vr_ref->refcount); return vr_ref; } -vrequest* vrequest_release_ref(vrequest_ref *vr_ref) { - vrequest *vr = vr_ref->vr; +liVRequest* vrequest_release_ref(liVRequestRef *vr_ref) { + liVRequest *vr = vr_ref->vr; g_assert(vr_ref->refcount > 0); if (g_atomic_int_dec_and_test(&vr_ref->refcount)) { g_assert(vr == NULL); /* we are the last user, and the ref holded by vr itself is handled extra, so the vr was already reset */ - g_slice_free(vrequest_ref, vr_ref); + g_slice_free(liVRequestRef, vr_ref); } return vr; } -void vrequest_error(vrequest *vr) { - vr->state = VRS_ERROR; +void vrequest_error(liVRequest *vr) { + vr->state = LI_VRS_ERROR; vr->out->is_closed = TRUE; vrequest_joblist_append(vr); } -void vrequest_backend_error(vrequest *vr, backend_error berror) { +void vrequest_backend_error(liVRequest *vr, liBackendError berror) { vr->action_stack.backend_failed = TRUE; vr->action_stack.backend_error = berror; - vr->state = VRS_HANDLE_REQUEST_HEADERS; + vr->state = LI_VRS_HANDLE_REQUEST_HEADERS; vr->backend = NULL; vrequest_joblist_append(vr); } -void vrequest_backend_overloaded(vrequest *vr) { +void vrequest_backend_overloaded(liVRequest *vr) { vrequest_backend_error(vr, BACKEND_OVERLOAD); } -void vrequest_backend_dead(vrequest *vr) { +void vrequest_backend_dead(liVRequest *vr) { vrequest_backend_error(vr, BACKEND_DEAD); } /* received all request headers */ -void vrequest_handle_request_headers(vrequest *vr) { - if (VRS_CLEAN == vr->state) { - vr->state = VRS_HANDLE_REQUEST_HEADERS; +void vrequest_handle_request_headers(liVRequest *vr) { + if (LI_VRS_CLEAN == vr->state) { + vr->state = LI_VRS_HANDLE_REQUEST_HEADERS; } vrequest_joblist_append(vr); } /* received (partial) request content */ -void vrequest_handle_request_body(vrequest *vr) { - if (VRS_READ_CONTENT <= vr->state) { +void vrequest_handle_request_body(liVRequest *vr) { + if (LI_VRS_READ_CONTENT <= vr->state) { vrequest_joblist_append(vr); } } /* received all response headers/status code - call once from your indirect handler */ -void vrequest_handle_response_headers(vrequest *vr) { - if (VRS_HANDLE_RESPONSE_HEADERS > vr->state) { - vr->state = VRS_HANDLE_RESPONSE_HEADERS; +void vrequest_handle_response_headers(liVRequest *vr) { + if (LI_VRS_HANDLE_RESPONSE_HEADERS > vr->state) { + vr->state = LI_VRS_HANDLE_RESPONSE_HEADERS; } vrequest_joblist_append(vr); } /* received (partial) response content - call from your indirect handler */ -void vrequest_handle_response_body(vrequest *vr) { - if (VRS_WRITE_CONTENT == vr->state) { +void vrequest_handle_response_body(liVRequest *vr) { + if (LI_VRS_WRITE_CONTENT == vr->state) { vrequest_joblist_append(vr); } } /* response completely ready */ -gboolean vrequest_handle_direct(vrequest *vr) { - if (vr->state < VRS_READ_CONTENT) { - vr->state = VRS_HANDLE_RESPONSE_HEADERS; +gboolean vrequest_handle_direct(liVRequest *vr) { + if (vr->state < LI_VRS_READ_CONTENT) { + vr->state = LI_VRS_HANDLE_RESPONSE_HEADERS; vr->out->is_closed = TRUE; vr->backend = NULL; return TRUE; @@ -305,9 +305,9 @@ gboolean vrequest_handle_direct(vrequest *vr) { } /* handle request over time */ -gboolean vrequest_handle_indirect(vrequest *vr, plugin *p) { - if (vr->state < VRS_READ_CONTENT) { - vr->state = VRS_READ_CONTENT; +gboolean vrequest_handle_indirect(liVRequest *vr, liPlugin *p) { + if (vr->state < LI_VRS_READ_CONTENT) { + vr->state = LI_VRS_READ_CONTENT; vr->backend = p; return TRUE; } else { @@ -315,31 +315,31 @@ gboolean vrequest_handle_indirect(vrequest *vr, plugin *p) { } } -gboolean vrequest_is_handled(vrequest *vr) { - return vr->state >= VRS_READ_CONTENT; +gboolean vrequest_is_handled(liVRequest *vr) { + return vr->state >= LI_VRS_READ_CONTENT; } -static gboolean vrequest_do_handle_actions(vrequest *vr) { - handler_t res = action_execute(vr); +static gboolean vrequest_do_handle_actions(liVRequest *vr) { + liHandlerResult res = action_execute(vr); switch (res) { - case HANDLER_GO_ON: - if (vr->state == VRS_HANDLE_REQUEST_HEADERS) { + case LI_HANDLER_GO_ON: + if (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS) { /* request not handled */ vrequest_handle_direct(vr); vr->response.http_status = 404; - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "actions didn't handle request"); } return TRUE; } /* otherwise state already changed */ break; - case HANDLER_COMEBACK: + case LI_HANDLER_COMEBACK: vrequest_joblist_append(vr); /* come back later */ return FALSE; - case HANDLER_WAIT_FOR_EVENT: + case LI_HANDLER_WAIT_FOR_EVENT: return FALSE; - case HANDLER_ERROR: + case LI_HANDLER_ERROR: vrequest_error(vr); return FALSE; } @@ -347,7 +347,7 @@ static gboolean vrequest_do_handle_actions(vrequest *vr) { } -static gboolean vrequest_do_handle_read(vrequest *vr) { +static gboolean vrequest_do_handle_read(liVRequest *vr) { if (vr->backend && vr->backend->handle_request_body) { if (!filters_run(vr, &vr->filters_in)) { vrequest_error(vr); @@ -355,14 +355,14 @@ static gboolean vrequest_do_handle_read(vrequest *vr) { if (vr->vr_in->is_closed) vr->in->is_closed = TRUE; switch (vr->backend->handle_request_body(vr, vr->backend)) { - case HANDLER_GO_ON: + case LI_HANDLER_GO_ON: break; - case HANDLER_COMEBACK: + case LI_HANDLER_COMEBACK: vrequest_joblist_append(vr); /* come back later */ return FALSE; - case HANDLER_WAIT_FOR_EVENT: + case LI_HANDLER_WAIT_FOR_EVENT: return FALSE; - case HANDLER_ERROR: + case LI_HANDLER_ERROR: vrequest_error(vr); break; } @@ -373,94 +373,94 @@ static gboolean vrequest_do_handle_read(vrequest *vr) { return TRUE; } -static gboolean vrequest_do_handle_write(vrequest *vr) { +static gboolean vrequest_do_handle_write(liVRequest *vr) { if (!filters_run(vr, &vr->filters_out)) { vrequest_error(vr); } switch (vr->handle_response_body(vr)) { - case HANDLER_GO_ON: + case LI_HANDLER_GO_ON: break; - case HANDLER_COMEBACK: + case LI_HANDLER_COMEBACK: vrequest_joblist_append(vr); /* come back later */ return FALSE; - case HANDLER_WAIT_FOR_EVENT: + case LI_HANDLER_WAIT_FOR_EVENT: return FALSE; - case HANDLER_ERROR: + case LI_HANDLER_ERROR: vrequest_error(vr); break; } return TRUE; } -void vrequest_state_machine(vrequest *vr) { +void vrequest_state_machine(liVRequest *vr) { gboolean done = FALSE; - handler_t res; + liHandlerResult res; do { switch (vr->state) { - case VRS_CLEAN: + case LI_VRS_CLEAN: done = TRUE; break; - case VRS_HANDLE_REQUEST_HEADERS: - if (CORE_OPTION(CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { + case LI_VRS_HANDLE_REQUEST_HEADERS: + if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "handle request header"); } if (!vrequest_do_handle_actions(vr)) return; res = vr->handle_request_headers(vr); switch (res) { - case HANDLER_GO_ON: - if (vr->state == VRS_HANDLE_REQUEST_HEADERS) { + case LI_HANDLER_GO_ON: + if (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS) { /* unhandled request */ vr->response.http_status = 404; vrequest_handle_direct(vr); } break; - case HANDLER_COMEBACK: + case LI_HANDLER_COMEBACK: vrequest_joblist_append(vr); /* come back later */ done = TRUE; break; - case HANDLER_WAIT_FOR_EVENT: - done = (vr->state == VRS_HANDLE_REQUEST_HEADERS); + case LI_HANDLER_WAIT_FOR_EVENT: + done = (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS); break; - case HANDLER_ERROR: + case LI_HANDLER_ERROR: vrequest_error(vr); break; } break; - case VRS_READ_CONTENT: + case LI_VRS_READ_CONTENT: done = !vrequest_do_handle_read(vr); - done = done || (vr->state == VRS_READ_CONTENT); + done = done || (vr->state == LI_VRS_READ_CONTENT); break; - case VRS_HANDLE_RESPONSE_HEADERS: + case LI_VRS_HANDLE_RESPONSE_HEADERS: if (!vrequest_do_handle_actions(vr)) return; res = vr->handle_response_headers(vr); switch (res) { - case HANDLER_GO_ON: - vr->state = VRS_WRITE_CONTENT; + case LI_HANDLER_GO_ON: + vr->state = LI_VRS_WRITE_CONTENT; break; - case HANDLER_COMEBACK: + case LI_HANDLER_COMEBACK: vrequest_joblist_append(vr); /* come back later */ done = TRUE; break; - case HANDLER_WAIT_FOR_EVENT: - done = (vr->state == VRS_HANDLE_REQUEST_HEADERS); + case LI_HANDLER_WAIT_FOR_EVENT: + done = (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS); break; - case HANDLER_ERROR: + case LI_HANDLER_ERROR: vrequest_error(vr); break; } break; - case VRS_WRITE_CONTENT: + case LI_VRS_WRITE_CONTENT: vrequest_do_handle_read(vr); vrequest_do_handle_write(vr); done = TRUE; break; - case VRS_ERROR: + case LI_VRS_ERROR: /* this will probably reset the vrequest, so stop handling after it */ vr->handle_response_error(vr); return; @@ -468,23 +468,23 @@ void vrequest_state_machine(vrequest *vr) { } while (!done); } -void vrequest_joblist_append(vrequest *vr) { - worker *wrk = vr->wrk; +void vrequest_joblist_append(liVRequest *vr) { + liWorker *wrk = vr->wrk; GQueue *const q = &wrk->job_queue; if (!g_atomic_int_compare_and_exchange(&vr->queued, 0, 1)) return; /* already in queue */ g_queue_push_tail_link(q, &vr->job_queue_link); ev_timer_start(wrk->loop, &wrk->job_queue_watcher); } -void vrequest_joblist_append_async(vrequest *vr) { - worker *wrk = vr->wrk; +void vrequest_joblist_append_async(liVRequest *vr) { + liWorker *wrk = vr->wrk; GAsyncQueue *const q = wrk->job_async_queue; if (!g_atomic_int_compare_and_exchange(&vr->queued, 0, 1)) return; /* already in queue */ g_async_queue_push(q, vrequest_acquire_ref(vr)); ev_async_send(wrk->loop, &wrk->job_async_queue_watcher); } -gboolean vrequest_stat(vrequest *vr) { +gboolean vrequest_stat(liVRequest *vr) { /* Do not stat again */ if (vr->physical.have_stat || vr->physical.have_errno) return vr->physical.have_stat; @@ -507,7 +507,7 @@ gboolean vrequest_stat(vrequest *vr) { return TRUE; } -gboolean vrequest_redirect(vrequest *vr, GString *uri) { +gboolean vrequest_redirect(liVRequest *vr, GString *uri) { if (!vrequest_handle_direct(vr)) return FALSE; diff --git a/src/waitqueue.c b/src/waitqueue.c index 6bd91c4..3cdc50b 100644 --- a/src/waitqueue.c +++ b/src/waitqueue.c @@ -1,7 +1,7 @@ -#include +#include -void waitqueue_init(waitqueue *queue, struct ev_loop *loop, waitqueue_cb callback, gdouble delay, gpointer data) { +void waitqueue_init(liWaitQueue *queue, struct ev_loop *loop, liWaitQueueCB callback, gdouble delay, gpointer data) { ev_timer_init(&queue->timer, callback, delay, delay); queue->timer.data = data; @@ -10,11 +10,11 @@ void waitqueue_init(waitqueue *queue, struct ev_loop *loop, waitqueue_cb callbac queue->delay = delay; } -void waitqueue_stop(waitqueue *queue) { +void waitqueue_stop(liWaitQueue *queue) { ev_timer_stop(queue->loop, &queue->timer); } -void waitqueue_update(waitqueue *queue) { +void waitqueue_update(liWaitQueue *queue) { ev_tstamp repeat; ev_tstamp now = ev_now(queue->loop); @@ -33,7 +33,7 @@ void waitqueue_update(waitqueue *queue) { } } -void waitqueue_push(waitqueue *queue, waitqueue_elem *elem) { +void waitqueue_push(liWaitQueue *queue, liWaitQueueElem *elem) { elem->ts = ev_now(queue->loop); if (!elem->queued) { @@ -74,8 +74,8 @@ void waitqueue_push(waitqueue *queue, waitqueue_elem *elem) { ev_timer_start(queue->loop, &queue->timer); } -waitqueue_elem *waitqueue_pop(waitqueue *queue) { - waitqueue_elem *elem = queue->head; +liWaitQueueElem *waitqueue_pop(liWaitQueue *queue) { + liWaitQueueElem *elem = queue->head; ev_tstamp now = ev_now(queue->loop); if (!elem || (elem->ts + queue->delay) > now) { @@ -94,7 +94,7 @@ waitqueue_elem *waitqueue_pop(waitqueue *queue) { return elem; } -void waitqueue_remove(waitqueue *queue, waitqueue_elem *elem) { +void waitqueue_remove(liWaitQueue *queue, liWaitQueueElem *elem) { if (!elem->queued) return; @@ -116,9 +116,9 @@ void waitqueue_remove(waitqueue *queue, waitqueue_elem *elem) { } -guint waitqueue_length(waitqueue *queue) { +guint waitqueue_length(liWaitQueue *queue) { guint i = 0; - waitqueue_elem *elem = queue->head; + liWaitQueueElem *elem = queue->head; while (elem) { i++; @@ -128,9 +128,9 @@ guint waitqueue_length(waitqueue *queue) { return i; } -guint waitqueue_pop_ready(waitqueue *queue, waitqueue_elem **head) { +guint waitqueue_pop_ready(liWaitQueue *queue, liWaitQueueElem **head) { guint i = 0; - waitqueue_elem *elem = queue->head; + liWaitQueueElem *elem = queue->head; ev_tstamp now = ev_now(queue->loop); *head = elem; diff --git a/src/worker.c b/src/worker.c index ec79ea9..18bfc97 100644 --- a/src/worker.c +++ b/src/worker.c @@ -3,16 +3,15 @@ #include -static connection* worker_con_get(worker *wrk); -void worker_con_put(connection *con); +static liConnection* worker_con_get(liWorker *wrk); +void worker_con_put(liConnection *con); /* closing sockets - wait for proper shutdown */ -struct worker_closing_socket; typedef struct worker_closing_socket worker_closing_socket; struct worker_closing_socket { - worker *wrk; + liWorker *wrk; GList *link; int fd; }; @@ -28,11 +27,11 @@ static void worker_closing_socket_cb(int revents, void* arg) { g_slice_free(worker_closing_socket, scs); } -void worker_add_closing_socket(worker *wrk, int fd) { +void worker_add_closing_socket(liWorker *wrk, int fd) { worker_closing_socket *scs; shutdown(fd, SHUT_WR); - if (g_atomic_int_get(&wrk->srv->state) == SERVER_STOPPING) { + if (g_atomic_int_get(&wrk->srv->state) == LI_SERVER_STOPPING) { shutdown(fd, SHUT_RD); close(fd); return; @@ -48,35 +47,35 @@ void worker_add_closing_socket(worker *wrk, int fd) { } /* Kill it - frees fd */ -static void worker_rem_closing_socket(worker *wrk, worker_closing_socket *scs) { +static void worker_rem_closing_socket(liWorker *wrk, worker_closing_socket *scs) { ev_feed_fd_event(wrk->loop, scs->fd, EV_READ); } /* Keep alive */ -void worker_check_keepalive(worker *wrk) { +void worker_check_keepalive(liWorker *wrk) { ev_tstamp now = ev_now(wrk->loop); if (0 == wrk->keep_alive_queue.length) { ev_timer_stop(wrk->loop, &wrk->keep_alive_timer); } else { - wrk->keep_alive_timer.repeat = ((connection*)g_queue_peek_head(&wrk->keep_alive_queue))->keep_alive_data.timeout - now + 1; + wrk->keep_alive_timer.repeat = ((liConnection*)g_queue_peek_head(&wrk->keep_alive_queue))->keep_alive_data.timeout - now + 1; ev_timer_again(wrk->loop, &wrk->keep_alive_timer); } } static void worker_keepalive_cb(struct ev_loop *loop, ev_timer *w, int revents) { - worker *wrk = (worker*) w->data; + liWorker *wrk = (liWorker*) w->data; ev_tstamp now = ev_now(wrk->loop); GQueue *q = &wrk->keep_alive_queue; GList *l; - connection *con; + liConnection *con; UNUSED(loop); UNUSED(revents); while ( NULL != (l = g_queue_peek_head_link(q)) && - (con = (connection*) l->data)->keep_alive_data.timeout <= now ) { + (con = (liConnection*) l->data)->keep_alive_data.timeout <= now ) { ev_tstamp remaining = con->keep_alive_data.max_idle - wrk->srv->keep_alive_queue_timeout - (now - con->keep_alive_data.timeout); if (remaining > 0) { g_queue_delete_link(q, l); @@ -99,9 +98,9 @@ static void worker_keepalive_cb(struct ev_loop *loop, ev_timer *w, int revents) /* check for timeouted connections */ static void worker_io_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) { - worker *wrk = (worker*) w->data; - connection *con; - waitqueue_elem *wqe; + liWorker *wrk = (liWorker*) w->data; + liConnection *con; + liWaitQueueElem *wqe; ev_tstamp now = CUR_TS(wrk); UNUSED(loop); @@ -120,10 +119,10 @@ static void worker_io_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) /* run vreqest state machine */ static void worker_job_queue_cb(struct ev_loop *loop, ev_timer *w, int revents) { - worker *wrk = (worker*) w->data; + liWorker *wrk = (liWorker*) w->data; GQueue q = wrk->job_queue; GList *l; - vrequest *vr; + liVRequest *vr; UNUSED(loop); UNUSED(revents); @@ -138,10 +137,10 @@ static void worker_job_queue_cb(struct ev_loop *loop, ev_timer *w, int revents) /* run vreqest state machine for async queued jobs */ static void worker_job_async_queue_cb(struct ev_loop *loop, ev_async *w, int revents) { - worker *wrk = (worker*) w->data; + liWorker *wrk = (liWorker*) w->data; GAsyncQueue *q = wrk->job_async_queue; - vrequest_ref *vr_ref; - vrequest *vr; + liVRequestRef *vr_ref; + liVRequest *vr; UNUSED(loop); UNUSED(revents); @@ -155,10 +154,10 @@ static void worker_job_async_queue_cb(struct ev_loop *loop, ev_async *w, int rev /* cache timestamp */ -GString *worker_current_timestamp(worker *wrk, guint format_ndx) { +GString *worker_current_timestamp(liWorker *wrk, guint format_ndx) { gsize len; struct tm tm; - worker_ts *wts = &g_array_index(wrk->timestamps, worker_ts, format_ndx); + liWorkerTS *wts = &g_array_index(wrk->timestamps, liWorkerTS, format_ndx); time_t now = (time_t)CUR_TS(wrk); /* cache hit */ @@ -179,7 +178,7 @@ GString *worker_current_timestamp(worker *wrk, guint format_ndx) { /* stop worker watcher */ static void worker_stop_cb(struct ev_loop *loop, ev_async *w, int revents) { - worker *wrk = (worker*) w->data; + liWorker *wrk = (liWorker*) w->data; UNUSED(loop); UNUSED(revents); @@ -188,28 +187,27 @@ static void worker_stop_cb(struct ev_loop *loop, ev_async *w, int revents) { /* exit worker watcher */ static void worker_exit_cb(struct ev_loop *loop, ev_async *w, int revents) { - worker *wrk = (worker*) w->data; + liWorker *wrk = (liWorker*) w->data; UNUSED(loop); UNUSED(revents); worker_exit(wrk, wrk); } -struct worker_new_con_data; typedef struct worker_new_con_data worker_new_con_data; struct worker_new_con_data { - sockaddr_t remote_addr; + liSocketAddress remote_addr; int s; - server_socket *srv_sock; + liServerSocket *srv_sock; }; /* new con watcher */ -void worker_new_con(worker *ctx, worker *wrk, sockaddr_t remote_addr, int s, server_socket *srv_sock) { +void worker_new_con(liWorker *ctx, liWorker *wrk, liSocketAddress remote_addr, int s, liServerSocket *srv_sock) { if (ctx == wrk) { - connection *con = worker_con_get(wrk); + liConnection *con = worker_con_get(wrk); con->srv_sock = srv_sock; - con->state = CON_STATE_REQUEST_START; + con->state = LI_CON_STATE_REQUEST_START; con->remote_addr = remote_addr; ev_io_set(&con->sock_watcher, s, EV_READ); ev_io_start(wrk->loop, &con->sock_watcher); @@ -227,7 +225,7 @@ void worker_new_con(worker *ctx, worker *wrk, sockaddr_t remote_addr, int s, ser } static void worker_new_con_cb(struct ev_loop *loop, ev_async *w, int revents) { - worker *wrk = (worker*) w->data; + liWorker *wrk = (liWorker*) w->data; worker_new_con_data *d; UNUSED(loop); UNUSED(revents); @@ -240,7 +238,7 @@ static void worker_new_con_cb(struct ev_loop *loop, ev_async *w, int revents) { /* stats watcher */ static void worker_stats_watcher_cb(struct ev_loop *loop, ev_timer *w, int revents) { - worker *wrk = (worker*) w->data; + liWorker *wrk = (liWorker*) w->data; ev_tstamp now = ev_now(wrk->loop); UNUSED(loop); UNUSED(revents); @@ -280,8 +278,8 @@ static void worker_stats_watcher_cb(struct ev_loop *loop, ev_timer *w, int reven /* init */ -worker* worker_new(struct server *srv, struct ev_loop *loop) { - worker *wrk = g_slice_new0(worker); +liWorker* worker_new(liServer *srv, struct ev_loop *loop) { + liWorker *wrk = g_slice_new0(liWorker); wrk->srv = srv; wrk->loop = loop; @@ -290,16 +288,16 @@ worker* worker_new(struct server *srv, struct ev_loop *loop) { wrk->keep_alive_timer.data = wrk; wrk->connections_active = 0; - wrk->connections = g_array_new(FALSE, TRUE, sizeof(connection*)); + wrk->connections = g_array_new(FALSE, TRUE, sizeof(liConnection*)); wrk->tmp_str = g_string_sized_new(255); - wrk->timestamps = g_array_sized_new(FALSE, TRUE, sizeof(worker_ts), srv->ts_formats->len); + wrk->timestamps = g_array_sized_new(FALSE, TRUE, sizeof(liWorkerTS), srv->ts_formats->len); g_array_set_size(wrk->timestamps, srv->ts_formats->len); { guint i; for (i = 0; i < srv->ts_formats->len; i++) - g_array_index(wrk->timestamps, worker_ts, i).str = g_string_sized_new(255); + g_array_index(wrk->timestamps, liWorkerTS, i).str = g_string_sized_new(255); } ev_init(&wrk->worker_exit_watcher, worker_exit_cb); @@ -349,7 +347,7 @@ worker* worker_new(struct server *srv, struct ev_loop *loop) { return wrk; } -void worker_free(worker *wrk) { +void worker_free(liWorker *wrk) { if (!wrk) return; { /* close connections */ @@ -357,12 +355,12 @@ void worker_free(worker *wrk) { if (wrk->connections_active > 0) { ERROR(wrk->srv, "Server shutdown with unclosed connections: %u", wrk->connections_active); for (i = wrk->connections_active; i-- > 0;) { - connection *con = g_array_index(wrk->connections, connection*, i); + liConnection *con = g_array_index(wrk->connections, liConnection*, i); connection_error(con); } } for (i = 0; i < wrk->connections->len; i++) { - connection_free(g_array_index(wrk->connections, connection*, i)); + connection_free(g_array_index(wrk->connections, liConnection*, i)); } g_array_free(wrk->connections, TRUE); } @@ -381,7 +379,7 @@ void worker_free(worker *wrk) { { /* free timestamps */ guint i; for (i = 0; i < wrk->timestamps->len; i++) - g_string_free(g_array_index(wrk->timestamps, worker_ts, i).str, TRUE); + g_string_free(g_array_index(wrk->timestamps, liWorkerTS, i).str, TRUE); g_array_free(wrk->timestamps, TRUE); } @@ -390,8 +388,8 @@ void worker_free(worker *wrk) { { GAsyncQueue *q = wrk->job_async_queue; - vrequest_ref *vr_ref; - vrequest *vr; + liVRequestRef *vr_ref; + liVRequest *vr; while (NULL != (vr_ref = g_async_queue_try_pop(q))) { if (NULL != (vr = vrequest_release_ref(vr_ref))) { @@ -418,10 +416,10 @@ void worker_free(worker *wrk) { stat_cache_free(wrk->stat_cache); - g_slice_free(worker, wrk); + g_slice_free(liWorker, wrk); } -void worker_run(worker *wrk) { +void worker_run(liWorker *wrk) { #ifdef LIGHTY_OS_LINUX /* sched_setaffinity is only available on linux */ cpu_set_t mask; @@ -446,7 +444,7 @@ void worker_run(worker *wrk) { ev_loop(wrk->loop, 0); } -void worker_stop(worker *context, worker *wrk) { +void worker_stop(liWorker *context, liWorker *wrk) { if (context == wrk) { guint i; @@ -458,8 +456,8 @@ void worker_stop(worker *context, worker *wrk) { /* close keep alive connections */ for (i = wrk->connections_active; i-- > 0;) { - connection *con = g_array_index(wrk->connections, connection*, i); - if (con->state == CON_STATE_KEEP_ALIVE) + liConnection *con = g_array_index(wrk->connections, liConnection*, i); + if (con->state == LI_CON_STATE_KEEP_ALIVE) worker_con_put(con); } @@ -476,7 +474,7 @@ void worker_stop(worker *context, worker *wrk) { } } -void worker_exit(worker *context, worker *wrk) { +void worker_exit(liWorker *context, liWorker *wrk) { if (context == wrk) { ev_unloop (wrk->loop, EVUNLOOP_ALL); } else { @@ -485,26 +483,26 @@ void worker_exit(worker *context, worker *wrk) { } -static connection* worker_con_get(worker *wrk) { - connection *con; +static liConnection* worker_con_get(liWorker *wrk) { + liConnection *con; if (wrk->connections_active >= wrk->connections->len) { con = connection_new(wrk); con->idx = wrk->connections_active; g_array_append_val(wrk->connections, con); } else { - con = g_array_index(wrk->connections, connection*, wrk->connections_active); + con = g_array_index(wrk->connections, liConnection*, wrk->connections_active); } g_atomic_int_inc((gint*) &wrk->connections_active); return con; } -void worker_con_put(connection *con) { +void worker_con_put(liConnection *con) { guint threshold; - worker *wrk = con->wrk; + liWorker *wrk = con->wrk; ev_tstamp now = CUR_TS(wrk); - if (con->state == CON_STATE_DEAD) + if (con->state == LI_CON_STATE_DEAD) /* already disconnected */ return; @@ -513,13 +511,13 @@ void worker_con_put(connection *con) { if (con->idx != wrk->connections_active) { /* Swap [con->idx] and [wrk->connections_active] */ - connection *tmp; + liConnection *tmp; assert(con->idx < wrk->connections_active); /* con must be an active connection */ - tmp = g_array_index(wrk->connections, connection*, wrk->connections_active); + tmp = g_array_index(wrk->connections, liConnection*, wrk->connections_active); tmp->idx = con->idx; con->idx = wrk->connections_active; - g_array_index(wrk->connections, connection*, con->idx) = con; - g_array_index(wrk->connections, connection*, tmp->idx) = tmp; + g_array_index(wrk->connections, liConnection*, con->idx) = con; + g_array_index(wrk->connections, liConnection*, tmp->idx) = tmp; } /* realloc wrk->connections if it makes sense (too many allocated, only every 60sec) */ @@ -530,7 +528,7 @@ void worker_con_put(connection *con) { guint i; threshold = (wrk->connections->len * 85) / 100; for (i = wrk->connections->len; i > threshold; i--) { - connection_free(g_array_index(wrk->connections, connection*, i-1)); + connection_free(g_array_index(wrk->connections, liConnection*, i-1)); } wrk->connections->len = threshold; wrk->connections_gc_ts = now;