commit 3e5bb10

default  ·  2023-08-08 17:29:34 +0000 UTC
parent 3611af7
Renamed json dump functions to new xs spec.
10 files changed,  +54, -54
M data.c
M html.c
M main.c
+2, -2
 1@@ -294,7 +294,7 @@ int send_to_inbox_raw(const char *keyid, const char *seckey,
 2 {
 3     int status;
 4     xs_dict *response;
 5-    xs *j_msg = xs_json_dumps_pp((xs_dict *)msg, 4);
 6+    xs *j_msg = xs_json_dumps((xs_dict *)msg, 4);
 7 
 8     response = http_signed_request_raw(keyid, seckey, "POST", inbox,
 9         NULL, j_msg, strlen(j_msg), &status, payload, p_size, timeout);
10@@ -2028,7 +2028,7 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path,
11         status = 404;
12 
13     if (status == 200 && msg != NULL) {
14-        *body   = xs_json_dumps_pp(msg, 4);
15+        *body   = xs_json_dumps(msg, 4);
16         *b_size = strlen(*body);
17     }
18 
M data.c
+10, -10
 1@@ -632,7 +632,7 @@ int _object_add(const char *id, const xs_dict *obj, int ow)
 2     if ((f = fopen(fn, "w")) != NULL) {
 3         flock(fileno(f), LOCK_EX);
 4 
 5-        xs_json_dump_pp(obj, 4, f);
 6+        xs_json_dump(obj, 4, f);
 7         fclose(f);
 8 
 9         /* does this object has a parent? */
10@@ -1175,7 +1175,7 @@ int following_add(snac *snac, const char *actor, const xs_dict *msg)
11     FILE *f;
12 
13     if ((f = fopen(fn, "w")) != NULL) {
14-        xs_json_dump_pp(msg, 4, f);
15+        xs_json_dump(msg, 4, f);
16         fclose(f);
17 
18         /* get the filename of the actor object */
19@@ -1913,7 +1913,7 @@ void notify_add(snac *snac, const char *type, const char *utype,
20         noti = xs_dict_append(noti, "objid", objid);
21 
22     if ((f = fopen(fn, "w")) != NULL) {
23-        xs_json_dump_pp(noti, 4, f);
24+        xs_json_dump(noti, 4, f);
25         fclose(f);
26     }
27 }
28@@ -1986,7 +1986,7 @@ static xs_dict *_enqueue_put(const char *fn, xs_dict *msg)
29     FILE *f;
30 
31     if ((f = fopen(tfn, "w")) != NULL) {
32-        xs_json_dump_pp(msg, 4, f);
33+        xs_json_dump(msg, 4, f);
34         fclose(f);
35 
36         rename(tfn, fn);
37@@ -2484,8 +2484,8 @@ void srv_archive(const char *direction, const char *url, xs_dict *req,
38         xs *meta_fn = xs_fmt("%s/_META", dir);
39 
40         if ((f = fopen(meta_fn, "w")) != NULL) {
41-            xs *j1 = xs_json_dumps_pp(req, 4);
42-            xs *j2 = xs_json_dumps_pp(headers, 4);
43+            xs *j1 = xs_json_dumps(req, 4);
44+            xs *j2 = xs_json_dumps(headers, 4);
45 
46             fprintf(f, "dir: %s\n", direction);
47 
48@@ -2513,7 +2513,7 @@ void srv_archive(const char *direction, const char *url, xs_dict *req,
49                     xs *j1 = NULL;
50 
51                     if (v1 != NULL)
52-                        j1 = xs_json_dumps_pp(v1, 4);
53+                        j1 = xs_json_dumps(v1, 4);
54 
55                     if (j1 != NULL)
56                         fwrite(j1, strlen(j1), 1, f);
57@@ -2544,7 +2544,7 @@ void srv_archive(const char *direction, const char *url, xs_dict *req,
58                     xs *j1 = NULL;
59 
60                     if (v1 != NULL)
61-                        j1 = xs_json_dumps_pp(v1, 4);
62+                        j1 = xs_json_dumps(v1, 4);
63 
64                     if (j1 != NULL)
65                         fwrite(j1, strlen(j1), 1, f);
66@@ -2581,7 +2581,7 @@ void srv_archive_error(const char *prefix, const xs_str *err,
67         if (req) {
68             fprintf(f, "Request headers:\n");
69 
70-            xs_json_dump_pp(req, 4, f);
71+            xs_json_dump(req, 4, f);
72 
73             fprintf(f, "\n");
74         }
75@@ -2590,7 +2590,7 @@ void srv_archive_error(const char *prefix, const xs_str *err,
76             fprintf(f, "Data:\n");
77 
78             if (xs_type(data) == XSTYPE_LIST || xs_type(data) == XSTYPE_DICT) {
79-                xs_json_dump_pp(data, 4, f);
80+                xs_json_dump(data, 4, f);
81             }
82             else
83                 fprintf(f, "%s", data);
M html.c
+2, -2
 1@@ -1990,7 +1990,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
 2     p_vars = xs_dict_get(req, "p_vars");
 3 
 4 #if 0
 5-    xs_json_dump_pp(p_vars, 4, stdout);
 6+    xs_json_dump(p_vars, 4, stdout);
 7 #endif
 8 
 9     if (p_path && strcmp(p_path, "admin/note") == 0) { /** **/
10@@ -2312,7 +2312,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
11         rename(fn, bfn);
12 
13         if ((f = fopen(fn, "w")) != NULL) {
14-            xs_json_dump_pp(snac.config, 4, f);
15+            xs_json_dump(snac.config, 4, f);
16             fclose(f);
17         }
18         else
M main.c
+8, -8
 1@@ -200,7 +200,7 @@ int main(int argc, char *argv[])
 2         xs *list = index_list_desc(idx, 0, 256);
 3         xs *tl   = timeline_top_level(&snac, list);
 4 
 5-        xs_json_dump_pp(tl, 4, stdout);
 6+        xs_json_dump(tl, 4, stdout);
 7 
 8         return 0;
 9     }
10@@ -231,7 +231,7 @@ int main(int argc, char *argv[])
11             enqueue_message(&snac, msg);
12 
13             if (dbglevel) {
14-                xs_json_dump_pp(msg, 4, stdout);
15+                xs_json_dump(msg, 4, stdout);
16             }
17         }
18 
19@@ -249,7 +249,7 @@ int main(int argc, char *argv[])
20             enqueue_output_by_actor(&snac, msg, actor, 0);
21 
22             if (dbglevel) {
23-                xs_json_dump_pp(msg, 4, stdout);
24+                xs_json_dump(msg, 4, stdout);
25             }
26         }
27 
28@@ -311,7 +311,7 @@ int main(int argc, char *argv[])
29             enqueue_output_by_actor(&snac, msg, url, 0);
30 
31             if (dbglevel) {
32-                xs_json_dump_pp(msg, 4, stdout);
33+                xs_json_dump(msg, 4, stdout);
34             }
35         }
36         else {
37@@ -350,7 +350,7 @@ int main(int argc, char *argv[])
38         xs *c_msg = msg_create(&snac, msg);
39 
40         if (dbglevel) {
41-            xs_json_dump_pp(c_msg, 4, stdout);
42+            xs_json_dump(c_msg, 4, stdout);
43         }
44 
45         enqueue_message(&snac, c_msg);
46@@ -370,7 +370,7 @@ int main(int argc, char *argv[])
47         printf("status: %d\n", status);
48 
49         if (data != NULL) {
50-            xs_json_dump_pp(data, 4, stdout);
51+            xs_json_dump(data, 4, stdout);
52         }
53 
54         return 0;
55@@ -385,7 +385,7 @@ int main(int argc, char *argv[])
56         printf("status: %d\n", status);
57 
58         if (valid_status(status)) {
59-            xs_json_dump_pp(data, 4, stdout);
60+            xs_json_dump(data, 4, stdout);
61         }
62 
63         return 0;
64@@ -428,7 +428,7 @@ int main(int argc, char *argv[])
65         c_msg = msg_create(&snac, msg);
66 
67         if (dbglevel) {
68-            xs_json_dump_pp(c_msg, 4, stdout);
69+            xs_json_dump(c_msg, 4, stdout);
70         }
71 
72         enqueue_message(&snac, c_msg);
+20, -20
  1@@ -39,7 +39,7 @@ int app_add(const char *id, const xs_dict *app)
  2     fn = xs_str_cat(fn, ".json");
  3 
  4     if ((f = fopen(fn, "w")) != NULL) {
  5-        xs_json_dump_pp(app, 4, f);
  6+        xs_json_dump(app, 4, f);
  7         fclose(f);
  8     }
  9     else
 10@@ -102,7 +102,7 @@ int token_add(const char *id, const xs_dict *token)
 11     fn = xs_str_cat(fn, ".json");
 12 
 13     if ((f = fopen(fn, "w")) != NULL) {
 14-        xs_json_dump_pp(token, 4, f);
 15+        xs_json_dump(token, 4, f);
 16         fclose(f);
 17     }
 18     else
 19@@ -358,7 +358,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
 20                 if (!xs_is_null(scope))
 21                     rsp = xs_dict_append(rsp, "scope", scope);
 22 
 23-                *body  = xs_json_dumps_pp(rsp, 4);
 24+                *body  = xs_json_dumps(rsp, 4);
 25                 *ctype = "application/json";
 26                 status = 200;
 27 
 28@@ -962,7 +962,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 29 
 30             acct = xs_dict_append(acct, "avatar", avatar);
 31 
 32-            *body  = xs_json_dumps_pp(acct, 4);
 33+            *body  = xs_json_dumps(acct, 4);
 34             *ctype = "application/json";
 35             status = 200;
 36         }
 37@@ -989,7 +989,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 38                     res = xs_list_append(res, rel);
 39             }
 40 
 41-            *body  = xs_json_dumps_pp(res, 4);
 42+            *body  = xs_json_dumps(res, 4);
 43             *ctype = "application/json";
 44             status = 200;
 45         }
 46@@ -1132,7 +1132,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 47             }
 48 
 49             if (out != NULL) {
 50-                *body  = xs_json_dumps_pp(out, 4);
 51+                *body  = xs_json_dumps(out, 4);
 52                 *ctype = "application/json";
 53                 status = 200;
 54             }
 55@@ -1222,7 +1222,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 56                 cnt++;
 57             }
 58 
 59-            *body  = xs_json_dumps_pp(out, 4);
 60+            *body  = xs_json_dumps(out, 4);
 61             *ctype = "application/json";
 62             status = 200;
 63 
 64@@ -1277,7 +1277,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 65             }
 66         }
 67 
 68-        *body  = xs_json_dumps_pp(out, 4);
 69+        *body  = xs_json_dumps(out, 4);
 70         *ctype = "application/json";
 71         status = 200;
 72     }
 73@@ -1360,7 +1360,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 74                 out = xs_list_append(out, mn);
 75             }
 76 
 77-            *body  = xs_json_dumps_pp(out, 4);
 78+            *body  = xs_json_dumps(out, 4);
 79             *ctype = "application/json";
 80             status = 200;
 81         }
 82@@ -1498,7 +1498,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 83             }
 84         }
 85 
 86-        *body  = xs_json_dumps_pp(ins, 4);
 87+        *body  = xs_json_dumps(ins, 4);
 88         *ctype = "application/json";
 89         status = 200;
 90     }
 91@@ -1597,7 +1597,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 92                     srv_debug(1, xs_fmt("mastoapi status: bad id %s", id));
 93 
 94                 if (out != NULL) {
 95-                    *body  = xs_json_dumps_pp(out, 4);
 96+                    *body  = xs_json_dumps(out, 4);
 97                     *ctype = "application/json";
 98                     status = 200;
 99                 }
