[srvx-commits] CVS: services/src/srvx modules.c,1.1,1.2 modules.h,1.1,1.2
Brought to you by:
entrope
From: Entrope <en...@us...> - 2001-10-25 16:38:26
|
Update of /cvsroot/srvx/services/src/srvx In directory usw-pr-cvs1:/tmp/cvs-serv17173/src/srvx Modified Files: modules.c modules.h Log Message: support aliases for modules (e.g. "proto" "proto_ircu_p10";) allow looking up module commands Index: modules.c =================================================================== RCS file: /cvsroot/srvx/services/src/srvx/modules.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** modules.c 2001/10/20 18:47:05 1.1 --- modules.c 2001/10/25 16:38:23 1.2 *************** *** 73,77 **** if (!(lib->handle = dlopen(so_name, RTLD_GLOBAL|RTLD_LAZY))) { - log(MAIN_LOG, LOG_ERROR, "Unable to load shared library %s: %s\n", so_name, dlerror()); free(lib); return NULL; --- 73,76 ---- *************** *** 125,136 **** { struct module *mod; ! char path[256], *libname; if ((mod = dict_find(loaded_modules, name, NULL))) return mod; ! /* try to find a shared library that contains the module */ ! /* first: what's specified in the configuration file */ ! snprintf(path, sizeof(path), "modules/%s/path", name); ! if ((libname = database_get_data(conf_db, path, RECDB_QSTRING))) { ! module_load_library(libname); if ((mod = dict_find(loaded_modules, name, NULL))) return mod; } --- 124,159 ---- { struct module *mod; ! struct record_data *rd; ! char path[256]; if ((mod = dict_find(loaded_modules, name, NULL))) return mod; ! /* look to see if we should resolve an alias or anything */ ! rd = dict_find(conf_db, "modules", NULL); ! if (rd) { ! if (rd->type != RECDB_OBJECT) { ! log(MAIN_LOG, LOG_ERROR, N_("\"modules\" key in config DB isn't an object.\n")); ! return NULL; ! } ! rd = dict_find(rd->d.object, name, NULL); ! if (rd) { ! switch (rd->type) { ! case RECDB_QSTRING: ! return module_try_load(rd->d.qstring); ! default: ! log(MAIN_LOG, LOG_ERROR, N_("Unknown/invalid record type for config DB key \"modules\"/\"%s\"."), name); ! return NULL; ! case RECDB_OBJECT: ! /* unaliased name; try to find the shared library */ ! break; ! } ! } ! } ! /* first: what's specified in the configuration file (if anything) */ ! if (rd && (rd = dict_find(rd->d.object, "path", NULL))) { ! if (rd->type != RECDB_QSTRING) { ! log(MAIN_LOG, LOG_ERROR, N_("Config DB key \"modules\"/\"%s\"/\"path\" should be a string, but isn't.\n"), name); ! return NULL; ! } ! module_load_library(rd->d.qstring); if ((mod = dict_find(loaded_modules, name, NULL))) return mod; } *************** *** 198,202 **** { if (dict_find(mod->commands, cmd->name, NULL)) { ! log(MAIN_LOG, LOG_ERROR, "Module %s attempted to insert duplicate command %s\n", mod->name, cmd->name); return; } --- 221,225 ---- { if (dict_find(mod->commands, cmd->name, NULL)) { ! log(MAIN_LOG, LOG_ERROR, N_("Module %s attempted to insert duplicate command %s\n"), mod->name, cmd->name); return; } *************** *** 204,208 **** cmd->default_rule = expression_parse(cmd->default_rule_text); if (!cmd->default_rule) { ! log(MAIN_LOG, LOG_ERROR, "Parse error for default rule for module %s command %s: %s\n", mod->name, cmd->name, cmd->default_rule_text); } } --- 227,231 ---- cmd->default_rule = expression_parse(cmd->default_rule_text); if (!cmd->default_rule) { ! log(MAIN_LOG, LOG_ERROR, N_("Parse error for default rule for module %s command %s: %s\n"), mod->name, cmd->name, cmd->default_rule_text); } } *************** *** 214,217 **** --- 237,246 ---- { return module_resolve_symbol(module->lib, symname); + } + + struct module_command * + module_find_command(struct module *mod, const char *cmd_name) + { + return dict_find(mod->commands, cmd_name, NULL); } Index: modules.h =================================================================== RCS file: /cvsroot/srvx/services/src/srvx/modules.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** modules.h 2001/10/20 18:47:05 1.1 --- modules.h 2001/10/25 16:38:23 1.2 *************** *** 83,86 **** --- 83,87 ---- struct module *module_find_loaded(const char *name); void module_define_command(struct module *mod, struct module_command *cmd); + struct module_command *module_find_command(struct module *mod, const char *cmd_name); void *get_module_symbol(struct module *module, const char *symname); |