#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)
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;
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));
}
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;
}
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;
/*
* 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
}
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);
}
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 {
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;
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);
}
}
DELETE_OUT_BUFFER (d, cur);
}
/* Cleanup temporary data */
- memory_pool_cleanup_tmp (d->pool);
+ rspamd_mempool_cleanup_tmp (d->pool);
d->in_buf = NULL;
}
} 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 */
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 */
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 */
* @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
* @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
* @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
/*
* 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
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 */
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");
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);
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 {
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);
}
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;
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);
}
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);
}
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;
}
}
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;
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);
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:
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:
}
/* 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;
}
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);
}
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;
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);
}
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];
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);
}
}
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;
}
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);
}
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] == '.') {
&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,
}
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') {
}
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 *
}
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;
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 */
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;
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;
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;
{
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;
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
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));
}
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;
}
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;
}
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;
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;
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)) {
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 */
struct worker_task;
struct classifier_ctx {
- memory_pool_t *pool;
+ rspamd_mempool_t *pool;
GHashTable *results;
gboolean debug;
struct classifier_config *cfg;
/* 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,
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);
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);
}
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;
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;
*/
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);
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;
}
}
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;
close (session->sock);
- memory_pool_delete (session->session_pool);
+ rspamd_mempool_delete (session->session_pool);
g_slice_free1 (sizeof (struct controller_session), session);
}
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));
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);
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;
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);
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;
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) {
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) {
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;
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;
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;
}
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;
}
}
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;
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;
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;
* @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;
} 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;
/* 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 */
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;
}
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;
#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;
* @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
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;
* @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
/* 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;
}
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;
#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;
#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;
}
}
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;
event_finalizer_t cleanup;
GHashTable *events;
void *user_data;
- memory_pool_t *pool;
+ rspamd_mempool_t *pool;
gboolean wanna_die;
guint threads;
GMutex *mtx;
* @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);
/* 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);
* 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;
}
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) {
}
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;
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;
* 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;
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) {
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);
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);
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) {
/* 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) {
/* 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 */
* 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;
}
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++;
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;
}
}
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;
}
}
}
- 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';
}
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 = '/';
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;
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;
}
}
- 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) {
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) {
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) {
}
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;
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;
}
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;
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;
* @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")
* @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
* @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
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;
}
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 */
}
}
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) {
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;
}
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;
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);
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;
}
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;
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;
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 {
* 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);
* 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;
* 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;
* 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;
* 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;
/*
* 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
/*
* 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
/* 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) {
}
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;
}
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;
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;
* @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
* @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
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];
}
}
if (hash->shared) {
- memory_pool_runlock_rwlock (hash->lock);
+ rspamd_mempool_runlock_rwlock (hash->lock);
}
return node_ptr;
}
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;
hash->nnodes--;
if (hash->shared) {
- memory_pool_wunlock_rwlock (hash->lock);
+ rspamd_mempool_wunlock_rwlock (hash->lock);
}
}
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++) {
hash->size = new_size;
if (hash->shared) {
- memory_pool_wunlock_rwlock (hash->lock);
+ rspamd_mempool_wunlock_rwlock (hash->lock);
}
}
/* 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;
* 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;
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;
}
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;
hash->nnodes++;
}
if (hash->shared) {
- memory_pool_wunlock_rwlock (hash->lock);
+ rspamd_mempool_wunlock_rwlock (hash->lock);
}
if (!hash->shared) {
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) {
}
}
if (hash->shared) {
- memory_pool_runlock_rwlock (hash->lock);
+ rspamd_mempool_runlock_rwlock (hash->lock);
}
}
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);
* @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
* @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
}
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;
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) == '/') {
}
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);
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);
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) {
}
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;
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);
}
/*
* 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);
/*
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;
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;
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;
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;
KVSTORAGE_STATE_ERROR
} state;
struct kvstorage_config *current_storage;
- memory_pool_t *pool;
+ rspamd_mempool_t *pool;
gchar *cur_elt;
};
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));
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);
}
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;
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);
}
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 */
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;
}
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;
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;
#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);
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
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;
guint id;
guint argc;
guint argnum;
- memory_pool_t *pool;
+ rspamd_mempool_t *pool;
gchar *key;
guint keylen;
struct kvstorage_config *cf;
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;
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;
* 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;
}
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 {
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;
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);
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;
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);
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;
/* 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 {
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 {
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 {
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;
}
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;
}
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 {
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;
}
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 {
}
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;
}
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 {
}
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;
}
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);
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);
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);
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);
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);
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 {
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;
}
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 {
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);
}
}
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);
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 {
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;
}
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 {
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;
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;
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;
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);
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;
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 ++;
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 */
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 */
* 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;
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;
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;
/* 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);
}
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);
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;
/* 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);
}
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);
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},
struct lua_mempool_udata {
lua_State *L;
gint cbref;
- memory_pool_t *mempool;
+ rspamd_mempool_t *mempool;
};
struct memory_pool_s *
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 *));
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");
struct memory_pool_s *mempool = lua_check_mempool (L);
if (mempool) {
- memory_pool_delete (mempool);
+ rspamd_mempool_delete (mempool);
return 0;
}
else {
}
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 {
*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 {
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);
}
/* 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;
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 */
{NULL, NULL}
};
-memory_pool_t *regexp_static_pool = NULL;
+rspamd_mempool_t *regexp_static_pool = NULL;
struct rspamd_lua_regexp {
GRegex *re;
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;
}
{
struct rspamd_async_session *session, **psession;
struct lua_session_udata *cbdata;
- memory_pool_t *mempool;
+ rspamd_mempool_t *mempool;
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);
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);
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;
}
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);
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 {
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
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);
}
/* 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 */
/* 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");
}
}
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);
}
#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) {
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));
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) {
/* 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);
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) {
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 */
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 */
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
* 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;
/* 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);
}
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';
}
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);
}
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;
}
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;
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);
}
/* 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);
}
/* 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);
}
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);
}
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);
}
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);
}
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 ();
}
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);
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;
}
}
}
/* 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));
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;
}
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));
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));
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);
/**
* 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;
/**
* 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
#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
* @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 ();
}
}
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;
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);
}
}
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);
}
}
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;
}
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;
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;
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;
}
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;
}
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)) {
}
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)) {
/* 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;
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;
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;
}
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;
}
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;
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;
}
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;
/* 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);
#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;
}
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)) {
}
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)) {
}
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);
}
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;
/**
* Destructor type definition
*/
-typedef void (*pool_destruct_func)(void *ptr);
+typedef void (*rspamd_mempool_destruct_t)(void *ptr);
/**
* Pool mutex structure
gint lock;
pid_t owner;
guint spin;
-} memory_pool_mutex_t;
+} rspamd_mempool_mutex_t;
/**
* Pool page structure
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 */
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
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
* @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
* @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
* @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
* @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
* @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
* @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
* @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
* @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
* @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
* @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
#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;
}
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;
}
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;
}
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 {
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;
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);
}
}
/* 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;
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) {
}
else {
*p = '\0';
- *res = memory_pool_strdup (pool, s);
+ *res = rspamd_mempool_strdup (pool, s);
*p = ']';
p++;
state = RSPAMD_RECV_STATE_SKIP_SPACES;
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;
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;
}
/* 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;
}
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 --) {
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;
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;
}
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) {
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));
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;
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;
}
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);
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);
}
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
}
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
#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;
/* 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);
*/
#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));
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));
}
#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;
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)));
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)));
struct multipart_cb_data {
GList *ret;
- memory_pool_t *pool;
+ rspamd_mempool_t *pool;
const gchar *field;
gboolean try_search;
gboolean strong;
}
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;
/* 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);
* 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;
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;
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);
}
}
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));
}
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;
* @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
const gchar *symbol;
double threshold;
- memory_pool_t *chartable_pool;
+ rspamd_mempool_t *chartable_pool;
};
static struct chartable_ctx *chartable_module_ctx = NULL;
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;
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);
}
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;
{
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;
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);
}
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 {
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;
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)) {
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 {
}
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;
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]);
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++;
}
}
}
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;
{
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;
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);
}
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;
}
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;
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);
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);
}
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;
/* 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");
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;
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;
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;
/* 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;
/* 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;
}
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;
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;
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;
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)) {
/* 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");
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);
}
}
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);
{
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;
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) {
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)) {
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);
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);
}
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);
# 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);
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;
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;
};
{
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;
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);
}
}
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;
}
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);
}
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);
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;
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;
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) {
}
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 ++;
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);
}
}
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);
}
}
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;
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");
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);
}
}
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);
}
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);
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;
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);
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;
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,
}
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 */
}
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 --) {
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)) {
(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)));
}
}
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);
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);
}
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);
}
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;
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);
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);
}
/*
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);
guint use_redirector;
struct redirector_upstream *redirectors;
guint32 redirectors_number;
- memory_pool_t *surbl_pool;
+ rspamd_mempool_t *surbl_pool;
};
struct suffix_item {
}
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;
}
* @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;
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 */
* @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);
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);
{
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);
{
g_return_if_fail (tree != NULL);
- memory_pool_delete (tree->pool);
+ rspamd_mempool_delete (tree->pool);
g_free (tree);
}
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);
* @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;
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;
}
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 */
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;
};
/**
* @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
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;
}
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;
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);
}
}
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) {
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;
}
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);
}
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);
"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);
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);
"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);
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);
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");
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;
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;
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;
{
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;
gsize upstream_num;
gchar *upstreams_str;
- memory_pool_t *pool;
+ rspamd_mempool_t *pool;
gchar *smtp_banner;
gchar *smtp_banner_str;
guint32 smtp_delay;
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;
#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;
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';
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 ++) {
}
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;
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 == ':') {
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;
}
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) {
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;
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;
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;
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;
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)) {
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)) {
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;
}
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);
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;
/*
* 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
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;
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;
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);
}
}
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],
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);
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;
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,
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;
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;
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);
}
}
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);
}
}
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");
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;
if (session->temp_fd != -1) {
close (session->temp_fd);
}
- memory_pool_delete (session->pool);
+ rspamd_mempool_delete (session->pool);
g_free (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 */
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 {
}
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;
g_strfreev (strv);
return FALSE;
}
- cur->name = memory_pool_strdup (pool, resolved_path);
+ cur->name = rspamd_mempool_strdup (pool, resolved_path);
(*count) ++;
}
else {
g_strfreev (strv);
return FALSE;
}
- cur->name = memory_pool_strdup (pool, p);
+ cur->name = rspamd_mempool_strdup (pool, p);
(*count) ++;
}
}
* @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_ */
}
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);
}
}
/* 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;
/* 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;
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;
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));
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 ++;
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 ++;
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)) {
return begin;
}
- new = memory_pool_alloc (task->task_pool, len + 1);
+ new = rspamd_mempool_alloc (task->task_pool, len + 1);
c = new;
p = 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; \
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) {
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) {
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';
}
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) {
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';
}
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;
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;
}
/* 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) {
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);
}
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;
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;
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);
}
return -1;
}
- memory_pool_lock_mutex (pool->lock);
+ rspamd_mempool_lock_mutex (pool->lock);
if (file->map) {
msg_info ("syncing statfile %s", file->filename);
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;
}
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;
}
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;
}
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;
}
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;
}
if (buf) {
g_free (buf);
}
- memory_pool_unlock_mutex (pool->lock);
+ rspamd_mempool_unlock_mutex (pool->lock);
return -1;
}
nblocks --;
}
close (fd);
- memory_pool_unlock_mutex (pool->lock);
+ rspamd_mempool_unlock_mutex (pool->lock);
if (buf) {
g_free (buf);
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
}
}
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);
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;
/**
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 */
* @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
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;
}
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;
/* 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;
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;
}
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)
{
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;
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);
}
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);
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);
}
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);
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;
}
/* Init locking */
- cache->lock = memory_pool_get_rwlock (pool);
+ cache->lock = rspamd_mempool_get_rwlock (pool);
cache->cfg = cfg;
/* 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;
}
}
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);
/* 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);
/**
* @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);
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;
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]));
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) {
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) {
} 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;
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;
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;
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;
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");
/* 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);
};
/* 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);
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;
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;
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);
}
struct rspamd_trie_state root;
GPtrArray *fail_states;
gboolean icase;
- memory_pool_t *pool;
+ rspamd_mempool_t *pool;
} rspamd_trie_t;
/*
}
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;
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;
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);
}
*/
static gchar *
-reencode_escapes (gchar *s, memory_pool_t * pool)
+reencode_escapes (gchar *s, rspamd_mempool_t * pool)
{
const gchar *p1;
gchar *newstr, *p2;
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. */
}
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;
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;
}
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;
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);
/* 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;
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';
}
* @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
* @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
* @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
/* 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;
}
/* Allocate new string */
- new = memory_pool_alloc (pool, len);
+ new = rspamd_mempool_alloc (pool, len);
c = pattern;
s = new;
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
/*
* 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
#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);
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;
}
GList *symbols_re_list;
gboolean skip_check;
- memory_pool_t *pool;
+ rspamd_mempool_t *pool;
};
* @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
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 {
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;
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);
}
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) {
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,
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;
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);
}
}
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;
{
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;
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);
{
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);
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);
line ++;
}
- memory_pool_delete (pool);
+ rspamd_mempool_delete (pool);
}
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;
g_assert (diff2 == 100);
}
- memory_pool_delete (pool);
+ rspamd_mempool_delete (pool);
}
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);
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);
}
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);
#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 ();