commit 3d8eda9c860cbcbf195fe2242c67dd57fe966b3e from: Bryan Caldwell via: Florian Westphal date: Mon May 05 14:12:41 2008 UTC Allow KICK to handle comma-delimited lists (of channels, nicks). includes test cases. [fw@strlen.de: - move code around to avoid duplication - use const where possible - integrate test case] commit - 3283d275ba26c470d131ce0b6f66ee54a00bfd1c commit + 3d8eda9c860cbcbf195fe2242c67dd57fe966b3e blob - 921bbf6b5d7acac4d2cb1657b572483010201f97 blob + 490257eb20f2e456c8caa14fe7bd63a6f38db717 --- ChangeLog +++ ChangeLog @@ -12,6 +12,8 @@ ngIRCd-dev + - Fixed Bug 75: KICK now handles comma-delimited lists. + (Brandon Beresini, Bryan Caldwell) - Fixed Bug 83: ngIRCd chokes on 1-character messages. - Add support for modeless channels ("+channels"). (Bryan Caldwell, Ali Shemiran) blob - bbedcf4caf9968a4ecfbc7a8291660741a73d02a blob + 715323be3ddd0f947079bdb879b494ca674ab3a4 --- src/ngircd/irc-op.c +++ src/ngircd/irc-op.c @@ -14,8 +14,6 @@ #include "portab.h" -static char UNUSED id[] = "$Id: irc-op.c,v 1.17 2006/12/07 17:57:20 fw Exp $"; - #include "imp.h" #include #include @@ -35,30 +33,98 @@ static char UNUSED id[] = "$Id: irc-op.c,v 1.17 2006/1 #include "irc-op.h" +static bool +try_kick(CLIENT* from, const char *nick, const char *channel, const char *reason) +{ + CLIENT *target = Client_Search(nick); + + if (!target) + return IRC_WriteStrClient(from, ERR_NOSUCHNICK_MSG, Client_ID(from), nick); + + Channel_Kick(target, from, channel, reason); + return true; +} + + GLOBAL bool -IRC_KICK( CLIENT *Client, REQUEST *Req ) +IRC_KICK(CLIENT *Client, REQUEST *Req) { - CLIENT *target, *from; - + CLIENT *from; + char *itemList = Req->argv[0]; + const char* currentNick, *currentChannel, *reason; + unsigned int channelCount = 1; + unsigned int nickCount = 1; + assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ - if(( Req->argc < 2) || ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); + if ((Req->argc < 2) || (Req->argc > 3)) + 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 ); - - /* Ziel-User suchen */ - target = Client_Search( Req->argv[1] ); - if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[1] ); + while (*itemList) { + if (*itemList == ',') { + *itemList = '\0'; + channelCount++; + } + itemList++; + } - Channel_Kick( target, from, Req->argv[0], Req->argc == 3 ? Req->argv[2] : Client_ID( from )); - return CONNECTED; -} /* IRC_KICK */ + itemList = Req->argv[1]; + while (*itemList) { + if (*itemList == ',') { + *itemList = '\0'; + nickCount++; + } + itemList++; + } + 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); + + reason = Req->argc == 3 ? Req->argv[2] : Client_ID(from); + currentNick = Req->argv[1]; + currentChannel = Req->argv[0]; + if (channelCount == 1) { + while (nickCount > 0) { + if (!try_kick(from, currentNick, currentChannel, reason)) + return false; + + while (*currentNick) + currentNick++; + + currentNick++; + nickCount--; + } + } else if (channelCount == nickCount) { + while (nickCount > 0) { + if (!try_kick(from, currentNick, currentChannel, reason)) + return false; + + while (*currentNick) + currentNick++; + + while (*currentChannel) + currentChannel++; + + currentNick++; + currentChannel++; + nickCount--; + } + } else { + return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, + Client_ID(Client), Req->command); + } + return true; +} /* IRC_KICK */ + + GLOBAL bool IRC_INVITE(CLIENT *Client, REQUEST *Req) { blob - bc8df8442deb534d61a6f4f25ad3c21397249904 blob + af1d980bc289b8a55276f220570f37b02fc1848f --- src/testsuite/Makefile.am +++ src/testsuite/Makefile.am @@ -21,6 +21,7 @@ EXTRA_DIST = \ start-server.sh stop-server.sh tests.sh stress-server.sh \ test-loop.sh wait-tests.sh \ channel-test.e connect-test.e check-idle.e misc-test.e mode-test.e \ + kick-test.e \ opless-channel-test.e \ who-test.e stress-A.e stress-B.e \ ngircd-test.conf @@ -48,6 +49,10 @@ channel-test: tests.sh rm -f channel-test ln -s $(srcdir)/tests.sh channel-test +kick-test: tests.sh + rm -f kick-test + ln -s $(srcdir)/tests.sh kick-test + opless-channel-test: tests.sh rm -f opless-channel-test ln -s $(srcdir)/tests.sh opless-channel-test @@ -67,6 +72,7 @@ mode-test: tests.sh TESTS = start-server.sh \ connect-test \ channel-test \ + kick-test \ misc-test \ mode-test \ who-test \ blob - /dev/null blob + 9412d321b990be4c852f5834ff06259ad4b962c0 (mode 644) --- /dev/null +++ src/testsuite/kick-test.e @@ -0,0 +1,112 @@ +spawn telnet localhost 6789 +expect { + timeout { exit 1 } + "Connected" +} + +send "nick nick\r" +send "user user . . :User\r" +expect { + timeout { exit 1 } + "376" +} + +send "kick #Channel nick\r" +expect { + timeout { exit 1 } + "403" +} + +send "join #Channel\r" + +send "kick #Channel nick\r" +expect { + timeout { exit 1 } + "@* KICK #Channel nick :nick" +} + +send "join #Channel\r" + +send "kick #Channel nick :reason\r" +expect { + timeout { exit 1 } + "@* KICK #Channel nick :reason" +} + +send "join #Channel,#Channel2\r" + +send "kick #Channel,#Channel2 nick\r" +expect { + timeout { exit 1 } + "461" +} + +send "kick #Channel,#Channel2,#NoExists,#NoExists nick1,nick,nick3,nick :reason\r" +expect { + timeout { exit 1 } + "401" +} +expect { + timeout { exit 1 } + "@* KICK #Channel2 nick :reason" +} +expect { + timeout { exit 1 } + "401" +} +expect { + timeout { exit 1 } + "403" +} + +send "kick #Channel nick2,nick,nick3\r" +expect { + timeout { exit 1 } + "401" +} +expect { + timeout { exit 1 } + "@* KICK #Channel nick :nick" +} +expect { + timeout { exit 1 } + "401" +} + +send "kick #Channel ,,\r" +expect { + timeout { exit 1 } + "401" +} +expect { + timeout { exit 1 } + "401" +} + +send "kick ,, ,,,\r" +expect { + timeout { exit 1 } + "461" +} + +send "kick ,, ,,\r" +expect { + timeout { exit 1 } + "401" +} +expect { + timeout { exit 1 } + "401" +} +expect { + timeout { exit 1 } + "401" +} + +send "quit\r" +expect { + timeout { exit 1 } + "Connection closed" +} + +# -eof-