#include "libutil/http_private.h"
#include "libserver/protocol_internal.h"
#include "libmime/filter.h"
+#include "libserver/worker_util.h"
#include "utlist.h"
#define msg_err_milter(...) rspamd_default_log_function(G_LOG_LEVEL_CRITICAL, \
struct rspamd_milter_context {
gchar *spam_header;
+ void *sessions_cache;
};
static struct rspamd_milter_context *milter_ctx = NULL;
g_hash_table_destroy (priv->headers);
}
+ if (milter_ctx->sessions_cache) {
+ rspamd_worker_session_cache_remove (milter_ctx->sessions_cache,
+ session);
+ }
+
rspamd_mempool_delete (priv->pool);
g_free (priv);
g_free (session);
g_assert (finish_cb != NULL);
g_assert (error_cb != NULL);
-
- if (G_UNLIKELY (milter_ctx == NULL)) {
- milter_ctx = g_malloc (sizeof (*milter_ctx));
- milter_ctx->spam_header = g_strdup (RSPAMD_MILTER_SPAM_HEADER);
- }
+ g_assert (milter_ctx != NULL);
session = g_malloc0 (sizeof (*session));
priv = g_malloc0 (sizeof (*priv));
session->priv = priv;
REF_INIT_RETAIN (session, rspamd_milter_session_dtor);
+ if (milter_ctx->sessions_cache) {
+ rspamd_worker_session_cache_add (milter_ctx->sessions_cache,
+ priv->pool->tag.uid, &session->ref.refcount, session);
+ }
+
return rspamd_milter_handle_session (session, priv);
}
}
void
-rspamd_milter_init_library (const gchar *spam_header)
+rspamd_milter_init_library (const gchar *spam_header, void *sessions_cache)
{
if (milter_ctx) {
g_free (milter_ctx->spam_header);
}
milter_ctx = g_malloc (sizeof (*milter_ctx));
- milter_ctx->spam_header = g_strdup (spam_header);
+
+ if (spam_header) {
+ milter_ctx->spam_header = g_strdup (spam_header);
+ }
+ else {
+ milter_ctx->spam_header = g_strdup (RSPAMD_MILTER_SPAM_HEADER);
+ }
+
+ milter_ctx->sessions_cache = sessions_cache;
}
rspamd_mempool_t *
* Init internal milter context
* @param spam_header spam header name (must NOT be NULL)
*/
-void rspamd_milter_init_library (const gchar *spam_header);
+void rspamd_milter_init_library (const gchar *spam_header,
+ void *sessions_cache);
/**
* Returns pool for a session
struct rspamd_worker_session_elt {
void *ptr;
- gint *pref;
+ guint *pref;
const gchar *tag;
time_t when;
};
void
rspamd_worker_session_cache_add (void *cache, const gchar *tag,
- gint *pref, void *ptr)
+ guint *pref, void *ptr)
{
struct rspamd_worker_session_cache *c = cache;
struct rspamd_worker_session_elt *elt;
* @param ptr
*/
void rspamd_worker_session_cache_add (void *cache, const gchar *tag,
- gint *pref, void *ptr);
+ guint *pref, void *ptr);
/**
* Removes session from cache
gboolean milter;
/* Milter spam header */
gchar *spam_header;
+ /* Sessions cache */
+ void *sessions_cache;
};
enum rspamd_backend_flags {
close (session->client_sock);
}
+ if (session->ctx->sessions_cache) {
+ rspamd_worker_session_cache_remove (session->ctx->sessions_cache,
+ session);
+ }
+
if (session->pool) {
rspamd_mempool_delete (session->pool);
}
REF_INIT_RETAIN (nsession, proxy_session_dtor);
+ if (nsession->ctx->sessions_cache) {
+ rspamd_worker_session_cache_add (nsession->ctx->sessions_cache,
+ nsession->pool->tag.uid, &nsession->ref.refcount, nsession);
+ }
+
return nsession;
}
session->ctx = ctx;
session->worker = worker;
+ if (ctx->sessions_cache) {
+ rspamd_worker_session_cache_add (ctx->sessions_cache,
+ session->pool->tag.uid, &session->ref.refcount, session);
+ }
+
if (!ctx->milter) {
session->client_conn = rspamd_http_connection_new (NULL,
proxy_client_error_handler,
rspamd_worker_init_scanner (worker, ctx->ev_base, ctx->resolver);
}
- if (ctx->spam_header) {
- rspamd_milter_init_library (ctx->spam_header);
+ if (worker->srv->cfg->enable_sessions_cache) {
+ ctx->sessions_cache = rspamd_worker_session_cache_new (worker,
+ ctx->ev_base);
}
+ rspamd_milter_init_library (ctx->spam_header, ctx->sessions_cache);
+
event_base_loop (ctx->ev_base, 0);
rspamd_worker_block_signals ();