#include "contrib/libottery/ottery.h"
#include "contrib/http-parser/http_parser.h"
#include "rspamd.h"
+#include "libev_helper.h"
INIT_LOG_MODULE(http_context)
struct rspamd_http_context *ctx;
GQueue *queue;
GList *link;
- struct event ev;
+ struct rspamd_io_ev ev;
};
static void
}
static void
-rspamd_http_context_client_rotate_ev (gint fd, short what, void *arg)
+rspamd_http_context_client_rotate_ev (struct ev_loop *loop, ev_periodic *w, int revents)
{
struct timeval rot_tv;
- struct rspamd_http_context *ctx = arg;
+ struct rspamd_http_context *ctx = (struct rspamd_http_context *)w->data;
gpointer kp;
double_to_tv (ctx->config.client_key_rotate_time, &rot_tv);
msg_debug_http_context ("rotate local keypair, next rotate in %d seconds",
(int)rot_tv.tv_sec);
- event_del (&ctx->client_rotate_ev);
- event_add (&ctx->client_rotate_ev, &rot_tv);
+ ev_periodic_again (loop, w);
kp = ctx->client_kp;
ctx->client_kp = rspamd_keypair_new (RSPAMD_KEYPAIR_KEX,
}
if (ctx->config.client_key_rotate_time > 0 && ctx->event_loop) {
- struct timeval tv;
double jittered = rspamd_time_jitter (ctx->config.client_key_rotate_time,
0);
- double_to_tv (jittered, &tv);
- event_set (&ctx->client_rotate_ev, -1, EV_TIMEOUT,
- rspamd_http_context_client_rotate_ev, ctx);
- event_base_set (ctx->event_loop, &ctx->client_rotate_ev);
- event_add (&ctx->client_rotate_ev, &tv);
+ ev_periodic_init (&ctx->client_rotate_ev,
+ rspamd_http_context_client_rotate_ev, 0.0, jittered, NULL);
+ ev_periodic_start (ctx->event_loop, &ctx->client_rotate_ev);
+ ctx->client_rotate_ev.data = ctx;
}
if (ctx->config.http_proxy) {
struct rspamd_http_connection *conn;
cbd = g_queue_pop_head (conns);
- event_del (&cbd->ev);
+ rspamd_ev_watcher_stop (ctx->event_loop, &cbd->ev);
conn = cbd->conn;
g_free (cbd);
cbdata->conn->keepalive_hash_key->host,
cbdata->queue->length);
rspamd_http_connection_unref (cbdata->conn);
+ rspamd_ev_watcher_stop (cbdata->ctx->event_loop, &cbdata->ev);
g_free (cbdata);
}
rspamd_http_context_push_keepalive (struct rspamd_http_context *ctx,
struct rspamd_http_connection *conn,
struct rspamd_http_message *msg,
- struct ev_loop *ev_base)
+ struct ev_loop *event_loop)
{
struct rspamd_http_keepalive_cbdata *cbdata;
- struct timeval tv;
gdouble timeout = ctx->config.keepalive_interval;
g_assert (conn->keepalive_hash_key != NULL);
cbdata->ctx = ctx;
conn->finished = FALSE;
- event_set (&cbdata->ev, conn->fd, EV_READ|EV_TIMEOUT,
+ rspamd_ev_watcher_init (&cbdata->ev, conn->fd, EV_READ,
rspamd_http_keepalive_handler,
cbdata);
+ rspamd_ev_watcher_start (event_loop, &cbdata->ev, timeout);
msg_debug_http_context ("push keepalive element %s (%s), %d connections queued, %.1f timeout",
rspamd_inet_address_to_string_pretty (cbdata->conn->keepalive_hash_key->addr),
cbdata->conn->keepalive_hash_key->host,
cbdata->queue->length,
timeout);
-
- double_to_tv (timeout, &tv);
- event_base_set (ev_base, &cbdata->ev);
- event_add (&cbdata->ev, &tv);
}
\ No newline at end of file
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;
char next_check_date[128];
guchar *aux_data, *in = NULL;
}
static void
-rspamd_map_http_check_callback (gint fd, short what, void *ud)
+rspamd_map_http_check_callback (struct map_periodic_cbdata *cbd)
{
- struct map_periodic_cbdata *cbd = ud;
struct rspamd_map *map;
struct rspamd_map_backend *bk;
}
static void
-rspamd_map_http_read_callback (void *ud)
+rspamd_map_http_read_callback (struct map_periodic_cbdata *cbd)
{
- struct map_periodic_cbdata *cbd = ud;
struct rspamd_map *map;
struct rspamd_map_backend *bk;
}
static void
-rspamd_map_file_check_callback (void *ud)
+rspamd_map_file_check_callback (struct map_periodic_cbdata *periodic)
{
struct rspamd_map *map;
- struct map_periodic_cbdata *periodic = ud;
struct file_map_data *data;
struct rspamd_map_backend *bk;
}
static void
-rspamd_map_static_check_callback (gint fd, short what, void *ud)
+rspamd_map_static_check_callback (struct map_periodic_cbdata *periodic)
{
struct rspamd_map *map;
- struct map_periodic_cbdata *periodic = ud;
struct static_map_data *data;
struct rspamd_map_backend *bk;
switch (bk->protocol) {
case MAP_PROTO_HTTP:
case MAP_PROTO_HTTPS:
- rspamd_map_http_read_callback (fd, what, cbd);
+ rspamd_map_http_read_callback (cbd);
break;
case MAP_PROTO_FILE:
- rspamd_map_file_read_callback (fd, what, cbd);
+ rspamd_map_file_read_callback (cbd);
break;
case MAP_PROTO_STATIC:
- rspamd_map_static_read_callback (fd, what, cbd);
+ rspamd_map_static_read_callback (cbd);
break;
}
} else {
switch (bk->protocol) {
case MAP_PROTO_HTTP:
case MAP_PROTO_HTTPS:
- rspamd_map_http_check_callback (fd, what, cbd);
+ rspamd_map_http_check_callback (cbd);
break;
case MAP_PROTO_FILE:
- rspamd_map_file_check_callback (fd, what, cbd);
+ rspamd_map_file_check_callback (cbd);
break;
case MAP_PROTO_STATIC:
- rspamd_map_static_check_callback (fd, what, cbd);
+ rspamd_map_static_check_callback (cbd);
break;
}
}
if (data->cur_cache_cbd) {
MAP_RELEASE (data->cur_cache_cbd->shm,
"rspamd_http_map_cached_cbdata");
- event_del (&data->cur_cache_cbd->timeout);
+ ev_periodic_stop (ev_default_loop (0),
+ &data->cur_cache_cbd->timeout);
g_free (data->cur_cache_cbd);
data->cur_cache_cbd = NULL;
}
/* Now check for each proto separately */
if (bk->protocol == MAP_PROTO_FILE) {
fdata = g_malloc0 (sizeof (struct file_map_data));
- fdata->st.st_mtime = -1;
if (access (bk->uri, R_OK) == -1) {
if (errno != ENOENT) {