From d2150fc165e99bb8d6a7411bffee6fd7d36d4763 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 29 Nov 2014 17:02:49 +0000 Subject: [PATCH] Refactor function names. --- src/client/rspamdclient.c | 2 +- src/controller.c | 8 ++-- src/fuzzy_storage.c | 38 +++++++++--------- src/kvstorage_server.c | 18 ++++----- src/libmime/expressions.c | 4 +- src/libmime/filter.c | 18 ++++----- src/libmime/message.c | 4 +- src/libmime/message.h | 6 +-- src/libmime/smtp_proto.c | 20 +++++----- src/libmime/smtp_proto.h | 4 +- src/libserver/binlog.c | 42 ++++++++++---------- src/libserver/buffer.c | 12 +++--- src/libserver/buffer.h | 4 +- src/libserver/cfg_utils.c | 4 +- src/libserver/dynamic_cfg.c | 2 +- src/libserver/statfile.c | 10 ++--- src/libserver/statfile_sync.c | 8 ++-- src/libserver/task.c | 4 +- src/libserver/url.c | 4 +- src/libserver/worker_util.c | 2 +- src/libutil/addr.c | 2 +- src/libutil/aio_event.c | 2 +- src/libutil/diff.c | 8 ++-- src/libutil/diff.h | 4 +- src/libutil/fstring.c | 62 +++++++++++++++--------------- src/libutil/fstring.h | 44 ++++++++++----------- src/libutil/fuzzy.c | 56 +++++++++++++-------------- src/libutil/fuzzy.h | 16 ++++---- src/libutil/logger.c | 38 +++++++++--------- src/libutil/logger.h | 16 ++++---- src/libutil/map.c | 32 ++++++++-------- src/libutil/map.h | 22 +++++------ src/libutil/printf.c | 4 +- src/libutil/util.c | 72 +++++++++++++++++------------------ src/libutil/util.h | 40 +++++++++---------- src/lmtp.c | 6 +-- src/lmtp_proto.c | 50 ++++++++++++------------ src/lmtp_proto.h | 2 +- src/lua/lua_buffer.c | 2 +- src/lua/lua_config.c | 10 ++--- src/lua/lua_redis.c | 4 +- src/lua/lua_rsa.c | 36 +++++++++--------- src/lua/lua_task.c | 4 +- src/lua_worker.c | 4 +- src/main.c | 26 ++++++------- src/main.h | 4 +- src/plugins/dkim_check.c | 8 ++-- src/plugins/fuzzy_check.c | 26 ++++++------- src/plugins/spf.c | 4 +- src/plugins/surbl.c | 28 +++++++------- src/smtp.c | 10 ++--- src/smtp_proxy.c | 6 +-- src/tokenizers/osb.c | 8 ++-- src/tokenizers/tokenizers.c | 16 ++++---- src/tokenizers/tokenizers.h | 8 ++-- src/worker.c | 4 +- test/rspamd_fuzzy_test.c | 24 ++++++------ test/rspamd_test_suite.c | 2 +- 58 files changed, 463 insertions(+), 461 deletions(-) diff --git a/src/client/rspamdclient.c b/src/client/rspamdclient.c index e9a8f5409..b66d67f2d 100644 --- a/src/client/rspamdclient.c +++ b/src/client/rspamdclient.c @@ -137,7 +137,7 @@ rspamd_client_init (struct event_base *ev_base, const gchar *name, struct rspamd_client_connection *conn; gint fd; - fd = make_universal_socket (name, port, SOCK_STREAM, TRUE, FALSE, TRUE); + fd = rspamd_socket (name, port, SOCK_STREAM, TRUE, FALSE, TRUE); if (fd == -1) { return NULL; } diff --git a/src/controller.c b/src/controller.c index 22104d7b6..fe9d6bc29 100644 --- a/src/controller.c +++ b/src/controller.c @@ -1634,9 +1634,9 @@ start_controller_worker (struct rspamd_worker *worker) ctx->custom_commands = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); if (ctx->secure_ip != NULL) { - if (!add_map (worker->srv->cfg, ctx->secure_ip, + if (!rspamd_map_add (worker->srv->cfg, ctx->secure_ip, "Allow webui access from the specified IP", - read_radix_list, fin_radix_list, (void **)&ctx->secure_map)) { + rspamd_radix_read, rspamd_radix_fin, (void **)&ctx->secure_map)) { if (!radix_add_generic_iplist (ctx->secure_ip, &ctx->secure_map)) { msg_warn ("cannot load or parse ip list from '%s'", @@ -1728,11 +1728,11 @@ start_controller_worker (struct rspamd_worker *worker) rspamd_upstreams_library_init (ctx->resolver->r, ctx->ev_base); rspamd_upstreams_library_config (worker->srv->cfg); /* Maps events */ - start_map_watch (worker->srv->cfg, ctx->ev_base); + rspamd_map_watch (worker->srv->cfg, ctx->ev_base); event_base_loop (ctx->ev_base, 0); g_mime_shutdown (); - close_log (rspamd_main->logger); + rspamd_log_close (rspamd_main->logger); exit (EXIT_SUCCESS); } diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index dd43f1008..46d4b3ff4 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -106,7 +106,7 @@ struct rspamd_fuzzy_node { gint32 value; gint32 flag; guint64 time; - fuzzy_hash_t h; + rspamd_fuzzy_t h; }; struct fuzzy_session { @@ -226,7 +226,7 @@ sync_cache (gpointer ud) continue; } - (void) lock_file (fd, FALSE); + (void) rspamd_file_lock (fd, FALSE); now = (guint64) time (NULL ); @@ -317,7 +317,7 @@ end: if (nodes_expired != NULL) { g_free (nodes_expired); } - (void) unlock_file (fd, FALSE); + (void) rspamd_file_unlock (fd, FALSE); close (fd); rspamd_mutex_unlock (ctx->update_mtx); @@ -370,7 +370,7 @@ read_hashes_file (struct rspamd_worker *wrk) struct { gint32 value; guint64 time; - fuzzy_hash_t h; + rspamd_fuzzy_t h; } legacy_node; if (server_stat->fuzzy_hashes != 0) { @@ -387,7 +387,7 @@ read_hashes_file (struct rspamd_worker *wrk) return FALSE; } - (void)lock_file (fd, FALSE); + (void)rspamd_file_lock (fd, FALSE); fstat (fd, &st); @@ -427,7 +427,7 @@ read_hashes_file (struct rspamd_worker *wrk) } node->value = legacy_node.value; node->time = legacy_node.time; - memcpy (&node->h, &legacy_node.h, sizeof (fuzzy_hash_t)); + memcpy (&node->h, &legacy_node.h, sizeof (rspamd_fuzzy_t)); node->flag = 0; } else { @@ -461,7 +461,7 @@ read_hashes_file (struct rspamd_worker *wrk) } } - (void)unlock_file (fd, FALSE); + (void)rspamd_file_unlock (fd, FALSE); close (fd); if (r > 0) { @@ -477,7 +477,7 @@ read_hashes_file (struct rspamd_worker *wrk) } static inline struct rspamd_fuzzy_node * -check_hash_node (GQueue *hash, fuzzy_hash_t *s, gint update_value, +check_hash_node (GQueue *hash, rspamd_fuzzy_t *s, gint update_value, guint64 time, struct rspamd_fuzzy_storage_ctx *ctx) { GList *cur; @@ -509,7 +509,7 @@ check_hash_node (GQueue *hash, fuzzy_hash_t *s, gint update_value, cur = frequent->head; while (cur) { h = cur->data; - if ((prob = fuzzy_compare_hashes (&h->h, s)) > LEV_LIMIT) { + if ((prob = rspamd_fuzzy_compare (&h->h, s)) > LEV_LIMIT) { msg_info ("fuzzy hash was found, probability %d%%", prob); if (h->time == INVALID_NODE_TIME) { return NULL; @@ -531,7 +531,7 @@ check_hash_node (GQueue *hash, fuzzy_hash_t *s, gint update_value, cur = hash->head; while (cur) { h = cur->data; - if ((prob = fuzzy_compare_hashes (&h->h, s)) > LEV_LIMIT) { + if ((prob = rspamd_fuzzy_compare (&h->h, s)) > LEV_LIMIT) { msg_info ("fuzzy hash was found, probability %d%%", prob); if (h->time == INVALID_NODE_TIME) { return NULL; @@ -565,7 +565,7 @@ process_check_command (struct fuzzy_cmd *cmd, guint64 time, struct rspamd_fuzzy_storage_ctx *ctx) { - fuzzy_hash_t s; + rspamd_fuzzy_t s; struct rspamd_fuzzy_node *h; @@ -625,7 +625,7 @@ update_hash (struct fuzzy_cmd *cmd, guint64 time, struct rspamd_fuzzy_storage_ctx *ctx) { - fuzzy_hash_t s; + rspamd_fuzzy_t s; struct rspamd_fuzzy_node *n; memcpy (s.hash_pipe, cmd->hash, sizeof (s.hash_pipe)); @@ -679,7 +679,7 @@ process_write_command (struct fuzzy_cmd *cmd, } static gboolean -delete_hash (GQueue *hash, fuzzy_hash_t *s, +delete_hash (GQueue *hash, rspamd_fuzzy_t *s, struct rspamd_fuzzy_storage_ctx *ctx) { GList *cur, *tmp; @@ -703,7 +703,7 @@ delete_hash (GQueue *hash, fuzzy_hash_t *s, /* XXX: too slow way */ while (cur) { h = cur->data; - if (fuzzy_compare_hashes (&h->h, s) > LEV_LIMIT) { + if (rspamd_fuzzy_compare (&h->h, s) > LEV_LIMIT) { g_slice_free1 (sizeof (struct rspamd_fuzzy_node), h); tmp = cur; cur = g_list_next (cur); @@ -729,7 +729,7 @@ process_delete_command (struct fuzzy_cmd *cmd, guint64 time, struct rspamd_fuzzy_storage_ctx *ctx) { - fuzzy_hash_t s; + rspamd_fuzzy_t s; gboolean res = FALSE; if (!rspamd_bloom_check (bf, cmd->hash)) { @@ -1050,9 +1050,9 @@ start_fuzzy (struct rspamd_worker *worker) /* Create radix tree */ if (ctx->update_map != NULL) { - if (!add_map (worker->srv->cfg, ctx->update_map, + if (!rspamd_map_add (worker->srv->cfg, ctx->update_map, "Allow fuzzy updates from specified addresses", - read_radix_list, fin_radix_list, (void **)&ctx->update_ips)) { + rspamd_radix_read, rspamd_radix_fin, (void **)&ctx->update_ips)) { if (!radix_add_generic_iplist (ctx->update_map, &ctx->update_ips)) { msg_warn ("cannot load or parse ip list from '%s'", @@ -1062,7 +1062,7 @@ start_fuzzy (struct rspamd_worker *worker) } /* Maps events */ - start_map_watch (worker->srv->cfg, ctx->ev_base); + rspamd_map_watch (worker->srv->cfg, ctx->ev_base); ctx->update_thread = rspamd_create_thread ("fuzzy update", sync_cache, @@ -1078,6 +1078,6 @@ start_fuzzy (struct rspamd_worker *worker) g_thread_join (ctx->update_thread); } - close_log (rspamd_main->logger); + rspamd_log_close (rspamd_main->logger); exit (EXIT_SUCCESS); } diff --git a/src/kvstorage_server.c b/src/kvstorage_server.c index ecf86f7b3..25dbc05a1 100644 --- a/src/kvstorage_server.c +++ b/src/kvstorage_server.c @@ -246,7 +246,7 @@ parse_kvstorage_command (struct kvstorage_session *session, gchar *c, guint len) * Parse kvstorage line */ static gboolean -parse_kvstorage_line (struct kvstorage_session *session, f_str_t *in) +parse_kvstorage_line (struct kvstorage_session *session, rspamd_fstring_t *in) { gchar *p, *c, *end; gint state = 0, next_state = 0; @@ -728,7 +728,7 @@ kvstorage_process_command (struct kvstorage_session *session, gboolean is_redis) } static gboolean -kvstorage_read_arglen (f_str_t *in, guint *len) +kvstorage_read_arglen (rspamd_fstring_t *in, guint *len) { gchar *p = in->begin, *end = in->begin + in->len, *c; gint state = 0; @@ -797,7 +797,7 @@ kvstorage_check_argnum (struct kvstorage_session *session) * Callback that is called when there is data to read in buffer */ static gboolean -kvstorage_read_socket (f_str_t * in, void *arg) +kvstorage_read_socket (rspamd_fstring_t * in, void *arg) { struct kvstorage_session *session = (struct kvstorage_session *) arg; struct kvstorage_worker_thread *thr; @@ -1248,11 +1248,11 @@ create_kvstorage_thread (struct rspamd_worker *worker, new->id = id; /* Create and setup terminating socket */ - if (make_socketpair (new->term_sock) == -1) { + if (rspamd_socketpair (new->term_sock) == -1) { msg_err ("socket failed: %s", strerror (errno)); return NULL; } - make_socket_nonblocking (new->term_sock[0]); + rspamd_socket_nonblocking (new->term_sock[0]); #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30)) new->thr = g_thread_create (kvstorage_thread, new, FALSE, &err); @@ -1299,7 +1299,7 @@ start_keystorage (struct rspamd_worker *worker) exit (EXIT_SUCCESS); } /* Create socketpair */ - if (make_socketpair (ctx->s_pair) == -1) { + if (rspamd_socketpair (ctx->s_pair) == -1) { msg_err ("cannot create socketpair, exiting"); exit (EXIT_SUCCESS); } @@ -1320,7 +1320,7 @@ start_keystorage (struct rspamd_worker *worker) exit (EXIT_SUCCESS); } - init_signals (&signals, sig_handler); + rspamd_signals_init (&signals, sig_handler); /* Set umask */ umask (S_IWGRP | S_IWOTH | S_IROTH | S_IRGRP); @@ -1393,7 +1393,7 @@ start_keystorage (struct rspamd_worker *worker) } else if (do_reopen_log == 1) { do_reopen_log = 0; - reopen_log (rspamd_main->logger); + rspamd_log_reopen (rspamd_main->logger); } } @@ -1408,6 +1408,6 @@ start_keystorage (struct rspamd_worker *worker) } #endif destroy_kvstorage_config (); - close_log (rspamd_main->logger); + rspamd_log_close (rspamd_main->logger); exit (EXIT_SUCCESS); } diff --git a/src/libmime/expressions.c b/src/libmime/expressions.c index 154649b51..0ff34e24b 100644 --- a/src/libmime/expressions.c +++ b/src/libmime/expressions.c @@ -1168,11 +1168,11 @@ rspamd_parts_distance (struct rspamd_task * task, GList * args, void *unused) } if (!p1->is_empty && !p2->is_empty) { if (p1->diff_str != NULL && p2->diff_str != NULL) { - diff = compare_diff_distance_normalized (p1->diff_str, + diff = rspamd_diff_distance_normalized (p1->diff_str, p2->diff_str); } else { - diff = fuzzy_compare_parts (p1, p2); + diff = rspamd_fuzzy_compare_parts (p1, p2); } debug_task ( "got likeliness between parts of %d%%, threshold is %d%%", diff --git a/src/libmime/filter.c b/src/libmime/filter.c index 091887839..c6a4752fa 100644 --- a/src/libmime/filter.c +++ b/src/libmime/filter.c @@ -746,7 +746,7 @@ classifiers_callback (gpointer value, void *arg) struct rspamd_statfile_config *st; GTree *tokens = NULL; GList *cur; - f_str_t c; + rspamd_fstring_t c; gchar *header = NULL; gint *dist = NULL, diff; gboolean is_twopart = FALSE, is_headers = FALSE; @@ -807,10 +807,10 @@ classifiers_callback (gpointer value, void *arg) p2 = text_part; if (p1->diff_str != NULL && p2->diff_str != NULL) { diff = - compare_diff_distance (p1->diff_str, p2->diff_str); + rspamd_diff_distance (p1->diff_str, p2->diff_str); } else { - diff = fuzzy_compare_parts (p1, p2); + diff = rspamd_fuzzy_compare_parts (p1, p2); } if (diff >= COMMON_PART_FACTOR) { msg_info ( @@ -1115,7 +1115,7 @@ rspamd_learn_task (const gchar *statfile, struct rspamd_task *task, GError **err struct rspamd_classifier_config *cl; struct classifier_ctx *cls_ctx; gchar *s; - f_str_t c; + rspamd_fstring_t c; GTree *tokens = NULL; struct rspamd_statfile_config *st; stat_file_t *stf; @@ -1174,10 +1174,10 @@ rspamd_learn_task (const gchar *statfile, struct rspamd_task *task, GError **err p1 = cur->prev->data; p2 = part; if (p1->diff_str != NULL && p2->diff_str != NULL) { - diff = compare_diff_distance (p1->diff_str, p2->diff_str); + diff = rspamd_diff_distance (p1->diff_str, p2->diff_str); } else { - diff = fuzzy_compare_parts (p1, p2); + diff = rspamd_fuzzy_compare_parts (p1, p2); } if (diff >= COMMON_PART_FACTOR) { msg_info ( @@ -1261,7 +1261,7 @@ rspamd_learn_task_spam (struct rspamd_classifier_config *cl, { GList *cur, *ex; struct classifier_ctx *cls_ctx; - f_str_t c; + rspamd_fstring_t c; GTree *tokens = NULL; struct mime_text_part *part, *p1, *p2; gboolean is_utf = FALSE, is_twopart = FALSE; @@ -1292,10 +1292,10 @@ rspamd_learn_task_spam (struct rspamd_classifier_config *cl, p1 = cur->prev->data; p2 = part; if (p1->diff_str != NULL && p2->diff_str != NULL) { - diff = compare_diff_distance (p1->diff_str, p2->diff_str); + diff = rspamd_diff_distance (p1->diff_str, p2->diff_str); } else { - diff = fuzzy_compare_parts (p1, p2); + diff = rspamd_fuzzy_compare_parts (p1, p2); } if (diff >= COMMON_PART_FACTOR) { msg_info ( diff --git a/src/libmime/message.c b/src/libmime/message.c index 3a1baf798..0e33967ca 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -1090,7 +1090,7 @@ process_text_part (struct rspamd_task *task, } url_parse_text (task->task_pool, task, text_part, TRUE); - fuzzy_init_part (text_part, task->task_pool, task->cfg->max_diff); + rspamd_fuzzy_from_text_part (text_part, task->task_pool, task->cfg->max_diff); rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) free_byte_array_callback, text_part->content); @@ -1117,7 +1117,7 @@ process_text_part (struct rspamd_task *task, text_part); text_part->orig = part_content; url_parse_text (task->task_pool, task, text_part, FALSE); - fuzzy_init_part (text_part, task->task_pool, task->cfg->max_diff); + rspamd_fuzzy_from_text_part (text_part, task->task_pool, task->cfg->max_diff); task->text_parts = g_list_prepend (task->text_parts, text_part); } } diff --git a/src/libmime/message.h b/src/libmime/message.h index 35eb3ff1e..ddc5939fa 100644 --- a/src/libmime/message.h +++ b/src/libmime/message.h @@ -31,11 +31,11 @@ struct mime_text_part { GByteArray *content; GNode *html_nodes; GList *urls_offset; /**< list of offsets of urls */ - fuzzy_hash_t *fuzzy; - fuzzy_hash_t *double_fuzzy; + rspamd_fuzzy_t *fuzzy; + rspamd_fuzzy_t *double_fuzzy; GMimeObject *parent; GUnicodeScript script; - f_str_t *diff_str; + rspamd_fstring_t *diff_str; }; struct received_header { diff --git a/src/libmime/smtp_proto.c b/src/libmime/smtp_proto.c index c716b7480..ec7ab191a 100644 --- a/src/libmime/smtp_proto.c +++ b/src/libmime/smtp_proto.c @@ -57,7 +57,7 @@ make_smtp_error (rspamd_mempool_t *pool, gboolean parse_smtp_command (struct smtp_session *session, - f_str_t *line, + rspamd_fstring_t *line, struct smtp_command **cmd) { enum { @@ -68,7 +68,7 @@ parse_smtp_command (struct smtp_session *session, } state; gchar *p, *c, ch, cmd_buf[4]; guint i; - f_str_t *arg = NULL; + rspamd_fstring_t *arg = NULL; struct smtp_command *pcmd; if (line->len == 0) { @@ -164,7 +164,7 @@ parse_smtp_command (struct smtp_session *session, } else if (ch != ' ' && ch != ':') { state = SMTP_PARSE_ARGUMENT; - arg = rspamd_mempool_alloc (session->pool, sizeof (f_str_t)); + arg = rspamd_mempool_alloc (session->pool, sizeof (rspamd_fstring_t)); c = p; } break; @@ -209,7 +209,7 @@ end: } static gboolean -check_smtp_path (f_str_t *path) +check_smtp_path (rspamd_fstring_t *path) { guint i; gchar *p; @@ -230,7 +230,7 @@ check_smtp_path (f_str_t *path) gboolean parse_smtp_helo (struct smtp_session *session, struct smtp_command *cmd) { - f_str_t *arg; + rspamd_fstring_t *arg; if (cmd->args == NULL) { session->error = SMTP_ERROR_BAD_ARGUMENTS; @@ -265,7 +265,7 @@ parse_smtp_helo (struct smtp_session *session, struct smtp_command *cmd) gboolean parse_smtp_from (struct smtp_session *session, struct smtp_command *cmd) { - f_str_t *arg; + rspamd_fstring_t *arg; GList *cur = cmd->args; if (cmd->args == NULL) { @@ -303,7 +303,7 @@ parse_smtp_from (struct smtp_session *session, struct smtp_command *cmd) gboolean parse_smtp_rcpt (struct smtp_session *session, struct smtp_command *cmd) { - f_str_t *arg; + rspamd_fstring_t *arg; GList *cur = cmd->args; if (cmd->args == NULL) { @@ -339,7 +339,7 @@ parse_smtp_rcpt (struct smtp_session *session, struct smtp_command *cmd) /* Return -1 if there are some error, 1 if all is ok and 0 in case of incomplete reply */ static gint -check_smtp_ustream_reply (f_str_t *in, gchar success_code) +check_smtp_ustream_reply (rspamd_fstring_t *in, gchar success_code) { gchar *p; @@ -368,7 +368,7 @@ smtp_upstream_write_list (GList *args, gchar *buf, size_t buflen) { GList *cur = args; size_t r = 0; - f_str_t *arg; + rspamd_fstring_t *arg; while (cur && r < buflen - 3) { arg = cur->data; @@ -401,7 +401,7 @@ smtp_upstream_write_socket (void *arg) } gboolean -smtp_upstream_read_socket (f_str_t * in, void *arg) +smtp_upstream_read_socket (rspamd_fstring_t * in, void *arg) { struct smtp_session *session = arg; gchar outbuf[BUFSIZ]; diff --git a/src/libmime/smtp_proto.h b/src/libmime/smtp_proto.h index a5c865889..a0f2ec5c2 100644 --- a/src/libmime/smtp_proto.h +++ b/src/libmime/smtp_proto.h @@ -53,7 +53,7 @@ gchar * make_smtp_error (rspamd_mempool_t *pool, * Parse a single SMTP command */ gboolean parse_smtp_command (struct smtp_session *session, - f_str_t *line, + rspamd_fstring_t *line, struct smtp_command **cmd); /* @@ -79,7 +79,7 @@ gboolean parse_smtp_rcpt (struct smtp_session *session, /* * Read a line from SMTP upstream */ -gboolean smtp_upstream_read_socket (f_str_t * in, void *arg); +gboolean smtp_upstream_read_socket (rspamd_fstring_t * in, void *arg); /* * Write to SMTP upstream diff --git a/src/libserver/binlog.c b/src/libserver/binlog.c index 6565d41e1..5eeae7ac2 100644 --- a/src/libserver/binlog.c +++ b/src/libserver/binlog.c @@ -45,7 +45,7 @@ binlog_write_header (struct rspamd_binlog *log) }; header.create_time = time (NULL); - lock_file (log->fd, FALSE); + rspamd_file_lock (log->fd, FALSE); if (write (log->fd, &header, sizeof (struct rspamd_binlog_header)) == -1) { msg_warn ("cannot write file %s, error %d, %s", @@ -72,7 +72,7 @@ binlog_write_header (struct rspamd_binlog *log) log->filename, errno, strerror (errno)); - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); return FALSE; } @@ -86,11 +86,11 @@ binlog_write_header (struct rspamd_binlog *log) log->filename, errno, strerror (errno)); - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); return FALSE; } - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); return TRUE; } @@ -278,12 +278,12 @@ write_binlog_tree (struct rspamd_binlog *log, GTree *nodes) off_t seek; struct rspamd_binlog_index *idx; - lock_file (log->fd, FALSE); + rspamd_file_lock (log->fd, FALSE); log->cur_seq++; /* Seek to end of file */ if ((seek = lseek (log->fd, 0, SEEK_END)) == -1) { - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); msg_info ("cannot seek in file: %s, error: %s", log->filename, strerror (errno)); @@ -301,7 +301,7 @@ write_binlog_tree (struct rspamd_binlog *log, GTree *nodes) idx->len = g_tree_nnodes (nodes) * sizeof (struct rspamd_binlog_element); if (lseek (log->fd, log->metaindex->indexes[log->metaindex->last_index], SEEK_SET) == -1) { - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); msg_info ( "cannot seek in file: %s, error: %s, seek: %L, op: insert index", log->filename, @@ -312,14 +312,14 @@ write_binlog_tree (struct rspamd_binlog *log, GTree *nodes) log->cur_idx->last_index++; if (write (log->fd, log->cur_idx, sizeof (struct rspamd_index_block)) == -1) { - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); msg_info ("cannot write index to file: %s, error: %s", log->filename, strerror (errno)); return FALSE; } - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); return TRUE; } @@ -329,12 +329,12 @@ create_new_metaindex_block (struct rspamd_binlog *log) { off_t seek; - lock_file (log->fd, FALSE); + rspamd_file_lock (log->fd, FALSE); log->metaindex->last_index++; /* Seek to end of file */ if ((seek = lseek (log->fd, 0, SEEK_END)) == -1) { - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); msg_info ("cannot seek in file: %s, error: %s", log->filename, strerror (errno)); @@ -342,7 +342,7 @@ create_new_metaindex_block (struct rspamd_binlog *log) } if (write (log->fd, log->cur_idx, sizeof (struct rspamd_index_block)) == -1) { - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); g_free (log->cur_idx); msg_warn ("cannot write file %s, error %d, %s", log->filename, @@ -354,7 +354,7 @@ create_new_metaindex_block (struct rspamd_binlog *log) log->metaindex->indexes[log->metaindex->last_index] = seek; /* Overwrite all metaindexes */ if (lseek (log->fd, sizeof (struct rspamd_binlog_header), SEEK_SET) == -1) { - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); msg_info ("cannot seek in file: %s, error: %s", log->filename, strerror (errno)); @@ -362,14 +362,14 @@ create_new_metaindex_block (struct rspamd_binlog *log) } if (write (log->fd, log->metaindex, sizeof (struct rspamd_binlog_metaindex)) == -1) { - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); msg_info ("cannot write metaindex in file: %s, error: %s", log->filename, strerror (errno)); return FALSE; } bzero (log->cur_idx, sizeof (struct rspamd_index_block)); - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); return TRUE; } @@ -393,7 +393,7 @@ rotate_binlog (struct rspamd_binlog *log) gchar *backup_name; struct stat st; - lock_file (log->fd, FALSE); + rspamd_file_lock (log->fd, FALSE); /* Unmap mapped fragments */ if (log->metaindex) { @@ -416,7 +416,7 @@ rotate_binlog (struct rspamd_binlog *log) g_free (backup_name); /* XXX: maybe race condition here */ - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); close (log->fd); return binlog_create (log); @@ -519,12 +519,12 @@ binlog_sync (struct rspamd_binlog *log, } else if (metaindex_num != log->metaindex->last_index) { /* Need to remap index block */ - lock_file (log->fd, FALSE); + rspamd_file_lock (log->fd, FALSE); idxb = g_malloc (sizeof (struct rspamd_index_block)); idx_mapped = TRUE; if (lseek (log->fd, log->metaindex->indexes[metaindex_num], SEEK_SET) == -1) { - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); msg_warn ("cannot seek file %s, error %d, %s", log->filename, errno, @@ -535,7 +535,7 @@ binlog_sync (struct rspamd_binlog *log, if ((read (log->fd, idxb, sizeof (struct rspamd_index_block))) != sizeof (struct rspamd_index_block)) { - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); msg_warn ("cannot read index from file %s, error %d, %s", log->filename, errno, @@ -543,7 +543,7 @@ binlog_sync (struct rspamd_binlog *log, res = FALSE; goto end; } - unlock_file (log->fd, FALSE); + rspamd_file_unlock (log->fd, FALSE); } else { idxb = log->cur_idx; diff --git a/src/libserver/buffer.c b/src/libserver/buffer.c index 5fbf91578..1cb09df46 100644 --- a/src/libserver/buffer.c +++ b/src/libserver/buffer.c @@ -314,7 +314,7 @@ read_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean skip_read) { ssize_t r; GError *err = NULL; - f_str_t res; + rspamd_fstring_t res; gchar *c, *b; gchar *end; size_t len; @@ -329,10 +329,10 @@ read_buffers (gint fd, rspamd_io_dispatcher_t * d, gboolean skip_read) 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); + d->in_buf->data = rspamd_fstralloc_tmp (d->pool, d->default_buf_size); } else { - d->in_buf->data = fstralloc_tmp (d->pool, d->nchars + 1); + d->in_buf->data = rspamd_fstralloc_tmp (d->pool, d->nchars + 1); } d->in_buf->pos = d->in_buf->data->begin; } @@ -656,7 +656,7 @@ rspamd_set_dispatcher_policy (rspamd_io_dispatcher_t * d, enum io_policy policy, size_t nchars) { - f_str_t *tmp; + rspamd_fstring_t *tmp; gint t; if (d->policy != policy || nchars != d->nchars) { @@ -665,7 +665,7 @@ rspamd_set_dispatcher_policy (rspamd_io_dispatcher_t * d, /* Resize input buffer if needed */ if (policy == BUFFER_CHARACTER && nchars != 0) { if (d->in_buf && d->in_buf->data->size < nchars) { - tmp = fstralloc_tmp (d->pool, d->nchars + 1); + tmp = rspamd_fstralloc_tmp (d->pool, d->nchars + 1); memcpy (tmp->begin, d->in_buf->data->begin, d->in_buf->data->len); t = d->in_buf->pos - d->in_buf->data->begin; @@ -676,7 +676,7 @@ rspamd_set_dispatcher_policy (rspamd_io_dispatcher_t * d, } else if (policy == BUFFER_LINE || policy == BUFFER_ANY) { if (d->in_buf && d->nchars < d->default_buf_size) { - tmp = fstralloc_tmp (d->pool, d->default_buf_size); + tmp = rspamd_fstralloc_tmp (d->pool, d->default_buf_size); memcpy (tmp->begin, d->in_buf->data->begin, d->in_buf->data->len); t = d->in_buf->pos - d->in_buf->data->begin; diff --git a/src/libserver/buffer.h b/src/libserver/buffer.h index 6795ff41d..7fa799573 100644 --- a/src/libserver/buffer.h +++ b/src/libserver/buffer.h @@ -10,7 +10,7 @@ #include "mem_pool.h" #include "fstring.h" -typedef gboolean (*dispatcher_read_callback_t)(f_str_t *in, void *user_data); +typedef gboolean (*dispatcher_read_callback_t)(rspamd_fstring_t *in, void *user_data); typedef gboolean (*dispatcher_write_callback_t)(void *user_data); typedef void (*dispatcher_err_callback_t)(GError *err, void *user_data); @@ -27,7 +27,7 @@ enum io_policy { * Buffer structure */ typedef struct rspamd_buffer_s { - f_str_t *data; /**< buffer logic */ + rspamd_fstring_t *data; /**< buffer logic */ gchar *pos; /**< current position */ } rspamd_buffer_t; diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index cd1aa0f0f..ded0e0eb9 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -145,7 +145,7 @@ rspamd_config_free (struct rspamd_config *cfg) GList *cur; struct rspamd_symbols_group *gr; - remove_all_maps (cfg); + rspamd_map_remove_all (cfg); ucl_obj_unref (cfg->rcl_obj); g_hash_table_remove_all (cfg->metrics); g_hash_table_unref (cfg->metrics); @@ -568,7 +568,7 @@ rspamd_include_map_handler (const guchar *data, gsize len, cbdata->cfg = cfg; *pcbdata = cbdata; - return add_map (cfg, + return rspamd_map_add (cfg, map_line, "ucl include", rspamd_ucl_read_cb, diff --git a/src/libserver/dynamic_cfg.c b/src/libserver/dynamic_cfg.c index 01bfb83b5..c9e93a583 100644 --- a/src/libserver/dynamic_cfg.c +++ b/src/libserver/dynamic_cfg.c @@ -264,7 +264,7 @@ init_dynamic_config (struct rspamd_config *cfg) jb->buf = NULL; jb->cfg = cfg; *pjb = jb; - if (!add_map (cfg, cfg->dynamic_conf, "Dynamic configuration map", + if (!rspamd_map_add (cfg, cfg->dynamic_conf, "Dynamic configuration map", json_config_read_cb, json_config_fin_cb, (void **)pjb)) { msg_err ("cannot add map for configuration %s", cfg->dynamic_conf); } diff --git a/src/libserver/statfile.c b/src/libserver/statfile.c index 031c45cf5..066671a95 100644 --- a/src/libserver/statfile.c +++ b/src/libserver/statfile.c @@ -86,7 +86,7 @@ convert_statfile_10 (stat_file_t * file) g_free (backup_name); /* XXX: maybe race condition here */ - unlock_file (file->fd, FALSE); + rspamd_file_unlock (file->fd, FALSE); close (file->fd); if ((file->fd = open (file->filename, O_RDWR | O_TRUNC | O_CREAT, @@ -97,7 +97,7 @@ convert_statfile_10 (stat_file_t * file) strerror (errno)); return FALSE; } - lock_file (file->fd, FALSE); + rspamd_file_lock (file->fd, FALSE); /* Now make new header and copy it to new file */ if (write (file->fd, &header, sizeof (header)) == -1) { msg_info ("cannot write to file %s, error %d, %s", @@ -411,15 +411,15 @@ statfile_pool_open (statfile_pool_t * pool, } } /* Acquire lock for this operation */ - lock_file (new_file->fd, FALSE); + rspamd_file_lock (new_file->fd, FALSE); if (statfile_pool_check (new_file) == -1) { pool->opened--; rspamd_mempool_unlock_mutex (pool->lock); - unlock_file (new_file->fd, FALSE); + rspamd_file_unlock (new_file->fd, FALSE); munmap (new_file->map, st.st_size); return NULL; } - unlock_file (new_file->fd, FALSE); + rspamd_file_unlock (new_file->fd, FALSE); new_file->open_time = time (NULL); new_file->access_time = new_file->open_time; diff --git a/src/libserver/statfile_sync.c b/src/libserver/statfile_sync.c index 262176880..23ed96e12 100644 --- a/src/libserver/statfile_sync.c +++ b/src/libserver/statfile_sync.c @@ -85,7 +85,7 @@ log_next_sync (const gchar *symbol, time_t delay) } static gboolean -parse_revision_line (struct rspamd_sync_ctx *ctx, f_str_t *in) +parse_revision_line (struct rspamd_sync_ctx *ctx, rspamd_fstring_t *in) { guint i, state = 0; gchar *p, *c, numbuf[sizeof("18446744073709551615")]; @@ -151,7 +151,7 @@ parse_revision_line (struct rspamd_sync_ctx *ctx, f_str_t *in) } static gboolean -read_blocks (struct rspamd_sync_ctx *ctx, f_str_t *in) +read_blocks (struct rspamd_sync_ctx *ctx, rspamd_fstring_t *in) { struct rspamd_binlog_element *elt; guint i; @@ -173,7 +173,7 @@ read_blocks (struct rspamd_sync_ctx *ctx, f_str_t *in) } static gboolean -sync_read (f_str_t * in, void *arg) +sync_read (rspamd_fstring_t * in, void *arg) { struct rspamd_sync_ctx *ctx = arg; gchar buf[256]; @@ -290,7 +290,7 @@ sync_timer_callback (gint fd, short what, void *ud) } if ((ctx->sock = - make_universal_socket (ctx->st->binlog->master_addr, + rspamd_socket (ctx->st->binlog->master_addr, ctx->st->binlog->master_port, SOCK_STREAM, TRUE, FALSE, TRUE)) == -1) { msg_info ("cannot connect to %s", ctx->st->binlog->master_addr); diff --git a/src/libserver/task.c b/src/libserver/task.c index 2cec9cb3a..b6a910a91 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -90,11 +90,11 @@ rspamd_task_new (struct rspamd_worker *worker) rspamd_mempool_add_destructor (new_task->task_pool, (rspamd_mempool_destruct_t) g_hash_table_unref, new_task->raw_headers); - new_task->emails = g_tree_new (compare_email_func); + new_task->emails = g_tree_new (rspamd_emails_cmp); 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); + new_task->urls = g_tree_new (rspamd_urls_cmp); rspamd_mempool_add_destructor (new_task->task_pool, (rspamd_mempool_destruct_t) g_tree_destroy, new_task->urls); diff --git a/src/libserver/url.c b/src/libserver/url.c index 389fae938..3e4ccc827 100644 --- a/src/libserver/url.c +++ b/src/libserver/url.c @@ -1413,8 +1413,8 @@ parse_uri (struct uri *uri, gchar *uristring, rspamd_mempool_t * pool) uri->post = prefix_end + 1; } - convert_to_lowercase (uri->string, uri->protocollen); - convert_to_lowercase (uri->host, uri->hostlen); + rspamd_str_lc (uri->string, uri->protocollen); + rspamd_str_lc (uri->host, uri->hostlen); /* Decode %HH sequences in host name. This is important not so much to support %HH sequences in host names (which other browser don't), but to support binary characters (which will have been diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c index 17c5ba872..94ad5bd6c 100644 --- a/src/libserver/worker_util.c +++ b/src/libserver/worker_util.c @@ -82,7 +82,7 @@ rspamd_worker_usr1_handler (gint fd, short what, void *arg) struct rspamd_worker_signal_handler *sigh = (struct rspamd_worker_signal_handler *)arg; - reopen_log (sigh->worker->srv->logger); + rspamd_log_reopen (sigh->worker->srv->logger); if (sigh->post_handler) { sigh->post_handler (sigh->handler_data); diff --git a/src/libutil/addr.c b/src/libutil/addr.c index 4234561b0..bf9fc5d8a 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -107,7 +107,7 @@ rspamd_accept_from_socket (gint sock, rspamd_inet_addr_t *addr) addr->slen = len; addr->af = addr->addr.sa.sa_family; - if (make_socket_nonblocking (nfd) < 0) { + if (rspamd_socket_nonblocking (nfd) < 0) { goto out; } diff --git a/src/libutil/aio_event.c b/src/libutil/aio_event.c index 99b8845d5..ed257bab0 100644 --- a/src/libutil/aio_event.c +++ b/src/libutil/aio_event.c @@ -273,7 +273,7 @@ rspamd_aio_init (struct event_base *base) } else { /* Set this socket non-blocking */ - if (make_socket_nonblocking (new->event_fd) == -1) { + if (rspamd_socket_nonblocking (new->event_fd) == -1) { msg_err ("non blocking for eventfd failed: %s", strerror (errno)); close (new->event_fd); } diff --git a/src/libutil/diff.c b/src/libutil/diff.c index cee175ceb..135c74624 100644 --- a/src/libutil/diff.c +++ b/src/libutil/diff.c @@ -336,7 +336,7 @@ rspamd_diff (const void *a, gint aoff, gint n, const void *b, gint boff, gint m, } static guint32 -compare_diff_distance_unnormalized (f_str_t *s1, f_str_t *s2) +compare_diff_distance_unnormalized (rspamd_fstring_t *s1, rspamd_fstring_t *s2) { GArray *ses; struct diff_edit *e; @@ -365,7 +365,7 @@ compare_diff_distance_unnormalized (f_str_t *s1, f_str_t *s2) } guint32 -compare_diff_distance (f_str_t *s1, f_str_t *s2) +rspamd_diff_distance (rspamd_fstring_t *s1, rspamd_fstring_t *s2) { return 100 - @@ -376,11 +376,11 @@ compare_diff_distance (f_str_t *s1, f_str_t *s2) guint32 -compare_diff_distance_normalized (f_str_t *s1, f_str_t *s2) +rspamd_diff_distance_normalized (rspamd_fstring_t *s1, rspamd_fstring_t *s2) { gchar b1[BUFSIZ], b2[BUFSIZ], *t, *h, *p1, *p2; gsize r1, r2; - f_str_t t1, t2; + rspamd_fstring_t t1, t2; guint32 cur_diff = 0; r1 = s1->len; diff --git a/src/libutil/diff.h b/src/libutil/diff.h index 7caa35dd8..d20ac8e1f 100644 --- a/src/libutil/diff.h +++ b/src/libutil/diff.h @@ -69,13 +69,13 @@ gint rspamd_diff (const void *a, * Calculate distance between two strings (in percentage) using diff algorithm. * @return 100 in case of identical strings and 0 in case of totally different strings. */ -guint32 compare_diff_distance (f_str_t *s1, f_str_t *s2); +guint32 rspamd_diff_distance (rspamd_fstring_t *s1, rspamd_fstring_t *s2); /* * Calculate distance between two strings (in percentage) using diff algorithm. Strings are normalized before: * all spaces are removed and all characters are lowercased. * @return 100 in case of identical strings and 0 in case of totally different strings. */ -guint32 compare_diff_distance_normalized (f_str_t *s1, f_str_t *s2); +guint32 rspamd_diff_distance_normalized (rspamd_fstring_t *s1, rspamd_fstring_t *s2); #endif /* DIFF_H_ */ diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c index a83bbd662..e45b0ded5 100644 --- a/src/libutil/fstring.c +++ b/src/libutil/fstring.c @@ -28,7 +28,7 @@ * Search first occurence of character in string */ ssize_t -fstrchr (f_str_t * src, gchar c) +rspamd_fstrchr (rspamd_fstring_t * src, gchar c) { register size_t cur = 0; @@ -46,7 +46,7 @@ fstrchr (f_str_t * src, gchar c) * Search last occurence of character in string */ ssize_t -fstrrchr (f_str_t * src, gchar c) +rspamd_fstrrchr (rspamd_fstring_t * src, gchar c) { register ssize_t cur = src->len; @@ -64,7 +64,7 @@ fstrrchr (f_str_t * src, gchar c) * Search for pattern in orig */ ssize_t -fstrstr (f_str_t * orig, f_str_t * pattern) +rspamd_fstrstr (rspamd_fstring_t * orig, rspamd_fstring_t * pattern) { register size_t cur = 0, pcur = 0; @@ -74,6 +74,7 @@ fstrstr (f_str_t * orig, f_str_t * pattern) while (cur < orig->len) { if (*(orig->begin + cur) == *pattern->begin) { + pcur = 0; while (cur < orig->len && pcur < pattern->len) { if (*(orig->begin + cur) != *(pattern->begin + pcur)) { pcur = 0; @@ -95,7 +96,7 @@ fstrstr (f_str_t * orig, f_str_t * pattern) * Search for pattern in orig ignoring case */ ssize_t -fstrstri (f_str_t * orig, f_str_t * pattern) +rspamd_fstrstri (rspamd_fstring_t * orig, rspamd_fstring_t * pattern) { register size_t cur = 0, pcur = 0; @@ -106,6 +107,7 @@ fstrstri (f_str_t * orig, f_str_t * pattern) while (cur < orig->len) { if (g_ascii_tolower (*(orig->begin + cur)) == g_ascii_tolower (*pattern->begin)) { + pcur = 0; while (cur < orig->len && pcur < pattern->len) { if (g_ascii_tolower (*(orig->begin + cur)) != g_ascii_tolower (*(pattern->begin + pcur))) { @@ -133,7 +135,7 @@ fstrstri (f_str_t * orig, f_str_t * pattern) * 0 - last word extracted */ gint -fstrtok (f_str_t * text, const gchar *sep, f_tok_t * state) +rspamd_fstrtok (rspamd_fstring_t * text, const gchar *sep, rspamd_fstring_token_t * state) { register size_t cur; const gchar *csep = sep; @@ -170,7 +172,7 @@ fstrtok (f_str_t * text, const gchar *sep, f_tok_t * state) * Copy one string into other */ size_t -fstrcpy (f_str_t * dest, f_str_t * src) +rspamd_fstrcpy (rspamd_fstring_t * dest, rspamd_fstring_t * src) { register size_t cur = 0; @@ -190,7 +192,7 @@ fstrcpy (f_str_t * dest, f_str_t * src) * Concatenate two strings */ size_t -fstrcat (f_str_t * dest, f_str_t * src) +rspamd_fstrcat (rspamd_fstring_t * dest, rspamd_fstring_t * src) { register size_t cur = 0; gchar *p = dest->begin + dest->len; @@ -215,7 +217,7 @@ fstrcat (f_str_t * dest, f_str_t * src) * Make copy of string to 0-terminated string */ gchar * -fstrcstr (f_str_t * str, rspamd_mempool_t * pool) +rspamd_fstr_c_str (rspamd_fstring_t * str, rspamd_mempool_t * pool) { gchar *res; res = rspamd_mempool_alloc (pool, str->len + 1); @@ -231,7 +233,7 @@ fstrcstr (f_str_t * str, rspamd_mempool_t * pool) * Push one character to fstr */ gint -fstrpush (f_str_t * dest, gchar c) +rspamd_fstrappend_c (rspamd_fstring_t * dest, gchar c) { if (dest->size < dest->len) { /* Need to reallocate string */ @@ -247,7 +249,7 @@ fstrpush (f_str_t * dest, gchar c) * Push one character to fstr */ gint -fstrpush_unichar (f_str_t * dest, gunichar c) +rspamd_fstrappend_u (rspamd_fstring_t * dest, gunichar c) { int l; if (dest->size < dest->len) { @@ -263,10 +265,10 @@ fstrpush_unichar (f_str_t * dest, gunichar c) /* * Allocate memory for f_str_t */ -f_str_t * -fstralloc (rspamd_mempool_t * pool, size_t len) +rspamd_fstring_t * +rspamd_fstralloc (rspamd_mempool_t * pool, size_t len) { - f_str_t *res = rspamd_mempool_alloc (pool, sizeof (f_str_t)); + rspamd_fstring_t *res = rspamd_mempool_alloc (pool, sizeof (rspamd_fstring_t)); res->begin = rspamd_mempool_alloc (pool, len); @@ -278,10 +280,10 @@ fstralloc (rspamd_mempool_t * pool, size_t len) /* * Allocate memory for f_str_t from temporary pool */ -f_str_t * -fstralloc_tmp (rspamd_mempool_t * pool, size_t len) +rspamd_fstring_t * +rspamd_fstralloc_tmp (rspamd_mempool_t * pool, size_t len) { - f_str_t *res = rspamd_mempool_alloc_tmp (pool, sizeof (f_str_t)); + rspamd_fstring_t *res = rspamd_mempool_alloc_tmp (pool, sizeof (rspamd_fstring_t)); res->begin = rspamd_mempool_alloc_tmp (pool, len); @@ -293,20 +295,20 @@ fstralloc_tmp (rspamd_mempool_t * pool, size_t len) /* * Truncate string to its len */ -f_str_t * -fstrtruncate (rspamd_mempool_t * pool, f_str_t * orig) +rspamd_fstring_t * +rspamd_fstrtruncate (rspamd_mempool_t * pool, rspamd_fstring_t * orig) { - f_str_t *res; + rspamd_fstring_t *res; if (orig == NULL || orig->len == 0 || orig->size <= orig->len) { return orig; } - res = fstralloc (pool, orig->len); + res = rspamd_fstralloc (pool, orig->len); if (res == NULL) { return NULL; } - fstrcpy (res, orig); + rspamd_fstrcpy (res, orig); return res; } @@ -314,20 +316,20 @@ fstrtruncate (rspamd_mempool_t * pool, f_str_t * orig) /* * Enlarge string to new size */ -f_str_t * -fstrgrow (rspamd_mempool_t * pool, f_str_t * orig, size_t newlen) +rspamd_fstring_t * +rspamd_fstrgrow (rspamd_mempool_t * pool, rspamd_fstring_t * orig, size_t newlen) { - f_str_t *res; + rspamd_fstring_t *res; if (orig == NULL || orig->len == 0 || orig->size >= newlen) { return orig; } - res = fstralloc (pool, newlen); + res = rspamd_fstralloc (pool, newlen); if (res == NULL) { return NULL; } - fstrcpy (res, orig); + rspamd_fstrcpy (res, orig); return res; } @@ -364,7 +366,7 @@ fstrhash_c (gchar c, guint32 hval) * Return hash value for a string */ guint32 -fstrhash (f_str_t * str) +rspamd_fstrhash (rspamd_fstring_t * str) { size_t i; guint32 hval; @@ -385,7 +387,7 @@ fstrhash (f_str_t * str) * Return hash value for a string */ guint32 -fstrhash_lowercase (f_str_t * str, gboolean is_utf) +rspamd_fstrhash_lc (rspamd_fstring_t * str, gboolean is_utf) { gsize i; guint32 j, hval; @@ -401,7 +403,7 @@ fstrhash_lowercase (f_str_t * str, gboolean is_utf) if (is_utf) { while (end < str->begin + str->len) { if (!g_utf8_validate (p, str->len, &end)) { - return fstrhash_lowercase (str, FALSE); + return rspamd_fstrhash_lc (str, FALSE); } while (p < end) { uc = g_unichar_tolower (g_utf8_get_char (p)); @@ -427,7 +429,7 @@ fstrhash_lowercase (f_str_t * str, gboolean is_utf) } void -fstrstrip (f_str_t * str) +rspamd_fstrstrip (rspamd_fstring_t * str) { gchar *p = str->begin; guint r = 0; diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h index 3cba00592..3dbc2233b 100644 --- a/src/libutil/fstring.h +++ b/src/libutil/fstring.h @@ -15,84 +15,84 @@ typedef struct f_str_s { gchar *begin; size_t len; size_t size; -} f_str_t; +} rspamd_fstring_t; typedef struct f_str_buf_s { - f_str_t *buf; + rspamd_fstring_t *buf; gchar *pos; size_t free; -} f_str_buf_t; +} rspamd_fstring_buf_t; typedef struct f_tok_s { - f_str_t word; + rspamd_fstring_t word; size_t pos; -} f_tok_t; +} rspamd_fstring_token_t; /* * Search first occurence of character in string */ -ssize_t fstrchr (f_str_t *src, gchar c); +ssize_t rspamd_fstrchr (rspamd_fstring_t *src, gchar c); /* * Search last occurence of character in string */ -ssize_t fstrrchr (f_str_t *src, gchar c); +ssize_t rspamd_fstrrchr (rspamd_fstring_t *src, gchar c); /* * Search for pattern in orig */ -ssize_t fstrstr (f_str_t *orig, f_str_t *pattern); +ssize_t rspamd_fstrstr (rspamd_fstring_t *orig, rspamd_fstring_t *pattern); /* * Search for pattern in orig ignoring case */ -ssize_t fstrstri (f_str_t *orig, f_str_t *pattern); +ssize_t rspamd_fstrstri (rspamd_fstring_t *orig, rspamd_fstring_t *pattern); /* * Split string by tokens * word contains parsed word */ -gint fstrtok (f_str_t *text, const gchar *sep, f_tok_t *state); +gint rspamd_fstrtok (rspamd_fstring_t *text, const gchar *sep, rspamd_fstring_token_t *state); /* * Copy one string into other */ -size_t fstrcpy (f_str_t *dest, f_str_t *src); +size_t rspamd_fstrcpy (rspamd_fstring_t *dest, rspamd_fstring_t *src); /* * Concatenate two strings */ -size_t fstrcat (f_str_t *dest, f_str_t *src); +size_t rspamd_fstrcat (rspamd_fstring_t *dest, rspamd_fstring_t *src); /* * Push one character to fstr */ -gint fstrpush (f_str_t *dest, gchar c); +gint rspamd_fstrappend_c (rspamd_fstring_t *dest, gchar c); /* * Push one character to fstr */ -gint fstrpush_unichar (f_str_t *dest, gunichar c); +gint rspamd_fstrappend_u (rspamd_fstring_t *dest, gunichar c); /* * Allocate memory for f_str_t */ -f_str_t * fstralloc (rspamd_mempool_t *pool, size_t len); +rspamd_fstring_t * rspamd_fstralloc (rspamd_mempool_t *pool, size_t len); /* * Allocate memory for f_str_t from temporary pool */ -f_str_t * fstralloc_tmp (rspamd_mempool_t *pool, size_t len); +rspamd_fstring_t * rspamd_fstralloc_tmp (rspamd_mempool_t *pool, size_t len); /* * Truncate string to its len */ -f_str_t * fstrtruncate (rspamd_mempool_t *pool, f_str_t *orig); +rspamd_fstring_t * rspamd_fstrtruncate (rspamd_mempool_t *pool, rspamd_fstring_t *orig); /* * Enlarge string to new size */ -f_str_t * fstrgrow (rspamd_mempool_t *pool, f_str_t *orig, size_t newlen); +rspamd_fstring_t * rspamd_fstrgrow (rspamd_mempool_t *pool, rspamd_fstring_t *orig, size_t newlen); /* * Return specified character @@ -102,20 +102,20 @@ f_str_t * fstrgrow (rspamd_mempool_t *pool, f_str_t *orig, size_t newlen); /* * Return fast hash value for fixed string */ -guint32 fstrhash (f_str_t *str); +guint32 rspamd_fstrhash (rspamd_fstring_t *str); /* * Return fast hash value for fixed string converted to lowercase */ -guint32 fstrhash_lowercase (f_str_t *str, gboolean is_utf); +guint32 rspamd_fstrhash_lc (rspamd_fstring_t *str, gboolean is_utf); /* * Make copy of string to 0-terminated string */ -gchar * fstrcstr (f_str_t *str, rspamd_mempool_t *pool); +gchar * rspamd_fstr_c_str (rspamd_fstring_t *str, rspamd_mempool_t *pool); /* * Strip fstr string from space symbols */ -void fstrstrip (f_str_t *str); +void rspamd_fstrstrip (rspamd_fstring_t *str); #endif diff --git a/src/libutil/fuzzy.c b/src/libutil/fuzzy.c index a01377f24..83cb9cd29 100644 --- a/src/libutil/fuzzy.c +++ b/src/libutil/fuzzy.c @@ -98,7 +98,7 @@ fuzzy_blocksize (guint32 len) /* Update hash with new symbol */ static void -fuzzy_update (fuzzy_hash_t * h, guint c) +fuzzy_update (rspamd_fuzzy_t * h, guint c) { h->rh = fuzzy_roll_hash (c); h->h = fuzzy_fnv_hash (c, h->h); @@ -113,7 +113,7 @@ fuzzy_update (fuzzy_hash_t * h, guint c) } static void -fuzzy_update2 (fuzzy_hash_t * h1, fuzzy_hash_t *h2, guint c) +fuzzy_update2 (rspamd_fuzzy_t * h1, rspamd_fuzzy_t *h2, guint c) { h1->rh = fuzzy_roll_hash (c); h1->h = fuzzy_fnv_hash (c, h1->h); @@ -142,7 +142,7 @@ fuzzy_update2 (fuzzy_hash_t * h1, fuzzy_hash_t *h2, guint c) * Replace cost is normally 1, and 2 with nonzero xcost. */ guint32 -lev_distance (gchar *s1, gint len1, gchar *s2, gint len2) +rspamd_levinstein_distance (gchar *s1, gint len1, gchar *s2, gint len2) { gint i; gint *row; /* we only need to keep one row of costs */ @@ -255,15 +255,15 @@ lev_distance (gchar *s1, gint len1, gchar *s2, gint len2) } /* Calculate fuzzy hash for specified string */ -fuzzy_hash_t * -fuzzy_init (f_str_t * in, rspamd_mempool_t * pool) +rspamd_fuzzy_t * +rspamd_fuzzy_init (rspamd_fstring_t * in, rspamd_mempool_t * pool) { - fuzzy_hash_t *new; + rspamd_fuzzy_t *new; guint i, repeats = 0; gchar *c = in->begin, last = '\0'; gsize real_len = 0; - new = rspamd_mempool_alloc0 (pool, sizeof (fuzzy_hash_t)); + new = rspamd_mempool_alloc0 (pool, sizeof (rspamd_fuzzy_t)); bzero (&rs, sizeof (rs)); for (i = 0; i < in->len; i++) { if (*c == last) { @@ -304,23 +304,23 @@ fuzzy_init (f_str_t * in, rspamd_mempool_t * pool) return new; } -fuzzy_hash_t * -fuzzy_init_byte_array (GByteArray * in, rspamd_mempool_t * pool) +rspamd_fuzzy_t * +rspamd_fuzzy_from_byte_array (GByteArray * in, rspamd_mempool_t * pool) { - f_str_t f; + rspamd_fstring_t f; f.begin = (gchar *)in->data; f.len = in->len; - return fuzzy_init (&f, pool); + return rspamd_fuzzy_init (&f, pool); } void -fuzzy_init_part (struct mime_text_part *part, +rspamd_fuzzy_from_text_part (struct mime_text_part *part, rspamd_mempool_t *pool, gsize max_diff) { - fuzzy_hash_t *new, *new2; + rspamd_fuzzy_t *new, *new2; gchar *c, *end, *begin, *p; gsize real_len = 0, len = part->content->len; GList *cur_offset; @@ -335,8 +335,8 @@ fuzzy_init_part (struct mime_text_part *part, begin = (gchar *)part->content->data; c = begin; - new = rspamd_mempool_alloc0 (pool, sizeof (fuzzy_hash_t)); - new2 = rspamd_mempool_alloc0 (pool, sizeof (fuzzy_hash_t)); + new = rspamd_mempool_alloc0 (pool, sizeof (rspamd_fuzzy_t)); + new2 = rspamd_mempool_alloc0 (pool, sizeof (rspamd_fuzzy_t)); bzero (&rs, sizeof (rs)); end = c + len; @@ -383,7 +383,7 @@ fuzzy_init_part (struct mime_text_part *part, write_diff = real_len > 0 && real_len < max_diff; if (write_diff) { - part->diff_str = fstralloc (pool, real_len + 1); + part->diff_str = rspamd_fstralloc (pool, real_len + 1); } else { part->diff_str = NULL; @@ -415,7 +415,7 @@ fuzzy_init_part (struct mime_text_part *part, if (g_unichar_isalnum (uc)) { fuzzy_update2 (new, new2, uc); if (write_diff) { - fstrpush_unichar (part->diff_str, uc); + rspamd_fstrappend_u (part->diff_str, uc); } } c = g_utf8_next_char (c); @@ -435,7 +435,7 @@ fuzzy_init_part (struct mime_text_part *part, if (!g_ascii_isspace (*c) && !g_ascii_ispunct (*c)) { fuzzy_update2 (new, new2, *c); if (write_diff) { - fstrpush (part->diff_str, *c); + rspamd_fstrappend_c (part->diff_str, *c); } } c++; @@ -457,7 +457,7 @@ fuzzy_init_part (struct mime_text_part *part, /* Compare score of difference between two hashes 0 - different hashes, 100 - identical hashes */ gint -fuzzy_compare_hashes (fuzzy_hash_t * h1, fuzzy_hash_t * h2) +rspamd_fuzzy_compare (rspamd_fuzzy_t * h1, rspamd_fuzzy_t * h2) { gint res, l1, l2; @@ -478,24 +478,24 @@ fuzzy_compare_hashes (fuzzy_hash_t * h1, fuzzy_hash_t * h2) } } - res = lev_distance (h1->hash_pipe, l1, h2->hash_pipe, l2); + res = rspamd_levinstein_distance (h1->hash_pipe, l1, h2->hash_pipe, l2); res = 100 - (2 * res * 100) / (l1 + l2); return res; } gint -fuzzy_compare_parts (struct mime_text_part *p1, struct mime_text_part *p2) +rspamd_fuzzy_compare_parts (struct mime_text_part *p1, struct mime_text_part *p2) { if (p1->fuzzy != NULL && p2->fuzzy != NULL) { if (p1->fuzzy->block_size == p2->fuzzy->block_size) { - return fuzzy_compare_hashes (p1->fuzzy, p2->fuzzy); + return rspamd_fuzzy_compare (p1->fuzzy, p2->fuzzy); } else if (p1->double_fuzzy->block_size == p2->fuzzy->block_size) { - return fuzzy_compare_hashes (p1->double_fuzzy, p2->fuzzy); + return rspamd_fuzzy_compare (p1->double_fuzzy, p2->fuzzy); } else if (p2->double_fuzzy->block_size == p1->fuzzy->block_size) { - return fuzzy_compare_hashes (p2->double_fuzzy, p1->fuzzy); + return rspamd_fuzzy_compare (p2->double_fuzzy, p1->fuzzy); } } @@ -503,7 +503,7 @@ fuzzy_compare_parts (struct mime_text_part *p1, struct mime_text_part *p2) } gint -rspamd_fuzzy_len (fuzzy_hash_t *h) +rspamd_fuzzy_len (rspamd_fuzzy_t *h) { gint len; void *nullpos; @@ -523,7 +523,7 @@ rspamd_fuzzy_len (fuzzy_hash_t *h) guint rspamd_fuzzy_hash (gconstpointer key) { - fuzzy_hash_t *fh = (fuzzy_hash_t *)key; + rspamd_fuzzy_t *fh = (rspamd_fuzzy_t *)key; void *st; st = XXH32_init (0xdeadbeef); @@ -536,8 +536,8 @@ rspamd_fuzzy_hash (gconstpointer key) gboolean rspamd_fuzzy_equal (gconstpointer v1, gconstpointer v2) { - fuzzy_hash_t *fh1= (fuzzy_hash_t *)v1, - *fh2 = (fuzzy_hash_t *)v2; + rspamd_fuzzy_t *fh1= (rspamd_fuzzy_t *)v1, + *fh2 = (rspamd_fuzzy_t *)v2; if (fh1->block_size == fh2->block_size) { gint l1 = rspamd_fuzzy_len (fh1), diff --git a/src/libutil/fuzzy.h b/src/libutil/fuzzy.h index 73bddad79..813599c6b 100644 --- a/src/libutil/fuzzy.h +++ b/src/libutil/fuzzy.h @@ -18,7 +18,7 @@ typedef struct fuzzy_hash_s { guint32 rh; /**< roll hash value */ guint32 h; /**< hash of block */ guint32 hi; /**< current index in hash pipe */ -} fuzzy_hash_t; +} rspamd_fuzzy_t; struct mime_text_part; @@ -28,14 +28,14 @@ struct mime_text_part; * @param pool pool object * @return fuzzy_hash object allocated in pool */ -fuzzy_hash_t * fuzzy_init (f_str_t *in, rspamd_mempool_t *pool); +rspamd_fuzzy_t * rspamd_fuzzy_init (rspamd_fstring_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, rspamd_mempool_t *pool); +rspamd_fuzzy_t * rspamd_fuzzy_from_byte_array (GByteArray *in, rspamd_mempool_t *pool); /** * Calculate fuzzy hash for specified text part @@ -44,7 +44,7 @@ fuzzy_hash_t * fuzzy_init_byte_array (GByteArray *in, rspamd_mempool_t *pool); * @param max_diff maximum text length to use diff algorithm in comparasions * @return fuzzy_hash object allocated in pool */ -void fuzzy_init_part (struct mime_text_part *part, +void rspamd_fuzzy_from_text_part (struct mime_text_part *part, rspamd_mempool_t *pool, gsize max_diff); @@ -54,23 +54,23 @@ void fuzzy_init_part (struct mime_text_part *part, * @param h2 second hash * @return result in percents 0 - different hashes, 100 - identical hashes */ -gint fuzzy_compare_hashes (fuzzy_hash_t *h1, fuzzy_hash_t *h2); +gint rspamd_fuzzy_compare (rspamd_fuzzy_t *h1, rspamd_fuzzy_t *h2); /* * Compare two text parts and return percents of difference */ -gint fuzzy_compare_parts (struct mime_text_part *p1, struct mime_text_part *p2); +gint rspamd_fuzzy_compare_parts (struct mime_text_part *p1, struct mime_text_part *p2); /* * Calculate levenstein distance between two strings. Note: this algorithm should be used * only for short texts - it runs too slow on long ones. */ -guint32 lev_distance (gchar *s1, gint len1, gchar *s2, gint len2); +guint32 rspamd_levinstein_distance (gchar *s1, gint len1, gchar *s2, gint len2); /* * Hash table utilities */ -gint rspamd_fuzzy_len (fuzzy_hash_t *h); +gint rspamd_fuzzy_len (rspamd_fuzzy_t *h); guint rspamd_fuzzy_hash (gconstpointer key); gboolean rspamd_fuzzy_equal (gconstpointer v1, gconstpointer v2); diff --git a/src/libutil/logger.c b/src/libutil/logger.c index c4c36b4f8..2cb51cbb8 100644 --- a/src/libutil/logger.c +++ b/src/libutil/logger.c @@ -119,7 +119,7 @@ direct_write_log_line (rspamd_logger_t *rspamd_log, strerror (errno)); if (errno == EIO || errno == EINTR) { /* Descriptor is somehow invalid, try to restart */ - reopen_log (rspamd_log); + rspamd_log_reopen (rspamd_log); if (write (rspamd_log->fd, errmsg, r) != -1) { /* Try again */ direct_write_log_line (rspamd_log, data, count, is_iov); @@ -160,7 +160,7 @@ rspamd_escape_log_string (gchar *str) /* Logging utility functions */ gint -open_log_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) +rspamd_log_open_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) { switch (rspamd_log->cfg->log_type) { case RSPAMD_LOG_CONSOLE: @@ -193,10 +193,10 @@ open_log_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) } void -close_log_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) +rspamd_log_close_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) { gchar tmpbuf[256]; - flush_log_buf (rspamd_log); + rspamd_log_flush (rspamd_log); switch (rspamd_log->type) { case RSPAMD_LOG_CONSOLE: @@ -247,10 +247,10 @@ close_log_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) } gint -reopen_log_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) +rspamd_log_reopen_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) { - close_log_priv (rspamd_log, uid, gid); - if (open_log_priv (rspamd_log, uid, gid) == 0) { + rspamd_log_close_priv (rspamd_log, uid, gid); + if (rspamd_log_open_priv (rspamd_log, uid, gid) == 0) { msg_info ("log file reopened"); return 0; } @@ -262,25 +262,25 @@ reopen_log_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) * Open log file or initialize other structures */ gint -open_log (rspamd_logger_t *logger) +rspamd_log_open (rspamd_logger_t *logger) { - return open_log_priv (logger, -1, -1); + return rspamd_log_open_priv (logger, -1, -1); } /** * Close log file or destroy other structures */ void -close_log (rspamd_logger_t *logger) +rspamd_log_close (rspamd_logger_t *logger) { - close_log_priv (logger, -1, -1); + rspamd_log_close_priv (logger, -1, -1); } /** * Close and open log again */ gint -reopen_log (rspamd_logger_t *logger) +rspamd_log_reopen (rspamd_logger_t *logger) { - return reopen_log_priv (logger, -1, -1); + return rspamd_log_reopen_priv (logger, -1, -1); } /* @@ -336,9 +336,9 @@ rspamd_set_logger (struct rspamd_config *cfg, radix_destroy_compressed (rspamd->logger->debug_ip); } rspamd->logger->debug_ip = radix_create_compressed (); - if (!add_map (rspamd->cfg, rspamd->cfg->debug_ip_map, + if (!rspamd_map_add (rspamd->cfg, rspamd->cfg->debug_ip_map, "IP addresses for which debug logs are enabled", - read_radix_list, fin_radix_list, + rspamd_radix_read, rspamd_radix_fin, (void **)&rspamd->logger->debug_ip)) { radix_add_generic_iplist (rspamd->cfg->debug_ip_map, &rspamd->logger->debug_ip); @@ -356,7 +356,7 @@ rspamd_set_logger (struct rspamd_config *cfg, * Used after fork() for updating structure params */ void -update_log_pid (GQuark ptype, rspamd_logger_t *rspamd_log) +rspamd_log_update_pid (GQuark ptype, rspamd_logger_t *rspamd_log) { rspamd_log->pid = getpid (); rspamd_log->process_type = ptype; @@ -366,7 +366,7 @@ update_log_pid (GQuark ptype, rspamd_logger_t *rspamd_log) * Flush logging buffer */ void -flush_log_buf (rspamd_logger_t *rspamd_log) +rspamd_log_flush (rspamd_logger_t *rspamd_log) { if (rspamd_log->is_buffered && (rspamd_log->type == RSPAMD_LOG_CONSOLE || rspamd_log->type == @@ -495,12 +495,12 @@ file_log_helper (rspamd_logger_t *rspamd_log, /* Fill buffer */ if (rspamd_log->io_buf.size < len) { /* Buffer is too small to hold this string, so write it dirrectly */ - flush_log_buf (rspamd_log); + rspamd_log_flush (rspamd_log); direct_write_log_line (rspamd_log, (void *)iov, iovcnt, TRUE); } else if (rspamd_log->io_buf.used + len >= rspamd_log->io_buf.size) { /* Buffer is full, try to write it dirrectly */ - flush_log_buf (rspamd_log); + rspamd_log_flush (rspamd_log); fill_buffer (rspamd_log, iov, iovcnt); } else { diff --git a/src/libutil/logger.h b/src/libutil/logger.h index 078180b86..4b200c83d 100644 --- a/src/libutil/logger.h +++ b/src/libutil/logger.h @@ -22,38 +22,38 @@ void rspamd_set_logger (struct rspamd_config *cfg, /** * Open log file or initialize other structures */ -gint open_log (rspamd_logger_t *logger); +gint rspamd_log_open (rspamd_logger_t *logger); /** * Close log file or destroy other structures */ -void close_log (rspamd_logger_t *logger); +void rspamd_log_close (rspamd_logger_t *logger); /** * Close and open log again */ -gint reopen_log (rspamd_logger_t *logger); +gint rspamd_log_reopen (rspamd_logger_t *logger); /** * Open log file or initialize other structures for privileged processes */ -gint open_log_priv (rspamd_logger_t *logger, uid_t uid, gid_t gid); +gint rspamd_log_open_priv (rspamd_logger_t *logger, uid_t uid, gid_t gid); /** * Close log file or destroy other structures for privileged processes */ -void close_log_priv (rspamd_logger_t *logger, uid_t uid, gid_t gid); +void rspamd_log_close_priv (rspamd_logger_t *logger, uid_t uid, gid_t gid); /** * Close and open log again for privileged processes */ -gint reopen_log_priv (rspamd_logger_t *logger, uid_t uid, gid_t gid); +gint rspamd_log_reopen_priv (rspamd_logger_t *logger, uid_t uid, gid_t gid); /** * Set log pid */ -void update_log_pid (GQuark ptype, rspamd_logger_t *logger); +void rspamd_log_update_pid (GQuark ptype, rspamd_logger_t *logger); /** * Flush log buffer for some types of logging */ -void flush_log_buf (rspamd_logger_t *logger); +void rspamd_log_flush (rspamd_logger_t *logger); /** * Log function that is compatible for glib messages */ diff --git a/src/libutil/map.c b/src/libutil/map.c index 89ab75b64..18c33e63d 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -84,7 +84,7 @@ connect_http (struct rspamd_map *map, { gint sock; - if ((sock = make_tcp_socket (data->addr, FALSE, is_async)) == -1) { + if ((sock = rspamd_socket_tcp (data->addr, FALSE, is_async)) == -1) { msg_info ("cannot connect to http server %s: %d, %s", data->host, errno, @@ -381,7 +381,7 @@ http_callback (gint fd, short what, void *ud) /* Start watching event for all maps */ void -start_map_watch (struct rspamd_config *cfg, struct event_base *ev_base) +rspamd_map_watch (struct rspamd_config *cfg, struct event_base *ev_base) { GList *cur = cfg->maps; struct rspamd_map *map; @@ -412,7 +412,7 @@ start_map_watch (struct rspamd_config *cfg, struct event_base *ev_base) } void -remove_all_maps (struct rspamd_config *cfg) +rspamd_map_remove_all (struct rspamd_config *cfg) { g_list_free (cfg->maps); cfg->maps = NULL; @@ -423,7 +423,7 @@ remove_all_maps (struct rspamd_config *cfg) } gboolean -check_map_proto (const gchar *map_line, gint *res, const gchar **pos) +rspamd_map_check_proto (const gchar *map_line, gint *res, const gchar **pos) { if (g_ascii_strncasecmp (map_line, "http://", sizeof ("http://") - 1) == 0) { @@ -453,7 +453,7 @@ check_map_proto (const gchar *map_line, gint *res, const gchar **pos) } gboolean -add_map (struct rspamd_config *cfg, +rspamd_map_add (struct rspamd_config *cfg, const gchar *map_line, const gchar *description, map_cb_t read_callback, @@ -470,7 +470,7 @@ add_map (struct rspamd_config *cfg, struct addrinfo hints, *res; /* First of all detect protocol line */ - if (!check_map_proto (map_line, (int *)&proto, &def)) { + if (!rspamd_map_check_proto (map_line, (int *)&proto, &def)) { return FALSE; } /* Constant pool */ @@ -577,7 +577,7 @@ add_map (struct rspamd_config *cfg, return FALSE; } /* Now try to connect */ - if ((s = make_tcp_socket (hdata->addr, FALSE, FALSE)) == -1) { + if ((s = rspamd_socket_tcp (hdata->addr, FALSE, FALSE)) == -1) { msg_info ("cannot connect to http server %s: %d, %s", hdata->host, errno, @@ -712,7 +712,7 @@ abstract_parse_kv_list (rspamd_mempool_t * pool, } gchar * -abstract_parse_list (rspamd_mempool_t * pool, +rspamd_parse_abstract_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data, @@ -803,7 +803,7 @@ radix_tree_insert_helper (gpointer st, gconstpointer key, gpointer value) /* Helpers */ gchar * -read_host_list (rspamd_mempool_t * pool, +rspamd_hosts_read (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) @@ -812,7 +812,7 @@ read_host_list (rspamd_mempool_t * pool, data->cur_data = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); } - return abstract_parse_list (pool, + return rspamd_parse_abstract_list (pool, chunk, len, data, @@ -820,7 +820,7 @@ read_host_list (rspamd_mempool_t * pool, } void -fin_host_list (rspamd_mempool_t * pool, struct map_cb_data *data) +rspamd_hosts_fin (rspamd_mempool_t * pool, struct map_cb_data *data) { if (data->prev_data) { g_hash_table_destroy (data->prev_data); @@ -828,7 +828,7 @@ fin_host_list (rspamd_mempool_t * pool, struct map_cb_data *data) } gchar * -read_kv_list (rspamd_mempool_t * pool, +rspamd_kv_list_read (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) @@ -845,7 +845,7 @@ read_kv_list (rspamd_mempool_t * pool, } void -fin_kv_list (rspamd_mempool_t * pool, struct map_cb_data *data) +rspamd_kv_list_fin (rspamd_mempool_t * pool, struct map_cb_data *data) { if (data->prev_data) { g_hash_table_destroy (data->prev_data); @@ -853,7 +853,7 @@ fin_kv_list (rspamd_mempool_t * pool, struct map_cb_data *data) } gchar * -read_radix_list (rspamd_mempool_t * pool, +rspamd_radix_read (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) @@ -861,7 +861,7 @@ read_radix_list (rspamd_mempool_t * pool, if (data->cur_data == NULL) { data->cur_data = radix_create_compressed (); } - return abstract_parse_list (pool, + return rspamd_parse_abstract_list (pool, chunk, len, data, @@ -869,7 +869,7 @@ read_radix_list (rspamd_mempool_t * pool, } void -fin_radix_list (rspamd_mempool_t * pool, struct map_cb_data *data) +rspamd_radix_fin (rspamd_mempool_t * pool, struct map_cb_data *data) { if (data->prev_data) { radix_destroy_compressed (data->prev_data); diff --git a/src/libutil/map.h b/src/libutil/map.h index c0f1adc2d..64421ec1b 100644 --- a/src/libutil/map.h +++ b/src/libutil/map.h @@ -61,11 +61,11 @@ struct map_cb_data { /** * Check map protocol */ -gboolean check_map_proto (const gchar *map_line, gint *res, const gchar **pos); +gboolean rspamd_map_check_proto (const gchar *map_line, gint *res, const gchar **pos); /** * Add map from line */ -gboolean add_map (struct rspamd_config *cfg, +gboolean rspamd_map_add (struct rspamd_config *cfg, const gchar *map_line, const gchar *description, map_cb_t read_callback, @@ -75,12 +75,12 @@ gboolean add_map (struct rspamd_config *cfg, /** * Start watching of maps by adding events to libevent event loop */ -void start_map_watch (struct rspamd_config *cfg, struct event_base *ev_base); +void rspamd_map_watch (struct rspamd_config *cfg, struct event_base *ev_base); /** * Remove all maps watched (remove events) */ -void remove_all_maps (struct rspamd_config *cfg); +void rspamd_map_remove_all (struct rspamd_config *cfg); typedef void (*insert_func) (gpointer st, gconstpointer key, gconstpointer value); @@ -92,34 +92,34 @@ typedef void (*insert_func) (gpointer st, gconstpointer key, /** * Radix list is a list like ip/mask */ -gchar * read_radix_list (rspamd_mempool_t *pool, +gchar * rspamd_radix_read (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); +void rspamd_radix_fin (rspamd_mempool_t *pool, struct map_cb_data *data); /** * Host list is an ordinal list of hosts or domains */ -gchar * read_host_list (rspamd_mempool_t *pool, +gchar * rspamd_hosts_read (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); +void rspamd_hosts_fin (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 (rspamd_mempool_t *pool, +gchar * rspamd_kv_list_read (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); +void rspamd_kv_list_fin (rspamd_mempool_t *pool, struct map_cb_data *data); /** * FSM for lists parsing (support comments, blank lines and partial replies) */ -gchar * abstract_parse_list (rspamd_mempool_t * pool, +gchar * rspamd_parse_abstract_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data, diff --git a/src/libutil/printf.c b/src/libutil/printf.c index 772a68745..d43e38810 100644 --- a/src/libutil/printf.c +++ b/src/libutil/printf.c @@ -335,7 +335,7 @@ rspamd_vprintf_common (rspamd_printf_append_func func, gint64 i64; guint64 ui64; guint width, sign, hex, humanize, bytes, frac_width, i; - f_str_t *v; + rspamd_fstring_t *v; GString *gs; gboolean bv; @@ -438,7 +438,7 @@ rspamd_vprintf_common (rspamd_printf_append_func func, switch (*fmt) { case 'V': - v = va_arg (args, f_str_t *); + v = va_arg (args, rspamd_fstring_t *); RSPAMD_PRINTF_APPEND (v->begin, v->len); continue; diff --git a/src/libutil/util.c b/src/libutil/util.c index ec125704f..b45a68455 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -53,7 +53,7 @@ #define CONNECT_TIMEOUT 3 gint -make_socket_nonblocking (gint fd) +rspamd_socket_nonblocking (gint fd) { gint ofl; @@ -67,7 +67,7 @@ make_socket_nonblocking (gint fd) } gint -make_socket_blocking (gint fd) +rspamd_socket_blocking (gint fd) { gint ofl; @@ -81,7 +81,7 @@ make_socket_blocking (gint fd) } gint -poll_sync_socket (gint fd, gint timeout, short events) +rspamd_socket_poll (gint fd, gint timeout, short events) { gint r; struct pollfd fds[1]; @@ -116,7 +116,7 @@ rspamd_socket_create (gint af, gint type, gint protocol, gboolean async) return -1; } if (async) { - if (make_socket_nonblocking (fd) == -1) { + if (rspamd_socket_nonblocking (fd) == -1) { close (fd); return -1; } @@ -169,7 +169,7 @@ rspamd_inet_socket_create (gint type, struct addrinfo *addr, gboolean is_server, } if (!async) { /* Try to poll */ - if (poll_sync_socket (fd, CONNECT_TIMEOUT * 1000, + if (rspamd_socket_poll (fd, CONNECT_TIMEOUT * 1000, POLLOUT) <= 0) { errno = ETIMEDOUT; msg_warn ("bind/connect failed: timeout"); @@ -177,7 +177,7 @@ rspamd_inet_socket_create (gint type, struct addrinfo *addr, gboolean is_server, } else { /* Make synced again */ - if (make_socket_blocking (fd) < 0) { + if (rspamd_socket_blocking (fd) < 0) { goto out; } } @@ -212,19 +212,19 @@ out: } gint -make_tcp_socket (struct addrinfo *addr, gboolean is_server, gboolean async) +rspamd_socket_tcp (struct addrinfo *addr, gboolean is_server, gboolean async) { return rspamd_inet_socket_create (SOCK_STREAM, addr, is_server, async, NULL); } gint -make_udp_socket (struct addrinfo *addr, gboolean is_server, gboolean async) +rspamd_socket_udp (struct addrinfo *addr, gboolean is_server, gboolean async) { return rspamd_inet_socket_create (SOCK_DGRAM, addr, is_server, async, NULL); } gint -make_unix_socket (const gchar *path, +rspamd_socket_unix (const gchar *path, struct sockaddr_un *addr, gint type, gboolean is_server, @@ -271,7 +271,7 @@ make_unix_socket (const gchar *path, return -1; } - if (make_socket_nonblocking (fd) < 0) { + if (rspamd_socket_nonblocking (fd) < 0) { goto out; } @@ -300,14 +300,14 @@ make_unix_socket (const gchar *path, } if (!async) { /* Try to poll */ - if (poll_sync_socket (fd, CONNECT_TIMEOUT * 1000, POLLOUT) <= 0) { + if (rspamd_socket_poll (fd, CONNECT_TIMEOUT * 1000, POLLOUT) <= 0) { errno = ETIMEDOUT; msg_warn ("bind/connect failed %s: timeout", addr->sun_path); goto out; } else { /* Make synced again */ - if (make_socket_blocking (fd) < 0) { + if (rspamd_socket_blocking (fd) < 0) { goto out; } } @@ -344,7 +344,7 @@ out: * @param try_resolve try name resolution for a socket (BLOCKING) */ gint -make_universal_socket (const gchar *credits, guint16 port, +rspamd_socket (const gchar *credits, guint16 port, gint type, gboolean async, gboolean is_server, gboolean try_resolve) { struct sockaddr_un un; @@ -355,7 +355,7 @@ make_universal_socket (const gchar *credits, guint16 port, if (*credits == '/') { if (is_server) { - return make_unix_socket (credits, &un, type, is_server, async); + return rspamd_socket_unix (credits, &un, type, is_server, async); } else { r = stat (credits, &st); @@ -371,7 +371,7 @@ make_universal_socket (const gchar *credits, guint16 port, return -1; } else { - return make_unix_socket (credits, + return rspamd_socket_unix (credits, &un, type, is_server, @@ -419,7 +419,7 @@ make_universal_socket (const gchar *credits, guint16 port, * @param try_resolve try name resolution for a socket (BLOCKING) */ GList * -make_universal_sockets_list (const gchar *credits, guint16 port, +rspamd_sockets_list (const gchar *credits, guint16 port, gint type, gboolean async, gboolean is_server, gboolean try_resolve) { struct sockaddr_un un; @@ -438,7 +438,7 @@ make_universal_sockets_list (const gchar *credits, guint16 port, while (*cur != NULL) { if (*credits == '/') { if (is_server) { - fd = make_unix_socket (credits, &un, type, is_server, async); + fd = rspamd_socket_unix (credits, &un, type, is_server, async); } else { r = stat (credits, &st); @@ -454,7 +454,7 @@ make_universal_sockets_list (const gchar *credits, guint16 port, goto err; } else { - fd = make_unix_socket (credits, + fd = rspamd_socket_unix (credits, &un, type, is_server, @@ -525,7 +525,7 @@ err: } gint -make_socketpair (gint pair[2]) +rspamd_socketpair (gint pair[2]) { gint r; @@ -555,7 +555,7 @@ out: } gint -write_pid (struct rspamd_main *main) +rspamd_write_pid (struct rspamd_main *main) { pid_t pid; @@ -587,12 +587,12 @@ write_pid (struct rspamd_main *main) #ifdef HAVE_SA_SIGINFO void -init_signals (struct sigaction *signals, void (*sig_handler)(gint, +rspamd_signals_init (struct sigaction *signals, void (*sig_handler)(gint, siginfo_t *, void *)) #else void -init_signals (struct sigaction *signals, void (*sig_handler)(gint)) +rspamd_signals_init (struct sigaction *signals, void (*sig_handler)(gint)) #endif { struct sigaction sigpipe_act; @@ -643,13 +643,13 @@ pass_signal_cb (gpointer key, gpointer value, gpointer ud) } void -pass_signal_worker (GHashTable * workers, gint signo) +rspamd_pass_signal (GHashTable * workers, gint signo) { g_hash_table_foreach (workers, pass_signal_cb, GINT_TO_POINTER (signo)); } void -convert_to_lowercase (gchar *str, guint size) +rspamd_str_lc (gchar *str, guint size) { while (size--) { *str = g_ascii_tolower (*str); @@ -865,7 +865,7 @@ rspamd_pidfile_open (const gchar *path, mode_t mode, pid_t * pidptr) * pidfile_write() can be called multiple times. */ fd = open (pfh->pf_path, O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode); - lock_file (fd, TRUE); + rspamd_file_lock (fd, TRUE); if (fd == -1) { count = 0; rqtp.tv_sec = 0; @@ -979,7 +979,7 @@ _rspamd_pidfile_remove (rspamd_pidfh_t *pfh, gint freeit) if (unlink (pfh->pf_path) == -1) error = errno; - if (!unlock_file (pfh->pf_fd, FALSE)) { + if (!rspamd_file_unlock (pfh->pf_fd, FALSE)) { if (error == 0) error = errno; } @@ -1189,9 +1189,9 @@ rspamd_str_equal (gconstpointer v, gconstpointer v2) } gboolean -fstr_strcase_equal (gconstpointer v, gconstpointer v2) +rspamd_fstring_equal (gconstpointer v, gconstpointer v2) { - const f_str_t *f1 = v, *f2 = v2; + const rspamd_fstring_t *f1 = v, *f2 = v2; if (f1->len == f2->len && g_ascii_strncasecmp (f1->begin, f2->begin, f1->len) == 0) { return TRUE; @@ -1202,9 +1202,9 @@ fstr_strcase_equal (gconstpointer v, gconstpointer v2) guint -fstr_strcase_hash (gconstpointer key) +rspamd_fstring_hash (gconstpointer key) { - const f_str_t *f = key; + const rspamd_fstring_t *f = key; const gchar *p; guint i = 0; gchar buf[256]; @@ -1266,7 +1266,7 @@ gperf_profiler_init (struct rspamd_config *cfg, const gchar *descr) #ifdef HAVE_FLOCK /* Flock version */ gboolean -lock_file (gint fd, gboolean async) +rspamd_file_lock (gint fd, gboolean async) { gint flags; @@ -1289,7 +1289,7 @@ lock_file (gint fd, gboolean async) } gboolean -unlock_file (gint fd, gboolean async) +rspamd_file_unlock (gint fd, gboolean async) { gint flags; @@ -1314,7 +1314,7 @@ unlock_file (gint fd, gboolean async) #else /* HAVE_FLOCK */ /* Fctnl version */ gboolean -lock_file (gint fd, gboolean async) +rspamd_file_lock (gint fd, gboolean async) { struct flock fl = { .l_type = F_WRLCK, @@ -1335,7 +1335,7 @@ lock_file (gint fd, gboolean async) } gboolean -unlock_file (gint fd, gboolean async) +rspamd_file_unlock (gint fd, gboolean async) { struct flock fl = { .l_type = F_UNLCK, @@ -1425,7 +1425,7 @@ rspamd_strlcpy_tolower (gchar *dst, const gchar *src, gsize siz) /* Compare two emails for building emails tree */ gint -compare_email_func (gconstpointer a, gconstpointer b) +rspamd_emails_cmp (gconstpointer a, gconstpointer b) { const struct uri *u1 = a, *u2 = b; gint r; @@ -1451,7 +1451,7 @@ compare_email_func (gconstpointer a, gconstpointer b) } gint -compare_url_func (gconstpointer a, gconstpointer b) +rspamd_urls_cmp (gconstpointer a, gconstpointer b) { const struct uri *u1 = a, *u2 = b; int r; diff --git a/src/libutil/util.h b/src/libutil/util.h index e7a9f520a..de723ecd3 100644 --- a/src/libutil/util.h +++ b/src/libutil/util.h @@ -27,16 +27,16 @@ gint rspamd_socket_create (gint af, gint type, gint protocol, gboolean async); /* * Create socket and bind or connect it to specified address and port */ -gint make_tcp_socket (struct addrinfo *, gboolean is_server, gboolean async); +gint rspamd_socket_tcp (struct addrinfo *, gboolean is_server, gboolean async); /* * Create socket and bind or connect it to specified address and port */ -gint make_udp_socket (struct addrinfo *, gboolean is_server, gboolean async); +gint rspamd_socket_udp (struct addrinfo *, gboolean is_server, gboolean async); /* * Create and bind or connect unix socket */ -gint make_unix_socket (const gchar *, +gint rspamd_socket_unix (const gchar *, struct sockaddr_un *, gint type, gboolean is_server, @@ -51,7 +51,7 @@ gint make_unix_socket (const gchar *, * @param is_server make this socket as server socket * @param try_resolve try name resolution for a socket (BLOCKING) */ -gint make_universal_socket (const gchar *credits, guint16 port, gint type, +gint rspamd_socket (const gchar *credits, guint16 port, gint type, gboolean async, gboolean is_server, gboolean try_resolve); /** @@ -63,7 +63,7 @@ gint make_universal_socket (const gchar *credits, guint16 port, gint type, * @param is_server make this socket as server socket * @param try_resolve try name resolution for a socket (BLOCKING) */ -GList * make_universal_sockets_list (const gchar *credits, +GList * rspamd_sockets_list (const gchar *credits, guint16 port, gint type, gboolean async, @@ -72,46 +72,46 @@ GList * make_universal_sockets_list (const gchar *credits, /* * Create socketpair */ -gint make_socketpair (gint pair[2]); +gint rspamd_socketpair (gint pair[2]); /* * Write pid to file */ -gint write_pid (struct rspamd_main *); +gint rspamd_write_pid (struct rspamd_main *); /* * Make specified socket non-blocking */ -gint make_socket_nonblocking (gint); +gint rspamd_socket_nonblocking (gint); /* * Make specified socket blocking */ -gint make_socket_blocking (gint); +gint rspamd_socket_blocking (gint); /* * Poll a sync socket for specified events */ -gint poll_sync_socket (gint fd, gint timeout, short events); +gint rspamd_socket_poll (gint fd, gint timeout, short events); /* * Init signals */ #ifdef HAVE_SA_SIGINFO -void init_signals (struct sigaction *sa, void (*sig_handler)(gint, +void rspamd_signals_init (struct sigaction *sa, void (*sig_handler)(gint, siginfo_t *, void *)); #else -void init_signals (struct sigaction *sa, void (*sig_handler)(gint)); +void rspamd_signals_init (struct sigaction *sa, void (*sig_handler)(gint)); #endif /* * Send specified signal to each worker */ -void pass_signal_worker (GHashTable *, gint ); +void rspamd_pass_signal (GHashTable *, gint ); /* * Convert string to lowercase */ -void convert_to_lowercase (gchar *str, guint size); +void rspamd_str_lc (gchar *str, guint size); #ifndef HAVE_SETPROCTITLE /* @@ -175,8 +175,8 @@ const gchar * calculate_check_time (struct timeval *begin, /* * File locking functions */ -gboolean lock_file (gint fd, gboolean async); -gboolean unlock_file (gint fd, gboolean async); +gboolean rspamd_file_lock (gint fd, gboolean async); +gboolean rspamd_file_unlock (gint fd, gboolean async); /* * Hash table utility functions for case insensitive hashing @@ -194,8 +194,8 @@ gboolean rspamd_str_equal (gconstpointer v, gconstpointer v2); /* * Hash table utility functions for hashing fixed strings */ -guint fstr_strcase_hash (gconstpointer key); -gboolean fstr_strcase_equal (gconstpointer v, gconstpointer v2); +guint rspamd_fstring_hash (gconstpointer key); +gboolean rspamd_fstring_equal (gconstpointer v, gconstpointer v2); /* * Google perf-tools initialization function @@ -246,10 +246,10 @@ gsize rspamd_strlcpy_tolower (gchar *dst, const gchar *src, gsize siz); #define tv_to_msec(tv) ((tv)->tv_sec * 1000LLU + (tv)->tv_usec / 1000LLU) /* Compare two emails for building emails tree */ -gint compare_email_func (gconstpointer a, gconstpointer b); +gint rspamd_emails_cmp (gconstpointer a, gconstpointer b); /* Compare two urls for building emails tree */ -gint compare_url_func (gconstpointer a, gconstpointer b); +gint rspamd_urls_cmp (gconstpointer a, gconstpointer b); /* * Find string find in string s ignoring case diff --git a/src/lmtp.c b/src/lmtp.c index 350c61ff4..91fbff17e 100644 --- a/src/lmtp.c +++ b/src/lmtp.c @@ -93,7 +93,7 @@ sigusr1_handler (gint fd, short what, void *arg) { struct rspamd_worker *worker = (struct rspamd_worker *) arg; - reopen_log (worker->srv->logger); + rspamd_log_reopen (worker->srv->logger); return; } @@ -147,7 +147,7 @@ free_lmtp_task (struct rspamd_lmtp_proto *lmtp, gboolean is_soft) * Callback that is called when there is data to read in buffer */ static gboolean -lmtp_read_socket (f_str_t * in, void *arg) +lmtp_read_socket (rspamd_fstring_t * in, void *arg) { struct rspamd_lmtp_proto *lmtp = (struct rspamd_lmtp_proto *)arg; struct rspamd_task *task = lmtp->task; @@ -316,7 +316,7 @@ start_lmtp (struct rspamd_worker *worker) worker->srv->pid = getpid (); worker->ctx = event_init (); - init_signals (&signals, sig_handler); + rspamd_signals_init (&signals, sig_handler); sigprocmask (SIG_UNBLOCK, &signals.sa_mask, NULL); /* SIGUSR2 handler */ diff --git a/src/lmtp_proto.c b/src/lmtp_proto.c index 67ca50e22..84c2ada82 100644 --- a/src/lmtp_proto.c +++ b/src/lmtp_proto.c @@ -33,27 +33,27 @@ #define OUTBUFSIZ 1000 /* LMTP commands */ -static f_str_t lhlo_command = { +static rspamd_fstring_t lhlo_command = { .begin = "LHLO", .len = sizeof ("LHLO") - 1 }; -static f_str_t mail_command = { +static rspamd_fstring_t mail_command = { .begin = "MAIL FROM:", .len = sizeof ("MAIL FROM:") - 1 }; -static f_str_t rcpt_command = { +static rspamd_fstring_t rcpt_command = { .begin = "RCPT TO:", .len = sizeof ("RCPT TO:") - 1 }; -static f_str_t data_command = { +static rspamd_fstring_t data_command = { .begin = "DATA", .len = sizeof ("DATA") - 1 }; -static f_str_t data_dot = { +static rspamd_fstring_t data_dot = { .begin = ".\r\n", .len = sizeof (".\r\n") - 1 }; @@ -67,7 +67,7 @@ static GRegex *mail_re = NULL; * return <> if no valid address detected */ static gchar * -extract_mail (rspamd_mempool_t * pool, f_str_t * line) +extract_mail (rspamd_mempool_t * pool, rspamd_fstring_t * line) { GError *err = NULL; gchar *match; @@ -111,16 +111,16 @@ out_lmtp_reply (struct rspamd_task *task, gint code, gchar *rcode, gchar *msg) } gint -read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t * line) +read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, rspamd_fstring_t * line) { gchar *c, *rcpt; - f_str_t fstr; + rspamd_fstring_t fstr; gint i = 0, l = 0, size; switch (lmtp->state) { case LMTP_READ_LHLO: /* Search LHLO line */ - if ((i = fstrstri (line, &lhlo_command)) == -1) { + if ((i = rspamd_fstrstri (line, &lhlo_command)) == -1) { msg_info ("LHLO expected but not found"); (void)out_lmtp_reply (lmtp->task, LMTP_BAD_CMD, @@ -149,7 +149,7 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t * line) break; case LMTP_READ_FROM: /* Search MAIL FROM: line */ - if ((i = fstrstri (line, &mail_command)) == -1) { + if ((i = rspamd_fstrstri (line, &mail_command)) == -1) { msg_info ("MAIL expected but not found"); (void)out_lmtp_reply (lmtp->task, LMTP_BAD_CMD, @@ -172,7 +172,7 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t * line) break; case LMTP_READ_RCPT: /* Search RCPT_TO: line */ - if ((i = fstrstri (line, &rcpt_command)) == -1) { + if ((i = rspamd_fstrstri (line, &rcpt_command)) == -1) { msg_info ("RCPT expected but not found"); (void)out_lmtp_reply (lmtp->task, LMTP_NO_RCPT, @@ -207,7 +207,7 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t * line) break; case LMTP_READ_DATA: /* Search DATA line */ - if ((i = fstrstri (line, &data_command)) == -1) { + if ((i = rspamd_fstrstri (line, &data_command)) == -1) { msg_info ("DATA expected but not found"); (void)out_lmtp_reply (lmtp->task, LMTP_BAD_CMD, @@ -232,7 +232,7 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t * line) "Enter message, ending with \".\" on a line by itself")) { return -1; } - lmtp->task->msg = fstralloc (lmtp->task->task_pool, BUFSIZ); + lmtp->task->msg = rspamd_fstralloc (lmtp->task->task_pool, BUFSIZ); return 0; } break; @@ -254,11 +254,11 @@ read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t * line) /* size *= 2 */ size <<= 1; } - lmtp->task->msg = fstrgrow (lmtp->task->task_pool, + lmtp->task->msg = rspamd_fstrgrow (lmtp->task->task_pool, lmtp->task->msg, size); } - fstrcat (lmtp->task->msg, line); + rspamd_fstrcat (lmtp->task->msg, line); return 0; } break; @@ -290,10 +290,10 @@ struct mta_callback_data { }; static gboolean -parse_mta_str (f_str_t * in, struct mta_callback_data *cd) +parse_mta_str (rspamd_fstring_t * in, struct mta_callback_data *cd) { gint r; - static f_str_t okres1 = { + static rspamd_fstring_t okres1 = { .begin = "250 ", .len = sizeof ("250 ") - 1, } @@ -310,13 +310,13 @@ parse_mta_str (f_str_t * in, struct mta_callback_data *cd) case LMTP_WANT_RCPT: case LMTP_WANT_DATA: case LMTP_WANT_CLOSING: - r = fstrstr (in, &okres1); + r = rspamd_fstrstr (in, &okres1); if (r == -1) { - r = fstrstr (in, &okres2); + r = rspamd_fstrstr (in, &okres2); } break; case LMTP_WANT_DOT: - r = fstrstr (in, &datares); + r = rspamd_fstrstr (in, &datares); break; } @@ -344,13 +344,13 @@ close_mta_connection (struct mta_callback_data *cd, gboolean is_success) * Callback that is called when there is data to read in buffer */ static gboolean -mta_read_socket (f_str_t * in, void *arg) +mta_read_socket (rspamd_fstring_t * in, void *arg) { struct mta_callback_data *cd = (struct mta_callback_data *)arg; gchar outbuf[1024], *hostbuf, *c; gint hostmax, r; GList *cur; - static f_str_t contres1 = { + static rspamd_fstring_t contres1 = { .begin = "250-", .len = sizeof ("250-") - 1, } @@ -358,7 +358,7 @@ mta_read_socket (f_str_t * in, void *arg) .begin = "220-",.len = sizeof ("220-") - 1, }; - if (fstrstr (in, &contres1) != -1 || fstrstr (in, &contres2) != -1) { + if (rspamd_fstrstr (in, &contres1) != -1 || rspamd_fstrstr (in, &contres2) != -1) { /* Skip such lines */ return TRUE; } @@ -499,14 +499,14 @@ lmtp_deliver_mta (struct rspamd_task *task) if (task->cfg->deliver_family == AF_UNIX) { un = alloca (sizeof (struct sockaddr_un)); - sock = make_unix_socket (task->cfg->deliver_host, + sock = rspamd_socket_unix (task->cfg->deliver_host, un, SOCK_STREAM, FALSE, TRUE); } else { - sock = make_universal_socket (task->cfg->deliver_host, + sock = rspamd_socket (task->cfg->deliver_host, task->cfg->deliver_port, SOCK_STREAM, TRUE, diff --git a/src/lmtp_proto.h b/src/lmtp_proto.h index 143915818..fb2f0f8f2 100644 --- a/src/lmtp_proto.h +++ b/src/lmtp_proto.h @@ -25,7 +25,7 @@ struct rspamd_lmtp_proto { * @param line line of user's input * @return 0 if line was successfully parsed and -1 if we have protocol error */ -gint read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, f_str_t *line); +gint read_lmtp_input_line (struct rspamd_lmtp_proto *lmtp, rspamd_fstring_t *line); /** * Deliver message via lmtp/smtp or pipe to LDA diff --git a/src/lua/lua_buffer.c b/src/lua/lua_buffer.c index ee64a84ab..5d00db585 100644 --- a/src/lua/lua_buffer.c +++ b/src/lua/lua_buffer.c @@ -79,7 +79,7 @@ lua_check_event_base (lua_State *L) /* Dispatcher callbacks */ static gboolean -lua_io_read_cb (f_str_t * in, void *arg) +lua_io_read_cb (rspamd_fstring_t * in, void *arg) { struct lua_dispatcher_cbdata *cbdata = arg; gboolean res; diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 14bfb9d07..3043013ba 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -716,8 +716,8 @@ lua_config_add_radix_map (lua_State *L) description = lua_tostring (L, 3); r = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (radix_compressed_t *)); *r = radix_create_compressed (); - if (!add_map (cfg, map_line, description, read_radix_list, - fin_radix_list, (void **)r)) { + if (!rspamd_map_add (cfg, map_line, description, rspamd_radix_read, + rspamd_radix_fin, (void **)r)) { msg_warn ("invalid radix map %s", map_line); radix_destroy_compressed (*r); lua_pushnil (L); @@ -747,7 +747,7 @@ lua_config_add_hash_map (lua_State *L) description = lua_tostring (L, 3); 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, + if (!rspamd_map_add (cfg, map_line, description, rspamd_hosts_read, rspamd_hosts_fin, (void **)r)) { msg_warn ("invalid hash map %s", map_line); g_hash_table_destroy (*r); @@ -781,7 +781,7 @@ lua_config_add_kv_map (lua_State *L) description = lua_tostring (L, 3); 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, + if (!rspamd_map_add (cfg, map_line, description, rspamd_kv_list_read, rspamd_kv_list_fin, (void **)r)) { msg_warn ("invalid hash map %s", map_line); g_hash_table_destroy (*r); @@ -1279,7 +1279,7 @@ lua_config_add_map (lua_State *L) cbdata->ref = luaL_ref (L, LUA_REGISTRYINDEX); pcbdata = rspamd_mempool_alloc (cfg->cfg_pool, sizeof (cbdata)); *pcbdata = cbdata; - if (!add_map (cfg, map_line, description, lua_map_read, lua_map_fin, + if (!rspamd_map_add (cfg, map_line, description, lua_map_read, lua_map_fin, (void **)pcbdata)) { msg_warn ("invalid hash map %s", map_line); lua_pushboolean (L, false); diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index 67c86586e..da64a1a17 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -59,7 +59,7 @@ struct lua_redis_userdata { struct in_addr ina; gchar *reqline; guint16 port; - f_str_t *args; + rspamd_fstring_t *args; guint args_num; }; @@ -325,7 +325,7 @@ lua_redis_make_request (lua_State *L) /* Now get remaining args */ ud->args_num = lua_gettop (L) - 5; ud->args = rspamd_mempool_alloc (task->task_pool, - ud->args_num * sizeof (f_str_t)); + ud->args_num * sizeof (rspamd_fstring_t)); for (i = 0; i < ud->args_num; i++) { tmp = lua_tolstring (L, i + 6, &ud->args[i].len); /* Make a copy of argument */ diff --git a/src/lua/lua_rsa.c b/src/lua/lua_rsa.c index e4dee90b0..394332fd0 100644 --- a/src/lua/lua_rsa.c +++ b/src/lua/lua_rsa.c @@ -114,13 +114,13 @@ lua_check_rsa_privkey (lua_State * L, int pos) return ud ? *((RSA **)ud) : NULL; } -static f_str_t * +static rspamd_fstring_t * lua_check_rsa_sign (lua_State * L, int pos) { void *ud = luaL_checkudata (L, pos, "rspamd{rsa_signature}"); luaL_argcheck (L, ud != NULL, 1, "'rsa_signature' expected"); - return ud ? *((f_str_t **)ud) : NULL; + return ud ? *((rspamd_fstring_t **)ud) : NULL; } static gint @@ -280,7 +280,7 @@ lua_rsa_privkey_gc (lua_State *L) static gint lua_rsa_signature_load (lua_State *L) { - f_str_t *sig, **psig; + rspamd_fstring_t *sig, **psig; const gchar *filename; gpointer data; int fd; @@ -295,7 +295,7 @@ lua_rsa_signature_load (lua_State *L) lua_pushnil (L); } else { - sig = g_malloc (sizeof (f_str_t)); + sig = g_malloc (sizeof (rspamd_fstring_t)); if (fstat (fd, &st) == -1 || (data = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, @@ -308,7 +308,7 @@ lua_rsa_signature_load (lua_State *L) sig->len = sig->size; sig->begin = g_malloc (sig->len); memcpy (sig->begin, data, sig->len); - psig = lua_newuserdata (L, sizeof (f_str_t *)); + psig = lua_newuserdata (L, sizeof (rspamd_fstring_t *)); rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1); *psig = sig; munmap (data, st.st_size); @@ -325,7 +325,7 @@ lua_rsa_signature_load (lua_State *L) static gint lua_rsa_signature_save (lua_State *L) { - f_str_t *sig; + rspamd_fstring_t *sig; gint fd, flags; const gchar *filename; gboolean forced = FALSE, res = TRUE; @@ -376,17 +376,17 @@ lua_rsa_signature_save (lua_State *L) static gint lua_rsa_signature_create (lua_State *L) { - f_str_t *sig, **psig; + rspamd_fstring_t *sig, **psig; const gchar *data; data = luaL_checkstring (L, 1); if (data != NULL) { - sig = g_malloc (sizeof (f_str_t)); + sig = g_malloc (sizeof (rspamd_fstring_t)); sig->len = strlen (data); sig->size = sig->len; sig->begin = g_malloc (sig->len); memcpy (sig->begin, data, sig->len); - psig = lua_newuserdata (L, sizeof (f_str_t *)); + psig = lua_newuserdata (L, sizeof (rspamd_fstring_t *)); rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1); *psig = sig; } @@ -397,7 +397,7 @@ lua_rsa_signature_create (lua_State *L) static gint lua_rsa_signature_gc (lua_State *L) { - f_str_t *sig = lua_check_rsa_sign (L, 1); + rspamd_fstring_t *sig = lua_check_rsa_sign (L, 1); if (sig != NULL) { if (sig->begin != NULL) { @@ -423,7 +423,7 @@ static gint lua_rsa_verify_memory (lua_State *L) { RSA *rsa; - f_str_t *signature; + rspamd_fstring_t *signature; const gchar *data; gchar *data_sig; gint ret; @@ -467,7 +467,7 @@ static gint lua_rsa_verify_file (lua_State *L) { RSA *rsa; - f_str_t *signature; + rspamd_fstring_t *signature; const gchar *filename; gchar *data = NULL, *data_sig; gint ret, fd; @@ -532,7 +532,7 @@ static gint lua_rsa_sign_memory (lua_State *L) { RSA *rsa; - f_str_t *signature, **psig; + rspamd_fstring_t *signature, **psig; const gchar *data; gchar *data_sig; gint ret; @@ -541,7 +541,7 @@ lua_rsa_sign_memory (lua_State *L) data = luaL_checkstring (L, 2); if (rsa != NULL && data != NULL) { - signature = g_malloc (sizeof (f_str_t)); + signature = g_malloc (sizeof (rspamd_fstring_t)); signature->len = RSA_size (rsa); signature->size = signature->len; signature->begin = g_malloc (signature->len); @@ -556,7 +556,7 @@ lua_rsa_sign_memory (lua_State *L) g_free (signature); } else { - psig = lua_newuserdata (L, sizeof (f_str_t *)); + psig = lua_newuserdata (L, sizeof (rspamd_fstring_t *)); rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1); *psig = signature; } @@ -583,7 +583,7 @@ static gint lua_rsa_sign_file (lua_State *L) { RSA *rsa; - f_str_t *signature, **psig; + rspamd_fstring_t *signature, **psig; const gchar *filename; gchar *data = NULL, *data_sig; gint ret, fd; @@ -607,7 +607,7 @@ lua_rsa_sign_file (lua_State *L) lua_pushnil (L); } else { - signature = g_malloc (sizeof (f_str_t)); + signature = g_malloc (sizeof (rspamd_fstring_t)); signature->len = RSA_size (rsa); signature->size = signature->len; signature->begin = g_malloc (signature->len); @@ -624,7 +624,7 @@ lua_rsa_sign_file (lua_State *L) g_free (signature); } else { - psig = lua_newuserdata (L, sizeof (f_str_t *)); + psig = lua_newuserdata (L, sizeof (rspamd_fstring_t *)); rspamd_lua_setclass (L, "rspamd{rsa_signature}", -1); *psig = signature; } diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index dc123795f..9a61dd5c5 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -2161,11 +2161,11 @@ lua_textpart_compare_distance (lua_State * L) else { if (!part->is_empty && !other->is_empty) { if (part->diff_str != NULL && other->diff_str != NULL) { - diff = compare_diff_distance (part->diff_str, + diff = rspamd_diff_distance (part->diff_str, other->diff_str); } else { - diff = fuzzy_compare_parts (part, other); + diff = rspamd_fuzzy_compare_parts (part, other); } } else if ((part->is_empty && diff --git a/src/lua_worker.c b/src/lua_worker.c index 65c5b9011..95c3be719 100644 --- a/src/lua_worker.c +++ b/src/lua_worker.c @@ -387,7 +387,7 @@ start_lua_worker (struct rspamd_worker *worker) } /* Maps events */ - start_map_watch (worker->srv->cfg, ctx->ev_base); + rspamd_map_watch (worker->srv->cfg, ctx->ev_base); event_base_loop (ctx->ev_base, 0); luaL_unref (L, LUA_REGISTRYINDEX, ctx->cbref_accept); @@ -405,7 +405,7 @@ start_lua_worker (struct rspamd_worker *worker) luaL_unref (L, LUA_REGISTRYINDEX, ctx->cbref_fin); } - close_log (rspamd_main->logger); + rspamd_log_close (rspamd_main->logger); exit (EXIT_SUCCESS); } diff --git a/src/main.c b/src/main.c index 7f7d82725..b1d9d51ff 100644 --- a/src/main.c +++ b/src/main.c @@ -337,7 +337,7 @@ config_logger (struct rspamd_config *cfg, gpointer ud) } rspamd_set_logger (cfg, g_quark_try_string ("main"), rm); - if (open_log_priv (rm->logger, rm->workers_uid, rm->workers_gid) == -1) { + if (rspamd_log_open_priv (rm->logger, rm->workers_uid, rm->workers_gid) == -1) { fprintf (stderr, "Fatal error, cannot open logfile, exiting\n"); exit (EXIT_FAILURE); } @@ -490,7 +490,7 @@ fork_worker (struct rspamd_main *rspamd, struct rspamd_worker_conf *cf) switch (cur->pid) { case 0: /* Update pid for logging */ - update_log_pid (cf->type, rspamd->logger); + rspamd_log_update_pid (cf->type, rspamd->logger); /* Lock statfile pool if possible */ statfile_pool_lockall (rspamd->statfile_pool); /* Init PRNG after fork */ @@ -503,8 +503,8 @@ fork_worker (struct rspamd_main *rspamd, struct rspamd_worker_conf *cf) setproctitle ("%s process", cf->worker->name); rspamd_pidfile_close (rspamd->pfh); /* Do silent log reopen to avoid collisions */ - close_log (rspamd->logger); - open_log (rspamd->logger); + rspamd_log_close (rspamd->logger); + rspamd_log_open (rspamd->logger); #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30)) # if (GLIB_MINOR_VERSION > 20) /* Ugly hack for old glib */ @@ -1246,7 +1246,7 @@ main (gint argc, gchar **argv, gchar **env) /* First set logger to console logger */ rspamd_main->cfg->log_type = RSPAMD_LOG_CONSOLE; rspamd_set_logger (rspamd_main->cfg, type, rspamd_main); - (void)open_log (rspamd_main->logger); + (void)rspamd_log_open (rspamd_main->logger); g_log_set_default_handler (rspamd_glib_log_function, rspamd_main->logger); detect_priv (rspamd_main); @@ -1335,9 +1335,9 @@ main (gint argc, gchar **argv, gchar **env) rspamd_main->pid = getpid (); rspamd_main->type = type; - init_signals (&signals, sig_handler); + rspamd_signals_init (&signals, sig_handler); - if (write_pid (rspamd_main) == -1) { + if (rspamd_write_pid (rspamd_main) == -1) { msg_err ("cannot write pid file %s", rspamd_main->cfg->pid_file); exit (-errno); } @@ -1380,7 +1380,7 @@ main (gint argc, gchar **argv, gchar **env) (void)validate_cache (rspamd_main->cfg->cache, rspamd_main->cfg, FALSE); /* Flush log */ - flush_log_buf (rspamd_main->logger); + rspamd_log_flush (rspamd_main->logger); /* Preload all statfiles */ preload_statfiles (rspamd_main); @@ -1406,7 +1406,7 @@ main (gint argc, gchar **argv, gchar **env) if (do_terminate) { do_terminate = 0; msg_info ("catch termination signal, waiting for children"); - pass_signal_worker (rspamd_main->workers, SIGTERM); + rspamd_pass_signal (rspamd_main->workers, SIGTERM); break; } if (child_dead) { @@ -1458,18 +1458,18 @@ main (gint argc, gchar **argv, gchar **env) } if (do_restart) { do_restart = 0; - reopen_log_priv (rspamd_main->logger, + rspamd_log_reopen_priv (rspamd_main->logger, rspamd_main->workers_uid, rspamd_main->workers_gid); msg_info ("rspamd " RVERSION " is restarting"); g_hash_table_foreach (rspamd_main->workers, kill_old_workers, NULL); - remove_all_maps (rspamd_main->cfg); + rspamd_map_remove_all (rspamd_main->cfg); reread_config (rspamd_main); spawn_workers (rspamd_main); } if (do_reopen_log) { do_reopen_log = 0; - reopen_log_priv (rspamd_main->logger, + rspamd_log_reopen_priv (rspamd_main->logger, rspamd_main->workers_uid, rspamd_main->workers_gid); g_hash_table_foreach (rspamd_main->workers, reopen_log_handler, @@ -1505,7 +1505,7 @@ main (gint argc, gchar **argv, gchar **env) statfile_pool_delete (rspamd_main->statfile_pool); - close_log (rspamd_main->logger); + rspamd_log_close (rspamd_main->logger); rspamd_config_free (rspamd_main->cfg); g_free (rspamd_main->cfg); diff --git a/src/main.h b/src/main.h index a70db8762..de571c27f 100644 --- a/src/main.h +++ b/src/main.h @@ -163,11 +163,11 @@ struct controller_session { gchar *learn_symbol; /**< symbol to train */ double learn_multiplier; /**< multiplier for learning */ rspamd_io_dispatcher_t *dispatcher; /**< IO dispatcher object */ - f_str_t *learn_buf; /**< learn input */ + rspamd_fstring_t *learn_buf; /**< learn input */ GList *parts; /**< extracted mime parts */ gint in_class; /**< positive or negative learn */ gboolean (*other_handler)(struct controller_session *session, - f_str_t *in); /**< other command handler to execute at the end of processing */ + rspamd_fstring_t *in); /**< other command handler to execute at the end of processing */ void *other_data; /**< and its data */ controller_func_t custom_handler; /**< custom command handler */ struct rspamd_async_session * s; /**< async session object */ diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index bc687065e..d09bddd54 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -155,8 +155,8 @@ dkim_module_config (struct rspamd_config *cfg) } if ((value = rspamd_config_get_module_opt (cfg, "dkim", "whitelist")) != NULL) { - if (!add_map (cfg, ucl_obj_tostring (value), - "DKIM whitelist", read_radix_list, fin_radix_list, + if (!rspamd_map_add (cfg, ucl_obj_tostring (value), + "DKIM whitelist", rspamd_radix_read, rspamd_radix_fin, (void **)&dkim_module_ctx->whitelist_ip)) { radix_add_generic_iplist (ucl_obj_tostring (value), &dkim_module_ctx->whitelist_ip); @@ -164,8 +164,8 @@ dkim_module_config (struct rspamd_config *cfg) } if ((value = rspamd_config_get_module_opt (cfg, "dkim", "domains")) != NULL) { - if (!add_map (cfg, ucl_obj_tostring (value), - "DKIM domains", read_kv_list, fin_kv_list, + if (!rspamd_map_add (cfg, ucl_obj_tostring (value), + "DKIM domains", rspamd_kv_list_read, rspamd_kv_list_fin, (void **)&dkim_module_ctx->dkim_domains)) { msg_warn ("cannot load dkim domains list from %s", ucl_obj_tostring (value)); diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index d89798c87..4162f164f 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -94,7 +94,7 @@ struct fuzzy_ctx { struct fuzzy_client_session { gint state; - fuzzy_hash_t *h; + rspamd_fuzzy_t *h; struct event ev; struct timeval tv; struct rspamd_task *task; @@ -105,7 +105,7 @@ struct fuzzy_client_session { struct fuzzy_learn_session { struct event ev; - fuzzy_hash_t *h; + rspamd_fuzzy_t *h; gint cmd; gint value; gint flag; @@ -254,7 +254,7 @@ fuzzy_normalize (gint32 in, double weight) } static const gchar * -fuzzy_to_string (fuzzy_hash_t *h) +fuzzy_to_string (rspamd_fuzzy_t *h) { static gchar strbuf [FUZZY_HASHLEN * 2 + 1]; const int max_print = 5; @@ -441,8 +441,8 @@ fuzzy_check_module_config (struct rspamd_config *cfg) rspamd_config_get_module_opt (cfg, "fuzzy_check", "whitelist")) != NULL) { fuzzy_module_ctx->whitelist = radix_create_compressed (); - if (!add_map (cfg, ucl_obj_tostring (value), - "Fuzzy whitelist", read_radix_list, fin_radix_list, + if (!rspamd_map_add (cfg, ucl_obj_tostring (value), + "Fuzzy whitelist", rspamd_radix_read, rspamd_radix_fin, (void **)&fuzzy_module_ctx->whitelist)) { radix_add_generic_iplist (ucl_obj_tostring (value), &fuzzy_module_ctx->whitelist); @@ -715,7 +715,7 @@ fuzzy_learn_callback (gint fd, short what, void *arg) static inline void register_fuzzy_call (struct rspamd_task *task, struct fuzzy_rule *rule, - fuzzy_hash_t *h) + rspamd_fuzzy_t *h) { struct fuzzy_client_session *session; struct upstream *selected; @@ -764,7 +764,7 @@ fuzzy_check_rule (struct rspamd_task *task, struct fuzzy_rule *rule) gchar *checksum; gsize hashlen; GList *cur; - fuzzy_hash_t *fake_fuzzy; + rspamd_fuzzy_t *fake_fuzzy; cur = task->text_parts; @@ -820,7 +820,7 @@ fuzzy_check_rule (struct rspamd_task *task, struct fuzzy_rule *rule) image->data->len); /* Construct fake fuzzy hash */ fake_fuzzy = rspamd_mempool_alloc0 (task->task_pool, - sizeof (fuzzy_hash_t)); + sizeof (rspamd_fuzzy_t)); rspamd_strlcpy (fake_fuzzy->hash_pipe, checksum, sizeof (fake_fuzzy->hash_pipe)); register_fuzzy_call (task, rule, fake_fuzzy); @@ -843,7 +843,7 @@ fuzzy_check_rule (struct rspamd_task *task, struct fuzzy_rule *rule) /* Construct fake fuzzy hash */ fake_fuzzy = rspamd_mempool_alloc0 (task->task_pool, - sizeof (fuzzy_hash_t)); + sizeof (rspamd_fuzzy_t)); rspamd_strlcpy (fake_fuzzy->hash_pipe, checksum, sizeof (fake_fuzzy->hash_pipe)); register_fuzzy_call (task, rule, fake_fuzzy); @@ -882,7 +882,7 @@ fuzzy_symbol_callback (struct rspamd_task *task, void *unused) static inline gboolean register_fuzzy_controller_call (struct rspamd_http_connection_entry *entry, - struct fuzzy_rule *rule, struct rspamd_task *task, fuzzy_hash_t *h, + struct fuzzy_rule *rule, struct rspamd_task *task, rspamd_fuzzy_t *h, gint cmd, gint value, gint flag, gint *saved, GError **err) { struct fuzzy_learn_session *s; @@ -908,8 +908,8 @@ register_fuzzy_controller_call (struct rspamd_http_connection_entry *entry, msec_to_tv (fuzzy_module_ctx->io_timeout, &s->tv); s->task = task; s->h = - rspamd_mempool_alloc (task->task_pool, sizeof (fuzzy_hash_t)); - memcpy (s->h, h, sizeof (fuzzy_hash_t)); + rspamd_mempool_alloc (task->task_pool, sizeof (rspamd_fuzzy_t)); + memcpy (s->h, h, sizeof (rspamd_fuzzy_t)); s->http_entry = entry; s->server = selected; s->cmd = cmd; @@ -947,7 +947,7 @@ fuzzy_process_rule (struct rspamd_http_connection_entry *entry, struct rspamd_image *image; GList *cur; gchar *checksum; - fuzzy_hash_t fake_fuzzy; + rspamd_fuzzy_t fake_fuzzy; gint processed = 0; /* Plan new event for writing */ diff --git a/src/plugins/spf.c b/src/plugins/spf.c index adc61e17c..bbb9b8a76 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -146,8 +146,8 @@ spf_module_config (struct rspamd_config *cfg) } if ((value = rspamd_config_get_module_opt (cfg, "spf", "whitelist")) != NULL) { - if (!add_map (cfg, ucl_obj_tostring (value), - "SPF whitelist", read_radix_list, fin_radix_list, + if (!rspamd_map_add (cfg, ucl_obj_tostring (value), + "SPF whitelist", rspamd_radix_read, rspamd_radix_fin, (void **)&spf_module_ctx->whitelist_ip)) { radix_add_generic_iplist (ucl_obj_tostring (value), &spf_module_ctx->whitelist_ip); diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 3c141256d..2fe35031a 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -90,7 +90,7 @@ exception_insert (gpointer st, gconstpointer key, gpointer value) GHashTable **t = st; gint level = 0; const gchar *p = key; - f_str_t *val; + rspamd_fstring_t *val; while (*p) { @@ -106,12 +106,12 @@ exception_insert (gpointer st, gconstpointer key, gpointer value) return; } - val = g_malloc (sizeof (f_str_t)); + val = g_malloc (sizeof (rspamd_fstring_t)); val->begin = (gchar *)key; val->len = strlen (key); if (t[level] == NULL) { - t[level] = g_hash_table_new_full (fstr_strcase_hash, - fstr_strcase_equal, + t[level] = g_hash_table_new_full (rspamd_fstring_hash, + rspamd_fstring_equal, g_free, NULL); } @@ -128,7 +128,7 @@ read_exceptions_list (rspamd_mempool_t * pool, data->cur_data = rspamd_mempool_alloc0 (pool, sizeof (GHashTable *) * MAX_LEVELS); } - return abstract_parse_list (pool, + return rspamd_parse_abstract_list (pool, chunk, len, data, @@ -217,7 +217,7 @@ read_redirectors_list (rspamd_mempool_t * pool, redirector_item_free); } - return abstract_parse_list (pool, + return rspamd_parse_abstract_list (pool, chunk, len, data, @@ -379,7 +379,7 @@ surbl_module_config (struct rspamd_config *cfg) if ((value = rspamd_config_get_module_opt (cfg, "surbl", "redirector_hosts_map")) != NULL) { - add_map (cfg, ucl_obj_tostring ( + rspamd_map_add (cfg, ucl_obj_tostring ( value), "SURBL redirectors list", read_redirectors_list, fin_redirectors_list, (void **)&surbl_module_ctx->redirector_hosts); @@ -394,7 +394,7 @@ surbl_module_config (struct rspamd_config *cfg) } if ((value = rspamd_config_get_module_opt (cfg, "surbl", "exceptions")) != NULL) { - if (add_map (cfg, ucl_obj_tostring (value), + if (rspamd_map_add (cfg, ucl_obj_tostring (value), "SURBL exceptions list", read_exceptions_list, fin_exceptions_list, (void **)&surbl_module_ctx->exceptions)) { surbl_module_ctx->tld2_file = rspamd_mempool_strdup ( @@ -404,8 +404,8 @@ surbl_module_config (struct rspamd_config *cfg) } if ((value = rspamd_config_get_module_opt (cfg, "surbl", "whitelist")) != NULL) { - if (add_map (cfg, ucl_obj_tostring (value), - "SURBL whitelist", read_host_list, fin_host_list, + if (rspamd_map_add (cfg, ucl_obj_tostring (value), + "SURBL whitelist", rspamd_hosts_read, rspamd_hosts_fin, (void **)&surbl_module_ctx->whitelist)) { surbl_module_ctx->whitelist_file = rspamd_mempool_strdup ( surbl_module_ctx->surbl_pool, @@ -571,7 +571,7 @@ surbl_module_reconfig (struct rspamd_config *cfg) static gchar * format_surbl_request (rspamd_mempool_t * pool, - f_str_t * hostname, + rspamd_fstring_t * hostname, struct suffix_item *suffix, gboolean append_suffix, GError ** err, @@ -585,7 +585,7 @@ format_surbl_request (rspamd_mempool_t * pool, gint len, slen, r, i, dots_num = 0, level = MAX_LEVELS; gboolean is_numeric = TRUE; guint64 ip_num; - f_str_t f; + rspamd_fstring_t f; if (G_LIKELY (suffix != NULL)) { slen = strlen (suffix->suffix); @@ -758,7 +758,7 @@ make_surbl_requests (struct uri *url, struct rspamd_task *task, struct suffix_item *suffix, gboolean forced, GTree *tree) { gchar *surbl_req; - f_str_t f; + rspamd_fstring_t f; GError *err = NULL; struct dns_param *param; @@ -1147,7 +1147,7 @@ write_urls_buffer (gpointer key, gpointer value, gpointer cbdata) { struct urls_tree_cb_data *cb = cbdata; struct uri *url = value; - f_str_t f; + rspamd_fstring_t f; gchar *urlstr; gsize len; diff --git a/src/smtp.c b/src/smtp.c index e66e5bbb7..343d1d557 100644 --- a/src/smtp.c +++ b/src/smtp.c @@ -83,7 +83,7 @@ call_stage_filters (struct smtp_session *session, enum rspamd_smtp_stage stage) } static gboolean -read_smtp_command (struct smtp_session *session, f_str_t *line) +read_smtp_command (struct smtp_session *session, rspamd_fstring_t *line) { struct smtp_command *cmd; gchar outbuf[BUFSIZ]; @@ -248,7 +248,7 @@ process_smtp_data (struct smtp_session *session) struct stat st; gint r; GList *cur, *t; - f_str_t *f; + rspamd_fstring_t *f; gchar *s; if (fstat (session->temp_fd, &st) == -1) { @@ -350,7 +350,7 @@ err: * Callback that is called when there is data to read in buffer */ static gboolean -smtp_read_socket (f_str_t * in, void *arg) +smtp_read_socket (rspamd_fstring_t * in, void *arg) { struct smtp_session *session = arg; @@ -996,7 +996,7 @@ start_smtp (struct rspamd_worker *worker) } /* Maps events */ - start_map_watch (worker->srv->cfg, ctx->ev_base); + rspamd_map_watch (worker->srv->cfg, ctx->ev_base); /* DNS resolver */ ctx->resolver = dns_resolver_init (ctx->ev_base, worker->srv->cfg); @@ -1006,7 +1006,7 @@ start_smtp (struct rspamd_worker *worker) event_base_loop (ctx->ev_base, 0); - close_log (rspamd_main->logger); + rspamd_log_close (rspamd_main->logger); exit (EXIT_SUCCESS); } diff --git a/src/smtp_proxy.c b/src/smtp_proxy.c index 2db126d37..efec0926e 100644 --- a/src/smtp_proxy.c +++ b/src/smtp_proxy.c @@ -732,7 +732,7 @@ smtp_dns_cb (struct rdns_reply *reply, void *arg) } static void -proxy_parse_smtp_input (f_str_t *line, struct smtp_proxy_session *session) +proxy_parse_smtp_input (rspamd_fstring_t *line, struct smtp_proxy_session *session) { gchar *p, *c, *end; gsize len; @@ -786,7 +786,7 @@ proxy_parse_smtp_input (f_str_t *line, struct smtp_proxy_session *session) * Callback that is called when there is data to read in buffer */ static gboolean -smtp_proxy_read_socket (f_str_t * in, void *arg) +smtp_proxy_read_socket (rspamd_fstring_t * in, void *arg) { struct smtp_proxy_session *session = arg; gchar *p; @@ -1079,7 +1079,7 @@ start_smtp_proxy (struct rspamd_worker *worker) event_base_loop (ctx->ev_base, 0); - close_log (rspamd_main->logger); + rspamd_log_close (rspamd_main->logger); exit (EXIT_SUCCESS); } diff --git a/src/tokenizers/osb.c b/src/tokenizers/osb.c index b74441eca..1ee251f81 100644 --- a/src/tokenizers/osb.c +++ b/src/tokenizers/osb.c @@ -37,14 +37,14 @@ extern const int primes[]; int osb_tokenize_text (struct tokenizer *tokenizer, rspamd_mempool_t * pool, - f_str_t * input, + rspamd_fstring_t * input, GTree ** tree, gboolean save_token, gboolean is_utf, GList *exceptions) { token_node_t *new = NULL; - f_str_t token = { NULL, 0, 0 }; + rspamd_fstring_t token = { NULL, 0, 0 }; guint32 hashpipe[FEATURE_WINDOW_SIZE], h1, h2; gint i, l, processed = 0; gchar *res; @@ -75,14 +75,14 @@ osb_tokenize_text (struct tokenizer *tokenizer, if (processed < FEATURE_WINDOW_SIZE) { /* Just fill a hashpipe */ hashpipe[FEATURE_WINDOW_SIZE - ++processed] = - fstrhash_lowercase (&token, is_utf); + rspamd_fstrhash_lc (&token, is_utf); } else { /* Shift hashpipe */ for (i = FEATURE_WINDOW_SIZE - 1; i > 0; i--) { hashpipe[i] = hashpipe[i - 1]; } - hashpipe[0] = fstrhash_lowercase (&token, is_utf); + hashpipe[0] = rspamd_fstrhash_lc (&token, is_utf); processed++; for (i = 1; i < FEATURE_WINDOW_SIZE; i++) { diff --git a/src/tokenizers/tokenizers.c b/src/tokenizers/tokenizers.c index 6598d66e8..4789d8f62 100644 --- a/src/tokenizers/tokenizers.c +++ b/src/tokenizers/tokenizers.c @@ -104,7 +104,7 @@ token_node_compare_func (gconstpointer a, gconstpointer b) /* Get next word from specified f_str_t buf */ gchar * -get_next_word (f_str_t * buf, f_str_t * token, GList **exceptions) +get_next_word (rspamd_fstring_t * buf, rspamd_fstring_t * token, GList **exceptions) { gsize remain, pos; guchar *p; @@ -195,8 +195,8 @@ tokenize_headers (rspamd_mempool_t * pool, GTree ** tree) { token_node_t *new = NULL; - f_str_t headername; - f_str_t headervalue; + rspamd_fstring_t headername; + rspamd_fstring_t headervalue; if (*tree == NULL) { *tree = g_tree_new (token_node_compare_func); @@ -215,8 +215,8 @@ tokenize_headers (rspamd_mempool_t * pool, headername.len = strlen (h->name); headervalue.begin = h->value; headervalue.len = strlen (h->value); - new->h1 = fstrhash (&headername) * primes[0]; - new->h2 = fstrhash (&headervalue) * primes[1]; + new->h1 = rspamd_fstrhash (&headername) * primes[0]; + new->h2 = rspamd_fstrhash (&headervalue) * primes[1]; if (g_tree_lookup (*tree, new) == NULL) { g_tree_insert (*tree, new, new); } @@ -241,8 +241,8 @@ tokenize_headers (rspamd_mempool_t * pool, headername.len = strlen (name); headervalue.begin = (u_char *)value; headervalue.len = strlen (value); - new->h1 = fstrhash (&headername) * primes[0]; - new->h2 = fstrhash (&headervalue) * primes[1]; + new->h1 = rspamd_fstrhash (&headername) * primes[0]; + new->h2 = rspamd_fstrhash (&headervalue) * primes[1]; if (g_tree_lookup (*tree, new) == NULL) { g_tree_insert (*tree, new, new); } @@ -259,7 +259,7 @@ tokenize_headers (rspamd_mempool_t * pool, void tokenize_subject (struct rspamd_task *task, GTree ** tree) { - f_str_t subject; + rspamd_fstring_t subject; const gchar *sub; struct tokenizer *osb_tokenizer; diff --git a/src/tokenizers/tokenizers.h b/src/tokenizers/tokenizers.h index 883f38058..b10729614 100644 --- a/src/tokenizers/tokenizers.h +++ b/src/tokenizers/tokenizers.h @@ -20,9 +20,9 @@ typedef struct token_node_s { struct tokenizer { gchar *name; gint (*tokenize_func)(struct tokenizer *tokenizer, rspamd_mempool_t *pool, - f_str_t *input, + rspamd_fstring_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); + gchar * (*get_next_word)(rspamd_fstring_t *buf, rspamd_fstring_t *token, GList **exceptions); }; /* Compare two token nodes */ @@ -30,11 +30,11 @@ int token_node_compare_func (gconstpointer a, gconstpointer b); /* Get tokenizer structure by name or return NULL if this name is not found */ struct tokenizer * get_tokenizer (const char *name); /* Get next word from specified f_str_t buf */ -gchar * get_next_word (f_str_t *buf, f_str_t *token, GList **exceptions); +gchar * get_next_word (rspamd_fstring_t *buf, rspamd_fstring_t *token, GList **exceptions); /* OSB tokenize function */ int osb_tokenize_text (struct tokenizer *tokenizer, rspamd_mempool_t *pool, - f_str_t *input, + rspamd_fstring_t *input, GTree **cur, gboolean save_token, gboolean is_utf, diff --git a/src/worker.c b/src/worker.c index aff9c1b00..62a129235 100644 --- a/src/worker.c +++ b/src/worker.c @@ -311,7 +311,7 @@ start_worker (struct rspamd_worker *worker) ctx->ev_base = rspamd_prepare_worker (worker, "normal", accept_socket); msec_to_tv (ctx->timeout, &ctx->io_tv); - start_map_watch (worker->srv->cfg, ctx->ev_base); + rspamd_map_watch (worker->srv->cfg, ctx->ev_base); ctx->resolver = dns_resolver_init (worker->srv->logger, @@ -339,7 +339,7 @@ start_worker (struct rspamd_worker *worker) event_base_loop (ctx->ev_base, 0); g_mime_shutdown (); - close_log (rspamd_main->logger); + rspamd_log_close (rspamd_main->logger); exit (EXIT_SUCCESS); } diff --git a/test/rspamd_fuzzy_test.c b/test/rspamd_fuzzy_test.c index 7bee03164..b1f1f5dcd 100644 --- a/test/rspamd_fuzzy_test.c +++ b/test/rspamd_fuzzy_test.c @@ -37,8 +37,8 @@ void rspamd_fuzzy_test_func () { rspamd_mempool_t *pool; - fuzzy_hash_t *h1, *h2, *h3, *h4, *h5; - f_str_t f1, f2, f3, f4, f5; + rspamd_fuzzy_t *h1, *h2, *h3, *h4, *h5; + rspamd_fstring_t f1, f2, f3, f4, f5; int diff2; pool = rspamd_mempool_new (1024); @@ -53,17 +53,17 @@ rspamd_fuzzy_test_func () f5.begin = s5; f5.len = strlen (s5); - h1 = fuzzy_init (&f1, pool); - h2 = fuzzy_init (&f2, pool); - h3 = fuzzy_init (&f3, pool); - h4 = fuzzy_init (&f4, pool); - h5 = fuzzy_init (&f5, pool); + h1 = rspamd_fuzzy_init (&f1, pool); + h2 = rspamd_fuzzy_init (&f2, pool); + h3 = rspamd_fuzzy_init (&f3, pool); + h4 = rspamd_fuzzy_init (&f4, pool); + h5 = rspamd_fuzzy_init (&f5, pool); - diff2 = fuzzy_compare_hashes (h2, h5); - msg_debug ("rspamd_fuzzy_test_func: s1, s2 difference between strings is %d", fuzzy_compare_hashes (h1, h2)); - msg_debug ("rspamd_fuzzy_test_func: s1, s3 difference between strings is %d", fuzzy_compare_hashes (h1, h3)); - msg_debug ("rspamd_fuzzy_test_func: s3, s4 difference between strings is %d", fuzzy_compare_hashes (h3, h4)); - msg_debug ("rspamd_fuzzy_test_func: s2, s4 difference between strings is %d", fuzzy_compare_hashes (h2, h4)); + diff2 = rspamd_fuzzy_compare (h2, h5); + msg_debug ("rspamd_fuzzy_test_func: s1, s2 difference between strings is %d", rspamd_fuzzy_compare (h1, h2)); + msg_debug ("rspamd_fuzzy_test_func: s1, s3 difference between strings is %d", rspamd_fuzzy_compare (h1, h3)); + msg_debug ("rspamd_fuzzy_test_func: s3, s4 difference between strings is %d", rspamd_fuzzy_compare (h3, h4)); + msg_debug ("rspamd_fuzzy_test_func: s2, s4 difference between strings is %d", rspamd_fuzzy_compare (h2, h4)); msg_debug ("rspamd_fuzzy_test_func: s2, s5 difference between strings is %d", diff2); /* Identical strings */ diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c index 1d78fac49..61fde350a 100644 --- a/test/rspamd_test_suite.c +++ b/test/rspamd_test_suite.c @@ -40,7 +40,7 @@ main (int argc, char **argv) cfg->log_type = RSPAMD_LOG_CONSOLE; /* First set logger to console logger */ rspamd_set_logger (cfg, g_quark_from_static_string("rspamd-test"), rspamd_main); - (void)open_log (rspamd_main->logger); + (void)rspamd_log_open (rspamd_main->logger); g_log_set_default_handler (rspamd_glib_log_function, rspamd_main->logger); g_test_add_func ("/rspamd/mem_pool", rspamd_mem_pool_test_func); -- 2.39.5