mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 22:45:05 +00:00
Added xs_json_load() wherever possible.
This commit is contained in:
parent
381a2f5b7b
commit
15f755960b
2 changed files with 21 additions and 41 deletions
55
data.c
55
data.c
|
@ -595,13 +595,9 @@ int object_get_by_md5(const char *md5, xs_dict **obj)
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if ((f = fopen(fn, "r")) != NULL) {
|
if ((f = fopen(fn, "r")) != NULL) {
|
||||||
flock(fileno(f), LOCK_SH);
|
*obj = xs_json_load(f);
|
||||||
|
|
||||||
xs *j = xs_readall(f);
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
*obj = xs_json_loads(j);
|
|
||||||
|
|
||||||
if (*obj)
|
if (*obj)
|
||||||
status = 200;
|
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);
|
xs *fn = timeline_fn_by_md5(snac, md5);
|
||||||
|
|
||||||
if (fn != NULL && (f = fopen(fn, "r")) != NULL) {
|
if (fn != NULL && (f = fopen(fn, "r")) != NULL) {
|
||||||
flock(fileno(f), LOCK_SH);
|
*msg = xs_json_load(f);
|
||||||
|
|
||||||
xs *j = xs_readall(f);
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if ((*msg = xs_json_loads(j)) != NULL)
|
if (*msg != NULL)
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1234,11 +1228,8 @@ int following_get(snac *snac, const char *actor, xs_dict **data)
|
||||||
int status = 200;
|
int status = 200;
|
||||||
|
|
||||||
if ((f = fopen(fn, "r")) != NULL) {
|
if ((f = fopen(fn, "r")) != NULL) {
|
||||||
xs *j = xs_readall(f);
|
*data = xs_json_load(f);
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
*data = xs_json_loads(j);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status = 404;
|
status = 404;
|
||||||
|
@ -1263,29 +1254,25 @@ xs_list *following_list(snac *snac)
|
||||||
|
|
||||||
/* load the follower data */
|
/* load the follower data */
|
||||||
if ((f = fopen(v, "r")) != NULL) {
|
if ((f = fopen(v, "r")) != NULL) {
|
||||||
xs *j = xs_readall(f);
|
xs *o = xs_json_load(f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if (j != NULL) {
|
if (o != NULL) {
|
||||||
xs *o = xs_json_loads(j);
|
const char *type = xs_dict_get(o, "type");
|
||||||
|
|
||||||
if (o != NULL) {
|
if (!xs_is_null(type) && strcmp(type, "Accept") == 0) {
|
||||||
const char *type = xs_dict_get(o, "type");
|
const char *actor = xs_dict_get(o, "actor");
|
||||||
|
|
||||||
if (!xs_is_null(type) && strcmp(type, "Accept") == 0) {
|
if (!xs_is_null(actor)) {
|
||||||
const char *actor = xs_dict_get(o, "actor");
|
list = xs_list_append(list, actor);
|
||||||
|
|
||||||
if (!xs_is_null(actor)) {
|
/* check if there is a link to the actor object */
|
||||||
list = xs_list_append(list, actor);
|
xs *v2 = xs_replace(v, ".json", "_a.json");
|
||||||
|
|
||||||
/* check if there is a link to the actor object */
|
if (mtime(v2) == 0.0) {
|
||||||
xs *v2 = xs_replace(v, ".json", "_a.json");
|
/* no; add a link to it */
|
||||||
|
xs *actor_fn = _object_fn(actor);
|
||||||
if (mtime(v2) == 0.0) {
|
link(actor_fn, v2);
|
||||||
/* no; add a link to it */
|
|
||||||
xs *actor_fn = _object_fn(actor);
|
|
||||||
link(actor_fn, v2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1896,10 +1883,8 @@ xs_dict *notify_get(snac *snac, const char *id)
|
||||||
xs_dict *out = NULL;
|
xs_dict *out = NULL;
|
||||||
|
|
||||||
if ((f = fopen(fn, "r")) != NULL) {
|
if ((f = fopen(fn, "r")) != NULL) {
|
||||||
xs *j = xs_readall(f);
|
out = xs_json_load(f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
out = xs_json_loads(j);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
@ -2231,9 +2216,7 @@ xs_dict *queue_get(const char *fn)
|
||||||
xs_dict *obj = NULL;
|
xs_dict *obj = NULL;
|
||||||
|
|
||||||
if ((f = fopen(fn, "r")) != NULL) {
|
if ((f = fopen(fn, "r")) != NULL) {
|
||||||
xs *j = xs_readall(f);
|
obj = xs_json_load(f);
|
||||||
obj = xs_json_loads(j);
|
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,10 +66,9 @@ xs_dict *app_get(const char *id)
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if ((f = fopen(fn, "r")) != NULL) {
|
if ((f = fopen(fn, "r")) != NULL) {
|
||||||
xs *j = xs_readall(f);
|
app = xs_json_load(f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
app = xs_json_loads(j);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
|
@ -124,10 +123,8 @@ xs_dict *token_get(const char *id)
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if ((f = fopen(fn, "r")) != NULL) {
|
if ((f = fopen(fn, "r")) != NULL) {
|
||||||
xs *j = xs_readall(f);
|
token = xs_json_load(f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
token = xs_json_loads(j);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
|
|
Loading…
Reference in a new issue