From 5d0a833af478b87f4fb815e37da0beb5a09c6067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Sat, 10 Jul 2021 23:21:25 +0800 Subject: Use the response data to initiate client It's correct now, but the problem is, the client pushes the catalog page faster than the web server can reload to make the newly built sample URL valid. --- handler.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'handler.c') diff --git a/handler.c b/handler.c index 8e118f7..1a0ce01 100644 --- a/handler.c +++ b/handler.c @@ -3,21 +3,24 @@ #include #include -static void recurse_catalog(TidyDoc doc, TidyNode tnod, struct icclient_catalog **catalog) +static void recurse_catalog(TidyDoc doc, TidyNode tnod, const char *image_dir, + struct icclient_catalog **catalog) { for (TidyNode child = tidyGetChild(tnod); child; child = tidyGetNext(child)) { ctmbstr name = tidyNodeGetName(child); if (!name) continue; if (strcmp(name, "img")) { - recurse_catalog(doc, child, catalog); + recurse_catalog(doc, child, image_dir, catalog); continue; } - static const char *prefix = IMAGE_DIR"/thumb/"; + static const char *subdir = "/thumb/"; + char prefix[strlen(image_dir) + strlen(subdir) + 1]; size_t prefix_len = strlen(prefix); bool bail = false; for (TidyAttr attr = tidyAttrFirst(child); attr; attr = tidyAttrNext(attr)) - if (!strcmp(tidyAttrName(attr), "src") && strncmp(tidyAttrValue(attr), prefix, prefix_len)) { + if (!strcmp(tidyAttrName(attr), "src") + && strncmp(tidyAttrValue(attr), prefix, prefix_len)) { bail = true; break; } @@ -47,7 +50,7 @@ static void recurse_catalog(TidyDoc doc, TidyNode tnod, struct icclient_catalog } } -struct icclient_catalog *catalog_data(const char *response) +struct icclient_catalog *catalog_data(const char *response, const char *image_dir) { TidyDoc tdoc = tidyCreate(); TidyBuffer output = {0}; @@ -55,7 +58,7 @@ struct icclient_catalog *catalog_data(const char *response) tidySaveBuffer(tdoc, &output); struct icclient_catalog *catalog = malloc(sizeof(struct icclient_catalog)); catalog->length = 0; - recurse_catalog(tdoc, tidyGetRoot(tdoc), &catalog); + recurse_catalog(tdoc, tidyGetRoot(tdoc), image_dir, &catalog); tidyBufFree(&output); tidyRelease(tdoc); return catalog; -- cgit v1.2.3