aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kike.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/kike.c b/kike.c
index 3a80b5d..783c6e2 100644
--- a/kike.c
+++ b/kike.c
@@ -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;
}