commit - b1d38de4d23e78ec27c11277a007c202e3edcd38
commit + 70254a5553b97109df8417c2a6fcb71d55ab371d
blob - 86e1ace2a56ef0efe49fcce8580ab09e60b50ca2
blob + 43f2c1b6e4c1949724fa2e6281b70a11375a3ea3
--- src/ngircd/irc-info.c
+++ src/ngircd/irc-info.c
} /* IRC_WHOIS */
+static bool
+WHOWAS_EntryWrite(CLIENT *prefix, WHOWAS *entry)
+{
+ char t_str[60];
+
+ (void)strftime(t_str, sizeof(t_str), "%a %b %d %H:%M:%S %Y",
+ localtime(&entry->time));
+
+ if (!IRC_WriteStrClient(prefix, RPL_WHOWASUSER_MSG, Client_ID(prefix),
+ entry->id, entry->user, entry->host, entry->info))
+ return DISCONNECTED;
+
+ return IRC_WriteStrClient(prefix, RPL_WHOISSERVER_MSG, Client_ID(prefix),
+ entry->id, entry->server, t_str);
+}
+
/**
* IRC "WHOWAS" function.
* This function implements the IRC command "WHOWHAS". It handles local
{
CLIENT *target, *prefix;
WHOWAS *whowas;
- int max, last, count, i;
- char t_str[60];
-
+ char tok_buf[COMMAND_LEN];
+ int max, last, count, i, nc;
+ const char *nick;
+
assert( Client != NULL );
assert( Req != NULL );
/* Wrong number of parameters? */
- if(( Req->argc < 1 ) || ( Req->argc > 3 ))
- return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG,
- Client_ID( Client ), Req->command );
+ if (Req->argc > 3)
+ return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+ Client_ID(Client), Req->command);
+ if (Req->argc < 1)
+ return IRC_WriteStrClient(Client, ERR_NONICKNAMEGIVEN_MSG, Client_ID(Client));
- /* Search taget */
- if( Req->argc == 3 )
- target = Client_Search( Req->argv[2] );
+ /* Search target */
+ if (Req->argc == 3)
+ target = Client_Search(Req->argv[2]);
else
- target = Client_ThisServer( );
+ target = Client_ThisServer();
/* Get prefix */
- if( Client_Type( Client ) == CLIENT_SERVER )
- prefix = Client_Search( Req->prefix );
+ if (Client_Type(Client) == CLIENT_SERVER)
+ prefix = Client_Search(Req->prefix);
else
prefix = Client;
- if( ! prefix )
- return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG,
- Client_ID( Client ), Req->prefix );
+ if (!prefix)
+ return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
+ Client_ID(Client), Req->prefix);
/* Forward to other server? */
- if( target != Client_ThisServer( ))
- {
- if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER ))
- return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG,
- Client_ID( prefix ),
- Req->argv[2] );
+ if (target != Client_ThisServer()) {
+ if (!target || (Client_Type(target) != CLIENT_SERVER))
+ return IRC_WriteStrClient(prefix, ERR_NOSUCHSERVER_MSG,
+ Client_ID(prefix), Req->argv[2]);
/* Forward */
IRC_WriteStrClientPrefix( target, prefix, "WHOWAS %s %s %s",
Req->argv[2] );
return CONNECTED;
}
-
+
whowas = Client_GetWhowas( );
last = Client_GetLastWhowasIndex( );
- if( last < 0 ) last = 0;
-
- if( Req->argc > 1 )
- {
- max = atoi( Req->argv[1] );
- if( max < 1 ) max = MAX_WHOWAS;
+ if (last < 0)
+ last = 0;
+
+ max = DEFAULT_WHOWAS;
+ if (Req->argc > 1) {
+ max = atoi(Req->argv[1]);
+ if (max < 1)
+ max = MAX_WHOWAS;
}
- else
- max = DEFAULT_WHOWAS;
-
- i = last;
- count = 0;
- do
- {
- /* Used entry? */
- if( whowas[i].time > 0 &&
- strcasecmp( Req->argv[0], whowas[i].id ) == 0 )
- {
- (void)strftime( t_str, sizeof(t_str),
- "%a %b %d %H:%M:%S %Y",
- localtime( &whowas[i].time ));
-
- if( ! IRC_WriteStrClient( prefix, RPL_WHOWASUSER_MSG,
- Client_ID( prefix ),
- whowas[i].id,
- whowas[i].user,
- whowas[i].host,
- whowas[i].info ))
- return DISCONNECTED;
-
- if( ! IRC_WriteStrClient( prefix, RPL_WHOISSERVER_MSG,
- Client_ID( prefix ),
- whowas[i].id,
- whowas[i].server, t_str ))
- return DISCONNECTED;
-
- count++;
- if( count >= max ) break;
- }
-
- /* previos entry */
- i--;
- /* "underflow", wrap around */
- if( i < 0 ) i = MAX_WHOWAS - 1;
- } while( i != last );
-
- return IRC_WriteStrClient( prefix, RPL_ENDOFWHOWAS_MSG,
- Client_ID( prefix ), Req->argv[0] );
+ /*
+ * Break up the nick argument into a list of nicks, if applicable
+ * Can't modify Req->argv[0] because we need it for RPL_ENDOFWHOWAS_MSG.
+ */
+ strlcpy(tok_buf, Req->argv[0], sizeof(tok_buf));
+ nick = strtok(tok_buf, ",");
+
+ for (i=last, count=0; nick != NULL ; nick = strtok(NULL, ",")) {
+ nc = 0;
+ do {
+ /* Used entry? */
+ if (whowas[i].time > 0 && strcasecmp(nick, whowas[i].id) == 0) {
+ if (!WHOWAS_EntryWrite(prefix, &whowas[i]))
+ return DISCONNECTED;
+ nc++;
+ count++;
+ }
+ /* previous entry */
+ i--;
+
+ /* "underflow", wrap around */
+ if (i < 0)
+ i = MAX_WHOWAS - 1;
+
+ if (nc && count >= max)
+ break;
+ } while (i != last);
+
+ if (nc == 0 && !IRC_WriteStrClient(prefix, ERR_WASNOSUCHNICK_MSG,
+ Client_ID(prefix), nick))
+ return DISCONNECTED;
+ }
+ return IRC_WriteStrClient(prefix, RPL_ENDOFWHOWAS_MSG, Client_ID(prefix), Req->argv[0]);
} /* IRC_WHOWAS */
blob - bde1c095fc73cf0a58e356c6ddea758f326dcdab
blob + 36d6f48e6e5409fd20932b47f7c3640a6583edec
--- src/ngircd/messages.h
+++ src/ngircd/messages.h
#define ERR_NOTEXTTOSEND_MSG "412 %s :No text to send"
#define ERR_UNKNOWNCOMMAND_MSG "421 %s %s :Unknown command"
#define ERR_NOMOTD_MSG "422 %s :MOTD file is missing"
+#define ERR_NONICKNAMEGIVEN_MSG "431 %s :No nickname given"
#define ERR_ERRONEUSNICKNAME_MSG "432 %s %s :Erroneous nickname"
#define ERR_NICKNAMEINUSE_MSG "433 %s %s :Nickname already in use"
#define ERR_USERNOTINCHANNEL_MSG "441 %s %s %s :They aren't on that channel"