mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 05:15:04 +00:00
Renamed json dump functions to new xs spec.
This commit is contained in:
parent
3611af78d6
commit
3e5bb109d1
10 changed files with 54 additions and 54 deletions
|
@ -294,7 +294,7 @@ int send_to_inbox_raw(const char *keyid, const char *seckey,
|
|||
{
|
||||
int status;
|
||||
xs_dict *response;
|
||||
xs *j_msg = xs_json_dumps_pp((xs_dict *)msg, 4);
|
||||
xs *j_msg = xs_json_dumps((xs_dict *)msg, 4);
|
||||
|
||||
response = http_signed_request_raw(keyid, seckey, "POST", inbox,
|
||||
NULL, j_msg, strlen(j_msg), &status, payload, p_size, timeout);
|
||||
|
@ -2028,7 +2028,7 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path,
|
|||
status = 404;
|
||||
|
||||
if (status == 200 && msg != NULL) {
|
||||
*body = xs_json_dumps_pp(msg, 4);
|
||||
*body = xs_json_dumps(msg, 4);
|
||||
*b_size = strlen(*body);
|
||||
}
|
||||
|
||||
|
|
20
data.c
20
data.c
|
@ -632,7 +632,7 @@ int _object_add(const char *id, const xs_dict *obj, int ow)
|
|||
if ((f = fopen(fn, "w")) != NULL) {
|
||||
flock(fileno(f), LOCK_EX);
|
||||
|
||||
xs_json_dump_pp(obj, 4, f);
|
||||
xs_json_dump(obj, 4, f);
|
||||
fclose(f);
|
||||
|
||||
/* does this object has a parent? */
|
||||
|
@ -1175,7 +1175,7 @@ int following_add(snac *snac, const char *actor, const xs_dict *msg)
|
|||
FILE *f;
|
||||
|
||||
if ((f = fopen(fn, "w")) != NULL) {
|
||||
xs_json_dump_pp(msg, 4, f);
|
||||
xs_json_dump(msg, 4, f);
|
||||
fclose(f);
|
||||
|
||||
/* get the filename of the actor object */
|
||||
|
@ -1913,7 +1913,7 @@ void notify_add(snac *snac, const char *type, const char *utype,
|
|||
noti = xs_dict_append(noti, "objid", objid);
|
||||
|
||||
if ((f = fopen(fn, "w")) != NULL) {
|
||||
xs_json_dump_pp(noti, 4, f);
|
||||
xs_json_dump(noti, 4, f);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
@ -1986,7 +1986,7 @@ static xs_dict *_enqueue_put(const char *fn, xs_dict *msg)
|
|||
FILE *f;
|
||||
|
||||
if ((f = fopen(tfn, "w")) != NULL) {
|
||||
xs_json_dump_pp(msg, 4, f);
|
||||
xs_json_dump(msg, 4, f);
|
||||
fclose(f);
|
||||
|
||||
rename(tfn, fn);
|
||||
|
@ -2484,8 +2484,8 @@ void srv_archive(const char *direction, const char *url, xs_dict *req,
|
|||
xs *meta_fn = xs_fmt("%s/_META", dir);
|
||||
|
||||
if ((f = fopen(meta_fn, "w")) != NULL) {
|
||||
xs *j1 = xs_json_dumps_pp(req, 4);
|
||||
xs *j2 = xs_json_dumps_pp(headers, 4);
|
||||
xs *j1 = xs_json_dumps(req, 4);
|
||||
xs *j2 = xs_json_dumps(headers, 4);
|
||||
|
||||
fprintf(f, "dir: %s\n", direction);
|
||||
|
||||
|
@ -2513,7 +2513,7 @@ void srv_archive(const char *direction, const char *url, xs_dict *req,
|
|||
xs *j1 = NULL;
|
||||
|
||||
if (v1 != NULL)
|
||||
j1 = xs_json_dumps_pp(v1, 4);
|
||||
j1 = xs_json_dumps(v1, 4);
|
||||
|
||||
if (j1 != NULL)
|
||||
fwrite(j1, strlen(j1), 1, f);
|
||||
|
@ -2544,7 +2544,7 @@ void srv_archive(const char *direction, const char *url, xs_dict *req,
|
|||
xs *j1 = NULL;
|
||||
|
||||
if (v1 != NULL)
|
||||
j1 = xs_json_dumps_pp(v1, 4);
|
||||
j1 = xs_json_dumps(v1, 4);
|
||||
|
||||
if (j1 != NULL)
|
||||
fwrite(j1, strlen(j1), 1, f);
|
||||
|
@ -2581,7 +2581,7 @@ void srv_archive_error(const char *prefix, const xs_str *err,
|
|||
if (req) {
|
||||
fprintf(f, "Request headers:\n");
|
||||
|
||||
xs_json_dump_pp(req, 4, f);
|
||||
xs_json_dump(req, 4, f);
|
||||
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
|
@ -2590,7 +2590,7 @@ void srv_archive_error(const char *prefix, const xs_str *err,
|
|||
fprintf(f, "Data:\n");
|
||||
|
||||
if (xs_type(data) == XSTYPE_LIST || xs_type(data) == XSTYPE_DICT) {
|
||||
xs_json_dump_pp(data, 4, f);
|
||||
xs_json_dump(data, 4, f);
|
||||
}
|
||||
else
|
||||
fprintf(f, "%s", data);
|
||||
|
|
4
html.c
4
html.c
|
@ -1990,7 +1990,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
|
|||
p_vars = xs_dict_get(req, "p_vars");
|
||||
|
||||
#if 0
|
||||
xs_json_dump_pp(p_vars, 4, stdout);
|
||||
xs_json_dump(p_vars, 4, stdout);
|
||||
#endif
|
||||
|
||||
if (p_path && strcmp(p_path, "admin/note") == 0) { /** **/
|
||||
|
@ -2312,7 +2312,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
|
|||
rename(fn, bfn);
|
||||
|
||||
if ((f = fopen(fn, "w")) != NULL) {
|
||||
xs_json_dump_pp(snac.config, 4, f);
|
||||
xs_json_dump(snac.config, 4, f);
|
||||
fclose(f);
|
||||
}
|
||||
else
|
||||
|
|
16
main.c
16
main.c
|
@ -200,7 +200,7 @@ int main(int argc, char *argv[])
|
|||
xs *list = index_list_desc(idx, 0, 256);
|
||||
xs *tl = timeline_top_level(&snac, list);
|
||||
|
||||
xs_json_dump_pp(tl, 4, stdout);
|
||||
xs_json_dump(tl, 4, stdout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ int main(int argc, char *argv[])
|
|||
enqueue_message(&snac, msg);
|
||||
|
||||
if (dbglevel) {
|
||||
xs_json_dump_pp(msg, 4, stdout);
|
||||
xs_json_dump(msg, 4, stdout);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,7 +249,7 @@ int main(int argc, char *argv[])
|
|||
enqueue_output_by_actor(&snac, msg, actor, 0);
|
||||
|
||||
if (dbglevel) {
|
||||
xs_json_dump_pp(msg, 4, stdout);
|
||||
xs_json_dump(msg, 4, stdout);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -311,7 +311,7 @@ int main(int argc, char *argv[])
|
|||
enqueue_output_by_actor(&snac, msg, url, 0);
|
||||
|
||||
if (dbglevel) {
|
||||
xs_json_dump_pp(msg, 4, stdout);
|
||||
xs_json_dump(msg, 4, stdout);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -350,7 +350,7 @@ int main(int argc, char *argv[])
|
|||
xs *c_msg = msg_create(&snac, msg);
|
||||
|
||||
if (dbglevel) {
|
||||
xs_json_dump_pp(c_msg, 4, stdout);
|
||||
xs_json_dump(c_msg, 4, stdout);
|
||||
}
|
||||
|
||||
enqueue_message(&snac, c_msg);
|
||||
|
@ -370,7 +370,7 @@ int main(int argc, char *argv[])
|
|||
printf("status: %d\n", status);
|
||||
|
||||
if (data != NULL) {
|
||||
xs_json_dump_pp(data, 4, stdout);
|
||||
xs_json_dump(data, 4, stdout);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -385,7 +385,7 @@ int main(int argc, char *argv[])
|
|||
printf("status: %d\n", status);
|
||||
|
||||
if (valid_status(status)) {
|
||||
xs_json_dump_pp(data, 4, stdout);
|
||||
xs_json_dump(data, 4, stdout);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -428,7 +428,7 @@ int main(int argc, char *argv[])
|
|||
c_msg = msg_create(&snac, msg);
|
||||
|
||||
if (dbglevel) {
|
||||
xs_json_dump_pp(c_msg, 4, stdout);
|
||||
xs_json_dump(c_msg, 4, stdout);
|
||||
}
|
||||
|
||||
enqueue_message(&snac, c_msg);
|
||||
|
|
40
mastoapi.c
40
mastoapi.c
|
@ -39,7 +39,7 @@ int app_add(const char *id, const xs_dict *app)
|
|||
fn = xs_str_cat(fn, ".json");
|
||||
|
||||
if ((f = fopen(fn, "w")) != NULL) {
|
||||
xs_json_dump_pp(app, 4, f);
|
||||
xs_json_dump(app, 4, f);
|
||||
fclose(f);
|
||||
}
|
||||
else
|
||||
|
@ -102,7 +102,7 @@ int token_add(const char *id, const xs_dict *token)
|
|||
fn = xs_str_cat(fn, ".json");
|
||||
|
||||
if ((f = fopen(fn, "w")) != NULL) {
|
||||
xs_json_dump_pp(token, 4, f);
|
||||
xs_json_dump(token, 4, f);
|
||||
fclose(f);
|
||||
}
|
||||
else
|
||||
|
@ -358,7 +358,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
|
|||
if (!xs_is_null(scope))
|
||||
rsp = xs_dict_append(rsp, "scope", scope);
|
||||
|
||||
*body = xs_json_dumps_pp(rsp, 4);
|
||||
*body = xs_json_dumps(rsp, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
|
||||
|
@ -962,7 +962,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||
|
||||
acct = xs_dict_append(acct, "avatar", avatar);
|
||||
|
||||
*body = xs_json_dumps_pp(acct, 4);
|
||||
*body = xs_json_dumps(acct, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -989,7 +989,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||
res = xs_list_append(res, rel);
|
||||
}
|
||||
|
||||
*body = xs_json_dumps_pp(res, 4);
|
||||
*body = xs_json_dumps(res, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -1132,7 +1132,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||
}
|
||||
|
||||
if (out != NULL) {
|
||||
*body = xs_json_dumps_pp(out, 4);
|
||||
*body = xs_json_dumps(out, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -1222,7 +1222,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||
cnt++;
|
||||
}
|
||||
|
||||
*body = xs_json_dumps_pp(out, 4);
|
||||
*body = xs_json_dumps(out, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
|
||||
|
@ -1277,7 +1277,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||
}
|
||||
}
|
||||
|
||||
*body = xs_json_dumps_pp(out, 4);
|
||||
*body = xs_json_dumps(out, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -1360,7 +1360,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||
out = xs_list_append(out, mn);
|
||||
}
|
||||
|
||||
*body = xs_json_dumps_pp(out, 4);
|
||||
*body = xs_json_dumps(out, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -1498,7 +1498,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||
}
|
||||
}
|
||||
|
||||
*body = xs_json_dumps_pp(ins, 4);
|
||||
*body = xs_json_dumps(ins, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -1597,7 +1597,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||
srv_debug(1, xs_fmt("mastoapi status: bad id %s", id));
|
||||
|
||||
if (out != NULL) {
|
||||
*body = xs_json_dumps_pp(out, 4);
|
||||
*body = xs_json_dumps(out, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -1661,7 +1661,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||
res = xs_dict_append(res, "statuses", stl);
|
||||
res = xs_dict_append(res, "hashtags", htl);
|
||||
|
||||
*body = xs_json_dumps_pp(res, 4);
|
||||
*body = xs_json_dumps(res, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -1739,7 +1739,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
|||
app = xs_dict_append(app, "vapid_key", vkey);
|
||||
app = xs_dict_append(app, "id", id);
|
||||
|
||||
*body = xs_json_dumps_pp(app, 4);
|
||||
*body = xs_json_dumps(app, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
|
||||
|
@ -1828,7 +1828,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
|||
/* convert to a mastodon status as a response code */
|
||||
xs *st = mastoapi_status(&snac, msg);
|
||||
|
||||
*body = xs_json_dumps_pp(st, 4);
|
||||
*body = xs_json_dumps(st, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -1924,7 +1924,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
|||
}
|
||||
|
||||
if (out != NULL) {
|
||||
*body = xs_json_dumps_pp(out, 4);
|
||||
*body = xs_json_dumps(out, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -1967,7 +1967,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
|||
xs *server_key = random_str();
|
||||
wpush = xs_dict_append(wpush, "server_key", server_key);
|
||||
|
||||
*body = xs_json_dumps_pp(wpush, 4);
|
||||
*body = xs_json_dumps(wpush, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -2010,7 +2010,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
|||
rsp = xs_dict_append(rsp, "remote_url", url);
|
||||
rsp = xs_dict_append(rsp, "description", desc);
|
||||
|
||||
*body = xs_json_dumps_pp(rsp, 4);
|
||||
*body = xs_json_dumps(rsp, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -2095,7 +2095,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
|||
}
|
||||
|
||||
if (rsp != NULL) {
|
||||
*body = xs_json_dumps_pp(rsp, 4);
|
||||
*body = xs_json_dumps(rsp, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -2157,7 +2157,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
|||
}
|
||||
|
||||
if (out != NULL) {
|
||||
*body = xs_json_dumps_pp(out, 4);
|
||||
*body = xs_json_dumps(out, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
@ -2226,7 +2226,7 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
|
|||
rsp = xs_dict_append(rsp, "remote_url", url);
|
||||
rsp = xs_dict_append(rsp, "description", desc);
|
||||
|
||||
*body = xs_json_dumps_pp(rsp, 4);
|
||||
*body = xs_json_dumps(rsp, 4);
|
||||
*ctype = "application/json";
|
||||
status = 200;
|
||||
}
|
||||
|
|
|
@ -312,7 +312,7 @@ int snac_upgrade(xs_str **error)
|
|||
FILE *f;
|
||||
|
||||
if ((f = fopen(fn, "w")) != NULL) {
|
||||
xs_json_dump_pp(srv_config, 4, f);
|
||||
xs_json_dump(srv_config, 4, f);
|
||||
fclose(f);
|
||||
|
||||
srv_log(xs_fmt("disk layout upgraded %s after %d changes", fn, changed));
|
||||
|
|
8
utils.c
8
utils.c
|
@ -194,7 +194,7 @@ int snac_init(const char *basedir)
|
|||
return 1;
|
||||
}
|
||||
|
||||
xs_json_dump_pp(srv_config, 4, f);
|
||||
xs_json_dump(srv_config, 4, f);
|
||||
fclose(f);
|
||||
|
||||
printf("Done.\n");
|
||||
|
@ -275,7 +275,7 @@ int adduser(const char *uid)
|
|||
return 1;
|
||||
}
|
||||
else {
|
||||
xs_json_dump_pp(config, 4, f);
|
||||
xs_json_dump(config, 4, f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,7 @@ int adduser(const char *uid)
|
|||
return 1;
|
||||
}
|
||||
else {
|
||||
xs_json_dump_pp(key, 4, f);
|
||||
xs_json_dump(key, 4, f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ int resetpwd(snac *snac)
|
|||
snac->config = xs_dict_set(snac->config, "passwd", hashed_pwd);
|
||||
|
||||
if ((f = fopen(fn, "w")) != NULL) {
|
||||
xs_json_dump_pp(snac->config, 4, f);
|
||||
xs_json_dump(snac->config, 4, f);
|
||||
fclose(f);
|
||||
|
||||
printf("New password for user %s is %s\n", snac->uid, clear_pwd);
|
||||
|
|
|
@ -184,7 +184,7 @@ int webfinger_get_handler(d_char *req, char *q_path,
|
|||
obj = xs_dict_append(obj, "subject", acct);
|
||||
obj = xs_dict_append(obj, "links", links);
|
||||
|
||||
j = xs_json_dumps_pp(obj, 4);
|
||||
j = xs_json_dumps(obj, 4);
|
||||
|
||||
user_free(&snac);
|
||||
|
||||
|
|
10
xs_json.h
10
xs_json.h
|
@ -4,8 +4,8 @@
|
|||
|
||||
#define _XS_JSON_H
|
||||
|
||||
int xs_json_dump_pp(const xs_val *data, int indent, FILE *f);
|
||||
xs_str *xs_json_dumps_pp(const xs_val *data, int indent);
|
||||
int xs_json_dump(const xs_val *data, int indent, FILE *f);
|
||||
xs_str *xs_json_dumps(const xs_val *data, int indent);
|
||||
xs_val *xs_json_loads(const xs_str *json);
|
||||
xs_val *xs_json_load(FILE *f);
|
||||
|
||||
|
@ -141,7 +141,7 @@ static void _xs_json_dump(const xs_val *s_data, int level, int indent, FILE *f)
|
|||
}
|
||||
|
||||
|
||||
xs_str *xs_json_dumps_pp(const xs_val *data, int indent)
|
||||
xs_str *xs_json_dumps(const xs_val *data, int indent)
|
||||
/* dumps data as a JSON string */
|
||||
{
|
||||
xs_str *s = NULL;
|
||||
|
@ -149,7 +149,7 @@ xs_str *xs_json_dumps_pp(const xs_val *data, int indent)
|
|||
FILE *f;
|
||||
|
||||
if ((f = open_memstream(&s, &sz)) != NULL) {
|
||||
int r = xs_json_dump_pp(data, indent, f);
|
||||
int r = xs_json_dump(data, indent, f);
|
||||
fclose(f);
|
||||
|
||||
if (!r)
|
||||
|
@ -160,7 +160,7 @@ xs_str *xs_json_dumps_pp(const xs_val *data, int indent)
|
|||
}
|
||||
|
||||
|
||||
int xs_json_dump_pp(const xs_val *data, int indent, FILE *f)
|
||||
int xs_json_dump(const xs_val *data, int indent, FILE *f)
|
||||
/* dumps data into a file as JSON */
|
||||
{
|
||||
xstype t = xs_type(data);
|
||||
|
|
|
@ -1 +1 @@
|
|||
/* 568c95296bb7d5b40e35e49220403358bc7dadfc */
|
||||
/* 4d883b5331e9275f2439b0983a0f978d1cd21e11 */
|
||||
|
|
Loading…
Reference in a new issue