X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Firc-info.c;h=3ce821a275e3d20205c659a141fcaa827c14cb95;hp=a22ea7c64490f7c79a69371c1654f75085dfd705;hb=b8d7dcec7739aab840fc1ccae8e4dfaa8db330a1;hpb=490f28ffd1b42ee2076ce89c62d0e672ee7e541e diff --git a/src/ngircd/irc-info.c b/src/ngircd/irc-info.c index a22ea7c6..3ce821a2 100644 --- a/src/ngircd/irc-info.c +++ b/src/ngircd/irc-info.c @@ -14,7 +14,7 @@ #include "portab.h" -static char UNUSED id[] = "$Id: irc-info.c,v 1.5 2002/12/12 12:24:18 alex Exp $"; +static char UNUSED id[] = "$Id: irc-info.c,v 1.13 2002/12/30 17:15:42 alex Exp $"; #include "imp.h" #include @@ -23,7 +23,8 @@ static char UNUSED id[] = "$Id: irc-info.c,v 1.5 2002/12/12 12:24:18 alex Exp $" #include #include "ngircd.h" -#include "conn.h" +#include "conn-func.h" +#include "conn-zip.h" #include "client.h" #include "channel.h" #include "resolve.h" @@ -57,12 +58,12 @@ IRC_ADMIN(CLIENT *Client, REQUEST *Req ) /* Prefix ermitteln */ if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix ); else prefix = Client; - if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix ); + if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix ); /* An anderen Server weiterleiten? */ if( target != Client_ThisServer( )) { - if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] ); + if( ! target ) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] ); /* forwarden */ IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] ); @@ -104,8 +105,8 @@ IRC_ISON( CLIENT *Client, REQUEST *Req ) if( c && ( Client_Type( c ) == CLIENT_USER )) { /* Dieser Nick ist "online" */ - strcat( rpl, ptr ); - strcat( rpl, " " ); + strlcat( rpl, ptr, sizeof( rpl )); + strlcat( rpl, " ", sizeof( rpl )); } ptr = strtok( NULL, " " ); } @@ -141,7 +142,7 @@ IRC_LINKS( CLIENT *Client, REQUEST *Req ) if( Req->argc == 2 ) { target = Client_Search( Req->argv[0] ); - if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] ); + if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] ); else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] ); } @@ -184,7 +185,7 @@ IRC_LUSERS( CLIENT *Client, REQUEST *Req ) if( Req->argc == 2 ) { target = Client_Search( Req->argv[1] ); - if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] ); + if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] ); else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] ); } @@ -213,13 +214,13 @@ IRC_MOTD( CLIENT *Client, REQUEST *Req ) /* From aus Prefix ermitteln */ if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix ); else from = Client; - if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix ); + if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix ); if( Req->argc == 1 ) { /* an anderen Server forwarden */ target = Client_Search( Req->argv[0] ); - if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] ); + if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] ); if( target != Client_ThisServer( )) { @@ -248,13 +249,13 @@ IRC_NAMES( CLIENT *Client, REQUEST *Req ) /* From aus Prefix ermitteln */ if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix ); else from = Client; - if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix ); + if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix ); if( Req->argc == 2 ) { /* an anderen Server forwarden */ target = Client_Search( Req->argv[1] ); - if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] ); + if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] ); if( target != Client_ThisServer( )) { @@ -296,20 +297,20 @@ IRC_NAMES( CLIENT *Client, REQUEST *Req ) /* Nun noch alle Clients ausgeben, die in keinem Channel sind */ c = Client_First( ); - sprintf( rpl, RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" ); + snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" ); while( c ) { if(( Client_Type( c ) == CLIENT_USER ) && ( Channel_FirstChannelOf( c ) == NULL ) && ( ! strchr( Client_Modes( c ), 'i' ))) { /* Okay, das ist ein User: anhaengen */ - if( rpl[strlen( rpl ) - 1] != ':' ) strcat( rpl, " " ); - strcat( rpl, Client_ID( c )); + if( rpl[strlen( rpl ) - 1] != ':' ) strlcat( rpl, " ", sizeof( rpl )); + strlcat( rpl, Client_ID( c ), sizeof( rpl )); if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 )) { /* Zeile wird zu lang: senden! */ if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED; - sprintf( rpl, RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" ); + snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" ); } } @@ -332,6 +333,7 @@ IRC_STATS( CLIENT *Client, REQUEST *Req ) CLIENT *from, *target, *cl; CONN_ID con; CHAR query; + COMMAND *cmd; assert( Client != NULL ); assert( Req != NULL ); @@ -342,18 +344,18 @@ IRC_STATS( CLIENT *Client, REQUEST *Req ) /* From aus Prefix ermitteln */ if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix ); else from = Client; - if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix ); + if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix ); if( Req->argc == 2 ) { /* an anderen Server forwarden */ target = Client_Search( Req->argv[1] ); - if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] ); + if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] ); if( target != Client_ThisServer( )) { /* Ok, anderer Server ist das Ziel: forwarden */ - return IRC_WriteStrClientPrefix( target, from, "STATS %s", Req->argv[0], Req->argv[1] ); + return IRC_WriteStrClientPrefix( target, from, "STATS %s %s", Req->argv[0], Req->argv[1] ); } } @@ -368,12 +370,13 @@ IRC_STATS( CLIENT *Client, REQUEST *Req ) while( con != NONE ) { cl = Client_GetFromConn( con ); - if( cl ) + if( cl && (( Client_Type( cl ) == CLIENT_SERVER ) || ( cl == Client ))) { + /* Server link or our own connection */ #ifdef USE_ZLIB if( Conn_Options( con ) & CONN_ZIP ) { - if( ! IRC_WriteStrClient( from, RPL_STATSLINKINFOZIP_MSG, Client_ID( from ), Client_Mask( cl ), Conn_SendQ( con ), Conn_SendMsg( con ), Conn_SendBytesZip( con ), Conn_SendBytes( con ), Conn_RecvMsg( con ), Conn_RecvBytesZip( con ), Conn_RecvBytes( con ), (LONG)( time( NULL ) - Conn_StartTime( con )))) return DISCONNECTED; + if( ! IRC_WriteStrClient( from, RPL_STATSLINKINFOZIP_MSG, Client_ID( from ), Client_Mask( cl ), Conn_SendQ( con ), Conn_SendMsg( con ), Zip_SendBytes( con ), Conn_SendBytes( con ), Conn_RecvMsg( con ), Zip_RecvBytes( con ), Conn_RecvBytes( con ), (LONG)( time( NULL ) - Conn_StartTime( con )))) return DISCONNECTED; } else #endif @@ -386,6 +389,15 @@ IRC_STATS( CLIENT *Client, REQUEST *Req ) break; case 'm': /* IRC-Befehle */ case 'M': + cmd = Parse_GetCommandStruct( ); + while( cmd->name ) + { + if( cmd->lcount > 0 || cmd->rcount > 0 ) + { + if( ! IRC_WriteStrClient( from, RPL_STATSCOMMANDS_MSG, Client_ID( from ), cmd->name, cmd->lcount, cmd->bytes, cmd->rcount )) return DISCONNECTED; + } + cmd++; + } break; } @@ -409,7 +421,7 @@ IRC_TIME( CLIENT *Client, REQUEST *Req ) /* From aus Prefix ermitteln */ if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix ); else from = Client; - if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix ); + if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix ); if( Req->argc == 1 ) { @@ -453,15 +465,15 @@ IRC_USERHOST( CLIENT *Client, REQUEST *Req ) if( c && ( Client_Type( c ) == CLIENT_USER )) { /* Dieser Nick ist "online" */ - strcat( rpl, Client_ID( c )); - if( Client_HasMode( c, 'o' )) strcat( rpl, "*" ); - strcat( rpl, "=" ); - if( Client_HasMode( c, 'a' )) strcat( rpl, "-" ); - else strcat( rpl, "+" ); - strcat( rpl, Client_User( c )); - strcat( rpl, "@" ); - strcat( rpl, Client_Hostname( c )); - strcat( rpl, " " ); + strlcat( rpl, Client_ID( c ), sizeof( rpl )); + if( Client_HasMode( c, 'o' )) strlcat( rpl, "*", sizeof( rpl )); + strlcat( rpl, "=", sizeof( rpl )); + if( Client_HasMode( c, 'a' )) strlcat( rpl, "-", sizeof( rpl )); + else strlcat( rpl, "+", sizeof( rpl )); + strlcat( rpl, Client_User( c ), sizeof( rpl )); + strlcat( rpl, "@", sizeof( rpl )); + strlcat( rpl, Client_Hostname( c ), sizeof( rpl )); + strlcat( rpl, " ", sizeof( rpl )); } } if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0'; @@ -488,12 +500,12 @@ IRC_VERSION( CLIENT *Client, REQUEST *Req ) /* Prefix ermitteln */ if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix ); else prefix = Client; - if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix ); + if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix ); /* An anderen Server weiterleiten? */ if( target != Client_ThisServer( )) { - if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] ); + if( ! target ) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] ); /* forwarden */ IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] ); @@ -561,7 +573,7 @@ IRC_WHO( CLIENT *Client, REQUEST *Req ) { /* Flags zusammenbasteln */ strcpy( flags, "H" ); - if( strchr( Client_Modes( c ), 'o' )) strcat( flags, "*" ); + if( strchr( Client_Modes( c ), 'o' )) strlcat( flags, "*", sizeof( flags )); /* ausgeben */ cl2chan = Channel_FirstChannelOf( c ); @@ -625,7 +637,7 @@ IRC_WHOIS( CLIENT *Client, REQUEST *Req ) if( ! IRC_WriteStrClient( from, RPL_WHOISSERVER_MSG, Client_ID( from ), Client_ID( c ), Client_ID( Client_Introducer( c )), Client_Info( Client_Introducer( c )))) return DISCONNECTED; /* Channels */ - sprintf( str, RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c )); + snprintf( str, sizeof( str ), RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c )); cl2chan = Channel_FirstChannelOf( c ); while( cl2chan ) { @@ -633,16 +645,16 @@ IRC_WHOIS( CLIENT *Client, REQUEST *Req ) assert( chan != NULL ); /* Channel-Name anhaengen */ - if( str[strlen( str ) - 1] != ':' ) strcat( str, " " ); - if( strchr( Channel_UserModes( chan, c ), 'o' )) strcat( str, "@" ); - else if( strchr( Channel_UserModes( chan, c ), 'v' )) strcat( str, "+" ); - strcat( str, Channel_Name( chan )); + if( str[strlen( str ) - 1] != ':' ) strlcat( str, " ", sizeof( str )); + if( strchr( Channel_UserModes( chan, c ), 'o' )) strlcat( str, "@", sizeof( str )); + else if( strchr( Channel_UserModes( chan, c ), 'v' )) strlcat( str, "+", sizeof( str )); + strlcat( str, Channel_Name( chan ), sizeof( str )); if( strlen( str ) > ( LINE_LEN - CHANNEL_NAME_LEN - 4 )) { /* Zeile wird zu lang: senden! */ if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED; - sprintf( str, RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c )); + snprintf( str, sizeof( str ), RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c )); } /* naechstes Mitglied suchen */ @@ -699,29 +711,36 @@ IRC_Send_LUSERS( CLIENT *Client ) assert( Client != NULL ); - /* Users, Services und Serevr im Netz */ + /* Users, services and serevers in the network */ if( ! IRC_WriteStrClient( Client, RPL_LUSERCLIENT_MSG, Client_ID( Client ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED; - /* IRC-Operatoren im Netz */ + /* Number of IRC operators */ cnt = Client_OperCount( ); if( cnt > 0 ) { if( ! IRC_WriteStrClient( Client, RPL_LUSEROP_MSG, Client_ID( Client ), cnt )) return DISCONNECTED; } - /* Unbekannt Verbindungen */ + /* Unknown connections */ cnt = Client_UnknownCount( ); if( cnt > 0 ) { if( ! IRC_WriteStrClient( Client, RPL_LUSERUNKNOWN_MSG, Client_ID( Client ), cnt )) return DISCONNECTED; } - /* Channels im Netz */ + /* Number of created channels */ if( ! IRC_WriteStrClient( Client, RPL_LUSERCHANNELS_MSG, Client_ID( Client ), Channel_Count( ))) return DISCONNECTED; - /* Channels im Netz */ + /* Number of local users, services and servers */ if( ! IRC_WriteStrClient( Client, RPL_LUSERME_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED; +#ifndef STRICT_RFC + /* Maximum number of local users */ + if( ! IRC_WriteStrClient( Client, RPL_LOCALUSERS_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyMaxUserCount( ))) return DISCONNECTED; + /* Maximum number of users in the network */ + if( ! IRC_WriteStrClient( Client, RPL_NETUSERS_MSG, Client_ID( Client ), Client_UserCount( ), Client_MaxUserCount( ))) return DISCONNECTED; +#endif + return CONNECTED; } /* IRC_Send_LUSERS */ @@ -776,7 +795,7 @@ IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan ) else is_member = FALSE; /* Alle Mitglieder suchen */ - sprintf( str, RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan )); + snprintf( str, sizeof( str ), RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan )); cl2chan = Channel_FirstMember( Chan ); while( cl2chan ) { @@ -788,16 +807,16 @@ IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan ) if( is_member || is_visible ) { /* Nick anhaengen */ - if( str[strlen( str ) - 1] != ':' ) strcat( str, " " ); - if( strchr( Channel_UserModes( Chan, cl ), 'o' )) strcat( str, "@" ); - else if( strchr( Channel_UserModes( Chan, cl ), 'v' )) strcat( str, "+" ); - strcat( str, Client_ID( cl )); + if( str[strlen( str ) - 1] != ':' ) strlcat( str, " ", sizeof( str )); + if( strchr( Channel_UserModes( Chan, cl ), 'o' )) strlcat( str, "@", sizeof( str )); + else if( strchr( Channel_UserModes( Chan, cl ), 'v' )) strlcat( str, "+", sizeof( str )); + strlcat( str, Client_ID( cl ), sizeof( str )); if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 )) { /* Zeile wird zu lang: senden! */ if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED; - sprintf( str, RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan )); + snprintf( str, sizeof( str ), RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan )); } } @@ -841,9 +860,9 @@ IRC_Send_WHO( CLIENT *Client, CHANNEL *Chan, BOOLEAN OnlyOps ) { /* Flags zusammenbasteln */ strcpy( flags, "H" ); - if( strchr( Client_Modes( c ), 'o' )) strcat( flags, "*" ); - if( strchr( Channel_UserModes( Chan, c ), 'o' )) strcat( flags, "@" ); - else if( strchr( Channel_UserModes( Chan, c ), 'v' )) strcat( flags, "+" ); + if( strchr( Client_Modes( c ), 'o' )) strlcat( flags, "*", sizeof( flags )); + if( strchr( Channel_UserModes( Chan, c ), 'o' )) strlcat( flags, "@", sizeof( flags )); + else if( strchr( Channel_UserModes( Chan, c ), 'v' )) strlcat( flags, "+", sizeof( flags )); /* ausgeben */ if(( ! OnlyOps ) || ( strchr( Client_Modes( c ), 'o' )))