100@@ -1661,7 +1661,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
101             res = xs_dict_append(res, "statuses", stl);
102             res = xs_dict_append(res, "hashtags", htl);
103 
104-            *body  = xs_json_dumps_pp(res, 4);
105+            *body  = xs_json_dumps(res, 4);
106             *ctype = "application/json";
107             status = 200;
108         }
109@@ -1739,7 +1739,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
110             app = xs_dict_append(app, "vapid_key",     vkey);
111             app = xs_dict_append(app, "id",            id);
112 
113-            *body  = xs_json_dumps_pp(app, 4);
114+            *body  = xs_json_dumps(app, 4);
115             *ctype = "application/json";
116             status = 200;
117 
118@@ -1828,7 +1828,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
119             /* convert to a mastodon status as a response code */
120             xs *st = mastoapi_status(&snac, msg);
121 
122-            *body  = xs_json_dumps_pp(st, 4);
123+            *body  = xs_json_dumps(st, 4);
124             *ctype = "application/json";
125             status = 200;
126         }
127@@ -1924,7 +1924,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
128                 }
129 
130                 if (out != NULL) {
131-                    *body  = xs_json_dumps_pp(out, 4);
132+                    *body  = xs_json_dumps(out, 4);
133                     *ctype = "application/json";
134                     status = 200;
135                 }
136@@ -1967,7 +1967,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
137             xs *server_key = random_str();
138             wpush = xs_dict_append(wpush, "server_key", server_key);
139 
140-            *body  = xs_json_dumps_pp(wpush, 4);
141+            *body  = xs_json_dumps(wpush, 4);
142             *ctype = "application/json";
143             status = 200;
144         }
145@@ -2010,7 +2010,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
146                     rsp = xs_dict_append(rsp, "remote_url",  url);
147                     rsp = xs_dict_append(rsp, "description", desc);
148 
149-                    *body  = xs_json_dumps_pp(rsp, 4);
150+                    *body  = xs_json_dumps(rsp, 4);
151                     *ctype = "application/json";
152                     status = 200;
153                 }
154@@ -2095,7 +2095,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
155             }
156 
157             if (rsp != NULL) {
158-                *body  = xs_json_dumps_pp(rsp, 4);
159+                *body  = xs_json_dumps(rsp, 4);
160                 *ctype = "application/json";
161                 status = 200;
162             }
163@@ -2157,7 +2157,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
164                 }
165 
166                 if (out != NULL) {
167-                    *body  = xs_json_dumps_pp(out, 4);
168+                    *body  = xs_json_dumps(out, 4);
169                     *ctype = "application/json";
170                     status = 200;
171                 }
172@@ -2226,7 +2226,7 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
173                 rsp = xs_dict_append(rsp, "remote_url",  url);
174                 rsp = xs_dict_append(rsp, "description", desc);
175 
176-                *body  = xs_json_dumps_pp(rsp, 4);
177+                *body  = xs_json_dumps(rsp, 4);
178                 *ctype = "application/json";
179                 status = 200;
180             }
+1, -1
1@@ -312,7 +312,7 @@ int snac_upgrade(xs_str **error)
2         FILE *f;
3 
4         if ((f = fopen(fn, "w")) != NULL) {
5-            xs_json_dump_pp(srv_config, 4, f);
6+            xs_json_dump(srv_config, 4, f);
7             fclose(f);
8 
9             srv_log(xs_fmt("disk layout upgraded %s after %d changes", fn, changed));
+4, -4
 1@@ -194,7 +194,7 @@ int snac_init(const char *basedir)
 2         return 1;
 3     }
 4 
 5-    xs_json_dump_pp(srv_config, 4, f);
 6+    xs_json_dump(srv_config, 4, f);
 7     fclose(f);
 8 
 9     printf("Done.\n");
