summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-08-19 09:59:58 +0200
committerGravatar default2023-08-19 09:59:58 +0200
commitdae2e406d633ba32f2660100ef417ec13726765c (patch)
treef0fc2ee7f826907665ff883cd205d1f355030a2c
parentstatic_get() and history_get() both share the same code. (diff)
downloadsnac2-dae2e406d633ba32f2660100ef417ec13726765c.tar.gz
snac2-dae2e406d633ba32f2660100ef417ec13726765c.tar.xz
snac2-dae2e406d633ba32f2660100ef417ec13726765c.zip
history_add() now creates an etag.
-rw-r--r--data.c8
-rw-r--r--html.c4
-rw-r--r--snac.h3
3 files changed, 11 insertions, 4 deletions
diff --git a/data.c b/data.c
index 9c335be..bfe035e 100644
--- a/data.c
+++ b/data.c
@@ -1677,7 +1677,8 @@ double history_mtime(snac *snac, const char *id)
1677} 1677}
1678 1678
1679 1679
1680void history_add(snac *snac, const char *id, const char *content, int size) 1680void 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
diff --git a/html.c b/html.c
index 11c1918..2b690e9 100644
--- a/html.c
+++ b/html.c
@@ -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 }
diff --git a/snac.h b/snac.h
index 8df5fb4..547b8b0 100644
--- a/snac.h
+++ b/snac.h
@@ -149,7 +149,8 @@ void static_put_meta(snac *snac, const char *id, const char *str);
149xs_str *static_get_meta(snac *snac, const char *id); 149xs_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,
153 xs_str **etag);
153int history_get(snac *snac, const char *id, xs_str **content, int *size, 154int 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);
155int history_del(snac *snac, const char *id); 156int history_del(snac *snac, const char *id);