#ifdef HAVE_SYS_SENDFILE_H
#include <sys/sendfile.h>
#endif
+#include "utlist.h"
#define G_DISPATCHER_ERROR dispatcher_error_quark ()
#define debug_ip(...) rspamd_conditional_debug (rspamd_main->logger, \
#include "upstream.h"
#include "symbols_cache.h"
#include "cfg_rcl.h"
-#include "utlist.h"
#include "ucl.h"
#define DEFAULT_BIND_PORT 11333
struct rspamd_worker_bind_conf *next;
};
-struct rspamd_worker_param_parser {
- rspamd_rcl_handler_t handler; /**< handler function */
- struct rspamd_rcl_struct_parser parser; /**< parser attributes */
- const gchar *name; /**< parameter's name */
- UT_hash_handle hh; /**< hash by name */
-};
-
-struct rspamd_worker_cfg_parser {
- struct rspamd_worker_param_parser *parsers; /**< parsers hash */
- gint type; /**< workers quark */
- gboolean (*def_obj_parser)(const ucl_object_t *obj, gpointer ud); /**< default object parser */
- gpointer def_ud;
- UT_hash_handle hh; /**< hash by type */
-};
-
/**
* Config params for rspamd worker
*/
gboolean rspamd_config_parse_ip_list (const gchar *ip_list,
radix_tree_t **tree);
+void rspamd_ucl_add_conf_macros (struct ucl_parser *parser,
+ struct rspamd_config *cfg);
+
+void rspamd_ucl_add_conf_variables (struct ucl_parser *parser);
+
#endif /* ifdef CFG_FILE_H */
/*
* vi:ts=4
#include "cfg_rcl.h"
#include "main.h"
+#include "uthash_strcase.h"
+#include "utlist.h"
#include "cfg_file.h"
#include "lua/lua_common.h"
#include "expressions.h"
#include "classifiers/classifiers.h"
#include "tokenizers/tokenizers.h"
+
+struct rspamd_rcl_default_handler_data {
+ struct rspamd_rcl_struct_parser pd;
+ const gchar *key;
+ rspamd_rcl_handler_t handler;
+ UT_hash_handle hh;
+};
+
+struct rspamd_rcl_section {
+ const gchar *name; /**< name of section */
+ rspamd_rcl_handler_t handler; /**< handler of section attributes */
+ enum ucl_type type; /**< type of attribute */
+ gboolean required; /**< whether this param is required */
+ gboolean strict_type; /**< whether we need strict type */
+ UT_hash_handle hh; /** hash handle */
+ struct rspamd_rcl_section *subsections; /**< hash table of subsections */
+ struct rspamd_rcl_default_handler_data *default_parser; /**< generic parsing fields */
+ rspamd_rcl_section_fin_t fin; /** called at the end of section parsing */
+ gpointer fin_ud;
+};
+
+struct rspamd_worker_param_parser {
+ rspamd_rcl_handler_t handler; /**< handler function */
+ struct rspamd_rcl_struct_parser parser; /**< parser attributes */
+ const gchar *name; /**< parameter's name */
+ UT_hash_handle hh; /**< hash by name */
+};
+
+struct rspamd_worker_cfg_parser {
+ struct rspamd_worker_param_parser *parsers; /**< parsers hash */
+ gint type; /**< workers quark */
+ gboolean (*def_obj_parser)(const ucl_object_t *obj, gpointer ud); /**< default object parser */
+ gpointer def_ud;
+ UT_hash_handle hh; /**< hash by type */
+};
+
/*
* Common section handlers
*/
nparser->def_obj_parser = func;
nparser->def_ud = ud;
}
+
+gboolean
+rspamd_config_read (struct rspamd_config *cfg, const gchar *filename,
+ const gchar *convert_to, rspamd_rcl_section_fin_t logger_fin,
+ gpointer logger_ud)
+{
+ struct stat st;
+ gint fd;
+ gchar *data;
+ GError *err = NULL;
+ struct rspamd_rcl_section *top, *logger;
+ gboolean res;
+ struct ucl_parser *parser;
+
+ if (stat (filename, &st) == -1) {
+ msg_err ("cannot stat %s: %s", filename, strerror (errno));
+ return FALSE;
+ }
+ if ((fd = open (filename, O_RDONLY)) == -1) {
+ msg_err ("cannot open %s: %s", filename, strerror (errno));
+ return FALSE;
+
+ }
+ /* Now mmap this file to simplify reading process */
+ if ((data =
+ mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
+ msg_err ("cannot mmap %s: %s", filename, strerror (errno));
+ close (fd);
+ return FALSE;
+ }
+ close (fd);
+
+ parser = ucl_parser_new (UCL_PARSER_KEY_LOWERCASE);
+ rspamd_ucl_add_conf_variables (parser);
+ rspamd_ucl_add_conf_macros (parser, cfg);
+ if (!ucl_parser_add_chunk (parser, data, st.st_size)) {
+ msg_err ("ucl parser error: %s", ucl_parser_get_error (parser));
+ ucl_parser_free (parser);
+ munmap (data, st.st_size);
+ return FALSE;
+ }
+ munmap (data, st.st_size);
+ cfg->rcl_obj = ucl_parser_get_object (parser);
+ ucl_parser_free (parser);
+ res = TRUE;
+
+ if (!res) {
+ return FALSE;
+ }
+
+ top = rspamd_rcl_config_init ();
+ err = NULL;
+
+ HASH_FIND_STR (top, "logging", logger);
+ if (logger != NULL) {
+ logger->fin = logger_fin;
+ logger->fin_ud = logger_ud;
+ }
+
+ if (!rspamd_read_rcl_config (top, cfg, cfg->rcl_obj, &err)) {
+ msg_err ("rcl parse error: %s", err->message);
+ return FALSE;
+ }
+
+ return TRUE;
+}
#define CFG_RCL_H_
#include "config.h"
-#include "ucl/include/ucl.h"
-#include "uthash.h"
+#include "ucl.h"
#define CFG_RCL_ERROR cfg_rcl_error_quark ()
static inline GQuark
struct rspamd_rcl_section;
struct rspamd_config;
+struct rspamd_rcl_default_handler_data;
struct rspamd_rcl_struct_parser {
gpointer user_struct;
typedef void (*rspamd_rcl_section_fin_t)(struct rspamd_config *cfg,
gpointer ud);
-struct rspamd_rcl_default_handler_data {
- struct rspamd_rcl_struct_parser pd;
- const gchar *key;
- rspamd_rcl_handler_t handler;
- UT_hash_handle hh;
-};
-struct rspamd_rcl_section {
- const gchar *name; /**< name of section */
- rspamd_rcl_handler_t handler; /**< handler of section attributes */
- enum ucl_type type; /**< type of attribute */
- gboolean required; /**< whether this param is required */
- gboolean strict_type; /**< whether we need strict type */
- UT_hash_handle hh; /** hash handle */
- struct rspamd_rcl_section *subsections; /**< hash table of subsections */
- struct rspamd_rcl_default_handler_data *default_parser; /**< generic parsing fields */
- rspamd_rcl_section_fin_t fin; /** called at the end of section parsing */
- gpointer fin_ud;
-};
/**
* Init common sections known to rspamd
#include "cfg_file.h"
#include "main.h"
+#include "uthash_strcase.h"
#include "filter.h"
#include "classifiers/classifiers.h"
#include "lua/lua_common.h"
#include "kvstorage_config.h"
#include "map.h"
#include "dynamic_cfg.h"
-#include "xxhash.h"
+#include "utlist.h"
#define DEFAULT_SCORE 10.0
#define RSPAMD_PREFIX_MACRO "PREFIX"
#define RSPAMD_VERSION_MACRO "VERSION"
-static void
+void
rspamd_ucl_add_conf_variables (struct ucl_parser *parser)
{
ucl_parser_register_variable (parser,
ucl_parser_register_variable (parser, RSPAMD_VERSION_MACRO, RVERSION);
}
-static void
+void
rspamd_ucl_add_conf_macros (struct ucl_parser *parser,
struct rspamd_config *cfg)
{
cfg);
}
-gboolean
-rspamd_config_read (struct rspamd_config *cfg, const gchar *filename,
- const gchar *convert_to, rspamd_rcl_section_fin_t logger_fin,
- gpointer logger_ud)
-{
- struct stat st;
- gint fd;
- gchar *data;
- GError *err = NULL;
- struct rspamd_rcl_section *top, *logger;
- gboolean res;
- struct ucl_parser *parser;
-
- if (stat (filename, &st) == -1) {
- msg_err ("cannot stat %s: %s", filename, strerror (errno));
- return FALSE;
- }
- if ((fd = open (filename, O_RDONLY)) == -1) {
- msg_err ("cannot open %s: %s", filename, strerror (errno));
- return FALSE;
-
- }
- /* Now mmap this file to simplify reading process */
- if ((data =
- mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
- msg_err ("cannot mmap %s: %s", filename, strerror (errno));
- close (fd);
- return FALSE;
- }
- close (fd);
-
- parser = ucl_parser_new (0);
- rspamd_ucl_add_conf_variables (parser);
- rspamd_ucl_add_conf_macros (parser, cfg);
- if (!ucl_parser_add_chunk (parser, data, st.st_size)) {
- msg_err ("ucl parser error: %s", ucl_parser_get_error (parser));
- ucl_parser_free (parser);
- munmap (data, st.st_size);
- return FALSE;
- }
- munmap (data, st.st_size);
- cfg->rcl_obj = ucl_parser_get_object (parser);
- ucl_parser_free (parser);
- res = TRUE;
-
- if (!res) {
- return FALSE;
- }
-
- top = rspamd_rcl_config_init ();
- err = NULL;
-
- HASH_FIND_STR (top, "logging", logger);
- if (logger != NULL) {
- logger->fin = logger_fin;
- logger->fin_ud = logger_ud;
- }
-
- if (!rspamd_read_rcl_config (top, cfg, cfg->rcl_obj, &err)) {
- msg_err ("rcl parse error: %s", err->message);
- return FALSE;
- }
-
- return TRUE;
-}
-
static void
symbols_classifiers_callback (gpointer key, gpointer value, gpointer ud)
{
#include "message.h"
#include "dkim.h"
#include "dns.h"
+#include "utlist.h"
/* Parser of dkim params */
typedef gboolean (*dkim_parse_param_f) (rspamd_dkim_context_t * ctx,
#include "util.h"
#include "cfg_file.h"
#include "message.h"
+#include "utlist.h"
/* Max line size */
#define OUTBUFSIZ BUFSIZ
#include "main.h"
#include "message.h"
#include "filter.h"
+#include "utlist.h"
#define SPF_VER1_STR "v=spf1"
#define SPF_VER2_STR "spf2."
#include "config.h"
#include "hash.h"
+#define HASH_CASELESS
#include "uthash_strcase.h"
#include "utlist.h"
}
res = rspamd_lru_create_node (hash, key, value, now, ttl);
- HASH_ADD (hh, hash->elements, key, strlen (key), res);
+ HASH_ADD_KEYPTR (hh, hash->elements, key, strlen (key), res);
}
void
#include "xxhash.h"
+
/* Utils for uthash tuning */
+#ifndef HASH_CASELESS
#define HASH_FUNCTION(key,keylen,num_bkts,hashv,bkt) do {\
hashv = XXH32(key, keylen, 0); \
bkt = (hashv) & (num_bkts-1); \
} while (0)
+#define HASH_KEYCMP(a,b,len) memcmp(a,b,len)
+#else
+#define HASH_FUNCTION(key,keylen,num_bkts,hashv,bkt) do {\
+ void *xxh = XXH32_init(0xdead); \
+ unsigned char *p = (unsigned char *)key, t; \
+ for (unsigned int i = 0; i < keylen; i ++) { \
+ t = g_ascii_tolower(p[i]); \
+ XXH32_update(xxh, &t, 1); \
+ } \
+ hashv = XXH32_digest(xxh); \
+ bkt = (hashv) & (num_bkts-1); \
+} while (0)
#define HASH_KEYCMP(a,b,len) strncasecmp(a,b,len)
+#endif
#include "uthash.h"
#include "lua_common.h"
#include "dns.h"
+#include "utlist.h"
/* Public prototypes */
struct rspamd_dns_resolver * lua_check_dns_resolver (lua_State * L);
#include "buffer.h"
#include "dns.h"
#include "http.h"
+#include "utlist.h"
#define MAX_HEADERS_SIZE 8192
#include "lua/lua_common.h"
#include "ottery.h"
#include "xxhash.h"
+#include "utlist.h"
#ifdef HAVE_OPENSSL
#include <openssl/rand.h>
#include <openssl/err.h>
#include "protocol.h"
#include "filter.h"
#include "buffer.h"
-#include "hash.h"
#include "events.h"
#include "util.h"
#include "logger.h"
rspamd_mempool_t *server_pool; /**< server's memory pool */
statfile_pool_t *statfile_pool; /**< shared statfiles pool */
GHashTable *workers; /**< workers pool indexed by pid */
- rspamd_hash_t *counters; /**< symbol cache counters */
rspamd_logger_t *logger;
uid_t workers_uid; /**< worker's uid running to */
gid_t workers_gid; /**< worker's gid running to */
struct roll_history *history; /**< rolling history */
};
-struct counter_data {
- guint64 value;
- gint number;
-};
-
/**
* Structure to point exception in text from processing
*/
dkim_module_ctx->symbol_allow,
1);
- dkim_module_ctx->dkim_hash = rspamd_lru_hash_new (rspamd_strcase_hash,
- rspamd_strcase_equal,
+ dkim_module_ctx->dkim_hash = rspamd_lru_hash_new (
cache_size,
cache_expire,
g_free,
#include "map.h"
#include "images.h"
#include "fuzzy_storage.h"
+#include "utlist.h"
#define DEFAULT_SYMBOL "R_FUZZY_HASH"
#define DEFAULT_UPSTREAM_ERROR_TIME 10
register_virtual_symbol (&cfg->cache, spf_module_ctx->symbol_softfail, 1);
register_virtual_symbol (&cfg->cache, spf_module_ctx->symbol_allow, 1);
- spf_module_ctx->spf_hash = rspamd_lru_hash_new (rspamd_strcase_hash,
- rspamd_strcase_equal,
+ spf_module_ctx->spf_hash = rspamd_lru_hash_new (
cache_size,
cache_expire,
g_free,
#include "map.h"
#include "dns.h"
#include "hash.h"
+#include "utlist.h"
#include "surbl.h"
#include "dns.h"
#include "upstream.h"
#include "proxy.h"
+#include "utlist.h"
/*
* SMTP proxy is a simple smtp proxy worker for dns resolving and
-Subproject commit 3e1ff238ab86fdb951b2664c25563414a84ce0c9
+Subproject commit 006dd46060d6aa44191a3e404b975ba93bfb9b99