{
struct rspamd_http_map_cached_cbdata *cache_cbd = ud;
struct rspamd_map *map;
+ struct http_map_data *data;
struct timeval tv;
map = cache_cbd->map;
+ data = cache_cbd->data;
if (cache_cbd->gen != cache_cbd->data->gen) {
/* We have another update, so this cache element is obviously expired */
event_add (&cache_cbd->timeout, &tv);
}
else {
- map->cur_cache_cbd = NULL;
- g_atomic_int_set (&map->cache->available, 0);
+ data->cur_cache_cbd = NULL;
+ g_atomic_int_set (&data->cache->available, 0);
MAP_RELEASE (cache_cbd->shm, "rspamd_http_map_cached_cbdata");
msg_info_map ("cached data is now expired for %s", map->name);
event_del (&cache_cbd->timeout);
struct http_callback_data *cbd = conn->ud;
struct rspamd_map *map;
struct rspamd_map_backend *bk;
+ struct http_map_data *data;
struct rspamd_http_map_cached_cbdata *cache_cbd;
struct timeval tv;
const rspamd_ftok_t *expires_hdr, *etag_hdr;
map = cbd->map;
bk = cbd->bk;
+ data = bk->data.hd;
if (msg->code == 200) {
/* Reset the whole chain */
cbd->periodic->cur_backend = 0;
/* Reset cache, old cached data will be cleaned on timeout */
- g_atomic_int_set (&map->cache->available, 0);
- map->cur_cache_cbd = NULL;
+ g_atomic_int_set (&data->cache->available, 0);
+ data->cur_cache_cbd = NULL;
rspamd_map_periodic_callback (-1, EV_TIMEOUT, cbd->periodic);
MAP_RELEASE (cbd, "http_callback_data");
/*
* We know that a map is in the locked state
*/
- g_atomic_int_set (&map->cache->available, 1);
+ g_atomic_int_set (&data->cache->available, 1);
/* Store cached data */
- rspamd_strlcpy (map->cache->shmem_name, cbd->shmem_data->shm_name,
- sizeof (map->cache->shmem_name));
- map->cache->len = cbd->data_len;
- map->cache->last_modified = cbd->data->last_modified;
+ rspamd_strlcpy (data->cache->shmem_name, cbd->shmem_data->shm_name,
+ sizeof (data->cache->shmem_name));
+ data->cache->len = cbd->data_len;
+ data->cache->last_modified = cbd->data->last_modified;
cache_cbd = g_malloc0 (sizeof (*cache_cbd));
cache_cbd->shm = cbd->shmem_data;
cache_cbd->map = map;
cache_cbd);
event_base_set (cbd->ev_base, &cache_cbd->timeout);
event_add (&cache_cbd->timeout, &tv);
- map->cur_cache_cbd = cache_cbd;
+ data->cur_cache_cbd = cache_cbd;
if (map->next_check) {
rspamd_http_date_format (next_check_date, sizeof (next_check_date),
{
gsize len;
gpointer in;
+ struct http_map_data *data;
- in = rspamd_shmem_xmap (map->cache->shmem_name, PROT_READ, &len);
+ data = bk->data.hd;
+
+ in = rspamd_shmem_xmap (data->cache->shmem_name, PROT_READ, &len);
if (in == NULL) {
- msg_err ("cannot map cache from %s: %s", map->cache->shmem_name,
+ msg_err ("cannot map cache from %s: %s", data->cache->shmem_name,
strerror (errno));
return FALSE;
}
- if (len < map->cache->len) {
+ if (len < data->cache->len) {
msg_err ("cannot map cache from %s: bad length %z, %z expected",
- map->cache->shmem_name,
- len, map->cache->len);
+ data->cache->shmem_name,
+ len, data->cache->len);
munmap (in, len);
+
return FALSE;
}
data = bk->data.hd;
- if (g_atomic_int_get (&map->cache->available) == 1) {
+ if (g_atomic_int_get (&data->cache->available) == 1) {
/* Read cached data */
if (check) {
- if (data->last_modified < map->cache->last_modified) {
+ if (data->last_modified < data->cache->last_modified) {
periodic->need_modify = TRUE;
/* Reset the whole chain */
periodic->cur_backend = 0;
}
else {
if (map->active_http &&
- data->last_modified > map->cache->last_modified) {
+ data->last_modified > data->cache->last_modified) {
goto check;
}
else if (rspamd_map_read_cached (map, bk, periodic, data->host)) {
/* Switch to the next backend */
periodic->cur_backend++;
- data->last_modified = map->cache->last_modified;
+ data->last_modified = data->cache->last_modified;
rspamd_map_periodic_callback (-1, EV_TIMEOUT, periodic);
return;
for (cur = cfg->maps; cur != NULL; cur = g_list_next (cur)) {
map = cur->data;
- if (g_atomic_int_compare_and_exchange (&map->cache->available, 1, 0)) {
- if (map->cur_cache_cbd) {
- MAP_RELEASE (map->cur_cache_cbd->shm, "rspamd_http_map_cached_cbdata");
- event_del (&map->cur_cache_cbd->timeout);
- g_free (map->cur_cache_cbd);
- map->cur_cache_cbd = NULL;
- }
-
- unlink (map->cache->shmem_name);
- }
-
if (map->tmp_dtor) {
map->tmp_dtor (map->tmp_dtor_data);
}
for (i = 0; i < map->backends->len; i ++) {
bk = g_ptr_array_index (map->backends, i);
+
MAP_RELEASE (bk, "rspamd_map_backend");
}
case MAP_PROTO_HTTP:
case MAP_PROTO_HTTPS:
if (bk->data.hd) {
- g_free (bk->data.hd->host);
- g_free (bk->data.hd->path);
+ struct http_map_data *data = bk->data.hd;
- if (bk->data.hd->etag) {
- rspamd_fstring_free (bk->data.hd->etag);
+ g_free (data->host);
+ g_free (data->path);
+
+ if (data->etag) {
+ rspamd_fstring_free (data->etag);
+ }
+
+ if (g_atomic_int_compare_and_exchange (&data->cache->available, 1, 0)) {
+ if (data->cur_cache_cbd) {
+ MAP_RELEASE (data->cur_cache_cbd->shm,
+ "rspamd_http_map_cached_cbdata");
+ event_del (&data->cur_cache_cbd->timeout);
+ g_free (data->cur_cache_cbd);
+ data->cur_cache_cbd = NULL;
+ }
+
+ unlink (data->cache->shmem_name);
}
g_free (bk->data.hd);
}
}
+ hdata->cache = rspamd_mempool_alloc0_shared (cfg->cfg_pool,
+ sizeof (*hdata->cache));
+
bk->data.hd = hdata;
}
else if (bk->protocol == MAP_PROTO_STATIC) {
map->id = rspamd_random_uint64_fast ();
map->locked =
rspamd_mempool_alloc0_shared (cfg->cfg_pool, sizeof (gint));
- map->cache =
- rspamd_mempool_alloc0_shared (cfg->cfg_pool, sizeof (*map->cache));
map->backends = g_ptr_array_sized_new (1);
rspamd_mempool_add_destructor (cfg->cfg_pool, rspamd_ptr_array_free_hard,
map->backends);
map->id = rspamd_random_uint64_fast ();
map->locked =
rspamd_mempool_alloc0_shared (cfg->cfg_pool, sizeof (gint));
- map->cache =
- rspamd_mempool_alloc0_shared (cfg->cfg_pool, sizeof (*map->cache));
map->backends = g_ptr_array_new ();
rspamd_mempool_add_destructor (cfg->cfg_pool, rspamd_ptr_array_free_hard,
map->backends);
bk = rspamd_map_parse_backend (cfg, ucl_object_tostring (cur));
if (bk != NULL) {
- g_ptr_array_add (map->backends, bk);
+ rspamd_map_add_backend (map, bk);
if (!map->name) {
map->name = rspamd_mempool_strdup (cfg->cfg_pool,
bk = rspamd_map_parse_backend (cfg, ucl_object_tostring (cur));
if (bk != NULL) {
- g_ptr_array_add (map->backends, bk);
+ rspamd_map_add_backend (map, bk);
if (!map->name) {
map->name = rspamd_mempool_strdup (cfg->cfg_pool,
bk = rspamd_map_parse_backend (cfg, ucl_object_tostring (elt));
if (bk != NULL) {
- g_ptr_array_add (map->backends, bk);
+ rspamd_map_add_backend (map, bk);
if (!map->name) {
map->name = rspamd_mempool_strdup (cfg->cfg_pool,