Exemplo n.º 1
0
/* Start watching event for all maps */
void
rspamd_map_watch (struct rspamd_config *cfg,
		struct event_base *ev_base,
		struct rspamd_dns_resolver *resolver)
{
	GList *cur = cfg->maps;
	struct rspamd_map *map;

	/* First of all do synced read of data */
	while (cur) {
		map = cur->data;
		map->ev_base = ev_base;
		map->r = resolver;

		if (!g_atomic_int_compare_and_exchange (map->locked, 0, 1)) {
			msg_debug_map (
					"don't try to reread map as it is locked by other process, "
					"will reread it later");
			rspamd_map_schedule_periodic (map, TRUE, TRUE, FALSE);
		}
		else {
			rspamd_map_schedule_periodic (map, FALSE, TRUE, FALSE);
		}

		cur = g_list_next (cur);
	}
}
Exemplo n.º 2
0
static void
rspamd_map_periodic_dtor (struct map_periodic_cbdata *periodic)
{
	if (periodic->need_modify) {
		/* We are done */
		periodic->map->fin_callback (&periodic->cbdata);
		*periodic->map->user_data = periodic->cbdata.cur_data;
	}
	else {
		/* Not modified */
	}

	rspamd_map_schedule_periodic (periodic->map, FALSE, FALSE, FALSE);
	g_atomic_int_set (periodic->map->locked, 0);
	g_slice_free1 (sizeof (*periodic), periodic);
}
Exemplo n.º 3
0
static void
rspamd_map_periodic_callback (gint fd, short what, void *ud)
{
	struct rspamd_map_backend *bk;
	struct map_periodic_cbdata *cbd = ud;

	if (cbd->errored) {
		/* We should not check other backends if some backend has failed */
		rspamd_map_schedule_periodic (cbd->map, FALSE, FALSE, TRUE);
		g_atomic_int_set (cbd->map->locked, 0);
		MAP_RELEASE (cbd);

		return;
	}

	/* For each backend we need to check for modifications */
	if (cbd->cur_backend >= cbd->map->backends->len) {
		/* Last backend */
		MAP_RELEASE (cbd);

		return;
	}

	bk = g_ptr_array_index (cbd->map->backends, cbd->cur_backend);
	g_assert (bk != NULL);

	if (cbd->need_modify) {
		/* Load data from the next backend */
		if (bk->protocol == MAP_PROTO_HTTP) {
			rspamd_map_http_read_callback (fd, what, cbd);
		}
		else {
			rspamd_map_file_read_callback (fd, what, cbd);
		}
	}
	else {
		/* Check the next backend */
		if (bk->protocol == MAP_PROTO_HTTP) {
			rspamd_map_http_check_callback (fd, what, cbd);
		}
		else {
			rspamd_map_file_check_callback (fd, what, cbd);
		}
	}
}
Exemplo n.º 4
0
/* Start watching event for all maps */
void
rspamd_map_watch (struct rspamd_config *cfg,
		struct event_base *ev_base,
		struct rspamd_dns_resolver *resolver)
{
	GList *cur = cfg->maps;
	struct rspamd_map *map;

	/* First of all do synced read of data */
	while (cur) {
		map = cur->data;
		map->ev_base = ev_base;
		map->r = resolver;

		rspamd_map_schedule_periodic (map, FALSE, TRUE, FALSE);

		cur = g_list_next (cur);
	}
}
Exemplo n.º 5
0
static void
rspamd_map_periodic_callback (gint fd, short what, void *ud)
{
	struct rspamd_map_backend *bk;
	struct map_periodic_cbdata *cbd = ud;
	struct rspamd_map *map;

	map = cbd->map;

	if (!cbd->locked) {
		if (!g_atomic_int_compare_and_exchange (cbd->map->locked, 0, 1)) {
			msg_debug_map (
					"don't try to reread map as it is locked by other process, "
					"will reread it later");
			rspamd_map_schedule_periodic (map, TRUE, FALSE, FALSE);
			MAP_RELEASE (cbd, "periodic");

			return;
		}
		else {
			cbd->locked = TRUE;
		}
	}

	if (cbd->errored) {
		/* We should not check other backends if some backend has failed */
		rspamd_map_schedule_periodic (cbd->map, FALSE, FALSE, TRUE);

		if (cbd->locked) {
			g_atomic_int_set (cbd->map->locked, 0);
		}
		MAP_RELEASE (cbd, "periodic");

		return;
	}

	/* For each backend we need to check for modifications */
	if (cbd->cur_backend >= cbd->map->backends->len) {
		/* Last backend */
		MAP_RELEASE (cbd, "periodic");

		return;
	}

	bk = g_ptr_array_index (cbd->map->backends, cbd->cur_backend);
	g_assert (bk != NULL);

	if (cbd->need_modify) {
		/* Load data from the next backend */
		if (bk->protocol == MAP_PROTO_HTTP || bk->protocol == MAP_PROTO_HTTPS) {
			rspamd_map_http_read_callback (fd, what, cbd);
		}
		else {
			rspamd_map_file_read_callback (fd, what, cbd);
		}
	}
	else {
		/* Check the next backend */
		if (bk->protocol == MAP_PROTO_HTTP || bk->protocol == MAP_PROTO_HTTPS) {
			rspamd_map_http_check_callback (fd, what, cbd);
		}
		else {
			rspamd_map_file_check_callback (fd, what, cbd);
		}
	}
}