commit 5de1a9c
default
·
2023-08-19 07:31:13 +0000 UTC
parent 46cfc37
Rewritten history_get() prototype to match static_get().
M
data.c
+9,
-4
1@@ -1681,18 +1681,23 @@ void history_add(snac *snac, const char *id, const char *content, int size)
2 }
3
4
5-xs_str *history_get(snac *snac, const char *id)
6+int history_get(snac *snac, const char *id, xs_str **content, int *size,
7+ const char *inm, xs_str **etag)
8 {
9- xs_str *content = NULL;
10 xs *fn = _history_fn(snac, id);
11 FILE *f;
12+ int status = 404;
13
14 if (fn && (f = fopen(fn, "r")) != NULL) {
15- content = xs_readall(f);
16+ *content = xs_readall(f);
17 fclose(f);
18+
19+ *size = strlen(*content);
20+
21+ status = 200;
22 }
23
24- return content;
25+ return status;
26 }
27
28
M
html.c
+3,
-10
1@@ -1875,9 +1875,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
2 if (cache && history_mtime(&snac, h) > timeline_mtime(&snac)) {
3 snac_debug(&snac, 1, xs_fmt("serving cached local timeline"));
4
5- *body = history_get(&snac, h);
6- *b_size = strlen(*body);
7- status = 200;
8+ status = history_get(&snac, h, body, b_size, NULL, NULL);
9 }
10 else {
11 xs *list = timeline_list(&snac, "public", skip, show);
12@@ -1905,9 +1903,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
13 if (cache && history_mtime(&snac, "timeline.html_") > timeline_mtime(&snac)) {
14 snac_debug(&snac, 1, xs_fmt("serving cached timeline"));
15
16- *body = history_get(&snac, "timeline.html_");
17- *b_size = strlen(*body);
18- status = 200;
19+ status = history_get(&snac, "timeline.html_", body, b_size, NULL, NULL);
20 }
21 else {
22 snac_debug(&snac, 1, xs_fmt("building timeline"));
23@@ -1996,10 +1992,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
24 status = 404;
25 }
26 else
27- if ((*body = history_get(&snac, id)) != NULL) {
28- *b_size = strlen(*body);
29- status = 200;
30- }
31+ status = history_get(&snac, id, body, b_size, NULL, NULL);
32 }
33 }
34 else
M
snac.h
+2,
-1
1@@ -150,7 +150,8 @@ xs_str *static_get_meta(snac *snac, const char *id);
2
3 double history_mtime(snac *snac, const char *id);
4 void history_add(snac *snac, const char *id, const char *content, int size);
5-xs_str *history_get(snac *snac, const char *id);
6+int history_get(snac *snac, const char *id, xs_str **content, int *size,
7+ const char *inm, xs_str **etag);
8 int history_del(snac *snac, const char *id);
9 xs_list *history_list(snac *snac);
10