diff options
author | June McEnroe <june@causal.agency> | 2020-07-12 13:01:41 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-07-12 13:01:41 -0400 |
commit | 99713eb86d677c5d40838f42c19327e11bd513d0 (patch) | |
tree | 7d185de465f35f73499583531ae7be016b835150 | |
parent | Bump default overlap to 30s (diff) | |
download | scooper-99713eb86d677c5d40838f42c19327e11bd513d0.tar.gz scooper-99713eb86d677c5d40838f42c19327e11bd513d0.zip |
Add network MOTD to contexts page
-rw-r--r-- | contexts.c | 29 | ||||
-rw-r--r-- | server.h | 4 |
2 files changed, 33 insertions, 0 deletions
diff --git a/contexts.c b/contexts.c index b486ef9..6ed9223 100644 --- a/contexts.c +++ b/contexts.c @@ -25,6 +25,14 @@ bool contextsPublic; int contextsRecent = 500; +const char *ContextsMOTDQuery = SQL( + SELECT motd + FROM motds + WHERE network = :network + ORDER BY time DESC + LIMIT 1; +); + const char *ContextsQuery = SQL( WITH recentEvents AS ( SELECT time, context @@ -112,5 +120,26 @@ enum kcgi_err contextsPage(struct kreq *req) { if (error) return error; } if (result != SQLITE_DONE) errx(EX_SOFTWARE, "%s", sqlite3_errmsg(db)); + + error = khtml_closeelem(&html, 1); + if (error) return error; + + sqlite3_reset(stmt.contextsMOTD); + dbBindText(stmt.contextsMOTD, ":network", scope.network); + + result = sqlite3_step(stmt.contextsMOTD); + if (result == SQLITE_ROW) { + error = 0 + || khtml_elem(&html, KELEM_H2) + || khtml_puts(&html, "MOTD") + || khtml_closeelem(&html, 1) + || khtml_elem(&html, KELEM_PRE) + || khtml_puts(&html, sqlite3_column_text(stmt.contextsMOTD, 0)) + || khtml_closeelem(&html, 1); + if (error) return error; + result = sqlite3_step(stmt.contextsMOTD); + } + if (result != SQLITE_DONE) errx(EX_SOFTWARE, "%s", sqlite3_errmsg(db)); + return htmlFooter(&html) || khtml_close(&html); } diff --git a/server.h b/server.h index 45008a1..eee5419 100644 --- a/server.h +++ b/server.h @@ -83,6 +83,7 @@ extern int contextsRecent; extern bool contextsPublic; extern const char *NetworksQuery; extern const char *ContextsQuery; +extern const char *ContextsMOTDQuery; enum kcgi_err networksPage(struct kreq *req); enum kcgi_err contextsPage(struct kreq *req); @@ -100,6 +101,7 @@ extern sqlite3 *db; extern struct Statements { sqlite3_stmt *networks; sqlite3_stmt *contexts; + sqlite3_stmt *contextsMOTD; sqlite3_stmt *eventsAfter; sqlite3_stmt *eventsBefore; sqlite3_stmt *search; @@ -115,6 +117,7 @@ static inline void dbPrepare(sqlite3_stmt **stmt, const char *query) { static inline void dbPrepareAll(void) { dbPrepare(&stmt.networks, NetworksQuery); dbPrepare(&stmt.contexts, ContextsQuery); + dbPrepare(&stmt.contextsMOTD, ContextsMOTDQuery); dbPrepare(&stmt.eventsAfter, EventsAfterQuery); dbPrepare(&stmt.eventsBefore, EventsBeforeQuery); dbPrepare(&stmt.search, SearchQuery); @@ -123,6 +126,7 @@ static inline void dbPrepareAll(void) { static inline void dbClose(void) { sqlite3_finalize(stmt.networks); sqlite3_finalize(stmt.contexts); + sqlite3_finalize(stmt.contextsMOTD); sqlite3_finalize(stmt.eventsAfter); sqlite3_finalize(stmt.eventsBefore); sqlite3_finalize(stmt.search); |