guint64 hits;
guint64 total_hits;
double value;
- struct statfile *st;
+ struct rspamd_statfile_config *st;
stat_file_t *file;
};
}
struct classifier_ctx*
-bayes_init (rspamd_mempool_t *pool, struct classifier_config *cfg)
+bayes_init (rspamd_mempool_t *pool, struct rspamd_classifier_config *cfg)
{
struct classifier_ctx *ctx = rspamd_mempool_alloc (pool, sizeof (struct classifier_ctx));
gint minnodes;
guint64 maxhits = 0, rev;
double final_prob, h, s;
- struct statfile *st;
+ struct rspamd_statfile_config *st;
stat_file_t *file;
GList *cur;
char *sumbuf;
data.total_ham = 0;
data.total_spam = 0;
if (ctx->cfg->opts && (value = g_hash_table_lookup (ctx->cfg->opts, "max_tokens")) != NULL) {
- minnodes = parse_limit (value, -1);
+ minnodes = rspamd_config_parse_limit (value, -1);
data.max_tokens = minnodes;
}
else {
gchar *value;
gint nodes;
gint minnodes;
- struct statfile *st, *sel_st = NULL;
+ struct rspamd_statfile_config *st, *sel_st = NULL;
stat_file_t *to_learn;
GList *cur;
data.processed_tokens = 0;
data.processed_tokens = 0;
if (ctx->cfg->opts && (value = g_hash_table_lookup (ctx->cfg->opts, "max_tokens")) != NULL) {
- minnodes = parse_limit (value, -1);
+ minnodes = rspamd_config_parse_limit (value, -1);
data.max_tokens = minnodes;
}
else {
gchar *value;
gint nodes;
gint minnodes;
- struct statfile *st;
+ struct rspamd_statfile_config *st;
stat_file_t *file;
GList *cur;
gboolean skip_labels;
data.processed_tokens = 0;
if (ctx->cfg->opts && (value = g_hash_table_lookup (ctx->cfg->opts, "max_tokens")) != NULL) {
- minnodes = parse_limit (value, -1);
+ minnodes = rspamd_config_parse_limit (value, -1);
data.max_tokens = minnodes;
}
else {
/* Consider this value as 0 */
#define ALPHA 0.0001
-struct classifier_config;
+struct rspamd_classifier_config;
struct rspamd_task;
struct classifier_ctx {
rspamd_mempool_t *pool;
GHashTable *results;
gboolean debug;
- struct classifier_config *cfg;
+ struct rspamd_classifier_config *cfg;
};
struct classify_weight {
/* Common classifier structure */
struct classifier {
char *name;
- struct classifier_ctx* (*init_func)(rspamd_mempool_t *pool, struct classifier_config *cf);
+ struct classifier_ctx* (*init_func)(rspamd_mempool_t *pool, struct rspamd_classifier_config *cf);
gboolean (*classify_func)(struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct rspamd_task *task, lua_State *L);
gboolean (*learn_func)(struct classifier_ctx* ctx, statfile_pool_t *pool,
const char *symbol, GTree *input, gboolean in_class,
struct classifier* get_classifier (const char *name);
/* Winnow algorithm */
-struct classifier_ctx* winnow_init (rspamd_mempool_t *pool, struct classifier_config *cf);
+struct classifier_ctx* winnow_init (rspamd_mempool_t *pool, struct rspamd_classifier_config *cf);
gboolean winnow_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct rspamd_task *task, lua_State *L);
gboolean winnow_learn (struct classifier_ctx* ctx, statfile_pool_t *pool, const char *symbol, GTree *input,
gboolean in_class, double *sum, double multiplier, GError **err);
GList *winnow_weights (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct rspamd_task *task);
/* Bayes algorithm */
-struct classifier_ctx* bayes_init (rspamd_mempool_t *pool, struct classifier_config *cf);
+struct classifier_ctx* bayes_init (rspamd_mempool_t *pool, struct rspamd_classifier_config *cf);
gboolean bayes_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct rspamd_task *task, lua_State *L);
gboolean bayes_learn (struct classifier_ctx* ctx, statfile_pool_t *pool, const char *symbol, GTree *input,
gboolean in_class, double *sum, double multiplier, GError **err);
}
struct classifier_ctx *
-winnow_init (rspamd_mempool_t * pool, struct classifier_config *cfg)
+winnow_init (rspamd_mempool_t * pool, struct rspamd_classifier_config *cfg)
{
struct classifier_ctx *ctx = rspamd_mempool_alloc (pool, sizeof (struct classifier_ctx));
char *sumbuf, *value;
long double res = 0., max = 0.;
GList *cur;
- struct statfile *st, *sel = NULL;
+ struct rspamd_statfile_config *st, *sel = NULL;
int nodes, minnodes;
g_assert (pool != NULL);
struct winnow_callback_data data;
long double res = 0.;
GList *cur, *resl = NULL;
- struct statfile *st;
+ struct rspamd_statfile_config *st;
struct classify_weight *w;
char *value;
int nodes, minnodes;
};
char *value;
int nodes, minnodes, iterations = 0;
- struct statfile *st, *sel_st = NULL;
+ struct rspamd_statfile_config *st, *sel_st = NULL;
stat_file_t *sel = NULL, *to_learn;
long double res = 0., max = 0., start_value = 0., end_value = 0.;
double learn_threshold = 0.0;
#define CONTROLLER_RRD_STEP 60
/* Init functions */
-gpointer init_controller (struct config_file *cfg);
+gpointer init_controller (struct rspamd_config *cfg);
void start_controller (struct rspamd_worker *worker);
worker_t controller_worker = {
}
static gboolean
-write_whole_statfile (struct controller_session *session, gchar *symbol, struct classifier_config *ccf)
+write_whole_statfile (struct controller_session *session, gchar *symbol, struct rspamd_classifier_config *ccf)
{
stat_file_t *statfile;
- struct statfile *st;
+ struct rspamd_statfile_config *st;
gchar out_buf[BUFSIZ];
guint i;
guint64 rev, ti, len, pos, blocks;
gchar out_buf[BUFSIZ], *arg, *err_str, *symbol;
gint r;
guint64 rev, time;
- struct statfile *st = NULL;
- struct classifier_config *ccf;
+ struct rspamd_statfile_config *st = NULL;
+ struct rspamd_classifier_config *ccf;
GList *cur;
struct rspamd_binlog *binlog;
GByteArray *data = NULL;
guint64 used, total, rev, ham = 0, spam = 0;
time_t ti;
rspamd_mempool_stat_t mem_st;
- struct classifier_config *ccf;
+ struct rspamd_classifier_config *ccf;
stat_file_t *statfile;
- struct statfile *st;
+ struct rspamd_statfile_config *st;
GList *cur_cl, *cur_st;
struct rspamd_stat *stat, stat_copy;
static gboolean
process_dynamic_conf_command (gchar **cmd_args, struct controller_session *session, gboolean is_action)
{
- struct config_file *cfg = session->cfg;
+ struct rspamd_config *cfg = session->cfg;
gchar *arg, *metric, *name, *err_str;
gdouble value;
gboolean res;
gint r = 0, days, hours, minutes;
time_t uptime;
guint32 size = 0;
- struct classifier_config *cl;
+ struct rspamd_classifier_config *cl;
struct rspamd_controller_ctx *ctx = session->worker->ctx;
switch (cmd->type) {
}
return TRUE;
}
- cl = find_classifier_conf (session->cfg, *cmd_args);
+ cl = rspamd_config_find_classifier (session->cfg, *cmd_args);
}
else {
if ((arg = g_hash_table_lookup (session->kwargs, "classifier")) == NULL) {
return TRUE;
}
else {
- cl = find_classifier_conf (session->cfg, arg);
+ cl = rspamd_config_find_classifier (session->cfg, arg);
}
if ((arg = g_hash_table_lookup (session->kwargs, "content-length")) == NULL) {
msg_debug ("no size specified in learn command");
}
return TRUE;
}
- cl = find_classifier_conf (session->cfg, *cmd_args);
+ cl = rspamd_config_find_classifier (session->cfg, *cmd_args);
}
else {
if ((arg = g_hash_table_lookup (session->kwargs, "classifier")) == NULL) {
return TRUE;
}
else {
- cl = find_classifier_conf (session->cfg, arg);
+ cl = rspamd_config_find_classifier (session->cfg, arg);
}
if ((arg = g_hash_table_lookup (session->kwargs, "content-length")) == NULL) {
msg_debug ("no size specified in learn command");
}
gpointer
-init_controller (struct config_file *cfg)
+init_controller (struct rspamd_config *cfg)
{
struct rspamd_controller_ctx *ctx;
GQuark type;
GError *err = NULL;
struct timeval tv;
- ctx->ev_base = prepare_worker (worker, "controller", accept_socket);
+ ctx->ev_base = rspamd_prepare_worker (worker, "controller", accept_socket);
g_mime_init (0);
start_time = time (NULL);
#define INVALID_NODE_TIME (guint64)-1
/* Init functions */
-gpointer init_fuzzy (struct config_file *cfg);
+gpointer init_fuzzy (struct rspamd_config *cfg);
void start_fuzzy (struct rspamd_worker *worker);
worker_t fuzzy_worker = {
tv.tv_usec = 0;
event_del (&worker->sig_ev_usr1);
event_del (&worker->sig_ev_usr2);
- worker_stop_accept (worker);
+ rspamd_worker_stop_accept (worker);
msg_info ("worker's shutdown is pending in %d sec", SOFT_SHUTDOWN_TIME);
rspamd_mutex_lock (ctx->update_mtx);
mods = ctx->max_mods + 1;
}
gpointer
-init_fuzzy (struct config_file *cfg)
+init_fuzzy (struct rspamd_config *cfg)
{
struct rspamd_fuzzy_storage_ctx *ctx;
GQuark type;
GError *err = NULL;
gint i;
- ctx->ev_base = prepare_worker (worker, "controller", accept_fuzzy_socket);
+ ctx->ev_base = rspamd_prepare_worker (worker, "controller", accept_fuzzy_socket);
server_stat = worker->srv->stat;
/* Custom SIGUSR2 handler */
if (ctx->update_map != NULL) {
if (!add_map (worker->srv->cfg, ctx->update_map, "Allow fuzzy updates from specified addresses",
read_radix_list, fin_radix_list, (void **)&ctx->update_ips)) {
- if (!rspamd_parse_ip_list (ctx->update_map, &ctx->update_ips)) {
+ if (!rspamd_config_parse_ip_list (ctx->update_map, &ctx->update_ips)) {
msg_warn ("cannot load or parse ip list from '%s'", ctx->update_map);
}
}
rspamd_strlcpy (kv_parser->current_storage->name, text, text_len + 1);
break;
case KVSTORAGE_STATE_CACHE_MAX_ELTS:
- kv_parser->current_storage->cache.max_elements = parse_limit (text, text_len);
+ kv_parser->current_storage->cache.max_elements = rspamd_config_parse_limit (text, text_len);
break;
case KVSTORAGE_STATE_CACHE_MAX_MEM:
- kv_parser->current_storage->cache.max_memory = parse_limit (text, text_len);
+ kv_parser->current_storage->cache.max_memory = rspamd_config_parse_limit (text, text_len);
break;
case KVSTORAGE_STATE_CACHE_NO_OVERWRITE:
- kv_parser->current_storage->cache.no_overwrite = parse_flag (text);
+ kv_parser->current_storage->cache.no_overwrite = rspamd_config_parse_flag (text);
break;
case KVSTORAGE_STATE_CACHE_TYPE:
if (g_ascii_strncasecmp (text, "hash", MIN (text_len, sizeof ("hash") - 1)) == 0) {
rspamd_strlcpy (kv_parser->current_storage->backend.filename, text, text_len + 1);
break;
case KVSTORAGE_STATE_BACKEND_SYNC_OPS:
- kv_parser->current_storage->backend.sync_ops = parse_limit (text, text_len);
+ kv_parser->current_storage->backend.sync_ops = rspamd_config_parse_limit (text, text_len);
break;
case KVSTORAGE_STATE_BACKEND_DO_FSYNC:
- kv_parser->current_storage->backend.do_fsync = parse_flag (text);
+ kv_parser->current_storage->backend.do_fsync = rspamd_config_parse_flag (text);
break;
case KVSTORAGE_STATE_BACKEND_DO_REF:
- kv_parser->current_storage->backend.do_ref = parse_flag (text);
+ kv_parser->current_storage->backend.do_ref = rspamd_config_parse_flag (text);
break;
case KVSTORAGE_STATE_EXPIRE_TYPE:
if (g_ascii_strncasecmp (text, "lru", MIN (text_len, sizeof ("lru") - 1)) == 0) {
}
void
-process_autolearn (struct statfile *st, struct rspamd_task *task, GTree * tokens, struct classifier *classifier, gchar *filename, struct classifier_ctx *ctx)
+process_autolearn (struct rspamd_statfile_config *st, struct rspamd_task *task, GTree * tokens, struct classifier *classifier, gchar *filename, struct classifier_ctx *ctx)
{
stat_file_t *statfile;
- struct statfile *unused;
+ struct rspamd_statfile_config *unused;
if (check_autolearn (st->autolearn, task)) {
if (tokens) {
{
struct classifiers_cbdata *cbdata = arg;
struct rspamd_task *task;
- struct classifier_config *cl = value;
+ struct rspamd_classifier_config *cl = value;
struct classifier_ctx *ctx;
struct mime_text_part *text_part, *p1, *p2;
- struct statfile *st;
+ struct rspamd_statfile_config *st;
GTree *tokens = NULL;
GList *cur;
f_str_t c;
learn_task (const gchar *statfile, struct rspamd_task *task, GError **err)
{
GList *cur, *ex;
- struct classifier_config *cl;
+ struct rspamd_classifier_config *cl;
struct classifier_ctx *cls_ctx;
gchar *s;
f_str_t c;
GTree *tokens = NULL;
- struct statfile *st;
+ struct rspamd_statfile_config *st;
stat_file_t *stf;
gdouble sum;
struct mime_text_part *part, *p1, *p2;
}
gboolean
-learn_task_spam (struct classifier_config *cl, struct rspamd_task *task, gboolean is_spam, GError **err)
+learn_task_spam (struct rspamd_classifier_config *cl, struct rspamd_task *task, gboolean is_spam, GError **err)
{
GList *cur, *ex;
struct classifier_ctx *cls_ctx;
struct rspamd_task;
struct rspamd_settings;
-struct classifier_config;
+struct rspamd_classifier_config;
typedef double (*metric_cons_func)(struct rspamd_task *task, const gchar *metric_name, const gchar *func_name);
typedef void (*filter_func)(struct rspamd_task *task);
* @param err pointer to GError
* @return true if learn succeed
*/
-gboolean learn_task_spam (struct classifier_config *cl, struct rspamd_task *task, gboolean is_spam, GError **err);
+gboolean learn_task_spam (struct rspamd_classifier_config *cl, struct rspamd_task *task, gboolean is_spam, GError **err);
/*
* Get action from a string
case 'j':
case 'J':
if (g_ascii_strcasecmp (headern, JSON_HEADER) == 0) {
- task->is_json = parse_flag (h->value->str);
+ task->is_json = rspamd_config_parse_flag (h->value->str);
}
else {
debug_task ("wrong header: %s", headern);
(*count) ++;
}
else {
- if (! parse_host_port (pool, p, &cur->addr, &cur->port)) {
+ if (! rspamd_parse_host_port (pool, p, &cur->addr, &cur->port)) {
g_strfreev (strv);
return FALSE;
}
}
gboolean
-maybe_write_binlog (struct classifier_config *ccf, struct statfile *st, stat_file_t *file, GTree *nodes)
+maybe_write_binlog (struct rspamd_classifier_config *ccf, struct rspamd_statfile_config *st, stat_file_t *file, GTree *nodes)
{
struct rspamd_binlog *log;
}
struct rspamd_binlog*
-get_binlog_by_statfile (struct statfile *st)
+get_binlog_by_statfile (struct rspamd_statfile_config *st)
{
struct rspamd_binlog *log;
struct rspamd_index_block *cur_idx;
};
-struct classifier_config;
+struct rspamd_classifier_config;
/*
* Open binlog at specified path with specified rotate params
/*
* Get and open binlog for specified statfile
*/
-struct rspamd_binlog* get_binlog_by_statfile (struct statfile *st);
+struct rspamd_binlog* get_binlog_by_statfile (struct rspamd_statfile_config *st);
/*
* Close binlog
/*
* Conditional write to a binlog for specified statfile
*/
-gboolean maybe_write_binlog (struct classifier_config *ccf, struct statfile *st, stat_file_t *file, GTree *nodes);
+gboolean maybe_write_binlog (struct rspamd_classifier_config *ccf, struct rspamd_statfile_config *st, stat_file_t *file, GTree *nodes);
#endif
/**
* Module option
*/
-struct module_opt {
+struct rspamd_module_opt {
gchar *param; /**< parameter name */
gchar *value; /**< parameter value */
gchar *description; /**< parameter description */
enum lua_var_type lua_type; /**< type of lua variable */
};
-struct module_meta_opt {
- gchar *name; /**< Name of meta option */
- GList *options; /**< List of struct module_opt */
-};
-
/**
* Symbol definition
*/
-struct symbol_def {
+struct rspamd_symbol_def {
gchar *name;
gchar *description;
gdouble *weight_ptr;
/**
* Symbols group
*/
-struct symbols_group {
+struct rspamd_symbols_group {
gchar *name;
GList *symbols;
};
/**
* Statfile section definition
*/
-struct statfile_section {
+struct rspamd_statfile_section {
guint32 code; /**< section's code */
guint64 size; /**< size of section */
double weight; /**< weight coefficient for section */
guint16 master_port;
};
-typedef double (*statfile_normalize_func)(struct config_file *cfg, long double score, void *params);
+typedef double (*statfile_normalize_func)(struct rspamd_config *cfg, long double score, void *params);
/**
* Statfile config definition
*/
-struct statfile {
+struct rspamd_statfile_config {
gchar *symbol; /**< symbol of statfile */
gchar *path; /**< filesystem pattern (with %r or %f) */
gchar *label; /**< label of this statfile */
/**
* Classifier config definition
*/
-struct classifier_config {
+struct rspamd_classifier_config {
GList *statfiles; /**< statfiles list */
GHashTable *labels; /**< statfiles with labels */
gchar *metric; /**< metric of this classifier */
/**
* Config params for rspamd worker
*/
-struct worker_conf {
+struct rspamd_worker_conf {
worker_t *worker; /**< pointer to worker type */
GQuark type; /**< type of worker */
struct rspamd_worker_bind_conf *bind_conf; /**< bind configuration */
/**
* Structure that stores all config data
*/
-struct config_file {
+struct rspamd_config {
gchar *rspamd_user; /**< user to run as */
gchar *rspamd_group; /**< group to run as */
rspamd_mempool_t *cfg_pool; /**< memory pool for config */
* @param priority priority
* @return TRUE if string was parsed
*/
-gboolean parse_host_port_priority (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint16 *port, guint *priority);
+gboolean rspamd_parse_host_port_priority (rspamd_mempool_t *pool,
+ const gchar *str, gchar **addr, guint16 *port, guint *priority);
/**
* Parse host:port line
* @param port port
* @return TRUE if string was parsed
*/
-gboolean parse_host_port (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint16 *port);
+gboolean rspamd_parse_host_port (rspamd_mempool_t *pool, const gchar *str,
+ gchar **addr, guint16 *port);
/**
* Parse host:priority line
* @param priority priority
* @return TRUE if string was parsed
*/
-gboolean parse_host_priority (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint *priority);
+gboolean rspamd_parse_host_priority (rspamd_mempool_t *pool, const gchar *str,
+ gchar **addr, guint *priority);
/**
* Parse bind credits
* @param type type of credits
* @return 1 if line was successfully parsed and 0 in case of error
*/
-gboolean parse_bind_line (struct config_file *cfg, struct worker_conf *cf, const gchar *str);
+gboolean rspamd_parse_bind_line (struct rspamd_config *cfg,
+ struct rspamd_worker_conf *cf, const gchar *str);
/**
* Init default values
* @param cfg config file
*/
-void init_defaults (struct config_file *cfg);
+void rspamd_config_defaults (struct rspamd_config *cfg);
/**
* Free memory used by config structure
* @param cfg config file
*/
-void free_config (struct config_file *cfg);
+void rspamd_config_free (struct rspamd_config *cfg);
/**
* Gets module option with specified name
* @param opt_name name of option to get
* @return module value or NULL if option does not defined
*/
-const ucl_object_t* get_module_opt (struct config_file *cfg, const gchar *module_name,
+const ucl_object_t* rspamd_config_get_module_opt (struct rspamd_config *cfg,
+ const gchar *module_name,
const gchar *opt_name);
/**
* @param limit string representation of limit (eg. 1M)
* @return numeric value of limit
*/
-guint64 parse_limit (const gchar *limit, guint len);
+guint64 rspamd_config_parse_limit (const gchar *limit, guint len);
/**
* Parse flag
* @param str string representation of flag (eg. 'on')
* @return numeric value of flag (0 or 1)
*/
-gchar parse_flag (const gchar *str);
+gchar rspamd_config_parse_flag (const gchar *str);
/**
* Do post load actions for config
* @param cfg config file
*/
-void post_load_config (struct config_file *cfg);
+void rspamd_config_post_load (struct rspamd_config *cfg);
/**
* Calculate checksum for config file
* @param cfg config file
*/
-gboolean get_config_checksum (struct config_file *cfg);
+gboolean rspamd_config_calculate_checksum (struct rspamd_config *cfg);
/**
* Replace all \" with a single " in given string
* @param line input string
*/
-void unescape_quotes (gchar *line);
+void rspamd_config_unescape_quotes (gchar *line);
/*
* Convert comma separated string to a list of strings
*/
-GList* parse_comma_list (rspamd_mempool_t *pool, const gchar *line);
+GList* rspamd_config_parse_comma_list (rspamd_mempool_t *pool,
+ const gchar *line);
/*
* Return a new classifier_config structure, setting default and non-conflicting attributes
*/
-struct classifier_config* check_classifier_conf (struct config_file *cfg, struct classifier_config *c);
+struct rspamd_classifier_config* rspamd_config_new_classifier (struct rspamd_config *cfg,
+ struct rspamd_classifier_config *c);
/*
* Return a new worker_conf structure, setting default and non-conflicting attributes
*/
-struct worker_conf* check_worker_conf (struct config_file *cfg, struct worker_conf *c);
+struct rspamd_worker_conf* rspamd_config_new_worker (struct rspamd_config *cfg,
+ struct rspamd_worker_conf *c);
/*
* Return a new metric structure, setting default and non-conflicting attributes
*/
-struct metric* check_metric_conf (struct config_file *cfg, struct metric *c);
+struct metric* rspamd_config_new_metric (struct rspamd_config *cfg,
+ struct metric *c);
/*
* Return a new statfile structure, setting default and non-conflicting attributes
*/
-struct statfile* check_statfile_conf (struct config_file *cfg, struct statfile *c);
+struct rspamd_statfile_config* rspamd_config_new_statfile (struct rspamd_config *cfg,
+ struct rspamd_statfile_config *c);
/*
* Read XML configuration file
*/
-gboolean read_rspamd_config (struct config_file *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);
/*
* Register symbols of classifiers inside metrics
*/
-void insert_classifier_symbols (struct config_file *cfg);
+void rspamd_config_insert_classify_symbols (struct rspamd_config *cfg);
/*
* Check statfiles inside a classifier
*/
-gboolean check_classifier_statfiles (struct classifier_config *cf);
+gboolean rspamd_config_check_statfiles (struct rspamd_classifier_config *cf);
/*
* Find classifier config by name
*/
-struct classifier_config* find_classifier_conf (struct config_file *cfg, const gchar *name);
+struct rspamd_classifier_config* rspamd_config_find_classifier (
+ struct rspamd_config *cfg,
+ const gchar *name);
/*
* Parse input `ip_list` to radix tree `tree`. Now supports only IPv4 addresses.
*/
-gboolean rspamd_parse_ip_list (const gchar *ip_list, radix_tree_t **tree);
+gboolean rspamd_config_parse_ip_list (const gchar *ip_list,
+ radix_tree_t **tree);
#endif /* ifdef CFG_FILE_H */
/*
* Common section handlers
*/
static gboolean
-rspamd_rcl_logging_handler (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_logging_handler (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
const ucl_object_t *val;
}
static gboolean
-rspamd_rcl_options_handler (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_options_handler (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
const ucl_object_t *val;
static gint
rspamd_symbols_group_find_func (gconstpointer a, gconstpointer b)
{
- const struct symbols_group *gr = a;
+ const struct rspamd_symbols_group *gr = a;
const gchar *uv = b;
return g_ascii_strcasecmp (gr->name, uv);
* @return
*/
static gboolean
-rspamd_rcl_insert_symbol (struct config_file *cfg, struct metric *metric,
+rspamd_rcl_insert_symbol (struct rspamd_config *cfg, struct metric *metric,
const ucl_object_t *obj, gboolean is_legacy, GError **err)
{
const gchar *group = "ungrouped", *description = NULL, *sym_name;
gdouble symbol_score, *score_ptr;
const ucl_object_t *val;
- struct symbols_group *sym_group;
- struct symbol_def *sym_def;
+ struct rspamd_symbols_group *sym_group;
+ struct rspamd_symbol_def *sym_def;
GList *metric_list, *group_list;
/*
return FALSE;
}
- sym_def = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct symbol_def));
+ sym_def = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct rspamd_symbol_def));
score_ptr = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (gdouble));
*score_ptr = symbol_score;
group_list = g_list_find_custom (cfg->symbols_groups, group, rspamd_symbols_group_find_func);
if (group_list == NULL) {
/* Create new group */
- sym_group = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct symbols_group));
+ sym_group = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct rspamd_symbols_group));
sym_group->name = rspamd_mempool_strdup (cfg->cfg_pool, group);
sym_group->symbols = NULL;
cfg->symbols_groups = g_list_prepend (cfg->symbols_groups, sym_group);
}
static gboolean
-rspamd_rcl_metric_handler (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_metric_handler (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
const ucl_object_t *val, *cur;
metric = g_hash_table_lookup (cfg->metrics, metric_name);
if (metric == NULL) {
- metric = check_metric_conf (cfg, metric);
+ metric = rspamd_config_new_metric (cfg, metric);
metric->name = metric_name;
}
else {
}
static gboolean
-rspamd_rcl_worker_handler (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_worker_handler (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
const ucl_object_t *val, *cur;
ucl_object_iter_t it = NULL;
const gchar *worker_type, *worker_bind;
GQuark qtype;
- struct worker_conf *wrk;
+ struct rspamd_worker_conf *wrk;
struct rspamd_worker_cfg_parser *wparser;
struct rspamd_worker_param_parser *whandler;
if (val != NULL && ucl_object_tostring_safe (val, &worker_type)) {
qtype = g_quark_try_string (worker_type);
if (qtype != 0) {
- wrk = check_worker_conf (cfg, NULL);
- wrk->worker = get_worker_by_type (qtype);
+ wrk = rspamd_config_new_worker (cfg, NULL);
+ wrk->worker = rspamd_get_worker_by_type (qtype);
if (wrk->worker == NULL) {
g_set_error (err, CFG_RCL_ERROR, EINVAL, "unknown worker type: %s", worker_type);
return FALSE;
if (!ucl_object_tostring_safe (cur, &worker_bind)) {
continue;
}
- if (!parse_bind_line (cfg, wrk, worker_bind)) {
+ if (!rspamd_parse_bind_line (cfg, wrk, worker_bind)) {
g_set_error (err, CFG_RCL_ERROR, EINVAL, "cannot parse bind line: %s", worker_bind);
return FALSE;
}
}
static void
-rspamd_rcl_set_lua_globals (struct config_file *cfg, lua_State *L)
+rspamd_rcl_set_lua_globals (struct rspamd_config *cfg, lua_State *L)
{
- struct config_file **pcfg;
+ struct rspamd_config **pcfg;
/* First check for global variable 'config' */
lua_getglobal (L, "config");
lua_setglobal (L, "classifiers");
}
- pcfg = lua_newuserdata (L, sizeof (struct config_file *));
+ pcfg = lua_newuserdata (L, sizeof (struct rspamd_config *));
lua_setclass (L, "rspamd{config}", -1);
*pcfg = cfg;
lua_setglobal (L, "rspamd_config");
}
static gboolean
-rspamd_rcl_lua_handler (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_lua_handler (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
const gchar *lua_src = rspamd_mempool_strdup (cfg->cfg_pool, ucl_object_tostring (obj));
}
static gboolean
-rspamd_rcl_add_module_path (struct config_file *cfg, const gchar *path, GError **err)
+rspamd_rcl_add_module_path (struct rspamd_config *cfg, const gchar *path, GError **err)
{
struct stat st;
struct script_module *cur_mod;
}
static gboolean
-rspamd_rcl_modules_handler (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_modules_handler (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
const ucl_object_t *val, *cur;
}
static gboolean
-rspamd_rcl_statfile_handler (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_statfile_handler (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
- struct classifier_config *ccf = ud;
+ struct rspamd_classifier_config *ccf = ud;
const ucl_object_t *val;
- struct statfile *st;
+ struct rspamd_statfile_config *st;
const gchar *data;
gdouble binlog_rotate;
GList *labels;
- st = check_statfile_conf (cfg, NULL);
+ st = rspamd_config_new_statfile (cfg, NULL);
val = ucl_object_find_key (obj, "binlog");
if (val != NULL && ucl_object_tostring_safe (val, &data)) {
}
val = ucl_object_find_key (obj, "binlog_master");
if (val != NULL && ucl_object_tostring_safe (val, &data)) {
- if (!parse_host_port (cfg->cfg_pool, data, &st->binlog->master_addr, &st->binlog->master_port)) {
+ if (!rspamd_parse_host_port (cfg->cfg_pool, data, &st->binlog->master_addr, &st->binlog->master_port)) {
msg_err ("cannot parse master address: %s", data);
return FALSE;
}
}
static gboolean
-rspamd_rcl_classifier_handler (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_classifier_handler (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
const ucl_object_t *val, *cur;
ucl_object_iter_t it = NULL;
const gchar *key, *type;
- struct classifier_config *ccf, *found = NULL;
+ struct rspamd_classifier_config *ccf, *found = NULL;
gboolean res = TRUE;
struct rspamd_rcl_section *stat_section;
GList *cur_cl;
}
if (found == NULL) {
- ccf = check_classifier_conf (cfg, NULL);
+ ccf = rspamd_config_new_classifier (cfg, NULL);
ccf->classifier = get_classifier (type);
}
else {
}
static gboolean
-rspamd_rcl_composite_handler (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_composite_handler (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
const ucl_object_t *val;
* for default handlers
*/
static gboolean
-rspamd_rcl_empty_handler (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_empty_handler (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
return rspamd_rcl_section_parse_defaults (section, cfg, obj, cfg, err);
FALSE, TRUE);
/* Default handlers */
rspamd_rcl_add_default_handler (sub, "log_buffer", rspamd_rcl_parse_struct_integer,
- G_STRUCT_OFFSET (struct config_file, log_buf_size), 0);
+ G_STRUCT_OFFSET (struct rspamd_config, log_buf_size), 0);
rspamd_rcl_add_default_handler (sub, "log_urls", rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct config_file, log_urls), 0);
+ G_STRUCT_OFFSET (struct rspamd_config, log_urls), 0);
rspamd_rcl_add_default_handler (sub, "debug_ip", rspamd_rcl_parse_struct_string,
- G_STRUCT_OFFSET (struct config_file, debug_ip_map), 0);
+ G_STRUCT_OFFSET (struct rspamd_config, debug_ip_map), 0);
rspamd_rcl_add_default_handler (sub, "debug_symbols", rspamd_rcl_parse_struct_string_list,
- G_STRUCT_OFFSET (struct config_file, debug_symbols), 0);
+ G_STRUCT_OFFSET (struct rspamd_config, debug_symbols), 0);
rspamd_rcl_add_default_handler (sub, "log_color", rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct config_file, log_color), 0);
+ G_STRUCT_OFFSET (struct rspamd_config, log_color), 0);
/**
* Options section
*/
sub = rspamd_rcl_add_section (&new, "options", rspamd_rcl_options_handler, UCL_OBJECT,
FALSE, TRUE);
rspamd_rcl_add_default_handler (sub, "cache_file", rspamd_rcl_parse_struct_string,
- G_STRUCT_OFFSET (struct config_file, cache_filename), RSPAMD_CL_FLAG_STRING_PATH);
+ G_STRUCT_OFFSET (struct rspamd_config, cache_filename), RSPAMD_CL_FLAG_STRING_PATH);
rspamd_rcl_add_default_handler (sub, "dns_nameserver", rspamd_rcl_parse_struct_string_list,
- G_STRUCT_OFFSET (struct config_file, nameservers), 0);
+ G_STRUCT_OFFSET (struct rspamd_config, nameservers), 0);
rspamd_rcl_add_default_handler (sub, "dns_timeout", rspamd_rcl_parse_struct_time,
- G_STRUCT_OFFSET (struct config_file, dns_timeout), RSPAMD_CL_FLAG_TIME_FLOAT);
+ G_STRUCT_OFFSET (struct rspamd_config, dns_timeout), RSPAMD_CL_FLAG_TIME_FLOAT);
rspamd_rcl_add_default_handler (sub, "dns_retransmits", rspamd_rcl_parse_struct_integer,
- G_STRUCT_OFFSET (struct config_file, dns_retransmits), RSPAMD_CL_FLAG_INT_32);
+ G_STRUCT_OFFSET (struct rspamd_config, dns_retransmits), RSPAMD_CL_FLAG_INT_32);
rspamd_rcl_add_default_handler (sub, "dns_sockets", rspamd_rcl_parse_struct_integer,
- G_STRUCT_OFFSET (struct config_file, dns_io_per_server), RSPAMD_CL_FLAG_INT_32);
+ G_STRUCT_OFFSET (struct rspamd_config, dns_io_per_server), RSPAMD_CL_FLAG_INT_32);
rspamd_rcl_add_default_handler (sub, "raw_mode", rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct config_file, raw_mode), 0);
+ G_STRUCT_OFFSET (struct rspamd_config, raw_mode), 0);
rspamd_rcl_add_default_handler (sub, "one_shot", rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct config_file, one_shot_mode), 0);
+ G_STRUCT_OFFSET (struct rspamd_config, one_shot_mode), 0);
rspamd_rcl_add_default_handler (sub, "check_attachements", rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct config_file, check_text_attachements), 0);
+ G_STRUCT_OFFSET (struct rspamd_config, check_text_attachements), 0);
rspamd_rcl_add_default_handler (sub, "tempdir", rspamd_rcl_parse_struct_string,
- G_STRUCT_OFFSET (struct config_file, temp_dir), RSPAMD_CL_FLAG_STRING_PATH);
+ G_STRUCT_OFFSET (struct rspamd_config, temp_dir), RSPAMD_CL_FLAG_STRING_PATH);
rspamd_rcl_add_default_handler (sub, "pidfile", rspamd_rcl_parse_struct_string,
- G_STRUCT_OFFSET (struct config_file, pid_file), RSPAMD_CL_FLAG_STRING_PATH);
+ G_STRUCT_OFFSET (struct rspamd_config, pid_file), RSPAMD_CL_FLAG_STRING_PATH);
rspamd_rcl_add_default_handler (sub, "filters", rspamd_rcl_parse_struct_string,
- G_STRUCT_OFFSET (struct config_file, filters_str), 0);
+ G_STRUCT_OFFSET (struct rspamd_config, filters_str), 0);
rspamd_rcl_add_default_handler (sub, "sync_interval", rspamd_rcl_parse_struct_time,
- G_STRUCT_OFFSET (struct config_file, statfile_sync_interval), RSPAMD_CL_FLAG_TIME_INTEGER);
+ G_STRUCT_OFFSET (struct rspamd_config, statfile_sync_interval), RSPAMD_CL_FLAG_TIME_INTEGER);
rspamd_rcl_add_default_handler (sub, "sync_timeout", rspamd_rcl_parse_struct_time,
- G_STRUCT_OFFSET (struct config_file, statfile_sync_timeout), RSPAMD_CL_FLAG_TIME_INTEGER);
+ G_STRUCT_OFFSET (struct rspamd_config, statfile_sync_timeout), RSPAMD_CL_FLAG_TIME_INTEGER);
rspamd_rcl_add_default_handler (sub, "max_diff", rspamd_rcl_parse_struct_integer,
- G_STRUCT_OFFSET (struct config_file, max_diff), RSPAMD_CL_FLAG_INT_SIZE);
+ G_STRUCT_OFFSET (struct rspamd_config, max_diff), RSPAMD_CL_FLAG_INT_SIZE);
rspamd_rcl_add_default_handler (sub, "map_watch_interval", rspamd_rcl_parse_struct_time,
- G_STRUCT_OFFSET (struct config_file, map_timeout), RSPAMD_CL_FLAG_TIME_FLOAT);
+ G_STRUCT_OFFSET (struct rspamd_config, map_timeout), RSPAMD_CL_FLAG_TIME_FLOAT);
rspamd_rcl_add_default_handler (sub, "dynamic_conf", rspamd_rcl_parse_struct_string,
- G_STRUCT_OFFSET (struct config_file, dynamic_conf), 0);
+ G_STRUCT_OFFSET (struct rspamd_config, dynamic_conf), 0);
rspamd_rcl_add_default_handler (sub, "rrd", rspamd_rcl_parse_struct_string,
- G_STRUCT_OFFSET (struct config_file, rrd_file), RSPAMD_CL_FLAG_STRING_PATH);
+ G_STRUCT_OFFSET (struct rspamd_config, rrd_file), RSPAMD_CL_FLAG_STRING_PATH);
rspamd_rcl_add_default_handler (sub, "history_file", rspamd_rcl_parse_struct_string,
- G_STRUCT_OFFSET (struct config_file, history_file), RSPAMD_CL_FLAG_STRING_PATH);
+ G_STRUCT_OFFSET (struct rspamd_config, history_file), RSPAMD_CL_FLAG_STRING_PATH);
rspamd_rcl_add_default_handler (sub, "use_mlock", rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct config_file, mlock_statfile_pool), 0);
+ G_STRUCT_OFFSET (struct rspamd_config, mlock_statfile_pool), 0);
rspamd_rcl_add_default_handler (sub, "strict_protocol_headers", rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct config_file, strict_protocol_headers), 0);
+ G_STRUCT_OFFSET (struct rspamd_config, strict_protocol_headers), 0);
/**
* Metric section
sub = rspamd_rcl_add_section (&new, "worker", rspamd_rcl_worker_handler, UCL_OBJECT,
FALSE, TRUE);
rspamd_rcl_add_default_handler (sub, "count", rspamd_rcl_parse_struct_integer,
- G_STRUCT_OFFSET (struct worker_conf, count), RSPAMD_CL_FLAG_INT_16);
+ G_STRUCT_OFFSET (struct rspamd_worker_conf, count), RSPAMD_CL_FLAG_INT_16);
rspamd_rcl_add_default_handler (sub, "max_files", rspamd_rcl_parse_struct_integer,
- G_STRUCT_OFFSET (struct worker_conf, rlimit_nofile), RSPAMD_CL_FLAG_INT_32);
+ G_STRUCT_OFFSET (struct rspamd_worker_conf, rlimit_nofile), RSPAMD_CL_FLAG_INT_32);
rspamd_rcl_add_default_handler (sub, "max_core", rspamd_rcl_parse_struct_integer,
- G_STRUCT_OFFSET (struct worker_conf, rlimit_maxcore), RSPAMD_CL_FLAG_INT_32);
+ G_STRUCT_OFFSET (struct rspamd_worker_conf, rlimit_maxcore), RSPAMD_CL_FLAG_INT_32);
/**
* Lua handler
ssub = rspamd_rcl_add_section (&sub->subsections, "statfile", rspamd_rcl_statfile_handler,
UCL_OBJECT, TRUE, TRUE);
rspamd_rcl_add_default_handler (ssub, "symbol", rspamd_rcl_parse_struct_string,
- G_STRUCT_OFFSET (struct statfile, symbol), 0);
+ G_STRUCT_OFFSET (struct rspamd_statfile_config, symbol), 0);
rspamd_rcl_add_default_handler (ssub, "path", rspamd_rcl_parse_struct_string,
- G_STRUCT_OFFSET (struct statfile, path), RSPAMD_CL_FLAG_STRING_PATH);
+ G_STRUCT_OFFSET (struct rspamd_statfile_config, path), RSPAMD_CL_FLAG_STRING_PATH);
rspamd_rcl_add_default_handler (ssub, "label", rspamd_rcl_parse_struct_string,
- G_STRUCT_OFFSET (struct statfile, label), 0);
+ G_STRUCT_OFFSET (struct rspamd_statfile_config, label), 0);
rspamd_rcl_add_default_handler (ssub, "size", rspamd_rcl_parse_struct_integer,
- G_STRUCT_OFFSET (struct statfile, size), RSPAMD_CL_FLAG_INT_SIZE);
+ G_STRUCT_OFFSET (struct rspamd_statfile_config, size), RSPAMD_CL_FLAG_INT_SIZE);
rspamd_rcl_add_default_handler (ssub, "spam", rspamd_rcl_parse_struct_boolean,
- G_STRUCT_OFFSET (struct statfile, is_spam), 0);
+ G_STRUCT_OFFSET (struct rspamd_statfile_config, is_spam), 0);
/**
* Composites handler
gboolean
rspamd_read_rcl_config (struct rspamd_rcl_section *top,
- struct config_file *cfg, const ucl_object_t *obj, GError **err)
+ struct rspamd_config *cfg, const ucl_object_t *obj, GError **err)
{
const ucl_object_t *found, *cur_obj;
struct rspamd_rcl_section *cur, *tmp;
}
gboolean rspamd_rcl_section_parse_defaults (struct rspamd_rcl_section *section,
- struct config_file *cfg, const ucl_object_t *obj, gpointer ptr,
+ struct rspamd_config *cfg, const ucl_object_t *obj, gpointer ptr,
GError **err)
{
const ucl_object_t *found;
}
gboolean
-rspamd_rcl_parse_struct_string (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_parse_struct_string (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
struct rspamd_rcl_struct_parser *pd = ud;
}
gboolean
-rspamd_rcl_parse_struct_integer (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_parse_struct_integer (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
struct rspamd_rcl_struct_parser *pd = ud;
}
gboolean
-rspamd_rcl_parse_struct_double (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_parse_struct_double (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
struct rspamd_rcl_struct_parser *pd = ud;
}
gboolean
-rspamd_rcl_parse_struct_time (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_parse_struct_time (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
struct rspamd_rcl_struct_parser *pd = ud;
}
gboolean
-rspamd_rcl_parse_struct_string_list (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_parse_struct_string_list (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
struct rspamd_rcl_struct_parser *pd = ud;
}
gboolean
-rspamd_rcl_parse_struct_boolean (struct config_file *cfg, const ucl_object_t *obj,
+rspamd_rcl_parse_struct_boolean (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
struct rspamd_rcl_struct_parser *pd = ud;
}
void
-rspamd_rcl_register_worker_option (struct config_file *cfg, gint type, const gchar *name,
+rspamd_rcl_register_worker_option (struct rspamd_config *cfg, gint type, const gchar *name,
rspamd_rcl_handler_t handler, gpointer target, gsize offset, gint flags)
{
struct rspamd_worker_param_parser *nhandler;
void
-rspamd_rcl_register_worker_parser (struct config_file *cfg, gint type,
+rspamd_rcl_register_worker_parser (struct rspamd_config *cfg, gint type,
gboolean (*func)(ucl_object_t *, gpointer), gpointer ud)
{
struct rspamd_worker_cfg_parser *nparser;
}
struct rspamd_rcl_section;
-struct config_file;
+struct rspamd_config;
struct rspamd_rcl_struct_parser {
gpointer user_struct;
* @param err error object
* @return TRUE if a section has been parsed
*/
-typedef gboolean (*rspamd_rcl_handler_t) (struct config_file *cfg, const ucl_object_t *obj,
+typedef gboolean (*rspamd_rcl_handler_t) (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err);
/**
* @param cfg configuration
* @param ud user data
*/
-typedef void (*rspamd_rcl_section_fin_t)(struct config_file *cfg, gpointer ud);
+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;
* @return TRUE if an object can be parsed
*/
gboolean rspamd_read_rcl_config (struct rspamd_rcl_section *top,
- struct config_file *cfg, const ucl_object_t *obj, GError **err);
+ struct rspamd_config *cfg, const ucl_object_t *obj, GError **err);
/**
* @return TRUE if the object has been parsed
*/
gboolean rspamd_rcl_section_parse_defaults (struct rspamd_rcl_section *section,
- struct config_file *cfg, const ucl_object_t *obj, gpointer ptr,
+ struct rspamd_config *cfg, const ucl_object_t *obj, gpointer ptr,
GError **err);
/**
* Here is a section of common handlers that accepts rcl_struct_parser
* @param err error pointer
* @return TRUE if a string value has been successfully parsed
*/
-gboolean rspamd_rcl_parse_struct_string (struct config_file *cfg, const ucl_object_t *obj,
+gboolean rspamd_rcl_parse_struct_string (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err);
/**
* @param err error pointer
* @return TRUE if a value has been successfully parsed
*/
-gboolean rspamd_rcl_parse_struct_integer (struct config_file *cfg, const ucl_object_t *obj,
+gboolean rspamd_rcl_parse_struct_integer (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err);
* @param err error pointer
* @return TRUE if a value has been successfully parsed
*/
-gboolean rspamd_rcl_parse_struct_double (struct config_file *cfg, const ucl_object_t *obj,
+gboolean rspamd_rcl_parse_struct_double (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err);
/**
* @param err error pointer
* @return TRUE if a value has been successfully parsed
*/
-gboolean rspamd_rcl_parse_struct_time (struct config_file *cfg, const ucl_object_t *obj,
+gboolean rspamd_rcl_parse_struct_time (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err);
/**
* @param err error pointer
* @return TRUE if a value has been successfully parsed
*/
-gboolean rspamd_rcl_parse_struct_string_list (struct config_file *cfg, const ucl_object_t *obj,
+gboolean rspamd_rcl_parse_struct_string_list (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err);
/**
* @param err error pointer
* @return TRUE if a value has been successfully parsed
*/
-gboolean rspamd_rcl_parse_struct_boolean (struct config_file *cfg, const ucl_object_t *obj,
+gboolean rspamd_rcl_parse_struct_boolean (struct rspamd_config *cfg, const ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err);
/**
* @param target opaque target structure
* @param offset offset inside a structure
*/
-void rspamd_rcl_register_worker_option (struct config_file *cfg, gint type, const gchar *name,
+void rspamd_rcl_register_worker_option (struct rspamd_config *cfg, gint type, const gchar *name,
rspamd_rcl_handler_t handler, gpointer target, gsize offset, gint flags);
/**
* @param func handler function
* @param ud userdata for handler function
*/
-void rspamd_rcl_register_worker_parser (struct config_file *cfg, gint type,
+void rspamd_rcl_register_worker_parser (struct rspamd_config *cfg, gint type,
gboolean (*func)(ucl_object_t *, gpointer), gpointer ud);
#endif /* CFG_RCL_H_ */
#define DEFAULT_MAP_TIMEOUT 10
struct rspamd_ucl_map_cbdata {
- struct config_file *cfg;
+ struct rspamd_config *cfg;
GString *buf;
};
static gchar* rspamd_ucl_read_cb (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data);
}
gboolean
-parse_host_port_priority (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint16 *port, guint *priority)
+rspamd_parse_host_port_priority (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint16 *port, guint *priority)
{
gchar **tokens;
gboolean ret;
}
gboolean
-parse_host_port (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint16 *port)
+rspamd_parse_host_port (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint16 *port)
{
- return parse_host_port_priority (pool, str, addr, port, NULL);
+ return rspamd_parse_host_port_priority (pool, str, addr, port, NULL);
}
gboolean
-parse_host_priority (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint *priority)
+rspamd_parse_host_priority (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint *priority)
{
- return parse_host_port_priority (pool, str, addr, NULL, priority);
+ return rspamd_parse_host_port_priority (pool, str, addr, NULL, priority);
}
gboolean
-parse_bind_line (struct config_file *cfg, struct worker_conf *cf, const gchar *str)
+rspamd_parse_bind_line (struct rspamd_config *cfg, struct rspamd_worker_conf *cf, const gchar *str)
{
struct rspamd_worker_bind_conf *cnf;
gchar **tokens, *tmp, *err;
}
void
-init_defaults (struct config_file *cfg)
+rspamd_config_defaults (struct rspamd_config *cfg)
{
cfg->memcached_error_time = DEFAULT_UPSTREAM_ERROR_TIME;
}
void
-free_config (struct config_file *cfg)
+rspamd_config_free (struct rspamd_config *cfg)
{
GList *cur;
- struct symbols_group *gr;
+ struct rspamd_symbols_group *gr;
remove_all_maps (cfg);
ucl_obj_unref (cfg->rcl_obj);
}
const ucl_object_t *
-get_module_opt (struct config_file *cfg, const gchar *module_name, const gchar *opt_name)
+rspamd_config_get_module_opt (struct rspamd_config *cfg, const gchar *module_name, const gchar *opt_name)
{
const ucl_object_t *res = NULL, *sec;
}
guint64
-parse_limit (const gchar *limit, guint len)
+rspamd_config_parse_limit (const gchar *limit, guint len)
{
guint64 result = 0;
const gchar *err_str;
}
gchar
-parse_flag (const gchar *str)
+rspamd_config_parse_flag (const gchar *str)
{
guint len;
gchar c;
}
gboolean
-get_config_checksum (struct config_file *cfg)
+rspamd_config_calculate_checksum (struct rspamd_config *cfg)
{
gint fd;
void *map;
* Perform post load actions
*/
void
-post_load_config (struct config_file *cfg)
+rspamd_config_post_load (struct rspamd_config *cfg)
{
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
#endif
if ((def_metric = g_hash_table_lookup (cfg->metrics, DEFAULT_METRIC)) == NULL) {
- def_metric = check_metric_conf (cfg, NULL);
+ def_metric = rspamd_config_new_metric (cfg, NULL);
def_metric->name = DEFAULT_METRIC;
def_metric->actions[METRIC_ACTION_REJECT].score = DEFAULT_SCORE;
cfg->metrics_list = g_list_prepend (cfg->metrics_list, def_metric);
#endif
void
-unescape_quotes (gchar *line)
+rspamd_config_unescape_quotes (gchar *line)
{
gchar *c = line, *t;
}
GList *
-parse_comma_list (rspamd_mempool_t * pool, const gchar *line)
+rspamd_config_parse_comma_list (rspamd_mempool_t * pool, const gchar *line)
{
GList *res = NULL;
const gchar *c, *p;
return res;
}
-struct classifier_config *
-check_classifier_conf (struct config_file *cfg, struct classifier_config *c)
+struct rspamd_classifier_config *
+rspamd_config_new_classifier (struct rspamd_config *cfg, struct rspamd_classifier_config *c)
{
if (c == NULL) {
- c = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct classifier_config));
+ c = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_classifier_config));
}
if (c->opts == NULL) {
c->opts = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
return c;
}
-struct statfile*
-check_statfile_conf (struct config_file *cfg, struct statfile *c)
+struct rspamd_statfile_config*
+rspamd_config_new_statfile (struct rspamd_config *cfg, struct rspamd_statfile_config *c)
{
if (c == NULL) {
- c = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct statfile));
+ c = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_statfile_config));
}
return c;
}
struct metric *
-check_metric_conf (struct config_file *cfg, struct metric *c)
+rspamd_config_new_metric (struct rspamd_config *cfg, struct metric *c)
{
int i;
if (c == NULL) {
return c;
}
-struct worker_conf *
-check_worker_conf (struct config_file *cfg, struct worker_conf *c)
+struct rspamd_worker_conf *
+rspamd_config_new_worker (struct rspamd_config *cfg, struct rspamd_worker_conf *c)
{
if (c == NULL) {
- c = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct worker_conf));
+ c = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_conf));
c->params = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
c->active_workers = g_queue_new ();
rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_hash_table_destroy, c->params);
static bool
rspamd_include_map_handler (const guchar *data, gsize len, void* ud)
{
- struct config_file *cfg = (struct config_file *)ud;
+ struct rspamd_config *cfg = (struct rspamd_config *)ud;
struct rspamd_ucl_map_cbdata *cbdata, **pcbdata;
gchar *map_line;
}
static void
-rspamd_ucl_add_conf_macros (struct ucl_parser *parser, struct config_file *cfg)
+rspamd_ucl_add_conf_macros (struct ucl_parser *parser, struct rspamd_config *cfg)
{
ucl_parser_register_macro (parser, "include_map", rspamd_include_map_handler, cfg);
}
gboolean
-read_rspamd_config (struct config_file *cfg, const gchar *filename,
+rspamd_config_read (struct rspamd_config *cfg, const gchar *filename,
const gchar *convert_to, rspamd_rcl_section_fin_t logger_fin,
gpointer logger_ud)
{
static void
symbols_classifiers_callback (gpointer key, gpointer value, gpointer ud)
{
- struct config_file *cfg = ud;
+ struct rspamd_config *cfg = ud;
register_virtual_symbol (&cfg->cache, key, 1.0);
}
void
-insert_classifier_symbols (struct config_file *cfg)
+rspamd_config_insert_classify_symbols (struct rspamd_config *cfg)
{
g_hash_table_foreach (cfg->classifiers_symbols, symbols_classifiers_callback, cfg);
}
-struct classifier_config*
-find_classifier_conf (struct config_file *cfg, const gchar *name)
+struct rspamd_classifier_config*
+rspamd_config_find_classifier (struct rspamd_config *cfg, const gchar *name)
{
GList *cur;
- struct classifier_config *cf;
+ struct rspamd_classifier_config *cf;
if (name == NULL) {
return NULL;
}
gboolean
-check_classifier_statfiles (struct classifier_config *cf)
+rspamd_config_check_statfiles (struct rspamd_classifier_config *cf)
{
- struct statfile *st;
+ struct rspamd_statfile_config *st;
gboolean has_other = FALSE, res = FALSE, cur_class;
GList *cur;
}
gboolean
-rspamd_parse_ip_list (const gchar *ip_list, radix_tree_t **tree)
+rspamd_config_parse_ip_list (const gchar *ip_list, radix_tree_t **tree)
{
gchar **strvec, **cur;
struct in_addr ina;
struct rspamd_dns_resolver *
-dns_resolver_init (rspamd_logger_t *logger, struct event_base *ev_base, struct config_file *cfg)
+dns_resolver_init (rspamd_logger_t *logger, struct event_base *ev_base, struct rspamd_config *cfg)
{
GList *cur;
struct rspamd_dns_resolver *new;
* Init DNS resolver, params are obtained from a config file or system file /etc/resolv.conf
*/
struct rspamd_dns_resolver *dns_resolver_init (rspamd_logger_t *logger,
- struct event_base *ev_base, struct config_file *cfg);
+ struct event_base *ev_base, struct rspamd_config *cfg);
/**
* Make a DNS request
gchar *buf;
gchar *pos;
size_t buflen;
- struct config_file *cfg;
+ struct rspamd_config *cfg;
GList *config_metrics;
};
* @param cfg
*/
static void
-apply_dynamic_conf (GList *conf_metrics, struct config_file *cfg)
+apply_dynamic_conf (GList *conf_metrics, struct rspamd_config *cfg)
{
GList *cur, *cur_elt;
struct dynamic_cfg_metric *metric;
* @param cfg config file
*/
void
-init_dynamic_config (struct config_file *cfg)
+init_dynamic_config (struct rspamd_config *cfg)
{
struct config_json_buf *jb, **pjb;
* @return
*/
gboolean
-dump_dynamic_config (struct config_file *cfg)
+dump_dynamic_config (struct rspamd_config *cfg)
{
struct stat st;
gchar *dir, pathbuf[PATH_MAX];
* @return
*/
gboolean
-add_dynamic_symbol (struct config_file *cfg, const gchar *metric_name, const gchar *symbol, gdouble value)
+add_dynamic_symbol (struct rspamd_config *cfg, const gchar *metric_name, const gchar *symbol, gdouble value)
{
GList *cur;
struct dynamic_cfg_metric *metric = NULL;
* @return
*/
gboolean
-add_dynamic_action (struct config_file *cfg, const gchar *metric_name, guint action, gdouble value)
+add_dynamic_action (struct rspamd_config *cfg, const gchar *metric_name, guint action, gdouble value)
{
GList *cur;
struct dynamic_cfg_metric *metric = NULL;
* Init dynamic configuration using map logic and specific configuration
* @param cfg config file
*/
-void init_dynamic_config (struct config_file *cfg);
+void init_dynamic_config (struct rspamd_config *cfg);
/**
* Dump dynamic configuration to the disk
* @param cfg
* @return
*/
-gboolean dump_dynamic_config (struct config_file *cfg);
+gboolean dump_dynamic_config (struct rspamd_config *cfg);
/**
* Add symbol for specified metric
* @param value value of symbol
* @return
*/
-gboolean add_dynamic_symbol (struct config_file *cfg, const gchar *metric, const gchar *symbol, gdouble value);
+gboolean add_dynamic_symbol (struct rspamd_config *cfg, const gchar *metric, const gchar *symbol, gdouble value);
/**
* @param value value of symbol
* @return
*/
-gboolean add_dynamic_action (struct config_file *cfg, const gchar *metric, guint action, gdouble value);
+gboolean add_dynamic_action (struct rspamd_config *cfg, const gchar *metric, guint action, gdouble value);
#endif /* DYNAMIC_CFG_H_ */
}
gboolean
-read_settings (const gchar *path, const gchar *description, struct config_file *cfg, GHashTable * table)
+read_settings (const gchar *path, const gchar *description, struct rspamd_config *cfg, GHashTable * table)
{
struct json_buf *jb = g_malloc (sizeof (struct json_buf)), **pjb;
}
void
-init_settings (struct config_file *cfg)
+init_settings (struct rspamd_config *cfg)
{
cfg->domain_settings = g_hash_table_new_full (rspamd_strcase_hash, rspamd_strcase_equal,
g_free, (GDestroyNotify)settings_unref);
/*
* Read settings from specified path
*/
-gboolean read_settings (const gchar *path, const gchar *description, struct config_file *cfg, GHashTable *table);
+gboolean read_settings (const gchar *path, const gchar *description, struct rspamd_config *cfg, GHashTable *table);
/*
* Init configuration structures for settings
*/
-void init_settings (struct config_file *cfg);
+void init_settings (struct rspamd_config *cfg);
/*
* Check scores settings
stat_file_t *
-get_statfile_by_symbol (statfile_pool_t *pool, struct classifier_config *ccf,
- const gchar *symbol, struct statfile **st, gboolean try_create)
+get_statfile_by_symbol (statfile_pool_t *pool, struct rspamd_classifier_config *ccf,
+ const gchar *symbol, struct rspamd_statfile_config **st, gboolean try_create)
{
stat_file_t *res = NULL;
GList *cur;
} statfile_pool_t;
/* Forwarded declarations */
-struct classifier_config;
-struct statfile;
+struct rspamd_classifier_config;
+struct rspamd_statfile_config;
/**
* Create new statfile pool
* @param st statfile to get
* @param try_create whether we need to create statfile if it is absent
*/
-stat_file_t* get_statfile_by_symbol (statfile_pool_t *pool, struct classifier_config *ccf,
- const gchar *symbol, struct statfile **st, gboolean try_create);
+stat_file_t* get_statfile_by_symbol (statfile_pool_t *pool, struct rspamd_classifier_config *ccf,
+ const gchar *symbol, struct rspamd_statfile_config **st, gboolean try_create);
#endif
/* Context of sync process */
struct rspamd_sync_ctx {
- struct statfile *st;
+ struct rspamd_statfile_config *st;
stat_file_t *real_statfile;
statfile_pool_t *pool;
rspamd_io_dispatcher_t *dispatcher;
}
static gboolean
-add_statfile_watch (statfile_pool_t *pool, struct statfile *st, struct config_file *cfg, struct event_base *ev_base)
+add_statfile_watch (statfile_pool_t *pool, struct rspamd_statfile_config *st, struct rspamd_config *cfg, struct event_base *ev_base)
{
struct rspamd_sync_ctx *ctx;
guint32 jittered_interval;
}
gboolean
-start_statfile_sync (statfile_pool_t *pool, struct config_file *cfg, struct event_base *ev_base)
+start_statfile_sync (statfile_pool_t *pool, struct rspamd_config *cfg, struct event_base *ev_base)
{
GList *cur, *l;
- struct classifier_config *cl;
- struct statfile *st;
+ struct rspamd_classifier_config *cl;
+ struct rspamd_statfile_config *st;
/*
* First of all walk through all classifiers and find those statfiles
/*
* Start synchronization of statfiles. Must be called after event_init as it adds events
*/
-gboolean start_statfile_sync (statfile_pool_t *pool, struct config_file *cfg, struct event_base *ev_base);
+gboolean start_statfile_sync (statfile_pool_t *pool, struct rspamd_config *cfg, struct event_base *ev_base);
#endif
pcache->used_items++;
g_hash_table_insert (pcache->items_by_symbol, item->s->symbol, item);
msg_debug ("used items: %d, added symbol: %s", (*cache)->used_items, name);
- set_counter (item->s->symbol, 0);
+ rspamd_set_counter (item->s->symbol, 0);
*target = g_list_prepend (*target, item);
}
pcache->used_items++;
msg_debug ("used items: %d, added symbol: %s", (*cache)->used_items, name);
- set_counter (item->s->symbol, 0);
+ rspamd_set_counter (item->s->symbol, 0);
g_hash_table_insert (pcache->items_by_symbol, item->s->symbol, item);
}
gboolean
-init_symbols_cache (rspamd_mempool_t * pool, struct symbols_cache *cache, struct config_file *cfg,
+init_symbols_cache (rspamd_mempool_t * pool, struct symbols_cache *cache, struct rspamd_config *cfg,
const gchar *filename, gboolean ignore_checksum)
{
struct stat st;
}
static gboolean
-check_debug_symbol (struct config_file *cfg, const gchar *symbol)
+check_debug_symbol (struct rspamd_config *cfg, const gchar *symbol)
{
GList *cur;
}
gboolean
-validate_cache (struct symbols_cache *cache, struct config_file *cfg, gboolean strict)
+validate_cache (struct symbols_cache *cache, struct rspamd_config *cfg, gboolean strict)
{
struct cache_item *item;
GList *cur, *p, *metric_symbols;
#else
diff = (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec);
#endif
- item->s->avg_time = set_counter (item->s->symbol, diff);
+ item->s->avg_time = rspamd_set_counter (item->s->symbol, diff);
}
s->saved_item = item;
#define MAX_SYMBOL 128
struct rspamd_task;
-struct config_file;
+struct rspamd_config;
typedef void (*symbol_func_t)(struct rspamd_task *task, gpointer user_data);
guint uses;
gpointer map;
rspamd_mempool_rwlock_t *lock;
- struct config_file *cfg;
+ struct rspamd_config *cfg;
};
/**
* Load symbols cache from file, must be called _after_ init_symbols_cache
*/
-gboolean init_symbols_cache (rspamd_mempool_t *pool, struct symbols_cache *cache, struct config_file *cfg,
+gboolean init_symbols_cache (rspamd_mempool_t *pool, struct symbols_cache *cache, struct rspamd_config *cfg,
const gchar *filename, gboolean ignore_checksum);
/**
* @param cfg configuration
* @param strict do strict checks - symbols MUST be described in metrics
*/
-gboolean validate_cache (struct symbols_cache *cache, struct config_file *cfg, gboolean strict);
+gboolean validate_cache (struct symbols_cache *cache, struct rspamd_config *cfg, gboolean strict);
#endif
* pointer */
GList *messages; /**< list of messages that would be reported */
GHashTable *re_cache; /**< cache for matched or not matched regexps */
- struct config_file *cfg; /**< pointer to config object */
+ struct rspamd_config *cfg; /**< pointer to config object */
gchar *last_error; /**< last error */
gint error_code; /**< code of last error */
rspamd_mempool_t *task_pool; /**< memory pool for task */
* @return worker's control structure or NULL
*/
worker_t*
-get_worker_by_type (GQuark type)
+rspamd_get_worker_by_type (GQuark type)
{
worker_t **cur;
}
double
-set_counter (const gchar *name, guint32 value)
+rspamd_set_counter (const gchar *name, guint32 value)
{
struct counter_data *cd;
double alpha;
tv.tv_usec = 0;
event_del (&worker->sig_ev_usr1);
event_del (&worker->sig_ev_usr2);
- worker_stop_accept (worker);
+ rspamd_worker_stop_accept (worker);
msg_info ("worker's shutdown is pending in %d sec", SOFT_SHUTDOWN_TIME);
event_loopexit (&tv);
}
}
struct event_base *
-prepare_worker (struct rspamd_worker *worker, const char *name,
+rspamd_prepare_worker (struct rspamd_worker *worker, const char *name,
void (*accept_handler)(int, short, void *))
{
struct event_base *ev_base;
}
void
-worker_stop_accept (struct rspamd_worker *worker)
+rspamd_worker_stop_accept (struct rspamd_worker *worker)
{
GList *cur;
struct event *event;
* @param type
* @return worker's control structure or NULL
*/
-worker_t* get_worker_by_type (GQuark type);
+worker_t* rspamd_get_worker_by_type (GQuark type);
/**
* Set counter for a symbol
*/
-double set_counter (const gchar *name, guint32 value);
+double rspamd_set_counter (const gchar *name, guint32 value);
#ifndef HAVE_SA_SIGINFO
typedef void (*rspamd_sig_handler_t) (gint);
* @return event base suitable for a worker
*/
struct event_base *
-prepare_worker (struct rspamd_worker *worker, const char *name,
+rspamd_prepare_worker (struct rspamd_worker *worker, const char *name,
void (*accept_handler)(int, short, void *));
/**
* Stop accepting new connections for a worker
* @param worker
*/
-void worker_stop_accept (struct rspamd_worker *worker);
+void rspamd_worker_stop_accept (struct rspamd_worker *worker);
#endif /* WORKER_UTIL_H_ */
*/
struct rspamd_logger_s {
rspamd_log_func_t log_func;
- struct config_file *cfg;
+ struct rspamd_config *cfg;
struct {
guint32 size;
guint32 used;
* Setup logger
*/
void
-rspamd_set_logger (struct config_file *cfg, GQuark ptype, struct rspamd_main *rspamd)
+rspamd_set_logger (struct rspamd_config *cfg, GQuark ptype, struct rspamd_main *rspamd)
{
gchar **strvec, *p, *err;
gint num, i, k;
/**
* Init logger
*/
-void rspamd_set_logger (struct config_file *cfg, GQuark ptype, struct rspamd_main *main);
+void rspamd_set_logger (struct rspamd_config *cfg, GQuark ptype, struct rspamd_main *main);
/**
* Open log file or initialize other structures
*/
/* Start watching event for all maps */
void
-start_map_watch (struct config_file *cfg, struct event_base *ev_base)
+start_map_watch (struct rspamd_config *cfg, struct event_base *ev_base)
{
GList *cur = cfg->maps;
struct rspamd_map *map;
}
void
-remove_all_maps (struct config_file *cfg)
+remove_all_maps (struct rspamd_config *cfg)
{
g_list_free (cfg->maps);
cfg->maps = NULL;
}
gboolean
-add_map (struct config_file *cfg, const gchar *map_line, const gchar *description,
+add_map (struct rspamd_config *cfg, const gchar *map_line, const gchar *description,
map_cb_t read_callback, map_fin_cb_t fin_callback, void **user_data)
{
struct rspamd_map *new_map;
/**
* Common map object
*/
-struct config_file;
+struct rspamd_config;
struct rspamd_map {
rspamd_mempool_t *pool;
- struct config_file *cfg;
+ struct rspamd_config *cfg;
enum fetch_proto protocol;
map_cb_t read_callback;
map_fin_cb_t fin_callback;
/**
* Add map from line
*/
-gboolean add_map (struct config_file *cfg, const gchar *map_line, const gchar *description,
+gboolean add_map (struct rspamd_config *cfg, const gchar *map_line, const gchar *description,
map_cb_t read_callback, map_fin_cb_t fin_callback, void **user_data);
/**
* Start watching of maps by adding events to libevent event loop
*/
-void start_map_watch (struct config_file *cfg, struct event_base *ev_base);
+void start_map_watch (struct rspamd_config *cfg, struct event_base *ev_base);
/**
* Remove all maps watched (remove events)
*/
-void remove_all_maps (struct config_file *cfg);
+void remove_all_maps (struct rspamd_config *cfg);
typedef void (*insert_func) (gpointer st, gconstpointer key, gconstpointer value);
}
void
-gperf_profiler_init (struct config_file *cfg, const gchar *descr)
+gperf_profiler_init (struct rspamd_config *cfg, const gchar *descr)
{
#if defined(WITH_GPERF_TOOLS)
gchar prof_path[PATH_MAX];
#include "fstring.h"
#include "ucl.h"
-struct config_file;
+struct rspamd_config;
struct rspamd_main;
struct workq;
-struct statfile;
-struct classifier_config;
+struct rspamd_statfile_config;
+struct rspamd_classifier_config;
/**
* Union that is used for storing sockaddrs
/*
* Google perf-tools initialization function
*/
-void gperf_profiler_init (struct config_file *cfg, const gchar *descr);
+void gperf_profiler_init (struct rspamd_config *cfg, const gchar *descr);
/*
* Workarounds for older versions of glib
/* Process a single item in 'metrics' table */
static void
-lua_process_metric (lua_State *L, const gchar *name, struct config_file *cfg)
+lua_process_metric (lua_State *L, const gchar *name, struct rspamd_config *cfg)
{
GList *metric_list;
gchar *symbol, *old_desc;
/* Get module opt structure */
if ((metric = g_hash_table_lookup (cfg->metrics, name)) == NULL) {
- metric = check_metric_conf (cfg, metric);
+ metric = rspamd_config_new_metric (cfg, metric);
metric->name = rspamd_mempool_strdup (cfg->cfg_pool, name);
}
/* Do post load initialization based on lua */
void
-lua_post_load_config (struct config_file *cfg)
+lua_post_load_config (struct rspamd_config *cfg)
{
lua_State *L = cfg->lua_state;
const gchar *name, *val;
#define FAKE_RES_VAR "rspamd_res"
gboolean
-lua_check_condition (struct config_file *cfg, const gchar *condition)
+lua_check_condition (struct rspamd_config *cfg, const gchar *condition)
{
lua_State *L = cfg->lua_state;
gchar *hostbuf, *condbuf;
const gchar *name;
};
-static struct statfile* lua_check_statfile (lua_State * L);
+static struct rspamd_statfile_config* lua_check_statfile (lua_State * L);
/* Classifier implementation */
-static struct classifier_config *
+static struct rspamd_classifier_config *
lua_check_classifier (lua_State * L)
{
void *ud = luaL_checkudata (L, 1, "rspamd{classifier}");
luaL_argcheck (L, ud != NULL, 1, "'classifier' expected");
- return ud ? *((struct classifier_config **)ud) : NULL;
+ return ud ? *((struct rspamd_classifier_config **)ud) : NULL;
}
static GList *
-call_classifier_pre_callback (struct classifier_config *ccf, struct rspamd_task *task,
+call_classifier_pre_callback (struct rspamd_classifier_config *ccf, struct rspamd_task *task,
lua_State *L, gboolean is_learn, gboolean is_spam)
{
- struct classifier_config **pccf;
+ struct rspamd_classifier_config **pccf;
struct rspamd_task **ptask;
- struct statfile **pst;
+ struct rspamd_statfile_config **pst;
GList *res = NULL;
- pccf = lua_newuserdata (L, sizeof (struct classifier_config *));
+ pccf = lua_newuserdata (L, sizeof (struct rspamd_classifier_config *));
lua_setclass (L, "rspamd{classifier}", -1);
*pccf = ccf;
/* Return list of statfiles that should be checked for this message */
GList *
-call_classifier_pre_callbacks (struct classifier_config *ccf, struct rspamd_task *task,
+call_classifier_pre_callbacks (struct rspamd_classifier_config *ccf, struct rspamd_task *task,
gboolean is_learn, gboolean is_spam, lua_State *L)
{
GList *res = NULL, *cur;
/* Return result mark for statfile */
double
-call_classifier_post_callbacks (struct classifier_config *ccf, struct rspamd_task *task, double in, lua_State *L)
+call_classifier_post_callbacks (struct rspamd_classifier_config *ccf, struct rspamd_task *task, double in, lua_State *L)
{
struct classifier_callback_data *cd;
- struct classifier_config **pccf;
+ struct rspamd_classifier_config **pccf;
struct rspamd_task **ptask;
double out = in;
GList *cur;
cd = cur->data;
lua_getglobal (L, cd->name);
- pccf = lua_newuserdata (L, sizeof (struct classifier_config *));
+ pccf = lua_newuserdata (L, sizeof (struct rspamd_classifier_config *));
lua_setclass (L, "rspamd{classifier}", -1);
*pccf = ccf;
static gint
lua_classifier_register_pre_callback (lua_State *L)
{
- struct classifier_config *ccf = lua_check_classifier (L);
+ struct rspamd_classifier_config *ccf = lua_check_classifier (L);
struct classifier_callback_data *cd;
const gchar *name;
static gint
lua_classifier_register_post_callback (lua_State *L)
{
- struct classifier_config *ccf = lua_check_classifier (L);
+ struct rspamd_classifier_config *ccf = lua_check_classifier (L);
struct classifier_callback_data *cd;
const gchar *name;
static gint
lua_classifier_get_statfiles (lua_State *L)
{
- struct classifier_config *ccf = lua_check_classifier (L);
+ struct rspamd_classifier_config *ccf = lua_check_classifier (L);
GList *cur;
- struct statfile *st, **pst;
+ struct rspamd_statfile_config *st, **pst;
gint i;
if (ccf) {
i = 1;
while (cur) {
st = cur->data;
- pst = lua_newuserdata (L, sizeof (struct statfile *));
+ pst = lua_newuserdata (L, sizeof (struct rspamd_statfile_config *));
lua_setclass (L, "rspamd{statfile}", -1);
*pst = st;
lua_rawseti (L, -2, i++);
static gint
lua_classifier_get_statfile_by_label (lua_State *L)
{
- struct classifier_config *ccf = lua_check_classifier (L);
- struct statfile *st, **pst;
+ struct rspamd_classifier_config *ccf = lua_check_classifier (L);
+ struct rspamd_statfile_config *st, **pst;
const gchar *label;
GList *cur;
gint i;
i = 1;
while (cur) {
st = cur->data;
- pst = lua_newuserdata (L, sizeof (struct statfile *));
+ pst = lua_newuserdata (L, sizeof (struct rspamd_statfile_config *));
lua_setclass (L, "rspamd{statfile}", -1);
*pst = st;
lua_rawseti (L, -2, i++);
static gint
lua_statfile_get_symbol (lua_State *L)
{
- struct statfile *st = lua_check_statfile (L);
+ struct rspamd_statfile_config *st = lua_check_statfile (L);
if (st != NULL) {
lua_pushstring (L, st->symbol);
static gint
lua_statfile_get_label (lua_State *L)
{
- struct statfile *st = lua_check_statfile (L);
+ struct rspamd_statfile_config *st = lua_check_statfile (L);
if (st != NULL && st->label != NULL) {
lua_pushstring (L, st->label);
static gint
lua_statfile_get_path (lua_State *L)
{
- struct statfile *st = lua_check_statfile (L);
+ struct rspamd_statfile_config *st = lua_check_statfile (L);
if (st != NULL) {
lua_pushstring (L, st->path);
static gint
lua_statfile_get_size (lua_State *L)
{
- struct statfile *st = lua_check_statfile (L);
+ struct rspamd_statfile_config *st = lua_check_statfile (L);
if (st != NULL) {
lua_pushinteger (L, st->size);
static gint
lua_statfile_is_spam (lua_State *L)
{
- struct statfile *st = lua_check_statfile (L);
+ struct rspamd_statfile_config *st = lua_check_statfile (L);
if (st != NULL) {
lua_pushboolean (L, st->is_spam);
static gint
lua_statfile_get_param (lua_State *L)
{
- struct statfile *st = lua_check_statfile (L);
+ struct rspamd_statfile_config *st = lua_check_statfile (L);
const gchar *param;
const ucl_object_t *value;
return 1;
}
-static struct statfile *
+static struct rspamd_statfile_config *
lua_check_statfile (lua_State * L)
{
void *ud = luaL_checkudata (L, 1, "rspamd{statfile}");
luaL_argcheck (L, ud != NULL, 1, "'statfile' expected");
- return ud ? *((struct statfile **)ud) : NULL;
+ return ud ? *((struct rspamd_statfile_config **)ud) : NULL;
}
}
lua_State *
-init_lua (struct config_file *cfg)
+init_lua (struct rspamd_config *cfg)
{
lua_State *L;
* Initialize new locked lua_State structure
*/
struct lua_locked_state*
-init_lua_locked (struct config_file *cfg)
+init_lua_locked (struct rspamd_config *cfg)
{
struct lua_locked_state *new;
}
gboolean
-init_lua_filters (struct config_file *cfg)
+init_lua_filters (struct rspamd_config *cfg)
{
- struct config_file **pcfg;
+ struct rspamd_config **pcfg;
GList *cur, *tmp;
struct script_module *module;
- struct statfile *st;
+ struct rspamd_statfile_config *st;
lua_State *L = cfg->lua_state;
cur = g_list_first (cfg->script_modules);
}
/* Initialize config structure */
- pcfg = lua_newuserdata (L, sizeof (struct config_file *));
+ pcfg = lua_newuserdata (L, sizeof (struct rspamd_config *));
lua_setclass (L, "rspamd{config}", -1);
*pcfg = cfg;
lua_setglobal (L, "rspamd_config");
}
double
-lua_normalizer_func (struct config_file *cfg, long double score, void *params)
+lua_normalizer_func (struct rspamd_config *cfg, long double score, void *params)
{
GList *p = params;
long double res = score;
/**
* Initialize lua and bindings
*/
-lua_State* init_lua (struct config_file *cfg);
+lua_State* init_lua (struct rspamd_config *cfg);
/**
* Load and initialize lua plugins
*/
-gboolean init_lua_filters (struct config_file *cfg);
+gboolean init_lua_filters (struct rspamd_config *cfg);
/**
* Initialize new locked lua_State structure
*/
-struct lua_locked_state* init_lua_locked (struct config_file *cfg);
+struct lua_locked_state* init_lua_locked (struct rspamd_config *cfg);
/**
* Free locked state structure
*/
void add_luabuf (const gchar *line);
/* Classify functions */
-GList *call_classifier_pre_callbacks (struct classifier_config *ccf, struct rspamd_task *task, gboolean is_learn, gboolean is_spam, lua_State *L);
-double call_classifier_post_callbacks (struct classifier_config *ccf, struct rspamd_task *task, double in, lua_State *L);
+GList *call_classifier_pre_callbacks (struct rspamd_classifier_config *ccf, struct rspamd_task *task, gboolean is_learn, gboolean is_spam, lua_State *L);
+double call_classifier_post_callbacks (struct rspamd_classifier_config *ccf, struct rspamd_task *task, double in, lua_State *L);
-double lua_normalizer_func (struct config_file *cfg, long double score, void *params);
+double lua_normalizer_func (struct rspamd_config *cfg, long double score, void *params);
/* Config file functions */
-void lua_post_load_config (struct config_file *cfg);
-void lua_process_element (struct config_file *cfg, const gchar *name,
- const gchar *module_name, struct module_opt *opt, gint idx, gboolean allow_meta);
+void lua_post_load_config (struct rspamd_config *cfg);
+void lua_process_element (struct rspamd_config *cfg, const gchar *name,
+ const gchar *module_name, struct rspamd_module_opt *opt, gint idx, gboolean allow_meta);
gboolean lua_handle_param (struct rspamd_task *task, gchar *mname, gchar *optname,
enum lua_var_type expected_type, gpointer *res);
-gboolean lua_check_condition (struct config_file *cfg, const gchar *condition);
+gboolean lua_check_condition (struct rspamd_config *cfg, const gchar *condition);
void lua_dumpstack (lua_State *L);
struct memory_pool_s *lua_check_mempool (lua_State * L);
{NULL, NULL}
};
-static struct config_file *
+static struct rspamd_config *
lua_check_config (lua_State * L)
{
void *ud = luaL_checkudata (L, 1, "rspamd{config}");
luaL_argcheck (L, ud != NULL, 1, "'config' expected");
- return ud ? *((struct config_file **)ud) : NULL;
+ return ud ? *((struct rspamd_config **)ud) : NULL;
}
static radix_tree_t *
static gint
lua_config_get_module_opt (lua_State * L)
{
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
const gchar *mname, *optname;
const ucl_object_t *obj;
optname = luaL_checkstring (L, 3);
if (mname && optname) {
- obj = get_module_opt (cfg, mname, optname);
+ obj = rspamd_config_get_module_opt (cfg, mname, optname);
if (obj) {
return lua_rcl_obj_push (L, obj, TRUE);
}
lua_config_get_mempool (lua_State * L)
{
rspamd_mempool_t **ppool;
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
if (cfg != NULL) {
ppool = lua_newuserdata (L, sizeof (rspamd_mempool_t *));
static gint
lua_config_get_all_opt (lua_State * L)
{
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
const gchar *mname;
const ucl_object_t *obj;
static gint
lua_config_get_classifier (lua_State * L)
{
- struct config_file *cfg = lua_check_config (L);
- struct classifier_config *clc = NULL, **pclc = NULL;
+ struct rspamd_config *cfg = lua_check_config (L);
+ struct rspamd_classifier_config *clc = NULL, **pclc = NULL;
const gchar *name;
GList *cur;
cur = g_list_next (cur);
}
if (pclc) {
- pclc = lua_newuserdata (L, sizeof (struct classifier_config *));
+ pclc = lua_newuserdata (L, sizeof (struct rspamd_classifier_config *));
lua_setclass (L, "rspamd{classifier}", -1);
*pclc = clc;
return 1;
static gint
lua_config_register_function (lua_State *L)
{
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
gchar *name;
struct lua_callback_data *cd;
static gint
lua_config_register_post_filter (lua_State *L)
{
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
struct lua_callback_data *cd;
if (cfg) {
static gint
lua_config_register_pre_filter (lua_State *L)
{
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
struct lua_callback_data *cd;
if (cfg) {
static gint
lua_config_add_radix_map (lua_State *L)
{
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
const gchar *map_line, *description;
radix_tree_t **r, ***ud;
static gint
lua_config_add_hash_map (lua_State *L)
{
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
const gchar *map_line, *description;
GHashTable **r, ***ud;
static gint
lua_config_add_kv_map (lua_State *L)
{
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
const gchar *map_line, *description;
GHashTable **r, ***ud;
static gint
lua_config_register_symbol (lua_State * L)
{
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
gchar *name;
double weight;
struct lua_callback_data *cd;
static gint
lua_config_register_symbols (lua_State *L)
{
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
struct lua_callback_data *cd;
gint i, top;
gchar *sym;
static gint
lua_config_register_virtual_symbol (lua_State * L)
{
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
gchar *name;
double weight;
static gint
lua_config_register_callback_symbol (lua_State * L)
{
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
gchar *name;
double weight;
struct lua_callback_data *cd;
static gint
lua_config_register_callback_symbol_priority (lua_State * L)
{
- struct config_file *cfg = lua_check_config (L);
+ struct rspamd_config *cfg = lua_check_config (L);
gchar *name;
double weight;
gint priority;
lua_dns_resolver_init (lua_State *L)
{
struct rspamd_dns_resolver *resolver, **presolver;
- struct config_file *cfg, **pcfg;
+ struct rspamd_config *cfg, **pcfg;
struct event_base *base, **pbase;
/* Check args */
#include "statfile_sync.h"
#include "diff.h"
-extern stat_file_t* get_statfile_by_symbol (statfile_pool_t *pool, struct classifier_config *ccf,
- const gchar *symbol, struct statfile **st, gboolean try_create);
+extern stat_file_t* get_statfile_by_symbol (statfile_pool_t *pool, struct rspamd_classifier_config *ccf,
+ const gchar *symbol, struct rspamd_statfile_config **st, gboolean try_create);
/* Task creation */
LUA_FUNCTION_DEF (task, create_empty);
void *ud = luaL_checkudata (L, 2, "rspamd{config}");
luaL_argcheck (L, ud != NULL, 1, "'config' expected");
- task->cfg = ud ? *((struct config_file **)ud) : NULL;
+ task->cfg = ud ? *((struct rspamd_config **)ud) : NULL;
return 0;
}
{
struct rspamd_task *task = lua_check_task (L);
const gchar *symbol;
- struct classifier_config *cl;
+ struct rspamd_classifier_config *cl;
GTree *tokens;
- struct statfile *st;
+ struct rspamd_statfile_config *st;
stat_file_t *statfile;
struct classifier_ctx *ctx;
new = g_slice_alloc0 (sizeof (struct lua_upstream));
new->def = g_strdup (def);
new->addr = g_malloc (INET6_ADDRSTRLEN);
- if (!parse_host_port_priority (NULL, new->def, &new->addr, &new->port, &new->up.priority)) {
+ if (!rspamd_parse_host_port_priority (NULL, new->def, &new->addr, &new->port, &new->up.priority)) {
g_free (new->def);
g_slice_free1 (sizeof (struct lua_upstream), new);
lua_pushnil (L);
for (i = 0; i < new->count; i ++) {
cur = &new->upstreams[i];
cur->addr = g_malloc (INET6_ADDRSTRLEN);
- if (!parse_host_port_priority (NULL, tokens[i], &cur->addr, &cur->port, &cur->up.priority)) {
+ if (!rspamd_parse_host_port_priority (NULL, tokens[i], &cur->addr, &cur->port, &cur->up.priority)) {
goto err;
}
if (cur->port == 0) {
/* 60 seconds for worker's IO */
#define DEFAULT_WORKER_IO_TIMEOUT 60000
-gpointer init_lua_worker (struct config_file *cfg);
+gpointer init_lua_worker (struct rspamd_config *cfg);
void start_lua_worker (struct rspamd_worker *worker);
worker_t lua_worker = {
/* Callback for finishing */
gint cbref_fin;
/* Config file */
- struct config_file *cfg;
+ struct rspamd_config *cfg;
/* The rest options */
ucl_object_t *opts;
};
lua_worker_get_cfg (lua_State *L)
{
struct rspamd_lua_worker_ctx *ctx = lua_check_lua_worker (L);
- struct config_file **pcfg;
+ struct rspamd_config **pcfg;
if (ctx) {
pcfg = lua_newuserdata (L, sizeof (gpointer));
}
gpointer
-init_lua_worker (struct config_file *cfg)
+init_lua_worker (struct rspamd_config *cfg)
{
struct rspamd_lua_worker_ctx *ctx;
GQuark type;
monstartup ((u_long) & _start, (u_long) & etext);
#endif
- ctx->ev_base = prepare_worker (worker, "lua_worker", lua_accept_socket);
+ ctx->ev_base = rspamd_prepare_worker (worker, "lua_worker", lua_accept_socket);
L = worker->srv->cfg->lua_state;
ctx->L = L;
/* 10 seconds after getting termination signal to terminate all workers with SIGKILL */
#define HARD_TERMINATION_TIME 10
-static struct rspamd_worker *fork_worker (struct rspamd_main *, struct worker_conf *);
-static gboolean load_rspamd_config (struct config_file *cfg, gboolean init_modules);
-static void init_cfg_cache (struct config_file *cfg);
+static struct rspamd_worker *fork_worker (struct rspamd_main *, struct rspamd_worker_conf *);
+static gboolean load_rspamd_config (struct rspamd_config *cfg, gboolean init_modules);
+static void init_cfg_cache (struct rspamd_config *cfg);
sig_atomic_t do_restart = 0;
sig_atomic_t do_reopen_log = 0;
static void
-read_cmd_line (gint argc, gchar **argv, struct config_file *cfg)
+read_cmd_line (gint argc, gchar **argv, struct rspamd_config *cfg)
{
GError *error = NULL;
GOptionContext *context;
}
static void
-config_logger (struct config_file *cfg, gpointer ud)
+config_logger (struct rspamd_config *cfg, gpointer ud)
{
struct rspamd_main *rm = ud;
}
static void
-parse_filters_str (struct config_file *cfg, const gchar *str)
+parse_filters_str (struct rspamd_config *cfg, const gchar *str)
{
gchar **strvec, **p;
struct filter *cur;
static void
reread_config (struct rspamd_main *rspamd)
{
- struct config_file *tmp_cfg;
+ struct rspamd_config *tmp_cfg;
gchar *cfg_file;
GList *l;
struct filter *filt;
- tmp_cfg = (struct config_file *)g_malloc (sizeof (struct config_file));
+ tmp_cfg = (struct rspamd_config *)g_malloc (sizeof (struct rspamd_config));
if (tmp_cfg) {
- bzero (tmp_cfg, sizeof (struct config_file));
+ bzero (tmp_cfg, sizeof (struct rspamd_config));
tmp_cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
- init_defaults (tmp_cfg);
+ rspamd_config_defaults (tmp_cfg);
cfg_file = rspamd_mempool_strdup (tmp_cfg->cfg_pool, rspamd->cfg->cfg_name);
/* Save some variables */
tmp_cfg->cfg_name = cfg_file;
if (! load_rspamd_config (tmp_cfg, FALSE)) {
rspamd_set_logger (rspamd_main->cfg, g_quark_try_string ("main"), rspamd_main);
msg_err ("cannot parse new config file, revert to old one");
- free_config (tmp_cfg);
+ rspamd_config_free (tmp_cfg);
}
else {
msg_debug ("replacing config");
- free_config (rspamd->cfg);
+ rspamd_config_free (rspamd->cfg);
close_log (rspamd->logger);
g_free (rspamd->cfg);
rspamd->cfg = tmp_cfg;
}
static void
-set_worker_limits (struct worker_conf *cf)
+set_worker_limits (struct rspamd_worker_conf *cf)
{
struct rlimit rlmt;
}
static struct rspamd_worker *
-fork_worker (struct rspamd_main *rspamd, struct worker_conf *cf)
+fork_worker (struct rspamd_main *rspamd, struct rspamd_worker_conf *cf)
{
struct rspamd_worker *cur;
/* Starting worker process */
cur->srv = rspamd;
cur->type = cf->type;
cur->pid = fork ();
- cur->cf = g_malloc (sizeof (struct worker_conf));
- memcpy (cur->cf, cf, sizeof (struct worker_conf));
+ cur->cf = g_malloc (sizeof (struct rspamd_worker_conf));
+ memcpy (cur->cf, cf, sizeof (struct rspamd_worker_conf));
cur->pending = FALSE;
cur->ctx = cf->ctx;
switch (cur->pid) {
}
static void
-delay_fork (struct worker_conf *cf)
+delay_fork (struct rspamd_worker_conf *cf)
{
workers_pending = g_list_prepend (workers_pending, cf);
set_alarm (SOFT_FORK_TIME);
fork_delayed (struct rspamd_main *rspamd)
{
GList *cur;
- struct worker_conf *cf;
+ struct rspamd_worker_conf *cf;
while (workers_pending != NULL) {
cur = workers_pending;
spawn_workers (struct rspamd_main *rspamd)
{
GList *cur, *ls;
- struct worker_conf *cf;
+ struct rspamd_worker_conf *cf;
gint i, key;
gpointer p;
struct rspamd_worker_bind_conf *bcf;
static void
preload_statfiles (struct rspamd_main *rspamd)
{
- struct classifier_config *cf;
- struct statfile *st;
+ struct rspamd_classifier_config *cf;
+ struct rspamd_statfile_config *st;
stat_file_t *stf;
GList *cur_cl, *cur_st;
}
static gboolean
-load_rspamd_config (struct config_file *cfg, gboolean init_modules)
+load_rspamd_config (struct rspamd_config *cfg, gboolean init_modules)
{
GList *l;
struct filter *filt;
struct module_ctx *cur_module = NULL;
- if (! read_rspamd_config (cfg, cfg->cfg_name, NULL,
+ if (! rspamd_config_read (cfg, cfg->cfg_name, NULL,
config_logger, rspamd_main)) {
return FALSE;
}
}
/* Do post-load actions */
- post_load_config (cfg);
+ rspamd_config_post_load (cfg);
parse_filters_str (cfg, cfg->filters_str);
if (init_modules) {
}
static void
-init_cfg_cache (struct config_file *cfg)
+init_cfg_cache (struct rspamd_config *cfg)
{
if (!init_symbols_cache (cfg->cfg_pool, cfg->cache, cfg, cfg->cache_filename, FALSE)) {
}
static void
-print_symbols_cache (struct config_file *cfg)
+print_symbols_cache (struct rspamd_config *cfg)
{
GList *cur;
struct cache_item *item;
}
static gint
-perform_lua_tests (struct config_file *cfg)
+perform_lua_tests (struct rspamd_config *cfg)
{
gint i, tests_num, res = EXIT_SUCCESS;
gchar *cur_script;
rspamd_main = (struct rspamd_main *)g_malloc (sizeof (struct rspamd_main));
memset (rspamd_main, 0, sizeof (struct rspamd_main));
rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
- rspamd_main->cfg = (struct config_file *)g_malloc (sizeof (struct config_file));
+ rspamd_main->cfg = (struct rspamd_config *)g_malloc (sizeof (struct rspamd_config));
if (!rspamd_main || !rspamd_main->cfg) {
fprintf (stderr, "Cannot allocate memory\n");
rspamd_main->stat = rspamd_mempool_alloc_shared (rspamd_main->server_pool, sizeof (struct rspamd_stat));
memset (rspamd_main->stat, 0, sizeof (struct rspamd_stat));
- memset (rspamd_main->cfg, 0, sizeof (struct config_file));
+ memset (rspamd_main->cfg, 0, sizeof (struct rspamd_config));
rspamd_main->cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
- init_defaults (rspamd_main->cfg);
+ rspamd_config_defaults (rspamd_main->cfg);
memset (&signals, 0, sizeof (struct sigaction));
l = g_list_next (l);
}
/* Insert classifiers symbols */
- (void)insert_classifier_symbols (rspamd_main->cfg);
+ (void)rspamd_config_insert_classify_symbols (rspamd_main->cfg);
if (! validate_cache (rspamd_main->cfg->cache, rspamd_main->cfg, FALSE)) {
res = FALSE;
/* Insert classifiers symbols */
- (void)insert_classifier_symbols (rspamd_main->cfg);
+ (void)rspamd_config_insert_classify_symbols (rspamd_main->cfg);
/* Perform modules configuring */
l = g_list_first (rspamd_main->cfg->filters);
close_log (rspamd_main->logger);
- free_config (rspamd_main->cfg);
+ rspamd_config_free (rspamd_main->cfg);
g_free (rspamd_main->cfg);
g_free (rspamd_main);
struct event sig_ev_usr1; /**< signals event */
struct event sig_ev_usr2; /**< signals event */
GList *accept_events; /**< socket events */
- struct worker_conf *cf; /**< worker config data */
+ struct rspamd_worker_conf *cf; /**< worker config data */
gpointer ctx; /**< worker's specific data */
};
*/
struct pidfh;
-struct config_file;
+struct rspamd_config;
struct tokenizer;
struct classifier;
-struct classifier_config;
+struct rspamd_classifier_config;
struct mime_part;
struct rspamd_dns_resolver;
struct rspamd_task;
* Struct that determine main server object (for logging purposes)
*/
struct rspamd_main {
- struct config_file *cfg; /**< pointer to config structure */
+ struct rspamd_config *cfg; /**< pointer to config structure */
pid_t pid; /**< main pid */
/* Pid file structure */
rspamd_pidfh_t *pfh; /**< struct pidfh for pidfile */
GHashTable *kwargs; /**< keyword arguments for restful command */
struct controller_command *cmd; /**< real command */
rspamd_mempool_t *session_pool; /**< memory pool for session */
- struct config_file *cfg; /**< pointer to config file */
+ struct rspamd_config *cfg; /**< pointer to config file */
gchar *learn_rcpt; /**< recipient for learning */
gchar *learn_from; /**< from address for learning */
- struct classifier_config *learn_classifier;
+ struct rspamd_classifier_config *learn_classifier;
gchar *learn_symbol; /**< symbol to train */
double learn_multiplier; /**< multiplier for learning */
rspamd_io_dispatcher_t *dispatcher; /**< IO dispatcher object */
gint (*filter)(struct rspamd_task *task); /**< pointer to headers process function */
};
-/**
- * Common structure for C module
- */
-struct c_module {
- const gchar *name; /**< name */
- struct module_ctx *ctx; /**< pointer to context */
-};
-
/**
* Register custom controller function
*/
#define DEFAULT_THRESHOLD 0.1
/* Initialization */
-gint chartable_module_init (struct config_file *cfg, struct module_ctx **ctx);
-gint chartable_module_config (struct config_file *cfg);
-gint chartable_module_reconfig (struct config_file *cfg);
+gint chartable_module_init (struct rspamd_config *cfg, struct module_ctx **ctx);
+gint chartable_module_config (struct rspamd_config *cfg);
+gint chartable_module_reconfig (struct rspamd_config *cfg);
module_t chartable_module = {
"chartable",
static void chartable_symbol_callback (struct rspamd_task *task, void *unused);
gint
-chartable_module_init (struct config_file *cfg, struct module_ctx **ctx)
+chartable_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
chartable_module_ctx = g_malloc (sizeof (struct chartable_ctx));
gint
-chartable_module_config (struct config_file *cfg)
+chartable_module_config (struct rspamd_config *cfg)
{
const ucl_object_t *value;
gint res = TRUE;
- if ((value = get_module_opt (cfg, "chartable", "symbol")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "chartable", "symbol")) != NULL) {
chartable_module_ctx->symbol = ucl_obj_tostring (value);
}
else {
chartable_module_ctx->symbol = DEFAULT_SYMBOL;
}
- if ((value = get_module_opt (cfg, "chartable", "threshold")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "chartable", "threshold")) != NULL) {
if (!ucl_obj_todouble_safe (value, &chartable_module_ctx->threshold)) {
msg_warn ("invalid numeric value");
chartable_module_ctx->threshold = DEFAULT_THRESHOLD;
}
gint
-chartable_module_reconfig (struct config_file *cfg)
+chartable_module_reconfig (struct rspamd_config *cfg)
{
rspamd_mempool_delete (chartable_module_ctx->chartable_pool);
chartable_module_ctx->chartable_pool = rspamd_mempool_new (1024);
};
/* Exported functions */
-void module_init (struct config_file *cfg);
+void module_init (struct rspamd_config *cfg);
void* before_connect (void);
gboolean parse_line (const char *line, size_t len, char **output, void *user_data);
void after_connect (char **output, char **log_line, void *user_data);
/* Implementation */
char *
-get_module_opt (struct config_file *cfg, char *module_name, char *opt_name)
+rspamd_config_get_module_opt (struct rspamd_config *cfg, char *module_name, char *opt_name)
{
GList *cur_opt;
- struct module_opt *cur;
+ struct rspamd_module_opt *cur;
cur_opt = g_hash_table_lookup (cfg->modules_opts, module_name);
if (cur_opt == NULL) {
}
void
-module_init (struct config_file *cfg)
+module_init (struct rspamd_config *cfg)
{
char *value;
- if (cfg && (value = get_module_opt (cfg, "ipmark", "file")) != NULL) {
+ if (cfg && (value = rspamd_config_get_module_opt (cfg, "ipmark", "file")) != NULL) {
filename = g_strdup (value);
}
#define MAX_LEVELS 32
/* Exported functions */
-void module_init (struct config_file *cfg);
+void module_init (struct rspamd_config *cfg);
void* before_connect (void);
gboolean parse_line (const char *line, size_t len, char **output, void *user_data);
void after_connect (char **output, char **log_line, void *user_data);
/* Implementation */
char *
-get_module_opt (struct config_file *cfg, char *module_name, char *opt_name)
+rspamd_config_get_module_opt (struct rspamd_config *cfg, char *module_name, char *opt_name)
{
GList *cur_opt;
- struct module_opt *cur;
+ struct rspamd_module_opt *cur;
cur_opt = g_hash_table_lookup (cfg->modules_opts, module_name);
if (cur_opt == NULL) {
}
void
-module_init (struct config_file *cfg)
+module_init (struct rspamd_config *cfg)
{
char *value;
- if (cfg && (value = get_module_opt (cfg, "ipmark", "file")) != NULL) {
+ if (cfg && (value = rspamd_config_get_module_opt (cfg, "ipmark", "file")) != NULL) {
filename = g_strdup (value);
}
static void dkim_symbol_callback (struct rspamd_task *task, void *unused);
/* Initialization */
-gint dkim_module_init (struct config_file *cfg, struct module_ctx **ctx);
-gint dkim_module_config (struct config_file *cfg);
-gint dkim_module_reconfig (struct config_file *cfg);
+gint dkim_module_init (struct rspamd_config *cfg, struct module_ctx **ctx);
+gint dkim_module_config (struct rspamd_config *cfg);
+gint dkim_module_reconfig (struct rspamd_config *cfg);
module_t dkim_module = {
"dkim",
};
gint
-dkim_module_init (struct config_file *cfg, struct module_ctx **ctx)
+dkim_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
dkim_module_ctx = g_malloc0 (sizeof (struct dkim_ctx));
}
gint
-dkim_module_config (struct config_file *cfg)
+dkim_module_config (struct rspamd_config *cfg)
{
const ucl_object_t *value;
gint res = TRUE;
dkim_module_ctx->whitelist_ip = radix_tree_create ();
- if ((value = get_module_opt (cfg, "dkim", "symbol_reject")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "dkim", "symbol_reject")) != NULL) {
dkim_module_ctx->symbol_reject = ucl_obj_tostring (value);
}
else {
dkim_module_ctx->symbol_reject = DEFAULT_SYMBOL_REJECT;
}
- if ((value = get_module_opt (cfg, "dkim", "symbol_tempfail")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "dkim", "symbol_tempfail")) != NULL) {
dkim_module_ctx->symbol_tempfail = ucl_obj_tostring (value);
}
else {
dkim_module_ctx->symbol_tempfail = DEFAULT_SYMBOL_TEMPFAIL;
}
- if ((value = get_module_opt (cfg, "dkim", "symbol_allow")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "dkim", "symbol_allow")) != NULL) {
dkim_module_ctx->symbol_allow = ucl_obj_tostring (value);
}
else {
dkim_module_ctx->symbol_allow = DEFAULT_SYMBOL_ALLOW;
}
- if ((value = get_module_opt (cfg, "dkim", "dkim_cache_size")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "dkim", "dkim_cache_size")) != NULL) {
cache_size = ucl_obj_toint (value);
}
else {
cache_size = DEFAULT_CACHE_SIZE;
}
- if ((value = get_module_opt (cfg, "dkim", "dkim_cache_expire")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "dkim", "dkim_cache_expire")) != NULL) {
cache_expire = ucl_obj_todouble (value);
}
else {
cache_expire = DEFAULT_CACHE_MAXAGE;
}
- if ((value = get_module_opt (cfg, "dkim", "time_jitter")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "dkim", "time_jitter")) != NULL) {
dkim_module_ctx->time_jitter = ucl_obj_todouble (value);
}
else {
dkim_module_ctx->time_jitter = DEFAULT_TIME_JITTER;
}
- if ((value = get_module_opt (cfg, "dkim", "whitelist")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "dkim", "whitelist")) != NULL) {
if (! add_map (cfg, ucl_obj_tostring (value),
"DKIM whitelist", read_radix_list, fin_radix_list,
(void **)&dkim_module_ctx->whitelist_ip)) {
msg_warn ("cannot load whitelist from %s", ucl_obj_tostring (value));
}
}
- if ((value = get_module_opt (cfg, "dkim", "domains")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "dkim", "domains")) != NULL) {
if (! add_map (cfg, ucl_obj_tostring (value),
"DKIM domains", read_kv_list, fin_kv_list,
(void **)&dkim_module_ctx->dkim_domains)) {
got_trusted = TRUE;
}
}
- if ((value = get_module_opt (cfg, "dkim", "strict_multiplier")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "dkim", "strict_multiplier")) != NULL) {
dkim_module_ctx->strict_multiplier = ucl_obj_toint (value);
}
else {
dkim_module_ctx->strict_multiplier = 1;
}
- if ((value = get_module_opt (cfg, "dkim", "trusted_only")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "dkim", "trusted_only")) != NULL) {
dkim_module_ctx->trusted_only = ucl_obj_toboolean (value);
}
else {
dkim_module_ctx->trusted_only = FALSE;
}
- if ((value = get_module_opt (cfg, "dkim", "skip_multi")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "dkim", "skip_multi")) != NULL) {
dkim_module_ctx->skip_multi = ucl_obj_toboolean (value);
}
else {
}
gint
-dkim_module_reconfig (struct config_file *cfg)
+dkim_module_reconfig (struct rspamd_config *cfg)
{
rspamd_mempool_delete (dkim_module_ctx->dkim_pool);
radix_tree_free (dkim_module_ctx->whitelist_ip);
struct controller_session *session);
/* Initialization */
-gint fuzzy_check_module_init (struct config_file *cfg, struct module_ctx **ctx);
-gint fuzzy_check_module_config (struct config_file *cfg);
-gint fuzzy_check_module_reconfig (struct config_file *cfg);
+gint fuzzy_check_module_init (struct rspamd_config *cfg, struct module_ctx **ctx);
+gint fuzzy_check_module_config (struct rspamd_config *cfg);
+gint fuzzy_check_module_reconfig (struct rspamd_config *cfg);
module_t fuzzy_check_module = {
"fuzzy_check",
};
static void
-parse_flags (struct fuzzy_rule *rule, struct config_file *cfg, const ucl_object_t *val)
+parse_flags (struct fuzzy_rule *rule, struct rspamd_config *cfg, const ucl_object_t *val)
{
const ucl_object_t *elt;
struct fuzzy_mapping *map;
g_strstrip (strvec[i]);
cur = &rule->servers[rule->servers_num];
- if (parse_host_port (fuzzy_module_ctx->fuzzy_pool, strvec[i], &cur->addr, &cur->port)) {
+ if (rspamd_parse_host_port (fuzzy_module_ctx->fuzzy_pool, strvec[i], &cur->addr, &cur->port)) {
if (cur->port == 0) {
cur->port = DEFAULT_PORT;
}
}
static gint
-fuzzy_parse_rule (struct config_file *cfg, const ucl_object_t *obj)
+fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj)
{
const ucl_object_t *value, *cur;
struct fuzzy_rule *rule;
}
gint
-fuzzy_check_module_init (struct config_file *cfg, struct module_ctx **ctx)
+fuzzy_check_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
fuzzy_module_ctx = g_malloc0 (sizeof (struct fuzzy_ctx));
}
gint
-fuzzy_check_module_config (struct config_file *cfg)
+fuzzy_check_module_config (struct rspamd_config *cfg)
{
const ucl_object_t *value, *cur;
gint res = TRUE;
- if ((value = get_module_opt (cfg, "fuzzy_check", "symbol")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "symbol")) != NULL) {
fuzzy_module_ctx->default_symbol = ucl_obj_tostring (value);
}
else {
fuzzy_module_ctx->default_symbol = DEFAULT_SYMBOL;
}
- if ((value = get_module_opt (cfg, "fuzzy_check", "min_length")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "min_length")) != NULL) {
fuzzy_module_ctx->min_hash_len = ucl_obj_toint (value);
}
else {
fuzzy_module_ctx->min_hash_len = 0;
}
- if ((value = get_module_opt (cfg, "fuzzy_check", "min_bytes")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "min_bytes")) != NULL) {
fuzzy_module_ctx->min_bytes = ucl_obj_toint (value);
}
else {
fuzzy_module_ctx->min_bytes = 0;
}
- if ((value = get_module_opt (cfg, "fuzzy_check", "min_height")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "min_height")) != NULL) {
fuzzy_module_ctx->min_height = ucl_obj_toint (value);
}
else {
fuzzy_module_ctx->min_height = 0;
}
- if ((value = get_module_opt (cfg, "fuzzy_check", "min_width")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "min_width")) != NULL) {
fuzzy_module_ctx->min_width = ucl_obj_toint (value);
}
else {
fuzzy_module_ctx->min_width = 0;
}
- if ((value = get_module_opt (cfg, "fuzzy_check", "timeout")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "timeout")) != NULL) {
fuzzy_module_ctx->io_timeout = ucl_obj_todouble (value) * 1000;
}
else {
fuzzy_module_ctx->io_timeout = DEFAULT_IO_TIMEOUT;
}
- if ((value = get_module_opt (cfg, "fuzzy_check", "whitelist")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "whitelist")) != NULL) {
fuzzy_module_ctx->whitelist = radix_tree_create ();
if (!add_map (cfg, ucl_obj_tostring (value),
"Fuzzy whitelist", read_radix_list, fin_radix_list,
fuzzy_module_ctx->whitelist = NULL;
}
- if ((value = get_module_opt (cfg, "fuzzy_check", "rule")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "rule")) != NULL) {
LL_FOREACH (value, cur) {
if (fuzzy_parse_rule (cfg, cur) == -1) {
return -1;
}
gint
-fuzzy_check_module_reconfig (struct config_file *cfg)
+fuzzy_check_module_reconfig (struct rspamd_config *cfg)
{
rspamd_mempool_delete (fuzzy_module_ctx->fuzzy_pool);
gchar *buf;
gchar *pos;
size_t buflen;
- struct config_file *cfg;
+ struct rspamd_config *cfg;
};
/* Lua regexp module for checking rspamd regexps */
/* Initialization */
-gint regexp_module_init (struct config_file *cfg, struct module_ctx **ctx);
-gint regexp_module_config (struct config_file *cfg);
-gint regexp_module_reconfig (struct config_file *cfg);
+gint regexp_module_init (struct rspamd_config *cfg, struct module_ctx **ctx);
+gint regexp_module_config (struct rspamd_config *cfg);
+gint regexp_module_reconfig (struct rspamd_config *cfg);
module_t regexp_module = {
"regexp",
/* Init function */
gint
-regexp_module_init (struct config_file *cfg, struct module_ctx **ctx)
+regexp_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
regexp_module_ctx = g_malloc (sizeof (struct regexp_ctx));
* SYMBOL:statfile:weight
*/
void
-parse_autolearn_param (const gchar *param, const gchar *value, struct config_file *cfg)
+parse_autolearn_param (const gchar *param, const gchar *value, struct rspamd_config *cfg)
{
struct autolearn_data *d;
gchar *p;
}
gint
-regexp_module_config (struct config_file *cfg)
+regexp_module_config (struct rspamd_config *cfg)
{
struct regexp_module_item *cur_item;
const ucl_object_t *sec, *value;
}
gint
-regexp_module_reconfig (struct config_file *cfg)
+regexp_module_reconfig (struct rspamd_config *cfg)
{
rspamd_mempool_delete (regexp_module_ctx->regexp_pool);
regexp_module_ctx->regexp_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
static void spf_record_destroy (gpointer list);
/* Initialization */
-gint spf_module_init (struct config_file *cfg, struct module_ctx **ctx);
-gint spf_module_config (struct config_file *cfg);
-gint spf_module_reconfig (struct config_file *cfg);
+gint spf_module_init (struct rspamd_config *cfg, struct module_ctx **ctx);
+gint spf_module_config (struct rspamd_config *cfg);
+gint spf_module_reconfig (struct rspamd_config *cfg);
module_t spf_module = {
"spf",
};
gint
-spf_module_init (struct config_file *cfg, struct module_ctx **ctx)
+spf_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
spf_module_ctx = g_malloc (sizeof (struct spf_ctx));
gint
-spf_module_config (struct config_file *cfg)
+spf_module_config (struct rspamd_config *cfg)
{
const ucl_object_t *value;
gint res = TRUE;
spf_module_ctx->whitelist_ip = radix_tree_create ();
- if ((value = get_module_opt (cfg, "spf", "symbol_fail")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "spf", "symbol_fail")) != NULL) {
spf_module_ctx->symbol_fail = ucl_obj_tostring (value);
}
else {
spf_module_ctx->symbol_fail = DEFAULT_SYMBOL_FAIL;
}
- if ((value = get_module_opt (cfg, "spf", "symbol_softfail")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "spf", "symbol_softfail")) != NULL) {
spf_module_ctx->symbol_softfail = ucl_obj_tostring (value);
}
else {
spf_module_ctx->symbol_softfail = DEFAULT_SYMBOL_SOFTFAIL;
}
- if ((value = get_module_opt (cfg, "spf", "symbol_allow")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "spf", "symbol_allow")) != NULL) {
spf_module_ctx->symbol_allow = ucl_obj_tostring (value);
}
else {
spf_module_ctx->symbol_allow = DEFAULT_SYMBOL_ALLOW;
}
- if ((value = get_module_opt (cfg, "spf", "spf_cache_size")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "spf", "spf_cache_size")) != NULL) {
cache_size = ucl_obj_toint (value);
}
else {
cache_size = DEFAULT_CACHE_SIZE;
}
- if ((value = get_module_opt (cfg, "spf", "spf_cache_expire")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "spf", "spf_cache_expire")) != NULL) {
cache_expire = ucl_obj_toint (value);
}
else {
cache_expire = DEFAULT_CACHE_MAXAGE;
}
- if ((value = get_module_opt (cfg, "spf", "whitelist")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "spf", "whitelist")) != NULL) {
if (! add_map (cfg, ucl_obj_tostring (value),
"SPF whitelist", read_radix_list, fin_radix_list,
(void **)&spf_module_ctx->whitelist_ip)) {
}
gint
-spf_module_reconfig (struct config_file *cfg)
+spf_module_reconfig (struct rspamd_config *cfg)
{
rspamd_mempool_delete (spf_module_ctx->spf_pool);
radix_tree_free (spf_module_ctx->whitelist_ip);
}
/* Initialization */
-gint surbl_module_init (struct config_file *cfg, struct module_ctx **ctx);
-gint surbl_module_config (struct config_file *cfg);
-gint surbl_module_reconfig (struct config_file *cfg);
+gint surbl_module_init (struct rspamd_config *cfg, struct module_ctx **ctx);
+gint surbl_module_config (struct rspamd_config *cfg);
+gint surbl_module_reconfig (struct rspamd_config *cfg);
module_t surbl_module = {
"surbl",
}
gint
-surbl_module_init (struct config_file *cfg, struct module_ctx **ctx)
+surbl_module_init (struct rspamd_config *cfg, struct module_ctx **ctx)
{
surbl_module_ctx = g_malloc (sizeof (struct surbl_ctx));
* Register virtual symbols for suffixes with bit wildcard
*/
static void
-register_bit_symbols (struct config_file *cfg, struct suffix_item *suffix)
+register_bit_symbols (struct rspamd_config *cfg, struct suffix_item *suffix)
{
GList *cur;
struct surbl_bit_item *bit;
}
gint
-surbl_module_config (struct config_file *cfg)
+surbl_module_config (struct rspamd_config *cfg)
{
GList *cur_opt;
struct suffix_item *new_suffix, *cur_suffix = NULL;
gint i, idx;
- if ((value = get_module_opt (cfg, "surbl", "redirector")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "surbl", "redirector")) != NULL) {
i = 0;
LL_FOREACH (value, cur) {
i ++;
LL_FOREACH (value, cur) {
redir_val = ucl_obj_tostring (cur);
surbl_module_ctx->redirectors[idx].up.priority = 100;
- if (! parse_host_port_priority (surbl_module_ctx->surbl_pool,
+ if (! rspamd_parse_host_port_priority (surbl_module_ctx->surbl_pool,
redir_val, &surbl_module_ctx->redirectors[idx].addr,
&surbl_module_ctx->redirectors[idx].port,
&surbl_module_ctx->redirectors[idx].up.priority)) {
surbl_module_ctx->redirectors_number = idx;
surbl_module_ctx->use_redirector = (surbl_module_ctx->redirectors_number != 0);
}
- if ((value = get_module_opt (cfg, "surbl", "redirector_symbol")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "surbl", "redirector_symbol")) != NULL) {
surbl_module_ctx->redirector_symbol = ucl_obj_tostring (value);
register_virtual_symbol (&cfg->cache, surbl_module_ctx->redirector_symbol, 1.0);
}
else {
surbl_module_ctx->redirector_symbol = NULL;
}
- if ((value = get_module_opt (cfg, "surbl", "weight")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "surbl", "weight")) != NULL) {
surbl_module_ctx->weight = ucl_obj_toint (value);
}
else {
surbl_module_ctx->weight = DEFAULT_SURBL_WEIGHT;
}
- if ((value = get_module_opt (cfg, "surbl", "url_expire")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "surbl", "url_expire")) != NULL) {
surbl_module_ctx->url_expire = ucl_obj_todouble (value);
}
else {
surbl_module_ctx->url_expire = DEFAULT_SURBL_URL_EXPIRE;
}
- if ((value = get_module_opt (cfg, "surbl", "redirector_connect_timeout")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "surbl", "redirector_connect_timeout")) != NULL) {
surbl_module_ctx->connect_timeout = ucl_obj_todouble (value);
}
else {
surbl_module_ctx->connect_timeout = DEFAULT_REDIRECTOR_CONNECT_TIMEOUT;
}
- if ((value = get_module_opt (cfg, "surbl", "redirector_read_timeout")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "surbl", "redirector_read_timeout")) != NULL) {
surbl_module_ctx->read_timeout = ucl_obj_todouble (value);
}
else {
surbl_module_ctx->read_timeout = DEFAULT_REDIRECTOR_READ_TIMEOUT;
}
- if ((value = get_module_opt (cfg, "surbl", "redirector_hosts_map")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "surbl", "redirector_hosts_map")) != NULL) {
add_map (cfg, ucl_obj_tostring (value),
"SURBL redirectors list", read_redirectors_list, fin_redirectors_list,
(void **)&surbl_module_ctx->redirector_hosts);
}
- if ((value = get_module_opt (cfg, "surbl", "max_urls")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "surbl", "max_urls")) != NULL) {
surbl_module_ctx->max_urls = ucl_obj_toint (value);
}
else {
surbl_module_ctx->max_urls = DEFAULT_SURBL_MAX_URLS;
}
- if ((value = get_module_opt (cfg, "surbl", "exceptions")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "surbl", "exceptions")) != NULL) {
if (add_map (cfg, ucl_obj_tostring (value),
"SURBL exceptions list", read_exceptions_list, fin_exceptions_list,
(void **)&surbl_module_ctx->exceptions)) {
ucl_obj_tostring (value) + sizeof ("file://") - 1);
}
}
- if ((value = get_module_opt (cfg, "surbl", "whitelist")) != NULL) {
+ if ((value = rspamd_config_get_module_opt (cfg, "surbl", "whitelist")) != NULL) {
if (add_map (cfg, ucl_obj_tostring (value),
"SURBL whitelist", read_host_list, fin_host_list,
(void **)&surbl_module_ctx->whitelist)) {
}
}
- value = get_module_opt (cfg, "surbl", "rule");
+ value = rspamd_config_get_module_opt (cfg, "surbl", "rule");
if (value != NULL && value->type == UCL_OBJECT) {
LL_FOREACH (value, cur_rule) {
cur = ucl_obj_get_key (cur_rule, "suffix");
}
gint
-surbl_module_reconfig (struct config_file *cfg)
+surbl_module_reconfig (struct rspamd_config *cfg)
{
/* Delete pool and objects */
rspamd_mempool_delete (surbl_module_ctx->surbl_pool);
static gboolean smtp_write_socket (void *arg);
/* Init functions */
-gpointer init_smtp (struct config_file *cfg);
+gpointer init_smtp (struct rspamd_config *cfg);
void start_smtp (struct rspamd_worker *worker);
worker_t smtp_worker = {
}
gpointer
-init_smtp (struct config_file *cfg)
+init_smtp (struct rspamd_config *cfg)
{
struct smtp_worker_ctx *ctx;
GQuark type;
{
struct smtp_worker_ctx *ctx = worker->ctx;
- ctx->ev_base = prepare_worker (worker, "smtp_worker", accept_socket);
+ ctx->ev_base = rspamd_prepare_worker (worker, "smtp_worker", accept_socket);
/* Set smtp options */
if ( !config_smtp_worker (worker)) {
struct smtp_session {
struct smtp_worker_ctx *ctx;
- struct config_file *cfg;
+ struct rspamd_config *cfg;
rspamd_mempool_t *pool;
enum rspamd_smtp_state state;
/* Init functions */
-gpointer init_smtp_proxy (struct config_file *cfg);
+gpointer init_smtp_proxy (struct rspamd_config *cfg);
void start_smtp_proxy (struct rspamd_worker *worker);
worker_t smtp_proxy_worker = {
}
gpointer
-init_smtp_proxy (struct config_file *cfg)
+init_smtp_proxy (struct rspamd_config *cfg)
{
struct smtp_proxy_ctx *ctx;
GQuark type;
{
struct smtp_proxy_ctx *ctx = worker->ctx;
- ctx->ev_base = prepare_worker (worker, "smtp_proxy", accept_socket);
+ ctx->ev_base = rspamd_prepare_worker (worker, "smtp_proxy", accept_socket);
/* Set smtp options */
if ( !config_smtp_proxy_worker (worker)) {
#define COLOR_REJECT "#CB4B4B"
#define COLOR_TOTAL "#9440ED"
-gpointer init_webui_worker (struct config_file *cfg);
+gpointer init_webui_worker (struct rspamd_config *cfg);
void start_webui_worker (struct rspamd_worker *worker);
worker_t webui_worker = {
/* Main server */
struct rspamd_main *srv;
/* Configuration */
- struct config_file *cfg;
+ struct rspamd_config *cfg;
/* SSL cert */
gchar *ssl_cert;
/* SSL private key */
struct rspamd_webui_worker_ctx *ctx;
rspamd_mempool_t *pool;
struct rspamd_task *task;
- struct classifier_config *cl;
+ struct rspamd_classifier_config *cl;
rspamd_inet_addr_t from_addr;
gboolean is_spam;
};
{
struct rspamd_webui_session *session = conn_ent->ud;
GList *cur_gr, *cur_sym;
- struct symbols_group *gr;
- struct symbol_def *sym;
+ struct rspamd_symbols_group *gr;
+ struct rspamd_symbol_def *sym;
ucl_object_t *obj, *top, *sym_obj;
if (!rspamd_webui_check_password (conn_ent, session, msg, FALSE)) {
{
struct rspamd_webui_session *session = conn_ent->ud;
struct rspamd_webui_worker_ctx *ctx;
- struct classifier_config *cl;
+ struct rspamd_classifier_config *cl;
struct rspamd_task *task;
const gchar *classifier;
classifier = "bayes";
}
- cl = find_classifier_conf (ctx->cfg, classifier);
+ cl = rspamd_config_find_classifier (ctx->cfg, classifier);
if (cl == NULL) {
rspamd_webui_send_error (conn_ent, 400, "Classifier not found");
return 0;
guint64 used, total, rev, ham = 0, spam = 0;
time_t ti;
rspamd_mempool_stat_t mem_st;
- struct classifier_config *ccf;
+ struct rspamd_classifier_config *ccf;
stat_file_t *statfile;
- struct statfile *st;
+ struct rspamd_statfile_config *st;
GList *cur_cl, *cur_st;
struct rspamd_stat *stat, stat_copy;
}
gpointer
-init_webui_worker (struct config_file *cfg)
+init_webui_worker (struct rspamd_config *cfg)
{
struct rspamd_webui_worker_ctx *ctx;
GQuark type;
{
struct rspamd_webui_worker_ctx *ctx = worker->ctx;
- ctx->ev_base = prepare_worker (worker, "controller", rspamd_webui_accept_socket);
+ ctx->ev_base = rspamd_prepare_worker (worker, "controller", rspamd_webui_accept_socket);
msec_to_tv (ctx->timeout, &ctx->io_tv);
ctx->start_time = time (NULL);
if (ctx->secure_ip != NULL) {
if (!add_map (worker->srv->cfg, ctx->secure_ip, "Allow webui access from the specified IP",
read_radix_list, fin_radix_list, (void **)&ctx->secure_map)) {
- if (!rspamd_parse_ip_list (ctx->secure_ip, &ctx->secure_map)) {
+ if (!rspamd_config_parse_ip_list (ctx->secure_ip, &ctx->secure_map)) {
msg_warn ("cannot load or parse ip list from '%s'", ctx->secure_ip);
}
}
/* 60 seconds for worker's IO */
#define DEFAULT_WORKER_IO_TIMEOUT 60000
-gpointer init_worker (struct config_file *cfg);
+gpointer init_worker (struct rspamd_config *cfg);
void start_worker (struct rspamd_worker *worker);
worker_t normal_worker = {
}
gpointer
-init_worker (struct config_file *cfg)
+init_worker (struct rspamd_config *cfg)
{
struct rspamd_worker_ctx *ctx;
GQuark type;
GError *err = NULL;
struct lua_locked_state *nL;
- ctx->ev_base = prepare_worker (worker, "normal", accept_socket);
+ ctx->ev_base = rspamd_prepare_worker (worker, "normal", accept_socket);
msec_to_tv (ctx->timeout, &ctx->io_tv);
start_map_watch (worker->srv->cfg, ctx->ev_base);
rspamd_dkim_key_t *key;
rspamd_mempool_t *pool;
struct rspamd_dns_resolver *resolver;
- struct config_file *cfg;
+ struct rspamd_config *cfg;
GError *err = NULL;
struct rspamd_async_session *s;
- cfg = (struct config_file *)g_malloc (sizeof (struct config_file));
- bzero (cfg, sizeof (struct config_file));
+ cfg = (struct rspamd_config *)g_malloc (sizeof (struct rspamd_config));
+ bzero (cfg, sizeof (struct rspamd_config));
cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
cfg->dns_retransmits = 10;
cfg->dns_timeout = 1000;
rspamd_dns_test_func ()
{
struct rspamd_dns_resolver *resolver;
- struct config_file *cfg;
+ struct rspamd_config *cfg;
rspamd_mempool_t *pool;
struct rspamd_async_session *s;
struct in_addr ina;
- cfg = (struct config_file *)g_malloc (sizeof (struct config_file));
- bzero (cfg, sizeof (struct config_file));
+ cfg = (struct rspamd_config *)g_malloc (sizeof (struct rspamd_config));
+ bzero (cfg, sizeof (struct rspamd_config));
cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
cfg->dns_retransmits = 10;
cfg->dns_timeout = 1000;
int
main (int argc, char **argv)
{
- struct config_file *cfg;
+ struct rspamd_config *cfg;
g_test_init (&argc, &argv, NULL);
memset (rspamd_main, 0, sizeof (struct rspamd_main));
rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
- rspamd_main->cfg = (struct config_file *)g_malloc (sizeof (struct config_file));
+ rspamd_main->cfg = (struct rspamd_config *)g_malloc (sizeof (struct rspamd_config));
cfg = rspamd_main->cfg;
- bzero (cfg, sizeof (struct config_file));
+ bzero (cfg, sizeof (struct rspamd_config));
cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ());
base = event_init ();