From 8cc7ef2fa96a936a04886353c64f94309bcdbfd2 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Wed, 18 Dec 2019 01:03:25 -0500 Subject: Wrap handlers in transactions --- litterbox.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'litterbox.c') diff --git a/litterbox.c b/litterbox.c index e37f78a..1401112 100644 --- a/litterbox.c +++ b/litterbox.c @@ -258,21 +258,24 @@ static void handlePing(struct Message *msg) { static const struct { const char *cmd; + bool transaction; Handler *fn; } Handlers[] = { - { "001", handleReplyWelcome }, - { "005", handleReplyISupport }, - { "CAP", handleCap }, - { "NOTICE", handlePrivmsg }, - { "PING", handlePing }, - { "PRIVMSG", handlePrivmsg }, + { "001", false, handleReplyWelcome }, + { "005", false, handleReplyISupport }, + { "CAP", false, handleCap }, + { "NOTICE", true, handlePrivmsg }, + { "PING", false, handlePing }, + { "PRIVMSG", true, handlePrivmsg }, }; static void handle(struct Message msg) { if (!msg.cmd) return; for (size_t i = 0; i < ARRAY_LEN(Handlers); ++i) { if (strcmp(msg.cmd, Handlers[i].cmd)) continue; + dbExec(db, SQL(BEGIN TRANSACTION;)); Handlers[i].fn(&msg); + dbExec(db, SQL(COMMIT TRANSACTION;)); break; } } -- cgit 1.4.1