diff options
Diffstat (limited to 'search.c')
-rw-r--r-- | search.c | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/search.c b/search.c index 767081b..6fba589 100644 --- a/search.c +++ b/search.c @@ -46,20 +46,12 @@ const char *SearchQuery = SQL( ); enum kcgi_err pageSearch(struct kreq *req) { - if (!req->fieldmap[Query]) { - return httpFail(req, KHTTP_400); - } - if (req->fieldmap[Context] && !req->fieldmap[Network]) { - return httpFail(req, KHTTP_400); - } - const char *query = req->fieldmap[Query]->parsed.s; + struct Scope scope = htmlScope(req); + if (!scope.query) return httpFail(req, KHTTP_400); + if (scope.context && !scope.network) return httpFail(req, KHTTP_400); int64_t offset = 0; - const char *network = NULL; - const char *context = NULL; if (req->fieldmap[Offset]) offset = req->fieldmap[Offset]->parsed.i; - if (req->fieldmap[Network]) network = req->fieldmap[Network]->parsed.s; - if (req->fieldmap[Context]) context = req->fieldmap[Context]->parsed.s; enum kcgi_err error = httpHead(req, KHTTP_200, KMIME_TEXT_HTML); if (req->method == KMETHOD_HEAD) return error; @@ -68,16 +60,16 @@ enum kcgi_err pageSearch(struct kreq *req) { error = error || khttp_body(req) || khtml_open(&html, req, KHTML_PRETTY) - || htmlHead(&html, query) - || htmlNav(&html, network, context) + || htmlHead(&html, scope.query) + || htmlNav(&html, scope) || khtml_elem(&html, KELEM_TABLE); if (error) return error; dbBindText(stmt.search, ":highlight", "\26"); - dbBindText(stmt.search, ":network", network); - dbBindText(stmt.search, ":context", context); + dbBindText(stmt.search, ":network", scope.network); + dbBindText(stmt.search, ":context", scope.context); if (pagePublic) dbBindInt(stmt.search, ":query", false); - dbBindText(stmt.search, ":search", query); + dbBindText(stmt.search, ":search", scope.query); dbBindInt(stmt.search, ":limit", pageLimit); dbBindInt(stmt.search, ":offset", offset); @@ -95,7 +87,7 @@ enum kcgi_err pageSearch(struct kreq *req) { .target = (const char *)sqlite3_column_text(stmt.search, 8), .message = (const char *)sqlite3_column_text(stmt.search, 9), }; - error = htmlEvent(&html, event); + error = htmlEvent(&html, scope, event); if (error) break; } if (result != SQLITE_DONE) errx(EX_SOFTWARE, "%s", sqlite3_errmsg(db)); |