summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--litterbox.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/litterbox.c b/litterbox.c
index 2b2736d..1eb663a 100644
--- a/litterbox.c
+++ b/litterbox.c
@@ -96,6 +96,19 @@ static struct Message parse(char *line) {
 	return msg;
 }
 
+static void require(const struct Message *msg, bool nick, size_t len) {
+	if (nick && !msg->nick) {
+		errx(EX_PROTOCOL, "%s missing origin nick", msg->cmd);
+	}
+	for (size_t i = 0; i < len; ++i) {
+		if (msg->params[i]) continue;
+		errx(EX_PROTOCOL, "%s missing parameter %zu", msg->cmd, 1 + i);
+	}
+}
+
+static char *self;
+static const char *join;
+
 typedef void Handler(struct Message *msg);
 
 static void handleCap(struct Message *msg) {
@@ -103,8 +116,15 @@ static void handleCap(struct Message *msg) {
 	format("CAP END\r\n");
 }
 
+static void handleReplyWelcome(struct Message *msg) {
+	require(msg, false, 1);
+	self = strdup(msg->params[0]);
+	if (!self) err(EX_OSERR, "strdup");
+	format("JOIN :%s\r\n", join);
+}
+
 static void handlePing(struct Message *msg) {
-	// TODO: Require params[0].
+	require(msg, false, 1);
 	format("PONG :%s\r\n", msg->params[0]);
 }
 
@@ -112,6 +132,7 @@ static const struct {
 	const char *cmd;
 	Handler *fn;
 } Handlers[] = {
+	{ "001", handleReplyWelcome },
 	{ "CAP", handleCap },
 	{ "PING", handlePing },
 };
@@ -139,12 +160,13 @@ int main(int argc, char *argv[]) {
 	const char *pass = NULL;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "!d:h:imn:p:u:vw:"))) {
+	while (0 < (opt = getopt(argc, argv, "!d:h:ij:mn:p:u:vw:"))) {
 		switch (opt) {
 			break; case '!': insecure = true;
 			break; case 'd': path = optarg;
 			break; case 'h': host = optarg;
 			break; case 'i': init = true;
+			break; case 'j': join = optarg;
 			break; case 'm': migrate = true;
 			break; case 'n': nick = optarg;
 			break; case 'p': port = optarg;
nohover-highlight'> Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-06-07Add head-include configuration option.Mark Lodato This patch adds an option to the configuration file, "head-include", which works just like "header" or "footer", except the content is put into the HTML's <head> tag. 2009-03-15CGIT 0.8.2.1Lars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-03-15Fix doc-related glitches in Makefile and .gitignoreLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-03-15ui-snapshot: avoid segfault when no filename is specifiedLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-03-15fix segfault when displaying empty blobsEric Wong When size is zero, subtracting one from it turns it into ULONG_MAX which causes an out-of-bounds access on buf. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-19Add support for HEAD requestsLars Hjemli This is a quick 'n dirty hack which makes cgit honor HEAD requests. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-19Add support for ETag in 'plain' viewLars Hjemli When downloading a blob identified by its path, the client might want to know if the blob has been modified since a previous download of the same path. To this end, an ETag containing the blob SHA1 seems to be ideal. Todo: add support for HEAD requests... Suggested-by: Owen Taylor <otaylor@redhat.com> Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-12ui-tree: escape ascii-text properly in hexdump viewLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2009-02-12Makefile: add doc-related targetsLars Hjemli