diff options
| author | 2023-08-19 09:59:58 +0200 | |
|---|---|---|
| committer | 2023-08-19 09:59:58 +0200 | |
| commit | dae2e406d633ba32f2660100ef417ec13726765c (patch) | |
| tree | f0fc2ee7f826907665ff883cd205d1f355030a2c | |
| parent | static_get() and history_get() both share the same code. (diff) | |
| download | snac2-dae2e406d633ba32f2660100ef417ec13726765c.tar.gz snac2-dae2e406d633ba32f2660100ef417ec13726765c.tar.xz snac2-dae2e406d633ba32f2660100ef417ec13726765c.zip | |
history_add() now creates an etag.
| -rw-r--r-- | data.c | 8 | ||||
| -rw-r--r-- | html.c | 4 | ||||
| -rw-r--r-- | snac.h | 3 |
3 files changed, 11 insertions, 4 deletions
| @@ -1677,7 +1677,8 @@ double history_mtime(snac *snac, const char *id) | |||
| 1677 | } | 1677 | } |
| 1678 | 1678 | ||
| 1679 | 1679 | ||
| 1680 | void history_add(snac *snac, const char *id, const char *content, int size) | 1680 | void history_add(snac *snac, const char *id, const char *content, int size, |
| 1681 | xs_str **etag) | ||
| 1681 | /* adds something to the history */ | 1682 | /* adds something to the history */ |
| 1682 | { | 1683 | { |
| 1683 | xs *fn = _history_fn(snac, id); | 1684 | xs *fn = _history_fn(snac, id); |
| @@ -1686,6 +1687,11 @@ void history_add(snac *snac, const char *id, const char *content, int size) | |||
| 1686 | if (fn && (f = fopen(fn, "w")) != NULL) { | 1687 | if (fn && (f = fopen(fn, "w")) != NULL) { |
| 1687 | fwrite(content, size, 1, f); | 1688 | fwrite(content, size, 1, f); |
| 1688 | fclose(f); | 1689 | fclose(f); |
| 1690 | |||
| 1691 | if (etag) { | ||
| 1692 | double tm = mtime(fn); | ||
| 1693 | *etag = xs_fmt("W/\"snac-%.0lf\"", tm); | ||
| 1694 | } | ||
| 1689 | } | 1695 | } |
| 1690 | } | 1696 | } |
| 1691 | 1697 | ||
| @@ -1891,7 +1891,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 1891 | status = 200; | 1891 | status = 200; |
| 1892 | 1892 | ||
| 1893 | if (save) | 1893 | if (save) |
| 1894 | history_add(&snac, h, *body, *b_size); | 1894 | history_add(&snac, h, *body, *b_size, etag); |
| 1895 | } | 1895 | } |
| 1896 | } | 1896 | } |
| 1897 | else | 1897 | else |
| @@ -1922,7 +1922,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 1922 | status = 200; | 1922 | status = 200; |
| 1923 | 1923 | ||
| 1924 | if (save) | 1924 | if (save) |
| 1925 | history_add(&snac, "timeline.html_", *body, *b_size); | 1925 | history_add(&snac, "timeline.html_", *body, *b_size, etag); |
| 1926 | } | 1926 | } |
| 1927 | } | 1927 | } |
| 1928 | } | 1928 | } |
| @@ -149,7 +149,8 @@ void static_put_meta(snac *snac, const char *id, const char *str); | |||
| 149 | xs_str *static_get_meta(snac *snac, const char *id); | 149 | 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 **etag); | ||
| 153 | int history_get(snac *snac, const char *id, xs_str **content, int *size, | 154 | int history_get(snac *snac, const char *id, xs_str **content, int *size, |
| 154 | const char *inm, xs_str **etag); | 155 | const char *inm, xs_str **etag); |
| 155 | int history_del(snac *snac, const char *id); | 156 | int history_del(snac *snac, const char *id); |