]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-info.c
const'ify command name variable in _COMMAND strcuture
[ngircd-alex.git] / src / ngircd / irc-info.c
index 5a8555a0606f8095229feffffc48dda6efab0d92..7e0bf63c8911d6bef8a235c8cb6e685f319c2dc9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2009 Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2010 Alexander Barton <alex@barton.de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -465,6 +465,10 @@ uptime_mins(time_t *now)
 }
 
 
+/**
+ * Handler for the IRC command "STATS".
+ * See RFC 2812 section 3.4.4.
+ */
 GLOBAL bool
 IRC_STATS( CLIENT *Client, REQUEST *Req )
 {
@@ -475,11 +479,12 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
        time_t time_now;
        unsigned int days, hrs, mins;
 
-       assert( Client != NULL );
-       assert( Req != NULL );
+       assert(Client != NULL);
+       assert(Req != NULL);
 
        if (Req->argc > 2)
-               return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command);
+               return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+                                         Client_ID(Client), Req->command);
 
        /* use prefix to determine "From" */
        if (Client_Type(Client) == CLIENT_SERVER)
@@ -487,18 +492,21 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
        else
                from = Client;
 
-       if (! from)
-               return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix);
+       if (!from)
+               return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
+                                         Client_ID(Client), Req->prefix);
 
        if (Req->argc == 2) {
                /* forward to another server? */
-               target = Client_Search( Req->argv[1] );
-               if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER ))
-                       return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
+               target = Client_Search(Req->argv[1]);
+               if ((!target) || (Client_Type(target) != CLIENT_SERVER))
+                       return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
+                                                Client_ID(from), Req->argv[1]);
 
-               iftarget != Client_ThisServer()) {
+               if (target != Client_ThisServer()) {
                        /* forward to another server */
-                       return IRC_WriteStrClientPrefix( target, from, "STATS %s %s", Req->argv[0], Req->argv[1] );
+                       return IRC_WriteStrClientPrefix(target, from,
+                                    "STATS %s %s", Req->argv[0], Req->argv[1]);
                }
        }
 
