kike: some refactoring

This commit is contained in:
Přemysl Eric Janouch 2015-06-13 12:27:58 +02:00
parent a60fc4d47f
commit dd91b521df
1 changed files with 21 additions and 16 deletions

37
kike.c
View File

@ -1130,6 +1130,8 @@ irc_try_finish_registration (struct client *c)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// IRCv3 capability negotiation. See http://ircv3.org for details.
struct irc_cap_args
{
const char *subcommand; ///< The subcommand being processed
@ -1138,6 +1140,19 @@ struct irc_cap_args
const char *target; ///< Target parameter for replies
};
static struct
{
unsigned flag; ///< Flag
const char *name; ///< Name of the capability
}
irc_cap_table[] =
{
{ IRC_CAP_MULTI_PREFIX, "multi-prefix" },
{ IRC_CAP_INVITE_NOTIFY, "invite-notify" },
{ IRC_CAP_ECHO_MESSAGE, "echo-message" },
{ IRC_CAP_USERHOST_IN_NAMES, "userhost-in-names" },
};
static void
irc_handle_cap_ls (struct client *c, struct irc_cap_args *a)
{
@ -1157,14 +1172,9 @@ irc_handle_cap_list (struct client *c, struct irc_cap_args *a)
struct str_vector caps;
str_vector_init (&caps);
if (c->caps_enabled & IRC_CAP_MULTI_PREFIX)
str_vector_add (&caps, "multi-prefix");
if (c->caps_enabled & IRC_CAP_INVITE_NOTIFY)
str_vector_add (&caps, "invite-notify");
if (c->caps_enabled & IRC_CAP_ECHO_MESSAGE)
str_vector_add (&caps, "echo-message");
if (c->caps_enabled & IRC_CAP_USERHOST_IN_NAMES)
str_vector_add (&caps, "userhost-in-names");
for (size_t i = 0; i < N_ELEMENTS (irc_cap_table); i++)
if (c->caps_enabled & irc_cap_table[i].flag)
str_vector_add (&caps, irc_cap_table[i].name);
char *caps_str = join_str_vector (&caps, ' ');
str_vector_free (&caps);
@ -1175,14 +1185,9 @@ irc_handle_cap_list (struct client *c, struct irc_cap_args *a)
static unsigned
irc_decode_capability (const char *name)
{
if (!strcmp (name, "multi-prefix"))
return IRC_CAP_MULTI_PREFIX;
if (!strcmp (name, "invite-notify"))
return IRC_CAP_INVITE_NOTIFY;
if (!strcmp (name, "echo-message"))
return IRC_CAP_ECHO_MESSAGE;
if (!strcmp (name, "userhost-in-names"))
return IRC_CAP_USERHOST_IN_NAMES;
for (size_t i = 0; i < N_ELEMENTS (irc_cap_table); i++)
if (!strcmp (irc_cap_table[i].name, name))
return irc_cap_table[i].flag;
return 0;
}