From 282a2d1b4aa67f454ed59d7eb4d331e23b06ca38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Thu, 9 Jul 2009 22:17:24 +0200 Subject: [PATCH] Prefix LI_API functions with "li_" --- include/lighttpd/actions.h | 24 +-- include/lighttpd/angel.h | 6 +- include/lighttpd/angel_config_parser.h | 6 +- include/lighttpd/angel_connection.h | 26 +-- include/lighttpd/angel_data.h | 24 +-- include/lighttpd/angel_log.h | 18 +- include/lighttpd/angel_plugin.h | 2 +- include/lighttpd/angel_server.h | 22 +-- include/lighttpd/angel_value.h | 22 +-- include/lighttpd/chunk.h | 58 +++---- include/lighttpd/chunk_parser.h | 16 +- include/lighttpd/collect.h | 10 +- include/lighttpd/condition.h | 26 +-- include/lighttpd/config_lua.h | 2 +- include/lighttpd/connection.h | 18 +- include/lighttpd/environment.h | 20 +-- include/lighttpd/etag.h | 8 +- include/lighttpd/filter_chunked.h | 4 +- include/lighttpd/http_headers.h | 28 ++-- include/lighttpd/http_request_parser.h | 8 +- include/lighttpd/http_response_parser.h | 8 +- include/lighttpd/idlist.h | 10 +- include/lighttpd/ip_parsers.h | 6 +- include/lighttpd/lighttpd-glue.h | 10 +- include/lighttpd/log.h | 36 ++-- include/lighttpd/module.h | 20 +-- include/lighttpd/network.h | 16 +- include/lighttpd/options.h | 8 +- include/lighttpd/plugin.h | 38 ++--- include/lighttpd/radix.h | 22 +-- include/lighttpd/request.h | 14 +- include/lighttpd/response.h | 10 +- include/lighttpd/server.h | 32 ++-- include/lighttpd/stat_cache.h | 8 +- include/lighttpd/typedefs.h | 4 +- include/lighttpd/url_parser.h | 4 +- include/lighttpd/utils.h | 56 +++---- include/lighttpd/value.h | 26 +-- include/lighttpd/value_lua.h | 4 +- include/lighttpd/virtualrequest.h | 46 +++--- include/lighttpd/waitqueue.h | 20 +-- include/lighttpd/worker.h | 22 +-- src/actions.c | 58 +++---- src/actions_lua.c | 2 +- src/angel.c | 24 +-- src/angel_config_parser.rl | 42 ++--- src/angel_connection.c | 86 +++++----- src/angel_data.c | 28 ++-- src/angel_fake.c | 6 +- src/angel_log.c | 4 +- src/angel_main.c | 4 +- src/angel_plugin.c | 22 +-- src/angel_plugin_core.c | 32 ++-- src/angel_server.c | 60 +++---- src/angel_value.c | 54 +++--- src/chunk.c | 80 ++++----- src/chunk_parser.c | 24 +-- src/collect.c | 6 +- src/condition.c | 82 ++++----- src/condition_lua.c | 24 +-- src/config_lua.c | 20 +-- src/config_parser.rl | 210 ++++++++++++------------ src/connection.c | 158 +++++++++--------- src/environment.c | 22 +-- src/etag.c | 40 ++--- src/filter_chunked.c | 12 +- src/http_headers.c | 48 +++--- src/http_request_parser.rl | 44 ++--- src/http_response_parser.rl | 46 +++--- src/idlist.c | 10 +- src/ip_parsers.rl | 6 +- src/lighttpd-glue.c | 10 +- src/lighttpd.c | 20 +-- src/log.c | 30 ++-- src/module.c | 20 +-- src/modules/mod_access.c | 42 ++--- src/modules/mod_accesslog.c | 16 +- src/modules/mod_balancer.c | 20 +-- src/modules/mod_cache_disk_etag.c | 34 ++-- src/modules/mod_debug.c | 24 +-- src/modules/mod_dirlist.c | 50 +++--- src/modules/mod_expire.c | 14 +- src/modules/mod_fastcgi.c | 116 ++++++------- src/modules/mod_fortune.c | 18 +- src/modules/mod_rewrite.c | 8 +- src/modules/mod_status.c | 78 ++++----- src/modules/mod_vhost.c | 24 +-- src/network.c | 18 +- src/network_sendfile.c | 10 +- src/network_write.c | 8 +- src/network_writev.c | 10 +- src/options.c | 14 +- src/plugin.c | 96 +++++------ src/plugin_core.c | 204 +++++++++++------------ src/radix.c | 18 +- src/request.c | 44 ++--- src/response.c | 64 ++++---- src/server.c | 106 ++++++------ src/stat_cache.c | 34 ++-- src/tests.c | 20 +-- src/throttle.c | 6 +- src/url_parser.rl | 4 +- src/utils.c | 72 ++++---- src/value.c | 66 ++++---- src/value_lua.c | 34 ++-- src/virtualrequest.c | 164 +++++++++--------- src/waitqueue.c | 16 +- src/worker.c | 108 ++++++------ 108 files changed, 1831 insertions(+), 1831 deletions(-) diff --git a/include/lighttpd/actions.h b/include/lighttpd/actions.h index 328be0e..b8a52c5 100644 --- a/include/lighttpd/actions.h +++ b/include/lighttpd/actions.h @@ -72,22 +72,22 @@ struct liAction { }; /* no new/free function, so just use the struct direct (i.e. not a pointer) */ -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); +LI_API void li_action_stack_init(liActionStack *as); +LI_API void li_action_stack_reset(liVRequest *vr, liActionStack *as); +LI_API void li_action_stack_clear(liVRequest *vr, liActionStack *as); /** handle sublist now, remember current position (stack) */ -LI_API void action_enter(liVRequest *vr, liAction *a); -LI_API liHandlerResult action_execute(liVRequest *vr); +LI_API void li_action_enter(liVRequest *vr, liAction *a); +LI_API liHandlerResult li_action_execute(liVRequest *vr); -LI_API void action_release(liServer *srv, liAction *a); -LI_API void action_acquire(liAction *a); +LI_API void li_action_release(liServer *srv, liAction *a); +LI_API void li_action_acquire(liAction *a); /* create new action */ -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); +LI_API liAction *li_action_new_setting(liOptionSet setting); +LI_API liAction *li_action_new_function(liActionFuncCB func, liActionCleanupCB fcleanup, liActionFreeCB ffree, gpointer param); +LI_API liAction *li_action_new_list(); +LI_API liAction *li_action_new_condition(liCondition *cond, liAction *target, liAction *target_else); +LI_API liAction *li_action_new_balancer(liBackendSelectCB bselect, liBackendFallbackCB bfallback, liBackendFinishedCB bfinished, liBalancerFreeCB bfree, gpointer param, gboolean provide_backlog); #endif diff --git a/include/lighttpd/angel.h b/include/lighttpd/angel.h index 2c6528c..947575a 100644 --- a/include/lighttpd/angel.h +++ b/include/lighttpd/angel.h @@ -2,13 +2,13 @@ #define _LIGHTTPD_ANGEL_H_ /* interface to the angel; implementation needs to work without angel too */ -LI_API void angel_setup(liServer *srv); +LI_API void li_angel_setup(liServer *srv); /* listen to a socket */ -LI_API void angel_listen(liServer *srv, GString *str); +LI_API void li_angel_listen(liServer *srv, GString *str); /* send log messages during startup to angel, frees the string */ -LI_API void angel_log(liServer *srv, GString *str); +LI_API void li_angel_log(liServer *srv, GString *str); /* angle_fake definitions, only for internal use */ diff --git a/include/lighttpd/angel_config_parser.h b/include/lighttpd/angel_config_parser.h index 14be0ca..9b346ef 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 LI_ANGEL_CONFIG_PARSER_ERROR angel_config_parser_error_quark() -LI_API GQuark angel_config_parser_error_quark(); +#define LI_ANGEL_CONFIG_PARSER_ERROR li_angel_config_parser_error_quark() +LI_API GQuark li_angel_config_parser_error_quark(); typedef enum { LI_ANGEL_CONFIG_PARSER_ERROR_PARSE, /* parse error */ } liAngelConfigParserError; -LI_API gboolean angel_config_parse_file(liServer *srv, const gchar *filename, GError **err); +LI_API gboolean li_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 9a625f9..a9b8344 100644 --- a/include/lighttpd/angel_connection.h +++ b/include/lighttpd/angel_connection.h @@ -59,11 +59,11 @@ struct liAngelCall { }; /* error handling */ -#define LI_ANGEL_CALL_ERROR angel_call_error_quark() -LI_API GQuark angel_call_error_quark(); +#define LI_ANGEL_CALL_ERROR li_angel_call_error_quark() +LI_API GQuark li_angel_call_error_quark(); -#define LI_ANGEL_CONNECTION_ERROR angel_connection_error_quark() -LI_API GQuark angel_connection_error_quark(); +#define LI_ANGEL_CONNECTION_ERROR li_angel_connection_error_quark() +LI_API GQuark li_angel_connection_error_quark(); typedef enum { LI_ANGEL_CALL_ALREADY_RUNNING, /* the angel_call struct is already in use for a call */ @@ -77,39 +77,39 @@ typedef enum { } liAngelConnectionError; /* create connection */ -LI_API liAngelConnection* angel_connection_new( +LI_API liAngelConnection* li_angel_connection_new( struct ev_loop *loop, int fd, gpointer data, liAngelReceiveCallCB recv_call, liAngelCloseCB close_cb); -LI_API void angel_connection_free(liAngelConnection *acon); +LI_API void li_angel_connection_free(liAngelConnection *acon); -LI_API liAngelCall *angel_call_new(liAngelCallCB callback, ev_tstamp timeout); +LI_API liAngelCall *li_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(liAngelCall *call); +LI_API gboolean li_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( +LI_API gboolean li_angel_send_simple_call( liAngelConnection *acon, const gchar *mod, gsize mod_len, const gchar *action, gsize action_len, GString *data, GError **err); -LI_API gboolean angel_send_call( +LI_API gboolean li_angel_send_call( liAngelConnection *acon, const gchar *mod, gsize mod_len, const gchar *action, gsize action_len, liAngelCall *call, GString *data, GError **err); -LI_API gboolean angel_send_result( +LI_API gboolean li_angel_send_result( 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(liAngelConnection *acon); +LI_API void li_angel_cleanup_tables(liAngelConnection *acon); /* Usage */ #if 0 @@ -131,7 +131,7 @@ gboolean start_call(curctx) { return TRUE; } data = build_call_data(); - if (!angel_send_call(acon, CONST_STR_LEN("mymod"), CONST_STR_LEN("myaction"), &ctx->call, 10, data, &err)) { + if (!li_angel_send_call(acon, CONST_STR_LEN("mymod"), CONST_STR_LEN("myaction"), &ctx->call, 10, data, &err)) { unlock(); report_error(&err); return FALSE; diff --git a/include/lighttpd/angel_data.h b/include/lighttpd/angel_data.h index 0f1bfaf..84af58e 100644 --- a/include/lighttpd/angel_data.h +++ b/include/lighttpd/angel_data.h @@ -27,8 +27,8 @@ struct liAngelBuffer { }; /* error handling */ -#define LI_ANGEL_DATA_ERROR angel_data_error_quark() -LI_API GQuark angel_data_error_quark(); +#define LI_ANGEL_DATA_ERROR li_angel_data_error_quark() +LI_API GQuark li_angel_data_error_quark(); typedef enum { LI_ANGEL_DATA_ERROR_EOF, /* not enough data to read value */ @@ -37,11 +37,11 @@ typedef enum { } liAngelDataError; /* write */ -LI_API gboolean angel_data_write_int32(GString *buf, gint32 i, GError **err); -LI_API gboolean angel_data_write_int64(GString *buf, gint64 i, GError **err); -LI_API gboolean angel_data_write_char (GString *buf, gchar c, GError **err); -LI_API gboolean angel_data_write_str (GString *buf, const GString *str, GError **err); -LI_API gboolean angel_data_write_cstr (GString *buf, const gchar *str, gsize len, GError **err); +LI_API gboolean li_angel_data_write_int32(GString *buf, gint32 i, GError **err); +LI_API gboolean li_angel_data_write_int64(GString *buf, gint64 i, GError **err); +LI_API gboolean li_angel_data_write_char (GString *buf, gchar c, GError **err); +LI_API gboolean li_angel_data_write_str (GString *buf, const GString *str, GError **err); +LI_API gboolean li_angel_data_write_cstr (GString *buf, const gchar *str, gsize len, GError **err); /* read: * - if the val pointer is NULL, the data will be discarded @@ -49,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(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); +LI_API gboolean li_angel_data_read_int32(liAngelBuffer *buf, gint32 *val, GError **err); +LI_API gboolean li_angel_data_read_int64(liAngelBuffer *buf, gint64 *val, GError **err); +LI_API gboolean li_angel_data_read_char (liAngelBuffer *buf, gchar *val, GError **err); +LI_API gboolean li_angel_data_read_str (liAngelBuffer *buf, GString **val, GError **err); +LI_API gboolean li_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 a967110..ac4198b 100644 --- a/include/lighttpd/angel_log.h +++ b/include/lighttpd/angel_log.h @@ -9,34 +9,34 @@ #define LI_REMOVE_PATH_FROM_FILE 1 #if LI_REMOVE_PATH_FROM_FILE -LI_API const char *remove_path(const char *path); -#define LI_REMOVE_PATH(file) remove_path(file) +LI_API const char *li_remove_path(const char *path); +#define LI_REMOVE_PATH(file) li_remove_path(file) #else #define LI_REMOVE_PATH(file) file #endif #define SEGFAULT(srv, fmt, ...) \ do { \ - log_write_(srv, LI_LOG_LEVEL_ABORT, LI_LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \ + li_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, LI_LOG_LEVEL_ERROR, LI_LOG_FLAG_TIMESTAMP, "error (%s:%d): "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_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, LI_LOG_LEVEL_WARNING, LI_LOG_FLAG_TIMESTAMP, "warning (%s:%d): "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_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, LI_LOG_LEVEL_INFO, LI_LOG_FLAG_TIMESTAMP, "info (%s:%d): "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_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, LI_LOG_LEVEL_DEBUG, LI_LOG_FLAG_TIMESTAMP, "debug (%s:%d): "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_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, LI_LOG_LEVEL_ERROR, LI_LOG_FLAG_NONE, "lighttpd[%d]: %s", (int) inst->pid, msg) + li_log_write(srv, LI_LOG_LEVEL_ERROR, LI_LOG_FLAG_NONE, "lighttpd[%d]: %s", (int) inst->pid, msg) typedef enum { LI_LOG_LEVEL_DEBUG, @@ -76,6 +76,6 @@ struct liLog { void log_init(liServer *srv); void log_clean(liServer *srv); -LI_API void log_write(liServer *srv, liLogLevel log_level, guint flags, const gchar *fmt, ...) G_GNUC_PRINTF(4, 5); +LI_API void li_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 17ac488..385c197 100644 --- a/include/lighttpd/angel_plugin.h +++ b/include/lighttpd/angel_plugin.h @@ -77,6 +77,6 @@ void plugins_handle_item(liServer *srv, GString *itemname, liValue *hash); /* "core" is a reserved module name for interal use */ gboolean plugins_load_module(liServer *srv, const gchar *name); /* Needed by modules to register their plugin(s) */ -LI_API liPlugin *angel_plugin_register(liServer *srv, liModule *mod, const gchar *name, liPluginInitCB init); +LI_API liPlugin *li_angel_plugin_register(liServer *srv, liModule *mod, const gchar *name, liPluginInitCB init); #endif diff --git a/include/lighttpd/angel_server.h b/include/lighttpd/angel_server.h index e29153e..76d4993 100644 --- a/include/lighttpd/angel_server.h +++ b/include/lighttpd/angel_server.h @@ -60,20 +60,20 @@ struct liServer { liLog log; }; -LI_API liServer* server_new(const gchar *module_dir); -LI_API void server_free(liServer* srv); +LI_API liServer* li_server_new(const gchar *module_dir); +LI_API void li_server_free(liServer* srv); -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 liInstance* li_server_new_instance(liServer *srv, liInstanceConf *ic); +LI_API void li_instance_replace(liInstance *oldi, liInstance *newi); +LI_API void li_instance_set_state(liInstance *i, liInstanceState s); -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 liInstanceConf* li_instance_conf_new(gchar **cmd, GString *username, uid_t uid, gid_t gid); +LI_API void li_instance_conf_release(liInstanceConf *ic); +LI_API void li_instance_conf_acquire(liInstanceConf *ic); -LI_API void instance_release(liInstance *i); -LI_API void instance_acquire(liInstance *i); +LI_API void li_instance_release(liInstance *i); +LI_API void li_instance_acquire(liInstance *i); -LI_API void instance_job_append(liInstance *i); +LI_API void li_instance_job_append(liInstance *i); #endif diff --git a/include/lighttpd/angel_value.h b/include/lighttpd/angel_value.h index f9c954c..e5a9b4a 100644 --- a/include/lighttpd/angel_value.h +++ b/include/lighttpd/angel_value.h @@ -40,19 +40,19 @@ struct liValue { } data; }; -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 liValue* li_value_new_none(); +LI_API liValue* li_value_new_bool(gboolean val); +LI_API liValue* li_value_new_number(gint64 val); +LI_API liValue* li_value_new_string(GString *val); +LI_API liValue* li_value_new_range(liValueRange val); +LI_API liValue* li_value_new_list(); +LI_API liValue* li_value_new_hash(); -LI_API liValue* value_copy(liValue* val); -LI_API void value_free(liValue* val); +LI_API liValue* li_value_copy(liValue* val); +LI_API void li_value_free(liValue* val); -LI_API const char* value_type_string(liValueType type); +LI_API const char* li_value_type_string(liValueType type); -LI_API GString *value_to_string(liValue *val); +LI_API GString *li_value_to_string(liValue *val); #endif diff --git a/include/lighttpd/chunk.h b/include/lighttpd/chunk.h index 8228670..9e4e72c 100644 --- a/include/lighttpd/chunk.h +++ b/include/lighttpd/chunk.h @@ -77,7 +77,7 @@ struct liChunkIter { /* open the file cf->name if it is not already opened for reading * may return HANDLER_GO_ON, HANDLER_ERROR */ -LI_API liHandlerResult chunkfile_open(liVRequest *vr, liChunkFile *cf); +LI_API liHandlerResult li_chunkfile_open(liVRequest *vr, liChunkFile *cf); /****************** * chunk iterator * @@ -91,12 +91,12 @@ INLINE goffset chunkiter_length(liChunkIter iter); * 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 liHandlerResult chunkiter_read(liVRequest *vr, liChunkIter iter, off_t start, off_t length, char **data_start, off_t *data_len); +LI_API liHandlerResult li_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(); +/* same as li_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 liHandlerResult chunkiter_read_mmap(liVRequest *vr, liChunkIter iter, off_t start, off_t length, char **data_start, off_t *data_len); +LI_API liHandlerResult li_chunkiter_read_mmap(liVRequest *vr, liChunkIter iter, off_t start, off_t length, char **data_start, off_t *data_len); /****************** * chunk * @@ -108,66 +108,66 @@ INLINE goffset chunk_length(liChunk *c); * cqlimit * ******************/ -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); +LI_API liCQLimit* li_cqlimit_new(liVRequest *vr); +LI_API void li_cqlimit_reset(liCQLimit *cql); +LI_API void li_cqlimit_acquire(liCQLimit *cql); +LI_API void li_cqlimit_release(liCQLimit *cql); +LI_API void li_cqlimit_set_limit(liCQLimit *cql, goffset limit); /****************** * chunkqueue * ******************/ -LI_API liChunkQueue* chunkqueue_new(); -LI_API void chunkqueue_reset(liChunkQueue *cq); -LI_API void chunkqueue_free(liChunkQueue *cq); +LI_API liChunkQueue* li_chunkqueue_new(); +LI_API void li_chunkqueue_reset(liChunkQueue *cq); +LI_API void li_chunkqueue_free(liChunkQueue *cq); -LI_API void chunkqueue_use_limit(liChunkQueue *cq, liVRequest *vr); -LI_API void chunkqueue_set_limit(liChunkQueue *cq, liCQLimit* cql); +LI_API void li_chunkqueue_use_limit(liChunkQueue *cq, liVRequest *vr); +LI_API void li_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(liChunkQueue *cq); +LI_API goffset li_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(liChunkQueue *cq, GString *str); +LI_API void li_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(liChunkQueue *cq, GByteArray *mem); +LI_API void li_chunkqueue_append_bytearr(liChunkQueue *cq, GByteArray *mem); /* memory gets copied */ -LI_API void chunkqueue_append_mem(liChunkQueue *cq, const void *mem, gssize len); +LI_API void li_chunkqueue_append_mem(liChunkQueue *cq, const void *mem, gssize len); /* pass ownership of filename, do not free it */ -LI_API void chunkqueue_append_file(liChunkQueue *cq, GString *filename, off_t start, off_t length); +LI_API void li_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(liChunkQueue *cq, GString *filename, off_t start, off_t length, int fd); +LI_API void li_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(liChunkQueue *cq, GString *filename, off_t start, off_t length); +LI_API void li_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(liChunkQueue *cq, GString *filename, off_t start, off_t length, int fd); +LI_API void li_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(liChunkQueue *out, liChunkQueue *in, goffset length); +LI_API goffset li_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(liChunkQueue *out, liChunkQueue *in); +LI_API goffset li_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(liChunkQueue *out, liChunkQueue *in); +LI_API goffset li_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(liChunkQueue *cq, goffset length); +LI_API goffset li_chunkqueue_skip(liChunkQueue *cq, goffset length); /* skip all chunks in a queue (similar to reset, but keeps stats) */ -LI_API goffset chunkqueue_skip_all(liChunkQueue *cq); +LI_API goffset li_chunkqueue_skip_all(liChunkQueue *cq); /* if the chunk an iterator refers gets stolen/skipped/..., * the iterator isn't valid anymore @@ -176,8 +176,8 @@ INLINE liChunkIter chunkqueue_iter(liChunkQueue *cq); INLINE liChunk* chunkqueue_first_chunk(liChunkQueue *cq); -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); +LI_API gboolean li_chunkqueue_extract_to(liVRequest *vr, liChunkQueue *cq, goffset len, GString *dest); +LI_API gboolean li_chunkqueue_extract_to_bytearr(liVRequest *vr, liChunkQueue *cq, goffset len, GByteArray *dest); /******************** * Inline functions * diff --git a/include/lighttpd/chunk_parser.h b/include/lighttpd/chunk_parser.h index c0c2ffe..cbd29a8 100644 --- a/include/lighttpd/chunk_parser.h +++ b/include/lighttpd/chunk_parser.h @@ -25,14 +25,14 @@ struct liChunkParserMark { off_t pos; }; -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(liVRequest *vr, liChunkParserMark from, liChunkParserMark to, GString *dest); -LI_API GString* chunk_extract(liVRequest *vr, liChunkParserMark from, liChunkParserMark to); +LI_API void li_chunk_parser_init(liChunkParserCtx *ctx, liChunkQueue *cq); +LI_API void li_chunk_parser_reset(liChunkParserCtx *ctx); +LI_API liHandlerResult li_chunk_parser_prepare(liChunkParserCtx *ctx); +LI_API liHandlerResult li_chunk_parser_next(liVRequest *vr, liChunkParserCtx *ctx, char **p, char **pe); +LI_API void li_chunk_parser_done(liChunkParserCtx *ctx, goffset len); + +LI_API gboolean li_chunk_extract_to(liVRequest *vr, liChunkParserMark from, liChunkParserMark to, GString *dest); +LI_API GString* li_chunk_extract(liVRequest *vr, liChunkParserMark from, liChunkParserMark to); INLINE liChunkParserMark chunk_parser_getmark(liChunkParserCtx *ctx, const char *fpc); diff --git a/include/lighttpd/collect.h b/include/lighttpd/collect.h index 6b3af75..28fb564 100644 --- a/include/lighttpd/collect.h +++ b/include/lighttpd/collect.h @@ -20,17 +20,17 @@ typedef gpointer (*liCollectFuncCB)(liWorker *wrk, gpointer fdata); * - fdata : the data the CollectFunc got (this data must be valid until cb is called) * - result: the return values * - complete: determines if cbdata is still valid - * if this is FALSE, it may be called from another context than collect_start was called + * if this is FALSE, it may be called from another context than li_collect_start was called */ typedef void (*liCollectCB)(gpointer cbdata, gpointer fdata, GPtrArray *result, gboolean complete); 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 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 */ +/** li_collect_start returns NULL if the callback was called directly (e.g. for only one worker and ctx = wrk) */ +LI_API liCollectInfo* li_collect_start(liWorker *ctx, liCollectFuncCB func, gpointer fdata, liCollectCB cb, gpointer cbdata); +LI_API void li_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); +LI_API void li_collect_watcher_cb(struct ev_loop *loop, ev_async *w, int revents); #endif diff --git a/include/lighttpd/condition.h b/include/lighttpd/condition.h index 0f91252..604e9ad 100644 --- a/include/lighttpd/condition.h +++ b/include/lighttpd/condition.h @@ -52,7 +52,7 @@ typedef enum { LI_COMP_PHYSICAL_ISFILE, /* needs a key */ - LI_COMP_REQUEST_HEADER, /**< needs lowercase key, enforced by condition_lvalue_new */ + LI_COMP_REQUEST_HEADER, /**< needs lowercase key, enforced by li_condition_lvalue_new */ LI_COMP_UNKNOWN } liCondLValue; @@ -106,21 +106,21 @@ struct liCondition { }; /* 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 liConditionLValue* li_condition_lvalue_new(liCondLValue type, GString *key); +LI_API void li_condition_lvalue_acquire(liConditionLValue *lvalue); +LI_API void li_condition_lvalue_release(liConditionLValue *lvalue); -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 liCondition* li_condition_new_bool(liServer *srv, liConditionLValue *lvalue, gboolean b); +LI_API liCondition* li_condition_new_string(liServer *srv, liCompOperator op, liConditionLValue *lvalue, GString *str); +LI_API liCondition* li_condition_new_int(liServer *srv, liCompOperator op, liConditionLValue *lvalue, gint64 i); -LI_API void condition_acquire(liCondition *c); -LI_API void condition_release(liServer *srv, liCondition* c); +LI_API void li_condition_acquire(liCondition *c); +LI_API void li_condition_release(liServer *srv, liCondition* c); -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); +LI_API const char* li_comp_op_to_string(liCompOperator op); +LI_API const char* li_cond_lvalue_to_string(liCondLValue t); +LI_API liCondLValue li_cond_lvalue_from_string(const gchar *str, guint len); -LI_API liHandlerResult condition_check(liVRequest *vr, liCondition *cond, gboolean *result); +LI_API liHandlerResult li_condition_check(liVRequest *vr, liCondition *cond, gboolean *result); #endif diff --git a/include/lighttpd/config_lua.h b/include/lighttpd/config_lua.h index a36c281..3facf89 100644 --- a/include/lighttpd/config_lua.h +++ b/include/lighttpd/config_lua.h @@ -3,6 +3,6 @@ #include -LI_API gboolean config_lua_load(liServer *srv, const gchar *filename); +LI_API gboolean li_config_lua_load(liServer *srv, const gchar *filename); #endif diff --git a/include/lighttpd/connection.h b/include/lighttpd/connection.h index fb4e974..496e2ef 100644 --- a/include/lighttpd/connection.h +++ b/include/lighttpd/connection.h @@ -93,17 +93,17 @@ struct liConnection { } stats; }; -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 liConnection* li_connection_new(liWorker *wrk); +LI_API void li_connection_reset(liConnection *con); +LI_API void li_connection_reset_keep_alive(liConnection *con); +LI_API void li_connection_free(liConnection *con); -LI_API void connection_error(liConnection *con); -LI_API void connection_internal_error(liConnection *con); +LI_API void li_connection_error(liConnection *con); +LI_API void li_connection_internal_error(liConnection *con); -LI_API void connection_handle_direct(liConnection *con); -LI_API void connection_handle_indirect(liConnection *con, liPlugin *p); +LI_API void li_connection_handle_direct(liConnection *con); +LI_API void li_connection_handle_indirect(liConnection *con, liPlugin *p); -LI_API gchar *connection_state_str(liConnectionState state); +LI_API gchar *li_connection_state_str(liConnectionState state); #endif diff --git a/include/lighttpd/environment.h b/include/lighttpd/environment.h index cf41dc5..a0c2765 100644 --- a/include/lighttpd/environment.h +++ b/include/lighttpd/environment.h @@ -17,25 +17,25 @@ struct liEnvironmentDup { GHashTable *table; }; -LI_API void environment_init(liEnvironment *env); -LI_API void environment_reset(liEnvironment *env); -LI_API void environment_clear(liEnvironment *env); +LI_API void li_environment_init(liEnvironment *env); +LI_API void li_environment_reset(liEnvironment *env); +LI_API void li_environment_clear(liEnvironment *env); /* overwrite previous value */ -LI_API void environment_set(liEnvironment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); +LI_API void li_environment_set(liEnvironment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); /* do not overwrite */ -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); +LI_API void li_environment_insert(liEnvironment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); +LI_API void li_environment_remove(liEnvironment *env, const gchar *key, size_t keylen); +LI_API GString* li_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 liEnvironmentDup* environment_make_dup(liEnvironment *env); -LI_API void environment_dup_free(liEnvironmentDup *envdup); +LI_API liEnvironmentDup* li_environment_make_dup(liEnvironment *env); +LI_API void li_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(liEnvironmentDup *envdup, const gchar *key, size_t keylen); +LI_API GString* li_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 31ce2d4..cab4f1b 100644 --- a/include/lighttpd/etag.h +++ b/include/lighttpd/etag.h @@ -5,11 +5,11 @@ #error Please include instead of this file #endif -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); +LI_API tristate_t li_http_response_handle_cachable_etag(liVRequest *vr, GString *etag); +LI_API tristate_t li_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(liVRequest *vr, struct stat *st, gboolean *cachable); +LI_API void li_etag_mutate(GString *mut, GString *etag); +LI_API void li_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 77cd850..6fdbf13 100644 --- a/include/lighttpd/filter_chunked.h +++ b/include/lighttpd/filter_chunked.h @@ -3,7 +3,7 @@ #include -LI_API liHandlerResult filter_chunked_encode(liConnection *con, liChunkQueue *out, liChunkQueue *in); -LI_API liHandlerResult filter_chunked_decode(liConnection *con, liChunkQueue *out, liChunkQueue *in); +LI_API liHandlerResult li_filter_chunked_encode(liConnection *con, liChunkQueue *out, liChunkQueue *in); +LI_API liHandlerResult li_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 da55fdf..28fa6bf 100644 --- a/include/lighttpd/http_headers.h +++ b/include/lighttpd/http_headers.h @@ -22,30 +22,30 @@ struct liHttpHeaders { /* strings alweays get copied, so you should free key and value yourself */ -LI_API liHttpHeaders* http_headers_new(); -LI_API void http_headers_reset(liHttpHeaders* headers); -LI_API void http_headers_free(liHttpHeaders* headers); +LI_API liHttpHeaders* li_http_headers_new(); +LI_API void li_http_headers_reset(liHttpHeaders* headers); +LI_API void li_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(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); +LI_API void li_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(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); +LI_API void li_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(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 void li_http_header_overwrite(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); +LI_API gboolean li_http_header_remove(liHttpHeaders *headers, const gchar *key, size_t keylen); +LI_API void li_http_header_remove_link(liHttpHeaders *headers, GList *l); -LI_API liHttpHeader* http_header_lookup(liHttpHeaders *headers, const gchar *key, size_t keylen); +LI_API liHttpHeader* li_http_header_lookup(liHttpHeaders *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(liHttpHeaders *headers, const gchar *key, size_t keylen); +LI_API GList* li_http_header_find_first(liHttpHeaders *headers, const gchar *key, size_t keylen); +LI_API GList* li_http_header_find_next(GList *l, const gchar *key, size_t keylen); +LI_API GList* li_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(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen); +LI_API gboolean li_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, liHttpHeaders *headers, const gchar *key, size_t keylen); +LI_API void li_http_header_get_fast(GString *dest, liHttpHeaders *headers, 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 b917b2a..80ae85c 100644 --- a/include/lighttpd/http_request_parser.h +++ b/include/lighttpd/http_request_parser.h @@ -13,11 +13,11 @@ struct liHttpRequestCtx { GString *h_key, *h_value; }; -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 void li_http_request_parser_init(liHttpRequestCtx* ctx, liRequest *req, liChunkQueue *cq); +LI_API void li_http_request_parser_reset(liHttpRequestCtx* ctx); +LI_API void li_http_request_parser_clear(liHttpRequestCtx *ctx); -LI_API liHandlerResult http_request_parse(liVRequest *vr, liHttpRequestCtx *ctx); +LI_API liHandlerResult li_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 dc2dbcf..48d7d36 100644 --- a/include/lighttpd/http_response_parser.h +++ b/include/lighttpd/http_response_parser.h @@ -15,11 +15,11 @@ struct liHttpResponseCtx { GString *h_key, *h_value; }; -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 void li_http_response_parser_init(liHttpResponseCtx* ctx, liResponse *req, liChunkQueue *cq, gboolean accept_cgi, gboolean accept_nph); +LI_API void li_http_response_parser_reset(liHttpResponseCtx* ctx); +LI_API void li_http_response_parser_clear(liHttpResponseCtx *ctx); -LI_API liHandlerResult http_response_parse(liVRequest *vr, liHttpResponseCtx *ctx); +LI_API liHandlerResult li_http_response_parse(liVRequest *vr, liHttpResponseCtx *ctx); #endif diff --git a/include/lighttpd/idlist.h b/include/lighttpd/idlist.h index 25ab09c..4e25b62 100644 --- a/include/lighttpd/idlist.h +++ b/include/lighttpd/idlist.h @@ -24,18 +24,18 @@ struct liIDList { }; /* create new idlist; the parameter max_ids is "signed" on purpose */ -LI_API liIDList* idlist_new(gint max_ids); +LI_API liIDList* li_idlist_new(gint max_ids); /* free idlist */ -LI_API void idlist_free(liIDList *l); +LI_API void li_idlist_free(liIDList *l); /* request new id; return -1 if no id is available, valid ids are always > 0 */ -LI_API gint idlist_get(liIDList *l); +LI_API gint li_idlist_get(liIDList *l); /* check whether an id is in use and can be "_put" */ -LI_API gboolean idlist_is_used(liIDList *l, gint id); +LI_API gboolean li_idlist_is_used(liIDList *l, gint id); /* release id. never release an id more than once! */ -LI_API void idlist_put(liIDList *l, gint id); +LI_API void li_idlist_put(liIDList *l, gint id); #endif diff --git a/include/lighttpd/ip_parsers.h b/include/lighttpd/ip_parsers.h index d5d0434..44785d8 100644 --- a/include/lighttpd/ip_parsers.h +++ b/include/lighttpd/ip_parsers.h @@ -4,10 +4,10 @@ #include /** parse an IPv4 (if netmask is not NULL with optional cidr netmask, if port is not NULL with optional port) */ -LI_API gboolean parse_ipv4(const char *str, guint32 *ip, guint32 *netmask, guint16 *port); +LI_API gboolean li_parse_ipv4(const char *str, guint32 *ip, guint32 *netmask, guint16 *port); /** parse an IPv6 (if network is not NULL with optional cidr network, if port is not NULL with optional port if the ip/cidr part is in [...]) */ -LI_API gboolean parse_ipv6(const char *str, guint8 *ip, guint *network, guint16 *port); +LI_API gboolean li_parse_ipv6(const char *str, guint8 *ip, guint *network, guint16 *port); /** print the ip into dest, return dest */ -LI_API GString* ipv6_tostring(GString *dest, const guint8 ip[16]); +LI_API GString* li_ipv6_tostring(GString *dest, const guint8 ip[16]); #endif diff --git a/include/lighttpd/lighttpd-glue.h b/include/lighttpd/lighttpd-glue.h index 44a54ef..22ea46f 100644 --- a/include/lighttpd/lighttpd-glue.h +++ b/include/lighttpd/lighttpd-glue.h @@ -6,15 +6,15 @@ #endif /* 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); +LI_API gchar *li_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(liHttpMethod method, guint *len); +LI_API gchar *li_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(liHttpVersion method, guint *len); +LI_API gchar *li_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[]); +LI_API void li_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(liVRequest *vr, GString *filename); +LI_API GString *li_mimetype_get(liVRequest *vr, GString *filename); #endif diff --git a/include/lighttpd/log.h b/include/lighttpd/log.h index f76009f..bb7206b 100644 --- a/include/lighttpd/log.h +++ b/include/lighttpd/log.h @@ -9,35 +9,35 @@ #define REMOVE_PATH_FROM_FILE 1 #if REMOVE_PATH_FROM_FILE -LI_API const char *remove_path(const char *path); -#define REMOVE_PATH(file) remove_path(file) +LI_API const char *li_remove_path(const char *path); +#define REMOVE_PATH(file) li_remove_path(file) #else #define REMOVE_PATH(file) file #endif #define _SEGFAULT(srv, vr, fmt, ...) \ do { \ - log_write_(srv, NULL, LI_LOG_LEVEL_ABORT, LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \ + li_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, LI_LOG_LEVEL_ERROR, LOG_FLAG_TIMESTAMP, "(error) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_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, LI_LOG_LEVEL_WARNING, LOG_FLAG_TIMESTAMP, "(warning) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_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, LI_LOG_LEVEL_INFO, LOG_FLAG_TIMESTAMP, "(info) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_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, LI_LOG_LEVEL_DEBUG, LOG_FLAG_TIMESTAMP, "(debug) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_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, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, "(backend) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_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, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, txt, "(backend) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_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,7 +55,7 @@ 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__) -/* flags for log_write */ +/* flags for li_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 */ @@ -118,17 +118,17 @@ void log_thread_wakeup(liServer *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(liServer *srv, liLog *log, GString *msg); -/* log_write_ is used to write to the errorlog */ -LI_API gboolean log_write_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, const gchar *fmt, ...) G_GNUC_PRINTF(5, 6); +/* li_log_write is used to directly write a message to a log target */ +LI_API void li_log_write(liServer *srv, liLog *log, GString *msg); +/* li_log_write_ is used to write to the errorlog */ +LI_API gboolean li_log_write_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, const gchar *fmt, ...) G_GNUC_PRINTF(5, 6); -LI_API liLogTimestamp *log_timestamp_new(liServer *srv, GString *format); -LI_API gboolean log_timestamp_free(liServer *srv, liLogTimestamp *ts); +LI_API liLogTimestamp *li_log_timestamp_new(liServer *srv, GString *format); +LI_API gboolean li_log_timestamp_free(liServer *srv, liLogTimestamp *ts); /* replaces '\r' and '\n' with '\0' */ -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); +LI_API void li_log_split_lines(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, gchar *txt, const gchar *prefix); +LI_API void li_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 e09e7bc..74e24be 100644 --- a/include/lighttpd/module.h +++ b/include/lighttpd/module.h @@ -15,9 +15,9 @@ } \ } while(0) -/** see module_load */ +/** see li_module_load */ #define MODULE_DEPENDS(mods, name) do { \ - if (!module_load(mods, name)) { \ + if (!li_module_load(mods, name)) { \ ERROR(mods->main, "Couldn't load dependency '%s'", name); \ return FALSE; \ } } while(0) @@ -50,20 +50,20 @@ struct liModules { guint8 sizeof_off_t; /** holds the value of sizeof(off_t) to check if loaded module was compiled with the same flags */ }; -LI_API liModules* modules_new(gpointer main, const gchar *module_dir); -LI_API void modules_free(liModules *mods); +LI_API liModules* li_modules_new(gpointer main, const gchar *module_dir); +LI_API void li_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 liModule* module_load(liModules *mods, const gchar* name); + * You should release modules after you used them with li_module_release or li_module_release_name */ +LI_API liModule* li_module_load(liModules *mods, const gchar* name); /* find module by name */ -LI_API liModule *module_lookup(liModules *mods, const gchar *name); +LI_API liModule *li_module_lookup(liModules *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); +LI_API void li_module_acquire(liModule *mod); +LI_API void li_module_release(liModules *mods, liModule *mod); +LI_API void li_module_release_name(liModules *mods, const gchar* name); #endif diff --git a/include/lighttpd/network.h b/include/lighttpd/network.h index 23c6aab..4e7cac5 100644 --- a/include/lighttpd/network.h +++ b/include/lighttpd/network.h @@ -19,25 +19,25 @@ typedef enum { } liNetworkStatus; /** repeats write after EINTR */ -LI_API ssize_t net_write(int fd, void *buf, ssize_t nbyte); +LI_API ssize_t li_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 ssize_t li_net_read(int fd, void *buf, ssize_t nbyte); -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); +LI_API liNetworkStatus li_network_write(liVRequest *vr, int fd, liChunkQueue *cq, goffset write_max); +LI_API liNetworkStatus li_network_read(liVRequest *vr, int fd, liChunkQueue *cq); /* use writev for mem chunks, buffered read/write for files */ -LI_API liNetworkStatus network_write_writev(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max); +LI_API liNetworkStatus li_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 liNetworkStatus network_write_sendfile(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max); +LI_API liNetworkStatus li_network_write_sendfile(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max); #endif /* write backends */ -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); +LI_API liNetworkStatus li_network_backend_write(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max); +LI_API liNetworkStatus li_network_backend_writev(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max); #define LI_NETWORK_FALLBACK(f, write_max) do { \ liNetworkStatus res; \ diff --git a/include/lighttpd/options.h b/include/lighttpd/options.h index c17a343..67e3ae6 100644 --- a/include/lighttpd/options.h +++ b/include/lighttpd/options.h @@ -25,10 +25,10 @@ struct liOptionSet { }; /* Extract content from value, value set to none */ -LI_API liOptionValue value_extract(liValue *val); +LI_API liOptionValue li_value_extract(liValue *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); +LI_API gpointer li_value_extract_ptr(liValue *val); +LI_API gint64 li_value_extract_number(liValue *val); +LI_API gboolean li_value_extract_bool(liValue *val); #endif diff --git a/include/lighttpd/plugin.h b/include/lighttpd/plugin.h index f6a8ec6..b018976 100644 --- a/include/lighttpd/plugin.h +++ b/include/lighttpd/plugin.h @@ -54,13 +54,13 @@ struct liPluginOption { liValueType type; gpointer default_value; - liPluginParseOptionCB parse_option; + liPluginParseOptionCB li_parse_option; liPluginFreeOptionCB free_option; }; struct liPluginAction { const gchar *name; - liPluginCreateActionCB create_action; + liPluginCreateActionCB li_create_action; }; struct liliPluginSetupCB { @@ -72,14 +72,14 @@ struct liliPluginSetupCB { 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* + /** the value is freed with li_value_free after the parse call, so you + * probably want to extract the content via li_value_extract* * val is zero to get the global default value if nothing is specified * save result in value * * Default behaviour (NULL) is to extract the inner value from val */ - liPluginParseOptionCB parse_option; + liPluginParseOptionCB li_parse_option; /** the free_option handler has to free all allocated resources; * it may get called with 0 initialized options, so you have to @@ -87,7 +87,7 @@ struct liServerOption { */ liPluginFreeOptionCB free_option; - /** if parse_option is NULL, the default_value is used; it is only used + /** if li_parse_option is NULL, the default_value is used; it is only used * for the following value types: * - BOOLEAN, NUMBER: casted with GPOINTER_TO_INT, i.e. set it with GINT_TO_POINTER * the numbers are limited to the 32-bit range according to the glib docs @@ -101,7 +101,7 @@ struct liServerOption { struct liServerAction { liPlugin *p; - liPluginCreateActionCB create_action; + liPluginCreateActionCB li_create_action; }; struct liServerSetup { @@ -110,32 +110,32 @@ struct liServerSetup { }; /* Needed by modules to register their plugin(s) */ -LI_API liPlugin *plugin_register(liServer *srv, const gchar *name, liPluginInitCB init); +LI_API liPlugin *li_plugin_register(liServer *srv, const gchar *name, liPluginInitCB init); /* Internal needed functions */ -LI_API void plugin_free(liServer *srv, liPlugin *p); -LI_API void server_plugins_free(liServer *srv); +LI_API void li_plugin_free(liServer *srv, liPlugin *p); +LI_API void li_server_plugins_free(liServer *srv); /** free val after call (val may be modified by parser) */ -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 gboolean li_parse_option(liServer *srv, const char *name, liValue *val, liOptionSet *mark); +LI_API void li_release_option(liServer *srv, liOptionSet *mark); /**< Does not free the option_set memory */ -LI_API void plugins_prepare_callbacks(liServer *srv); -LI_API void plugins_handle_close(liConnection *con); -LI_API void plugins_handle_vrclose(liVRequest *vr); +LI_API void li_plugins_prepare_callbacks(liServer *srv); +LI_API void li_plugins_handle_close(liConnection *con); +LI_API void li_plugins_handle_vrclose(liVRequest *vr); /* Needed for config frontends */ /** For parsing 'somemod.option = "somevalue"', free value after call */ -LI_API liAction* option_action(liServer *srv, const gchar *name, liValue *val); +LI_API liAction* li_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 liAction* create_action(liServer *srv, const gchar *name, liValue *val); +LI_API liAction* li_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(liServer *srv, const char *name, liValue *val); +LI_API gboolean li_call_setup(liServer *srv, const char *name, liValue *val); /** free val after call */ -LI_API gboolean plugin_set_default_option(liServer *srv, const gchar* name, liValue *val); +LI_API gboolean li_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/radix.h b/include/lighttpd/radix.h index 03dfb94..f6bf97f 100644 --- a/include/lighttpd/radix.h +++ b/include/lighttpd/radix.h @@ -27,19 +27,19 @@ struct liRadixTree32 { }; -LI_API liRadixTree32 *radixtree32_new(guint32 root_width); -LI_API guint32 radixtree32_free(liRadixTree32 *tree); +LI_API liRadixTree32 *li_radixtree32_new(guint32 root_width); +LI_API guint32 li_radixtree32_free(liRadixTree32 *tree); -LI_API void radixtree32_insert(liRadixTree32 *tree, guint32 key, guint32 mask, gpointer data); -LI_API gboolean radixtree32_remove(liRadixTree32 *tree, guint32 key, guint32 mask); +LI_API void li_radixtree32_insert(liRadixTree32 *tree, guint32 key, guint32 mask, gpointer data); +LI_API gboolean li_radixtree32_remove(liRadixTree32 *tree, guint32 key, guint32 mask); /* lookup tree node (best match) */ -LI_API liRadixNode32 *radixtree32_lookup_node(liRadixTree32 *tree, guint32 key); +LI_API liRadixNode32 *li_radixtree32_lookup_node(liRadixTree32 *tree, guint32 key); /* lookup data pointer (best match) */ -LI_API gpointer radixtree32_lookup(liRadixTree32 *tree, guint32 key); +LI_API gpointer li_radixtree32_lookup(liRadixTree32 *tree, guint32 key); /* lookup data pointer (exact match) */ -LI_API gpointer radixtree32_lookup_exact(liRadixTree32 *tree, guint32 key); +LI_API gpointer li_radixtree32_lookup_exact(liRadixTree32 *tree, guint32 key); /* typedef struct liRadixNode128 liRadixNode128; @@ -61,10 +61,10 @@ struct liRadixTree128 { } LI_api liRadixTree128 *radixtree128_new(guint32 root_width); -LI_API guint radixtree128_free(liRadixTree128 *tree); +LI_API guint li_radixtree128_free(liRadixTree128 *tree); -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); +LI_API void li_radixtree128_insert(liRadixTree128 *tree, guint32 *key, guint32 *mask, gpointer data); +LI_API gboolean li_radixtree128_remove(liRadixTree128 *tree, guint32 *key, guint32 *mask); +LI_API gpointer li_radixtree128_lookup(liRadixTree128 *tree, guint32 *key); */ #endif diff --git a/include/lighttpd/request.h b/include/lighttpd/request.h index 0c3e4bc..69fe11f 100644 --- a/include/lighttpd/request.h +++ b/include/lighttpd/request.h @@ -43,14 +43,14 @@ struct liRequest { goffset content_length; }; -LI_API void request_init(liRequest *req); -LI_API void request_reset(liRequest *req); -LI_API void request_clear(liRequest *req); +LI_API void li_request_init(liRequest *req); +LI_API void li_request_reset(liRequest *req); +LI_API void li_request_clear(liRequest *req); -LI_API gboolean request_validate_header(liConnection *con); +LI_API gboolean li_request_validate_header(liConnection *con); -LI_API void physical_init(liPhysical *phys); -LI_API void physical_reset(liPhysical *phys); -LI_API void physical_clear(liPhysical *phys); +LI_API void li_physical_init(liPhysical *phys); +LI_API void li_physical_reset(liPhysical *phys); +LI_API void li_physical_clear(liPhysical *phys); #endif diff --git a/include/lighttpd/response.h b/include/lighttpd/response.h index 8d7a81f..fa1890c 100644 --- a/include/lighttpd/response.h +++ b/include/lighttpd/response.h @@ -11,11 +11,11 @@ struct liResponse { liTransferEncoding transfer_encoding; }; -LI_API void response_init(liResponse *resp); -LI_API void response_reset(liResponse *resp); -LI_API void response_clear(liResponse *resp); +LI_API void li_response_init(liResponse *resp); +LI_API void li_response_reset(liResponse *resp); +LI_API void li_response_clear(liResponse *resp); -LI_API void response_send_headers(liConnection *con); -LI_API void response_send_error_page(liConnection *con); +LI_API void li_response_send_headers(liConnection *con); +LI_API void li_response_send_error_page(liConnection *con); #endif diff --git a/include/lighttpd/server.h b/include/lighttpd/server.h index 6f13098..d849ec6 100644 --- a/include/lighttpd/server.h +++ b/include/lighttpd/server.h @@ -27,7 +27,7 @@ struct liServer { liWorker *main_worker; guint worker_count; GArray *workers; - GArray *ts_formats; /** array of (GString*), add with server_ts_format_add() */ + GArray *ts_formats; /** array of (GString*), add with li_server_ts_format_add() */ struct ev_loop *loop; guint loop_flags; @@ -50,8 +50,8 @@ struct liServer { GHashTable *actions; /**< const gchar* => (server_action*) */ GHashTable *setups; /**< const gchar* => (server_setup*) */ - GArray *plugins_handle_close; /** list of handle_close callbacks */ - GArray *plugins_handle_vrclose; /** list of handle_vrclose callbacks */ + GArray *li_plugins_handle_close; /** list of handle_close callbacks */ + GArray *li_plugins_handle_vrclose; /** list of handle_vrclose callbacks */ GArray *option_def_values;/** array of option_value */ liAction *mainaction; @@ -84,27 +84,27 @@ struct liServer { }; -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 liServer* li_server_new(const gchar *module_dir); +LI_API void li_server_free(liServer* srv); +LI_API gboolean li_server_loop_init(liServer *srv); +LI_API gboolean li_server_worker_init(liServer *srv); -LI_API void server_listen(liServer *srv, int fd); +LI_API void li_server_listen(liServer *srv, int fd); /* Start accepting connection, use log files, no new plugins after that */ -LI_API void server_start(liServer *srv); +LI_API void li_server_start(liServer *srv); /* stop accepting connections, turn keep-alive off, close all shutdown sockets, set exiting = TRUE */ -LI_API void server_stop(liServer *srv); +LI_API void li_server_stop(liServer *srv); /* exit asap with cleanup */ -LI_API void server_exit(liServer *srv); +LI_API void li_server_exit(liServer *srv); -LI_API GString *server_current_timestamp(); +LI_API GString *li_server_current_timestamp(); -LI_API void server_out_of_fds(liServer *srv); +LI_API void li_server_out_of_fds(liServer *srv); -LI_API guint server_ts_format_add(liServer *srv, GString* format); +LI_API guint li_server_ts_format_add(liServer *srv, GString* format); -LI_API void server_socket_release(liServerSocket* sock); -LI_API void server_socket_acquire(liServerSocket* sock); +LI_API void li_server_socket_release(liServerSocket* sock); +LI_API void li_server_socket_acquire(liServerSocket* sock); #endif diff --git a/include/lighttpd/stat_cache.h b/include/lighttpd/stat_cache.h index 8c58ccd..337a999 100644 --- a/include/lighttpd/stat_cache.h +++ b/include/lighttpd/stat_cache.h @@ -91,16 +91,16 @@ void stat_cache_free(liStatCache *sc); 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 liHandlerResult stat_cache_get(liVRequest *vr, GString *path, struct stat *st, int *err, int *fd); +LI_API liHandlerResult li_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 liHandlerResult stat_cache_get_dirlist(liVRequest *vr, GString *path, liStatCacheEntry **result); +LI_API liHandlerResult li_stat_cache_get_dirlist(liVRequest *vr, GString *path, liStatCacheEntry **result); -LI_API void stat_cache_entry_acquire(liVRequest *vr, liStatCacheEntry *sce); +LI_API void li_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(liVRequest *vr, liStatCacheEntry *sce); +LI_API void li_stat_cache_entry_release(liVRequest *vr, liStatCacheEntry *sce); #endif \ No newline at end of file diff --git a/include/lighttpd/typedefs.h b/include/lighttpd/typedefs.h index 9478c38..95f3871 100644 --- a/include/lighttpd/typedefs.h +++ b/include/lighttpd/typedefs.h @@ -79,11 +79,11 @@ typedef struct liHttpHeader liHttpHeader; typedef struct liHttpHeaders liHttpHeaders; -/* http_request_parser.h */ +/* li_http_request_parser.h */ typedef struct liHttpRequestCtx liHttpRequestCtx; -/* http_response_parser.h */ +/* li_http_response_parser.h */ typedef struct liHttpResponseCtx liHttpResponseCtx; diff --git a/include/lighttpd/url_parser.h b/include/lighttpd/url_parser.h index 48043dc..667c0c5 100644 --- a/include/lighttpd/url_parser.h +++ b/include/lighttpd/url_parser.h @@ -3,7 +3,7 @@ #include -LI_API gboolean parse_raw_url(liRequestUri *uri); -LI_API gboolean parse_hostname(liRequestUri *uri); +LI_API gboolean li_parse_raw_url(liRequestUri *uri); +LI_API gboolean li_parse_hostname(liRequestUri *uri); #endif diff --git a/include/lighttpd/utils.h b/include/lighttpd/utils.h index a7074a1..2a3ae9b 100644 --- a/include/lighttpd/utils.h +++ b/include/lighttpd/utils.h @@ -11,60 +11,60 @@ typedef enum { -LI_API void fatal(const gchar* msg); +LI_API void li_fatal(const gchar* msg); /* set O_NONBLOCK and FD_CLOEXEC */ -LI_API void fd_init(int fd); -LI_API void fd_no_block(int fd); -LI_API void fd_block(int fd); +LI_API void li_fd_init(int fd); +LI_API void li_fd_no_block(int fd); +LI_API void li_fd_block(int fd); #ifndef _WIN32 /* return -2 for EAGAIN, -1 for some other error, 0 for success */ -LI_API int send_fd(int s, int fd); /* write fd to unix socket s */ -LI_API int receive_fd(int s, int *fd); /* read fd from unix socket s */ +LI_API int li_send_fd(int s, int fd); /* write fd to unix socket s */ +LI_API int li_receive_fd(int s, int *fd); /* read fd from unix socket s */ #endif -LI_API void ev_io_add_events(struct ev_loop *loop, ev_io *watcher, int events); -LI_API void ev_io_rem_events(struct ev_loop *loop, ev_io *watcher, int events); -LI_API void ev_io_set_events(struct ev_loop *loop, ev_io *watcher, int events); +LI_API void li_ev_io_add_events(struct ev_loop *loop, ev_io *watcher, int events); +LI_API void li_ev_io_rem_events(struct ev_loop *loop, ev_io *watcher, int events); +LI_API void li_ev_io_set_events(struct ev_loop *loop, ev_io *watcher, int events); /* URL inplace decode: replace %XX with character \xXX; replace control characters with '_' (< 32 || == 127) */ -LI_API void url_decode(GString *path); +LI_API void li_url_decode(GString *path); -LI_API void path_simplify(GString *path); +LI_API void li_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, liCounterType t, GString *dest); +LI_API GString *li_counter_format(guint64 count, liCounterType t, GString *dest); -LI_API gchar *ev_backend_string(guint backend); +LI_API gchar *li_ev_backend_string(guint backend); -LI_API void string_destroy_notify(gpointer str); +LI_API void li_string_destroy_notify(gpointer str); /* expects a pointer to a 32bit value */ -LI_API guint hash_ipv4(gconstpointer key); +LI_API guint li_hash_ipv4(gconstpointer key); /* expects a pointer to a 128bit value */ -LI_API guint hash_ipv6(gconstpointer key); +LI_API guint li_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(liSocketAddress addr, GString *dest, gboolean showport); +LI_API GString *li_sockaddr_to_string(liSocketAddress addr, GString *dest, gboolean showport); -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 liSocketAddress li_sockaddr_from_string(GString *str, guint tcp_default_port); +LI_API liSocketAddress li_sockaddr_local_from_socket(gint fd); +LI_API liSocketAddress li_sockaddr_remote_from_socket(gint fd); +LI_API void li_sockaddr_clear(liSocketAddress *saddr); -LI_API void gstring_replace_char_with_str_len(GString *gstr, gchar c, gchar *str, guint len); +LI_API void li_gstring_replace_char_with_str_len(GString *gstr, gchar c, gchar *str, guint len); -LI_API gboolean l_g_strncase_equal(GString *str, const gchar *s, guint len); +LI_API gboolean li_strncase_equal(GString *str, const gchar *s, guint len); -LI_API GString *l_g_string_assign_len(GString *string, const gchar *val, gssize len); +LI_API GString *li_string_assign_len(GString *string, const gchar *val, gssize len); -LI_API gboolean l_g_string_prefix(GString *str, const gchar *s, gsize len); -LI_API gboolean l_g_string_suffix(GString *str, const gchar *s, gsize len); +LI_API gboolean li_string_prefix(GString *str, const gchar *s, gsize len); +LI_API gboolean li_string_suffix(GString *str, const gchar *s, gsize len); -LI_API void l_g_string_append_int(GString *dest, gint64 val); +LI_API void li_string_append_int(GString *dest, gint64 val); -LI_API gsize dirent_buf_size(DIR * dirp); +LI_API gsize li_dirent_buf_size(DIR * dirp); #endif diff --git a/include/lighttpd/value.h b/include/lighttpd/value.h index 226b839..b8954bc 100644 --- a/include/lighttpd/value.h +++ b/include/lighttpd/value.h @@ -26,22 +26,22 @@ struct liValue { } data; }; -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 liValue* li_value_new_none(); +LI_API liValue* li_value_new_bool(gboolean val); +LI_API liValue* li_value_new_number(gint64 val); +LI_API liValue* li_value_new_string(GString *val); +LI_API liValue* li_value_new_list(); +LI_API liValue* li_value_new_hash(); +LI_API liValue* li_value_new_action(liServer *srv, liAction *a); +LI_API liValue* li_value_new_condition(liServer *srv, liCondition *c); -LI_API liValue* value_copy(liValue* val); -LI_API void value_free(liValue* val); +LI_API liValue* li_value_copy(liValue* val); +LI_API void li_value_free(liValue* val); -LI_API const char* value_type_string(liValueType type); +LI_API const char* li_value_type_string(liValueType type); -LI_API GString *value_to_string(liValue *val); +LI_API GString *li_value_to_string(liValue *val); -LI_API void value_list_free(GArray *vallist); +LI_API void li_value_list_free(GArray *vallist); #endif diff --git a/include/lighttpd/value_lua.h b/include/lighttpd/value_lua.h index 90c3d32..5a31530 100644 --- a/include/lighttpd/value_lua.h +++ b/include/lighttpd/value_lua.h @@ -8,8 +8,8 @@ * and pops the value * returns NULL if it couldn't convert the value (still pops it) */ -LI_API liValue* value_from_lua(liServer *srv, lua_State *L); +LI_API liValue* li_value_from_lua(liServer *srv, lua_State *L); -LI_API GString* lua_togstring(lua_State *L, int ndx); +LI_API GString* li_lua_togstring(lua_State *L, int ndx); #endif diff --git a/include/lighttpd/virtualrequest.h b/include/lighttpd/virtualrequest.h index 32f5cb7..0bd350e 100644 --- a/include/lighttpd/virtualrequest.h +++ b/include/lighttpd/virtualrequest.h @@ -104,44 +104,44 @@ struct liVRequest { } \ } while (0) -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 liVRequest* li_vrequest_new(liConnection *con, liVRequestHandlerCB handle_response_headers, liVRequestHandlerCB handle_response_body, liVRequestHandlerCB handle_response_error, liVRequestHandlerCB handle_request_headers); +LI_API void li_vrequest_free(liVRequest *vr); +LI_API void li_vrequest_reset(liVRequest *vr); -LI_API liVRequestRef* vrequest_acquire_ref(liVRequest *vr); -LI_API liVRequest* vrequest_release_ref(liVRequestRef *vr_ref); +LI_API liVRequestRef* li_vrequest_acquire_ref(liVRequest *vr); +LI_API liVRequest* li_vrequest_release_ref(liVRequestRef *vr_ref); -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); +LI_API void li_vrequest_add_filter_in(liVRequest *vr, liFilterHandlerCB handle_data, liFilterFreeCB handle_free, gpointer param); +LI_API void li_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(liVRequest *vr); +LI_API void li_vrequest_error(liVRequest *vr); -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); +LI_API void li_vrequest_backend_overloaded(liVRequest *vr); +LI_API void li_vrequest_backend_dead(liVRequest *vr); +LI_API void li_vrequest_backend_error(liVRequest *vr, liBackendError berror); /* received all request headers */ -LI_API void vrequest_handle_request_headers(liVRequest *vr); +LI_API void li_vrequest_handle_request_headers(liVRequest *vr); /* received (partial) request content */ -LI_API void vrequest_handle_request_body(liVRequest *vr); +LI_API void li_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(liVRequest *vr); +LI_API void li_vrequest_handle_response_headers(liVRequest *vr); /* received (partial) response content - call from your indirect handler */ -LI_API void vrequest_handle_response_body(liVRequest *vr); +LI_API void li_vrequest_handle_response_body(liVRequest *vr); /* response completely ready */ -LI_API gboolean vrequest_handle_direct(liVRequest *vr); +LI_API gboolean li_vrequest_handle_direct(liVRequest *vr); /* handle request over time */ -LI_API gboolean vrequest_handle_indirect(liVRequest *vr, liPlugin *p); -LI_API gboolean vrequest_is_handled(liVRequest *vr); +LI_API gboolean li_vrequest_handle_indirect(liVRequest *vr, liPlugin *p); +LI_API gboolean li_vrequest_is_handled(liVRequest *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 void li_vrequest_state_machine(liVRequest *vr); +LI_API void li_vrequest_joblist_append(liVRequest *vr); +LI_API void li_vrequest_joblist_append_async(liVRequest *vr); -LI_API gboolean vrequest_stat(liVRequest *vr); +LI_API gboolean li_vrequest_stat(liVRequest *vr); -LI_API gboolean vrequest_redirect(liVRequest *vr, GString *uri); +LI_API gboolean li_vrequest_redirect(liVRequest *vr, GString *uri); #endif diff --git a/include/lighttpd/waitqueue.h b/include/lighttpd/waitqueue.h index 499b6b6..3ec8dcb 100644 --- a/include/lighttpd/waitqueue.h +++ b/include/lighttpd/waitqueue.h @@ -26,31 +26,31 @@ struct liWaitQueue { /* * waitqueues are queues used to implement delays for certain tasks in a lightweight, non-blocking way * they are used for io timeouts or throttling for example - * waitqueue_push, waitqueue_pop and waitqueue_remove have O(1) complexity + * li_waitqueue_push, li_waitqueue_pop and li_waitqueue_remove have O(1) complexity */ /* initializes a waitqueue by creating and starting the ev_timer. precision is sub-seconds */ -LI_API void waitqueue_init(liWaitQueue *queue, struct ev_loop *loop, liWaitQueueCB callback, gdouble delay, gpointer data); +LI_API void li_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(liWaitQueue *queue); +/* stops the waitqueue. to restart it, simply call li_waitqueue_update */ +LI_API void li_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(liWaitQueue *queue); +LI_API void li_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(liWaitQueue *queue, liWaitQueueElem *elem); +LI_API void li_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 liWaitQueueElem *waitqueue_pop(liWaitQueue *queue); +LI_API liWaitQueueElem *li_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(liWaitQueue *queue, liWaitQueueElem **head); +LI_API guint li_waitqueue_pop_ready(liWaitQueue *queue, liWaitQueueElem **head); /* removes an element from the queue */ -LI_API void waitqueue_remove(liWaitQueue *queue, liWaitQueueElem *elem); +LI_API void li_waitqueue_remove(liWaitQueue *queue, liWaitQueueElem *elem); /* returns the length of the queue */ -LI_API guint waitqueue_length(liWaitQueue *queue); +LI_API guint li_waitqueue_length(liWaitQueue *queue); #endif diff --git a/include/lighttpd/worker.h b/include/lighttpd/worker.h index d86aded..a313fdd 100644 --- a/include/lighttpd/worker.h +++ b/include/lighttpd/worker.h @@ -54,7 +54,7 @@ struct liWorker { struct ev_loop *loop; ev_prepare loop_prepare; ev_check loop_check; - ev_async worker_stop_watcher, worker_exit_watcher; + ev_async li_worker_stop_watcher, li_worker_exit_watcher; guint connections_active; /** 0..con_act-1: active connections, con_act..used-1: free connections * use with atomic, read direct from local worker context @@ -77,7 +77,7 @@ struct liWorker { guint connection_load; /** incremented by server_accept_cb, decremented by worker_con_put. use atomic access */ - GArray *timestamps; /** array of (worker_ts), use only from local worker context and through worker_current_timestamp(wrk, ndx) */ + GArray *timestamps; /** array of (worker_ts), use only from local worker context and through li_worker_current_timestamp(wrk, ndx) */ /* incoming queues */ /* - new connections (after accept) */ @@ -100,20 +100,20 @@ struct liWorker { liStatCache *stat_cache; }; -LI_API liWorker* worker_new(liServer *srv, struct ev_loop *loop); -LI_API void worker_free(liWorker *wrk); +LI_API liWorker* li_worker_new(liServer *srv, struct ev_loop *loop); +LI_API void li_worker_free(liWorker *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 li_worker_run(liWorker *wrk); +LI_API void li_worker_stop(liWorker *context, liWorker *wrk); +LI_API void li_worker_exit(liWorker *context, liWorker *wrk); -LI_API void worker_new_con(liWorker *ctx, liWorker *wrk, liSocketAddress remote_addr, int s, liServerSocket *srv_sock); +LI_API void li_worker_new_con(liWorker *ctx, liWorker *wrk, liSocketAddress remote_addr, int s, liServerSocket *srv_sock); -LI_API void worker_check_keepalive(liWorker *wrk); +LI_API void li_worker_check_keepalive(liWorker *wrk); -LI_API GString* worker_current_timestamp(liWorker *wrk, guint format_ndx); +LI_API GString* li_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(liWorker *wrk, int fd); +LI_API void li_worker_add_closing_socket(liWorker *wrk, int fd); #endif diff --git a/src/actions.c b/src/actions.c index 8485a49..6431416 100644 --- a/src/actions.c +++ b/src/actions.c @@ -12,14 +12,14 @@ struct action_stack_element { gboolean finished, backlog_provided; }; -void action_release(liServer *srv, liAction *a) { +void li_action_release(liServer *srv, liAction *a) { guint i; if (!a) return; assert(g_atomic_int_get(&a->refcount) > 0); if (g_atomic_int_dec_and_test(&a->refcount)) { switch (a->type) { case ACTION_TSETTING: - release_option(srv, &a->data.setting); + li_release_option(srv, &a->data.setting); break; case ACTION_TFUNCTION: if (a->data.function.free) { @@ -27,13 +27,13 @@ void action_release(liServer *srv, liAction *a) { } break; case ACTION_TCONDITION: - condition_release(srv, a->data.condition.cond); - action_release(srv, a->data.condition.target); - action_release(srv, a->data.condition.target_else); + li_condition_release(srv, a->data.condition.cond); + li_action_release(srv, a->data.condition.target); + li_action_release(srv, a->data.condition.target_else); break; case ACTION_TLIST: for (i = a->data.list->len; i-- > 0; ) { - action_release(srv, g_array_index(a->data.list, liAction*, i)); + li_action_release(srv, g_array_index(a->data.list, liAction*, i)); } g_array_free(a->data.list, TRUE); break; @@ -47,12 +47,12 @@ void action_release(liServer *srv, liAction *a) { } } -void action_acquire(liAction *a) { +void li_action_acquire(liAction *a) { assert(g_atomic_int_get(&a->refcount) > 0); g_atomic_int_inc(&a->refcount); } -liAction *action_new_setting(liOptionSet setting) { +liAction *li_action_new_setting(liOptionSet setting) { liAction *a = g_slice_new(liAction); a->refcount = 1; @@ -62,7 +62,7 @@ liAction *action_new_setting(liOptionSet setting) { return a; } -liAction *action_new_function(liActionFuncCB func, liActionCleanupCB fcleanup, liActionFreeCB ffree, gpointer param) { +liAction *li_action_new_function(liActionFuncCB func, liActionCleanupCB fcleanup, liActionFreeCB ffree, gpointer param) { liAction *a; a = g_slice_new(liAction); @@ -76,7 +76,7 @@ liAction *action_new_function(liActionFuncCB func, liActionCleanupCB fcleanup, l return a; } -liAction *action_new_list() { +liAction *li_action_new_list() { liAction *a; a = g_slice_new(liAction); @@ -87,7 +87,7 @@ liAction *action_new_list() { return a; } -liAction *action_new_condition(liCondition *cond, liAction *target, liAction *target_else) { +liAction *li_action_new_condition(liCondition *cond, liAction *target, liAction *target_else) { liAction *a; a = g_slice_new(liAction); @@ -100,7 +100,7 @@ liAction *action_new_condition(liCondition *cond, liAction *target, liAction *ta return a; } -liAction *action_new_balancer(liBackendSelectCB bselect, liBackendFallbackCB bfallback, liBackendFinishedCB bfinished, liBalancerFreeCB bfree, gpointer param, gboolean provide_backlog) { +liAction *li_action_new_balancer(liBackendSelectCB bselect, liBackendFallbackCB bfallback, liBackendFinishedCB bfinished, liBalancerFreeCB bfree, gpointer param, gboolean provide_backlog) { liAction *a; a = g_slice_new(liAction); @@ -147,18 +147,18 @@ static void action_stack_element_release(liServer *srv, liVRequest *vr, action_s break; } - action_release(srv, ase->act); + li_action_release(srv, ase->act); ase->act = NULL; ase->data.context = NULL; } -void action_stack_init(liActionStack *as) { +void li_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(liActionRegexStackElement), 15); g_array_set_size(as->regex_stack, 0); } -void action_stack_reset(liVRequest *vr, liActionStack *as) { +void li_action_stack_reset(liVRequest *vr, liActionStack *as) { liServer *srv = vr->wrk->srv; guint i; for (i = as->stack->len; i-- > 0; ) { @@ -168,7 +168,7 @@ void action_stack_reset(liVRequest *vr, liActionStack *as) { as->backend_failed = FALSE; } -void action_stack_clear(liVRequest *vr, liActionStack *as) { +void li_action_stack_clear(liVRequest *vr, liActionStack *as) { liServer *srv = vr->wrk->srv; guint i; for (i = as->stack->len; i-- > 0; ) { @@ -184,12 +184,12 @@ static action_stack_element *action_stack_top(liActionStack* as) { } /** handle sublist now, remember current position (stack) */ -void action_enter(liVRequest *vr, liAction *a) { +void li_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) }; - action_acquire(a); + li_action_acquire(a); g_array_append_val(as->stack, ase); } @@ -198,7 +198,7 @@ static void action_stack_pop(liServer *srv, liVRequest *vr, liActionStack *as) { g_array_set_size(as->stack, as->stack->len - 1); } -liHandlerResult action_execute(liVRequest *vr) { +liHandlerResult li_action_execute(liVRequest *vr) { liAction *a; liActionStack *as = &vr->action_stack; action_stack_element *ase; @@ -218,7 +218,7 @@ liHandlerResult action_execute(liVRequest *vr) { ase = action_stack_top(as); } if (!ase) { /* no backlogging balancer found */ - if (vrequest_handle_direct(vr)) + if (li_vrequest_handle_direct(vr)) vr->response.http_status = 503; return LI_HANDLER_GO_ON; } @@ -232,7 +232,7 @@ liHandlerResult action_execute(liVRequest *vr) { ase->finished = TRUE; break; case LI_HANDLER_ERROR: - action_stack_reset(vr, as); + li_action_stack_reset(vr, as); case LI_HANDLER_COMEBACK: case LI_HANDLER_WAIT_FOR_EVENT: return res; @@ -266,7 +266,7 @@ liHandlerResult action_execute(liVRequest *vr) { ase->finished = TRUE; break; case LI_HANDLER_ERROR: - action_stack_reset(vr, as); + li_action_stack_reset(vr, as); case LI_HANDLER_COMEBACK: case LI_HANDLER_WAIT_FOR_EVENT: return res; @@ -274,19 +274,19 @@ liHandlerResult action_execute(liVRequest *vr) { break; case ACTION_TCONDITION: condres = FALSE; - res = condition_check(vr, a->data.condition.cond, &condres); + res = li_condition_check(vr, a->data.condition.cond, &condres); switch (res) { case LI_HANDLER_GO_ON: ase->finished = TRUE; if (condres) { - if (a->data.condition.target) action_enter(vr, a->data.condition.target); + if (a->data.condition.target) li_action_enter(vr, a->data.condition.target); } else if (a->data.condition.target_else) { - action_enter(vr, a->data.condition.target_else); + li_action_enter(vr, a->data.condition.target_else); } break; case LI_HANDLER_ERROR: - action_stack_reset(vr, as); + li_action_stack_reset(vr, as); case LI_HANDLER_COMEBACK: case LI_HANDLER_WAIT_FOR_EVENT: return res; @@ -296,7 +296,7 @@ liHandlerResult action_execute(liVRequest *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, liAction*, ase->data.pos)); + li_action_enter(vr, g_array_index(a->data.list, liAction*, ase->data.pos)); ase->data.pos++; } break; @@ -307,7 +307,7 @@ liHandlerResult action_execute(liVRequest *vr) { ase->finished = TRUE; break; case LI_HANDLER_ERROR: - action_stack_reset(vr, as); + li_action_stack_reset(vr, as); case LI_HANDLER_COMEBACK: case LI_HANDLER_WAIT_FOR_EVENT: return res; @@ -316,7 +316,7 @@ liHandlerResult action_execute(liVRequest *vr) { } } if (as->backend_failed) { - if (vrequest_handle_direct(vr)) + if (li_vrequest_handle_direct(vr)) vr->response.http_status = 503; } return LI_HANDLER_GO_ON; diff --git a/src/actions_lua.c b/src/actions_lua.c index 7667eb1..b3e4169 100644 --- a/src/actions_lua.c +++ b/src/actions_lua.c @@ -24,7 +24,7 @@ static int lua_action_gc(lua_State *L) { if (!a || !*a) return 0; srv = (liServer*) lua_touserdata(L, lua_upvalueindex(1)); - action_release(srv, *a); + li_action_release(srv, *a); return 0; } diff --git a/src/angel.c b/src/angel.c index 04b4a93..558979f 100644 --- a/src/angel.c +++ b/src/angel.c @@ -7,26 +7,26 @@ static void angel_call_cb(liAngelConnection *acon, gint32 id, GString *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); + if (-1 != id) li_angel_send_result(acon, id, g_string_new_len(CONST_STR_LEN("not implemented yet")), NULL, NULL, NULL); } 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)); + ERROR(srv, "li_fatal: angel connection close: %s", err ? err->message : g_strerror(errno)); if (err) g_error_free(err); exit(1); } -void angel_setup(liServer *srv) { - srv->acon = angel_connection_new(srv->loop, 0, srv, angel_call_cb, angel_close_cb); +void li_angel_setup(liServer *srv) { + srv->acon = li_angel_connection_new(srv->loop, 0, srv, angel_call_cb, angel_close_cb); } -static void angel_listen_cb(liAngelCall *acall, gpointer ctx, gboolean timeout, GString *error, GString *data, GArray *fds) { +static void li_angel_listen_cb(liAngelCall *acall, gpointer ctx, gboolean timeout, GString *error, GString *data, GArray *fds) { liServer *srv = ctx; guint i; UNUSED(data); - angel_call_free(acall); + li_angel_call_free(acall); ERROR(srv, "%s", "listen_cb"); @@ -44,7 +44,7 @@ static void angel_listen_cb(liAngelCall *acall, gpointer ctx, gboolean timeout, if (fds && fds->len > 0) { for (i = 0; i < fds->len; i++) { INFO(srv, "listening on fd %i", g_array_index(fds, int, i)); - server_listen(srv, g_array_index(fds, int, i)); + li_server_listen(srv, g_array_index(fds, int, i)); } g_array_set_size(fds, 0); } else { @@ -53,13 +53,13 @@ static void angel_listen_cb(liAngelCall *acall, gpointer ctx, gboolean timeout, } /* listen to a socket */ -void angel_listen(liServer *srv, GString *str) { +void li_angel_listen(liServer *srv, GString *str) { if (srv->acon) { - liAngelCall *acall = angel_call_new(angel_listen_cb, 3.0); + liAngelCall *acall = li_angel_call_new(li_angel_listen_cb, 3.0); GError *err = NULL; acall->context = srv; - if (!angel_send_call(srv->acon, CONST_STR_LEN("core"), CONST_STR_LEN("listen"), acall, g_string_new_len(GSTR_LEN(str)), &err)) { + if (!li_angel_send_call(srv->acon, CONST_STR_LEN("core"), CONST_STR_LEN("listen"), acall, g_string_new_len(GSTR_LEN(str)), &err)) { ERROR(srv, "couldn't send call: %s", err->message); g_error_free(err); } @@ -69,12 +69,12 @@ void angel_listen(liServer *srv, GString *str) { ERROR(srv, "listen('%s') failed", str->str); /* TODO: exit? */ } else { - server_listen(srv, fd); + li_server_listen(srv, fd); } } } /* send log messages while startup to angel */ -void angel_log(liServer *srv, GString *str) { +void li_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 53ea66d..7bff8c5 100644 --- a/src/angel_config_parser.rl +++ b/src/angel_config_parser.rl @@ -37,7 +37,7 @@ typedef struct { int line, column; } filecontext; -GQuark angel_config_parser_error_quark() { +GQuark li_angel_config_parser_error_quark() { return g_quark_from_static_string("angel-config-parser-error-quark"); } @@ -98,14 +98,14 @@ static gchar *format_char(pcontext *ctx, gchar c) { action startitem { ctx->itemname = ctx->token; ctx->token = g_string_sized_new(0); - ctx->itemvalue = value_new_hash(); + ctx->itemvalue = li_value_new_hash(); } action enditem { plugins_handle_item(srv, ctx->itemname, ctx->itemvalue); g_string_free(ctx->itemname, TRUE); ctx->itemname = NULL; - value_free(ctx->itemvalue); + li_value_free(ctx->itemvalue); ctx->itemvalue = NULL; } @@ -199,22 +199,22 @@ static gchar *format_char(pcontext *ctx, gchar c) { action value_true { - ctx->curvalue = value_new_bool(TRUE); + ctx->curvalue = li_value_new_bool(TRUE); } action value_false { - ctx->curvalue = value_new_bool(FALSE); + ctx->curvalue = li_value_new_bool(FALSE); } action value_number { - ctx->curvalue = value_new_number(ctx->number); + ctx->curvalue = li_value_new_number(ctx->number); } action value_range { liValueRange vr = { ctx->number2, ctx->number }; - ctx->curvalue = value_new_range(vr); + ctx->curvalue = li_value_new_range(vr); if (ctx->number2 > ctx->number) { - GString *tmp = value_to_string(ctx->curvalue); + GString *tmp = li_value_to_string(ctx->curvalue); UPDATE_COLUMN(); PARSE_ERROR_FMT("range broken: %s (from > to)", tmp->str); g_string_free(tmp, TRUE); @@ -223,12 +223,12 @@ static gchar *format_char(pcontext *ctx, gchar c) { } action value_string { - ctx->curvalue = value_new_string(ctx->token); + ctx->curvalue = li_value_new_string(ctx->token); ctx->token = g_string_sized_new(0); } action value_list_start { - g_ptr_array_add(ctx->valuestack, value_new_list()); + g_ptr_array_add(ctx->valuestack, li_value_new_list()); ctx->curvalue = NULL; fcall value_list_sub; } @@ -245,7 +245,7 @@ static gchar *format_char(pcontext *ctx, gchar c) { } action value_hash_start { - g_ptr_array_add(ctx->valuestack, value_new_hash()); + g_ptr_array_add(ctx->valuestack, li_value_new_hash()); ctx->curvalue = NULL; fcall value_hash_sub; } @@ -261,13 +261,13 @@ static gchar *format_char(pcontext *ctx, gchar c) { if (NULL != g_hash_table_lookup(vhash->data.hash, vname->data.string)) { UPDATE_COLUMN(); PARSE_ERROR_FMT("duplicate key '%s' in item '%s'", vname->data.string->str, ctx->itemname->str); - value_free(vname); + li_value_free(vname); ctx->cs = angel_config_parser_error; fbreak; } g_hash_table_insert(vhash->data.hash, vname->data.string, ctx->curvalue); ctx->curvalue = NULL; vname->type = LI_VALUE_NONE; - value_free(vname); + li_value_free(vname); } action value_hash_end { guint ndx = ctx->valuestack->len - 1; @@ -277,7 +277,7 @@ static gchar *format_char(pcontext *ctx, gchar c) { } action option_start { - g_ptr_array_add(ctx->valuestack, value_new_string(ctx->token)); + g_ptr_array_add(ctx->valuestack, li_value_new_string(ctx->token)); ctx->token = g_string_sized_new(0); ctx->curvalue= NULL; } @@ -285,17 +285,17 @@ static gchar *format_char(pcontext *ctx, gchar c) { guint ndx = ctx->valuestack->len-1; 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 (!ctx->curvalue) ctx->curvalue = li_value_new_none(); if (NULL != g_hash_table_lookup(ctx->itemvalue->data.hash, vname->data.string)) { UPDATE_COLUMN(); PARSE_ERROR_FMT("duplicate key '%s' in item '%s'", vname->data.string->str, ctx->itemname->str); - value_free(vname); + li_value_free(vname); ctx->cs = angel_config_parser_error; fbreak; } g_hash_table_insert(ctx->itemvalue->data.hash, vname->data.string, ctx->curvalue); ctx->curvalue = NULL; vname->type = LI_VALUE_NONE; - value_free(vname); + li_value_free(vname); } line_sane = ( '\n' ) @newline; @@ -403,12 +403,12 @@ static void angel_config_parser_free(pcontext *ctx) { g_array_free(ctx->g_stack, TRUE); g_string_free(ctx->token, TRUE); for (guint i = 0; i < ctx->valuestack->len; i++) { - value_free(g_ptr_array_index(ctx->valuestack, i)); + li_value_free(g_ptr_array_index(ctx->valuestack, i)); } g_ptr_array_free(ctx->valuestack, TRUE); if (ctx->itemname) g_string_free(ctx->itemname, TRUE); - value_free(ctx->itemvalue); - value_free(ctx->curvalue); + li_value_free(ctx->itemvalue); + li_value_free(ctx->curvalue); g_slice_free(pcontext, ctx); } @@ -442,7 +442,7 @@ static gboolean angel_config_parse_data(liServer *srv, pcontext *ctx, filecontex return TRUE; } -gboolean angel_config_parse_file(liServer *srv, const gchar *filename, GError **err) { +gboolean li_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 e2300b0..ce35985 100644 --- a/src/angel_connection.c +++ b/src/angel_connection.c @@ -84,10 +84,10 @@ static void send_queue_clean(GQueue *queue) { } } -GQuark angel_call_error_quark() { +GQuark li_angel_call_error_quark() { return g_quark_from_static_string("angel-call-error-quark"); } -GQuark angel_connection_error_quark() { +GQuark li_angel_connection_error_quark() { return g_quark_from_static_string("angel-connection-error-quark"); } @@ -187,14 +187,14 @@ static gboolean angel_dispatch(liAngelConnection *acon, GError **err) { case ANGEL_CALL_SEND_RESULT: g_printerr("received result: %i\n", id); g_mutex_lock(acon->mutex); - if (!idlist_is_used(acon->call_id_list, id)) { + if (!li_idlist_is_used(acon->call_id_list, id)) { g_mutex_unlock(acon->mutex); 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); + li_idlist_put(acon->call_id_list, id); if (type == ANGEL_CALL_SEND_RESULT && (guint) id < acon->call_table->len) { call = (liAngelCall*) g_ptr_array_index(acon->call_table, id); g_ptr_array_index(acon->call_table, id) = NULL; @@ -230,14 +230,14 @@ static gboolean angel_connection_read(liAngelConnection *acon, GError **err) { if (!angel_fill_buffer(acon, 8*4, err)) return FALSE; if (acon->in.data->len - acon->in.pos < 8*4) return TRUE; /* need more data */ - if (!angel_data_read_int32(&acon->in, &magic, err)) return FALSE; - if (!angel_data_read_int32(&acon->in, &acon->parse.type, err)) return FALSE; - if (!angel_data_read_int32(&acon->in, &acon->parse.id, err)) return FALSE; - if (!angel_data_read_int32(&acon->in, &acon->parse.mod_len, err)) return FALSE; - if (!angel_data_read_int32(&acon->in, &acon->parse.action_len, err)) return FALSE; - if (!angel_data_read_int32(&acon->in, &acon->parse.error_len, err)) return FALSE; - if (!angel_data_read_int32(&acon->in, &acon->parse.data_len, err)) return FALSE; - if (!angel_data_read_int32(&acon->in, &acon->parse.missing_fds, err)) return FALSE; + if (!li_angel_data_read_int32(&acon->in, &magic, err)) return FALSE; + if (!li_angel_data_read_int32(&acon->in, &acon->parse.type, err)) return FALSE; + if (!li_angel_data_read_int32(&acon->in, &acon->parse.id, err)) return FALSE; + if (!li_angel_data_read_int32(&acon->in, &acon->parse.mod_len, err)) return FALSE; + if (!li_angel_data_read_int32(&acon->in, &acon->parse.action_len, err)) return FALSE; + if (!li_angel_data_read_int32(&acon->in, &acon->parse.error_len, err)) return FALSE; + if (!li_angel_data_read_int32(&acon->in, &acon->parse.data_len, err)) return FALSE; + if (!li_angel_data_read_int32(&acon->in, &acon->parse.missing_fds, err)) return FALSE; if (ANGEL_MAGIC != magic) { g_set_error(err, LI_ANGEL_CONNECTION_ERROR, LI_ANGEL_CONNECTION_INVALID_DATA, @@ -253,7 +253,7 @@ static gboolean angel_connection_read(liAngelConnection *acon, GError **err) { if (acon->in.data->len - acon->in.pos < acon->parse.body_size) return TRUE; /* need more data */ while (acon->parse.missing_fds > 0) { int fd = -1; - switch (receive_fd(acon->fd, &fd)) { + switch (li_receive_fd(acon->fd, &fd)) { case 0: g_array_append_val(acon->parse.fds, fd); acon->parse.missing_fds--; @@ -269,10 +269,10 @@ static gboolean angel_connection_read(liAngelConnection *acon, GError **err) { } acon->parse.have_header = FALSE; - if (!angel_data_read_mem(&acon->in, &acon->parse.mod, acon->parse.mod_len, err)) return FALSE; - if (!angel_data_read_mem(&acon->in, &acon->parse.action, acon->parse.action_len, err)) return FALSE; - if (!angel_data_read_mem(&acon->in, &acon->parse.error, acon->parse.error_len, err)) return FALSE; - if (!angel_data_read_mem(&acon->in, &acon->parse.data, acon->parse.data_len, err)) return FALSE; + if (!li_angel_data_read_mem(&acon->in, &acon->parse.mod, acon->parse.mod_len, err)) return FALSE; + if (!li_angel_data_read_mem(&acon->in, &acon->parse.action, acon->parse.action_len, err)) return FALSE; + if (!li_angel_data_read_mem(&acon->in, &acon->parse.error, acon->parse.error_len, err)) return FALSE; + if (!li_angel_data_read_mem(&acon->in, &acon->parse.data, acon->parse.data_len, err)) return FALSE; if (!angel_dispatch(acon, err)) return FALSE; @@ -331,7 +331,7 @@ static void angel_connection_io_cb(struct ev_loop *loop, ev_io *w, int revents) case ANGEL_CONNECTION_ITEM_FDS: while (send_item->value.fds.pos < send_item->value.fds.fds->len) { - switch (send_fd(w->fd, g_array_index(send_item->value.fds.fds, int, send_item->value.fds.pos))) { + switch (li_send_fd(w->fd, g_array_index(send_item->value.fds.fds, int, send_item->value.fds.pos))) { case 0: send_item->value.fds.pos++; continue; @@ -360,7 +360,7 @@ write_eagain: out_queue_empty = (0 == acon->out->length); g_mutex_unlock(acon->mutex); - if (out_queue_empty) ev_io_rem_events(loop, w, EV_WRITE); + if (out_queue_empty) li_ev_io_rem_events(loop, w, EV_WRITE); } if (revents | EV_READ) { @@ -376,11 +376,11 @@ write_eagain: static void angel_connection_out_notify_cb(struct ev_loop *loop, ev_async *w, int revents) { liAngelConnection *acon = (liAngelConnection*) w->data; UNUSED(revents); - ev_io_add_events(loop, &acon->fd_watcher, EV_WRITE); + li_ev_io_add_events(loop, &acon->fd_watcher, EV_WRITE); } /* create connection */ -liAngelConnection* angel_connection_new(struct ev_loop *loop, int fd, gpointer data, +liAngelConnection* li_angel_connection_new(struct ev_loop *loop, int fd, gpointer data, liAngelReceiveCallCB recv_call, liAngelCloseCB close_cb) { liAngelConnection *acon = g_slice_new0(liAngelConnection); @@ -388,7 +388,7 @@ liAngelConnection* angel_connection_new(struct ev_loop *loop, int fd, gpointer d acon->mutex = g_mutex_new(); acon->loop = loop; acon->fd = fd; - acon->call_id_list = idlist_new(65535); + acon->call_id_list = li_idlist_new(65535); acon->call_table = g_ptr_array_new(); ev_io_init(&acon->fd_watcher, angel_connection_io_cb, fd, EV_READ); ev_io_start(acon->loop, &acon->fd_watcher); @@ -412,11 +412,11 @@ liAngelConnection* angel_connection_new(struct ev_loop *loop, int fd, gpointer d return acon; } -void angel_connection_free(liAngelConnection *acon) { +void li_angel_connection_free(liAngelConnection *acon) { angel_connection_send_item_t *send_item; guint i; - g_printerr("angel_connection_free\n"); + g_printerr("li_angel_connection_free\n"); if (!acon) return; @@ -445,7 +445,7 @@ void angel_connection_free(liAngelConnection *acon) { ev_io_stop(acon->loop, &acon->fd_watcher); ev_async_stop(acon->loop, &acon->out_notify_watcher); - idlist_free(acon->call_id_list); + li_idlist_free(acon->call_id_list); while (NULL != (send_item = g_queue_pop_head(acon->out))) { send_queue_item_free(send_item); } @@ -474,7 +474,7 @@ static void angel_call_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents if (cb) cb(call, ctx, TRUE, NULL, NULL, NULL); } -liAngelCall *angel_call_new(liAngelCallCB callback, ev_tstamp timeout) { +liAngelCall *li_angel_call_new(liAngelCallCB callback, ev_tstamp timeout) { liAngelCall* call = g_slice_new0(liAngelCall); g_assert(NULL != callback); @@ -487,7 +487,7 @@ liAngelCall *angel_call_new(liAngelCallCB callback, ev_tstamp timeout) { } /* returns TRUE if a call was cancelled */ -gboolean angel_call_free(liAngelCall *call) { +gboolean li_angel_call_free(liAngelCall *call) { gboolean r = FALSE; if (call->acon) { @@ -517,19 +517,19 @@ static gboolean prepare_call_header(GString **pbuf, g_printerr("Prepare call with id: %i\n", id); - if (!angel_data_write_int32(buf, ANGEL_MAGIC, err)) return FALSE; - if (!angel_data_write_int32(buf, type, err)) return FALSE; - if (!angel_data_write_int32(buf, id, err)) return FALSE; + if (!li_angel_data_write_int32(buf, ANGEL_MAGIC, err)) return FALSE; + if (!li_angel_data_write_int32(buf, type, err)) return FALSE; + if (!li_angel_data_write_int32(buf, id, err)) return FALSE; if (type != ANGEL_CALL_SEND_RESULT) { - if (!angel_data_write_int32(buf, mod_len, err)) return FALSE; - if (!angel_data_write_int32(buf, action_len, err)) return FALSE; + if (!li_angel_data_write_int32(buf, mod_len, err)) return FALSE; + if (!li_angel_data_write_int32(buf, action_len, err)) return FALSE; } else { - if (!angel_data_write_int32(buf, 0, err)) return FALSE; - if (!angel_data_write_int32(buf, 0, err)) return FALSE; + if (!li_angel_data_write_int32(buf, 0, err)) return FALSE; + if (!li_angel_data_write_int32(buf, 0, err)) return FALSE; } - if (!angel_data_write_int32(buf, error_len, err)) return FALSE; - if (!angel_data_write_int32(buf, data_len, err)) return FALSE; - if (!angel_data_write_int32(buf, fd_count, err)) return FALSE; + if (!li_angel_data_write_int32(buf, error_len, err)) return FALSE; + if (!li_angel_data_write_int32(buf, data_len, err)) return FALSE; + if (!li_angel_data_write_int32(buf, fd_count, err)) return FALSE; if (type != ANGEL_CALL_SEND_RESULT) { g_string_append_len(buf, mod, mod_len); @@ -539,7 +539,7 @@ static gboolean prepare_call_header(GString **pbuf, return TRUE; } -gboolean angel_send_simple_call( +gboolean li_angel_send_simple_call( liAngelConnection *acon, const gchar *mod, gsize mod_len, const gchar *action, gsize action_len, GString *data, @@ -578,7 +578,7 @@ error: return FALSE; } -gboolean angel_send_call( +gboolean li_angel_send_call( liAngelConnection *acon, const gchar *mod, gsize mod_len, const gchar *action, gsize action_len, liAngelCall *call, @@ -601,7 +601,7 @@ gboolean angel_send_call( goto error_before_new_id; } - if (-1 == (call->id = idlist_get(acon->call_id_list))) { + if (-1 == (call->id = li_idlist_get(acon->call_id_list))) { g_mutex_unlock(acon->mutex); g_set_error(err, LI_ANGEL_CALL_ERROR, LI_ANGEL_CALL_OUT_OF_CALL_IDS, "out of call ids"); goto error; @@ -636,7 +636,7 @@ gboolean angel_send_call( error: if (-1 != call->id) { - idlist_put(acon->call_id_list, call->id); + li_idlist_put(acon->call_id_list, call->id); call->id = -1; call->acon = NULL; } @@ -646,7 +646,7 @@ error_before_new_id: return FALSE; } -gboolean angel_send_result( +gboolean li_angel_send_result( liAngelConnection *acon, gint32 id, GString *error, GString *data, GArray *fds, @@ -692,7 +692,7 @@ error: } /* free temporary needed memroy; call this once in while after some activity */ -void angel_cleanup_tables(liAngelConnection *acon) { +void li_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 fe9ad7d..81d2621 100644 --- a/src/angel_data.c +++ b/src/angel_data.c @@ -3,7 +3,7 @@ #include /* error handling */ -GQuark angel_data_error_quark() { +GQuark li_angel_data_error_quark() { return g_quark_from_static_string("angel-data-error-quark"); } @@ -17,25 +17,25 @@ static gboolean error_eof(GError **err, const gchar *info) { /* write */ -gboolean angel_data_write_int32(GString *buf, gint32 i, GError **err) { +gboolean li_angel_data_write_int32(GString *buf, gint32 i, GError **err) { g_return_val_if_fail(err == NULL || *err == NULL, FALSE); g_string_append_len(buf, (const gchar*) &i, sizeof(i)); return TRUE; } -gboolean angel_data_write_int64(GString *buf, gint64 i, GError **err) { +gboolean li_angel_data_write_int64(GString *buf, gint64 i, GError **err) { g_return_val_if_fail(err == NULL || *err == NULL, FALSE); g_string_append_len(buf, (const gchar*) &i, sizeof(i)); return TRUE; } -gboolean angel_data_write_char (GString *buf, gchar c, GError **err) { +gboolean li_angel_data_write_char (GString *buf, gchar c, GError **err) { g_return_val_if_fail(err == NULL || *err == NULL, FALSE); g_string_append_len(buf, &c, sizeof(c)); return TRUE; } -gboolean angel_data_write_str (GString *buf, const GString *str, GError **err) { +gboolean li_angel_data_write_str (GString *buf, const GString *str, GError **err) { g_return_val_if_fail(err == NULL || *err == NULL, FALSE); if (str->len > LI_ANGEL_DATA_MAX_STR_LEN) { g_set_error(err, @@ -44,19 +44,19 @@ gboolean angel_data_write_str (GString *buf, const GString *str, GError **err) "String too long (len: %" G_GSIZE_FORMAT "): '%s'", str->len, str->str); return FALSE; } - if (!angel_data_write_int32(buf, str->len, err)) return FALSE; + if (!li_angel_data_write_int32(buf, str->len, err)) return FALSE; g_string_append_len(buf, GSTR_LEN(str)); return TRUE; } -gboolean angel_data_write_cstr (GString *buf, const gchar *str, gsize len, GError **err) { +gboolean li_angel_data_write_cstr (GString *buf, const gchar *str, gsize len, GError **err) { const GString tmps = { (gchar*) str, len, 0 }; /* fake const GString */ - return angel_data_write_str(buf, &tmps, err); + return li_angel_data_write_str(buf, &tmps, err); } /* read */ -gboolean angel_data_read_int32(liAngelBuffer *buf, gint32 *val, GError **err) { +gboolean li_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(liAngelBuffer *buf, gint32 *val, GError **err) { return TRUE; } -gboolean angel_data_read_int64(liAngelBuffer *buf, gint64 *val, GError **err) { +gboolean li_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(liAngelBuffer *buf, gint64 *val, GError **err) { return TRUE; } -gboolean angel_data_read_char (liAngelBuffer *buf, gchar *val, GError **err) { +gboolean li_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 (liAngelBuffer *buf, gchar *val, GError **err) { return TRUE; } -gboolean angel_data_read_mem (liAngelBuffer *buf, GString **val, gsize len, GError **err) { +gboolean li_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 (liAngelBuffer *buf, GString **val, gsize len, GEr return TRUE; } -gboolean angel_data_read_str (liAngelBuffer *buf, GString **val, GError **err) { +gboolean li_angel_data_read_str (liAngelBuffer *buf, GString **val, GError **err) { gint32 ilen; g_return_val_if_fail(err == NULL || *err == NULL, FALSE); @@ -127,7 +127,7 @@ gboolean angel_data_read_str (liAngelBuffer *buf, GString **val, GError **err) "String length in buffer invalid: %i", (gint) ilen); return FALSE; } - if (!angel_data_read_mem(buf, val, (gsize) ilen, err)) { + if (!li_angel_data_read_mem(buf, val, (gsize) ilen, err)) { buf->pos -= sizeof(gint32); return FALSE; } diff --git a/src/angel_fake.c b/src/angel_fake.c index a318815..c3a9706 100644 --- a/src/angel_fake.c +++ b/src/angel_fake.c @@ -11,7 +11,7 @@ int angel_fake_listen(liServer *srv, GString *str) { #endif guint16 port = 80; - if (parse_ipv4(str->str, &ipv4, NULL, &port)) { + if (li_parse_ipv4(str->str, &ipv4, NULL, &port)) { int s, v; struct sockaddr_in addr; memset(&addr, 0, sizeof(addr)); @@ -41,11 +41,11 @@ int angel_fake_listen(liServer *srv, GString *str) { DEBUG(srv, "listen to ipv4: '%s' port: %d", inet_ntoa(*(struct in_addr*)&ipv4), port); return s; #ifdef HAVE_IPV6 - } else if (parse_ipv6(str->str, ipv6, NULL, &port)) { + } else if (li_parse_ipv6(str->str, ipv6, NULL, &port)) { GString *ipv6_str = g_string_sized_new(0); int s, v; struct sockaddr_in6 addr; - ipv6_tostring(ipv6_str, ipv6); + li_ipv6_tostring(ipv6_str, ipv6); memset(&addr, 0, sizeof(addr)); addr.sin6_family = AF_INET6; diff --git a/src/angel_log.c b/src/angel_log.c index bfb24de..79f5c0d 100644 --- a/src/angel_log.c +++ b/src/angel_log.c @@ -2,7 +2,7 @@ #include #if LI_REMOVE_PATH_FROM_FILE -const char *remove_path(const char *path) { +const char *li_remove_path(const char *path) { char *p = strrchr(path, DIR_SEPERATOR); if (NULL != p && *(p) != '\0') { return (p + 1); @@ -31,7 +31,7 @@ void log_clean(liServer *srv) { g_string_free(srv->log.log_line, TRUE); } -void log_write(liServer *srv, liLogLevel log_level, guint flags, const gchar *fmt, ...) { +void li_log_write(liServer *srv, liLogLevel log_level, guint flags, const gchar *fmt, ...) { va_list ap; GString *log_line = srv->log.log_line; diff --git a/src/angel_main.c b/src/angel_main.c index 6e4d760..4f7a926 100644 --- a/src/angel_main.c +++ b/src/angel_main.c @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) { /* initialize threading */ g_thread_init(NULL); - srv = server_new(module_dir); + srv = li_server_new(module_dir); if (!plugins_config_load(srv, config_path)) { result = -1; @@ -84,7 +84,7 @@ int main(int argc, char *argv[]) { INFO(srv, "%s", "going down"); cleanup: - if (srv) server_free(srv); + if (srv) li_server_free(srv); if (config_path) g_free((gchar*) config_path); if (module_dir != def_module_dir) g_free((gchar*) module_dir); diff --git a/src/angel_plugin.c b/src/angel_plugin.c index 7b22a86..532c8b7 100644 --- a/src/angel_plugin.c +++ b/src/angel_plugin.c @@ -36,7 +36,7 @@ static server_item* server_item_new(liPlugin *p, const liPluginItem *p_item) { return si; } -static void plugin_free(liServer *srv, liPlugin *p) { +static void li_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(liPlugin, p); @@ -58,10 +58,10 @@ static void _server_module_release(gpointer d) { for (i = sm->plugins->len; i-- > 0; ) { liPlugin *p = g_ptr_array_index(sm->plugins, i); - plugin_free(sm->srv, p); + li_plugin_free(sm->srv, p); } g_ptr_array_free(sm->plugins, TRUE); - if (sm->mod) module_release(sm->srv->plugins.modules, sm->mod); + if (sm->mod) li_module_release(sm->srv->plugins.modules, sm->mod); g_free(sm->name); g_slice_free(server_module, sm); } @@ -83,7 +83,7 @@ static server_module* server_module_new(liServer *srv, const gchar *name) { /* m void plugins_init(liServer *srv, const gchar *module_dir) { liPlugins *ps = &srv->plugins; - ps->modules = modules_new(srv, module_dir); + ps->modules = li_modules_new(srv, module_dir); ps->items = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, _server_item_free); ps->load_items = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, _server_item_free); @@ -117,7 +117,7 @@ void plugins_clear(liServer *srv) { if (ps->config_filename) g_string_free(ps->config_filename, TRUE); - modules_free(ps->modules); + li_modules_free(ps->modules); } void plugins_config_clean(liServer *srv) { @@ -146,7 +146,7 @@ gboolean plugins_config_load(liServer *srv, const gchar *filename) { return FALSE; } - if (!angel_config_parse_file(srv, filename, &error)) { + if (!li_angel_config_parse_file(srv, filename, &error)) { ERROR(srv, "failed to parse config file: %s", error->message); g_error_free(error); plugins_config_clean(srv); @@ -208,7 +208,7 @@ void plugins_handle_item(liServer *srv, GString *itemname, liValue *hash) { #if 1 /* debug items */ { - GString *tmp = value_to_string(hash); + GString *tmp = li_value_to_string(hash); ERROR(srv, "Item '%s': %s", itemname->str, tmp->str); g_string_free(tmp, TRUE); } @@ -250,7 +250,7 @@ void plugins_handle_item(liServer *srv, GString *itemname, liValue *hash) { 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)); + pi->name, itemname->str, li_value_type_string(optlist[i]->type), li_value_type_string(pi->type)); valid = FALSE; } } @@ -328,7 +328,7 @@ gboolean plugins_load_module(liServer *srv, const gchar *name) { sm = server_module_new(srv, modname); g_hash_table_insert(ps->load_module_refs, sm->name, sm); if (name) { - mod = module_load(ps->modules, name); + mod = li_module_load(ps->modules, name); if (!mod) { _server_module_release(sm); @@ -351,7 +351,7 @@ gboolean plugins_load_module(liServer *srv, const gchar *name) { return TRUE; } -liPlugin *angel_plugin_register(liServer *srv, liModule *mod, const gchar *name, liPluginInitCB init) { +liPlugin *li_angel_plugin_register(liServer *srv, liModule *mod, const gchar *name, liPluginInitCB init) { liPlugins *ps = &srv->plugins; server_module *sm; liPlugin *p; @@ -366,7 +366,7 @@ liPlugin *angel_plugin_register(liServer *srv, liModule *mod, const gchar *name, p = plugin_new(name); if (!init(srv, p)) { ERROR(srv, "Couldn't load plugin '%s' for module '%s': init failed", name, mod->name->str); - plugin_free(srv, p); + li_plugin_free(srv, p); return NULL; } diff --git a/src/angel_plugin_core.c b/src/angel_plugin_core.c index a317f46..4b3624c 100644 --- a/src/angel_plugin_core.c +++ b/src/angel_plugin_core.c @@ -86,7 +86,7 @@ static void core_instance_parse(liServer *srv, liPlugin *p, liValue **options) { g_ptr_array_add(cmd, NULL); cmdarr = (gchar**) g_ptr_array_free(cmd, FALSE); - config->load_instconf = instance_conf_new(cmdarr, user, uid, gid); + config->load_instconf = li_instance_conf_new(cmdarr, user, uid, gid); } static const liPluginItemOption core_instance_options[] = { @@ -111,7 +111,7 @@ static int do_listen(liServer *srv, GString *str) { #endif guint16 port = 80; - if (parse_ipv4(str->str, &ipv4, NULL, &port)) { + if (li_parse_ipv4(str->str, &ipv4, NULL, &port)) { int s, v; struct sockaddr_in addr; memset(&addr, 0, sizeof(addr)); @@ -141,11 +141,11 @@ static int do_listen(liServer *srv, GString *str) { DEBUG(srv, "listen to ipv4: '%s' port: %d", str->str, port); return s; #ifdef HAVE_IPV6 - } else if (parse_ipv6(str->str, ipv6, NULL, &port)) { + } else if (li_parse_ipv6(str->str, ipv6, NULL, &port)) { GString *ipv6_str = g_string_sized_new(0); int s, v; struct sockaddr_in6 addr; - ipv6_tostring(ipv6_str, ipv6); + li_ipv6_tostring(ipv6_str, ipv6); memset(&addr, 0, sizeof(addr)); addr.sin6_family = AF_INET6; @@ -204,7 +204,7 @@ static void core_listen(liServer *srv, liInstance *i, liPlugin *p, gint32 id, GS if (-1 == fd) { GString *error = g_string_sized_new(0); g_string_printf(error, "Couldn't listen to '%s'", data->str); - if (!angel_send_result(i->acon, id, error, NULL, NULL, &err)) { + if (!li_angel_send_result(i->acon, id, error, NULL, NULL, &err)) { ERROR(srv, "Couldn't send result: %s", err->message); g_error_free(err); } @@ -214,7 +214,7 @@ static void core_listen(liServer *srv, liInstance *i, liPlugin *p, gint32 id, GS fds = g_array_new(FALSE, FALSE, sizeof(int)); g_array_append_val(fds, fd); - if (!angel_send_result(i->acon, id, NULL, NULL, fds, &err)) { + if (!li_angel_send_result(i->acon, id, NULL, NULL, fds, &err)) { ERROR(srv, "Couldn't send result: %s", err->message); g_error_free(err); return; @@ -228,13 +228,13 @@ static void core_free(liServer *srv, liPlugin *p) { core_clean(srv, p); if (config->instconf) { - instance_conf_release(config->instconf); + li_instance_conf_release(config->instconf); config->instconf = NULL; } if (config->inst) { - instance_set_state(config->inst, LI_INSTANCE_DOWN); - instance_release(config->inst); + li_instance_set_state(config->inst, LI_INSTANCE_DOWN); + li_instance_release(config->inst); config->inst = NULL; } } @@ -244,7 +244,7 @@ static void core_clean(liServer *srv, liPlugin *p) { UNUSED(srv); if (config->load_instconf) { - instance_conf_release(config->load_instconf); + li_instance_conf_release(config->load_instconf); config->load_instconf = NULL; } @@ -261,13 +261,13 @@ static void core_activate(liServer *srv, liPlugin *p) { liPluginCoreConfig *config = (liPluginCoreConfig*) p->data; if (config->instconf) { - instance_conf_release(config->instconf); + li_instance_conf_release(config->instconf); config->instconf = NULL; } if (config->inst) { - instance_set_state(config->inst, LI_INSTANCE_DOWN); - instance_release(config->inst); + li_instance_set_state(config->inst, LI_INSTANCE_DOWN); + li_instance_release(config->inst); config->inst = NULL; } @@ -275,8 +275,8 @@ static void core_activate(liServer *srv, liPlugin *p) { config->load_instconf = NULL; if (config->instconf) { - config->inst = server_new_instance(srv, config->instconf); - instance_set_state(config->inst, LI_INSTANCE_ACTIVE); + config->inst = li_server_new_instance(srv, config->instconf); + li_instance_set_state(config->inst, LI_INSTANCE_ACTIVE); ERROR(srv, "%s", "Starting instance"); } } @@ -298,5 +298,5 @@ static gboolean core_init(liServer *srv, liPlugin *p) { gboolean plugin_core_init(liServer *srv) { /* load core plugins */ - return NULL != angel_plugin_register(srv, NULL, "core", core_init); + return NULL != li_angel_plugin_register(srv, NULL, "core", core_init); } diff --git a/src/angel_server.c b/src/angel_server.c index bfef507..96925f2 100644 --- a/src/angel_server.c +++ b/src/angel_server.c @@ -18,11 +18,11 @@ static void jobqueue_callback(struct ev_loop *loop, ev_async *w, int revents) { while (NULL != (i = g_queue_pop_head(&todo))) { i->in_jobqueue = FALSE; instance_state_machine(i); - instance_release(i); + li_instance_release(i); } } -liServer* server_new(const gchar *module_dir) { +liServer* li_server_new(const gchar *module_dir) { liServer *srv = g_slice_new0(liServer); srv->loop = ev_default_loop(0); @@ -38,7 +38,7 @@ liServer* server_new(const gchar *module_dir) { return srv; } -void server_free(liServer* srv) { +void li_server_free(liServer* srv) { plugins_clear(srv); log_clean(srv); @@ -61,7 +61,7 @@ static void instance_angel_call_cb(liAngelConnection *acon, GString *errstr = g_string_sized_new(0); GError *err = NULL; g_string_printf(errstr, "Plugin '%s' not available in lighttpd-angel", mod); - if (!angel_send_result(acon, id, errstr, NULL, NULL, &err)) { + if (!li_angel_send_result(acon, id, errstr, NULL, NULL, &err)) { ERROR(srv, "Couldn't send result: %s", err->message); g_error_free(err); } @@ -73,7 +73,7 @@ static void instance_angel_call_cb(liAngelConnection *acon, GString *errstr = g_string_sized_new(0); GError *err = NULL; g_string_printf(errstr, "Action '%s' not available in plugin '%s' of lighttpd-angel", action, mod); - if (!angel_send_result(acon, id, errstr, NULL, NULL, &err)) { + if (!li_angel_send_result(acon, id, errstr, NULL, NULL, &err)) { ERROR(srv, "Couldn't send result: %s", err->message); g_error_free(err); } @@ -91,7 +91,7 @@ static void instance_angel_close_cb(liAngelConnection *acon, GError *err) { if (err) g_error_free(err); i->acon = NULL; - angel_connection_free(acon); + li_angel_connection_free(acon); } static void instance_child_cb(struct ev_loop *loop, ev_child *w, int revents) { @@ -105,11 +105,11 @@ static void instance_child_cb(struct ev_loop *loop, ev_child *w, int revents) { i->s_cur = LI_INSTANCE_DOWN; } i->pid = -1; - angel_connection_free(i->acon); + li_angel_connection_free(i->acon); i->acon = NULL; ev_child_stop(loop, w); - instance_job_append(i); - instance_release(i); + li_instance_job_append(i); + li_instance_release(i); } static void instance_spawn(liInstance *i) { @@ -118,10 +118,10 @@ static void instance_spawn(liInstance *i) { ERROR(i->srv, "socketpair error, cannot spawn instance: %s", g_strerror(errno)); return; } - fd_init(confd[0]); - fd_no_block(confd[1]); + li_fd_init(confd[0]); + li_fd_no_block(confd[1]); - i->acon = angel_connection_new(i->srv->loop, confd[0], i, instance_angel_call_cb, instance_angel_close_cb); + i->acon = li_angel_connection_new(i->srv->loop, confd[0], i, instance_angel_call_cb, instance_angel_close_cb); i->pid = fork(); switch (i->pid) { case 0: { @@ -150,19 +150,19 @@ static void instance_spawn(liInstance *i) { ev_child_set(&i->child_watcher, i->pid, 0); ev_child_start(i->srv->loop, &i->child_watcher); i->s_cur = LI_INSTANCE_LOADING; - instance_acquire(i); + li_instance_acquire(i); ERROR(i->srv, "Instance (%i) spawned: %s", i->pid, i->ic->cmd[0]); break; } } -liInstance* server_new_instance(liServer *srv, liInstanceConf *ic) { +liInstance* li_server_new_instance(liServer *srv, liInstanceConf *ic) { liInstance *i; i = g_slice_new0(liInstance); i->refcount = 1; i->srv = srv; - instance_conf_acquire(ic); + li_instance_conf_acquire(ic); i->ic = ic; i->pid = -1; i->s_cur = i->s_dest = LI_INSTANCE_DOWN; @@ -172,10 +172,10 @@ liInstance* server_new_instance(liServer *srv, liInstanceConf *ic) { return i; } -void instance_replace(liInstance *oldi, liInstance *newi) { +void li_instance_replace(liInstance *oldi, liInstance *newi) { } -void instance_set_state(liInstance *i, liInstanceState s) { +void li_instance_set_state(liInstance *i, liInstanceState s) { if (i->s_dest == s) return; switch (s) { case LI_INSTANCE_DOWN: @@ -206,10 +206,10 @@ void instance_set_state(liInstance *i, liInstanceState s) { case LI_INSTANCE_WARMUP: break; case LI_INSTANCE_ACTIVE: - angel_send_simple_call(i->acon, CONST_STR_LEN("core"), CONST_STR_LEN("run"), buf, &error); + li_angel_send_simple_call(i->acon, CONST_STR_LEN("core"), CONST_STR_LEN("run"), buf, &error); break; case LI_INSTANCE_SUSPEND: - angel_send_simple_call(i->acon, CONST_STR_LEN("core"), CONST_STR_LEN("suspend"), buf, &error); + li_angel_send_simple_call(i->acon, CONST_STR_LEN("core"), CONST_STR_LEN("suspend"), buf, &error); break; } } @@ -252,7 +252,7 @@ static void instance_state_machine(liInstance *i) { } } -void instance_release(liInstance *i) { +void li_instance_release(liInstance *i) { liServer *srv; liInstance *t; if (!i) return; @@ -264,28 +264,28 @@ void instance_release(liInstance *i) { kill(i->pid, SIGTERM); i->pid = -1; i->s_cur = LI_INSTANCE_DOWN; - angel_connection_free(i->acon); + li_angel_connection_free(i->acon); i->acon = NULL; } - instance_conf_release(i->ic); + li_instance_conf_release(i->ic); i->ic = NULL; t = i->replace; i->replace = NULL; - instance_release(t); + li_instance_release(t); t = i->replace_by; i->replace_by = NULL; - instance_release(t); + li_instance_release(t); g_slice_free(liInstance, i); } -void instance_acquire(liInstance *i) { +void li_instance_acquire(liInstance *i) { assert(g_atomic_int_get(&i->refcount) > 0); g_atomic_int_inc(&i->refcount); } -liInstanceConf* instance_conf_new(gchar **cmd, GString *username, uid_t uid, gid_t gid) { +liInstanceConf* li_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; @@ -297,7 +297,7 @@ liInstanceConf* instance_conf_new(gchar **cmd, GString *username, uid_t uid, gid return ic; } -void instance_conf_release(liInstanceConf *ic) { +void li_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; @@ -305,15 +305,15 @@ void instance_conf_release(liInstanceConf *ic) { g_slice_free(liInstanceConf, ic); } -void instance_conf_acquire(liInstanceConf *ic) { +void li_instance_conf_acquire(liInstanceConf *ic) { assert(g_atomic_int_get(&ic->refcount) > 0); g_atomic_int_inc(&ic->refcount); } -void instance_job_append(liInstance *i) { +void li_instance_job_append(liInstance *i) { liServer *srv = i->srv; if (!i->in_jobqueue) { - instance_acquire(i); + li_instance_acquire(i); i->in_jobqueue = TRUE; g_queue_push_tail(&srv->job_queue, i); ev_async_send(srv->loop, &srv->job_watcher); diff --git a/src/angel_value.c b/src/angel_value.c index a19e869..5d85d94 100644 --- a/src/angel_value.c +++ b/src/angel_value.c @@ -1,40 +1,40 @@ #include -liValue* value_new_none() { +liValue* li_value_new_none() { liValue *v = g_slice_new0(liValue); v->type = LI_VALUE_NONE; return v; } -liValue* value_new_bool(gboolean val) { +liValue* li_value_new_bool(gboolean val) { liValue *v = g_slice_new0(liValue); v->data.boolean = val; v->type = LI_VALUE_BOOLEAN; return v; } -liValue* value_new_number(gint64 val) { +liValue* li_value_new_number(gint64 val) { liValue *v = g_slice_new0(liValue); v->data.number = val; v->type = LI_VALUE_NUMBER; return v; } -liValue* value_new_string(GString *val) { +liValue* li_value_new_string(GString *val) { liValue *v = g_slice_new0(liValue); v->data.string = val; v->type = LI_VALUE_STRING; return v; } -liValue* value_new_range(liValueRange val) { +liValue* li_value_new_range(liValueRange val) { liValue *v = g_slice_new0(liValue); v->data.range = val; v->type = LI_VALUE_RANGE; return v; } -liValue* value_new_list() { +liValue* li_value_new_list() { liValue *v = g_slice_new0(liValue); v->data.list = g_ptr_array_new(); v->type = LI_VALUE_LIST; @@ -46,10 +46,10 @@ static void _value_hash_free_key(gpointer data) { } static void _value_hash_free_value(gpointer data) { - value_free((liValue*) data); + li_value_free((liValue*) data); } -liValue* value_new_hash() { +liValue* li_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, @@ -58,47 +58,47 @@ liValue* value_new_hash() { return v; } -liValue* value_copy(liValue* val) { +liValue* li_value_copy(liValue* val) { liValue *n; switch (val->type) { - 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); + case LI_VALUE_NONE: n = li_value_new_bool(FALSE); n->type = LI_VALUE_NONE; return n; /* hack */ + case LI_VALUE_BOOLEAN: return li_value_new_bool(val->data.boolean); + case LI_VALUE_NUMBER: return li_value_new_number(val->data.number); + case LI_VALUE_STRING: return li_value_new_string(g_string_new_len(GSTR_LEN(val->data.string))); + case LI_VALUE_RANGE: return li_value_new_range(val->data.range); /* list: we have to copy every value in the list! */ case LI_VALUE_LIST: - n = value_new_list(); + n = li_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++) { - g_ptr_array_index(n->data.list, i) = value_copy(g_ptr_array_index(val->data.list, i)); + g_ptr_array_index(n->data.list, i) = li_value_copy(g_ptr_array_index(val->data.list, i)); } return n; /* hash: iterate over hashtable, clone each value */ case LI_VALUE_HASH: - n = value_new_hash(); + n = li_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((liValue*)v)); + g_hash_table_insert(n->data.hash, g_string_new_len(GSTR_LEN((GString*)k)), li_value_copy((liValue*)v)); } return n; } return NULL; } -static void value_list_free(GPtrArray *vallist) { +static void li_value_list_free(GPtrArray *vallist) { if (!vallist) return; for (gsize i = 0; i < vallist->len; i++) { - value_free(g_ptr_array_index(vallist, i)); + li_value_free(g_ptr_array_index(vallist, i)); } g_ptr_array_free(vallist, TRUE); } -void value_free(liValue* val) { +void li_value_free(liValue* val) { if (!val) return; switch (val->type) { @@ -113,7 +113,7 @@ void value_free(liValue* val) { case LI_VALUE_RANGE: break; case LI_VALUE_LIST: - value_list_free(val->data.list); + li_value_list_free(val->data.list); break; case LI_VALUE_HASH: g_hash_table_destroy(val->data.hash); @@ -123,7 +123,7 @@ void value_free(liValue* val) { g_slice_free(liValue, val); } -const char* value_type_string(liValueType type) { +const char* li_value_type_string(liValueType type) { switch(type) { case LI_VALUE_NONE: return "none"; @@ -143,7 +143,7 @@ const char* value_type_string(liValueType type) { return ""; } -GString *value_to_string(liValue *val) { +GString *li_value_to_string(liValue *val) { GString *str = NULL; switch (val->type) { @@ -168,11 +168,11 @@ GString *value_to_string(liValue *val) { 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)); + GString *tmp = li_value_to_string(g_ptr_array_index(val->data.list, 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_ptr_array_index(val->data.list, i)); + tmp = li_value_to_string(g_ptr_array_index(val->data.list, i)); g_string_append_len(str, CONST_STR_LEN(", ")); g_string_append(str, tmp->str); g_string_free(tmp, TRUE); @@ -193,7 +193,7 @@ GString *value_to_string(liValue *val) { while (g_hash_table_iter_next(&iter, &k, &v)) { if (i) g_string_append_len(str, CONST_STR_LEN(", ")); - tmp = value_to_string((liValue*)v); + tmp = li_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 ecf2588..59b7319 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -43,7 +43,7 @@ static void chunkfile_release(liChunkFile *cf) { /* open the file cf->name if it is not already opened for reading * may return HANDLER_GO_ON, HANDLER_ERROR */ -liHandlerResult chunkfile_open(liVRequest *vr, liChunkFile *cf) { +liHandlerResult li_chunkfile_open(liVRequest *vr, liChunkFile *cf) { if (!cf) return LI_HANDLER_ERROR; if (-1 != cf->fd) return LI_HANDLER_GO_ON; if (!cf->name) { @@ -52,7 +52,7 @@ liHandlerResult chunkfile_open(liVRequest *vr, liChunkFile *cf) { } if (-1 == (cf->fd = open(cf->name->str, O_RDONLY))) { if (EMFILE == errno) { - server_out_of_fds(vr->wrk->srv); + li_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 LI_HANDLER_ERROR; @@ -83,7 +83,7 @@ liHandlerResult chunkfile_open(liVRequest *vr, liChunkFile *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 */ -liHandlerResult chunkiter_read(liVRequest *vr, liChunkIter iter, off_t start, off_t length, char **data_start, off_t *data_len) { +liHandlerResult li_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; liHandlerResult res = LI_HANDLER_GO_ON; @@ -106,7 +106,7 @@ liHandlerResult chunkiter_read(liVRequest *vr, liChunkIter iter, off_t start, of *data_len = length; break; case FILE_CHUNK: - if (LI_HANDLER_GO_ON != (res = chunkfile_open(vr, c->file.file))) return res; + if (LI_HANDLER_GO_ON != (res = li_chunkfile_open(vr, c->file.file))) return res; if (length > MAX_MMAP_CHUNK) length = MAX_MMAP_CHUNK; @@ -155,10 +155,10 @@ read_chunk: return LI_HANDLER_GO_ON; } -/* same as chunkiter_read, but tries mmap() first and falls back to read(); +/* same as li_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. */ -liHandlerResult chunkiter_read_mmap(liVRequest *vr, liChunkIter iter, off_t start, off_t length, char **data_start, off_t *data_len) { +liHandlerResult li_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; liHandlerResult res = LI_HANDLER_GO_ON; @@ -182,7 +182,7 @@ liHandlerResult chunkiter_read_mmap(liVRequest *vr, liChunkIter iter, off_t star *data_len = length; break; case FILE_CHUNK: - if (LI_HANDLER_GO_ON != (res = chunkfile_open(vr, c->file.file))) return res; + if (LI_HANDLER_GO_ON != (res = li_chunkfile_open(vr, c->file.file))) return res; if (length > MAX_MMAP_CHUNK) length = MAX_MMAP_CHUNK; @@ -327,7 +327,7 @@ static void chunk_free(liChunk *c) { /****************** * cqlimit * ******************/ -liCQLimit* cqlimit_new(liVRequest *vr) { +liCQLimit* li_cqlimit_new(liVRequest *vr) { liCQLimit *cql = g_slice_new0(liCQLimit); cql->refcount = 1; cql->vr = vr; @@ -335,7 +335,7 @@ liCQLimit* cqlimit_new(liVRequest *vr) { return cql; } -void cqlimit_reset(liCQLimit *cql) { +void li_cqlimit_reset(liCQLimit *cql) { assert(cql->current == 0); assert(cql->io_watcher == NULL); assert(cql->notify == NULL); @@ -345,12 +345,12 @@ void cqlimit_reset(liCQLimit *cql) { cql->notify = NULL; } -void cqlimit_acquire(liCQLimit *cql) { +void li_cqlimit_acquire(liCQLimit *cql) { assert(g_atomic_int_get(&cql->refcount) > 0); g_atomic_int_inc(&cql->refcount); } -void cqlimit_release(liCQLimit *cql) { +void li_cqlimit_release(liCQLimit *cql) { if (!cql) return; assert(g_atomic_int_get(&cql->refcount) > 0); if (g_atomic_int_dec_and_test(&cql->refcount)) { @@ -361,7 +361,7 @@ void cqlimit_release(liCQLimit *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); + li_ev_io_rem_events(cql->vr->wrk->loop, cql->io_watcher, EV_READ); } if (cql->notify) { cql->notify(cql->vr, cql->context, cql->locked); @@ -371,7 +371,7 @@ static void cqlimit_lock(liCQLimit *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); + li_ev_io_add_events(cql->vr->wrk->loop, cql->io_watcher, EV_READ); } if (cql->notify) { cql->notify(cql->vr, cql->context, cql->locked); @@ -402,7 +402,7 @@ static void cqlimit_update(liChunkQueue *cq, goffset d) { } } -void cqlimit_set_limit(liCQLimit *cql, goffset limit) { +void li_cqlimit_set_limit(liCQLimit *cql, goffset limit) { if (!cql) return; cql->limit = limit; @@ -422,7 +422,7 @@ void cqlimit_set_limit(liCQLimit *cql, goffset limit) { * chunkqueue * ******************/ -liChunkQueue* chunkqueue_new() { +liChunkQueue* li_chunkqueue_new() { liChunkQueue *cq = g_slice_new0(liChunkQueue); cq->queue = g_queue_new(); return cq; @@ -436,7 +436,7 @@ static void __chunk_free(gpointer _c, gpointer userdata) { chunk_free(c); } -void chunkqueue_reset(liChunkQueue *cq) { +void li_chunkqueue_reset(liChunkQueue *cq) { if (!cq) return; cq->is_closed = FALSE; cq->bytes_in = cq->bytes_out = cq->length = 0; @@ -446,35 +446,35 @@ void chunkqueue_reset(liChunkQueue *cq) { g_queue_clear(cq->queue); } -void chunkqueue_free(liChunkQueue *cq) { +void li_chunkqueue_free(liChunkQueue *cq) { if (!cq) return; g_queue_foreach(cq->queue, __chunk_free, cq); g_queue_free(cq->queue); cq->queue = NULL; - cqlimit_release(cq->limit); + li_cqlimit_release(cq->limit); cq->limit = NULL; assert(cq->mem_usage == 0); cq->mem_usage = 0; g_slice_free(liChunkQueue, cq); } -void chunkqueue_use_limit(liChunkQueue *cq, liVRequest *vr) { +void li_chunkqueue_use_limit(liChunkQueue *cq, liVRequest *vr) { if (cq->limit) return; - cq->limit = cqlimit_new(vr); + cq->limit = li_cqlimit_new(vr); } -void chunkqueue_set_limit(liChunkQueue *cq, liCQLimit* cql) { +void li_chunkqueue_set_limit(liChunkQueue *cq, liCQLimit* cql) { gboolean upd_limit = (cql != cq->limit); goffset memusage = cq->mem_usage; - if (cql) cqlimit_acquire(cql); + if (cql) li_cqlimit_acquire(cql); if (upd_limit) cqlimit_update(cq, -memusage); - cqlimit_release(cq->limit); + li_cqlimit_release(cq->limit); cq->limit = cql; if (upd_limit) cqlimit_update(cq, memusage); } /* return -1 for unlimited, 0 for full and n > 0 for n bytes free */ -goffset chunkqueue_limit_available(liChunkQueue *cq) { +goffset li_chunkqueue_limit_available(liChunkQueue *cq) { liCQLimit *cql = cq->limit; goffset avail; if (!cql) return -1; @@ -488,7 +488,7 @@ goffset chunkqueue_limit_available(liChunkQueue *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(liChunkQueue *cq, GString *str) { +void li_chunkqueue_append_string(liChunkQueue *cq, GString *str) { liChunk *c; if (!str->len) { g_string_free(str, TRUE); @@ -507,7 +507,7 @@ void chunkqueue_append_string(liChunkQueue *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(liChunkQueue *cq, GByteArray *mem) { +void li_chunkqueue_append_bytearr(liChunkQueue *cq, GByteArray *mem) { liChunk *c; if (!mem->len) { g_byte_array_free(mem, TRUE); @@ -523,7 +523,7 @@ void chunkqueue_append_bytearr(liChunkQueue *cq, GByteArray *mem) { } /* memory gets copied */ -void chunkqueue_append_mem(liChunkQueue *cq, const void *mem, gssize len) { +void li_chunkqueue_append_mem(liChunkQueue *cq, const void *mem, gssize len) { liChunk *c; if (!len) return; c = chunk_new(); @@ -548,32 +548,32 @@ static void __chunkqueue_append_file(liChunkQueue *cq, GString *filename, off_t cq->bytes_in += length; } /* pass ownership of filename, do not free it */ -void chunkqueue_append_file(liChunkQueue *cq, GString *filename, off_t start, off_t length) { +void li_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(liChunkQueue *cq, GString *filename, off_t start, off_t length, int fd) { +void li_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(liChunkQueue *cq, GString *filename, off_t start, off_t length) { +void li_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(liChunkQueue *cq, GString *filename, off_t start, off_t length, int fd) { +void li_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(liChunkQueue *out, liChunkQueue *in, goffset length) { +goffset li_chunkqueue_steal_len(liChunkQueue *out, liChunkQueue *in, goffset length) { liChunk *c, *cnew; GList* l; goffset bytes = 0, meminbytes = 0, memoutbytes = 0; @@ -647,7 +647,7 @@ 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 */ -goffset chunkqueue_steal_all(liChunkQueue *out, liChunkQueue *in) { +goffset li_chunkqueue_steal_all(liChunkQueue *out, liChunkQueue *in) { goffset len; /* if in->queue is empty, do nothing */ @@ -685,7 +685,7 @@ goffset chunkqueue_steal_all(liChunkQueue *out, liChunkQueue *in) { } /* steal the first chunk from in and append it to out, return number of bytes stolen */ -goffset chunkqueue_steal_chunk(liChunkQueue *out, liChunkQueue *in) { +goffset li_chunkqueue_steal_chunk(liChunkQueue *out, liChunkQueue *in) { liChunk *c; goffset length; GList *l = g_queue_pop_head_link(in->queue); @@ -711,7 +711,7 @@ goffset chunkqueue_steal_chunk(liChunkQueue *out, liChunkQueue *in) { } /* skip up to length bytes in a chunkqueue, return number of bytes skipped */ -goffset chunkqueue_skip(liChunkQueue *cq, goffset length) { +goffset li_chunkqueue_skip(liChunkQueue *cq, goffset length) { liChunk *c; goffset bytes = 0; goffset we_have; @@ -737,7 +737,7 @@ goffset chunkqueue_skip(liChunkQueue *cq, goffset length) { return bytes; } -goffset chunkqueue_skip_all(liChunkQueue *cq) { +goffset li_chunkqueue_skip_all(liChunkQueue *cq) { goffset bytes = cq->length; g_queue_foreach(cq->queue, __chunk_free, cq); @@ -749,7 +749,7 @@ goffset chunkqueue_skip_all(liChunkQueue *cq) { return bytes; } -gboolean chunkqueue_extract_to(liVRequest *vr, liChunkQueue *cq, goffset len, GString *dest) { +gboolean li_chunkqueue_extract_to(liVRequest *vr, liChunkQueue *cq, goffset len, GString *dest) { liChunkIter ci; goffset coff, clen; g_string_set_size(dest, 0); @@ -765,7 +765,7 @@ gboolean chunkqueue_extract_to(liVRequest *vr, liChunkQueue *cq, goffset len, GS while (coff < clen) { gchar *buf; off_t we_have; - if (LI_HANDLER_GO_ON != chunkiter_read(vr, ci, coff, len, &buf, &we_have)) goto error; + if (LI_HANDLER_GO_ON != li_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,7 +781,7 @@ error: return FALSE; } -gboolean chunkqueue_extract_to_bytearr(liVRequest *vr, liChunkQueue *cq, goffset len, GByteArray *dest) { +gboolean li_chunkqueue_extract_to_bytearr(liVRequest *vr, liChunkQueue *cq, goffset len, GByteArray *dest) { liChunkIter ci; goffset coff, clen; g_byte_array_set_size(dest, 0); @@ -800,7 +800,7 @@ gboolean chunkqueue_extract_to_bytearr(liVRequest *vr, liChunkQueue *cq, goffset while (coff < clen) { gchar *buf; off_t we_have; - if (LI_HANDLER_GO_ON != chunkiter_read(vr, ci, coff, len, &buf, &we_have)) goto error; + if (LI_HANDLER_GO_ON != li_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 e855962..a59ace3 100644 --- a/src/chunk_parser.c +++ b/src/chunk_parser.c @@ -1,12 +1,12 @@ #include -void chunk_parser_init(liChunkParserCtx *ctx, liChunkQueue *cq) { +void li_chunk_parser_init(liChunkParserCtx *ctx, liChunkQueue *cq) { ctx->cq = cq; - chunk_parser_reset(ctx); + li_chunk_parser_reset(ctx); } -void chunk_parser_reset(liChunkParserCtx *ctx) { +void li_chunk_parser_reset(liChunkParserCtx *ctx) { ctx->bytes_in = 0; ctx->curi.element = NULL; ctx->start = 0; @@ -14,7 +14,7 @@ void chunk_parser_reset(liChunkParserCtx *ctx) { ctx->buf = NULL; } -liHandlerResult chunk_parser_prepare(liChunkParserCtx *ctx) { +liHandlerResult li_chunk_parser_prepare(liChunkParserCtx *ctx) { if (NULL == ctx->curi.element) { ctx->curi = chunkqueue_iter(ctx->cq); if (NULL == ctx->curi.element) return LI_HANDLER_WAIT_FOR_EVENT; @@ -22,7 +22,7 @@ liHandlerResult chunk_parser_prepare(liChunkParserCtx *ctx) { return LI_HANDLER_GO_ON; } -liHandlerResult chunk_parser_next(liVRequest *vr, liChunkParserCtx *ctx, char **p, char **pe) { +liHandlerResult li_chunk_parser_next(liVRequest *vr, liChunkParserCtx *ctx, char **p, char **pe) { off_t l; liHandlerResult res; @@ -38,7 +38,7 @@ liHandlerResult chunk_parser_next(liVRequest *vr, liChunkParserCtx *ctx, char ** if (NULL == ctx->curi.element) return LI_HANDLER_WAIT_FOR_EVENT; - if (LI_HANDLER_GO_ON != (res = chunkiter_read(vr, ctx->curi, ctx->start, l - ctx->start, &ctx->buf, &ctx->length))) { + if (LI_HANDLER_GO_ON != (res = li_chunkiter_read(vr, ctx->curi, ctx->start, l - ctx->start, &ctx->buf, &ctx->length))) { return res; } @@ -47,12 +47,12 @@ liHandlerResult chunk_parser_next(liVRequest *vr, liChunkParserCtx *ctx, char ** return LI_HANDLER_GO_ON; } -void chunk_parser_done(liChunkParserCtx *ctx, goffset len) { +void li_chunk_parser_done(liChunkParserCtx *ctx, goffset len) { ctx->bytes_in += len; ctx->start += len; } -gboolean chunk_extract_to(liVRequest *vr, liChunkParserMark from, liChunkParserMark to, GString *dest) { +gboolean li_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(liVRequest *vr, liChunkParserMark from, liChunkParserM while (i.pos < len) { char *buf; off_t we_have; - if (LI_HANDLER_GO_ON != chunkiter_read(vr, i.ci, i.pos, len - i.pos, &buf, &we_have)) goto error; + if (LI_HANDLER_GO_ON != li_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(liVRequest *vr, liChunkParserMark from, liChunkParserM while (i.pos < to.pos) { char *buf; off_t we_have; - if (LI_HANDLER_GO_ON != chunkiter_read(vr, i.ci, i.pos, to.pos - i.pos, &buf, &we_have)) goto error; + if (LI_HANDLER_GO_ON != li_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,9 +83,9 @@ error: return FALSE; } -GString* chunk_extract(liVRequest *vr, liChunkParserMark from, liChunkParserMark to) { +GString* li_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; + if (li_chunk_extract_to(vr, from, to, str)) return str; g_string_free(str, TRUE); return NULL; } diff --git a/src/collect.c b/src/collect.c index ca3df6a..9876859 100644 --- a/src/collect.c +++ b/src/collect.c @@ -95,17 +95,17 @@ static gboolean collect_insert_func(liWorker *ctx, liCollectInfo *ci) { return FALSE; } -liCollectInfo* collect_start(liWorker *ctx, liCollectFuncCB func, gpointer fdata, liCollectCB cb, gpointer cbdata) { +liCollectInfo* li_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(liCollectInfo* ci) { +void li_collect_break(liCollectInfo* ci) { ci->stopped = TRUE; } -void collect_watcher_cb(struct ev_loop *loop, ev_async *w, int revents) { +void li_collect_watcher_cb(struct ev_loop *loop, ev_async *w, int revents) { liWorker *wrk = (liWorker*) w->data; collect_job *j; UNUSED(loop); diff --git a/src/condition.c b/src/condition.c index 6341821..4227fd8 100644 --- a/src/condition.c +++ b/src/condition.c @@ -1,12 +1,12 @@ #include static gboolean condition_parse_ip(liConditionRValue *val, const char *txt) { - if (parse_ipv4(txt, &val->ipv4.addr, NULL, NULL)) { + if (li_parse_ipv4(txt, &val->ipv4.addr, NULL, NULL)) { val->type = LI_COND_VALUE_SOCKET_IPV4; val->ipv4.networkmask = 0xFFFFFFFF; return TRUE; } - if (parse_ipv6(txt, val->ipv6.addr, NULL, NULL)) { + if (li_parse_ipv6(txt, val->ipv6.addr, NULL, NULL)) { val->type = LI_COND_VALUE_SOCKET_IPV6; val->ipv6.network = 128; return TRUE; @@ -15,11 +15,11 @@ static gboolean condition_parse_ip(liConditionRValue *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)) { + if (li_parse_ipv4(txt, &val->ipv4.addr, &val->ipv4.networkmask, NULL)) { val->type = LI_COND_VALUE_SOCKET_IPV4; return TRUE; } - if (parse_ipv6(txt, val->ipv6.addr, &val->ipv6.network, NULL)) { + if (li_parse_ipv6(txt, val->ipv6.addr, &val->ipv6.network, NULL)) { val->type = LI_COND_VALUE_SOCKET_IPV6; return TRUE; } @@ -44,7 +44,7 @@ static gboolean condition_ip_from_socket(liConditionRValue *val, liSockAddr *add return FALSE; } -liConditionLValue* condition_lvalue_new(liCondLValue type, GString *key) { +liConditionLValue* li_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; @@ -53,12 +53,12 @@ liConditionLValue* condition_lvalue_new(liCondLValue type, GString *key) { return lvalue; } -void condition_lvalue_acquire(liConditionLValue *lvalue) { +void li_condition_lvalue_acquire(liConditionLValue *lvalue) { assert(g_atomic_int_get(&lvalue->refcount) > 0); g_atomic_int_inc(&lvalue->refcount); } -void condition_lvalue_release(liConditionLValue *lvalue) { +void li_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)) { @@ -113,13 +113,13 @@ static liCondition* cond_new_ip(liServer *srv, liCompOperator op, liConditionLVa c = condition_new(op, lvalue); if (!condition_parse_ip_net(&c->rvalue, str->str)) { ERROR(srv, "Invalid ip address '%s'", str->str); - condition_release(srv, c); + li_condition_release(srv, c); return NULL; } return c; } -liCondition* condition_new_bool(liServer *srv, liConditionLValue *lvalue, gboolean b) { +liCondition* li_condition_new_bool(liServer *srv, liConditionLValue *lvalue, gboolean b) { liCondition *c; UNUSED(srv); c = condition_new(LI_CONFIG_COND_EQ, lvalue); @@ -128,7 +128,7 @@ liCondition* condition_new_bool(liServer *srv, liConditionLValue *lvalue, gboole return c; } -liCondition* condition_new_string(liServer *srv, liCompOperator op, liConditionLValue *lvalue, GString *str) { +liCondition* li_condition_new_string(liServer *srv, liCompOperator op, liConditionLValue *lvalue, GString *str) { switch (op) { case LI_CONFIG_COND_EQ: case LI_CONFIG_COND_NE: @@ -147,16 +147,16 @@ liCondition* condition_new_string(liServer *srv, liCompOperator op, liConditionL 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)); + ERROR(srv, "Cannot compare strings with '%s'", li_comp_op_to_string(op)); return NULL; } ERROR(srv, "Condition creation failed: %s %s '%s' (perhaps you compiled without pcre?)", - cond_lvalue_to_string(lvalue->type), comp_op_to_string(op), + li_cond_lvalue_to_string(lvalue->type), li_comp_op_to_string(op), str->str); return NULL; } -liCondition* condition_new_int(liServer *srv, liCompOperator op, liConditionLValue *lvalue, gint64 i) { +liCondition* li_condition_new_int(liServer *srv, liCompOperator op, liConditionLValue *lvalue, gint64 i) { liCondition *c; switch (op) { case LI_CONFIG_COND_PREFIX: @@ -167,7 +167,7 @@ liCondition* condition_new_int(liServer *srv, liCompOperator op, liConditionLVal 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)); + ERROR(srv, "Cannot compare integers with '%s'", li_comp_op_to_string(op)); return NULL; case LI_CONFIG_COND_EQ: case LI_CONFIG_COND_NE: @@ -181,14 +181,14 @@ liCondition* condition_new_int(liServer *srv, liCompOperator op, liConditionLVal return c; } ERROR(srv, "Condition creation failed: %s %s %"G_GINT64_FORMAT" (perhaps you compiled without pcre?)", - cond_lvalue_to_string(lvalue->type), comp_op_to_string(op), + li_cond_lvalue_to_string(lvalue->type), li_comp_op_to_string(op), i); return NULL; } static void condition_free(liCondition *c) { - condition_lvalue_release(c->lvalue); + li_condition_lvalue_release(c->lvalue); switch (c->rvalue.type) { case LI_COND_VALUE_BOOL: case LI_COND_VALUE_NUMBER: @@ -208,12 +208,12 @@ static void condition_free(liCondition *c) { g_slice_free(liCondition, c); } -void condition_acquire(liCondition *c) { +void li_condition_acquire(liCondition *c) { assert(g_atomic_int_get(&c->refcount) > 0); g_atomic_int_inc(&c->refcount); } -void condition_release(liServer *srv, liCondition* c) { +void li_condition_release(liServer *srv, liCondition* c) { UNUSED(srv); if (!c) return; assert(g_atomic_int_get(&c->refcount) > 0); @@ -222,7 +222,7 @@ void condition_release(liServer *srv, liCondition* c) { } } -const char* comp_op_to_string(liCompOperator op) { +const char* li_comp_op_to_string(liCompOperator op) { switch (op) { case LI_CONFIG_COND_EQ: return "=="; case LI_CONFIG_COND_NE: return "!="; @@ -243,7 +243,7 @@ const char* comp_op_to_string(liCompOperator op) { return ""; } -const char* cond_lvalue_to_string(liCondLValue t) { +const char* li_cond_lvalue_to_string(liCondLValue t) { switch (t) { case LI_COMP_REQUEST_LOCALIP: return "request.localip"; case LI_COMP_REQUEST_REMOTEIP: return "request.remoteip"; @@ -265,7 +265,7 @@ const char* cond_lvalue_to_string(liCondLValue t) { return ""; } -liCondLValue cond_lvalue_from_string(const gchar *str, guint len) { +liCondLValue li_cond_lvalue_from_string(const gchar *str, guint len) { gchar *c = (gchar*)str; if (g_str_has_prefix(c, "request.")) { @@ -309,13 +309,13 @@ liCondLValue cond_lvalue_from_string(const gchar *str, guint len) { return LI_COMP_UNKNOWN; } -static liHandlerResult condition_check_eval_bool(liVRequest *vr, liCondition *cond, gboolean *res) { +static liHandlerResult li_condition_check_eval_bool(liVRequest *vr, liCondition *cond, gboolean *res) { *res = FALSE; 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)) { + if (vr->physical.have_errno || !li_vrequest_stat(vr)) { switch (vr->physical.stat_errno) { case EACCES: vr->response.http_status = 403; break; case EBADF: vr->response.http_status = 500; break; @@ -327,7 +327,7 @@ static liHandlerResult condition_check_eval_bool(liVRequest *vr, liCondition *co case ENOTDIR: vr->response.http_status = 404; break; default: vr->response.http_status = 500; } - vrequest_handle_direct(vr); + li_vrequest_handle_direct(vr); return LI_HANDLER_GO_ON; } } @@ -341,7 +341,7 @@ static liHandlerResult condition_check_eval_bool(liVRequest *vr, liCondition *co *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)); + VR_ERROR(vr, "invalid lvalue \"%s\" for boolean comparison", li_cond_lvalue_to_string(cond->lvalue->type)); return LI_HANDLER_ERROR; } @@ -349,7 +349,7 @@ static liHandlerResult condition_check_eval_bool(liVRequest *vr, liCondition *co } /* LI_COND_VALUE_STRING and LI_COND_VALUE_REGEXP only */ -static liHandlerResult condition_check_eval_string(liVRequest *vr, liCondition *cond, gboolean *res) { +static liHandlerResult li_condition_check_eval_string(liVRequest *vr, liCondition *cond, gboolean *res) { liActionRegexStackElement arse; liConnection *con = vr->con; const char *val = ""; @@ -384,7 +384,7 @@ static liHandlerResult condition_check_eval_string(liVRequest *vr, liCondition * /* TODO: physical path exists */ break; case LI_COMP_REQUEST_HEADER: - http_header_get_fast(con->wrk->tmp_str, vr->request.headers, GSTR_LEN(cond->lvalue->key)); + li_http_header_get_fast(con->wrk->tmp_str, vr->request.headers, GSTR_LEN(cond->lvalue->key)); val = con->wrk->tmp_str->str; break; case LI_COMP_REQUEST_CONTENT_LENGTH: @@ -430,7 +430,7 @@ static liHandlerResult condition_check_eval_string(liVRequest *vr, liCondition * 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)); + VR_ERROR(vr, "cannot compare string/regexp with '%s'", li_comp_op_to_string(cond->op)); return LI_HANDLER_ERROR; } @@ -438,7 +438,7 @@ static liHandlerResult condition_check_eval_string(liVRequest *vr, liCondition * } -static liHandlerResult condition_check_eval_int(liVRequest *vr, liCondition *cond, gboolean *res) { +static liHandlerResult li_condition_check_eval_int(liVRequest *vr, liCondition *cond, gboolean *res) { gint64 val; *res = FALSE; @@ -447,7 +447,7 @@ static liHandlerResult condition_check_eval_int(liVRequest *vr, liCondition *con val = vr->request.content_length; case LI_COMP_PHYSICAL_SIZE: if (!vr->physical.have_stat) { - if (vr->physical.have_errno || !vrequest_stat(vr)) { + if (vr->physical.have_errno || !li_vrequest_stat(vr)) { switch (vr->physical.stat_errno) { case EACCES: vr->response.http_status = 403; break; case EBADF: vr->response.http_status = 500; break; @@ -459,14 +459,14 @@ static liHandlerResult condition_check_eval_int(liVRequest *vr, liCondition *con case ENOTDIR: vr->response.http_status = 404; break; default: vr->response.http_status = 500; } - vrequest_handle_direct(vr); + li_vrequest_handle_direct(vr); 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)); + VR_ERROR(vr, "couldn't get int value for '%s'", li_cond_lvalue_to_string(cond->lvalue->type)); return LI_HANDLER_ERROR; } @@ -497,7 +497,7 @@ static liHandlerResult condition_check_eval_int(liVRequest *vr, liCondition *con 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)); + VR_ERROR(vr, "cannot compare int with '%s'", li_comp_op_to_string(cond->op)); return LI_HANDLER_ERROR; } @@ -546,7 +546,7 @@ static gboolean ip_in_net(liConditionRValue *target, liConditionRValue *network) } /* LI_CONFIG_COND_IP and LI_CONFIG_COND_NOTIP only */ -static liHandlerResult condition_check_eval_ip(liVRequest *vr, liCondition *cond, gboolean *res) { +static liHandlerResult li_condition_check_eval_ip(liVRequest *vr, liCondition *cond, gboolean *res) { liConnection *con = vr->con; liConditionRValue ipval; const char *val = NULL; @@ -585,7 +585,7 @@ static liHandlerResult condition_check_eval_ip(liVRequest *vr, liCondition *cond return LI_HANDLER_ERROR; break; case LI_COMP_REQUEST_HEADER: - http_header_get_fast(con->wrk->tmp_str, vr->request.headers, GSTR_LEN(cond->lvalue->key)); + li_http_header_get_fast(con->wrk->tmp_str, vr->request.headers, GSTR_LEN(cond->lvalue->key)); val = con->wrk->tmp_str->str; break; case LI_COMP_PHYSICAL_SIZE: @@ -623,27 +623,27 @@ static liHandlerResult condition_check_eval_ip(liVRequest *vr, liCondition *cond 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)); + VR_ERROR(vr, "cannot match ips with '%s'", li_comp_op_to_string(cond->op)); return LI_HANDLER_ERROR; } return LI_HANDLER_GO_ON; } -liHandlerResult condition_check(liVRequest *vr, liCondition *cond, gboolean *res) { +liHandlerResult li_condition_check(liVRequest *vr, liCondition *cond, gboolean *res) { switch (cond->rvalue.type) { case LI_COND_VALUE_BOOL: - return condition_check_eval_bool(vr, cond, res); + return li_condition_check_eval_bool(vr, cond, res); case LI_COND_VALUE_STRING: #ifdef HAVE_PCRE_H case LI_COND_VALUE_REGEXP: #endif - return condition_check_eval_string(vr, cond, res); + return li_condition_check_eval_string(vr, cond, res); case LI_COND_VALUE_NUMBER: - return condition_check_eval_int(vr, cond, res); + return li_condition_check_eval_int(vr, cond, res); case LI_COND_VALUE_SOCKET_IPV4: case LI_COND_VALUE_SOCKET_IPV6: - return condition_check_eval_ip(vr, cond, res); + return li_condition_check_eval_ip(vr, cond, res); } VR_ERROR(vr, "Unsupported conditional type: %i", cond->rvalue.type); return LI_HANDLER_ERROR; diff --git a/src/condition_lua.c b/src/condition_lua.c index 3307744..83e5039 100644 --- a/src/condition_lua.c +++ b/src/condition_lua.c @@ -99,7 +99,7 @@ static int lua_condition_gc(lua_State *L) { if (!c || !*c) return 0; srv = (liServer*) lua_touserdata(L, lua_upvalueindex(1)); - condition_release(srv, *c); + li_condition_release(srv, *c); return 0; } @@ -107,7 +107,7 @@ static int lua_cond_lvalue_gc(lua_State *L) { liConditionLValue **lvalue = (liConditionLValue**) luaL_checkudata(L, 1, LUA_COND_LVALUE); if (!lvalue || !*lvalue) return 0; - condition_lvalue_release(*lvalue); + li_condition_lvalue_release(*lvalue); return 0; } @@ -138,7 +138,7 @@ int lua_push_condition(liServer *srv, lua_State *L, liCondition *c) { static int lua_cond_lvalue_tostring(lua_State *L) { liConditionLValue *lvalue = lua_get_condition_lvalue(L, 1); if (!lvalue) return 0; - lua_pushstring(L, cond_lvalue_to_string(lvalue->type)); + lua_pushstring(L, li_cond_lvalue_to_string(lvalue->type)); if (lvalue->key) { lua_pushstring(L, "['"); lua_pushstring(L, lvalue->key->str); @@ -159,10 +159,10 @@ static int lua_cond_lvalue_cmp(lua_State *L) { 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); + if (NULL == (sval = li_lua_togstring(L, 2))) return 0; + c = li_condition_new_string(srv, cmpop, lvalue, sval); if (c) { - condition_lvalue_acquire(lvalue); + li_condition_lvalue_acquire(lvalue); lua_push_condition(srv, L, c); return 1; } @@ -209,7 +209,7 @@ static int lua_push_cond_lvalue(liServer *srv, lua_State *L, liConditionLValue * /* cond_lvalue_t metatable */ static int lua_cond_lvalue_t_tostring(lua_State *L) { liCondLValue t = lua_get_cond_lvalue_t(L, 1); - lua_pushstring(L, cond_lvalue_to_string(t)); + lua_pushstring(L, li_cond_lvalue_to_string(t)); return 1; } @@ -220,8 +220,8 @@ static int lua_cond_lvalue_t_index(lua_State *L) { 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)); + if (NULL == (key = li_lua_togstring(L, 2))) return 0; + lua_push_cond_lvalue(srv, L, li_condition_lvalue_new(t, key)); return 1; } @@ -253,12 +253,12 @@ void lua_push_lvalues_dict(liServer *srv, lua_State *L) { size_t 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)); + lua_push_cond_lvalue(srv, L, li_condition_lvalue_new(i, NULL)); + lua_settop_in_dicts(L, li_cond_lvalue_to_string(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)); + lua_settop_in_dicts(L, li_cond_lvalue_to_string(i)); } } diff --git a/src/config_lua.c b/src/config_lua.c index d0c5976..a0c74d5 100644 --- a/src/config_lua.c +++ b/src/config_lua.c @@ -16,14 +16,14 @@ static liValue* lua_params_to_value(liServer *srv, lua_State *L) { case 1: return NULL; case 2: - return value_from_lua(srv, L); + return li_value_from_lua(srv, L); default: - val = value_new_list(); + val = li_value_new_list(); g_array_set_size(val->data.list, lua_gettop(L) - 1); while (lua_gettop(L) > 1) { - if (NULL == (subval = value_from_lua(srv, L))) { + if (NULL == (subval = li_value_from_lua(srv, L))) { ERROR(srv, "Couldn't convert value from lua (lua type '%s')", lua_typename(L, lua_type(L, -1))); - value_free(val); + li_value_free(val); return NULL; } g_array_index(val->data.list, liValue*, lua_gettop(L) - 1) = subval; @@ -140,8 +140,8 @@ static int handle_server_action(liServer *srv, lua_State *L, gpointer _sa) { val = lua_params_to_value(srv, L); /* TRACE(srv, "%s", "Creating action"); */ - a = sa->create_action(srv, sa->p, val); - value_free(val); + a = sa->li_create_action(srv, sa->p, val); + li_value_free(val); if (NULL == a) { lua_pushstring(L, "creating action failed"); @@ -161,16 +161,16 @@ static int handle_server_setup(liServer *srv, lua_State *L, gpointer _ss) { /* TRACE(srv, "%s", "Calling setup"); */ if (!ss->setup(srv, ss->p, val)) { - value_free(val); + li_value_free(val); lua_pushstring(L, "setup failed"); lua_error(L); } - value_free(val); + li_value_free(val); return 0; } -gboolean config_lua_load(liServer *srv, const gchar *filename) { +gboolean li_config_lua_load(liServer *srv, const gchar *filename) { lua_State *L; L = luaL_newstate(); @@ -200,7 +200,7 @@ gboolean config_lua_load(liServer *srv, const gchar *filename) { lua_getfield(L, LUA_GLOBALSINDEX, "actions"); srv->mainaction = lua_get_action(L, -1); - action_acquire(srv->mainaction); + li_action_acquire(srv->mainaction); lua_pop(L, 1); assert(lua_gettop(L) == 0); diff --git a/src/config_parser.rl b/src/config_parser.rl index 1e7b5a8..6f0a5b0 100644 --- a/src/config_parser.rl +++ b/src/config_parser.rl @@ -37,7 +37,7 @@ action boolean { liValue *o; - o = value_new_bool(*ctx->mark == 't' ? TRUE : FALSE); + o = li_value_new_bool(*ctx->mark == 't' ? TRUE : FALSE); g_queue_push_head(ctx->option_stack, o); _printf("got boolean %s in line %zd\n", *ctx->mark == 't' ? "true" : "false", ctx->line); @@ -50,7 +50,7 @@ for (gchar *c = ctx->mark; c < fpc; c++) i = i * 10 + *c - 48; - o = value_new_number(i); + o = li_value_new_number(i); /* push value onto stack */ g_queue_push_head(ctx->option_stack, o); @@ -139,7 +139,7 @@ } } - o = value_new_string(str); + o = li_value_new_string(str); g_queue_push_head(ctx->option_stack, o); _printf("got string %s", ""); @@ -152,7 +152,7 @@ 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(); + o = li_value_new_list(); g_queue_push_head(ctx->option_stack, o); fcall list_scanner; @@ -169,7 +169,7 @@ g_array_append_val(l->data.list, o); - _printf("list_push %s\n", value_type_string(o->type)); + _printf("list_push %s\n", li_value_type_string(o->type)); } action list_end { @@ -180,7 +180,7 @@ 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(); + o = li_value_new_hash(); g_queue_push_head(ctx->option_stack, o); fcall hash_scanner; @@ -199,9 +199,9 @@ g_hash_table_insert(h->data.hash, str, v); - _printf("hash_push: %s: %s => %s\n", value_type_string(k->type), value_type_string(v->type), value_type_string(h->type)); + _printf("hash_push: %s: %s => %s\n", li_value_type_string(k->type), li_value_type_string(v->type), li_value_type_string(h->type)); - value_free(k); + li_value_free(k); } action hash_end { @@ -229,12 +229,12 @@ v = g_queue_pop_head(ctx->option_stack); k = g_queue_pop_head(ctx->option_stack); - l = value_new_list(); + l = li_value_new_list(); g_array_append_val(l->list, k); g_array_append_val(l->list, v); - _printf("key-value pair: %s => %s in line %zd\n", value_type_string(k->type), value_type_string(v->type), ctx->line); + _printf("key-value pair: %s => %s in line %zd\n", li_value_type_string(k->type), li_value_type_string(v->type), ctx->line); /* push list on the stack */ g_queue_push_head(ctx->option_stack, l); @@ -258,7 +258,7 @@ gboolean negative = FALSE; if (o->type != LI_VALUE_STRING) { - ERROR(srv, "can only cast strings to integers, %s given", value_type_string(o->type)); + ERROR(srv, "can only cast strings to integers, %s given", li_value_type_string(o->type)); return FALSE; } @@ -288,7 +288,7 @@ GString *str; if (o->type != LI_VALUE_NUMBER) { - ERROR(srv, "can only cast integers to strings, %s given", value_type_string(o->type)); + ERROR(srv, "can only cast integers to strings, %s given", li_value_type_string(o->type)); return FALSE; } @@ -301,7 +301,7 @@ ctx->cast = LI_CFG_PARSER_CAST_NONE; } - _printf("value (%s) in line %zd\n", value_type_string(o->type), ctx->line); + _printf("value (%s) in line %zd\n", li_value_type_string(o->type), ctx->line); } action value_statement_start { @@ -333,16 +333,16 @@ /* value => value */ free_l = FALSE; free_r = FALSE; - o = value_new_list(); + o = li_value_new_list(); g_array_append_val(o->data.list, l); g_array_append_val(o->data.list, r); } 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; - case '*': o = value_new_number(l->data.number * r->data.number); break; - case '/': o = value_new_number(l->data.number / r->data.number); break; + case '+': o = li_value_new_number(l->data.number + r->data.number); break; + case '-': o = li_value_new_number(l->data.number - r->data.number); break; + case '*': o = li_value_new_number(l->data.number * r->data.number); break; + case '/': o = li_value_new_number(l->data.number / r->data.number); break; } } else if (l->type == LI_VALUE_STRING) { @@ -413,23 +413,23 @@ if (o == NULL) { WARNING(srv, "erronous value statement: %s %c %s in line %zd\n", - value_type_string(l->type), ctx->value_op, - value_type_string(r->type), ctx->line); + li_value_type_string(l->type), ctx->value_op, + li_value_type_string(r->type), ctx->line); return FALSE; } _printf("value statement: %s %c%s %s => %s in line %zd\n", - value_type_string(l->type), + li_value_type_string(l->type), ctx->value_op, ctx->value_op == '=' ? ">" : "", - value_type_string(r->type), - value_type_string(o->type), + li_value_type_string(r->type), + li_value_type_string(o->type), ctx->line); if (free_l) - value_free(l); + li_value_free(l); if (free_r) - value_free(r); + li_value_free(r); g_queue_push_head(ctx->option_stack, o); } @@ -440,7 +440,7 @@ GString *str; str = g_string_new_len(ctx->mark, fpc - ctx->mark); - o = value_new_string(str); + o = li_value_new_string(str); g_queue_push_head(ctx->option_stack, o); } @@ -459,22 +459,22 @@ if (t == NULL) { WARNING(srv, "unknown variable '%s'", o->data.string->str); - value_free(o); + li_value_free(o); return FALSE; } - r = value_copy(t); + r = li_value_copy(t); } else if (g_str_has_prefix(o->data.string->str, "env.")) { /* look up string in environment, push value onto stack */ gchar *env = getenv(o->data.string->str + 4); if (env == NULL) { ERROR(srv, "unknown environment variable: %s", o->data.string->str + 4); - value_free(o); + li_value_free(o); return FALSE; } - r = value_new_string(g_string_new(env)); + r = li_value_new_string(g_string_new(env)); } else { /* real action, lookup hashtable and create new action value */ @@ -486,12 +486,12 @@ return FALSE; } - action_acquire(a); - r = value_new_action(srv, a); + li_action_acquire(a); + r = li_value_new_action(srv, a); } g_queue_push_head(ctx->option_stack, r); - value_free(o); + li_value_free(o); } action operator { @@ -526,19 +526,19 @@ 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); + _printf("got assignment: %s = %s; in line %zd\n", name->data.string->str, li_value_type_string(val->type), ctx->line); if (g_str_has_prefix(name->data.string->str, "var.")) { /* assignment vor user defined variable, insert into hashtable */ gpointer old_key; gpointer old_val; - GString *str = value_extract(name).string; + GString *str = li_value_extract(name).string; /* free old key and value if we are overwriting it */ if (g_hash_table_lookup_extended(ctx->uservars, str, &old_key, &old_val)) { g_hash_table_remove(ctx->uservars, str); g_string_free(old_key, TRUE); - value_free(old_val); + li_value_free(old_val); } g_hash_table_insert(ctx->uservars, str, val); @@ -546,22 +546,22 @@ else if (ctx->in_setup_block) { /* in setup { } block, override default values for options */ - if (!plugin_set_default_option(srv, name->data.string->str, val)) { + if (!li_plugin_set_default_option(srv, name->data.string->str, val)) { ERROR(srv, "failed overriding default value for option \"%s\"", name->data.string->str); - value_free(name); - value_free(val); + li_value_free(name); + li_value_free(val); return FALSE; } - value_free(val); + li_value_free(val); } else { /* normal assignment */ - a = option_action(srv, name->data.string->str, val); - value_free(val); + a = li_option_action(srv, name->data.string->str, val); + li_value_free(val); if (a == NULL) { - value_free(name); + li_value_free(name); return FALSE; } @@ -569,7 +569,7 @@ g_array_append_val(al->data.list, a); } - value_free(name); + li_value_free(name); } action function_noparam { @@ -589,17 +589,17 @@ else { if (ctx->in_setup_block) { /* we are in the setup { } block, call setups and don't append to action list */ - if (!call_setup(srv, name->data.string->str, NULL)) { - value_free(name); + if (!li_call_setup(srv, name->data.string->str, NULL)) { + li_value_free(name); return FALSE; } } else { al = g_queue_peek_head(ctx->action_list_stack); - a = create_action(srv, name->data.string->str, NULL); + a = li_create_action(srv, name->data.string->str, NULL); if (a == NULL) { - value_free(name); + li_value_free(name); return FALSE; } @@ -607,7 +607,7 @@ } } - value_free(name); + li_value_free(name); } action function_param { @@ -621,47 +621,47 @@ 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); + _printf("got function: %s %s; in line %zd\n", name->data.string->str, li_value_type_string(val->type), ctx->line); if (g_str_equal(name->data.string->str, "include")) { 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); + WARNING(srv, "include directive takes a string as parameter, %s given", li_value_type_string(val->type)); + li_value_free(name); + li_value_free(val); return FALSE; } if (!config_parser_file(srv, ctx_stack, val->data.string->str)) { - value_free(name); - value_free(val); + li_value_free(name); + li_value_free(val); return FALSE; } - value_free(val); + li_value_free(val); } else if (g_str_equal(name->data.string->str, "include_shell")) { 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); + WARNING(srv, "include_shell directive takes a string as parameter, %s given", li_value_type_string(val->type)); + li_value_free(name); + li_value_free(val); return FALSE; } if (!config_parser_shell(srv, ctx_stack, val->data.string->str)) { - value_free(name); - value_free(val); + li_value_free(name); + li_value_free(val); return FALSE; } - value_free(val); + li_value_free(val); } /* internal functions */ else if (g_str_has_prefix(name->data.string->str, "__")) { if (g_str_equal(name->data.string->str + 2, "print")) { - GString *tmpstr = value_to_string(val); - g_printerr("%s:%zd type: %s, value: %s\n", ctx->filename, ctx->line, value_type_string(val->type), tmpstr->str); + GString *tmpstr = li_value_to_string(val); + g_printerr("%s:%zd type: %s, value: %s\n", ctx->filename, ctx->line, li_value_type_string(val->type), tmpstr->str); g_string_free(tmpstr, TRUE); - value_free(val); + li_value_free(val); } } /* normal function action */ @@ -669,20 +669,20 @@ /* TODO */ if (ctx->in_setup_block) { /* we are in the setup { } block, call setups and don't append to action list */ - if (!call_setup(srv, name->data.string->str, val)) { - value_free(name); - value_free(val); + if (!li_call_setup(srv, name->data.string->str, val)) { + li_value_free(name); + li_value_free(val); return FALSE; } - value_free(val); + li_value_free(val); } else { al = g_queue_peek_head(ctx->action_list_stack); - a = create_action(srv, name->data.string->str, val); - value_free(val); + a = li_create_action(srv, name->data.string->str, val); + li_value_free(val); if (a == NULL) { - value_free(name); + li_value_free(name); return FALSE; } @@ -690,7 +690,7 @@ } } - value_free(name); + li_value_free(name); } action condition_start { @@ -716,7 +716,7 @@ 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);*/ + /*_printf("got condition: %s:%s %s %s in line %zd\n", n->data.string->str, ctx->condition_with_key ? k->data.string->str : "", li_comp_op_to_string(ctx->op), li_value_type_string(v->type), ctx->line);*/ /* create condition lvalue */ str = n->data.string->str; @@ -733,21 +733,21 @@ } if (g_str_equal(str, "host")) - lvalue = condition_lvalue_new(LI_COMP_REQUEST_HOST, NULL); + lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_HOST, NULL); else if (g_str_equal(str, "path")) - lvalue = condition_lvalue_new(LI_COMP_REQUEST_PATH, NULL); + lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_PATH, NULL); else if (g_str_equal(str, "query")) - lvalue = condition_lvalue_new(LI_COMP_REQUEST_QUERY_STRING, NULL); + lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_QUERY_STRING, NULL); else if (g_str_equal(str, "method")) - lvalue = condition_lvalue_new(LI_COMP_REQUEST_METHOD, NULL); + lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_METHOD, NULL); else if (g_str_equal(str, "scheme")) - lvalue = condition_lvalue_new(LI_COMP_REQUEST_SCHEME, NULL); + lvalue = li_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(LI_COMP_REQUEST_HEADER, value_extract(k).string); + lvalue = li_condition_lvalue_new(LI_COMP_REQUEST_HEADER, li_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(LI_COMP_PHYSICAL_PATH, NULL); + lvalue = li_condition_lvalue_new(LI_COMP_PHYSICAL_PATH, NULL); else if (g_str_equal(str, "exists")) - lvalue = condition_lvalue_new(LI_COMP_PHYSICAL_PATH_EXISTS, NULL); + lvalue = li_condition_lvalue_new(LI_COMP_PHYSICAL_PATH_EXISTS, NULL); else if (g_str_equal(str, "size")) - lvalue = condition_lvalue_new(LI_COMP_PHYSICAL_SIZE, NULL); + lvalue = li_condition_lvalue_new(LI_COMP_PHYSICAL_SIZE, NULL); else if (g_str_equal(str, "is_dir")) - lvalue = condition_lvalue_new(LI_COMP_PHYSICAL_ISDIR, NULL); + lvalue = li_condition_lvalue_new(LI_COMP_PHYSICAL_ISDIR, NULL); else if (g_str_equal(str, "is_file")) - lvalue = condition_lvalue_new(LI_COMP_PHYSICAL_ISFILE, NULL); + lvalue = li_condition_lvalue_new(LI_COMP_PHYSICAL_ISFILE, NULL); else { WARNING(srv, "unkown lvalue for condition: %s", n->data.string->str); return FALSE; @@ -787,16 +787,16 @@ if (ctx->condition_nonbool) { if (v->type == LI_VALUE_STRING) { - cond = condition_new_string(srv, ctx->op, lvalue, value_extract(v).string); + cond = li_condition_new_string(srv, ctx->op, lvalue, li_value_extract(v).string); } else if (v->type == LI_VALUE_NUMBER) - cond = condition_new_int(srv, ctx->op, lvalue, value_extract_number(v)); + cond = li_condition_new_int(srv, ctx->op, lvalue, li_value_extract_number(v)); else { cond = NULL; } } else { /* boolean condition */ - cond = condition_new_bool(srv, lvalue, !ctx->condition_negated); + cond = li_condition_new_bool(srv, lvalue, !ctx->condition_negated); } if (cond == NULL) { @@ -806,12 +806,12 @@ g_queue_push_head(ctx->condition_stack, cond); - g_queue_push_head(ctx->action_list_stack, action_new_list()); + g_queue_push_head(ctx->action_list_stack, li_action_new_list()); - value_free(n); + li_value_free(n); if (ctx->condition_nonbool) { - value_free(k); - value_free(v); + li_value_free(k); + li_value_free(v); } ctx->condition_with_key = FALSE; @@ -825,7 +825,7 @@ cond = g_queue_pop_head(ctx->condition_stack); al = g_queue_pop_head(ctx->action_list_stack); - a = action_new_condition(cond, al, NULL); + a = li_action_new_condition(cond, al, NULL); al = g_queue_peek_head(ctx->action_list_stack); g_array_append_val(al->data.list, a); } @@ -836,7 +836,7 @@ action else_nocond_start { /* start a new action list */ - g_queue_push_head(ctx->action_list_stack, action_new_list()); + g_queue_push_head(ctx->action_list_stack, li_action_new_list()); _printf("got else_nocond_start in line %zd\n", ctx->line); } @@ -916,14 +916,14 @@ _printf("action block %s in line %zd\n", o->data.string->str, ctx->line); /* create new action list and put it on the stack */ - al = action_new_list(); + al = li_action_new_list(); g_queue_push_head(ctx->action_list_stack, al); /* insert into hashtable for later lookups */ str = g_string_new_len(o->data.string->str, o->data.string->len); g_hash_table_insert(ctx->action_blocks, str, al); } - value_free(o); + li_value_free(o); } action action_block_end { @@ -949,7 +949,7 @@ _printf("action block in line %zd\n", ctx->line); /* create new action list and put it on the stack */ - al = action_new_list(); + al = li_action_new_list(); g_queue_push_head(ctx->action_list_stack, al); } @@ -959,7 +959,7 @@ /* pop action list stack */ a = g_queue_pop_head(ctx->action_list_stack); - v = value_new_action(srv, a); + v = li_value_new_action(srv, a); g_queue_push_head(ctx->option_stack, v); } @@ -1039,7 +1039,7 @@ GList *config_parser_init(liServer* srv) { liConfigParserContext *ctx = config_parser_context_new(srv, NULL); - srv->mainaction = action_new_list(); + srv->mainaction = li_action_new_list(); g_queue_push_head(ctx->action_list_stack, srv->mainaction); return g_list_append(NULL, ctx); @@ -1067,7 +1067,7 @@ void config_parser_finish(liServer *srv, GList *ctx_stack, gboolean free_all) { g_hash_table_iter_init(&iter, ctx->action_blocks); while (g_hash_table_iter_next(&iter, &key, &val)) { - action_release(srv, val); + li_action_release(srv, val); g_string_free(key, TRUE); } @@ -1076,7 +1076,7 @@ void config_parser_finish(liServer *srv, GList *ctx_stack, gboolean free_all) { g_hash_table_iter_init(&iter, ctx->uservars); while (g_hash_table_iter_next(&iter, &key, &val)) { - value_free(val); + li_value_free(val); g_string_free(key, TRUE); } @@ -1120,7 +1120,7 @@ liConfigParserContext *config_parser_context_new(liServer *srv, GList *ctx_stack /* initialize var.PID */ /* TODO: what if pid_t is not a 32bit integer? */ - o = value_new_number(getpid()); + o = li_value_new_number(getpid()); str = g_string_new_len(CONST_STR_LEN("var.PID")); g_hash_table_insert(ctx->uservars, str, o); @@ -1128,7 +1128,7 @@ liConfigParserContext *config_parser_context_new(liServer *srv, GList *ctx_stack str = g_string_sized_new(1024); if (NULL != getcwd(str->str, 1023)) { g_string_set_size(str, strlen(str->str)); - o = value_new_string(str); + o = li_value_new_string(str); str = g_string_new_len(CONST_STR_LEN("var.CWD")); g_hash_table_insert(ctx->uservars, str, o); } @@ -1151,13 +1151,13 @@ void config_parser_context_free(liServer *srv, liConfigParserContext *ctx, gbool if (g_queue_get_length(ctx->option_stack) > 0) { liValue *o; while ((o = g_queue_pop_head(ctx->option_stack))) - value_free(o); + li_value_free(o); } if (g_queue_get_length(ctx->condition_stack) > 0) { liCondition *c; while ((c = g_queue_pop_head(ctx->condition_stack))) - condition_release(srv, c); + li_condition_release(srv, c); } g_queue_free(ctx->action_list_stack); diff --git a/src/connection.c b/src/connection.c index 301574f..265728d 100644 --- a/src/connection.c +++ b/src/connection.c @@ -7,22 +7,22 @@ void worker_con_put(liConnection *con); /* worker.c */ 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); + li_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 */ - chunkqueue_steal_all(con->in, con->raw_in); + li_chunkqueue_steal_all(con->in, con->raw_in); } else { if (con->in->bytes_in < con->mainvr->request.content_length) { - chunkqueue_steal_len(con->in, con->raw_in, con->mainvr->request.content_length - con->in->bytes_in); + li_chunkqueue_steal_len(con->in, con->raw_in, con->mainvr->request.content_length - con->in->bytes_in); } if (con->in->bytes_in == con->mainvr->request.content_length) { con->in->is_closed = TRUE; - ev_io_rem_events(con->wrk->loop, &con->sock_watcher, EV_READ); + li_ev_io_rem_events(con->wrk->loop, &con->sock_watcher, EV_READ); } } - vrequest_handle_request_body(con->mainvr); + li_vrequest_handle_request_body(con->mainvr); } else { - ev_io_rem_events(con->wrk->loop, &con->sock_watcher, EV_READ); + li_ev_io_rem_events(con->wrk->loop, &con->sock_watcher, EV_READ); } } @@ -34,22 +34,22 @@ static void forward_response_body(liConnection *con) { if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "write response headers"); } - response_send_headers(con); + li_response_send_headers(con); } if (vr->response.transfer_encoding & LI_HTTP_TRANSFER_ENCODING_CHUNKED) { - filter_chunked_encode(con, con->raw_out, con->out); + li_filter_chunked_encode(con, con->raw_out, con->out); } else { - chunkqueue_steal_all(con->raw_out, con->out); + li_chunkqueue_steal_all(con->raw_out, con->out); } if (con->out->is_closed) con->raw_out->is_closed = TRUE; if (con->raw_out->length > 0) { - ev_io_add_events(con->wrk->loop, &con->sock_watcher, EV_WRITE); + li_ev_io_add_events(con->wrk->loop, &con->sock_watcher, EV_WRITE); } else { - ev_io_rem_events(con->wrk->loop, &con->sock_watcher, EV_WRITE); + li_ev_io_rem_events(con->wrk->loop, &con->sock_watcher, EV_WRITE); } } else { - ev_io_rem_events(con->wrk->loop, &con->sock_watcher, EV_WRITE); + li_ev_io_rem_events(con->wrk->loop, &con->sock_watcher, EV_WRITE); } } @@ -59,10 +59,10 @@ static void connection_request_done(liConnection *con) { VR_DEBUG(con->mainvr, "response end (keep_alive = %i)", con->keep_alive); } - plugins_handle_close(con); + li_plugins_handle_close(con); if (con->keep_alive && g_atomic_int_get(&con->srv->state) == LI_SERVER_RUNNING) { - connection_reset_keep_alive(con); + li_connection_reset_keep_alive(con); } else { worker_con_put(con); } @@ -82,41 +82,41 @@ static void connection_close(liConnection *con) { VR_DEBUG(vr, "%s", "connection closed"); } - plugins_handle_close(con); + li_plugins_handle_close(con); worker_con_put(con); } -void connection_error(liConnection *con) { +void li_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)"); } - plugins_handle_close(con); + li_plugins_handle_close(con); worker_con_put(con); } -void connection_internal_error(liConnection *con) { +void li_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); + li_connection_error(con); } else { liHttpVersion v; VR_ERROR(vr, "%s", "internal error"); /* We only need the http version from the http request */ v = con->mainvr->request.http_version; - vrequest_reset(con->mainvr); + li_vrequest_reset(con->mainvr); con->mainvr->request.http_version = v; con->keep_alive = FALSE; con->mainvr->response.http_status = 500; con->state = LI_CON_STATE_WRITE; /* skips further vrequest handling */ - chunkqueue_reset(con->out); + li_chunkqueue_reset(con->out); con->out->is_closed = TRUE; con->in->is_closed = TRUE; forward_response_body(con); @@ -154,7 +154,7 @@ static gboolean connection_handle_read(liConnection *con) { 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)) { + switch(li_http_request_parse(con->mainvr, &con->req_parser_ctx)) { case LI_HANDLER_GO_ON: break; /* go on */ case LI_HANDLER_WAIT_FOR_EVENT: @@ -162,7 +162,7 @@ static gboolean connection_handle_read(liConnection *con) { case LI_HANDLER_ERROR: case LI_HANDLER_COMEBACK: /* unexpected */ /* unparsable header */ - connection_error(con); + li_connection_error(con); return FALSE; } @@ -172,7 +172,7 @@ static gboolean connection_handle_read(liConnection *con) { if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "validating request header"); } - if (!request_validate_header(con)) { + if (!li_request_validate_header(con)) { /* skip mainvr handling */ con->state = LI_CON_STATE_WRITE; con->keep_alive = FALSE; @@ -188,14 +188,14 @@ static gboolean connection_handle_read(liConnection *con) { 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")); + li_chunkqueue_append_mem(con->raw_out, CONST_STR_LEN("HTTP/1.1 100 Continue\r\n\r\n")); con->expect_100_cont = FALSE; - ev_io_add_events(con->wrk->loop, &con->sock_watcher, EV_WRITE); + li_ev_io_add_events(con->wrk->loop, &con->sock_watcher, EV_WRITE); } con->state = LI_CON_STATE_HANDLE_MAINVR; - action_enter(con->mainvr, con->srv->mainaction); - vrequest_handle_request_headers(con->mainvr); + li_action_enter(con->mainvr, con->srv->mainaction); + li_vrequest_handle_request_headers(con->mainvr); } } else { parse_request_body(con); @@ -213,11 +213,11 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) { if (revents & EV_READ) { if (con->in->is_closed) { /* don't read the next request before current one is done */ - ev_io_rem_events(loop, w, EV_READ); + li_ev_io_rem_events(loop, w, EV_READ); } else { transferred = con->raw_in->length; - res = network_read(con->mainvr, w->fd, con->raw_in); + res = li_network_read(con->mainvr, w->fd, con->raw_in); transferred = con->raw_in->length - transferred; con->wrk->stats.bytes_in += transferred; @@ -229,7 +229,7 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) { break; case LI_NETWORK_STATUS_FATAL_ERROR: _ERROR(con->srv, con->mainvr, "%s", "network read fatal error"); - connection_error(con); + li_connection_error(con); return; case LI_NETWORK_STATUS_CONNECTION_CLOSE: con->raw_in->is_closed = TRUE; @@ -240,7 +240,7 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) { break; case LI_NETWORK_STATUS_WAIT_FOR_AIO_EVENT: /* TODO: aio */ - ev_io_rem_events(loop, w, EV_READ); + li_ev_io_rem_events(loop, w, EV_READ); break; } } @@ -257,7 +257,7 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) { if (write_max > 0) { transferred = con->raw_out->length; - res = network_write(con->mainvr, w->fd, con->raw_out, write_max); + res = li_network_write(con->mainvr, w->fd, con->raw_out, write_max); transferred = transferred - con->raw_out->length; con->wrk->stats.bytes_out += transferred; @@ -265,11 +265,11 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) { switch (res) { case LI_NETWORK_STATUS_SUCCESS: - vrequest_joblist_append(con->mainvr); + li_vrequest_joblist_append(con->mainvr); break; case LI_NETWORK_STATUS_FATAL_ERROR: _ERROR(con->srv, con->mainvr, "%s", "network write fatal error"); - connection_error(con); + li_connection_error(con); return; case LI_NETWORK_STATUS_CONNECTION_CLOSE: connection_close(con); @@ -277,7 +277,7 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) { case LI_NETWORK_STATUS_WAIT_FOR_EVENT: break; case LI_NETWORK_STATUS_WAIT_FOR_AIO_EVENT: - ev_io_rem_events(loop, w, EV_WRITE); + li_ev_io_rem_events(loop, w, EV_WRITE); _ERROR(con->srv, con->mainvr, "%s", "TODO: wait for aio"); /* TODO: aio */ break; @@ -299,8 +299,8 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) { /*g_print("%p wrote %"G_GINT64_FORMAT"/%"G_GINT64_FORMAT" bytes, mags: %d/%d, queued: %s\n", (void*)con, transferred, write_max, con->throttle.pool.magazine, con->throttle.con.magazine, con->throttle.pool.queued ? "yes":"no");*/ if (con->throttle.con.magazine <= 0) { - ev_io_rem_events(loop, w, EV_WRITE); - waitqueue_push(&con->wrk->throttle_queue, &con->throttle.wqueue_elem); + li_ev_io_rem_events(loop, w, EV_WRITE); + li_waitqueue_push(&con->wrk->throttle_queue, &con->throttle.wqueue_elem); } if (con->throttle.pool.ptr && con->throttle.pool.magazine <= MAX(write_max,0) && !con->throttle.pool.queued) { @@ -312,12 +312,12 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) { } } else { _DEBUG(con->srv, con->mainvr, "%s", "write event for empty queue"); - ev_io_rem_events(loop, w, EV_WRITE); + li_ev_io_rem_events(loop, w, EV_WRITE); } } if ((con->io_timeout_elem.ts + 1.0) < ev_now(loop)) - waitqueue_push(&con->wrk->io_timeout_queue, &con->io_timeout_elem); + li_waitqueue_push(&con->wrk->io_timeout_queue, &con->io_timeout_elem); check_response_done(con); } @@ -355,7 +355,7 @@ static liHandlerResult mainvr_handle_response_body(liVRequest *vr) { } static liHandlerResult mainvr_handle_response_error(liVRequest *vr) { - connection_internal_error(vr->con); + li_connection_internal_error(vr->con); return LI_HANDLER_GO_ON; } @@ -365,7 +365,7 @@ static liHandlerResult mainvr_handle_request_headers(liVRequest *vr) { return LI_HANDLER_GO_ON; } -liConnection* connection_new(liWorker *wrk) { +liConnection* li_connection_new(liWorker *wrk) { liServer *srv = wrk->srv; liConnection *con = g_slice_new0(liConnection); con->wrk = wrk; @@ -381,25 +381,25 @@ liConnection* connection_new(liWorker *wrk) { con->remote_addr_str = g_string_sized_new(INET6_ADDRSTRLEN); con->keep_alive = TRUE; - con->raw_in = chunkqueue_new(); - con->raw_out = chunkqueue_new(); + con->raw_in = li_chunkqueue_new(); + con->raw_out = li_chunkqueue_new(); - con->mainvr = vrequest_new(con, + con->mainvr = li_vrequest_new(con, mainvr_handle_response_headers, mainvr_handle_response_body, mainvr_handle_response_error, mainvr_handle_request_headers); - http_request_parser_init(&con->req_parser_ctx, &con->mainvr->request, con->raw_in); + li_http_request_parser_init(&con->req_parser_ctx, &con->mainvr->request, con->raw_in); con->in = con->mainvr->vr_in; con->out = con->mainvr->vr_out; - chunkqueue_use_limit(con->raw_in, con->mainvr); - chunkqueue_use_limit(con->raw_out, con->mainvr); - chunkqueue_set_limit(con->mainvr->vr_in, con->raw_in->limit); - chunkqueue_set_limit(con->mainvr->vr_out, con->raw_out->limit); - chunkqueue_set_limit(con->mainvr->in, con->raw_in->limit); - chunkqueue_set_limit(con->mainvr->out, con->raw_out->limit); + li_chunkqueue_use_limit(con->raw_in, con->mainvr); + li_chunkqueue_use_limit(con->raw_out, con->mainvr); + li_chunkqueue_set_limit(con->mainvr->vr_in, con->raw_in->limit); + li_chunkqueue_set_limit(con->mainvr->vr_out, con->raw_out->limit); + li_chunkqueue_set_limit(con->mainvr->in, con->raw_in->limit); + li_chunkqueue_set_limit(con->mainvr->out, con->raw_out->limit); con->keep_alive_data.link = NULL; con->keep_alive_data.timeout = 0; @@ -416,12 +416,12 @@ liConnection* connection_new(liWorker *wrk) { return con; } -void connection_reset(liConnection *con) { +void li_connection_reset(liConnection *con) { con->state = LI_CON_STATE_DEAD; con->response_headers_sent = FALSE; con->expect_100_cont = FALSE; - server_socket_release(con->srv_sock); + li_server_socket_release(con->srv_sock); con->srv_sock = NULL; ev_io_stop(con->wrk->loop, &con->sock_watcher); @@ -430,22 +430,22 @@ void connection_reset(liConnection *con) { shutdown(con->sock_watcher.fd, SHUT_WR); close(con->sock_watcher.fd); } else { - worker_add_closing_socket(con->wrk, con->sock_watcher.fd); + li_worker_add_closing_socket(con->wrk, con->sock_watcher.fd); } } ev_io_set(&con->sock_watcher, -1, 0); - vrequest_reset(con->mainvr); - http_request_parser_reset(&con->req_parser_ctx); + li_vrequest_reset(con->mainvr); + li_http_request_parser_reset(&con->req_parser_ctx); g_string_truncate(con->remote_addr_str, 0); - sockaddr_clear(&con->remote_addr); + li_sockaddr_clear(&con->remote_addr); con->keep_alive = TRUE; - chunkqueue_reset(con->raw_in); - chunkqueue_reset(con->raw_out); - cqlimit_reset(con->raw_in->limit); - cqlimit_reset(con->raw_out->limit); + li_chunkqueue_reset(con->raw_in); + li_chunkqueue_reset(con->raw_out); + li_cqlimit_reset(con->raw_in->limit); + li_cqlimit_reset(con->raw_out->limit); if (con->keep_alive_data.link) { g_queue_delete_link(&con->wrk->keep_alive_queue, con->keep_alive_data.link); @@ -466,10 +466,10 @@ void connection_reset(liConnection *con) { con->stats.last_avg = 0; /* remove from timeout queue */ - waitqueue_remove(&con->wrk->io_timeout_queue, &con->io_timeout_elem); + li_waitqueue_remove(&con->wrk->io_timeout_queue, &con->io_timeout_elem); /* remove from throttle queue */ - waitqueue_remove(&con->wrk->throttle_queue, &con->throttle.wqueue_elem); + li_waitqueue_remove(&con->wrk->throttle_queue, &con->throttle.wqueue_elem); if (con->throttle.pool.ptr) { if (con->throttle.pool.queued) { @@ -507,7 +507,7 @@ void connection_reset(liConnection *con) { } void server_check_keepalive(liServer *srv); -void connection_reset_keep_alive(liConnection *con) { +void li_connection_reset_keep_alive(liConnection *con) { liVRequest *vr = con->mainvr; ev_timer_stop(con->wrk->loop, &con->keep_alive_data.watcher); { @@ -523,7 +523,7 @@ void connection_reset_keep_alive(liConnection *con) { g_queue_push_tail(&con->wrk->keep_alive_queue, con); con->keep_alive_data.link = g_queue_peek_tail_link(&con->wrk->keep_alive_queue); if (need_start) - worker_check_keepalive(con->wrk); + li_worker_check_keepalive(con->wrk); } else { ev_timer_set(&con->keep_alive_data.watcher, con->keep_alive_data.max_idle, 0); ev_timer_start(con->wrk->loop, &con->keep_alive_data.watcher); @@ -534,13 +534,13 @@ void connection_reset_keep_alive(liConnection *con) { con->response_headers_sent = FALSE; con->expect_100_cont = FALSE; - ev_io_set_events(con->wrk->loop, &con->sock_watcher, EV_READ); + li_ev_io_set_events(con->wrk->loop, &con->sock_watcher, EV_READ); con->keep_alive = TRUE; con->raw_out->is_closed = FALSE; - vrequest_reset(con->mainvr); - http_request_parser_reset(&con->req_parser_ctx); + li_vrequest_reset(con->mainvr); + li_http_request_parser_reset(&con->req_parser_ctx); con->ts = CUR_TS(con->wrk); @@ -554,9 +554,9 @@ void connection_reset_keep_alive(liConnection *con) { con->stats.last_avg = 0; /* remove from timeout queue */ - waitqueue_remove(&con->wrk->io_timeout_queue, &con->io_timeout_elem); + li_waitqueue_remove(&con->wrk->io_timeout_queue, &con->io_timeout_elem); /* remove from throttle queue */ - waitqueue_remove(&con->wrk->throttle_queue, &con->throttle.wqueue_elem); + li_waitqueue_remove(&con->wrk->throttle_queue, &con->throttle.wqueue_elem); if (con->throttle.pool.ptr) { if (con->throttle.pool.queued) { @@ -593,12 +593,12 @@ void connection_reset_keep_alive(liConnection *con) { con->throttled = FALSE; } -void connection_free(liConnection *con) { +void li_connection_free(liConnection *con) { con->state = LI_CON_STATE_DEAD; con->response_headers_sent = FALSE; con->expect_100_cont = FALSE; - server_socket_release(con->srv_sock); + li_server_socket_release(con->srv_sock); con->srv_sock = NULL; if (con->wrk) @@ -610,14 +610,14 @@ void connection_free(liConnection *con) { } ev_io_set(&con->sock_watcher, -1, 0); g_string_free(con->remote_addr_str, TRUE); - sockaddr_clear(&con->remote_addr); + li_sockaddr_clear(&con->remote_addr); con->keep_alive = TRUE; - chunkqueue_free(con->raw_in); - chunkqueue_free(con->raw_out); + li_chunkqueue_free(con->raw_in); + li_chunkqueue_free(con->raw_out); - vrequest_free(con->mainvr); - http_request_parser_clear(&con->req_parser_ctx); + li_vrequest_free(con->mainvr); + li_http_request_parser_clear(&con->req_parser_ctx); if (con->keep_alive_data.link && con->wrk) { g_queue_delete_link(&con->wrk->keep_alive_queue, con->keep_alive_data.link); @@ -631,7 +631,7 @@ void connection_free(liConnection *con) { g_slice_free(liConnection, con); } -gchar *connection_state_str(liConnectionState state) { +gchar *li_connection_state_str(liConnectionState state) { static const gchar *states[] = { "dead", "keep-alive", diff --git a/src/environment.c b/src/environment.c index 2a1ed18..6634ef9 100644 --- a/src/environment.c +++ b/src/environment.c @@ -5,28 +5,28 @@ static void _hash_free_gstring(gpointer data) { g_string_free((GString*) data, TRUE); } -void environment_init(liEnvironment *env) { +void li_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(liEnvironment *env) { +void li_environment_reset(liEnvironment *env) { g_hash_table_remove_all(env->table); } -void environment_clear(liEnvironment *env) { +void li_environment_clear(liEnvironment *env) { g_hash_table_destroy(env->table); } -void environment_set(liEnvironment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { +void li_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(liEnvironment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { - GString *sval = environment_get(env, key, keylen), *skey; +void li_environment_insert(liEnvironment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { + GString *sval = li_environment_get(env, key, keylen), *skey; if (!sval) { skey = g_string_new_len(key, keylen); sval = g_string_new_len(val, valuelen); @@ -34,17 +34,17 @@ void environment_insert(liEnvironment *env, const gchar *key, size_t keylen, con } } -void environment_remove(liEnvironment *env, const gchar *key, size_t keylen) { +void li_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(liEnvironment *env, const gchar *key, size_t keylen) { +GString* li_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); } -liEnvironmentDup* environment_make_dup(liEnvironment *env) { +liEnvironmentDup* li_environment_make_dup(liEnvironment *env) { GHashTableIter i; GHashTable *tdst; gpointer key, val; @@ -58,12 +58,12 @@ liEnvironmentDup* environment_make_dup(liEnvironment *env) { return envdup; } -void environment_dup_free(liEnvironmentDup *envdup) { +void li_environment_dup_free(liEnvironmentDup *envdup) { g_hash_table_destroy(envdup->table); g_slice_free(liEnvironmentDup, envdup); } -GString* environment_dup_pop(liEnvironmentDup *envdup, const gchar *key, size_t keylen) { +GString* li_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 ca051ae..5b71d49 100644 --- a/src/etag.c +++ b/src/etag.c @@ -2,22 +2,22 @@ #include #include -tristate_t http_response_handle_cachable_etag(liVRequest *vr, GString *etag) { +tristate_t li_http_response_handle_cachable_etag(liVRequest *vr, GString *etag) { GList *l; tristate_t res = TRI_MAYBE; gchar *setag = NULL; if (!etag) { - liHttpHeader *hetag = http_header_lookup(vr->response.headers, CONST_STR_LEN("etag")); + liHttpHeader *hetag = li_http_header_lookup(vr->response.headers, CONST_STR_LEN("etag")); if (hetag) setag = hetag->data->str + hetag->keylen + 2; } else { setag = etag->str; } for ( - l = http_header_find_first(vr->request.headers, CONST_STR_LEN("If-None-Match")); + l = li_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"))) { + l = li_http_header_find_next(l, CONST_STR_LEN("If-None-Match"))) { liHttpHeader *h = (liHttpHeader*) l->data; res = TRI_FALSE; /* if the header was given at least once, we need a match */ if (!setag) return res; @@ -28,7 +28,7 @@ tristate_t http_response_handle_cachable_etag(liVRequest *vr, GString *etag) { return res; } -tristate_t http_response_handle_cachable_modified(liVRequest *vr, GString *last_modified) { +tristate_t li_http_response_handle_cachable_modified(liVRequest *vr, GString *last_modified) { GList *l; gchar *slm = NULL, *hlm; liHttpHeader *h; @@ -36,15 +36,15 @@ tristate_t http_response_handle_cachable_modified(liVRequest *vr, GString *last_ char *semicolon; if (!last_modified) { - h = http_header_lookup(vr->response.headers, CONST_STR_LEN("last-modified")); + h = li_http_header_lookup(vr->response.headers, CONST_STR_LEN("last-modified")); if (h) slm = h->data->str + h->keylen + 2; } else { slm = last_modified->str; } - l = http_header_find_first(vr->request.headers, CONST_STR_LEN("If-Modified-Since")); + l = li_http_header_find_first(vr->request.headers, CONST_STR_LEN("If-Modified-Since")); if (!l) return TRI_MAYBE; /* no if-modified-since header */ - if (http_header_find_next(l, CONST_STR_LEN("If-Modified-Since"))) { + if (li_http_header_find_next(l, CONST_STR_LEN("If-Modified-Since"))) { return TRI_FALSE; /* we only check one if-modified-since header */ } h = (liHttpHeader*) l->data; @@ -94,7 +94,7 @@ tristate_t http_response_handle_cachable_modified(liVRequest *vr, GString *last_ } } -void etag_mutate(GString *mut, GString *etag) { +void li_etag_mutate(GString *mut, GString *etag) { guint i; guint32 h; @@ -102,41 +102,41 @@ void etag_mutate(GString *mut, GString *etag) { g_string_truncate(mut, 0); g_string_append_len(mut, CONST_STR_LEN("\"")); - l_g_string_append_int(mut, (guint64) h); + li_string_append_int(mut, (guint64) h); g_string_append_len(mut, CONST_STR_LEN("\"")); } -void etag_set_header(liVRequest *vr, struct stat *st, gboolean *cachable) { +void li_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; if (0 == flags) { - http_header_remove(vr->response.headers, CONST_STR_LEN("etag")); + li_http_header_remove(vr->response.headers, CONST_STR_LEN("etag")); } else { g_string_truncate(tmp_str, 0); if (flags & LI_ETAG_USE_INODE) { - l_g_string_append_int(tmp_str, st->st_ino); + li_string_append_int(tmp_str, st->st_ino); } 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); + li_string_append_int(tmp_str, st->st_size); } 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); + li_string_append_int(tmp_str, st->st_mtime); } - etag_mutate(tmp_str, tmp_str); + li_etag_mutate(tmp_str, tmp_str); - http_header_overwrite(vr->response.headers, CONST_STR_LEN("ETag"), GSTR_LEN(tmp_str)); + li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("ETag"), GSTR_LEN(tmp_str)); if (c_able != TRI_FALSE) { - switch (http_response_handle_cachable_etag(vr, tmp_str)) { + switch (li_http_response_handle_cachable_etag(vr, tmp_str)) { case TRI_FALSE: c_able = TRI_FALSE; break; case TRI_MAYBE: break; case TRI_TRUE : c_able = TRI_TRUE; break; @@ -148,10 +148,10 @@ void etag_set_header(liVRequest *vr, struct stat *st, gboolean *cachable) { g_string_set_size(tmp_str, 256); g_string_set_size(tmp_str, strftime(tmp_str->str, tmp_str->len-1, "%a, %d %b %Y %H:%M:%S GMT", &tm)); - http_header_overwrite(vr->response.headers, CONST_STR_LEN("Last-Modified"), GSTR_LEN(tmp_str)); + li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Last-Modified"), GSTR_LEN(tmp_str)); if (c_able != TRI_FALSE) { - switch (http_response_handle_cachable_modified(vr, tmp_str)) { + switch (li_http_response_handle_cachable_modified(vr, tmp_str)) { case TRI_FALSE: c_able = TRI_FALSE; break; case TRI_MAYBE: break; case TRI_TRUE : c_able = TRI_TRUE; break; diff --git a/src/filter_chunked.c b/src/filter_chunked.c index b8cda8f..78209be 100644 --- a/src/filter_chunked.c +++ b/src/filter_chunked.c @@ -21,21 +21,21 @@ static void http_chunk_append_len(liChunkQueue *cq, size_t len) { } g_byte_array_append(a, (guint8*) CONST_STR_LEN("\r\n")); - chunkqueue_append_bytearr(cq, a); + li_chunkqueue_append_bytearr(cq, a); } -liHandlerResult filter_chunked_encode(liConnection *con, liChunkQueue *out, liChunkQueue *in) { +liHandlerResult li_filter_chunked_encode(liConnection *con, liChunkQueue *out, liChunkQueue *in) { UNUSED(con); if (in->length > 0) { http_chunk_append_len(out, in->length); - chunkqueue_steal_all(out, in); - chunkqueue_append_mem(out, CONST_STR_LEN("\r\n")); + li_chunkqueue_steal_all(out, in); + li_chunkqueue_append_mem(out, CONST_STR_LEN("\r\n")); } if (in->is_closed) { if (!out->is_closed) { - chunkqueue_append_mem(out, CONST_STR_LEN("0\r\n\r\n")); + li_chunkqueue_append_mem(out, CONST_STR_LEN("0\r\n\r\n")); out->is_closed = TRUE; } return LI_HANDLER_GO_ON; @@ -43,7 +43,7 @@ liHandlerResult filter_chunked_encode(liConnection *con, liChunkQueue *out, liCh return LI_HANDLER_GO_ON; } -liHandlerResult filter_chunked_decode(liConnection *con, liChunkQueue *out, liChunkQueue *in) { +liHandlerResult li_filter_chunked_decode(liConnection *con, liChunkQueue *out, liChunkQueue *in) { UNUSED(con); UNUSED(out); UNUSED(in); diff --git a/src/http_headers.c b/src/http_headers.c index 53978b6..65a153b 100644 --- a/src/http_headers.c +++ b/src/http_headers.c @@ -22,18 +22,18 @@ static void _header_queue_free(gpointer data, gpointer userdata) { _http_header_free((liHttpHeader*) data); } -liHttpHeaders* http_headers_new() { +liHttpHeaders* li_http_headers_new() { liHttpHeaders* headers = g_slice_new0(liHttpHeaders); g_queue_init(&headers->entries); return headers; } -void http_headers_reset(liHttpHeaders* headers) { +void li_http_headers_reset(liHttpHeaders* headers) { g_queue_foreach(&headers->entries, _header_queue_free, NULL); g_queue_clear(&headers->entries); } -void http_headers_free(liHttpHeaders* headers) { +void li_http_headers_free(liHttpHeaders* headers) { if (!headers) return; g_queue_foreach(&headers->entries, _header_queue_free, NULL); g_queue_clear(&headers->entries); @@ -41,12 +41,12 @@ void http_headers_free(liHttpHeaders* headers) { } /** just insert normal header, allow duplicates */ -void http_header_insert(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { +void li_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(liHttpHeaders *headers, const gchar *key, size_t keylen) { +GList* li_http_header_find_first(liHttpHeaders *headers, const gchar *key, size_t keylen) { liHttpHeader *h; GList *l; @@ -57,7 +57,7 @@ GList* http_header_find_first(liHttpHeaders *headers, const gchar *key, size_t k return NULL; } -GList* http_header_find_next(GList *l, const gchar *key, size_t keylen) { +GList* li_http_header_find_next(GList *l, const gchar *key, size_t keylen) { liHttpHeader *h; for (l = g_list_next(l); l; l = g_list_next(l)) { @@ -67,7 +67,7 @@ GList* http_header_find_next(GList *l, const gchar *key, size_t keylen) { return NULL; } -GList* http_header_find_last(liHttpHeaders *headers, const gchar *key, size_t keylen) { +GList* li_http_header_find_last(liHttpHeaders *headers, const gchar *key, size_t keylen) { liHttpHeader *h; GList *l; @@ -79,13 +79,13 @@ GList* http_header_find_last(liHttpHeaders *headers, const gchar *key, size_t ke } /** If header does not exist, just insert normal header. If it exists, append (", %s", value) to the last inserted one */ -void http_header_append(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { +void li_http_header_append(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { GList *l; liHttpHeader *h; - l = http_header_find_last(headers, key, keylen); + l = li_http_header_find_last(headers, key, keylen); if (NULL == l) { - http_header_insert(headers, key, keylen, val, valuelen); + li_http_header_insert(headers, key, keylen, val, valuelen); } else { h = (liHttpHeader*) l->data; g_string_append_len(h->data, CONST_STR_LEN(", ")); @@ -94,13 +94,13 @@ void http_header_append(liHttpHeaders *headers, const gchar *key, size_t keylen, } /** If header does not exist, just insert normal header. If it exists, overwrite the last occurrence */ -void http_header_overwrite(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { +void li_http_header_overwrite(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { GList *l; liHttpHeader *h; - l = http_header_find_last(headers, key, keylen); + l = li_http_header_find_last(headers, key, keylen); if (NULL == l) { - http_header_insert(headers, key, keylen, val, valuelen); + li_http_header_insert(headers, key, keylen, val, valuelen); } else { h = (liHttpHeader*) l->data; g_string_truncate(h->data, 0); @@ -110,43 +110,43 @@ void http_header_overwrite(liHttpHeaders *headers, const gchar *key, size_t keyl } } -void http_header_remove_link(liHttpHeaders *headers, GList *l) { +void li_http_header_remove_link(liHttpHeaders *headers, GList *l) { _http_header_free(l->data); g_queue_delete_link(&headers->entries, l); } -gboolean http_header_remove(liHttpHeaders *headers, const gchar *key, size_t keylen) { +gboolean li_http_header_remove(liHttpHeaders *headers, const gchar *key, size_t keylen) { GList *l, *lp = NULL; gboolean res = FALSE; - for (l = http_header_find_first(headers, key, keylen); l; l = http_header_find_next(l, key, keylen)) { + for (l = li_http_header_find_first(headers, key, keylen); l; l = li_http_header_find_next(l, key, keylen)) { if (lp) { - http_header_remove_link(headers, lp); + li_http_header_remove_link(headers, lp); res = TRUE; lp = NULL; } lp = l; } if (lp) { - http_header_remove_link(headers, lp); + li_http_header_remove_link(headers, lp); res = TRUE; lp = NULL; } return res; } -liHttpHeader* http_header_lookup(liHttpHeaders *headers, const gchar *key, size_t keylen) { +liHttpHeader* li_http_header_lookup(liHttpHeaders *headers, const gchar *key, size_t keylen) { GList *l; - l = http_header_find_last(headers, key, keylen); + l = li_http_header_find_last(headers, key, keylen); return NULL == l ? NULL : (liHttpHeader*) l->data; } -gboolean http_header_is(liHttpHeaders *headers, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) { +gboolean li_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)) { + for (l = li_http_header_find_first(headers, key, keylen); l; l = li_http_header_find_next(l, key, keylen)) { 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; @@ -154,11 +154,11 @@ gboolean http_header_is(liHttpHeaders *headers, const gchar *key, size_t keylen, return FALSE; } -void http_header_get_fast(GString *dest, liHttpHeaders *headers, const gchar *key, size_t keylen) { +void li_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)) { + for (l = li_http_header_find_first(headers, key, keylen); l; l = li_http_header_find_next(l, key, keylen)) { 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 7caf113..7adfcac 100644 --- a/src/http_request_parser.rl +++ b/src/http_request_parser.rl @@ -4,16 +4,16 @@ /** Machine **/ -#define _getString(M, FPC) (chunk_extract(vr, ctx->M, GETMARK(FPC))) +#define _getString(M, FPC) (li_chunk_extract(vr, ctx->M, GETMARK(FPC))) #define getString(FPC) _getString(mark, FPC) -#define _getStringTo(M, FPC, s) (chunk_extract_to(vr, ctx->M, GETMARK(FPC), s)) +#define _getStringTo(M, FPC, s) (li_chunk_extract_to(vr, ctx->M, GETMARK(FPC), s)) #define getStringTo(FPC, s) _getStringTo(mark, FPC, s) %%{ - machine http_request_parser; + machine li_http_request_parser; variable cs ctx->chunk_ctx.cs; action mark { ctx->mark = GETMARK(fpc); } @@ -30,7 +30,7 @@ getStringTo(fpc, ctx->h_value); } action header { - http_header_insert(ctx->request->headers, GSTR_LEN(ctx->h_key), GSTR_LEN(ctx->h_value)); + li_http_header_insert(ctx->request->headers, GSTR_LEN(ctx->h_key), GSTR_LEN(ctx->h_value)); } # RFC 2616 @@ -118,16 +118,16 @@ %% write data; -static int http_request_parser_has_error(liHttpRequestCtx *ctx) { - return ctx->chunk_ctx.cs == http_request_parser_error; +static int li_http_request_parser_has_error(liHttpRequestCtx *ctx) { + return ctx->chunk_ctx.cs == li_http_request_parser_error; } -static int http_request_parser_is_finished(liHttpRequestCtx *ctx) { - return ctx->chunk_ctx.cs >= http_request_parser_first_final; +static int li_http_request_parser_is_finished(liHttpRequestCtx *ctx) { + return ctx->chunk_ctx.cs >= li_http_request_parser_first_final; } -void http_request_parser_init(liHttpRequestCtx* ctx, liRequest *req, liChunkQueue *cq) { - chunk_parser_init(&ctx->chunk_ctx, cq); +void li_http_request_parser_init(liHttpRequestCtx* ctx, liRequest *req, liChunkQueue *cq) { + li_chunk_parser_init(&ctx->chunk_ctx, cq); ctx->request = req; ctx->h_key = g_string_sized_new(0); ctx->h_value = g_string_sized_new(0); @@ -135,39 +135,39 @@ void http_request_parser_init(liHttpRequestCtx* ctx, liRequest *req, liChunkQueu %% write init; } -void http_request_parser_reset(liHttpRequestCtx* ctx) { - chunk_parser_reset(&ctx->chunk_ctx); +void li_http_request_parser_reset(liHttpRequestCtx* ctx) { + li_chunk_parser_reset(&ctx->chunk_ctx); g_string_truncate(ctx->h_key, 0); g_string_truncate(ctx->h_value, 0); %% write init; } -void http_request_parser_clear(liHttpRequestCtx *ctx) { +void li_http_request_parser_clear(liHttpRequestCtx *ctx) { g_string_free(ctx->h_key, TRUE); g_string_free(ctx->h_value, TRUE); } -liHandlerResult http_request_parse(liVRequest *vr, liHttpRequestCtx *ctx) { +liHandlerResult li_http_request_parse(liVRequest *vr, liHttpRequestCtx *ctx) { liHandlerResult res; - if (http_request_parser_is_finished(ctx)) return LI_HANDLER_GO_ON; + if (li_http_request_parser_is_finished(ctx)) return LI_HANDLER_GO_ON; - if (LI_HANDLER_GO_ON != (res = chunk_parser_prepare(&ctx->chunk_ctx))) return res; + if (LI_HANDLER_GO_ON != (res = li_chunk_parser_prepare(&ctx->chunk_ctx))) return res; - while (!http_request_parser_has_error(ctx) && !http_request_parser_is_finished(ctx)) { + while (!li_http_request_parser_has_error(ctx) && !li_http_request_parser_is_finished(ctx)) { char *p, *pe; - if (LI_HANDLER_GO_ON != (res = chunk_parser_next(vr, &ctx->chunk_ctx, &p, &pe))) return res; + if (LI_HANDLER_GO_ON != (res = li_chunk_parser_next(vr, &ctx->chunk_ctx, &p, &pe))) return res; %% write exec; - chunk_parser_done(&ctx->chunk_ctx, p - ctx->chunk_ctx.buf); + li_chunk_parser_done(&ctx->chunk_ctx, p - ctx->chunk_ctx.buf); } - 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); + if (li_http_request_parser_has_error(ctx)) return LI_HANDLER_ERROR; + if (li_http_request_parser_is_finished(ctx)) { + li_chunkqueue_skip(ctx->chunk_ctx.cq, ctx->chunk_ctx.bytes_in); return LI_HANDLER_GO_ON; } return LI_HANDLER_ERROR; diff --git a/src/http_response_parser.rl b/src/http_response_parser.rl index 89508e8..50973f0 100644 --- a/src/http_response_parser.rl +++ b/src/http_response_parser.rl @@ -4,16 +4,16 @@ /** Machine **/ -#define _getString(M, FPC) (chunk_extract(vr, ctx->M, GETMARK(FPC))) +#define _getString(M, FPC) (li_chunk_extract(vr, ctx->M, GETMARK(FPC))) #define getString(FPC) _getString(mark, FPC) -#define _getStringTo(M, FPC, s) (chunk_extract_to(vr, ctx->M, GETMARK(FPC), s)) +#define _getStringTo(M, FPC, s) (li_chunk_extract_to(vr, ctx->M, GETMARK(FPC), s)) #define getStringTo(FPC, s) _getStringTo(mark, FPC, s) %%{ - machine http_response_parser; + machine li_http_response_parser; variable cs ctx->chunk_ctx.cs; action mark { ctx->mark = GETMARK(fpc); } @@ -32,10 +32,10 @@ getStringTo(fpc, ctx->h_value); } action header { - if (ctx->accept_cgi && l_g_strncase_equal(ctx->h_key, CONST_STR_LEN("Status"))) { + if (ctx->accept_cgi && li_strncase_equal(ctx->h_key, CONST_STR_LEN("Status"))) { ctx->response->http_status = atoi(ctx->h_value->str); } else { - http_header_insert(ctx->response->headers, GSTR_LEN(ctx->h_key), GSTR_LEN(ctx->h_value)); + li_http_header_insert(ctx->response->headers, GSTR_LEN(ctx->h_key), GSTR_LEN(ctx->h_value)); } } @@ -88,16 +88,16 @@ %% write data; -static int http_response_parser_has_error(liHttpResponseCtx *ctx) { - return ctx->chunk_ctx.cs == http_response_parser_error; +static int li_http_response_parser_has_error(liHttpResponseCtx *ctx) { + return ctx->chunk_ctx.cs == li_http_response_parser_error; } -static int http_response_parser_is_finished(liHttpResponseCtx *ctx) { - return ctx->chunk_ctx.cs >= http_response_parser_first_final; +static int li_http_response_parser_is_finished(liHttpResponseCtx *ctx) { + return ctx->chunk_ctx.cs >= li_http_response_parser_first_final; } -void http_response_parser_init(liHttpResponseCtx* ctx, liResponse *req, liChunkQueue *cq, gboolean accept_cgi, gboolean accept_nph) { - chunk_parser_init(&ctx->chunk_ctx, cq); +void li_http_response_parser_init(liHttpResponseCtx* ctx, liResponse *req, liChunkQueue *cq, gboolean accept_cgi, gboolean accept_nph) { + li_chunk_parser_init(&ctx->chunk_ctx, cq); ctx->response = req; ctx->accept_cgi = accept_cgi; ctx->accept_nph = accept_nph; @@ -107,39 +107,39 @@ void http_response_parser_init(liHttpResponseCtx* ctx, liResponse *req, liChunkQ %% write init; } -void http_response_parser_reset(liHttpResponseCtx* ctx) { - chunk_parser_reset(&ctx->chunk_ctx); +void li_http_response_parser_reset(liHttpResponseCtx* ctx) { + li_chunk_parser_reset(&ctx->chunk_ctx); g_string_truncate(ctx->h_key, 0); g_string_truncate(ctx->h_value, 0); %% write init; } -void http_response_parser_clear(liHttpResponseCtx *ctx) { +void li_http_response_parser_clear(liHttpResponseCtx *ctx) { g_string_free(ctx->h_key, TRUE); g_string_free(ctx->h_value, TRUE); } -liHandlerResult http_response_parse(liVRequest *vr, liHttpResponseCtx *ctx) { +liHandlerResult li_http_response_parse(liVRequest *vr, liHttpResponseCtx *ctx) { liHandlerResult res; - if (http_response_parser_is_finished(ctx)) return LI_HANDLER_GO_ON; + if (li_http_response_parser_is_finished(ctx)) return LI_HANDLER_GO_ON; - if (LI_HANDLER_GO_ON != (res = chunk_parser_prepare(&ctx->chunk_ctx))) return res; + if (LI_HANDLER_GO_ON != (res = li_chunk_parser_prepare(&ctx->chunk_ctx))) return res; - while (!http_response_parser_has_error(ctx) && !http_response_parser_is_finished(ctx)) { + while (!li_http_response_parser_has_error(ctx) && !li_http_response_parser_is_finished(ctx)) { char *p, *pe; - if (LI_HANDLER_GO_ON != (res = chunk_parser_next(vr, &ctx->chunk_ctx, &p, &pe))) return res; + if (LI_HANDLER_GO_ON != (res = li_chunk_parser_next(vr, &ctx->chunk_ctx, &p, &pe))) return res; %% write exec; - chunk_parser_done(&ctx->chunk_ctx, p - ctx->chunk_ctx.buf); + li_chunk_parser_done(&ctx->chunk_ctx, p - ctx->chunk_ctx.buf); } - 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 (li_http_response_parser_has_error(ctx)) return LI_HANDLER_ERROR; + if (li_http_response_parser_is_finished(ctx)) { + li_chunkqueue_skip(ctx->chunk_ctx.cq, ctx->chunk_ctx.bytes_in); if (ctx->response->http_status == 0) ctx->response->http_status = 200; return LI_HANDLER_GO_ON; } diff --git a/src/idlist.c b/src/idlist.c index 725d9a9..bc341b7 100644 --- a/src/idlist.c +++ b/src/idlist.c @@ -9,7 +9,7 @@ * of the form 2^n this should result in bit shifts in the executable code. */ -liIDList* idlist_new(gint max_ids) { +liIDList* li_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)); @@ -19,7 +19,7 @@ liIDList* idlist_new(gint max_ids) { return l; } -void idlist_free(liIDList *l) { +void li_idlist_free(liIDList *l) { if (!l) return; g_array_free(l->bitvector, TRUE); g_slice_free(liIDList, l); @@ -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(liIDList *l) { +gint li_idlist_get(liIDList *l) { guint fndx, ndx; gint newid, bndx; gulong u = -1; @@ -97,7 +97,7 @@ gint idlist_get(liIDList *l) { return newid; } -gboolean idlist_is_used(liIDList *l, gint id) { +gboolean li_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(liIDList *l, gint id) { return (0 != (g_array_index(a, gulong, ndx) & (bmask))); } -void idlist_put(liIDList *l, gint id) { +void li_idlist_put(liIDList *l, gint id) { clear_bit(l->bitvector, id); l->used_ids--; diff --git a/src/ip_parsers.rl b/src/ip_parsers.rl index b3f5070..9a8bf22 100644 --- a/src/ip_parsers.rl +++ b/src/ip_parsers.rl @@ -32,7 +32,7 @@ write data; }%% -gboolean parse_ipv4(const char *str, guint32 *ip, guint32 *netmask, guint16 *port) { +gboolean li_parse_ipv4(const char *str, guint32 *ip, guint32 *netmask, guint16 *port) { guint8 *data = (guint8*) ip; const char *p = str; gboolean res = TRUE; @@ -108,7 +108,7 @@ gboolean parse_ipv4(const char *str, guint32 *ip, guint32 *netmask, guint16 *por write data; }%% -gboolean parse_ipv6(const char *str, guint8 *ip, guint *network, guint16 *port) { +gboolean li_parse_ipv6(const char *str, guint8 *ip, guint *network, guint16 *port) { guint8 data[4] = {0,0,0,0}; guint16 *predata = (guint16*) ip, postdata[8]; size_t prec = 0, postc = 0; @@ -132,7 +132,7 @@ gboolean parse_ipv6(const char *str, guint8 *ip, guint *network, guint16 *port) return TRUE; } -GString* ipv6_tostring(GString *dest, const guint8 ip[16]) { +GString* li_ipv6_tostring(GString *dest, const guint8 ip[16]) { #define IPV6_TEMPLATE "ffff:ffff:ffff:ffff:ffff:ffff:abc.def.ghi.jkl" guint16 *data = (guint16*) ip; size_t i; diff --git a/src/lighttpd-glue.c b/src/lighttpd-glue.c index 139625a..1713cb7 100644 --- a/src/lighttpd-glue.c +++ b/src/lighttpd-glue.c @@ -8,7 +8,7 @@ return x; \ } while(0) -gchar *http_status_string(guint status_code, guint *len) { +gchar *li_http_status_string(guint status_code, guint *len) { /* RFC 2616 (as well as RFC 2518, RFC 2817, RFC 2295, RFC 2774, RFC 4918) */ switch (status_code) { /* 1XX information */ @@ -75,7 +75,7 @@ gchar *http_status_string(guint status_code, guint *len) { } } -gchar *http_method_string(liHttpMethod method, guint *len) { +gchar *li_http_method_string(liHttpMethod method, guint *len) { switch (method) { case LI_HTTP_METHOD_UNSET: SET_LEN_AND_RETURN_STR("UNKNOWN"); case LI_HTTP_METHOD_GET: SET_LEN_AND_RETURN_STR("GET"); @@ -106,7 +106,7 @@ gchar *http_method_string(liHttpMethod method, guint *len) { return NULL; } -gchar *http_version_string(liHttpVersion method, guint *len) { +gchar *li_http_version_string(liHttpVersion method, guint *len) { switch (method) { 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"); @@ -119,7 +119,7 @@ gchar *http_version_string(liHttpVersion method, guint *len) { #undef SET_LEN_AND_RETURN_STR -void http_status_to_str(gint status_code, gchar status_str[]) { +void li_http_status_to_str(gint status_code, gchar status_str[]) { status_str[2] = status_code % 10 + '0'; status_code /= 10; status_str[1] = status_code % 10 + '0'; @@ -128,7 +128,7 @@ void http_status_to_str(gint status_code, gchar status_str[]) { } -GString *mimetype_get(liVRequest *vr, GString *filename) { +GString *li_mimetype_get(liVRequest *vr, GString *filename) { /* search in mime_types option for the first match */ GArray *arr; diff --git a/src/lighttpd.c b/src/lighttpd.c index 3579e56..f6d1893 100644 --- a/src/lighttpd.c +++ b/src/lighttpd.c @@ -73,13 +73,13 @@ int main(int argc, char *argv[]) { /* initialize threading */ g_thread_init(NULL); - srv = server_new(module_dir); - server_loop_init(srv); + srv = li_server_new(module_dir); + li_server_loop_init(srv); /* load core plugin */ - srv->core_plugin = plugin_register(srv, "core", plugin_core_init); + srv->core_plugin = li_plugin_register(srv, "core", plugin_core_init); if (use_angel) { - angel_setup(srv); + li_angel_setup(srv); } /* if no path is specified for the config, read lighttpd.conf from current directory */ @@ -107,14 +107,14 @@ int main(int argc, char *argv[]) { log_thread_start(srv); g_atomic_int_set(&srv->exiting, TRUE); log_thread_wakeup(srv); - server_free(srv); + li_server_free(srv); if (free_config_path) g_free(config_path); return 1; } /* append fallback "static" action */ - a = create_action(srv, "static", NULL); + a = li_create_action(srv, "static", NULL); g_array_append_val(srv->mainaction->data.list, a); g_get_current_time(&end); @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) { } else { #ifdef HAVE_LUA_H - config_lua_load(srv, config_path); + li_config_lua_load(srv, config_path); /* lua config frontend */ #else g_print("lua config frontend not available\n"); @@ -145,15 +145,15 @@ int main(int argc, char *argv[]) { /* TRACE(srv, "%s", "Test!"); */ - server_worker_init(srv); - server_start(srv); + li_server_worker_init(srv); + li_server_start(srv); if (!luaconfig) config_parser_finish(srv, ctx_stack, TRUE); INFO(srv, "%s", "going down"); - server_free(srv); + li_server_free(srv); if (module_dir != def_module_dir) g_free((gpointer)module_dir); diff --git a/src/log.c b/src/log.c index 7831a06..47a133f 100644 --- a/src/log.c +++ b/src/log.c @@ -12,7 +12,7 @@ #include #if REMOVE_PATH_FROM_FILE -const char *remove_path(const char *path) { +const char *li_remove_path(const char *path) { char *p = strrchr(path, DIR_SEPERATOR); if (NULL != p && *(p) != '\0') { return (p + 1); @@ -21,11 +21,11 @@ const char *remove_path(const char *path) { } #endif -void log_write(liServer *srv, liLog *log, GString *msg) { +void li_log_write(liServer *srv, liLog *log, GString *msg) { liLogEntry *log_entry; if (g_atomic_int_get(&srv->state) == LI_SERVER_STARTING) { - angel_log(srv, msg); + li_angel_log(srv, msg); return; } @@ -38,7 +38,7 @@ void log_write(liServer *srv, liLog *log, GString *msg) { g_async_queue_push(srv->logs.queue, log_entry); } -gboolean log_write_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, const gchar *fmt, ...) { +gboolean li_log_write_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, const gchar *fmt, ...) { va_list ap; GString *log_line; liLog *log = NULL; @@ -85,7 +85,7 @@ gboolean log_write_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint f if (log->lastmsg_count > 0) { guint count = log->lastmsg_count; log->lastmsg_count = 0; - log_write_(srv, vr, log_level, flags | LOG_FLAG_NOLOCK | LOG_FLAG_ALLOW_REPEAT, "last message repeated %d times", count); + li_log_write_(srv, vr, log_level, flags | LOG_FLAG_NOLOCK | LOG_FLAG_ALLOW_REPEAT, "last message repeated %d times", count); } } } @@ -128,7 +128,7 @@ gboolean log_write_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint f if (g_atomic_int_get(&srv->state) == LI_SERVER_STARTING) { log_unref(srv, log); - angel_log(srv, log_line); + li_angel_log(srv, log_line); return TRUE; } log_entry = g_slice_new(liLogEntry); @@ -404,7 +404,7 @@ void log_init(liServer *srv) { srv->logs.thread_alive = FALSE; /* first entry in srv->logs.timestamps is the default timestamp */ - log_timestamp_new(srv, g_string_new_len(CONST_STR_LEN("%d/%b/%Y %T %Z"))); + li_log_timestamp_new(srv, g_string_new_len(CONST_STR_LEN("%d/%b/%Y %T %Z"))); /* first entry in srv->logs.targets is the plain good old stderr */ str = g_string_new_len(CONST_STR_LEN("stderr")); @@ -441,7 +441,7 @@ void log_cleanup(liServer *srv) { }*/ } - log_timestamp_free(srv, g_array_index(srv->logs.timestamps, liLogTimestamp*, 0)); + li_log_timestamp_free(srv, g_array_index(srv->logs.timestamps, liLogTimestamp*, 0)); g_array_free(srv->logs.timestamps, TRUE); } @@ -493,7 +493,7 @@ void log_unlock(liLog *log) { g_mutex_unlock(log->mutex); } -liLogTimestamp *log_timestamp_new(liServer *srv, GString *format) { +liLogTimestamp *li_log_timestamp_new(liServer *srv, GString *format) { liLogTimestamp *ts; /* check if there already exists a timestamp entry with the same format */ @@ -518,7 +518,7 @@ liLogTimestamp *log_timestamp_new(liServer *srv, GString *format) { return ts; } -gboolean log_timestamp_free(liServer *srv, liLogTimestamp *ts) { +gboolean li_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, liLogTimestamp*, i)->format, ts->format)) { @@ -535,7 +535,7 @@ gboolean log_timestamp_free(liServer *srv, liLogTimestamp *ts) { return FALSE; } -void log_split_lines(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, gchar *txt, const gchar *prefix) { +void li_log_split_lines(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, gchar *txt, const gchar *prefix) { gchar *start; start = txt; @@ -543,7 +543,7 @@ void log_split_lines(liServer *srv, liVRequest *vr, liLogLevel log_level, guint if ('\r' == *txt || '\n' == *txt) { *txt = '\0'; if (txt - start > 1) { /* skip empty lines*/ - log_write_(srv, vr, log_level, flags, "%s%s", prefix, start); + li_log_write_(srv, vr, log_level, flags, "%s%s", prefix, start); } txt++; while (*txt == '\n' || *txt == '\r') txt++; @@ -553,11 +553,11 @@ void log_split_lines(liServer *srv, liVRequest *vr, liLogLevel log_level, guint } } if (txt - start > 1) { /* skip empty lines*/ - log_write_(srv, vr, log_level, flags, "%s%s", prefix, start); + li_log_write_(srv, vr, log_level, flags, "%s%s", prefix, start); } } -void log_split_lines_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, gchar *txt, const gchar *fmt, ...) { +void li_log_split_lines_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint flags, gchar *txt, const gchar *fmt, ...) { va_list ap; GString *prefix; @@ -566,7 +566,7 @@ void log_split_lines_(liServer *srv, liVRequest *vr, liLogLevel log_level, guint g_string_vprintf(prefix, fmt, ap); va_end(ap); - log_split_lines(srv, vr, log_level, flags, txt, prefix->str); + li_log_split_lines(srv, vr, log_level, flags, txt, prefix->str); g_string_free(prefix, TRUE); } diff --git a/src/module.c b/src/module.c index a64e13c..d6095a4 100644 --- a/src/module.c +++ b/src/module.c @@ -1,7 +1,7 @@ #include -liModules *modules_new(gpointer main, const gchar *module_dir) { +liModules *li_modules_new(gpointer main, const gchar *module_dir) { liModules *m = g_slice_new(liModules); m->version = MODULE_VERSION; @@ -13,7 +13,7 @@ liModules *modules_new(gpointer main, const gchar *module_dir) { return m; } -liModule *module_lookup(liModules *mods, const gchar *name) { +liModule *li_module_lookup(liModules *mods, const gchar *name) { liModule *mod; GArray *a = mods->mods; @@ -26,7 +26,7 @@ liModule *module_lookup(liModules *mods, const gchar *name) { return NULL; } -void modules_free(liModules* mods) { +void li_modules_free(liModules* mods) { /* unload all modules */ GArray *a = mods->mods; liModule *mod; @@ -35,7 +35,7 @@ void modules_free(liModules* mods) { mod = g_array_index(a, liModule*, i); if (!mod) continue; - module_release(mods, mod); + li_module_release(mods, mod); } g_array_free(mods->mods, TRUE); @@ -44,13 +44,13 @@ void modules_free(liModules* mods) { } -liModule* module_load(liModules *mods, const gchar* name) { +liModule* li_module_load(liModules *mods, const gchar* name) { liModule *mod; liModuleInitCB m_init; GString *m_init_str, *m_free_str; guint i; - mod = module_lookup(mods, name); + mod = li_module_lookup(mods, name); if (mod) { /* module already loaded, increment refcount and return */ @@ -121,7 +121,7 @@ liModule* module_load(liModules *mods, const gchar* name) { return mod; } -void module_release(liModules *mods, liModule *mod) { +void li_module_release(liModules *mods, liModule *mod) { guint i; if (--mod->refcount > 0) @@ -142,9 +142,9 @@ void module_release(liModules *mods, liModule *mod) { g_slice_free(liModule, mod); } -void module_release_name(liModules *mods, const gchar* name) { - liModule *mod = module_lookup(mods, name); +void li_module_release_name(liModules *mods, const gchar* name) { + liModule *mod = li_module_lookup(mods, name); if (mod) - module_release(mods, mod); + li_module_release(mods, mod); } diff --git a/src/modules/mod_access.c b/src/modules/mod_access.c index 40e5a16..f165766 100644 --- a/src/modules/mod_access.c +++ b/src/modules/mod_access.c @@ -67,8 +67,8 @@ static liHandlerResult access_check(liVRequest *vr, gpointer param, gpointer *co UNUSED(redirect_url); if (addr->plain.sa_family == AF_INET) { - if (radixtree32_lookup(acd->ipv4, htonl(addr->ipv4.sin_addr.s_addr))) { - vrequest_handle_direct(vr); + if (li_radixtree32_lookup(acd->ipv4, htonl(addr->ipv4.sin_addr.s_addr))) { + li_vrequest_handle_direct(vr); vr->response.http_status = 403; if (log_blocked) { @@ -91,7 +91,7 @@ static void access_check_free(liServer *srv, gpointer param) { UNUSED(srv); - radixtree32_free(acd->ipv4); + li_radixtree32_free(acd->ipv4); g_slice_free(access_check_data, acd); } @@ -115,14 +115,14 @@ static liAction* access_check_create(liServer *srv, liPlugin* p, liValue *val) { acd = g_slice_new0(access_check_data); acd->p = p; - acd->ipv4 = radixtree32_new(2); + acd->ipv4 = li_radixtree32_new(2); for (i = 0; i < arr->len; i++) { v = g_array_index(arr, liValue*, i); 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); + li_radixtree32_free(acd->ipv4); g_slice_free(access_check_data, acd); return NULL; } @@ -131,7 +131,7 @@ static liAction* access_check_create(liServer *srv, liPlugin* p, liValue *val) { 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); + li_radixtree32_free(acd->ipv4); g_slice_free(access_check_data, acd); return NULL; } @@ -143,7 +143,7 @@ static liAction* access_check_create(liServer *srv, liPlugin* p, liValue *val) { got_deny = TRUE; } else { ERROR(srv, "access_check: invalid option \"%s\"", v->data.string->str); - radixtree32_free(acd->ipv4); + li_radixtree32_free(acd->ipv4); g_slice_free(access_check_data, acd); return NULL; } @@ -152,7 +152,7 @@ static liAction* access_check_create(liServer *srv, liPlugin* p, liValue *val) { 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); + li_radixtree32_free(acd->ipv4); g_slice_free(access_check_data, acd); return NULL; } @@ -162,20 +162,20 @@ static liAction* access_check_create(liServer *srv, liPlugin* p, liValue *val) { 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); + li_radixtree32_free(acd->ipv4); g_slice_free(access_check_data, acd); return NULL; } if (g_str_equal(ip->data.string->str, "all")) { - radixtree32_insert(acd->ipv4, 0, 0x00000000, GINT_TO_POINTER(deny)); - } else if (parse_ipv4(ip->data.string->str, &ipv4, &netmaskv4, NULL)) { - radixtree32_insert(acd->ipv4, htonl(ipv4), htonl(netmaskv4), GINT_TO_POINTER(deny)); - /*} else if (parse_ipv6(v->data.string->str, ..., NULL) { - radixtree128_insert(acd->ipv6, ipv6, netmaskv6, (gpointer)allow;*/ + li_radixtree32_insert(acd->ipv4, 0, 0x00000000, GINT_TO_POINTER(deny)); + } else if (li_parse_ipv4(ip->data.string->str, &ipv4, &netmaskv4, NULL)) { + li_radixtree32_insert(acd->ipv4, htonl(ipv4), htonl(netmaskv4), GINT_TO_POINTER(deny)); + /*} else if (li_parse_ipv6(v->data.string->str, ..., NULL) { + li_radixtree128_insert(acd->ipv6, ipv6, netmaskv6, (gpointer)allow;*/ } else { ERROR(srv, "access_check: error parsing ip: %s", ip->data.string->str); - radixtree32_free(acd->ipv4); + li_radixtree32_free(acd->ipv4); g_slice_free(access_check_data, acd); return NULL; } @@ -183,9 +183,9 @@ static liAction* access_check_create(liServer *srv, liPlugin* p, liValue *val) { } if (!got_deny) - radixtree32_insert(acd->ipv4, 0, 0x00000000, GINT_TO_POINTER(TRUE)); + li_radixtree32_insert(acd->ipv4, 0, 0x00000000, GINT_TO_POINTER(TRUE)); - return action_new_function(access_check, NULL, access_check_free, acd); + return li_action_new_function(access_check, NULL, access_check_free, acd); } @@ -196,7 +196,7 @@ static liHandlerResult access_deny(liVRequest *vr, gpointer param, gpointer *con UNUSED(context); UNUSED(redirect_url); - vrequest_handle_direct(vr); + li_vrequest_handle_direct(vr); vr->response.http_status = 403; if (log_blocked) { @@ -215,7 +215,7 @@ static liAction* access_deny_create(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - return action_new_function(access_deny, NULL, NULL, p); + return li_action_new_function(access_deny, NULL, NULL, p); } @@ -252,14 +252,14 @@ gboolean mod_access_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); - mod->config = plugin_register(mods->main, "mod_access", plugin_access_init); + mod->config = li_plugin_register(mods->main, "mod_access", plugin_access_init); return mod->config != NULL; } gboolean mod_access_free(liModules *mods, liModule *mod) { if (mod->config) - plugin_free(mods->main, mod->config); + li_plugin_free(mods->main, mod->config); return TRUE; } diff --git a/src/modules/mod_accesslog.c b/src/modules/mod_accesslog.c index 406e929..7a30ef7 100644 --- a/src/modules/mod_accesslog.c +++ b/src/modules/mod_accesslog.c @@ -265,7 +265,7 @@ static GString *al_format_log(liConnection *con, al_data *ald, GArray *format) { g_string_append_c(str, '-'); break; case AL_FORMAT_REQUEST_HEADER: - http_header_get_fast(tmp_gstr, req->headers, GSTR_LEN(e->key)); + li_http_header_get_fast(tmp_gstr, req->headers, GSTR_LEN(e->key)); if (tmp_gstr->len) al_append_escaped(str, tmp_gstr); else @@ -275,7 +275,7 @@ static GString *al_format_log(liConnection *con, al_data *ald, GArray *format) { g_string_append_len(str, GSTR_LEN(req->http_method_str)); break; case AL_FORMAT_RESPONSE_HEADER: - http_header_get_fast(tmp_gstr, resp->headers, GSTR_LEN(e->key)); + li_http_header_get_fast(tmp_gstr, resp->headers, GSTR_LEN(e->key)); if (tmp_gstr->len) al_append_escaped(str, tmp_gstr); else @@ -296,7 +296,7 @@ static GString *al_format_log(liConnection *con, al_data *ald, GArray *format) { al_append_escaped(str, req->uri.query); } g_string_append_c(str, ' '); - tmp_str = http_version_string(req->http_version, &len); + tmp_str = li_http_version_string(req->http_version, &len); g_string_append_len(str, tmp_str, len); break; case AL_FORMAT_STATUS_CODE: @@ -304,7 +304,7 @@ static GString *al_format_log(liConnection *con, al_data *ald, GArray *format) { break; case AL_FORMAT_TIME: /* todo: implement format string */ - tmp_gstr2 = worker_current_timestamp(con->wrk, ald->ts_ndx_gmtime); + tmp_gstr2 = li_worker_current_timestamp(con->wrk, ald->ts_ndx_gmtime); g_string_append_len(str, GSTR_LEN(tmp_gstr2)); break; case AL_FORMAT_AUTHED_USER: @@ -377,7 +377,7 @@ static void al_handle_close(liConnection *con, liPlugin *p) { msg = al_format_log(con, p->data, format); g_string_append_len(msg, CONST_STR_LEN("\r\n")); - log_write(con->srv, log, msg); + li_log_write(con->srv, log, msg); } @@ -487,7 +487,7 @@ static void plugin_accesslog_init(liServer *srv, liPlugin *p) { p->handle_close = al_handle_close; ald = g_slice_new0(al_data); - ald->ts_ndx_gmtime = server_ts_format_add(srv, g_string_new_len(CONST_STR_LEN("[%d/%b/%Y:%H:%M:%S +0000]"))); + ald->ts_ndx_gmtime = li_server_ts_format_add(srv, g_string_new_len(CONST_STR_LEN("[%d/%b/%Y:%H:%M:%S +0000]"))); p->data = ald; } @@ -496,7 +496,7 @@ LI_API gboolean mod_accesslog_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); - mod->config = plugin_register(mods->main, "mod_accesslog", plugin_accesslog_init); + mod->config = li_plugin_register(mods->main, "mod_accesslog", plugin_accesslog_init); return mod->config != NULL; } @@ -505,7 +505,7 @@ LI_API gboolean mod_accesslog_free(liModules *mods, liModule *mod) { UNUSED(mods); UNUSED(mod); if (mod->config) - plugin_free(mods->main, mod->config); + li_plugin_free(mods->main, mod->config); return TRUE; } diff --git a/src/modules/mod_balancer.c b/src/modules/mod_balancer.c index beea8fa..d65a61f 100644 --- a/src/modules/mod_balancer.c +++ b/src/modules/mod_balancer.c @@ -42,7 +42,7 @@ static void balancer_free(liServer *srv, balancer *b) { if (!b) return; for (i = 0; i < b->backends->len; i++) { backend *be = &g_array_index(b->backends, backend, i); - action_release(srv, be->act); + li_action_release(srv, be->act); } g_array_free(b->backends, TRUE); g_slice_free(balancer, b); @@ -52,7 +52,7 @@ 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); + li_action_acquire(be.act); g_array_append_val(b->backends, be); return TRUE; } else if (val->type == LI_VALUE_LIST) { @@ -64,19 +64,19 @@ static gboolean balancer_fill_backends(balancer *b, liServer *srv, liValue *val) for (i = 0; i < val->data.list->len; i++) { 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)); + ERROR(srv, "expected action at entry %u of list, got %s", i, li_value_type_string(oa->type)); return FALSE; } assert(srv == oa->data.val_action.srv); { backend be = { oa->data.val_action.action, 0, BE_ALIVE }; - action_acquire(be.act); + li_action_acquire(be.act); g_array_append_val(b->backends, be); } } return TRUE; } else { - ERROR(srv, "expected list, got %s", value_type_string(val->type)); + ERROR(srv, "expected list, got %s", li_value_type_string(val->type)); return FALSE; } } @@ -91,7 +91,7 @@ static liHandlerResult balancer_act_select(liVRequest *vr, gboolean backlog_prov /* TODO implement some selection algorithms */ be->load++; - action_enter(vr, be->act); + li_action_enter(vr, be->act); *context = GINT_TO_POINTER(be_ndx); return LI_HANDLER_GO_ON; @@ -111,7 +111,7 @@ static liHandlerResult balancer_act_fallback(liVRequest *vr, gboolean backlog_pr be->load--; *context = GINT_TO_POINTER(-1); - vrequest_backend_error(vr, error); + li_vrequest_backend_error(vr, error); return LI_HANDLER_GO_ON; } @@ -150,7 +150,7 @@ static liAction* balancer_rr(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - a = action_new_balancer(balancer_act_select, balancer_act_fallback, balancer_act_finished, balancer_act_free, b, TRUE); + a = li_action_new_balancer(balancer_act_select, balancer_act_fallback, balancer_act_finished, balancer_act_free, b, TRUE); return a; } @@ -181,14 +181,14 @@ static void plugin_init(liServer *srv, liPlugin *p) { gboolean mod_balancer_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); - mod->config = plugin_register(mods->main, "mod_balancer", plugin_init); + mod->config = li_plugin_register(mods->main, "mod_balancer", plugin_init); return mod->config != NULL; } gboolean mod_balancer_free(liModules *mods, liModule *mod) { if (mod->config) - plugin_free(mods->main, mod->config); + li_plugin_free(mods->main, mod->config); return TRUE; } diff --git a/src/modules/mod_cache_disk_etag.c b/src/modules/mod_cache_disk_etag.c index 5286013..a5b36de 100644 --- a/src/modules/mod_cache_disk_etag.c +++ b/src/modules/mod_cache_disk_etag.c @@ -139,7 +139,7 @@ static liHandlerResult cache_etag_filter_hit(liVRequest *vr, liFilter *f) { f->in->is_closed = TRUE; - chunkqueue_append_file_fd(f->out, NULL, 0, cfile->hit_length, cfile->hit_fd); + li_chunkqueue_append_file_fd(f->out, NULL, 0, cfile->hit_length, cfile->hit_fd); cfile->hit_fd = -1; cache_etag_file_free(cfile); f->param = NULL; @@ -160,16 +160,16 @@ static liHandlerResult cache_etag_filter_miss(liVRequest *vr, liFilter *f) { if (0 == f->in->length) return LI_HANDLER_GO_ON; if (!cfile) { /* somehow we lost the file */ - chunkqueue_steal_all(f->out, f->in); + li_chunkqueue_steal_all(f->out, f->in); if (f->in->is_closed) f->out->is_closed = TRUE; return LI_HANDLER_GO_ON; } - if (LI_HANDLER_GO_ON != chunkiter_read(vr, citer, 0, 64*1024, &buf, &buflen)) { + if (LI_HANDLER_GO_ON != li_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); + li_chunkqueue_steal_all(f->out, f->in); if (f->in->is_closed) f->out->is_closed = TRUE; return LI_HANDLER_GO_ON; } @@ -185,12 +185,12 @@ static liHandlerResult cache_etag_filter_miss(liVRequest *vr, liFilter *f) { cfile->tmpfilename->str, g_strerror(errno)); cache_etag_file_free(cfile); f->param = NULL; - chunkqueue_steal_all(f->out, f->in); + li_chunkqueue_steal_all(f->out, f->in); if (f->in->is_closed) f->out->is_closed = TRUE; return LI_HANDLER_GO_ON; } } else { - chunkqueue_steal_len(f->out, f->in, res); + li_chunkqueue_steal_len(f->out, f->in, res); if (f->in->length == 0 && f->in->is_closed) { cache_etag_file_finish(vr, cfile); f->param = NULL; @@ -240,9 +240,9 @@ static liHandlerResult cache_etag_handle(liVRequest *vr, gpointer param, gpointe /* Don't cache static files */ 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")); + etag_entry = li_http_header_find_first(vr->response.headers, CONST_STR_LEN("etag")); if (!etag_entry) return LI_HANDLER_GO_ON; /* no etag -> no caching */ - if (http_header_find_next(etag_entry, CONST_STR_LEN("etag"))) { + if (li_http_header_find_next(etag_entry, CONST_STR_LEN("etag"))) { VR_ERROR(vr, "%s", "duplicate etag header in response, will not cache it"); return LI_HANDLER_GO_ON; } @@ -260,7 +260,7 @@ static liHandlerResult cache_etag_handle(liVRequest *vr, gpointer param, gpointe } if (-1 == (cfile->hit_fd = open(cfile->filename->str, O_RDONLY))) { if (EMFILE == errno) { - server_out_of_fds(vr->wrk->srv); + li_server_out_of_fds(vr->wrk->srv); } VR_ERROR(vr, "Couldn't open cache file '%s': %s", cfile->filename->str, g_strerror(errno)); return LI_HANDLER_GO_ON; /* no caching */ @@ -273,9 +273,9 @@ static liHandlerResult cache_etag_handle(liVRequest *vr, gpointer param, gpointe } cfile->hit_length = st.st_size; g_string_truncate(tmp_str, 0); - l_g_string_append_int(tmp_str, st.st_size); - 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); + li_string_append_int(tmp_str, st.st_size); + li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Length"), GSTR_LEN(tmp_str)); + li_vrequest_add_filter_out(vr, cache_etag_filter_hit, cache_etag_filter_free, cfile); *context = NULL; return LI_HANDLER_GO_ON; } @@ -289,7 +289,7 @@ static liHandlerResult cache_etag_handle(liVRequest *vr, gpointer param, gpointe return LI_HANDLER_GO_ON; /* no caching */ } - vrequest_add_filter_out(vr, cache_etag_filter_miss, cache_etag_filter_free, cfile); + li_vrequest_add_filter_out(vr, cache_etag_filter_miss, cache_etag_filter_free, cfile); *context = NULL; return LI_HANDLER_GO_ON; @@ -313,9 +313,9 @@ static liAction* cache_etag_create(liServer *srv, liPlugin* p, liValue *val) { } ctx = g_slice_new0(cache_etag_context); - ctx->path = value_extract_ptr(val); + ctx->path = li_value_extract_ptr(val); - return action_new_function(cache_etag_handle, cache_etag_cleanup, cache_etag_free, ctx); + return li_action_new_function(cache_etag_handle, cache_etag_cleanup, cache_etag_free, ctx); } static const liPluginOption options[] = { @@ -343,14 +343,14 @@ static void plugin_init(liServer *srv, liPlugin *p) { 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); + mod->config = li_plugin_register(mods->main, "mod_cache_disk_etag", plugin_init); return mod->config != NULL; } gboolean mod_cache_disk_etag_free(liModules *mods, liModule *mod) { if (mod->config) - plugin_free(mods->main, mod->config); + li_plugin_free(mods->main, mod->config); return TRUE; } diff --git a/src/modules/mod_debug.c b/src/modules/mod_debug.c index 4245af3..e435973 100644 --- a/src/modules/mod_debug.c +++ b/src/modules/mod_debug.c @@ -119,7 +119,7 @@ static gpointer debug_collect_func(liWorker *wrk, gpointer fdata) { g_string_append_printf(cd->detailed, " remote_addr_str = \"%s\",\n", cd->remote_addr_str->str); g_string_append_printf(cd->detailed, " local_addr_str = \"%s\",\n", cd->local_addr_str->str); g_string_append_printf(cd->detailed, " fd = %d,\n", cd->fd); - g_string_append_printf(cd->detailed, " state = \"%s\",\n", connection_state_str(cd->state)); + g_string_append_printf(cd->detailed, " state = \"%s\",\n", li_connection_state_str(cd->state)); g_string_append_printf(cd->detailed, " ts = %f,\n", cd->ts); g_string_append_printf(cd->detailed, " io_timeout_elem = {\n" @@ -159,7 +159,7 @@ static void debug_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result, UNUSED(fdata); if (!complete) { - /* someone called collect_break, so we don't need any vrequest handling here. just free the result data */ + /* someone called li_collect_break, so we don't need any vrequest handling here. just free the result data */ guint i, j; for (i = 0; i < result->len; i++) { @@ -215,7 +215,7 @@ static void debug_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result, for (j = 0; j < cons->len; j++) { mod_debug_data_t *d = &g_array_index(cons, mod_debug_data_t, j); - counter_format((guint64)(CUR_TS(vr->wrk) - d->ts), COUNTER_TIME, duration); + li_counter_format((guint64)(CUR_TS(vr->wrk) - d->ts), COUNTER_TIME, duration); g_string_append_printf(html, "%s%sdebug\n", d->remote_addr_str->str, duration->str, @@ -243,10 +243,10 @@ static void debug_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result, g_string_append_len(html, CONST_STR_LEN("\n\n")); - chunkqueue_append_string(vr->out, html); - http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html")); + li_chunkqueue_append_string(vr->out, html); + li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html")); vr->response.http_status = 200; - vrequest_joblist_append(vr); + li_vrequest_joblist_append(vr); if (job->detailed.remote_addr_str) g_string_free(job->detailed.remote_addr_str, TRUE); @@ -259,13 +259,13 @@ static liHandlerResult debug_show_connections_cleanup(liVRequest *vr, gpointer p UNUSED(vr); UNUSED(param); - collect_break(ci); + li_collect_break(ci); return LI_HANDLER_GO_ON; } static liHandlerResult debug_show_connections(liVRequest *vr, gpointer param, gpointer *context) { - if (vrequest_handle_direct(vr)) { + if (li_vrequest_handle_direct(vr)) { liCollectInfo *ci; mod_debug_job_t *j = g_slice_new0(mod_debug_job_t); j->vr = vr; @@ -282,7 +282,7 @@ static liHandlerResult debug_show_connections(liVRequest *vr, gpointer param, gp VR_DEBUG(vr, "%s", "collecting debug info..."); - ci = collect_start(vr->wrk, debug_collect_func, j, debug_collect_cb, j); + ci = li_collect_start(vr->wrk, debug_collect_func, j, debug_collect_cb, j); *context = ci; /* may be NULL */ } @@ -297,7 +297,7 @@ static liAction* debug_show_connections_create(liServer *srv, liPlugin* p, liVal return NULL; } - return action_new_function(debug_show_connections, debug_show_connections_cleanup, NULL, p); + return li_action_new_function(debug_show_connections, debug_show_connections_cleanup, NULL, p); } @@ -330,14 +330,14 @@ gboolean mod_debug_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); - mod->config = plugin_register(mods->main, "mod_debug", plugin_debug_init); + mod->config = li_plugin_register(mods->main, "mod_debug", plugin_debug_init); return mod->config != NULL; } gboolean mod_debug_free(liModules *mods, liModule *mod) { if (mod->config) - plugin_free(mods->main, mod->config); + li_plugin_free(mods->main, mod->config); return TRUE; } diff --git a/src/modules/mod_dirlist.c b/src/modules/mod_dirlist.c index 40b30dd..2491c83 100644 --- a/src/modules/mod_dirlist.c +++ b/src/modules/mod_dirlist.c @@ -172,11 +172,11 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context UNUSED(context); - if (vrequest_is_handled(vr)) return LI_HANDLER_GO_ON; + if (li_vrequest_is_handled(vr)) return LI_HANDLER_GO_ON; if (vr->physical.path->len == 0) return LI_HANDLER_GO_ON; - switch (stat_cache_get_dirlist(vr, vr->physical.path, &sce)) { + switch (li_stat_cache_get_dirlist(vr, vr->physical.path, &sce)) { case LI_HANDLER_GO_ON: break; case LI_HANDLER_WAIT_FOR_EVENT: return LI_HANDLER_WAIT_FOR_EVENT; default: return LI_HANDLER_ERROR; @@ -187,13 +187,13 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context if (sce->data.failed) { /* stat failed */ - stat_cache_entry_release(vr, sce); + li_stat_cache_entry_release(vr, sce); switch (sce->data.err) { case ENOENT: case ENOTDIR: return LI_HANDLER_GO_ON; case EACCES: - if (!vrequest_handle_direct(vr)) return LI_HANDLER_ERROR; + if (!li_vrequest_handle_direct(vr)) return LI_HANDLER_ERROR; vr->response.http_status = 403; return LI_HANDLER_GO_ON; default: @@ -201,12 +201,12 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context return LI_HANDLER_ERROR; } } else if (!S_ISDIR(sce->data.st.st_mode)) { - stat_cache_entry_release(vr, sce); + li_stat_cache_entry_release(vr, sce); 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); + if (!li_vrequest_handle_direct(vr)) { + li_stat_cache_entry_release(vr, sce); return LI_HANDLER_ERROR; } /* redirect to scheme + host + path + / + querystring if directory without trailing slash */ @@ -230,9 +230,9 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context } vr->response.http_status = 301; - http_header_overwrite(vr->response.headers, CONST_STR_LEN("Location"), GSTR_LEN(uri)); + li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Location"), GSTR_LEN(uri)); g_string_free(uri, TRUE); - stat_cache_entry_release(vr, sce); + li_stat_cache_entry_release(vr, sce); return LI_HANDLER_GO_ON; } else { /* everything ok, we have the directory listing */ @@ -247,8 +247,8 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context struct tm tm; gboolean hide; - if (!vrequest_handle_direct(vr)) { - stat_cache_entry_release(vr, sce); + if (!li_vrequest_handle_direct(vr)) { + li_stat_cache_entry_release(vr, sce); return LI_HANDLER_ERROR; } vr->response.http_status = 200; @@ -256,11 +256,11 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context if (dd->debug) VR_DEBUG(vr, "dirlist for \"%s\", %u entries", sce->data.path->str, sce->dirlist->len); - http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), GSTR_LEN(dd->content_type)); - etag_set_header(vr, &sce->data.st, &cachable); + li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), GSTR_LEN(dd->content_type)); + li_etag_set_header(vr, &sce->data.st, &cachable); if (cachable) { vr->response.http_status = 304; - stat_cache_entry_release(vr, sce); + li_stat_cache_entry_release(vr, sce); return LI_HANDLER_GO_ON; } @@ -285,7 +285,7 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context continue; for (j = 0; j < dd->exclude_suffix->len; j++) { - if (l_g_string_suffix(sced->path, GSTR_LEN((GString*)g_ptr_array_index(dd->exclude_suffix, j)))) { + if (li_string_suffix(sced->path, GSTR_LEN((GString*)g_ptr_array_index(dd->exclude_suffix, j)))) { hide = TRUE; break; } @@ -295,7 +295,7 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context continue; for (j = 0; j < dd->exclude_prefix->len; j++) { - if (l_g_string_prefix(sced->path, GSTR_LEN((GString*)g_ptr_array_index(dd->exclude_prefix, j)))) { + if (li_string_prefix(sced->path, GSTR_LEN((GString*)g_ptr_array_index(dd->exclude_prefix, j)))) { hide = TRUE; break; } @@ -345,7 +345,7 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context string_encode(sced->path->str, encoded, ENCODING_HTML); g_string_append_len(listing, GSTR_LEN(encoded)); g_string_append_len(listing, CONST_STR_LEN("st.st_mtime); + li_string_append_int(listing, sced->st.st_mtime); g_string_append_len(listing, CONST_STR_LEN("\">")); g_string_append_len(listing, datebuf, datebuflen); g_string_append_len(listing, CONST_STR_LEN("" @@ -359,7 +359,7 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context /* list files */ for (i = 0; i < files->len; i++) { sced = &g_array_index(sce->dirlist, liStatCacheEntryData, g_array_index(files, guint, i)); - mime_str = mimetype_get(vr, sced->path); + mime_str = li_mimetype_get(vr, sced->path); localtime_r(&(sced->st.st_mtime), &tm); datebuflen = strftime(datebuf, sizeof(datebuf), "%Y-%b-%d %H:%M:%S", &tm); @@ -376,11 +376,11 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context g_string_append_len(listing, CONST_STR_LEN( "" "st.st_mtime); + li_string_append_int(listing, sced->st.st_mtime); g_string_append_len(listing, CONST_STR_LEN("\">")); g_string_append_len(listing, datebuf, datebuflen); g_string_append_len(listing, CONST_STR_LEN("st.st_size); + li_string_append_int(listing, sced->st.st_size); g_string_append_len(listing, CONST_STR_LEN("\">")); g_string_append(listing, sizebuf); g_string_append_len(listing, CONST_STR_LEN("")); @@ -404,13 +404,13 @@ static liHandlerResult dirlist(liVRequest *vr, gpointer param, gpointer *context g_string_append_printf(listing, html_footer, CORE_OPTION(LI_CORE_OPTION_SERVER_TAG).string->str); - chunkqueue_append_string(vr->out, listing); + li_chunkqueue_append_string(vr->out, listing); g_string_free(encoded, TRUE); g_array_free(directories, TRUE); g_array_free(files, TRUE); } - stat_cache_entry_release(vr, sce); + li_stat_cache_entry_release(vr, sce); return LI_HANDLER_GO_ON; } @@ -550,7 +550,7 @@ static liAction* dirlist_create(liServer *srv, liPlugin* p, liValue *val) { } } - return action_new_function(dirlist, NULL, dirlist_free, data); + return li_action_new_function(dirlist, NULL, dirlist_free, data); } static const liPluginOption options[] = { @@ -600,14 +600,14 @@ gboolean mod_dirlist_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); - mod->config = plugin_register(mods->main, "mod_dirlist", plugin_dirlist_init); + mod->config = li_plugin_register(mods->main, "mod_dirlist", plugin_dirlist_init); return mod->config != NULL; } gboolean mod_dirlist_free(liModules *mods, liModule *mod) { if (mod->config) - plugin_free(mods->main, mod->config); + li_plugin_free(mods->main, mod->config); return TRUE; } diff --git a/src/modules/mod_expire.c b/src/modules/mod_expire.c index 59f0ccc..02eac2e 100644 --- a/src/modules/mod_expire.c +++ b/src/modules/mod_expire.c @@ -87,7 +87,7 @@ static liHandlerResult expire(liVRequest *vr, gpointer param, gpointer *context) if (!vr->physical.path->len) return LI_HANDLER_GO_ON; - switch (stat_cache_get(vr, vr->physical.path, &st, &err, NULL)) { + switch (li_stat_cache_get(vr, vr->physical.path, &st, &err, NULL)) { case LI_HANDLER_GO_ON: break; case LI_HANDLER_WAIT_FOR_EVENT: return LI_HANDLER_WAIT_FOR_EVENT; default: return LI_HANDLER_GO_ON; @@ -116,11 +116,11 @@ static liHandlerResult expire(liVRequest *vr, gpointer param, gpointer *context) g_string_set_size(date_str, len); /* finally set the headers */ - http_header_overwrite(vr->response.headers, CONST_STR_LEN("Expires"), GSTR_LEN(date_str)); + li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Expires"), GSTR_LEN(date_str)); g_string_truncate(date_str, 0); g_string_append_len(date_str, CONST_STR_LEN("max-age=")); - l_g_string_append_int(date_str, max_age); - http_header_append(vr->response.headers, CONST_STR_LEN("Cache-Control"), GSTR_LEN(date_str)); + li_string_append_int(date_str, max_age); + li_http_header_append(vr->response.headers, CONST_STR_LEN("Cache-Control"), GSTR_LEN(date_str)); return LI_HANDLER_GO_ON; } @@ -204,7 +204,7 @@ static liAction* expire_create(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - return action_new_function(expire, NULL, expire_free, rule); + return li_action_new_function(expire, NULL, expire_free, rule); } @@ -238,14 +238,14 @@ gboolean mod_expire_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); - mod->config = plugin_register(mods->main, "mod_expire", plugin_expire_init); + mod->config = li_plugin_register(mods->main, "mod_expire", plugin_expire_init); return mod->config != NULL; } gboolean mod_expire_free(liModules *mods, liModule *mod) { if (mod->config) - plugin_free(mods->main, mod->config); + li_plugin_free(mods->main, mod->config); return TRUE; } diff --git a/src/modules/mod_fastcgi.c b/src/modules/mod_fastcgi.c index b9b482c..fa5dd25 100644 --- a/src/modules/mod_fastcgi.c +++ b/src/modules/mod_fastcgi.c @@ -131,7 +131,7 @@ enum FCGI_ProtocolStatus { 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); + saddr = li_sockaddr_from_string(dest_socket, 0); if (NULL == saddr.addr) { ERROR(srv, "Invalid socket address '%s'", dest_socket->str); return NULL; @@ -148,7 +148,7 @@ static void fastcgi_context_release(fastcgi_context *ctx) { if (!ctx) return; assert(g_atomic_int_get(&ctx->refcount) > 0); if (g_atomic_int_dec_and_test(&ctx->refcount)) { - sockaddr_clear(&ctx->socket); + li_sockaddr_clear(&ctx->socket); g_slice_free(fastcgi_context, ctx); } } @@ -170,13 +170,13 @@ static fastcgi_connection* fastcgi_connection_new(liVRequest *vr, fastcgi_contex ev_init(&fcon->fd_watcher, fastcgi_fd_cb); ev_io_set(&fcon->fd_watcher, -1, 0); fcon->fd_watcher.data = fcon; - fcon->fcgi_in = chunkqueue_new(); - fcon->fcgi_out = chunkqueue_new(); - fcon->stdout = chunkqueue_new(); + fcon->fcgi_in = li_chunkqueue_new(); + fcon->fcgi_out = li_chunkqueue_new(); + fcon->stdout = li_chunkqueue_new(); fcon->buf_in_record = g_byte_array_sized_new(FCGI_HEADER_LEN); fcon->requestid = 1; fcon->state = FS_WAIT_FOR_REQUEST; - http_response_parser_init(&fcon->parse_response_ctx, &vr->response, fcon->stdout, TRUE, FALSE); + li_http_response_parser_init(&fcon->parse_response_ctx, &vr->response, fcon->stdout, TRUE, FALSE); fcon->response_headers_finished = FALSE; return fcon; } @@ -190,12 +190,12 @@ static void fastcgi_connection_free(fastcgi_connection *fcon) { fastcgi_context_release(fcon->ctx); if (fcon->fd != -1) close(fcon->fd); - chunkqueue_free(fcon->fcgi_in); - chunkqueue_free(fcon->fcgi_out); - chunkqueue_free(fcon->stdout); + li_chunkqueue_free(fcon->fcgi_in); + li_chunkqueue_free(fcon->fcgi_out); + li_chunkqueue_free(fcon->stdout); g_byte_array_free(fcon->buf_in_record, TRUE); - http_response_parser_clear(&fcon->parse_response_ctx); + li_http_response_parser_clear(&fcon->parse_response_ctx); g_slice_free(fastcgi_connection, fcon); } @@ -236,7 +236,7 @@ static guint8 stream_build_fcgi_record(GByteArray *buf, guint8 type, guint16 req 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); + li_chunkqueue_append_bytearr(out, record); return padlen; } @@ -247,7 +247,7 @@ static void stream_send_data(liChunkQueue *out, guint8 type, guint16 requestid, GByteArray *tmpa = g_byte_array_sized_new(tosend + padlen); g_byte_array_append(tmpa, (const guint8*) data, tosend); append_padding(tmpa, padlen); - chunkqueue_append_bytearr(out, tmpa); + li_chunkqueue_append_bytearr(out, tmpa); data += tosend; datalen -= tosend; } @@ -261,7 +261,7 @@ static void stream_send_bytearr(liChunkQueue *out, guint8 type, guint16 requesti } else { guint8 padlen = stream_send_fcgi_record(out, type, requestid, data->len); append_padding(data, padlen); - chunkqueue_append_bytearr(out, data); + li_chunkqueue_append_bytearr(out, data); } } @@ -269,8 +269,8 @@ static void stream_send_chunks(liChunkQueue *out, guint8 type, guint16 requestid while (in->length > 0) { guint16 tosend = (in->length > G_MAXUINT16) ? G_MAXUINT16 : in->length; guint8 padlen = stream_send_fcgi_record(out, type, requestid, tosend); - chunkqueue_steal_len(out, in, tosend); - chunkqueue_append_mem(out, __padding, padlen); + li_chunkqueue_steal_len(out, in, tosend); + li_chunkqueue_append_mem(out, __padding, padlen); } if (in->is_closed && !out->is_closed) { @@ -308,13 +308,13 @@ static void fastcgi_send_begin(fastcgi_connection *fcon) { g_byte_array_append(buf, (const guint8*) &w, sizeof(w)); l_byte_array_append_c(buf, 0); /* TODO: FCGI_KEEP_CONN */ append_padding(buf, 5); - chunkqueue_append_bytearr(fcon->fcgi_out, buf); + li_chunkqueue_append_bytearr(fcon->fcgi_out, buf); } 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))) { + if (NULL != (sval = li_environment_dup_pop(envdup, key, keylen))) { append_key_value_pair(buf, key, keylen, GSTR_LEN(sval)); } else { append_key_value_pair(buf, key, keylen, val, valuelen); @@ -419,7 +419,7 @@ static void fastcgi_send_env(liVRequest *vr, fastcgi_connection *fcon) { GByteArray *buf = g_byte_array_sized_new(0); liEnvironmentDup *envdup; - envdup = environment_make_dup(&vr->env); + envdup = li_environment_make_dup(&vr->env); fastcgi_env_create(vr, envdup, buf); { @@ -430,7 +430,7 @@ static void fastcgi_send_env(liVRequest *vr, fastcgi_connection *fcon) { 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"))) { + if (!li_strncase_equal(&hkey, CONST_STR_LEN("CONTENT-TYPE"))) { g_string_append_len(tmp, CONST_STR_LEN("HTTP_")); } g_string_append_len(tmp, h->data->str, h->keylen); @@ -450,7 +450,7 @@ static void fastcgi_send_env(liVRequest *vr, fastcgi_connection *fcon) { } } - environment_dup_free(envdup); + li_environment_dup_free(envdup); stream_send_bytearr(fcon->fcgi_out, FCGI_PARAMS, fcon->requestid, buf); stream_send_fcgi_record(fcon->fcgi_out, FCGI_PARAMS, fcon->requestid, 0); @@ -459,7 +459,7 @@ static void fastcgi_send_env(liVRequest *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); + li_ev_io_add_events(vr->wrk->loop, &fcon->fd_watcher, EV_WRITE); } static gboolean fastcgi_get_packet(fastcgi_connection *fcon) { @@ -471,7 +471,7 @@ static gboolean fastcgi_get_packet(fastcgi_connection *fcon) { /* wait for padding data ? */ gint len = fcon->fcgi_in->length; if (len > fcon->fcgi_in_record.remainingPadding) len = fcon->fcgi_in_record.remainingPadding; - chunkqueue_skip(fcon->fcgi_in, len); + li_chunkqueue_skip(fcon->fcgi_in, len); fcon->fcgi_in_record.remainingPadding -= len; if (0 != fcon->fcgi_in_record.remainingPadding) return FALSE; /* wait for data */ fcon->fcgi_in_record.valid = FALSE; /* read next packet */ @@ -480,7 +480,7 @@ static gboolean fastcgi_get_packet(fastcgi_connection *fcon) { } } - if (!chunkqueue_extract_to_bytearr(fcon->vr, fcon->fcgi_in, FCGI_HEADER_LEN, fcon->buf_in_record)) return FALSE; /* need more data */ + if (!li_chunkqueue_extract_to_bytearr(fcon->vr, fcon->fcgi_in, FCGI_HEADER_LEN, fcon->buf_in_record)) return FALSE; /* need more data */ data = (const unsigned char*) fcon->buf_in_record->data; fcon->fcgi_in_record.version = data[0]; @@ -493,7 +493,7 @@ static gboolean fastcgi_get_packet(fastcgi_connection *fcon) { fcon->fcgi_in_record.valid = TRUE; fcon->fcgi_in_record.first = TRUE; - chunkqueue_skip(fcon->fcgi_in, FCGI_HEADER_LEN); + li_chunkqueue_skip(fcon->fcgi_in, FCGI_HEADER_LEN); return TRUE; } @@ -515,34 +515,34 @@ static gboolean fastcgi_parse_response(fastcgi_connection *fcon) { VR_ERROR(vr, "Unknown fastcgi protocol version %i", (gint) fcon->fcgi_in_record.version); close(fcon->fd); fcon->fd = -1; - vrequest_error(vr); + li_vrequest_error(vr); return FALSE; } switch (fcon->fcgi_in_record.type) { case FCGI_END_REQUEST: - chunkqueue_skip(fcon->fcgi_in, fastcgi_available(fcon)); + li_chunkqueue_skip(fcon->fcgi_in, fastcgi_available(fcon)); fcon->stdout->is_closed = TRUE; break; case FCGI_STDOUT: if (0 == fcon->fcgi_in_record.contentLength) { fcon->stdout->is_closed = TRUE; } else { - chunkqueue_steal_len(fcon->stdout, fcon->fcgi_in, fastcgi_available(fcon)); + li_chunkqueue_steal_len(fcon->stdout, fcon->fcgi_in, fastcgi_available(fcon)); } break; case FCGI_STDERR: len = fastcgi_available(fcon); - chunkqueue_extract_to(vr, fcon->fcgi_in, len, vr->wrk->tmp_str); + li_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, LI_LOG_LEVEL_BACKEND, 0, vr->wrk->tmp_str->str, ""); + li_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) "); } - chunkqueue_skip(fcon->fcgi_in, len); + li_chunkqueue_skip(fcon->fcgi_in, len); break; default: if (fcon->fcgi_in_record.first) VR_WARNING(vr, "Unhandled fastcgi record type %i", (gint) fcon->fcgi_in_record.type); - chunkqueue_skip(fcon->fcgi_in, fastcgi_available(fcon)); + li_chunkqueue_skip(fcon->fcgi_in, fastcgi_available(fcon)); break; } fcon->fcgi_in_record.first = FALSE; @@ -559,21 +559,21 @@ static void fastcgi_fd_cb(struct ev_loop *loop, ev_io *w, int revents) { if (fcon->state == FS_CONNECTING) { if (LI_HANDLER_GO_ON != fastcgi_statemachine(fcon->vr, fcon)) { - vrequest_error(fcon->vr); + li_vrequest_error(fcon->vr); } return; } if (revents & EV_READ) { if (fcon->fcgi_in->is_closed) { - ev_io_rem_events(loop, w, EV_READ); + li_ev_io_rem_events(loop, w, EV_READ); } else { - switch (network_read(fcon->vr, w->fd, fcon->fcgi_in)) { + switch (li_network_read(fcon->vr, w->fd, fcon->fcgi_in)) { case LI_NETWORK_STATUS_SUCCESS: break; case LI_NETWORK_STATUS_FATAL_ERROR: VR_ERROR(fcon->vr, "%s", "network read fatal error"); - vrequest_error(fcon->vr); + li_vrequest_error(fcon->vr); return; case LI_NETWORK_STATUS_CONNECTION_CLOSE: fcon->fcgi_in->is_closed = TRUE; @@ -585,7 +585,7 @@ static void fastcgi_fd_cb(struct ev_loop *loop, ev_io *w, int revents) { break; case LI_NETWORK_STATUS_WAIT_FOR_AIO_EVENT: /* TODO: aio */ - ev_io_rem_events(loop, w, EV_READ); + li_ev_io_rem_events(loop, w, EV_READ); break; } } @@ -593,12 +593,12 @@ 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)) { + switch (li_network_write(fcon->vr, w->fd, fcon->fcgi_out, 256*1024)) { case LI_NETWORK_STATUS_SUCCESS: break; case LI_NETWORK_STATUS_FATAL_ERROR: VR_ERROR(fcon->vr, "%s", "network write fatal error"); - vrequest_error(fcon->vr); + li_vrequest_error(fcon->vr); return; case LI_NETWORK_STATUS_CONNECTION_CLOSE: fcon->fcgi_in->is_closed = TRUE; @@ -609,32 +609,32 @@ static void fastcgi_fd_cb(struct ev_loop *loop, ev_io *w, int revents) { case LI_NETWORK_STATUS_WAIT_FOR_EVENT: break; case LI_NETWORK_STATUS_WAIT_FOR_AIO_EVENT: - ev_io_rem_events(loop, w, EV_WRITE); + li_ev_io_rem_events(loop, w, EV_WRITE); /* TODO: aio */ break; } } if (fcon->fcgi_out->length == 0) { - ev_io_rem_events(loop, w, EV_WRITE); + li_ev_io_rem_events(loop, w, EV_WRITE); } } if (!fastcgi_parse_response(fcon)) return; - if (!fcon->response_headers_finished && LI_HANDLER_GO_ON == http_response_parse(fcon->vr, &fcon->parse_response_ctx)) { + if (!fcon->response_headers_finished && LI_HANDLER_GO_ON == li_http_response_parse(fcon->vr, &fcon->parse_response_ctx)) { fcon->response_headers_finished = TRUE; - vrequest_handle_response_headers(fcon->vr); + li_vrequest_handle_response_headers(fcon->vr); } if (fcon->response_headers_finished) { - chunkqueue_steal_all(fcon->vr->out, fcon->stdout); + li_chunkqueue_steal_all(fcon->vr->out, fcon->stdout); fcon->vr->out->is_closed = fcon->stdout->is_closed; - vrequest_handle_response_body(fcon->vr); + li_vrequest_handle_response_body(fcon->vr); } if (fcon->fcgi_in->is_closed && !fcon->vr->out->is_closed) { VR_ERROR(fcon->vr, "%s", "unexpected end-of-file (perhaps the fastcgi process died)"); - vrequest_error(fcon->vr); + li_vrequest_error(fcon->vr); } } @@ -650,7 +650,7 @@ static liHandlerResult fastcgi_statemachine(liVRequest *vr, fastcgi_connection * 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)) + if (0 != li_chunkqueue_limit_available(vr->in)) return LI_HANDLER_GO_ON; } fcon->state = FS_CONNECT; @@ -662,12 +662,12 @@ static liHandlerResult fastcgi_statemachine(liVRequest *vr, fastcgi_connection * } while (-1 == fcon->fd && errno == EINTR); if (-1 == fcon->fd) { if (errno == EMFILE) { - server_out_of_fds(vr->wrk->srv); + li_server_out_of_fds(vr->wrk->srv); } VR_ERROR(vr, "Couldn't open socket: %s", g_strerror(errno)); return LI_HANDLER_ERROR; } - fd_init(fcon->fd); + li_fd_init(fcon->fd); ev_io_set(&fcon->fd_watcher, fcon->fd, EV_READ | EV_WRITE); ev_io_start(vr->wrk->loop, &fcon->fd_watcher); @@ -682,14 +682,14 @@ static liHandlerResult fastcgi_statemachine(liVRequest *vr, fastcgi_connection * return LI_HANDLER_GO_ON; case EAGAIN: /* backend overloaded */ fastcgi_close(vr, p); - vrequest_backend_overloaded(vr); + li_vrequest_backend_overloaded(vr); 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, + li_sockaddr_to_string(fcon->ctx->socket, vr->wrk->tmp_str, TRUE)->str, g_strerror(errno)); fastcgi_close(vr, p); - vrequest_backend_dead(vr); + li_vrequest_backend_dead(vr); return LI_HANDLER_GO_ON; } } @@ -719,7 +719,7 @@ static liHandlerResult fastcgi_handle(liVRequest *vr, gpointer param, gpointer * fastcgi_context *ctx = (fastcgi_context*) param; fastcgi_connection *fcon; UNUSED(context); - if (!vrequest_handle_indirect(vr, ctx->plugin)) return LI_HANDLER_GO_ON; + if (!li_vrequest_handle_indirect(vr, ctx->plugin)) return LI_HANDLER_GO_ON; fcon = fastcgi_connection_new(vr, ctx); if (!fcon) { @@ -727,9 +727,9 @@ static liHandlerResult fastcgi_handle(liVRequest *vr, gpointer param, gpointer * } g_ptr_array_index(vr->plugin_ctx, ctx->plugin->id) = fcon; - chunkqueue_set_limit(fcon->fcgi_in, vr->out->limit); - chunkqueue_set_limit(fcon->stdout, vr->out->limit); - chunkqueue_set_limit(fcon->fcgi_out, vr->in->limit); + li_chunkqueue_set_limit(fcon->fcgi_in, vr->out->limit); + li_chunkqueue_set_limit(fcon->stdout, vr->out->limit); + li_chunkqueue_set_limit(fcon->fcgi_out, vr->in->limit); if (vr->out->limit) vr->out->limit->io_watcher = &fcon->fd_watcher; return fastcgi_statemachine(vr, fcon); @@ -771,7 +771,7 @@ static liAction* fastcgi_create(liServer *srv, liPlugin* p, liValue *val) { ctx = fastcgi_context_new(srv, p, val->data.string); if (!ctx) return NULL; - return action_new_function(fastcgi_handle, NULL, fastcgi_free, ctx); + return li_action_new_function(fastcgi_handle, NULL, fastcgi_free, ctx); } static const liPluginOption options[] = { @@ -805,14 +805,14 @@ static void plugin_init(liServer *srv, liPlugin *p) { gboolean mod_fastcgi_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); - mod->config = plugin_register(mods->main, "mod_fastcgi", plugin_init); + mod->config = li_plugin_register(mods->main, "mod_fastcgi", plugin_init); return mod->config != NULL; } gboolean mod_fastcgi_free(liModules *mods, liModule *mod) { if (mod->config) - plugin_free(mods->main, mod->config); + li_plugin_free(mods->main, mod->config); return TRUE; } diff --git a/src/modules/mod_fortune.c b/src/modules/mod_fortune.c index aa59ff6..0c1363c 100644 --- a/src/modules/mod_fortune.c +++ b/src/modules/mod_fortune.c @@ -50,14 +50,14 @@ static liHandlerResult fortune_header_handle(liVRequest *vr, gpointer param, gpo if (fd->cookies->len) { GString *cookie = fortune_rand(fd); - http_header_insert(vr->response.headers, CONST_STR_LEN("X-fortune"), GSTR_LEN(cookie)); + li_http_header_insert(vr->response.headers, CONST_STR_LEN("X-fortune"), GSTR_LEN(cookie)); } return LI_HANDLER_GO_ON; } 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); + return li_action_new_function(fortune_header_handle, NULL, NULL, p->data); } static liHandlerResult fortune_page_handle(liVRequest *vr, gpointer param, gpointer *context) { @@ -65,16 +65,16 @@ static liHandlerResult fortune_page_handle(liVRequest *vr, gpointer param, gpoin UNUSED(context); - if (!vrequest_handle_direct(vr)) + if (!li_vrequest_handle_direct(vr)) return LI_HANDLER_GO_ON; vr->response.http_status = 200; if (fd->cookies->len) { GString *cookie = fortune_rand(fd); - chunkqueue_append_mem(vr->out, GSTR_LEN(cookie)); + li_chunkqueue_append_mem(vr->out, GSTR_LEN(cookie)); } else { - chunkqueue_append_mem(vr->out, CONST_STR_LEN("no cookies in the cookie box")); + li_chunkqueue_append_mem(vr->out, CONST_STR_LEN("no cookies in the cookie box")); } return LI_HANDLER_GO_ON; @@ -82,7 +82,7 @@ static liHandlerResult fortune_page_handle(liVRequest *vr, gpointer param, gpoin 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); + return li_action_new_function(fortune_page_handle, NULL, NULL, p->data); } static gboolean fortune_load(liServer *srv, liPlugin* p, liValue *val) { @@ -94,7 +94,7 @@ static gboolean fortune_load(liServer *srv, liPlugin* p, liValue *val) { fortune_data *fd = p->data; 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"); + ERROR(srv, "fortune.load takes a string as parameter, %s given", val ? li_value_type_string(val->type) : "none"); return FALSE; } @@ -189,7 +189,7 @@ gboolean mod_fortune_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); - mod->config = plugin_register(srv, "mod_fortune", plugin_fortune_init); + mod->config = li_plugin_register(srv, "mod_fortune", plugin_fortune_init); if (!mod->config) return FALSE; @@ -199,7 +199,7 @@ gboolean mod_fortune_init(liModules *mods, liModule *mod) { gboolean mod_fortune_free(liModules *mods, liModule *mod) { if (mod->config) - plugin_free(mods->main, mod->config); + li_plugin_free(mods->main, mod->config); return TRUE; } diff --git a/src/modules/mod_rewrite.c b/src/modules/mod_rewrite.c index 780ca10..7939c9b 100644 --- a/src/modules/mod_rewrite.c +++ b/src/modules/mod_rewrite.c @@ -172,7 +172,7 @@ static GArray *rewrite_parts_parse(GString *str, gboolean *has_querystring) { return NULL; } - rp.data.cond_lval = cond_lvalue_from_string(c-len, len); + rp.data.cond_lval = li_cond_lvalue_from_string(c-len, len); if (rp.data.cond_lval == LI_COMP_UNKNOWN) { /* parse error */ @@ -447,7 +447,7 @@ static liAction* rewrite_create(liServer *srv, liPlugin* p, liValue *val) { } - return action_new_function(rewrite, NULL, rewrite_free, rd); + return li_action_new_function(rewrite, NULL, rewrite_free, rd); } @@ -501,14 +501,14 @@ gboolean mod_rewrite_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); - mod->config = plugin_register(mods->main, "mod_rewrite", plugin_rewrite_init); + mod->config = li_plugin_register(mods->main, "mod_rewrite", plugin_rewrite_init); return mod->config != NULL; } gboolean mod_rewrite_free(liModules *mods, liModule *mod) { if (mod->config) - plugin_free(mods->main, mod->config); + li_plugin_free(mods->main, mod->config); return TRUE; } diff --git a/src/modules/mod_status.c b/src/modules/mod_status.c index 51e897e..1499ab7 100644 --- a/src/modules/mod_status.c +++ b/src/modules/mod_status.c @@ -229,7 +229,7 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result UNUSED(fdata); if (!complete) { - /* someone called collect_break, so we don't need any vrequest handling here. just free the result data */ + /* someone called li_collect_break, so we don't need any vrequest handling here. just free the result data */ guint i, j; for (i = 0; i < result->len; i++) { @@ -321,7 +321,7 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result " \n" )); - counter_format((guint64)(CUR_TS(vr->wrk) - vr->wrk->srv->started), COUNTER_TIME, tmpstr); + li_counter_format((guint64)(CUR_TS(vr->wrk) - vr->wrk->srv->started), COUNTER_TIME, tmpstr); g_string_append_printf(html, html_top, vr->request.uri.host->str, tmpstr->str, @@ -338,9 +338,9 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result #define PERCENTAGE(x, y) (y ? (x * 100 / y) : 0) for (i = 0; i < result->len; i++) { mod_status_wrk_data *sd = g_ptr_array_index(result, i); - counter_format(sd->stats.requests, COUNTER_UNITS, count_req); - counter_format(sd->stats.bytes_in, COUNTER_BYTES, count_bin); - counter_format(sd->stats.bytes_out, COUNTER_BYTES, count_bout); + li_counter_format(sd->stats.requests, COUNTER_UNITS, count_req); + li_counter_format(sd->stats.bytes_in, COUNTER_BYTES, count_bin); + li_counter_format(sd->stats.bytes_out, COUNTER_BYTES, count_bout); g_string_printf(tmpstr, "Worker #%u", i+1); g_string_append_printf(html, html_worker_row, "", tmpstr->str, count_req->str, PERCENTAGE(sd->stats.requests, totals.requests), @@ -350,9 +350,9 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result } #undef PERCENTAGE - counter_format(totals.requests, COUNTER_UNITS, count_req); - counter_format(totals.bytes_in, COUNTER_BYTES, count_bin); - counter_format(totals.bytes_out, COUNTER_BYTES, count_bout); + li_counter_format(totals.requests, COUNTER_UNITS, count_req); + li_counter_format(totals.bytes_in, COUNTER_BYTES, count_bin); + li_counter_format(totals.bytes_out, COUNTER_BYTES, count_bout); g_string_append_printf(html, html_worker_row, "totals", "Total", count_req->str, G_GUINT64_CONSTANT(100), count_bin->str, G_GUINT64_CONSTANT(100), @@ -371,9 +371,9 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result for (i = 0; i < result->len; i++) { mod_status_wrk_data *sd = g_ptr_array_index(result, i); - counter_format(sd->stats.requests / uptime, COUNTER_UNITS, count_req); - counter_format(sd->stats.bytes_in / uptime, COUNTER_BYTES, count_bin); - counter_format(sd->stats.bytes_out / uptime, COUNTER_BYTES, count_bout); + li_counter_format(sd->stats.requests / uptime, COUNTER_UNITS, count_req); + li_counter_format(sd->stats.bytes_in / uptime, COUNTER_BYTES, count_bin); + li_counter_format(sd->stats.bytes_out / uptime, COUNTER_BYTES, count_bout); g_string_printf(tmpstr, "Worker #%u", i+1); g_string_append_printf(html, html_worker_row_avg, "", tmpstr->str, count_req->str, @@ -384,9 +384,9 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result } #undef PERCENTAGE - counter_format(totals.requests / uptime, COUNTER_UNITS, count_req); - counter_format(totals.bytes_in / uptime, COUNTER_BYTES, count_bin); - counter_format(totals.bytes_out / uptime, COUNTER_BYTES, count_bout); + li_counter_format(totals.requests / uptime, COUNTER_UNITS, count_req); + li_counter_format(totals.bytes_in / uptime, COUNTER_BYTES, count_bin); + li_counter_format(totals.bytes_out / uptime, COUNTER_BYTES, count_bout); g_string_append_printf(html, html_worker_row_avg, "totals", "Total", count_req->str, count_bin->str, @@ -407,9 +407,9 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result for (i = 0; i < result->len; i++) { mod_status_wrk_data *sd = g_ptr_array_index(result, i); - counter_format(sd->stats.requests_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_UNITS, count_req); - counter_format(sd->stats.bytes_in_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_BYTES, count_bin); - counter_format(sd->stats.bytes_out_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_BYTES, count_bout); + li_counter_format(sd->stats.requests_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_UNITS, count_req); + li_counter_format(sd->stats.bytes_in_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_BYTES, count_bin); + li_counter_format(sd->stats.bytes_out_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_BYTES, count_bout); g_string_printf(tmpstr, "Worker #%u", i+1); g_string_append_printf(html, html_worker_row_avg, "", tmpstr->str, count_req->str, @@ -420,9 +420,9 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result } #undef PERCENTAGE - counter_format(totals.requests_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_UNITS, count_req); - counter_format(totals.bytes_in_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_BYTES, count_bin); - counter_format(totals.bytes_out_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_BYTES, count_bout); + li_counter_format(totals.requests_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_UNITS, count_req); + li_counter_format(totals.bytes_in_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_BYTES, count_bin); + li_counter_format(totals.bytes_out_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_BYTES, count_bout); g_string_append_printf(html, html_worker_row_avg, "totals", "Total", count_req->str, count_bin->str, @@ -480,17 +480,17 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result for (j = 0; j < sd->connections->len; j++) { mod_status_con_data *cd = &g_array_index(sd->connections, mod_status_con_data, j); - counter_format((guint64)(CUR_TS(vr->wrk) - cd->ts), COUNTER_TIME, ts); - counter_format(cd->bytes_in, COUNTER_BYTES, bytes_in); - counter_format(cd->bytes_in_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_BYTES, bytes_in_5s); - counter_format(cd->bytes_out, COUNTER_BYTES, bytes_out); - counter_format(cd->bytes_out_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_BYTES, bytes_out_5s); - counter_format(cd->request_size, COUNTER_BYTES, req_len); - counter_format(cd->response_size, COUNTER_BYTES, resp_len); + li_counter_format((guint64)(CUR_TS(vr->wrk) - cd->ts), COUNTER_TIME, ts); + li_counter_format(cd->bytes_in, COUNTER_BYTES, bytes_in); + li_counter_format(cd->bytes_in_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_BYTES, bytes_in_5s); + li_counter_format(cd->bytes_out, COUNTER_BYTES, bytes_out); + li_counter_format(cd->bytes_out_5s_diff / G_GUINT64_CONSTANT(5), COUNTER_BYTES, bytes_out_5s); + li_counter_format(cd->request_size, COUNTER_BYTES, req_len); + li_counter_format(cd->response_size, COUNTER_BYTES, resp_len); g_string_append_printf(html, html_connections_row, cd->remote_addr_str->str, - connection_state_str(cd->state), + li_connection_state_str(cd->state), cd->host->str, cd->path->str, cd->query->len ? "?":"", @@ -500,7 +500,7 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result bytes_out->str, bytes_in_5s->str, bytes_out_5s->str, - (cd->state >= LI_CON_STATE_HANDLE_MAINVR) ? http_method_string(cd->method, &len) : "", + (cd->state >= LI_CON_STATE_HANDLE_MAINVR) ? li_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 : "" ); @@ -536,8 +536,8 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result " \n" "\n" )); - chunkqueue_append_string(vr->out, html); - http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html")); + li_chunkqueue_append_string(vr->out, html); + li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html")); g_string_free(count_req, TRUE); g_string_free(count_bin, TRUE); @@ -546,16 +546,16 @@ static void status_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *result vr->response.http_status = 200; - vrequest_joblist_append(vr); + li_vrequest_joblist_append(vr); } else { /* something went wrong, client may have dropped the connection */ VR_ERROR(vr, "%s", "collect request didn't end up complete"); - vrequest_error(vr); + li_vrequest_error(vr); } } static liHandlerResult status_page_handle(liVRequest *vr, gpointer param, gpointer *context) { - if (vrequest_handle_direct(vr)) { + if (li_vrequest_handle_direct(vr)) { liCollectInfo *ci; mod_status_job *j = g_slice_new(mod_status_job); j->vr = vr; @@ -564,7 +564,7 @@ static liHandlerResult status_page_handle(liVRequest *vr, gpointer param, gpoint VR_DEBUG(vr, "%s", "collecting stats..."); - ci = collect_start(vr->wrk, status_collect_func, NULL, status_collect_cb, j); + ci = li_collect_start(vr->wrk, status_collect_func, NULL, status_collect_cb, j); *context = ci; /* may be NULL */ } @@ -577,7 +577,7 @@ static liHandlerResult status_page_cleanup(liVRequest *vr, gpointer param, gpoin UNUSED(vr); UNUSED(param); - collect_break(ci); + li_collect_break(ci); return LI_HANDLER_GO_ON; } @@ -586,7 +586,7 @@ static liAction* status_page(liServer *srv, liPlugin* p, liValue *val) { UNUSED(srv); UNUSED(val); - return action_new_function(status_page_handle, status_page_cleanup, NULL, p); + return li_action_new_function(status_page_handle, status_page_cleanup, NULL, p); } @@ -622,7 +622,7 @@ gboolean mod_status_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); - mod->config = plugin_register(mods->main, "mod_status", plugin_status_init); + mod->config = li_plugin_register(mods->main, "mod_status", plugin_status_init); return mod->config != NULL; } @@ -631,7 +631,7 @@ gboolean mod_status_free(liModules *mods, liModule *mod) { UNUSED(mods); UNUSED(mod); if (mod->config) - plugin_free(mods->main, mod->config); + li_plugin_free(mods->main, mod->config); return TRUE; } diff --git a/src/modules/mod_vhost.c b/src/modules/mod_vhost.c index 43a7241..5ae9a8c 100644 --- a/src/modules/mod_vhost.c +++ b/src/modules/mod_vhost.c @@ -222,7 +222,7 @@ static liAction* vhost_simple_create(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - *setting = value_extract(v).string; + *setting = li_value_extract(v).string; } if (!sd->server_root || !sd->docroot || !sd->default_vhost) { @@ -238,7 +238,7 @@ static liAction* vhost_simple_create(liServer *srv, liPlugin* p, liValue *val) { if (sd->docroot->len == 0 || sd->docroot->str[0] != G_DIR_SEPARATOR) g_string_prepend_c(sd->docroot, G_DIR_SEPARATOR); - return action_new_function(vhost_simple, NULL, vhost_simple_free, sd); + return li_action_new_function(vhost_simple, NULL, vhost_simple_free, sd); } static liHandlerResult vhost_map(liVRequest *vr, gpointer param, gpointer *context) { @@ -253,11 +253,11 @@ static liHandlerResult vhost_map(liVRequest *vr, gpointer param, gpointer *conte if (v) { if (debug) VR_DEBUG(vr, "vhost_map: host %s found in hashtable", vr->request.uri.host->str); - action_enter(vr, v->data.val_action.action); + li_action_enter(vr, v->data.val_action.action); } else if (md->default_action) { if (debug) VR_DEBUG(vr, "vhost_map: host %s not found in hashtable, executing default action", vr->request.uri.host->str); - action_enter(vr, md->default_action->data.val_action.action); + li_action_enter(vr, md->default_action->data.val_action.action); } else { if (debug) VR_DEBUG(vr, "vhost_map: neither host %s found in hashtable nor default action specified, doing nothing", vr->request.uri.host->str); @@ -289,7 +289,7 @@ static liAction* vhost_map_create(liServer *srv, liPlugin* p, liValue *val) { md = g_slice_new0(vhost_map_data); md->plugin = p; - md->hash = value_extract(val).hash; + md->hash = li_value_extract(val).hash; str = g_string_new_len(CONST_STR_LEN("default")); md->default_action = g_hash_table_lookup(md->hash, str); g_string_free(str, TRUE); @@ -300,15 +300,15 @@ static liAction* vhost_map_create(liServer *srv, liPlugin* p, liValue *val) { val = v; 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)); + ERROR(srv, "vhost.map expects a hashtable with action values as parameter, %s value given", li_value_type_string(val->type)); vhost_map_free(srv, md); return NULL; } - action_acquire(val->data.val_action.action); + li_action_acquire(val->data.val_action.action); } - return action_new_function(vhost_map, NULL, vhost_map_free, md); + return li_action_new_function(vhost_map, NULL, vhost_map_free, md); } static liHandlerResult vhost_pattern(liVRequest *vr, gpointer param, gpointer *context) { @@ -418,7 +418,7 @@ static liAction* vhost_pattern_create(liServer *srv, liPlugin* p, liValue *val) return NULL; } - str = value_extract(val).string; + str = li_value_extract(val).string; pd = g_slice_new0(vhost_pattern_data); pd->parts = g_array_sized_new(FALSE, TRUE, sizeof(vhost_pattern_part), 6); @@ -501,7 +501,7 @@ static liAction* vhost_pattern_create(liServer *srv, liPlugin* p, liValue *val) g_array_append_val(pd->parts, part); } - return action_new_function(vhost_pattern, NULL, vhost_pattern_free, pd); + return li_action_new_function(vhost_pattern, NULL, vhost_pattern_free, pd); } @@ -538,14 +538,14 @@ gboolean mod_vhost_init(liModules *mods, liModule *mod) { MODULE_VERSION_CHECK(mods); - mod->config = plugin_register(mods->main, "mod_vhost", plugin_vhost_init); + mod->config = li_plugin_register(mods->main, "mod_vhost", plugin_vhost_init); return mod->config != NULL; } gboolean mod_vhost_free(liModules *mods, liModule *mod) { if (mod->config) - plugin_free(mods->main, mod->config); + li_plugin_free(mods->main, mod->config); return TRUE; } diff --git a/src/network.c b/src/network.c index de1cf6e..a67540a 100644 --- a/src/network.c +++ b/src/network.c @@ -3,7 +3,7 @@ #include /** repeats write after EINTR */ -ssize_t net_write(int fd, void *buf, ssize_t nbyte) { +ssize_t li_net_write(int fd, void *buf, ssize_t nbyte) { ssize_t r; while (-1 == (r = write(fd, buf, nbyte))) { switch (errno) { @@ -20,7 +20,7 @@ ssize_t net_write(int fd, void *buf, ssize_t nbyte) { } /** repeats read after EINTR */ -ssize_t net_read(int fd, void *buf, ssize_t nbyte) { +ssize_t li_net_read(int fd, void *buf, ssize_t nbyte) { ssize_t r; while (-1 == (r = read(fd, buf, nbyte))) { switch (errno) { @@ -36,7 +36,7 @@ ssize_t net_read(int fd, void *buf, ssize_t nbyte) { return r; } -liNetworkStatus network_write(liVRequest *vr, int fd, liChunkQueue *cq, goffset write_max) { +liNetworkStatus li_network_write(liVRequest *vr, int fd, liChunkQueue *cq, goffset write_max) { liNetworkStatus res; #ifdef TCP_CORK int corked = 0; @@ -56,9 +56,9 @@ liNetworkStatus network_write(liVRequest *vr, int fd, liChunkQueue *cq, goffset write_bytes = write_max; /* TODO: add setup-option to select the backend */ #ifdef USE_SENDFILE - res = network_write_sendfile(vr, fd, cq, &write_bytes); + res = li_network_write_sendfile(vr, fd, cq, &write_bytes); #else - res = network_write_writev(vr, fd, cq, &write_bytes); + res = li_network_write_writev(vr, fd, cq, &write_bytes); #endif wrote = write_max - write_bytes; if (wrote > 0 && res == LI_NETWORK_STATUS_WAIT_FOR_EVENT) res = LI_NETWORK_STATUS_SUCCESS; @@ -73,7 +73,7 @@ liNetworkStatus network_write(liVRequest *vr, int fd, liChunkQueue *cq, goffset return res; } -liNetworkStatus network_read(liVRequest *vr, int fd, liChunkQueue *cq) { +liNetworkStatus li_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; @@ -84,7 +84,7 @@ liNetworkStatus network_read(liVRequest *vr, int fd, liChunkQueue *cq) { max_read = cq->limit->limit - cq->limit->current; if (max_read <= 0) { max_read = 0; /* we still have to read something */ - VR_ERROR(vr, "%s", "network_read: fd should be disabled as chunkqueue is already full"); + VR_ERROR(vr, "%s", "li_network_read: fd should be disabled as chunkqueue is already full"); } } } @@ -92,7 +92,7 @@ liNetworkStatus network_read(liVRequest *vr, int fd, liChunkQueue *cq) { do { GByteArray *buf = g_byte_array_sized_new(blocksize); g_byte_array_set_size(buf, blocksize); - if (-1 == (r = net_read(fd, buf->data, blocksize))) { + if (-1 == (r = li_net_read(fd, buf->data, blocksize))) { g_byte_array_free(buf, TRUE); switch (errno) { case EAGAIN: @@ -111,7 +111,7 @@ liNetworkStatus network_read(liVRequest *vr, int fd, liChunkQueue *cq) { return len ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_CONNECTION_CLOSE; } g_byte_array_set_size(buf, r); - chunkqueue_append_bytearr(cq, buf); + li_chunkqueue_append_bytearr(cq, buf); len += r; } while (r == blocksize && len < max_read); diff --git a/src/network_sendfile.c b/src/network_sendfile.c index 233975e..dc8722f 100644 --- a/src/network_sendfile.c +++ b/src/network_sendfile.c @@ -167,7 +167,7 @@ static liNetworkStatus network_backend_sendfile(liVRequest *vr, int fd, liChunkQ return did_write_something ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_FATAL_ERROR; } - switch (chunkfile_open(vr, c->file.file)) { + switch (li_chunkfile_open(vr, c->file.file)) { case LI_HANDLER_GO_ON: break; default: @@ -181,13 +181,13 @@ static liNetworkStatus network_backend_sendfile(liVRequest *vr, int fd, liChunkQ r = 0; switch (lighty_sendfile(vr, fd, c->file.file->fd, file_offset, toSend, &r)) { case NSR_SUCCESS: - chunkqueue_skip(cq, r); + li_chunkqueue_skip(cq, r); *write_max -= r; break; case NSR_WAIT_FOR_EVENT: return LI_NETWORK_STATUS_WAIT_FOR_EVENT; case NSR_FALLBACK: - LI_NETWORK_FALLBACK(network_backend_write, write_max); + LI_NETWORK_FALLBACK(li_network_backend_write, write_max); break; case NSR_CLOSE: return LI_NETWORK_STATUS_CONNECTION_CLOSE; @@ -218,14 +218,14 @@ static liNetworkStatus network_backend_sendfile(liVRequest *vr, int fd, liChunkQ return LI_NETWORK_STATUS_SUCCESS; } -liNetworkStatus network_write_sendfile(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max) { +liNetworkStatus li_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: - LI_NETWORK_FALLBACK(network_backend_writev, write_max); + LI_NETWORK_FALLBACK(li_network_backend_writev, write_max); break; case FILE_CHUNK: LI_NETWORK_FALLBACK(network_backend_sendfile, write_max); diff --git a/src/network_write.c b/src/network_write.c index 4ad60d0..09706c1 100644 --- a/src/network_write.c +++ b/src/network_write.c @@ -1,7 +1,7 @@ #include -liNetworkStatus network_backend_write(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max) { +liNetworkStatus li_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; @@ -15,7 +15,7 @@ liNetworkStatus network_backend_write(liVRequest *vr, int fd, liChunkQueue *cq, ci = chunkqueue_iter(cq); /* TODO: handle SIGBUS */ - switch (chunkiter_read_mmap(vr, ci, 0, blocksize, &block_data, &block_len)) { + switch (li_chunkiter_read_mmap(vr, ci, 0, blocksize, &block_data, &block_len)) { case LI_HANDLER_GO_ON: break; case LI_HANDLER_ERROR: @@ -23,7 +23,7 @@ liNetworkStatus network_backend_write(liVRequest *vr, int fd, liChunkQueue *cq, return LI_NETWORK_STATUS_FATAL_ERROR; } - if (-1 == (r = net_write(fd, block_data, block_len))) { + if (-1 == (r = li_net_write(fd, block_data, block_len))) { switch (errno) { case EAGAIN: #if EWOULDBLOCK != EAGAIN @@ -41,7 +41,7 @@ liNetworkStatus network_backend_write(liVRequest *vr, int fd, liChunkQueue *cq, return did_write_something ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_WAIT_FOR_EVENT; } - chunkqueue_skip(cq, r); + li_chunkqueue_skip(cq, r); did_write_something = TRUE; *write_max -= r; } while (r == block_len && *write_max > 0); diff --git a/src/network_writev.c b/src/network_writev.c index 713a084..d561d93 100644 --- a/src/network_writev.c +++ b/src/network_writev.c @@ -25,7 +25,7 @@ #endif /* first chunk must be a STRING_CHUNK ! */ -liNetworkStatus network_backend_writev(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max) { +liNetworkStatus li_network_backend_writev(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max) { off_t we_have; ssize_t r; gboolean did_write_something = FALSE; @@ -87,7 +87,7 @@ liNetworkStatus network_backend_writev(liVRequest *vr, int fd, liChunkQueue *cq, res = LI_NETWORK_STATUS_WAIT_FOR_EVENT; goto cleanup; } - chunkqueue_skip(cq, r); + li_chunkqueue_skip(cq, r); *write_max -= r; if (r != we_have) { @@ -111,15 +111,15 @@ cleanup: return res; } -liNetworkStatus network_write_writev(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max) { +liNetworkStatus li_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: - LI_NETWORK_FALLBACK(network_backend_writev, write_max); + LI_NETWORK_FALLBACK(li_network_backend_writev, write_max); break; case FILE_CHUNK: - LI_NETWORK_FALLBACK(network_backend_write, write_max); + LI_NETWORK_FALLBACK(li_network_backend_write, write_max); break; default: return LI_NETWORK_STATUS_FATAL_ERROR; diff --git a/src/options.c b/src/options.c index bceb652..25ad7fa 100644 --- a/src/options.c +++ b/src/options.c @@ -2,7 +2,7 @@ #include /* Extract ovalue from ovalue, ovalue set to none */ -liOptionValue value_extract(liValue *val) { +liOptionValue li_value_extract(liValue *val) { liOptionValue oval = {0}; if (!val) return oval; @@ -35,15 +35,15 @@ liOptionValue value_extract(liValue *val) { return oval; } -gpointer value_extract_ptr(liValue *val) { - liOptionValue oval = value_extract(val); +gpointer li_value_extract_ptr(liValue *val) { + liOptionValue oval = li_value_extract(val); return oval.ptr; } -gint64 value_extract_number(liValue *val) { - liOptionValue oval = value_extract(val); +gint64 li_value_extract_number(liValue *val) { + liOptionValue oval = li_value_extract(val); return oval.number; } -gboolean value_extract_bool(liValue *val) { - liOptionValue oval = value_extract(val); +gboolean li_value_extract_bool(liValue *val) { + liOptionValue oval = li_value_extract(val); return oval.boolean; } diff --git a/src/plugin.c b/src/plugin.c index 942ad76..9196e7f 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -2,7 +2,7 @@ #include static gboolean plugin_load_default_option(liServer *srv, liServerOption *sopt); -static void plugin_free_default_options(liServer *srv, liPlugin *p); +static void li_plugin_free_default_options(liServer *srv, liPlugin *p); static liPlugin* plugin_new(const gchar *name) { liPlugin *p = g_slice_new0(liPlugin); @@ -10,7 +10,7 @@ static liPlugin* plugin_new(const gchar *name) { return p; } -static void plugin_free_options(liServer *srv, liPlugin *p) { +static void li_plugin_free_options(liServer *srv, liPlugin *p) { size_t i; const liPluginOption *po; liServerOption *so; @@ -23,7 +23,7 @@ static void plugin_free_options(liServer *srv, liPlugin *p) { } } -static void plugin_free_actions(liServer *srv, liPlugin *p) { +static void li_plugin_free_actions(liServer *srv, liPlugin *p) { size_t i; const liPluginAction *pa; liServerAction *sa; @@ -36,7 +36,7 @@ static void plugin_free_actions(liServer *srv, liPlugin *p) { } } -static void plugin_free_setups(liServer *srv, liPlugin *p) { +static void li_plugin_free_setups(liServer *srv, liPlugin *p) { size_t i; const liliPluginSetupCB *ps; liServerSetup *ss; @@ -49,7 +49,7 @@ static void plugin_free_setups(liServer *srv, liPlugin *p) { } } -void plugin_free(liServer *srv, liPlugin *p) { +void li_plugin_free(liServer *srv, liPlugin *p) { if (!p) return; if (g_atomic_int_get(&srv->state) == LI_SERVER_RUNNING) { @@ -58,17 +58,17 @@ void plugin_free(liServer *srv, liPlugin *p) { } g_hash_table_remove(srv->plugins, p->name); - plugin_free_default_options(srv, p); - plugin_free_options(srv, p); - plugin_free_actions(srv, p); - plugin_free_setups(srv, p); + li_plugin_free_default_options(srv, p); + li_plugin_free_options(srv, p); + li_plugin_free_actions(srv, p); + li_plugin_free_setups(srv, p); if (p->free) p->free(srv, p); g_slice_free(liPlugin, p); } -void server_plugins_free(liServer *srv) { +void li_server_plugins_free(liServer *srv) { gpointer key, val; GHashTableIter i; @@ -81,9 +81,9 @@ void server_plugins_free(liServer *srv) { while (g_hash_table_iter_next(&i, &key, &val)) { liPlugin *p = (liPlugin*) val; - plugin_free_options(srv, p); - plugin_free_actions(srv, p); - plugin_free_setups(srv, p); + li_plugin_free_options(srv, p); + li_plugin_free_actions(srv, p); + li_plugin_free_setups(srv, p); g_slice_free(liPlugin, p); } @@ -93,7 +93,7 @@ void server_plugins_free(liServer *srv) { g_hash_table_destroy(srv->setups); } -liPlugin *plugin_register(liServer *srv, const gchar *name, liPluginInitCB init) { +liPlugin *li_plugin_register(liServer *srv, const gchar *name, liPluginInitCB init) { liPlugin *p; if (!init) { @@ -129,12 +129,12 @@ liPlugin *plugin_register(liServer *srv, const gchar *name, liPluginInitCB init) po->name, so->p ? so->p->name : "", p->name); - plugin_free(srv, p); + li_plugin_free(srv, p); return NULL; } so = g_slice_new0(liServerOption); so->type = po->type; - so->parse_option = po->parse_option; + so->li_parse_option = po->li_parse_option; so->free_option = po->free_option; so->index = g_hash_table_size(srv->options); so->module_index = i; @@ -156,11 +156,11 @@ liPlugin *plugin_register(liServer *srv, const gchar *name, liPluginInitCB init) pa->name, sa->p ? sa->p->name : "", p->name); - plugin_free(srv, p); + li_plugin_free(srv, p); return NULL; } sa = g_slice_new0(liServerAction); - sa->create_action = pa->create_action; + sa->li_create_action = pa->li_create_action; sa->p = p; g_hash_table_insert(srv->actions, (gchar*) pa->name, sa); } @@ -177,7 +177,7 @@ liPlugin *plugin_register(liServer *srv, const gchar *name, liPluginInitCB init) ps->name, ss->p ? ss->p->name : "", p->name); - plugin_free(srv, p); + li_plugin_free(srv, p); return NULL; } ss = g_slice_new0(liServerSetup); @@ -195,7 +195,7 @@ static liServerOption* find_option(liServer *srv, const char *name) { return (liServerOption*) g_hash_table_lookup(srv->options, name); } -gboolean parse_option(liServer *srv, const char *name, liValue *val, liOptionSet *mark) { +gboolean li_parse_option(liServer *srv, const char *name, liValue *val, liOptionSet *mark) { liServerOption *sopt; if (!srv || !name || !mark) return FALSE; @@ -208,14 +208,14 @@ gboolean parse_option(liServer *srv, const char *name, liValue *val, liOptionSet 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); + li_value_type_string(val->type), li_value_type_string(sopt->type), name); return FALSE; } - if (!sopt->parse_option) { - mark->value = value_extract(val); + if (!sopt->li_parse_option) { + mark->value = li_value_extract(val); } else { - if (!sopt->parse_option(srv, sopt->p, sopt->module_index, val, &mark->value)) { + if (!sopt->li_parse_option(srv, sopt->p, sopt->module_index, val, &mark->value)) { /* errors should be logged by parse function */ return FALSE; } @@ -227,7 +227,7 @@ gboolean parse_option(liServer *srv, const char *name, liValue *val, liOptionSet return TRUE; } -void release_option(liServer *srv, liOptionSet *mark) { /** Does not free the option_set memory */ +void li_release_option(liServer *srv, liOptionSet *mark) { /** Does not free the option_set memory */ liServerOption *sopt; if (!srv || !mark || !mark->sopt) return; sopt = mark->sopt; @@ -246,7 +246,7 @@ void release_option(liServer *srv, liOptionSet *mark) { /** Does not free the op break; case LI_VALUE_LIST: if (mark->value.list) - value_list_free(mark->value.list); + li_value_list_free(mark->value.list); break; case LI_VALUE_HASH: if (mark->value.hash) @@ -254,11 +254,11 @@ void release_option(liServer *srv, liOptionSet *mark) { /** Does not free the op break; case LI_VALUE_ACTION: if (mark->value.action) - action_release(srv, mark->value.action); + li_action_release(srv, mark->value.action); break; case LI_VALUE_CONDITION: if (mark->value.cond) - condition_release(srv, mark->value.cond); + li_condition_release(srv, mark->value.cond); break; } } else { @@ -270,17 +270,17 @@ void release_option(liServer *srv, liOptionSet *mark) { /** Does not free the op } } -liAction* option_action(liServer *srv, const gchar *name, liValue *val) { +liAction* li_option_action(liServer *srv, const gchar *name, liValue *val) { liOptionSet setting; - if (!parse_option(srv, name, val, &setting)) { + if (!li_parse_option(srv, name, val, &setting)) { return NULL; } - return action_new_setting(setting); + return li_action_new_setting(setting); } -liAction* create_action(liServer *srv, const gchar *name, liValue *val) { +liAction* li_create_action(liServer *srv, const gchar *name, liValue *val) { liAction *a; liServerAction *sa; @@ -289,7 +289,7 @@ liAction* create_action(liServer *srv, const gchar *name, liValue *val) { return NULL; } - if (NULL == (a = sa->create_action(srv, sa->p, val))) { + if (NULL == (a = sa->li_create_action(srv, sa->p, val))) { ERROR(srv, "Action '%s' creation failed", name); return NULL; } @@ -297,7 +297,7 @@ liAction* create_action(liServer *srv, const gchar *name, liValue *val) { return a; } -gboolean call_setup(liServer *srv, const char *name, liValue *val) { +gboolean li_call_setup(liServer *srv, const char *name, liValue *val) { liServerSetup *ss; if (NULL == (ss = (liServerSetup*) g_hash_table_lookup(srv->setups, name))) { @@ -313,7 +313,7 @@ gboolean call_setup(liServer *srv, const char *name, liValue *val) { return TRUE; } -void plugins_prepare_callbacks(liServer *srv) { +void li_plugins_prepare_callbacks(liServer *srv) { GHashTableIter iter; liPlugin *p; gpointer v; @@ -322,14 +322,14 @@ void plugins_prepare_callbacks(liServer *srv) { while (g_hash_table_iter_next(&iter, NULL, &v)) { p = (liPlugin*) v; if (p->handle_close) - g_array_append_val(srv->plugins_handle_close, p); + g_array_append_val(srv->li_plugins_handle_close, p); if (p->handle_vrclose) - g_array_append_val(srv->plugins_handle_vrclose, p); + g_array_append_val(srv->li_plugins_handle_vrclose, p); } } -void plugins_handle_close(liConnection *con) { - GArray *a = con->srv->plugins_handle_close; +void li_plugins_handle_close(liConnection *con) { + GArray *a = con->srv->li_plugins_handle_close; guint i, len = a->len; for (i = 0; i < len; i++) { liPlugin *p = g_array_index(a, liPlugin*, i); @@ -337,8 +337,8 @@ void plugins_handle_close(liConnection *con) { } } -void plugins_handle_vrclose(liVRequest *vr) { - GArray *a = vr->wrk->srv->plugins_handle_vrclose; +void li_plugins_handle_vrclose(liVRequest *vr) { + GArray *a = vr->wrk->srv->li_plugins_handle_vrclose; guint i, len = a->len; for (i = 0; i < len; i++) { liPlugin *p = g_array_index(a, liPlugin*, i); @@ -346,7 +346,7 @@ void plugins_handle_vrclose(liVRequest *vr) { } } -gboolean plugin_set_default_option(liServer *srv, const gchar* name, liValue *val) { +gboolean li_plugin_set_default_option(liServer *srv, const gchar* name, liValue *val) { liServerOption *sopt; liOptionSet setting; liOptionValue v; @@ -359,7 +359,7 @@ gboolean plugin_set_default_option(liServer *srv, const gchar* name, liValue *va } /* assign new value */ - if (!parse_option(srv, name, val, &setting)) { + if (!li_parse_option(srv, name, val, &setting)) { return FALSE; } @@ -371,7 +371,7 @@ gboolean plugin_set_default_option(liServer *srv, const gchar* name, liValue *va setting.ndx = sopt->index; setting.value = v; - release_option(srv, &setting); + li_release_option(srv, &setting); return TRUE; } @@ -382,7 +382,7 @@ static gboolean plugin_load_default_option(liServer *srv, liServerOption *sopt) if (!sopt) return FALSE; - if (!sopt->parse_option) { + if (!sopt->li_parse_option) { switch (sopt->type) { case LI_VALUE_NONE: break; @@ -398,7 +398,7 @@ static gboolean plugin_load_default_option(liServer *srv, liServerOption *sopt) oval.ptr = NULL; } } else { - if (!sopt->parse_option(srv, sopt->p, sopt->module_index, NULL, &oval)) { + if (!sopt->li_parse_option(srv, sopt->p, sopt->module_index, NULL, &oval)) { /* errors should be logged by parse function */ return FALSE; } @@ -412,7 +412,7 @@ static gboolean plugin_load_default_option(liServer *srv, liServerOption *sopt) return TRUE; } -static void plugin_free_default_options(liServer *srv, liPlugin *p) { +static void li_plugin_free_default_options(liServer *srv, liPlugin *p) { static const liOptionValue oempty = {0}; GHashTableIter iter; gpointer k, v; @@ -429,7 +429,7 @@ static void plugin_free_default_options(liServer *srv, liPlugin *p) { mark.value = g_array_index(srv->option_def_values, liOptionValue, sopt->index); - release_option(srv, &mark); + li_release_option(srv, &mark); g_array_index(srv->option_def_values, liOptionValue, sopt->index) = oempty; } } diff --git a/src/plugin_core.c b/src/plugin_core.c index 5db31c4..affe092 100644 --- a/src/plugin_core.c +++ b/src/plugin_core.c @@ -18,25 +18,25 @@ static liAction* core_list(liServer *srv, liPlugin* p, liValue *val) { if (val->type == LI_VALUE_ACTION) { a = val->data.val_action.action; - action_acquire(a); + li_action_acquire(a); return a; } if (val->type != LI_VALUE_LIST) { - ERROR(srv, "expected list, got %s", value_type_string(val->type)); + ERROR(srv, "expected list, got %s", li_value_type_string(val->type)); return NULL; } - a = action_new_list(); + a = li_action_new_list(); for (i = 0; i < val->data.list->len; i++) { 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); + ERROR(srv, "expected action at entry %u of list, got %s", i, li_value_type_string(oa->type)); + li_action_release(srv, a); return NULL; } assert(srv == oa->data.val_action.srv); - action_acquire(oa->data.val_action.action); + li_action_acquire(oa->data.val_action.action); g_array_append_val(a->data.list, oa->data.val_action.action); } return a; @@ -52,7 +52,7 @@ static liAction* core_when(liServer *srv, liPlugin* p, liValue *val) { return NULL; } if (val->type != LI_VALUE_LIST) { - ERROR(srv, "expected list, got %s", value_type_string(val->type)); + ERROR(srv, "expected list, got %s", li_value_type_string(val->type)); return NULL; } if (val->data.list->len == 2) { @@ -68,7 +68,7 @@ static liAction* core_when(liServer *srv, liPlugin* p, liValue *val) { val_act = g_array_index(val->data.list, liValue*, 1); if (val_cond->type != LI_VALUE_CONDITION) { - ERROR(srv, "expected condition as first parameter, got %s", value_type_string(val_cond->type)); + ERROR(srv, "expected condition as first parameter, got %s", li_value_type_string(val_cond->type)); return NULL; } if (val_act->type == LI_VALUE_NONE) { @@ -76,7 +76,7 @@ static liAction* core_when(liServer *srv, liPlugin* p, liValue *val) { } 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)); + ERROR(srv, "expected action as second parameter, got %s", li_value_type_string(val_act->type)); return NULL; } if (val_act_else) { @@ -85,14 +85,14 @@ static liAction* core_when(liServer *srv, liPlugin* p, liValue *val) { } 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)); + ERROR(srv, "expected action as third parameter, got %s", li_value_type_string(val_act_else->type)); return NULL; } } - condition_acquire(val_cond->data.val_cond.cond); - if (act) action_acquire(act); - if (act_else) action_acquire(act_else); - a = action_new_condition(val_cond->data.val_cond.cond, act, act_else); + li_condition_acquire(val_cond->data.val_cond.cond); + if (act) li_action_acquire(act); + if (act_else) li_action_acquire(act_else); + a = li_action_new_condition(val_cond->data.val_cond.cond, act, act_else); return a; } @@ -106,7 +106,7 @@ static liAction* core_set(liServer *srv, liPlugin* p, liValue *val) { return NULL; } if (val->type != LI_VALUE_LIST) { - ERROR(srv, "expected list, got %s", value_type_string(val->type)); + ERROR(srv, "expected list, got %s", li_value_type_string(val->type)); return NULL; } if (val->data.list->len != 2) { @@ -116,10 +116,10 @@ static liAction* core_set(liServer *srv, liPlugin* p, liValue *val) { 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)); + ERROR(srv, "expected string as first parameter, got %s", li_value_type_string(val_name->type)); return NULL; } - a = option_action(srv, val_name->data.string->str, val_val); + a = li_option_action(srv, val_name->data.string->str, val_val); return a; } @@ -132,7 +132,7 @@ static gboolean core_setup_set(liServer *srv, liPlugin* p, liValue *val) { return FALSE; } if (val->type != LI_VALUE_LIST) { - ERROR(srv, "expected list, got %s", value_type_string(val->type)); + ERROR(srv, "expected list, got %s", li_value_type_string(val->type)); return FALSE; } if (val->data.list->len != 2) { @@ -142,10 +142,10 @@ static gboolean core_setup_set(liServer *srv, liPlugin* p, liValue *val) { 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)); + ERROR(srv, "expected string as first parameter, got %s", li_value_type_string(val_name->type)); return FALSE; } - return plugin_set_default_option(srv, val_name->data.string->str, val_val); + return li_plugin_set_default_option(srv, val_name->data.string->str, val_val); } static liHandlerResult core_handle_docroot(liVRequest *vr, gpointer param, gpointer *context) { @@ -181,7 +181,7 @@ static liAction* core_docroot(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - return action_new_function(core_handle_docroot, NULL, core_docroot_free, value_extract(val).string); + return li_action_new_function(core_handle_docroot, NULL, core_docroot_free, li_value_extract(val).string); } @@ -201,7 +201,7 @@ static liHandlerResult core_handle_index(liVRequest *vr, gpointer param, gpointe } - res = stat_cache_get(vr, vr->physical.path, &st, &err, NULL); + res = li_stat_cache_get(vr, vr->physical.path, &st, &err, NULL); if (res == LI_HANDLER_WAIT_FOR_EVENT) return LI_HANDLER_WAIT_FOR_EVENT; @@ -227,11 +227,11 @@ static liHandlerResult core_handle_index(liVRequest *vr, gpointer param, gpointe /* entries beginning with a slash shall be looked up directly at the docroot */ g_string_truncate(tmp_docroot, vr->physical.doc_root->len); g_string_append_len(tmp_docroot, GSTR_LEN(file)); - res = stat_cache_get(vr, tmp_docroot, &st, &err, NULL); + res = li_stat_cache_get(vr, tmp_docroot, &st, &err, NULL); } else { g_string_truncate(tmp_path, vr->physical.path->len); g_string_append_len(tmp_path, GSTR_LEN(file)); - res = stat_cache_get(vr, tmp_path, &st, &err, NULL); + res = li_stat_cache_get(vr, tmp_path, &st, &err, NULL); } if (res == LI_HANDLER_WAIT_FOR_EVENT) { @@ -268,7 +268,7 @@ static void core_index_free(liServer *srv, gpointer param) { UNUSED(srv); for (i = 0; i < files->len; i++) - value_free(g_array_index(files, liValue*, i)); + li_value_free(g_array_index(files, liValue*, i)); g_array_free(files, TRUE); } @@ -293,7 +293,7 @@ static liAction* core_index(liServer *srv, liPlugin* p, liValue *val) { } } - return action_new_function(core_handle_index, NULL, core_index_free, value_extract(val).list); + return li_action_new_function(core_handle_index, NULL, core_index_free, li_value_extract(val).list); } @@ -314,11 +314,11 @@ static liHandlerResult core_handle_static(liVRequest *vr, gpointer param, gpoint return LI_HANDLER_GO_ON; } - if (vrequest_is_handled(vr)) return LI_HANDLER_GO_ON; + if (li_vrequest_is_handled(vr)) return LI_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); + res = li_stat_cache_get(vr, vr->physical.path, &st, &err, &fd); if (res == LI_HANDLER_WAIT_FOR_EVENT) return res; @@ -332,7 +332,7 @@ static liHandlerResult core_handle_static(liVRequest *vr, gpointer param, gpoint if (fd != -1) close(fd); - if (!vrequest_handle_direct(vr)) { + if (!li_vrequest_handle_direct(vr)) { return LI_HANDLER_ERROR; } @@ -360,7 +360,7 @@ static liHandlerResult core_handle_static(liVRequest *vr, gpointer param, gpoint if (fd != -1) close(fd); - if (!vrequest_handle_direct(vr)) { + if (!li_vrequest_handle_direct(vr)) { return LI_HANDLER_ERROR; } vr->response.http_status = 403; @@ -371,25 +371,25 @@ static liHandlerResult core_handle_static(liVRequest *vr, gpointer param, gpoint fcntl(fd, F_SETFD, FD_CLOEXEC); #endif - if (!vrequest_handle_direct(vr)) { + if (!li_vrequest_handle_direct(vr)) { close(fd); return LI_HANDLER_ERROR; } - etag_set_header(vr, &st, &cachable); + li_etag_set_header(vr, &st, &cachable); if (cachable) { vr->response.http_status = 304; close(fd); return LI_HANDLER_GO_ON; } - mime_str = mimetype_get(vr, vr->physical.path); + mime_str = li_mimetype_get(vr, vr->physical.path); vr->response.http_status = 200; if (mime_str) - http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), GSTR_LEN(mime_str)); + li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), GSTR_LEN(mime_str)); else - http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("application/octet-stream")); - chunkqueue_append_file_fd(vr->out, NULL, 0, st.st_size, fd); + li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("application/octet-stream")); + li_chunkqueue_append_file_fd(vr->out, NULL, 0, st.st_size, fd); } return LI_HANDLER_GO_ON; @@ -402,7 +402,7 @@ static liAction* core_static(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - return action_new_function(core_handle_static, NULL, NULL, NULL); + return li_action_new_function(core_handle_static, NULL, NULL, NULL); } @@ -425,9 +425,9 @@ static liAction* core_status(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - ptr = GINT_TO_POINTER((gint) value_extract(val).number); + ptr = GINT_TO_POINTER((gint) li_value_extract(val).number); - return action_new_function(core_handle_status, NULL, NULL, ptr); + return li_action_new_function(core_handle_status, NULL, NULL, ptr); } @@ -453,7 +453,7 @@ static liAction* core_log_write(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - return action_new_function(core_handle_log_write, NULL, core_log_write_free, value_extract(val).string); + return li_action_new_function(core_handle_log_write, NULL, core_log_write_free, li_value_extract(val).string); } @@ -461,7 +461,7 @@ static liHandlerResult core_handle_blank(liVRequest *vr, gpointer param, gpointe UNUSED(param); UNUSED(context); - if (!vrequest_handle_direct(vr)) return LI_HANDLER_GO_ON; + if (!li_vrequest_handle_direct(vr)) return LI_HANDLER_GO_ON; vr->response.http_status = 200; @@ -476,7 +476,7 @@ static liAction* core_blank(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - return action_new_function(core_handle_blank, NULL, NULL, NULL); + return li_action_new_function(core_handle_blank, NULL, NULL, NULL); } static liHandlerResult core_handle_profile_mem(liVRequest *vr, gpointer param, gpointer *context) { @@ -498,7 +498,7 @@ static liAction* core_profile_mem(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - return action_new_function(core_handle_profile_mem, NULL, NULL, NULL); + return li_action_new_function(core_handle_profile_mem, NULL, NULL, NULL); } static gboolean core_listen(liServer *srv, liPlugin* p, liValue *val) { @@ -511,7 +511,7 @@ static gboolean core_listen(liServer *srv, liPlugin* p, liValue *val) { } ipstr = val->data.string; - angel_listen(srv, ipstr); + li_angel_listen(srv, ipstr); return TRUE; } @@ -581,49 +581,49 @@ static gboolean core_workers(liServer *srv, liPlugin* p, liValue *val) { } static gboolean core_module_load(liServer *srv, liPlugin* p, liValue *val) { - liValue *mods = value_new_list(); + liValue *mods = li_value_new_list(); UNUSED(p); if (!g_module_supported()) { ERROR(srv, "%s", "module loading not supported on this platform"); - value_free(mods); + li_value_free(mods); return FALSE; } if (val->type == LI_VALUE_STRING) { /* load only one module */ - liValue *name = value_new_string(value_extract(val).string); + liValue *name = li_value_new_string(li_value_extract(val).string); g_array_append_val(mods->data.list, name); } else if (val->type == LI_VALUE_LIST) { /* load a list of modules */ for (guint i = 0; i < val->data.list->len; i++) { 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); + ERROR(srv, "module_load takes either a string or a list of strings as parameter, list with %s entry given", li_value_type_string(v->type)); + li_value_free(mods); return FALSE; } } g_array_free(mods->data.list, TRUE); - mods->data.list = value_extract(val).list; + mods->data.list = li_value_extract(val).list; } else { - ERROR(srv, "module_load takes either a string or a list of strings as parameter, %s given", value_type_string(val->type)); + ERROR(srv, "module_load takes either a string or a list of strings as parameter, %s given", li_value_type_string(val->type)); return FALSE; } /* parameter types ok, load modules */ for (guint i = 0; i < mods->data.list->len; i++) { GString *name = g_array_index(mods->data.list, liValue*, i)->data.string; - if (!module_load(srv->modules, name->str)) { + if (!li_module_load(srv->modules, name->str)) { ERROR(srv, "could not load module '%s': %s", name->str, g_module_error()); - value_free(mods); + li_value_free(mods); return FALSE; } DEBUG(srv, "loaded module '%s'", name->str); } - value_free(mods); + li_value_free(mods); return TRUE; } @@ -636,7 +636,7 @@ static gboolean core_io_timeout(liServer *srv, liPlugin* p, liValue *val) { return FALSE; } - srv->io_timeout = value_extract(val).number; + srv->io_timeout = li_value_extract(val).number; return TRUE; } @@ -649,7 +649,7 @@ static gboolean core_stat_cache_ttl(liServer *srv, liPlugin* p, liValue *val) { return FALSE; } - srv->stat_cache_ttl = (gdouble)value_extract(val).number; + srv->stat_cache_ttl = (gdouble)li_value_extract(val).number; return TRUE; } @@ -687,7 +687,7 @@ static gboolean core_option_log_parse(liServer *srv, liPlugin *p, size_t ndx, li g_hash_table_iter_init(&iter, val->data.hash); while (g_hash_table_iter_next(&iter, &k, &v)) { if (((liValue*)v)->type != LI_VALUE_STRING) { - ERROR(srv, "log expects a hashtable with string values, %s given", value_type_string(((liValue*)v)->type)); + ERROR(srv, "log expects a hashtable with string values, %s given", li_value_type_string(((liValue*)v)->type)); g_array_free(arr, TRUE); return FALSE; } @@ -734,7 +734,7 @@ static gboolean core_option_log_timestamp_parse(liServer *srv, liPlugin *p, size UNUSED(ndx); if (!val) return TRUE; - oval->ptr = log_timestamp_new(srv, value_extract(val).string); + oval->ptr = li_log_timestamp_new(srv, li_value_extract(val).string); return TRUE; } @@ -744,7 +744,7 @@ static void core_option_log_timestamp_free(liServer *srv, liPlugin *p, size_t nd UNUSED(ndx); if (!oval.ptr) return; - log_timestamp_free(srv, oval.ptr); + li_log_timestamp_free(srv, oval.ptr); } static gboolean core_option_mime_types_parse(liServer *srv, liPlugin *p, size_t ndx, liValue *val, liOptionValue *oval) { @@ -766,7 +766,7 @@ static gboolean core_option_mime_types_parse(liServer *srv, liPlugin *p, size_t 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)); + ERROR(srv, "mime_types option expects a list of string tuples, entry #%u is of type %s", i, li_value_type_string(v->type)); return FALSE; } @@ -778,13 +778,13 @@ static gboolean core_option_mime_types_parse(liServer *srv, liPlugin *p, size_t 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)); + ERROR(srv, "mime_types option expects a list of string tuples, entry #%u is a (%s,%s) tuple", i, li_value_type_string(v1->type), li_value_type_string(v2->type)); return FALSE; } } /* everything ok */ - oval->list = value_extract(val).list; + oval->list = li_value_extract(val).list; return TRUE; } @@ -795,7 +795,7 @@ static void core_option_mime_types_free(liServer *srv, liPlugin *p, size_t ndx, UNUSED(ndx); for (guint i = 0; i < oval.list->len; i++) - value_free(g_array_index(oval.list, liValue*, i)); + li_value_free(g_array_index(oval.list, liValue*, i)); g_array_free(oval.list, TRUE); } @@ -813,14 +813,14 @@ static gboolean core_option_etag_use_parse(liServer *srv, liPlugin *p, size_t nd } 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)); + ERROR(srv, "etag.use option expects a list of strings, parameter is of type %s", li_value_type_string(val->type)); } arr = val->data.list; for (guint i = 0; i < arr->len; i++) { 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)); + ERROR(srv, "etag.use option expects a list of strings, entry #%u is of type %s", i, li_value_type_string(v->type)); return FALSE; } @@ -847,14 +847,14 @@ static liHandlerResult core_handle_header_add(liVRequest *vr, gpointer param, gp UNUSED(param); UNUSED(context); - http_header_insert(vr->response.headers, GSTR_LEN(k), GSTR_LEN(v)); + li_http_header_insert(vr->response.headers, GSTR_LEN(k), GSTR_LEN(v)); return LI_HANDLER_GO_ON; } static void core_header_free(liServer *srv, gpointer param) { UNUSED(srv); - value_list_free(param); + li_value_list_free(param); } static liAction* core_header_add(liServer *srv, liPlugin* p, liValue *val) { @@ -862,7 +862,7 @@ static liAction* core_header_add(liServer *srv, liPlugin* p, liValue *val) { UNUSED(p); 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)); + ERROR(srv, "'core_header_add' action expects a string tuple as parameter, %s given", li_value_type_string(val->type)); return NULL; } @@ -878,7 +878,7 @@ static liAction* core_header_add(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - return action_new_function(core_handle_header_add, NULL, core_header_free, value_extract(val).list); + return li_action_new_function(core_handle_header_add, NULL, core_header_free, li_value_extract(val).list); } @@ -889,7 +889,7 @@ static liHandlerResult core_handle_header_append(liVRequest *vr, gpointer param, UNUSED(param); UNUSED(context); - http_header_append(vr->response.headers, GSTR_LEN(k), GSTR_LEN(v)); + li_http_header_append(vr->response.headers, GSTR_LEN(k), GSTR_LEN(v)); return LI_HANDLER_GO_ON; } @@ -899,7 +899,7 @@ static liAction* core_header_append(liServer *srv, liPlugin* p, liValue *val) { UNUSED(p); 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)); + ERROR(srv, "'core_header_append' action expects a string tuple as parameter, %s given", li_value_type_string(val->type)); return NULL; } @@ -915,7 +915,7 @@ static liAction* core_header_append(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - return action_new_function(core_handle_header_append, NULL, core_header_free, value_extract(val).list); + return li_action_new_function(core_handle_header_append, NULL, core_header_free, li_value_extract(val).list); } @@ -926,7 +926,7 @@ static liHandlerResult core_handle_header_overwrite(liVRequest *vr, gpointer par UNUSED(param); UNUSED(context); - http_header_overwrite(vr->response.headers, GSTR_LEN(k), GSTR_LEN(v)); + li_http_header_overwrite(vr->response.headers, GSTR_LEN(k), GSTR_LEN(v)); return LI_HANDLER_GO_ON; } @@ -936,7 +936,7 @@ static liAction* core_header_overwrite(liServer *srv, liPlugin* p, liValue *val) UNUSED(p); 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)); + ERROR(srv, "'core_header_overwrite' action expects a string tuple as parameter, %s given", li_value_type_string(val->type)); return NULL; } @@ -952,7 +952,7 @@ static liAction* core_header_overwrite(liServer *srv, liPlugin* p, liValue *val) return NULL; } - return action_new_function(core_handle_header_overwrite, NULL, core_header_free, value_extract(val).list); + return li_action_new_function(core_handle_header_overwrite, NULL, core_header_free, li_value_extract(val).list); } typedef struct { @@ -968,13 +968,13 @@ static core_conditional* core_conditional_create(liServer *srv, liValue *val, gu 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); + li_action_acquire(act_true); cc->target_true = act_true; return cc; } if (val->type != LI_VALUE_LIST) { - ERROR(srv, "unexpected parameter of type %s, expected list", value_type_string(val->type)); + ERROR(srv, "unexpected parameter of type %s, expected list", li_value_type_string(val->type)); return NULL; } @@ -992,7 +992,7 @@ static core_conditional* core_conditional_create(liServer *srv, liValue *val, gu } 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)); + ERROR(srv, "expected action at entry %u of list, got %s", idx, li_value_type_string(val_true->type)); } if (val_false) { @@ -1001,15 +1001,15 @@ static core_conditional* core_conditional_create(liServer *srv, liValue *val, gu } 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)); + ERROR(srv, "expected action at entry %u of list, got %s", idx+1, li_value_type_string(val_false->type)); } } else { act_false = NULL; } cc = g_slice_new0(core_conditional); - if (act_true) action_acquire(act_true); - if (act_false) action_acquire(act_false); + if (act_true) li_action_acquire(act_true); + if (act_false) li_action_acquire(act_false); cc->target_true = act_true; cc->target_false = act_false; return cc; @@ -1018,15 +1018,15 @@ static core_conditional* core_conditional_create(liServer *srv, liValue *val, gu static void core_conditional_free(liServer *srv, gpointer param) { core_conditional *cc = (core_conditional*) param; if (!cc) return; - action_release(srv, cc->target_true); - action_release(srv, cc->target_false); + li_action_release(srv, cc->target_true); + li_action_release(srv, cc->target_false); g_slice_free(core_conditional, cc); } 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); } + if (way) { if (cc->target_true) li_action_enter(vr, cc->target_true); } + else { if (cc->target_false) li_action_enter(vr, cc->target_false); } return LI_HANDLER_GO_ON; } @@ -1034,7 +1034,7 @@ static liHandlerResult core_handle_physical_exists(liVRequest *vr, gpointer para UNUSED(context); if (0 == vr->physical.path->len) return core_conditional_do(vr, param, FALSE); - vrequest_stat(vr); + li_vrequest_stat(vr); return core_conditional_do(vr, param, vr->physical.have_stat); } static liAction* core_physical_exists(liServer *srv, liPlugin* p, liValue *val) { @@ -1042,14 +1042,14 @@ static liAction* core_physical_exists(liServer *srv, liPlugin* p, liValue *val) UNUSED(p); if (!cc) return NULL; - return action_new_function(core_handle_physical_exists, NULL, core_conditional_free, cc); + return li_action_new_function(core_handle_physical_exists, NULL, core_conditional_free, cc); } 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); + li_vrequest_stat(vr); return core_conditional_do(vr, param, vr->physical.have_stat && S_ISREG(vr->physical.stat.st_mode)); } static liAction* core_physical_is_file(liServer *srv, liPlugin* p, liValue *val) { @@ -1057,14 +1057,14 @@ static liAction* core_physical_is_file(liServer *srv, liPlugin* p, liValue *val) UNUSED(p); if (!cc) return NULL; - return action_new_function(core_handle_physical_is_file, NULL, core_conditional_free, cc); + return li_action_new_function(core_handle_physical_is_file, NULL, core_conditional_free, cc); } 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); + li_vrequest_stat(vr); return core_conditional_do(vr, param, vr->physical.have_stat && S_ISDIR(vr->physical.stat.st_mode)); } static liAction* core_physical_is_dir(liServer *srv, liPlugin* p, liValue *val) { @@ -1072,7 +1072,7 @@ static liAction* core_physical_is_dir(liServer *srv, liPlugin* p, liValue *val) UNUSED(p); if (!cc) return NULL; - return action_new_function(core_handle_physical_is_dir, NULL, core_conditional_free, cc); + return li_action_new_function(core_handle_physical_is_dir, NULL, core_conditional_free, cc); } /* chunkqueue memory limits */ @@ -1080,7 +1080,7 @@ static liHandlerResult core_handle_buffer_out(liVRequest *vr, gpointer param, gp gint limit = GPOINTER_TO_INT(param); UNUSED(context); - cqlimit_set_limit(vr->out->limit, limit); + li_cqlimit_set_limit(vr->out->limit, limit); return LI_HANDLER_GO_ON; } @@ -1090,7 +1090,7 @@ static liAction* core_buffer_out(liServer *srv, liPlugin* p, liValue *val) { UNUSED(p); if (val->type != LI_VALUE_NUMBER) { - ERROR(srv, "'buffer.out' action expects an integer as parameter, %s given", value_type_string(val->type)); + ERROR(srv, "'buffer.out' action expects an integer as parameter, %s given", li_value_type_string(val->type)); return NULL; } @@ -1106,14 +1106,14 @@ static liAction* core_buffer_out(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - return action_new_function(core_handle_buffer_out, NULL, NULL, GINT_TO_POINTER((gint) limit)); + return li_action_new_function(core_handle_buffer_out, NULL, NULL, GINT_TO_POINTER((gint) limit)); } 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); + li_cqlimit_set_limit(vr->out->limit, limit); return LI_HANDLER_GO_ON; } @@ -1123,7 +1123,7 @@ static liAction* core_buffer_in(liServer *srv, liPlugin* p, liValue *val) { UNUSED(p); if (val->type != LI_VALUE_NUMBER) { - ERROR(srv, "'buffer.in' action expects an integer as parameter, %s given", value_type_string(val->type)); + ERROR(srv, "'buffer.in' action expects an integer as parameter, %s given", li_value_type_string(val->type)); return NULL; } @@ -1137,7 +1137,7 @@ static liAction* core_buffer_in(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - return action_new_function(core_handle_buffer_in, NULL, NULL, GINT_TO_POINTER((gint) limit)); + return li_action_new_function(core_handle_buffer_in, NULL, NULL, GINT_TO_POINTER((gint) limit)); } static liHandlerResult core_handle_throttle_pool(liVRequest *vr, gpointer param, gpointer *context) { @@ -1182,7 +1182,7 @@ static liAction* core_throttle_pool(liServer *srv, liPlugin* p, liValue *val) { UNUSED(p); 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)); + ERROR(srv, "'throttle_pool' action expects a string or a string-number tuple as parameter, %s given", li_value_type_string(val->type)); return NULL; } @@ -1233,11 +1233,11 @@ static liAction* core_throttle_pool(liServer *srv, liPlugin* p, liValue *val) { return NULL; } - pool = throttle_pool_new(srv, value_extract(g_array_index(val->data.list, liValue*, 0)).string, (guint)rate); + pool = throttle_pool_new(srv, li_value_extract(g_array_index(val->data.list, liValue*, 0)).string, (guint)rate); g_array_append_val(srv->throttle_pools, pool); } - return action_new_function(core_handle_throttle_pool, NULL, NULL, pool); + return li_action_new_function(core_handle_throttle_pool, NULL, NULL, pool); } @@ -1265,7 +1265,7 @@ static liAction* core_throttle_connection(liServer *srv, liPlugin* p, liValue *v UNUSED(p); if (val->type != LI_VALUE_NUMBER) { - ERROR(srv, "'throttle_connection' action expects a positiv integer as parameter, %s given", value_type_string(val->type)); + ERROR(srv, "'throttle_connection' action expects a positiv integer as parameter, %s given", li_value_type_string(val->type)); return NULL; } @@ -1285,7 +1285,7 @@ static liAction* core_throttle_connection(liServer *srv, liPlugin* p, liValue *v return NULL; } - return action_new_function(core_handle_throttle_connection, NULL, NULL, GUINT_TO_POINTER((guint) rate)); + return li_action_new_function(core_handle_throttle_connection, NULL, NULL, GUINT_TO_POINTER((guint) rate)); } diff --git a/src/radix.c b/src/radix.c index 3235ca9..0ff10e6 100644 --- a/src/radix.c +++ b/src/radix.c @@ -1,7 +1,7 @@ #include -liRadixTree32 *radixtree32_new(guint32 root_width) { +liRadixTree32 *li_radixtree32_new(guint32 root_width) { guint32 i; liRadixTree32 *tree = g_slice_new(liRadixTree32); @@ -21,7 +21,7 @@ liRadixTree32 *radixtree32_new(guint32 root_width) { return tree; } -guint radixtree32_free(liRadixTree32 *tree) { +guint li_radixtree32_free(liRadixTree32 *tree) { guint32 i; liRadixNode32 *node, *parent; guint32 n = 0; @@ -58,7 +58,7 @@ guint radixtree32_free(liRadixTree32 *tree) { return n; } -void radixtree32_insert(liRadixTree32 *tree, guint32 key, guint32 mask, gpointer data) { +void li_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)); @@ -161,7 +161,7 @@ void radixtree32_insert(liRadixTree32 *tree, guint32 key, guint32 mask, gpointer tree->size++; } -gboolean radixtree32_remove(liRadixTree32 *tree, guint32 key, guint32 mask) { +gboolean li_radixtree32_remove(liRadixTree32 *tree, guint32 key, guint32 mask) { liRadixNode32 *node = tree->root[(key & tree->root_mask) >> (32 - tree->root_width)]; while (node) { @@ -224,7 +224,7 @@ gboolean radixtree32_remove(liRadixTree32 *tree, guint32 key, guint32 mask) { return FALSE; } -liRadixNode32 *radixtree32_lookup_node(liRadixTree32 *tree, guint32 key) { +liRadixNode32 *li_radixtree32_lookup_node(liRadixTree32 *tree, guint32 key) { liRadixNode32 *node = tree->root[(key & tree->root_mask) >> (32 - tree->root_width)]; liRadixNode32 *result = NULL; @@ -246,14 +246,14 @@ liRadixNode32 *radixtree32_lookup_node(liRadixTree32 *tree, guint32 key) { return result; } -gpointer radixtree32_lookup(liRadixTree32 *tree, guint32 key) { - liRadixNode32 *node = radixtree32_lookup_node(tree, key); +gpointer li_radixtree32_lookup(liRadixTree32 *tree, guint32 key) { + liRadixNode32 *node = li_radixtree32_lookup_node(tree, key); return node ? node->data : NULL; } -gpointer radixtree32_lookup_exact(liRadixTree32 *tree, guint32 key) { - liRadixNode32 *node = radixtree32_lookup_node(tree, key); +gpointer li_radixtree32_lookup_exact(liRadixTree32 *tree, guint32 key) { + liRadixNode32 *node = li_radixtree32_lookup_node(tree, key); if (!node) return NULL; diff --git a/src/request.c b/src/request.c index 2947722..ab0dda0 100644 --- a/src/request.c +++ b/src/request.c @@ -2,7 +2,7 @@ #include #include -void request_init(liRequest *req) { +void li_request_init(liRequest *req) { req->http_method = LI_HTTP_METHOD_UNSET; req->http_method_str = g_string_sized_new(0); req->http_version = LI_HTTP_VERSION_UNSET; @@ -15,12 +15,12 @@ void request_init(liRequest *req) { req->uri.query = g_string_sized_new(0); req->uri.host = g_string_sized_new(0); - req->headers = http_headers_new(); + req->headers = li_http_headers_new(); req->content_length = -1; } -void request_reset(liRequest *req) { +void li_request_reset(liRequest *req) { req->http_method = LI_HTTP_METHOD_UNSET; g_string_truncate(req->http_method_str, 0); req->http_version = LI_HTTP_VERSION_UNSET; @@ -33,12 +33,12 @@ void request_reset(liRequest *req) { g_string_truncate(req->uri.query, 0); g_string_truncate(req->uri.host, 0); - http_headers_reset(req->headers); + li_http_headers_reset(req->headers); req->content_length = -1; } -void request_clear(liRequest *req) { +void li_request_clear(liRequest *req) { req->http_method = LI_HTTP_METHOD_UNSET; g_string_free(req->http_method_str, TRUE); req->http_version = LI_HTTP_VERSION_UNSET; @@ -51,7 +51,7 @@ void request_clear(liRequest *req) { g_string_free(req->uri.query, TRUE); g_string_free(req->uri.host, TRUE); - http_headers_free(req->headers); + li_http_headers_free(req->headers); req->content_length = -1; } @@ -60,7 +60,7 @@ void request_clear(liRequest *req) { static void bad_request(liConnection *con, int status) { con->keep_alive = FALSE; con->mainvr->response.http_status = status; - vrequest_handle_direct(con->mainvr); + li_vrequest_handle_direct(con->mainvr); } static gboolean request_parse_url(liVRequest *vr) { @@ -69,15 +69,15 @@ static gboolean request_parse_url(liVRequest *vr) { g_string_truncate(req->uri.query, 0); g_string_truncate(req->uri.path, 0); - if (!parse_raw_url(&req->uri)) + if (!li_parse_raw_url(&req->uri)) return FALSE; /* "*" only allowed for method OPTIONS */ if (0 == strcmp(req->uri.path->str, "*") && req->http_method != LI_HTTP_METHOD_OPTIONS) return FALSE; - url_decode(req->uri.path); - path_simplify(req->uri.path); + li_url_decode(req->uri.path); + li_path_simplify(req->uri.path); if (0 == req->uri.orig_path->len) { g_string_append_len(req->uri.orig_path, GSTR_LEN(req->uri.path)); /* save orig path */ @@ -86,18 +86,18 @@ static gboolean request_parse_url(liVRequest *vr) { return TRUE; } -gboolean request_validate_header(liConnection *con) { +gboolean li_request_validate_header(liConnection *con) { liRequest *req = &con->mainvr->request; liHttpHeader *hh; GList *l; switch (req->http_version) { case LI_HTTP_VERSION_1_0: - if (!http_header_is(req->headers, CONST_STR_LEN("connection"), CONST_STR_LEN("keep-alive"))) + if (!li_http_header_is(req->headers, CONST_STR_LEN("connection"), CONST_STR_LEN("keep-alive"))) con->keep_alive = FALSE; break; case LI_HTTP_VERSION_1_1: - if (http_header_is(req->headers, CONST_STR_LEN("connection"), CONST_STR_LEN("close"))) + if (li_http_header_is(req->headers, CONST_STR_LEN("connection"), CONST_STR_LEN("close"))) con->keep_alive = FALSE; break; case LI_HTTP_VERSION_UNSET: @@ -111,9 +111,9 @@ gboolean request_validate_header(liConnection *con) { } /* get hostname */ - l = http_header_find_first(req->headers, CONST_STR_LEN("host")); + l = li_http_header_find_first(req->headers, CONST_STR_LEN("host")); if (NULL != l) { - if (NULL != http_header_find_next(l, CONST_STR_LEN("host"))) { + if (NULL != li_http_header_find_next(l, CONST_STR_LEN("host"))) { /* more than one "host" header */ bad_request(con, 400); /* bad request */ return FALSE; @@ -121,7 +121,7 @@ gboolean request_validate_header(liConnection *con) { hh = (liHttpHeader*) l->data; g_string_append_len(req->uri.authority, HEADER_VALUE_LEN(hh)); - if (!parse_hostname(&req->uri)) { + if (!li_parse_hostname(&req->uri)) { bad_request(con, 400); /* bad request */ return FALSE; } @@ -140,7 +140,7 @@ gboolean request_validate_header(liConnection *con) { } /* content-length */ - hh = http_header_lookup(req->headers, CONST_STR_LEN("content-length")); + hh = li_http_header_lookup(req->headers, CONST_STR_LEN("content-length")); if (hh) { const gchar *val = HEADER_VALUE(hh); gint64 r; @@ -176,11 +176,11 @@ gboolean request_validate_header(liConnection *con) { } /* Expect: 100-continue */ - l = http_header_find_first(req->headers, CONST_STR_LEN("expect")); + l = li_http_header_find_first(req->headers, CONST_STR_LEN("expect")); if (l) { gboolean expect_100_cont = FALSE; - for ( ; l ; l = http_header_find_next(l, CONST_STR_LEN("expect")) ) { + for ( ; l ; l = li_http_header_find_next(l, CONST_STR_LEN("expect")) ) { hh = (liHttpHeader*) l->data; if (0 == g_strcasecmp( HEADER_VALUE(hh), "100-continue" )) { expect_100_cont = TRUE; @@ -235,7 +235,7 @@ gboolean request_validate_header(liConnection *con) { return TRUE; } -void physical_init(liPhysical *phys) { +void li_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(liPhysical *phys) { phys->have_errno = FALSE; } -void physical_reset(liPhysical *phys) { +void li_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(liPhysical *phys) { phys->have_errno = FALSE; } -void physical_clear(liPhysical *phys) { +void li_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 409086c..ef5cef1 100644 --- a/src/response.c +++ b/src/response.c @@ -2,32 +2,32 @@ #include #include -void response_init(liResponse *resp) { - resp->headers = http_headers_new(); +void li_response_init(liResponse *resp) { + resp->headers = li_http_headers_new(); resp->http_status = 0; resp->transfer_encoding = LI_HTTP_TRANSFER_ENCODING_IDENTITY; } -void response_reset(liResponse *resp) { - http_headers_reset(resp->headers); +void li_response_reset(liResponse *resp) { + li_http_headers_reset(resp->headers); resp->http_status = 0; resp->transfer_encoding = LI_HTTP_TRANSFER_ENCODING_IDENTITY; } -void response_clear(liResponse *resp) { - http_headers_free(resp->headers); +void li_response_clear(liResponse *resp) { + li_http_headers_free(resp->headers); resp->http_status = 0; resp->transfer_encoding = LI_HTTP_TRANSFER_ENCODING_IDENTITY; } -void response_send_headers(liConnection *con) { +void li_response_send_headers(liConnection *con) { GString *head; 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); con->response_headers_sent = FALSE; - connection_internal_error(con); + li_connection_internal_error(con); return; } @@ -36,8 +36,8 @@ void response_send_headers(liConnection *con) { if (0 == con->out->length && con->mainvr->handle_response_body == NULL && vr->response.http_status >= 400 && vr->response.http_status < 600) { - /*chunkqueue_append_mem(con->out, CONST_STR_LEN("Custom error\r\n"));*/ - response_send_error_page(con); + /*li_chunkqueue_append_mem(con->out, CONST_STR_LEN("Custom error\r\n"));*/ + li_response_send_error_page(con); } if (con->mainvr->handle_response_body == NULL) { @@ -49,16 +49,16 @@ void response_send_headers(liConnection *con) { vr->response.http_status == 205 || vr->response.http_status == 304) { /* They never have a content-body/length */ - chunkqueue_reset(con->out); + li_chunkqueue_reset(con->out); con->out->is_closed = TRUE; } 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)); + li_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 == LI_HTTP_VERSION_1_1) { /* TODO: maybe someone set a content length header? */ 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")); + li_http_header_append(vr->response.headers, CONST_STR_LEN("Transfer-Encoding"), CONST_STR_LEN("chunked")); } } else { /* Unknown content length, no chunked encoding */ @@ -67,7 +67,7 @@ void response_send_headers(liConnection *con) { if (vr->request.http_method == LI_HTTP_METHOD_HEAD) { /* content-length is set, but no body */ - chunkqueue_reset(con->out); + li_chunkqueue_reset(con->out); con->out->is_closed = TRUE; } @@ -75,18 +75,18 @@ void response_send_headers(liConnection *con) { 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")); + li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Connection"), CONST_STR_LEN("close")); } else { g_string_append_len(head, CONST_STR_LEN("HTTP/1.0 ")); if (con->keep_alive) - http_header_overwrite(vr->response.headers, CONST_STR_LEN("Connection"), CONST_STR_LEN("keep-alive")); + li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Connection"), CONST_STR_LEN("keep-alive")); } { guint len; gchar status_str[4]; - gchar *str = http_status_string(vr->response.http_status, &len); - http_status_to_str(vr->response.http_status, status_str); + gchar *str = li_http_status_string(vr->response.http_status, &len); + li_http_status_to_str(vr->response.http_status, status_str); status_str[3] = ' '; g_string_append_len(head, status_str, 4); g_string_append_len(head, str, len); @@ -108,7 +108,7 @@ void response_send_headers(liConnection *con) { } if (!have_date) { - GString *d = worker_current_timestamp(con->wrk, 0); + GString *d = li_worker_current_timestamp(con->wrk, 0); /* HTTP/1.1 requires a Date: header */ g_string_append_len(head, CONST_STR_LEN("Date: ")); g_string_append_len(head, GSTR_LEN(d)); @@ -127,16 +127,16 @@ void response_send_headers(liConnection *con) { } g_string_append_len(head, CONST_STR_LEN("\r\n")); - chunkqueue_append_string(con->raw_out, head); + li_chunkqueue_append_string(con->raw_out, head); } -void response_send_error_page(liConnection *con) { +void li_response_send_error_page(liConnection *con) { gchar status_str[3]; guint len; gchar *str; - chunkqueue_append_mem(con->out, CONST_STR_LEN( + li_chunkqueue_append_mem(con->out, CONST_STR_LEN( "\n" "\n" @@ -145,25 +145,25 @@ void response_send_error_page(liConnection *con) { " " )); - http_status_to_str(con->mainvr->response.http_status, status_str); + li_http_status_to_str(con->mainvr->response.http_status, status_str); - chunkqueue_append_mem(con->out, status_str, 3); - chunkqueue_append_mem(con->out, CONST_STR_LEN(" - ")); - str = http_status_string(con->mainvr->response.http_status, &len); - chunkqueue_append_mem(con->out, str, len); + li_chunkqueue_append_mem(con->out, status_str, 3); + li_chunkqueue_append_mem(con->out, CONST_STR_LEN(" - ")); + str = li_http_status_string(con->mainvr->response.http_status, &len); + li_chunkqueue_append_mem(con->out, str, len); - chunkqueue_append_mem(con->out, CONST_STR_LEN( + li_chunkqueue_append_mem(con->out, CONST_STR_LEN( "\n" " \n" " \n" "

" )); - chunkqueue_append_mem(con->out, status_str, 3); - chunkqueue_append_mem(con->out, CONST_STR_LEN(" - ")); - chunkqueue_append_mem(con->out, str, len); + li_chunkqueue_append_mem(con->out, status_str, 3); + li_chunkqueue_append_mem(con->out, CONST_STR_LEN(" - ")); + li_chunkqueue_append_mem(con->out, str, len); - chunkqueue_append_mem(con->out, CONST_STR_LEN( + li_chunkqueue_append_mem(con->out, CONST_STR_LEN( "

\n" " \n" "\n" diff --git a/src/server.c b/src/server.c index 09e1da5..e150554 100644 --- a/src/server.c +++ b/src/server.c @@ -2,33 +2,33 @@ #include #include -static void server_listen_cb(struct ev_loop *loop, ev_io *w, int revents); +static void li_server_listen_cb(struct ev_loop *loop, ev_io *w, int revents); static liServerSocket* server_socket_new(int fd) { liServerSocket *sock = g_slice_new0(liServerSocket); sock->refcount = 1; sock->watcher.data = sock; - sock->local_addr = sockaddr_local_from_socket(fd); + sock->local_addr = li_sockaddr_local_from_socket(fd); sock->local_addr_str = g_string_sized_new(0); - sockaddr_to_string(sock->local_addr, sock->local_addr_str, FALSE); - fd_init(fd); - ev_init(&sock->watcher, server_listen_cb); + li_sockaddr_to_string(sock->local_addr, sock->local_addr_str, FALSE); + li_fd_init(fd); + ev_init(&sock->watcher, li_server_listen_cb); ev_io_set(&sock->watcher, fd, EV_READ); return sock; } -void server_socket_release(liServerSocket* sock) { +void li_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); + li_sockaddr_clear(&sock->local_addr); g_string_free(sock->local_addr_str, TRUE); g_slice_free(liServerSocket, sock); } } -void server_socket_acquire(liServerSocket* sock) { +void li_server_socket_acquire(liServerSocket* sock) { assert(g_atomic_int_get(&sock->refcount) > 0); g_atomic_int_inc(&sock->refcount); } @@ -64,7 +64,7 @@ static void sigint_cb(struct ev_loop *loop, struct ev_signal *w, int revents) { if (g_atomic_int_get(&srv->state) != LI_SERVER_STOPPING) { INFO(srv, "%s", "Got signal, shutdown"); - server_stop(srv); + li_server_stop(srv); } else { INFO(srv, "%s", "Got second signal, force shutdown"); @@ -80,7 +80,7 @@ static void sigpipe_cb(struct ev_loop *loop, struct ev_signal *w, int revents) { UNUSED(loop); UNUSED(w); UNUSED(revents); } -liServer* server_new(const gchar *module_dir) { +liServer* li_server_new(const gchar *module_dir) { liServer* srv = g_slice_new0(liServer); srv->magic = LIGHTTPD_SERVER_MAGIC; @@ -91,15 +91,15 @@ liServer* server_new(const gchar *module_dir) { srv->sockets = g_ptr_array_new(); - srv->modules = modules_new(srv, module_dir); + srv->modules = li_modules_new(srv, module_dir); srv->plugins = g_hash_table_new(g_str_hash, g_str_equal); srv->options = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, server_value_free); 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(liPlugin*)); - srv->plugins_handle_vrclose = g_array_new(FALSE, TRUE, sizeof(liPlugin*)); + srv->li_plugins_handle_close = g_array_new(FALSE, TRUE, sizeof(liPlugin*)); + srv->li_plugins_handle_vrclose = g_array_new(FALSE, TRUE, sizeof(liPlugin*)); srv->option_def_values = g_array_new(FALSE, TRUE, sizeof(liOptionValue)); srv->mainaction = NULL; @@ -108,7 +108,7 @@ liServer* server_new(const gchar *module_dir) { srv->ts_formats = g_array_new(FALSE, TRUE, sizeof(GString*)); /* error log ts format */ - server_ts_format_add(srv, g_string_new("%a, %d %b %Y %H:%M:%S GMT")); + li_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(liThrottlePool*)); @@ -119,10 +119,10 @@ liServer* server_new(const gchar *module_dir) { return srv; } -void server_free(liServer* srv) { +void li_server_free(liServer* srv) { if (!srv) return; - server_stop(srv); + li_server_stop(srv); g_atomic_int_set(&srv->exiting, TRUE); /* join all workers */ @@ -131,12 +131,12 @@ void server_free(liServer* srv) { for (i = 1; i < srv->workers->len; i++) { liWorker *wrk; wrk = g_array_index(srv->workers, liWorker*, i); - worker_exit(srv->main_worker, wrk); + li_worker_exit(srv->main_worker, wrk); g_thread_join(wrk->thread); } } - action_release(srv, srv->mainaction); + li_action_release(srv, srv->mainaction); /* free throttle pools */ { @@ -155,7 +155,7 @@ void server_free(liServer* srv) { struct ev_loop *loop; wrk = g_array_index(srv->workers, liWorker*, i); loop = wrk->loop; - worker_free(wrk); + li_worker_free(wrk); if (i == 0) { ev_default_destroy(); } else { @@ -166,9 +166,9 @@ void server_free(liServer* srv) { } /* release modules */ - modules_free(srv->modules); + li_modules_free(srv->modules); - plugin_free(srv, srv->core_plugin); + li_plugin_free(srv, srv->core_plugin); log_cleanup(srv); @@ -176,7 +176,7 @@ void server_free(liServer* srv) { guint i; for (i = 0; i < srv->sockets->len; i++) { liServerSocket *sock = g_ptr_array_index(srv->sockets, i); close(sock->watcher.fd); - server_socket_release(sock); + li_server_socket_release(sock); } g_ptr_array_free(srv->sockets, TRUE); } @@ -189,9 +189,9 @@ void server_free(liServer* srv) { } g_array_free(srv->option_def_values, TRUE); - server_plugins_free(srv); - g_array_free(srv->plugins_handle_close, TRUE); - g_array_free(srv->plugins_handle_vrclose, TRUE); + li_server_plugins_free(srv); + g_array_free(srv->li_plugins_handle_close, TRUE); + g_array_free(srv->li_plugins_handle_vrclose, TRUE); if (srv->started_str) g_string_free(srv->started_str, TRUE); @@ -201,22 +201,22 @@ void server_free(liServer* srv) { static gpointer server_worker_cb(gpointer data) { liWorker *wrk = (liWorker*) data; - worker_run(wrk); + li_worker_run(wrk); return NULL; } -gboolean server_loop_init(liServer *srv) { +gboolean li_server_loop_init(liServer *srv) { srv->loop = ev_default_loop(srv->loop_flags); if (!srv->loop) { - fatal ("could not initialise libev, bad $LIBEV_FLAGS in environment?"); + li_fatal ("could not initialise libev, bad $LIBEV_FLAGS in environment?"); return FALSE; } return TRUE; } -gboolean server_worker_init(liServer *srv) { +gboolean li_server_worker_init(liServer *srv) { struct ev_loop *loop = srv->loop; guint i; @@ -226,16 +226,16 @@ gboolean server_worker_init(liServer *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, liWorker*, 0) = worker_new(srv, loop); + srv->main_worker = g_array_index(srv->workers, liWorker*, 0) = li_worker_new(srv, loop); srv->main_worker->ndx = 0; for (i = 1; i < srv->worker_count; i++) { GError *error = NULL; liWorker *wrk; if (NULL == (loop = ev_loop_new(srv->loop_flags))) { - fatal ("could not create extra libev loops"); + li_fatal ("could not create extra libev loops"); return FALSE; } - wrk = g_array_index(srv->workers, liWorker*, i) = worker_new(srv, loop); + wrk = g_array_index(srv->workers, liWorker*, i) = li_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 ); @@ -246,7 +246,7 @@ gboolean server_worker_init(liServer *srv) { return TRUE; } -static void server_listen_cb(struct ev_loop *loop, ev_io *w, int revents) { +static void li_server_listen_cb(struct ev_loop *loop, ev_io *w, int revents) { liServerSocket *sock = (liServerSocket*) w->data; liServer *srv = sock->srv; int s; @@ -265,11 +265,11 @@ static void server_listen_cb(struct ev_loop *loop, ev_io *w, int revents) { remote_addr.len = l; memcpy(remote_addr.addr, &sa, l); } else { - remote_addr = sockaddr_remote_from_socket(s); + remote_addr = li_sockaddr_remote_from_socket(s); } l = sizeof(sa); /* reset l */ - fd_init(s); + li_fd_init(s); for (i = 1; i < srv->worker_count; i++) { liWorker *wt = g_array_index(srv->workers, liWorker*, i); @@ -283,8 +283,8 @@ static void server_listen_cb(struct ev_loop *loop, ev_io *w, int revents) { g_atomic_int_inc((gint*) &wrk->connection_load); /* TRACE(srv, "selected worker %u with load %u", sel, min_load); */ - server_socket_acquire(sock); - worker_new_con(srv->main_worker, wrk, remote_addr, s, sock); + li_server_socket_acquire(sock); + li_worker_new_con(srv->main_worker, wrk, remote_addr, s, sock); } #ifdef _WIN32 @@ -303,7 +303,7 @@ static void server_listen_cb(struct ev_loop *loop, ev_io *w, int revents) { break; case EMFILE: /* we are out of FDs */ - server_out_of_fds(srv); + li_server_out_of_fds(srv); /* TODO: disable accept callbacks? */ break; default: @@ -312,7 +312,7 @@ static void server_listen_cb(struct ev_loop *loop, ev_io *w, int revents) { } } -void server_listen(liServer *srv, int fd) { +void li_server_listen(liServer *srv, int fd) { liServerSocket *sock = server_socket_new(fd); sock->srv = srv; @@ -321,7 +321,7 @@ void server_listen(liServer *srv, int fd) { if (g_atomic_int_get(&srv->state) == LI_SERVER_RUNNING) ev_io_start(srv->main_worker->loop, &sock->watcher); } -void server_start(liServer *srv) { +void li_server_start(liServer *srv) { guint i; liServerState srvstate = g_atomic_int_get(&srv->state); if (srvstate == LI_SERVER_STOPPING || srvstate == LI_SERVER_RUNNING) return; /* no restart after stop */ @@ -329,13 +329,13 @@ void server_start(liServer *srv) { if (!srv->mainaction) { ERROR(srv, "%s", "No action handlers defined"); - server_stop(srv); + li_server_stop(srv); return; } srv->keep_alive_queue_timeout = 5; - plugins_prepare_callbacks(srv); + li_plugins_prepare_callbacks(srv); for (i = 0; i < srv->sockets->len; i++) { liServerSocket *sock = g_ptr_array_index(srv->sockets, i); @@ -344,17 +344,17 @@ void server_start(liServer *srv) { srv->started = ev_now(srv->main_worker->loop); { - GString *str = worker_current_timestamp(srv->main_worker, 0); + GString *str = li_worker_current_timestamp(srv->main_worker, 0); srv->started = ev_now(srv->main_worker->loop); srv->started_str = g_string_new_len(GSTR_LEN(str)); } log_thread_start(srv); - worker_run(srv->main_worker); + li_worker_run(srv->main_worker); } -void server_stop(liServer *srv) { +void li_server_stop(liServer *srv) { guint i; if (g_atomic_int_get(&srv->state) == LI_SERVER_STOPPING) return; @@ -370,15 +370,15 @@ void server_stop(liServer *srv) { for (i = 0; i < srv->worker_count; i++) { liWorker *wrk; wrk = g_array_index(srv->workers, liWorker*, i); - worker_stop(srv->main_worker, wrk); + li_worker_stop(srv->main_worker, wrk); } } log_thread_wakeup(srv); } -void server_exit(liServer *srv) { - server_stop(srv); +void li_server_exit(liServer *srv) { + li_server_stop(srv); g_atomic_int_set(&srv->exiting, TRUE); @@ -388,13 +388,13 @@ void server_exit(liServer *srv) { for (i = 0; i < srv->worker_count; i++) { liWorker *wrk; wrk = g_array_index(srv->workers, liWorker*, i); - worker_exit(srv->main_worker, wrk); + li_worker_exit(srv->main_worker, wrk); } } } /* cache timestamp */ -GString *server_current_timestamp() { +GString *li_server_current_timestamp() { static GStaticPrivate last_ts_key = G_STATIC_PRIVATE_INIT; static GStaticPrivate ts_str_key = G_STATIC_PRIVATE_INIT; @@ -409,7 +409,7 @@ GString *server_current_timestamp() { } if (ts_str == NULL) { ts_str = g_string_sized_new(255); - g_static_private_set(&ts_str_key, ts_str, (GDestroyNotify)string_destroy_notify); + g_static_private_set(&ts_str_key, ts_str, (GDestroyNotify)li_string_destroy_notify); } if (cur_ts != *last_ts) { @@ -425,11 +425,11 @@ GString *server_current_timestamp() { return ts_str; } -void server_out_of_fds(liServer *srv) { +void li_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(liServer *srv, GString* format) { +guint li_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 5813161..1e4014d 100644 --- a/src/stat_cache.c +++ b/src/stat_cache.c @@ -23,7 +23,7 @@ void stat_cache_new(liWorker *wrk, gdouble ttl) { sc->job_queue_in = g_async_queue_new(); sc->job_queue_out = g_async_queue_new(); - waitqueue_init(&sc->delete_queue, wrk->loop, stat_cache_delete_cb, ttl, sc); + li_waitqueue_init(&sc->delete_queue, wrk->loop, stat_cache_delete_cb, ttl, sc); ev_init(&sc->job_watcher, stat_cache_job_cb); sc->job_watcher.data = wrk; @@ -58,7 +58,7 @@ void stat_cache_free(liStatCache *sc) { stat_cache_entry_free(v); } - waitqueue_stop(&sc->delete_queue); + li_waitqueue_stop(&sc->delete_queue); g_async_queue_unref(sc->job_queue_in); g_async_queue_unref(sc->job_queue_out); g_hash_table_destroy(sc->entries); @@ -74,7 +74,7 @@ static void stat_cache_delete_cb(struct ev_loop *loop, ev_timer *w, int revents) UNUSED(loop); UNUSED(revents); - while ((wqe = waitqueue_pop(&sc->delete_queue)) != NULL) { + while ((wqe = li_waitqueue_pop(&sc->delete_queue)) != NULL) { /* stat cache entry TTL over */ sce = wqe->data; @@ -89,14 +89,14 @@ static void stat_cache_delete_cb(struct ev_loop *loop, ev_timer *w, int revents) if (sce->refcount) { /* if there are still vrequests using this entry just requeue it */ - waitqueue_push(&sc->delete_queue, wqe); + li_waitqueue_push(&sc->delete_queue, wqe); } else { /* no more vrequests using this entry, finally free it */ stat_cache_entry_free(sce); } } - waitqueue_update(&sc->delete_queue); + li_waitqueue_update(&sc->delete_queue); } /* called whenever an async stat job has finished */ @@ -116,7 +116,7 @@ static void stat_cache_job_cb(struct ev_loop *loop, ev_async *w, int revents) { /* queue pending vrequests */ for (i = 0; i < sce->vrequests->len; i++) { vr = g_ptr_array_index(sce->vrequests, i); - vrequest_joblist_append(vr); + li_vrequest_joblist_append(vr); if (sce->type == STAT_CACHE_ENTRY_SINGLE) { sce->refcount--; g_ptr_array_remove_fast(vr->stat_cache_entries, sce); @@ -181,7 +181,7 @@ static gpointer stat_cache_thread(gpointer data) { sce->data.failed = TRUE; sce->data.err = errno; } else { - size = dirent_buf_size(dirp); + size = li_dirent_buf_size(dirp); assert(size != (gsize)-1); entry = g_slice_alloc(size); @@ -247,7 +247,7 @@ static liStatCacheEntry *stat_cache_entry_new(GString *path) { return sce; } -liHandlerResult stat_cache_get_dirlist(liVRequest *vr, GString *path, liStatCacheEntry **result) { +liHandlerResult li_stat_cache_get_dirlist(liVRequest *vr, GString *path, liStatCacheEntry **result) { liStatCache *sc; liStatCacheEntry *sce; guint i; @@ -263,7 +263,7 @@ liHandlerResult stat_cache_get_dirlist(liVRequest *vr, GString *path, liStatCach if (g_ptr_array_index(vr->stat_cache_entries, i) == sce) return LI_HANDLER_WAIT_FOR_EVENT; } - stat_cache_entry_acquire(vr, sce); + li_stat_cache_entry_acquire(vr, sce); return LI_HANDLER_WAIT_FOR_EVENT; } @@ -277,8 +277,8 @@ liHandlerResult stat_cache_get_dirlist(liVRequest *vr, GString *path, liStatCach sce = stat_cache_entry_new(path); sce->type = STAT_CACHE_ENTRY_DIR; 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); + li_stat_cache_entry_acquire(vr, sce); + li_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++; @@ -286,7 +286,7 @@ liHandlerResult stat_cache_get_dirlist(liVRequest *vr, GString *path, liStatCach } } -liHandlerResult stat_cache_get(liVRequest *vr, GString *path, struct stat *st, int *err, int *fd) { +liHandlerResult li_stat_cache_get(liVRequest *vr, GString *path, struct stat *st, int *err, int *fd) { liStatCache *sc; liStatCacheEntry *sce; guint i; @@ -302,7 +302,7 @@ liHandlerResult stat_cache_get(liVRequest *vr, GString *path, struct stat *st, i if (g_ptr_array_index(vr->stat_cache_entries, i) == sce) return LI_HANDLER_WAIT_FOR_EVENT; } - stat_cache_entry_acquire(vr, sce); + li_stat_cache_entry_acquire(vr, sce); return LI_HANDLER_WAIT_FOR_EVENT; } @@ -311,8 +311,8 @@ liHandlerResult stat_cache_get(liVRequest *vr, GString *path, struct stat *st, i /* cache miss, allocate new entry */ sce = stat_cache_entry_new(path); sce->type = STAT_CACHE_ENTRY_SINGLE; - stat_cache_entry_acquire(vr, sce); - waitqueue_push(&sc->delete_queue, &sce->queue_elem); + li_stat_cache_entry_acquire(vr, sce); + li_waitqueue_push(&sc->delete_queue, &sce->queue_elem); g_hash_table_insert(sc->entries, sce->data.path, sce); g_async_queue_push(sc->job_queue_out, sce); sc->misses++; @@ -340,13 +340,13 @@ liHandlerResult stat_cache_get(liVRequest *vr, GString *path, struct stat *st, i return LI_HANDLER_GO_ON; } -void stat_cache_entry_acquire(liVRequest *vr, liStatCacheEntry *sce) { +void li_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(liVRequest *vr, liStatCacheEntry *sce) { +void li_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 15e51c1..921f197 100644 --- a/src/tests.c +++ b/src/tests.c @@ -10,17 +10,17 @@ int request_test() { liRequest req; liHandlerResult res; - cq = chunkqueue_new(); - request_init(&req, cq); + cq = li_chunkqueue_new(); + li_request_init(&req, cq); - chunkqueue_append_mem(cq, CONST_STR_LEN( + li_chunkqueue_append_mem(cq, CONST_STR_LEN( "GET / HTTP/1.1\r\n" "Host: www.example.com\r\n" "\r\n" "abc" )); - res = http_request_parse(NULL, NULL, &req.parser_ctx); + res = li_http_request_parse(NULL, NULL, &req.parser_ctx); if (res != LI_HANDLER_GO_ON) { fprintf(stderr, "Parser return %i", res); } @@ -28,8 +28,8 @@ int request_test() { assert(req.http_method == LI_HTTP_METHOD_GET); assert(cq->length == 3); - request_clear(&req); - chunkqueue_free(cq); + li_request_clear(&req); + li_chunkqueue_free(cq); return res == LI_HANDLER_GO_ON ? 0 : 1; } @@ -38,21 +38,21 @@ int main() { liServer *srv; guint32 ip, netmask; - assert(parse_ipv4("10.0.3.8/24", &ip, &netmask, NULL)); + assert(li_parse_ipv4("10.0.3.8/24", &ip, &netmask, NULL)); printf("parsed ip: %s\n", inet_ntoa(*(struct in_addr*) &ip)); printf("parsed netmask: %s\n", inet_ntoa(*(struct in_addr*) &netmask)); guint8 ipv6[16]; guint network; GString *s; - assert(parse_ipv6("::ffff:192.168.0.1/80", ipv6, &network, NULL)); - s = ipv6_tostring(ipv6); + assert(li_parse_ipv6("::ffff:192.168.0.1/80", ipv6, &network, NULL)); + s = li_ipv6_tostring(ipv6); printf("parsed ipv6: %s/%u\n", s->str, network); request_test(); return 0; - srv = server_new(); + srv = li_server_new(); return 0; } diff --git a/src/throttle.c b/src/throttle.c index 255a9d2..0273648 100644 --- a/src/throttle.c +++ b/src/throttle.c @@ -72,7 +72,7 @@ void throttle_cb(struct ev_loop *loop, ev_timer *w, int revents) { wrk = w->data; now = ev_now(loop); - while (NULL != (wqe = waitqueue_pop(&wrk->throttle_queue))) { + while (NULL != (wqe = li_waitqueue_pop(&wrk->throttle_queue))) { con = wqe->data; if (con->throttle.pool.ptr) { @@ -138,8 +138,8 @@ void throttle_cb(struct ev_loop *loop, ev_timer *w, int revents) { con->throttle.con.magazine += con->throttle.con.rate * THROTTLE_GRANULARITY; } - ev_io_add_events(loop, &con->sock_watcher, EV_WRITE); + li_ev_io_add_events(loop, &con->sock_watcher, EV_WRITE); } - waitqueue_update(&wrk->throttle_queue); + li_waitqueue_update(&wrk->throttle_queue); } \ No newline at end of file diff --git a/src/url_parser.rl b/src/url_parser.rl index 455a8d7..476e8e5 100644 --- a/src/url_parser.rl +++ b/src/url_parser.rl @@ -77,7 +77,7 @@ write data; }%% -gboolean parse_raw_url(liRequestUri *uri) { +gboolean li_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(liRequestUri *uri) { return (cs >= url_parser_first_final); } -gboolean parse_hostname(liRequestUri *uri) { +gboolean li_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 ad32a4a..7578862 100644 --- a/src/utils.c +++ b/src/utils.c @@ -20,19 +20,19 @@ #include #endif -/* for send/receive_fd */ +/* for send/li_receive_fd */ union fdmsg { struct cmsghdr h; gchar buf[1000]; }; -void fatal(const gchar* msg) { +void li_fatal(const gchar* msg) { fprintf(stderr, "%s\n", msg); abort(); } -void fd_no_block(int fd) { +void li_fd_no_block(int fd) { #ifdef O_NONBLOCK fcntl(fd, F_SETFL, O_NONBLOCK | O_RDWR); #elif defined _WIN32 @@ -43,7 +43,7 @@ void fd_no_block(int fd) { #endif } -void fd_block(int fd) { +void li_fd_block(int fd) { #ifdef O_NONBLOCK fcntl(fd, F_SETFL, O_RDWR); #elif defined _WIN32 @@ -54,17 +54,17 @@ void fd_block(int fd) { #endif } -void fd_init(int fd) { +void li_fd_init(int fd) { #ifdef FD_CLOEXEC /* close fd on exec (cgi) */ fcntl(fd, F_SETFD, FD_CLOEXEC); #endif - fd_no_block(fd); + li_fd_no_block(fd); } #if 0 #ifndef _WIN32 -int send_fd(int s, int fd) { /* write fd to unix socket s */ +int li_send_fd(int s, int fd) { /* write fd to unix socket s */ for ( ;; ) { if (-1 == ioctl(s, I_SENDFD, fd)) { switch (errno) { @@ -78,7 +78,7 @@ int send_fd(int s, int fd) { /* write fd to unix socket s */ } } -int receive_fd(int s, int *fd) { /* read fd from unix socket s */ +int li_receive_fd(int s, int *fd) { /* read fd from unix socket s */ struct strrecvfd res; memset(&res, 0, sizeof(res)); for ( ;; ) { @@ -96,7 +96,7 @@ int receive_fd(int s, int *fd) { /* read fd from unix socket s */ #endif #endif -gint send_fd(gint s, gint fd) { /* write fd to unix socket s */ +gint li_send_fd(gint s, gint fd) { /* write fd to unix socket s */ struct msghdr msg; struct iovec iov; #ifdef CMSG_FIRSTHDR @@ -149,7 +149,7 @@ gint send_fd(gint s, gint fd) { /* write fd to unix socket s */ } -gint receive_fd(gint s, gint *fd) { /* read fd from unix socket s */ +gint li_receive_fd(gint s, gint *fd) { /* read fd from unix socket s */ struct iovec iov; struct msghdr msg; #ifdef CMSG_FIRSTHDR @@ -228,21 +228,21 @@ gint receive_fd(gint s, gint *fd) { /* read fd from unix socket s */ -void ev_io_add_events(struct ev_loop *loop, ev_io *watcher, int events) { +void li_ev_io_add_events(struct ev_loop *loop, ev_io *watcher, int events) { if ((watcher->events & events) == events) return; ev_io_stop(loop, watcher); ev_io_set(watcher, watcher->fd, watcher->events | events); ev_io_start(loop, watcher); } -void ev_io_rem_events(struct ev_loop *loop, ev_io *watcher, int events) { +void li_ev_io_rem_events(struct ev_loop *loop, ev_io *watcher, int events) { if (0 == (watcher->events & events)) return; ev_io_stop(loop, watcher); ev_io_set(watcher, watcher->fd, watcher->events & ~events); ev_io_start(loop, watcher); } -void ev_io_set_events(struct ev_loop *loop, ev_io *watcher, int events) { +void li_ev_io_set_events(struct ev_loop *loop, ev_io *watcher, int events) { if (events == (watcher->events & (EV_READ | EV_WRITE))) return; ev_io_stop(loop, watcher); ev_io_set(watcher, watcher->fd, (watcher->events & ~(EV_READ | EV_WRITE)) | events); @@ -270,7 +270,7 @@ static int hex2int(unsigned char hex) { return res; } -void url_decode(GString *path) { +void li_url_decode(GString *path) { char *src, *dst, c; src = dst = path->str; for ( ; *src; src++) { @@ -307,7 +307,7 @@ void url_decode(GString *path) { * the operation is performed in-place. */ -void path_simplify(GString *path) { +void li_path_simplify(GString *path) { int toklen; char c, pre1; char *start, *slash, *walk, *out; @@ -374,7 +374,7 @@ void path_simplify(GString *path) { } -GString *counter_format(guint64 count, liCounterType t, GString *dest) { +GString *li_counter_format(guint64 count, liCounterType t, GString *dest) { guint64 rest; if (!dest) @@ -444,7 +444,7 @@ GString *counter_format(guint64 count, liCounterType t, GString *dest) { } -gchar *ev_backend_string(guint backend) { +gchar *li_ev_backend_string(guint backend) { switch (backend) { case EVBACKEND_SELECT: return "select"; case EVBACKEND_POLL: return "poll"; @@ -457,22 +457,22 @@ gchar *ev_backend_string(guint backend) { } -void string_destroy_notify(gpointer str) { +void li_string_destroy_notify(gpointer str) { g_string_free((GString*)str, TRUE); } -guint hash_ipv4(gconstpointer key) { +guint li_hash_ipv4(gconstpointer key) { return *((guint*)key) * 2654435761; } -guint hash_ipv6(gconstpointer key) { +guint li_hash_ipv6(gconstpointer key) { guint *i = ((guint*)key); return (i[0] ^ i[1] ^ i[2] ^ i[3]) * 2654435761; } -GString *sockaddr_to_string(liSocketAddress addr, GString *dest, gboolean showport) { +GString *li_sockaddr_to_string(liSocketAddress addr, GString *dest, gboolean showport) { gchar *p; guint8 len = 0; guint8 tmp; @@ -519,7 +519,7 @@ GString *sockaddr_to_string(liSocketAddress addr, GString *dest, gboolean showpo if (!dest) dest = g_string_sized_new(INET6_ADDRSTRLEN+6); - ipv6_tostring(dest, saddr->ipv6.sin6_addr.s6_addr); + li_ipv6_tostring(dest, saddr->ipv6.sin6_addr.s6_addr); if (showport) g_string_append_printf(dest, ":%u", (unsigned int) ntohs(saddr->ipv6.sin6_port)); break; #endif @@ -537,13 +537,13 @@ GString *sockaddr_to_string(liSocketAddress addr, GString *dest, gboolean showpo if (!dest) dest = g_string_new_len(CONST_STR_LEN("unknown sockaddr family")); else - l_g_string_assign_len(dest, CONST_STR_LEN("unknown sockaddr family")); + li_string_assign_len(dest, CONST_STR_LEN("unknown sockaddr family")); } return dest; } -liSocketAddress sockaddr_from_string(GString *str, guint tcp_default_port) { +liSocketAddress li_sockaddr_from_string(GString *str, guint tcp_default_port) { guint32 ipv4; #ifdef HAVE_IPV6 guint8 ipv6[16]; @@ -559,7 +559,7 @@ liSocketAddress sockaddr_from_string(GString *str, guint tcp_default_port) { strcpy(saddr.addr->un.sun_path, str->str + 5); } else #endif - if (parse_ipv4(str->str, &ipv4, NULL, &port)) { + if (li_parse_ipv4(str->str, &ipv4, NULL, &port)) { if (!port) return saddr; saddr.len = sizeof(struct sockaddr_in); saddr.addr = (liSockAddr*) g_slice_alloc0(saddr.len); @@ -568,7 +568,7 @@ liSocketAddress sockaddr_from_string(GString *str, guint tcp_default_port) { saddr.addr->ipv4.sin_port = htons(port); #ifdef HAVE_IPV6 } else - if (parse_ipv6(str->str, ipv6, NULL, &port)) { + if (li_parse_ipv6(str->str, ipv6, NULL, &port)) { if (!port) return saddr; saddr.len = sizeof(struct sockaddr_in6); saddr.addr = (liSockAddr*) g_slice_alloc0(saddr.len); @@ -580,7 +580,7 @@ liSocketAddress sockaddr_from_string(GString *str, guint tcp_default_port) { return saddr; } -liSocketAddress sockaddr_local_from_socket(gint fd) { +liSocketAddress li_sockaddr_local_from_socket(gint fd) { socklen_t l = 0; static struct sockaddr sa; liSocketAddress saddr = { 0, NULL }; @@ -596,7 +596,7 @@ liSocketAddress sockaddr_local_from_socket(gint fd) { return saddr; } -liSocketAddress sockaddr_remote_from_socket(gint fd) { +liSocketAddress li_sockaddr_remote_from_socket(gint fd) { socklen_t l = 0; static struct sockaddr sa; liSocketAddress saddr = { 0, NULL }; @@ -612,14 +612,14 @@ liSocketAddress sockaddr_remote_from_socket(gint fd) { return saddr; } -void sockaddr_clear(liSocketAddress *saddr) { +void li_sockaddr_clear(liSocketAddress *saddr) { if (saddr->addr) g_slice_free1(saddr->len, saddr->addr); saddr->addr = NULL; saddr->len = 0; } /* unused */ -void gstring_replace_char_with_str_len(GString *gstr, gchar c, gchar *str, guint len) { +void li_gstring_replace_char_with_str_len(GString *gstr, gchar c, gchar *str, guint len) { for (guint i = 0; i < gstr->len; i++) { if (gstr->str[i] == c) { /* char found, replace */ @@ -631,32 +631,32 @@ void gstring_replace_char_with_str_len(GString *gstr, gchar c, gchar *str, guint } } -gboolean l_g_strncase_equal(GString *str, const gchar *s, guint len) { +gboolean li_strncase_equal(GString *str, const gchar *s, guint len) { if (str->len != len) return FALSE; return 0 == g_ascii_strncasecmp(str->str, s, len); } -gboolean l_g_string_suffix(GString *str, const gchar *s, gsize len) { +gboolean li_string_suffix(GString *str, const gchar *s, gsize len) { if (str->len < len) return FALSE; return (strcmp(str->str + str->len - len, s) == 0); } -gboolean l_g_string_prefix(GString *str, const gchar *s, gsize len) { +gboolean li_string_prefix(GString *str, const gchar *s, gsize len) { if (str->len < len) return FALSE; return (strncmp(str->str, s, len) == 0); } -GString *l_g_string_assign_len(GString *string, const gchar *val, gssize len) { +GString *li_string_assign_len(GString *string, const gchar *val, gssize len) { g_string_truncate(string, 0); g_string_append_len(string, val, len); return string; } -void l_g_string_append_int(GString *dest, gint64 v) { +void li_string_append_int(GString *dest, gint64 v) { gchar *buf, *end, swap; gsize len; guint64 val; @@ -696,7 +696,7 @@ void l_g_string_append_int(GString *dest, gint64 v) { } /* http://womble.decadentplace.org.uk/readdir_r-advisory.html */ -gsize dirent_buf_size(DIR * dirp) { +gsize li_dirent_buf_size(DIR * dirp) { glong name_max; gsize name_end; diff --git a/src/value.c b/src/value.c index 783d7a4..1625572 100644 --- a/src/value.c +++ b/src/value.c @@ -1,33 +1,33 @@ #include -liValue* value_new_none() { +liValue* li_value_new_none() { liValue *v = g_slice_new0(liValue); v->type = LI_VALUE_NONE; return v; } -liValue* value_new_bool(gboolean val) { +liValue* li_value_new_bool(gboolean val) { liValue *v = g_slice_new0(liValue); v->data.boolean = val; v->type = LI_VALUE_BOOLEAN; return v; } -liValue* value_new_number(gint64 val) { +liValue* li_value_new_number(gint64 val) { liValue *v = g_slice_new0(liValue); v->data.number = val; v->type = LI_VALUE_NUMBER; return v; } -liValue* value_new_string(GString *val) { +liValue* li_value_new_string(GString *val) { liValue *v = g_slice_new0(liValue); v->data.string = val; v->type = LI_VALUE_STRING; return v; } -liValue* value_new_list() { +liValue* li_value_new_list() { liValue *v = g_slice_new0(liValue); v->data.list = g_array_new(FALSE, TRUE, sizeof(liValue*)); v->type = LI_VALUE_LIST; @@ -39,10 +39,10 @@ static void _value_hash_free_key(gpointer data) { } static void _value_hash_free_value(gpointer data) { - value_free((liValue*) data); + li_value_free((liValue*) data); } -liValue* value_new_hash() { +liValue* li_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, @@ -51,7 +51,7 @@ liValue* value_new_hash() { return v; } -liValue* value_new_action(liServer *srv, liAction *a) { +liValue* li_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; @@ -59,7 +59,7 @@ liValue* value_new_action(liServer *srv, liAction *a) { return v; } -liValue* value_new_condition(liServer *srv, liCondition *c) { +liValue* li_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; @@ -67,46 +67,46 @@ liValue* value_new_condition(liServer *srv, liCondition *c) { return v; } -liValue* value_copy(liValue* val) { +liValue* li_value_copy(liValue* val) { liValue *n; switch (val->type) { - 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_NONE: n = li_value_new_bool(FALSE); n->type = LI_VALUE_NONE; return n; /* hack */ + case LI_VALUE_BOOLEAN: return li_value_new_bool(val->data.boolean); + case LI_VALUE_NUMBER: return li_value_new_number(val->data.number); + case LI_VALUE_STRING: return li_value_new_string(g_string_new_len(GSTR_LEN(val->data.string))); /* list: we have to copy every value in the list! */ case LI_VALUE_LIST: - n = value_new_list(); + n = li_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, liValue*, i) = value_copy(g_array_index(val->data.list, liValue*, i)); + g_array_index(n->data.list, liValue*, i) = li_value_copy(g_array_index(val->data.list, liValue*, i)); } return n; /* hash: iterate over hashtable, clone each value */ case LI_VALUE_HASH: - n = value_new_hash(); + n = li_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((liValue*)v)); + g_hash_table_insert(n->data.hash, g_string_new_len(GSTR_LEN((GString*)k)), li_value_copy((liValue*)v)); } return n; 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); + li_action_acquire(val->data.val_action.action); + n = li_value_new_action(val->data.val_action.srv, val->data.val_action.action); return n; 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); + li_condition_acquire(val->data.val_cond.cond); + n = li_value_new_condition(val->data.val_cond.srv, val->data.val_cond.cond); return n; } return NULL; } -void value_free(liValue* val) { +void li_value_free(liValue* val) { if (!val) return; switch (val->type) { @@ -119,23 +119,23 @@ void value_free(liValue* val) { g_string_free(val->data.string, TRUE); break; case LI_VALUE_LIST: - value_list_free(val->data.list); + li_value_list_free(val->data.list); break; case LI_VALUE_HASH: g_hash_table_destroy(val->data.hash); break; case LI_VALUE_ACTION: - action_release(val->data.val_action.srv, val->data.val_action.action); + li_action_release(val->data.val_action.srv, val->data.val_action.action); break; case LI_VALUE_CONDITION: - condition_release(val->data.val_cond.srv, val->data.val_cond.cond); + li_condition_release(val->data.val_cond.srv, val->data.val_cond.cond); break; } val->type = LI_VALUE_NONE; g_slice_free(liValue, val); } -const char* value_type_string(liValueType type) { +const char* li_value_type_string(liValueType type) { switch(type) { case LI_VALUE_NONE: return "none"; @@ -157,15 +157,15 @@ const char* value_type_string(liValueType type) { return ""; } -void value_list_free(GArray *vallist) { +void li_value_list_free(GArray *vallist) { if (!vallist) return; for (gsize i = 0; i < vallist->len; i++) { - value_free(g_array_index(vallist, liValue*, i)); + li_value_free(g_array_index(vallist, liValue*, i)); } g_array_free(vallist, TRUE); } -GString *value_to_string(liValue *val) { +GString *li_value_to_string(liValue *val) { GString *str; switch (val->type) { @@ -186,11 +186,11 @@ GString *value_to_string(liValue *val) { 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, liValue*, 0)); + GString *tmp = li_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, liValue*, i)); + tmp = li_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); @@ -211,7 +211,7 @@ GString *value_to_string(liValue *val) { while (g_hash_table_iter_next(&iter, &k, &v)) { if (i) g_string_append_len(str, CONST_STR_LEN(", ")); - tmp = value_to_string((liValue*)v); + tmp = li_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/value_lua.c b/src/value_lua.c index 0c92e7b..60db824 100644 --- a/src/value_lua.c +++ b/src/value_lua.c @@ -13,7 +13,7 @@ static int lua_fixindex(lua_State *L, int ndx) { return ndx; } -static liValue* value_from_lua_table(liServer *srv, lua_State *L, int ndx) { +static liValue* li_value_from_lua_table(liServer *srv, lua_State *L, int ndx) { liValue *val = NULL, *sub_option; GArray *list = NULL; GHashTable *hash = NULL; @@ -27,7 +27,7 @@ static liValue* value_from_lua_table(liServer *srv, lua_State *L, int ndx) { case LUA_TNUMBER: if (hash) goto mixerror; if (!list) { - val = value_new_list(); + val = li_value_new_list(); list = val->data.list; } ikey = lua_tointeger(L, -2) - 1; @@ -36,7 +36,7 @@ static liValue* value_from_lua_table(liServer *srv, lua_State *L, int ndx) { lua_pop(L, 1); continue; } - sub_option = value_from_lua(srv, L); + sub_option = li_value_from_lua(srv, L); if (!sub_option) continue; if ((size_t) ikey >= list->len) { g_array_set_size(list, ikey + 1); @@ -47,16 +47,16 @@ static liValue* value_from_lua_table(liServer *srv, lua_State *L, int ndx) { case LUA_TSTRING: if (list) goto mixerror; if (!hash) { - val = value_new_hash(); + val = li_value_new_hash(); hash = val->data.hash; } - skey = lua_togstring(L, -2); + skey = li_lua_togstring(L, -2); if (g_hash_table_lookup(hash, skey)) { ERROR(srv, "Key already exists in hash: '%s' - skipping entry", skey->str); lua_pop(L, 1); continue; } - sub_option = value_from_lua(srv, L); + sub_option = li_value_from_lua(srv, L); if (!sub_option) { g_string_free(skey, TRUE); continue; @@ -80,31 +80,31 @@ mixerror: } -liValue* value_from_lua(liServer *srv, lua_State *L) { +liValue* li_value_from_lua(liServer *srv, lua_State *L) { liValue *val; switch (lua_type(L, -1)) { case LUA_TNIL: lua_pop(L, 1); - return value_new_none(); + return li_value_new_none(); case LUA_TBOOLEAN: - val = value_new_bool(lua_toboolean(L, -1)); + val = li_value_new_bool(lua_toboolean(L, -1)); lua_pop(L, 1); return val; case LUA_TNUMBER: - val = value_new_number(lua_tonumber(L, -1)); + val = li_value_new_number(lua_tonumber(L, -1)); lua_pop(L, 1); return val; case LUA_TSTRING: - val = value_new_string(lua_togstring(L, -1)); + val = li_value_new_string(li_lua_togstring(L, -1)); lua_pop(L, 1); return val; case LUA_TTABLE: - val = value_from_lua_table(srv, L, -1); + val = li_value_from_lua_table(srv, L, -1); lua_pop(L, 1); return val; @@ -112,17 +112,17 @@ liValue* value_from_lua(liServer *srv, lua_State *L) { { /* check for action */ liAction *a = lua_get_action(L, -1); if (a) { - action_acquire(a); + li_action_acquire(a); lua_pop(L, 1); - return val = value_new_action(srv, a); + return val = li_value_new_action(srv, a); } } { /* check for condition */ liCondition *c = lua_get_condition(L, -1); if (c) { - condition_acquire(c); + li_condition_acquire(c); lua_pop(L, 1); - return val = value_new_condition(srv, c); + return val = li_value_new_condition(srv, c); } } ERROR(srv, "%s", "Unknown lua userdata"); @@ -140,7 +140,7 @@ liValue* value_from_lua(liServer *srv, lua_State *L) { } } -GString* lua_togstring(lua_State *L, int ndx) { +GString* li_lua_togstring(lua_State *L, int ndx) { const char *buf; size_t len = 0; GString *str = NULL; diff --git a/src/virtualrequest.c b/src/virtualrequest.c index 3736111..43cbb9e 100644 --- a/src/virtualrequest.c +++ b/src/virtualrequest.c @@ -4,8 +4,8 @@ static void filters_init(liFilters *fs) { fs->queue = g_ptr_array_new(); - fs->in = chunkqueue_new(); - fs->out = chunkqueue_new(); + fs->in = li_chunkqueue_new(); + fs->out = li_chunkqueue_new(); } static void filters_clean(liVRequest *vr, liFilters *fs) { @@ -13,12 +13,12 @@ static void filters_clean(liVRequest *vr, liFilters *fs) { for (i = 0; i < fs->queue->len; 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); + if (i > 0) li_chunkqueue_free(fs->in); g_slice_free(liFilter, f); } g_ptr_array_free(fs->queue, TRUE); - chunkqueue_free(fs->in); - chunkqueue_free(fs->out); + li_chunkqueue_free(fs->in); + li_chunkqueue_free(fs->out); } static void filters_reset(liVRequest *vr, liFilters *fs) { @@ -27,18 +27,18 @@ static void filters_reset(liVRequest *vr, liFilters *fs) { for (i = 0; i < fs->queue->len; 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); + if (i > 0) li_chunkqueue_free(fs->in); g_slice_free(liFilter, f); } g_ptr_array_set_size(fs->queue, 0); - chunkqueue_reset(fs->in); - chunkqueue_reset(fs->out); + li_chunkqueue_reset(fs->in); + li_chunkqueue_reset(fs->out); } static gboolean filters_run(liVRequest *vr, liFilters *fs) { guint i; if (0 == fs->queue->len) { - chunkqueue_steal_all(fs->out, fs->in); + li_chunkqueue_steal_all(fs->out, fs->in); if (fs->in->is_closed) fs->out->is_closed = TRUE; return TRUE; } @@ -48,10 +48,10 @@ static gboolean filters_run(liVRequest *vr, liFilters *fs) { case LI_HANDLER_GO_ON: break; case LI_HANDLER_COMEBACK: - vrequest_joblist_append(vr); + li_vrequest_joblist_append(vr); break; case LI_HANDLER_WAIT_FOR_EVENT: - break; /* ignore - filter has to call vrequest_joblist_append(vr); */ + break; /* ignore - filter has to call li_vrequest_joblist_append(vr); */ case LI_HANDLER_ERROR: return FALSE; } @@ -84,21 +84,21 @@ static void filters_add(liFilters *fs, liFilterHandlerCB handle_data, liFilterFr f->in = fs->in; } else { 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); + f->in = prev->out = li_chunkqueue_new(); + li_chunkqueue_set_limit(f->in, fs->in->limit); } g_ptr_array_add(fs->queue, f); } -void vrequest_add_filter_in(liVRequest *vr, liFilterHandlerCB handle_data, liFilterFreeCB handle_free, gpointer param) { +void li_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(liVRequest *vr, liFilterHandlerCB handle_data, liFilterFreeCB handle_free, gpointer param) { +void li_vrequest_add_filter_out(liVRequest *vr, liFilterHandlerCB handle_data, liFilterFreeCB handle_free, gpointer param) { filters_add(&vr->filters_out, handle_data, handle_free, param); } -liVRequest* vrequest_new(liConnection *con, liVRequestHandlerCB handle_response_headers, liVRequestHandlerCB handle_response_body, liVRequestHandlerCB handle_response_error, liVRequestHandlerCB handle_request_headers) { +liVRequest* li_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); @@ -118,10 +118,10 @@ liVRequest* vrequest_new(liConnection *con, liVRequestHandlerCB handle_response_ 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(liOptionValue), srv->option_def_values->data); - request_init(&vr->request); - physical_init(&vr->physical); - response_init(&vr->response); - environment_init(&vr->env); + li_request_init(&vr->request); + li_physical_init(&vr->physical); + li_response_init(&vr->response); + li_environment_init(&vr->env); filters_init(&vr->filters_in); filters_init(&vr->filters_out); @@ -134,22 +134,22 @@ liVRequest* vrequest_new(liConnection *con, liVRequestHandlerCB handle_response_ vr->job_queue_link.data = vr; - action_stack_init(&vr->action_stack); + li_action_stack_init(&vr->action_stack); return vr; } -void vrequest_free(liVRequest* vr) { +void li_vrequest_free(liVRequest* vr) { guint i; - action_stack_clear(vr, &vr->action_stack); - plugins_handle_vrclose(vr); + li_action_stack_clear(vr, &vr->action_stack); + li_plugins_handle_vrclose(vr); g_ptr_array_free(vr->plugin_ctx, TRUE); - request_clear(&vr->request); - physical_clear(&vr->physical); - response_clear(&vr->response); - environment_clear(&vr->env); + li_request_clear(&vr->request); + li_physical_clear(&vr->physical); + li_response_clear(&vr->response); + li_environment_clear(&vr->env); filters_clean(vr, &vr->filters_in); filters_clean(vr, &vr->filters_out); @@ -164,7 +164,7 @@ void vrequest_free(liVRequest* vr) { for (i = 0; i < vr->stat_cache_entries->len; i++) { liStatCacheEntry *sce = g_ptr_array_index(vr->stat_cache_entries, i); - stat_cache_entry_release(vr, sce); + li_stat_cache_entry_release(vr, sce); } g_ptr_array_free(vr->stat_cache_entries, TRUE); @@ -176,11 +176,11 @@ void vrequest_free(liVRequest* vr) { g_slice_free(liVRequest, vr); } -void vrequest_reset(liVRequest *vr) { +void li_vrequest_reset(liVRequest *vr) { guint i; - action_stack_reset(vr, &vr->action_stack); - plugins_handle_vrclose(vr); + li_action_stack_reset(vr, &vr->action_stack); + li_plugins_handle_vrclose(vr); { gint len = vr->plugin_ctx->len; g_ptr_array_set_size(vr->plugin_ctx, 0); @@ -191,10 +191,10 @@ void vrequest_reset(liVRequest *vr) { vr->backend = NULL; - request_reset(&vr->request); - physical_reset(&vr->physical); - response_reset(&vr->response); - environment_reset(&vr->env); + li_request_reset(&vr->request); + li_physical_reset(&vr->physical); + li_response_reset(&vr->response); + li_environment_reset(&vr->env); filters_reset(vr, &vr->filters_in); filters_reset(vr, &vr->filters_out); @@ -206,7 +206,7 @@ void vrequest_reset(liVRequest *vr) { for (i = 0; i < vr->stat_cache_entries->len; i++) { liStatCacheEntry *sce = g_ptr_array_index(vr->stat_cache_entries, i); - stat_cache_entry_release(vr, sce); + li_stat_cache_entry_release(vr, sce); } memcpy(vr->options, vr->wrk->srv->option_def_values->data, vr->wrk->srv->option_def_values->len * sizeof(liOptionValue)); @@ -223,14 +223,14 @@ void vrequest_reset(liVRequest *vr) { } } -liVRequestRef* vrequest_acquire_ref(liVRequest *vr) { +liVRequestRef* li_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; } -liVRequest* vrequest_release_ref(liVRequestRef *vr_ref) { +liVRequest* li_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)) { @@ -240,60 +240,60 @@ liVRequest* vrequest_release_ref(liVRequestRef *vr_ref) { return vr; } -void vrequest_error(liVRequest *vr) { +void li_vrequest_error(liVRequest *vr) { vr->state = LI_VRS_ERROR; vr->out->is_closed = TRUE; - vrequest_joblist_append(vr); + li_vrequest_joblist_append(vr); } -void vrequest_backend_error(liVRequest *vr, liBackendError berror) { +void li_vrequest_backend_error(liVRequest *vr, liBackendError berror) { vr->action_stack.backend_failed = TRUE; vr->action_stack.backend_error = berror; vr->state = LI_VRS_HANDLE_REQUEST_HEADERS; vr->backend = NULL; - vrequest_joblist_append(vr); + li_vrequest_joblist_append(vr); } -void vrequest_backend_overloaded(liVRequest *vr) { - vrequest_backend_error(vr, BACKEND_OVERLOAD); +void li_vrequest_backend_overloaded(liVRequest *vr) { + li_vrequest_backend_error(vr, BACKEND_OVERLOAD); } -void vrequest_backend_dead(liVRequest *vr) { - vrequest_backend_error(vr, BACKEND_DEAD); +void li_vrequest_backend_dead(liVRequest *vr) { + li_vrequest_backend_error(vr, BACKEND_DEAD); } /* received all request headers */ -void vrequest_handle_request_headers(liVRequest *vr) { +void li_vrequest_handle_request_headers(liVRequest *vr) { if (LI_VRS_CLEAN == vr->state) { vr->state = LI_VRS_HANDLE_REQUEST_HEADERS; } - vrequest_joblist_append(vr); + li_vrequest_joblist_append(vr); } /* received (partial) request content */ -void vrequest_handle_request_body(liVRequest *vr) { +void li_vrequest_handle_request_body(liVRequest *vr) { if (LI_VRS_READ_CONTENT <= vr->state) { - vrequest_joblist_append(vr); + li_vrequest_joblist_append(vr); } } /* received all response headers/status code - call once from your indirect handler */ -void vrequest_handle_response_headers(liVRequest *vr) { +void li_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); + li_vrequest_joblist_append(vr); } /* received (partial) response content - call from your indirect handler */ -void vrequest_handle_response_body(liVRequest *vr) { +void li_vrequest_handle_response_body(liVRequest *vr) { if (LI_VRS_WRITE_CONTENT == vr->state) { - vrequest_joblist_append(vr); + li_vrequest_joblist_append(vr); } } /* response completely ready */ -gboolean vrequest_handle_direct(liVRequest *vr) { +gboolean li_vrequest_handle_direct(liVRequest *vr) { if (vr->state < LI_VRS_READ_CONTENT) { vr->state = LI_VRS_HANDLE_RESPONSE_HEADERS; vr->out->is_closed = TRUE; @@ -305,7 +305,7 @@ gboolean vrequest_handle_direct(liVRequest *vr) { } /* handle request over time */ -gboolean vrequest_handle_indirect(liVRequest *vr, liPlugin *p) { +gboolean li_vrequest_handle_indirect(liVRequest *vr, liPlugin *p) { if (vr->state < LI_VRS_READ_CONTENT) { vr->state = LI_VRS_READ_CONTENT; vr->backend = p; @@ -315,17 +315,17 @@ gboolean vrequest_handle_indirect(liVRequest *vr, liPlugin *p) { } } -gboolean vrequest_is_handled(liVRequest *vr) { +gboolean li_vrequest_is_handled(liVRequest *vr) { return vr->state >= LI_VRS_READ_CONTENT; } static gboolean vrequest_do_handle_actions(liVRequest *vr) { - liHandlerResult res = action_execute(vr); + liHandlerResult res = li_action_execute(vr); switch (res) { case LI_HANDLER_GO_ON: if (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS) { /* request not handled */ - vrequest_handle_direct(vr); + li_vrequest_handle_direct(vr); vr->response.http_status = 404; if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) { VR_DEBUG(vr, "%s", "actions didn't handle request"); @@ -335,12 +335,12 @@ static gboolean vrequest_do_handle_actions(liVRequest *vr) { /* otherwise state already changed */ break; case LI_HANDLER_COMEBACK: - vrequest_joblist_append(vr); /* come back later */ + li_vrequest_joblist_append(vr); /* come back later */ return FALSE; case LI_HANDLER_WAIT_FOR_EVENT: return FALSE; case LI_HANDLER_ERROR: - vrequest_error(vr); + li_vrequest_error(vr); return FALSE; } return TRUE; @@ -350,7 +350,7 @@ static gboolean vrequest_do_handle_actions(liVRequest *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); + li_vrequest_error(vr); } if (vr->vr_in->is_closed) vr->in->is_closed = TRUE; @@ -358,16 +358,16 @@ static gboolean vrequest_do_handle_read(liVRequest *vr) { case LI_HANDLER_GO_ON: break; case LI_HANDLER_COMEBACK: - vrequest_joblist_append(vr); /* come back later */ + li_vrequest_joblist_append(vr); /* come back later */ return FALSE; case LI_HANDLER_WAIT_FOR_EVENT: return FALSE; case LI_HANDLER_ERROR: - vrequest_error(vr); + li_vrequest_error(vr); break; } } else { - chunkqueue_skip_all(vr->vr_in); + li_chunkqueue_skip_all(vr->vr_in); if (vr->vr_in->is_closed) vr->in->is_closed = TRUE; } return TRUE; @@ -375,25 +375,25 @@ static gboolean vrequest_do_handle_read(liVRequest *vr) { static gboolean vrequest_do_handle_write(liVRequest *vr) { if (!filters_run(vr, &vr->filters_out)) { - vrequest_error(vr); + li_vrequest_error(vr); } switch (vr->handle_response_body(vr)) { case LI_HANDLER_GO_ON: break; case LI_HANDLER_COMEBACK: - vrequest_joblist_append(vr); /* come back later */ + li_vrequest_joblist_append(vr); /* come back later */ return FALSE; case LI_HANDLER_WAIT_FOR_EVENT: return FALSE; case LI_HANDLER_ERROR: - vrequest_error(vr); + li_vrequest_error(vr); break; } return TRUE; } -void vrequest_state_machine(liVRequest *vr) { +void li_vrequest_state_machine(liVRequest *vr) { gboolean done = FALSE; liHandlerResult res; do { @@ -413,18 +413,18 @@ void vrequest_state_machine(liVRequest *vr) { if (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS) { /* unhandled request */ vr->response.http_status = 404; - vrequest_handle_direct(vr); + li_vrequest_handle_direct(vr); } break; case LI_HANDLER_COMEBACK: - vrequest_joblist_append(vr); /* come back later */ + li_vrequest_joblist_append(vr); /* come back later */ done = TRUE; break; case LI_HANDLER_WAIT_FOR_EVENT: done = (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS); break; case LI_HANDLER_ERROR: - vrequest_error(vr); + li_vrequest_error(vr); break; } break; @@ -442,14 +442,14 @@ void vrequest_state_machine(liVRequest *vr) { vr->state = LI_VRS_WRITE_CONTENT; break; case LI_HANDLER_COMEBACK: - vrequest_joblist_append(vr); /* come back later */ + li_vrequest_joblist_append(vr); /* come back later */ done = TRUE; break; case LI_HANDLER_WAIT_FOR_EVENT: done = (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS); break; case LI_HANDLER_ERROR: - vrequest_error(vr); + li_vrequest_error(vr); break; } break; @@ -468,7 +468,7 @@ void vrequest_state_machine(liVRequest *vr) { } while (!done); } -void vrequest_joblist_append(liVRequest *vr) { +void li_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 */ @@ -476,15 +476,15 @@ void vrequest_joblist_append(liVRequest *vr) { ev_timer_start(wrk->loop, &wrk->job_queue_watcher); } -void vrequest_joblist_append_async(liVRequest *vr) { +void li_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)); + g_async_queue_push(q, li_vrequest_acquire_ref(vr)); ev_async_send(wrk->loop, &wrk->job_async_queue_watcher); } -gboolean vrequest_stat(liVRequest *vr) { +gboolean li_vrequest_stat(liVRequest *vr) { /* Do not stat again */ if (vr->physical.have_stat || vr->physical.have_errno) return vr->physical.have_stat; @@ -507,12 +507,12 @@ gboolean vrequest_stat(liVRequest *vr) { return TRUE; } -gboolean vrequest_redirect(liVRequest *vr, GString *uri) { - if (!vrequest_handle_direct(vr)) +gboolean li_vrequest_redirect(liVRequest *vr, GString *uri) { + if (!li_vrequest_handle_direct(vr)) return FALSE; vr->response.http_status = 301; - http_header_overwrite(vr->response.headers, CONST_STR_LEN("Location"), GSTR_LEN(uri)); + li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Location"), GSTR_LEN(uri)); return TRUE; } diff --git a/src/waitqueue.c b/src/waitqueue.c index 3cdc50b..0aed5fc 100644 --- a/src/waitqueue.c +++ b/src/waitqueue.c @@ -1,7 +1,7 @@ #include -void waitqueue_init(liWaitQueue *queue, struct ev_loop *loop, liWaitQueueCB callback, gdouble delay, gpointer data) { +void li_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(liWaitQueue *queue, struct ev_loop *loop, liWaitQueueCB call queue->delay = delay; } -void waitqueue_stop(liWaitQueue *queue) { +void li_waitqueue_stop(liWaitQueue *queue) { ev_timer_stop(queue->loop, &queue->timer); } -void waitqueue_update(liWaitQueue *queue) { +void li_waitqueue_update(liWaitQueue *queue) { ev_tstamp repeat; ev_tstamp now = ev_now(queue->loop); @@ -33,7 +33,7 @@ void waitqueue_update(liWaitQueue *queue) { } } -void waitqueue_push(liWaitQueue *queue, liWaitQueueElem *elem) { +void li_waitqueue_push(liWaitQueue *queue, liWaitQueueElem *elem) { elem->ts = ev_now(queue->loop); if (!elem->queued) { @@ -74,7 +74,7 @@ void waitqueue_push(liWaitQueue *queue, liWaitQueueElem *elem) { ev_timer_start(queue->loop, &queue->timer); } -liWaitQueueElem *waitqueue_pop(liWaitQueue *queue) { +liWaitQueueElem *li_waitqueue_pop(liWaitQueue *queue) { liWaitQueueElem *elem = queue->head; ev_tstamp now = ev_now(queue->loop); @@ -94,7 +94,7 @@ liWaitQueueElem *waitqueue_pop(liWaitQueue *queue) { return elem; } -void waitqueue_remove(liWaitQueue *queue, liWaitQueueElem *elem) { +void li_waitqueue_remove(liWaitQueue *queue, liWaitQueueElem *elem) { if (!elem->queued) return; @@ -116,7 +116,7 @@ void waitqueue_remove(liWaitQueue *queue, liWaitQueueElem *elem) { } -guint waitqueue_length(liWaitQueue *queue) { +guint li_waitqueue_length(liWaitQueue *queue) { guint i = 0; liWaitQueueElem *elem = queue->head; @@ -128,7 +128,7 @@ guint waitqueue_length(liWaitQueue *queue) { return i; } -guint waitqueue_pop_ready(liWaitQueue *queue, liWaitQueueElem **head) { +guint li_waitqueue_pop_ready(liWaitQueue *queue, liWaitQueueElem **head) { guint i = 0; liWaitQueueElem *elem = queue->head; ev_tstamp now = ev_now(queue->loop); diff --git a/src/worker.c b/src/worker.c index 18bfc97..f95adb7 100644 --- a/src/worker.c +++ b/src/worker.c @@ -27,7 +27,7 @@ static void worker_closing_socket_cb(int revents, void* arg) { g_slice_free(worker_closing_socket, scs); } -void worker_add_closing_socket(liWorker *wrk, int fd) { +void li_worker_add_closing_socket(liWorker *wrk, int fd) { worker_closing_socket *scs; shutdown(fd, SHUT_WR); @@ -53,7 +53,7 @@ static void worker_rem_closing_socket(liWorker *wrk, worker_closing_socket *scs) /* Keep alive */ -void worker_check_keepalive(liWorker *wrk) { +void li_worker_check_keepalive(liWorker *wrk) { ev_tstamp now = ev_now(wrk->loop); if (0 == wrk->keep_alive_queue.length) { @@ -106,15 +106,15 @@ static void worker_io_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) UNUSED(loop); UNUSED(revents); - while ((wqe = waitqueue_pop(&wrk->io_timeout_queue)) != NULL) { + while ((wqe = li_waitqueue_pop(&wrk->io_timeout_queue)) != NULL) { /* connection has timed out */ con = wqe->data; _DEBUG(con->srv, con->mainvr, "connection io-timeout from %s after %.2f seconds", con->remote_addr_str->str, now - wqe->ts); - plugins_handle_close(con); + li_plugins_handle_close(con); worker_con_put(con); } - waitqueue_update(&wrk->io_timeout_queue); + li_waitqueue_update(&wrk->io_timeout_queue); } /* run vreqest state machine */ @@ -131,7 +131,7 @@ static void worker_job_queue_cb(struct ev_loop *loop, ev_timer *w, int revents) while (NULL != (l = g_queue_pop_head_link(&q))) { vr = l->data; g_assert(g_atomic_int_compare_and_exchange(&vr->queued, 1, 0)); - vrequest_state_machine(vr); + li_vrequest_state_machine(vr); } } @@ -145,16 +145,16 @@ static void worker_job_async_queue_cb(struct ev_loop *loop, ev_async *w, int rev UNUSED(revents); while (NULL != (vr_ref = g_async_queue_try_pop(q))) { - if (NULL != (vr = vrequest_release_ref(vr_ref))) { + if (NULL != (vr = li_vrequest_release_ref(vr_ref))) { g_assert(g_atomic_int_compare_and_exchange(&vr->queued, 1, 0)); - vrequest_state_machine(vr); + li_vrequest_state_machine(vr); } } } /* cache timestamp */ -GString *worker_current_timestamp(liWorker *wrk, guint format_ndx) { +GString *li_worker_current_timestamp(liWorker *wrk, guint format_ndx) { gsize len; struct tm tm; liWorkerTS *wts = &g_array_index(wrk->timestamps, liWorkerTS, format_ndx); @@ -177,32 +177,32 @@ GString *worker_current_timestamp(liWorker *wrk, guint format_ndx) { } /* stop worker watcher */ -static void worker_stop_cb(struct ev_loop *loop, ev_async *w, int revents) { +static void li_worker_stop_cb(struct ev_loop *loop, ev_async *w, int revents) { liWorker *wrk = (liWorker*) w->data; UNUSED(loop); UNUSED(revents); - worker_stop(wrk, wrk); + li_worker_stop(wrk, wrk); } /* exit worker watcher */ -static void worker_exit_cb(struct ev_loop *loop, ev_async *w, int revents) { +static void li_worker_exit_cb(struct ev_loop *loop, ev_async *w, int revents) { liWorker *wrk = (liWorker*) w->data; UNUSED(loop); UNUSED(revents); - worker_exit(wrk, wrk); + li_worker_exit(wrk, wrk); } -typedef struct worker_new_con_data worker_new_con_data; -struct worker_new_con_data { +typedef struct li_worker_new_con_data li_worker_new_con_data; +struct li_worker_new_con_data { liSocketAddress remote_addr; int s; liServerSocket *srv_sock; }; /* new con watcher */ -void worker_new_con(liWorker *ctx, liWorker *wrk, liSocketAddress remote_addr, int s, liServerSocket *srv_sock) { +void li_worker_new_con(liWorker *ctx, liWorker *wrk, liSocketAddress remote_addr, int s, liServerSocket *srv_sock) { if (ctx == wrk) { liConnection *con = worker_con_get(wrk); @@ -212,10 +212,10 @@ void worker_new_con(liWorker *ctx, liWorker *wrk, liSocketAddress remote_addr, i ev_io_set(&con->sock_watcher, s, EV_READ); ev_io_start(wrk->loop, &con->sock_watcher); con->ts = CUR_TS(con->wrk); - sockaddr_to_string(remote_addr, con->remote_addr_str, FALSE); - waitqueue_push(&wrk->io_timeout_queue, &con->io_timeout_elem); + li_sockaddr_to_string(remote_addr, con->remote_addr_str, FALSE); + li_waitqueue_push(&wrk->io_timeout_queue, &con->io_timeout_elem); } else { - worker_new_con_data *d = g_slice_new(worker_new_con_data); + li_worker_new_con_data *d = g_slice_new(li_worker_new_con_data); d->remote_addr = remote_addr; d->s = s; d->srv_sock = srv_sock; @@ -224,15 +224,15 @@ void worker_new_con(liWorker *ctx, liWorker *wrk, liSocketAddress remote_addr, i } } -static void worker_new_con_cb(struct ev_loop *loop, ev_async *w, int revents) { +static void li_worker_new_con_cb(struct ev_loop *loop, ev_async *w, int revents) { liWorker *wrk = (liWorker*) w->data; - worker_new_con_data *d; + li_worker_new_con_data *d; UNUSED(loop); UNUSED(revents); while (NULL != (d = g_async_queue_try_pop(wrk->new_con_queue))) { - worker_new_con(wrk, wrk, d->remote_addr, d->s, d->srv_sock); - g_slice_free(worker_new_con_data, d); + li_worker_new_con(wrk, wrk, d->remote_addr, d->s, d->srv_sock); + g_slice_free(li_worker_new_con_data, d); } } @@ -278,7 +278,7 @@ static void worker_stats_watcher_cb(struct ev_loop *loop, ev_timer *w, int reven /* init */ -liWorker* worker_new(liServer *srv, struct ev_loop *loop) { +liWorker* li_worker_new(liServer *srv, struct ev_loop *loop) { liWorker *wrk = g_slice_new0(liWorker); wrk->srv = srv; wrk->loop = loop; @@ -300,16 +300,16 @@ liWorker* worker_new(liServer *srv, struct ev_loop *loop) { g_array_index(wrk->timestamps, liWorkerTS, i).str = g_string_sized_new(255); } - ev_init(&wrk->worker_exit_watcher, worker_exit_cb); - wrk->worker_exit_watcher.data = wrk; - ev_async_start(wrk->loop, &wrk->worker_exit_watcher); + ev_init(&wrk->li_worker_exit_watcher, li_worker_exit_cb); + wrk->li_worker_exit_watcher.data = wrk; + ev_async_start(wrk->loop, &wrk->li_worker_exit_watcher); ev_unref(wrk->loop); /* this watcher shouldn't keep the loop alive */ - ev_init(&wrk->worker_stop_watcher, worker_stop_cb); - wrk->worker_stop_watcher.data = wrk; - ev_async_start(wrk->loop, &wrk->worker_stop_watcher); + ev_init(&wrk->li_worker_stop_watcher, li_worker_stop_cb); + wrk->li_worker_stop_watcher.data = wrk; + ev_async_start(wrk->loop, &wrk->li_worker_stop_watcher); - ev_init(&wrk->new_con_watcher, worker_new_con_cb); + ev_init(&wrk->new_con_watcher, li_worker_new_con_cb); wrk->new_con_watcher.data = wrk; ev_async_start(wrk->loop, &wrk->new_con_watcher); wrk->new_con_queue = g_async_queue_new(); @@ -319,17 +319,17 @@ liWorker* worker_new(liServer *srv, struct ev_loop *loop) { ev_timer_start(wrk->loop, &wrk->stats_watcher); ev_unref(wrk->loop); /* this watcher shouldn't keep the loop alive */ - ev_init(&wrk->collect_watcher, collect_watcher_cb); + ev_init(&wrk->collect_watcher, li_collect_watcher_cb); wrk->collect_watcher.data = wrk; ev_async_start(wrk->loop, &wrk->collect_watcher); wrk->collect_queue = g_async_queue_new(); ev_unref(wrk->loop); /* this watcher shouldn't keep the loop alive */ /* io timeout timer */ - waitqueue_init(&wrk->io_timeout_queue, wrk->loop, worker_io_timeout_cb, srv->io_timeout, wrk); + li_waitqueue_init(&wrk->io_timeout_queue, wrk->loop, worker_io_timeout_cb, srv->io_timeout, wrk); /* throttling */ - waitqueue_init(&wrk->throttle_queue, wrk->loop, throttle_cb, THROTTLE_GRANULARITY, wrk); + li_waitqueue_init(&wrk->throttle_queue, wrk->loop, throttle_cb, THROTTLE_GRANULARITY, wrk); /* job queue */ g_queue_init(&wrk->job_queue); @@ -347,7 +347,7 @@ liWorker* worker_new(liServer *srv, struct ev_loop *loop) { return wrk; } -void worker_free(liWorker *wrk) { +void li_worker_free(liWorker *wrk) { if (!wrk) return; { /* close connections */ @@ -356,11 +356,11 @@ void worker_free(liWorker *wrk) { ERROR(wrk->srv, "Server shutdown with unclosed connections: %u", wrk->connections_active); for (i = wrk->connections_active; i-- > 0;) { liConnection *con = g_array_index(wrk->connections, liConnection*, i); - connection_error(con); + li_connection_error(con); } } for (i = 0; i < wrk->connections->len; i++) { - connection_free(g_array_index(wrk->connections, liConnection*, i)); + li_connection_free(g_array_index(wrk->connections, liConnection*, i)); } g_array_free(wrk->connections, TRUE); } @@ -384,7 +384,7 @@ void worker_free(liWorker *wrk) { } ev_ref(wrk->loop); - ev_async_stop(wrk->loop, &wrk->worker_exit_watcher); + ev_async_stop(wrk->loop, &wrk->li_worker_exit_watcher); { GAsyncQueue *q = wrk->job_async_queue; @@ -392,9 +392,9 @@ void worker_free(liWorker *wrk) { liVRequest *vr; while (NULL != (vr_ref = g_async_queue_try_pop(q))) { - if (NULL != (vr = vrequest_release_ref(vr_ref))) { + if (NULL != (vr = li_vrequest_release_ref(vr_ref))) { g_assert(g_atomic_int_compare_and_exchange(&vr->queued, 1, 0)); - vrequest_state_machine(vr); + li_vrequest_state_machine(vr); } } @@ -409,7 +409,7 @@ void worker_free(liWorker *wrk) { ev_ref(wrk->loop); ev_async_stop(wrk->loop, &wrk->collect_watcher); - collect_watcher_cb(wrk->loop, &wrk->collect_watcher, 0); + li_collect_watcher_cb(wrk->loop, &wrk->collect_watcher, 0); g_async_queue_unref(wrk->collect_queue); g_string_free(wrk->tmp_str, TRUE); @@ -419,7 +419,7 @@ void worker_free(liWorker *wrk) { g_slice_free(liWorker, wrk); } -void worker_run(liWorker *wrk) { +void li_worker_run(liWorker *wrk) { #ifdef LIGHTY_OS_LINUX /* sched_setaffinity is only available on linux */ cpu_set_t mask; @@ -444,15 +444,15 @@ void worker_run(liWorker *wrk) { ev_loop(wrk->loop, 0); } -void worker_stop(liWorker *context, liWorker *wrk) { +void li_worker_stop(liWorker *context, liWorker *wrk) { if (context == wrk) { guint i; - ev_async_stop(wrk->loop, &wrk->worker_stop_watcher); + ev_async_stop(wrk->loop, &wrk->li_worker_stop_watcher); ev_async_stop(wrk->loop, &wrk->new_con_watcher); - waitqueue_stop(&wrk->io_timeout_queue); - waitqueue_stop(&wrk->throttle_queue); - worker_new_con_cb(wrk->loop, &wrk->new_con_watcher, 0); /* handle remaining new connections */ + li_waitqueue_stop(&wrk->io_timeout_queue); + li_waitqueue_stop(&wrk->throttle_queue); + li_worker_new_con_cb(wrk->loop, &wrk->new_con_watcher, 0); /* handle remaining new connections */ /* close keep alive connections */ for (i = wrk->connections_active; i-- > 0;) { @@ -461,7 +461,7 @@ void worker_stop(liWorker *context, liWorker *wrk) { worker_con_put(con); } - worker_check_keepalive(wrk); + li_worker_check_keepalive(wrk); { /* force closing sockets */ GList *iter; @@ -470,15 +470,15 @@ void worker_stop(liWorker *context, liWorker *wrk) { } } } else { - ev_async_send(wrk->loop, &wrk->worker_stop_watcher); + ev_async_send(wrk->loop, &wrk->li_worker_stop_watcher); } } -void worker_exit(liWorker *context, liWorker *wrk) { +void li_worker_exit(liWorker *context, liWorker *wrk) { if (context == wrk) { ev_unloop (wrk->loop, EVUNLOOP_ALL); } else { - ev_async_send(wrk->loop, &wrk->worker_exit_watcher); + ev_async_send(wrk->loop, &wrk->li_worker_exit_watcher); } } @@ -487,7 +487,7 @@ static liConnection* worker_con_get(liWorker *wrk) { liConnection *con; if (wrk->connections_active >= wrk->connections->len) { - con = connection_new(wrk); + con = li_connection_new(wrk); con->idx = wrk->connections_active; g_array_append_val(wrk->connections, con); } else { @@ -528,12 +528,12 @@ void worker_con_put(liConnection *con) { guint i; threshold = (wrk->connections->len * 85) / 100; for (i = wrk->connections->len; i > threshold; i--) { - connection_free(g_array_index(wrk->connections, liConnection*, i-1)); + li_connection_free(g_array_index(wrk->connections, liConnection*, i-1)); } wrk->connections->len = threshold; wrk->connections_gc_ts = now; } else { /* no realloc */ - connection_reset(con); + li_connection_reset(con); } }