about summary refs log tree commit diff
path: root/client.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-03-29 19:15:30 -0400
committerJune McEnroe <june@causal.agency>2022-03-29 19:15:30 -0400
commit78daf36f34b2b59618ee971cbb797bbd2ec41fd5 (patch)
tree7099abca0cae8a2f6686e09d48c3812578c57021 /client.c
parentSend 900 as part of stateSync (diff)
downloadpounce-78daf36f34b2b59618ee971cbb797bbd2ec41fd5.tar.gz
pounce-78daf36f34b2b59618ee971cbb797bbd2ec41fd5.zip
Rename client->error to client->remove
Diffstat (limited to '')
-rw-r--r--client.c61
1 files changed, 31 insertions, 30 deletions
diff --git a/client.c b/client.c
index 6b75681..a20700d 100644
--- a/client.c
+++ b/client.c
@@ -43,10 +43,28 @@
 #include "bounce.h"
 
 enum Cap clientCaps = CapServerTime | CapConsumer | CapPassive | CapSTS;
-char *clientOrigin = "irc.invalid";
+char *clientOrigin;
 char *clientPass;
 char *clientAway;
 
+static size_t active;
+
+static void activeIncr(const struct Client *client) {
+	if (client->need) return;
+	if (client->caps & CapPassive) return;
+	if (!active++) {
+		serverEnqueue("AWAY\r\n");
+	}
+}
+
+static void activeDecr(const struct Client *client) {
+	if (client->need) return;
+	if (client->caps & CapPassive) return;
+	if (!--active && !stateAway) {
+		serverEnqueue("AWAY :%s\r\n", clientAway);
+	}
+}
+
 struct Client *clientAlloc(int sock, struct tls *tls) {
 	struct Client *client = calloc(1, sizeof(*client));
 	if (!client) err(EX_OSERR, "calloc");
@@ -65,7 +83,7 @@ static void clientHandshake(struct Client *client) {
 	if (error == TLS_WANT_POLLIN || error == TLS_WANT_POLLOUT) return;
 	if (error) {
 		warnx("client tls_handshake: %s", tls_error(client->tls));
-		client->error = true;
+		client->remove = true;
 		return;
 	}
 	client->need &= ~NeedHandshake;
@@ -74,24 +92,6 @@ static void clientHandshake(struct Client *client) {
 	}
 }
 
-static size_t active;
-
-static void activeIncr(const struct Client *client) {
-	if (client->need) return;
-	if (client->caps & CapPassive) return;
-	if (!active++) {
-		serverEnqueue("AWAY\r\n");
-	}
-}
-
-static void activeDecr(const struct Client *client) {
-	if (client->need) return;
-	if (client->caps & CapPassive) return;
-	if (!--active && !stateAway) {
-		serverEnqueue("AWAY :%s\r\n", clientAway);
-	}
-}
-
 void clientFree(struct Client *client) {
 	activeDecr(client);
 	tls_close(client->tls);
@@ -107,7 +107,7 @@ void clientSend(struct Client *client, const char *ptr, size_t len) {
 		if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) continue;
 		if (ret < 0) {
 			warnx("client tls_write: %s", tls_error(client->tls));
-			client->error = true;
+			client->remove = true;
 			break;
 		}
 		ptr += ret;
@@ -134,7 +134,7 @@ static void passRequired(struct Client *client) {
 		"ERROR :Password incorrect\r\n",
 		clientOrigin
 	);
-	client->error = true;
+	client->remove = true;
 }
 
 static void maybeSync(struct Client *client) {
@@ -156,7 +156,7 @@ static void handleNick(struct Client *client, struct Message *msg) {
 
 static void handleUser(struct Client *client, struct Message *msg) {
 	if (!msg->params[0]) {
-		client->error = true;
+		client->remove = true;
 		return;
 	}
 	if (client->need & NeedPass) {
@@ -172,7 +172,7 @@ static void handleUser(struct Client *client, struct Message *msg) {
 static void handlePass(struct Client *client, struct Message *msg) {
 	if (!clientPass) return;
 	if (!msg->params[0]) {
-		client->error = true;
+		client->remove = true;
 		return;
 	}
 #ifdef __OpenBSD__
@@ -180,13 +180,13 @@ static void handlePass(struct Client *client, struct Message *msg) {
 #else
 	int error = strcmp(crypt(msg->params[0], clientPass), clientPass);
 #endif
+	explicit_bzero(msg->params[0], strlen(msg->params[0]));
 	if (error) {
 		passRequired(client);
 	} else {
 		client->need &= ~NeedPass;
 		maybeSync(client);
 	}
-	explicit_bzero(msg->params[0], strlen(msg->params[0]));
 }
 
 static void handleCap(struct Client *client, struct Message *msg) {
@@ -238,7 +238,8 @@ static void handleCap(struct Client *client, struct Message *msg) {
 		} else {
 			clientFormat(
 				client, ":%s CAP * NAK :%s\r\n",
-				clientOrigin, msg->params[1]);
+				clientOrigin, msg->params[1]
+			);
 		}
 
 	} else if (!strcmp(msg->params[0], "LIST")) {
@@ -280,7 +281,7 @@ static void handleAuthenticate(struct Client *client, struct Message *msg) {
 static void handleQuit(struct Client *client, struct Message *msg) {
 	(void)msg;
 	clientFormat(client, "ERROR :Detaching\r\n");
-	client->error = true;
+	client->remove = true;
 }
 
 static bool hasTag(const char *tags, const char *tag) {
@@ -395,7 +396,7 @@ static void clientParse(struct Client *client, char *line) {
 		Handlers[i].fn(client, &msg);
 		return;
 	}
-	client->error = true;
+	client->remove = true;
 }
 
 static bool intercept(const char *line, size_t len) {
@@ -429,7 +430,7 @@ void clientRecv(struct Client *client) {
 	if (read == TLS_WANT_POLLIN || read == TLS_WANT_POLLOUT) return;
 	if (read <= 0) {
 		if (read < 0) warnx("client tls_read: %s", tls_error(client->tls));
-		client->error = true;
+		client->remove = true;
 		return;
 	}
 	client->len += read;
@@ -657,5 +658,5 @@ void clientConsume(struct Client *client) {
 	} else {
 		clientFormat(client, "%s\r\n", line);
 	}
-	if (!client->error) ringConsume(NULL, client->consumer);
+	if (!client->remove) ringConsume(NULL, client->consumer);
 }