[srvx-commits] CVS: services/src modcmd.c,1.4,1.5
Brought to you by:
entrope
|
From: Entrope <en...@us...> - 2002-07-31 03:42:15
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv2422/src
Modified Files:
modcmd.c
Log Message:
fix return value when argc < min_argc
fix infinite recursion when expanding an alias
Index: modcmd.c
===================================================================
RCS file: /cvsroot/srvx/services/src/modcmd.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** modcmd.c 31 Jul 2002 02:40:15 -0000 1.4
--- modcmd.c 31 Jul 2002 03:42:12 -0000 1.5
***************
*** 34,38 ****
struct alias_expansion {
! struct modcmd *base;
unsigned int argc;
unsigned char *argv[1]; /* may secretly be longer than 1 element */
--- 34,38 ----
struct alias_expansion {
! struct svccmd *base;
unsigned int argc;
unsigned char *argv[1]; /* may secretly be longer than 1 element */
***************
*** 318,331 ****
if (!base_cmd) return 0;
- if (base_cmd->command->min_argc > argc) {
- send_message(user, bot, MSG_MISSING_PARAMS, base_cmd->name);
- goto refuse;
- }
memset(&cmd, 0, sizeof(cmd));
cmd.name = base_cmd->name;
cmd.flags = base_cmd->command->flags;
! for(cmd2 = base_cmd; cmd2; cmd2 = cmd2->template)
! {
cmd.flags |= cmd2->flags;
cmd.req_account_flags |= cmd2->req_account_flags;
--- 318,326 ----
if (!base_cmd) return 0;
memset(&cmd, 0, sizeof(cmd));
cmd.name = base_cmd->name;
cmd.flags = base_cmd->command->flags;
! for (cmd2 = base_cmd; cmd2; cmd2 = cmd2->template) {
cmd.flags |= cmd2->flags;
cmd.req_account_flags |= cmd2->req_account_flags;
***************
*** 345,348 ****
--- 340,347 ----
if (cmd.flags & (MODCMD_REQUIRE_NETWORK_HELPER|MODCMD_REQUIRE_SUPPORT_HELPER)) cmd.flags |= MODCMD_REQUIRE_AUTHED;
+ if (base_cmd->command->min_argc > argc) {
+ send_message(user, bot, MSG_MISSING_PARAMS, base_cmd->name);
+ goto refuse;
+ }
if (cmd.min_opserv_level > 0) {
if (!oper_has_access(user, bot, cmd.min_opserv_level, 0)) goto refuse;
***************
*** 559,568 ****
int
svccmd_send_help_2(struct userNode *user, struct userNode *bot, struct service *service, const char *topic) {
! struct svccmd *cmd = dict_find(service->commands, topic, NULL);
! if (!cmd) {
send_message(user, bot, MSG_TOPIC_UNKNOWN);
return 0;
}
- return svccmd_send_help(user, bot, cmd);
}
--- 558,569 ----
int
svccmd_send_help_2(struct userNode *user, struct userNode *bot, struct service *service, const char *topic) {
! struct svccmd *cmd;
! if ((cmd = dict_find(service->commands, topic, NULL))) {
! return svccmd_send_help(user, bot, cmd);
! } else {
! /* TODO: fall back to a default helpfile (or module helpfile) instead */
send_message(user, bot, MSG_TOPIC_UNKNOWN);
return 0;
}
}
***************
*** 723,736 ****
}
}
! return svccmd_invoke_real(user, cmd->parent, cmd, channel, new_argc, new_argv, 0);
}
static MODCMD_FUNC(cmd_bind) {
struct service *service;
- struct module *module;
- struct modcmd *basecmd;
struct svccmd *template, *newcmd;
! char *svcname, *newname, *cmdname, *sep;
! char buf[MAXLEN];
assert(argc > 3);
--- 724,734 ----
}
}
! return svccmd_invoke_real(user, cmd->parent, exp->base, channel, new_argc, new_argv, 0);
}
static MODCMD_FUNC(cmd_bind) {
struct service *service;
struct svccmd *template, *newcmd;
! char *svcname, *newname, *cmdname;
assert(argc > 3);
***************
*** 744,777 ****
}
! if ((basecmd = dict_find(service->commands, newname, NULL))) {
send_message(user, cmd->parent->bot, "%s already has a command bound as %s", service->bot->nick, newname);
return 0;
}
- if ((sep = strchr(cmdname, '.'))) {
- memcpy(buf, cmdname, sep-cmdname);
- buf[sep-cmdname] = 0;
- if (!(module = module_find(buf))) {
- send_message(user, cmd->parent->bot, MSG_MODULE_UNKNOWN, buf);
- return 0;
- }
- if (!(basecmd = dict_find(module->commands, sep+1, NULL))) {
- send_message(user, cmd->parent->bot, "Unknown command name %s (in module %s)", sep+1, module->name);
- return 0;
- }
- template = basecmd->defaults;
- } else {
- if (!(template = dict_find(service->commands, cmdname, NULL))) {
- send_message(user, cmd->parent->bot, "%s has nothing bound as command %s", service->bot->nick, cmdname);
- return 0;
- }
- basecmd = template->command;
- }
-
newcmd = calloc(1, sizeof(*newcmd));
newcmd->name = strdup(newname);
newcmd->parent = service;
! newcmd->command = basecmd;
newcmd->template = template;
if (argc > 4) {
--- 742,761 ----
}
! if ((newcmd = dict_find(service->commands, newname, NULL))) {
send_message(user, cmd->parent->bot, "%s already has a command bound as %s", service->bot->nick, newname);
return 0;
}
newcmd = calloc(1, sizeof(*newcmd));
newcmd->name = strdup(newname);
newcmd->parent = service;
! if (!(template = svccmd_resolve_name(newcmd, cmdname))) {
! send_message(user, cmd->parent->bot, "Unknown command name %s (relative to service %s)", cmdname, service->bot->nick);
! free(newcmd->name);
! free(newcmd);
! return 0;
! }
newcmd->template = template;
+ newcmd->command = template->command;
if (argc > 4) {
***************
*** 788,792 ****
}
exp = calloc(1, sizeof(*exp)+(argc-4)*sizeof(exp->argv[0]));
! exp->base = basecmd;
exp->argc = argc - 3;
newcmd->command = expand_alias_command;
--- 772,776 ----
}
exp = calloc(1, sizeof(*exp)+(argc-4)*sizeof(exp->argv[0]));
! exp->base = template;
exp->argc = argc - 3;
newcmd->command = expand_alias_command;
***************
*** 845,849 ****
}
dict_insert(obj, "aliased", alloc_record_data_string_list(slist));
! modcmd = expn->base;
} else {
modcmd = cmd->command;
--- 829,833 ----
}
dict_insert(obj, "aliased", alloc_record_data_string_list(slist));
! modcmd = expn->base->command;
} else {
modcmd = cmd->command;
***************
*** 889,893 ****
}
if (cmd->template != modcmd->defaults) {
! if (cmd->template->parent) {
sprintf(buf, "%s.%s", cmd->template->parent->bot->nick, cmd->template->name);
} else {
--- 873,879 ----
}
if (cmd->template != modcmd->defaults) {
! if (cmd->template->parent == cmd->parent) {
! sprintf(buf, "%s", cmd->template->name);
! } else if (cmd->template->parent) {
sprintf(buf, "%s.%s", cmd->template->parent->bot->nick, cmd->template->name);
} else {
***************
*** 1100,1104 ****
expn = calloc(1, sizeof(*expn) + (slist->used-1)*sizeof(expn->argv[0]));
! expn->base = svccmd->command;
for (nn=0; nn<slist->used; ++nn) expn->argv[nn] = strdup(slist->list[nn]);
expn->argc = nn;
--- 1086,1090 ----
expn = calloc(1, sizeof(*expn) + (slist->used-1)*sizeof(expn->argv[0]));
! expn->base = svccmd;
for (nn=0; nn<slist->used; ++nn) expn->argv[nn] = strdup(slist->list[nn]);
expn->argc = nn;
***************
*** 1137,1141 ****
}
svccmd->extra = expn = calloc(1, sizeof(*expn) + (argc-1)*sizeof(expn->argv[0]));
! expn->base = svccmd->template->command;
expn->argc = argc;
for (nn=0; nn<argc; nn++) expn->argv[nn] = strdup(argv[nn]);
--- 1123,1127 ----
}
svccmd->extra = expn = calloc(1, sizeof(*expn) + (argc-1)*sizeof(expn->argv[0]));
! expn->base = svccmd->template;
expn->argc = argc;
for (nn=0; nn<argc; nn++) expn->argv[nn] = strdup(argv[nn]);
|