Added xs_json_load() wherever possible.

This commit is contained in:
default 2023-08-05 14:56:07 +02:00
parent 381a2f5b7b
commit 15f755960b
2 changed files with 21 additions and 41 deletions

31
data.c
View File

@ -595,13 +595,9 @@ int object_get_by_md5(const char *md5, xs_dict **obj)
FILE *f;
if ((f = fopen(fn, "r")) != NULL) {
flock(fileno(f), LOCK_SH);
xs *j = xs_readall(f);
*obj = xs_json_load(f);
fclose(f);
*obj = xs_json_loads(j);
if (*obj)
status = 200;
}
@ -1012,12 +1008,10 @@ int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg)
xs *fn = timeline_fn_by_md5(snac, md5);
if (fn != NULL && (f = fopen(fn, "r")) != NULL) {
flock(fileno(f), LOCK_SH);
xs *j = xs_readall(f);
*msg = xs_json_load(f);
fclose(f);
if ((*msg = xs_json_loads(j)) != NULL)
if (*msg != NULL)
status = 200;
}
@ -1234,11 +1228,8 @@ int following_get(snac *snac, const char *actor, xs_dict **data)
int status = 200;
if ((f = fopen(fn, "r")) != NULL) {
xs *j = xs_readall(f);
*data = xs_json_load(f);
fclose(f);
*data = xs_json_loads(j);
}
else
status = 404;
@ -1263,12 +1254,9 @@ xs_list *following_list(snac *snac)
/* load the follower data */
if ((f = fopen(v, "r")) != NULL) {
xs *j = xs_readall(f);
xs *o = xs_json_load(f);
fclose(f);
if (j != NULL) {
xs *o = xs_json_loads(j);
if (o != NULL) {
const char *type = xs_dict_get(o, "type");
@ -1291,7 +1279,6 @@ xs_list *following_list(snac *snac)
}
}
}
}
return list;
}
@ -1896,10 +1883,8 @@ xs_dict *notify_get(snac *snac, const char *id)
xs_dict *out = NULL;
if ((f = fopen(fn, "r")) != NULL) {
xs *j = xs_readall(f);
out = xs_json_load(f);
fclose(f);
out = xs_json_loads(j);
}
return out;
@ -2231,9 +2216,7 @@ xs_dict *queue_get(const char *fn)
xs_dict *obj = NULL;
if ((f = fopen(fn, "r")) != NULL) {
xs *j = xs_readall(f);
obj = xs_json_loads(j);
obj = xs_json_load(f);
fclose(f);
}

View File

@ -66,10 +66,9 @@ xs_dict *app_get(const char *id)
FILE *f;
if ((f = fopen(fn, "r")) != NULL) {
xs *j = xs_readall(f);
app = xs_json_load(f);
fclose(f);
app = xs_json_loads(j);
}
return app;
@ -124,10 +123,8 @@ xs_dict *token_get(const char *id)
FILE *f;
if ((f = fopen(fn, "r")) != NULL) {
xs *j = xs_readall(f);
token = xs_json_load(f);
fclose(f);
token = xs_json_loads(j);
}
return token;