gboolean confgen_module_init(GlobalConfig *cfg, CfgArgs *args) { const gchar *name, *context, *exec; name = cfg_args_get(args, "name"); if (!name) { msg_error("confgen: name argument expected", NULL); return FALSE; } context = cfg_args_get(args, "context"); if (!context) { msg_error("confgen: context argument expected", NULL); return FALSE; } exec = cfg_args_get(args, "exec"); if (!exec) { msg_error("confgen: exec argument expected", NULL); return FALSE; } cfg_lexer_register_block_generator(cfg->lexer, cfg_lexer_lookup_context_type_by_name(context), name, confgen_generate, g_strdup(exec), g_free); return TRUE; }
gboolean confgen_module_init(PluginContext *plugin_context, CfgArgs *args) { const gchar *name, *context, *exec; name = cfg_args_get(args, "name"); if (!name) { msg_error("confgen: name argument expected"); return FALSE; } context = cfg_args_get(args, "context"); if (!context) { msg_error("confgen: context argument expected"); return FALSE; } exec = cfg_args_get(args, "exec"); if (!exec) { msg_error("confgen: exec argument expected"); return FALSE; } cfg_lexer_register_generator_plugin(plugin_context, confgen_exec_new(cfg_lexer_lookup_context_type_by_name(context), name, exec)); return TRUE; }
gboolean plugin_load_module(const gchar *module_name, GlobalConfig *cfg, CfgArgs *args) { GModule *mod; static GModule *main_module_handle; gboolean (*init_func)(GlobalConfig *cfg, CfgArgs *args); gchar *module_init_func; const gchar *mp; gchar *p; if (!main_module_handle) main_module_handle = g_module_open(NULL, 0); module_init_func = g_strdup_printf("%s_module_init", module_name); for (p = module_init_func; *p; p++) { if ((*p) == '-') *p = '_'; } if (g_module_symbol(main_module_handle, module_init_func, (gpointer *) &init_func)) { /* already linked in, no need to load explicitly */ goto call_init; } if (cfg->lexer) mp = cfg_args_get(cfg->lexer->globals, "module-path"); else mp = NULL; if (!mp) mp = module_path; mod = plugin_dlopen_module(module_name, mp); if (!mod) { g_free(module_init_func); return FALSE; } g_module_make_resident(mod); if (!g_module_symbol(mod, module_init_func, (gpointer *) &init_func)) { msg_error("Error finding init function in module", evt_tag_str("module", module_name), evt_tag_str("symbol", module_init_func), evt_tag_str("error", g_module_error()), NULL); g_free(module_init_func); return FALSE; } call_init: g_free(module_init_func); return (*init_func)(cfg, args); }
void cfg_load_candidate_modules(GlobalConfig *self) { /* we enable autoload for pre-3.1 configs or when the user requested * auto-load (the default) */ if ((cfg_is_config_version_older(self, 0x0302) || atoi(cfg_args_get(self->lexer->globals, "autoload-compiled-modules"))) && !self->candidate_plugins) { plugin_load_candidate_modules(self); } }
static void cfg_args_validate_callback(gpointer k, gpointer v, gpointer user_data) { CfgArgs *defs = ((gpointer *) user_data)[0]; gchar **bad_key = (gchar **) &((gpointer *) user_data)[1]; gchar **bad_value = (gchar **) &((gpointer *) user_data)[2]; if ((*bad_key == NULL) && (!defs || cfg_args_get(defs, k) == NULL)) { *bad_key = k; *bad_value = v; } }
gboolean plugin_load_module(const gchar *module_name, GlobalConfig *cfg, CfgArgs *args) { GModule *mod; static GModule *main_module_handle; gboolean (*init_func)(GlobalConfig *cfg, CfgArgs *args); gchar *module_init_func; const gchar *mp; gboolean result; ModuleInfo *module_info; /* lookup in the main executable */ if (!main_module_handle) main_module_handle = g_module_open(NULL, 0); module_init_func = plugin_get_module_init_name(module_name); if (g_module_symbol(main_module_handle, module_init_func, (gpointer *) &init_func)) { /* already linked in, no need to load explicitly */ goto call_init; } /* try to load it from external .so */ if (cfg->lexer) mp = cfg_args_get(cfg->lexer->globals, "module-path"); else mp = NULL; if (!mp) mp = resolvedConfigurablePaths.initial_module_path; mod = plugin_dlopen_module(module_name, mp); if (!mod) { g_free(module_init_func); return FALSE; } g_module_make_resident(mod); module_info = plugin_get_module_info(mod); if (module_info->canonical_name) { g_free(module_init_func); module_init_func = plugin_get_module_init_name(module_info->canonical_name ? : module_name); }
gboolean cfg_allow_config_dups(GlobalConfig *self) { const gchar *s; if (cfg_is_config_version_older(self, 0x0303)) return TRUE; s = cfg_args_get(self->lexer->globals, "allow-config-dups"); if (s && atoi(s)) { return TRUE; } else { /* duplicate found, but allow-config-dups is not enabled, hint the user that he might want to use allow-config-dups */ msg_warning_once("WARNING: Duplicate configuration objects (sources, destinations, ...) are not allowed by default starting with syslog-ng 3.3, add \"@define allow-config-dups 1\" to your configuration to reenable", NULL); return FALSE; } }
static const gchar * _get_include_path(CfgLexer *self) { return self->cfg ? cfg_args_get(self->cfg->globals, "include-path") : NULL; }