]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-info.c
Simplify mode checking on channels and users within a channel
[ngircd-alex.git] / src / ngircd / irc-info.c
index 046648fdfa02cab53369ccbf81f33de40801de0f..5d2ae36ddda7afc217f504368ca143e7f415d6c9 100644 (file)
@@ -165,7 +165,7 @@ IRC_WHO_Channel(CLIENT *Client, CHANNEL *Chan, bool OnlyOps)
        is_member = Channel_IsMemberOf(Chan, Client);
 
        /* Secret channel? */
-       if (!is_member && strchr(Channel_Modes(Chan), 's'))
+       if (!is_member && Channel_HasMode(Chan, 's'))
                return IRC_WriteStrClient(Client, RPL_ENDOFWHO_MSG,
                                          Client_ID(Client), Channel_Name(Chan));
 
@@ -174,11 +174,11 @@ IRC_WHO_Channel(CLIENT *Client, CHANNEL *Chan, bool OnlyOps)
                c = Channel_GetClient(cl2chan);
 
                client_modes = Client_Modes(c);
-               is_ircop = strchr(client_modes, 'o') != NULL;
+               is_ircop = Client_HasMode(c, 'o');
                if (OnlyOps && !is_ircop)
                        continue;
 
-               is_visible = strchr(client_modes, 'i') == NULL;
+               is_visible = Client_HasMode(c, 'i');
                if (is_member || is_visible) {
                        strlcpy(flags, who_flags_status(client_modes),
                                sizeof(flags));
@@ -275,7 +275,7 @@ IRC_WHO_Mask(CLIENT *Client, char *Mask, bool OnlyOps)
                        break;
 
                strlcpy(flags, who_flags_status(Client_Modes(c)), sizeof(flags));
-               if (strchr(Client_Modes(c), 'o'))
+               if (Client_HasMode(c, 'o'))
                        strlcat(flags, "*", sizeof(flags));
 
                if (!write_whoreply(Client, c, "*", flags))
@@ -330,7 +330,7 @@ IRC_WHOIS_SendReply(CLIENT *Client, CLIENT *from, CLIENT *c)
                cl2chan = Channel_NextChannelOf(c, cl2chan);
 
                /* Secret channel? */
-               if (strchr(Channel_Modes(chan), 's')
+               if (Channel_HasMode(chan, 's')
                    && !Channel_IsMemberOf(chan, Client))
                        continue;
 
@@ -381,10 +381,19 @@ IRC_WHOIS_SendReply(CLIENT *Client, CLIENT *from, CLIENT *c)
                return DISCONNECTED;
 
        /* Connected using SSL? */
-       if (Conn_UsesSSL(Client_Conn(c)) &&
-           !IRC_WriteStrClient(from, RPL_WHOISSSL_MSG, Client_ID(from),
-                               Client_ID(c)))
-               return DISCONNECTED;
+       if (Conn_UsesSSL(Client_Conn(c))) {
+               if (!IRC_WriteStrClient(from, RPL_WHOISSSL_MSG, Client_ID(from),
+                                       Client_ID(c)))
+                       return DISCONNECTED;
+
+               /* Certificate fingerprint? */
+               if (Conn_GetCertFp(Client_Conn(c)) &&
+                   from == c &&
+                   !IRC_WriteStrClient(from, RPL_WHOISCERTFP_MSG,
+                                       Client_ID(from), Client_ID(c),
+                                       Conn_GetCertFp(Client_Conn(c))))
+                       return DISCONNECTED;
+       }
 
        /* Registered nickname? */
        if (Client_HasMode(c, 'R') &&
@@ -439,51 +448,37 @@ WHOWAS_EntryWrite(CLIENT *prefix, WHOWAS *entry)
                                  entry->id, entry->server, t_str);
 }
 
-static bool
-Show_MOTD_Start(CLIENT *Client)
-{
-       return IRC_WriteStrClient(Client, RPL_MOTDSTART_MSG,
-                                 Client_ID( Client ), Client_ID( Client_ThisServer( )));
-}
-
-static bool
-Show_MOTD_Sendline(CLIENT *Client, const char *msg)
-{
-       return IRC_WriteStrClient(Client, RPL_MOTD_MSG, Client_ID( Client ), msg);
-}
-
-static bool
-Show_MOTD_End(CLIENT *Client)
-{
-       if (!IRC_WriteStrClient(Client, RPL_ENDOFMOTD_MSG, Client_ID(Client)))
-               return DISCONNECTED;
-
-       if (*Conf_CloakHost)
-               return IRC_WriteStrClient(Client, RPL_HOSTHIDDEN_MSG,
-                                         Client_ID(Client),
-                                         Client_Hostname(Client));
-
-       return CONNECTED;
-}
-
 #ifdef SSL_SUPPORT
-static bool Show_MOTD_SSLInfo(CLIENT *Client)
+static bool
+Show_MOTD_SSLInfo(CLIENT *Client)
 {
-       bool ret = true;
-       char buf[COMMAND_LEN] = "Connected using Cipher ";
-
-       if (!Conn_GetCipherInfo(Client_Conn(Client), buf + 23, sizeof buf - 23))
-               return true;
+       char buf[COMMAND_LEN];
+       char c_str[128];
+
+       if (Conn_GetCipherInfo(Client_Conn(Client), c_str, sizeof(c_str))) {
+               snprintf(buf, sizeof(buf), "Connected using Cipher %s", c_str);
+               if (!IRC_WriteStrClient(Client, RPL_MOTD_MSG,
+                                       Client_ID(Client), buf))
+                       return false;
+       }
 
-       if (!Show_MOTD_Sendline(Client, buf))
-               ret = false;
+       if (Conn_GetCertFp(Client_Conn(Client))) {
+               snprintf(buf, sizeof(buf),
+                        "Your client certificate fingerprint is: %s",
+                        Conn_GetCertFp(Client_Conn(Client)));
+               if (!IRC_WriteStrClient(Client, RPL_MOTD_MSG,
+                                       Client_ID(Client), buf))
+                       return false;
+       }
 
-       return ret;
+       return true;
 }
 #else
-static inline bool
+static bool
 Show_MOTD_SSLInfo(UNUSED CLIENT *c)
-{ return true; }
+{
+       return true;
+}
 #endif
 
 /* Global functions */
@@ -838,7 +833,7 @@ IRC_NAMES( CLIENT *Client, REQUEST *Req )
        while (c) {
                if (Client_Type(c) == CLIENT_USER
                    && Channel_FirstChannelOf(c) == NULL
-                   && !strchr(Client_Modes(c), 'i'))
+                   && !Client_HasMode(c, 'i'))
                {
                        /* its a user, concatenate ... */
                        if (rpl[strlen(rpl) - 1] != ':')
@@ -1409,7 +1404,7 @@ IRC_Send_LUSERS(CLIENT *Client)
 
        assert(Client != NULL);
 
-       /* Users, services and serevers in the network */
+       /* Users, services and servers in the network */
        if (!IRC_WriteStrClient(Client, RPL_LUSERCLIENT_MSG, Client_ID(Client),
                                Client_UserCount(), Client_ServiceCount(),
                                Client_ServerCount()))
@@ -1477,7 +1472,8 @@ IRC_Show_MOTD( CLIENT *Client )
        if (len_tot == 0 && !Conn_UsesSSL(Client_Conn(Client)))
                return IRC_WriteStrClient(Client, ERR_NOMOTD_MSG, Client_ID(Client));
 
-       if (!Show_MOTD_Start(Client))
+       if (!IRC_WriteStrClient(Client, RPL_MOTDSTART_MSG, Client_ID(Client),
+                               Client_ID(Client_ThisServer())))
                return DISCONNECTED;
 
        line = array_start(&Conf_Motd);
@@ -1487,14 +1483,23 @@ IRC_Show_MOTD( CLIENT *Client )
                assert(len_tot >= len_str);
                len_tot -= len_str;
 
-               if (!Show_MOTD_Sendline(Client, line))
+               if (!IRC_WriteStrClient(Client, RPL_MOTD_MSG, Client_ID(Client), line))
                        return DISCONNECTED;
                line += len_str;
        }
 
        if (!Show_MOTD_SSLInfo(Client))
                return DISCONNECTED;
-       return Show_MOTD_End(Client);
+
+       if (!IRC_WriteStrClient(Client, RPL_ENDOFMOTD_MSG, Client_ID(Client)))
+               return DISCONNECTED;
+
+       if (*Conf_CloakHost)
+               return IRC_WriteStrClient(Client, RPL_HOSTHIDDEN_MSG,
+                                         Client_ID(Client),
+                                         Client_Hostname(Client));
+
+       return CONNECTED;
 } /* IRC_Show_MOTD */
 
 /**
@@ -1525,7 +1530,7 @@ IRC_Send_NAMES(CLIENT * Client, CHANNEL * Chan)
                return CONNECTED;
 
        /* Secret channel? */
-       if (!is_member && strchr(Channel_Modes(Chan), 's'))
+       if (!is_member && Channel_HasMode(Chan, 's'))
                return CONNECTED;
 
        snprintf(str, sizeof(str), RPL_NAMREPLY_MSG, Client_ID(Client), "=",
@@ -1534,7 +1539,7 @@ IRC_Send_NAMES(CLIENT * Client, CHANNEL * Chan)
        while (cl2chan) {
                cl = Channel_GetClient(cl2chan);
 
-               if (strchr(Client_Modes(cl), 'i'))
+               if (Client_HasMode(cl, 'i'))
                        is_visible = false;
                else
                        is_visible = true;
@@ -1575,7 +1580,7 @@ GLOBAL bool
 IRC_Send_ISUPPORT(CLIENT * Client)
 {
        if (!IRC_WriteStrClient(Client, RPL_ISUPPORT1_MSG, Client_ID(Client),
-                               Conf_MaxJoins))
+                               CHANTYPES, CHANTYPES, Conf_MaxJoins))
                return DISCONNECTED;
        return IRC_WriteStrClient(Client, RPL_ISUPPORT2_MSG, Client_ID(Client),
                                  CHANNEL_NAME_LEN - 1, Conf_MaxNickLength - 1,