commit de628c5

default  ·  2024-07-23 08:09:12 +0000 UTC
parent c061325
Use MD5_HEX_SIZE in more places.
3 files changed,  +12, -14
M data.c
M snac.h
M data.c
+8, -10
 1@@ -541,17 +541,15 @@ int index_in(const char *fn, const char *id)
 2 }
 3 
 4 
 5-int index_first(const char *fn, char *line, int size)
 6+int index_first(const char *fn, char md5[MD5_HEX_SIZE])
 7 /* reads the first entry of an index */
 8 {
 9     FILE *f;
10     int ret = 0;
11 
12     if ((f = fopen(fn, "r")) != NULL) {
13-        flock(fileno(f), LOCK_SH);
14-
15-        if (fgets(line, size, f) != NULL) {
16-            line[MD5_HEX_SIZE - 1] = '\0';
17+        if (fread(md5, MD5_HEX_SIZE, 1, f)) {
18+            md5[MD5_HEX_SIZE - 1] = '\0';
19             ret = 1;
20         }
21 
22@@ -958,13 +956,13 @@ xs_list *object_announces(const char *id)
23 }
24 
25 
26-int object_parent(const char *md5, char *buf, int size)
27+int object_parent(const char *md5, char parent[MD5_HEX_SIZE])
28 /* returns the object parent, if any */
29 {
30     xs *fn = _object_fn_by_md5(md5, "object_parent");
31 
32     fn = xs_replace_i(fn, ".json", "_p.idx");
33-    return index_first(fn, buf, size);
34+    return index_first(fn, parent);
35 }
36 
37 
38@@ -1268,15 +1266,15 @@ xs_list *timeline_top_level(snac *snac, const xs_list *list)
39 
40     int c = 0;
41     while (xs_list_next(list, &v, &c)) {
42-        char line[256] = "";
43+        char line[MD5_HEX_SIZE] = "";
44 
45         strncpy(line, v, sizeof(line));
46 
47         for (;;) {
48-            char line2[256];
49+            char line2[MD5_HEX_SIZE];
50 
51             /* if it doesn't have a parent, use this */
52-            if (!object_parent(line, line2, sizeof(line2)))
53+            if (!object_parent(line, line2))
54                 break;
55 
56             /* well, there is a parent... but is it here? */
+2, -2
 1@@ -2186,12 +2186,12 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2                         xs *des = xs_list_new();
 3                         xs_list *p;
 4                         const xs_str *v;
 5-                        char pid[64];
 6+                        char pid[MD5_HEX_SIZE];
 7 
 8                         /* build the [grand]parent list, moving up */
 9                         strncpy(pid, id, sizeof(pid));
10 
11-                        while (object_parent(pid, pid, sizeof(pid))) {
12+                        while (object_parent(pid, pid)) {
13                             xs *m2 = NULL;
14 
15                             if (valid_status(timeline_get_by_md5(&snac1, pid, &m2))) {
M snac.h
+2, -2
 1@@ -100,7 +100,7 @@ double f_ctime(const char *fn);
 2 int index_add_md5(const char *fn, const char *md5);
 3 int index_add(const char *fn, const char *id);
 4 int index_gc(const char *fn);
 5-int index_first(const char *fn, char *buf, int size);
 6+int index_first(const char *fn, char md5[MD5_HEX_SIZE]);
 7 int index_len(const char *fn);
 8 xs_list *index_list(const char *fn, int max);
 9 int index_desc_next(FILE *f, char md5[MD5_HEX_SIZE]);
10@@ -130,7 +130,7 @@ int object_announces_len(const char *id);
11 xs_list *object_children(const char *id);
12 xs_list *object_likes(const char *id);
13 xs_list *object_announces(const char *id);
14-int object_parent(const char *id, char *buf, int size);
15+int object_parent(const char *md5, char parent[MD5_HEX_SIZE]);
16 
17 int object_user_cache_add(snac *snac, const char *id, const char *cachedir);
18 int object_user_cache_del(snac *snac, const char *id, const char *cachedir);