kike: some refactoring

This commit is contained in:
Přemysl Eric Janouch 2015-06-13 12:27:58 +02:00
parent a60fc4d47f
commit dd91b521df

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 struct irc_cap_args
{ {
const char *subcommand; ///< The subcommand being processed const char *subcommand; ///< The subcommand being processed
@ -1138,6 +1140,19 @@ struct irc_cap_args
const char *target; ///< Target parameter for replies 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 static void
irc_handle_cap_ls (struct client *c, struct irc_cap_args *a) 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; struct str_vector caps;
str_vector_init (&caps); str_vector_init (&caps);
if (c->caps_enabled & IRC_CAP_MULTI_PREFIX) for (size_t i = 0; i < N_ELEMENTS (irc_cap_table); i++)
str_vector_add (&caps, "multi-prefix"); if (c->caps_enabled & irc_cap_table[i].flag)
if (c->caps_enabled & IRC_CAP_INVITE_NOTIFY) str_vector_add (&caps, irc_cap_table[i].name);
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");
char *caps_str = join_str_vector (&caps, ' '); char *caps_str = join_str_vector (&caps, ' ');
str_vector_free (&caps); str_vector_free (&caps);
@ -1175,14 +1185,9 @@ irc_handle_cap_list (struct client *c, struct irc_cap_args *a)
static unsigned static unsigned
irc_decode_capability (const char *name) irc_decode_capability (const char *name)
{ {
if (!strcmp (name, "multi-prefix")) for (size_t i = 0; i < N_ELEMENTS (irc_cap_table); i++)
return IRC_CAP_MULTI_PREFIX; if (!strcmp (irc_cap_table[i].name, name))
if (!strcmp (name, "invite-notify")) return irc_cap_table[i].flag;
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;
return 0; return 0;
} }