diff options
| author | 2024-07-23 10:09:12 +0200 | |
|---|---|---|
| committer | 2024-07-23 10:09:12 +0200 | |
| commit | de628c5f33fa7989a14a3748a713d73e1ea6ff23 (patch) | |
| tree | 2f016f98682cf90fa02f10675dfbb19d6b9a70d3 | |
| parent | New constant MD5_HEX_SIZE. (diff) | |
| download | snac2-de628c5f33fa7989a14a3748a713d73e1ea6ff23.tar.gz snac2-de628c5f33fa7989a14a3748a713d73e1ea6ff23.tar.xz snac2-de628c5f33fa7989a14a3748a713d73e1ea6ff23.zip | |
Use MD5_HEX_SIZE in more places.
| -rw-r--r-- | data.c | 18 | ||||
| -rw-r--r-- | mastoapi.c | 4 | ||||
| -rw-r--r-- | snac.h | 4 |
3 files changed, 12 insertions, 14 deletions
| @@ -541,17 +541,15 @@ int index_in(const char *fn, const char *id) | |||
| 541 | } | 541 | } |
| 542 | 542 | ||
| 543 | 543 | ||
| 544 | int index_first(const char *fn, char *line, int size) | 544 | int 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 | ||
| 961 | int object_parent(const char *md5, char *buf, int size) | 959 | int 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? */ |
| @@ -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))) { |
| @@ -100,7 +100,7 @@ double f_ctime(const char *fn); | |||
| 100 | int index_add_md5(const char *fn, const char *md5); | 100 | int index_add_md5(const char *fn, const char *md5); |
| 101 | int index_add(const char *fn, const char *id); | 101 | int index_add(const char *fn, const char *id); |
| 102 | int index_gc(const char *fn); | 102 | int index_gc(const char *fn); |
| 103 | int index_first(const char *fn, char *buf, int size); | 103 | int index_first(const char *fn, char md5[MD5_HEX_SIZE]); |
| 104 | int index_len(const char *fn); | 104 | int index_len(const char *fn); |
| 105 | xs_list *index_list(const char *fn, int max); | 105 | xs_list *index_list(const char *fn, int max); |
| 106 | int index_desc_next(FILE *f, char md5[MD5_HEX_SIZE]); | 106 | int index_desc_next(FILE *f, char md5[MD5_HEX_SIZE]); |
| @@ -130,7 +130,7 @@ int object_announces_len(const char *id); | |||
| 130 | xs_list *object_children(const char *id); | 130 | xs_list *object_children(const char *id); |
| 131 | xs_list *object_likes(const char *id); | 131 | xs_list *object_likes(const char *id); |
| 132 | xs_list *object_announces(const char *id); | 132 | xs_list *object_announces(const char *id); |
| 133 | int object_parent(const char *id, char *buf, int size); | 133 | int object_parent(const char *md5, char parent[MD5_HEX_SIZE]); |
| 134 | 134 | ||
| 135 | int object_user_cache_add(snac *snac, const char *id, const char *cachedir); | 135 | int object_user_cache_add(snac *snac, const char *id, const char *cachedir); |
| 136 | int object_user_cache_del(snac *snac, const char *id, const char *cachedir); | 136 | int object_user_cache_del(snac *snac, const char *id, const char *cachedir); |