~rcr/rirc

d230dfc263acdb4b5a6d56e6d15817f7e94dff0f — Richard Robbins 30 days ago 0dcaae1
fix numeric 401 handling should be sent to channel if found
2 files changed, 77 insertions(+), 2 deletions(-)

M src/handlers/irc_recv.c
M test/handlers/irc_recv.c
M src/handlers/irc_recv.c => src/handlers/irc_recv.c +27 -1
@@ 46,6 46,7 @@ static int irc_numeric_329(struct server*, struct irc_message*);
static int irc_numeric_332(struct server*, struct irc_message*);
static int irc_numeric_333(struct server*, struct irc_message*);
static int irc_numeric_353(struct server*, struct irc_message*);
static int irc_numeric_401(struct server*, struct irc_message*);
static int irc_numeric_433(struct server*, struct irc_message*);

static int irc_recv_numeric(struct server*, struct irc_message*);


@@ 154,7 155,7 @@ static const irc_recv_f irc_numerics[] = {
	[381] = irc_generic_info,   /* RPL_YOUREOPER */
	[391] = irc_generic_info,   /* RPL_TIME */
	[396] = irc_generic_info,   /* RPL_VISIBLEHOST */
	[401] = irc_generic_error,  /* ERR_NOSUCHNICK */
	[401] = irc_numeric_401,    /* ERR_NOSUCHNICK */
	[402] = irc_generic_error,  /* ERR_NOSUCHSERVER */
	[403] = irc_generic_error,  /* ERR_NOSUCHCHANNEL */
	[404] = irc_generic_error,  /* ERR_CANNOTSENDTOCHAN */


@@ 556,6 557,31 @@ irc_numeric_353(struct server *s, struct irc_message *m)
}

static int
irc_numeric_401(struct server *s, struct irc_message *m)
{
	/* <nick> :No such nick/channel */

	char *message;
	char *nick;
	struct channel *c;

	if (!irc_message_param(m, &nick))
		failf(s, "ERR_NOSUCHNICK: nick is null");

	if (!(c = channel_list_get(&(s->clist), nick, s->casemapping)))
		c = s->channel;

	irc_message_param(m, &message);

	if (message && *message)
		newlinef(c, 0, FROM_ERROR, "[%s] %s", nick, message);
	else
		newlinef(c, 0, FROM_ERROR, "[%s] No such nick/channel", nick);

	return 0;
}

static int
irc_numeric_433(struct server *s, struct irc_message *m)
{
	/* 433 <nick> :Nickname is already in use */

M test/handlers/irc_recv.c => test/handlers/irc_recv.c +50 -1
@@ 36,6 36,9 @@ static struct irc_message m;
static struct channel *c1;
static struct channel *c2;
static struct channel *c3;
static struct channel *p1;
static struct channel *p2;
static struct channel *p3;
static struct server *s;

static void


@@ 232,6 235,44 @@ test_irc_numeric_353(void)
}

static void
test_irc_numeric_401(void)
{
	/* <nick> :No such nick/channel */

	server_reset(s);

	/* test errors */
	CHECK_RECV("401 me", 1, 1, 0);
	assert_strcmp(mock_chan[0], "host");
	assert_strcmp(mock_line[0], "ERR_NOSUCHNICK: nick is null");

	/* test channel buffer not found */
	CHECK_RECV("401 me #notfound", 0, 1, 0);
	assert_strcmp(mock_chan[0], "host");
	assert_strcmp(mock_line[0], "[#notfound] No such nick/channel");

	/* test privmsg buffer not found */
	CHECK_RECV("401 me notfound", 0, 1, 0);
	assert_strcmp(mock_chan[0], "host");
	assert_strcmp(mock_line[0], "[notfound] No such nick/channel");

	/* test channel buffer found */
	CHECK_RECV("401 me #c1", 0, 1, 0);
	assert_strcmp(mock_chan[0], "#c1");
	assert_strcmp(mock_line[0], "[#c1] No such nick/channel");

	/* test privmsg buffer found */
	CHECK_RECV("401 me p1", 0, 1, 0);
	assert_strcmp(mock_chan[0], "p1");
	assert_strcmp(mock_line[0], "[p1] No such nick/channel");

	/* test with message */
	CHECK_RECV("401 me p1 :401 message", 0, 1, 0);
	assert_strcmp(mock_chan[0], "p1");
	assert_strcmp(mock_line[0], "[p1] 401 message");
}

static void
test_recv(void)
{
	server_reset(s);


@@ 899,14 940,21 @@ main(void)
	c1 = channel("#c1", CHANNEL_T_CHANNEL);
	c2 = channel("#c2", CHANNEL_T_CHANNEL);
	c3 = channel("#c3", CHANNEL_T_CHANNEL);
	p1 = channel("p1", CHANNEL_T_PRIVMSG);
	p2 = channel("p2", CHANNEL_T_PRIVMSG);
	p3 = channel("p3", CHANNEL_T_PRIVMSG);

	s = server("host", "port", NULL, "user", "real");

	if (!s || !c1 || !c2 || !c3)
	if (!s || !c1 || !c2 || !c3 || !p1 || !p2 || !p3)
		test_abort_main("Failed test setup");

	channel_list_add(&s->clist, c1);
	channel_list_add(&s->clist, c2);
	channel_list_add(&s->clist, c3);
	channel_list_add(&s->clist, p1);
	channel_list_add(&s->clist, p2);
	channel_list_add(&s->clist, p3);

	server_nick_set(s, "me");



@@ 917,6 965,7 @@ main(void)
		TESTCASE(test_irc_generic_info),
		TESTCASE(test_irc_generic_unknown),
		TESTCASE(test_irc_numeric_353),
		TESTCASE(test_irc_numeric_401),
		TESTCASE(test_recv),
		TESTCASE(test_recv_error),
		TESTCASE(test_recv_invite),