/*
* ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2008 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
* 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 "defines.h"
#include "conn.h"
-#include "client.h"
#include "channel.h"
#include "conn-func.h"
#include "lists.h"
#include "parse.h"
#include "irc-info.h"
#include "irc-write.h"
-#include "resolve.h"
#include "conf.h"
#include "exp.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)
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,
}
channel_modes = Channel_Modes(chan);
- if ((strchr(channel_modes, 'i')) && !is_invited) {
+ if (strchr(channel_modes, 'i') && !is_invited) {
/* Channel is "invite-only" and client is not on invite list */
IRC_WriteStrClient(Client, ERR_INVITEONLYCHAN_MSG,
Client_ID(Client), channame);
return false;
}
- if ((strchr(channel_modes, 'l')) &&
+ if (strchr(channel_modes, 'l') &&
(Channel_MaxUsers(chan) <= Channel_MemberCount(chan))) {
/* There are more clints joined to this channel than allowed */
IRC_WriteStrClient(Client, ERR_CHANNELISFULL_MSG,
return false;
}
+ if (strchr(channel_modes, 'z') && !Conn_UsesSSL(Client_Conn(Client))) {
+ /* Only "secure" clients are allowed, but clients doesn't
+ * use SSL encryption */
+ IRC_WriteStrClient(Client, ERR_SECURECHANNEL_MSG,
+ Client_ID(Client), 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;
+ }
+
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)
{
/* 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)
{
} /* 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;
} /* 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)
/* 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 )
{
/**
* 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)
} /* 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 )
{
CHANNEL *chan;
CLIENT *from;
char *topic;
- bool r;
+ bool onchannel, topicok, use_servermode, r;
assert( Client != NULL );
assert( Req != NULL );
- if ((Req->argc < 1) || (Req->argc > 2))
- return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command);
+ if (Req->argc < 1 || Req->argc > 2)
+ return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+ Client_ID(Client), Req->command);
- if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
- else from = Client;
- if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
+ if (Client_Type(Client) == CLIENT_SERVER)
+ from = Client_Search(Req->prefix);
+ else
+ from = Client;
- /* Welcher Channel? */
- chan = Channel_Search( Req->argv[0] );
- if( ! chan ) return IRC_WriteStrClient( from, ERR_NOSUCHCHANNEL_MSG, Client_ID( from ), Req->argv[0] );
+ if (!from)
+ return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
+ Client_ID(Client), Req->prefix);
- /* Ist der User Mitglied in dem Channel? */
- if( ! Channel_IsMemberOf( chan, from )) return IRC_WriteStrClient( from, ERR_NOTONCHANNEL_MSG, Client_ID( from ), Req->argv[0] );
+ chan = Channel_Search(Req->argv[0]);
+ if (!chan)
+ return IRC_WriteStrClient(from, ERR_NOSUCHCHANNEL_MSG,
+ Client_ID(from), Req->argv[0]);
- if( Req->argc == 1 )
- {
+ Channel_CheckAdminRights(chan, Client, from,
+ &onchannel, &topicok, &use_servermode);
+
+ if (!onchannel && !topicok)
+ return IRC_WriteStrClient(from, ERR_NOTONCHANNEL_MSG,
+ Client_ID(from), Req->argv[0]);
+
+ if (Req->argc == 1) {
/* Request actual topic */
topic = Channel_Topic(chan);
if (*topic) {
r = IRC_WriteStrClient(from, RPL_TOPIC_MSG,
- Client_ID(Client), Channel_Name(chan), topic);
+ 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),
- Channel_TopicWho(chan),
- Channel_TopicTime(chan));
+ Client_ID(Client),
+ Channel_Name(chan),
+ Channel_TopicWho(chan),
+ Channel_TopicTime(chan));
#endif
return r;
}
else
- return IRC_WriteStrClient(from, RPL_NOTOPIC_MSG,
- Client_ID(from), Channel_Name(chan));
+ return IRC_WriteStrClient(from, RPL_NOTOPIC_MSG,
+ Client_ID(from),
+ Channel_Name(chan));
}
- if( strchr( Channel_Modes( chan ), 't' ))
- {
- /* Topic Lock. Ist der User ein Channel Operator? */
- if( ! strchr( Channel_UserModes( chan, from ), 'o' )) return IRC_WriteStrClient( from, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( from ), Channel_Name( chan ));
+ if (strchr(Channel_Modes(chan), 't')) {
+ /* Topic Lock. Is the user a channel or IRC operator? */
+ if (!topicok)
+ return IRC_WriteStrClient(from, ERR_CHANOPRIVSNEEDED_MSG,
+ Client_ID(from),
+ Channel_Name(chan));
}
/* Set new topic */
Client_TypeText(from), Client_Mask(from), Channel_Name(chan),
Req->argv[1][0] ? Req->argv[1] : "<none>");
+ if (use_servermode)
+ from = Client_ThisServer();
+
/* Update channel and forward new topic to other servers */
if (!Channel_IsLocal(chan))
IRC_WriteStrServersPrefix(Client, from, "TOPIC %s :%s",
/**
* 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 )
} /* 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 )
{
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;