typedef struct worker_s {
const gchar *name;
- gpointer (*worker_init_func)(void);
+ gpointer (*worker_init_func)(struct config_file *cfg);
void (*worker_start_func)(struct rspamd_worker *worker);
gboolean has_socket;
gboolean unique;
#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
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
*/
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 */
};
/**
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*/
}
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 {
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);
+}
#include "config.h"
#include "rcl/rcl.h"
-#include "main.h"
#define CFG_RCL_ERROR cfg_rcl_error_quark ()
static inline GQuark
}
struct rspamd_rcl_section;
+struct config_file;
struct rspamd_rcl_struct_parser {
gpointer user_struct;
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_ */
}
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 {
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 */