aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c219
1 files changed, 2 insertions, 217 deletions
diff --git a/src/util.c b/src/util.c
index 4d2665f6b..2efd8f0d5 100644
--- a/src/util.c
+++ b/src/util.c
@@ -38,8 +38,6 @@
/* Default connect timeout for sync sockets */
#define CONNECT_TIMEOUT 3
-rspamd_hash_t *counters = NULL;
-
static gchar* rspamd_sprintf_num (gchar *buf, gchar *last, guint64 ui64, gchar zero, guint hexadecimal, guint width);
gint
@@ -939,35 +937,6 @@ calculate_check_time (struct timeval *begin, gint resolution)
return (const gchar *)res;
}
-double
-set_counter (const gchar *name, guint32 value)
-{
- struct counter_data *cd;
- double alpha;
- gchar *key;
-
- cd = rspamd_hash_lookup (counters, (gpointer) name);
-
- if (cd == NULL) {
- cd = memory_pool_alloc_shared (counters->pool, sizeof (struct counter_data));
- cd->value = value;
- cd->number = 0;
- key = memory_pool_strdup_shared (counters->pool, name);
- rspamd_hash_insert (counters, (gpointer) key, (gpointer) cd);
- }
- else {
- /* Calculate new value */
- memory_pool_wlock_rwlock (counters->lock);
-
- alpha = 2. / (++cd->number + 1);
- cd->value = cd->value * (1. - alpha) + value * alpha;
-
- memory_pool_wunlock_rwlock (counters->lock);
- }
-
- return cd->value;
-}
-
#ifndef g_tolower
# define g_tolower(x) (((x) >= 'A' && (x) <= 'Z') ? (x) - 'A' + 'a' : (x))
#endif
@@ -1147,52 +1116,6 @@ unlock_file (gint fd, gboolean async)
}
#endif /* HAVE_FLOCK */
-stat_file_t *
-get_statfile_by_symbol (statfile_pool_t *pool, struct classifier_config *ccf,
- const gchar *symbol, struct statfile **st, gboolean try_create)
-{
- stat_file_t *res = NULL;
- GList *cur;
-
- if (pool == NULL || ccf == NULL || symbol == NULL) {
- msg_err ("invalid input arguments");
- return NULL;
- }
-
- cur = g_list_first (ccf->statfiles);
- while (cur) {
- *st = cur->data;
- if (strcmp (symbol, (*st)->symbol) == 0) {
- break;
- }
- *st = NULL;
- cur = g_list_next (cur);
- }
- if (*st == NULL) {
- msg_info ("cannot find statfile with symbol %s", symbol);
- return NULL;
- }
-
- if ((res = statfile_pool_is_open (pool, (*st)->path)) == NULL) {
- if ((res = statfile_pool_open (pool, (*st)->path, (*st)->size, FALSE)) == NULL) {
- msg_warn ("cannot open %s", (*st)->path);
- if (try_create) {
- if (statfile_pool_create (pool, (*st)->path, (*st)->size) == -1) {
- msg_err ("cannot create statfile %s", (*st)->path);
- return NULL;
- }
- res = statfile_pool_open (pool, (*st)->path, (*st)->size, FALSE);
- if (res == NULL) {
- msg_err ("cannot open statfile %s after creation", (*st)->path);
- }
- }
- }
- }
-
- return res;
-}
-
-
#if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION < 22))
void
@@ -1276,22 +1199,8 @@ str_to_process (const gchar *str)
return TYPE_UNKNOWN;
}
-/*
- * Destructor for recipients list
- */
-static void
-rcpt_destruct (void *pointer)
-{
- struct worker_task *task = (struct worker_task *) pointer;
-
- if (task->rcpt) {
- g_list_free (task->rcpt);
- }
-}
-
-
/* Compare two emails for building emails tree */
-static gint
+gint
compare_email_func (gconstpointer a, gconstpointer b)
{
const struct uri *u1 = a, *u2 = b;
@@ -1317,7 +1226,7 @@ compare_email_func (gconstpointer a, gconstpointer b)
return 0;
}
-static gint
+gint
compare_url_func (gconstpointer a, gconstpointer b)
{
const struct uri *u1 = a, *u2 = b;
@@ -1333,130 +1242,6 @@ compare_url_func (gconstpointer a, gconstpointer b)
return r;
}
-/*
- * Create new task
- */
-struct worker_task *
-construct_task (struct rspamd_worker *worker)
-{
- struct worker_task *new_task;
-
- new_task = g_slice_alloc0 (sizeof (struct worker_task));
-
- new_task->worker = worker;
- new_task->state = READ_COMMAND;
- new_task->cfg = worker->srv->cfg;
- new_task->from_addr.s_addr = INADDR_NONE;
- new_task->view_checked = FALSE;
-#ifdef HAVE_CLOCK_GETTIME
-# ifdef HAVE_CLOCK_PROCESS_CPUTIME_ID
- clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &new_task->ts);
-# elif defined(HAVE_CLOCK_VIRTUAL)
- clock_gettime (CLOCK_VIRTUAL, &new_task->ts);
-# else
- clock_gettime (CLOCK_REALTIME, &new_task->ts);
-# endif
-#endif
- if (gettimeofday (&new_task->tv, NULL) == -1) {
- msg_warn ("gettimeofday failed: %s", strerror (errno));
- }
-
- new_task->task_pool = memory_pool_new (memory_pool_get_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);
- new_task->results = g_hash_table_new (g_str_hash, g_str_equal);
- memory_pool_add_destructor (new_task->task_pool,
- (pool_destruct_func) g_hash_table_destroy,
- new_task->results);
- new_task->re_cache = g_hash_table_new (g_str_hash, g_str_equal);
- memory_pool_add_destructor (new_task->task_pool,
- (pool_destruct_func) 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,
- 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,
- 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,
- new_task->urls);
- new_task->s =
- new_async_session (new_task->task_pool, free_task_hard, new_task);
- new_task->sock = -1;
- new_task->is_mime = TRUE;
-
- return new_task;
-}
-
-
-/*
- * Free all structures of worker_task
- */
-void
-free_task (struct worker_task *task, gboolean is_soft)
-{
- GList *part;
- struct mime_part *p;
-
- if (task) {
- debug_task ("free pointer %p", task);
- while ((part = g_list_first (task->parts))) {
- task->parts = g_list_remove_link (task->parts, part);
- p = (struct mime_part *) part->data;
- g_byte_array_free (p->content, TRUE);
- g_list_free_1 (part);
- }
- if (task->text_parts) {
- g_list_free (task->text_parts);
- }
- if (task->images) {
- g_list_free (task->images);
- }
- if (task->messages) {
- g_list_free (task->messages);
- }
- if (task->received) {
- g_list_free (task->received);
- }
- memory_pool_delete (task->task_pool);
- if (task->dispatcher) {
- if (is_soft) {
- /* Plan dispatcher shutdown */
- task->dispatcher->wanna_die = 1;
- }
- else {
- rspamd_remove_dispatcher (task->dispatcher);
- }
- }
- if (task->sock != -1) {
- close (task->sock);
- }
- g_slice_free1 (sizeof (struct worker_task), task);
- }
-}
-
-void
-free_task_hard (gpointer ud)
-{
- struct worker_task *task = ud;
-
- free_task (task, FALSE);
-}
-
-void
-free_task_soft (gpointer ud)
-{
- struct worker_task *task = ud;
-
- free_task (task, FALSE);
-}
-
gchar *
escape_braces_addr_fstr (memory_pool_t *pool, f_str_t *in)
{