@@ -508,57 +516,70 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
                query = '*';
 
        switch (query) {
-               case 'l':       /* Links */
-               case 'L':
-                       time_now = time(NULL);
-                       for (con = Conn_First(); con != NONE ;con = Conn_Next(con)) {
-                               cl = Conn_GetClient(con);
-                               if (!cl)
-                                       continue;
-                               if ((Client_Type(cl) == CLIENT_SERVER) || (cl == Client)) {
-                                       /* Server link or our own connection */
+       case 'l':       /* Link status (servers and own link) */
+       case 'L':
+               time_now = time(NULL);
+               for (con = Conn_First(); con != NONE; con = Conn_Next(con)) {
+                       cl = Conn_GetClient(con);
+                       if (!cl)
+                               continue;
+                       if ((Client_Type(cl) == CLIENT_SERVER)
+                           || (cl == Client)) {
+                               /* Server link or our own connection */
 #ifdef ZLIB
-                                       if (Conn_Options(con) & CONN_ZIP) {
-                                               if (!IRC_WriteStrClient(from, RPL_STATSLINKINFOZIP_MSG,
-                                                       Client_ID(from), Client_Mask(cl), Conn_SendQ(con),
-                                                       Conn_SendMsg(con), Zip_SendBytes(con), Conn_SendBytes(con),
-                                                       Conn_RecvMsg(con), Zip_RecvBytes(con), Conn_RecvBytes(con), (long)(time_now - Conn_StartTime(con))))
-                                                               return DISCONNECTED;
-                                               continue;
-                                       }
-#endif
-                                       if (!IRC_WriteStrClient(from, RPL_STATSLINKINFO_MSG, Client_ID(from),
-                                               Client_Mask(cl), Conn_SendQ(con), Conn_SendMsg(con), Conn_SendBytes(con),
-                                               Conn_RecvMsg(con), Conn_RecvBytes(con), (long)(time_now - Conn_StartTime(con))))
-                                                       return DISCONNECTED;
-                               }
-                       }
-                       break;
-               case 'm':       /* IRC-Commands */
-               case 'M':
-                       cmd = Parse_GetCommandStruct( );
-                       for (; cmd->name ; cmd++) {
-                               if (cmd->lcount == 0 && cmd->rcount == 0)
+                               if (Conn_Options(con) & CONN_ZIP) {
+                                       if (!IRC_WriteStrClient
+                                           (from, RPL_STATSLINKINFOZIP_MSG,
+                                            Client_ID(from), Client_Mask(cl),
+                                            Conn_SendQ(con), Conn_SendMsg(con),
+                                            Zip_SendBytes(con),
+                                            Conn_SendBytes(con),
+                                            Conn_RecvMsg(con),
+                                            Zip_RecvBytes(con),
+                                            Conn_RecvBytes(con),
+                                            (long)(time_now - Conn_StartTime(con))))
+                                               return DISCONNECTED;
                                        continue;
-                               if (!IRC_WriteStrClient(from, RPL_STATSCOMMANDS_MSG, Client_ID(from),
-                                               cmd->name, cmd->lcount, cmd->bytes, cmd->rcount))
-                                                       return DISCONNECTED;
+                               }
+#endif
+                               if (!IRC_WriteStrClient
+                                   (from, RPL_STATSLINKINFO_MSG,
+                                    Client_ID(from), Client_Mask(cl),
+                                    Conn_SendQ(con), Conn_SendMsg(con),
+                                    Conn_SendBytes(con), Conn_RecvMsg(con),
+                                    Conn_RecvBytes(con),
+                                    (long)(time_now - Conn_StartTime(con))))
+                                       return DISCONNECTED;
                        }
-                       break;
-               case 'u':       /* server uptime */
-               case 'U':
-                       time_now = time(NULL) - NGIRCd_Start;
-                       days = uptime_days(&time_now);
-                       hrs = uptime_hrs(&time_now);
-                       mins = uptime_mins(&time_now);
-                       if (!IRC_WriteStrClient(from, RPL_STATSUPTIME, Client_ID(from),
-                                       days, hrs, mins, (unsigned int) time_now))
-                                               return DISCONNECTED;
-                       break;
+               }
+               break;
+       case 'm':       /* IRC command status (usage count) */
+       case 'M':
+               cmd = Parse_GetCommandStruct();
+               for (; cmd->name; cmd++) {
+                       if (cmd->lcount == 0 && cmd->rcount == 0)
+                               continue;
+                       if (!IRC_WriteStrClient
+                           (from, RPL_STATSCOMMANDS_MSG, Client_ID(from),
+                            cmd->name, cmd->lcount, cmd->bytes, cmd->rcount))
+                               return DISCONNECTED;
+               }
+               break;
+       case 'u':       /* Server uptime */
+       case 'U':
+               time_now = time(NULL) - NGIRCd_Start;
+               days = uptime_days(&time_now);
+               hrs = uptime_hrs(&time_now);
+               mins = uptime_mins(&time_now);
+               if (!IRC_WriteStrClient(from, RPL_STATSUPTIME, Client_ID(from),
+                                      days, hrs, mins, (unsigned int)time_now))
+                       return DISCONNECTED;
+               break;
        }
 
        IRC_SetPenalty(from, 2);
-       return IRC_WriteStrClient(from, RPL_ENDOFSTATS_MSG, Client_ID(from), query);
+       return IRC_WriteStrClient(from, RPL_ENDOFSTATS_MSG,
+                                 Client_ID(from), query);
 } /* IRC_STATS */
 
 
@@ -972,6 +993,13 @@ IRC_WHOIS( CLIENT *Client, REQUEST *Req )
                if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
        }
 
+       /* Connected using SSL? */
+       if (Conn_UsesSSL(Client_Conn(c))) {
+               if (!IRC_WriteStrClient
+                   (from, RPL_WHOISSSL_MSG, Client_ID(from), Client_ID(c)))
+                       return DISCONNECTED;
+       }
+
        /* Idle and signon time (local clients only!) */
        if (Client_Conn(c) > NONE ) {
                if (! IRC_WriteStrClient(from, RPL_WHOISIDLE_MSG,
@@ -1155,6 +1183,10 @@ IRC_Send_LUSERS( CLIENT *Client )
        if(! IRC_WriteStrClient(Client, RPL_NETUSERS_MSG, Client_ID(Client),
                        cnt, max, cnt, max))
                return DISCONNECTED;
+       /* Connection counters */
+       if (! IRC_WriteStrClient(Client, RPL_STATSCONN_MSG, Client_ID(Client),
+                       Conn_CountMax(), Conn_CountAccepted()))
+               return DISCONNECTED;
 #endif
        
        return CONNECTED;