summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2024-07-23 10:09:12 +0200
committerGravatar default2024-07-23 10:09:12 +0200
commitde628c5f33fa7989a14a3748a713d73e1ea6ff23 (patch)
tree2f016f98682cf90fa02f10675dfbb19d6b9a70d3
parentNew constant MD5_HEX_SIZE. (diff)
downloadsnac2-de628c5f33fa7989a14a3748a713d73e1ea6ff23.tar.gz
snac2-de628c5f33fa7989a14a3748a713d73e1ea6ff23.tar.xz
snac2-de628c5f33fa7989a14a3748a713d73e1ea6ff23.zip
Use MD5_HEX_SIZE in more places.
-rw-r--r--data.c18
-rw-r--r--mastoapi.c4
-rw-r--r--snac.h4
3 files changed, 12 insertions, 14 deletions
diff --git a/data.c b/data.c
index fcfd917..121407f 100644
--- a/data.c
+++ b/data.c
@@ -541,17 +541,15 @@ int index_in(const char *fn, const char *id)
541} 541}
542 542
543 543
544int index_first(const char *fn, char *line, int size) 544int index_first(const char *fn, char md5[MD5_HEX_SIZE])
545/* reads the first entry of an index */ 545/* reads the first entry of an index */
546{ 546{
547 FILE *f; 547 FILE *f;
548 int ret = 0; 548 int ret = 0;
549 549
550 if ((f = fopen(fn, "r")) != NULL) { 550 if ((f = fopen(fn, "r")) != NULL) {
551 flock(fileno(f), LOCK_SH); 551 if (fread(md5, MD5_HEX_SIZE, 1, f)) {
552 552 md5[MD5_HEX_SIZE - 1] = '\0';
553 if (fgets(line, size, f) != NULL) {
554 line[MD5_HEX_SIZE - 1] = '\0';
555 ret = 1; 553 ret = 1;
556 } 554 }
557 555
@@ -958,13 +956,13 @@ xs_list *object_announces(const char *id)
958} 956}
959 957
960 958
961int object_parent(const char *md5, char *buf, int size) 959int object_parent(const char *md5, char parent[MD5_HEX_SIZE])
962/* returns the object parent, if any */ 960/* returns the object parent, if any */
963{ 961{
964 xs *fn = _object_fn_by_md5(md5, "object_parent"); 962 xs *fn = _object_fn_by_md5(md5, "object_parent");
965 963
966 fn = xs_replace_i(fn, ".json", "_p.idx"); 964 fn = xs_replace_i(fn, ".json", "_p.idx");
967 return index_first(fn, buf, size); 965 return index_first(fn, parent);
968} 966}
969 967
970 968
@@ -1268,15 +1266,15 @@ xs_list *timeline_top_level(snac *snac, const xs_list *list)
1268 1266
1269 int c = 0; 1267 int c = 0;
1270 while (xs_list_next(list, &v, &c)) { 1268 while (xs_list_next(list, &v, &c)) {
1271 char line[256] = ""; 1269 char line[MD5_HEX_SIZE] = "";
1272 1270
1273 strncpy(line, v, sizeof(line)); 1271 strncpy(line, v, sizeof(line));
1274 1272
1275 for (;;) { 1273 for (;;) {
1276 char line2[256]; 1274 char line2[MD5_HEX_SIZE];
1277 1275
1278 /* if it doesn't have a parent, use this */ 1276 /* if it doesn't have a parent, use this */
1279 if (!object_parent(line, line2, sizeof(line2))) 1277 if (!object_parent(line, line2))
1280 break; 1278 break;
1281 1279
1282 /* well, there is a parent... but is it here? */ 1280 /* well, there is a parent... but is it here? */
diff --git a/mastoapi.c b/mastoapi.c
index be477c3..8a6cbe6 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -2186,12 +2186,12 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2186 xs *des = xs_list_new(); 2186 xs *des = xs_list_new();
2187 xs_list *p; 2187 xs_list *p;
2188 const xs_str *v; 2188 const xs_str *v;
2189 char pid[64]; 2189 char pid[MD5_HEX_SIZE];
2190 2190
2191 /* build the [grand]parent list, moving up */ 2191 /* build the [grand]parent list, moving up */
2192 strncpy(pid, id, sizeof(pid)); 2192 strncpy(pid, id, sizeof(pid));
2193 2193
2194 while (object_parent(pid, pid, sizeof(pid))) { 2194 while (object_parent(pid, pid)) {
2195 xs *m2 = NULL; 2195 xs *m2 = NULL;
2196 2196
2197 if (valid_status(timeline_get_by_md5(&snac1, pid, &m2))) { 2197 if (valid_status(timeline_get_by_md5(&snac1, pid, &m2))) {
diff --git a/snac.h b/snac.h
index 78c39ef..280dc15 100644
--- a/snac.h
+++ b/snac.h
@@ -100,7 +100,7 @@ double f_ctime(const char *fn);
100int index_add_md5(const char *fn, const char *md5); 100int index_add_md5(const char *fn, const char *md5);
101int index_add(const char *fn, const char *id); 101int index_add(const char *fn, const char *id);
102int index_gc(const char *fn); 102int index_gc(const char *fn);
103int index_first(const char *fn, char *buf, int size); 103int index_first(const char *fn, char md5[MD5_HEX_SIZE]);
104int index_len(const char *fn); 104int index_len(const char *fn);
105xs_list *index_list(const char *fn, int max); 105xs_list *index_list(const char *fn, int max);
106int index_desc_next(FILE *f, char md5[MD5_HEX_SIZE]); 106int index_desc_next(FILE *f, char md5[MD5_HEX_SIZE]);
@@ -130,7 +130,7 @@ int object_announces_len(const char *id);
130xs_list *object_children(const char *id); 130xs_list *object_children(const char *id);
131xs_list *object_likes(const char *id); 131xs_list *object_likes(const char *id);
132xs_list *object_announces(const char *id); 132xs_list *object_announces(const char *id);
133int object_parent(const char *id, char *buf, int size); 133int object_parent(const char *md5, char parent[MD5_HEX_SIZE]);
134 134
135int object_user_cache_add(snac *snac, const char *id, const char *cachedir); 135int object_user_cache_add(snac *snac, const char *id, const char *cachedir);
136int object_user_cache_del(snac *snac, const char *id, const char *cachedir); 136int object_user_cache_del(snac *snac, const char *id, const char *cachedir);