diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-04-20 08:16:49 -0700 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-04-20 08:16:49 -0700 |
commit | ad837700b86153be3587672124ee663c964f0f15 (patch) | |
tree | 7ec6e8fbe539a169d501a3d1767644b68fab2dab | |
parent | baeb17562f47dc31610c0f65079c45a7e6ad44bb (diff) | |
download | rspamd-ad837700b86153be3587672124ee663c964f0f15.tar.gz rspamd-ad837700b86153be3587672124ee663c964f0f15.zip |
Refactor memory pool naming.
101 files changed, 1027 insertions, 1019 deletions
diff --git a/src/binlog.c b/src/binlog.c index c6aa4ec08..f085a7de0 100644 --- a/src/binlog.c +++ b/src/binlog.c @@ -33,7 +33,7 @@ #define VALID_VERSION { '1', '0' } static GHashTable *binlog_opened = NULL; -static memory_pool_t *binlog_pool = NULL; +static rspamd_mempool_t *binlog_pool = NULL; static gboolean binlog_write_header (struct rspamd_binlog *log) @@ -151,13 +151,13 @@ binlog_open_real (struct rspamd_binlog *log) struct rspamd_binlog* -binlog_open (memory_pool_t *pool, const gchar *path, time_t rotate_time, gint rotate_jitter) +binlog_open (rspamd_mempool_t *pool, const gchar *path, time_t rotate_time, gint rotate_jitter) { struct rspamd_binlog *new; gint len = strlen (path); struct stat st; - new = memory_pool_alloc0 (pool, sizeof (struct rspamd_binlog)); + new = rspamd_mempool_alloc0 (pool, sizeof (struct rspamd_binlog)); new->pool = pool; new->rotate_time = rotate_time; new->fd = -1; @@ -166,7 +166,7 @@ binlog_open (memory_pool_t *pool, const gchar *path, time_t rotate_time, gint ro new->rotate_jitter = g_random_int_range (0, rotate_jitter); } - new->filename = memory_pool_alloc (pool, len + sizeof (BINLOG_SUFFIX)); + new->filename = rspamd_mempool_alloc (pool, len + sizeof (BINLOG_SUFFIX)); rspamd_strlcpy (new->filename, path, len + 1); rspamd_strlcpy (new->filename + len, BINLOG_SUFFIX, sizeof (BINLOG_SUFFIX)); @@ -508,7 +508,7 @@ maybe_init_static (void) } if (!binlog_pool) { - binlog_pool = memory_pool_new (memory_pool_get_size ()); + binlog_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); if (!binlog_pool) { return FALSE; } diff --git a/src/binlog.h b/src/binlog.h index c6df22bce..9e1a786d3 100644 --- a/src/binlog.h +++ b/src/binlog.h @@ -46,7 +46,7 @@ struct rspamd_binlog { guint64 cur_seq; guint64 cur_time; gint fd; - memory_pool_t *pool; + rspamd_mempool_t *pool; struct rspamd_binlog_header header; struct rspamd_binlog_metaindex *metaindex; @@ -58,7 +58,7 @@ struct classifier_config; /* * Open binlog at specified path with specified rotate params */ -struct rspamd_binlog* binlog_open (memory_pool_t *pool, const gchar *path, time_t rotate_time, gint rotate_jitter); +struct rspamd_binlog* binlog_open (rspamd_mempool_t *pool, const gchar *path, time_t rotate_time, gint rotate_jitter); /* * Get and open binlog for specified statfile diff --git a/src/buffer.c b/src/buffer.c index 33efa86ed..95104d2a5 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -309,7 +309,7 @@ read_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean skip_read) } if (d->in_buf == NULL) { - d->in_buf = memory_pool_alloc_tmp (d->pool, sizeof (rspamd_buffer_t)); + d->in_buf = rspamd_mempool_alloc_tmp (d->pool, sizeof (rspamd_buffer_t)); if (d->policy == BUFFER_LINE || d->policy == BUFFER_ANY) { d->in_buf->data = fstralloc_tmp (d->pool, d->default_buf_size); } @@ -570,9 +570,9 @@ rspamd_create_dispatcher (struct event_base *base, gint fd, enum io_policy polic new = g_slice_alloc0 (sizeof (rspamd_io_dispatcher_t)); - new->pool = memory_pool_new (memory_pool_get_size ()); + new->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); if (tv != NULL) { - new->tv = memory_pool_alloc (new->pool, sizeof (struct timeval)); + new->tv = rspamd_mempool_alloc (new->pool, sizeof (struct timeval)); memcpy (new->tv, tv, sizeof (struct timeval)); } else { @@ -591,7 +591,7 @@ rspamd_create_dispatcher (struct event_base *base, gint fd, enum io_policy polic new->is_restored = FALSE; new->default_buf_size = sysconf (_SC_PAGESIZE); - new->ev = memory_pool_alloc0 (new->pool, sizeof (struct event)); + new->ev = rspamd_mempool_alloc0 (new->pool, sizeof (struct event)); new->fd = fd; new->ev_base = base; @@ -612,7 +612,7 @@ rspamd_remove_dispatcher (rspamd_io_dispatcher_t * d) DELETE_OUT_BUFFER (d, cur); } event_del (d->ev); - memory_pool_delete (d->pool); + rspamd_mempool_delete (d->pool); g_slice_free1 (sizeof (rspamd_io_dispatcher_t), d); } } @@ -775,7 +775,7 @@ rspamd_dispacther_cleanup (rspamd_io_dispatcher_t *d) DELETE_OUT_BUFFER (d, cur); } /* Cleanup temporary data */ - memory_pool_cleanup_tmp (d->pool); + rspamd_mempool_cleanup_tmp (d->pool); d->in_buf = NULL; } diff --git a/src/buffer.h b/src/buffer.h index a68284af0..5ed42bfb3 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -45,7 +45,7 @@ typedef struct rspamd_io_dispatcher_s { } out_buffers; /**< output buffers chain */ struct timeval *tv; /**< io timeout */ struct event *ev; /**< libevent io event */ - memory_pool_t *pool; /**< where to store data */ + rspamd_mempool_t *pool; /**< where to store data */ enum io_policy policy; /**< IO policy */ size_t nchars; /**< how many chars to read */ gint fd; /**< descriptor */ diff --git a/src/cfg_file.h b/src/cfg_file.h index 6038cb00d..8960b5bb1 100644 --- a/src/cfg_file.h +++ b/src/cfg_file.h @@ -270,7 +270,7 @@ struct worker_conf { struct config_file { gchar *rspamd_user; /**< user to run as */ gchar *rspamd_group; /**< group to run as */ - memory_pool_t *cfg_pool; /**< memory pool for config */ + rspamd_mempool_t *cfg_pool; /**< memory pool for config */ gchar *cfg_name; /**< name of config file */ gchar *pid_file; /**< name of pid file */ gchar *temp_dir; /**< dir for temp files */ @@ -349,7 +349,7 @@ struct config_file { gint clock_res; /**< resolution of clock used */ GList *maps; /**< maps active */ - memory_pool_t *map_pool; /**< static maps pool */ + rspamd_mempool_t *map_pool; /**< static maps pool */ gdouble map_timeout; /**< maps watch timeout */ struct symbols_cache *cache; /**< symbols cache object */ @@ -380,7 +380,7 @@ struct config_file { * @param priority priority * @return TRUE if string was parsed */ -gboolean parse_host_port_priority (memory_pool_t *pool, const gchar *str, gchar **addr, guint16 *port, guint *priority); +gboolean parse_host_port_priority (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint16 *port, guint *priority); /** * Parse host:port line @@ -388,7 +388,7 @@ gboolean parse_host_port_priority (memory_pool_t *pool, const gchar *str, gchar * @param port port * @return TRUE if string was parsed */ -gboolean parse_host_port (memory_pool_t *pool, const gchar *str, gchar **addr, guint16 *port); +gboolean parse_host_port (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint16 *port); /** * Parse host:priority line @@ -396,7 +396,7 @@ gboolean parse_host_port (memory_pool_t *pool, const gchar *str, gchar **addr, g * @param priority priority * @return TRUE if string was parsed */ -gboolean parse_host_priority (memory_pool_t *pool, const gchar *str, gchar **addr, guint *priority); +gboolean parse_host_priority (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint *priority); /** * Parse bind credits @@ -465,7 +465,7 @@ void unescape_quotes (gchar *line); /* * Convert comma separated string to a list of strings */ -GList* parse_comma_list (memory_pool_t *pool, const gchar *line); +GList* parse_comma_list (rspamd_mempool_t *pool, const gchar *line); /* * Return a new classifier_config structure, setting default and non-conflicting attributes diff --git a/src/cfg_rcl.c b/src/cfg_rcl.c index 2714b428e..f577bc4e8 100644 --- a/src/cfg_rcl.c +++ b/src/cfg_rcl.c @@ -51,7 +51,7 @@ rspamd_rcl_logging_handler (struct config_file *cfg, const ucl_object_t *obj, return FALSE; } cfg->log_type = RSPAMD_LOG_FILE; - cfg->log_file = memory_pool_strdup (cfg->cfg_pool, ucl_object_tostring (val)); + cfg->log_file = rspamd_mempool_strdup (cfg->cfg_pool, ucl_object_tostring (val)); } else if (g_ascii_strcasecmp (log_type, "syslog") == 0) { /* Need to get facility */ @@ -168,7 +168,7 @@ rspamd_rcl_options_handler (struct config_file *cfg, const ucl_object_t *obj, g_set_error (err, CFG_RCL_ERROR, EINVAL, "cannot read settings: %s", user_settings); return FALSE; } - cfg->user_settings_str = memory_pool_strdup (cfg->cfg_pool, user_settings); + cfg->user_settings_str = rspamd_mempool_strdup (cfg->cfg_pool, user_settings); } val = ucl_object_find_key (obj, "domain_settings"); @@ -177,7 +177,7 @@ rspamd_rcl_options_handler (struct config_file *cfg, const ucl_object_t *obj, g_set_error (err, CFG_RCL_ERROR, EINVAL, "cannot read settings: %s", domain_settings); return FALSE; } - cfg->domain_settings_str = memory_pool_strdup (cfg->cfg_pool, domain_settings); + cfg->domain_settings_str = rspamd_mempool_strdup (cfg->cfg_pool, domain_settings); } return rspamd_rcl_section_parse_defaults (section, cfg, obj, cfg, err); @@ -255,19 +255,19 @@ rspamd_rcl_insert_symbol (struct config_file *cfg, struct metric *metric, return FALSE; } - sym_def = memory_pool_alloc (cfg->cfg_pool, sizeof (struct symbol_def)); - score_ptr = memory_pool_alloc (cfg->cfg_pool, sizeof (gdouble)); + sym_def = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct symbol_def)); + score_ptr = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (gdouble)); *score_ptr = symbol_score; sym_def->weight_ptr = score_ptr; - sym_def->name = memory_pool_strdup (cfg->cfg_pool, sym_name); + sym_def->name = rspamd_mempool_strdup (cfg->cfg_pool, sym_name); sym_def->description = (gchar *)description; g_hash_table_insert (metric->symbols, sym_def->name, score_ptr); if ((metric_list = g_hash_table_lookup (cfg->metrics_symbols, sym_def->name)) == NULL) { metric_list = g_list_prepend (NULL, metric); - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)g_list_free, metric_list); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_list_free, metric_list); g_hash_table_insert (cfg->metrics_symbols, sym_def->name, metric_list); } else { @@ -281,8 +281,8 @@ rspamd_rcl_insert_symbol (struct config_file *cfg, struct metric *metric, group_list = g_list_find_custom (cfg->symbols_groups, group, rspamd_symbols_group_find_func); if (group_list == NULL) { /* Create new group */ - sym_group = memory_pool_alloc (cfg->cfg_pool, sizeof (struct symbols_group)); - sym_group->name = memory_pool_strdup (cfg->cfg_pool, group); + sym_group = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct 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); } @@ -556,7 +556,7 @@ static gboolean rspamd_rcl_lua_handler (struct config_file *cfg, const ucl_object_t *obj, gpointer ud, struct rspamd_rcl_section *section, GError **err) { - const gchar *lua_src = memory_pool_strdup (cfg->cfg_pool, ucl_object_tostring (obj)); + const gchar *lua_src = rspamd_mempool_strdup (cfg->cfg_pool, ucl_object_tostring (obj)); gchar *cur_dir, *lua_dir, *lua_file, *tmp1, *tmp2; lua_State *L = cfg->lua_state; @@ -645,8 +645,8 @@ rspamd_rcl_add_module_path (struct config_file *cfg, const gchar *path, GError * if (glob (pattern, GLOB_DOOFFS, NULL, &globbuf) == 0) { for (i = 0; i < globbuf.gl_pathc; i ++) { - cur_mod = memory_pool_alloc (cfg->cfg_pool, sizeof (struct script_module)); - cur_mod->path = memory_pool_strdup (cfg->cfg_pool, globbuf.gl_pathv[i]); + cur_mod = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct script_module)); + cur_mod->path = rspamd_mempool_strdup (cfg->cfg_pool, globbuf.gl_pathv[i]); cfg->script_modules = g_list_prepend (cfg->script_modules, cur_mod); } globfree (&globbuf); @@ -660,8 +660,8 @@ rspamd_rcl_add_module_path (struct config_file *cfg, const gchar *path, GError * } else { /* Handle single file */ - cur_mod = memory_pool_alloc (cfg->cfg_pool, sizeof (struct script_module)); - cur_mod->path = memory_pool_strdup (cfg->cfg_pool, path); + cur_mod = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct script_module)); + cur_mod->path = rspamd_mempool_strdup (cfg->cfg_pool, path); cfg->script_modules = g_list_prepend (cfg->script_modules, cur_mod); } @@ -680,14 +680,14 @@ rspamd_rcl_modules_handler (struct config_file *cfg, const ucl_object_t *obj, LL_FOREACH (val, cur) { if (ucl_object_tostring_safe (cur, &data)) { - if (!rspamd_rcl_add_module_path (cfg, memory_pool_strdup (cfg->cfg_pool, data), err)) { + if (!rspamd_rcl_add_module_path (cfg, rspamd_mempool_strdup (cfg->cfg_pool, data), err)) { return FALSE; } } } } else if (ucl_object_tostring_safe (obj, &data)) { - if (!rspamd_rcl_add_module_path (cfg, memory_pool_strdup (cfg->cfg_pool, data), err)) { + if (!rspamd_rcl_add_module_path (cfg, rspamd_mempool_strdup (cfg->cfg_pool, data), err)) { return FALSE; } } @@ -715,7 +715,7 @@ rspamd_rcl_statfile_handler (struct config_file *cfg, const ucl_object_t *obj, val = ucl_object_find_key (obj, "binlog"); if (val != NULL && ucl_object_tostring_safe (val, &data)) { if (st->binlog == NULL) { - st->binlog = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile_binlog_params)); + st->binlog = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct statfile_binlog_params)); } if (g_ascii_strcasecmp (data, "master") == 0) { st->binlog->affinity = AFFINITY_MASTER; @@ -891,7 +891,7 @@ rspamd_rcl_composite_handler (struct config_file *cfg, const ucl_object_t *obj, return FALSE; } - composite = memory_pool_alloc (cfg->cfg_pool, sizeof (struct rspamd_composite)); + composite = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct rspamd_composite)); composite->expr = expr; composite->id = g_hash_table_size (cfg->composite_symbols) + 1; g_hash_table_insert (cfg->composite_symbols, (gpointer)composite_name, composite); @@ -1279,18 +1279,18 @@ rspamd_rcl_parse_struct_string (struct config_file *cfg, const ucl_object_t *obj target = (gchar **)(((gchar *)pd->user_struct) + pd->offset); switch (obj->type) { case UCL_STRING: - *target = memory_pool_strdup (cfg->cfg_pool, ucl_copy_value_trash (obj)); + *target = rspamd_mempool_strdup (cfg->cfg_pool, ucl_copy_value_trash (obj)); break; case UCL_INT: - *target = memory_pool_alloc (cfg->cfg_pool, num_str_len); + *target = rspamd_mempool_alloc (cfg->cfg_pool, num_str_len); rspamd_snprintf (*target, num_str_len, "%L", obj->value.iv); break; case UCL_FLOAT: - *target = memory_pool_alloc (cfg->cfg_pool, num_str_len); + *target = rspamd_mempool_alloc (cfg->cfg_pool, num_str_len); rspamd_snprintf (*target, num_str_len, "%f", obj->value.dv); break; case UCL_BOOLEAN: - *target = memory_pool_alloc (cfg->cfg_pool, num_str_len); + *target = rspamd_mempool_alloc (cfg->cfg_pool, num_str_len); rspamd_snprintf (*target, num_str_len, "%b", (gboolean)obj->value.iv); break; default: @@ -1446,18 +1446,18 @@ rspamd_rcl_parse_struct_string_list (struct config_file *cfg, const ucl_object_t while ((cur = ucl_iterate_object (obj, &iter, true)) != NULL) { switch (cur->type) { case UCL_STRING: - val = memory_pool_strdup (cfg->cfg_pool, ucl_copy_value_trash (cur)); + val = rspamd_mempool_strdup (cfg->cfg_pool, ucl_copy_value_trash (cur)); break; case UCL_INT: - val = memory_pool_alloc (cfg->cfg_pool, num_str_len); + val = rspamd_mempool_alloc (cfg->cfg_pool, num_str_len); rspamd_snprintf (val, num_str_len, "%L", cur->value.iv); break; case UCL_FLOAT: - val = memory_pool_alloc (cfg->cfg_pool, num_str_len); + val = rspamd_mempool_alloc (cfg->cfg_pool, num_str_len); rspamd_snprintf (val, num_str_len, "%f", cur->value.dv); break; case UCL_BOOLEAN: - val = memory_pool_alloc (cfg->cfg_pool, num_str_len); + val = rspamd_mempool_alloc (cfg->cfg_pool, num_str_len); rspamd_snprintf (val, num_str_len, "%b", (gboolean)cur->value.iv); break; default: @@ -1468,7 +1468,7 @@ rspamd_rcl_parse_struct_string_list (struct config_file *cfg, const ucl_object_t } /* Add a destructor */ - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)g_list_free, *target); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_list_free, *target); return TRUE; } @@ -1506,7 +1506,7 @@ rspamd_rcl_register_worker_option (struct config_file *cfg, gint type, const gch HASH_FIND_INT (cfg->wrk_parsers, &type, nparser); if (nparser == NULL) { /* Allocate new parser for this worker */ - nparser = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_cfg_parser)); + nparser = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_cfg_parser)); nparser->type = type; HASH_ADD_INT (cfg->wrk_parsers, type, nparser); } @@ -1517,7 +1517,7 @@ rspamd_rcl_register_worker_option (struct config_file *cfg, gint type, const gch name, g_quark_to_string (type)); return; } - nhandler = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_param_parser)); + nhandler = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_param_parser)); nhandler->name = name; nhandler->parser.flags = flags; nhandler->parser.offset = offset; @@ -1535,7 +1535,7 @@ rspamd_rcl_register_worker_parser (struct config_file *cfg, gint type, HASH_FIND_INT (cfg->wrk_parsers, &type, nparser); if (nparser == NULL) { /* Allocate new parser for this worker */ - nparser = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_cfg_parser)); + nparser = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_cfg_parser)); nparser->type = type; HASH_ADD_INT (cfg->wrk_parsers, type, nparser); } diff --git a/src/cfg_utils.c b/src/cfg_utils.c index 3f31946f1..2ca846ebd 100644 --- a/src/cfg_utils.c +++ b/src/cfg_utils.c @@ -45,11 +45,11 @@ struct rspamd_ucl_map_cbdata { struct config_file *cfg; GString *buf; }; -static gchar* rspamd_ucl_read_cb (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data); -static void rspamd_ucl_fin_cb (memory_pool_t * pool, struct map_cb_data *data); +static gchar* rspamd_ucl_read_cb (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data); +static void rspamd_ucl_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data); static gboolean -parse_host_port_priority_strv (memory_pool_t *pool, gchar **tokens, +parse_host_port_priority_strv (rspamd_mempool_t *pool, gchar **tokens, gchar **addr, guint16 *port, guint *priority, guint default_port) { gchar *err_str, portbuf[8]; @@ -135,13 +135,13 @@ parse_host_port_priority_strv (memory_pool_t *pool, gchar **tokens, memcpy (&addr_holder, res->ai_addr, MIN (sizeof (addr_holder), res->ai_addrlen)); if (res->ai_family == AF_INET) { if (pool != NULL) { - *addr = memory_pool_alloc (pool, INET_ADDRSTRLEN + 1); + *addr = rspamd_mempool_alloc (pool, INET_ADDRSTRLEN + 1); } inet_ntop (res->ai_family, &addr_holder.v4.sin_addr, *addr, INET_ADDRSTRLEN + 1); } else { if (pool != NULL) { - *addr = memory_pool_alloc (pool, INET6_ADDRSTRLEN + 1); + *addr = rspamd_mempool_alloc (pool, INET6_ADDRSTRLEN + 1); } inet_ntop (res->ai_family, &addr_holder.v6.sin6_addr, *addr, INET6_ADDRSTRLEN + 1); } @@ -162,7 +162,7 @@ err: } gboolean -parse_host_port_priority (memory_pool_t *pool, const gchar *str, gchar **addr, guint16 *port, guint *priority) +parse_host_port_priority (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint16 *port, guint *priority) { gchar **tokens; gboolean ret; @@ -180,13 +180,13 @@ parse_host_port_priority (memory_pool_t *pool, const gchar *str, gchar **addr, g } gboolean -parse_host_port (memory_pool_t *pool, const gchar *str, gchar **addr, guint16 *port) +parse_host_port (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint16 *port) { return parse_host_port_priority (pool, str, addr, port, NULL); } gboolean -parse_host_priority (memory_pool_t *pool, const gchar *str, gchar **addr, guint *priority) +parse_host_priority (rspamd_mempool_t *pool, const gchar *str, gchar **addr, guint *priority) { return parse_host_port_priority (pool, str, addr, NULL, priority); } @@ -207,9 +207,9 @@ parse_bind_line (struct config_file *cfg, struct worker_conf *cf, const gchar *s return FALSE; } - cnf = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_bind_conf)); + cnf = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_bind_conf)); cnf->bind_port = DEFAULT_BIND_PORT; - cnf->bind_host = memory_pool_strdup (cfg->cfg_pool, str); + cnf->bind_host = rspamd_mempool_strdup (cfg->cfg_pool, str); cnf->ai = AF_UNSPEC; if (*tokens[0] == '/' || *tokens[0] == '.') { @@ -226,9 +226,9 @@ parse_bind_line (struct config_file *cfg, struct worker_conf *cf, const gchar *s &cnf->bind_host, &cnf->bind_port, NULL, DEFAULT_BIND_PORT))) { LL_PREPEND (cf->bind_conf, cnf); } - cnf = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_bind_conf)); + cnf = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_bind_conf)); cnf->bind_port = DEFAULT_BIND_PORT; - cnf->bind_host = memory_pool_strdup (cfg->cfg_pool, str); + cnf->bind_host = rspamd_mempool_strdup (cfg->cfg_pool, str); cnf->ai = AF_INET6; tokens[0] = "*v6"; if ((ret &= parse_host_port_priority_strv (cfg->cfg_pool, tokens, @@ -239,7 +239,7 @@ parse_bind_line (struct config_file *cfg, struct worker_conf *cf, const gchar *s } else if (strcmp (tokens[0], "systemd") == 0) { /* The actual socket will be passed by systemd environment */ - cnf->bind_host = memory_pool_strdup (cfg->cfg_pool, str); + cnf->bind_host = rspamd_mempool_strdup (cfg->cfg_pool, str); cnf->ai = strtoul (tokens[1], &err, 10); cnf->is_systemd = TRUE; if (err == NULL || *err == '\0') { @@ -333,7 +333,7 @@ free_config (struct config_file *cfg) } g_list_free (cfg->classifiers); g_list_free (cfg->metrics_list); - memory_pool_delete (cfg->cfg_pool); + rspamd_mempool_delete (cfg->cfg_pool); } const ucl_object_t * @@ -569,7 +569,7 @@ unescape_quotes (gchar *line) } GList * -parse_comma_list (memory_pool_t * pool, const gchar *line) +parse_comma_list (rspamd_mempool_t * pool, const gchar *line) { GList *res = NULL; const gchar *c, *p; @@ -580,7 +580,7 @@ parse_comma_list (memory_pool_t * pool, const gchar *line) while (*p) { if (*p == ',' && *c != *p) { - str = memory_pool_alloc (pool, p - c + 1); + str = rspamd_mempool_alloc (pool, p - c + 1); rspamd_strlcpy (str, c, p - c + 1); res = g_list_prepend (res, str); /* Skip spaces */ @@ -591,7 +591,7 @@ parse_comma_list (memory_pool_t * pool, const gchar *line) p++; } if (res != NULL) { - memory_pool_add_destructor (pool, (pool_destruct_func) g_list_free, res); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) g_list_free, res); } return res; @@ -601,15 +601,15 @@ struct classifier_config * check_classifier_conf (struct config_file *cfg, struct classifier_config *c) { if (c == NULL) { - c = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct classifier_config)); + c = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct classifier_config)); } if (c->opts == NULL) { c->opts = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func) g_hash_table_destroy, c->opts); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t) g_hash_table_destroy, c->opts); } if (c->labels == NULL) { c->labels = g_hash_table_new_full (rspamd_str_hash, rspamd_str_equal, NULL, (GDestroyNotify)g_list_free); - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func) g_hash_table_destroy, c->labels); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t) g_hash_table_destroy, c->labels); } return c; @@ -619,7 +619,7 @@ struct statfile* check_statfile_conf (struct config_file *cfg, struct statfile *c) { if (c == NULL) { - c = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct statfile)); + c = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct statfile)); } return c; @@ -630,15 +630,15 @@ check_metric_conf (struct config_file *cfg, struct metric *c) { int i; if (c == NULL) { - c = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct metric)); + c = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct metric)); c->grow_factor = 1.0; c->symbols = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); c->descriptions = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); for (i = METRIC_ACTION_REJECT; i < METRIC_ACTION_MAX; i ++) { c->actions[i].score = -1.0; } - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func) g_hash_table_destroy, c->symbols); - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func) g_hash_table_destroy, c->descriptions); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t) g_hash_table_destroy, c->symbols); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t) g_hash_table_destroy, c->descriptions); } return c; @@ -648,11 +648,11 @@ struct worker_conf * check_worker_conf (struct config_file *cfg, struct worker_conf *c) { if (c == NULL) { - c = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct worker_conf)); + c = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct worker_conf)); c->params = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); c->active_workers = g_queue_new (); - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)g_hash_table_destroy, c->params); - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)g_queue_free, c->active_workers); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_hash_table_destroy, c->params); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_queue_free, c->active_workers); #ifdef HAVE_SC_NPROCESSORS_ONLN c->count = sysconf (_SC_NPROCESSORS_ONLN); #else @@ -673,7 +673,7 @@ rspamd_include_map_handler (const guchar *data, gsize len, void* ud) struct rspamd_ucl_map_cbdata *cbdata, **pcbdata; gchar *map_line; - map_line = memory_pool_alloc (cfg->cfg_pool, len + 1); + map_line = rspamd_mempool_alloc (cfg->cfg_pool, len + 1); rspamd_strlcpy (map_line, data, len + 1); cbdata = g_malloc (sizeof (struct rspamd_ucl_map_cbdata)); @@ -882,7 +882,7 @@ check_classifier_statfiles (struct classifier_config *cf) } static gchar* -rspamd_ucl_read_cb (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) +rspamd_ucl_read_cb (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { struct rspamd_ucl_map_cbdata *cbdata = data->cur_data, *prev; @@ -900,7 +900,7 @@ rspamd_ucl_read_cb (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb } static void -rspamd_ucl_fin_cb (memory_pool_t * pool, struct map_cb_data *data) +rspamd_ucl_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data) { struct rspamd_ucl_map_cbdata *cbdata = data->cur_data, *prev = data->prev_data; ucl_object_t *obj; diff --git a/src/classifiers/bayes.c b/src/classifiers/bayes.c index dfa4f768b..405336be7 100644 --- a/src/classifiers/bayes.c +++ b/src/classifiers/bayes.c @@ -190,9 +190,9 @@ bayes_classify_callback (gpointer key, gpointer value, gpointer data) } struct classifier_ctx* -bayes_init (memory_pool_t *pool, struct classifier_config *cfg) +bayes_init (rspamd_mempool_t *pool, struct classifier_config *cfg) { - struct classifier_ctx *ctx = memory_pool_alloc (pool, sizeof (struct classifier_ctx)); + struct classifier_ctx *ctx = rspamd_mempool_alloc (pool, sizeof (struct classifier_ctx)); ctx->pool = pool; ctx->cfg = cfg; @@ -231,7 +231,7 @@ bayes_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, cur = call_classifier_pre_callbacks (ctx->cfg, task, FALSE, FALSE, L); if (cur) { - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_list_free, cur); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_list_free, cur); } else { cur = ctx->cfg->statfiles; @@ -296,7 +296,7 @@ bayes_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, if (data.processed_tokens > 0 && fabs (final_prob - 0.5) > 0.05) { - sumbuf = memory_pool_alloc (task->task_pool, 32); + sumbuf = rspamd_mempool_alloc (task->task_pool, 32); for (i = 0; i < cnt; i ++) { if ((final_prob > 0.5 && !data.statfiles[i].st->is_spam) || (final_prob < 0.5 && data.statfiles[i].st->is_spam)) { @@ -461,7 +461,7 @@ bayes_learn_spam (struct classifier_ctx* ctx, statfile_pool_t *pool, cur = call_classifier_pre_callbacks (ctx->cfg, task, TRUE, is_spam, L); if (cur) { skip_labels = FALSE; - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_list_free, cur); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_list_free, cur); } else { /* Do not try to learn specific statfiles if pre callback returned nil */ diff --git a/src/classifiers/classifiers.h b/src/classifiers/classifiers.h index fa9b60ad6..a316008cd 100644 --- a/src/classifiers/classifiers.h +++ b/src/classifiers/classifiers.h @@ -14,7 +14,7 @@ struct classifier_config; struct worker_task; struct classifier_ctx { - memory_pool_t *pool; + rspamd_mempool_t *pool; GHashTable *results; gboolean debug; struct classifier_config *cfg; @@ -28,7 +28,7 @@ struct classify_weight { /* Common classifier structure */ struct classifier { char *name; - struct classifier_ctx* (*init_func)(memory_pool_t *pool, struct classifier_config *cf); + struct classifier_ctx* (*init_func)(rspamd_mempool_t *pool, struct classifier_config *cf); gboolean (*classify_func)(struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct worker_task *task, lua_State *L); gboolean (*learn_func)(struct classifier_ctx* ctx, statfile_pool_t *pool, const char *symbol, GTree *input, gboolean in_class, @@ -42,7 +42,7 @@ struct classifier { struct classifier* get_classifier (const char *name); /* Winnow algorithm */ -struct classifier_ctx* winnow_init (memory_pool_t *pool, struct classifier_config *cf); +struct classifier_ctx* winnow_init (rspamd_mempool_t *pool, struct classifier_config *cf); gboolean winnow_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct worker_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); @@ -51,7 +51,7 @@ gboolean winnow_learn_spam (struct classifier_ctx* ctx, statfile_pool_t *pool, GList *winnow_weights (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct worker_task *task); /* Bayes algorithm */ -struct classifier_ctx* bayes_init (memory_pool_t *pool, struct classifier_config *cf); +struct classifier_ctx* bayes_init (rspamd_mempool_t *pool, struct classifier_config *cf); gboolean bayes_classify (struct classifier_ctx* ctx, statfile_pool_t *pool, GTree *input, struct worker_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); diff --git a/src/classifiers/winnow.c b/src/classifiers/winnow.c index 9568092b5..b9b5b7af9 100644 --- a/src/classifiers/winnow.c +++ b/src/classifiers/winnow.c @@ -182,9 +182,9 @@ winnow_learn_callback (gpointer key, gpointer value, gpointer data) } struct classifier_ctx * -winnow_init (memory_pool_t * pool, struct classifier_config *cfg) +winnow_init (rspamd_mempool_t * pool, struct classifier_config *cfg) { - struct classifier_ctx *ctx = memory_pool_alloc (pool, sizeof (struct classifier_ctx)); + struct classifier_ctx *ctx = rspamd_mempool_alloc (pool, sizeof (struct classifier_ctx)); ctx->pool = pool; ctx->cfg = cfg; @@ -223,7 +223,7 @@ winnow_classify (struct classifier_ctx *ctx, statfile_pool_t * pool, GTree * inp cur = call_classifier_pre_callbacks (ctx->cfg, task, FALSE, FALSE, L); if (cur) { - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_list_free, cur); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_list_free, cur); } else { cur = ctx->cfg->statfiles; @@ -272,7 +272,7 @@ winnow_classify (struct classifier_ctx *ctx, statfile_pool_t * pool, GTree * inp */ max = tanh ((double) max); #endif - sumbuf = memory_pool_alloc (task->task_pool, 32); + sumbuf = rspamd_mempool_alloc (task->task_pool, 32); rspamd_snprintf (sumbuf, 32, "%.2F", max); cur = g_list_prepend (NULL, sumbuf); insert_result (task, sel->symbol, max, cur); @@ -328,7 +328,7 @@ winnow_weights (struct classifier_ctx *ctx, statfile_pool_t * pool, GTree * inpu g_tree_foreach (input, winnow_classify_callback, &data); } - w = memory_pool_alloc0 (task->task_pool, sizeof (struct classify_weight)); + w = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct classify_weight)); if (data.count != 0) { res = data.sum / (double)data.count; } @@ -342,7 +342,7 @@ winnow_weights (struct classifier_ctx *ctx, statfile_pool_t * pool, GTree * inpu } if (resl != NULL) { - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_list_free, resl); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_list_free, resl); } return resl; diff --git a/src/controller.c b/src/controller.c index b1ba37162..01f2a6a83 100644 --- a/src/controller.c +++ b/src/controller.c @@ -215,7 +215,7 @@ free_session (void *ud) close (session->sock); - memory_pool_delete (session->session_pool); + rspamd_mempool_delete (session->session_pool); g_slice_free1 (sizeof (struct controller_session), session); } @@ -330,7 +330,7 @@ write_whole_statfile (struct controller_session *session, gchar *symbol, struct blocks = statfile_get_total_blocks (statfile); len = blocks * sizeof (struct rspamd_binlog_element); - out = memory_pool_alloc (session->session_pool, len); + out = rspamd_mempool_alloc (session->session_pool, len); for (i = 0, pos = 0; i < blocks; i ++) { stat_elt = (struct stat_file_block *)((u_char *)statfile->map + statfile->seek_pos + i * sizeof (struct stat_file_block)); @@ -508,14 +508,14 @@ process_stat_command (struct controller_session *session, gboolean do_reset) gint i; guint64 used, total, rev, ham = 0, spam = 0; time_t ti; - memory_pool_stat_t mem_st; + rspamd_mempool_stat_t mem_st; struct classifier_config *ccf; stat_file_t *statfile; struct statfile *st; GList *cur_cl, *cur_st; struct rspamd_stat *stat, stat_copy; - memory_pool_stat (&mem_st); + rspamd_mempool_stat (&mem_st); memcpy (&stat_copy, session->worker->srv->stat, sizeof (stat_copy)); stat = &stat_copy; out = g_string_sized_new (BUFSIZ); @@ -1020,7 +1020,7 @@ process_command (struct controller_command *cmd, gchar **cmd_args, struct contro return TRUE; } - session->learn_symbol = memory_pool_strdup (session->session_pool, *cmd_args); + session->learn_symbol = rspamd_mempool_strdup (session->session_pool, *cmd_args); cl = g_hash_table_lookup (session->cfg->classifiers_symbols, *cmd_args); session->learn_classifier = cl; @@ -1041,7 +1041,7 @@ process_command (struct controller_command *cmd, gchar **cmd_args, struct contro return FALSE; } } - session->learn_rcpt = memory_pool_strdup (session->session_pool, arg); + session->learn_rcpt = rspamd_mempool_strdup (session->session_pool, arg); break; case 'f': arg = *(cmd_args + 1); @@ -1051,7 +1051,7 @@ process_command (struct controller_command *cmd, gchar **cmd_args, struct contro return FALSE; } } - session->learn_from = memory_pool_strdup (session->session_pool, arg); + session->learn_from = rspamd_mempool_strdup (session->session_pool, arg); break; case 'n': session->in_class = 0; @@ -1318,7 +1318,7 @@ controller_read_socket (f_str_t * in, void *arg) s = fstrcstr (in, session->session_pool); params = g_strsplit_set (s, " ", -1); - memory_pool_add_destructor (session->session_pool, (pool_destruct_func) g_strfreev, params); + rspamd_mempool_add_destructor (session->session_pool, (rspamd_mempool_destruct_t) g_strfreev, params); len = g_strv_length (params); if (len > 0) { @@ -1758,7 +1758,7 @@ accept_socket (gint fd, short what, void *arg) new_session->sock = nfd; new_session->cfg = worker->srv->cfg; new_session->state = STATE_COMMAND; - new_session->session_pool = memory_pool_new (memory_pool_get_size () - 1); + new_session->session_pool = rspamd_mempool_new (rspamd_mempool_suggest_size () - 1); new_session->resolver = ctx->resolver; new_session->ev_base = ctx->ev_base; if (ctx->password == NULL) { @@ -1767,7 +1767,7 @@ accept_socket (gint fd, short what, void *arg) worker->srv->stat->control_connections_count++; /* Set up dispatcher */ - io_tv = memory_pool_alloc (new_session->session_pool, sizeof (struct timeval)); + io_tv = rspamd_mempool_alloc (new_session->session_pool, sizeof (struct timeval)); io_tv->tv_sec = ctx->timeout / 1000; io_tv->tv_usec = ctx->timeout - io_tv->tv_sec * 1000; diff --git a/src/dkim.c b/src/dkim.c index 67e109506..fd3807344 100644 --- a/src/dkim.c +++ b/src/dkim.c @@ -77,7 +77,7 @@ dkim_error_quark (void) static gboolean rspamd_dkim_parse_signature (rspamd_dkim_context_t* ctx, const gchar *param, gsize len, GError **err) { - ctx->b = memory_pool_alloc (ctx->pool, len + 1); + ctx->b = rspamd_mempool_alloc (ctx->pool, len + 1); rspamd_strlcpy (ctx->b, param, len + 1); #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 20)) gchar *tmp; @@ -115,7 +115,7 @@ rspamd_dkim_parse_signalg (rspamd_dkim_context_t* ctx, const gchar *param, gsize static gboolean rspamd_dkim_parse_domain (rspamd_dkim_context_t* ctx, const gchar *param, gsize len, GError **err) { - ctx->domain = memory_pool_alloc (ctx->pool, len + 1); + ctx->domain = rspamd_mempool_alloc (ctx->pool, len + 1); rspamd_strlcpy (ctx->domain, param, len + 1); return TRUE; } @@ -186,7 +186,7 @@ rspamd_dkim_parse_ignore (rspamd_dkim_context_t* ctx, const gchar *param, gsize static gboolean rspamd_dkim_parse_selector (rspamd_dkim_context_t* ctx, const gchar *param, gsize len, GError **err) { - ctx->selector = memory_pool_alloc (ctx->pool, len + 1); + ctx->selector = rspamd_mempool_alloc (ctx->pool, len + 1); rspamd_strlcpy (ctx->selector, param, len + 1); return TRUE; } @@ -248,8 +248,8 @@ rspamd_dkim_parse_hdrlist (rspamd_dkim_context_t* ctx, const gchar *param, gsize } else { /* Insert new header to the list */ - new = memory_pool_alloc (ctx->pool, sizeof (struct rspamd_dkim_header)); - h = memory_pool_alloc (ctx->pool, p - c + 1); + new = rspamd_mempool_alloc (ctx->pool, sizeof (struct rspamd_dkim_header)); + h = rspamd_mempool_alloc (ctx->pool, p - c + 1); rspamd_strlcpy (h, c, p - c + 1); g_strstrip (h); new->name = h; @@ -279,7 +279,7 @@ rspamd_dkim_parse_hdrlist (rspamd_dkim_context_t* ctx, const gchar *param, gsize return FALSE; } /* Reverse list */ - memory_pool_add_destructor (ctx->pool, (pool_destruct_func)rspamd_dkim_hlist_free, ctx->hlist); + rspamd_mempool_add_destructor (ctx->pool, (rspamd_mempool_destruct_t)rspamd_dkim_hlist_free, ctx->hlist); } return TRUE; @@ -328,7 +328,7 @@ rspamd_dkim_parse_expiration (rspamd_dkim_context_t* ctx, const gchar *param, gs static gboolean rspamd_dkim_parse_bodyhash (rspamd_dkim_context_t* ctx, const gchar *param, gsize len, GError **err) { - ctx->bh = memory_pool_alloc (ctx->pool, len + 1); + ctx->bh = rspamd_mempool_alloc (ctx->pool, len + 1); rspamd_strlcpy (ctx->bh, param, len + 1); #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 20)) gchar *tmp; @@ -365,7 +365,7 @@ rspamd_dkim_parse_bodylength (rspamd_dkim_context_t* ctx, const gchar *param, gs * @return new context or NULL */ rspamd_dkim_context_t* -rspamd_create_dkim_context (const gchar *sig, memory_pool_t *pool, guint time_jitter, GError **err) +rspamd_create_dkim_context (const gchar *sig, rspamd_mempool_t *pool, guint time_jitter, GError **err) { const gchar *p, *c, *tag = NULL, *end; gsize taglen; @@ -381,7 +381,7 @@ rspamd_create_dkim_context (const gchar *sig, memory_pool_t *pool, guint time_ji } state, next_state; - new = memory_pool_alloc0 (pool, sizeof (rspamd_dkim_context_t)); + new = rspamd_mempool_alloc0 (pool, sizeof (rspamd_dkim_context_t)); new->pool = pool; new->header_canon_type = DKIM_CANON_DEFAULT; new->body_canon_type = DKIM_CANON_DEFAULT; @@ -604,7 +604,7 @@ rspamd_create_dkim_context (const gchar *sig, memory_pool_t *pool, guint time_ji /* Now create dns key to request further */ taglen = strlen (new->domain) + strlen (new->selector) + sizeof (DKIM_DNSKEYNAME) + 2; - new->dns_key = memory_pool_alloc (new->pool, taglen); + new->dns_key = rspamd_mempool_alloc (new->pool, taglen); rspamd_snprintf (new->dns_key, taglen, "%s.%s.%s", new->selector, DKIM_DNSKEYNAME, new->domain); /* Create checksums for further operations */ @@ -621,8 +621,8 @@ rspamd_create_dkim_context (const gchar *sig, memory_pool_t *pool, guint time_ji return NULL; } - memory_pool_add_destructor (new->pool, (pool_destruct_func)g_checksum_free, new->body_hash); - memory_pool_add_destructor (new->pool, (pool_destruct_func)g_checksum_free, new->headers_hash); + rspamd_mempool_add_destructor (new->pool, (rspamd_mempool_destruct_t)g_checksum_free, new->body_hash); + rspamd_mempool_add_destructor (new->pool, (rspamd_mempool_destruct_t)g_checksum_free, new->headers_hash); return new; } @@ -797,7 +797,7 @@ rspamd_get_dkim_key (rspamd_dkim_context_t *ctx, struct rspamd_dns_resolver *res g_return_val_if_fail (ctx != NULL, FALSE); g_return_val_if_fail (ctx->dns_key != NULL, FALSE); - cbdata = memory_pool_alloc (ctx->pool, sizeof (struct rspamd_dkim_key_cbdata)); + cbdata = rspamd_mempool_alloc (ctx->pool, sizeof (struct rspamd_dkim_key_cbdata)); cbdata->ctx = ctx; cbdata->handler = handler; cbdata->ud = ud; diff --git a/src/dkim.h b/src/dkim.h index e49b9c479..897c65fef 100644 --- a/src/dkim.h +++ b/src/dkim.h @@ -131,7 +131,7 @@ #define DKIM_RECORD_ERROR 4 /* error requesting record */ typedef struct rspamd_dkim_context_s { - memory_pool_t *pool; + rspamd_mempool_t *pool; gint sig_alg; gint header_canon_type; gint body_canon_type; @@ -177,7 +177,7 @@ typedef void (*dkim_key_handler_f)(rspamd_dkim_key_t *key, gsize keylen, rspamd_ * @param err pointer to error object * @return new context or NULL */ -rspamd_dkim_context_t* rspamd_create_dkim_context (const gchar *sig, memory_pool_t *pool, guint time_jitter, GError **err); +rspamd_dkim_context_t* rspamd_create_dkim_context (const gchar *sig, rspamd_mempool_t *pool, guint time_jitter, GError **err); /** * Make DNS request for specified context and obtain and parse key @@ -64,13 +64,13 @@ rspamd_dns_callback (struct rdns_reply *reply, gpointer ud) gboolean make_dns_request (struct rspamd_dns_resolver *resolver, - struct rspamd_async_session *session, memory_pool_t *pool, dns_callback_type cb, + struct rspamd_async_session *session, rspamd_mempool_t *pool, dns_callback_type cb, gpointer ud, enum rdns_request_type type, const char *name) { struct rdns_request *req; struct rspamd_dns_request_ud *reqdata; - reqdata = memory_pool_alloc (pool, sizeof (struct rspamd_dns_request_ud)); + reqdata = rspamd_mempool_alloc (pool, sizeof (struct rspamd_dns_request_ud)); reqdata->session = session; reqdata->cb = cb; reqdata->ud = ud; @@ -54,7 +54,7 @@ struct rspamd_dns_resolver *dns_resolver_init (rspamd_logger_t *logger, * @return TRUE if request was sent. */ gboolean make_dns_request (struct rspamd_dns_resolver *resolver, - struct rspamd_async_session *session, memory_pool_t *pool, + struct rspamd_async_session *session, rspamd_mempool_t *pool, dns_callback_type cb, gpointer ud, enum rdns_request_type type, const char *name); #endif diff --git a/src/dynamic_cfg.c b/src/dynamic_cfg.c index 970fcea16..7f5e8530d 100644 --- a/src/dynamic_cfg.c +++ b/src/dynamic_cfg.c @@ -139,7 +139,7 @@ apply_dynamic_conf (GList *conf_metrics, struct config_file *cfg) /* Callbacks for reading json dynamic rules */ gchar * -json_config_read_cb (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) +json_config_read_cb (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { struct config_json_buf *jb; gint free, off; @@ -180,7 +180,7 @@ json_config_read_cb (memory_pool_t * pool, gchar * chunk, gint len, struct map_c } void -json_config_fin_cb (memory_pool_t * pool, struct map_cb_data *data) +json_config_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data) { struct config_json_buf *jb; guint nelts, i, j, selts; diff --git a/src/events.c b/src/events.c index 711c3b24d..85843fd05 100644 --- a/src/events.c +++ b/src/events.c @@ -65,12 +65,12 @@ event_cond_free (gpointer data) #endif struct rspamd_async_session * -new_async_session (memory_pool_t * pool, session_finalizer_t fin, +new_async_session (rspamd_mempool_t * pool, session_finalizer_t fin, event_finalizer_t restore, event_finalizer_t cleanup, void *user_data) { struct rspamd_async_session *new; - new = memory_pool_alloc (pool, sizeof (struct rspamd_async_session)); + new = rspamd_mempool_alloc (pool, sizeof (struct rspamd_async_session)); new->pool = pool; new->fin = fin; new->restore = restore; @@ -81,19 +81,19 @@ new_async_session (memory_pool_t * pool, session_finalizer_t fin, #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30)) new->mtx = g_mutex_new (); new->cond = g_cond_new (); - memory_pool_add_destructor (pool, (pool_destruct_func) event_mutex_free, new->mtx); - memory_pool_add_destructor (pool, (pool_destruct_func) event_cond_free, new->cond); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) event_mutex_free, new->mtx); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) event_cond_free, new->cond); #else - new->mtx = memory_pool_alloc (pool, sizeof (GMutex)); + new->mtx = rspamd_mempool_alloc (pool, sizeof (GMutex)); g_mutex_init (new->mtx); - new->cond = memory_pool_alloc (pool, sizeof (GCond)); + new->cond = rspamd_mempool_alloc (pool, sizeof (GCond)); g_cond_init (new->cond); - memory_pool_add_destructor (pool, (pool_destruct_func) g_mutex_clear, new->mtx); - memory_pool_add_destructor (pool, (pool_destruct_func) g_cond_clear, new->cond); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) g_mutex_clear, new->mtx); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) g_cond_clear, new->cond); #endif new->threads = 0; - memory_pool_add_destructor (pool, (pool_destruct_func) g_hash_table_destroy, new->events); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) g_hash_table_destroy, new->events); return new; } @@ -109,7 +109,7 @@ register_async_event (struct rspamd_async_session *session, event_finalizer_t fi } g_mutex_lock (session->mtx); - new = memory_pool_alloc (session->pool, sizeof (struct rspamd_async_event)); + new = rspamd_mempool_alloc (session->pool, sizeof (struct rspamd_async_event)); new->fin = fin; new->user_data = user_data; new->subsystem = subsystem; diff --git a/src/events.h b/src/events.h index 1329d5837..072a243da 100644 --- a/src/events.h +++ b/src/events.h @@ -21,7 +21,7 @@ struct rspamd_async_session { event_finalizer_t cleanup; GHashTable *events; void *user_data; - memory_pool_t *pool; + rspamd_mempool_t *pool; gboolean wanna_die; guint threads; GMutex *mtx; @@ -37,7 +37,7 @@ struct rspamd_async_session { * @param user_data abstract user data * @return */ -struct rspamd_async_session *new_async_session (memory_pool_t *pool, +struct rspamd_async_session *new_async_session (rspamd_mempool_t *pool, session_finalizer_t fin, event_finalizer_t restore, event_finalizer_t cleanup, void *user_data); diff --git a/src/expressions.c b/src/expressions.c index f63ec2d74..8642251da 100644 --- a/src/expressions.c +++ b/src/expressions.c @@ -80,41 +80,41 @@ fl_cmp (const void *s1, const void *s2) /* Cache for regular expressions that are used in functions */ void * -re_cache_check (const gchar *line, memory_pool_t *pool) +re_cache_check (const gchar *line, rspamd_mempool_t *pool) { GHashTable *re_cache; - re_cache = memory_pool_get_variable (pool, "re_cache"); + re_cache = rspamd_mempool_get_variable (pool, "re_cache"); if (re_cache == NULL) { re_cache = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); - memory_pool_set_variable (pool, "re_cache", re_cache, (pool_destruct_func)g_hash_table_destroy); + rspamd_mempool_set_variable (pool, "re_cache", re_cache, (rspamd_mempool_destruct_t)g_hash_table_destroy); return NULL; } return g_hash_table_lookup (re_cache, line); } void -re_cache_add (const gchar *line, void *pointer, memory_pool_t *pool) +re_cache_add (const gchar *line, void *pointer, rspamd_mempool_t *pool) { GHashTable *re_cache; - re_cache = memory_pool_get_variable (pool, "re_cache"); + re_cache = rspamd_mempool_get_variable (pool, "re_cache"); if (re_cache == NULL) { re_cache = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); - memory_pool_set_variable (pool, "re_cache", re_cache, (pool_destruct_func)g_hash_table_destroy); + rspamd_mempool_set_variable (pool, "re_cache", re_cache, (rspamd_mempool_destruct_t)g_hash_table_destroy); } g_hash_table_insert (re_cache, (gpointer)line, pointer); } void -re_cache_del (const gchar *line, memory_pool_t *pool) +re_cache_del (const gchar *line, rspamd_mempool_t *pool) { GHashTable *re_cache; - re_cache = memory_pool_get_variable (pool, "re_cache"); + re_cache = rspamd_mempool_get_variable (pool, "re_cache"); if (re_cache != NULL) { g_hash_table_remove (re_cache, line); @@ -134,10 +134,10 @@ struct expression_stack { * Push operand or operator to stack */ static struct expression_stack * -push_expression_stack (memory_pool_t * pool, struct expression_stack *head, gchar op) +push_expression_stack (rspamd_mempool_t * pool, struct expression_stack *head, gchar op) { struct expression_stack *new; - new = memory_pool_alloc (pool, sizeof (struct expression_stack)); + new = rspamd_mempool_alloc (pool, sizeof (struct expression_stack)); new->op = op; new->next = head; return new; @@ -284,11 +284,11 @@ is_regexp_flag (gchar a) } static void -insert_expression (memory_pool_t * pool, struct expression **head, gint type, gchar op, void *operand, const gchar *orig) +insert_expression (rspamd_mempool_t * pool, struct expression **head, gint type, gchar op, void *operand, const gchar *orig) { struct expression *new, *cur; - new = memory_pool_alloc (pool, sizeof (struct expression)); + new = rspamd_mempool_alloc (pool, sizeof (struct expression)); new->type = type; new->orig = orig; if (new->type != EXPR_OPERATION) { @@ -312,7 +312,7 @@ insert_expression (memory_pool_t * pool, struct expression **head, gint type, gc } static struct expression * -maybe_parse_expression (memory_pool_t * pool, gchar *line) +maybe_parse_expression (rspamd_mempool_t * pool, gchar *line) { struct expression *expr; gchar *p = line; @@ -324,9 +324,9 @@ maybe_parse_expression (memory_pool_t * pool, gchar *line) p++; } - expr = memory_pool_alloc (pool, sizeof (struct expression)); + expr = rspamd_mempool_alloc (pool, sizeof (struct expression)); expr->type = EXPR_STR; - expr->content.operand = memory_pool_strdup (pool, line); + expr->content.operand = rspamd_mempool_strdup (pool, line); expr->next = NULL; return expr; @@ -337,7 +337,7 @@ maybe_parse_expression (memory_pool_t * pool, gchar *line) * Memory is allocated from given pool */ struct expression * -parse_expression (memory_pool_t * pool, gchar *line) +parse_expression (rspamd_mempool_t * pool, gchar *line) { struct expression *expr = NULL; struct expression_stack *stack = NULL; @@ -364,7 +364,7 @@ parse_expression (memory_pool_t * pool, gchar *line) msg_debug ("parsing expression {{ %s }}", line); function_stack = g_queue_new (); - copy = memory_pool_strdup (pool, line); + copy = rspamd_mempool_strdup (pool, line); p = line; c = p; while (*p) { @@ -462,7 +462,7 @@ parse_expression (memory_pool_t * pool, gchar *line) if ((is_regexp_flag (*p) || *p == '/') && *(p + 1) == '\0') { p++; } - str = memory_pool_alloc (pool, p - c + 2); + str = rspamd_mempool_alloc (pool, p - c + 2); rspamd_strlcpy (str, c - 1, (p - c + 2)); g_strstrip (str); msg_debug ("found regexp: %s", str); @@ -486,8 +486,8 @@ parse_expression (memory_pool_t * pool, gchar *line) p++; } else if (*p == '(') { - func = memory_pool_alloc (pool, sizeof (struct expression_function)); - func->name = memory_pool_alloc (pool, p - c + 1); + func = rspamd_mempool_alloc (pool, sizeof (struct expression_function)); + func->name = rspamd_mempool_alloc (pool, p - c + 1); func->args = NULL; rspamd_strlcpy (func->name, c, (p - c + 1)); g_strstrip (func->name); @@ -499,7 +499,7 @@ parse_expression (memory_pool_t * pool, gchar *line) else if (is_operation_symbol (p)) { /* In fact it is not function, but symbol */ if (c != p) { - str = memory_pool_alloc (pool, p - c + 1); + str = rspamd_mempool_alloc (pool, p - c + 1); rspamd_strlcpy (str, c, (p - c + 1)); g_strstrip (str); if (strlen (str) > 0) { @@ -512,7 +512,7 @@ parse_expression (memory_pool_t * pool, gchar *line) /* In fact it is not function, but symbol */ p++; if (c != p) { - str = memory_pool_alloc (pool, p - c + 1); + str = rspamd_mempool_alloc (pool, p - c + 1); rspamd_strlcpy (str, c, (p - c + 1)); g_strstrip (str); if (strlen (str) > 0) { @@ -535,7 +535,7 @@ parse_expression (memory_pool_t * pool, gchar *line) /* Append argument to list */ if (*p == ',' || (*p == ')' && brackets == 0)) { arg = NULL; - str = memory_pool_alloc (pool, p - c + 1); + str = rspamd_mempool_alloc (pool, p - c + 1); rspamd_strlcpy (str, c, (p - c + 1)); g_strstrip (str); /* Recursive call */ @@ -587,7 +587,7 @@ parse_expression (memory_pool_t * pool, gchar *line) * Rspamd regexp utility functions */ struct rspamd_regexp * -parse_regexp (memory_pool_t * pool, const gchar *line, gboolean raw_mode) +parse_regexp (rspamd_mempool_t * pool, const gchar *line, gboolean raw_mode) { const gchar *begin, *end, *p, *src, *start; gchar *dbegin, *dend; @@ -601,7 +601,7 @@ parse_regexp (memory_pool_t * pool, const gchar *line, gboolean raw_mode) } src = line; - result = memory_pool_alloc0 (pool, sizeof (struct rspamd_regexp)); + result = rspamd_mempool_alloc0 (pool, sizeof (struct rspamd_regexp)); /* Skip whitespaces */ while (g_ascii_isspace (*line)) { line++; @@ -624,14 +624,14 @@ parse_regexp (memory_pool_t * pool, const gchar *line, gboolean raw_mode) p --; } if (end) { - result->header = memory_pool_alloc (pool, end - line + 1); + result->header = rspamd_mempool_alloc (pool, end - line + 1); rspamd_strlcpy (result->header, line, end - line + 1); result->type = REGEXP_HEADER; line = end; } } else { - result->header = memory_pool_strdup (pool, line); + result->header = rspamd_mempool_strdup (pool, line); result->type = REGEXP_HEADER; line = start; } @@ -644,7 +644,7 @@ parse_regexp (memory_pool_t * pool, const gchar *line, gboolean raw_mode) } else if (result->header == NULL) { /* Assume that line without // is just a header name */ - result->header = memory_pool_strdup (pool, line); + result->header = rspamd_mempool_strdup (pool, line); result->type = REGEXP_HEADER; return result; } @@ -741,7 +741,7 @@ parse_regexp (memory_pool_t * pool, const gchar *line, gboolean raw_mode) } } - result->regexp_text = memory_pool_strdup (pool, start); + result->regexp_text = rspamd_mempool_strdup (pool, start); dbegin = result->regexp_text + (begin - start); dend = result->regexp_text + (end - start); *dend = '\0'; @@ -770,9 +770,9 @@ parse_regexp (memory_pool_t * pool, const gchar *line, gboolean raw_mode) } else { result->raw_regexp = g_regex_new (dbegin, regexp_flags | G_REGEX_RAW, 0, &err); - memory_pool_add_destructor (pool, (pool_destruct_func) g_regex_unref, (void *)result->raw_regexp); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) g_regex_unref, (void *)result->raw_regexp); } - memory_pool_add_destructor (pool, (pool_destruct_func) g_regex_unref, (void *)result->regexp); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) g_regex_unref, (void *)result->regexp); *dend = '/'; @@ -820,7 +820,7 @@ get_function_arg (struct expression *expr, struct worker_task *task, gboolean wa return NULL; } if (expr->next == NULL) { - res = memory_pool_alloc (task->task_pool, sizeof (struct expression_argument)); + res = rspamd_mempool_alloc (task->task_pool, sizeof (struct expression_argument)); if (expr->type == EXPR_REGEXP || expr->type == EXPR_STR || expr->type == EXPR_REGEXP_PARSED) { res->type = EXPRESSION_ARGUMENT_NORMAL; res->data = expr->content.operand; @@ -837,7 +837,7 @@ get_function_arg (struct expression *expr, struct worker_task *task, gboolean wa return res; } else if (!want_string) { - res = memory_pool_alloc (task->task_pool, sizeof (struct expression_argument)); + res = rspamd_mempool_alloc (task->task_pool, sizeof (struct expression_argument)); res->type = EXPRESSION_ARGUMENT_BOOL; stack = g_queue_new (); it = expr; @@ -1005,7 +1005,7 @@ rspamd_parts_distance (struct worker_task * task, GList * args, void *unused) } } - if ((pdiff = memory_pool_get_variable (task->task_pool, "parts_distance")) != NULL) { + if ((pdiff = rspamd_mempool_get_variable (task->task_pool, "parts_distance")) != NULL) { diff = *pdiff; if (diff != -1) { if (threshold2 > 0) { @@ -1029,7 +1029,7 @@ rspamd_parts_distance (struct worker_task * task, GList * args, void *unused) cur = g_list_first (task->text_parts); p1 = cur->data; cur = g_list_next (cur); - pdiff = memory_pool_alloc (task->task_pool, sizeof (gint)); + pdiff = rspamd_mempool_alloc (task->task_pool, sizeof (gint)); *pdiff = -1; if (cur == NULL) { @@ -1047,13 +1047,13 @@ rspamd_parts_distance (struct worker_task * task, GList * args, void *unused) if (ct == NULL || ! g_mime_content_type_is_type ((GMimeContentType *)ct, "multipart", "alternative")) { #endif debug_task ("two parts are not belong to multipart/alternative container, skip check"); - memory_pool_set_variable (task->task_pool, "parts_distance", pdiff, NULL); + rspamd_mempool_set_variable (task->task_pool, "parts_distance", pdiff, NULL); return FALSE; } } else { debug_task ("message contains two parts but they are in different multi-parts"); - memory_pool_set_variable (task->task_pool, "parts_distance", pdiff, NULL); + rspamd_mempool_set_variable (task->task_pool, "parts_distance", pdiff, NULL); return FALSE; } if (!p1->is_empty && !p2->is_empty) { @@ -1065,7 +1065,7 @@ rspamd_parts_distance (struct worker_task * task, GList * args, void *unused) } debug_task ("got likeliness between parts of %d%%, threshold is %d%%", diff, threshold); *pdiff = diff; - memory_pool_set_variable (task->task_pool, "parts_distance", pdiff, NULL); + rspamd_mempool_set_variable (task->task_pool, "parts_distance", pdiff, NULL); if (threshold2 > 0) { if (diff >= MIN (threshold, threshold2) && diff < MAX (threshold, threshold2)) { return TRUE; @@ -1080,17 +1080,17 @@ rspamd_parts_distance (struct worker_task * task, GList * args, void *unused) else if ((p1->is_empty && !p2->is_empty) || (!p1->is_empty && p2->is_empty)) { /* Empty and non empty parts are different */ *pdiff = 0; - memory_pool_set_variable (task->task_pool, "parts_distance", pdiff, NULL); + rspamd_mempool_set_variable (task->task_pool, "parts_distance", pdiff, NULL); return TRUE; } } else { debug_task ("message has too many text parts, so do not try to compare them with each other"); - memory_pool_set_variable (task->task_pool, "parts_distance", pdiff, NULL); + rspamd_mempool_set_variable (task->task_pool, "parts_distance", pdiff, NULL); return FALSE; } - memory_pool_set_variable (task->task_pool, "parts_distance", pdiff, NULL); + rspamd_mempool_set_variable (task->task_pool, "parts_distance", pdiff, NULL); return FALSE; } @@ -1133,14 +1133,14 @@ rspamd_recipients_distance (struct worker_task *task, GList * args, void *unused if (num < MIN_RCPT_TO_COMPARE) { return FALSE; } - ar = memory_pool_alloc0 (task->task_pool, num * sizeof (struct addr_list)); + ar = rspamd_mempool_alloc0 (task->task_pool, num * sizeof (struct addr_list)); /* Fill array */ cur = task->rcpts; #ifdef GMIME24 for (i = 0; i < num; i ++) { addr = internet_address_list_get_address (cur, i); - ar[i].name = memory_pool_strdup (task->task_pool, internet_address_get_name (addr)); + ar[i].name = rspamd_mempool_strdup (task->task_pool, internet_address_get_name (addr)); if (ar[i].name != NULL && (c = strchr (ar[i].name, '@')) != NULL) { *c = '\0'; ar[i].addr = c + 1; @@ -1151,7 +1151,7 @@ rspamd_recipients_distance (struct worker_task *task, GList * args, void *unused while (cur) { addr = internet_address_list_get_address (cur); if (addr && internet_address_get_type (addr) == INTERNET_ADDRESS_NAME) { - ar[i].name = memory_pool_strdup (task->task_pool, internet_address_get_addr (addr)); + ar[i].name = rspamd_mempool_strdup (task->task_pool, internet_address_get_addr (addr)); if (ar[i].name != NULL && (c = strchr (ar[i].name, '@')) != NULL) { *c = '\0'; ar[i].addr = c + 1; diff --git a/src/expressions.h b/src/expressions.h index da55c250c..526af8686 100644 --- a/src/expressions.h +++ b/src/expressions.h @@ -59,7 +59,7 @@ typedef gboolean (*rspamd_internal_func_t)(struct worker_task *, GList *args, vo * @param line incoming line * @return regexp structure or NULL in case of error */ -struct rspamd_regexp* parse_regexp (memory_pool_t *pool, const gchar *line, gboolean raw_mode); +struct rspamd_regexp* parse_regexp (rspamd_mempool_t *pool, const gchar *line, gboolean raw_mode); /** * Parse composites line to composites structure (eg. "SYMBOL1&SYMBOL2|!SYMBOL3") @@ -67,7 +67,7 @@ struct rspamd_regexp* parse_regexp (memory_pool_t *pool, const gchar *line, gboo * @param line incoming line * @return expression structure or NULL in case of error */ -struct expression* parse_expression (memory_pool_t *pool, gchar *line); +struct expression* parse_expression (rspamd_mempool_t *pool, gchar *line); /** * Call specified fucntion and return boolean result @@ -90,20 +90,20 @@ void register_expression_function (const gchar *name, rspamd_internal_func_t fun * @param line symbolic representation * @param pointer regexp data */ -void re_cache_add (const gchar *line, void *pointer, memory_pool_t *pool); +void re_cache_add (const gchar *line, void *pointer, rspamd_mempool_t *pool); /** * Check regexp in cache * @param line symbolic representation * @return pointer to regexp data or NULL if regexp is not found */ -void * re_cache_check (const gchar *line, memory_pool_t *pool); +void * re_cache_check (const gchar *line, rspamd_mempool_t *pool); /** * Remove regexp from regexp cache * @param line symbolic representation */ -void re_cache_del (const gchar *line, memory_pool_t *pool); +void re_cache_del (const gchar *line, rspamd_mempool_t *pool); /** * Add regexp to regexp task cache diff --git a/src/filter.c b/src/filter.c index 311a9aa25..d5e430e38 100644 --- a/src/filter.c +++ b/src/filter.c @@ -74,10 +74,10 @@ insert_metric_result (struct worker_task *task, struct metric *metric, const gch if (metric_res == NULL) { /* Create new metric chain */ - metric_res = memory_pool_alloc (task->task_pool, sizeof (struct metric_result)); + metric_res = rspamd_mempool_alloc (task->task_pool, sizeof (struct metric_result)); metric_res->symbols = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); metric_res->checked = FALSE; - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_hash_table_unref, metric_res->symbols); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_hash_table_unref, metric_res->symbols); metric_res->metric = metric; metric_res->grow_factor = 0; metric_res->score = 0; @@ -108,7 +108,7 @@ insert_metric_result (struct worker_task *task, struct metric *metric, const gch } else if (opts) { s->options = g_list_copy (opts); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_list_free, s->options); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_list_free, s->options); } if (!single) { /* Handle grow factor */ @@ -128,7 +128,7 @@ insert_metric_result (struct worker_task *task, struct metric *metric, const gch } } else { - s = memory_pool_alloc (task->task_pool, sizeof (struct symbol)); + s = rspamd_mempool_alloc (task->task_pool, sizeof (struct symbol)); /* Handle grow factor */ if (metric_res->grow_factor && w > 0) { @@ -145,7 +145,7 @@ insert_metric_result (struct worker_task *task, struct metric *metric, const gch if (opts) { s->options = g_list_copy (opts); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_list_free, s->options); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_list_free, s->options); } else { s->options = NULL; @@ -426,7 +426,7 @@ composites_foreach_callback (gpointer key, gpointer value, void *data) } if (ms != NULL) { - rd = memory_pool_alloc (cd->task->task_pool, sizeof (struct symbol_remove_data)); + rd = rspamd_mempool_alloc (cd->task->task_pool, sizeof (struct symbol_remove_data)); rd->ms = ms; if (G_UNLIKELY (*sym == '~')) { rd->remove_weight = FALSE; @@ -558,13 +558,13 @@ static void composites_metric_callback (gpointer key, gpointer value, gpointer data) { struct worker_task *task = (struct worker_task *)data; - struct composites_data *cd = memory_pool_alloc (task->task_pool, sizeof (struct composites_data)); + struct composites_data *cd = rspamd_mempool_alloc (task->task_pool, sizeof (struct composites_data)); struct metric_result *metric_res = (struct metric_result *)value; cd->task = task; cd->metric_res = (struct metric_result *)metric_res; cd->symbols_to_remove = g_tree_new (remove_compare_data); - cd->checked = memory_pool_alloc0 (task->task_pool, NBYTES (g_hash_table_size (task->cfg->composite_symbols))); + cd->checked = rspamd_mempool_alloc0 (task->task_pool, NBYTES (g_hash_table_size (task->cfg->composite_symbols))); /* Process hash table */ g_hash_table_foreach (task->cfg->composite_symbols, composites_foreach_callback, cd); @@ -607,12 +607,12 @@ classifiers_callback (gpointer value, void *arg) if ((header = g_hash_table_lookup (cl->opts, "header")) != NULL) { cur = message_get_header (task->task_pool, task->message, header, FALSE); if (cur) { - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_list_free, cur); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_list_free, cur); } } else { cur = g_list_first (task->text_parts); - dist = memory_pool_get_variable (task->task_pool, "parts_distance"); + dist = rspamd_mempool_get_variable (task->task_pool, "parts_distance"); if (cur != NULL && cur->next != NULL && cur->next->next == NULL) { is_twopart = TRUE; } @@ -716,7 +716,7 @@ process_statfiles (struct worker_task *task) if (task->tokens == NULL) { task->tokens = g_hash_table_new (g_direct_hash, g_direct_equal); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_hash_table_unref, task->tokens); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_hash_table_unref, task->tokens); } cbdata.task = task; cbdata.nL = NULL; @@ -740,7 +740,7 @@ process_statfiles_threaded (gpointer data, gpointer user_data) if (task->tokens == NULL) { task->tokens = g_hash_table_new (g_direct_hash, g_direct_equal); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_hash_table_unref, task->tokens); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_hash_table_unref, task->tokens); } cbdata.task = task; @@ -905,7 +905,7 @@ learn_task (const gchar *statfile, struct worker_task *task, GError **err) if ((s = g_hash_table_lookup (cl->opts, "header")) != NULL) { cur = message_get_header (task->task_pool, task->message, s, FALSE); if (cur) { - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_list_free, cur); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_list_free, cur); } } else { diff --git a/src/fstring.c b/src/fstring.c index 8028d15a3..098824101 100644 --- a/src/fstring.c +++ b/src/fstring.c @@ -213,10 +213,10 @@ fstrcat (f_str_t * dest, f_str_t * src) * Make copy of string to 0-terminated string */ gchar * -fstrcstr (f_str_t * str, memory_pool_t * pool) +fstrcstr (f_str_t * str, rspamd_mempool_t * pool) { gchar *res; - res = memory_pool_alloc (pool, str->len + 1); + res = rspamd_mempool_alloc (pool, str->len + 1); /* Do not allow multiply \0 characters */ memccpy (res, str->begin, '\0', str->len); @@ -262,11 +262,11 @@ fstrpush_unichar (f_str_t * dest, gunichar c) * Allocate memory for f_str_t */ f_str_t * -fstralloc (memory_pool_t * pool, size_t len) +fstralloc (rspamd_mempool_t * pool, size_t len) { - f_str_t *res = memory_pool_alloc (pool, sizeof (f_str_t)); + f_str_t *res = rspamd_mempool_alloc (pool, sizeof (f_str_t)); - res->begin = memory_pool_alloc (pool, len); + res->begin = rspamd_mempool_alloc (pool, len); res->size = len; res->len = 0; @@ -277,11 +277,11 @@ fstralloc (memory_pool_t * pool, size_t len) * Allocate memory for f_str_t from temporary pool */ f_str_t * -fstralloc_tmp (memory_pool_t * pool, size_t len) +fstralloc_tmp (rspamd_mempool_t * pool, size_t len) { - f_str_t *res = memory_pool_alloc_tmp (pool, sizeof (f_str_t)); + f_str_t *res = rspamd_mempool_alloc_tmp (pool, sizeof (f_str_t)); - res->begin = memory_pool_alloc_tmp (pool, len); + res->begin = rspamd_mempool_alloc_tmp (pool, len); res->size = len; res->len = 0; @@ -292,7 +292,7 @@ fstralloc_tmp (memory_pool_t * pool, size_t len) * Truncate string to its len */ f_str_t * -fstrtruncate (memory_pool_t * pool, f_str_t * orig) +fstrtruncate (rspamd_mempool_t * pool, f_str_t * orig) { f_str_t *res; @@ -313,7 +313,7 @@ fstrtruncate (memory_pool_t * pool, f_str_t * orig) * Enlarge string to new size */ f_str_t * -fstrgrow (memory_pool_t * pool, f_str_t * orig, size_t newlen) +fstrgrow (rspamd_mempool_t * pool, f_str_t * orig, size_t newlen) { f_str_t *res; diff --git a/src/fstring.h b/src/fstring.h index c55c3627a..bd680e365 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -76,22 +76,22 @@ gint fstrpush_unichar (f_str_t *dest, gunichar c); /* * Allocate memory for f_str_t */ -f_str_t* fstralloc (memory_pool_t *pool, size_t len); +f_str_t* fstralloc (rspamd_mempool_t *pool, size_t len); /* * Allocate memory for f_str_t from temporary pool */ -f_str_t* fstralloc_tmp (memory_pool_t *pool, size_t len); +f_str_t* fstralloc_tmp (rspamd_mempool_t *pool, size_t len); /* * Truncate string to its len */ -f_str_t* fstrtruncate (memory_pool_t *pool, f_str_t *orig); +f_str_t* fstrtruncate (rspamd_mempool_t *pool, f_str_t *orig); /* * Enlarge string to new size */ -f_str_t* fstrgrow (memory_pool_t *pool, f_str_t *orig, size_t newlen); +f_str_t* fstrgrow (rspamd_mempool_t *pool, f_str_t *orig, size_t newlen); /* * Return specified character @@ -110,7 +110,7 @@ guint32 fstrhash_lowercase (f_str_t *str, gboolean is_utf); /* * Make copy of string to 0-terminated string */ -gchar* fstrcstr (f_str_t *str, memory_pool_t *pool); +gchar* fstrcstr (f_str_t *str, rspamd_mempool_t *pool); /* * Strip fstr string from space symbols diff --git a/src/fuzzy.c b/src/fuzzy.c index 8e2660807..7e8a01ce3 100644 --- a/src/fuzzy.c +++ b/src/fuzzy.c @@ -253,14 +253,14 @@ lev_distance (gchar *s1, gint len1, gchar *s2, gint len2) /* Calculate fuzzy hash for specified string */ fuzzy_hash_t * -fuzzy_init (f_str_t * in, memory_pool_t * pool) +fuzzy_init (f_str_t * in, rspamd_mempool_t * pool) { fuzzy_hash_t *new; guint i, repeats = 0; gchar *c = in->begin, last = '\0'; gsize real_len = 0; - new = memory_pool_alloc0 (pool, sizeof (fuzzy_hash_t)); + new = rspamd_mempool_alloc0 (pool, sizeof (fuzzy_hash_t)); bzero (&rs, sizeof (rs)); for (i = 0; i < in->len; i++) { if (*c == last) { @@ -302,7 +302,7 @@ fuzzy_init (f_str_t * in, memory_pool_t * pool) } fuzzy_hash_t * -fuzzy_init_byte_array (GByteArray * in, memory_pool_t * pool) +fuzzy_init_byte_array (GByteArray * in, rspamd_mempool_t * pool) { f_str_t f; @@ -313,7 +313,7 @@ fuzzy_init_byte_array (GByteArray * in, memory_pool_t * pool) } void -fuzzy_init_part (struct mime_text_part *part, memory_pool_t *pool, gsize max_diff) +fuzzy_init_part (struct mime_text_part *part, rspamd_mempool_t *pool, gsize max_diff) { fuzzy_hash_t *new, *new2; gchar *c, *end, *begin; @@ -330,8 +330,8 @@ fuzzy_init_part (struct mime_text_part *part, memory_pool_t *pool, gsize max_dif begin = (gchar *)part->content->data; c = begin; - new = memory_pool_alloc0 (pool, sizeof (fuzzy_hash_t)); - new2 = memory_pool_alloc0 (pool, sizeof (fuzzy_hash_t)); + new = rspamd_mempool_alloc0 (pool, sizeof (fuzzy_hash_t)); + new2 = rspamd_mempool_alloc0 (pool, sizeof (fuzzy_hash_t)); bzero (&rs, sizeof (rs)); end = c + len; diff --git a/src/fuzzy.h b/src/fuzzy.h index 46c87d7bc..c226c5765 100644 --- a/src/fuzzy.h +++ b/src/fuzzy.h @@ -28,14 +28,14 @@ struct mime_text_part; * @param pool pool object * @return fuzzy_hash object allocated in pool */ -fuzzy_hash_t * fuzzy_init (f_str_t *in, memory_pool_t *pool); +fuzzy_hash_t * fuzzy_init (f_str_t *in, rspamd_mempool_t *pool); /** * Calculate fuzzy hash for specified byte array * @param in input string * @param pool pool object * @return fuzzy_hash object allocated in pool */ -fuzzy_hash_t * fuzzy_init_byte_array (GByteArray *in, memory_pool_t *pool); +fuzzy_hash_t * fuzzy_init_byte_array (GByteArray *in, rspamd_mempool_t *pool); /** * Calculate fuzzy hash for specified text part @@ -44,7 +44,7 @@ fuzzy_hash_t * fuzzy_init_byte_array (GByteArray *in, memory_pool_t *pool); * @param max_diff maximum text length to use diff algorithm in comparasions * @return fuzzy_hash object allocated in pool */ -void fuzzy_init_part (struct mime_text_part *part, memory_pool_t *pool, gsize max_diff); +void fuzzy_init_part (struct mime_text_part *part, rspamd_mempool_t *pool, gsize max_diff); /** * Compare score of difference between two hashes diff --git a/src/hash.c b/src/hash.c index e5efc72a7..3bb381651 100644 --- a/src/hash.c +++ b/src/hash.c @@ -40,7 +40,7 @@ rspamd_hash_lookup_node (rspamd_hash_t * hash, gconstpointer key, guint * hash_r hash_value = (*hash->hash_func) (key); if (hash->shared) { - memory_pool_rlock_rwlock (hash->lock); + rspamd_mempool_rlock_rwlock (hash->lock); } node_ptr = &hash->nodes[hash_value % hash->size]; @@ -73,7 +73,7 @@ rspamd_hash_lookup_node (rspamd_hash_t * hash, gconstpointer key, guint * hash_r } } if (hash->shared) { - memory_pool_runlock_rwlock (hash->lock); + rspamd_mempool_runlock_rwlock (hash->lock); } return node_ptr; } @@ -88,7 +88,7 @@ rspamd_hash_remove_node (rspamd_hash_t * hash, struct rspamd_hash_node ***node_p struct rspamd_hash_node **node_ptr, *node; if (hash->shared) { - memory_pool_wlock_rwlock (hash->lock); + rspamd_mempool_wlock_rwlock (hash->lock); } node_ptr = *node_ptr_ptr; node = *node_ptr; @@ -97,7 +97,7 @@ rspamd_hash_remove_node (rspamd_hash_t * hash, struct rspamd_hash_node ***node_p hash->nnodes--; if (hash->shared) { - memory_pool_wunlock_rwlock (hash->lock); + rspamd_mempool_wunlock_rwlock (hash->lock); } } @@ -117,14 +117,14 @@ rspamd_hash_resize (rspamd_hash_t * hash) new_size = CLAMP (new_size, HASH_TABLE_MIN_SIZE, HASH_TABLE_MAX_SIZE); if (hash->shared) { - new_nodes = memory_pool_alloc_shared (hash->pool, sizeof (struct rspamd_hash_node *) * new_size); + new_nodes = rspamd_mempool_alloc_shared (hash->pool, sizeof (struct rspamd_hash_node *) * new_size); } else { - new_nodes = memory_pool_alloc (hash->pool, sizeof (struct rspamd_hash_node *) * new_size); + new_nodes = rspamd_mempool_alloc (hash->pool, sizeof (struct rspamd_hash_node *) * new_size); } if (hash->shared) { - memory_pool_wlock_rwlock (hash->lock); + rspamd_mempool_wlock_rwlock (hash->lock); } for (i = 0; i < hash->size; i++) { @@ -140,7 +140,7 @@ rspamd_hash_resize (rspamd_hash_t * hash) hash->size = new_size; if (hash->shared) { - memory_pool_wunlock_rwlock (hash->lock); + rspamd_mempool_wunlock_rwlock (hash->lock); } } @@ -160,16 +160,16 @@ rspamd_hash_maybe_resize (rspamd_hash_t * hash) /* Create new hash in specified pool */ rspamd_hash_t * -rspamd_hash_new (memory_pool_t * pool, GHashFunc hash_func, GEqualFunc key_equal_func) +rspamd_hash_new (rspamd_mempool_t * pool, GHashFunc hash_func, GEqualFunc key_equal_func) { rspamd_hash_t *hash; - hash = memory_pool_alloc (pool, sizeof (rspamd_hash_t)); + hash = rspamd_mempool_alloc (pool, sizeof (rspamd_hash_t)); hash->size = HASH_TABLE_MIN_SIZE; hash->nnodes = 0; hash->hash_func = hash_func ? hash_func : g_direct_hash; hash->key_equal_func = key_equal_func; - hash->nodes = memory_pool_alloc0 (pool, sizeof (struct rspamd_hash_node *) * hash->size); + hash->nodes = rspamd_mempool_alloc0 (pool, sizeof (struct rspamd_hash_node *) * hash->size); hash->shared = 0; hash->pool = pool; @@ -180,19 +180,19 @@ rspamd_hash_new (memory_pool_t * pool, GHashFunc hash_func, GEqualFunc key_equal * Create new hash in specified pool using shared memory */ rspamd_hash_t * -rspamd_hash_new_shared (memory_pool_t * pool, GHashFunc hash_func, GEqualFunc key_equal_func, gint size) +rspamd_hash_new_shared (rspamd_mempool_t * pool, GHashFunc hash_func, GEqualFunc key_equal_func, gint size) { rspamd_hash_t *hash; - hash = memory_pool_alloc_shared (pool, sizeof (rspamd_hash_t)); + hash = rspamd_mempool_alloc_shared (pool, sizeof (rspamd_hash_t)); hash->size = size; hash->nnodes = 0; hash->hash_func = hash_func ? hash_func : g_direct_hash; hash->key_equal_func = key_equal_func; - hash->nodes = memory_pool_alloc0_shared (pool, sizeof (struct rspamd_hash_node *) * hash->size); + hash->nodes = rspamd_mempool_alloc0_shared (pool, sizeof (struct rspamd_hash_node *) * hash->size); hash->shared = 1; /* Get mutex from pool for locking on insert/remove operations */ - hash->lock = memory_pool_get_rwlock (pool); + hash->lock = rspamd_mempool_get_rwlock (pool); hash->pool = pool; return hash; @@ -211,7 +211,7 @@ rspamd_hash_insert (rspamd_hash_t * hash, gpointer key, gpointer value) node_ptr = rspamd_hash_lookup_node (hash, key, &key_hash); if (hash->shared) { - memory_pool_wlock_rwlock (hash->lock); + rspamd_mempool_wlock_rwlock (hash->lock); } if ((node = *node_ptr)) { node->key = key; @@ -219,10 +219,10 @@ rspamd_hash_insert (rspamd_hash_t * hash, gpointer key, gpointer value) } else { if (hash->shared) { - node = memory_pool_alloc_shared (hash->pool, sizeof (struct rspamd_hash_node)); + node = rspamd_mempool_alloc_shared (hash->pool, sizeof (struct rspamd_hash_node)); } else { - node = memory_pool_alloc (hash->pool, sizeof (struct rspamd_hash_node)); + node = rspamd_mempool_alloc (hash->pool, sizeof (struct rspamd_hash_node)); } node->key = key; @@ -234,7 +234,7 @@ rspamd_hash_insert (rspamd_hash_t * hash, gpointer key, gpointer value) hash->nnodes++; } if (hash->shared) { - memory_pool_wunlock_rwlock (hash->lock); + rspamd_mempool_wunlock_rwlock (hash->lock); } if (!hash->shared) { @@ -289,7 +289,7 @@ rspamd_hash_foreach (rspamd_hash_t * hash, GHFunc func, gpointer user_data) g_return_if_fail (func != NULL); if (hash->shared) { - memory_pool_rlock_rwlock (hash->lock); + rspamd_mempool_rlock_rwlock (hash->lock); } for (i = 0; i < hash->size; i++) { for (node = hash->nodes[i]; node; node = node->next) { @@ -297,7 +297,7 @@ rspamd_hash_foreach (rspamd_hash_t * hash, GHFunc func, gpointer user_data) } } if (hash->shared) { - memory_pool_runlock_rwlock (hash->lock); + rspamd_mempool_runlock_rwlock (hash->lock); } } diff --git a/src/hash.h b/src/hash.h index adc9d2823..c5d4639af 100644 --- a/src/hash.h +++ b/src/hash.h @@ -24,8 +24,8 @@ typedef struct rspamd_hash_s { GHashFunc hash_func; GEqualFunc key_equal_func; gint shared; - memory_pool_rwlock_t *lock; - memory_pool_t *pool; + rspamd_mempool_rwlock_t *lock; + rspamd_mempool_t *pool; } rspamd_hash_t; typedef void (*lru_cache_insert_func)(gpointer storage, gpointer key, gpointer value); @@ -65,7 +65,7 @@ typedef struct rspamd_lru_element_s { * @param key_equal_func pointer to function for comparing keys * @return new rspamd_hash object */ -rspamd_hash_t* rspamd_hash_new (memory_pool_t *pool, GHashFunc hash_func, GEqualFunc key_equal_func); +rspamd_hash_t* rspamd_hash_new (rspamd_mempool_t *pool, GHashFunc hash_func, GEqualFunc key_equal_func); /** * Create new hash in specified pool using shared memory @@ -74,7 +74,7 @@ rspamd_hash_t* rspamd_hash_new (memory_pool_t *pool, GHashFunc hash_func, GEqual * @param key_equal_func pointer to function for comparing keys * @return new rspamd_hash object */ -rspamd_hash_t* rspamd_hash_new_shared (memory_pool_t *pool, GHashFunc hash_func, GEqualFunc key_equal_func, gint size); +rspamd_hash_t* rspamd_hash_new_shared (rspamd_mempool_t *pool, GHashFunc hash_func, GEqualFunc key_equal_func, gint size); /** * Insert item in hash diff --git a/src/html.c b/src/html.c index cbec6e9d4..1f6d091d3 100644 --- a/src/html.c +++ b/src/html.c @@ -468,7 +468,7 @@ entity_cmp_num (const void *m1, const void *m2) } static GNode * -construct_html_node (memory_pool_t * pool, gchar *text, gsize tag_len) +construct_html_node (rspamd_mempool_t * pool, gchar *text, gsize tag_len) { struct html_node *html; GNode *n = NULL; @@ -479,7 +479,7 @@ construct_html_node (memory_pool_t * pool, gchar *text, gsize tag_len) return NULL; } - html = memory_pool_alloc0 (pool, sizeof (struct html_node)); + html = rspamd_mempool_alloc0 (pool, sizeof (struct html_node)); /* Check whether this tag is fully closed */ if (*(text + tag_len - 1) == '/') { @@ -712,7 +712,7 @@ check_phishing (struct worker_task *task, struct uri *href_url, const gchar *url } if (url_try_text (task->task_pool, url_text, len, NULL, NULL, &url_str, TRUE) && url_str != NULL) { - new = memory_pool_alloc0 (task->task_pool, sizeof (struct uri)); + new = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct uri)); if (new != NULL) { g_strstrip (url_str); rc = parse_uri (new, url_str, task->task_pool); @@ -839,7 +839,7 @@ parse_tag_url (struct worker_task *task, struct mime_text_part *part, tag_id_t i return; } - url_text = memory_pool_alloc (task->task_pool, len + 1); + url_text = rspamd_mempool_alloc (task->task_pool, len + 1); rspamd_strlcpy (url_text, c, len + 1); decode_entitles (url_text, NULL); @@ -850,7 +850,7 @@ parse_tag_url (struct worker_task *task, struct mime_text_part *part, tag_id_t i return; } - url = memory_pool_alloc (task->task_pool, sizeof (struct uri)); + url = rspamd_mempool_alloc (task->task_pool, sizeof (struct uri)); rc = parse_uri (url, url_text, task->task_pool); if (rc != URI_ERRNO_EMPTY && rc != URI_ERRNO_NO_HOST && url->hostlen != 0) { @@ -869,7 +869,7 @@ parse_tag_url (struct worker_task *task, struct mime_text_part *part, tag_id_t i } gboolean -add_html_node (struct worker_task *task, memory_pool_t * pool, struct mime_text_part *part, +add_html_node (struct worker_task *task, rspamd_mempool_t * pool, struct mime_text_part *part, gchar *tag_text, gsize tag_len, gsize remain, GNode ** cur_level) { GNode *new; @@ -892,7 +892,7 @@ add_html_node (struct worker_task *task, memory_pool_t * pool, struct mime_text_ new = g_node_new (NULL); *cur_level = new; part->html_nodes = new; - memory_pool_add_destructor (pool, (pool_destruct_func) g_node_destroy, part->html_nodes); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) g_node_destroy, part->html_nodes); /* Call once again with root node */ return add_html_node (task, pool, part, tag_text, tag_len, remain, cur_level); } diff --git a/src/html.h b/src/html.h index 2e5ae8bcf..601f076d2 100644 --- a/src/html.h +++ b/src/html.h @@ -210,7 +210,7 @@ struct worker_task; /* * Add a single node to the tags tree */ -gboolean add_html_node (struct worker_task *task, memory_pool_t *pool, +gboolean add_html_node (struct worker_task *task, rspamd_mempool_t *pool, struct mime_text_part *part, gchar *tag_text, gsize tag_len, gsize remain, GNode **cur_level); /* diff --git a/src/images.c b/src/images.c index ef9d44093..e3b300166 100644 --- a/src/images.c +++ b/src/images.c @@ -102,7 +102,7 @@ process_png_image (struct worker_task *task, GByteArray *data) return NULL; } - img = memory_pool_alloc (task->task_pool, sizeof (struct rspamd_image)); + img = rspamd_mempool_alloc (task->task_pool, sizeof (struct rspamd_image)); img->type = IMAGE_TYPE_PNG; img->data = data; @@ -124,7 +124,7 @@ process_jpg_image (struct worker_task *task, GByteArray *data) gsize remain; struct rspamd_image *img; - img = memory_pool_alloc (task->task_pool, sizeof (struct rspamd_image)); + img = rspamd_mempool_alloc (task->task_pool, sizeof (struct rspamd_image)); img->type = IMAGE_TYPE_JPG; img->data = data; @@ -157,7 +157,7 @@ process_gif_image (struct worker_task *task, GByteArray *data) return NULL; } - img = memory_pool_alloc (task->task_pool, sizeof (struct rspamd_image)); + img = rspamd_mempool_alloc (task->task_pool, sizeof (struct rspamd_image)); img->type = IMAGE_TYPE_GIF; img->data = data; @@ -184,7 +184,7 @@ process_bmp_image (struct worker_task *task, GByteArray *data) return NULL; } - img = memory_pool_alloc (task->task_pool, sizeof (struct rspamd_image)); + img = rspamd_mempool_alloc (task->task_pool, sizeof (struct rspamd_image)); img->type = IMAGE_TYPE_BMP; img->data = data; p = data->data + 18; diff --git a/src/kvstorage_config.c b/src/kvstorage_config.c index dbe58cb11..d7bb8cedd 100644 --- a/src/kvstorage_config.c +++ b/src/kvstorage_config.c @@ -61,7 +61,7 @@ struct kvstorage_config_parser { KVSTORAGE_STATE_ERROR } state; struct kvstorage_config *current_storage; - memory_pool_t *pool; + rspamd_mempool_t *pool; gchar *cur_elt; }; @@ -157,9 +157,9 @@ void kvstorage_xml_start_element (GMarkupParseContext *context, if (kv_parser->current_storage == NULL) { /* Make temporary pool */ if (kv_parser->pool != NULL) { - memory_pool_delete (kv_parser->pool); + rspamd_mempool_delete (kv_parser->pool); } - kv_parser->pool = memory_pool_new (memory_pool_get_size ()); + kv_parser->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); /* Create new kvstorage_config */ kv_parser->current_storage = g_malloc0 (sizeof (struct kvstorage_config)); @@ -514,7 +514,7 @@ init_kvstorage_config (void) kv_parser = g_malloc0 (sizeof (struct kvstorage_config_parser)); kv_parser->state = KVSTORAGE_STATE_PARAM; - kv_parser->pool = memory_pool_new (memory_pool_get_size ()); + kv_parser->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); register_subparser ("keystorage", 0, parser, kvstorage_cleanup, kv_parser); } diff --git a/src/kvstorage_server.c b/src/kvstorage_server.c index b493eee46..75ada2c77 100644 --- a/src/kvstorage_server.c +++ b/src/kvstorage_server.c @@ -108,7 +108,7 @@ init_keystorage (void) type = g_quark_try_string ("keystorage"); ctx = g_malloc0 (sizeof (struct kvstorage_worker_ctx)); - ctx->pool = memory_pool_new (memory_pool_get_size ()); + ctx->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); /* Set default values */ ctx->timeout_raw = 300000; @@ -139,7 +139,7 @@ static void free_kvstorage_session (struct kvstorage_session *session) { rspamd_remove_dispatcher (session->dispather); - memory_pool_delete (session->pool); + rspamd_mempool_delete (session->pool); close (session->sock); g_slice_free1 (sizeof (struct kvstorage_session), session); } @@ -322,7 +322,7 @@ parse_kvstorage_line (struct kvstorage_session *session, f_str_t *in) return FALSE; } else { - session->key = memory_pool_alloc (session->pool, p - c + 1); + session->key = rspamd_mempool_alloc (session->pool, p - c + 1); rspamd_strlcpy (session->key, c, p - c + 1); session->keylen = p - c; /* Now we must select next state based on command */ @@ -825,7 +825,7 @@ kvstorage_read_socket (f_str_t * in, void *arg) else if (session->argnum == 1) { if (session->command != KVSTORAGE_CMD_SELECT) { /* This argument is a key for normal command */ - session->key = memory_pool_fstrdup (session->pool, in); + session->key = rspamd_mempool_fstrdup (session->pool, in); session->keylen = in->len; if (session->argnum == session->argc - 1) { session->state = KVSTORAGE_STATE_READ_CMD; @@ -1010,7 +1010,7 @@ thr_accept_socket (gint fd, short what, void *arg) } session = g_slice_alloc0 (sizeof (struct kvstorage_session)); - session->pool = memory_pool_new (memory_pool_get_size ()); + session->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); session->state = KVSTORAGE_STATE_READ_CMD; session->thr = thr; session->sock = nfd; @@ -1084,7 +1084,7 @@ create_kvstorage_thread (struct rspamd_worker *worker, struct kvstorage_worker_c struct kvstorage_worker_thread *new; GError *err = NULL; - new = memory_pool_alloc (ctx->pool, sizeof (struct kvstorage_worker_thread)); + new = rspamd_mempool_alloc (ctx->pool, sizeof (struct kvstorage_worker_thread)); new->ctx = ctx; new->worker = worker; new->tv = &ctx->io_timeout; @@ -1104,7 +1104,7 @@ create_kvstorage_thread (struct rspamd_worker *worker, struct kvstorage_worker_c #else gchar *name; - name = memory_pool_alloc (ctx->pool, sizeof ("kvstorage_thread") + sizeof ("4294967296") - 1); + name = rspamd_mempool_alloc (ctx->pool, sizeof ("kvstorage_thread") + sizeof ("4294967296") - 1); rspamd_snprintf (name, sizeof ("kvstorage_thread") + sizeof ("4294967296") - 1, "kvstorage_thread%d", id); new->thr = g_thread_new (name, kvstorage_thread, new); @@ -1169,8 +1169,8 @@ start_keystorage (struct rspamd_worker *worker) ctx->log_mtx = g_mutex_new (); ctx->accept_mtx = g_mutex_new (); #else - ctx->log_mtx = memory_pool_alloc (ctx->pool, sizeof (GMutex)); - ctx->accept_mtx = memory_pool_alloc (ctx->pool, sizeof (GMutex)); + ctx->log_mtx = rspamd_mempool_alloc (ctx->pool, sizeof (GMutex)); + ctx->accept_mtx = rspamd_mempool_alloc (ctx->pool, sizeof (GMutex)); g_mutex_init (ctx->log_mtx); g_mutex_init (ctx->accept_mtx); #endif diff --git a/src/kvstorage_server.h b/src/kvstorage_server.h index 6e8e218ea..7af9d79ba 100644 --- a/src/kvstorage_server.h +++ b/src/kvstorage_server.h @@ -36,7 +36,7 @@ struct kvstorage_worker_ctx { GList *threads; gint s_pair[2]; gboolean is_redis; - memory_pool_t *pool; + rspamd_mempool_t *pool; struct event_base *ev_base; GMutex *log_mtx; GMutex *accept_mtx; @@ -78,7 +78,7 @@ struct kvstorage_session { guint id; guint argc; guint argnum; - memory_pool_t *pool; + rspamd_mempool_t *pool; gchar *key; guint keylen; struct kvstorage_config *cf; diff --git a/src/lmtp.c b/src/lmtp.c index 67743e92a..8ffef771f 100644 --- a/src/lmtp.c +++ b/src/lmtp.c @@ -128,7 +128,7 @@ free_lmtp_task (struct rspamd_lmtp_proto *lmtp, gboolean is_soft) g_byte_array_free (p->content, FALSE); g_list_free_1 (part); } - memory_pool_delete (lmtp->task->task_pool); + rspamd_mempool_delete (lmtp->task->task_pool); if (is_soft) { /* Plan dispatcher shutdown */ lmtp->task->dispatcher->wanna_die = 1; @@ -268,12 +268,12 @@ accept_socket (gint fd, short what, void *arg) new_task->sock = nfd; new_task->cfg = worker->srv->cfg; - new_task->task_pool = memory_pool_new (memory_pool_get_size ()); + new_task->task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); /* Add destructor for recipients list (it would be better to use anonymous function here */ - memory_pool_add_destructor (new_task->task_pool, (pool_destruct_func) rcpt_destruct, new_task); + rspamd_mempool_add_destructor (new_task->task_pool, (rspamd_mempool_destruct_t) rcpt_destruct, new_task); new_task->results = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); new_task->ev_base = worker->ctx; - memory_pool_add_destructor (new_task->task_pool, (pool_destruct_func) g_hash_table_destroy, new_task->results); + rspamd_mempool_add_destructor (new_task->task_pool, (rspamd_mempool_destruct_t) g_hash_table_destroy, new_task->results); worker->srv->stat->connections_count++; lmtp->task = new_task; lmtp->state = LMTP_READ_LHLO; diff --git a/src/lmtp_proto.c b/src/lmtp_proto.c index 95b8ca13a..06edc06ad 100644 --- a/src/lmtp_proto.c +++ b/src/lmtp_proto.c @@ -66,7 +66,7 @@ static GRegex *mail_re = NULL; * return <> if no valid address detected */ static gchar * -extract_mail (memory_pool_t * pool, f_str_t * line) +extract_mail (rspamd_mempool_t * pool, f_str_t * line) { GError *err = NULL; gchar *match; @@ -78,7 +78,7 @@ extract_mail (memory_pool_t * pool, f_str_t * line) } if (g_regex_match_full (mail_re, line->begin, line->len, 0, 0, &info, NULL) == TRUE) { - match = memory_pool_strdup (pool, g_match_info_fetch (info, 0)); + match = rspamd_mempool_strdup (pool, g_match_info_fetch (info, 0)); g_match_info_free (info); } else { @@ -129,7 +129,7 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t * line) i++; c++; } - lmtp->task->helo = memory_pool_alloc (lmtp->task->task_pool, line->len - i + 1); + lmtp->task->helo = rspamd_mempool_alloc (lmtp->task->task_pool, line->len - i + 1); /* Strlcpy makes string null terminated by design */ rspamd_strlcpy (lmtp->task->helo, c, line->len - i + 1); lmtp->state = LMTP_READ_FROM; @@ -201,7 +201,7 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t * line) while (g_ascii_isspace (*c++)) { i++; } - rcpt = memory_pool_alloc (lmtp->task->task_pool, line->len - i + 1); + rcpt = rspamd_mempool_alloc (lmtp->task->task_pool, line->len - i + 1); /* Strlcpy makes string null terminated by design */ rspamd_strlcpy (rcpt, c, line->len - i + 1); lmtp->task->rcpt = g_list_prepend (lmtp->task->rcpt, rcpt); @@ -410,7 +410,7 @@ mta_read_socket (f_str_t * in, void *arg) if (! rspamd_dispatcher_write (cd->task->dispatcher, c, r, TRUE, TRUE)) { return FALSE; } - memory_pool_add_destructor (cd->task->task_pool, (pool_destruct_func) g_free, c); + rspamd_mempool_add_destructor (cd->task->task_pool, (rspamd_mempool_destruct_t) g_free, c); r = rspamd_snprintf (outbuf, sizeof (outbuf), CRLF "." CRLF); if (! rspamd_dispatcher_write (cd->task->dispatcher, outbuf, r, FALSE, FALSE)) { return FALSE; @@ -463,7 +463,7 @@ lmtp_deliver_mta (struct worker_task *task) msg_warn ("cannot create socket for %s, %s", task->cfg->deliver_host, strerror (errno)); } - cd = memory_pool_alloc (task->task_pool, sizeof (struct mta_callback_data)); + cd = rspamd_mempool_alloc (task->task_pool, sizeof (struct mta_callback_data)); cd->task = task; cd->state = LMTP_WANT_GREETING; cd->dispatcher = rspamd_create_dispatcher (task->ev_base, sock, BUFFER_LINE, mta_read_socket, NULL, mta_err_socket, NULL, (void *)cd); @@ -508,7 +508,7 @@ format_lda_args (struct worker_task *task) c++; len++; } - res = memory_pool_alloc (task->task_pool, len + 1); + res = rspamd_mempool_alloc (task->task_pool, len + 1); r = res; c = task->cfg->deliver_agent_path; diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c index 9e636ecef..cc9c71309 100644 --- a/src/lua/lua_cfg_file.c +++ b/src/lua/lua_cfg_file.c @@ -46,20 +46,20 @@ lua_process_metric (lua_State *L, const gchar *name, struct config_file *cfg) /* Get module opt structure */ if ((metric = g_hash_table_lookup (cfg->metrics, name)) == NULL) { metric = check_metric_conf (cfg, metric); - metric->name = memory_pool_strdup (cfg->cfg_pool, name); + metric->name = rspamd_mempool_strdup (cfg->cfg_pool, name); } /* Now iterate throught module table */ for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) { /* key - -2, value - -1 */ - symbol = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, -2)); + symbol = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, -2)); if (symbol != NULL) { if (lua_istable (L, -1)) { /* We got a table, so extract individual attributes */ lua_pushstring (L, "weight"); lua_gettable (L, -2); if (lua_isnumber (L, -1)) { - score = memory_pool_alloc (cfg->cfg_pool, sizeof (double)); + score = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (double)); *score = lua_tonumber (L, -1); } else { @@ -75,18 +75,18 @@ lua_process_metric (lua_State *L, const gchar *name, struct config_file *cfg) if (old_desc) { msg_info ("replacing description for symbol %s", symbol); g_hash_table_replace (metric->descriptions, - symbol, memory_pool_strdup (cfg->cfg_pool, desc)); + symbol, rspamd_mempool_strdup (cfg->cfg_pool, desc)); } else { g_hash_table_insert (metric->descriptions, - symbol, memory_pool_strdup (cfg->cfg_pool, desc)); + symbol, rspamd_mempool_strdup (cfg->cfg_pool, desc)); } } lua_pop (L, 1); } else if (lua_isnumber (L, -1)) { /* Just got weight */ - score = memory_pool_alloc (cfg->cfg_pool, sizeof (double)); + score = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (double)); *score = lua_tonumber (L, -1); } else { @@ -104,7 +104,7 @@ lua_process_metric (lua_State *L, const gchar *name, struct config_file *cfg) if ((metric_list = g_hash_table_lookup (cfg->metrics_symbols, symbol)) == NULL) { metric_list = g_list_prepend (NULL, metric); - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)g_list_free, metric_list); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_list_free, metric_list); g_hash_table_insert (cfg->metrics_symbols, symbol, metric_list); } else { @@ -172,8 +172,8 @@ lua_post_load_config (struct config_file *cfg) name = luaL_checkstring (L, -2); if (name != NULL && lua_isstring (L, -1)) { val = lua_tostring (L, -1); - sym = memory_pool_strdup(cfg->cfg_pool, name); - if ((expr = parse_expression (cfg->cfg_pool, memory_pool_strdup(cfg->cfg_pool, val))) == NULL) { + sym = rspamd_mempool_strdup(cfg->cfg_pool, name); + if ((expr = parse_expression (cfg->cfg_pool, rspamd_mempool_strdup(cfg->cfg_pool, val))) == NULL) { msg_err ("cannot parse composite expression: %s", val); continue; } diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 878bb4ef1..b8be57896 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -175,11 +175,11 @@ lua_config_get_module_opt (lua_State * L) static int lua_config_get_mempool (lua_State * L) { - memory_pool_t **ppool; + rspamd_mempool_t **ppool; struct config_file *cfg = lua_check_config (L); if (cfg != NULL) { - ppool = lua_newuserdata (L, sizeof (memory_pool_t *)); + ppool = lua_newuserdata (L, sizeof (rspamd_mempool_t *)); lua_setclass (L, "rspamd{mempool}", -1); *ppool = cfg->cfg_pool; } @@ -316,11 +316,11 @@ lua_config_register_function (lua_State *L) struct lua_callback_data *cd; if (cfg) { - name = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); - cd = memory_pool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); + name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); + cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); if (lua_type (L, 3) == LUA_TSTRING) { - cd->callback.name = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 3)); + cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 3)); cd->cb_is_ref = FALSE; } else { @@ -334,7 +334,7 @@ lua_config_register_function (lua_State *L) cd->symbol = name; register_expression_function (name, lua_config_function_callback, cd); } - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)lua_destroy_cfg_symbol, cd); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, cd); } return 1; } @@ -380,9 +380,9 @@ lua_config_register_post_filter (lua_State *L) struct lua_callback_data *cd; if (cfg) { - cd = memory_pool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); + cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); if (lua_type (L, 2) == LUA_TSTRING) { - cd->callback.name = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); + cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); cd->cb_is_ref = FALSE; } else { @@ -393,7 +393,7 @@ lua_config_register_post_filter (lua_State *L) } cd->L = L; cfg->post_filters = g_list_prepend (cfg->post_filters, cd); - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)lua_destroy_cfg_symbol, cd); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, cd); } return 1; } @@ -433,9 +433,9 @@ lua_config_register_pre_filter (lua_State *L) struct lua_callback_data *cd; if (cfg) { - cd = memory_pool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); + cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); if (lua_type (L, 2) == LUA_TSTRING) { - cd->callback.name = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); + cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); cd->cb_is_ref = FALSE; } else { @@ -446,7 +446,7 @@ lua_config_register_pre_filter (lua_State *L) } cd->L = L; cfg->pre_filters = g_list_prepend (cfg->pre_filters, cd); - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)lua_destroy_cfg_symbol, cd); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, cd); } return 1; } @@ -461,7 +461,7 @@ lua_config_add_radix_map (lua_State *L) if (cfg) { map_line = luaL_checkstring (L, 2); description = lua_tostring (L, 3); - r = memory_pool_alloc (cfg->cfg_pool, sizeof (radix_tree_t *)); + r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (radix_tree_t *)); *r = radix_tree_create (); if (!add_map (cfg, map_line, description, read_radix_list, fin_radix_list, (void **)r)) { msg_warn ("invalid radix map %s", map_line); @@ -491,7 +491,7 @@ lua_config_add_hash_map (lua_State *L) if (cfg) { map_line = luaL_checkstring (L, 2); description = lua_tostring (L, 3); - r = memory_pool_alloc (cfg->cfg_pool, sizeof (GHashTable *)); + r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (GHashTable *)); *r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); if (!add_map (cfg, map_line, description, read_host_list, fin_host_list, (void **)r)) { msg_warn ("invalid hash map %s", map_line); @@ -499,7 +499,7 @@ lua_config_add_hash_map (lua_State *L) lua_pushnil (L); return 1; } - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)g_hash_table_destroy, *r); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_hash_table_destroy, *r); ud = lua_newuserdata (L, sizeof (GHashTable *)); *ud = r; lua_setclass (L, "rspamd{hash_table}", -1); @@ -522,7 +522,7 @@ lua_config_add_kv_map (lua_State *L) if (cfg) { map_line = luaL_checkstring (L, 2); description = lua_tostring (L, 3); - r = memory_pool_alloc (cfg->cfg_pool, sizeof (GHashTable *)); + r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (GHashTable *)); *r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); if (!add_map (cfg, map_line, description, read_kv_list, fin_kv_list, (void **)r)) { msg_warn ("invalid hash map %s", map_line); @@ -530,7 +530,7 @@ lua_config_add_kv_map (lua_State *L) lua_pushnil (L); return 1; } - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)g_hash_table_destroy, *r); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)g_hash_table_destroy, *r); ud = lua_newuserdata (L, sizeof (GHashTable *)); *ud = r; lua_setclass (L, "rspamd{hash_table}", -1); @@ -577,11 +577,11 @@ lua_config_register_symbol (lua_State * L) struct lua_callback_data *cd; if (cfg) { - name = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); + name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); weight = luaL_checknumber (L, 3); - cd = memory_pool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); + cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); if (lua_type (L, 4) == LUA_TSTRING) { - cd->callback.name = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 4)); + cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 4)); cd->cb_is_ref = FALSE; } else { @@ -595,7 +595,7 @@ lua_config_register_symbol (lua_State * L) cd->L = L; register_symbol (&cfg->cache, name, weight, lua_metric_symbol_callback, cd); } - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)lua_destroy_cfg_symbol, cd); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, cd); } return 0; } @@ -614,9 +614,9 @@ lua_config_register_symbols (lua_State *L) return 0; } if (cfg) { - cd = memory_pool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); + cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); if (lua_type (L, 2) == LUA_TSTRING) { - cd->callback.name = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); + cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); cd->cb_is_ref = FALSE; } else { @@ -632,12 +632,12 @@ lua_config_register_symbols (lua_State *L) else { top = 3; } - sym = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, top)); + sym = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, top)); cd->symbol = sym; cd->L = L; register_symbol (&cfg->cache, sym, weight, lua_metric_symbol_callback, cd); for (i = top; i < lua_gettop (L); i ++) { - sym = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, i + 1)); + sym = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, i + 1)); register_virtual_symbol (&cfg->cache, sym, weight); } } @@ -653,7 +653,7 @@ lua_config_register_virtual_symbol (lua_State * L) double weight; if (cfg) { - name = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); + name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); weight = luaL_checknumber (L, 3); if (name) { register_virtual_symbol (&cfg->cache, name, weight); @@ -671,11 +671,11 @@ lua_config_register_callback_symbol (lua_State * L) struct lua_callback_data *cd; if (cfg) { - name = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); + name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); weight = luaL_checknumber (L, 3); - cd = memory_pool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); + cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); if (lua_type (L, 4) == LUA_TSTRING) { - cd->callback.name = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 4)); + cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 4)); cd->cb_is_ref = FALSE; } else { @@ -689,7 +689,7 @@ lua_config_register_callback_symbol (lua_State * L) cd->L = L; register_callback_symbol (&cfg->cache, name, weight, lua_metric_symbol_callback, cd); } - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)lua_destroy_cfg_symbol, cd); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, cd); } return 0; } @@ -704,12 +704,12 @@ lua_config_register_callback_symbol_priority (lua_State * L) struct lua_callback_data *cd; if (cfg) { - name = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); + name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2)); weight = luaL_checknumber (L, 3); priority = luaL_checknumber (L, 4); - cd = memory_pool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); + cd = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct lua_callback_data)); if (lua_type (L, 5) == LUA_TSTRING) { - cd->callback.name = memory_pool_strdup (cfg->cfg_pool, luaL_checkstring (L, 5)); + cd->callback.name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 5)); cd->cb_is_ref = FALSE; } else { @@ -724,7 +724,7 @@ lua_config_register_callback_symbol_priority (lua_State * L) cd->symbol = name; register_callback_symbol_priority (&cfg->cache, name, weight, priority, lua_metric_symbol_callback, cd); } - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)lua_destroy_cfg_symbol, cd); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_destroy_cfg_symbol, cd); } return 0; diff --git a/src/lua/lua_dns.c b/src/lua/lua_dns.c index 45b76aea5..21599220a 100644 --- a/src/lua/lua_dns.c +++ b/src/lua/lua_dns.c @@ -194,7 +194,7 @@ lua_dns_resolver_resolve_common (lua_State *L, struct rspamd_dns_resolver *resol enum rdns_request_type type, int first) { struct rspamd_async_session *session, **psession; - memory_pool_t *pool, **ppool; + rspamd_mempool_t *pool, **ppool; const gchar *to_resolve; struct lua_dns_cbdata *cbdata; @@ -208,11 +208,11 @@ lua_dns_resolver_resolve_common (lua_State *L, struct rspamd_dns_resolver *resol to_resolve = luaL_checkstring (L, first + 2); if (pool != NULL && session != NULL && to_resolve != NULL && lua_isfunction (L, first + 3)) { - cbdata = memory_pool_alloc (pool, sizeof (struct lua_dns_cbdata)); + cbdata = rspamd_mempool_alloc (pool, sizeof (struct lua_dns_cbdata)); cbdata->L = L; cbdata->resolver = resolver; if (type != RDNS_REQUEST_PTR) { - cbdata->to_resolve = memory_pool_strdup (pool, to_resolve); + cbdata->to_resolve = rspamd_mempool_strdup (pool, to_resolve); } else { char *ptr_str; @@ -222,7 +222,7 @@ lua_dns_resolver_resolve_common (lua_State *L, struct rspamd_dns_resolver *resol lua_pushnil (L); return 1; } - cbdata->to_resolve = memory_pool_strdup (pool, ptr_str); + cbdata->to_resolve = rspamd_mempool_strdup (pool, ptr_str); free (ptr_str); } lua_pushvalue (L, first + 3); diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 3f30e1f3a..31bcffb77 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -47,7 +47,7 @@ struct lua_http_ud { struct worker_task *task; gint parser_state; struct rspamd_async_session *s; - memory_pool_t *pool; + rspamd_mempool_t *pool; struct rspamd_dns_resolver *resolver; struct event_base *ev_base; lua_State *L; @@ -211,8 +211,8 @@ lua_http_parse_header_line (struct lua_http_ud *ud, f_str_t *in) return FALSE; } /* Copy name */ - new = memory_pool_alloc (ud->pool, sizeof (struct lua_http_header)); - new->name = memory_pool_alloc (ud->pool, p - in->begin + 1); + new = rspamd_mempool_alloc (ud->pool, sizeof (struct lua_http_header)); + new->name = rspamd_mempool_alloc (ud->pool, p - in->begin + 1); rspamd_strlcpy (new->name, in->begin, p - in->begin + 1); p ++; @@ -220,7 +220,7 @@ lua_http_parse_header_line (struct lua_http_ud *ud, f_str_t *in) while (p < in->begin + in->len && g_ascii_isspace (*p)) { p ++; } - new->value = memory_pool_alloc (ud->pool, in->begin + in->len - p + 1); + new->value = rspamd_mempool_alloc (ud->pool, in->begin + in->len - p + 1); rspamd_strlcpy (new->value, p, in->begin + in->len - p + 1); /* Check content-length */ @@ -350,14 +350,14 @@ lua_http_make_request_common (lua_State *L, struct worker_task *task, const gcha s = MAX_HEADERS_SIZE + sizeof (CRLF) * 3 + strlen (hostname) + strlen (path) + datalen + sizeof ("POST HTTP/1.1"); - ud = memory_pool_alloc0 (task->task_pool, sizeof (struct lua_http_ud)); + ud = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct lua_http_ud)); ud->L = L; ud->s = task->s; ud->pool = task->task_pool; ud->ev_base = task->ev_base; ud->task = task; /* Preallocate buffer */ - ud->req_buf = memory_pool_alloc (task->task_pool, s); + ud->req_buf = rspamd_mempool_alloc (task->task_pool, s); ud->callback = callback; /* Print request */ @@ -415,7 +415,7 @@ lua_http_make_request_common (lua_State *L, struct worker_task *task, const gcha * Common request function (new version) */ static gint -lua_http_make_request_common_new (lua_State *L, struct rspamd_async_session *session, memory_pool_t *pool, struct event_base *base, gint cbref, +lua_http_make_request_common_new (lua_State *L, struct rspamd_async_session *session, rspamd_mempool_t *pool, struct event_base *base, gint cbref, const gchar *hostname, const gchar *path, const gchar *data, gint top) { gint r, s, datalen; @@ -428,13 +428,13 @@ lua_http_make_request_common_new (lua_State *L, struct rspamd_async_session *ses s = MAX_HEADERS_SIZE + sizeof (CRLF) * 3 + strlen (hostname) + strlen (path) + datalen + sizeof ("POST HTTP/1.1"); - ud = memory_pool_alloc0 (pool, sizeof (struct lua_http_ud)); + ud = rspamd_mempool_alloc0 (pool, sizeof (struct lua_http_ud)); ud->L = L; ud->pool = pool; ud->s = session; ud->ev_base = base; /* Preallocate buffer */ - ud->req_buf = memory_pool_alloc (pool, s); + ud->req_buf = rspamd_mempool_alloc (pool, s); ud->callback = NULL; ud->cbref = cbref; @@ -519,7 +519,7 @@ static gint lua_http_make_post_request (lua_State *L) { struct worker_task *task, **ptask; - memory_pool_t *pool, **ppool; + rspamd_mempool_t *pool, **ppool; struct rspamd_async_session *session, **psession; struct event_base *base, **pbase; const gchar *hostname, *path, *data, *callback; @@ -545,10 +545,10 @@ lua_http_make_post_request (lua_State *L) /* Now extract hostname, path and data */ if (task) { - callback = memory_pool_strdup (task->task_pool, luaL_checkstring (L, 2)); - hostname = memory_pool_strdup (task->task_pool, luaL_checkstring (L, 3)); - path = memory_pool_strdup (task->task_pool, luaL_checkstring (L, 4)); - data = memory_pool_strdup (task->task_pool, luaL_checkstring (L, 5)); + callback = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 2)); + hostname = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 3)); + path = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 4)); + data = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 5)); if (callback != NULL && hostname != NULL && path != NULL && data != NULL) { return lua_http_make_request_common (L, task, callback, hostname, path, data, 5); @@ -559,9 +559,9 @@ lua_http_make_post_request (lua_State *L) } else { /* Common version */ - hostname = memory_pool_strdup (pool, luaL_checkstring (L, 4)); - path = memory_pool_strdup (pool, luaL_checkstring (L, 5)); - data = memory_pool_strdup (pool, luaL_checkstring (L, 6)); + hostname = rspamd_mempool_strdup (pool, luaL_checkstring (L, 4)); + path = rspamd_mempool_strdup (pool, luaL_checkstring (L, 5)); + data = rspamd_mempool_strdup (pool, luaL_checkstring (L, 6)); if (session != NULL && pool != NULL && hostname != NULL && path != NULL && data != NULL && lua_isfunction (L, 7)) { lua_pushvalue (L, 7); cbref = luaL_ref (L, LUA_REGISTRYINDEX); @@ -580,7 +580,7 @@ static gint lua_http_make_get_request (lua_State *L) { struct worker_task *task, **ptask; - memory_pool_t *pool, **ppool; + rspamd_mempool_t *pool, **ppool; struct rspamd_async_session *session, **psession; struct event_base *base, **pbase; const gchar *hostname, *path, *callback; @@ -606,9 +606,9 @@ lua_http_make_get_request (lua_State *L) /* Now extract hostname, path and data */ if (task) { - callback = memory_pool_strdup (task->task_pool, luaL_checkstring (L, 2)); - hostname = memory_pool_strdup (task->task_pool, luaL_checkstring (L, 3)); - path = memory_pool_strdup (task->task_pool, luaL_checkstring (L, 4)); + callback = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 2)); + hostname = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 3)); + path = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 4)); if (callback != NULL && hostname != NULL && path != NULL) { return lua_http_make_request_common (L, task, callback, hostname, path, NULL, 4); @@ -619,8 +619,8 @@ lua_http_make_get_request (lua_State *L) } else { /* Common version */ - hostname = memory_pool_strdup (pool, luaL_checkstring (L, 4)); - path = memory_pool_strdup (pool, luaL_checkstring (L, 5)); + hostname = rspamd_mempool_strdup (pool, luaL_checkstring (L, 4)); + path = rspamd_mempool_strdup (pool, luaL_checkstring (L, 5)); if (session != NULL && pool != NULL && hostname != NULL && path != NULL && lua_isfunction (L, 6)) { lua_pushvalue (L, 6); cbref = luaL_ref (L, LUA_REGISTRYINDEX); diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c index 8eb0af5dc..2648a60b2 100644 --- a/src/lua/lua_mempool.c +++ b/src/lua/lua_mempool.c @@ -33,14 +33,14 @@ LUA_FUNCTION_DEF (mempool, create); LUA_FUNCTION_DEF (mempool, memory_pool_add_destructor); LUA_FUNCTION_DEF (mempool, memory_pool_delete); LUA_FUNCTION_DEF (mempool, memory_pool_stat); -LUA_FUNCTION_DEF (mempool, memory_pool_get_size); +LUA_FUNCTION_DEF (mempool, memory_pool_suggest_size); LUA_FUNCTION_DEF (mempool, memory_pool_set_variable); LUA_FUNCTION_DEF (mempool, memory_pool_get_variable); static const struct luaL_reg mempoollib_m[] = { LUA_INTERFACE_DEF (mempool, memory_pool_add_destructor), LUA_INTERFACE_DEF (mempool, memory_pool_stat), - LUA_INTERFACE_DEF (mempool, memory_pool_get_size), + LUA_INTERFACE_DEF (mempool, memory_pool_suggest_size), LUA_INTERFACE_DEF (mempool, memory_pool_set_variable), LUA_INTERFACE_DEF (mempool, memory_pool_get_variable), {"destroy", lua_mempool_memory_pool_delete}, @@ -60,7 +60,7 @@ static const struct luaL_reg mempoollib_f[] = { struct lua_mempool_udata { lua_State *L; gint cbref; - memory_pool_t *mempool; + rspamd_mempool_t *mempool; }; struct memory_pool_s * @@ -75,7 +75,7 @@ lua_check_mempool (lua_State * L) static int lua_mempool_create (lua_State *L) { - struct memory_pool_s *mempool = memory_pool_new (memory_pool_get_size ()), **pmempool; + struct memory_pool_s *mempool = rspamd_mempool_new (rspamd_mempool_suggest_size ()), **pmempool; if (mempool) { pmempool = lua_newuserdata (L, sizeof (struct memory_pool_s *)); @@ -109,13 +109,13 @@ lua_mempool_memory_pool_add_destructor (lua_State *L) if (mempool) { if (lua_isfunction (L, 2)) { - ud = memory_pool_alloc (mempool, sizeof (struct lua_mempool_udata)); + ud = rspamd_mempool_alloc (mempool, sizeof (struct lua_mempool_udata)); lua_pushvalue (L, 2); /* Get a reference */ ud->cbref = luaL_ref (L, LUA_REGISTRYINDEX); ud->L = L; ud->mempool = mempool; - memory_pool_add_destructor (mempool, lua_mempool_destructor_func, ud); + rspamd_mempool_add_destructor (mempool, lua_mempool_destructor_func, ud); } else { msg_err ("trying to add destructor without function"); @@ -134,7 +134,7 @@ lua_mempool_memory_pool_delete (lua_State *L) struct memory_pool_s *mempool = lua_check_mempool (L); if (mempool) { - memory_pool_delete (mempool); + rspamd_mempool_delete (mempool); return 0; } else { @@ -160,12 +160,12 @@ lua_mempool_memory_pool_stat (lua_State *L) } static int -lua_mempool_memory_pool_get_size (lua_State *L) +lua_mempool_memory_pool_suggest_size (lua_State *L) { struct memory_pool_s *mempool = lua_check_mempool (L); if (mempool) { - lua_pushinteger (L, memory_pool_get_size ()); + lua_pushinteger (L, rspamd_mempool_suggest_size ()); return 0; } else { @@ -183,7 +183,7 @@ lua_mempool_memory_pool_set_variable (lua_State *L) *value = luaL_checkstring (L, 3); if (mempool && var && value) { - memory_pool_set_variable (mempool, var, memory_pool_strdup (mempool, value), NULL); + rspamd_mempool_set_variable (mempool, var, rspamd_mempool_strdup (mempool, value), NULL); return 0; } else { @@ -201,7 +201,7 @@ lua_mempool_memory_pool_get_variable (lua_State *L) gchar *value; if (mempool && var) { - value = memory_pool_get_variable (mempool, var); + value = rspamd_mempool_get_variable (mempool, var); if (value) { lua_pushstring (L, value); } diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index 2f9020659..33caefad3 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -282,8 +282,8 @@ lua_redis_make_request (lua_State *L) /* Now get callback */ if (lua_isfunction (L, 4) && server != NULL && port > 0 && port < G_MAXUINT16) { /* Create userdata */ - ud = memory_pool_alloc (task->task_pool, sizeof (struct lua_redis_userdata)); - ud->server = memory_pool_strdup (task->task_pool, server); + ud = rspamd_mempool_alloc (task->task_pool, sizeof (struct lua_redis_userdata)); + ud->server = rspamd_mempool_strdup (task->task_pool, server); ud->port = port; ud->task = task; ud->L = L; @@ -292,14 +292,14 @@ lua_redis_make_request (lua_State *L) lua_pushvalue (L, 4); /* Get a reference */ ud->cbref = luaL_ref (L, LUA_REGISTRYINDEX); - ud->reqline = memory_pool_strdup (task->task_pool, luaL_checkstring (L, 5)); + ud->reqline = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 5)); /* Now get remaining args */ ud->args_num = lua_gettop (L) - 5; - ud->args = memory_pool_alloc (task->task_pool, ud->args_num * sizeof (f_str_t)); + ud->args = rspamd_mempool_alloc (task->task_pool, ud->args_num * sizeof (f_str_t)); for (i = 0; i < ud->args_num; i ++) { tmp = lua_tolstring (L, i + 6, &ud->args[i].len); /* Make a copy of argument */ - ud->args[i].begin = memory_pool_alloc (task->task_pool, ud->args[i].len); + ud->args[i].begin = rspamd_mempool_alloc (task->task_pool, ud->args[i].len); memcpy (ud->args[i].begin, tmp, ud->args[i].len); } /* Now check whether we need to perform DNS request */ diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c index f09116c93..ac489e53d 100644 --- a/src/lua/lua_regexp.c +++ b/src/lua/lua_regexp.c @@ -45,7 +45,7 @@ static const struct luaL_reg regexplib_f[] = { {NULL, NULL} }; -memory_pool_t *regexp_static_pool = NULL; +rspamd_mempool_t *regexp_static_pool = NULL; struct rspamd_lua_regexp { GRegex *re; @@ -269,7 +269,7 @@ luaopen_glib_regexp (lua_State * L) luaL_register (L, NULL, regexplib_m); luaL_register (L, "regexp", regexplib_f); - regexp_static_pool = memory_pool_new (memory_pool_get_size ()); + regexp_static_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); return 1; } diff --git a/src/lua/lua_session.c b/src/lua/lua_session.c index 9d0387edc..193488cef 100644 --- a/src/lua/lua_session.c +++ b/src/lua/lua_session.c @@ -143,7 +143,7 @@ lua_session_create (lua_State *L) { struct rspamd_async_session *session, **psession; struct lua_session_udata *cbdata; - memory_pool_t *mempool; + rspamd_mempool_t *mempool; @@ -166,7 +166,7 @@ lua_session_create (lua_State *L) return 1; } - cbdata = memory_pool_alloc0 (mempool, sizeof (struct lua_session_udata)); + cbdata = rspamd_mempool_alloc0 (mempool, sizeof (struct lua_session_udata)); cbdata->L = L; lua_pushvalue (L, 2); cbdata->cbref_fin = luaL_ref (L, LUA_REGISTRYINDEX); @@ -235,7 +235,7 @@ lua_session_register_async_event (lua_State *L) if (session) { if (lua_isfunction (L, 1)) { - cbdata = memory_pool_alloc (session->pool, sizeof (struct lua_event_udata)); + cbdata = rspamd_mempool_alloc (session->pool, sizeof (struct lua_event_udata)); cbdata->L = L; lua_pushvalue (L, 1); cbdata->cbref = luaL_ref (L, LUA_REGISTRYINDEX); diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 986684b27..075260359 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -354,11 +354,11 @@ lua_task_get_message (lua_State * L) static int lua_task_get_mempool (lua_State * L) { - memory_pool_t **ppool; + rspamd_mempool_t **ppool; struct worker_task *task = lua_check_task (L); if (task != NULL) { - ppool = lua_newuserdata (L, sizeof (memory_pool_t *)); + ppool = lua_newuserdata (L, sizeof (rspamd_mempool_t *)); lua_setclass (L, "rspamd{mempool}", -1); *ppool = task->task_pool; } @@ -412,13 +412,13 @@ lua_task_insert_result (lua_State * L) gint i, top; if (task != NULL) { - symbol_name = memory_pool_strdup (task->task_pool, luaL_checkstring (L, 2)); + symbol_name = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 2)); flag = luaL_checknumber (L, 3); top = lua_gettop (L); /* Get additional options */ for (i = 4; i <= top; i++) { param = luaL_checkstring (L, i); - params = g_list_prepend (params, memory_pool_strdup (task->task_pool, param)); + params = g_list_prepend (params, rspamd_mempool_strdup (task->task_pool, param)); } insert_result (task, symbol_name, flag, params); @@ -438,7 +438,7 @@ lua_task_set_pre_result (lua_State * L) if (action < task->pre_result.action) { task->pre_result.action = action; if (lua_gettop (L) >= 3) { - action_str = memory_pool_strdup (task->task_pool, luaL_checkstring (L, 3)); + action_str = rspamd_mempool_strdup (task->task_pool, luaL_checkstring (L, 3)); task->pre_result.str = action_str; } else { @@ -903,7 +903,7 @@ lua_task_set_from (lua_State *L) if (task) { new_from = luaL_checkstring (L, 2); if (new_from) { - task->from = memory_pool_strdup (task->task_pool, new_from); + task->from = rspamd_mempool_strdup (task->task_pool, new_from); } } @@ -933,7 +933,7 @@ lua_task_set_user (lua_State *L) if (task) { new_user = luaL_checkstring (L, 2); if (new_user) { - task->user = memory_pool_strdup (task->task_pool, new_user); + task->user = rspamd_mempool_strdup (task->task_pool, new_user); } } @@ -1057,7 +1057,7 @@ lua_task_set_helo (lua_State *L) if (task) { new_helo = luaL_checkstring (L, 2); if (new_helo) { - task->helo = memory_pool_strdup (task->task_pool, new_helo); + task->helo = rspamd_mempool_strdup (task->task_pool, new_helo); } } @@ -1103,7 +1103,7 @@ lua_task_set_hostname (lua_State *L) if (task) { new_hostname = luaL_checkstring (L, 2); if (new_hostname) { - task->hostname = memory_pool_strdup (task->task_pool, new_hostname); + task->hostname = rspamd_mempool_strdup (task->task_pool, new_hostname); } } diff --git a/src/main.c b/src/main.c index 83cf1c53a..0dea14d62 100644 --- a/src/main.c +++ b/src/main.c @@ -340,10 +340,10 @@ parse_filters_str (struct config_file *cfg, const gchar *str) while (*pmodule) { g_strstrip (*p); if ((*pmodule)->name != NULL && g_ascii_strcasecmp ((*pmodule)->name, *p) == 0) { - cur = memory_pool_alloc (cfg->cfg_pool, sizeof (struct filter)); + cur = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct filter)); cur->type = C_FILTER; msg_debug ("found C filter %s", *p); - cur->func_name = memory_pool_strdup (cfg->cfg_pool, *p); + cur->func_name = rspamd_mempool_strdup (cfg->cfg_pool, *p); cur->module = (*pmodule); cfg->filters = g_list_prepend (cfg->filters, cur); @@ -373,13 +373,13 @@ reread_config (struct rspamd_main *rspamd) tmp_cfg = (struct config_file *)g_malloc (sizeof (struct config_file)); if (tmp_cfg) { bzero (tmp_cfg, sizeof (struct config_file)); - tmp_cfg->cfg_pool = memory_pool_new (memory_pool_get_size ()); + tmp_cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); init_defaults (tmp_cfg); - cfg_file = memory_pool_strdup (tmp_cfg->cfg_pool, rspamd->cfg->cfg_name); + cfg_file = rspamd_mempool_strdup (tmp_cfg->cfg_pool, rspamd->cfg->cfg_name); /* Save some variables */ tmp_cfg->cfg_name = cfg_file; tmp_cfg->lua_state = init_lua (tmp_cfg); - memory_pool_add_destructor (tmp_cfg->cfg_pool, (pool_destruct_func)lua_close, tmp_cfg->lua_state); + rspamd_mempool_add_destructor (tmp_cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_close, tmp_cfg->lua_state); if (! load_rspamd_config (tmp_cfg, FALSE)) { rspamd_set_logger (rspamd_main->cfg, g_quark_try_string ("main"), rspamd_main); @@ -398,7 +398,7 @@ reread_config (struct rspamd_main *rspamd) } /* Pre-init of cache */ rspamd->cfg->cache = g_new0 (struct symbols_cache, 1); - rspamd->cfg->cache->static_pool = memory_pool_new (memory_pool_get_size ()); + rspamd->cfg->cache->static_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); rspamd->cfg->cache->cfg = rspamd->cfg; rspamd_main->cfg->cache->items_by_symbol = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); /* Perform modules configuring */ @@ -778,11 +778,11 @@ load_rspamd_config (struct config_file *cfg, gboolean init_modules) /* Strictly set temp dir */ if (!cfg->temp_dir) { msg_warn ("tempdir is not set, trying to use $TMPDIR"); - cfg->temp_dir = memory_pool_strdup (cfg->cfg_pool, getenv ("TMPDIR")); + cfg->temp_dir = rspamd_mempool_strdup (cfg->cfg_pool, getenv ("TMPDIR")); if (!cfg->temp_dir) { msg_warn ("$TMPDIR is empty too, using /tmp as default"); - cfg->temp_dir = memory_pool_strdup (cfg->cfg_pool, "/tmp"); + cfg->temp_dir = rspamd_mempool_strdup (cfg->cfg_pool, "/tmp"); } } @@ -797,7 +797,7 @@ load_rspamd_config (struct config_file *cfg, gboolean init_modules) while (l) { filt = l->data; if (filt->module) { - cur_module = memory_pool_alloc (cfg->cfg_pool, sizeof (struct module_ctx)); + cur_module = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct module_ctx)); if (filt->module->module_init_func (cfg, &cur_module) == 0) { g_hash_table_insert (cfg->c_modules, (gpointer) filt->module->name, cur_module); } @@ -1053,7 +1053,7 @@ main (gint argc, gchar **argv, gchar **env) #endif rspamd_main = (struct rspamd_main *)g_malloc (sizeof (struct rspamd_main)); memset (rspamd_main, 0, sizeof (struct rspamd_main)); - rspamd_main->server_pool = memory_pool_new (memory_pool_get_size ()); + rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); rspamd_main->cfg = (struct config_file *)g_malloc (sizeof (struct config_file)); if (!rspamd_main || !rspamd_main->cfg) { @@ -1065,11 +1065,11 @@ main (gint argc, gchar **argv, gchar **env) init_title (argc, argv, env); #endif - rspamd_main->stat = memory_pool_alloc_shared (rspamd_main->server_pool, sizeof (struct rspamd_stat)); + 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)); - rspamd_main->cfg->cfg_pool = memory_pool_new (memory_pool_get_size ()); + rspamd_main->cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); init_defaults (rspamd_main->cfg); memset (&signals, 0, sizeof (struct sigaction)); @@ -1113,7 +1113,7 @@ main (gint argc, gchar **argv, gchar **env) detect_priv (rspamd_main); rspamd_main->cfg->lua_state = init_lua (rspamd_main->cfg); - memory_pool_add_destructor (rspamd_main->cfg->cfg_pool, (pool_destruct_func)lua_close, rspamd_main->cfg->lua_state); + rspamd_mempool_add_destructor (rspamd_main->cfg->cfg_pool, (rspamd_mempool_destruct_t)lua_close, rspamd_main->cfg->lua_state); pworker = &workers[0]; while (*pworker) { @@ -1129,7 +1129,7 @@ main (gint argc, gchar **argv, gchar **env) /* Pre-init of cache */ rspamd_main->cfg->cache = g_new0 (struct symbols_cache, 1); - rspamd_main->cfg->cache->static_pool = memory_pool_new (memory_pool_get_size ()); + rspamd_main->cfg->cache->static_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); rspamd_main->cfg->cache->cfg = rspamd_main->cfg; rspamd_main->cfg->cache->items_by_symbol = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); @@ -1200,7 +1200,7 @@ main (gint argc, gchar **argv, gchar **env) rspamd_main->history = rspamd_roll_history_new (rspamd_main->server_pool); msg_info ("rspamd " RVERSION " is starting, build id: " RID); - rspamd_main->cfg->cfg_name = memory_pool_strdup (rspamd_main->cfg->cfg_pool, rspamd_main->cfg->cfg_name); + rspamd_main->cfg->cfg_name = rspamd_mempool_strdup (rspamd_main->cfg->cfg_pool, rspamd_main->cfg->cfg_name); /* Daemonize */ if (!rspamd_main->cfg->no_fork && daemon (0, 0) == -1) { diff --git a/src/main.h b/src/main.h index b47379c03..ec132fa9d 100644 --- a/src/main.h +++ b/src/main.h @@ -98,7 +98,7 @@ struct rspamd_main { guint ev_initialized; /**< is event system is initialized */ struct rspamd_stat *stat; /**< pointer to statistics */ - memory_pool_t *server_pool; /**< server's memory pool */ + rspamd_mempool_t *server_pool; /**< server's memory pool */ statfile_pool_t *statfile_pool; /**< shared statfiles pool */ GHashTable *workers; /**< workers pool indexed by pid */ rspamd_hash_t *counters; /**< symbol cache counters */ @@ -149,7 +149,7 @@ struct controller_session { gboolean restful; /**< whether this session is a restful session */ GHashTable *kwargs; /**< keyword arguments for restful command */ struct controller_command *cmd; /**< real command */ - memory_pool_t *session_pool; /**< memory pool for session */ + rspamd_mempool_t *session_pool; /**< memory pool for session */ struct config_file *cfg; /**< pointer to config file */ gchar *learn_rcpt; /**< recipient for learning */ gchar *learn_from; /**< from address for learning */ @@ -239,7 +239,7 @@ struct worker_task { struct config_file *cfg; /**< pointer to config object */ gchar *last_error; /**< last error */ gint error_code; /**< code of last error */ - memory_pool_t *task_pool; /**< memory pool for task */ + rspamd_mempool_t *task_pool; /**< memory pool for task */ #ifdef HAVE_CLOCK_GETTIME struct timespec ts; /**< time of connection */ #endif @@ -468,7 +468,7 @@ read_map_file (struct rspamd_map *map, struct file_map_data *data) * FSM for parsing lists */ gchar * -abstract_parse_kv_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data, insert_func func) +abstract_parse_kv_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data, insert_func func) { gchar *c, *p, *key = NULL, *value = NULL; @@ -482,7 +482,7 @@ abstract_parse_kv_list (memory_pool_t * pool, gchar * chunk, gint len, struct ma /* Check here comments, eol and end of buffer */ if (*p == '#') { if (key != NULL && p - c >= 0) { - value = memory_pool_alloc (pool, p - c + 1); + value = rspamd_mempool_alloc (pool, p - c + 1); memcpy (value, c, p - c); value[p - c] = '\0'; value = g_strstrip (value); @@ -493,7 +493,7 @@ abstract_parse_kv_list (memory_pool_t * pool, gchar * chunk, gint len, struct ma } else if (*p == '\r' || *p == '\n' || p - chunk == len - 1) { if (key != NULL && p - c >= 0) { - value = memory_pool_alloc (pool, p - c + 1); + value = rspamd_mempool_alloc (pool, p - c + 1); memcpy (value, c, p - c); value[p - c] = '\0'; @@ -503,10 +503,10 @@ abstract_parse_kv_list (memory_pool_t * pool, gchar * chunk, gint len, struct ma } else if (key == NULL && p - c > 0) { /* Key only line */ - key = memory_pool_alloc (pool, p - c + 1); + key = rspamd_mempool_alloc (pool, p - c + 1); memcpy (key, c, p - c); key[p - c] = '\0'; - value = memory_pool_alloc (pool, 1); + value = rspamd_mempool_alloc (pool, 1); *value = '\0'; func (data->cur_data, key, value); msg_debug ("insert kv pair: %s -> %s", key, value); @@ -516,7 +516,7 @@ abstract_parse_kv_list (memory_pool_t * pool, gchar * chunk, gint len, struct ma } else if (g_ascii_isspace (*p)) { if (p - c > 0) { - key = memory_pool_alloc (pool, p - c + 1); + key = rspamd_mempool_alloc (pool, p - c + 1); memcpy (key, c, p - c); key[p - c] = '\0'; data->state = 2; @@ -572,7 +572,7 @@ abstract_parse_kv_list (memory_pool_t * pool, gchar * chunk, gint len, struct ma } gchar * -abstract_parse_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data, insert_func func) +abstract_parse_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data, insert_func func) { gchar *s, *p, *str, *start; @@ -591,7 +591,7 @@ abstract_parse_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_c if (s != str) { /* Save previous string in lines like: "127.0.0.1 #localhost" */ *s = '\0'; - s = memory_pool_strdup (pool, g_strstrip (str)); + s = rspamd_mempool_strdup (pool, g_strstrip (str)); if (strlen (s) > 0) { func (data->cur_data, s, hash_fill); } @@ -604,7 +604,7 @@ abstract_parse_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_c /* Got EOL marker, save stored string */ if (s != str) { *s = '\0'; - s = memory_pool_strdup (pool, g_strstrip (str)); + s = rspamd_mempool_strdup (pool, g_strstrip (str)); if (strlen (s) > 0) { func (data->cur_data, s, hash_fill); } @@ -711,7 +711,7 @@ radix_tree_insert_helper (gpointer st, gconstpointer key, gpointer value) /* Helpers */ gchar * -read_host_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) +read_host_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { if (data->cur_data == NULL) { data->cur_data = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); @@ -720,7 +720,7 @@ read_host_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_dat } void -fin_host_list (memory_pool_t * pool, struct map_cb_data *data) +fin_host_list (rspamd_mempool_t * pool, struct map_cb_data *data) { if (data->prev_data) { g_hash_table_destroy (data->prev_data); @@ -728,7 +728,7 @@ fin_host_list (memory_pool_t * pool, struct map_cb_data *data) } gchar * -read_kv_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) +read_kv_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { if (data->cur_data == NULL) { data->cur_data = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); @@ -737,7 +737,7 @@ read_kv_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data } void -fin_kv_list (memory_pool_t * pool, struct map_cb_data *data) +fin_kv_list (rspamd_mempool_t * pool, struct map_cb_data *data) { if (data->prev_data) { g_hash_table_destroy (data->prev_data); @@ -745,7 +745,7 @@ fin_kv_list (memory_pool_t * pool, struct map_cb_data *data) } gchar * -read_radix_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) +read_radix_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { if (data->cur_data == NULL) { data->cur_data = radix_tree_create (); @@ -754,7 +754,7 @@ read_radix_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_da } void -fin_radix_list (memory_pool_t * pool, struct map_cb_data *data) +fin_radix_list (rspamd_mempool_t * pool, struct map_cb_data *data) { if (data->prev_data) { radix_tree_free (data->prev_data); @@ -988,7 +988,7 @@ remove_all_maps (struct config_file *cfg) g_list_free (cfg->maps); cfg->maps = NULL; if (cfg->map_pool != NULL) { - memory_pool_delete (cfg->map_pool); + rspamd_mempool_delete (cfg->map_pool); cfg->map_pool = NULL; } } @@ -1040,31 +1040,31 @@ add_map (struct config_file *cfg, const gchar *map_line, const gchar *descriptio } /* Constant pool */ if (cfg->map_pool == NULL) { - cfg->map_pool = memory_pool_new (memory_pool_get_size ()); + cfg->map_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); } - new_map = memory_pool_alloc0 (cfg->map_pool, sizeof (struct rspamd_map)); + new_map = rspamd_mempool_alloc0 (cfg->map_pool, sizeof (struct rspamd_map)); new_map->read_callback = read_callback; new_map->fin_callback = fin_callback; new_map->user_data = user_data; new_map->protocol = proto; new_map->cfg = cfg; new_map->id = g_random_int (); - new_map->locked = memory_pool_alloc0_shared (cfg->cfg_pool, sizeof (gint)); + new_map->locked = rspamd_mempool_alloc0_shared (cfg->cfg_pool, sizeof (gint)); if (proto == MAP_PROTO_FILE) { - new_map->uri = memory_pool_strdup (cfg->cfg_pool, def); + new_map->uri = rspamd_mempool_strdup (cfg->cfg_pool, def); def = new_map->uri; } else { - new_map->uri = memory_pool_strdup (cfg->cfg_pool, map_line); + new_map->uri = rspamd_mempool_strdup (cfg->cfg_pool, map_line); } if (description != NULL) { - new_map->description = memory_pool_strdup (cfg->cfg_pool, description); + new_map->description = rspamd_mempool_strdup (cfg->cfg_pool, description); } /* Now check for each proto separately */ if (proto == MAP_PROTO_FILE) { - fdata = memory_pool_alloc0 (cfg->map_pool, sizeof (struct file_map_data)); + fdata = rspamd_mempool_alloc0 (cfg->map_pool, sizeof (struct file_map_data)); if (access (def, R_OK) == -1) { if (errno != ENOENT) { msg_err ("cannot open file '%s': %s", def, strerror (errno)); @@ -1078,11 +1078,11 @@ add_map (struct config_file *cfg, const gchar *map_line, const gchar *descriptio else { stat (def, &fdata->st); } - fdata->filename = memory_pool_strdup (cfg->map_pool, def); + fdata->filename = rspamd_mempool_strdup (cfg->map_pool, def); new_map->map_data = fdata; } else if (proto == MAP_PROTO_HTTP) { - hdata = memory_pool_alloc0 (cfg->map_pool, sizeof (struct http_map_data)); + hdata = rspamd_mempool_alloc0 (cfg->map_pool, sizeof (struct http_map_data)); /* Try to search port */ if ((p = strchr (def, ':')) != NULL) { hostend = p; @@ -1109,9 +1109,9 @@ add_map (struct config_file *cfg, const gchar *map_line, const gchar *descriptio } hostend = p; } - hdata->host = memory_pool_alloc (cfg->map_pool, hostend - def + 1); + hdata->host = rspamd_mempool_alloc (cfg->map_pool, hostend - def + 1); rspamd_strlcpy (hdata->host, def, hostend - def + 1); - hdata->path = memory_pool_strdup (cfg->map_pool, p); + hdata->path = rspamd_mempool_strdup (cfg->map_pool, p); hdata->rlen = 0; /* Now try to resolve */ memset (&hints, 0, sizeof (hints)); @@ -1125,7 +1125,7 @@ add_map (struct config_file *cfg, const gchar *map_line, const gchar *descriptio if ((r = getaddrinfo (hdata->host, portbuf, &hints, &res)) == 0) { hdata->addr = res; - memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)freeaddrinfo, hdata->addr); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)freeaddrinfo, hdata->addr); } else { msg_err ("address resolution for %s failed: %s", hdata->host, gai_strerror (r)); @@ -1140,7 +1140,7 @@ add_map (struct config_file *cfg, const gchar *map_line, const gchar *descriptio new_map->map_data = hdata; } /* Temp pool */ - new_map->pool = memory_pool_new (memory_pool_get_size ()); + new_map->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); cfg->maps = g_list_prepend (cfg->maps, new_map); @@ -45,15 +45,15 @@ struct map_cb_data; /** * Callback types */ -typedef gchar* (*map_cb_t)(memory_pool_t *pool, gchar *chunk, gint len, struct map_cb_data *data); -typedef void (*map_fin_cb_t)(memory_pool_t *pool, struct map_cb_data *data); +typedef gchar* (*map_cb_t)(rspamd_mempool_t *pool, gchar *chunk, gint len, struct map_cb_data *data); +typedef void (*map_fin_cb_t)(rspamd_mempool_t *pool, struct map_cb_data *data); /** * Common map object */ struct config_file; struct rspamd_map { - memory_pool_t *pool; + rspamd_mempool_t *pool; struct config_file *cfg; enum fetch_proto protocol; map_cb_t read_callback; @@ -111,24 +111,24 @@ typedef void (*insert_func) (gpointer st, gconstpointer key, /** * Radix list is a list like ip/mask */ -gchar* read_radix_list (memory_pool_t *pool, gchar *chunk, gint len, struct map_cb_data *data); -void fin_radix_list (memory_pool_t *pool, struct map_cb_data *data); +gchar* read_radix_list (rspamd_mempool_t *pool, gchar *chunk, gint len, struct map_cb_data *data); +void fin_radix_list (rspamd_mempool_t *pool, struct map_cb_data *data); /** * Host list is an ordinal list of hosts or domains */ -gchar* read_host_list (memory_pool_t *pool, gchar *chunk, gint len, struct map_cb_data *data); -void fin_host_list (memory_pool_t *pool, struct map_cb_data *data); +gchar* read_host_list (rspamd_mempool_t *pool, gchar *chunk, gint len, struct map_cb_data *data); +void fin_host_list (rspamd_mempool_t *pool, struct map_cb_data *data); /** * Kv list is an ordinal list of keys and values separated by whitespace */ -gchar* read_kv_list (memory_pool_t *pool, gchar *chunk, gint len, struct map_cb_data *data); -void fin_kv_list (memory_pool_t *pool, struct map_cb_data *data); +gchar* read_kv_list (rspamd_mempool_t *pool, gchar *chunk, gint len, struct map_cb_data *data); +void fin_kv_list (rspamd_mempool_t *pool, struct map_cb_data *data); /** * FSM for lists parsing (support comments, blank lines and partial replies) */ -gchar * abstract_parse_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data, insert_func func); +gchar * abstract_parse_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data, insert_func func); #endif diff --git a/src/mem_pool.c b/src/mem_pool.c index 553b48fe1..8f1105add 100644 --- a/src/mem_pool.c +++ b/src/mem_pool.c @@ -56,7 +56,7 @@ pthread_mutex_t stat_mtx = PTHREAD_MUTEX_INITIALIZER; #undef MEMORY_GREEDY /* Internal statistic */ -static memory_pool_stat_t *mem_pool_stat = NULL; +static rspamd_mempool_stat_t *mem_pool_stat = NULL; /** * Function that return free space in pool page @@ -149,42 +149,42 @@ pool_chain_new_shared (gsize size) * @param size size of pool's page * @return new memory pool object */ -memory_pool_t * -memory_pool_new (gsize size) +rspamd_mempool_t * +rspamd_mempool_new (gsize size) { - memory_pool_t *new; + rspamd_mempool_t *new; gpointer map; g_return_val_if_fail (size > 0, NULL); /* Allocate statistic structure if it is not allocated before */ if (mem_pool_stat == NULL) { #if defined(HAVE_MMAP_ANON) - map = mmap (NULL, sizeof (memory_pool_stat_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0); + map = mmap (NULL, sizeof (rspamd_mempool_stat_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0); if (map == MAP_FAILED) { - msg_err ("cannot allocate %z bytes, aborting", sizeof (memory_pool_stat_t)); + msg_err ("cannot allocate %z bytes, aborting", sizeof (rspamd_mempool_stat_t)); abort (); } - mem_pool_stat = (memory_pool_stat_t *)map; + mem_pool_stat = (rspamd_mempool_stat_t *)map; #elif defined(HAVE_MMAP_ZERO) gint fd; fd = open ("/dev/zero", O_RDWR); g_assert (fd != -1); - map = mmap (NULL, sizeof (memory_pool_stat_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + map = mmap (NULL, sizeof (rspamd_mempool_stat_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (map == MAP_FAILED) { - msg_err ("cannot allocate %z bytes, aborting", sizeof (memory_pool_stat_t)); + msg_err ("cannot allocate %z bytes, aborting", sizeof (rspamd_mempool_stat_t)); abort (); } - mem_pool_stat = (memory_pool_stat_t *)map; + mem_pool_stat = (rspamd_mempool_stat_t *)map; #else # error No mmap methods are defined #endif - memset (map, 0, sizeof (memory_pool_stat_t)); + memset (map, 0, sizeof (rspamd_mempool_stat_t)); } - new = g_slice_alloc (sizeof (memory_pool_t)); + new = g_slice_alloc (sizeof (rspamd_mempool_t)); if (new == NULL) { - msg_err ("cannot allocate %z bytes, aborting", sizeof (memory_pool_t)); + msg_err ("cannot allocate %z bytes, aborting", sizeof (rspamd_mempool_t)); abort (); } @@ -204,7 +204,7 @@ memory_pool_new (gsize size) } static void * -memory_pool_alloc_common (memory_pool_t * pool, gsize size, gboolean is_tmp) +memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size, gboolean is_tmp) { guint8 *tmp; struct _pool_chain *new, *cur; @@ -285,21 +285,21 @@ memory_pool_alloc_common (memory_pool_t * pool, gsize size, gboolean is_tmp) void * -memory_pool_alloc (memory_pool_t * pool, gsize size) +rspamd_mempool_alloc (rspamd_mempool_t * pool, gsize size) { return memory_pool_alloc_common (pool, size, FALSE); } void * -memory_pool_alloc_tmp (memory_pool_t * pool, gsize size) +rspamd_mempool_alloc_tmp (rspamd_mempool_t * pool, gsize size) { return memory_pool_alloc_common (pool, size, TRUE); } void * -memory_pool_alloc0 (memory_pool_t * pool, gsize size) +rspamd_mempool_alloc0 (rspamd_mempool_t * pool, gsize size) { - void *pointer = memory_pool_alloc (pool, size); + void *pointer = rspamd_mempool_alloc (pool, size); if (pointer) { memset (pointer, 0, size); } @@ -307,9 +307,9 @@ memory_pool_alloc0 (memory_pool_t * pool, gsize size) } void * -memory_pool_alloc0_tmp (memory_pool_t * pool, gsize size) +rspamd_mempool_alloc0_tmp (rspamd_mempool_t * pool, gsize size) { - void *pointer = memory_pool_alloc_tmp (pool, size); + void *pointer = rspamd_mempool_alloc_tmp (pool, size); if (pointer) { memset (pointer, 0, size); } @@ -317,17 +317,71 @@ memory_pool_alloc0_tmp (memory_pool_t * pool, gsize size) } void * -memory_pool_alloc0_shared (memory_pool_t * pool, gsize size) +rspamd_mempool_alloc0_shared (rspamd_mempool_t * pool, gsize size) { - void *pointer = memory_pool_alloc_shared (pool, size); + void *pointer = rspamd_mempool_alloc_shared (pool, size); if (pointer) { memset (pointer, 0, size); } return pointer; } +void * +rspamd_mempool_alloc_shared (rspamd_mempool_t * pool, gsize size) +{ + guint8 *tmp; + struct _pool_chain_shared *new, *cur; + gint free; + + if (pool) { + g_return_val_if_fail(size > 0, NULL); + + POOL_MTX_LOCK () + ; + cur = pool->shared_pool; + if (!cur) { + cur = pool_chain_new_shared (pool->first_pool->len); + pool->shared_pool = cur; + } + + /* Find free space in pool chain */ + while ((free = pool_chain_free ((struct _pool_chain *) cur)) + < (gint) size && cur->next) { + cur = cur->next; + } + if (free < (gint) size && cur->next == NULL) { + /* Allocate new pool */ + + if (cur->len >= size + MEM_ALIGNMENT) { + new = pool_chain_new_shared (cur->len); + } + else { + mem_pool_stat->oversized_chunks++; + new = pool_chain_new_shared ( + size + pool->first_pool->len + MEM_ALIGNMENT); + } + /* Attach new pool to chain */ + cur->next = new; + new->pos += size; + STAT_LOCK (); + mem_pool_stat->bytes_allocated += size; + STAT_UNLOCK (); + POOL_MTX_UNLOCK () + ; + return new->begin; + } + tmp = align_ptr(cur->pos, MEM_ALIGNMENT); + cur->pos = tmp + size; + POOL_MTX_UNLOCK () + ; + return tmp; + } + return NULL; +} + + gchar * -memory_pool_strdup (memory_pool_t * pool, const gchar *src) +rspamd_mempool_strdup (rspamd_mempool_t * pool, const gchar *src) { gsize len; gchar *newstr; @@ -337,14 +391,14 @@ memory_pool_strdup (memory_pool_t * pool, const gchar *src) } len = strlen (src); - newstr = memory_pool_alloc (pool, len + 1); + newstr = rspamd_mempool_alloc (pool, len + 1); memcpy (newstr, src, len); newstr[len] = '\0'; return newstr; } gchar * -memory_pool_fstrdup (memory_pool_t * pool, const struct f_str_s *src) +rspamd_mempool_fstrdup (rspamd_mempool_t * pool, const struct f_str_s *src) { gchar *newstr; @@ -352,7 +406,7 @@ memory_pool_fstrdup (memory_pool_t * pool, const struct f_str_s *src) return NULL; } - newstr = memory_pool_alloc (pool, src->len + 1); + newstr = rspamd_mempool_alloc (pool, src->len + 1); memcpy (newstr, src->begin, src->len); newstr[src->len] = '\0'; return newstr; @@ -360,7 +414,7 @@ memory_pool_fstrdup (memory_pool_t * pool, const struct f_str_s *src) gchar * -memory_pool_strdup_shared (memory_pool_t * pool, const gchar *src) +rspamd_mempool_strdup_shared (rspamd_mempool_t * pool, const gchar *src) { gsize len; gchar *newstr; @@ -370,64 +424,15 @@ memory_pool_strdup_shared (memory_pool_t * pool, const gchar *src) } len = strlen (src); - newstr = memory_pool_alloc_shared (pool, len + 1); + newstr = rspamd_mempool_alloc_shared (pool, len + 1); memcpy (newstr, src, len); newstr[len] = '\0'; return newstr; } - -void * -memory_pool_alloc_shared (memory_pool_t * pool, gsize size) -{ - guint8 *tmp; - struct _pool_chain_shared *new, *cur; - gint free; - - if (pool) { - g_return_val_if_fail (size > 0, NULL); - - POOL_MTX_LOCK (); - cur = pool->shared_pool; - if (!cur) { - cur = pool_chain_new_shared (pool->first_pool->len); - pool->shared_pool = cur; - } - - /* Find free space in pool chain */ - while ((free = pool_chain_free ((struct _pool_chain *)cur)) < (gint)size && cur->next) { - cur = cur->next; - } - if (free < (gint)size && cur->next == NULL) { - /* Allocate new pool */ - - if (cur->len >= size + MEM_ALIGNMENT) { - new = pool_chain_new_shared (cur->len); - } - else { - mem_pool_stat->oversized_chunks++; - new = pool_chain_new_shared (size + pool->first_pool->len + MEM_ALIGNMENT); - } - /* Attach new pool to chain */ - cur->next = new; - new->pos += size; - STAT_LOCK (); - mem_pool_stat->bytes_allocated += size; - STAT_UNLOCK (); - POOL_MTX_UNLOCK (); - return new->begin; - } - tmp = align_ptr (cur->pos, MEM_ALIGNMENT); - cur->pos = tmp + size; - POOL_MTX_UNLOCK (); - return tmp; - } - return NULL; -} - /* Find pool for a pointer, returns NULL if pointer is not in pool */ static struct _pool_chain_shared * -memory_pool_find_pool (memory_pool_t * pool, void *pointer) +memory_pool_find_pool (rspamd_mempool_t * pool, void *pointer) { struct _pool_chain_shared *cur = pool->shared_pool; @@ -442,7 +447,7 @@ memory_pool_find_pool (memory_pool_t * pool, void *pointer) } static inline gint -__mutex_spin (memory_pool_mutex_t * mutex) +__mutex_spin (rspamd_mempool_mutex_t * mutex) { /* check spin count */ if (g_atomic_int_dec_and_test (&mutex->spin)) { @@ -479,7 +484,7 @@ __mutex_spin (memory_pool_mutex_t * mutex) } static void -memory_pool_mutex_spin (memory_pool_mutex_t * mutex) +memory_pool_mutex_spin (rspamd_mempool_mutex_t * mutex) { while (!g_atomic_int_compare_and_exchange (&mutex->lock, 0, 1)) { if (!__mutex_spin (mutex)) { @@ -490,7 +495,7 @@ memory_pool_mutex_spin (memory_pool_mutex_t * mutex) /* Simple implementation of spinlock */ void -memory_pool_lock_shared (memory_pool_t * pool, void *pointer) +rspamd_mempool_lock_shared (rspamd_mempool_t * pool, void *pointer) { struct _pool_chain_shared *chain; @@ -499,13 +504,13 @@ memory_pool_lock_shared (memory_pool_t * pool, void *pointer) return; } if (chain->lock == NULL) { - chain->lock = memory_pool_get_mutex (pool); + chain->lock = rspamd_mempool_get_mutex (pool); } - memory_pool_lock_mutex (chain->lock); + rspamd_mempool_lock_mutex (chain->lock); } void -memory_pool_unlock_shared (memory_pool_t * pool, void *pointer) +rspamd_mempool_unlock_shared (rspamd_mempool_t * pool, void *pointer) { struct _pool_chain_shared *chain; @@ -514,20 +519,20 @@ memory_pool_unlock_shared (memory_pool_t * pool, void *pointer) return; } if (chain->lock == NULL) { - chain->lock = memory_pool_get_mutex (pool); + chain->lock = rspamd_mempool_get_mutex (pool); return; } - memory_pool_unlock_mutex (chain->lock); + rspamd_mempool_unlock_mutex (chain->lock); } void -memory_pool_add_destructor_full (memory_pool_t * pool, pool_destruct_func func, void *data, +rspamd_mempool_add_destructor_full (rspamd_mempool_t * pool, rspamd_mempool_destruct_t func, void *data, const gchar *function, const gchar *line) { struct _pool_destructors *cur; - cur = memory_pool_alloc (pool, sizeof (struct _pool_destructors)); + cur = rspamd_mempool_alloc (pool, sizeof (struct _pool_destructors)); if (cur) { POOL_MTX_LOCK (); cur->func = func; @@ -541,7 +546,7 @@ memory_pool_add_destructor_full (memory_pool_t * pool, pool_destruct_func func, } void -memory_pool_replace_destructor (memory_pool_t * pool, pool_destruct_func func, void *old_data, void *new_data) +rspamd_mempool_replace_destructor (rspamd_mempool_t * pool, rspamd_mempool_destruct_t func, void *old_data, void *new_data) { struct _pool_destructors *tmp; @@ -558,7 +563,7 @@ memory_pool_replace_destructor (memory_pool_t * pool, pool_destruct_func func, v } void -memory_pool_delete (memory_pool_t * pool) +rspamd_mempool_delete (rspamd_mempool_t * pool) { struct _pool_chain *cur = pool->first_pool, *tmp; struct _pool_chain_shared *cur_shared = pool->shared_pool, *tmp_shared; @@ -613,11 +618,11 @@ memory_pool_delete (memory_pool_t * pool) mem_pool_stat->pools_freed++; POOL_MTX_UNLOCK (); rspamd_mutex_free (pool->mtx); - g_slice_free (memory_pool_t, pool); + g_slice_free (rspamd_mempool_t, pool); } void -memory_pool_cleanup_tmp (memory_pool_t* pool) +rspamd_mempool_cleanup_tmp (rspamd_mempool_t* pool) { struct _pool_chain *cur = pool->first_pool, *tmp; @@ -638,7 +643,7 @@ memory_pool_cleanup_tmp (memory_pool_t* pool) } void -memory_pool_stat (memory_pool_stat_t * st) +rspamd_mempool_stat (rspamd_mempool_stat_t * st) { st->pools_allocated = mem_pool_stat->pools_allocated; st->pools_freed = mem_pool_stat->pools_freed; @@ -653,7 +658,7 @@ memory_pool_stat (memory_pool_stat_t * st) /* By default allocate 8Kb chunks of memory */ #define FIXED_POOL_SIZE 8192 gsize -memory_pool_get_size (void) +rspamd_mempool_suggest_size (void) { #ifdef HAVE_GETPAGESIZE return MAX (getpagesize (), FIXED_POOL_SIZE); @@ -662,12 +667,12 @@ memory_pool_get_size (void) #endif } -memory_pool_mutex_t * -memory_pool_get_mutex (memory_pool_t * pool) +rspamd_mempool_mutex_t * +rspamd_mempool_get_mutex (rspamd_mempool_t * pool) { - memory_pool_mutex_t *res; + rspamd_mempool_mutex_t *res; if (pool != NULL) { - res = memory_pool_alloc_shared (pool, sizeof (memory_pool_mutex_t)); + res = rspamd_mempool_alloc_shared (pool, sizeof (rspamd_mempool_mutex_t)); res->lock = 0; res->owner = 0; res->spin = MUTEX_SPIN_COUNT; @@ -677,33 +682,33 @@ memory_pool_get_mutex (memory_pool_t * pool) } void -memory_pool_lock_mutex (memory_pool_mutex_t * mutex) +rspamd_mempool_lock_mutex (rspamd_mempool_mutex_t * mutex) { memory_pool_mutex_spin (mutex); mutex->owner = getpid (); } void -memory_pool_unlock_mutex (memory_pool_mutex_t * mutex) +rspamd_mempool_unlock_mutex (rspamd_mempool_mutex_t * mutex) { mutex->owner = 0; (void)g_atomic_int_compare_and_exchange (&mutex->lock, 1, 0); } -memory_pool_rwlock_t * -memory_pool_get_rwlock (memory_pool_t * pool) +rspamd_mempool_rwlock_t * +rspamd_mempool_get_rwlock (rspamd_mempool_t * pool) { - memory_pool_rwlock_t *lock; + rspamd_mempool_rwlock_t *lock; - lock = memory_pool_alloc_shared (pool, sizeof (memory_pool_rwlock_t)); - lock->__r_lock = memory_pool_get_mutex (pool); - lock->__w_lock = memory_pool_get_mutex (pool); + lock = rspamd_mempool_alloc_shared (pool, sizeof (rspamd_mempool_rwlock_t)); + lock->__r_lock = rspamd_mempool_get_mutex (pool); + lock->__w_lock = rspamd_mempool_get_mutex (pool); return lock; } void -memory_pool_rlock_rwlock (memory_pool_rwlock_t * lock) +rspamd_mempool_rlock_rwlock (rspamd_mempool_rwlock_t * lock) { /* Spin on write lock */ while (g_atomic_int_get (&lock->__w_lock->lock)) { @@ -717,10 +722,10 @@ memory_pool_rlock_rwlock (memory_pool_rwlock_t * lock) } void -memory_pool_wlock_rwlock (memory_pool_rwlock_t * lock) +rspamd_mempool_wlock_rwlock (rspamd_mempool_rwlock_t * lock) { /* Spin on write lock first */ - memory_pool_lock_mutex (lock->__w_lock); + rspamd_mempool_lock_mutex (lock->__w_lock); /* Now we have write lock set up */ /* Wait all readers */ while (g_atomic_int_get (&lock->__r_lock->lock)) { @@ -729,7 +734,7 @@ memory_pool_wlock_rwlock (memory_pool_rwlock_t * lock) } void -memory_pool_runlock_rwlock (memory_pool_rwlock_t * lock) +rspamd_mempool_runlock_rwlock (rspamd_mempool_rwlock_t * lock) { if (g_atomic_int_get (&lock->__r_lock->lock)) { (void)g_atomic_int_dec_and_test (&lock->__r_lock->lock); @@ -737,26 +742,26 @@ memory_pool_runlock_rwlock (memory_pool_rwlock_t * lock) } void -memory_pool_wunlock_rwlock (memory_pool_rwlock_t * lock) +rspamd_mempool_wunlock_rwlock (rspamd_mempool_rwlock_t * lock) { - memory_pool_unlock_mutex (lock->__w_lock); + rspamd_mempool_unlock_mutex (lock->__w_lock); } void -memory_pool_set_variable (memory_pool_t *pool, const gchar *name, gpointer value, pool_destruct_func destructor) +rspamd_mempool_set_variable (rspamd_mempool_t *pool, const gchar *name, gpointer value, rspamd_mempool_destruct_t destructor) { if (pool->variables == NULL) { pool->variables = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); } - g_hash_table_insert (pool->variables, memory_pool_strdup (pool, name), value); + g_hash_table_insert (pool->variables, rspamd_mempool_strdup (pool, name), value); if (destructor != NULL) { - memory_pool_add_destructor (pool, destructor, value); + rspamd_mempool_add_destructor (pool, destructor, value); } } gpointer -memory_pool_get_variable (memory_pool_t *pool, const gchar *name) +rspamd_mempool_get_variable (rspamd_mempool_t *pool, const gchar *name) { if (pool->variables == NULL) { return NULL; diff --git a/src/mem_pool.h b/src/mem_pool.h index 5bef5fee1..f759ed60a 100644 --- a/src/mem_pool.h +++ b/src/mem_pool.h @@ -24,7 +24,7 @@ struct f_str_s; /** * Destructor type definition */ -typedef void (*pool_destruct_func)(void *ptr); +typedef void (*rspamd_mempool_destruct_t)(void *ptr); /** * Pool mutex structure @@ -33,7 +33,7 @@ typedef struct memory_pool_mutex_s { gint lock; pid_t owner; guint spin; -} memory_pool_mutex_t; +} rspamd_mempool_mutex_t; /** * Pool page structure @@ -53,14 +53,14 @@ struct _pool_chain_shared { guint8 *pos; gsize len; struct _pool_chain_shared *next; - memory_pool_mutex_t *lock; + rspamd_mempool_mutex_t *lock; }; /** * Destructors list item structure */ struct _pool_destructors { - pool_destruct_func func; /**< pointer to destructor */ + rspamd_mempool_destruct_t func; /**< pointer to destructor */ void *data; /**< data to free */ const gchar *function; /**< function from which this destructor was added */ const gchar *loc; /**< line number */ @@ -80,7 +80,7 @@ typedef struct memory_pool_s { struct _pool_destructors *destructors; /**< destructors chain */ GHashTable *variables; /**< private memory pool variables */ struct rspamd_mutex_s *mtx; /**< threads lock */ -} memory_pool_t; +} rspamd_mempool_t; /** * Statistics structure @@ -93,22 +93,22 @@ typedef struct memory_pool_stat_s { gsize shared_chunks_allocated; /**< shared chunks allocated */ gsize chunks_freed; /**< chunks freed */ gsize oversized_chunks; /**< oversized chunks */ -} memory_pool_stat_t; +} rspamd_mempool_stat_t; /** * Rwlock for locking shared memory regions */ typedef struct memory_pool_rwlock_s { - memory_pool_mutex_t *__r_lock; /**< read mutex (private) */ - memory_pool_mutex_t *__w_lock; /**< write mutex (private) */ -} memory_pool_rwlock_t; + rspamd_mempool_mutex_t *__r_lock; /**< read mutex (private) */ + rspamd_mempool_mutex_t *__w_lock; /**< write mutex (private) */ +} rspamd_mempool_rwlock_t; /** * Allocate new memory poll * @param size size of pool's page * @return new memory pool object */ -memory_pool_t* memory_pool_new (gsize size); +rspamd_mempool_t* rspamd_mempool_new (gsize size); /** * Get memory from pool @@ -116,7 +116,7 @@ memory_pool_t* memory_pool_new (gsize size); * @param size bytes to allocate * @return pointer to allocated object */ -void* memory_pool_alloc (memory_pool_t* pool, gsize size); +void* rspamd_mempool_alloc (rspamd_mempool_t* pool, gsize size); /** * Get memory from temporary pool @@ -124,7 +124,7 @@ void* memory_pool_alloc (memory_pool_t* pool, gsize size); * @param size bytes to allocate * @return pointer to allocated object */ -void* memory_pool_alloc_tmp (memory_pool_t* pool, gsize size); +void* rspamd_mempool_alloc_tmp (rspamd_mempool_t* pool, gsize size); /** * Get memory and set it to zero @@ -132,7 +132,7 @@ void* memory_pool_alloc_tmp (memory_pool_t* pool, gsize size); * @param size bytes to allocate * @return pointer to allocated object */ -void* memory_pool_alloc0 (memory_pool_t* pool, gsize size); +void* rspamd_mempool_alloc0 (rspamd_mempool_t* pool, gsize size); /** * Get memory and set it to zero @@ -140,12 +140,12 @@ void* memory_pool_alloc0 (memory_pool_t* pool, gsize size); * @param size bytes to allocate * @return pointer to allocated object */ -void* memory_pool_alloc0_tmp (memory_pool_t* pool, gsize size); +void* rspamd_mempool_alloc0_tmp (rspamd_mempool_t* pool, gsize size); /** * Cleanup temporary data in pool */ -void memory_pool_cleanup_tmp (memory_pool_t* pool); +void rspamd_mempool_cleanup_tmp (rspamd_mempool_t* pool); /** * Make a copy of string in pool @@ -153,7 +153,7 @@ void memory_pool_cleanup_tmp (memory_pool_t* pool); * @param src source string * @return pointer to newly created string that is copy of src */ -gchar* memory_pool_strdup (memory_pool_t* pool, const gchar *src); +gchar* rspamd_mempool_strdup (rspamd_mempool_t* pool, const gchar *src); /** * Make a copy of fixed string in pool as null terminated string @@ -161,30 +161,30 @@ gchar* memory_pool_strdup (memory_pool_t* pool, const gchar *src); * @param src source string * @return pointer to newly created string that is copy of src */ -gchar* memory_pool_fstrdup (memory_pool_t* pool, const struct f_str_s *src); +gchar* rspamd_mempool_fstrdup (rspamd_mempool_t* pool, const struct f_str_s *src); /** * Allocate piece of shared memory * @param pool memory pool object * @param size bytes to allocate */ -void* memory_pool_alloc_shared (memory_pool_t *pool, gsize size); -void* memory_pool_alloc0_shared (memory_pool_t *pool, gsize size); -gchar* memory_pool_strdup_shared (memory_pool_t* pool, const gchar *src); +void* rspamd_mempool_alloc_shared (rspamd_mempool_t* pool, gsize size); +void* rspamd_mempool_alloc0_shared (rspamd_mempool_t *pool, gsize size); +gchar* rspamd_mempool_strdup_shared (rspamd_mempool_t* pool, const gchar *src); /** * Lock chunk of shared memory in which pointer is placed * @param pool memory pool object * @param pointer pointer of shared memory object that is to be locked (the whole page that contains that object is locked) */ -void memory_pool_lock_shared (memory_pool_t *pool, void *pointer); +void rspamd_mempool_lock_shared (rspamd_mempool_t *pool, void *pointer); /** * Unlock chunk of shared memory in which pointer is placed * @param pool memory pool object * @param pointer pointer of shared memory object that is to be unlocked (the whole page that contains that object is locked) */ -void memory_pool_unlock_shared (memory_pool_t *pool, void *pointer); +void rspamd_mempool_lock_shared (rspamd_mempool_t *pool, void *pointer); /** * Add destructor callback to pool @@ -192,11 +192,12 @@ void memory_pool_unlock_shared (memory_pool_t *pool, void *pointer); * @param func pointer to function-destructor * @param data pointer to data that would be passed to destructor */ -void memory_pool_add_destructor_full (memory_pool_t *pool, pool_destruct_func func, void *data, +void rspamd_mempool_add_destructor_full (rspamd_mempool_t *pool, rspamd_mempool_destruct_t func, void *data, const gchar *function, const gchar *line); /* Macros for common usage */ -#define memory_pool_add_destructor(pool, func, data) memory_pool_add_destructor_full(pool, func, data, G_STRFUNC, G_STRLOC) +#define rspamd_mempool_add_destructor(pool, func, data) \ + rspamd_mempool_add_destructor_full(pool, func, data, G_STRFUNC, G_STRLOC) /** * Replace destructor callback to pool for specified pointer @@ -205,75 +206,76 @@ void memory_pool_add_destructor_full (memory_pool_t *pool, pool_destruct_func fu * @param old_data pointer to old data * @param new_data pointer to data that would be passed to destructor */ -void memory_pool_replace_destructor (memory_pool_t *pool, pool_destruct_func func, void *old_data, void *new_data); +void rspamd_mempool_replace_destructor (rspamd_mempool_t *pool, + rspamd_mempool_destruct_t func, void *old_data, void *new_data); /** * Delete pool, free all its chunks and call destructors chain * @param pool memory pool object */ -void memory_pool_delete (memory_pool_t *pool); +void rspamd_mempool_delete (rspamd_mempool_t *pool); /** * Get new mutex from pool (allocated in shared memory) * @param pool memory pool object * @return mutex object */ -memory_pool_mutex_t* memory_pool_get_mutex (memory_pool_t *pool); +rspamd_mempool_mutex_t* rspamd_mempool_get_mutex (rspamd_mempool_t *pool); /** * Lock mutex * @param mutex mutex to lock */ -void memory_pool_lock_mutex (memory_pool_mutex_t *mutex); +void rspamd_mempool_lock_mutex (rspamd_mempool_mutex_t *mutex); /** * Unlock mutex * @param mutex mutex to unlock */ -void memory_pool_unlock_mutex (memory_pool_mutex_t *mutex); +void rspamd_mempool_unlock_mutex (rspamd_mempool_mutex_t *mutex); /** * Create new rwlock and place it in shared memory * @param pool memory pool object * @return rwlock object */ -memory_pool_rwlock_t* memory_pool_get_rwlock (memory_pool_t *pool); +rspamd_mempool_rwlock_t* rspamd_mempool_get_rwlock (rspamd_mempool_t *pool); /** * Aquire read lock * @param lock rwlock object */ -void memory_pool_rlock_rwlock (memory_pool_rwlock_t *lock); +void rspamd_mempool_rlock_rwlock (rspamd_mempool_rwlock_t *lock); /** * Aquire write lock * @param lock rwlock object */ -void memory_pool_wlock_rwlock (memory_pool_rwlock_t *lock); +void rspamd_mempool_wlock_rwlock (rspamd_mempool_rwlock_t *lock); /** * Release read lock * @param lock rwlock object */ -void memory_pool_runlock_rwlock (memory_pool_rwlock_t *lock); +void rspamd_mempool_runlock_rwlock (rspamd_mempool_rwlock_t *lock); /** * Release write lock * @param lock rwlock object */ -void memory_pool_wunlock_rwlock (memory_pool_rwlock_t *lock); +void rspamd_mempool_wunlock_rwlock (rspamd_mempool_rwlock_t *lock); /** * Get pool allocator statistics * @param st stat pool struct */ -void memory_pool_stat (memory_pool_stat_t *st); +void rspamd_mempool_stat (rspamd_mempool_stat_t *st); /** * Get optimal pool size based on page size for this system * @return size of memory page in system */ -gsize memory_pool_get_size (void); +gsize rspamd_mempool_suggest_size (void); /** * Set memory pool variable @@ -282,7 +284,8 @@ gsize memory_pool_get_size (void); * @param gpointer value value of variable * @param destructor pointer to function-destructor */ -void memory_pool_set_variable (memory_pool_t *pool, const gchar *name, gpointer value, pool_destruct_func destructor); +void rspamd_mempool_set_variable (rspamd_mempool_t *pool, const gchar *name, + gpointer value, rspamd_mempool_destruct_t destructor); /** * Get memory pool variable @@ -290,7 +293,7 @@ void memory_pool_set_variable (memory_pool_t *pool, const gchar *name, gpointer * @param name name of variable * @return NULL or pointer to variable data */ -gpointer memory_pool_get_variable (memory_pool_t *pool, const gchar *name); +gpointer rspamd_mempool_get_variable (rspamd_mempool_t *pool, const gchar *name); #endif diff --git a/src/message.c b/src/message.c index 6ad9610e4..b8d9d9d13 100644 --- a/src/message.c +++ b/src/message.c @@ -34,7 +34,7 @@ #define UTF8_CHARSET "UTF-8" GByteArray * -strip_html_tags (struct worker_task *task, memory_pool_t * pool, struct mime_text_part *part, GByteArray * src, gint *stateptr) +strip_html_tags (struct worker_task *task, rspamd_mempool_t * pool, struct mime_text_part *part, GByteArray * src, gint *stateptr) { uint8_t *p, *rp, *tbegin = NULL, *end, c, lc; gint br, i = 0, depth = 0, in_q = 0; @@ -252,7 +252,7 @@ unbreak_tag: } static void -parse_qmail_recv (memory_pool_t * pool, gchar *line, struct received_header *r) +parse_qmail_recv (rspamd_mempool_t * pool, gchar *line, struct received_header *r) { gchar *s, *p, t; @@ -276,7 +276,7 @@ parse_qmail_recv (memory_pool_t * pool, gchar *line, struct received_header *r) } else { *p = '\0'; - r->real_ip = memory_pool_strdup (pool, s); + r->real_ip = rspamd_mempool_strdup (pool, s); *p = '/'; /* Now try to parse hostname */ s = ++p; @@ -285,14 +285,14 @@ parse_qmail_recv (memory_pool_t * pool, gchar *line, struct received_header *r) } t = *p; *p = '\0'; - r->real_hostname = memory_pool_strdup (pool, s); + r->real_hostname = rspamd_mempool_strdup (pool, s); *p = t; } } } static void -parse_recv_header (memory_pool_t * pool, gchar *line, struct received_header *r) +parse_recv_header (rspamd_mempool_t * pool, gchar *line, struct received_header *r) { gchar *p, *s, t, **res = NULL; enum { @@ -347,7 +347,7 @@ parse_recv_header (memory_pool_t * pool, gchar *line, struct received_header *r) else { t = *p; *p = '\0'; - r->from_hostname = memory_pool_strdup (pool, s); + r->from_hostname = rspamd_mempool_strdup (pool, s); *p = t; state = RSPAMD_RECV_STATE_SKIP_SPACES; next_state = RSPAMD_RECV_STATE_IP_BLOCK; @@ -414,7 +414,7 @@ parse_recv_header (memory_pool_t * pool, gchar *line, struct received_header *r) p ++; } if (p > s) { - r->from_hostname = memory_pool_alloc (pool, p - s + 1); + r->from_hostname = rspamd_mempool_alloc (pool, p - s + 1); rspamd_strlcpy (r->from_hostname, s, p - s + 1); } } @@ -446,7 +446,7 @@ parse_recv_header (memory_pool_t * pool, gchar *line, struct received_header *r) /* Postfix style (hostname [ip]) */ t = *p; *p = '\0'; - r->real_hostname = memory_pool_strdup (pool, s); + r->real_hostname = rspamd_mempool_strdup (pool, s); *p = t; /* Now parse ip */ p += 2; @@ -485,11 +485,11 @@ parse_recv_header (memory_pool_t * pool, gchar *line, struct received_header *r) if (p[1] != '\0') { t = *p; *p = '\0'; - r->by_hostname = memory_pool_strdup (pool, s); + r->by_hostname = rspamd_mempool_strdup (pool, s); *p = t; } else { - r->by_hostname = memory_pool_strdup (pool, s); + r->by_hostname = rspamd_mempool_strdup (pool, s); } /* Now end of parsing */ if (is_exim) { @@ -520,7 +520,7 @@ parse_recv_header (memory_pool_t * pool, gchar *line, struct received_header *r) } else { *p = '\0'; - *res = memory_pool_strdup (pool, s); + *res = rspamd_mempool_strdup (pool, s); *p = ']'; p++; state = RSPAMD_RECV_STATE_SKIP_SPACES; @@ -577,9 +577,9 @@ process_raw_headers (struct worker_task *task) case 1: /* We got something like header's name */ if (*p == ':') { - new = memory_pool_alloc0 (task->task_pool, sizeof (struct raw_header)); + new = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct raw_header)); l = p - c; - tmp = memory_pool_alloc (task->task_pool, l + 1); + tmp = rspamd_mempool_alloc (task->task_pool, l + 1); rspamd_strlcpy (tmp, c, l + 1); new->name = tmp; new->empty_separator = TRUE; @@ -612,7 +612,7 @@ process_raw_headers (struct worker_task *task) state = 99; l = p - c; if (l > 0) { - tmp = memory_pool_alloc (task->task_pool, l + 1); + tmp = rspamd_mempool_alloc (task->task_pool, l + 1); rspamd_strlcpy (tmp, c, l + 1); new->separator = tmp; } @@ -624,7 +624,7 @@ process_raw_headers (struct worker_task *task) /* Process value */ l = p - c; if (l >= 0) { - tmp = memory_pool_alloc (task->task_pool, l + 1); + tmp = rspamd_mempool_alloc (task->task_pool, l + 1); rspamd_strlcpy (tmp, c, l + 1); new->separator = tmp; } @@ -649,7 +649,7 @@ process_raw_headers (struct worker_task *task) case 4: /* Copy header's value */ l = p - c; - tmp = memory_pool_alloc (task->task_pool, l + 1); + tmp = rspamd_mempool_alloc (task->task_pool, l + 1); tp = tmp; t_state = 0; while (l --) { @@ -812,10 +812,10 @@ convert_text_to_utf (struct worker_task *task, GByteArray * part_content, GMimeC return part_content; } - result_array = memory_pool_alloc (task->task_pool, sizeof (GByteArray)); + result_array = rspamd_mempool_alloc (task->task_pool, sizeof (GByteArray)); result_array->data = res_str; result_array->len = write_bytes; - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_free, res_str); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_free, res_str); text_part->is_raw = FALSE; text_part->is_utf = TRUE; @@ -847,7 +847,7 @@ process_text_part (struct worker_task *task, GByteArray *part_content, GMimeCont if (g_mime_content_type_is_type (type, "text", "html") || g_mime_content_type_is_type (type, "text", "xhtml")) { debug_task ("got urls from text/html part"); - text_part = memory_pool_alloc0 (task->task_pool, sizeof (struct mime_text_part)); + text_part = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct mime_text_part)); text_part->is_html = TRUE; if (is_empty) { text_part->is_empty = TRUE; @@ -875,13 +875,13 @@ process_text_part (struct worker_task *task, GByteArray *part_content, GMimeCont } fuzzy_init_part (text_part, task->task_pool, task->cfg->max_diff); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) free_byte_array_callback, text_part->content); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) free_byte_array_callback, text_part->content); task->text_parts = g_list_prepend (task->text_parts, text_part); } else if (g_mime_content_type_is_type (type, "text", "*")) { debug_task ("got urls from text/plain part"); - text_part = memory_pool_alloc0 (task->task_pool, sizeof (struct mime_text_part)); + text_part = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct mime_text_part)); text_part->is_html = FALSE; text_part->parent = parent; if (is_empty) { @@ -980,9 +980,9 @@ mime_foreach_callback (GMimeObject * part, gpointer user_data) msg_warn ("type of part is unknown, assume text/plain"); type = g_mime_content_type_new ("text", "plain"); #ifdef GMIME24 - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_object_unref, type); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_object_unref, type); #else - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_mime_content_type_destroy, type); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_mime_content_type_destroy, type); #endif } wrapper = g_mime_part_get_content_object (GMIME_PART (part)); @@ -996,7 +996,7 @@ mime_foreach_callback (GMimeObject * part, gpointer user_data) g_mime_stream_mem_set_owner (GMIME_STREAM_MEM (part_stream), FALSE); part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (part_stream)); g_object_unref (part_stream); - mime_part = memory_pool_alloc (task->task_pool, sizeof (struct mime_part)); + mime_part = rspamd_mempool_alloc (task->task_pool, sizeof (struct mime_part)); mime_part->type = type; mime_part->content = part_content; mime_part->parent = task->parser_parent_part; @@ -1047,7 +1047,7 @@ process_message (struct worker_task *task) gsize len; gint rc; - tmp = memory_pool_alloc (task->task_pool, sizeof (GByteArray)); + tmp = rspamd_mempool_alloc (task->task_pool, sizeof (GByteArray)); tmp->data = task->msg->str; tmp->len = task->msg->len; @@ -1074,7 +1074,7 @@ process_message (struct worker_task *task) } task->message = message; - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) destroy_message, task->message); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) destroy_message, task->message); /* Save message id for future use */ task->message_id = g_mime_message_get_message_id (task->message); @@ -1112,7 +1112,7 @@ process_message (struct worker_task *task) first = message_get_header (task->task_pool, message, "Received", FALSE); cur = first; while (cur) { - recv = memory_pool_alloc0 (task->task_pool, sizeof (struct received_header)); + recv = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct received_header)); parse_recv_header (task->task_pool, cur->data, recv); task->received = g_list_prepend (task->received, recv); cur = g_list_next (cur); @@ -1122,16 +1122,16 @@ process_message (struct worker_task *task) } if (task->raw_headers_str) { - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_free, task->raw_headers_str); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_free, task->raw_headers_str); process_raw_headers (task); } task->rcpts = g_mime_message_get_all_recipients (message); if (task->rcpts) { #ifdef GMIME24 - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_object_unref, task->rcpts); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_object_unref, task->rcpts); #else - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) internet_address_list_destroy, task->rcpts); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) internet_address_list_destroy, task->rcpts); #endif } @@ -1156,9 +1156,9 @@ process_message (struct worker_task *task) g_mime_part_set_content_object (part, wrapper); g_mime_message_set_mime_part (task->message, GMIME_OBJECT (part)); /* Register destructors */ - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_object_unref, wrapper); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_object_unref, part); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) destroy_message, task->message); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_object_unref, wrapper); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_object_unref, part); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) destroy_message, task->message); /* Now parse in a normal way */ task->parser_recursion = 0; #ifdef GMIME24 @@ -1168,7 +1168,7 @@ process_message (struct worker_task *task) #endif /* Generate message ID */ mid = g_mime_utils_generate_message_id ("localhost.localdomain"); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_free, mid); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_free, mid); g_mime_message_set_message_id (task->message, mid); task->message_id = mid; task->queue_id = mid; @@ -1200,7 +1200,7 @@ process_message (struct worker_task *task) /* Search to the end of url */ if (url_try_text (task->task_pool, p, end - p, NULL, &url_end, &url_str, FALSE)) { if (url_str != NULL) { - subject_url = memory_pool_alloc0 (task->task_pool, sizeof (struct uri)); + subject_url = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct uri)); if (subject_url != NULL) { /* Try to parse url */ rc = parse_uri (subject_url, url_str, task->task_pool); @@ -1261,13 +1261,13 @@ enum { */ #ifndef GMIME24 static void -header_iterate (memory_pool_t * pool, struct gmime_raw_header *h, GList ** ret, const gchar *field, gboolean strong) +header_iterate (rspamd_mempool_t * pool, struct gmime_raw_header *h, GList ** ret, const gchar *field, gboolean strong) { while (h) { if (G_LIKELY (!strong)) { if (h->value && !g_ascii_strncasecmp (field, h->name, strlen (field))) { if (pool != NULL) { - *ret = g_list_prepend (*ret, memory_pool_strdup (pool, h->value)); + *ret = g_list_prepend (*ret, rspamd_mempool_strdup (pool, h->value)); } else { *ret = g_list_prepend (*ret, g_strdup (h->value)); @@ -1277,7 +1277,7 @@ header_iterate (memory_pool_t * pool, struct gmime_raw_header *h, GList ** ret, else { if (h->value && !strncmp (field, h->name, strlen (field))) { if (pool != NULL) { - *ret = g_list_prepend (*ret, memory_pool_strdup (pool, h->value)); + *ret = g_list_prepend (*ret, rspamd_mempool_strdup (pool, h->value)); } else { *ret = g_list_prepend (*ret, g_strdup (h->value)); @@ -1289,7 +1289,7 @@ header_iterate (memory_pool_t * pool, struct gmime_raw_header *h, GList ** ret, } #else static void -header_iterate (memory_pool_t * pool, GMimeHeaderList * ls, GList ** ret, const gchar *field, gboolean strong) +header_iterate (rspamd_mempool_t * pool, GMimeHeaderList * ls, GList ** ret, const gchar *field, gboolean strong) { /* Use iterator in case of gmime 2.4 */ GMimeHeaderIter *iter; @@ -1308,7 +1308,7 @@ header_iterate (memory_pool_t * pool, GMimeHeaderList * ls, GList ** ret, const if (G_LIKELY (!strong)) { if (!g_ascii_strncasecmp (field, name, strlen (name))) { if (pool != NULL) { - *ret = g_list_prepend (*ret, memory_pool_strdup (pool, g_mime_header_iter_get_value (iter))); + *ret = g_list_prepend (*ret, rspamd_mempool_strdup (pool, g_mime_header_iter_get_value (iter))); } else { *ret = g_list_prepend (*ret, g_strdup (g_mime_header_iter_get_value (iter))); @@ -1318,7 +1318,7 @@ header_iterate (memory_pool_t * pool, GMimeHeaderList * ls, GList ** ret, const else { if (!strncmp (field, name, strlen (name))) { if (pool != NULL) { - *ret = g_list_prepend (*ret, memory_pool_strdup (pool, g_mime_header_iter_get_value (iter))); + *ret = g_list_prepend (*ret, rspamd_mempool_strdup (pool, g_mime_header_iter_get_value (iter))); } else { *ret = g_list_prepend (*ret, g_strdup (g_mime_header_iter_get_value (iter))); @@ -1337,7 +1337,7 @@ header_iterate (memory_pool_t * pool, GMimeHeaderList * ls, GList ** ret, const struct multipart_cb_data { GList *ret; - memory_pool_t *pool; + rspamd_mempool_t *pool; const gchar *field; gboolean try_search; gboolean strong; @@ -1392,7 +1392,7 @@ multipart_iterate (GMimeObject * part, gpointer user_data) } static GList * -local_message_get_header (memory_pool_t * pool, GMimeMessage * message, const gchar *field, gboolean strong) +local_message_get_header (rspamd_mempool_t * pool, GMimeMessage * message, const gchar *field, gboolean strong) { GList *gret = NULL; GMimeObject *part; @@ -1564,7 +1564,7 @@ local_message_get_recipients_##type (GMimeMessage *message, const gchar *unused) /* different declarations for different types of set and get functions */ typedef const gchar *(*GetFunc) (GMimeMessage * message); typedef InternetAddressList *(*GetRcptFunc) (GMimeMessage * message, const gchar *type); - typedef GList *(*GetListFunc) (memory_pool_t * pool, GMimeMessage * message, const gchar *type, gboolean strong); + typedef GList *(*GetListFunc) (rspamd_mempool_t * pool, GMimeMessage * message, const gchar *type, gboolean strong); typedef void (*SetFunc) (GMimeMessage * message, const gchar *value); typedef void (*SetListFunc) (GMimeMessage * message, const gchar *field, const gchar *value); @@ -1668,7 +1668,7 @@ message_set_header (GMimeMessage * message, const gchar *field, const gchar *val * You should free the GList list by yourself. **/ GList * -message_get_header (memory_pool_t * pool, GMimeMessage * message, const gchar *field, gboolean strong) +message_get_header (rspamd_mempool_t * pool, GMimeMessage * message, const gchar *field, gboolean strong) { gint i; gchar *ret = NULL, *ia_string; @@ -1692,7 +1692,7 @@ message_get_header (memory_pool_t * pool, GMimeMessage * message, const gchar *f ia_string = internet_address_to_string ((InternetAddress *) ia->address, FALSE); if (pool != NULL) { - memory_pool_add_destructor (pool, (pool_destruct_func) g_free, ia_string); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) g_free, ia_string); } gret = g_list_prepend (gret, ia_string); ia = ia->next; @@ -1702,7 +1702,7 @@ message_get_header (memory_pool_t * pool, GMimeMessage * message, const gchar *f while (--i >= 0) { ia_string = internet_address_to_string (internet_address_list_get_address (ia, i), FALSE); if (pool != NULL) { - memory_pool_add_destructor (pool, (pool_destruct_func) g_free, ia_string); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) g_free, ia_string); } gret = g_list_prepend (gret, ia_string); } @@ -1717,7 +1717,7 @@ message_get_header (memory_pool_t * pool, GMimeMessage * message, const gchar *f } if (gret == NULL && ret != NULL) { if (pool != NULL) { - gret = g_list_prepend (gret, memory_pool_strdup (pool, ret)); + gret = g_list_prepend (gret, rspamd_mempool_strdup (pool, ret)); } else { gret = g_list_prepend (gret, g_strdup (ret)); @@ -1757,7 +1757,7 @@ message_get_raw_header (struct worker_task *task, const gchar *field, gboolean s } if (gret != NULL) { - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_list_free, gret); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_list_free, gret); } return gret; diff --git a/src/message.h b/src/message.h index 5226b5209..f77c90825 100644 --- a/src/message.h +++ b/src/message.h @@ -77,7 +77,7 @@ void message_set_header (GMimeMessage *message, const gchar *field, const gchar * @param strong if this flag is TRUE header's name is case sensitive, otherwise it is not * @return A list of header's values or NULL. If list is not NULL it MUST be freed. If pool is NULL elements must be freed as well. */ -GList* message_get_header (memory_pool_t *pool, GMimeMessage *message, const gchar *field, gboolean strong); +GList* message_get_header (rspamd_mempool_t *pool, GMimeMessage *message, const gchar *field, gboolean strong); /* * Get a list of header's values with specified header's name using raw headers diff --git a/src/plugins/chartable.c b/src/plugins/chartable.c index 87f4c728e..fc9ff3f49 100644 --- a/src/plugins/chartable.c +++ b/src/plugins/chartable.c @@ -58,7 +58,7 @@ struct chartable_ctx { const gchar *symbol; double threshold; - memory_pool_t *chartable_pool; + rspamd_mempool_t *chartable_pool; }; static struct chartable_ctx *chartable_module_ctx = NULL; @@ -72,7 +72,7 @@ chartable_module_init (struct config_file *cfg, struct module_ctx **ctx) chartable_module_ctx = g_malloc (sizeof (struct chartable_ctx)); chartable_module_ctx->filter = chartable_mime_filter; - chartable_module_ctx->chartable_pool = memory_pool_new (memory_pool_get_size ()); + chartable_module_ctx->chartable_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); *ctx = (struct module_ctx *)chartable_module_ctx; @@ -110,8 +110,8 @@ chartable_module_config (struct config_file *cfg) gint chartable_module_reconfig (struct config_file *cfg) { - memory_pool_delete (chartable_module_ctx->chartable_pool); - chartable_module_ctx->chartable_pool = memory_pool_new (1024); + rspamd_mempool_delete (chartable_module_ctx->chartable_pool); + chartable_module_ctx->chartable_pool = rspamd_mempool_new (1024); return chartable_module_config (cfg); } diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index 29186e766..eb6cefb7d 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -61,7 +61,7 @@ struct dkim_ctx { const gchar *symbol_tempfail; const gchar *symbol_allow; - memory_pool_t *dkim_pool; + rspamd_mempool_t *dkim_pool; radix_tree_t *whitelist_ip; GHashTable *dkim_domains; guint strict_multiplier; @@ -92,7 +92,7 @@ dkim_module_init (struct config_file *cfg, struct module_ctx **ctx) { dkim_module_ctx = g_malloc0 (sizeof (struct dkim_ctx)); - dkim_module_ctx->dkim_pool = memory_pool_new (memory_pool_get_size ()); + dkim_module_ctx->dkim_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); *ctx = (struct module_ctx *)dkim_module_ctx; @@ -204,12 +204,12 @@ dkim_module_config (struct config_file *cfg) gint dkim_module_reconfig (struct config_file *cfg) { - memory_pool_delete (dkim_module_ctx->dkim_pool); + rspamd_mempool_delete (dkim_module_ctx->dkim_pool); radix_tree_free (dkim_module_ctx->whitelist_ip); if (dkim_module_ctx->dkim_domains) { g_hash_table_destroy (dkim_module_ctx->dkim_domains); } - dkim_module_ctx->dkim_pool = memory_pool_new (memory_pool_get_size ()); + dkim_module_ctx->dkim_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); return dkim_module_config (cfg); } @@ -289,7 +289,7 @@ dkim_module_key_handler (rspamd_dkim_key_t *key, gsize keylen, rspamd_dkim_conte msg_info ("cannot get key for domain %s", ctx->dns_key); if (err != NULL) { insert_result (task, dkim_module_ctx->symbol_tempfail, 1, - g_list_prepend (NULL, memory_pool_strdup (task->task_pool, err->message))); + g_list_prepend (NULL, rspamd_mempool_strdup (task->task_pool, err->message))); } else { diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index d184d85ea..663613e4c 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -89,7 +89,7 @@ struct fuzzy_rule { struct fuzzy_ctx { gint (*filter) (struct worker_task * task); - memory_pool_t *fuzzy_pool; + rspamd_mempool_t *fuzzy_pool; GList *fuzzy_rules; const gchar *default_symbol; guint32 min_hash_len; @@ -163,7 +163,7 @@ parse_flags (struct fuzzy_rule *rule, struct config_file *cfg, const ucl_object_ sym = ucl_object_key (val); } if (sym != NULL) { - map = memory_pool_alloc (fuzzy_module_ctx->fuzzy_pool, sizeof (struct fuzzy_mapping)); + map = rspamd_mempool_alloc (fuzzy_module_ctx->fuzzy_pool, sizeof (struct fuzzy_mapping)); map->symbol = sym; elt = ucl_object_find_key (val, "flag"); if (elt != NULL && ucl_obj_toint_safe (elt, &map->fuzzy_flag)) { @@ -205,9 +205,9 @@ parse_mime_types (const gchar *str) g_strstrip (strvec[i]); if ((p = strchr (strvec[i], '/')) != NULL) { *p = 0; - type = memory_pool_alloc (fuzzy_module_ctx->fuzzy_pool, sizeof (struct fuzzy_mime_type)); - type->type = memory_pool_strdup (fuzzy_module_ctx->fuzzy_pool, strvec[i]); - type->subtype = memory_pool_strdup (fuzzy_module_ctx->fuzzy_pool, p + 1); + type = rspamd_mempool_alloc (fuzzy_module_ctx->fuzzy_pool, sizeof (struct fuzzy_mime_type)); + type->type = rspamd_mempool_strdup (fuzzy_module_ctx->fuzzy_pool, strvec[i]); + type->subtype = rspamd_mempool_strdup (fuzzy_module_ctx->fuzzy_pool, p + 1); res = g_list_prepend (res, type); } else { @@ -216,7 +216,7 @@ parse_mime_types (const gchar *str) } if (res != NULL) { - memory_pool_add_destructor (fuzzy_module_ctx->fuzzy_pool, (pool_destruct_func)g_list_free, res); + rspamd_mempool_add_destructor (fuzzy_module_ctx->fuzzy_pool, (rspamd_mempool_destruct_t)g_list_free, res); } return res; @@ -250,7 +250,7 @@ parse_servers_string (struct fuzzy_rule *rule, const gchar *str) strvec = g_strsplit_set (str, ",", 0); num = g_strv_length (strvec); - rule->servers = memory_pool_alloc0 (fuzzy_module_ctx->fuzzy_pool, sizeof (struct storage_server) * num); + rule->servers = rspamd_mempool_alloc0 (fuzzy_module_ctx->fuzzy_pool, sizeof (struct storage_server) * num); for (i = 0; i < num; i++) { g_strstrip (strvec[i]); @@ -260,7 +260,7 @@ parse_servers_string (struct fuzzy_rule *rule, const gchar *str) if (cur->port == 0) { cur->port = DEFAULT_PORT; } - cur->name = memory_pool_strdup (fuzzy_module_ctx->fuzzy_pool, strvec[i]); + cur->name = rspamd_mempool_strdup (fuzzy_module_ctx->fuzzy_pool, strvec[i]); rule->servers_num++; } } @@ -309,15 +309,15 @@ fuzzy_to_string (fuzzy_hash_t *h) } static struct fuzzy_rule * -fuzzy_rule_new (const char *default_symbol, memory_pool_t *pool) +fuzzy_rule_new (const char *default_symbol, rspamd_mempool_t *pool) { struct fuzzy_rule *rule; - rule = memory_pool_alloc0 (pool, sizeof (struct fuzzy_rule)); + rule = rspamd_mempool_alloc0 (pool, sizeof (struct fuzzy_rule)); rule->mappings = g_hash_table_new (g_direct_hash, g_direct_equal); rule->symbol = default_symbol; - memory_pool_add_destructor (pool, (pool_destruct_func)g_hash_table_unref, rule->mappings); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t)g_hash_table_unref, rule->mappings); rule->read_only = FALSE; return rule; @@ -393,7 +393,7 @@ fuzzy_check_module_init (struct config_file *cfg, struct module_ctx **ctx) { fuzzy_module_ctx = g_malloc0 (sizeof (struct fuzzy_ctx)); - fuzzy_module_ctx->fuzzy_pool = memory_pool_new (memory_pool_get_size ()); + fuzzy_module_ctx->fuzzy_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); *ctx = (struct module_ctx *)fuzzy_module_ctx; @@ -481,9 +481,9 @@ fuzzy_check_module_config (struct config_file *cfg) gint fuzzy_check_module_reconfig (struct config_file *cfg) { - memory_pool_delete (fuzzy_module_ctx->fuzzy_pool); + rspamd_mempool_delete (fuzzy_module_ctx->fuzzy_pool); - fuzzy_module_ctx->fuzzy_pool = memory_pool_new (memory_pool_get_size ()); + fuzzy_module_ctx->fuzzy_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); return fuzzy_check_module_config (cfg); } @@ -558,7 +558,7 @@ fuzzy_io_callback (gint fd, short what, void *arg) if (map != NULL || !session->rule->skip_unknown) { rspamd_snprintf (buf, sizeof (buf), "%d: %d / %.2f", flag, value, nval); insert_result_single (session->task, symbol, nval, g_list_prepend (NULL, - memory_pool_strdup (session->task->task_pool, buf))); + rspamd_mempool_strdup (session->task->task_pool, buf))); } } goto ok; @@ -714,7 +714,7 @@ register_fuzzy_call (struct worker_task *task, struct fuzzy_rule *rule, fuzzy_ha } else { /* Create session for a socket */ - session = memory_pool_alloc (task->task_pool, sizeof (struct fuzzy_client_session)); + session = rspamd_mempool_alloc (task->task_pool, sizeof (struct fuzzy_client_session)); event_set (&session->ev, sock, EV_WRITE, fuzzy_io_callback, session); msec_to_tv (fuzzy_module_ctx->io_timeout, &session->tv); session->state = 0; @@ -786,7 +786,7 @@ fuzzy_check_rule (struct worker_task *task, struct fuzzy_rule *rule) if (fuzzy_module_ctx->min_width <= 0 || image->width >= fuzzy_module_ctx->min_width) { checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5, image->data->data, image->data->len); /* Construct fake fuzzy hash */ - fake_fuzzy = memory_pool_alloc0 (task->task_pool, sizeof (fuzzy_hash_t)); + fake_fuzzy = rspamd_mempool_alloc0 (task->task_pool, sizeof (fuzzy_hash_t)); rspamd_strlcpy (fake_fuzzy->hash_pipe, checksum, sizeof (fake_fuzzy->hash_pipe)); register_fuzzy_call (task, rule, fake_fuzzy); g_free (checksum); @@ -804,7 +804,7 @@ fuzzy_check_rule (struct worker_task *task, struct fuzzy_rule *rule) checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5, mime_part->content->data, mime_part->content->len); /* Construct fake fuzzy hash */ - fake_fuzzy = memory_pool_alloc0 (task->task_pool, sizeof (fuzzy_hash_t)); + fake_fuzzy = rspamd_mempool_alloc0 (task->task_pool, sizeof (fuzzy_hash_t)); rspamd_strlcpy (fake_fuzzy->hash_pipe, checksum, sizeof (fake_fuzzy->hash_pipe)); register_fuzzy_call (task, rule, fake_fuzzy); g_free (checksum); @@ -876,11 +876,11 @@ register_fuzzy_controller_call (struct controller_session *session, } else { /* Socket is made, create session */ - s = memory_pool_alloc (session->session_pool, sizeof (struct fuzzy_learn_session)); + s = rspamd_mempool_alloc (session->session_pool, sizeof (struct fuzzy_learn_session)); event_set (&s->ev, sock, EV_WRITE, fuzzy_learn_callback, s); msec_to_tv (fuzzy_module_ctx->io_timeout, &s->tv); s->task = task; - s->h = memory_pool_alloc (session->session_pool, sizeof (fuzzy_hash_t)); + s->h = rspamd_mempool_alloc (session->session_pool, sizeof (fuzzy_hash_t)); memcpy (s->h, h, sizeof (fuzzy_hash_t)); s->session = session; s->server = selected; @@ -1023,8 +1023,8 @@ fuzzy_process_handler (struct controller_session *session, f_str_t * in) /* Allocate message from string */ task->msg = g_string_new_len (in->begin, in->len); - saved = memory_pool_alloc0 (session->session_pool, sizeof (gint)); - err = memory_pool_alloc0 (session->session_pool, sizeof (GError *)); + saved = rspamd_mempool_alloc0 (session->session_pool, sizeof (gint)); + err = rspamd_mempool_alloc0 (session->session_pool, sizeof (GError *)); r = process_message (task); if (r == -1) { msg_warn ("processing of message failed"); @@ -1069,7 +1069,7 @@ fuzzy_process_handler (struct controller_session *session, f_str_t * in) cur = g_list_next (cur); } - memory_pool_add_destructor (session->session_pool, (pool_destruct_func)free_task_soft, task); + rspamd_mempool_add_destructor (session->session_pool, (rspamd_mempool_destruct_t)free_task_soft, task); if (res == -1) { session->state = STATE_REPLY; @@ -1200,7 +1200,7 @@ fuzzy_controller_handler (gchar **args, struct controller_session *session, gint rspamd_set_dispatcher_policy (session->dispatcher, BUFFER_CHARACTER, size); session->other_handler = fuzzy_process_handler; /* Prepare args */ - sargs = memory_pool_alloc (session->session_pool, sizeof (gint) * 3); + sargs = rspamd_mempool_alloc (session->session_pool, sizeof (gint) * 3); sargs[0] = cmd; sargs[1] = value; sargs[2] = flag; diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 298c03849..2a7978c73 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -58,8 +58,8 @@ struct regexp_ctx { GHashTable *autolearn_symbols; gchar *statfile_prefix; - memory_pool_t *regexp_pool; - memory_pool_t *dynamic_pool; + rspamd_mempool_t *regexp_pool; + rspamd_mempool_t *dynamic_pool; gsize max_size; gsize max_threads; GThreadPool *workers; @@ -304,7 +304,7 @@ parse_regexp_ipmask (const gchar *begin, struct dynamic_map_item *addr) /* Process regexp expression */ static gboolean -read_regexp_expression (memory_pool_t * pool, struct regexp_module_item *chain, +read_regexp_expression (rspamd_mempool_t * pool, struct regexp_module_item *chain, const gchar *symbol, const gchar *line, gboolean raw_mode) { struct expression *e, *cur; @@ -334,7 +334,7 @@ read_regexp_expression (memory_pool_t * pool, struct regexp_module_item *chain, /* Callbacks for reading json dynamic rules */ gchar * -json_regexp_read_cb (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) +json_regexp_read_cb (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { struct regexp_json_buf *jb; gint free, off; @@ -374,7 +374,7 @@ json_regexp_read_cb (memory_pool_t * pool, gchar * chunk, gint len, struct map_c } void -json_regexp_fin_cb (memory_pool_t * pool, struct map_cb_data *data) +json_regexp_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data) { struct regexp_json_buf *jb; guint nelts, i, j; @@ -385,7 +385,7 @@ json_regexp_fin_cb (memory_pool_t * pool, struct map_cb_data *data) struct regexp_module_item *cur_item; GList *cur_networks = NULL; struct dynamic_map_item *cur_nitem; - memory_pool_t *new_pool; + rspamd_mempool_t *new_pool; if (data->prev_data) { jb = data->prev_data; @@ -423,11 +423,11 @@ json_regexp_fin_cb (memory_pool_t * pool, struct map_cb_data *data) return; } - new_pool = memory_pool_new (memory_pool_get_size ()); + new_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); remove_dynamic_rules (jb->cfg->cache); if (regexp_module_ctx->dynamic_pool != NULL) { - memory_pool_delete (regexp_module_ctx->dynamic_pool); + rspamd_mempool_delete (regexp_module_ctx->dynamic_pool); } regexp_module_ctx->dynamic_pool = new_pool; @@ -454,7 +454,7 @@ json_regexp_fin_cb (memory_pool_t * pool, struct map_cb_data *data) msg_err ("symbol is not a string or not exists, but is required"); continue; } - cur_symbol = memory_pool_strdup (new_pool, json_string_value (cur_nm)); + cur_symbol = rspamd_mempool_strdup (new_pool, json_string_value (cur_nm)); /* Enabled flag */ cur_nm = json_object_get (cur_elt, "enabled"); if (cur_nm != NULL && json_is_boolean (cur_nm)) { @@ -467,7 +467,7 @@ json_regexp_fin_cb (memory_pool_t * pool, struct map_cb_data *data) /* Rule */ cur_nm = json_object_get (cur_elt, "rule"); if (cur_nm != NULL && json_is_string (cur_nm)) { - cur_rule = memory_pool_strdup (new_pool, json_string_value (cur_nm)); + cur_rule = rspamd_mempool_strdup (new_pool, json_string_value (cur_nm)); } /* Networks array */ cur_nm = json_object_get (cur_elt, "networks"); @@ -475,7 +475,7 @@ json_regexp_fin_cb (memory_pool_t * pool, struct map_cb_data *data) for (j = 0; j < json_array_size (cur_nm); j++) { it_val = json_array_get (cur_nm, i); if (it_val && json_is_string (it_val)) { - cur_nitem = memory_pool_alloc (new_pool, sizeof (struct dynamic_map_item)); + cur_nitem = rspamd_mempool_alloc (new_pool, sizeof (struct dynamic_map_item)); if (parse_regexp_ipmask (json_string_value (it_val), cur_nitem)) { cur_networks = g_list_prepend (cur_networks, cur_nitem); } @@ -484,7 +484,7 @@ json_regexp_fin_cb (memory_pool_t * pool, struct map_cb_data *data) } if (cur_rule) { /* Dynamic rule has rule option */ - cur_item = memory_pool_alloc0 (new_pool, sizeof (struct regexp_module_item)); + cur_item = rspamd_mempool_alloc0 (new_pool, sizeof (struct regexp_module_item)); cur_item->symbol = cur_symbol; if (read_regexp_expression (new_pool, cur_item, cur_symbol, cur_rule, jb->cfg->raw_mode)) { register_dynamic_symbol (new_pool, &jb->cfg->cache, cur_symbol, score, process_regexp_item, cur_item, cur_networks); @@ -510,7 +510,7 @@ regexp_module_init (struct config_file *cfg, struct module_ctx **ctx) { regexp_module_ctx = g_malloc (sizeof (struct regexp_ctx)); - regexp_module_ctx->regexp_pool = memory_pool_new (memory_pool_get_size ()); + regexp_module_ctx->regexp_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); regexp_module_ctx->dynamic_pool = NULL; regexp_module_ctx->autolearn_symbols = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); regexp_module_ctx->workers = NULL; @@ -543,8 +543,8 @@ parse_autolearn_param (const gchar *param, const gchar *value, struct config_fil struct autolearn_data *d; gchar *p; - p = memory_pool_strdup (regexp_module_ctx->regexp_pool, value); - d = memory_pool_alloc (regexp_module_ctx->regexp_pool, sizeof (struct autolearn_data)); + p = rspamd_mempool_strdup (regexp_module_ctx->regexp_pool, value); + d = rspamd_mempool_alloc (regexp_module_ctx->regexp_pool, sizeof (struct autolearn_data)); d->symbol = strsep (&p, ":"); if (d->symbol) { @@ -607,7 +607,7 @@ regexp_module_config (struct config_file *cfg) regexp_module_ctx->max_threads = ucl_obj_toint (value); } else if (value->type == UCL_STRING) { - cur_item = memory_pool_alloc0 (regexp_module_ctx->regexp_pool, sizeof (struct regexp_module_item)); + cur_item = rspamd_mempool_alloc0 (regexp_module_ctx->regexp_pool, sizeof (struct regexp_module_item)); cur_item->symbol = ucl_object_key (value); if (!read_regexp_expression (regexp_module_ctx->regexp_pool, cur_item, ucl_object_key (value), ucl_obj_tostring (value), cfg->raw_mode)) { @@ -616,7 +616,7 @@ regexp_module_config (struct config_file *cfg) register_symbol (&cfg->cache, cur_item->symbol, 1, process_regexp_item, cur_item); } else if (value->type == UCL_USERDATA) { - cur_item = memory_pool_alloc0 (regexp_module_ctx->regexp_pool, sizeof (struct regexp_module_item)); + cur_item = rspamd_mempool_alloc0 (regexp_module_ctx->regexp_pool, sizeof (struct regexp_module_item)); cur_item->symbol = ucl_object_key (value); cur_item->lua_function = value->value.ud; register_symbol (&cfg->cache, cur_item->symbol, 1, process_regexp_item, cur_item); @@ -632,8 +632,8 @@ regexp_module_config (struct config_file *cfg) gint regexp_module_reconfig (struct config_file *cfg) { - memory_pool_delete (regexp_module_ctx->regexp_pool); - regexp_module_ctx->regexp_pool = memory_pool_new (memory_pool_get_size ()); + rspamd_mempool_delete (regexp_module_ctx->regexp_pool); + regexp_module_ctx->regexp_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); return regexp_module_config (cfg); } @@ -744,7 +744,7 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task, const gchar return 0; } else { - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_list_free, headerlist); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_list_free, headerlist); /* Check whether we have regexp for it */ if (re->regexp == NULL) { debug_task ("regexp contains only header and it is found %s", re->header); @@ -1273,7 +1273,7 @@ process_regexp_item (struct worker_task *task, void *user_data) # endif workers_mtx = g_mutex_new (); #else - workers_mtx = memory_pool_alloc (regexp_module_ctx->regexp_pool, sizeof (GMutex)); + workers_mtx = rspamd_mempool_alloc (regexp_module_ctx->regexp_pool, sizeof (GMutex)); g_mutex_init (workers_mtx); #endif nL = init_lua_locked (task->cfg); @@ -1286,7 +1286,7 @@ process_regexp_item (struct worker_task *task, void *user_data) return; } } - thr_ud = memory_pool_alloc (task->task_pool, sizeof (struct regexp_threaded_ud)); + thr_ud = rspamd_mempool_alloc (task->task_pool, sizeof (struct regexp_threaded_ud)); thr_ud->item = item; thr_ud->task = task; diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 2a58021d3..239e58d3b 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -55,7 +55,7 @@ struct spf_ctx { const gchar *symbol_softfail; const gchar *symbol_allow; - memory_pool_t *spf_pool; + rspamd_mempool_t *spf_pool; radix_tree_t *whitelist_ip; rspamd_lru_hash_t *spf_hash; }; @@ -83,7 +83,7 @@ spf_module_init (struct config_file *cfg, struct module_ctx **ctx) { spf_module_ctx = g_malloc (sizeof (struct spf_ctx)); - spf_module_ctx->spf_pool = memory_pool_new (memory_pool_get_size ()); + spf_module_ctx->spf_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); *ctx = (struct module_ctx *)spf_module_ctx; @@ -151,9 +151,9 @@ spf_module_config (struct config_file *cfg) gint spf_module_reconfig (struct config_file *cfg) { - memory_pool_delete (spf_module_ctx->spf_pool); + rspamd_mempool_delete (spf_module_ctx->spf_pool); radix_tree_free (spf_module_ctx->whitelist_ip); - spf_module_ctx->spf_pool = memory_pool_new (memory_pool_get_size ()); + spf_module_ctx->spf_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); return spf_module_config (cfg); } diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index f26f7adc7..58f9acb58 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -116,16 +116,16 @@ exception_insert (gpointer st, gconstpointer key, gpointer value) } static gchar * -read_exceptions_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) +read_exceptions_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { if (data->cur_data == NULL) { - data->cur_data = memory_pool_alloc0 (pool, sizeof (GHashTable *) * MAX_LEVELS); + data->cur_data = rspamd_mempool_alloc0 (pool, sizeof (GHashTable *) * MAX_LEVELS); } return abstract_parse_list (pool, chunk, len, data, (insert_func) exception_insert); } static void -fin_exceptions_list (memory_pool_t * pool, struct map_cb_data *data) +fin_exceptions_list (rspamd_mempool_t * pool, struct map_cb_data *data) { GHashTable **t; gint i; @@ -190,7 +190,7 @@ redirector_item_free (gpointer p) } static gchar * -read_redirectors_list (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) +read_redirectors_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { if (data->cur_data == NULL) { data->cur_data = g_hash_table_new_full (rspamd_strcase_hash, rspamd_strcase_equal, g_free, redirector_item_free); @@ -200,7 +200,7 @@ read_redirectors_list (memory_pool_t * pool, gchar * chunk, gint len, struct map } void -fin_redirectors_list (memory_pool_t * pool, struct map_cb_data *data) +fin_redirectors_list (rspamd_mempool_t * pool, struct map_cb_data *data) { if (data->prev_data) { g_hash_table_destroy (data->prev_data); @@ -214,7 +214,7 @@ surbl_module_init (struct config_file *cfg, struct module_ctx **ctx) surbl_module_ctx->use_redirector = 0; surbl_module_ctx->suffixes = NULL; - surbl_module_ctx->surbl_pool = memory_pool_new (memory_pool_get_size ()); + surbl_module_ctx->surbl_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); surbl_module_ctx->tld2_file = NULL; surbl_module_ctx->whitelist_file = NULL; @@ -225,13 +225,13 @@ surbl_module_init (struct config_file *cfg, struct module_ctx **ctx) surbl_module_ctx->redirector_hosts = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); surbl_module_ctx->whitelist = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); /* Zero exceptions hashes */ - surbl_module_ctx->exceptions = memory_pool_alloc0 (surbl_module_ctx->surbl_pool, MAX_LEVELS * sizeof (GHashTable *)); + surbl_module_ctx->exceptions = rspamd_mempool_alloc0 (surbl_module_ctx->surbl_pool, MAX_LEVELS * sizeof (GHashTable *)); /* Register destructors */ - memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func) g_hash_table_destroy, surbl_module_ctx->whitelist); - memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func) g_hash_table_destroy, surbl_module_ctx->redirector_hosts); + rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool, (rspamd_mempool_destruct_t) g_hash_table_destroy, surbl_module_ctx->whitelist); + rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool, (rspamd_mempool_destruct_t) g_hash_table_destroy, surbl_module_ctx->redirector_hosts); - memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func) rspamd_trie_free, surbl_module_ctx->redirector_trie); - memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func) g_ptr_array_unref, surbl_module_ctx->redirector_ptrs); + rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool, (rspamd_mempool_destruct_t) rspamd_trie_free, surbl_module_ctx->redirector_trie); + rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool, (rspamd_mempool_destruct_t) g_ptr_array_unref, surbl_module_ctx->redirector_ptrs); *ctx = (struct module_ctx *)surbl_module_ctx; @@ -280,7 +280,7 @@ surbl_module_config (struct config_file *cfg) LL_FOREACH (value, cur) { i ++; } - surbl_module_ctx->redirectors = memory_pool_alloc0 (surbl_module_ctx->surbl_pool, + surbl_module_ctx->redirectors = rspamd_mempool_alloc0 (surbl_module_ctx->surbl_pool, i * sizeof (struct redirector_upstream)); idx = 0; LL_FOREACH (value, cur) { @@ -294,7 +294,7 @@ surbl_module_config (struct config_file *cfg) } else { if (surbl_module_ctx->redirectors[idx].port != 0) { - surbl_module_ctx->redirectors[idx].name = memory_pool_strdup (surbl_module_ctx->surbl_pool, + surbl_module_ctx->redirectors[idx].name = rspamd_mempool_strdup (surbl_module_ctx->surbl_pool, redir_val); msg_info ("add redirector %s", surbl_module_ctx->redirectors[idx].name); idx ++; @@ -352,7 +352,7 @@ surbl_module_config (struct config_file *cfg) if (add_map (cfg, ucl_obj_tostring (value), "SURBL exceptions list", read_exceptions_list, fin_exceptions_list, (void **)&surbl_module_ctx->exceptions)) { - surbl_module_ctx->tld2_file = memory_pool_strdup (surbl_module_ctx->surbl_pool, + surbl_module_ctx->tld2_file = rspamd_mempool_strdup (surbl_module_ctx->surbl_pool, ucl_obj_tostring (value) + sizeof ("file://") - 1); } } @@ -360,7 +360,7 @@ surbl_module_config (struct config_file *cfg) if (add_map (cfg, ucl_obj_tostring (value), "SURBL whitelist", read_host_list, fin_host_list, (void **)&surbl_module_ctx->whitelist)) { - surbl_module_ctx->whitelist_file = memory_pool_strdup (surbl_module_ctx->surbl_pool, + surbl_module_ctx->whitelist_file = rspamd_mempool_strdup (surbl_module_ctx->surbl_pool, ucl_obj_tostring (value) + sizeof ("file://") - 1); } } @@ -373,8 +373,8 @@ surbl_module_config (struct config_file *cfg) msg_err ("surbl rule must have explicit symbol definition"); continue; } - new_suffix = memory_pool_alloc (surbl_module_ctx->surbl_pool, sizeof (struct suffix_item)); - new_suffix->suffix = memory_pool_strdup (surbl_module_ctx->surbl_pool, + new_suffix = rspamd_mempool_alloc (surbl_module_ctx->surbl_pool, sizeof (struct suffix_item)); + new_suffix->suffix = rspamd_mempool_strdup (surbl_module_ctx->surbl_pool, ucl_obj_tostring (cur)); new_suffix->options = 0; new_suffix->bits = NULL; @@ -383,11 +383,11 @@ surbl_module_config (struct config_file *cfg) if (cur == NULL) { msg_warn ("surbl rule for suffix %s lacks symbol, using %s as symbol", new_suffix->suffix, DEFAULT_SURBL_SYMBOL); - new_suffix->symbol = memory_pool_strdup (surbl_module_ctx->surbl_pool, + new_suffix->symbol = rspamd_mempool_strdup (surbl_module_ctx->surbl_pool, DEFAULT_SURBL_SYMBOL); } else { - new_suffix->symbol = memory_pool_strdup (surbl_module_ctx->surbl_pool, + new_suffix->symbol = rspamd_mempool_strdup (surbl_module_ctx->surbl_pool, ucl_obj_tostring (cur)); } cur = ucl_obj_get_key (cur_rule, "options"); @@ -402,9 +402,9 @@ surbl_module_config (struct config_file *cfg) while ((cur_bit = ucl_iterate_object (cur, &it, true)) != NULL) { if (ucl_object_key (cur_bit) != NULL && cur_bit->type == UCL_INT) { bit = ucl_obj_toint (cur_bit); - new_bit = memory_pool_alloc (surbl_module_ctx->surbl_pool, sizeof (struct surbl_bit_item)); + new_bit = rspamd_mempool_alloc (surbl_module_ctx->surbl_pool, sizeof (struct surbl_bit_item)); new_bit->bit = bit; - new_bit->symbol = memory_pool_strdup (surbl_module_ctx->surbl_pool, ucl_object_key (cur_bit)); + new_bit->symbol = rspamd_mempool_strdup (surbl_module_ctx->surbl_pool, ucl_object_key (cur_bit)); msg_debug ("add new bit suffix: %d with symbol: %s", (gint)new_bit->bit, new_bit->symbol); new_suffix->bits = g_list_prepend (new_suffix->bits, new_bit); } @@ -421,7 +421,7 @@ surbl_module_config (struct config_file *cfg) } if (surbl_module_ctx->suffixes != NULL) { - memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func) g_list_free, + rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool, (rspamd_mempool_destruct_t) g_list_free, surbl_module_ctx->suffixes); } @@ -430,7 +430,7 @@ surbl_module_config (struct config_file *cfg) cur_suffix = cur_opt->data; if (cur_suffix->bits != NULL) { register_bit_symbols (cfg, cur_suffix); - memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func) g_list_free, + rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool, (rspamd_mempool_destruct_t) g_list_free, cur_suffix->bits); } cur_opt = g_list_next (cur_opt); @@ -443,11 +443,11 @@ gint surbl_module_reconfig (struct config_file *cfg) { /* Delete pool and objects */ - memory_pool_delete (surbl_module_ctx->surbl_pool); + rspamd_mempool_delete (surbl_module_ctx->surbl_pool); /* Reinit module */ surbl_module_ctx->use_redirector = 0; surbl_module_ctx->suffixes = NULL; - surbl_module_ctx->surbl_pool = memory_pool_new (memory_pool_get_size ()); + surbl_module_ctx->surbl_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); surbl_module_ctx->tld2_file = NULL; surbl_module_ctx->whitelist_file = NULL; @@ -457,15 +457,15 @@ surbl_module_reconfig (struct config_file *cfg) surbl_module_ctx->redirector_hosts = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); surbl_module_ctx->whitelist = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); /* Zero exceptions hashes */ - surbl_module_ctx->exceptions = memory_pool_alloc0 (surbl_module_ctx->surbl_pool, MAX_LEVELS * sizeof (GHashTable *)); + surbl_module_ctx->exceptions = rspamd_mempool_alloc0 (surbl_module_ctx->surbl_pool, MAX_LEVELS * sizeof (GHashTable *)); /* Register destructors */ - memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func) g_hash_table_destroy, surbl_module_ctx->whitelist); - memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func) g_hash_table_destroy, surbl_module_ctx->redirector_hosts); + rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool, (rspamd_mempool_destruct_t) g_hash_table_destroy, surbl_module_ctx->whitelist); + rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool, (rspamd_mempool_destruct_t) g_hash_table_destroy, surbl_module_ctx->redirector_hosts); - memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func) g_list_free, surbl_module_ctx->suffixes); + rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool, (rspamd_mempool_destruct_t) g_list_free, surbl_module_ctx->suffixes); - memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func) rspamd_trie_free, surbl_module_ctx->redirector_trie); - memory_pool_add_destructor (surbl_module_ctx->surbl_pool, (pool_destruct_func) g_ptr_array_unref, surbl_module_ctx->redirector_ptrs); + rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool, (rspamd_mempool_destruct_t) rspamd_trie_free, surbl_module_ctx->redirector_trie); + rspamd_mempool_add_destructor (surbl_module_ctx->surbl_pool, (rspamd_mempool_destruct_t) g_ptr_array_unref, surbl_module_ctx->redirector_ptrs); /* Perform configure */ return surbl_module_config (cfg); @@ -474,7 +474,7 @@ surbl_module_reconfig (struct config_file *cfg) static gchar * -format_surbl_request (memory_pool_t * pool, f_str_t * hostname, struct suffix_item *suffix, +format_surbl_request (rspamd_mempool_t * pool, f_str_t * hostname, struct suffix_item *suffix, gboolean append_suffix, GError ** err, gboolean forced, GTree *tree) { GHashTable *t; @@ -515,7 +515,7 @@ format_surbl_request (memory_pool_t * pool, f_str_t * hostname, struct suffix_it msg_info ("ignore request of ip url for list %s", suffix->symbol); return NULL; } - result = memory_pool_alloc (pool, len); + result = rspamd_mempool_alloc (pool, len); r = rspamd_snprintf (result, len, "%*s.%*s.%*s.%*s", (gint)(hostname->len - (dots[2] - hostname->begin + 1)), dots[2] + 1, @@ -545,7 +545,7 @@ format_surbl_request (memory_pool_t * pool, f_str_t * hostname, struct suffix_it } len = sizeof ("255.255.255.255") + slen; - result = memory_pool_alloc (pool, len); + result = rspamd_mempool_alloc (pool, len); /* Hack for bugged windows resolver */ ip_num &= 0xFFFFFFFF; /* Get octets */ @@ -554,7 +554,7 @@ format_surbl_request (memory_pool_t * pool, f_str_t * hostname, struct suffix_it } else { /* Not a numeric url */ - result = memory_pool_alloc (pool, len); + result = rspamd_mempool_alloc (pool, len); /* Now we should try to check for exceptions */ if (! forced) { for (i = MAX_LEVELS - 1; i >= 0; i --) { @@ -637,11 +637,11 @@ make_surbl_requests (struct uri *url, struct worker_task *task, if (check_view (task->cfg->views, suffix->symbol, task)) { if ((surbl_req = format_surbl_request (task->task_pool, &f, suffix, TRUE, &err, forced, tree)) != NULL) { - param = memory_pool_alloc (task->task_pool, sizeof (struct dns_param)); + param = rspamd_mempool_alloc (task->task_pool, sizeof (struct dns_param)); param->url = url; param->task = task; param->suffix = suffix; - param->host_resolve = memory_pool_strdup (task->task_pool, surbl_req); + param->host_resolve = rspamd_mempool_strdup (task->task_pool, surbl_req); debug_task ("send surbl dns request %s", surbl_req); if (make_dns_request (task->resolver, task->s, task->task_pool, dns_callback, (void *)param, RDNS_REQUEST_A, surbl_req)) { @@ -677,13 +677,13 @@ process_dns_results (struct worker_task *task, struct suffix_item *suffix, gchar (gint)bit->bit & (gint)ntohl (addr)); if (((gint)bit->bit & (gint)ntohl (addr)) != 0) { insert_result (task, bit->symbol, 1, - g_list_prepend (NULL, memory_pool_strdup (task->task_pool, url))); + g_list_prepend (NULL, rspamd_mempool_strdup (task->task_pool, url))); } cur = g_list_next (cur); } } else { - insert_result (task, suffix->symbol, 1, g_list_prepend (NULL, memory_pool_strdup (task->task_pool, url))); + insert_result (task, suffix->symbol, 1, g_list_prepend (NULL, rspamd_mempool_strdup (task->task_pool, url))); } } @@ -768,16 +768,16 @@ register_memcached_call (struct uri *url, struct worker_task *task, gchar *sum_str; gint *url_count; - param = memory_pool_alloc (task->task_pool, sizeof (struct memcached_param)); - cur_param = memory_pool_alloc0 (task->task_pool, sizeof (memcached_param_t)); - url_count = memory_pool_alloc (task->task_pool, sizeof (gint)); + param = rspamd_mempool_alloc (task->task_pool, sizeof (struct memcached_param)); + cur_param = rspamd_mempool_alloc0 (task->task_pool, sizeof (memcached_param_t)); + url_count = rspamd_mempool_alloc (task->task_pool, sizeof (gint)); param->url = url; param->task = task; param->suffix = suffix; param->tree = tree; - param->ctx = memory_pool_alloc0 (task->task_pool, sizeof (memcached_ctx_t)); + param->ctx = rspamd_mempool_alloc0 (task->task_pool, sizeof (memcached_ctx_t)); cur_param->buf = (gchar *) url_count; cur_param->bufsize = sizeof (gint); @@ -836,7 +836,7 @@ redirector_callback (gint fd, short what, void *arg) case STATE_CONNECT: /* We have write readiness after connect call, so reinit event */ if (what == EV_WRITE) { - timeout = memory_pool_alloc (param->task->task_pool, sizeof (struct timeval)); + timeout = rspamd_mempool_alloc (param->task->task_pool, sizeof (struct timeval)); timeout->tv_sec = surbl_module_ctx->read_timeout / 1000; timeout->tv_usec = (surbl_module_ctx->read_timeout - timeout->tv_sec * 1000) * 1000; event_del (¶m->ev); @@ -885,7 +885,7 @@ redirector_callback (gint fd, short what, void *arg) } if (found) { debug_task ("<%s> got reply from redirector: '%s' -> '%s'", param->task->message_id, struri (param->url), c); - r = parse_uri (param->url, memory_pool_strdup (param->task->task_pool, c), param->task->task_pool); + r = parse_uri (param->url, rspamd_mempool_strdup (param->task->task_pool, c), param->task->task_pool); if (r == URI_ERRNO_OK || r == URI_ERRNO_NO_SLASHES || r == URI_ERRNO_NO_HOST_SLASH) { make_surbl_requests (param->url, param->task, param->suffix, FALSE, param->tree); } @@ -930,7 +930,7 @@ register_redirector_call (struct uri *url, struct worker_task *task, return; } - param = memory_pool_alloc (task->task_pool, sizeof (struct redirector_param)); + param = rspamd_mempool_alloc (task->task_pool, sizeof (struct redirector_param)); param->url = url; param->task = task; param->state = STATE_CONNECT; @@ -939,7 +939,7 @@ register_redirector_call (struct uri *url, struct worker_task *task, param->redirector = selected; param->buf = g_string_sized_new (1024); param->tree = tree; - timeout = memory_pool_alloc (task->task_pool, sizeof (struct timeval)); + timeout = rspamd_mempool_alloc (task->task_pool, sizeof (struct timeval)); timeout->tv_sec = surbl_module_ctx->connect_timeout / 1000; timeout->tv_usec = (surbl_module_ctx->connect_timeout - timeout->tv_sec * 1000) * 1000; event_set (¶m->ev, s, EV_WRITE, redirector_callback, (void *)param); @@ -1016,7 +1016,7 @@ surbl_test_url (struct worker_task *task, void *user_data) param.task = task; param.suffix = suffix; param.tree = g_tree_new ((GCompareFunc)strcmp); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_tree_destroy, param.tree); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_tree_destroy, param.tree); g_tree_foreach (task->urls, surbl_tree_url_callback, ¶m); } /* @@ -1078,7 +1078,7 @@ urls_command_handler (struct worker_task *task) cb.off = 0; g_tree_foreach (task->urls, calculate_buflen_cb, &cb); - cb.buf = memory_pool_alloc (task->task_pool, cb.len * sizeof (gchar)); + cb.buf = rspamd_mempool_alloc (task->task_pool, cb.len * sizeof (gchar)); cb.off += rspamd_snprintf (cb.buf + cb.off, cb.len - cb.off, "%s/%s 0 %s" CRLF "Urls:", (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER, "1.3", SPAMD_OK); diff --git a/src/plugins/surbl.h b/src/plugins/surbl.h index 27eaa75dd..80554b713 100644 --- a/src/plugins/surbl.h +++ b/src/plugins/surbl.h @@ -45,7 +45,7 @@ struct surbl_ctx { guint use_redirector; struct redirector_upstream *redirectors; guint32 redirectors_number; - memory_pool_t *surbl_pool; + rspamd_mempool_t *surbl_pool; }; struct suffix_item { diff --git a/src/protocol.c b/src/protocol.c index b0b70954c..db1fa0bfd 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -560,7 +560,7 @@ make_rewritten_subject (struct metric *metric, struct worker_task *task) } res = g_mime_utils_header_encode_text (subj_buf); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_free, res); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_free, res); return res; } diff --git a/src/proxy.c b/src/proxy.c index b6f1917ae..67c7665b8 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -211,19 +211,19 @@ rspamd_proxy_backend_handler (gint fd, gshort what, gpointer data) * @return new proxy object */ rspamd_proxy_t* -rspamd_create_proxy (gint cfd, gint bfd, memory_pool_t *pool, struct event_base *base, +rspamd_create_proxy (gint cfd, gint bfd, rspamd_mempool_t *pool, struct event_base *base, gsize bufsize, struct timeval *tv, dispatcher_err_callback_t err_cb, gpointer ud) { rspamd_proxy_t *new; - new = memory_pool_alloc0 (pool, sizeof (rspamd_proxy_t)); + new = rspamd_mempool_alloc0 (pool, sizeof (rspamd_proxy_t)); new->cfd = dup (cfd); new->bfd = dup (bfd); new->pool = pool; new->base = base; new->bufsize = bufsize; - new->buf = memory_pool_alloc (pool, bufsize); + new->buf = rspamd_mempool_alloc (pool, bufsize); new->err_cb = err_cb; new->user_data = ud; new->tv = tv; diff --git a/src/proxy.h b/src/proxy.h index 970957e56..c505fe83d 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -37,7 +37,7 @@ typedef struct rspamd_proxy_s { struct event client_ev; /**< event for client's communication */ struct event backend_ev; /**< event for backend communication */ struct event_base *base; /**< base for event operations */ - memory_pool_t *pool; /**< memory pool */ + rspamd_mempool_t *pool; /**< memory pool */ dispatcher_err_callback_t err_cb; /**< error callback */ struct event_base *ev_base; /**< event base */ gint cfd; /**< client's socket */ @@ -60,7 +60,7 @@ typedef struct rspamd_proxy_s { * @param ud user data for callback * @return new proxy object */ -rspamd_proxy_t* rspamd_create_proxy (gint cfd, gint bfd, memory_pool_t *pool, +rspamd_proxy_t* rspamd_create_proxy (gint cfd, gint bfd, rspamd_mempool_t *pool, struct event_base *base, gsize bufsize, struct timeval *tv, dispatcher_err_callback_t err_cb, gpointer ud); diff --git a/src/radix.c b/src/radix.c index 680f7be54..1a05db178 100644 --- a/src/radix.c +++ b/src/radix.c @@ -39,7 +39,7 @@ radix_tree_create (void) return NULL; } - tree->pool = memory_pool_new (memory_pool_get_size ()); + tree->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); tree->size = 0; tree->root = radix_alloc (tree); @@ -290,7 +290,7 @@ radix_alloc (radix_tree_t * tree) { gchar *p; - p = memory_pool_alloc (tree->pool, sizeof (radix_node_t)); + p = rspamd_mempool_alloc (tree->pool, sizeof (radix_node_t)); tree->size += sizeof (radix_node_t); @@ -302,7 +302,7 @@ radix_tree_free (radix_tree_t * tree) { g_return_if_fail (tree != NULL); - memory_pool_delete (tree->pool); + rspamd_mempool_delete (tree->pool); g_free (tree); } diff --git a/src/radix.h b/src/radix.h index 7e45f5d12..4cc2873c7 100644 --- a/src/radix.h +++ b/src/radix.h @@ -20,7 +20,7 @@ struct radix_node_s { typedef struct { radix_node_t *root; size_t size; - memory_pool_t *pool; + rspamd_mempool_t *pool; } radix_tree_t; typedef gboolean (*radix_tree_traverse_func)(guint32 key, guint32 mask, uintptr_t value, void *user_data); diff --git a/src/roll_history.c b/src/roll_history.c index b189e12d6..1ffa9240f 100644 --- a/src/roll_history.c +++ b/src/roll_history.c @@ -34,7 +34,7 @@ * @return new structure */ struct roll_history* -rspamd_roll_history_new (memory_pool_t *pool) +rspamd_roll_history_new (rspamd_mempool_t *pool) { struct roll_history *new; @@ -42,9 +42,9 @@ rspamd_roll_history_new (memory_pool_t *pool) return NULL; } - new = memory_pool_alloc0_shared (pool, sizeof (struct roll_history)); + new = rspamd_mempool_alloc0_shared (pool, sizeof (struct roll_history)); new->pool = pool; - new->mtx = memory_pool_get_mutex (pool); + new->mtx = rspamd_mempool_get_mutex (pool); return new; } @@ -83,9 +83,9 @@ rspamd_roll_history_update (struct roll_history *history, struct worker_task *ta if (history->need_lock) { /* Some process is getting history, so wait on a mutex */ - memory_pool_lock_mutex (history->mtx); + rspamd_mempool_lock_mutex (history->mtx); history->need_lock = FALSE; - memory_pool_unlock_mutex (history->mtx); + rspamd_mempool_unlock_mutex (history->mtx); } /* First of all obtain check and obtain row number */ diff --git a/src/roll_history.h b/src/roll_history.h index 58ce6e9d9..a09584337 100644 --- a/src/roll_history.h +++ b/src/roll_history.h @@ -68,9 +68,9 @@ struct roll_history_row { struct roll_history { struct roll_history_row rows[HISTORY_MAX_ROWS]; gint cur_row; - memory_pool_t *pool; + rspamd_mempool_t *pool; gboolean need_lock; - memory_pool_mutex_t *mtx; + rspamd_mempool_mutex_t *mtx; }; /** @@ -78,7 +78,7 @@ struct roll_history { * @param pool pool for shared memory * @return new structure */ -struct roll_history* rspamd_roll_history_new (memory_pool_t *pool); +struct roll_history* rspamd_roll_history_new (rspamd_mempool_t *pool); /** * Update roll history with data from task diff --git a/src/settings.c b/src/settings.c index b5e043fbf..2e9b76fd8 100644 --- a/src/settings.c +++ b/src/settings.c @@ -115,7 +115,7 @@ settings_unref (struct rspamd_settings *s) gchar * -json_read_cb (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) +json_read_cb (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { struct json_buf *jb; size_t free, off; @@ -155,7 +155,7 @@ json_read_cb (memory_pool_t * pool, gchar * chunk, gint len, struct map_cb_data } void -json_fin_cb (memory_pool_t * pool, struct map_cb_data *data) +json_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data) { struct json_buf *jb; gint nelts, i, n, j; @@ -579,13 +579,13 @@ apply_metric_settings (struct worker_task *task, struct metric *metric, struct m if (us != NULL || ds != NULL) { if (us != NULL) { res->user_settings = settings_ref (us); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)settings_unref, + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)settings_unref, us); } if (ds != NULL) { /* Need to ref hash table to avoid occasional data corruption */ res->domain_settings = settings_ref (ds); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)settings_unref, + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)settings_unref, ds); } } diff --git a/src/smtp.c b/src/smtp.c index 6b7fbe1eb..32e9826b0 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -310,7 +310,7 @@ process_smtp_data (struct smtp_session *session) session->task->resolver = session->resolver; session->task->fin_callback = smtp_write_socket; session->task->fin_arg = session; - session->task->msg = memory_pool_alloc (session->pool, sizeof (GString)); + session->task->msg = rspamd_mempool_alloc (session->pool, sizeof (GString)); session->task->s = session->s; #ifdef HAVE_MMAP_NOCORE if ((session->task->msg->str = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED | MAP_NOCORE, session->temp_fd, 0)) == MAP_FAILED) { @@ -326,7 +326,7 @@ process_smtp_data (struct smtp_session *session) cur = session->from; if (cur) { f = cur->data; - s = memory_pool_alloc (session->pool, f->len + 1); + s = rspamd_mempool_alloc (session->pool, f->len + 1); rspamd_strlcpy (s, f->begin, f->len + 1); session->task->from = s; } @@ -336,7 +336,7 @@ process_smtp_data (struct smtp_session *session) cur = t->data; if (cur) { f = cur->data; - s = memory_pool_alloc (session->pool, f->len + 1); + s = rspamd_mempool_alloc (session->pool, f->len + 1); rspamd_strlcpy (s, f->begin, f->len + 1); session->task->rcpt = g_list_prepend (session->task->rcpt, s); } @@ -557,8 +557,8 @@ smtp_make_delay (struct smtp_session *session) gint32 jitter; if (session->ctx->smtp_delay != 0 && session->state == SMTP_STATE_DELAY) { - tev = memory_pool_alloc (session->pool, sizeof (struct event)); - tv = memory_pool_alloc (session->pool, sizeof (struct timeval)); + tev = rspamd_mempool_alloc (session->pool, sizeof (struct event)); + tv = rspamd_mempool_alloc (session->pool, sizeof (struct timeval)); if (session->ctx->delay_jitter != 0) { jitter = g_random_int_range (0, session->ctx->delay_jitter); msec_to_tv (session->ctx->smtp_delay + jitter, tv); @@ -597,10 +597,10 @@ smtp_dns_cb (struct rspamd_dns_reply *reply, void *arg) "DNS error: %s", dns_strerror (reply->code)); if (reply->code == RDNS_RC_NXDOMAIN) { - session->hostname = memory_pool_strdup (session->pool, XCLIENT_HOST_UNAVAILABLE); + session->hostname = rspamd_mempool_strdup (session->pool, XCLIENT_HOST_UNAVAILABLE); } else { - session->hostname = memory_pool_strdup (session->pool, XCLIENT_HOST_TEMPFAIL); + session->hostname = rspamd_mempool_strdup (session->pool, XCLIENT_HOST_TEMPFAIL); } session->state = SMTP_STATE_DELAY; smtp_make_delay (session); @@ -608,7 +608,7 @@ smtp_dns_cb (struct rspamd_dns_reply *reply, void *arg) else { if (reply->elements) { elt = reply->elements->data; - session->hostname = memory_pool_strdup (session->pool, elt->ptr.name); + session->hostname = rspamd_mempool_strdup (session->pool, elt->ptr.name); session->state = SMTP_STATE_RESOLVE_NORMAL; make_dns_request (session->resolver, session->s, session->pool, smtp_dns_cb, session, RDNS_REQUEST_A, session->hostname); @@ -622,10 +622,10 @@ smtp_dns_cb (struct rspamd_dns_reply *reply, void *arg) "DNS error: %s", dns_strerror (reply->code)); if (reply->code == RDNS_RC_NXDOMAIN) { - session->hostname = memory_pool_strdup (session->pool, XCLIENT_HOST_UNAVAILABLE); + session->hostname = rspamd_mempool_strdup (session->pool, XCLIENT_HOST_UNAVAILABLE); } else { - session->hostname = memory_pool_strdup (session->pool, XCLIENT_HOST_TEMPFAIL); + session->hostname = rspamd_mempool_strdup (session->pool, XCLIENT_HOST_TEMPFAIL); } session->state = SMTP_STATE_DELAY; smtp_make_delay (session); @@ -645,7 +645,7 @@ smtp_dns_cb (struct rspamd_dns_reply *reply, void *arg) if (res == 0) { msg_info ("cannot find address for hostname: %s, ip: %s", session->hostname, inet_ntoa (session->client_addr)); - session->hostname = memory_pool_strdup (session->pool, XCLIENT_HOST_UNAVAILABLE); + session->hostname = rspamd_mempool_strdup (session->pool, XCLIENT_HOST_UNAVAILABLE); } session->state = SMTP_STATE_DELAY; smtp_make_delay (session); @@ -689,7 +689,7 @@ accept_socket (gint fd, short what, void *arg) ctx = worker->ctx; session = g_malloc0 (sizeof (struct smtp_session)); - session->pool = memory_pool_new (memory_pool_get_size ()); + session->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); if (su.ss.ss_family == AF_UNIX) { msg_info ("accepted connection from unix socket"); @@ -773,7 +773,7 @@ parse_smtp_banner (struct smtp_worker_ctx *ctx, const gchar *line) banner_len += sizeof (CRLF); } - ctx->smtp_banner = memory_pool_alloc (ctx->pool, banner_len + 1); + ctx->smtp_banner = rspamd_mempool_alloc (ctx->pool, banner_len + 1); t = ctx->smtp_banner; p = (gchar *)line; @@ -841,7 +841,7 @@ make_capabilities (struct smtp_worker_ctx *ctx, const gchar *line) len += sizeof ("250-") + sizeof (CRLF) + strlen (p) - 2; } - result = memory_pool_alloc (ctx->pool, len); + result = rspamd_mempool_alloc (ctx->pool, len); ctx->smtp_capabilities = result; p = result; @@ -872,7 +872,7 @@ init_smtp (struct config_file *cfg) type = g_quark_try_string ("smtp"); ctx = g_malloc0 (sizeof (struct smtp_worker_ctx)); - ctx->pool = memory_pool_new (memory_pool_get_size ()); + ctx->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); /* Set default values */ ctx->smtp_timeout_raw = 300000; @@ -1006,7 +1006,7 @@ register_smtp_filter (struct smtp_worker_ctx *ctx, enum rspamd_smtp_stage stage, { struct smtp_filter *new; - new = memory_pool_alloc (ctx->pool, sizeof (struct smtp_filter)); + new = rspamd_mempool_alloc (ctx->pool, sizeof (struct smtp_filter)); new->filter = filter; new->filter_data = filter_data; diff --git a/src/smtp.h b/src/smtp.h index 714fb3523..ab5bc9766 100644 --- a/src/smtp.h +++ b/src/smtp.h @@ -24,7 +24,7 @@ struct smtp_worker_ctx { gsize upstream_num; gchar *upstreams_str; - memory_pool_t *pool; + rspamd_mempool_t *pool; gchar *smtp_banner; gchar *smtp_banner_str; guint32 smtp_delay; @@ -68,7 +68,7 @@ enum rspamd_smtp_state { struct smtp_session { struct smtp_worker_ctx *ctx; struct config_file *cfg; - memory_pool_t *pool; + rspamd_mempool_t *pool; enum rspamd_smtp_state state; enum rspamd_smtp_state upstream_state; diff --git a/src/smtp_proto.c b/src/smtp_proto.c index e1e7f3229..3af1c3910 100644 --- a/src/smtp_proto.c +++ b/src/smtp_proto.c @@ -31,7 +31,7 @@ #include "smtp_utils.h" gchar * -make_smtp_error (memory_pool_t *pool, gint error_code, const gchar *format, ...) +make_smtp_error (rspamd_mempool_t *pool, gint error_code, const gchar *format, ...) { va_list vp; gchar *result = NULL, *p; @@ -42,7 +42,7 @@ make_smtp_error (memory_pool_t *pool, gint error_code, const gchar *format, ...) va_end (vp); va_start (vp, format); len += sizeof ("65535 ") + sizeof (CRLF) - 1; - result = memory_pool_alloc (pool, len); + result = rspamd_mempool_alloc (pool, len); p = result + rspamd_snprintf (result, len, "%d ", error_code); p = rspamd_vsnprintf (p, len - (p - result), format, vp); *p++ = CR; *p++ = LF; *p = '\0'; @@ -73,7 +73,7 @@ parse_smtp_command (struct smtp_session *session, f_str_t *line, struct smtp_com state = SMTP_PARSE_START; c = line->begin; p = c; - *cmd = memory_pool_alloc0 (session->pool, sizeof (struct smtp_command)); + *cmd = rspamd_mempool_alloc0 (session->pool, sizeof (struct smtp_command)); pcmd = *cmd; for (i = 0; i < line->len; i ++, p ++) { @@ -158,7 +158,7 @@ parse_smtp_command (struct smtp_session *session, f_str_t *line, struct smtp_com } else if (ch != ' ' && ch != ':') { state = SMTP_PARSE_ARGUMENT; - arg = memory_pool_alloc (session->pool, sizeof (f_str_t)); + arg = rspamd_mempool_alloc (session->pool, sizeof (f_str_t)); c = p; } break; @@ -168,7 +168,7 @@ parse_smtp_command (struct smtp_session *session, f_str_t *line, struct smtp_com p ++; } arg->len = p - c; - arg->begin = memory_pool_alloc (session->pool, arg->len); + arg->begin = rspamd_mempool_alloc (session->pool, arg->len); memcpy (arg->begin, c, arg->len); pcmd->args = g_list_prepend (pcmd->args, arg); if (ch == ' ' || ch == ':') { @@ -194,7 +194,7 @@ parse_smtp_command (struct smtp_session *session, f_str_t *line, struct smtp_com end: if (pcmd->args) { pcmd->args = g_list_reverse (pcmd->args); - memory_pool_add_destructor (session->pool, (pool_destruct_func)g_list_free, pcmd->args); + rspamd_mempool_add_destructor (session->pool, (rspamd_mempool_destruct_t)g_list_free, pcmd->args); } return TRUE; } @@ -228,7 +228,7 @@ parse_smtp_helo (struct smtp_session *session, struct smtp_command *cmd) return FALSE; } arg = cmd->args->data; - session->helo = memory_pool_alloc (session->pool, arg->len + 1); + session->helo = rspamd_mempool_alloc (session->pool, arg->len + 1); rspamd_strlcpy (session->helo, arg->begin, arg->len + 1); /* Now try to write reply */ if (cmd->command == SMTP_COMMAND_HELO) { @@ -399,7 +399,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg) case SMTP_STATE_GREETING: r = check_smtp_ustream_reply (in, '2'); if (r == -1) { - session->error = memory_pool_alloc (session->pool, in->len + 1); + session->error = rspamd_mempool_alloc (session->pool, in->len + 1); rspamd_strlcpy (session->error, in->begin, in->len + 1); /* XXX: assume upstream errors as critical errors */ session->state = SMTP_STATE_CRITICAL_ERROR; @@ -438,7 +438,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg) case SMTP_STATE_HELO: r = check_smtp_ustream_reply (in, '2'); if (r == -1) { - session->error = memory_pool_alloc (session->pool, in->len + 1); + session->error = rspamd_mempool_alloc (session->pool, in->len + 1); rspamd_strlcpy (session->error, in->begin, in->len + 1); /* XXX: assume upstream errors as critical errors */ session->state = SMTP_STATE_CRITICAL_ERROR; @@ -468,7 +468,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg) case SMTP_STATE_FROM: r = check_smtp_ustream_reply (in, '2'); if (r == -1) { - session->error = memory_pool_alloc (session->pool, in->len + 1); + session->error = rspamd_mempool_alloc (session->pool, in->len + 1); rspamd_strlcpy (session->error, in->begin, in->len + 1); /* XXX: assume upstream errors as critical errors */ session->state = SMTP_STATE_CRITICAL_ERROR; @@ -492,7 +492,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg) case SMTP_STATE_RCPT: r = check_smtp_ustream_reply (in, '2'); if (r == -1) { - session->error = memory_pool_alloc (session->pool, in->len + 1); + session->error = rspamd_mempool_alloc (session->pool, in->len + 1); rspamd_strlcpy (session->error, in->begin, in->len + 1); /* XXX: assume upstream errors as critical errors */ session->state = SMTP_STATE_CRITICAL_ERROR; @@ -518,7 +518,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg) case SMTP_STATE_BEFORE_DATA: r = check_smtp_ustream_reply (in, '2'); if (r == -1) { - session->error = memory_pool_alloc (session->pool, in->len + 1); + session->error = rspamd_mempool_alloc (session->pool, in->len + 1); rspamd_strlcpy (session->error, in->begin, in->len + 1); rspamd_dispatcher_restore (session->dispatcher); if (! rspamd_dispatcher_write (session->dispatcher, session->error, in->len, FALSE, TRUE)) { @@ -550,7 +550,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg) session->upstream_state = SMTP_STATE_DATA; rspamd_dispatcher_pause (session->upstream_dispatcher); } - session->error = memory_pool_alloc (session->pool, in->len + 1); + session->error = rspamd_mempool_alloc (session->pool, in->len + 1); rspamd_strlcpy (session->error, in->begin, in->len + 1); /* Write to client */ if (! rspamd_dispatcher_write (session->dispatcher, session->error, in->len, FALSE, TRUE)) { @@ -568,7 +568,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg) case SMTP_STATE_DATA: r = check_smtp_ustream_reply (in, '3'); if (r == -1) { - session->error = memory_pool_alloc (session->pool, in->len + 1); + session->error = rspamd_mempool_alloc (session->pool, in->len + 1); rspamd_strlcpy (session->error, in->begin, in->len + 1); /* XXX: assume upstream errors as critical errors */ session->state = SMTP_STATE_CRITICAL_ERROR; @@ -606,7 +606,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg) } break; case SMTP_STATE_AFTER_DATA: - session->error = memory_pool_alloc (session->pool, in->len + 1); + session->error = rspamd_mempool_alloc (session->pool, in->len + 1); rspamd_strlcpy (session->error, in->begin, in->len + 1); session->state = SMTP_STATE_DATA; rspamd_dispatcher_restore (session->dispatcher); @@ -625,7 +625,7 @@ smtp_upstream_read_socket (f_str_t * in, void *arg) case SMTP_STATE_END: r = check_smtp_ustream_reply (in, '5'); if (r == -1) { - session->error = memory_pool_alloc (session->pool, in->len + 1); + session->error = rspamd_mempool_alloc (session->pool, in->len + 1); rspamd_strlcpy (session->error, in->begin, in->len + 1); /* XXX: assume upstream errors as critical errors */ session->state = SMTP_STATE_CRITICAL_ERROR; diff --git a/src/smtp_proto.h b/src/smtp_proto.h index efb09bf35..42fecd255 100644 --- a/src/smtp_proto.h +++ b/src/smtp_proto.h @@ -43,7 +43,7 @@ struct smtp_command { /* * Generate SMTP error message */ -gchar * make_smtp_error (memory_pool_t *pool, gint error_code, const gchar *format, ...); +gchar * make_smtp_error (rspamd_mempool_t *pool, gint error_code, const gchar *format, ...); /* * Parse a single SMTP command diff --git a/src/smtp_proxy.c b/src/smtp_proxy.c index be978e936..bffad8e48 100644 --- a/src/smtp_proxy.c +++ b/src/smtp_proxy.c @@ -70,7 +70,7 @@ struct smtp_proxy_ctx { size_t upstream_num; gchar *upstreams_str; - memory_pool_t *pool; + rspamd_mempool_t *pool; guint32 smtp_delay; guint32 delay_jitter; guint32 smtp_timeout_raw; @@ -102,7 +102,7 @@ enum rspamd_smtp_proxy_state { struct smtp_proxy_session { struct smtp_proxy_ctx *ctx; - memory_pool_t *pool; + rspamd_mempool_t *pool; enum rspamd_smtp_proxy_state state; struct rspamd_worker *worker; @@ -240,7 +240,7 @@ free_smtp_proxy_session (gpointer arg) event_del (&session->upstream_ev); close (session->upstream_sock); } - memory_pool_delete (session->pool); + rspamd_mempool_delete (session->pool); g_slice_free1 (sizeof (struct smtp_proxy_session), session); } } @@ -555,7 +555,7 @@ make_rbl_requests (struct smtp_proxy_session *session) cur = session->ctx->rbls; while (cur) { len = INET_ADDRSTRLEN + strlen (cur->data) + 1; - dst = memory_pool_alloc (session->pool, len); + dst = rspamd_mempool_alloc (session->pool, len); /* Print ipv4 addr */ p = (gchar *)&session->client_addr.s_addr; rspamd_snprintf (dst, len, "%ud.%ud.%ud.%ud.%s", (guint)p[3], @@ -621,8 +621,8 @@ smtp_make_delay (struct smtp_proxy_session *session) gint32 jitter; if (session->ctx->smtp_delay != 0 && session->state == SMTP_PROXY_STATE_DELAY) { - tev = memory_pool_alloc (session->pool, sizeof(struct event)); - tv = memory_pool_alloc (session->pool, sizeof(struct timeval)); + tev = rspamd_mempool_alloc (session->pool, sizeof(struct event)); + tv = rspamd_mempool_alloc (session->pool, sizeof(struct timeval)); if (session->ctx->delay_jitter != 0) { jitter = g_random_int_range (0, session->ctx->delay_jitter); msec_to_tv (session->ctx->smtp_delay + jitter, tv); @@ -671,11 +671,11 @@ smtp_dns_cb (struct rdns_reply *reply, void *arg) rdns_strerror (reply->code)); if (reply->code == RDNS_RC_NXDOMAIN) { - session->hostname = memory_pool_strdup (session->pool, + session->hostname = rspamd_mempool_strdup (session->pool, XCLIENT_HOST_UNAVAILABLE); } else { - session->hostname = memory_pool_strdup (session->pool, + session->hostname = rspamd_mempool_strdup (session->pool, XCLIENT_HOST_TEMPFAIL); } session->state = SMTP_PROXY_STATE_DELAY; @@ -684,7 +684,7 @@ smtp_dns_cb (struct rdns_reply *reply, void *arg) else { if (reply->entries) { elt = reply->entries; - session->hostname = memory_pool_strdup (session->pool, + session->hostname = rspamd_mempool_strdup (session->pool, elt->content.ptr.name); session->state = SMTP_PROXY_STATE_RESOLVE_NORMAL; make_dns_request (session->resolver, session->s, session->pool, @@ -700,11 +700,11 @@ smtp_dns_cb (struct rdns_reply *reply, void *arg) rdns_strerror (reply->code)); if (reply->code == RDNS_RC_NXDOMAIN) { - session->hostname = memory_pool_strdup (session->pool, + session->hostname = rspamd_mempool_strdup (session->pool, XCLIENT_HOST_UNAVAILABLE); } else { - session->hostname = memory_pool_strdup (session->pool, + session->hostname = rspamd_mempool_strdup (session->pool, XCLIENT_HOST_TEMPFAIL); } session->state = SMTP_PROXY_STATE_DELAY; @@ -726,7 +726,7 @@ smtp_dns_cb (struct rdns_reply *reply, void *arg) msg_info( "cannot find address for hostname: %s, ip: %s", session->hostname, inet_ntoa (session->client_addr)); - session->hostname = memory_pool_strdup (session->pool, + session->hostname = rspamd_mempool_strdup (session->pool, XCLIENT_HOST_UNAVAILABLE); } session->state = SMTP_PROXY_STATE_DELAY; @@ -759,7 +759,7 @@ proxy_parse_smtp_input (f_str_t *line, struct smtp_proxy_session *session) p ++; } len = p - c; - session->rcpt = memory_pool_alloc (session->pool, len + 1); + session->rcpt = rspamd_mempool_alloc (session->pool, len + 1); rspamd_strlcpy (session->rcpt, c, len + 1); } } @@ -775,7 +775,7 @@ proxy_parse_smtp_input (f_str_t *line, struct smtp_proxy_session *session) p ++; } len = p - c; - session->from = memory_pool_alloc (session->pool, len + 1); + session->from = rspamd_mempool_alloc (session->pool, len + 1); rspamd_strlcpy (session->from, c, len + 1); } } @@ -919,7 +919,7 @@ accept_socket (gint fd, short what, void *arg) ctx = worker->ctx; session = g_slice_alloc0 (sizeof (struct smtp_proxy_session)); - session->pool = memory_pool_new (memory_pool_get_size ()); + session->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); if (su.ss.ss_family == AF_UNIX) { msg_info ("accepted connection from unix socket"); @@ -967,7 +967,7 @@ init_smtp_proxy (struct config_file *cfg) type = g_quark_try_string ("smtp_proxy"); ctx = g_malloc0 (sizeof (struct smtp_worker_ctx)); - ctx->pool = memory_pool_new (memory_pool_get_size ()); + ctx->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); /* Set default values */ ctx->smtp_timeout_raw = 300000; diff --git a/src/smtp_utils.c b/src/smtp_utils.c index ed7dfeb7e..68aed8e81 100644 --- a/src/smtp_utils.c +++ b/src/smtp_utils.c @@ -53,7 +53,7 @@ free_smtp_session (gpointer arg) if (session->temp_fd != -1) { close (session->temp_fd); } - memory_pool_delete (session->pool); + rspamd_mempool_delete (session->pool); g_free (session); } } @@ -190,7 +190,7 @@ make_smtp_tempfile (struct smtp_session *session) gsize r; r = strlen (session->cfg->temp_dir) + sizeof ("/rspamd-XXXXXX"); - session->temp_name = memory_pool_alloc (session->pool, r); + session->temp_name = rspamd_mempool_alloc (session->pool, r); rspamd_snprintf (session->temp_name, r, "%s%crspamd-XXXXXX", session->cfg->temp_dir, G_DIR_SEPARATOR); #ifdef HAVE_MKSTEMP /* Umask is set before */ @@ -261,7 +261,7 @@ write_smtp_reply (struct smtp_session *session) old_subject = g_mime_message_get_subject (session->task->message); if (old_subject != NULL) { sublen = strlen (old_subject) + sizeof (SPAM_SUBJECT); - new_subject = memory_pool_alloc (session->pool, sublen); + new_subject = rspamd_mempool_alloc (session->pool, sublen); rspamd_snprintf (new_subject, sublen, "%s%s", SPAM_SUBJECT, old_subject); } else { @@ -306,7 +306,7 @@ err: } gboolean -parse_upstreams_line (memory_pool_t *pool, struct smtp_upstream *upstreams, const gchar *line, gsize *count) +parse_upstreams_line (rspamd_mempool_t *pool, struct smtp_upstream *upstreams, const gchar *line, gsize *count) { gchar **strv, *p, *t, *tt, *err_str; guint32 num, i; @@ -344,7 +344,7 @@ parse_upstreams_line (memory_pool_t *pool, struct smtp_upstream *upstreams, cons g_strfreev (strv); return FALSE; } - cur->name = memory_pool_strdup (pool, resolved_path); + cur->name = rspamd_mempool_strdup (pool, resolved_path); (*count) ++; } else { @@ -352,7 +352,7 @@ parse_upstreams_line (memory_pool_t *pool, struct smtp_upstream *upstreams, cons g_strfreev (strv); return FALSE; } - cur->name = memory_pool_strdup (pool, p); + cur->name = rspamd_mempool_strdup (pool, p); (*count) ++; } } diff --git a/src/smtp_utils.h b/src/smtp_utils.h index b27578804..652b6759f 100644 --- a/src/smtp_utils.h +++ b/src/smtp_utils.h @@ -58,6 +58,6 @@ void free_smtp_session (gpointer arg); * @param count targeted count * @return */ -gboolean parse_upstreams_line (memory_pool_t *pool, struct smtp_upstream *upstreams, const gchar *line, gsize *count); +gboolean parse_upstreams_line (rspamd_mempool_t *pool, struct smtp_upstream *upstreams, const gchar *line, gsize *count); #endif /* SMTP_UTILS_H_ */ @@ -372,14 +372,14 @@ parse_spf_hostmask (struct worker_task *task, const gchar *begin, struct spf_add } if (host == NULL) { hostlen = p - begin; - host = memory_pool_alloc (task->task_pool, hostlen); + host = rspamd_mempool_alloc (task->task_pool, hostlen); rspamd_strlcpy (host, begin, hostlen); } } else { addr->data.normal.mask = 32; if (host == NULL) { - host = memory_pool_strdup (task->task_pool, begin); + host = rspamd_mempool_strdup (task->task_pool, begin); } } @@ -423,7 +423,7 @@ spf_record_dns_callback (struct rdns_reply *reply, gpointer arg) /* Insert one more address */ tmp = spf_addr_find (cb->rec->addrs, cb->addr); if (tmp) { - new_addr = memory_pool_alloc (task->task_pool, sizeof (struct spf_addr)); + new_addr = rspamd_mempool_alloc (task->task_pool, sizeof (struct spf_addr)); memcpy (new_addr, cb->addr, sizeof (struct spf_addr)); new_addr->data.normal.d.in4.s_addr = elt_data->content.a.addr.s_addr; new_addr->data.normal.parsed = TRUE; @@ -448,7 +448,7 @@ spf_record_dns_callback (struct rdns_reply *reply, gpointer arg) /* Insert one more address */ tmp = spf_addr_find (cb->rec->addrs, cb->addr); if (tmp) { - new_addr = memory_pool_alloc (task->task_pool, sizeof (struct spf_addr)); + new_addr = rspamd_mempool_alloc (task->task_pool, sizeof (struct spf_addr)); memcpy (new_addr, cb->addr, sizeof (struct spf_addr)); memcpy (&new_addr->data.normal.d.in6, &elt_data->content.aaa.addr, sizeof (struct in6_addr)); new_addr->data.normal.parsed = TRUE; @@ -618,7 +618,7 @@ parse_spf_a (struct worker_task *task, const gchar *begin, struct spf_record *re return FALSE; } rec->dns_requests ++; - cb = memory_pool_alloc (task->task_pool, sizeof (struct spf_dns_cb)); + cb = rspamd_mempool_alloc (task->task_pool, sizeof (struct spf_dns_cb)); cb->rec = rec; cb->addr = addr; cb->cur_action = SPF_RESOLVE_A; @@ -665,7 +665,7 @@ parse_spf_mx (struct worker_task *task, const gchar *begin, struct spf_record *r return FALSE; } rec->dns_requests ++; - cb = memory_pool_alloc (task->task_pool, sizeof (struct spf_dns_cb)); + cb = rspamd_mempool_alloc (task->task_pool, sizeof (struct spf_dns_cb)); cb->rec = rec; cb->addr = addr; memset (&addr->data.normal, 0, sizeof (addr->data.normal)); @@ -733,14 +733,14 @@ parse_spf_include (struct worker_task *task, const gchar *begin, struct spf_reco begin ++; rec->dns_requests ++; - cb = memory_pool_alloc (task->task_pool, sizeof (struct spf_dns_cb)); + cb = rspamd_mempool_alloc (task->task_pool, sizeof (struct spf_dns_cb)); cb->rec = rec; cb->addr = addr; cb->cur_action = SPF_RESOLVE_INCLUDE; cb->in_include = rec->in_include; addr->is_list = TRUE; addr->data.list = NULL; - domain = memory_pool_strdup (task->task_pool, begin); + domain = rspamd_mempool_strdup (task->task_pool, begin); if (make_dns_request (task->resolver, task->s, task->task_pool, spf_record_dns_callback, (void *)cb, RDNS_REQUEST_TXT, domain)) { task->dns_requests ++; @@ -776,12 +776,12 @@ parse_spf_redirect (struct worker_task *task, const gchar *begin, struct spf_rec begin ++; rec->dns_requests ++; - cb = memory_pool_alloc (task->task_pool, sizeof (struct spf_dns_cb)); + cb = rspamd_mempool_alloc (task->task_pool, sizeof (struct spf_dns_cb)); cb->rec = rec; cb->addr = addr; cb->cur_action = SPF_RESOLVE_REDIRECT; cb->in_include = rec->in_include; - domain = memory_pool_strdup (task->task_pool, begin); + domain = rspamd_mempool_strdup (task->task_pool, begin); if (make_dns_request (task->resolver, task->s, task->task_pool, spf_record_dns_callback, (void *)cb, RDNS_REQUEST_TXT, domain)) { task->dns_requests ++; @@ -808,12 +808,12 @@ parse_spf_exists (struct worker_task *task, const gchar *begin, struct spf_recor rec->dns_requests ++; addr->data.normal.mask = 32; - cb = memory_pool_alloc (task->task_pool, sizeof (struct spf_dns_cb)); + cb = rspamd_mempool_alloc (task->task_pool, sizeof (struct spf_dns_cb)); cb->rec = rec; cb->addr = addr; cb->cur_action = SPF_RESOLVE_EXISTS; cb->in_include = rec->in_include; - host = memory_pool_strdup (task->task_pool, begin); + host = rspamd_mempool_strdup (task->task_pool, begin); if (make_dns_request (task->resolver, task->s, task->task_pool, spf_record_dns_callback, (void *)cb, RDNS_REQUEST_A, host)) { @@ -967,7 +967,7 @@ expand_spf_macro (struct worker_task *task, struct spf_record *rec, gchar *begin return begin; } - new = memory_pool_alloc (task->task_pool, len + 1); + new = rspamd_mempool_alloc (task->task_pool, len + 1); c = new; p = begin; @@ -1106,9 +1106,9 @@ expand_spf_macro (struct worker_task *task, struct spf_record *rec, gchar *begin } #define NEW_ADDR(x) do { \ - (x) = memory_pool_alloc (task->task_pool, sizeof (struct spf_addr)); \ + (x) = rspamd_mempool_alloc (task->task_pool, sizeof (struct spf_addr)); \ (x)->mech = check_spf_mech (rec->cur_elt, &need_shift); \ - (x)->spf_string = memory_pool_strdup (task->task_pool, begin); \ + (x)->spf_string = rspamd_mempool_strdup (task->task_pool, begin); \ memset (&(x)->data.normal, 0, sizeof ((x)->data.normal)); \ (x)->data.normal.mask = 32; \ (x)->is_list = FALSE; \ @@ -1300,7 +1300,7 @@ start_spf_parse (struct spf_record *rec, gchar *begin, guint ttl) rec->elts = g_strsplit_set (begin, " ", 0); rec->elt_num = 0; if (rec->elts) { - memory_pool_add_destructor (rec->task->task_pool, (pool_destruct_func)g_strfreev, rec->elts); + rspamd_mempool_add_destructor (rec->task->task_pool, (rspamd_mempool_destruct_t)g_strfreev, rec->elts); rec->cur_elt = rec->elts[0]; while (parse_spf_record (rec->task, rec)); if (ttl != 0) { @@ -1326,7 +1326,7 @@ start_spf_parse (struct spf_record *rec, gchar *begin, guint ttl) rec->elts = g_strsplit_set (begin, " ", 0); rec->elt_num = 0; if (rec->elts) { - memory_pool_add_destructor (rec->task->task_pool, (pool_destruct_func)g_strfreev, rec->elts); + rspamd_mempool_add_destructor (rec->task->task_pool, (rspamd_mempool_destruct_t)g_strfreev, rec->elts); rec->cur_elt = rec->elts[0]; while (parse_spf_record (rec->task, rec)); if (ttl != 0) { @@ -1365,7 +1365,7 @@ get_spf_domain (struct worker_task *task) GList *domains; if (task->from && (domain = strchr (task->from, '@')) != NULL && *domain == '@') { - res = memory_pool_strdup (task->task_pool, domain + 1); + res = rspamd_mempool_strdup (task->task_pool, domain + 1); if ((domain = strchr (res, '>')) != NULL) { *domain = '\0'; } @@ -1375,13 +1375,13 @@ get_spf_domain (struct worker_task *task) domains = message_get_header (task->task_pool, task->message, "From", FALSE); if (domains != NULL) { - res = memory_pool_strdup (task->task_pool, domains->data); + res = rspamd_mempool_strdup (task->task_pool, domains->data); if ((domain = strrchr (res, '@')) == NULL) { g_list_free (domains); return NULL; } - res = memory_pool_strdup (task->task_pool, domain + 1); + res = rspamd_mempool_strdup (task->task_pool, domain + 1); g_list_free (domains); if ((domain = strchr (res, '>')) != NULL) { @@ -1400,22 +1400,22 @@ resolve_spf (struct worker_task *task, spf_cb_t callback) gchar *domain; GList *domains; - rec = memory_pool_alloc0 (task->task_pool, sizeof (struct spf_record)); + rec = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct spf_record)); rec->task = task; rec->callback = callback; /* Add destructor */ - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)spf_record_destructor, rec); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)spf_record_destructor, rec); /* Extract from data */ if (task->from && (domain = strchr (task->from, '@')) != NULL && *domain == '@') { rec->sender = task->from; - rec->local_part = memory_pool_strdup (task->task_pool, task->from); + rec->local_part = rspamd_mempool_strdup (task->task_pool, task->from); *(rec->local_part + (domain - task->from)) = '\0'; if (*rec->local_part == '<') { memmove (rec->local_part, rec->local_part + 1, strlen (rec->local_part)); } - rec->cur_domain = memory_pool_strdup (task->task_pool, domain + 1); + rec->cur_domain = rspamd_mempool_strdup (task->task_pool, domain + 1); if ((domain = strchr (rec->cur_domain, '>')) != NULL) { *domain = '\0'; } @@ -1433,13 +1433,13 @@ resolve_spf (struct worker_task *task, spf_cb_t callback) domains = message_get_header (task->task_pool, task->message, "From", FALSE); if (domains != NULL) { - rec->cur_domain = memory_pool_strdup (task->task_pool, domains->data); + rec->cur_domain = rspamd_mempool_strdup (task->task_pool, domains->data); g_list_free (domains); if ((domain = strrchr (rec->cur_domain, '@')) == NULL) { return FALSE; } - rec->sender = memory_pool_strdup (task->task_pool, rec->cur_domain); + rec->sender = rspamd_mempool_strdup (task->task_pool, rec->cur_domain); rec->local_part = rec->cur_domain; *domain = '\0'; rec->cur_domain = domain + 1; diff --git a/src/statfile.c b/src/statfile.c index 9df60fd56..4c1cc13fb 100644 --- a/src/statfile.c +++ b/src/statfile.c @@ -168,14 +168,14 @@ statfile_pool_check (stat_file_t * file) statfile_pool_t * -statfile_pool_new (memory_pool_t *pool, gboolean use_mlock) +statfile_pool_new (rspamd_mempool_t *pool, gboolean use_mlock) { statfile_pool_t *new; - new = memory_pool_alloc0 (pool, sizeof (statfile_pool_t)); - new->pool = memory_pool_new (memory_pool_get_size ()); - new->files = memory_pool_alloc0 (new->pool, STATFILES_MAX * sizeof (stat_file_t)); - new->lock = memory_pool_get_mutex (new->pool); + new = rspamd_mempool_alloc0 (pool, sizeof (statfile_pool_t)); + new->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); + new->files = rspamd_mempool_alloc0 (new->pool, STATFILES_MAX * sizeof (stat_file_t)); + new->lock = rspamd_mempool_get_mutex (new->pool); new->mlock_ok = use_mlock; return new; @@ -198,17 +198,17 @@ statfile_pool_reindex (statfile_pool_t * pool, gchar *filename, size_t old_size, } /* First of all rename old file */ - memory_pool_lock_mutex (pool->lock); + rspamd_mempool_lock_mutex (pool->lock); backup = g_strconcat (filename, ".old", NULL); if (rename (filename, backup) == -1) { msg_err ("cannot rename %s to %s: %s", filename, backup, strerror (errno)); g_free (backup); - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); return NULL; } - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); /* Now create new file with required size */ if (statfile_pool_create (pool, filename, size) != 0) { @@ -306,10 +306,10 @@ statfile_pool_open (statfile_pool_t * pool, gchar *filename, size_t size, gboole return NULL; } - memory_pool_lock_mutex (pool->lock); + rspamd_mempool_lock_mutex (pool->lock); if (!forced && labs (size - st.st_size) > (long)sizeof (struct stat_file) * 2 && size > sizeof (struct stat_file)) { - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); msg_warn ("need to reindex statfile old size: %Hz, new size: %Hz", (size_t)st.st_size, size); return statfile_pool_reindex (pool, filename, st.st_size, size); } @@ -321,14 +321,14 @@ statfile_pool_open (statfile_pool_t * pool, gchar *filename, size_t size, gboole bzero (new_file, sizeof (stat_file_t)); if ((new_file->fd = open (filename, O_RDWR)) == -1) { msg_info ("cannot open file %s, error %d, %s", filename, errno, strerror (errno)); - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); pool->opened--; return NULL; } if ((new_file->map = mmap (NULL, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, new_file->fd, 0)) == MAP_FAILED) { close (new_file->fd); - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); msg_info ("cannot mmap file %s, error %d, %s", filename, errno, strerror (errno)); pool->opened--; return NULL; @@ -348,7 +348,7 @@ statfile_pool_open (statfile_pool_t * pool, gchar *filename, size_t size, gboole lock_file (new_file->fd, FALSE); if (statfile_pool_check (new_file) == -1) { pool->opened--; - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); unlock_file (new_file->fd, FALSE); munmap (new_file->map, st.st_size); return NULL; @@ -357,11 +357,11 @@ statfile_pool_open (statfile_pool_t * pool, gchar *filename, size_t size, gboole new_file->open_time = time (NULL); new_file->access_time = new_file->open_time; - new_file->lock = memory_pool_get_mutex (pool->pool); + new_file->lock = rspamd_mempool_get_mutex (pool->pool); statfile_preload (new_file); - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); return statfile_pool_is_open (pool, filename); } @@ -376,7 +376,7 @@ statfile_pool_close (statfile_pool_t * pool, stat_file_t * file, gboolean keep_s return -1; } - memory_pool_lock_mutex (pool->lock); + rspamd_mempool_lock_mutex (pool->lock); if (file->map) { msg_info ("syncing statfile %s", file->filename); @@ -390,7 +390,7 @@ statfile_pool_close (statfile_pool_t * pool, stat_file_t * file, gboolean keep_s memmove (pos, ((guint8 *)pos) + sizeof (stat_file_t), (--pool->opened - (pos - pool->files)) * sizeof (stat_file_t)); - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); return 0; } @@ -425,13 +425,13 @@ statfile_pool_create (statfile_pool_t * pool, gchar *filename, size_t size) return -1; } - memory_pool_lock_mutex (pool->lock); + rspamd_mempool_lock_mutex (pool->lock); nblocks = (size - sizeof (struct stat_file_header) - sizeof (struct stat_file_section)) / sizeof (struct stat_file_block); header.total_blocks = nblocks; if ((fd = open (filename, O_RDWR | O_TRUNC | O_CREAT, S_IWUSR | S_IRUSR)) == -1) { msg_info ("cannot create file %s, error %d, %s", filename, errno, strerror (errno)); - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); return -1; } @@ -441,7 +441,7 @@ statfile_pool_create (statfile_pool_t * pool, gchar *filename, size_t size) if (write (fd, &header, sizeof (header)) == -1) { msg_info ("cannot write header to file %s, error %d, %s", filename, errno, strerror (errno)); close (fd); - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); return -1; } @@ -449,7 +449,7 @@ statfile_pool_create (statfile_pool_t * pool, gchar *filename, size_t size) if (write (fd, §ion, sizeof (section)) == -1) { msg_info ("cannot write section header to file %s, error %d, %s", filename, errno, strerror (errno)); close (fd); - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); return -1; } @@ -465,7 +465,7 @@ statfile_pool_create (statfile_pool_t * pool, gchar *filename, size_t size) if (write (fd, buf, buflen) == -1) { msg_info ("cannot write blocks buffer to file %s, error %d, %s", filename, errno, strerror (errno)); close (fd); - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); g_free (buf); return -1; } @@ -478,7 +478,7 @@ statfile_pool_create (statfile_pool_t * pool, gchar *filename, size_t size) if (buf) { g_free (buf); } - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); return -1; } nblocks --; @@ -486,7 +486,7 @@ statfile_pool_create (statfile_pool_t * pool, gchar *filename, size_t size) } close (fd); - memory_pool_unlock_mutex (pool->lock); + rspamd_mempool_unlock_mutex (pool->lock); if (buf) { g_free (buf); @@ -503,21 +503,21 @@ statfile_pool_delete (statfile_pool_t * pool) for (i = 0; i < pool->opened; i++) { statfile_pool_close (pool, &pool->files[i], FALSE); } - memory_pool_delete (pool->pool); + rspamd_mempool_delete (pool->pool); } void statfile_pool_lock_file (statfile_pool_t * pool, stat_file_t * file) { - memory_pool_lock_mutex (file->lock); + rspamd_mempool_lock_mutex (file->lock); } void statfile_pool_unlock_file (statfile_pool_t * pool, stat_file_t * file) { - memory_pool_unlock_mutex (file->lock); + rspamd_mempool_unlock_mutex (file->lock); } double @@ -851,7 +851,7 @@ statfile_pool_plan_invalidate (statfile_pool_t *pool, time_t seconds, time_t jit } } else { - pool->invalidate_event = memory_pool_alloc (pool->pool, sizeof (struct event)); + pool->invalidate_event = rspamd_mempool_alloc (pool->pool, sizeof (struct event)); pool->invalidate_tv.tv_sec = seconds + g_random_int_range (0, jitter); pool->invalidate_tv.tv_usec = 0; evtimer_set (pool->invalidate_event, statfile_pool_invalidate_callback, pool); diff --git a/src/statfile.h b/src/statfile.h index ced4f2207..5786c4927 100644 --- a/src/statfile.h +++ b/src/statfile.h @@ -78,7 +78,7 @@ typedef struct stat_file_s { time_t open_time; /**< time when file was opened */ time_t access_time; /**< last access time */ size_t len; /**< length of file(in bytes) */ - memory_pool_mutex_t *lock; /**< mutex */ + rspamd_mempool_mutex_t *lock; /**< mutex */ } stat_file_t; /** @@ -88,8 +88,8 @@ typedef struct statfile_pool_s { stat_file_t *files; /**< hash table of opened files indexed by name */ void **maps; /**< shared hash table of mmaped areas indexed by name */ gint opened; /**< number of opened files */ - memory_pool_t *pool; /**< memory pool object */ - memory_pool_mutex_t *lock; /**< mutex */ + rspamd_mempool_t *pool; /**< memory pool object */ + rspamd_mempool_mutex_t *lock; /**< mutex */ struct event *invalidate_event; /**< event for pool invalidation */ struct timeval invalidate_tv; gboolean mlock_ok; /**< whether it is possible to use mlock (2) to avoid statfiles unloading */ @@ -104,7 +104,7 @@ struct statfile; * @param max_size maximum size * @return statfile pool object */ -statfile_pool_t* statfile_pool_new (memory_pool_t *pool, gboolean use_mlock); +statfile_pool_t* statfile_pool_new (rspamd_mempool_t *pool, gboolean use_mlock); /** * Open statfile and attach it to pool diff --git a/src/statfile_sync.c b/src/statfile_sync.c index 7e3c3be3c..6b545af17 100644 --- a/src/statfile_sync.c +++ b/src/statfile_sync.c @@ -286,7 +286,7 @@ add_statfile_watch (statfile_pool_t *pool, struct statfile *st, struct config_fi guint32 jittered_interval; if (st->binlog->master_addr != NULL) { - ctx = memory_pool_alloc (pool->pool, sizeof (struct rspamd_sync_ctx)); + ctx = rspamd_mempool_alloc (pool->pool, sizeof (struct rspamd_sync_ctx)); ctx->st = st; ctx->timeout = cfg->statfile_sync_timeout; ctx->sync_interval = cfg->statfile_sync_interval; diff --git a/src/symbols_cache.c b/src/symbols_cache.c index d6c17390d..ae9fd605a 100644 --- a/src/symbols_cache.c +++ b/src/symbols_cache.c @@ -155,7 +155,7 @@ unmap_cache_file (gpointer arg) } static gboolean -mmap_cache_file (struct symbols_cache *cache, gint fd, memory_pool_t *pool) +mmap_cache_file (struct symbols_cache *cache, gint fd, rspamd_mempool_t *pool) { guint8 *map; gint i; @@ -197,7 +197,7 @@ mmap_cache_file (struct symbols_cache *cache, gint fd, memory_pool_t *pool) /* Fd must be opened for writing, after creating file is mmapped */ static gboolean -create_cache_file (struct symbols_cache *cache, const gchar *filename, gint fd, memory_pool_t *pool) +create_cache_file (struct symbols_cache *cache, const gchar *filename, gint fd, rspamd_mempool_t *pool) { GChecksum *cksum; u_char *digest; @@ -281,12 +281,12 @@ register_symbol_common (struct symbols_cache **cache, const gchar *name, double if (*cache == NULL) { pcache = g_new0 (struct symbols_cache, 1); *cache = pcache; - pcache->static_pool = memory_pool_new (memory_pool_get_size ()); + pcache->static_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); pcache->items_by_symbol = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); } - item = memory_pool_alloc0 (pcache->static_pool, sizeof (struct cache_item)); - item->s = memory_pool_alloc0 (pcache->static_pool, sizeof (struct saved_cache_item)); + item = rspamd_mempool_alloc0 (pcache->static_pool, sizeof (struct cache_item)); + item->s = rspamd_mempool_alloc0 (pcache->static_pool, sizeof (struct saved_cache_item)); rspamd_strlcpy (item->s->symbol, name, sizeof (item->s->symbol)); item->func = func; item->user_data = user_data; @@ -366,7 +366,7 @@ register_callback_symbol_priority (struct symbols_cache **cache, const gchar *na } void -register_dynamic_symbol (memory_pool_t *dynamic_pool, struct symbols_cache **cache, +register_dynamic_symbol (rspamd_mempool_t *dynamic_pool, struct symbols_cache **cache, const gchar *name, double weight, symbol_func_t func, gpointer user_data, GList *networks) { @@ -382,11 +382,11 @@ register_dynamic_symbol (memory_pool_t *dynamic_pool, struct symbols_cache **cac if (*cache == NULL) { pcache = g_new0 (struct symbols_cache, 1); *cache = pcache; - pcache->static_pool = memory_pool_new (memory_pool_get_size ()); + pcache->static_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); } - item = memory_pool_alloc0 (dynamic_pool, sizeof (struct cache_item)); - item->s = memory_pool_alloc (dynamic_pool, sizeof (struct saved_cache_item)); + item = rspamd_mempool_alloc0 (dynamic_pool, sizeof (struct cache_item)); + item->s = rspamd_mempool_alloc (dynamic_pool, sizeof (struct saved_cache_item)); rspamd_strlcpy (item->s->symbol, name, sizeof (item->s->symbol)); item->func = func; item->user_data = user_data; @@ -425,7 +425,7 @@ register_dynamic_symbol (memory_pool_t *dynamic_pool, struct symbols_cache **cac t = (GList *)((gpointer)r); t = g_list_prepend (t, item); /* Replace pointers in radix tree and in destructor function */ - memory_pool_replace_destructor (dynamic_pool, (pool_destruct_func)g_list_free, (gpointer)r, t); + rspamd_mempool_replace_destructor (dynamic_pool, (rspamd_mempool_destruct_t)g_list_free, (gpointer)r, t); rr = radix32tree_replace (pcache->negative_dynamic_map, ntohl (it->addr.s_addr), mask, (uintptr_t)t); if (rr == -1) { msg_warn ("cannot replace ip to tree: %s, mask %X", inet_ntoa (it->addr), mask); @@ -433,7 +433,7 @@ register_dynamic_symbol (memory_pool_t *dynamic_pool, struct symbols_cache **cac } else { t = g_list_prepend (NULL, item); - memory_pool_add_destructor (dynamic_pool, (pool_destruct_func)g_list_free, t); + rspamd_mempool_add_destructor (dynamic_pool, (rspamd_mempool_destruct_t)g_list_free, t); rr = radix32tree_insert (pcache->negative_dynamic_map, ntohl (it->addr.s_addr), mask, (uintptr_t)t); if (rr == -1) { msg_warn ("cannot insert ip to tree: %s, mask %X", inet_ntoa (it->addr), mask); @@ -450,7 +450,7 @@ register_dynamic_symbol (memory_pool_t *dynamic_pool, struct symbols_cache **cac t = (GList *)((gpointer)r); t = g_list_prepend (t, item); /* Replace pointers in radix tree and in destructor function */ - memory_pool_replace_destructor (dynamic_pool, (pool_destruct_func)g_list_free, (gpointer)r, t); + rspamd_mempool_replace_destructor (dynamic_pool, (rspamd_mempool_destruct_t)g_list_free, (gpointer)r, t); rr = radix32tree_replace (pcache->dynamic_map, ntohl (it->addr.s_addr), mask, (uintptr_t)t); if (rr == -1) { msg_warn ("cannot replace ip to tree: %s, mask %X", inet_ntoa (it->addr), mask); @@ -458,7 +458,7 @@ register_dynamic_symbol (memory_pool_t *dynamic_pool, struct symbols_cache **cac } else { t = g_list_prepend (NULL, item); - memory_pool_add_destructor (dynamic_pool, (pool_destruct_func)g_list_free, t); + rspamd_mempool_add_destructor (dynamic_pool, (rspamd_mempool_destruct_t)g_list_free, t); rr = radix32tree_insert (pcache->dynamic_map, ntohl (it->addr.s_addr), mask, (uintptr_t)t); if (rr == -1) { msg_warn ("cannot insert ip to tree: %s, mask %X", inet_ntoa (it->addr), mask); @@ -516,13 +516,13 @@ free_cache (gpointer arg) radix_tree_free (cache->negative_dynamic_map); } g_hash_table_destroy (cache->items_by_symbol); - memory_pool_delete (cache->static_pool); + rspamd_mempool_delete (cache->static_pool); g_free (cache); } gboolean -init_symbols_cache (memory_pool_t * pool, struct symbols_cache *cache, struct config_file *cfg, +init_symbols_cache (rspamd_mempool_t * pool, struct symbols_cache *cache, struct config_file *cfg, const gchar *filename, gboolean ignore_checksum) { struct stat st; @@ -537,7 +537,7 @@ init_symbols_cache (memory_pool_t * pool, struct symbols_cache *cache, struct co } /* Init locking */ - cache->lock = memory_pool_get_rwlock (pool); + cache->lock = rspamd_mempool_get_rwlock (pool); cache->cfg = cfg; @@ -637,7 +637,7 @@ init_symbols_cache (memory_pool_t * pool, struct symbols_cache *cache, struct co /* MMap cache file and copy saved_cache structures */ res = mmap_cache_file (cache, fd, pool); - memory_pool_add_destructor (pool, (pool_destruct_func)free_cache, cache); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t)free_cache, cache); return res; } @@ -858,13 +858,13 @@ call_symbol_callback (struct worker_task * task, struct symbols_cache * cache, g } if (cache->uses++ >= MAX_USES) { msg_info ("resort symbols cache"); - memory_pool_wlock_rwlock (cache->lock); + rspamd_mempool_wlock_rwlock (cache->lock); cache->uses = 0; /* Resort while having write lock */ post_cache_init (cache); - memory_pool_wunlock_rwlock (cache->lock); + rspamd_mempool_wunlock_rwlock (cache->lock); } - s = memory_pool_alloc0 (task->task_pool, sizeof (struct symbol_callback_data)); + s = rspamd_mempool_alloc0 (task->task_pool, sizeof (struct symbol_callback_data)); *save = s; if (cache->negative_items != NULL) { s->list_pointer = g_list_first (cache->negative_items); diff --git a/src/symbols_cache.h b/src/symbols_cache.h index 658852a32..cbbc9e8ff 100644 --- a/src/symbols_cache.h +++ b/src/symbols_cache.h @@ -64,20 +64,20 @@ struct symbols_cache { /* Hash table for fast access */ GHashTable *items_by_symbol; - memory_pool_t *static_pool; + rspamd_mempool_t *static_pool; guint cur_items; guint used_items; guint uses; gpointer map; - memory_pool_rwlock_t *lock; + rspamd_mempool_rwlock_t *lock; struct config_file *cfg; }; /** * Load symbols cache from file, must be called _after_ init_symbols_cache */ -gboolean init_symbols_cache (memory_pool_t *pool, struct symbols_cache *cache, struct config_file *cfg, +gboolean init_symbols_cache (rspamd_mempool_t *pool, struct symbols_cache *cache, struct config_file *cfg, const gchar *filename, gboolean ignore_checksum); /** @@ -120,7 +120,7 @@ void register_callback_symbol_priority (struct symbols_cache **cache, const gcha * @param func pointer to handler * @param user_data pointer to user_data */ -void register_dynamic_symbol (memory_pool_t *pool, struct symbols_cache **cache, const gchar *name, +void register_dynamic_symbol (rspamd_mempool_t *pool, struct symbols_cache **cache, const gchar *name, double weight, symbol_func_t func, gpointer user_data, GList *networks); diff --git a/src/tokenizers/osb.c b/src/tokenizers/osb.c index c59536b31..823e1e5b5 100644 --- a/src/tokenizers/osb.c +++ b/src/tokenizers/osb.c @@ -35,7 +35,7 @@ extern const int primes[]; int -osb_tokenize_text (struct tokenizer *tokenizer, memory_pool_t * pool, f_str_t * input, GTree ** tree, +osb_tokenize_text (struct tokenizer *tokenizer, rspamd_mempool_t * pool, f_str_t * input, GTree ** tree, gboolean save_token, gboolean is_utf, GList *exceptions) { token_node_t *new = NULL; @@ -46,7 +46,7 @@ osb_tokenize_text (struct tokenizer *tokenizer, memory_pool_t * pool, f_str_t * if (*tree == NULL) { *tree = g_tree_new (token_node_compare_func); - memory_pool_add_destructor (pool, (pool_destruct_func) g_tree_destroy, *tree); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) g_tree_destroy, *tree); } memset (hashpipe, 0xfe, FEATURE_WINDOW_SIZE * sizeof (hashpipe[0])); @@ -80,11 +80,11 @@ osb_tokenize_text (struct tokenizer *tokenizer, memory_pool_t * pool, f_str_t * for (i = 1; i < FEATURE_WINDOW_SIZE; i++) { h1 = hashpipe[0] * primes[0] + hashpipe[i] * primes[i << 1]; h2 = hashpipe[0] * primes[1] + hashpipe[i] * primes[(i << 1) - 1]; - new = memory_pool_alloc0 (pool, sizeof (token_node_t)); + new = rspamd_mempool_alloc0 (pool, sizeof (token_node_t)); new->h1 = h1; new->h2 = h2; if (save_token) { - new->extra = (uintptr_t)memory_pool_fstrdup (pool, &token); + new->extra = (uintptr_t)rspamd_mempool_fstrdup (pool, &token); } if (g_tree_lookup (*tree, new) == NULL) { @@ -99,11 +99,11 @@ osb_tokenize_text (struct tokenizer *tokenizer, memory_pool_t * pool, f_str_t * for (i = 1; i < processed; i++) { h1 = hashpipe[0] * primes[0] + hashpipe[i] * primes[i << 1]; h2 = hashpipe[0] * primes[1] + hashpipe[i] * primes[(i << 1) - 1]; - new = memory_pool_alloc0 (pool, sizeof (token_node_t)); + new = rspamd_mempool_alloc0 (pool, sizeof (token_node_t)); new->h1 = h1; new->h2 = h2; if (save_token) { - new->extra = (uintptr_t)memory_pool_fstrdup (pool, &token); + new->extra = (uintptr_t)rspamd_mempool_fstrdup (pool, &token); } if (g_tree_lookup (*tree, new) == NULL) { diff --git a/src/tokenizers/tokenizers.c b/src/tokenizers/tokenizers.c index 43dcfac82..0cdd0aaf4 100644 --- a/src/tokenizers/tokenizers.c +++ b/src/tokenizers/tokenizers.c @@ -189,7 +189,7 @@ typedef struct _GMimeHeader { } local_GMimeHeader; int -tokenize_headers (memory_pool_t * pool, struct worker_task *task, GTree ** tree) +tokenize_headers (rspamd_mempool_t * pool, struct worker_task *task, GTree ** tree) { token_node_t *new = NULL; f_str_t headername; @@ -197,7 +197,7 @@ tokenize_headers (memory_pool_t * pool, struct worker_task *task, GTree ** tree) if (*tree == NULL) { *tree = g_tree_new (token_node_compare_func); - memory_pool_add_destructor (pool, (pool_destruct_func) g_tree_destroy, *tree); + rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t) g_tree_destroy, *tree); } #ifndef GMIME24 struct raw_header *h; @@ -205,7 +205,7 @@ tokenize_headers (memory_pool_t * pool, struct worker_task *task, GTree ** tree) h = GMIME_OBJECT (task->message)->headers->headers; while (h) { if (h->name && h->value) { - new = memory_pool_alloc (pool, sizeof (token_node_t)); + new = rspamd_mempool_alloc (pool, sizeof (token_node_t)); headername.begin = h->name; headername.len = strlen (h->name); headervalue.begin = h->value; @@ -229,7 +229,7 @@ tokenize_headers (memory_pool_t * pool, struct worker_task *task, GTree ** tree) if (g_mime_header_list_get_iter (ls, iter)) { while (g_mime_header_iter_is_valid (iter)) { - new = memory_pool_alloc (pool, sizeof (token_node_t)); + new = rspamd_mempool_alloc (pool, sizeof (token_node_t)); name = g_mime_header_iter_get_name (iter); value = g_mime_header_iter_get_value (iter); headername.begin = (u_char *)name; @@ -260,7 +260,7 @@ tokenize_subject (struct worker_task *task, GTree ** tree) if (*tree == NULL) { *tree = g_tree_new (token_node_compare_func); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func) g_tree_destroy, *tree); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_tree_destroy, *tree); } osb_tokenizer = get_tokenizer ("osb-text"); diff --git a/src/tokenizers/tokenizers.h b/src/tokenizers/tokenizers.h index f2e8c9a4f..0a8d27d57 100644 --- a/src/tokenizers/tokenizers.h +++ b/src/tokenizers/tokenizers.h @@ -19,7 +19,7 @@ typedef struct token_node_s { /* Common tokenizer structure */ struct tokenizer { gchar *name; - gint (*tokenize_func)(struct tokenizer *tokenizer, memory_pool_t *pool, f_str_t *input, + gint (*tokenize_func)(struct tokenizer *tokenizer, rspamd_mempool_t *pool, f_str_t *input, GTree **cur, gboolean save_token, gboolean is_utf, GList *exceptions); gchar* (*get_next_word)(f_str_t *buf, f_str_t *token, GList **exceptions); }; @@ -31,10 +31,10 @@ struct tokenizer* get_tokenizer (const char *name); /* Get next word from specified f_str_t buf */ gchar* get_next_word (f_str_t *buf, f_str_t *token, GList **exceptions); /* OSB tokenize function */ -int osb_tokenize_text (struct tokenizer *tokenizer, memory_pool_t *pool, f_str_t *input, +int osb_tokenize_text (struct tokenizer *tokenizer, rspamd_mempool_t *pool, f_str_t *input, GTree **cur, gboolean save_token, gboolean is_utf, GList *exceptions); /* Common tokenizer for headers */ -int tokenize_headers (memory_pool_t *pool, struct worker_task *task, GTree **cur); +int tokenize_headers (rspamd_mempool_t *pool, struct worker_task *task, GTree **cur); /* Make tokens for a subject */ void tokenize_subject (struct worker_task *task, GTree ** tree); diff --git a/src/trie.c b/src/trie.c index 9068abe08..394c4e939 100644 --- a/src/trie.c +++ b/src/trie.c @@ -33,7 +33,7 @@ rspamd_trie_create (gboolean icase) new = g_malloc (sizeof (rspamd_trie_t)); new->icase = icase; - new->pool = memory_pool_new (memory_pool_get_size ()); + new->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); new->root.fail = NULL; new->root.final = 0; new->root.id = 0; @@ -54,14 +54,14 @@ rspamd_trie_insert_char (rspamd_trie_t *trie, guint depth, struct rspamd_trie_st struct rspamd_trie_state *new_pos; /* New match is inserted before pos */ - new_match = memory_pool_alloc (trie->pool, sizeof (struct rspamd_trie_match)); + new_match = rspamd_mempool_alloc (trie->pool, sizeof (struct rspamd_trie_match)); new_match->next = pos->match; new_match->c = c; /* Now set match link */ pos->match = new_match; - new_match->state = memory_pool_alloc (trie->pool, sizeof (struct rspamd_trie_state)); + new_match->state = rspamd_mempool_alloc (trie->pool, sizeof (struct rspamd_trie_state)); new_pos = new_match->state; new_pos->match = NULL; new_pos->fail = &trie->root; @@ -225,6 +225,6 @@ void rspamd_trie_free (rspamd_trie_t *trie) { g_ptr_array_free (trie->fail_states, TRUE); - memory_pool_delete (trie->pool); + rspamd_mempool_delete (trie->pool); g_free (trie); } diff --git a/src/trie.h b/src/trie.h index ef01c3e4e..2792ee4a5 100644 --- a/src/trie.h +++ b/src/trie.h @@ -52,7 +52,7 @@ typedef struct rspamd_trie_s { struct rspamd_trie_state root; GPtrArray *fail_states; gboolean icase; - memory_pool_t *pool; + rspamd_mempool_t *pool; } rspamd_trie_t; /* @@ -679,7 +679,7 @@ url_strip (gchar *s) } static gchar * -url_escape_1 (const gchar *s, gint allow_passthrough, memory_pool_t * pool) +url_escape_1 (const gchar *s, gint allow_passthrough, rspamd_mempool_t * pool) { const gchar *p1; gchar *p2, *newstr; @@ -696,12 +696,12 @@ url_escape_1 (const gchar *s, gint allow_passthrough, memory_pool_t * pool) return (gchar *)s; } else { - return memory_pool_strdup (pool, s); + return rspamd_mempool_strdup (pool, s); } } newlen = (p1 - s) + addition; - newstr = (gchar *)memory_pool_alloc (pool, newlen + 1); + newstr = (gchar *)rspamd_mempool_alloc (pool, newlen + 1); p1 = s; p2 = newstr; @@ -725,7 +725,7 @@ url_escape_1 (const gchar *s, gint allow_passthrough, memory_pool_t * pool) string, returning a freshly allocated string. */ gchar * -url_escape (const gchar *s, memory_pool_t * pool) +url_escape (const gchar *s, rspamd_mempool_t * pool) { return url_escape_1 (s, 0, pool); } @@ -758,7 +758,7 @@ char_needs_escaping (const gchar *p) */ static gchar * -reencode_escapes (gchar *s, memory_pool_t * pool) +reencode_escapes (gchar *s, rspamd_mempool_t * pool) { const gchar *p1; gchar *newstr, *p2; @@ -780,7 +780,7 @@ reencode_escapes (gchar *s, memory_pool_t * pool) oldlen = p1 - s; /* Each encoding adds two characters (hex digits). */ newlen = oldlen + 2 * encode_count; - newstr = memory_pool_alloc (pool, newlen + 1); + newstr = rspamd_mempool_alloc (pool, newlen + 1); /* Second pass: copy the string to the destination address, encoding chars when needed. */ @@ -892,7 +892,7 @@ path_simplify (gchar *path) } enum uri_errno -parse_uri (struct uri *uri, gchar *uristring, memory_pool_t * pool) +parse_uri (struct uri *uri, gchar *uristring, rspamd_mempool_t * pool) { guchar *prefix_end, *host_end, *p; guchar *lbracket, *rbracket; @@ -920,7 +920,7 @@ parse_uri (struct uri *uri, gchar *uristring, memory_pool_t * pool) return URI_ERRNO_INVALID_PROTOCOL; } p = g_strconcat ("http://", uri->string, NULL); - uri->string = memory_pool_strdup (pool, p); + uri->string = rspamd_mempool_strdup (pool, p); g_free (p); uri->protocol = PROTOCOL_HTTP; prefix_end = struri (uri) + 7; @@ -1488,7 +1488,7 @@ url_email_end (const gchar *begin, const gchar *end, const gchar *pos, url_match } void -url_parse_text (memory_pool_t * pool, struct worker_task *task, struct mime_text_part *part, gboolean is_html) +url_parse_text (rspamd_mempool_t * pool, struct worker_task *task, struct mime_text_part *part, gboolean is_html) { gint rc; gchar *url_str = NULL, *url_start, *url_end; @@ -1516,8 +1516,8 @@ url_parse_text (memory_pool_t * pool, struct worker_task *task, struct mime_text while (p < end) { if (url_try_text (pool, p, end - p, &url_start, &url_end, &url_str, is_html)) { if (url_str != NULL) { - new = memory_pool_alloc0 (pool, sizeof (struct uri)); - ex = memory_pool_alloc0 (pool, sizeof (struct process_exception)); + new = rspamd_mempool_alloc0 (pool, sizeof (struct uri)); + ex = rspamd_mempool_alloc0 (pool, sizeof (struct process_exception)); if (new != NULL) { g_strstrip (url_str); rc = parse_uri (new, url_str, pool); @@ -1554,12 +1554,12 @@ url_parse_text (memory_pool_t * pool, struct worker_task *task, struct mime_text /* Handle offsets of this part */ if (part->urls_offset != NULL) { part->urls_offset = g_list_reverse (part->urls_offset); - memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_list_free, part->urls_offset); + rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_list_free, part->urls_offset); } } gboolean -url_try_text (memory_pool_t *pool, const gchar *begin, gsize len, gchar **start, gchar **fin, gchar **url_str, gboolean is_html) +url_try_text (rspamd_mempool_t *pool, const gchar *begin, gsize len, gchar **start, gchar **fin, gchar **url_str, gboolean is_html) { const gchar *end, *pos; gint idx, l; @@ -1583,11 +1583,11 @@ url_try_text (memory_pool_t *pool, const gchar *begin, gsize len, gchar **start, if (matcher->start (begin, end, pos, &m) && matcher->end (begin, end, pos, &m)) { if (m.add_prefix) { l = m.m_len + 1 + strlen (m.prefix); - *url_str = memory_pool_alloc (pool, l); + *url_str = rspamd_mempool_alloc (pool, l); rspamd_snprintf (*url_str, l, "%s%*s", m.prefix, m.m_len, m.m_begin); } else { - *url_str = memory_pool_alloc (pool, m.m_len + 1); + *url_str = rspamd_mempool_alloc (pool, m.m_len + 1); memcpy (*url_str, m.m_begin, m.m_len); (*url_str)[m.m_len] = '\0'; } @@ -81,7 +81,7 @@ enum protocol { * @param part current text part * @param is_html turn on html euristic */ -void url_parse_text (memory_pool_t *pool, struct worker_task *task, struct mime_text_part *part, gboolean is_html); +void url_parse_text (rspamd_mempool_t *pool, struct worker_task *task, struct mime_text_part *part, gboolean is_html); /* * Parse a single url into an uri structure @@ -89,7 +89,7 @@ void url_parse_text (memory_pool_t *pool, struct worker_task *task, struct mime_ * @param uristring text form of url * @param uri url object, must be pre allocated */ -enum uri_errno parse_uri(struct uri *uri, gchar *uristring, memory_pool_t *pool); +enum uri_errno parse_uri(struct uri *uri, gchar *uristring, rspamd_mempool_t *pool); /* * Try to extract url from a text @@ -101,7 +101,7 @@ enum uri_errno parse_uri(struct uri *uri, gchar *uristring, memory_pool_t *pool) * @param url_str storage for url string(or NULL) * @return TRUE if url is found in specified text */ -gboolean url_try_text (memory_pool_t *pool, const gchar *begin, gsize len, gchar **start, gchar **end, gchar **url_str, gboolean is_html); +gboolean url_try_text (rspamd_mempool_t *pool, const gchar *begin, gsize len, gchar **start, gchar **end, gchar **url_str, gboolean is_html); /* * Return text representation of url parsing error diff --git a/src/util.c b/src/util.c index 3db6a3fe1..d5a4a19df 100644 --- a/src/util.c +++ b/src/util.c @@ -971,7 +971,7 @@ rspamd_pidfile_remove (rspamd_pidfh_t *pfh) /* Replace %r with rcpt value and %f with from value, new string is allocated in pool */ gchar * -resolve_stat_filename (memory_pool_t * pool, gchar *pattern, gchar *rcpt, gchar *from) +resolve_stat_filename (rspamd_mempool_t * pool, gchar *pattern, gchar *rcpt, gchar *from) { gint need_to_format = 0, len = 0; gint rcptlen, fromlen; @@ -1014,7 +1014,7 @@ resolve_stat_filename (memory_pool_t * pool, gchar *pattern, gchar *rcpt, gchar } /* Allocate new string */ - new = memory_pool_alloc (pool, len); + new = rspamd_mempool_alloc (pool, len); c = pattern; s = new; @@ -1961,9 +1961,9 @@ void rspamd_hash_table_copy (GHashTable *src, GHashTable *dst, gpointer rspamd_str_pool_copy (gconstpointer data, gpointer ud) { - memory_pool_t *pool = ud; + rspamd_mempool_t *pool = ud; - return data ? memory_pool_strdup (pool, data) : NULL; + return data ? rspamd_mempool_strdup (pool, data) : NULL; } gboolean diff --git a/src/util.h b/src/util.h index 35d915698..643c8ef38 100644 --- a/src/util.h +++ b/src/util.h @@ -147,7 +147,7 @@ typedef struct pidfh rspamd_pidfh_t; /* * Replace %r with rcpt value and %f with from value, new string is allocated in pool */ -gchar* resolve_stat_filename (memory_pool_t *pool, gchar *pattern, gchar *rcpt, gchar *from); +gchar* resolve_stat_filename (rspamd_mempool_t *pool, gchar *pattern, gchar *rcpt, gchar *from); #ifdef HAVE_CLOCK_GETTIME /* * Calculate check time with specified resolution of timer diff --git a/src/view.c b/src/view.c index 2743e6a36..7ff7968bc 100644 --- a/src/view.c +++ b/src/view.c @@ -31,11 +31,11 @@ #include "map.h" struct rspamd_view * -init_view (struct config_file *cfg, memory_pool_t * pool) +init_view (struct config_file *cfg, rspamd_mempool_t * pool) { struct rspamd_view *new; - new = memory_pool_alloc0 (pool, sizeof (struct rspamd_view)); + new = rspamd_mempool_alloc0 (pool, sizeof (struct rspamd_view)); new->pool = pool; new->from_hash = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); @@ -45,7 +45,7 @@ init_view (struct config_file *cfg, memory_pool_t * pool) new->client_ip_tree = radix_tree_create (); new->cfg = cfg; - memory_pool_add_destructor (new->pool, (pool_destruct_func) g_hash_table_destroy, new->symbols_hash); + rspamd_mempool_add_destructor (new->pool, (rspamd_mempool_destruct_t) g_hash_table_destroy, new->symbols_hash); return new; } diff --git a/src/view.h b/src/view.h index 89de824b3..cb6fc6505 100644 --- a/src/view.h +++ b/src/view.h @@ -23,7 +23,7 @@ struct rspamd_view { GList *symbols_re_list; gboolean skip_check; - memory_pool_t *pool; + rspamd_mempool_t *pool; }; @@ -32,7 +32,7 @@ struct rspamd_view { * @param pool pool for view * @return */ -struct rspamd_view* init_view (struct config_file *cfg, memory_pool_t *pool); +struct rspamd_view* init_view (struct config_file *cfg, rspamd_mempool_t *pool); /** * Add from option for this view diff --git a/src/webui.c b/src/webui.c index 0a542993f..cd893f325 100644 --- a/src/webui.c +++ b/src/webui.c @@ -119,7 +119,7 @@ struct rspamd_webui_worker_ctx { struct rspamd_webui_session { struct rspamd_webui_worker_ctx *ctx; - memory_pool_t *pool; + rspamd_mempool_t *pool; struct worker_task *task; struct classifier_config *cl; struct { @@ -1166,11 +1166,11 @@ rspamd_webui_handle_history (struct rspamd_http_connection_entry *conn_ent, top = ucl_object_typed_new (UCL_ARRAY); /* Set lock on history */ - memory_pool_lock_mutex (ctx->srv->history->mtx); + rspamd_mempool_lock_mutex (ctx->srv->history->mtx); ctx->srv->history->need_lock = TRUE; /* Copy locked */ memcpy (&copied_history, ctx->srv->history, sizeof (copied_history)); - memory_pool_unlock_mutex (ctx->srv->history->mtx); + rspamd_mempool_unlock_mutex (ctx->srv->history->mtx); /* Go through all rows */ row_num = copied_history.cur_row; @@ -1683,7 +1683,7 @@ rspamd_webui_finish_handler (struct rspamd_http_connection_entry *conn_ent) struct rspamd_webui_session *session = conn_ent->ud; if (session->pool) { - memory_pool_delete (session->pool); + rspamd_mempool_delete (session->pool); } if (session->task != NULL) { destroy_session (session->task->s); @@ -1716,7 +1716,7 @@ rspamd_webui_accept_socket (gint fd, short what, void *arg) } nsession = g_slice_alloc0 (sizeof (struct rspamd_webui_session)); - nsession->pool = memory_pool_new (memory_pool_get_size ()); + nsession->pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); nsession->ctx = ctx; if (su.sa.sa_family == AF_UNIX) { diff --git a/src/worker.c b/src/worker.c index ddeadbd8e..8f6766350 100644 --- a/src/worker.c +++ b/src/worker.c @@ -359,7 +359,7 @@ accept_socket (gint fd, short what, void *arg) rspamd_worker_error_handler, rspamd_worker_finish_handler, 0, RSPAMD_HTTP_SERVER); new_task->ev_base = ctx->ev_base; ctx->tasks ++; - memory_pool_add_destructor (new_task->task_pool, (pool_destruct_func)reduce_tasks_count, &ctx->tasks); + rspamd_mempool_add_destructor (new_task->task_pool, (rspamd_mempool_destruct_t)reduce_tasks_count, &ctx->tasks); /* Set up async session */ new_task->s = new_async_session (new_task->task_pool, rspamd_fin_task, diff --git a/src/worker_util.c b/src/worker_util.c index f8e1b4b7e..9d86e8d3b 100644 --- a/src/worker_util.c +++ b/src/worker_util.c @@ -70,30 +70,30 @@ construct_task (struct rspamd_worker *worker) msg_warn ("gettimeofday failed: %s", strerror (errno)); } - new_task->task_pool = memory_pool_new (memory_pool_get_size ()); + new_task->task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); /* Add destructor for recipients list (it would be better to use anonymous function here */ - memory_pool_add_destructor (new_task->task_pool, - (pool_destruct_func) rcpt_destruct, new_task); + rspamd_mempool_add_destructor (new_task->task_pool, + (rspamd_mempool_destruct_t) rcpt_destruct, new_task); new_task->results = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); - memory_pool_add_destructor (new_task->task_pool, - (pool_destruct_func) g_hash_table_destroy, + rspamd_mempool_add_destructor (new_task->task_pool, + (rspamd_mempool_destruct_t) g_hash_table_destroy, new_task->results); new_task->re_cache = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); - memory_pool_add_destructor (new_task->task_pool, - (pool_destruct_func) g_hash_table_destroy, + rspamd_mempool_add_destructor (new_task->task_pool, + (rspamd_mempool_destruct_t) g_hash_table_destroy, new_task->re_cache); new_task->raw_headers = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); - memory_pool_add_destructor (new_task->task_pool, - (pool_destruct_func) g_hash_table_destroy, + rspamd_mempool_add_destructor (new_task->task_pool, + (rspamd_mempool_destruct_t) g_hash_table_destroy, new_task->raw_headers); new_task->emails = g_tree_new (compare_email_func); - memory_pool_add_destructor (new_task->task_pool, - (pool_destruct_func) g_tree_destroy, + rspamd_mempool_add_destructor (new_task->task_pool, + (rspamd_mempool_destruct_t) g_tree_destroy, new_task->emails); new_task->urls = g_tree_new (compare_url_func); - memory_pool_add_destructor (new_task->task_pool, - (pool_destruct_func) g_tree_destroy, + rspamd_mempool_add_destructor (new_task->task_pool, + (rspamd_mempool_destruct_t) g_tree_destroy, new_task->urls); new_task->sock = -1; new_task->is_mime = TRUE; @@ -170,7 +170,7 @@ free_task (struct worker_task *task, gboolean is_soft) if (task->sock != -1) { close (task->sock); } - memory_pool_delete (task->task_pool); + rspamd_mempool_delete (task->task_pool); g_slice_free1 (sizeof (struct worker_task), task); } } @@ -201,20 +201,20 @@ set_counter (const gchar *name, guint32 value) cd = rspamd_hash_lookup (rspamd_main->counters, (gpointer) name); if (cd == NULL) { - cd = memory_pool_alloc_shared (rspamd_main->counters->pool, sizeof (struct counter_data)); + cd = rspamd_mempool_alloc_shared (rspamd_main->counters->pool, sizeof (struct counter_data)); cd->value = value; cd->number = 0; - key = memory_pool_strdup_shared (rspamd_main->counters->pool, name); + key = rspamd_mempool_strdup_shared (rspamd_main->counters->pool, name); rspamd_hash_insert (rspamd_main->counters, (gpointer) key, (gpointer) cd); } else { /* Calculate new value */ - memory_pool_wlock_rwlock (rspamd_main->counters->lock); + rspamd_mempool_wlock_rwlock (rspamd_main->counters->lock); alpha = 2. / (++cd->number + 1); cd->value = cd->value * (1. - alpha) + value * alpha; - memory_pool_wunlock_rwlock (rspamd_main->counters->lock); + rspamd_mempool_wunlock_rwlock (rspamd_main->counters->lock); } return cd->value; diff --git a/test/rspamd_dkim_test.c b/test/rspamd_dkim_test.c index b6a613e48..a0c6332e4 100644 --- a/test/rspamd_dkim_test.c +++ b/test/rspamd_dkim_test.c @@ -63,7 +63,7 @@ rspamd_dkim_test_func () { rspamd_dkim_context_t *ctx; rspamd_dkim_key_t *key; - memory_pool_t *pool; + rspamd_mempool_t *pool; struct rspamd_dns_resolver *resolver; struct config_file *cfg; GError *err = NULL; @@ -71,11 +71,11 @@ rspamd_dkim_test_func () cfg = (struct config_file *)g_malloc (sizeof (struct config_file)); bzero (cfg, sizeof (struct config_file)); - cfg->cfg_pool = memory_pool_new (memory_pool_get_size ()); + cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); cfg->dns_retransmits = 10; cfg->dns_timeout = 1000; - pool = memory_pool_new (memory_pool_get_size ()); + pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); resolver = dns_resolver_init (base, cfg); diff --git a/test/rspamd_dns_test.c b/test/rspamd_dns_test.c index 9fa1d4901..897ed4253 100644 --- a/test/rspamd_dns_test.c +++ b/test/rspamd_dns_test.c @@ -67,17 +67,17 @@ rspamd_dns_test_func () { struct rspamd_dns_resolver *resolver; struct config_file *cfg; - memory_pool_t *pool; + 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->cfg_pool = memory_pool_new (memory_pool_get_size ()); + cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); cfg->dns_retransmits = 10; cfg->dns_timeout = 1000; - pool = memory_pool_new (memory_pool_get_size ()); + pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); s = new_async_session (pool, session_fin, NULL, NULL, NULL); diff --git a/test/rspamd_expression_test.c b/test/rspamd_expression_test.c index 7cf4bb123..2ce9e4f87 100644 --- a/test/rspamd_expression_test.c +++ b/test/rspamd_expression_test.c @@ -16,21 +16,21 @@ char *test_expressions[] = { void rspamd_expression_test_func () { - memory_pool_t *pool; + rspamd_mempool_t *pool; struct expression *cur; struct expression_argument *arg; char **line, *outstr; int r, s; GList *cur_arg; - pool = memory_pool_new (1024); + pool = rspamd_mempool_new (1024); line = test_expressions; while (*line) { r = 0; cur = parse_expression (pool, *line); s = strlen (*line) * 4; - outstr = memory_pool_alloc (pool, s); + outstr = rspamd_mempool_alloc (pool, s); while (cur) { if (cur->type == EXPR_REGEXP) { r += rspamd_snprintf (outstr + r, s - r, "OP:%s ", (char *)cur->content.operand); @@ -60,5 +60,5 @@ rspamd_expression_test_func () line ++; } - memory_pool_delete (pool); + rspamd_mempool_delete (pool); } diff --git a/test/rspamd_fuzzy_test.c b/test/rspamd_fuzzy_test.c index 7805e4f42..a5c76cb34 100644 --- a/test/rspamd_fuzzy_test.c +++ b/test/rspamd_fuzzy_test.c @@ -36,12 +36,12 @@ static char *s5 = "This is sample test text.\r\n" void rspamd_fuzzy_test_func () { - memory_pool_t *pool; + rspamd_mempool_t *pool; fuzzy_hash_t *h1, *h2, *h3, *h4, *h5; f_str_t f1, f2, f3, f4, f5; int diff2; - pool = memory_pool_new (1024); + pool = rspamd_mempool_new (1024); f1.begin = s1; f1.len = strlen (s1); f2.begin = s2; @@ -72,5 +72,5 @@ rspamd_fuzzy_test_func () g_assert (diff2 == 100); } - memory_pool_delete (pool); + rspamd_mempool_delete (pool); } diff --git a/test/rspamd_mem_pool_test.c b/test/rspamd_mem_pool_test.c index 51a32c47f..228644799 100644 --- a/test/rspamd_mem_pool_test.c +++ b/test/rspamd_mem_pool_test.c @@ -10,16 +10,16 @@ void rspamd_mem_pool_test_func () { - memory_pool_t *pool; - memory_pool_stat_t st; + rspamd_mempool_t *pool; + rspamd_mempool_stat_t st; char *tmp, *tmp2, *tmp3; pid_t pid; int ret; - pool = memory_pool_new (sizeof (TEST_BUF)); - tmp = memory_pool_alloc (pool, sizeof (TEST_BUF)); - tmp2 = memory_pool_alloc (pool, sizeof (TEST_BUF) * 2); - tmp3 = memory_pool_alloc_shared (pool, sizeof (TEST_BUF)); + pool = rspamd_mempool_new (sizeof (TEST_BUF)); + tmp = rspamd_mempool_alloc (pool, sizeof (TEST_BUF)); + tmp2 = rspamd_mempool_alloc (pool, sizeof (TEST_BUF) * 2); + tmp3 = rspamd_mempool_alloc_shared (pool, sizeof (TEST_BUF)); snprintf (tmp, sizeof (TEST_BUF), "%s", TEST_BUF); snprintf (tmp2, sizeof (TEST_BUF) * 2, "%s", TEST2_BUF); @@ -28,22 +28,22 @@ rspamd_mem_pool_test_func () g_assert (strncmp (tmp, TEST_BUF, sizeof (TEST_BUF)) == 0); g_assert (strncmp (tmp2, TEST2_BUF, sizeof (TEST2_BUF)) == 0); g_assert (strncmp (tmp3, TEST_BUF, sizeof (TEST_BUF)) == 0); - memory_pool_lock_shared (pool, tmp3); + rspamd_mempool_lock_shared (pool, tmp3); if ((pid = fork ()) == 0) { - memory_pool_lock_shared (pool, tmp3); + rspamd_mempool_lock_shared (pool, tmp3); g_assert (*tmp3 == 's'); *tmp3 = 't'; - memory_pool_unlock_shared (pool, tmp3); + rspamd_mempool_unlock_shared (pool, tmp3); exit (EXIT_SUCCESS); } else { *tmp3 = 's'; - memory_pool_unlock_shared (pool, tmp3); + rspamd_mempool_unlock_shared (pool, tmp3); } wait (&ret); g_assert (*tmp3 == 't'); - memory_pool_delete (pool); - memory_pool_stat (&st); + rspamd_mempool_delete (pool); + rspamd_mempool_stat (&st); } diff --git a/test/rspamd_statfile_test.c b/test/rspamd_statfile_test.c index f8e8a5294..870a827fa 100644 --- a/test/rspamd_statfile_test.c +++ b/test/rspamd_statfile_test.c @@ -10,12 +10,12 @@ void rspamd_statfile_test_func () { statfile_pool_t *pool; - memory_pool_t *p; + rspamd_mempool_t *p; stat_file_t *st; uint32_t random_hashes[HASHES_NUM], i, v; time_t now; - p = memory_pool_new (memory_pool_get_size ()); + p = rspamd_mempool_new (rspamd_mempool_suggest_size ()); umask (S_IWGRP | S_IWOTH); pool = statfile_pool_new (p, 10 * 1024 * 1024, TRUE); diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c index 7fb655347..fedcfd3eb 100644 --- a/test/rspamd_test_suite.c +++ b/test/rspamd_test_suite.c @@ -24,11 +24,11 @@ main (int argc, char **argv) #endif memset (rspamd_main, 0, sizeof (struct rspamd_main)); - rspamd_main->server_pool = memory_pool_new (memory_pool_get_size ()); + rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); rspamd_main->cfg = (struct config_file *)g_malloc (sizeof (struct config_file)); cfg = rspamd_main->cfg; bzero (cfg, sizeof (struct config_file)); - cfg->cfg_pool = memory_pool_new (memory_pool_get_size ()); + cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size ()); base = event_init (); |