diff options
author | June McEnroe <june@causal.agency> | 2019-12-18 01:03:25 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-12-18 01:03:25 -0500 |
commit | 8cc7ef2fa96a936a04886353c64f94309bcdbfd2 (patch) | |
tree | 1e0750185374f23da6dd003de8d224d9a56fd283 /litterbox.c | |
parent | Rewrite litterbox statements with functions (diff) | |
download | litterbox-8cc7ef2fa96a936a04886353c64f94309bcdbfd2.tar.gz litterbox-8cc7ef2fa96a936a04886353c64f94309bcdbfd2.zip |
Wrap handlers in transactions
Diffstat (limited to 'litterbox.c')
-rw-r--r-- | litterbox.c | 15 |
1 files changed, 9 insertions, 6 deletions
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; } } |