summary refs log tree commit diff stats
path: root/src/common/inbound.c
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2016-01-28 15:18:15 -0500
committerPatrick Griffis <tingping@tingping.se>2016-01-28 15:18:15 -0500
commit4e061a43b3453a9856d34250c3913175c45afe9d (patch)
treef92fcc0757c1bbc0cde2e6d3341a1c47c08470d6 /src/common/inbound.c
parent5c534ac344ab8646185e9c50198365eb774920a3 (diff)
Clean up handling CAP LS
Diffstat (limited to 'src/common/inbound.c')
-rw-r--r--src/common/inbound.c96
1 files changed, 37 insertions, 59 deletions
diff --git a/src/common/inbound.c b/src/common/inbound.c
index ef26890b..645cc824 100644
--- a/src/common/inbound.c
+++ b/src/common/inbound.c
@@ -1699,20 +1699,37 @@ inbound_cap_ack (server *serv, char *nick, char *extensions,
 	}
 }
 
+static const char * const supported_caps[] = {
+	"identify-msg",
+
+	/* IRCv3.1 */
+	"multi-prefix",
+	"away-notify",
+	"account-notify",
+	"extended-join",
+	/* "sasl", Handled manually */
+
+	/* IRCv3.2 */
+	"server-time"
+	"userhost-in-names",
+
+	/* ZNC */
+	"znc.in/server-time-iso",
+	"znc.in/server-time",
+};
+
 void
 inbound_cap_ls (server *serv, char *nick, char *extensions_str,
 					 const message_tags_data *tags_data)
 {
 	char buffer[256];	/* buffer for requesting capabilities and emitting the signal */
-	guint32 want_cap; /* format the CAP REQ string based on previous capabilities being requested or not */
-	guint32 want_sasl; /* CAP END shouldn't be sent when SASL is requested, it needs further responses */
+	gboolean want_cap = FALSE; /* format the CAP REQ string based on previous capabilities being requested or not */
+	gboolean want_sasl = FALSE; /* CAP END shouldn't be sent when SASL is requested, it needs further responses */
 	char **extensions;
 	int i;
 
 	EMIT_SIGNAL_TIMESTAMP (XP_TE_CAPLIST, serv->server_session, nick,
 								  extensions_str, NULL, NULL, 0, tags_data->timestamp);
-	want_cap = 0;
-	want_sasl = 0;
 
 	extensions = g_strsplit (extensions_str, " ", 0);
 
@@ -1721,66 +1738,27 @@ inbound_cap_ls (server *serv, char *nick, char *extensions_str,
 	for (i=0; extensions[i]; i++)
 	{
 		const char *extension = extensions[i];
+		gsize x;
 
-		if (!strcmp (extension, "identify-msg"))
-		{
-			strcat (buffer, "identify-msg ");
-			want_cap = 1;
-		}
-		if (!strcmp (extension, "multi-prefix"))
-		{
-			strcat (buffer, "multi-prefix ");
-			want_cap = 1;
-		}
-		if (!strcmp (extension, "away-notify"))
-		{
-			strcat (buffer, "away-notify ");
-			want_cap = 1;
-		}
-		if (!strcmp (extension, "account-notify"))
-		{
-			strcat (buffer, "account-notify ");
-			want_cap = 1;
-		}
-		if (!strcmp (extension, "extended-join"))
-		{
-			strcat (buffer, "extended-join ");
-			want_cap = 1;
-		}
-		if (!strcmp (extension, "userhost-in-names"))
+		/* if the SASL password is set AND auth mode is set to SASL, request SASL auth */
+		if (!g_strcmp0 (extension, "sasl") &&
+			((serv->loginmethod == LOGIN_SASL && strlen (serv->password) != 0)
+				|| (serv->loginmethod == LOGIN_SASLEXTERNAL && serv->have_cert)))
 		{
-			strcat (buffer, "userhost-in-names ");
-			want_cap = 1;
+			want_cap = TRUE;
+			want_sasl = TRUE;
+			g_strlcat (buffer, "sasl ", sizeof(buffer));
+			continue;
 		}
 
-		/* bouncers can prefix a name space to the extension so we should use.
-		 * znc <= 1.0 uses "znc.in/server-time" and newer use "znc.in/server-time-iso".
-		 */
-		if (!strcmp (extension, "znc.in/server-time-iso"))
-		{
-			strcat (buffer, "znc.in/server-time-iso ");
-			want_cap = 1;
-		}
-		if (!strcmp (extension, "znc.in/server-time"))
-		{
-			strcat (buffer, "znc.in/server-time ");
-			want_cap = 1;
-		}
-		if (prefs.hex_irc_cap_server_time
-			 && !strcmp (extension, "server-time"))
+		for (x = 0; x < G_N_ELEMENTS(supported_caps); ++x)
 		{
-			strcat (buffer, "server-time ");
-			want_cap = 1;
-		}
-		
-		/* if the SASL password is set AND auth mode is set to SASL, request SASL auth */
-		if (!strcmp (extension, "sasl")
-			&& ((serv->loginmethod == LOGIN_SASL && strlen (serv->password) != 0)
-			|| (serv->loginmethod == LOGIN_SASLEXTERNAL && serv->have_cert)))
-		{
-			strcat (buffer, "sasl ");
-			want_cap = 1;
-			want_sasl = 1;
+			if (!g_strcmp0 (extension, supported_caps[x]))
+			{
+				g_strlcat (buffer, extension, sizeof(buffer));
+				g_strlcat (buffer, " ", sizeof(buffer));
+				want_cap = TRUE;
+			}
 		}
 	}