Fix warnings about shadowed variables, and use -Wshadow in maintainer mode.
[srvx.git] / src / proto-common.c
index abb3a91cd74491dc560b70362e753f860d3efab4..3a14c68bdc0670b0371028711c61d30fa8d20273 100644 (file)
@@ -57,7 +57,7 @@ extern new_user_func_t *nuf_list;
 extern unsigned int nuf_size, nuf_used;
 extern del_user_func_t *duf_list;
 extern unsigned int duf_size, duf_used;
-extern time_t boot_time;
+extern unsigned long boot_time;
 
 void received_ping(void);
 
@@ -105,7 +105,7 @@ void replay_event_loop(void)
     while (!quit_services) {
         if (!replay_connected) {
             /* this time fudging is to get some of the logging right */
-            self->link = self->boot = now;
+            self->link_time = self->boot = now;
             cManager.uplink->state = AUTHENTICATING;
             irc_introduce(cManager.uplink->password);
             replay_connected = 1;
@@ -155,7 +155,7 @@ void
 replay_read_line(void)
 {
     struct tm timestamp;
-    time_t new_time;
+    unsigned long new_time;
 
     if (replay_line[0]) return;
   read_line:
@@ -185,7 +185,7 @@ replay_read_line(void)
     timestamp.tm_year = strtoul(replay_line+16, NULL, 10) - 1900;
     timestamp.tm_isdst = 0;
     new_time = mktime(&timestamp);
-    if (new_time == -1) {
+    if (new_time == (unsigned long)-1) {
         log_module(MAIN_LOG, LOG_ERROR, "Unable to parse time struct tm_sec=%d tm_min=%d tm_hour=%d tm_mday=%d tm_mon=%d tm_year=%d", timestamp.tm_sec, timestamp.tm_min, timestamp.tm_hour, timestamp.tm_mday, timestamp.tm_mon, timestamp.tm_year);
     } else {
         now = new_time;
@@ -274,7 +274,7 @@ close_socket(void)
         replay_connected = 0;
         socket_destroyed(socket_io_fd);
     } else {
-        ioset_close(socket_io_fd, 1);
+        ioset_close(socket_io_fd, 3);
         socket_io_fd = NULL;
     }
 }
@@ -311,11 +311,11 @@ static CMD_FUNC(cmd_pass)
         return 0;
     true_pass = cManager.uplink->their_password;
     if (true_pass && strcmp(true_pass, argv[1])) {
-       /* It might be good to mark the uplink as unavailable when
-          this happens, though there should be a way of resetting
-          the flag. */
-       irc_squit(self, "Incorrect password received.", NULL);
-       return 1;
+        /* It might be good to mark the uplink as unavailable when
+           this happens, though there should be a way of resetting
+           the flag. */
+        irc_squit(self, "Incorrect password received.", NULL);
+        return 1;
     }
 
     cManager.uplink->state = BURSTING;
@@ -330,13 +330,13 @@ static CMD_FUNC(cmd_dummy)
 
 static CMD_FUNC(cmd_error)
 {
-    if (argv[1]) log_module(MAIN_LOG, LOG_ERROR, "Error: %s", argv[1]);
+    if (argv[1]) log_module(MAIN_LOG, LOG_ERROR, "Error from ircd: %s", argv[1]);
     log_module(MAIN_LOG, LOG_ERROR, "Error received from uplink, squitting.");
 
     if (cManager.uplink->state != CONNECTED) {
-       /* Error messages while connected should be fine. */
-       cManager.uplink->flags |= UPLINK_UNAVAILABLE;
-       log_module(MAIN_LOG, LOG_ERROR, "Disabling uplink.");
+        /* Error messages while connected should be fine. */
+        cManager.uplink->flags |= UPLINK_UNAVAILABLE;
+        log_module(MAIN_LOG, LOG_ERROR, "Disabling uplink.");
     }
 
     close_socket();
@@ -353,7 +353,8 @@ static CMD_FUNC(cmd_stats)
         return 0;
     switch (argv[1][0]) {
     case 'u': {
-        unsigned int uptime = now - boot_time;
+        unsigned long uptime;
+        uptime = now - boot_time;
         irc_numeric(un, RPL_STATSUPTIME, ":Server Up %d days %d:%02d:%02d",
                     uptime/(24*60*60), (uptime/(60*60))%24, (uptime/60)%60, uptime%60);
         irc_numeric(un, RPL_MAXCONNECTIONS, ":Highest connection count: %d (%d clients)",
@@ -431,7 +432,7 @@ privmsg_chan_helper(struct chanNode *cn, void *data)
 {
     struct privmsg_desc *pd = data;
     struct modeNode *mn;
-    struct chanmsg_func *cf = &chanmsg_funcs[(unsigned char)pd->text[0]];
+    struct chanmsg_func *cf;
     int x;
 
     /* Don't complain if it can't find the modeNode because the channel might
@@ -440,9 +441,10 @@ privmsg_chan_helper(struct chanNode *cn, void *data)
         mn->idle_since = now;
 
     /* Never send a NOTICE to a channel to one of the services */
-    if (!pd->is_notice && cf->func
-        && ((cn->modes & MODE_REGISTERED) || GetUserMode(cn, cf->service)))
-        cf->func(pd->user, cn, pd->text+1, cf->service);
+    cf = &chanmsg_funcs[(unsigned char)pd->text[0]];
+    if (cf->func && !pd->is_notice
+        && GetUserMode(cn, cf->service) && !IsDeaf(cf->service))
+        cf->func(pd->user, cn, pd->text+1, cf->service, pd->is_notice);
 
     /* This catches *all* text sent to the channel that the services server sees */
     for (x = 0; x < ALLCHANMSG_FUNCS_MAX; x++) {
@@ -450,7 +452,7 @@ privmsg_chan_helper(struct chanNode *cn, void *data)
        if (!cf->func)
            break; /* end of list */
        else
-           cf->func(pd->user, cn, pd->text, cf->service);
+           cf->func(pd->user, cn, pd->text, cf->service, pd->is_notice);
     }
 }
 
@@ -494,7 +496,7 @@ void
 reg_chanmsg_func(unsigned char prefix, struct userNode *service, chanmsg_func_t handler)
 {
     if (chanmsg_funcs[prefix].func)
-       log_module(MAIN_LOG, LOG_WARNING, "Re-registering new chanmsg handler for character `%c'.", prefix);
+        log_module(MAIN_LOG, LOG_WARNING, "Re-registering new chanmsg handler for character `%c'.", prefix);
     chanmsg_funcs[prefix].func = handler;
     chanmsg_funcs[prefix].service = service;
 }
@@ -525,17 +527,47 @@ void
 reg_mode_change_func(mode_change_func_t handler)
 {
     if (mcf_used == mcf_size) {
-       if (mcf_size) {
-           mcf_size <<= 1;
-           mcf_list = realloc(mcf_list, mcf_size*sizeof(mode_change_func_t));
-       } else {
-           mcf_size = 8;
-           mcf_list = malloc(mcf_size*sizeof(mode_change_func_t));
-       }
+        if (mcf_size) {
+            mcf_size <<= 1;
+            mcf_list = realloc(mcf_list, mcf_size*sizeof(mode_change_func_t));
+        } else {
+            mcf_size = 8;
+            mcf_list = malloc(mcf_size*sizeof(mode_change_func_t));
+        }
     }
     mcf_list[mcf_used++] = handler;
 }
 
+static oper_func_t *of_list;
+static unsigned int of_size = 0, of_used = 0;
+
+void
+reg_oper_func(oper_func_t handler)
+{
+    if (of_used == of_size) {
+        if (of_size) {
+            of_size <<= 1;
+            of_list = realloc(of_list, of_size*sizeof(oper_func_t));
+        } else {
+            of_size = 8;
+            of_list = malloc(of_size*sizeof(oper_func_t));
+        }
+    }
+    of_list[of_used++] = handler;
+}
+
+static void
+call_oper_funcs(struct userNode *user)
+{
+    unsigned int n;
+    if (IsLocal(user))
+        return;
+    for (n=0; (n<of_used) && !user->dead; n++)
+    {
+        of_list[n](user);
+    }
+}
+
 struct mod_chanmode *
 mod_chanmode_alloc(unsigned int argc)
 {