diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-13 12:27:58 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-06-13 12:42:41 +0200 |
commit | dd91b521df5adc08e6b45be1927d0af6e5c2dcd4 (patch) | |
tree | 0b4d8e4a2d7157966a6cd3843b9a3420c3add3ca /kike.c | |
parent | a60fc4d47f827a4989799e88a6aaf7db1cc5a44c (diff) | |
download | xK-dd91b521df5adc08e6b45be1927d0af6e5c2dcd4.tar.gz xK-dd91b521df5adc08e6b45be1927d0af6e5c2dcd4.tar.xz xK-dd91b521df5adc08e6b45be1927d0af6e5c2dcd4.zip |
kike: some refactoring
Diffstat (limited to 'kike.c')
-rw-r--r-- | kike.c | 37 |
1 files changed, 21 insertions, 16 deletions
@@ -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; } |