diff options
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/lua_common.h | 164 | ||||
-rw-r--r-- | src/lua/lua_map.h | 8 | ||||
-rw-r--r-- | src/lua/lua_thread_pool.h | 44 |
3 files changed, 149 insertions, 67 deletions
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index 93bb5a28e..d14ebba54 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -2,7 +2,6 @@ #define RSPAMD_LUA_H #include "config.h" -#ifdef WITH_LUA #include <lua.h> #include <lauxlib.h> @@ -48,6 +47,10 @@ luaL_register (lua_State *L, const gchar *name, const struct luaL_reg *methods) lua_State * L) #define LUA_INTERFACE_DEF(class, name) { # name, lua_ ## class ## _ ## name } +#ifdef __cplusplus +extern "C" { +#endif + extern const luaL_reg null_reg[]; #define RSPAMD_LUA_API_VERSION 12 @@ -126,17 +129,17 @@ struct rspamd_lua_cached_entry { * Create and register new class */ void rspamd_lua_new_class (lua_State *L, - const gchar *classname, - const struct luaL_reg *methods); + const gchar *classname, + const struct luaL_reg *methods); /** * Create and register new class with static methods */ void rspamd_lua_new_class_full (lua_State *L, - const gchar *classname, - const gchar *static_name, - const struct luaL_reg *methods, - const struct luaL_reg *func); + const gchar *classname, + const gchar *static_name, + const struct luaL_reg *methods, + const struct luaL_reg *func); /** * Set class name for object at @param objidx position @@ -151,7 +154,7 @@ void rspamd_lua_table_set (lua_State *L, const gchar *index, const gchar *value) /** * Get string value of index in a table (return t['index']) */ -const gchar * rspamd_lua_table_get (lua_State *L, const gchar *index); +const gchar *rspamd_lua_table_get (lua_State *L, const gchar *index); /** * Convert classname to string @@ -169,6 +172,7 @@ gpointer rspamd_lua_check_class (lua_State *L, gint index, const gchar *name); lua_State *rspamd_lua_init (bool wipe_mem); void rspamd_lua_start_gc (struct rspamd_config *cfg); + /** * Sets field in a global variable * @param L @@ -178,7 +182,8 @@ void rspamd_lua_start_gc (struct rspamd_config *cfg); */ void rspamd_plugins_table_push_elt (lua_State *L, const gchar *field_name, - const gchar *new_elt); + const gchar *new_elt); + /** * Load and initialize lua plugins */ @@ -188,7 +193,8 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load); /** * Initialize new locked lua_State structure */ -struct lua_locked_state * rspamd_init_lua_locked (struct rspamd_config *cfg); +struct lua_locked_state *rspamd_init_lua_locked (struct rspamd_config *cfg); + /** * Free locked state structure */ @@ -207,11 +213,11 @@ void rspamd_lua_task_push (lua_State *L, struct rspamd_task *task); /** * Return lua ip structure at the specified address */ -struct rspamd_lua_ip * lua_check_ip (lua_State * L, gint pos); +struct rspamd_lua_ip *lua_check_ip (lua_State *L, gint pos); -struct rspamd_lua_text * lua_check_text (lua_State * L, gint pos); +struct rspamd_lua_text *lua_check_text (lua_State *L, gint pos); -struct rspamd_lua_regexp *lua_check_regexp (lua_State * L, gint pos); +struct rspamd_lua_regexp *lua_check_regexp (lua_State *L, gint pos); enum rspamd_lua_task_header_type { RSPAMD_TASK_HEADER_PUSH_SIMPLE = 0, @@ -223,6 +229,7 @@ enum rspamd_lua_task_header_type { gint rspamd_lua_push_header (lua_State *L, struct rspamd_mime_header *h, enum rspamd_lua_task_header_type how); + /** * Push specific header to lua */ @@ -233,10 +240,11 @@ gint rspamd_lua_push_header_array (lua_State *L, /** * Check for task at the specified position */ -struct rspamd_task *lua_check_task (lua_State * L, gint pos); -struct rspamd_task *lua_check_task_maybe (lua_State * L, gint pos); +struct rspamd_task *lua_check_task (lua_State *L, gint pos); + +struct rspamd_task *lua_check_task_maybe (lua_State *L, gint pos); -struct rspamd_lua_map *lua_check_map (lua_State * L, gint pos); +struct rspamd_lua_map *lua_check_map (lua_State *L, gint pos); /** * Push ip address from a string (nil is pushed if a string cannot be converted) @@ -257,74 +265,114 @@ int rspamd_lua_typerror (lua_State *L, int narg, const char *tname); void rspamd_lua_add_preload (lua_State *L, const gchar *name, lua_CFunction func); void luaopen_task (lua_State *L); + void luaopen_config (lua_State *L); + void luaopen_map (lua_State *L); -void luaopen_trie (lua_State * L); + +void luaopen_trie (lua_State *L); + void luaopen_textpart (lua_State *L); + void luaopen_mimepart (lua_State *L); + void luaopen_image (lua_State *L); + void luaopen_url (lua_State *L); + void luaopen_classifier (lua_State *L); -void luaopen_statfile (lua_State * L); + +void luaopen_statfile (lua_State *L); + void luaopen_regexp (lua_State *L); + void luaopen_cdb (lua_State *L); -void luaopen_xmlrpc (lua_State * L); -void luaopen_http (lua_State * L); -void luaopen_redis (lua_State * L); -void luaopen_upstream (lua_State * L); -void luaopen_mempool (lua_State * L); -void luaopen_dns_resolver (lua_State * L); -void luaopen_rsa (lua_State * L); -void luaopen_ip (lua_State * L); -void luaopen_expression (lua_State * L); -void luaopen_logger (lua_State * L); + +void luaopen_xmlrpc (lua_State *L); + +void luaopen_http (lua_State *L); + +void luaopen_redis (lua_State *L); + +void luaopen_upstream (lua_State *L); + +void luaopen_mempool (lua_State *L); + +void luaopen_dns_resolver (lua_State *L); + +void luaopen_rsa (lua_State *L); + +void luaopen_ip (lua_State *L); + +void luaopen_expression (lua_State *L); + +void luaopen_logger (lua_State *L); + void luaopen_text (lua_State *L); -void luaopen_util (lua_State * L); -void luaopen_tcp (lua_State * L); -void luaopen_html (lua_State * L); + +void luaopen_util (lua_State *L); + +void luaopen_tcp (lua_State *L); + +void luaopen_html (lua_State *L); + void luaopen_sqlite3 (lua_State *L); + void luaopen_cryptobox (lua_State *L); + void luaopen_dns (lua_State *L); -void luaopen_udp (lua_State * L); -void luaopen_worker (lua_State * L); -void luaopen_kann (lua_State * L); + +void luaopen_udp (lua_State *L); + +void luaopen_worker (lua_State *L); + +void luaopen_kann (lua_State *L); void rspamd_lua_dostring (const gchar *line); double rspamd_lua_normalize (struct rspamd_config *cfg, - long double score, - void *params); + long double score, + void *params); /* Config file functions */ void rspamd_lua_post_load_config (struct rspamd_config *cfg); + gboolean rspamd_lua_handle_param (struct rspamd_task *task, - gchar *mname, - gchar *optname, - enum lua_var_type expected_type, - gpointer *res); + gchar *mname, + gchar *optname, + enum lua_var_type expected_type, + gpointer *res); + gboolean rspamd_lua_check_condition (struct rspamd_config *cfg, - const gchar *condition); + const gchar *condition); + void rspamd_lua_dumpstack (lua_State *L); /* Set lua path according to the configuration */ void rspamd_lua_set_path (lua_State *L, const ucl_object_t *cfg_obj, - GHashTable *vars); + GHashTable *vars); /* Set some lua globals */ gboolean rspamd_lua_set_env (lua_State *L, GHashTable *vars, char **lua_env, - GError **err); + GError **err); + void rspamd_lua_set_globals (struct rspamd_config *cfg, lua_State *L); -struct memory_pool_s * rspamd_lua_check_mempool (lua_State * L, gint pos); -struct rspamd_config * lua_check_config (lua_State * L, gint pos); -struct rspamd_async_session* lua_check_session (lua_State * L, gint pos); -struct ev_loop* lua_check_ev_base (lua_State * L, gint pos); -struct rspamd_dns_resolver * lua_check_dns_resolver (lua_State * L, gint pos); +struct memory_pool_s *rspamd_lua_check_mempool (lua_State *L, gint pos); + +struct rspamd_config *lua_check_config (lua_State *L, gint pos); + +struct rspamd_async_session *lua_check_session (lua_State *L, gint pos); + +struct ev_loop *lua_check_ev_base (lua_State *L, gint pos); + +struct rspamd_dns_resolver *lua_check_dns_resolver (lua_State *L, gint pos); enum rspamd_lua_parse_arguments_flags { RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT = 0, RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING, }; + /** * Extract an arguments from lua table according to format string. Supported arguments are: * [*]key=S|I|N|B|V|U{a-z};[key=...] @@ -419,7 +467,7 @@ void *rspamd_lua_check_udata_maybe (lua_State *L, gint pos, const gchar *classna * @param task */ void lua_call_finish_script (struct rspamd_config_cfg_lua_script *sc, - struct rspamd_task *task); + struct rspamd_task *task); /** * Run post-load operations @@ -428,9 +476,10 @@ void lua_call_finish_script (struct rspamd_config_cfg_lua_script *sc, * @param ev_base */ void rspamd_lua_run_postloads (lua_State *L, struct rspamd_config *cfg, - struct ev_loop *ev_base, struct rspamd_worker *w); + struct ev_loop *ev_base, struct rspamd_worker *w); void rspamd_lua_run_config_post_init (lua_State *L, struct rspamd_config *cfg); + void rspamd_lua_run_config_unload (lua_State *L, struct rspamd_config *cfg); /** @@ -440,7 +489,7 @@ void rspamd_lua_run_config_unload (lua_State *L, struct rspamd_config *cfg); * @param ref */ void rspamd_lua_add_ref_dtor (lua_State *L, rspamd_mempool_t *pool, - gint ref); + gint ref); /** * Tries to load some module using `require` and get some method from it @@ -450,7 +499,7 @@ void rspamd_lua_add_ref_dtor (lua_State *L, rspamd_mempool_t *pool, * @return TRUE if function exists in that module, the function is pushed in stack, otherwise stack is unchanged and FALSE is returned */ gboolean rspamd_lua_require_function (lua_State *L, const gchar *modname, - const gchar *funcname); + const gchar *funcname); /** * Tries to load redis server definition from ucl object specified @@ -460,9 +509,10 @@ gboolean rspamd_lua_require_function (lua_State *L, const gchar *modname, * @return */ gboolean rspamd_lua_try_load_redis (lua_State *L, const ucl_object_t *obj, - struct rspamd_config *cfg, gint *ref_id); + struct rspamd_config *cfg, gint *ref_id); struct rspamd_stat_token_s; + /** * Pushes a single word into Lua * @param L @@ -477,6 +527,7 @@ enum rspamd_lua_words_type { RSPAMD_LUA_WORDS_FULL, RSPAMD_LUA_WORDS_MAX }; + /** * Pushes words (rspamd_stat_token_t) to Lua * @param L @@ -484,7 +535,7 @@ enum rspamd_lua_words_type { * @param how */ gint rspamd_lua_push_words (lua_State *L, GArray *words, - enum rspamd_lua_words_type how); + enum rspamd_lua_words_type how); /* Paths defs */ #define RSPAMD_CONFDIR_INDEX "CONFDIR" @@ -516,5 +567,8 @@ extern ucl_object_t *lua_traces; #define LUA_TRACE_POINT do {} while(0) #endif -#endif /* WITH_LUA */ +#ifdef __cplusplus +} +#endif + #endif /* RSPAMD_LUA_H */ diff --git a/src/lua/lua_map.h b/src/lua/lua_map.h index a44bd12e9..7b18df7a5 100644 --- a/src/lua/lua_map.h +++ b/src/lua/lua_map.h @@ -18,6 +18,10 @@ #include "lua_common.h" +#ifdef __cplusplus +extern "C" { +#endif + LUA_PUBLIC_FUNCTION_DEF (config, add_radix_map); LUA_PUBLIC_FUNCTION_DEF (config, radix_from_config); LUA_PUBLIC_FUNCTION_DEF (config, radix_from_ucl); @@ -27,4 +31,8 @@ LUA_PUBLIC_FUNCTION_DEF (config, add_kv_map); LUA_PUBLIC_FUNCTION_DEF (config, add_map); LUA_PUBLIC_FUNCTION_DEF (config, get_maps); +#ifdef __cplusplus +} +#endif + #endif /* SRC_LUA_LUA_MAP_H_ */ diff --git a/src/lua/lua_thread_pool.h b/src/lua/lua_thread_pool.h index d44eb0d54..be954271d 100644 --- a/src/lua/lua_thread_pool.h +++ b/src/lua/lua_thread_pool.h @@ -3,10 +3,15 @@ #include <lua.h> +#ifdef __cplusplus +extern "C" { +#endif + struct thread_entry; struct lua_thread_pool; typedef void (*lua_thread_finish_t) (struct thread_entry *thread, int ret); + typedef void (*lua_thread_error_t) (struct thread_entry *thread, int ret, const char *msg); struct thread_entry { @@ -37,7 +42,7 @@ struct lua_callback_state { * @return */ struct lua_thread_pool * -lua_thread_pool_new (lua_State * L); +lua_thread_pool_new (lua_State *L); /** * Destroys the pool @@ -80,8 +85,9 @@ void lua_thread_pool_return_full (struct lua_thread_pool *pool, struct thread_entry *thread_entry, const gchar *loc); + #define lua_thread_pool_return(pool, thread_entry) \ - lua_thread_pool_return_full (pool, thread_entry, G_STRLOC) + lua_thread_pool_return_full (pool, thread_entry, G_STRLOC) /** * Currently running thread. Typically needed in yielding point - to fill-up continuation. @@ -92,8 +98,10 @@ lua_thread_pool_return_full (struct lua_thread_pool *pool, struct thread_entry * lua_thread_pool_get_running_entry_full (struct lua_thread_pool *pool, const gchar *loc); + #define lua_thread_pool_get_running_entry(pool) \ - lua_thread_pool_get_running_entry_full (pool, G_STRLOC) + lua_thread_pool_get_running_entry_full (pool, G_STRLOC) + /** * Updates currently running thread * @@ -104,8 +112,10 @@ void lua_thread_pool_set_running_entry_full (struct lua_thread_pool *pool, struct thread_entry *thread_entry, const gchar *loc); + #define lua_thread_pool_set_running_entry(pool, thread_entry) \ - lua_thread_pool_set_running_entry_full (pool, thread_entry, G_STRLOC) + lua_thread_pool_set_running_entry_full (pool, thread_entry, G_STRLOC) + /** * Prevents yielded thread to be used for callback execution. lua_thread_pool_restore_callback() should be called afterwards. * @@ -114,9 +124,11 @@ lua_thread_pool_set_running_entry_full (struct lua_thread_pool *pool, */ void lua_thread_pool_prepare_callback_full (struct lua_thread_pool *pool, - struct lua_callback_state *cbs, const gchar *loc); + struct lua_callback_state *cbs, const gchar *loc); + #define lua_thread_pool_prepare_callback(pool, cbs) \ - lua_thread_pool_prepare_callback_full (pool, cbs, G_STRLOC) + lua_thread_pool_prepare_callback_full (pool, cbs, G_STRLOC) + /** * Restores state after lua_thread_pool_prepare_callback () usage * @@ -124,9 +136,10 @@ lua_thread_pool_prepare_callback_full (struct lua_thread_pool *pool, */ void lua_thread_pool_restore_callback_full (struct lua_callback_state *cbs, - const gchar *loc); + const gchar *loc); + #define lua_thread_pool_restore_callback(cbs) \ - lua_thread_pool_restore_callback_full (cbs, G_STRLOC) + lua_thread_pool_restore_callback_full (cbs, G_STRLOC) /** * Acts like lua_call but the tread is able to suspend execution. @@ -139,8 +152,9 @@ void lua_thread_call_full (struct thread_entry *thread_entry, int narg, const gchar *loc); + #define lua_thread_call(thread_entry, narg) \ - lua_thread_call_full (thread_entry, narg, G_STRLOC) + lua_thread_call_full (thread_entry, narg, G_STRLOC) /** * Yields thread. should be only called in return statement @@ -150,9 +164,10 @@ lua_thread_call_full (struct thread_entry *thread_entry, */ int lua_thread_yield_full (struct thread_entry *thread_entry, int nresults, - const gchar *loc); + const gchar *loc); + #define lua_thread_yield(thread_entry, narg) \ - lua_thread_yield_full (thread_entry, narg, G_STRLOC) + lua_thread_yield_full (thread_entry, narg, G_STRLOC) /** * Resumes suspended by lua_yield_thread () thread @@ -164,8 +179,13 @@ void lua_thread_resume_full (struct thread_entry *thread_entry, int narg, const gchar *loc); + #define lua_thread_resume(thread_entry, narg) \ - lua_thread_resume_full (thread_entry, narg, G_STRLOC) + lua_thread_resume_full (thread_entry, narg, G_STRLOC) + +#ifdef __cplusplus +} +#endif #endif /* LUA_THREAD_POOL_H_ */ |