summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c13
-rw-r--r--html.c13
-rw-r--r--snac.h3
3 files changed, 14 insertions, 15 deletions
diff --git a/data.c b/data.c
index 4f0d42a..ecc227e 100644
--- a/data.c
+++ b/data.c
@@ -1681,18 +1681,23 @@ void history_add(snac *snac, const char *id, const char *content, int size)
1681} 1681}
1682 1682
1683 1683
1684xs_str *history_get(snac *snac, const char *id) 1684int history_get(snac *snac, const char *id, xs_str **content, int *size,
1685 const char *inm, xs_str **etag)
1685{ 1686{
1686 xs_str *content = NULL;
1687 xs *fn = _history_fn(snac, id); 1687 xs *fn = _history_fn(snac, id);
1688 FILE *f; 1688 FILE *f;
1689 int status = 404;
1689 1690
1690 if (fn && (f = fopen(fn, "r")) != NULL) { 1691 if (fn && (f = fopen(fn, "r")) != NULL) {
1691 content = xs_readall(f); 1692 *content = xs_readall(f);
1692 fclose(f); 1693 fclose(f);
1694
1695 *size = strlen(*content);
1696
1697 status = 200;
1693 } 1698 }
1694 1699
1695 return content; 1700 return status;
1696} 1701}
1697 1702
1698 1703
diff --git a/html.c b/html.c
index e132f17..19ab6b7 100644
--- a/html.c
+++ b/html.c
@@ -1875,9 +1875,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
1875 if (cache && history_mtime(&snac, h) > timeline_mtime(&snac)) { 1875 if (cache && history_mtime(&snac, h) > timeline_mtime(&snac)) {
1876 snac_debug(&snac, 1, xs_fmt("serving cached local timeline")); 1876 snac_debug(&snac, 1, xs_fmt("serving cached local timeline"));
1877 1877
1878 *body = history_get(&snac, h); 1878 status = history_get(&snac, h, body, b_size, NULL, NULL);
1879 *b_size = strlen(*body);
1880 status = 200;
1881 } 1879 }
1882 else { 1880 else {
1883 xs *list = timeline_list(&snac, "public", skip, show); 1881 xs *list = timeline_list(&snac, "public", skip, show);
@@ -1905,9 +1903,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
1905 if (cache && history_mtime(&snac, "timeline.html_") > timeline_mtime(&snac)) { 1903 if (cache && history_mtime(&snac, "timeline.html_") > timeline_mtime(&snac)) {
1906 snac_debug(&snac, 1, xs_fmt("serving cached timeline")); 1904 snac_debug(&snac, 1, xs_fmt("serving cached timeline"));
1907 1905
1908 *body = history_get(&snac, "timeline.html_"); 1906 status = history_get(&snac, "timeline.html_", body, b_size, NULL, NULL);
1909 *b_size = strlen(*body);
1910 status = 200;
1911 } 1907 }
1912 else { 1908 else {
1913 snac_debug(&snac, 1, xs_fmt("building timeline")); 1909 snac_debug(&snac, 1, xs_fmt("building timeline"));
@@ -1996,10 +1992,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
1996 status = 404; 1992 status = 404;
1997 } 1993 }
1998 else 1994 else
1999 if ((*body = history_get(&snac, id)) != NULL) { 1995 status = history_get(&snac, id, body, b_size, NULL, NULL);
2000 *b_size = strlen(*body);
2001 status = 200;
2002 }
2003 } 1996 }
2004 } 1997 }
2005 else 1998 else
diff --git a/snac.h b/snac.h
index 67b273e..8df5fb4 100644
--- a/snac.h
+++ b/snac.h
@@ -150,7 +150,8 @@ xs_str *static_get_meta(snac *snac, const char *id);
150 150
151double history_mtime(snac *snac, const char *id); 151double history_mtime(snac *snac, const char *id);
152void history_add(snac *snac, const char *id, const char *content, int size); 152void history_add(snac *snac, const char *id, const char *content, int size);
153xs_str *history_get(snac *snac, const char *id); 153int history_get(snac *snac, const char *id, xs_str **content, int *size,
154 const char *inm, xs_str **etag);
154int history_del(snac *snac, const char *id); 155int history_del(snac *snac, const char *id);
155xs_list *history_list(snac *snac); 156xs_list *history_list(snac *snac);
156 157