X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Firc-write.c;h=16aac9a081859aa27904e116252d009ba02d3176;hp=ea0f5f8a288158531e55952212197b360690102e;hb=32f63abb59b5c9f47b4d517e0bbf9cc73fd044dc;hpb=544b9884f4ccab6488b6f75b5fafd68a85aa8cd7 diff --git a/src/ngircd/irc-write.c b/src/ngircd/irc-write.c index ea0f5f8a..16aac9a0 100644 --- a/src/ngircd/irc-write.c +++ b/src/ngircd/irc-write.c @@ -1,19 +1,21 @@ /* * ngIRCd -- The Next Generation IRC Daemon - * Copyright (c)2001-2005 by Alexander Barton (alex@barton.de) + * Copyright (c)2001-2008 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. - * - * Sending IRC commands over the network */ - #include "portab.h" +/** + * @file + * Sending IRC commands over the network + */ + #include "imp.h" #include #ifdef PROTOTYPES @@ -26,7 +28,6 @@ #include "defines.h" #include "conn-func.h" -#include "client.h" #include "channel.h" #include "exp.h" @@ -37,19 +38,20 @@ #define SEND_TO_SERVER 2 -static char *Get_Prefix PARAMS((CLIENT *Target, CLIENT *Client)); +static const char *Get_Prefix PARAMS((CLIENT *Target, CLIENT *Client)); static void cb_writeStrServersPrefixFlag PARAMS((CLIENT *Client, CLIENT *Prefix, void *Buffer)); +static bool Send_Marked_Connections PARAMS((CLIENT *Prefix, const char *Buffer)); #ifdef PROTOTYPES GLOBAL bool -IRC_WriteStrClient( CLIENT *Client, char *Format, ... ) +IRC_WriteStrClient( CLIENT *Client, const char *Format, ... ) #else GLOBAL bool IRC_WriteStrClient( Client, Format, va_alist ) CLIENT *Client; -char *Format; +const char *Format; va_dcl #endif { @@ -77,13 +79,13 @@ va_dcl #ifdef PROTOTYPES GLOBAL bool -IRC_WriteStrClientPrefix( CLIENT *Client, CLIENT *Prefix, char *Format, ... ) +IRC_WriteStrClientPrefix(CLIENT *Client, CLIENT *Prefix, const char *Format, ...) #else GLOBAL bool -IRC_WriteStrClientPrefix( Client, Prefix, Format, va_alist ) +IRC_WriteStrClientPrefix(Client, Prefix, Format, va_alist) CLIENT *Client; CLIENT *Prefix; -char *Format; +const char *Format; va_dcl #endif { @@ -104,20 +106,22 @@ va_dcl vsnprintf( buffer, 1000, Format, ap ); va_end( ap ); - return Conn_WriteStr( Client_Conn( Client_NextHop( Client )), ":%s %s", Get_Prefix( Client_NextHop( Client ), Prefix ), buffer ); + return Conn_WriteStr(Client_Conn(Client_NextHop(Client)), ":%s %s", + Get_Prefix(Client_NextHop(Client), Prefix), buffer); } /* IRC_WriteStrClientPrefix */ #ifdef PROTOTYPES GLOBAL bool -IRC_WriteStrChannel( CLIENT *Client, CHANNEL *Chan, bool Remote, char *Format, ... ) +IRC_WriteStrChannel(CLIENT *Client, CHANNEL *Chan, bool Remote, + const char *Format, ...) #else GLOBAL bool -IRC_WriteStrChannel( Client, Chan, Remote, Format, va_alist ) +IRC_WriteStrChannel(Client, Chan, Remote, Format, va_alist) CLIENT *Client; CHANNEL *Chan; bool Remote; -char *Format; +const char *Format; va_dcl #endif { @@ -146,19 +150,19 @@ va_dcl */ #ifdef PROTOTYPES GLOBAL bool -IRC_WriteStrChannelPrefix( CLIENT *Client, CHANNEL *Chan, CLIENT *Prefix, bool Remote, char *Format, ... ) +IRC_WriteStrChannelPrefix(CLIENT *Client, CHANNEL *Chan, CLIENT *Prefix, + bool Remote, const char *Format, ...) #else GLOBAL bool -IRC_WriteStrChannelPrefix( Client, Chan, Prefix, Remote, Format, va_alist ) +IRC_WriteStrChannelPrefix(Client, Chan, Prefix, Remote, Format, va_alist) CLIENT *Client; CHANNEL *Chan; CLIENT *Prefix; bool Remote; -char *Format; +const char *Format; va_dcl #endif { - bool ok = CONNECTED; char buffer[1000]; CL2CHAN *cl2chan; CONN_ID conn; @@ -200,30 +204,18 @@ va_dcl } cl2chan = Channel_NextMember( Chan, cl2chan ); } - - conn = Conn_First( ); - while( conn != NONE ) - { - /* do we need to send data via this connection? */ - if( Conn_Flag( conn ) == SEND_TO_SERVER) ok = Conn_WriteStr( conn, ":%s %s", Client_ID( Prefix ), buffer ); - else if( Conn_Flag( conn ) == SEND_TO_USER ) ok = Conn_WriteStr( conn, ":%s %s", Client_Mask( Prefix ), buffer ); - if( ! ok ) break; - - conn = Conn_Next( conn ); - } - - return ok; + return Send_Marked_Connections(Prefix, buffer); } /* IRC_WriteStrChannelPrefix */ #ifdef PROTOTYPES GLOBAL void -IRC_WriteStrServers( CLIENT *ExceptOf, char *Format, ... ) +IRC_WriteStrServers(CLIENT *ExceptOf, const char *Format, ...) #else GLOBAL void -IRC_WriteStrServers( ExceptOf, Format, va_alist ) +IRC_WriteStrServers(ExceptOf, Format, va_alist) CLIENT *ExceptOf; -char *Format; +const char *Format; va_dcl #endif { @@ -246,13 +238,14 @@ va_dcl #ifdef PROTOTYPES GLOBAL void -IRC_WriteStrServersPrefix( CLIENT *ExceptOf, CLIENT *Prefix, char *Format, ... ) +IRC_WriteStrServersPrefix(CLIENT *ExceptOf, CLIENT *Prefix, + const char *Format, ...) #else GLOBAL void -IRC_WriteStrServersPrefix( ExceptOf, Prefix, Format, va_alist ) +IRC_WriteStrServersPrefix(ExceptOf, Prefix, Format, va_alist) CLIENT *ExceptOf; CLIENT *Prefix; -char *Format; +const char *Format; va_dcl #endif { @@ -276,14 +269,15 @@ va_dcl #ifdef PROTOTYPES GLOBAL void -IRC_WriteStrServersPrefixFlag( CLIENT *ExceptOf, CLIENT *Prefix, char Flag, char *Format, ... ) +IRC_WriteStrServersPrefixFlag(CLIENT *ExceptOf, CLIENT *Prefix, char Flag, + const char *Format, ...) #else GLOBAL void -IRC_WriteStrServersPrefixFlag( ExceptOf, Prefix, Flag, Format, va_alist ) +IRC_WriteStrServersPrefixFlag(ExceptOf, Prefix, Flag, Format, va_alist) CLIENT *ExceptOf; CLIENT *Prefix; char Flag; -char *Format; +const char *Format; va_dcl #endif { @@ -331,18 +325,18 @@ IRC_WriteStrServersPrefixFlag_CB(CLIENT *ExceptOf, CLIENT *Prefix, char Flag, */ #ifdef PROTOTYPES GLOBAL bool -IRC_WriteStrRelatedPrefix( CLIENT *Client, CLIENT *Prefix, bool Remote, char *Format, ... ) +IRC_WriteStrRelatedPrefix(CLIENT *Client, CLIENT *Prefix, bool Remote, + const char *Format, ...) #else GLOBAL bool -IRC_WriteStrRelatedPrefix( Client, Prefix, Remote, Format, va_alist ) +IRC_WriteStrRelatedPrefix(Client, Prefix, Remote, Format, va_alist) CLIENT *Client; CLIENT *Prefix; bool Remote; -char *Format; +const char *Format; va_dcl #endif { - bool ok = CONNECTED; CL2CHAN *chan_cl2chan, *cl2chan; char buffer[1000]; CHANNEL *chan; @@ -390,19 +384,55 @@ va_dcl chan_cl2chan = Channel_NextChannelOf( Client, chan_cl2chan ); } + return Send_Marked_Connections(Prefix, buffer); +} /* IRC_WriteStrRelatedPrefix */ - conn = Conn_First( ); - while( conn != NONE ) - { - /* send data via this connection? */ - if( Conn_Flag( conn ) == SEND_TO_SERVER ) ok = Conn_WriteStr( conn, ":%s %s", Client_ID( Prefix ), buffer ); - else if( Conn_Flag( conn ) == SEND_TO_USER ) ok = Conn_WriteStr( conn, ":%s %s", Client_Mask( Prefix ), buffer ); - if( ! ok ) break; - conn = Conn_Next( conn ); +/** + * Send WALLOPS message. + */ +#ifdef PROTOTYPES +GLOBAL void +IRC_SendWallops(CLIENT *Client, CLIENT *From, const char *Format, ...) +#else +GLOBAL void +IRC_SendWallops(Client, From, Format, va_alist ) +CLIENT *Client; +CLIENT *From; +const char *Format; +va_dcl +#endif +{ + va_list ap; + char msg[1000]; + CLIENT *to; + +#ifdef PROTOTYPES + va_start(ap, Format); +#else + va_start(ap); +#endif + vsnprintf(msg, 1000, Format, ap); + va_end(ap); + + for (to=Client_First(); to != NULL; to=Client_Next(to)) { + if (Client_Conn(to) == NONE) /* no local connection */ + continue; + + switch (Client_Type(to)) { + case CLIENT_USER: + if (Client_HasMode(to, 'w')) + IRC_WriteStrClientPrefix(to, From, + "WALLOPS :%s", msg); + break; + case CLIENT_SERVER: + if (to != Client) + IRC_WriteStrClientPrefix(to, From, + "WALLOPS :%s", msg); + break; + } } - return ok; -} /* IRC_WriteStrRelatedPrefix */ +} /* IRC_SendWallops */ GLOBAL void @@ -421,14 +451,16 @@ IRC_SetPenalty( CLIENT *Client, time_t Seconds ) } /* IRC_SetPenalty */ -static char * -Get_Prefix( CLIENT *Target, CLIENT *Client ) +static const char * +Get_Prefix(CLIENT *Target, CLIENT *Client) { - assert( Target != NULL ); - assert( Client != NULL ); + assert (Target != NULL); + assert (Client != NULL); - if( Client_Type( Target ) == CLIENT_SERVER ) return Client_ID( Client ); - else return Client_Mask( Client ); + if (Client_Type(Target) == CLIENT_SERVER) + return Client_ID(Client); + else + return Client_MaskCloaked(Client); } /* Get_Prefix */ @@ -439,4 +471,29 @@ cb_writeStrServersPrefixFlag(CLIENT *Client, CLIENT *Prefix, void *Buffer) } /* cb_writeStrServersPrefixFlag */ +static bool +Send_Marked_Connections(CLIENT *Prefix, const char *Buffer) +{ + CONN_ID conn; + bool ok = CONNECTED; + + assert(Prefix != NULL); + assert(Buffer != NULL); + + conn = Conn_First(); + while (conn != NONE) { + if (Conn_Flag(conn) == SEND_TO_SERVER) + ok = Conn_WriteStr(conn, ":%s %s", + Client_ID(Prefix), Buffer); + else if (Conn_Flag(conn) == SEND_TO_USER) + ok = Conn_WriteStr(conn, ":%s %s", + Client_MaskCloaked(Prefix), Buffer); + if (!ok) + break; + conn = Conn_Next( conn ); + } + return ok; +} + + /* -eof- */