commit 5325da0

default  ·  2023-05-12 10:29:24 +0000 UTC
parent d35c949
Added some code comments.
1 files changed,  +36, -44
+36, -44
  1@@ -191,7 +191,7 @@ int oauth_get_handler(const xs_dict *req, const char *q_path,
  2 
  3     srv_debug(1, xs_fmt("oauth_get_handler %s", q_path));
  4 
  5-    if (strcmp(cmd, "/authorize") == 0) {
  6+    if (strcmp(cmd, "/authorize") == 0) { /** **/
  7         const char *cid   = xs_dict_get(msg, "client_id");
  8         const char *ruri  = xs_dict_get(msg, "redirect_uri");
  9         const char *rtype = xs_dict_get(msg, "response_type");
 10@@ -222,7 +222,7 @@ int oauth_get_handler(const xs_dict *req, const char *q_path,
 11             srv_debug(1, xs_fmt("oauth authorize: invalid or unset arguments"));
 12     }
 13     else
 14-    if (strcmp(cmd, "/x-snac-get-token") == 0) {
 15+    if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/
 16         const char *host = xs_dict_get(srv_config, "host");
 17 
 18         *body  = xs_fmt(login_page, host, "", host, "oauth/x-snac-get-token",
 19@@ -265,7 +265,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
 20 
 21     srv_debug(1, xs_fmt("oauth_post_handler %s", q_path));
 22 
 23-    if (strcmp(cmd, "/x-snac-login") == 0) {
 24+    if (strcmp(cmd, "/x-snac-login") == 0) { /** **/
 25         const char *login  = xs_dict_get(args, "login");
 26         const char *passwd = xs_dict_get(args, "passwd");
 27         const char *redir  = xs_dict_get(args, "redir");
 28@@ -325,7 +325,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
 29             srv_debug(1, xs_fmt("oauth x-snac-login: invalid or unset arguments"));
 30     }
 31     else
 32-    if (strcmp(cmd, "/token") == 0) {
 33+    if (strcmp(cmd, "/token") == 0) { /** **/
 34         xs *wrk = NULL;
 35         const char *gtype = xs_dict_get(args, "grant_type");
 36         const char *code  = xs_dict_get(args, "code");
 37@@ -408,7 +408,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
 38         }
 39     }
 40     else
 41-    if (strcmp(cmd, "/revoke") == 0) {
 42+    if (strcmp(cmd, "/revoke") == 0) { /** **/
 43         const char *cid   = xs_dict_get(args, "client_id");
 44         const char *csec  = xs_dict_get(args, "client_secret");
 45         const char *tokid = xs_dict_get(args, "token");
 46@@ -437,7 +437,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
 47             status = 403;
 48         }
 49     }
 50-    if (strcmp(cmd, "/x-snac-get-token") == 0) {
 51+    if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/
 52         const char *login  = xs_dict_get(args, "login");
 53         const char *passwd = xs_dict_get(args, "passwd");
 54 
 55@@ -590,8 +590,6 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
 56 
 57     xs *acct = mastoapi_account(actor);
 58 
 59-    /** shave the yak converting an ActivityPub Note to a Mastodon status **/
 60-
 61     xs *f   = xs_val_new(XSTYPE_FALSE);
 62     xs *t   = xs_val_new(XSTYPE_TRUE);
 63     xs *n   = xs_val_new(XSTYPE_NULL);
 64@@ -890,7 +888,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 65     snac snac1 = {0};
 66     int logged_in = process_auth_token(&snac1, req);
 67 
 68-    if (strcmp(cmd, "/v1/accounts/verify_credentials") == 0) {
 69+    if (strcmp(cmd, "/v1/accounts/verify_credentials") == 0) { /** **/
 70         if (logged_in) {
 71             xs *acct = xs_dict_new();
 72 
 73@@ -922,7 +920,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 74         }
 75     }
 76     else
 77-    if (strcmp(cmd, "/v1/accounts/relationships") == 0) {
 78+    if (strcmp(cmd, "/v1/accounts/relationships") == 0) { /** **/
 79         /* find if an account is followed, blocked, etc. */
 80         /* the account to get relationships about is in args "id[]" */
 81 
 82@@ -948,7 +946,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 83             status = 422;
 84     }
 85     else
 86-    if (xs_startswith(cmd, "/v1/accounts/")) {
 87+    if (xs_startswith(cmd, "/v1/accounts/")) { /** **/
 88         /* account-related information */
 89         xs *l = xs_split(cmd, "/");
 90         const char *uid = xs_list_get(l, 3);
 91@@ -1015,7 +1013,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 92         }
 93     }
 94     else
 95-    if (strcmp(cmd, "/v1/timelines/home") == 0) {
 96+    if (strcmp(cmd, "/v1/timelines/home") == 0) { /** **/
 97         /* the private timeline */
 98         if (logged_in) {
 99             const char *max_id   = xs_dict_get(args, "max_id");
100@@ -1097,7 +1095,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
101         }
102     }
103     else
104-    if (strcmp(cmd, "/v1/timelines/public") == 0) {
105+    if (strcmp(cmd, "/v1/timelines/public") == 0) { /** **/
106         /* the instance public timeline (public timelines for all users) */
107 
108         /* NOTE: this api call needs no authorization; but,
109@@ -1145,14 +1143,14 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
110         status = 200;
111     }
112     else
113-    if (strcmp(cmd, "/v1/conversations") == 0) {
114+    if (strcmp(cmd, "/v1/conversations") == 0) { /** **/
115         /* TBD */
116         *body  = xs_dup("[]");
117         *ctype = "application/json";
118         status = 200;
119     }
120     else
121-    if (strcmp(cmd, "/v1/notifications") == 0) {
122+    if (strcmp(cmd, "/v1/notifications") == 0) { /** **/
123         if (logged_in) {
124             xs *l      = notify_list(&snac1, 0);
125             xs *out    = xs_list_new();
126@@ -1227,63 +1225,63 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
127             status = 401;
128     }
129     else
130-    if (strcmp(cmd, "/v1/filters") == 0) {
131+    if (strcmp(cmd, "/v1/filters") == 0) { /** **/
132         /* snac will never have filters */
133         *body  = xs_dup("[]");
134         *ctype = "application/json";
135         status = 200;
136     }
137     else
138-    if (strcmp(cmd, "/v1/favourites") == 0) {
139+    if (strcmp(cmd, "/v1/favourites") == 0) { /** **/
140         /* snac will never support a list of favourites */
141         *body  = xs_dup("[]");
142         *ctype = "application/json";
143         status = 200;
144     }
145     else
146-    if (strcmp(cmd, "/v1/bookmarks") == 0) {
147+    if (strcmp(cmd, "/v1/bookmarks") == 0) { /** **/
148         /* snac does not support bookmarks */
149         *body  = xs_dup("[]");
150         *ctype = "application/json";
151         status = 200;
152     }
153     else
154-    if (strcmp(cmd, "/v1/lists") == 0) {
155+    if (strcmp(cmd, "/v1/lists") == 0) { /** **/
156         /* snac does not support lists */
157         *body  = xs_dup("[]");
158         *ctype = "application/json";
159         status = 200;
160     }
161     else
162-    if (strcmp(cmd, "/v1/scheduled_statuses") == 0) {
163-        /* snac does not scheduled notes */
164+    if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/
165+        /* snac does not schedule notes */
166         *body  = xs_dup("[]");
167         *ctype = "application/json";
168         status = 200;
169     }
170     else
171-    if (strcmp(cmd, "/v1/follow_requests") == 0) {
172+    if (strcmp(cmd, "/v1/follow_requests") == 0) { /** **/
173         /* snac does not support optional follow confirmations */
174         *body  = xs_dup("[]");
175         *ctype = "application/json";
176         status = 200;
177     }
178     else
179-    if (strcmp(cmd, "/v1/announcements") == 0) {
180+    if (strcmp(cmd, "/v1/announcements") == 0) { /** **/
181         /* snac has no announcements (yet?) */
182         *body  = xs_dup("[]");
183         *ctype = "application/json";
184         status = 200;
185     }
186     else
187-    if (strcmp(cmd, "/v1/custom_emojis") == 0) {
188+    if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/
189         /* are you kidding me? */
190         *body  = xs_dup("[]");
191         *ctype = "application/json";
192         status = 200;
193     }
194     else
195-    if (strcmp(cmd, "/v1/instance") == 0) {
196+    if (strcmp(cmd, "/v1/instance") == 0) { /** **/
197         /* returns an instance object */
198         xs *ins = xs_dict_new();
199         const char *host = xs_dict_get(srv_config, "host");
200@@ -1363,7 +1361,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
201         status = 200;
202     }
203     else
204-    if (xs_startswith(cmd, "/v1/statuses/")) {
205+    if (xs_startswith(cmd, "/v1/statuses/")) { /** **/
206         /* information about a status */
207         xs *l = xs_split(cmd, "/");
208         const char *id = xs_list_get(l, 3);
209@@ -1461,31 +1459,25 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
210         }
211     }
212     else
213-    if (strcmp(cmd, "/v1/filters") == 0) {
214-        *body  = xs_dup("[]");
215-        *ctype = "application/json";
216-        status = 200;
217-    }
218-    else
219-    if (strcmp(cmd, "/v1/preferences") == 0) {
220+    if (strcmp(cmd, "/v1/preferences") == 0) { /** **/
221         *body  = xs_dup("{}");
222         *ctype = "application/json";
223         status = 200;
224     }
225     else
226-    if (strcmp(cmd, "/v1/markers") == 0) {
227+    if (strcmp(cmd, "/v1/markers") == 0) { /** **/
228         *body  = xs_dup("{}");
229         *ctype = "application/json";
230         status = 200;
231     }
232     else
233-    if (strcmp(cmd, "/v1/followed_tags") == 0) {
234+    if (strcmp(cmd, "/v1/followed_tags") == 0) { /** **/
235         *body  = xs_dup("[]");
236         *ctype = "application/json";
237         status = 200;
238     }
239     else
240-    if (strcmp(cmd, "/v2/search") == 0) {
241+    if (strcmp(cmd, "/v2/search") == 0) { /** **/
242         const char *q      = xs_dict_get(args, "q");
243         const char *type   = xs_dict_get(args, "type");
244         const char *offset = xs_dict_get(args, "offset");
245@@ -1571,7 +1563,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
246     snac snac = {0};
247     int logged_in = process_auth_token(&snac, req);
248 
249-    if (strcmp(cmd, "/v1/apps") == 0) {
250+    if (strcmp(cmd, "/v1/apps") == 0) { /** **/
251         const char *name  = xs_dict_get(args, "client_name");
252         const char *ruri  = xs_dict_get(args, "redirect_uris");
253         const char *scope = xs_dict_get(args, "scope");
254@@ -1619,7 +1611,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
255         }
256     }
257     else
258-    if (strcmp(cmd, "/v1/statuses") == 0) {
259+    if (strcmp(cmd, "/v1/statuses") == 0) { /** **/
260         if (logged_in) {
261             /* post a new Note */
262 /*    {
263@@ -1706,7 +1698,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
264             status = 401;
265     }
266     else
267-    if (xs_startswith(cmd, "/v1/statuses")) {
268+    if (xs_startswith(cmd, "/v1/statuses")) { /** **/
269         if (logged_in) {
270             /* operations on a status */
271             xs *l = xs_split(cmd, "/");
272@@ -1798,7 +1790,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
273             status = 401;
274     }
275     else
276-    if (strcmp(cmd, "/v1/notifications/clear") == 0) {
277+    if (strcmp(cmd, "/v1/notifications/clear") == 0) { /** **/
278         if (logged_in) {
279             notify_clear(&snac);
280             timeline_touch(&snac);
281@@ -1811,7 +1803,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
282             status = 401;
283     }
284     else
285-    if (strcmp(cmd, "/v1/push/subscription") == 0) {
286+    if (strcmp(cmd, "/v1/push/subscription") == 0) { /** **/
287         /* I don't know what I'm doing */
288         if (logged_in) {
289             char *v;
290@@ -1839,7 +1831,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
291             status = 401;
292     }
293     else
294-    if (strcmp(cmd, "/v1/media") == 0 || strcmp(cmd, "/v2/media") == 0) {
295+    if (strcmp(cmd, "/v1/media") == 0 || strcmp(cmd, "/v2/media") == 0) { /** **/
296         if (logged_in) {
297 /*    {
298         xs *j = xs_json_dumps_pp(args, 4);
299@@ -1888,7 +1880,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
300             status = 401;
301     }
302     else
303-    if (xs_startswith(cmd, "/v1/accounts")) {
304+    if (xs_startswith(cmd, "/v1/accounts")) { /** **/
305         if (logged_in) {
306             /* account-related information */
307             xs *l = xs_split(cmd, "/");
308@@ -1993,7 +1985,7 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
309     snac snac = {0};
310     int logged_in = process_auth_token(&snac, req);
311 
312-    if (xs_startswith(cmd, "/v1/media") || xs_startswith(cmd, "/v2/media")) {
313+    if (xs_startswith(cmd, "/v1/media") || xs_startswith(cmd, "/v2/media")) { /** **/
314         if (logged_in) {
315             xs *l = xs_split(cmd, "/");
316             const char *stid = xs_list_get(l, 3);