diff options
| author | 2023-08-05 14:56:07 +0200 | |
|---|---|---|
| committer | 2023-08-05 14:56:07 +0200 | |
| commit | 15f755960b0b870f5d35105393c65c16d5633e58 (patch) | |
| tree | 23b11455ce6e75b347052c698183194f4ccfa4de | |
| parent | Use xs_json_load() in some places. (diff) | |
| download | penes-snac2-15f755960b0b870f5d35105393c65c16d5633e58.tar.gz penes-snac2-15f755960b0b870f5d35105393c65c16d5633e58.tar.xz penes-snac2-15f755960b0b870f5d35105393c65c16d5633e58.zip | |
Added xs_json_load() wherever possible.
| -rw-r--r-- | data.c | 55 | ||||
| -rw-r--r-- | mastoapi.c | 7 |
2 files changed, 21 insertions, 41 deletions
| @@ -595,13 +595,9 @@ int object_get_by_md5(const char *md5, xs_dict **obj) | |||
| 595 | FILE *f; | 595 | FILE *f; |
| 596 | 596 | ||
| 597 | if ((f = fopen(fn, "r")) != NULL) { | 597 | if ((f = fopen(fn, "r")) != NULL) { |
| 598 | flock(fileno(f), LOCK_SH); | 598 | *obj = xs_json_load(f); |
| 599 | |||
| 600 | xs *j = xs_readall(f); | ||
| 601 | fclose(f); | 599 | fclose(f); |
| 602 | 600 | ||
| 603 | *obj = xs_json_loads(j); | ||
| 604 | |||
| 605 | if (*obj) | 601 | if (*obj) |
| 606 | status = 200; | 602 | status = 200; |
| 607 | } | 603 | } |
| @@ -1012,12 +1008,10 @@ int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg) | |||
| 1012 | xs *fn = timeline_fn_by_md5(snac, md5); | 1008 | xs *fn = timeline_fn_by_md5(snac, md5); |
| 1013 | 1009 | ||
| 1014 | if (fn != NULL && (f = fopen(fn, "r")) != NULL) { | 1010 | if (fn != NULL && (f = fopen(fn, "r")) != NULL) { |
| 1015 | flock(fileno(f), LOCK_SH); | 1011 | *msg = xs_json_load(f); |
| 1016 | |||
| 1017 | xs *j = xs_readall(f); | ||
| 1018 | fclose(f); | 1012 | fclose(f); |
| 1019 | 1013 | ||
| 1020 | if ((*msg = xs_json_loads(j)) != NULL) | 1014 | if (*msg != NULL) |
| 1021 | status = 200; | 1015 | status = 200; |
| 1022 | } | 1016 | } |
| 1023 | 1017 | ||
| @@ -1234,11 +1228,8 @@ int following_get(snac *snac, const char *actor, xs_dict **data) | |||
| 1234 | int status = 200; | 1228 | int status = 200; |
| 1235 | 1229 | ||
| 1236 | if ((f = fopen(fn, "r")) != NULL) { | 1230 | if ((f = fopen(fn, "r")) != NULL) { |
| 1237 | xs *j = xs_readall(f); | 1231 | *data = xs_json_load(f); |
| 1238 | |||
| 1239 | fclose(f); | 1232 | fclose(f); |
| 1240 | |||
| 1241 | *data = xs_json_loads(j); | ||
| 1242 | } | 1233 | } |
| 1243 | else | 1234 | else |
| 1244 | status = 404; | 1235 | status = 404; |
| @@ -1263,29 +1254,25 @@ xs_list *following_list(snac *snac) | |||
| 1263 | 1254 | ||
| 1264 | /* load the follower data */ | 1255 | /* load the follower data */ |
| 1265 | if ((f = fopen(v, "r")) != NULL) { | 1256 | if ((f = fopen(v, "r")) != NULL) { |
| 1266 | xs *j = xs_readall(f); | 1257 | xs *o = xs_json_load(f); |
| 1267 | fclose(f); | 1258 | fclose(f); |
| 1268 | 1259 | ||
| 1269 | if (j != NULL) { | 1260 | if (o != NULL) { |
| 1270 | xs *o = xs_json_loads(j); | 1261 | const char *type = xs_dict_get(o, "type"); |
| 1271 | |||
| 1272 | if (o != NULL) { | ||
| 1273 | const char *type = xs_dict_get(o, "type"); | ||
| 1274 | 1262 | ||
| 1275 | if (!xs_is_null(type) && strcmp(type, "Accept") == 0) { | 1263 | if (!xs_is_null(type) && strcmp(type, "Accept") == 0) { |
| 1276 | const char *actor = xs_dict_get(o, "actor"); | 1264 | const char *actor = xs_dict_get(o, "actor"); |
| 1277 | 1265 | ||
| 1278 | if (!xs_is_null(actor)) { | 1266 | if (!xs_is_null(actor)) { |
| 1279 | list = xs_list_append(list, actor); | 1267 | list = xs_list_append(list, actor); |
| 1280 | 1268 | ||
| 1281 | /* check if there is a link to the actor object */ | 1269 | /* check if there is a link to the actor object */ |
| 1282 | xs *v2 = xs_replace(v, ".json", "_a.json"); | 1270 | xs *v2 = xs_replace(v, ".json", "_a.json"); |
| 1283 | 1271 | ||
| 1284 | if (mtime(v2) == 0.0) { | 1272 | if (mtime(v2) == 0.0) { |
| 1285 | /* no; add a link to it */ | 1273 | /* no; add a link to it */ |
| 1286 | xs *actor_fn = _object_fn(actor); | 1274 | xs *actor_fn = _object_fn(actor); |
| 1287 | link(actor_fn, v2); | 1275 | link(actor_fn, v2); |
| 1288 | } | ||
| 1289 | } | 1276 | } |
| 1290 | } | 1277 | } |
| 1291 | } | 1278 | } |
| @@ -1896,10 +1883,8 @@ xs_dict *notify_get(snac *snac, const char *id) | |||
| 1896 | xs_dict *out = NULL; | 1883 | xs_dict *out = NULL; |
| 1897 | 1884 | ||
| 1898 | if ((f = fopen(fn, "r")) != NULL) { | 1885 | if ((f = fopen(fn, "r")) != NULL) { |
| 1899 | xs *j = xs_readall(f); | 1886 | out = xs_json_load(f); |
| 1900 | fclose(f); | 1887 | fclose(f); |
| 1901 | |||
| 1902 | out = xs_json_loads(j); | ||
| 1903 | } | 1888 | } |
| 1904 | 1889 | ||
| 1905 | return out; | 1890 | return out; |
| @@ -2231,9 +2216,7 @@ xs_dict *queue_get(const char *fn) | |||
| 2231 | xs_dict *obj = NULL; | 2216 | xs_dict *obj = NULL; |
| 2232 | 2217 | ||
| 2233 | if ((f = fopen(fn, "r")) != NULL) { | 2218 | if ((f = fopen(fn, "r")) != NULL) { |
| 2234 | xs *j = xs_readall(f); | 2219 | obj = xs_json_load(f); |
| 2235 | obj = xs_json_loads(j); | ||
| 2236 | |||
| 2237 | fclose(f); | 2220 | fclose(f); |
| 2238 | } | 2221 | } |
| 2239 | 2222 | ||
| @@ -66,10 +66,9 @@ xs_dict *app_get(const char *id) | |||
| 66 | FILE *f; | 66 | FILE *f; |
| 67 | 67 | ||
| 68 | if ((f = fopen(fn, "r")) != NULL) { | 68 | if ((f = fopen(fn, "r")) != NULL) { |
| 69 | xs *j = xs_readall(f); | 69 | app = xs_json_load(f); |
| 70 | fclose(f); | 70 | fclose(f); |
| 71 | 71 | ||
| 72 | app = xs_json_loads(j); | ||
| 73 | } | 72 | } |
| 74 | 73 | ||
| 75 | return app; | 74 | return app; |
| @@ -124,10 +123,8 @@ xs_dict *token_get(const char *id) | |||
| 124 | FILE *f; | 123 | FILE *f; |
| 125 | 124 | ||
| 126 | if ((f = fopen(fn, "r")) != NULL) { | 125 | if ((f = fopen(fn, "r")) != NULL) { |
| 127 | xs *j = xs_readall(f); | 126 | token = xs_json_load(f); |
| 128 | fclose(f); | 127 | fclose(f); |
| 129 | |||
| 130 | token = xs_json_loads(j); | ||
| 131 | } | 128 | } |
| 132 | 129 | ||
| 133 | return token; | 130 | return token; |