[srvx-commits] CVS: services/src mod_common.c,1.6,1.7 modules.c,1.20,1.21 modules.h,1.9,1.10 service
Brought to you by:
entrope
From: Entrope <en...@us...> - 2001-10-20 01:14:43
|
Update of /cvsroot/srvx/services/src In directory usw-pr-cvs1:/tmp/cvs-serv794/src Modified Files: mod_common.c modules.c modules.h service.c Log Message: let modules specify a command's default rule by text as well as by expression struct make module_define_command() internally report any errors include REQUIRE_AUTHED command flag Index: mod_common.c =================================================================== RCS file: /cvsroot/srvx/services/src/mod_common.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** mod_common.c 2001/10/15 14:35:15 1.6 --- mod_common.c 2001/10/20 01:14:40 1.7 *************** *** 130,138 **** static struct module_command cmds[] = { ! { "help", 0, NULL, cmd_help }, ! { "readhelp", 0, NULL, cmd_readhelp }, ! { "timecmd", 0, NULL, cmd_timecmd }, ! { "write", 0, NULL, cmd_write }, ! { NULL, 0, 0, NULL }, }; --- 130,138 ---- static struct module_command cmds[] = { ! { "help", 0, NULL, cmd_help, NULL }, ! { "readhelp", 1 << REQUIRE_AUTHED, NULL, cmd_readhelp, "(umode +o)" }, ! { "timecmd", 1 << REQUIRE_AUTHED, NULL, cmd_timecmd, "(umode +o)" }, ! { "write", 1 << REQUIRE_AUTHED, NULL, cmd_write, "(umode +o)" }, ! { NULL, 0, 0, NULL, NULL } }; *************** *** 148,154 **** if (!mod_common_module) return 1; ! /* Register functions */ for (nn=0; cmds[nn].name; nn++) { ! if (module_define_command(mod_common_module, cmds+nn)) return 2+nn; } --- 148,154 ---- if (!mod_common_module) return 1; ! /* Register commands */ for (nn=0; cmds[nn].name; nn++) { ! module_define_command(mod_common_module, cmds+nn); } Index: modules.c =================================================================== RCS file: /cvsroot/srvx/services/src/modules.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -r1.20 -r1.21 *** modules.c 2001/10/15 14:35:15 1.20 --- modules.c 2001/10/20 01:14:40 1.21 *************** *** 28,31 **** --- 28,32 ---- #include "log.h" #include "recdb.h" + #include "rules.h" #include "modules.h" *************** *** 193,202 **** } ! int module_define_command(struct module *mod, struct module_command *cmd) { ! if (dict_find(mod->commands, cmd->name, NULL)) return 1; dict_insert(mod->commands, cmd->name, cmd); - return 0; } --- 194,211 ---- } ! void module_define_command(struct module *mod, struct module_command *cmd) { ! 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; ! } ! if (cmd->default_rule_text && !cmd->default_rule) { ! 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); ! } ! } dict_insert(mod->commands, cmd->name, cmd); } Index: modules.h =================================================================== RCS file: /cvsroot/srvx/services/src/modules.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -r1.9 -r1.10 *** modules.h 2001/10/12 02:03:34 1.9 --- modules.h 2001/10/20 01:14:40 1.10 *************** *** 15,20 **** * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * $Id$ */ --- 15,18 ---- *************** *** 60,63 **** --- 58,62 ---- /* In module_command.flags, bit 1<<N corresponds to (enum command_flag)N. */ enum command_flag { + REQUIRE_AUTHED, TAKES_CHANNEL, REQUIRE_CHANNEL, *************** *** 72,75 **** --- 71,75 ---- struct expression *default_rule; MODULE_COMMAND((*function)); + const unsigned char *default_rule_text; }; *************** *** 82,86 **** struct module *module_register(const char *name, modver_t ver, struct module_deplist *deps, struct shared_lib *lib); struct module *module_find_loaded(const char *name); ! int module_define_command(struct module *mod, struct module_command *cmd); void *get_module_symbol(struct module *module, const char *symname); --- 82,86 ---- struct module *module_register(const char *name, modver_t ver, struct module_deplist *deps, struct shared_lib *lib); struct module *module_find_loaded(const char *name); ! void module_define_command(struct module *mod, struct module_command *cmd); void *get_module_symbol(struct module *module, const char *symname); Index: service.c =================================================================== RCS file: /cvsroot/srvx/services/src/service.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** service.c 2001/10/14 19:45:40 1.6 --- service.c 2001/10/20 01:14:40 1.7 *************** *** 128,131 **** --- 128,135 ---- cmd = service_find_command(sinst, argv[0]); } + if ((cmd->base->flags & (1 << REQUIRE_AUTHED)) && !source->handle_info) { + send_message(source, bot, N_("You must authenticate yourself first.")); + return; + } if ((cmd->base->flags & (1 << TAKES_CHANNEL)) && shift) { chan = GetChannel(argv[shift-1]); |