Mercurial > blahgd
changeset 934:12f5bd552a11
index: use 'm' directly from the query nvlist
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Thu, 07 Sep 2017 17:31:40 +0300 |
parents | 9488e4db46f9 |
children | 690246b04ebe |
files | index.c req.c req.h |
diffstat | 3 files changed, 24 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/index.c Thu Sep 07 17:21:07 2017 +0300 +++ b/index.c Thu Sep 07 17:31:40 2017 +0300 @@ -134,15 +134,29 @@ return 0; } -static int validate_arch_id(int arch) +static bool valid_arch_id(uint64_t arch) { - int y = arch / 100; - int m = arch % 100; + uint64_t y = arch / 100; + uint64_t m = arch % 100; return (m >= 1) && (m <= 12) && (y >= 1970) && (y < 2100); } -int blahg_archive(struct req *req, int m, int page) +static int get_arch_id(struct req *req) +{ + const int default_arch_id = 197001; + uint64_t tmp; + + if (nvl_lookup_int(req->scgi->request.query, "m", &tmp)) + return default_arch_id; + + if (!valid_arch_id(tmp)) + return default_arch_id; + + return tmp; +} + +int blahg_archive(struct req *req, int page) { static const char *months[12] = { "January", "February", "March", "April", "May", "June", @@ -151,9 +165,9 @@ }; char nicetitle[32]; + int m; - if (!validate_arch_id(m)) - m = 197001; + m = get_arch_id(req); snprintf(nicetitle, sizeof(nicetitle), "%d ยป %s", m / 100, months[(m % 100) - 1]);
--- a/req.c Thu Sep 07 17:21:07 2017 +0300 +++ b/req.c Thu Sep 07 17:31:40 2017 +0300 @@ -251,7 +251,6 @@ struct str *uri; args->page = PAGE_INDEX; - args->m = -1; args->admin = 0; args->comment = 0; args->cat = NULL; @@ -290,7 +289,7 @@ } else if (!strcmp(name, "paged")) { continue; } else if (!strcmp(name, "m")) { - iptr = &args->m; + continue; } else if (!strcmp(name, "cat")) { cptr = &args->cat; } else if (!strcmp(name, "tag")) { @@ -321,7 +320,7 @@ args->page = PAGE_TAG; else if (args->cat) args->page = PAGE_CATEGORY; - else if (args->m != -1) + else if (nvl_exists(query, "m")) args->page = PAGE_ARCHIVE; else if (nvl_exists(query, "p")) args->page = PAGE_STORY; @@ -423,8 +422,7 @@ case PAGE_STATIC: return blahg_static(req); case PAGE_ARCHIVE: - return blahg_archive(req, req->args.m, - get_page_number(req)); + return blahg_archive(req, get_page_number(req)); case PAGE_CATEGORY: return blahg_category(req, req->args.cat, get_page_number(req));
--- a/req.h Thu Sep 07 17:21:07 2017 +0300 +++ b/req.h Thu Sep 07 17:31:40 2017 +0300 @@ -44,7 +44,6 @@ struct qs { int page; - int m; int admin; int comment; const char *cat; @@ -77,7 +76,7 @@ extern int R404(struct req *req, char *tmpl); extern int R301(struct req *req, const char *url); -extern int blahg_archive(struct req *req, int m, int paged); +extern int blahg_archive(struct req *req, int paged); extern int blahg_category(struct req *req, const char *cat, int page); extern int blahg_tag(struct req *req, const char *tag, int paged); extern int blahg_comment(struct req *req);