aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2013-09-30 16:43:52 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2013-09-30 16:43:52 +0100
commit0f3bef042e866e967e41848ebd8bae85a86fef73 (patch)
tree809b692999a1ee85d5e31d513088e517bad50c52 /src
parent3d218a89ecaf7ff265a26f922d99d74ef6ef6108 (diff)
downloadrspamd-0f3bef042e866e967e41848ebd8bae85a86fef73.tar.gz
rspamd-0f3bef042e866e967e41848ebd8bae85a86fef73.zip
Add rcl parsers for workers options.
Diffstat (limited to 'src')
-rw-r--r--src/cfg_file.h17
-rw-r--r--src/cfg_rcl.c32
-rw-r--r--src/cfg_rcl.h17
-rw-r--r--src/cfg_xml.c25
4 files changed, 66 insertions, 25 deletions
diff --git a/src/cfg_file.h b/src/cfg_file.h
index bfbc0efa9..89e4870db 100644
--- a/src/cfg_file.h
+++ b/src/cfg_file.h
@@ -11,7 +11,9 @@
#include "upstream.h"
#include "memcached.h"
#include "symbols_cache.h"
+#include "cfg_rcl.h"
#include "utlist.h"
+#include "rcl/rcl.h"
#define DEFAULT_BIND_PORT 768
#define DEFAULT_CONTROL_PORT 7608
@@ -253,6 +255,19 @@ struct rspamd_worker_bind_conf {
struct rspamd_worker_bind_conf *next;
};
+struct rspamd_worker_param_parser {
+ rspamd_rcl_handler_t handler; /**< handler function */
+ struct rspamd_rcl_struct_parser parser; /**< parser attributes */
+ const gchar *name; /**< parameter's name */
+ UT_hash_handle hh; /**< hash by name */
+};
+
+struct rspamd_worker_cfg_parser {
+ struct rspamd_worker_param_parser *parsers; /**< parsers hash */
+ gint type; /**< workers quark */
+ UT_hash_handle hh; /**< hash by type */
+};
+
/**
* Config params for rspamd worker
*/
@@ -268,6 +283,7 @@ struct worker_conf {
GQueue *active_workers; /**< linked list of spawned workers */
gboolean has_socket; /**< whether we should make listening socket in main process */
gpointer *ctx; /**< worker's context */
+ rspamd_cl_object_t *options; /**< other worker's options */
};
/**
@@ -330,6 +346,7 @@ struct config_file {
GList *filters; /**< linked list of all filters */
GList *workers; /**< linked list of all workers params */
+ struct rspamd_worker_cfg_parser *wrk_parsers; /**< hash for worker config parsers, indexed by worker quarks */
gchar *filters_str; /**< string of filters */
GHashTable* modules_opts; /**< hash for module options indexed by module name */
GHashTable* modules_metas; /**< hash for module meta options indexed by module name*/
diff --git a/src/cfg_rcl.c b/src/cfg_rcl.c
index 70f51f8cd..5c27a2516 100644
--- a/src/cfg_rcl.c
+++ b/src/cfg_rcl.c
@@ -388,7 +388,7 @@ rspamd_rcl_worker_handler (struct config_file *cfg, rspamd_cl_object_t *obj,
}
wrk->type = qtype;
if (wrk->worker->worker_init_func) {
- wrk->ctx = wrk->worker->worker_init_func ();
+ wrk->ctx = wrk->worker->worker_init_func (cfg);
}
}
else {
@@ -897,3 +897,33 @@ rspamd_rcl_parse_struct_boolean (struct config_file *cfg, rspamd_cl_object_t *ob
return TRUE;
}
+
+void
+rspamd_rcl_register_worker_option (struct config_file *cfg, gint type, const gchar *name,
+ rspamd_rcl_handler_t handler, gpointer target, gsize offset, gint flags)
+{
+ struct rspamd_worker_param_parser *nhandler;
+ struct rspamd_worker_cfg_parser *nparser;
+
+ HASH_FIND_INT (cfg->wrk_parsers, &type, nparser);
+ if (nparser == NULL) {
+ /* Allocate new parser for this worker */
+ nparser = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_cfg_parser));
+ nparser->type = type;
+ HASH_ADD_INT (cfg->wrk_parsers, type, nparser);
+ }
+
+ HASH_FIND_STR (nparser->parsers, name, nhandler);
+ if (nhandler != NULL) {
+ msg_warn ("handler for parameter %s is already registered for worker type %s",
+ name, g_quark_to_string (type));
+ return;
+ }
+ nhandler = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_param_parser));
+ nhandler->name = name;
+ nhandler->parser.flags = flags;
+ nhandler->parser.offset = offset;
+ nhandler->parser.user_struct = target;
+ nhandler->handler = handler;
+ HASH_ADD_STR (nparser->parsers, name, nhandler);
+}
diff --git a/src/cfg_rcl.h b/src/cfg_rcl.h
index 223431d79..1b19783cf 100644
--- a/src/cfg_rcl.h
+++ b/src/cfg_rcl.h
@@ -26,7 +26,6 @@
#include "config.h"
#include "rcl/rcl.h"
-#include "main.h"
#define CFG_RCL_ERROR cfg_rcl_error_quark ()
static inline GQuark
@@ -36,6 +35,7 @@ cfg_rcl_error_quark (void)
}
struct rspamd_rcl_section;
+struct config_file;
struct rspamd_rcl_struct_parser {
gpointer user_struct;
@@ -198,4 +198,19 @@ gboolean rspamd_rcl_parse_struct_string_list (struct config_file *cfg, rspamd_cl
gboolean rspamd_rcl_parse_struct_boolean (struct config_file *cfg, rspamd_cl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err);
+/**
+ * Utility functions
+ */
+
+/**
+ * Register new parser for a worker type of an option with the specified name
+ * @param cfg config structure
+ * @param type type of worker (GQuark)
+ * @param name name of option
+ * @param handler handler of option
+ * @param target opaque target structure
+ * @param offset offset inside a structure
+ */
+void rspamd_rcl_register_worker_option (struct config_file *cfg, gint type, const gchar *name,
+ rspamd_rcl_handler_t handler, gpointer target, gsize offset, gint flags);
#endif /* CFG_RCL_H_ */
diff --git a/src/cfg_xml.c b/src/cfg_xml.c
index fc7245390..215371f2f 100644
--- a/src/cfg_xml.c
+++ b/src/cfg_xml.c
@@ -1022,7 +1022,7 @@ worker_handle_type (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GH
}
wrk->type = type;
if (wrk->worker->worker_init_func) {
- wrk->ctx = wrk->worker->worker_init_func ();
+ wrk->ctx = wrk->worker->worker_init_func (cfg);
}
}
else {
@@ -2525,28 +2525,7 @@ register_module_opt (const gchar *mname, const gchar *optname, enum module_opt_t
void
register_worker_opt (gint wtype, const gchar *optname, element_handler_func func, gpointer dest_struct, gint offset)
{
- struct xml_config_param *param;
- GHashTable *worker;
- gint *new_key;
-
- if (worker_options == NULL) {
- worker_options = g_hash_table_new (g_int_hash, g_int_equal);
- }
- if ((worker = g_hash_table_lookup (worker_options, &wtype)) == NULL) {
- worker = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
- new_key = g_malloc (sizeof (gint));
- *new_key = wtype;
- g_hash_table_insert (worker_options, new_key, worker);
- }
- if ((param = g_hash_table_lookup (worker, optname)) == NULL) {
- /* Register new param */
- param = g_malloc (sizeof (struct xml_config_param));
- param->handler = func;
- param->user_data = dest_struct;
- param->offset = offset;
- param->name = optname;
- g_hash_table_insert (worker, (char *)optname, param);
- }
+ msg_err ("this function is depreciated and must not be used");
}
/* Register new classifier option */