Fix compilation with gcc 4.3 and glibc 2.8.90.
[srvx.git] / src / modcmd.c
index f30a4e9f073daf7688478cbb309229c15de416e8..da6826a71d88042c561195261f784fa3751f5623 100644 (file)
@@ -433,6 +433,7 @@ modcmd_register(struct module *module, const char *name, modcmd_func_t func, uns
  */
 int
 svccmd_can_invoke(struct userNode *user, struct userNode *bot, struct svccmd *cmd, struct chanNode *channel, int options) {
+    extern struct userNode *chanserv;
     unsigned int uData_checked = 0;
     struct userData *uData = NULL;
     int rflags = 0, flags = cmd->effective_flags;
@@ -466,15 +467,17 @@ svccmd_can_invoke(struct userNode *user, struct userNode *bot, struct svccmd *cm
             return 0;
         }
         if (flags & MODCMD_REQUIRE_REGCHAN) {
-            if (!channel->channel_info) {
+            if (!chanserv) {
+                /* Just use the inferred MODCMD_REQUIRE_CHANNEL. */
+            } else if (!channel->channel_info) {
                 if (options & SVCCMD_NOISY)
                     send_message(user, bot, "MCMSG_CHAN_NOT_REGISTERED", channel->name);
                 return 0;
             } else if (IsSuspended(channel->channel_info) && !(flags & MODCMD_IGNORE_CSUSPEND)) {
-                /* allow security-override users to always ignore channel suspensions, but flag it as a staff command */
-                if (!user->handle_info
-                    || !HANDLE_FLAGGED(user->handle_info, HELPING)
-                    || (flags & MODCMD_NEVER_CSUSPEND)) {
+                /* Allow security-override users to ignore most channel
+                 * suspensions, but flag that use as a staff command.
+                 */
+                if (!IsHelping(user) || (flags & MODCMD_NEVER_CSUSPEND)) {
                     if (options & SVCCMD_NOISY)
                         send_message(user, bot, "MCMSG_CHAN_SUSPENDED", channel->name, channel->channel_info->suspended->reason);
                     return 0;
@@ -485,7 +488,9 @@ svccmd_can_invoke(struct userNode *user, struct userNode *bot, struct svccmd *cm
         if (flags & MODCMD_REQUIRE_CHANUSER) {
             if (!uData_checked)
                 uData = _GetChannelUser(channel->channel_info, user->handle_info, 1, 0), uData_checked = 1;
-            if (!uData) {
+            if (!chanserv) {
+                /* Assume someone knows what they're doing. */
+            } else if (!uData) {
                 if (options & SVCCMD_NOISY)
                     send_message(user, bot, "MCMSG_NO_CHANNEL_ACCESS", channel->name);
                 return 0;
@@ -608,6 +613,8 @@ svccmd_expand_alias(struct svccmd *cmd, unsigned int old_argc, char *old_argv[],
                 log_module(MAIN_LOG, LOG_ERROR, "Alias expansion parse error in %s (near %s; %s.%s arg %d).", arg, end_num, cmd->parent->bot->nick, cmd->name, ii);
                 return 0;
             }
+            if (lbound >= old_argc)
+                return -1;
             if (ubound >= old_argc)
                 ubound = old_argc - 1;
             if (lbound < old_argc)
@@ -690,11 +697,17 @@ svccmd_invoke_argv(struct userNode *user, struct service *service, struct chanNo
     /* Expand the alias arguments, if there are any. */
     if (cmd->alias.used) {
         char *new_argv[MAXNUMPARAMS];
-        argc = svccmd_expand_alias(cmd, argc, argv, new_argv);
-        if (!argc) {
-            send_message(service->bot, user, "MCMSG_ALIAS_ERROR", cmd->name);
+        int res;
+
+        res = svccmd_expand_alias(cmd, argc, argv, new_argv);
+        if (res < 0) {
+            send_message(user, service->bot, "MSG_MISSING_PARAMS", cmd->name);
+            return 0;
+        } else if (res == 0) {
+            send_message(user, service->bot, "MCMSG_ALIAS_ERROR", cmd->name);
             return 0;
         }
+        argc = res;
         argv = new_argv;
 
         /* Try again to grab a handle to the channel after alias
@@ -977,8 +990,9 @@ check_alias_args(char *argv[], unsigned int argc) {
             continue;
         } else if (isdigit(argv[arg][1])) {
             char *end_num;
+            unsigned long arg;
 
-            strtoul(argv[arg]+1, &end_num, 10);
+            arg = strtoul(argv[arg]+1, &end_num, 10);
             switch (end_num[0]) {
             case 0:
                 continue;
@@ -1834,17 +1848,14 @@ static MODCMD_FUNC(cmd_dump_messages) {
         reply("MSG_INTERNAL_FAILURE");
         return 0;
     }
-    if ((res = setjmp(ctx->jbuf)) != 0) {
-        ctx->complex.used = 0; /* to avoid false assert()s in close */
-        saxdb_close_context(ctx);
-        fclose(pf);
+    if ((res = setjmp(*saxdb_jmp_buf(ctx))) != 0) {
+        saxdb_close_context(ctx, 1);
         reply("MCMSG_MESSAGE_DUMP_FAILED", strerror(res));
         return 0;
     } else {
         for (it = dict_first(lang_C->messages); it; it = iter_next(it))
             saxdb_write_string(ctx, iter_key(it), iter_data(it));
-        saxdb_close_context(ctx);
-        fclose(pf);
+        saxdb_close_context(ctx, 1);
         reply("MCMSG_MESSAGES_DUMPED", fname);
         return 1;
     }
@@ -1856,7 +1867,7 @@ static MODCMD_FUNC(cmd_version) {
      * command or its accessibility to normal IRC users, except to add
      * copyright information pertaining to changes you make to srvx.
      */
-    send_message_type(4, user, cmd->parent->bot, "$b"PACKAGE_STRING"$b ("CODENAME"), Built: "__DATE__", "__TIME__".  Copyright 2000-2007 srvx Development Team.");
+    send_message_type(4, user, cmd->parent->bot, "$b"PACKAGE_STRING"$b ("CODENAME"), Built: "__DATE__", "__TIME__".  Copyright 2000-2008 srvx Development Team.");
     if (argc > 1)
         send_message_type(4, user, cmd->parent->bot, "%s", git_version);
     else