10@@ -275,7 +275,7 @@ int adduser(const char *uid)
11         return 1;
12     }
13     else {
14-        xs_json_dump_pp(config, 4, f);
15+        xs_json_dump(config, 4, f);
16         fclose(f);
17     }
18 
19@@ -290,7 +290,7 @@ int adduser(const char *uid)
20         return 1;
21     }
22     else {
23-        xs_json_dump_pp(key, 4, f);
24+        xs_json_dump(key, 4, f);
25         fclose(f);
26     }
27 
28@@ -316,7 +316,7 @@ int resetpwd(snac *snac)
29     snac->config = xs_dict_set(snac->config, "passwd", hashed_pwd);
30 
31     if ((f = fopen(fn, "w")) != NULL) {
32-        xs_json_dump_pp(snac->config, 4, f);
33+        xs_json_dump(snac->config, 4, f);
34         fclose(f);
35 
36         printf("New password for user %s is %s\n", snac->uid, clear_pwd);
+1, -1
1@@ -184,7 +184,7 @@ int webfinger_get_handler(d_char *req, char *q_path,
2         obj = xs_dict_append(obj, "subject", acct);
3         obj = xs_dict_append(obj, "links",   links);
4 
5-        j = xs_json_dumps_pp(obj, 4);
6+        j = xs_json_dumps(obj, 4);
7 
8         user_free(&snac);
9 
+5, -5
 1@@ -4,8 +4,8 @@
 2 
 3 #define _XS_JSON_H
 4 
 5-int xs_json_dump_pp(const xs_val *data, int indent, FILE *f);
 6-xs_str *xs_json_dumps_pp(const xs_val *data, int indent);
 7+int xs_json_dump(const xs_val *data, int indent, FILE *f);
 8+xs_str *xs_json_dumps(const xs_val *data, int indent);
 9 xs_val *xs_json_loads(const xs_str *json);
10 xs_val *xs_json_load(FILE *f);
11 
12@@ -141,7 +141,7 @@ static void _xs_json_dump(const xs_val *s_data, int level, int indent, FILE *f)
13 }
14 
15 
16-xs_str *xs_json_dumps_pp(const xs_val *data, int indent)
17+xs_str *xs_json_dumps(const xs_val *data, int indent)
18 /* dumps data as a JSON string */
19 {
20     xs_str *s = NULL;
21@@ -149,7 +149,7 @@ xs_str *xs_json_dumps_pp(const xs_val *data, int indent)
22     FILE *f;
23 
24     if ((f = open_memstream(&s, &sz)) != NULL) {
25-        int r = xs_json_dump_pp(data, indent, f);
26+        int r = xs_json_dump(data, indent, f);
27         fclose(f);
28 
29         if (!r)
30@@ -160,7 +160,7 @@ xs_str *xs_json_dumps_pp(const xs_val *data, int indent)
31 }
32 
33 
34-int xs_json_dump_pp(const xs_val *data, int indent, FILE *f)
35+int xs_json_dump(const xs_val *data, int indent, FILE *f)
36 /* dumps data into a file as JSON */
37 {
38     xstype t = xs_type(data);
+1, -1
1@@ -1 +1 @@
2-/* 568c95296bb7d5b40e35e49220403358bc7dadfc */
3+/* 4d883b5331e9275f2439b0983a0f978d1cd21e11 */