diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-07-23 12:53:08 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-07-23 12:53:08 +0100 |
commit | fe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b (patch) | |
tree | c84e6a5d4c5cd78a7a2cc3c7adbc7af5d0541682 /src/libutil/map.c | |
parent | e0483657ff6cf1adc828ccce457814d61fe90a0d (diff) | |
download | rspamd-fe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b.tar.gz rspamd-fe79d8c5a39f2b717f78cc3f3ef21b3cfc46500b.zip |
Revert "Unify code style."
This reverts commit e0483657ff6cf1adc828ccce457814d61fe90a0d.
Diffstat (limited to 'src/libutil/map.c')
-rw-r--r-- | src/libutil/map.c | 384 |
1 files changed, 137 insertions, 247 deletions
diff --git a/src/libutil/map.c b/src/libutil/map.c index 21612ddfb..ffe3a1e6f 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -26,33 +26,33 @@ * Implementation of map files handling */ #include "config.h" +#include "map.h" #include "http.h" #include "main.h" -#include "map.h" -#include "mem_pool.h" #include "util.h" +#include "mem_pool.h" -static const gchar *hash_fill = "1"; +static const gchar *hash_fill = "1"; /* Http reply */ struct http_reply { - gint code; - GHashTable *headers; - gchar *cur_header; - gint parser_state; + gint code; + GHashTable *headers; + gchar *cur_header; + gint parser_state; }; struct http_callback_data { - struct event ev; - struct event_base *ev_base; - struct timeval tv; - struct rspamd_map *map; - struct http_map_data *data; - struct http_reply *reply; - struct map_cb_data cbdata; - - gint state; - gint fd; + struct event ev; + struct event_base *ev_base; + struct timeval tv; + struct rspamd_map *map; + struct http_map_data *data; + struct http_reply *reply; + struct map_cb_data cbdata; + + gint state; + gint fd; }; /* Value in seconds after whitch we would try to do stat on list file */ @@ -65,17 +65,12 @@ struct http_callback_data { * Helper for HTTP connection establishment */ static gint -connect_http (struct rspamd_map *map, - struct http_map_data *data, - gboolean is_async) +connect_http (struct rspamd_map *map, struct http_map_data *data, gboolean is_async) { - gint sock; + gint sock; if ((sock = make_tcp_socket (data->addr, FALSE, is_async)) == -1) { - msg_info ("cannot connect to http server %s: %d, %s", - data->host, - errno, - strerror (errno)); + msg_info ("cannot connect to http server %s: %d, %s", data->host, errno, strerror (errno)); return -1; } @@ -86,27 +81,17 @@ connect_http (struct rspamd_map *map, * Write HTTP request */ static void -write_http_request (struct rspamd_map *map, - struct http_map_data *data, - gint sock) +write_http_request (struct rspamd_map *map, struct http_map_data *data, gint sock) { - gchar outbuf[BUFSIZ], datebuf[128]; - gint r; - struct tm *tm; + gchar outbuf[BUFSIZ], datebuf[128]; + gint r; + struct tm *tm; tm = gmtime (&data->last_checked); strftime (datebuf, sizeof (datebuf), "%a, %d %b %Y %H:%M:%S %Z", tm); - r = rspamd_snprintf (outbuf, - sizeof (outbuf), - "GET %s%s HTTP/1.1" CRLF "Connection: close" CRLF "Host: %s" CRLF, - (*data->path == '/') ? "" : "/", - data->path, - data->host); + r = rspamd_snprintf (outbuf, sizeof (outbuf), "GET %s%s HTTP/1.1" CRLF "Connection: close" CRLF "Host: %s" CRLF, (*data->path == '/') ? "" : "/", data->path, data->host); if (data->last_checked != 0) { - r += rspamd_snprintf (outbuf + r, - sizeof (outbuf) - r, - "If-Modified-Since: %s" CRLF, - datebuf); + r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, "If-Modified-Since: %s" CRLF, datebuf); } r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r, CRLF); @@ -119,16 +104,16 @@ write_http_request (struct rspamd_map *map, /** * FSM for parsing HTTP reply */ -static gchar * +static gchar * parse_http_reply (gchar * chunk, gint len, struct http_reply *reply) { - gchar *s, *p, *err_str, *tmp; + gchar *s, *p, *err_str, *tmp; p = chunk; s = chunk; while (p - chunk < len) { switch (reply->parser_state) { - /* Search status code */ + /* Search status code */ case 0: /* Search for status code */ if (*p != ' ') { @@ -146,7 +131,7 @@ parse_http_reply (gchar * chunk, gint len, struct http_reply *reply) continue; } break; - /* Skip to end of line */ + /* Skip to end of line */ case 1: if (*p == '\n') { /* Switch to read header state */ @@ -155,7 +140,7 @@ parse_http_reply (gchar * chunk, gint len, struct http_reply *reply) /* Each skipped symbol is proceeded */ s = ++p; break; - /* Read header value */ + /* Read header value */ case 2: if (*p == ':') { reply->cur_header = g_malloc (p - s + 1); @@ -168,7 +153,7 @@ parse_http_reply (gchar * chunk, gint len, struct http_reply *reply) } p++; break; - /* Skip spaces after header name */ + /* Skip spaces after header name */ case 3: if (*p != ' ') { s = p; @@ -178,14 +163,13 @@ parse_http_reply (gchar * chunk, gint len, struct http_reply *reply) p++; } break; - /* Read header value */ + /* Read header value */ case 4: if (*p == '\r') { if (reply->cur_header != NULL) { tmp = g_malloc (p - s + 1); rspamd_strlcpy (tmp, s, p - s + 1); - g_hash_table_insert (reply->headers, reply->cur_header, - tmp); + g_hash_table_insert (reply->headers, reply->cur_header, tmp); reply->cur_header = NULL; } reply->parser_state = 1; @@ -214,14 +198,13 @@ parse_http_reply (gchar * chunk, gint len, struct http_reply *reply) static gint read_chunk_header (gchar * buf, gint len, struct http_map_data *data) { - gchar chunkbuf[32], *p, *c, *err_str; - gint skip = 0; + gchar chunkbuf[32], *p, *c, *err_str; + gint skip = 0; p = chunkbuf; c = buf; /* Find hex digits */ - while (g_ascii_isxdigit (*c) && p - chunkbuf < - (gint)(sizeof (chunkbuf) - 1) && skip < len) { + while (g_ascii_isxdigit (*c) && p - chunkbuf < (gint)(sizeof (chunkbuf) - 1) && skip < len) { *p++ = *c++; skip++; } @@ -248,15 +231,11 @@ read_chunk_header (gchar * buf, gint len, struct http_map_data *data) /** * Helper callback for reading chunked reply */ -static gboolean -read_http_chunked (gchar * buf, - size_t len, - struct rspamd_map *map, - struct http_map_data *data, - struct map_cb_data *cbdata) +static gboolean +read_http_chunked (gchar * buf, size_t len, struct rspamd_map *map, struct http_map_data *data, struct map_cb_data *cbdata) { - gchar *p = buf, *remain; - gint skip = 0; + gchar *p = buf, *remain; + gint skip = 0; if (data->chunked == 1) { /* Read first chunk data */ @@ -322,20 +301,14 @@ read_http_chunked (gchar * buf, /** * Callback for reading HTTP reply */ -static gboolean -read_http_common (struct rspamd_map *map, - struct http_map_data *data, - struct http_reply *reply, - struct map_cb_data *cbdata, - gint fd) +static gboolean +read_http_common (struct rspamd_map *map, struct http_map_data *data, struct http_reply *reply, struct map_cb_data *cbdata, gint fd) { - gchar *remain, *pos; - ssize_t r; - gchar *te, *date; - - if ((r = - read (fd, data->read_buf + data->rlen, sizeof (data->read_buf) - - data->rlen)) > 0) { + gchar *remain, *pos; + ssize_t r; + gchar *te, *date; + + if ((r = read (fd, data->read_buf + data->rlen, sizeof (data->read_buf) - data->rlen)) > 0) { r += data->rlen; data->rlen = 0; remain = parse_http_reply (data->read_buf, r, reply); @@ -352,9 +325,7 @@ read_http_common (struct rspamd_map *map, if (reply->parser_state == 6) { /* If reply header is parsed successfully, try to read further data */ if (reply->code != 200 && reply->code != 304) { - msg_err ("got error reply from server %s, %d", - data->host, - reply->code); + msg_err ("got error reply from server %s, %d", data->host, reply->code); return FALSE; } else if (reply->code == 304) { @@ -364,9 +335,7 @@ read_http_common (struct rspamd_map *map, pos = data->read_buf; /* Check for chunked */ if (data->chunked == 0) { - if ((te = - g_hash_table_lookup (reply->headers, - "Transfer-Encoding")) != NULL) { + if ((te = g_hash_table_lookup (reply->headers, "Transfer-Encoding")) != NULL) { if (g_ascii_strcasecmp (te, "chunked") == 0) { data->chunked = 1; } @@ -412,9 +381,9 @@ read_http_common (struct rspamd_map *map, static void read_http_sync (struct rspamd_map *map, struct http_map_data *data) { - struct map_cb_data cbdata; - gint fd; - struct http_reply *repl; + struct map_cb_data cbdata; + gint fd; + struct http_reply *repl; if (map->read_callback == NULL || map->fin_callback == NULL) { msg_err ("bad callback for reading map file"); @@ -435,12 +404,9 @@ read_http_sync (struct rspamd_map *map, struct http_map_data *data) repl = g_malloc (sizeof (struct http_reply)); repl->parser_state = 0; repl->code = 404; - repl->headers = g_hash_table_new_full (rspamd_strcase_hash, - rspamd_strcase_equal, - g_free, - g_free); + repl->headers = g_hash_table_new_full (rspamd_strcase_hash, rspamd_strcase_equal, g_free, g_free); - while (read_http_common (map, data, repl, &cbdata, fd)) ; + while (read_http_common (map, data, repl, &cbdata, fd)); close (fd); @@ -460,10 +426,10 @@ read_http_sync (struct rspamd_map *map, struct http_map_data *data) static void read_map_file (struct rspamd_map *map, struct file_map_data *data) { - struct map_cb_data cbdata; - gchar buf[BUFSIZ], *remain; - ssize_t r; - gint fd, rlen; + struct map_cb_data cbdata; + gchar buf[BUFSIZ], *remain; + ssize_t r; + gint fd, rlen; if (map->read_callback == NULL || map->fin_callback == NULL) { msg_err ("bad callback for reading map file"); @@ -471,8 +437,7 @@ read_map_file (struct rspamd_map *map, struct file_map_data *data) } if ((fd = open (data->filename, O_RDONLY)) == -1) { - msg_warn ("cannot open file '%s': %s", data->filename, - strerror (errno)); + msg_warn ("cannot open file '%s': %s", data->filename, strerror (errno)); return; } @@ -502,14 +467,10 @@ read_map_file (struct rspamd_map *map, struct file_map_data *data) /** * FSM for parsing lists */ -gchar * -abstract_parse_kv_list (rspamd_mempool_t * pool, - gchar * chunk, - gint len, - struct map_cb_data *data, - insert_func func) +gchar * +abstract_parse_kv_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data, insert_func func) { - gchar *c, *p, *key = NULL, *value = NULL; + gchar *c, *p, *key = NULL, *value = NULL; p = chunk; c = p; @@ -565,7 +526,7 @@ abstract_parse_kv_list (rspamd_mempool_t * pool, } } else { - p++; + p ++; } break; case 2: @@ -575,7 +536,7 @@ abstract_parse_kv_list (rspamd_mempool_t * pool, data->state = 0; } else { - p++; + p ++; } break; case 99: @@ -596,7 +557,7 @@ abstract_parse_kv_list (rspamd_mempool_t * pool, case 100: /* Skip \r\n and whitespaces */ if (*p == '\r' || *p == '\n' || g_ascii_isspace (*p)) { - p++; + p ++; } else { c = p; @@ -610,14 +571,10 @@ abstract_parse_kv_list (rspamd_mempool_t * pool, return c; } -gchar * -abstract_parse_list (rspamd_mempool_t * pool, - gchar * chunk, - gint len, - struct map_cb_data *data, - insert_func func) +gchar * +abstract_parse_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data, insert_func func) { - gchar *s, *p, *str, *start; + gchar *s, *p, *str, *start; p = chunk; start = p; @@ -627,7 +584,7 @@ abstract_parse_list (rspamd_mempool_t * pool, while (p - chunk < len) { switch (data->state) { - /* READ_SYMBOL */ + /* READ_SYMBOL */ case 0: if (*p == '#') { /* Got comment */ @@ -666,7 +623,7 @@ abstract_parse_list (rspamd_mempool_t * pool, p++; } break; - /* SKIP_COMMENT */ + /* SKIP_COMMENT */ case 1: /* Skip comment till end of line */ if (*p == '\r' || *p == '\n') { @@ -695,13 +652,13 @@ abstract_parse_list (rspamd_mempool_t * pool, static void radix_tree_insert_helper (gpointer st, gconstpointer key, gpointer value) { - radix_tree_t *tree = st; + radix_tree_t *tree = st; - guint32 mask = 0xFFFFFFFF; - guint32 ip; - gchar *token, *ipnet, *err_str, **strv, **cur; - struct in_addr ina; - gint k; + guint32 mask = 0xFFFFFFFF; + guint32 ip; + gchar *token, *ipnet, *err_str, **strv, **cur; + struct in_addr ina; + gint k; /* Split string if there are multiple items inside a single string */ strv = g_strsplit_set ((gchar *)key, " ,;", 0); @@ -720,10 +677,7 @@ radix_tree_insert_helper (gpointer st, gconstpointer key, gpointer value) /* Get mask */ k = strtoul (ipnet, &err_str, 10); if (errno != 0) { - msg_warn ( - "invalid netmask, error detected on symbol: %s, erorr: %s", - err_str, - strerror (errno)); + msg_warn ("invalid netmask, error detected on symbol: %s, erorr: %s", err_str, strerror (errno)); k = 32; } else if (k > 32 || k < 0) { @@ -744,12 +698,10 @@ radix_tree_insert_helper (gpointer st, gconstpointer key, gpointer value) ip = ntohl ((guint32) ina.s_addr); k = radix32tree_insert (tree, ip, mask, 1); if (k == -1) { - msg_warn ("cannot insert ip to tree: %s, mask %X", inet_ntoa ( - ina), mask); + msg_warn ("cannot insert ip to tree: %s, mask %X", inet_ntoa (ina), mask); } else if (k == 1) { - msg_warn ("ip %s, mask %X, value already exists", inet_ntoa ( - ina), mask); + msg_warn ("ip %s, mask %X, value already exists", inet_ntoa (ina), mask); } cur++; } @@ -758,21 +710,13 @@ radix_tree_insert_helper (gpointer st, gconstpointer key, gpointer value) } /* Helpers */ -gchar * -read_host_list (rspamd_mempool_t * pool, - gchar * chunk, - gint len, - struct map_cb_data *data) +gchar * +read_host_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { if (data->cur_data == NULL) { - data->cur_data = g_hash_table_new (rspamd_strcase_hash, - rspamd_strcase_equal); + data->cur_data = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); } - return abstract_parse_list (pool, - chunk, - len, - data, - (insert_func) g_hash_table_insert); + return abstract_parse_list (pool, chunk, len, data, (insert_func) g_hash_table_insert); } void @@ -783,21 +727,13 @@ fin_host_list (rspamd_mempool_t * pool, struct map_cb_data *data) } } -gchar * -read_kv_list (rspamd_mempool_t * pool, - gchar * chunk, - gint len, - struct map_cb_data *data) +gchar * +read_kv_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { if (data->cur_data == NULL) { - data->cur_data = g_hash_table_new (rspamd_strcase_hash, - rspamd_strcase_equal); + data->cur_data = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal); } - return abstract_parse_kv_list (pool, - chunk, - len, - data, - (insert_func) g_hash_table_insert); + return abstract_parse_kv_list (pool, chunk, len, data, (insert_func) g_hash_table_insert); } void @@ -808,20 +744,13 @@ fin_kv_list (rspamd_mempool_t * pool, struct map_cb_data *data) } } -gchar * -read_radix_list (rspamd_mempool_t * pool, - gchar * chunk, - gint len, - struct map_cb_data *data) +gchar * +read_radix_list (rspamd_mempool_t * pool, gchar * chunk, gint len, struct map_cb_data *data) { if (data->cur_data == NULL) { data->cur_data = radix_tree_create (); } - return abstract_parse_list (pool, - chunk, - len, - data, - (insert_func) radix_tree_insert_helper); + return abstract_parse_list (pool, chunk, len, data, (insert_func) radix_tree_insert_helper); } void @@ -838,28 +767,24 @@ fin_radix_list (rspamd_mempool_t * pool, struct map_cb_data *data) static void file_callback (gint fd, short what, void *ud) { - struct rspamd_map *map = ud; - struct file_map_data *data = map->map_data; - struct stat st; - gdouble jittered_sec; + struct rspamd_map *map = ud; + struct file_map_data *data = map->map_data; + struct stat st; + gdouble jittered_sec; /* Plan event again with jitter */ evtimer_del (&map->ev); - jittered_sec = - (map->cfg->map_timeout + g_random_double () * map->cfg->map_timeout); + jittered_sec = (map->cfg->map_timeout + g_random_double () * map->cfg->map_timeout); double_to_tv (jittered_sec, &map->tv); evtimer_add (&map->ev, &map->tv); if (g_atomic_int_get (map->locked)) { - msg_info ( - "don't try to reread map as it is locked by other process, will reread it later"); + msg_info ("don't try to reread map as it is locked by other process, will reread it later"); return; } - if (stat (data->filename, - &st) != -1 && - (st.st_mtime > data->st.st_mtime || data->st.st_mtime == -1)) { + if (stat (data->filename, &st) != -1 && (st.st_mtime > data->st.st_mtime || data->st.st_mtime == -1)) { /* File was modified since last check */ memcpy (&data->st, &st, sizeof (struct stat)); } @@ -893,7 +818,7 @@ free_http_cbdata (struct http_callback_data *cbd) static void http_async_callback (gint fd, short what, void *ud) { - struct http_callback_data *cbd = ud; + struct http_callback_data *cbd = ud; /* Begin of connection */ if (what == EV_WRITE) { @@ -901,11 +826,7 @@ http_async_callback (gint fd, short what, void *ud) /* Can write request */ write_http_request (cbd->map, cbd->data, fd); /* Plan reading */ - event_set (&cbd->ev, - cbd->fd, - EV_READ | EV_PERSIST, - http_async_callback, - cbd); + event_set (&cbd->ev, cbd->fd, EV_READ | EV_PERSIST, http_async_callback, cbd); event_base_set (cbd->ev_base, &cbd->ev); cbd->tv.tv_sec = HTTP_READ_TIMEOUT; cbd->tv.tv_usec = 0; @@ -914,10 +835,7 @@ http_async_callback (gint fd, short what, void *ud) cbd->reply = g_malloc (sizeof (struct http_reply)); cbd->reply->parser_state = 0; cbd->reply->code = 404; - cbd->reply->headers = g_hash_table_new_full (rspamd_strcase_hash, - rspamd_strcase_equal, - g_free, - g_free); + cbd->reply->headers = g_hash_table_new_full (rspamd_strcase_hash, rspamd_strcase_equal, g_free, g_free); cbd->cbdata.state = 0; cbd->cbdata.prev_data = *cbd->map->user_data; cbd->cbdata.cur_data = NULL; @@ -939,15 +857,13 @@ http_async_callback (gint fd, short what, void *ud) /* Got reply, parse it */ else if (what == EV_READ) { if (cbd->state >= 1) { - if (!read_http_common (cbd->map, cbd->data, cbd->reply, - &cbd->cbdata, cbd->fd)) { + if (!read_http_common (cbd->map, cbd->data, cbd->reply, &cbd->cbdata, cbd->fd)) { /* Handle Not-Modified in a special way */ if (cbd->reply->code == 304) { if (cbd->data->last_checked == (time_t)-1) { cbd->data->last_checked = time (NULL); } - msg_info ("data is not modified for server %s", - cbd->data->host); + msg_info ("data is not modified for server %s", cbd->data->host); } else if (cbd->cbdata.cur_data != NULL) { /* Destroy old data and start reading request data */ @@ -984,22 +900,20 @@ http_async_callback (gint fd, short what, void *ud) static void http_callback (gint fd, short what, void *ud) { - struct rspamd_map *map = ud; - struct http_map_data *data = map->map_data; - gint sock; - struct http_callback_data *cbd; - gdouble jittered_sec; + struct rspamd_map *map = ud; + struct http_map_data *data = map->map_data; + gint sock; + struct http_callback_data *cbd; + gdouble jittered_sec; /* Plan event again with jitter */ evtimer_del (&map->ev); - jittered_sec = - (map->cfg->map_timeout + g_random_double () * map->cfg->map_timeout); + jittered_sec = (map->cfg->map_timeout + g_random_double () * map->cfg->map_timeout); double_to_tv (jittered_sec, &map->tv); evtimer_add (&map->ev, &map->tv); if (g_atomic_int_get (map->locked)) { - msg_info ( - "don't try to reread map as it is locked by other process, will reread it later"); + msg_info ("don't try to reread map as it is locked by other process, will reread it later"); return; } @@ -1031,10 +945,10 @@ http_callback (gint fd, short what, void *ud) void start_map_watch (struct rspamd_config *cfg, struct event_base *ev_base) { - GList *cur = cfg->maps; - struct rspamd_map *map; - struct file_map_data *fdata; - gdouble jittered_sec; + GList *cur = cfg->maps; + struct rspamd_map *map; + struct file_map_data *fdata; + gdouble jittered_sec; /* First of all do synced read of data */ while (cur) { @@ -1050,9 +964,7 @@ start_map_watch (struct rspamd_config *cfg, struct event_base *ev_base) read_map_file (map, map->map_data); } /* Plan event with jitter */ - jittered_sec = - (map->cfg->map_timeout + g_random_double () * - map->cfg->map_timeout) / 2.; + jittered_sec = (map->cfg->map_timeout + g_random_double () * map->cfg->map_timeout) / 2.; double_to_tv (jittered_sec, &map->tv); evtimer_add (&map->ev, &map->tv); } @@ -1062,9 +974,7 @@ start_map_watch (struct rspamd_config *cfg, struct event_base *ev_base) /* Read initial data */ read_http_sync (map, map->map_data); /* Plan event with jitter */ - jittered_sec = - (map->cfg->map_timeout + g_random_double () * - map->cfg->map_timeout); + jittered_sec = (map->cfg->map_timeout + g_random_double () * map->cfg->map_timeout); double_to_tv (jittered_sec, &map->tv); evtimer_add (&map->ev, &map->tv); } @@ -1072,7 +982,7 @@ start_map_watch (struct rspamd_config *cfg, struct event_base *ev_base) } } -void +void remove_all_maps (struct rspamd_config *cfg) { g_list_free (cfg->maps); @@ -1086,15 +996,13 @@ remove_all_maps (struct rspamd_config *cfg) gboolean check_map_proto (const gchar *map_line, gint *res, const gchar **pos) { - if (g_ascii_strncasecmp (map_line, "http://", - sizeof ("http://") - 1) == 0) { + if (g_ascii_strncasecmp (map_line, "http://", sizeof ("http://") - 1) == 0) { if (res && pos) { *res = MAP_PROTO_HTTP; *pos = map_line + sizeof ("http://") - 1; } } - else if (g_ascii_strncasecmp (map_line, "file://", sizeof ("file://") - - 1) == 0) { + else if (g_ascii_strncasecmp (map_line, "file://", sizeof ("file://") - 1) == 0) { if (res && pos) { *res = MAP_PROTO_FILE; *pos = map_line + sizeof ("file://") - 1; @@ -1114,21 +1022,17 @@ check_map_proto (const gchar *map_line, gint *res, const gchar **pos) } gboolean -add_map (struct rspamd_config *cfg, - const gchar *map_line, - const gchar *description, - map_cb_t read_callback, - map_fin_cb_t fin_callback, - void **user_data) +add_map (struct rspamd_config *cfg, const gchar *map_line, const gchar *description, + map_cb_t read_callback, map_fin_cb_t fin_callback, void **user_data) { - struct rspamd_map *new_map; - enum fetch_proto proto; - const gchar *def, *p, *hostend; - struct file_map_data *fdata; - struct http_map_data *hdata; - gchar portbuf[6]; - gint i, s, r; - struct addrinfo hints, *res; + struct rspamd_map *new_map; + enum fetch_proto proto; + const gchar *def, *p, *hostend; + struct file_map_data *fdata; + struct http_map_data *hdata; + gchar portbuf[6]; + gint i, s, r; + struct addrinfo hints, *res; /* First of all detect protocol line */ if (!check_map_proto (map_line, (int *)&proto, &def)) { @@ -1145,8 +1049,7 @@ add_map (struct rspamd_config *cfg, new_map->protocol = proto; new_map->cfg = cfg; new_map->id = g_random_int (); - new_map->locked = - rspamd_mempool_alloc0_shared (cfg->cfg_pool, sizeof (gint)); + new_map->locked = rspamd_mempool_alloc0_shared (cfg->cfg_pool, sizeof (gint)); if (proto == MAP_PROTO_FILE) { new_map->uri = rspamd_mempool_strdup (cfg->cfg_pool, def); @@ -1156,24 +1059,19 @@ add_map (struct rspamd_config *cfg, new_map->uri = rspamd_mempool_strdup (cfg->cfg_pool, map_line); } if (description != NULL) { - new_map->description = - rspamd_mempool_strdup (cfg->cfg_pool, description); + new_map->description = rspamd_mempool_strdup (cfg->cfg_pool, description); } /* Now check for each proto separately */ if (proto == MAP_PROTO_FILE) { - fdata = - rspamd_mempool_alloc0 (cfg->map_pool, - sizeof (struct file_map_data)); + fdata = rspamd_mempool_alloc0 (cfg->map_pool, sizeof (struct file_map_data)); if (access (def, R_OK) == -1) { if (errno != ENOENT) { msg_err ("cannot open file '%s': %s", def, strerror (errno)); return FALSE; } - msg_info ( - "map '%s' is not found, but it can be loaded automatically later", - def); + msg_info ("map '%s' is not found, but it can be loaded automatically later", def); /* We still can add this file */ fdata->st.st_mtime = -1; } @@ -1184,9 +1082,7 @@ add_map (struct rspamd_config *cfg, new_map->map_data = fdata; } else if (proto == MAP_PROTO_HTTP) { - hdata = - rspamd_mempool_alloc0 (cfg->map_pool, - sizeof (struct http_map_data)); + hdata = rspamd_mempool_alloc0 (cfg->map_pool, sizeof (struct http_map_data)); /* Try to search port */ if ((p = strchr (def, ':')) != NULL) { hostend = p; @@ -1229,21 +1125,15 @@ add_map (struct rspamd_config *cfg, if ((r = getaddrinfo (hdata->host, portbuf, &hints, &res)) == 0) { hdata->addr = res; - rspamd_mempool_add_destructor (cfg->cfg_pool, - (rspamd_mempool_destruct_t)freeaddrinfo, hdata->addr); + rspamd_mempool_add_destructor (cfg->cfg_pool, (rspamd_mempool_destruct_t)freeaddrinfo, hdata->addr); } else { - msg_err ("address resolution for %s failed: %s", - hdata->host, - gai_strerror (r)); + msg_err ("address resolution for %s failed: %s", hdata->host, gai_strerror (r)); return FALSE; } /* Now try to connect */ if ((s = make_tcp_socket (hdata->addr, FALSE, FALSE)) == -1) { - msg_info ("cannot connect to http server %s: %d, %s", - hdata->host, - errno, - strerror (errno)); + msg_info ("cannot connect to http server %s: %d, %s", hdata->host, errno, strerror (errno)); return FALSE; } close (s); |