summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
authorGravatar default2023-08-03 09:02:08 +0200
committerGravatar default2023-08-03 09:02:08 +0200
commitf5a3dbf8d652dbf87f9ff27b50d11f6364551a61 (patch)
treea3c8fabb5baa25bde203a9cc8089134b8774d723 /mastoapi.c
parentBackport from xs. (diff)
downloadpenes-snac2-f5a3dbf8d652dbf87f9ff27b50d11f6364551a61.tar.gz
penes-snac2-f5a3dbf8d652dbf87f9ff27b50d11f6364551a61.tar.xz
penes-snac2-f5a3dbf8d652dbf87f9ff27b50d11f6364551a61.zip
Use xs_json_dump_pp() wherever possible.
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c41
1 files changed, 2 insertions, 39 deletions
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)
39 fn = xs_str_cat(fn, ".json"); 39 fn = xs_str_cat(fn, ".json");
40 40
41 if ((f = fopen(fn, "w")) != NULL) { 41 if ((f = fopen(fn, "w")) != NULL) {
42 xs *j = xs_json_dumps_pp(app, 4); 42 xs_json_dump_pp(app, 4, f);
43 fwrite(j, strlen(j), 1, f);
44 fclose(f); 43 fclose(f);
45 } 44 }
46 else 45 else
@@ -104,8 +103,7 @@ int token_add(const char *id, const xs_dict *token)
104 fn = xs_str_cat(fn, ".json"); 103 fn = xs_str_cat(fn, ".json");
105 104
106 if ((f = fopen(fn, "w")) != NULL) { 105 if ((f = fopen(fn, "w")) != NULL) {
107 xs *j = xs_json_dumps_pp(token, 4); 106 xs_json_dump_pp(token, 4, f);
108 fwrite(j, strlen(j), 1, f);
109 fclose(f); 107 fclose(f);
110 } 108 }
111 else 109 else
@@ -170,11 +168,6 @@ int oauth_get_handler(const xs_dict *req, const char *q_path,
170 if (!xs_startswith(q_path, "/oauth/")) 168 if (!xs_startswith(q_path, "/oauth/"))
171 return 0; 169 return 0;
172 170
173/* {
174 xs *j = xs_json_dumps_pp(req, 4);
175 printf("oauth get:\n%s\n", j);
176 }*/
177
178 int status = 404; 171 int status = 404;
179 xs_dict *msg = xs_dict_get(req, "q_vars"); 172 xs_dict *msg = xs_dict_get(req, "q_vars");
180 xs *cmd = xs_replace_n(q_path, "/oauth", "", 1); 173 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,
236 if (!xs_startswith(q_path, "/oauth/")) 229 if (!xs_startswith(q_path, "/oauth/"))
237 return 0; 230 return 0;
238 231
239/* {
240 xs *j = xs_json_dumps_pp(req, 4);
241 printf("oauth post:\n%s\n", j);
242 }*/
243
244 int status = 404; 232 int status = 404;
245 233
246 char *i_ctype = xs_dict_get(req, "content-type"); 234 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,
946 return 0; 934 return 0;
947 935
948 srv_debug(1, xs_fmt("mastoapi_get_handler %s", q_path)); 936 srv_debug(1, xs_fmt("mastoapi_get_handler %s", q_path));
949/* {
950 xs *j = xs_json_dumps_pp(req, 4);
951 printf("mastoapi get:\n%s\n", j);
952 }*/
953 937
954 int status = 404; 938 int status = 404;
955 xs_dict *args = xs_dict_get(req, "q_vars"); 939 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,
1707 return 0; 1691 return 0;
1708 1692
1709 srv_debug(1, xs_fmt("mastoapi_post_handler %s", q_path)); 1693 srv_debug(1, xs_fmt("mastoapi_post_handler %s", q_path));
1710/* {
1711 xs *j = xs_json_dumps_pp(req, 4);
1712 printf("mastoapi post:\n%s\n", j);
1713 }*/
1714 1694
1715 int status = 404; 1695 int status = 404;
1716 xs *args = NULL; 1696 xs *args = NULL;
@@ -1724,11 +1704,6 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
1724 if (args == NULL) 1704 if (args == NULL)
1725 return 400; 1705 return 400;
1726 1706
1727/* {
1728 xs *j = xs_json_dumps_pp(args, 4);
1729 printf("%s\n", j);
1730 }*/
1731
1732 xs *cmd = xs_replace_n(q_path, "/api", "", 1); 1707 xs *cmd = xs_replace_n(q_path, "/api", "", 1);
1733 1708
1734 snac snac = {0}; 1709 snac snac = {0};
@@ -1785,10 +1760,6 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
1785 if (strcmp(cmd, "/v1/statuses") == 0) { /** **/ 1760 if (strcmp(cmd, "/v1/statuses") == 0) { /** **/
1786 if (logged_in) { 1761 if (logged_in) {
1787 /* post a new Note */ 1762 /* post a new Note */
1788/* {
1789 xs *j = xs_json_dumps_pp(args, 4);
1790 printf("%s\n", j);
1791 }*/
1792 const char *content = xs_dict_get(args, "status"); 1763 const char *content = xs_dict_get(args, "status");
1793 const char *mid = xs_dict_get(args, "in_reply_to_id"); 1764 const char *mid = xs_dict_get(args, "in_reply_to_id");
1794 const char *visibility = xs_dict_get(args, "visibility"); 1765 const char *visibility = xs_dict_get(args, "visibility");
@@ -2009,10 +1980,6 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
2009 else 1980 else
2010 if (strcmp(cmd, "/v1/media") == 0 || strcmp(cmd, "/v2/media") == 0) { /** **/ 1981 if (strcmp(cmd, "/v1/media") == 0 || strcmp(cmd, "/v2/media") == 0) { /** **/
2011 if (logged_in) { 1982 if (logged_in) {
2012/* {
2013 xs *j = xs_json_dumps_pp(args, 4);
2014 printf("%s\n", j);
2015 }*/
2016 const xs_list *file = xs_dict_get(args, "file"); 1983 const xs_list *file = xs_dict_get(args, "file");
2017 const char *desc = xs_dict_get(args, "description"); 1984 const char *desc = xs_dict_get(args, "description");
2018 1985
@@ -2222,10 +2189,6 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
2222 return 0; 2189 return 0;
2223 2190
2224 srv_debug(1, xs_fmt("mastoapi_post_handler %s", q_path)); 2191 srv_debug(1, xs_fmt("mastoapi_post_handler %s", q_path));
2225/* {
2226 xs *j = xs_json_dumps_pp(req, 4);
2227 printf("mastoapi put:\n%s\n", j);
2228 }*/
2229 2192
2230 int status = 404; 2193 int status = 404;
2231 xs *args = NULL; 2194 xs *args = NULL;