From 6500baa1ffc720ec4c0f256dd99dab478225122b Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Thu, 16 Jul 2020 17:46:19 -0400 Subject: Big refactor, remove struct Scope --- search.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'search.c') diff --git a/search.c b/search.c index c284732..67ce79c 100644 --- a/search.c +++ b/search.c @@ -44,15 +44,15 @@ const char *SearchQuery = SQL( LIMIT :offset, :limit; ); -static char *offsetURL(struct Scope scope, int64_t offset) { - const char *networkKey = (scope.network ? Keys[Network].name : NULL); - const char *contextKey = (scope.context ? Keys[Context].name : NULL); +static char *offsetURL( + const char *network, const char *context, const char *query, int64_t offset +) { char *url = khttp_urlpartx( NULL, NULL, Pages[Search], - Keys[Query].name, KATTRX_STRING, scope.query, + Keys[Query].name, KATTRX_STRING, query, Keys[Offset].name, KATTRX_INT, offset, - networkKey, KATTRX_STRING, scope.network, - contextKey, KATTRX_STRING, scope.context, + (network ? Keys[Network].name : NULL), KATTRX_STRING, network, + (context ? Keys[Context].name : NULL), KATTRX_STRING, context, NULL ); if (!url) err(EX_OSERR, "khttp_urlpartx"); @@ -60,12 +60,15 @@ static char *offsetURL(struct Scope scope, int64_t offset) { } enum kcgi_err searchPage(struct kreq *req) { - struct Scope scope = pageScope(req); - if (!scope.query) return httpFail(req, KHTTP_400); - if (scope.context && !scope.network) return httpFail(req, KHTTP_400); - + if (!req->fieldmap[Query]) return httpFail(req, KHTTP_400); + const char *query = req->fieldmap[Query]->parsed.s; + const char *network = NULL; + const char *context = NULL; int64_t offset = 0; + if (req->fieldmap[Network]) network = req->fieldmap[Network]->parsed.s; + if (req->fieldmap[Context]) context = req->fieldmap[Context]->parsed.s; if (req->fieldmap[Offset]) offset = req->fieldmap[Offset]->parsed.i; + if (context && !network) return httpFail(req, KHTTP_400); enum kcgi_err error = 0 || httpHead(req, KHTTP_200, KMIME_TEXT_HTML) @@ -75,14 +78,14 @@ enum kcgi_err searchPage(struct kreq *req) { struct khtmlreq html; error = error || khtml_open(&html, req, 0) - || htmlHead(&html, scope.query) - || htmlNav(&html, scope) + || htmlHead(&html, query) + || htmlNav(&html, req) || khtml_elem(&html, KELEM_TABLE); if (error) return error; if (offset) { int64_t prev = offset - eventsLimit; - char *href = offsetURL(scope, (prev > 0 ? prev : 0)); + char *href = offsetURL(network, context, query, (prev > 0 ? prev : 0)); error = 0 || khtml_attr(&html, KELEM_TR, KATTR_CLASS, "page", KATTR__MAX) || khtml_attr(&html, KELEM_TH, KATTR_COLSPAN, "5", KATTR__MAX) @@ -95,9 +98,9 @@ enum kcgi_err searchPage(struct kreq *req) { sqlite3_reset(stmt.search); dbBindText(stmt.search, ":highlight", "\26"); - dbBindText(stmt.search, ":network", scope.network); - dbBindText(stmt.search, ":context", scope.context); - dbBindText(stmt.search, ":query", scope.query); + dbBindText(stmt.search, ":network", network); + dbBindText(stmt.search, ":context", context); + dbBindText(stmt.search, ":query", query); dbBindInt(stmt.search, ":public", contextsPublic); dbBindInt(stmt.search, ":limit", eventsLimit); dbBindInt(stmt.search, ":offset", offset); @@ -117,7 +120,7 @@ enum kcgi_err searchPage(struct kreq *req) { event.host = sqlite3_column_text(stmt.search, i++); event.target = sqlite3_column_text(stmt.search, i++); event.message = sqlite3_column_text(stmt.search, i++); - error = htmlEvent(&html, scope, event); + error = htmlEvent(&html, req, &event); if (error) return error; } if (result != SQLITE_DONE) { @@ -130,7 +133,7 @@ enum kcgi_err searchPage(struct kreq *req) { } if (rows == eventsLimit) { - char *href = offsetURL(scope, offset + eventsLimit); + char *href = offsetURL(network, context, query, offset + eventsLimit); error = 0 || khtml_attr(&html, KELEM_TR, KATTR_CLASS, "page", KATTR__MAX) || khtml_attr(&html, KELEM_TH, KATTR_COLSPAN, "5", KATTR__MAX) -- cgit 1.4.1 mand lineJune McEnroe 2018-02-06Add gfxx controls for custom bitsJune McEnroe 2018-02-06Add gfxx palette loading and dumpingJune McEnroe 2018-02-06Add tags targetJune McEnroe 2018-02-06Replace gfxx SCALE macro with interp functionJune McEnroe 2018-02-05Rename gfxx space indexed and add palette samplingJune McEnroe 2018-02-05Take scale into account for when to stop drawing in gfxxJune McEnroe 2018-02-05Always skip most significant bits in gfxxJune McEnroe 2018-02-05Set title in gfcocoaJune McEnroe 2018-02-05Double-buffer gfb frontendJune McEnroe 2018-02-05Rewrite gfxx bit handlingJune McEnroe 2018-02-05Add flip option to gfxxJune McEnroe 2018-02-05Remove gfxx reverse optionJune McEnroe 2018-02-04Fix gfxx draw stop conditionJune McEnroe 2018-02-04Reuse CGColorSpace and CGDataProvider in gfcocoaJune McEnroe 2018-02-04Mark mac target phonyJune McEnroe 2018-02-04Set up Makefile for gfxx-cocoa or gfxx-fbJune McEnroe 2018-02-04Avoid doing excessive work in gfxxJune McEnroe 2018-02-04Handle window resizing in gfcocoaJune McEnroe 2018-02-04Set cinoptionsJune McEnroe 2018-02-04Tweak colorscheme moreJune McEnroe 2018-02-04Color MatchParen DarkYellowJune McEnroe 2018-02-04Add palette sampling to gfxxJune McEnroe 2018-02-04Add 4-bit RGB to gfxxJune McEnroe 2018-02-04Add Quit menu item to gfcocoaJune McEnroe 2018-02-04Switch back to sane Objective-C styleJune McEnroe 2018-02-04Quit gfcocoa when window closesJune McEnroe 2018-02-03Apparently this is how people write Objective-CJune McEnroe