summaryrefslogtreecommitdiff
path: root/handler.c
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-07-10 23:21:25 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-07-10 23:21:25 +0800
commit5d0a833af478b87f4fb815e37da0beb5a09c6067 (patch)
tree00a1e021aea50625d0c57ddeb4321af47a3c0641 /handler.c
parent873f8a55d01ecbd11c957d140eaf2a0bb30ae51f (diff)
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.
Diffstat (limited to 'handler.c')
-rw-r--r--handler.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/handler.c b/handler.c
index 8e118f7..1a0ce01 100644
--- a/handler.c
+++ b/handler.c
@@ -3,21 +3,24 @@
#include <tidybuffio.h>
#include <icclient.h>
-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;