summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-10-25 17:40:23 -0400
committerJune McEnroe <june@causal.agency>2019-10-25 17:40:23 -0400
commit7f569f177f5f236daedc633acf8c002dcf346834 (patch)
tree92c294896c3e35a93e652659bd28fab807512a22
parentClean up state (diff)
downloadpounce-7f569f177f5f236daedc633acf8c002dcf346834.tar.gz
pounce-7f569f177f5f236daedc633acf8c002dcf346834.zip
Clean up client
Diffstat (limited to '')
-rw-r--r--client.c70
1 files changed, 35 insertions, 35 deletions
diff --git a/client.c b/client.c
index 4ac1ef4..7079d7a 100644
--- a/client.c
+++ b/client.c
@@ -36,13 +36,13 @@ enum Need {
 };
 
 struct Client {
-	bool error;
 	struct tls *tls;
-	size_t consumer;
 	enum Need need;
+	size_t consumer;
 	bool serverTime;
 	char buf[4096];
 	size_t len;
+	bool error;
 };
 
 struct Client *clientAlloc(struct tls *tls) {
@@ -79,12 +79,12 @@ void clientSend(struct Client *client, const char *ptr, size_t len) {
 }
 
 void clientFormat(struct Client *client, const char *format, ...) {
-	char buf[513];
+	char buf[1024];
 	va_list ap;
 	va_start(ap, format);
 	int len = vsnprintf(buf, sizeof(buf), format, ap);
 	va_end(ap);
-	assert(len > 0 && (size_t)len < sizeof(buf));
+	assert((size_t)len < sizeof(buf));
 	clientSend(client, buf, len);
 }
 
@@ -98,59 +98,61 @@ static void passRequired(struct Client *client) {
 	client->error = true;
 }
 
-typedef void Handler(struct Client *client, struct Message msg);
+static void sync(struct Client *client) {
+	if (client->need == NeedPass) passRequired(client);
+	if (!client->need) stateSync(client);
+}
 
-static void handleNick(struct Client *client, struct Message msg) {
+typedef void Handler(struct Client *client, struct Message *msg);
+
+static void handleNick(struct Client *client, struct Message *msg) {
 	(void)msg;
 	client->need &= ~NeedNick;
-	if (!client->need) stateSync(client);
-	if (client->need == NeedPass) passRequired(client);
+	sync(client);
 }
 
-static void handleUser(struct Client *client, struct Message msg) {
-	if (!msg.params[0]) {
+static void handleUser(struct Client *client, struct Message *msg) {
+	if (!msg->params[0]) {
 		client->error = true;
 		return;
 	}
-	client->consumer = ringConsumer(msg.params[0]);
+	client->consumer = ringConsumer(msg->params[0]);
 	client->need &= ~NeedUser;
-	if (!client->need) stateSync(client);
-	if (client->need == NeedPass) passRequired(client);
+	sync(client);
 }
 
-static void handlePass(struct Client *client, struct Message msg) {
+static void handlePass(struct Client *client, struct Message *msg) {
 	if (!clientPass) return;
-	if (!msg.params[0] || strcmp(clientPass, msg.params[0])) {
+	if (!msg->params[0] || strcmp(msg->params[0], clientPass)) {
 		passRequired(client);
 	} else {
 		client->need &= ~NeedPass;
-		if (!client->need) stateSync(client);
+		sync(client);
 	}
 }
 
-static void handleCap(struct Client *client, struct Message msg) {
-	if (!msg.params[0]) msg.params[0] = "";
+static void handleCap(struct Client *client, struct Message *msg) {
+	if (!msg->params[0]) msg->params[0] = "";
 
-	if (!strcmp(msg.params[0], "END")) {
-		if (client->need & NeedCapEnd) {
-			client->need &= ~NeedCapEnd;
-			if (!client->need) stateSync(client);
-		}
+	if (!strcmp(msg->params[0], "END")) {
+		if (!client->need) return;
+		client->need &= ~NeedCapEnd;
+		sync(client);
 
-	} else if (!strcmp(msg.params[0], "LS")) {
+	} else if (!strcmp(msg->params[0], "LS")) {
 		if (client->need) client->need |= NeedCapEnd;
 		clientFormat(client, ":%s CAP * LS :server-time\r\n", Origin);
 
-	} else if (!strcmp(msg.params[0], "REQ") && msg.params[1]) {
+	} else if (!strcmp(msg->params[0], "REQ") && msg->params[1]) {
 		if (client->need) client->need |= NeedCapEnd;
-		if (!strcmp(msg.params[1], "server-time")) {
+		if (!strcmp(msg->params[1], "server-time")) {
 			client->serverTime = true;
 			clientFormat(client, ":%s CAP * ACK :server-time\r\n", Origin);
 		} else {
-			clientFormat(client, ":%s CAP * NAK :%s\r\n", Origin, msg.params[1]);
+			clientFormat(client, ":%s CAP * NAK :%s\r\n", Origin, msg->params[1]);
 		}
 
-	} else if (!strcmp(msg.params[0], "LIST")) {
+	} else if (!strcmp(msg->params[0], "LIST")) {
 		clientFormat(
 			client, ":%s CAP * LIST :%s\r\n",
 			Origin, (client->serverTime ? "server-time" : "")
@@ -161,11 +163,10 @@ static void handleCap(struct Client *client, struct Message msg) {
 	}
 }
 
-static void handleQuit(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;
-	// TODO: Set AWAY if no more clients attached.
 }
 
 static const struct {
@@ -184,7 +185,7 @@ static void clientParse(struct Client *client, char *line) {
 	if (!msg.cmd) return;
 	for (size_t i = 0; i < ARRAY_LEN(Handlers); ++i) {
 		if (strcmp(msg.cmd, Handlers[i].cmd)) continue;
-		Handlers[i].fn(client, msg);
+		Handlers[i].fn(client, &msg);
 		break;
 	}
 }
@@ -192,7 +193,7 @@ static void clientParse(struct Client *client, char *line) {
 static bool intercept(const char *line, size_t len) {
 	if (len >= 4 && !memcmp(line, "CAP ", 4)) return true;
 	if (len >= 5 && !memcmp(line, "QUIT ", 5)) return true;
-	// TODO: Intercept PRIVMSG to send to other clients.
+	// TODO: Intercept PRIVMSG and NOTICE to send to other clients.
 	return false;
 }
 
@@ -202,8 +203,8 @@ void clientRecv(struct Client *client) {
 		&client->buf[client->len], sizeof(client->buf) - client->len
 	);
 	if (read == TLS_WANT_POLLIN || read == TLS_WANT_POLLOUT) return;
-	if (read < 0) warnx("tls_read: %s", tls_error(client->tls));
-	if (read < 1) {
+	if (read < 0) {
+		warnx("tls_read: %s", tls_error(client->tls));
 		client->error = true;
 		return;
 	}
@@ -234,7 +235,6 @@ size_t clientDiff(const struct Client *client) {
 	return ringDiff(client->consumer);
 }
 
-// TODO: Read several lines based on LOWAT for POLLOUT?
 void clientConsume(struct Client *client) {
 	time_t time;
 	const char *line = ringConsume(&time, client->consumer);
i-shared.c?h=1.4.1&id=c0b59823035efc136a82a96094d164a979d9b2e9&follow=1'>redirect: cleanlinessJason A. Donenfeld 2015-08-13redirect: be more careful for different cgi setupsJason A. Donenfeld 2015-08-12ui-log: fix double countingJohn Keeping This crept in while rebasing the previous commit onto an updated upstream. Signed-off-by: John Keeping <john@keeping.me.uk> 2015-08-12log: allow users to follow a fileJohn Keeping Teach the "log" UI to behave in the same way as "git log --follow", when given a suitable instruction by the user. The default behaviour remains to show the log without following renames, but the follow behaviour can be activated by following a link in the page header. Follow is not the default because outputting merges in follow mode is tricky ("git log --follow" will not show merges). We also disable the graph in follow mode because the commit graph is not simplified so we end up with frequent gaps in the graph and many lines that do not connect with any commits we're actually showing. We also teach the "diff" and "commit" UIs to respect the follow flag on URLs, causing the single-file version of these UIs to detect renames. This feature is needed only for commits that rename the path we're interested in. For commits before the file has been renamed (i.e. that appear later in the log list) we change the file path in the links from the log to point to the old name; this means that links to commits always limit by the path known to that commit. If we didn't do this we would need to walk down the log diff'ing every commit whenever we want to show a commit. The drawback is that the "Log" link in the top bar of such a page links to the log limited by the old name, so it will only show pre-rename commits. I consider this a reasonable trade-off since the "Back" button still works and the log matches the path displayed in the top bar. Since following renames requires running diff on every commit we consider, I've added a knob to the configuration file to globally enable/disable this feature. Note that we may consider a large number of commits the revision walking machinery no longer performs any path limitation so we have to examine every commit until we find a page full of commits that affect the target path or something related to it. Suggested-by: René Neumann <necoro@necoro.eu> Signed-off-by: John Keeping <john@keeping.me.uk> 2015-08-12shared: make cgit_diff_tree_cb publicJohn Keeping This will allow us to use this nice wrapper function elsewhere, avoiding dealing with the diff queue when we only need to inspect a filepair. Signed-off-by: John Keeping <john@keeping.me.uk> 2015-08-12t0110: Chain together using &&Jason A. Donenfeld 2015-08-12about: always ensure page has a trailing slashJason A. Donenfeld Otherwise we can't easily embed links to other /about/ pages. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2015-08-12filters: apply HTML escapingLazaros Koromilas http://www.w3.org/International/questions/qa-escapes#use 2015-08-12git: update to v2.5.0Christian Hesse Update to git version v2.5.0. * Upstream commit 5455ee0573a22bb793a7083d593ae1ace909cd4c (Merge branch 'bc/object-id') changed API: for_each_ref() callback functions were taught to name the objects not with "unsigned char sha1[20]" but with "struct object_id". * Upstream commit dcf692625ac569fefbe52269061230f4fde10e47 (path.c: make get_pathname() call sites return const char *) Signed-off-by: Christian Hesse <mail@eworm.de> 2015-08-12Fix processing of repo.hide and repo.ignoreDaniel Reichelt