]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-channel.c
New configuration option "PAMIsOptional"
[ngircd-alex.git] / src / ngircd / irc-channel.c
index 81a9eb2e89f5f017f7dc9a9007441655df66059d..cc70eb47d5d25e77bdf170e8117828ec8e92a6f1 100644 (file)
@@ -7,13 +7,15 @@
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  * Please read the file COPYING, README and AUTHORS for more information.
- *
- * IRC channel commands
  */
 
-
 #include "portab.h"
 
+/**
+ * @file
+ * IRC channel commands
+ */
+
 #include "imp.h"
 #include <assert.h>
 #include <stdlib.h>
 #include "irc-channel.h"
 
 
-/*
+/**
+ * Part from all channels.
+ *
  * RFC 2812, (3.2.1 Join message Command):
- *  Note that this message
- *  accepts a special argument ("0"), which is a special request to leave all
- *  channels the user is currently a member of. The server will process this
- *  message as if the user had sent a PART command (See Section 3.2.2) for
- *  each channel he is a member of.
+ *  Note that this message accepts a special argument ("0"), which is a
+ *  special request to leave all channels the user is currently a member of.
+ *  The server will process this message as if the user had sent a PART
+ *  command (See Section 3.2.2) for each channel he is a member of.
+ *
+ * @param client       Client that initiated the part request
+ * @param target       Client that should part all joined channels
+ * @returns            CONNECTED or DISCONNECTED
  */
 static bool
 part_from_all_channels(CLIENT* client, CLIENT *target)
@@ -57,17 +64,18 @@ part_from_all_channels(CLIENT* client, CLIENT *target)
                Channel_Part(target, client, Channel_Name(chan), Client_ID(target));
        }
        return CONNECTED;
-}
+} /* part_from_all_channels */
 
 
 /**
  * Check weather a local client is allowed to join an already existing
  * channel or not.
- * @param Client Client that sent the JOIN command
- * @param chan Channel to check
- * @param channame Name of the channel
- * @param key Provided channel key (or NULL if none has been provided)
- * @return true if client is allowed to join channel, false otherwise
+ *
+ * @param Client       Client that sent the JOIN command
+ * @param chan         Channel to check
+ * @param channame     Name of the channel
+ * @param key          Provided channel key (or NULL)
+ * @returns            true if client is allowed to join, false otherwise
  */
 static bool
 join_allowed(CLIENT *Client, CHANNEL *chan, const char *channame,
@@ -122,10 +130,31 @@ join_allowed(CLIENT *Client, CHANNEL *chan, const char *channame,
                return false;
        }
 
+       if (strchr(channel_modes, 'O') && !Client_OperByMe(Client)) {
+               /* Only IRC operators are allowed! */
+               IRC_WriteStrClient(Client, ERR_OPONLYCHANNEL_MSG,
+                                  Client_ID(Client), channame);
+               return false;
+       }
+
+       if (strchr(channel_modes, 'R') && !strchr(Client_Modes(Client), 'R')) {
+               /* Only registered users are allowed! */
+               IRC_WriteStrClient(Client, ERR_REGONLYCHANNEL_MSG,
+                                  Client_ID(Client), channame);
+               return false;
+       }
+
        return true;
-}
+} /* join_allowed */
 
 
+/**
+ * Set user channel modes.
+ *
+ * @param chan         Channel
+ * @param target       User to set modes for
+ * @param flags                Channel modes to add
+ */
 static void
 join_set_channelmodes(CHANNEL *chan, CLIENT *target, const char *flags)
 {
@@ -139,9 +168,22 @@ join_set_channelmodes(CHANNEL *chan, CLIENT *target, const char *flags)
        /* If channel persistent and client is ircop: make client chanop */
        if (strchr(Channel_Modes(chan), 'P') && strchr(Client_Modes(target), 'o'))
                Channel_UserModeAdd(chan, target, 'o');
-}
+} /* join_set_channelmodes */
 
 
+/**
+ * Forward JOIN command to a specific server
+ *
+ * This function diffentiates between servers using RFC 2813 mode that
+ * support the JOIN command with appended ASCII 7 character and channel
+ * modes, and servers using RFC 1459 protocol which require separate JOIN
+ * and MODE commands.
+ *
+ * @param To           Forward JOIN (and MODE) command to this peer server
+ * @param Prefix       Client used to prefix the genrated commands
+ * @param Data         Parameters of JOIN command to forward, probably
+ *                     containing channel modes separated by ASCII 7.
+ */
 static void
 cb_join_forward(CLIENT *To, CLIENT *Prefix, void *Data)
 {
@@ -166,12 +208,25 @@ cb_join_forward(CLIENT *To, CLIENT *Prefix, void *Data)
 } /* cb_join_forward */
 
 
