aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2012-04-23 18:43:08 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2012-04-23 18:43:08 +0400
commit6ec2d38af719d146d2539db6f401cc1b14fc2c10 (patch)
treeea4038a8efa050da38f706e4b93f2ba0eef9c25c
parent5b697ce84fa67e6d237d21001814b8f3a91342d6 (diff)
downloadrspamd-6ec2d38af719d146d2539db6f401cc1b14fc2c10.tar.gz
rspamd-6ec2d38af719d146d2539db6f401cc1b14fc2c10.zip
* Allow workers to specify multiply options of the same type.
-rw-r--r--src/cfg_xml.c45
-rw-r--r--src/smtp_proxy.c17
2 files changed, 57 insertions, 5 deletions
diff --git a/src/cfg_xml.c b/src/cfg_xml.c
index ea0685ca4..c700a0366 100644
--- a/src/cfg_xml.c
+++ b/src/cfg_xml.c
@@ -843,11 +843,21 @@ struct wrk_cbdata {
struct rspamd_xml_userdata *ctx;
};
+struct wrk_param {
+ gboolean is_list;
+ union {
+ gchar *param;
+ GList *list;
+ } d;
+};
+
static void
worker_foreach_callback (gpointer k, gpointer v, gpointer ud)
{
struct wrk_cbdata *cd = ud;
+ struct wrk_param *param = v;
struct xml_config_param *cparam;
+ GList *cur;
GHashTable *worker_config;
if (!worker_options || (worker_config = g_hash_table_lookup (worker_options, &cd->wrk->type)) == NULL ||
@@ -857,10 +867,19 @@ worker_foreach_callback (gpointer k, gpointer v, gpointer ud)
else {
if (cd->wrk->ctx != NULL) {
- cparam->handler (cd->cfg, cd->ctx, NULL, v, NULL, cd->wrk->ctx, cparam->offset);
+ if (param->is_list) {
+ cur = param->d.list;
+ while (cur) {
+ cparam->handler (cd->cfg, cd->ctx, NULL, cur->data, NULL, cd->wrk->ctx, cparam->offset);
+ cur = g_list_next (cur);
+ }
+ }
+ else {
+ cparam->handler (cd->cfg, cd->ctx, NULL, param->d.param, NULL, cd->wrk->ctx, cparam->offset);
+ }
}
else {
- msg_err ("Bad error detected: module %s has not initialized its context", g_quark_to_string (cd->wrk->type));
+ msg_err ("Bad error detected: worker %s has not initialized its context", g_quark_to_string (cd->wrk->type));
}
}
}
@@ -869,7 +888,8 @@ gboolean
worker_handle_param (struct config_file *cfg, struct rspamd_xml_userdata *ctx, const gchar *tag, GHashTable *attrs, gchar *data, gpointer user_data, gpointer dest_struct, gint offset)
{
struct worker_conf *wrk = ctx->section_pointer;
- const gchar *name;
+ const gchar *name, *tmp;
+ struct wrk_param *param;
if (g_ascii_strcasecmp (tag, "option") == 0 || g_ascii_strcasecmp (tag, "param") == 0) {
if (attrs == NULL || (name = g_hash_table_lookup (attrs, "name")) == NULL) {
@@ -881,7 +901,24 @@ worker_handle_param (struct config_file *cfg, struct rspamd_xml_userdata *ctx, c
name = memory_pool_strdup (cfg->cfg_pool, tag);
}
- g_hash_table_insert (wrk->params, (char *)name, memory_pool_strdup (cfg->cfg_pool, data));
+ if ((param = g_hash_table_lookup (wrk->params, name)) == NULL) {
+ param = memory_pool_alloc (cfg->cfg_pool, sizeof (struct wrk_param));
+ param->is_list = FALSE;
+ param->d.param = memory_pool_strdup (cfg->cfg_pool, data);
+ g_hash_table_insert (wrk->params, (char *)name, param);
+ }
+ else {
+ if (param->is_list) {
+ param->d.list = g_list_append (param->d.list, memory_pool_strdup (cfg->cfg_pool, data));
+ }
+ else {
+ /* Convert to list */
+ param->is_list = TRUE;
+ tmp = param->d.param;
+ param->d.list = g_list_prepend (NULL, (gpointer)tmp);
+ memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func)g_list_free, param->d.list);
+ }
+ }
return TRUE;
}
diff --git a/src/smtp_proxy.c b/src/smtp_proxy.c
index 75f4eaeba..1ada5ff1e 100644
--- a/src/smtp_proxy.c
+++ b/src/smtp_proxy.c
@@ -45,6 +45,8 @@
#define DEFAULT_UPSTREAM_DEAD_TIME 300
#define DEFAULT_UPSTREAM_MAXERRORS 10
+#define DEFAULT_PROXY_BUF_LEN 100 * 1024
+
static sig_atomic_t wanna_die = 0;
/* Init functions */
@@ -72,6 +74,10 @@ struct smtp_proxy_ctx {
guint32 smtp_timeout_raw;
struct timeval smtp_timeout;
+ gboolean use_xclient;
+
+ gsize proxy_buf_len;
+
struct rspamd_dns_resolver *resolver;
struct event_base *ev_base;
};
@@ -232,7 +238,8 @@ create_smtp_proxy_upstream_connection (struct smtp_proxy_session *session)
/* Create a proxy for upstream connection */
rspamd_dispatcher_pause (session->dispatcher);
session->proxy = rspamd_create_proxy (session->sock, session->upstream_sock, session->pool,
- session->ev_base, BUFSIZ, &session->ctx->smtp_timeout, smtp_proxy_err_proxy, session);
+ session->ev_base, session->ctx->proxy_buf_len,
+ &session->ctx->smtp_timeout, smtp_proxy_err_proxy, session);
return TRUE;
}
@@ -507,6 +514,10 @@ init_smtp_proxy (void)
G_STRUCT_OFFSET (struct smtp_proxy_ctx, smtp_delay));
register_worker_opt (type, "jitter", xml_handle_seconds, ctx,
G_STRUCT_OFFSET (struct smtp_proxy_ctx, delay_jitter));
+ register_worker_opt (type, "xclient", xml_handle_boolean, ctx,
+ G_STRUCT_OFFSET (struct smtp_proxy_ctx, use_xclient));
+ register_worker_opt (type, "proxy_buffer", xml_handle_size, ctx,
+ G_STRUCT_OFFSET (struct smtp_proxy_ctx, proxy_buf_len));
return ctx;
}
@@ -532,6 +543,10 @@ config_smtp_proxy_worker (struct rspamd_worker *worker)
return FALSE;
}
+ if (ctx->proxy_buf_len == 0) {
+ ctx->proxy_buf_len = DEFAULT_PROXY_BUF_LEN;
+ }
+
return TRUE;
}