]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc.c
Don't allow empty channel names ("#") in strict RFC mode.
[ngircd-alex.git] / src / ngircd / irc.c
index 33ee22684be0dd9165a5626f2cd9d0e0f32909e2..0418e7b4cb31cb82f4be6006c021c1af37c5f41a 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc.c,v 1.129 2006/04/23 10:37:27 fw Exp $";
+static char UNUSED id[] = "$Id: irc.c,v 1.132 2008/01/15 22:28:14 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -22,10 +22,9 @@ static char UNUSED id[] = "$Id: irc.c,v 1.129 2006/04/23 10:37:27 fw Exp $";
 #include <string.h>
 
 #include "ngircd.h"
-#include "conn.h"
 #include "resolve.h"
-#include "conf.h"
 #include "conn-func.h"
+#include "conf.h"
 #include "client.h"
 #include "channel.h"
 #include "defines.h"
@@ -38,7 +37,8 @@ static char UNUSED id[] = "$Id: irc.c,v 1.129 2006/04/23 10:37:27 fw Exp $";
 #include "irc.h"
 
 
-static char *Option_String PARAMS(( CONN_ID Idx ));
+static char *Option_String PARAMS((CONN_ID Idx));
+static bool Send_Message PARAMS((CLIENT *Client, REQUEST *Req, int ForceType));
 
 
 GLOBAL bool
@@ -171,6 +171,7 @@ GLOBAL bool
 IRC_NOTICE( CLIENT *Client, REQUEST *Req )
 {
        CLIENT *to, *from;
+       CHANNEL *chan;
 
        assert( Client != NULL );
        assert( Req != NULL );
@@ -190,51 +191,35 @@ IRC_NOTICE( CLIENT *Client, REQUEST *Req )
                /* Okay, Ziel ist ein User */
                return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
        }
-       else return CONNECTED;
+       else
+       {
+               chan = Channel_Search(Req->argv[0]);
+               if (chan)
+                       return Channel_Notice(chan, from, Client, Req->argv[1]);
+       }
+
+       return CONNECTED;
 } /* IRC_NOTICE */
 
 
+/**
+ * Handler for the IRC command PRIVMSG.
+ */
 GLOBAL bool
-IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
+IRC_PRIVMSG(CLIENT *Client, REQUEST *Req)
 {
-       CLIENT *cl, *from;
-       CHANNEL *chan;
-       
-       assert( Client != NULL );
-       assert( Req != NULL );
-
-       /* Falsche Anzahl Parameter? */
-       if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
-       if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
-       if( 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 );
-
-       cl = Client_Search( Req->argv[0] );
-       if( cl )
-       {
-               /* Okay, Ziel ist ein Client. Aber ist es auch ein User? */
-               if( Client_Type( cl ) != CLIENT_USER ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
-
-               /* Okay, Ziel ist ein User */
-               if(( Client_Type( Client ) != CLIENT_SERVER ) && ( strchr( Client_Modes( cl ), 'a' )))
-               {
-                       /* Ziel-User ist AWAY: Meldung verschicken */
-                       if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( cl ), Client_Away( cl ))) return DISCONNECTED;
-               }
-
-               /* Text senden */
-               if( Client_Conn( from ) > NONE ) Conn_UpdateIdle( Client_Conn( from ));
-               return IRC_WriteStrClientPrefix( cl, from, "PRIVMSG %s :%s", Client_ID( cl ), Req->argv[1] );
-       }
+       return Send_Message(Client, Req, CLIENT_USER);
+} /* IRC_PRIVMSG */
 
-       chan = Channel_Search( Req->argv[0] );
-       if( chan ) return Channel_Write( chan, from, Client, Req->argv[1] );
 
-       return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
-} /* IRC_PRIVMSG */
+/**
+ * Handler for the IRC command SQUERY.
+ */
+GLOBAL bool
+IRC_SQUERY(CLIENT *Client, REQUEST *Req)
+{
+       return Send_Message(Client, Req, CLIENT_SERVICE);
+} /* IRC_SQUERY */
 
 
 GLOBAL bool
@@ -329,17 +314,78 @@ static char *
 Option_String( CONN_ID Idx )
 {
        static char option_txt[8];
-       int options;
+       UINT16 options;
 
-       options = Conn_Options( Idx );
+       options = Conn_Options(Idx);
 
-       strcpy( option_txt, "F" );      /* No idea what this means but the original ircd sends it ... */
+       strcpy(option_txt, "F");        /* No idea what this means, but the
+                                        * original ircd sends it ... */
 #ifdef ZLIB
-       if( options & CONN_ZIP ) strcat( option_txt, "z" );
+       if(options & CONN_ZIP)          /* zlib compression supported. */
+               strcat(option_txt, "z");
 #endif
 
        return option_txt;
 } /* Option_String */
 
 
+static bool
+Send_Message(CLIENT * Client, REQUEST * Req, int ForceType)
+{
+       CLIENT *cl, *from;
+       CHANNEL *chan;
+
+       assert(Client != NULL);
+       assert(Req != NULL);
+
+       if (Req->argc == 0)
+               return IRC_WriteStrClient(Client, ERR_NORECIPIENT_MSG,
+                                         Client_ID(Client), Req->command);
+       if (Req->argc == 1)
+               return IRC_WriteStrClient(Client, ERR_NOTEXTTOSEND_MSG,
+                                         Client_ID(Client));
+       if (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);
+
+       cl = Client_Search(Req->argv[0]);
+       if (cl) {
+               /* Target is a user, enforce type */
+               if (Client_Type(cl) != ForceType)
+                       return IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG,
+                                                 Client_ID(from),
+                                                 Req->argv[0]);
+
+               if ((Client_Type(Client) != CLIENT_SERVER)
+                   && (strchr(Client_Modes(cl), 'a'))) {
+                       /* Target is away */
+                       if (!IRC_WriteStrClient
+                           (from, RPL_AWAY_MSG, Client_ID(from), Client_ID(cl),
+                            Client_Away(cl)))
+                               return DISCONNECTED;
+               }
+
+               if (Client_Conn(from) > NONE)
+                       Conn_UpdateIdle(Client_Conn(from));
+               return IRC_WriteStrClientPrefix(cl, from, "PRIVMSG %s :%s",
+                                               Client_ID(cl), Req->argv[1]);
+       }
+
+       chan = Channel_Search(Req->argv[0]);
+       if (chan)
+               return Channel_Write(chan, from, Client, Req->argv[1]);
+
+       return IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG,
+                                 Client_ID(from), Req->argv[0]);
+} /* Send_Message */
+
+
 /* -eof- */