commit 478cb2c
default
·
2023-06-15 15:51:24 +0000 UTC
parent 8d9289a
Use xs_stock_* values wherever possible.
2 files changed,
+38,
-52
M
html.c
M
html.c
+5,
-9
1@@ -1851,9 +1851,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
2 msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv);
3
4 if (sensitive != NULL) {
5- xs *t = xs_val_new(XSTYPE_TRUE);
6-
7- msg = xs_dict_set(msg, "sensitive", t);
8+ msg = xs_dict_set(msg, "sensitive", xs_stock_true);
9 msg = xs_dict_set(msg, "summary", "...");
10 }
11
12@@ -2010,8 +2008,6 @@ int html_post_handler(const xs_dict *req, const char *q_path,
13 /* change of user data */
14 char *v;
15 char *p1, *p2;
16- xs *byes = xs_val_new(XSTYPE_TRUE);
17- xs *bno = xs_val_new(XSTYPE_FALSE);
18
19 if ((v = xs_dict_get(p_vars, "name")) != NULL)
20 snac.config = xs_dict_set(snac.config, "name", v);
21@@ -2036,13 +2032,13 @@ int html_post_handler(const xs_dict *req, const char *q_path,
22 snac.config = xs_dict_set(snac.config, "purge_days", days);
23 }
24 if ((v = xs_dict_get(p_vars, "drop_dm_from_unknown")) != NULL && strcmp(v, "on") == 0)
25- snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", byes);
26+ snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", xs_stock_true);
27 else
28- snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", bno);
29+ snac.config = xs_dict_set(snac.config, "drop_dm_from_unknown", xs_stock_false);
30 if ((v = xs_dict_get(p_vars, "bot")) != NULL && strcmp(v, "on") == 0)
31- snac.config = xs_dict_set(snac.config, "bot", byes);
32+ snac.config = xs_dict_set(snac.config, "bot", xs_stock_true);
33 else
34- snac.config = xs_dict_set(snac.config, "bot", bno);
35+ snac.config = xs_dict_set(snac.config, "bot", xs_stock_false);
36
37 /* avatar upload */
38 xs_list *avatar_file = xs_dict_get(p_vars, "avatar_file");
+33,
-43
1@@ -523,9 +523,9 @@ xs_dict *mastoapi_account(const xs_dict *actor)
2 note = "";
3
4 if (strcmp(xs_dict_get(actor, "type"), "Service") == 0)
5- acct = xs_dict_append(acct, "bot", "true");
6+ acct = xs_dict_append(acct, "bot", xs_stock_true);
7 else
8- acct = xs_dict_append(acct, "bot", "false");
9+ acct = xs_dict_append(acct, "bot", xs_stock_false);
10
11 acct = xs_dict_append(acct, "note", note);
12
13@@ -559,7 +559,6 @@ xs_dict *mastoapi_account(const xs_dict *actor)
14 if (!xs_is_null(p = xs_dict_get(actor, "tag"))) {
15 xs *eml = xs_list_new();
16 xs_dict *v;
17- xs *t = xs_val_new(XSTYPE_TRUE);
18
19 while (xs_list_iter(&p, &v)) {
20 const char *type = xs_dict_get(v, "type");
21@@ -578,7 +577,7 @@ xs_dict *mastoapi_account(const xs_dict *actor)
22 d1 = xs_dict_append(d1, "shortcode", nm);
23 d1 = xs_dict_append(d1, "url", url);
24 d1 = xs_dict_append(d1, "static_url", url);
25- d1 = xs_dict_append(d1, "visible_in_picker", t);
26+ d1 = xs_dict_append(d1, "visible_in_picker", xs_stock_true);
27
28 eml = xs_list_append(eml, d1);
29 }
30@@ -598,8 +597,6 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg)
31 {
32 xs_dict *poll = xs_dict_new();
33 xs *mid = mastoapi_id(msg);
34- xs *f = xs_val_new(XSTYPE_FALSE);
35- xs *t = xs_val_new(XSTYPE_TRUE);
36 xs_list *opts = NULL;
37 xs_val *v;
38 int num_votes = 0;
39@@ -607,13 +604,14 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg)
40
41 poll = xs_dict_append(poll, "id", mid);
42 poll = xs_dict_append(poll, "expires_at", xs_dict_get(msg, "endTime"));
43- poll = xs_dict_append(poll, "expired", xs_dict_get(msg, "closed") != NULL ? t : f);
44+ poll = xs_dict_append(poll, "expired",
45+ xs_dict_get(msg, "closed") != NULL ? xs_stock_true : xs_stock_false);
46
47 if ((opts = xs_dict_get(msg, "oneOf")) != NULL)
48- poll = xs_dict_append(poll, "multiple", f);
49+ poll = xs_dict_append(poll, "multiple", xs_stock_false);
50 else {
51 opts = xs_dict_get(msg, "anyOf");
52- poll = xs_dict_append(poll, "multiple", t);
53+ poll = xs_dict_append(poll, "multiple", xs_stock_true);
54 }
55
56 while (xs_list_iter(&opts, &v)) {
57@@ -639,7 +637,7 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg)
58 poll = xs_dict_append(poll, "votes_count", vc);
59
60 poll = xs_dict_append(poll, "voted",
61- was_question_voted(snac, xs_dict_get(msg, "id")) ? t : f);
62+ was_question_voted(snac, xs_dict_get(msg, "id")) ? xs_stock_true : xs_stock_false);
63
64 return poll;
65 }
66@@ -660,9 +658,6 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
67
68 xs *acct = mastoapi_account(actor);
69
70- xs *f = xs_val_new(XSTYPE_FALSE);
71- xs *t = xs_val_new(XSTYPE_TRUE);
72- xs *n = xs_val_new(XSTYPE_NULL);
73 xs *idx = NULL;
74 xs *ixc = NULL;
75 char *tmp;
76@@ -682,7 +677,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
77
78 tmp = xs_dict_get(msg, "sensitive");
79 if (xs_is_null(tmp))
80- tmp = f;
81+ tmp = xs_stock_false;
82
83 st = xs_dict_append(st, "sensitive", tmp);
84
85@@ -781,12 +776,11 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
86
87 if (!xs_is_null(url)) {
88 xs *nm = xs_strip_chars_i(xs_dup(name), ":");
89- xs *t = xs_val_new(XSTYPE_TRUE);
90
91 d1 = xs_dict_append(d1, "shortcode", nm);
92 d1 = xs_dict_append(d1, "url", url);
93 d1 = xs_dict_append(d1, "static_url", url);
94- d1 = xs_dict_append(d1, "visible_in_picker", t);
95+ d1 = xs_dict_append(d1, "visible_in_picker", xs_stock_true);
96 d1 = xs_dict_append(d1, "category", "Emojis");
97
98 eml = xs_list_append(eml, d1);
99@@ -807,7 +801,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
100
101 st = xs_dict_append(st, "favourites_count", ixc);
102 st = xs_dict_append(st, "favourited",
103- xs_list_in(idx, snac->md5) != -1 ? t : f);
104+ xs_list_in(idx, snac->md5) != -1 ? xs_stock_true : xs_stock_false);
105
106 xs_free(idx);
107 xs_free(ixc);
108@@ -816,7 +810,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
109
110 st = xs_dict_append(st, "reblogs_count", ixc);
111 st = xs_dict_append(st, "reblogged",
112- xs_list_in(idx, snac->md5) != -1 ? t : f);
113+ xs_list_in(idx, snac->md5) != -1 ? xs_stock_true : xs_stock_false);
114
115 xs_free(idx);
116 xs_free(ixc);
117@@ -826,8 +820,8 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
118 st = xs_dict_append(st, "replies_count", ixc);
119
120 /* default in_reply_to values */
121- st = xs_dict_append(st, "in_reply_to_id", n);
122- st = xs_dict_append(st, "in_reply_to_account_id", n);
123+ st = xs_dict_append(st, "in_reply_to_id", xs_stock_null);
124+ st = xs_dict_append(st, "in_reply_to_account_id", xs_stock_null);
125
126 tmp = xs_dict_get(msg, "inReplyTo");
127 if (!xs_is_null(tmp)) {
128@@ -845,10 +839,10 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
129 }
130 }
131
132- st = xs_dict_append(st, "reblog", n);
133- st = xs_dict_append(st, "poll", n);
134- st = xs_dict_append(st, "card", n);
135- st = xs_dict_append(st, "language", n);
136+ st = xs_dict_append(st, "reblog", xs_stock_null);
137+ st = xs_dict_append(st, "poll", xs_stock_null);
138+ st = xs_dict_append(st, "card", xs_stock_null);
139+ st = xs_dict_append(st, "language", xs_stock_null);
140
141 tmp = xs_dict_get(msg, "sourceContent");
142 if (xs_is_null(tmp))
143@@ -858,7 +852,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
144
145 tmp = xs_dict_get(msg, "updated");
146 if (xs_is_null(tmp))
147- tmp = n;
148+ tmp = xs_stock_null;
149
150 st = xs_dict_append(st, "edited_at", tmp);
151
152@@ -877,29 +871,27 @@ xs_dict *mastoapi_relationship(snac *snac, const char *md5)
153 xs *actor_o = NULL;
154
155 if (valid_status(object_get_by_md5(md5, &actor_o))) {
156- xs *t = xs_val_new(XSTYPE_TRUE);
157- xs *f = xs_val_new(XSTYPE_FALSE);
158 rel = xs_dict_new();
159
160 const char *actor = xs_dict_get(actor_o, "id");
161
162 rel = xs_dict_append(rel, "id", md5);
163 rel = xs_dict_append(rel, "following",
164- following_check(snac, actor) ? t : f);
165+ following_check(snac, actor) ? xs_stock_true : xs_stock_false);
166
167- rel = xs_dict_append(rel, "showing_reblogs", t);
168- rel = xs_dict_append(rel, "notifying", f);
169+ rel = xs_dict_append(rel, "showing_reblogs", xs_stock_true);
170+ rel = xs_dict_append(rel, "notifying", xs_stock_false);
171 rel = xs_dict_append(rel, "followed_by",
172- follower_check(snac, actor) ? t : f);
173+ follower_check(snac, actor) ? xs_stock_true : xs_stock_false);
174
175 rel = xs_dict_append(rel, "blocking",
176- is_muted(snac, actor) ? t : f);
177+ is_muted(snac, actor) ? xs_stock_true : xs_stock_false);
178
179- rel = xs_dict_append(rel, "muting", f);
180- rel = xs_dict_append(rel, "muting_notifications", f);
181- rel = xs_dict_append(rel, "requested", f);
182- rel = xs_dict_append(rel, "domain_blocking", f);
183- rel = xs_dict_append(rel, "endorsed", f);
184+ rel = xs_dict_append(rel, "muting", xs_stock_false);
185+ rel = xs_dict_append(rel, "muting_notifications", xs_stock_false);
186+ rel = xs_dict_append(rel, "requested", xs_stock_false);
187+ rel = xs_dict_append(rel, "domain_blocking", xs_stock_false);
188+ rel = xs_dict_append(rel, "endorsed", xs_stock_false);
189 rel = xs_dict_append(rel, "note", "");
190 }
191
192@@ -1482,10 +1474,9 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
193 d1 = xs_dict_append(d1, "domain_count", z);
194 ins = xs_dict_append(ins, "stats", d1);
195
196- xs *f = xs_val_new(XSTYPE_FALSE);
197- ins = xs_dict_append(ins, "registrations", f);
198- ins = xs_dict_append(ins, "approval_required", f);
199- ins = xs_dict_append(ins, "invites_enabled", f);
200+ ins = xs_dict_append(ins, "registrations", xs_stock_false);
201+ ins = xs_dict_append(ins, "approval_required", xs_stock_false);
202+ ins = xs_dict_append(ins, "invites_enabled", xs_stock_false);
203
204 xs *cfg = xs_dict_new();
205
206@@ -1846,8 +1837,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
207 strcmp(visibility, "public") == 0 ? 0 : 1);
208
209 if (!xs_is_null(summary) && *summary) {
210- xs *t = xs_val_new(XSTYPE_TRUE);
211- msg = xs_dict_set(msg, "sensitive", t);
212+ msg = xs_dict_set(msg, "sensitive", xs_stock_true);
213 msg = xs_dict_set(msg, "summary", summary);
214 }
215