commit 15f7559
default
·
2023-08-05 12:56:07 +0000 UTC
parent 381a2f5
Added xs_json_load() wherever possible.
2 files changed,
+21,
-41
M
data.c
M
data.c
+19,
-36
1@@ -595,13 +595,9 @@ int object_get_by_md5(const char *md5, xs_dict **obj)
2 FILE *f;
3
4 if ((f = fopen(fn, "r")) != NULL) {
5- flock(fileno(f), LOCK_SH);
6-
7- xs *j = xs_readall(f);
8+ *obj = xs_json_load(f);
9 fclose(f);
10
11- *obj = xs_json_loads(j);
12-
13 if (*obj)
14 status = 200;
15 }
16@@ -1012,12 +1008,10 @@ int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg)
17 xs *fn = timeline_fn_by_md5(snac, md5);
18
19 if (fn != NULL && (f = fopen(fn, "r")) != NULL) {
20- flock(fileno(f), LOCK_SH);
21-
22- xs *j = xs_readall(f);
23+ *msg = xs_json_load(f);
24 fclose(f);
25
26- if ((*msg = xs_json_loads(j)) != NULL)
27+ if (*msg != NULL)
28 status = 200;
29 }
30
31@@ -1234,11 +1228,8 @@ int following_get(snac *snac, const char *actor, xs_dict **data)
32 int status = 200;
33
34 if ((f = fopen(fn, "r")) != NULL) {
35- xs *j = xs_readall(f);
36-
37+ *data = xs_json_load(f);
38 fclose(f);
39-
40- *data = xs_json_loads(j);
41 }
42 else
43 status = 404;
44@@ -1263,29 +1254,25 @@ xs_list *following_list(snac *snac)
45
46 /* load the follower data */
47 if ((f = fopen(v, "r")) != NULL) {
48- xs *j = xs_readall(f);
49+ xs *o = xs_json_load(f);
50 fclose(f);
51
52- if (j != NULL) {
53- xs *o = xs_json_loads(j);
54-
55- if (o != NULL) {
56- const char *type = xs_dict_get(o, "type");
57+ if (o != NULL) {
58+ const char *type = xs_dict_get(o, "type");
59
60- if (!xs_is_null(type) && strcmp(type, "Accept") == 0) {
61- const char *actor = xs_dict_get(o, "actor");
62+ if (!xs_is_null(type) && strcmp(type, "Accept") == 0) {
63+ const char *actor = xs_dict_get(o, "actor");
64
65- if (!xs_is_null(actor)) {
66- list = xs_list_append(list, actor);
67+ if (!xs_is_null(actor)) {
68+ list = xs_list_append(list, actor);
69
70- /* check if there is a link to the actor object */
71- xs *v2 = xs_replace(v, ".json", "_a.json");
72+ /* check if there is a link to the actor object */
73+ xs *v2 = xs_replace(v, ".json", "_a.json");
74
75- if (mtime(v2) == 0.0) {
76- /* no; add a link to it */
77- xs *actor_fn = _object_fn(actor);
78- link(actor_fn, v2);
79- }
80+ if (mtime(v2) == 0.0) {
81+ /* no; add a link to it */
82+ xs *actor_fn = _object_fn(actor);
83+ link(actor_fn, v2);
84 }
85 }
86 }
87@@ -1896,10 +1883,8 @@ xs_dict *notify_get(snac *snac, const char *id)
88 xs_dict *out = NULL;
89
90 if ((f = fopen(fn, "r")) != NULL) {
91- xs *j = xs_readall(f);
92+ out = xs_json_load(f);
93 fclose(f);
94-
95- out = xs_json_loads(j);
96 }
97
98 return out;
99@@ -2231,9 +2216,7 @@ xs_dict *queue_get(const char *fn)
100 xs_dict *obj = NULL;
101
102 if ((f = fopen(fn, "r")) != NULL) {
103- xs *j = xs_readall(f);
104- obj = xs_json_loads(j);
105-
106+ obj = xs_json_load(f);
107 fclose(f);
108 }
109
+2,
-5
1@@ -66,10 +66,9 @@ xs_dict *app_get(const char *id)
2 FILE *f;
3
4 if ((f = fopen(fn, "r")) != NULL) {
5- xs *j = xs_readall(f);
6+ app = xs_json_load(f);
7 fclose(f);
8
9- app = xs_json_loads(j);
10 }
11
12 return app;
13@@ -124,10 +123,8 @@ xs_dict *token_get(const char *id)
14 FILE *f;
15
16 if ((f = fopen(fn, "r")) != NULL) {
17- xs *j = xs_readall(f);
18+ token = xs_json_load(f);
19 fclose(f);
20-
21- token = xs_json_loads(j);
22 }
23
24 return token;