diff options
| author | 2023-08-19 09:31:13 +0200 | |
|---|---|---|
| committer | 2023-08-19 09:31:13 +0200 | |
| commit | 5de1a9ce0cbdda0ded72a51660130327636eb699 (patch) | |
| tree | 59265f2e9dc5fb8abb43e45a8a23ef3f5dfeaa4e | |
| parent | Be more strict when serving note objects. (diff) | |
| download | snac2-5de1a9ce0cbdda0ded72a51660130327636eb699.tar.gz snac2-5de1a9ce0cbdda0ded72a51660130327636eb699.tar.xz snac2-5de1a9ce0cbdda0ded72a51660130327636eb699.zip | |
Rewritten history_get() prototype to match static_get().
| -rw-r--r-- | data.c | 13 | ||||
| -rw-r--r-- | html.c | 13 | ||||
| -rw-r--r-- | snac.h | 3 |
3 files changed, 14 insertions, 15 deletions
| @@ -1681,18 +1681,23 @@ void history_add(snac *snac, const char *id, const char *content, int size) | |||
| 1681 | } | 1681 | } |
| 1682 | 1682 | ||
| 1683 | 1683 | ||
| 1684 | xs_str *history_get(snac *snac, const char *id) | 1684 | int 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 | ||
| @@ -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 |
| @@ -150,7 +150,8 @@ xs_str *static_get_meta(snac *snac, const char *id); | |||
| 150 | 150 | ||
| 151 | double history_mtime(snac *snac, const char *id); | 151 | double history_mtime(snac *snac, const char *id); |
| 152 | void history_add(snac *snac, const char *id, const char *content, int size); | 152 | void history_add(snac *snac, const char *id, const char *content, int size); |
| 153 | xs_str *history_get(snac *snac, const char *id); | 153 | int history_get(snac *snac, const char *id, xs_str **content, int *size, |
| 154 | const char *inm, xs_str **etag); | ||
| 154 | int history_del(snac *snac, const char *id); | 155 | int history_del(snac *snac, const char *id); |
| 155 | xs_list *history_list(snac *snac); | 156 | xs_list *history_list(snac *snac); |
| 156 | 157 | ||