From 8c4850df5058a8ed758ded21876563d9c690bddd Mon Sep 17 00:00:00 2001 From: default Date: Sat, 22 Apr 2023 00:24:15 +0200 Subject: [PATCH] New functions to get and set metadata into static files. --- data.c | 33 +++++++++++++++++++++++++++++++++ snac.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/data.c b/data.c index d3605ef..4405b15 100644 --- a/data.c +++ b/data.c @@ -1366,6 +1366,39 @@ void static_put(snac *snac, const char *id, const char *data, int size) } +void status_put_meta(snac *snac, const char *id, const char *str) +/* puts metadata (i.e. a media description string) to id */ +{ + xs *fn = _static_fn(snac, id); + fn = xs_str_cat(fn, ".txt"); + FILE *f; + + if ((f = fopen(fn, "w")) != NULL) { + fprintf(f, "%s\n", str); + fclose(f); + } +} + + +xs_str *status_get_meta(snac *snac, const char *id) +/* gets metadata from a media */ +{ + xs *fn = _static_fn(snac, id); + fn = xs_str_cat(fn, ".txt"); + xs_str *r = NULL; + FILE *f; + + if ((f = fopen(fn, "r")) != NULL) { + r = xs_strip_i(xs_readline(f)); + fclose(f); + } + else + r = xs_str_new(""); + + return r; +} + + d_char *_history_fn(snac *snac, char *id) /* gets the filename for the history */ { diff --git a/snac.h b/snac.h index c46b85c..6258d6c 100644 --- a/snac.h +++ b/snac.h @@ -130,6 +130,8 @@ int actor_get(snac *snac, const char *actor, d_char **data); int static_get(snac *snac, const char *id, d_char **data, int *size); void static_put(snac *snac, const char *id, const char *data, int size); +void status_put_meta(snac *snac, const char *id, const char *str); +xs_str *status_get_meta(snac *snac, const char *id); double history_mtime(snac *snac, char *id); void history_add(snac *snac, char *id, char *content, int size);