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;
}
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'",
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);
}
gint32 value;
gint32 flag;
guint64 time;
- fuzzy_hash_t h;
+ rspamd_fuzzy_t h;
};
struct fuzzy_session {
continue;
}
- (void) lock_file (fd, FALSE);
+ (void) rspamd_file_lock (fd, FALSE);
now = (guint64) time (NULL );
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);
struct {
gint32 value;
guint64 time;
- fuzzy_hash_t h;
+ rspamd_fuzzy_t h;
} legacy_node;
if (server_stat->fuzzy_hashes != 0) {
return FALSE;
}
- (void)lock_file (fd, FALSE);
+ (void)rspamd_file_lock (fd, FALSE);
fstat (fd, &st);
}
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 {
}
}
- (void)unlock_file (fd, FALSE);
+ (void)rspamd_file_unlock (fd, FALSE);
close (fd);
if (r > 0) {
}
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;
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;
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;
guint64 time,
struct rspamd_fuzzy_storage_ctx *ctx)
{
- fuzzy_hash_t s;
+ rspamd_fuzzy_t s;
struct rspamd_fuzzy_node *h;
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));
}
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;
/* 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);
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)) {
/* 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'",
}
/* 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,
g_thread_join (ctx->update_thread);
}
- close_log (rspamd_main->logger);
+ rspamd_log_close (rspamd_main->logger);
exit (EXIT_SUCCESS);
}
* 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;
}
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;
* 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;
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);
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);
}
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);
}
else if (do_reopen_log == 1) {
do_reopen_log = 0;
- reopen_log (rspamd_main->logger);
+ rspamd_log_reopen (rspamd_main->logger);
}
}
}
#endif
destroy_kvstorage_config ();
- close_log (rspamd_main->logger);
+ rspamd_log_close (rspamd_main->logger);
exit (EXIT_SUCCESS);
}
}
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%%",
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;
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 (
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;
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 (
{
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;
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 (
}
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);
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);
}
}
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 {
gboolean
parse_smtp_command (struct smtp_session *session,
- f_str_t *line,
+ rspamd_fstring_t *line,
struct smtp_command **cmd)
{
enum {
} 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) {
}
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;
}
static gboolean
-check_smtp_path (f_str_t *path)
+check_smtp_path (rspamd_fstring_t *path)
{
guint i;
gchar *p;
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;
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) {
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) {
/* 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;
{
GList *cur = args;
size_t r = 0;
- f_str_t *arg;
+ rspamd_fstring_t *arg;
while (cur && r < buflen - 3) {
arg = cur->data;
}
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];
* 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);
/*
/*
* 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
};
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",
log->filename,
errno,
strerror (errno));
- unlock_file (log->fd, FALSE);
+ rspamd_file_unlock (log->fd, FALSE);
return FALSE;
}
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;
}
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));
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,
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;
}
{
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));
}
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,
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));
}
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;
}
gchar *backup_name;
struct stat st;
- lock_file (log->fd, FALSE);
+ rspamd_file_lock (log->fd, FALSE);
/* Unmap mapped fragments */
if (log->metaindex) {
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);
}
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,
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,
res = FALSE;
goto end;
}
- unlock_file (log->fd, FALSE);
+ rspamd_file_unlock (log->fd, FALSE);
}
else {
idxb = log->cur_idx;
{
ssize_t r;
GError *err = NULL;
- f_str_t res;
+ rspamd_fstring_t res;
gchar *c, *b;
gchar *end;
size_t len;
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;
}
enum io_policy policy,
size_t nchars)
{
- f_str_t *tmp;
+ rspamd_fstring_t *tmp;
gint t;
if (d->policy != policy || nchars != d->nchars) {
/* 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;
}
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;
#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);
* 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;
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);
cbdata->cfg = cfg;
*pcbdata = cbdata;
- return add_map (cfg,
+ return rspamd_map_add (cfg,
map_line,
"ucl include",
rspamd_ucl_read_cb,
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);
}
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,
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",
}
}
/* 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;
}
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")];
}
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;
}
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];
}
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);
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);
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
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);
addr->slen = len;
addr->af = addr->addr.sa.sa_family;
- if (make_socket_nonblocking (nfd) < 0) {
+ if (rspamd_socket_nonblocking (nfd) < 0) {
goto out;
}
}
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);
}
}
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;
}
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 -
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;
* 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_ */
* 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;
* 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;
* 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;
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;
* 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;
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))) {
* 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;
* 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;
* 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;
* 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);
* 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 */
* 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) {
/*
* 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);
/*
* 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);
/*
* 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;
}
/*
* 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;
}
* Return hash value for a string
*/
guint32
-fstrhash (f_str_t * str)
+rspamd_fstrhash (rspamd_fstring_t * str)
{
size_t i;
guint32 hval;
* 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;
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));
}
void
-fstrstrip (f_str_t * str)
+rspamd_fstrstrip (rspamd_fstring_t * str)
{
gchar *p = str->begin;
guint r = 0;
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
/*
* 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
/* 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);
}
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);
* 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 */
}
/* 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) {
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;
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;
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;
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);
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++;
/* 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;
}
}
- 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);
}
}
}
gint
-rspamd_fuzzy_len (fuzzy_hash_t *h)
+rspamd_fuzzy_len (rspamd_fuzzy_t *h)
{
gint len;
void *nullpos;
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);
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),
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;
* @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
* @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);
* @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);
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);
/* 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:
}
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:
}
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;
}
* 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);
}
/*
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);
* 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;
* 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 ==
/* 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 {
/**
* 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
*/
{
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,
/* 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;
}
void
-remove_all_maps (struct rspamd_config *cfg)
+rspamd_map_remove_all (struct rspamd_config *cfg)
{
g_list_free (cfg->maps);
cfg->maps = NULL;
}
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) {
}
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,
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 */
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,
}
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,
/* 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)
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,
}
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);
}
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)
}
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);
}
gchar *
-read_radix_list (rspamd_mempool_t * pool,
+rspamd_radix_read (rspamd_mempool_t * pool,
gchar * chunk,
gint len,
struct map_cb_data *data)
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,
}
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);
/**
* 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,
/**
* 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);
/**
* 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,
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;
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;
#define CONNECT_TIMEOUT 3
gint
-make_socket_nonblocking (gint fd)
+rspamd_socket_nonblocking (gint fd)
{
gint ofl;
}
gint
-make_socket_blocking (gint fd)
+rspamd_socket_blocking (gint fd)
{
gint ofl;
}
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];
return -1;
}
if (async) {
- if (make_socket_nonblocking (fd) == -1) {
+ if (rspamd_socket_nonblocking (fd) == -1) {
close (fd);
return -1;
}
}
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");
}
else {
/* Make synced again */
- if (make_socket_blocking (fd) < 0) {
+ if (rspamd_socket_blocking (fd) < 0) {
goto 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,
return -1;
}
- if (make_socket_nonblocking (fd) < 0) {
+ if (rspamd_socket_nonblocking (fd) < 0) {
goto out;
}
}
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;
}
}
* @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;
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);
return -1;
}
else {
- return make_unix_socket (credits,
+ return rspamd_socket_unix (credits,
&un,
type,
is_server,
* @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;
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);
goto err;
}
else {
- fd = make_unix_socket (credits,
+ fd = rspamd_socket_unix (credits,
&un,
type,
is_server,
}
gint
-make_socketpair (gint pair[2])
+rspamd_socketpair (gint pair[2])
{
gint r;
}
gint
-write_pid (struct rspamd_main *main)
+rspamd_write_pid (struct rspamd_main *main)
{
pid_t pid;
#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;
}
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);
* 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;
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;
}
}
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;
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];
#ifdef HAVE_FLOCK
/* Flock version */
gboolean
-lock_file (gint fd, gboolean async)
+rspamd_file_lock (gint fd, gboolean async)
{
gint flags;
}
gboolean
-unlock_file (gint fd, gboolean async)
+rspamd_file_unlock (gint fd, gboolean async)
{
gint flags;
#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,
}
gboolean
-unlock_file (gint fd, gboolean async)
+rspamd_file_unlock (gint fd, gboolean async)
{
struct flock fl = {
.l_type = F_UNLCK,
/* 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;
}
gint
-compare_url_func (gconstpointer a, gconstpointer b)
+rspamd_urls_cmp (gconstpointer a, gconstpointer b)
{
const struct uri *u1 = a, *u2 = b;
int r;
/*
* 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,
* @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);
/**
* @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,
/*
* 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
/*
/*
* 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
/*
* 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
#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
{
struct rspamd_worker *worker = (struct rspamd_worker *) arg;
- reopen_log (worker->srv->logger);
+ rspamd_log_reopen (worker->srv->logger);
return;
}
* 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;
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 */
#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
};
* 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;
}
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,
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,
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,
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,
"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;
/* 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;
};
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,
}
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;
}
* 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,
}
.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;
}
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,
* @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
/* 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;
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);
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);
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);
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);
struct in_addr ina;
gchar *reqline;
guint16 port;
- f_str_t *args;
+ rspamd_fstring_t *args;
guint args_num;
};
/* 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 */
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
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;
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,
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);
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;
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;
}
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) {
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;
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;
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;
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);
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;
}
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;
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);
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;
}
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 &&
}
/* 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);
luaL_unref (L, LUA_REGISTRYINDEX, ctx->cbref_fin);
}
- close_log (rspamd_main->logger);
+ rspamd_log_close (rspamd_main->logger);
exit (EXIT_SUCCESS);
}
}
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);
}
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 */
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 */
/* 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);
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);
}
(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);
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) {
}
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,
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);
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 */
}
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);
}
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));
struct fuzzy_client_session {
gint state;
- fuzzy_hash_t *h;
+ rspamd_fuzzy_t *h;
struct event ev;
struct timeval tv;
struct rspamd_task *task;
struct fuzzy_learn_session {
struct event ev;
- fuzzy_hash_t *h;
+ rspamd_fuzzy_t *h;
gint cmd;
gint value;
gint flag;
}
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;
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);
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;
gchar *checksum;
gsize hashlen;
GList *cur;
- fuzzy_hash_t *fake_fuzzy;
+ rspamd_fuzzy_t *fake_fuzzy;
cur = task->text_parts;
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);
/* 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);
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;
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;
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 */
}
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);
GHashTable **t = st;
gint level = 0;
const gchar *p = key;
- f_str_t *val;
+ rspamd_fstring_t *val;
while (*p) {
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);
}
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,
redirector_item_free);
}
- return abstract_parse_list (pool,
+ return rspamd_parse_abstract_list (pool,
chunk,
len,
data,
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);
}
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 (
}
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,
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,
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);
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;
{
struct urls_tree_cb_data *cb = cbdata;
struct uri *url = value;
- f_str_t f;
+ rspamd_fstring_t f;
gchar *urlstr;
gsize len;
}
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];
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) {
* 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;
}
/* 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);
event_base_loop (ctx->ev_base, 0);
- close_log (rspamd_main->logger);
+ rspamd_log_close (rspamd_main->logger);
exit (EXIT_SUCCESS);
}
}
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;
* 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;
event_base_loop (ctx->ev_base, 0);
- close_log (rspamd_main->logger);
+ rspamd_log_close (rspamd_main->logger);
exit (EXIT_SUCCESS);
}
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;
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++) {
/* 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;
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);
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);
}
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);
}
void
tokenize_subject (struct rspamd_task *task, GTree ** tree)
{
- f_str_t subject;
+ rspamd_fstring_t subject;
const gchar *sub;
struct tokenizer *osb_tokenizer;
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 */
/* 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,
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,
event_base_loop (ctx->ev_base, 0);
g_mime_shutdown ();
- close_log (rspamd_main->logger);
+ rspamd_log_close (rspamd_main->logger);
exit (EXIT_SUCCESS);
}
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);
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 */
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);