aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-01-27 12:13:10 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-01-27 12:18:41 +0000
commit49647df07c2dad4ae1560f9329cbbb0684c51127 (patch)
tree279da3790e519a8b248fb3121e0454327c07cc27
parent29d5197458ea29a5bc75e171f007c4ab889f0299 (diff)
downloadrspamd-49647df07c2dad4ae1560f9329cbbb0684c51127.tar.gz
rspamd-49647df07c2dad4ae1560f9329cbbb0684c51127.zip
[Minor] Save resolver in config structure and allow to get it from Lua
-rw-r--r--CMakeLists.txt8
-rw-r--r--src/libserver/cfg_file.h2
-rw-r--r--src/libserver/dns.c4
-rw-r--r--src/lua/lua_config.c28
4 files changed, 37 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 887bc93f5..af5ed5d98 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -662,14 +662,12 @@ IF(ENABLE_JEMALLOC MATCHES "ON")
ROOT ${JEMALLOC_ROOT_DIR} MODULES jemalloc)
SET(WITH_JEMALLOC "1")
ENDIF()
+ProcessPackage(GTHREAD2 LIBRARY ghtread-2.0 INCLUDE glib.h
+ INCLUDE_SUFFIXES include/glib include/glib-2.0
+ ROOT ${GLIB_ROOT_DIR} MODULES gthread-2.0>=2.28)
ProcessPackage(GLIB2 LIBRARY glib-2.0 INCLUDE glib.h
INCLUDE_SUFFIXES include/glib include/glib-2.0
ROOT ${GLIB_ROOT_DIR} MODULES glib-2.0>=2.28)
-IF(GLIB_ROOT_DIR)
- LIST(APPEND RSPAMD_REQUIRED_LIBRARIES "-lpthread")
- LIST(APPEND RSPAMD_REQUIRED_LIBRARIES "-lffi")
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
-ENDIF()
IF(ENABLE_PCRE2 MATCHES "ON")
ProcessPackage(PCRE LIBRARY pcre2 INCLUDE pcre2.h INCLUDE_SUFFIXES include/pcre2
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index 89d13a1f2..5b0b87f8b 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -32,6 +32,7 @@ struct module_s;
struct worker_s;
struct rspamd_external_libs_ctx;
struct rspamd_cryptobox_pubkey;
+struct rspamd_dns_resolver;
enum { VAL_UNDEF=0, VAL_TRUE, VAL_FALSE };
@@ -399,6 +400,7 @@ struct rspamd_config {
gdouble upstream_error_time; /**< rate of upstream errors */
gdouble upstream_revive_time; /**< revive timeout for upstreams */
struct upstream_ctx *ups_ctx; /**< upstream context */
+ struct rspamd_dns_resolver *dns_resolver; /**< dns resolver if loaded */
guint min_word_len; /**< minimum length of the word to be considered */
guint max_word_len; /**< maximum length of the word to be considered */
diff --git a/src/libserver/dns.c b/src/libserver/dns.c
index 5d662d835..e1ab754db 100644
--- a/src/libserver/dns.c
+++ b/src/libserver/dns.c
@@ -287,6 +287,10 @@ dns_resolver_init (rspamd_logger_t *logger,
rdns_resolver_init (dns_resolver->r);
+ if (cfg != NULL) {
+ cfg->dns_resolver = dns_resolver;
+ }
+
return dns_resolver;
}
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 06157f44e..e5866d6ca 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -63,6 +63,12 @@ LUA_FUNCTION_DEF (config, get_all_opt);
*/
LUA_FUNCTION_DEF (config, get_mempool);
/***
+ * @method rspamd_config:get_resolver()
+ * Returns DNS resolver.
+ * @return {dns_resolver} opaque DNS resolver pointer if any
+ */
+LUA_FUNCTION_DEF (config, get_resolver);
+/***
* @method rspamd_config:add_radix_map(mapline[, description])
* Creates new dynamic map of IP/mask addresses.
* @param {string} mapline URL for a map
@@ -595,6 +601,7 @@ LUA_FUNCTION_DEF (config, set_peak_cb);
static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, get_module_opt),
LUA_INTERFACE_DEF (config, get_mempool),
+ LUA_INTERFACE_DEF (config, get_resolver),
LUA_INTERFACE_DEF (config, get_all_opt),
LUA_INTERFACE_DEF (config, add_radix_map),
LUA_INTERFACE_DEF (config, radix_from_config),
@@ -712,6 +719,27 @@ lua_config_get_mempool (lua_State * L)
rspamd_lua_setclass (L, "rspamd{mempool}", -1);
*ppool = cfg->cfg_pool;
}
+ else {
+ lua_pushnil (L);
+ }
+ return 1;
+}
+
+static int
+lua_config_get_resolver (lua_State * L)
+{
+ struct rspamd_dns_resolver **pres;
+ struct rspamd_config *cfg = lua_check_config (L, 1);
+
+ if (cfg != NULL && cfg->dns_resolver) {
+ pres = lua_newuserdata (L, sizeof (*pres));
+ rspamd_lua_setclass (L, "rspamd{resolver}", -1);
+ *pres = cfg->dns_resolver;
+ }
+ else {
+ lua_pushnil (L);
+ }
+
return 1;
}