diff --git a/data.c b/data.c index 62e326c..80200d2 100644 --- a/data.c +++ b/data.c @@ -643,9 +643,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 *j = xs_json_dumps_pp(obj, 4); - - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(obj, 4, f); fclose(f); /* does this object has a parent? */ @@ -1190,9 +1188,7 @@ int following_add(snac *snac, const char *actor, const xs_dict *msg) FILE *f; if ((f = fopen(fn, "w")) != NULL) { - xs *j = xs_json_dumps_pp(msg, 4); - - fwrite(j, 1, strlen(j), f); + xs_json_dump_pp(msg, 4, f); fclose(f); /* get the filename of the actor object */ @@ -1893,9 +1889,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 *j = xs_json_dumps_pp(noti, 4); - - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(noti, 4, f); fclose(f); } } @@ -1970,9 +1964,7 @@ static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) FILE *f; if ((f = fopen(tfn, "w")) != NULL) { - xs *j = xs_json_dumps_pp(msg, 4); - - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(msg, 4, f); fclose(f); rename(tfn, fn); @@ -2569,8 +2561,7 @@ void srv_archive_error(const char *prefix, const xs_str *err, if (req) { fprintf(f, "Request headers:\n"); - xs *j = xs_json_dumps_pp(req, 4); - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(req, 4, f); fprintf(f, "\n"); } @@ -2579,8 +2570,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 *j = xs_json_dumps_pp(data, 4); - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(data, 4, f); } else fprintf(f, "%s", data); diff --git a/html.c b/html.c index e96eb41..5313394 100644 --- a/html.c +++ b/html.c @@ -1985,10 +1985,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, p_vars = xs_dict_get(req, "p_vars"); #if 0 - { - xs *j1 = xs_json_dumps_pp(p_vars, 4); - printf("%s\n", j1); - } + xs_json_dump_pp(p_vars, 4, stdout); #endif if (p_path && strcmp(p_path, "admin/note") == 0) { /** **/ @@ -2310,8 +2307,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, rename(fn, bfn); if ((f = fopen(fn, "w")) != NULL) { - xs *j = xs_json_dumps_pp(snac.config, 4); - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(snac.config, 4, f); fclose(f); } else diff --git a/main.c b/main.c index b83a66e..62f5041 100644 --- a/main.c +++ b/main.c @@ -198,8 +198,7 @@ int main(int argc, char *argv[]) xs *list = index_list_desc(idx, 0, 256); xs *tl = timeline_top_level(&snac, list); - xs *j = xs_json_dumps_pp(tl, 4); - printf("%s\n", j); + xs_json_dump_pp(tl, 4, stdout); return 0; } @@ -230,8 +229,7 @@ int main(int argc, char *argv[]) enqueue_message(&snac, msg); if (dbglevel) { - xs *j = xs_json_dumps_pp(msg, 4); - printf("%s\n", j); + xs_json_dump_pp(msg, 4, stdout); } } @@ -249,8 +247,7 @@ int main(int argc, char *argv[]) enqueue_output_by_actor(&snac, msg, actor, 0); if (dbglevel) { - xs *j = xs_json_dumps_pp(msg, 4); - printf("%s\n", j); + xs_json_dump_pp(msg, 4, stdout); } } @@ -284,8 +281,7 @@ int main(int argc, char *argv[]) enqueue_output_by_actor(&snac, msg, url, 0); if (dbglevel) { - xs *j = xs_json_dumps_pp(msg, 4); - printf("%s\n", j); + xs_json_dump_pp(msg, 4, stdout); } } else { @@ -324,8 +320,7 @@ int main(int argc, char *argv[]) xs *c_msg = msg_create(&snac, msg); if (dbglevel) { - xs *j = xs_json_dumps_pp(c_msg, 4); - printf("%s\n", j); + xs_json_dump_pp(c_msg, 4, stdout); } enqueue_message(&snac, c_msg); @@ -345,8 +340,7 @@ int main(int argc, char *argv[]) printf("status: %d\n", status); if (data != NULL) { - xs *j = xs_json_dumps_pp(data, 4); - printf("%s\n", j); + xs_json_dump_pp(data, 4, stdout); } return 0; @@ -361,8 +355,7 @@ int main(int argc, char *argv[]) printf("status: %d\n", status); if (valid_status(status)) { - xs *j = xs_json_dumps_pp(data, 4); - printf("%s\n", j); + xs_json_dump_pp(data, 4, stdout); } return 0; @@ -405,8 +398,7 @@ int main(int argc, char *argv[]) c_msg = msg_create(&snac, msg); if (dbglevel) { - xs *j = xs_json_dumps_pp(c_msg, 4); - printf("%s\n", j); + xs_json_dump_pp(c_msg, 4, stdout); } enqueue_message(&snac, c_msg); diff --git a/mastoapi.c b/mastoapi.c index d851574..8256dcf 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -39,8 +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 *j = xs_json_dumps_pp(app, 4); - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(app, 4, f); fclose(f); } else @@ -104,8 +103,7 @@ int token_add(const char *id, const xs_dict *token) fn = xs_str_cat(fn, ".json"); if ((f = fopen(fn, "w")) != NULL) { - xs *j = xs_json_dumps_pp(token, 4); - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(token, 4, f); fclose(f); } else @@ -170,11 +168,6 @@ int oauth_get_handler(const xs_dict *req, const char *q_path, if (!xs_startswith(q_path, "/oauth/")) return 0; -/* { - xs *j = xs_json_dumps_pp(req, 4); - printf("oauth get:\n%s\n", j); - }*/ - int status = 404; xs_dict *msg = xs_dict_get(req, "q_vars"); xs *cmd = xs_replace_n(q_path, "/oauth", "", 1); @@ -236,11 +229,6 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, if (!xs_startswith(q_path, "/oauth/")) return 0; -/* { - xs *j = xs_json_dumps_pp(req, 4); - printf("oauth post:\n%s\n", j); - }*/ - int status = 404; char *i_ctype = xs_dict_get(req, "content-type"); @@ -946,10 +934,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, return 0; srv_debug(1, xs_fmt("mastoapi_get_handler %s", q_path)); -/* { - xs *j = xs_json_dumps_pp(req, 4); - printf("mastoapi get:\n%s\n", j); - }*/ int status = 404; xs_dict *args = xs_dict_get(req, "q_vars"); @@ -1707,10 +1691,6 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, return 0; srv_debug(1, xs_fmt("mastoapi_post_handler %s", q_path)); -/* { - xs *j = xs_json_dumps_pp(req, 4); - printf("mastoapi post:\n%s\n", j); - }*/ int status = 404; xs *args = NULL; @@ -1724,11 +1704,6 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (args == NULL) return 400; -/* { - xs *j = xs_json_dumps_pp(args, 4); - printf("%s\n", j); - }*/ - xs *cmd = xs_replace_n(q_path, "/api", "", 1); snac snac = {0}; @@ -1785,10 +1760,6 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (strcmp(cmd, "/v1/statuses") == 0) { /** **/ if (logged_in) { /* post a new Note */ -/* { - xs *j = xs_json_dumps_pp(args, 4); - printf("%s\n", j); - }*/ const char *content = xs_dict_get(args, "status"); const char *mid = xs_dict_get(args, "in_reply_to_id"); const char *visibility = xs_dict_get(args, "visibility"); @@ -2009,10 +1980,6 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, else if (strcmp(cmd, "/v1/media") == 0 || strcmp(cmd, "/v2/media") == 0) { /** **/ if (logged_in) { -/* { - xs *j = xs_json_dumps_pp(args, 4); - printf("%s\n", j); - }*/ const xs_list *file = xs_dict_get(args, "file"); const char *desc = xs_dict_get(args, "description"); @@ -2222,10 +2189,6 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path, return 0; srv_debug(1, xs_fmt("mastoapi_post_handler %s", q_path)); -/* { - xs *j = xs_json_dumps_pp(req, 4); - printf("mastoapi put:\n%s\n", j); - }*/ int status = 404; xs *args = NULL; diff --git a/upgrade.c b/upgrade.c index db0f121..8ff06c6 100644 --- a/upgrade.c +++ b/upgrade.c @@ -312,8 +312,7 @@ int snac_upgrade(xs_str **error) FILE *f; if ((f = fopen(fn, "w")) != NULL) { - xs *j = xs_json_dumps_pp(srv_config, 4); - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(srv_config, 4, f); fclose(f); srv_log(xs_fmt("disk layout upgraded %s after %d changes", fn, changed)); diff --git a/utils.c b/utils.c index 1c9a5aa..086fdf2 100644 --- a/utils.c +++ b/utils.c @@ -194,8 +194,7 @@ int snac_init(const char *basedir) return 1; } - xs *j = xs_json_dumps_pp(srv_config, 4); - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(srv_config, 4, f); fclose(f); printf("Done.\n"); @@ -276,8 +275,7 @@ int adduser(const char *uid) return 1; } else { - xs *j = xs_json_dumps_pp(config, 4); - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(config, 4, f); fclose(f); } @@ -292,8 +290,7 @@ int adduser(const char *uid) return 1; } else { - xs *j = xs_json_dumps_pp(key, 4); - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(key, 4, f); fclose(f); } @@ -319,8 +316,7 @@ int resetpwd(snac *snac) snac->config = xs_dict_set(snac->config, "passwd", hashed_pwd); if ((f = fopen(fn, "w")) != NULL) { - xs *j = xs_json_dumps_pp(snac->config, 4); - fwrite(j, strlen(j), 1, f); + xs_json_dump_pp(snac->config, 4, f); fclose(f); printf("New password for user %s is %s\n", snac->uid, clear_pwd);