+/**
+ * Forward JOIN command to all servers
+ *
+ * This function calls cb_join_forward(), which differentiates between
+ * protocol implementations (e.g. RFC 2812, RFC 1459).
+ *
+ * @param Client       Client used to prefix the genrated commands
+ * @param target       Forward JOIN (and MODE) command to this peer server
+ * @param chan         Channel structure
+ * @param channame     Channel name
+ */
 static void
 join_forward(CLIENT *Client, CLIENT *target, CHANNEL *chan,
                                        const char *channame)
 {
        char modes[CHANNEL_MODE_LEN], str[COMMAND_LEN];
 
+       /* RFC 2813, 4.2.1: channel modes are separated from the channel
+        * name with ASCII 7, if any, and not spaces: */
        strlcpy(&modes[1], Channel_UserModes(chan, target), sizeof(modes) - 1);
        if (modes[1])
                modes[0] = 0x7;
@@ -189,7 +244,7 @@ join_forward(CLIENT *Client, CLIENT *target, CHANNEL *chan,
        IRC_WriteStrChannelPrefix(Client, chan, target, false,
                                  "JOIN :%s",  channame);
 
-       /* syncronize channel modes */
+       /* synchronize channel modes */
        if (modes[1]) {
                IRC_WriteStrChannelPrefix(Client, chan, target, false,
                                          "MODE %s +%s %s", channame,
@@ -198,6 +253,14 @@ join_forward(CLIENT *Client, CLIENT *target, CHANNEL *chan,
 } /* join_forward */
 
 
+/**
+ * Aknowledge user JOIN request and send "channel info" numerics.
+ *
+ * @param Client       Client used to prefix the genrated commands
+ * @param target       Forward commands/numerics to this user
+ * @param chan         Channel structure
+ * @param channame     Channel name
+ */
 static bool
 join_send_topic(CLIENT *Client, CLIENT *target, CHANNEL *chan,
                                        const char *channame)
@@ -228,10 +291,20 @@ join_send_topic(CLIENT *Client, CLIENT *target, CHANNEL *chan,
        /* send list of channel members to client */
        if (!IRC_Send_NAMES(Client, chan))
                return false;
-       return IRC_WriteStrClient(Client, RPL_ENDOFNAMES_MSG, Client_ID(Client), Channel_Name(chan));
-}
+       return IRC_WriteStrClient(Client, RPL_ENDOFNAMES_MSG, Client_ID(Client),
+                                 Channel_Name(chan));
+} /* join_send_topic */
 
 
+/**
+ * Handler for the IRC "JOIN" command.
+ *
+ * See RFC 2812, 3.2.1 "Join message"; RFC 2813, 4.2.1 "Join message".
+ *
+ * @param Client       The client from which this command has been received
+ * @param Req          Request structure with prefix and all parameters
+ * @returns            CONNECTED or DISCONNECTED
+ */
 GLOBAL bool
 IRC_JOIN( CLIENT *Client, REQUEST *Req )
 {
@@ -356,6 +429,12 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
 
 /**
  * Handler for the IRC "PART" command.
+ *
+ * See RFC 2812, 3.2.2: "Part message".
+ *
+ * @param Client       The client from which this command has been received
+ * @param Req          Request structure with prefix and all parameters
+ * @returns            CONNECTED or DISCONNECTED
  */
 GLOBAL bool
 IRC_PART(CLIENT * Client, REQUEST * Req)
@@ -401,6 +480,15 @@ IRC_PART(CLIENT * Client, REQUEST * Req)
 } /* IRC_PART */
 
 
+/**
+ * Handler for the IRC "TOPIC" command.
+ *
+ * See RFC 2812, 3.2.4 "Topic message".
+ *
+ * @param Client       The client from which this command has been received
+ * @param Req          Request structure with prefix and all parameters
+ * @returns            CONNECTED or DISCONNECTED
+ */
 GLOBAL bool
 IRC_TOPIC( CLIENT *Client, REQUEST *Req )
 {
@@ -445,6 +533,8 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req )
                                               Client_ID(Client),
                                               Channel_Name(chan), topic);
 #ifndef STRICT_RFC
+                       if (!r)
+                               return r;
                        r = IRC_WriteStrClient(from, RPL_TOPICSETBY_MSG,
                                               Client_ID(Client),
                                               Channel_Name(chan),
@@ -493,8 +583,15 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req )
 
 /**
  * Handler for the IRC "LIST" command.
+ *
+ * See RFC 2812, 3.2.6 "List message".
+ *
  * This implementation handles the local case as well as the forwarding of the
  * LIST command to other servers in the IRC network.
+ *
+ * @param Client       The client from which this command has been received
+ * @param Req          Request structure with prefix and all parameters
+ * @returns            CONNECTED or DISCONNECTED
  */
 GLOBAL bool
 IRC_LIST( CLIENT *Client, REQUEST *Req )
@@ -578,6 +675,16 @@ IRC_LIST( CLIENT *Client, REQUEST *Req )
 } /* IRC_LIST */
 
 
+/**
+ * Handler for the IRC+ command "CHANINFO".
+ *
+ * See doc/Protocol.txt, section II.3:
+ * "Exchange channel-modes, topics, and persistent channels".
+ *
+ * @param Client       The client from which this command has been received
+ * @param Req          Request structure with prefix and all parameters
+ * @returns            CONNECTED or DISCONNECTED
+ */
 GLOBAL bool
 IRC_CHANINFO( CLIENT *Client, REQUEST *Req )
 {
@@ -590,7 +697,9 @@ IRC_CHANINFO( CLIENT *Client, REQUEST *Req )
        assert( Req != NULL );
 
        /* Bad number of parameters? */
-       if(( Req->argc < 2 ) || ( Req->argc == 4 ) || ( Req->argc > 5 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+       if (Req->argc < 2 || Req->argc == 4 || Req->argc > 5)
+               return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+                                         Client_ID(Client), Req->command);
 
        /* Compatibility kludge */
        if( Req->argc == 5 ) arg_topic = 4;