summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--litterbox.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/litterbox.c b/litterbox.c
index d13851b..338a003 100644
--- a/litterbox.c
+++ b/litterbox.c
@@ -40,10 +40,21 @@ static void printSQL(sqlite3_stmt *stmt) {
 
 static sqlite3 *db;
 
+static const char *CreateJoins = SQL(
+	CREATE TEMPORARY TABLE joins (
+		nick TEXT NOT NULL,
+		channel TEXT NOT NULL,
+		UNIQUE (nick, channel)
+	);
+);
+
 enum {
 	InsertContext,
 	InsertName,
 	InsertEvent,
+	InsertJoin,
+	DeleteJoin,
+	UpdateJoin,
 };
 static const char *Statements[] = {
 	[InsertContext] = SQL(
@@ -68,11 +79,22 @@ static const char *Statements[] = {
 			AND names.user = :user
 			AND names.host = :host;
 	),
+
+	[InsertJoin] = SQL(
+		INSERT INTO joins (nick, channel) VALUES (:nick, :channel);
+	),
+	[DeleteJoin] = SQL(
+		DELETE FROM joins WHERE nick = :nick AND channel = :channel;
+	),
+	[UpdateJoin] = SQL(
+		UPDATE joins SET nick = :new WHERE nick = :old;
+	),
 };
 
 static sqlite3_stmt *stmts[ARRAY_LEN(Statements)];
 
 static void prepare(void) {
+	dbExec(db, CreateJoins);
 	for (size_t i = 0; i < ARRAY_LEN(stmts); ++i) {
 		stmts[i] = dbPrepare(db, true, Statements[i]);
 	}
@@ -116,6 +138,22 @@ static void insertEvent(
 	sqlite3_reset(stmts[InsertEvent]);
 }
 
+static void insertJoin(const char *nick, const char *channel) {
+	dbBindText(stmts[InsertJoin], ":nick", nick);
+	dbBindText(stmts[InsertJoin], ":channel", channel);
+	dbStep(stmts[InsertJoin]);
+	printSQL(stmts[InsertJoin]);
+	sqlite3_reset(stmts[InsertJoin]);
+}
+
+static void deleteJoin(const char *nick, const char *channel) {
+	dbBindText(stmts[DeleteJoin], ":nick", nick);
+	dbBindText(stmts[DeleteJoin], ":channel", channel);
+	dbStep(stmts[DeleteJoin]);
+	printSQL(stmts[DeleteJoin]);
+	sqlite3_reset(stmts[DeleteJoin]);
+}
+
 static struct tls *client;
 
 static void clientWrite(const char *ptr, size_t len) {
@@ -255,6 +293,32 @@ static void handlePrivmsg(struct Message *msg) {
 	}
 }
 
+static void handleJoin(struct Message *msg) {
+	require(msg, 1);
+	insertJoin(msg->nick, msg->params[0]);
+	insertContext(msg->params[0], false);
+	insertName(msg->nick, msg->user, msg->host);
+	insertEvent(msg->time, Join, NULL, NULL);
+}
+
+static void handlePart(struct Message *msg) {
+	require(msg, 1);
+	deleteJoin(msg->nick, msg->params[0]);
+	insertContext(msg->params[0], false);
+	insertName(msg->nick, msg->user, msg->host);
+	insertEvent(msg->time, Part, NULL, msg->params[1]);
+	// TODO: Clear joins if self.
+}
+
+static void handleKick(struct Message *msg) {
+	require(msg, 2);
+	deleteJoin(msg->params[1], msg->params[0]);
+	insertContext(msg->params[0], false);
+	insertName(msg->nick, msg->user, msg->host);
+	insertEvent(msg->time, Kick, msg->params[1], msg->params[2]);
+	// TODO: Clear joins if self.
+}
+
 static void handlePing(struct Message *msg) {
 	require(msg, 1);
 	format("PONG :%s\r\n", msg->params[0]);
@@ -268,9 +332,12 @@ static const struct {
 	{ "001", false, handleReplyWelcome },
 	{ "005", false, handleReplyISupport },
 	{ "CAP", false, handleCap },
+	{ "JOIN", true, handleJoin },
 	{ "NOTICE", true, handlePrivmsg },
+	{ "PART", true, handlePart },
 	{ "PING", false, handlePing },
 	{ "PRIVMSG", true, handlePrivmsg },
+	{ "KICK", true, handleKick },
 };
 
 static void handle(struct Message msg) {
Git upstream bans sprintf() with commit: banned.h: mark sprintf() as banned cc8fdaee1eeaf05d8dd55ff11f111b815f673c58 Signed-off-by: Christian Hesse <mail@eworm.de> 2018-09-11parsing: ban strncpy()Christian Hesse Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse <mail@eworm.de> 2018-08-28filters: generate anchor links from markdownChristian Hesse This makes the markdown filter generate anchor links for headings. Signed-off-by: Christian Hesse <mail@eworm.de> Tested-by: jean-christophe manciot <actionmystique@gmail.com> 2018-08-03Bump version.Jason A. Donenfeld Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> 2018-08-03clone: fix directory traversalJason A. Donenfeld This was introduced in the initial version of this code, way back when in 2008. $ curl http://127.0.0.1/cgit/repo/objects/?path=../../../../../../../../../etc/passwd root:x:0:0:root:/root:/bin/sh ... Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reported-by: Jann Horn <jannh@google.com> 2018-08-03config: record repo.snapshot-prefix in the per-repo configKonstantin Ryabitsev