summary refs log tree commit diff
path: root/litterbox.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-17 17:13:41 -0500
committerJune McEnroe <june@causal.agency>2019-12-17 17:13:41 -0500
commitf5a8037feddd9801f9364bac6f76842b5334ae58 (patch)
treea958c967a237cd4acdef9d4c0bda47df6dcf7735 /litterbox.c
parentImplement -j join (diff)
downloadlitterbox-f5a8037feddd9801f9364bac6f76842b5334ae58.tar.gz
litterbox-f5a8037feddd9801f9364bac6f76842b5334ae58.zip
Handle ISUPPORT
Diffstat (limited to 'litterbox.c')
-rw-r--r--litterbox.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/litterbox.c b/litterbox.c
index 1eb663a..4171427 100644
--- a/litterbox.c
+++ b/litterbox.c
@@ -106,9 +106,19 @@ static void require(const struct Message *msg, bool nick, size_t len) {
 	}
 }
 
-static char *self;
 static const char *join;
 
+static char *self;
+static char *network;
+static char *chanTypes;
+static char *prefixes;
+
+static void set(char **field, const char *value) {
+	free(*field);
+	*field = strdup(value);
+	if (!*field) err(EX_OSERR, "strdup");
+}
+
 typedef void Handler(struct Message *msg);
 
 static void handleCap(struct Message *msg) {
@@ -118,11 +128,27 @@ static void handleCap(struct Message *msg) {
 
 static void handleReplyWelcome(struct Message *msg) {
 	require(msg, false, 1);
-	self = strdup(msg->params[0]);
-	if (!self) err(EX_OSERR, "strdup");
+	set(&self, msg->params[0]);
 	format("JOIN :%s\r\n", join);
 }
 
+static void handleReplyISupport(struct Message *msg) {
+	for (size_t i = 0; i < ParamCap; ++i) {
+		if (!msg->params[i]) break;
+		char *key = strsep(&msg->params[i], "=");
+		if (!msg->params[i]) continue;
+		if (!strcmp(key, "NETWORK")) {
+			set(&network, msg->params[i]);
+		} else if (!strcmp(key, "CHANTYPES")) {
+			set(&chanTypes, msg->params[i]);
+		} else if (!strcmp(key, "PREFIX")) {
+			strsep(&msg->params[i], ")");
+			if (!msg->params[i]) continue;
+			set(&prefixes, msg->params[i]);
+		}
+	}
+}
+
 static void handlePing(struct Message *msg) {
 	require(msg, false, 1);
 	format("PONG :%s\r\n", msg->params[0]);
@@ -133,6 +159,7 @@ static const struct {
 	Handler *fn;
 } Handlers[] = {
 	{ "001", handleReplyWelcome },
+	{ "005", handleReplyISupport },
 	{ "CAP", handleCap },
 	{ "PING", handlePing },
 };
@@ -197,6 +224,9 @@ int main(int argc, char *argv[]) {
 	}
 
 	if (!host) errx(EX_USAGE, "host required");
+	set(&network, host);
+	set(&chanTypes, "#&");
+	set(&prefixes, "@+");
 
 	client = tls_client();
 	if (!client) errx(EX_SOFTWARE, "tls_client");