aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-05-28 04:25:38 +0200
committerPřemysl Eric Janouch <p@janouch.name>2021-05-28 04:59:21 +0200
commitddffc71abe49a6d9f87b005e0814cb71a2ae8d54 (patch)
tree8a5ec6698146fea5e51750924e9dcbdecae51d44
parent5a0b2d1c5752c6e6541c9bb8c2ca7f5ce6a58565 (diff)
downloadxK-ddffc71abe49a6d9f87b005e0814cb71a2ae8d54.tar.gz
xK-ddffc71abe49a6d9f87b005e0814cb71a2ae8d54.tar.xz
xK-ddffc71abe49a6d9f87b005e0814cb71a2ae8d54.zip
degesch: factor out irc_try_finish_cap_negotiation()
Too much repeated, non-obvious code.
-rw-r--r--degesch.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/degesch.c b/degesch.c
index b186125..2033497 100644
--- a/degesch.c
+++ b/degesch.c
@@ -6601,6 +6601,15 @@ irc_toggle_cap (struct server *s, const char *cap, bool active)
}
static void
+irc_try_finish_cap_negotiation (struct server *s)
+{
+ // It does not make sense to do this post-registration, although it would
+ // not hurt either, as the server must ignore it in that case
+ if (s->state == IRC_CONNECTED)
+ irc_send (s, "CAP END");
+}
+
+static void
irc_handle_cap (struct server *s, const struct irc_message *msg)
{
if (msg->params.len < 2)
@@ -6629,15 +6638,14 @@ irc_handle_cap (struct server *s, const struct irc_message *msg)
}
if (s->cap_sasl && s->transport == &g_transport_tls)
irc_send (s, "AUTHENTICATE EXTERNAL");
- else if (s->state == IRC_CONNECTED)
- irc_send (s, "CAP END");
+ else
+ irc_try_finish_cap_negotiation (s);
}
else if (!strcasecmp_ascii (subcommand, "NAK"))
{
log_server_error (s, s->buffer,
"#s: #S", "Capabilities not acknowledged", args);
- if (s->state == IRC_CONNECTED)
- irc_send (s, "CAP END");
+ irc_try_finish_cap_negotiation (s);
}
else if (!strcasecmp_ascii (subcommand, "DEL"))
{
@@ -8002,8 +8010,7 @@ irc_process_numeric (struct server *s,
case IRC_ERR_SASLTOOLONG:
case IRC_ERR_SASLABORTED:
case IRC_ERR_SASLALREADY:
- if (s->state == IRC_CONNECTED)
- irc_send (s, "CAP END");
+ irc_try_finish_cap_negotiation (s);
break;
case IRC_RPL_LIST: