summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-05-12 12:29:24 +0200
committerGravatar default2023-05-12 12:29:24 +0200
commit5325da02e6d25589a3b04dcc1a3a78973762aa8b (patch)
tree0772efaa56b1dddb605ea371b420dca893a79460
parentResolve (partially) the issue with mentions without server. (diff)
downloadsnac2-5325da02e6d25589a3b04dcc1a3a78973762aa8b.tar.gz
snac2-5325da02e6d25589a3b04dcc1a3a78973762aa8b.tar.xz
snac2-5325da02e6d25589a3b04dcc1a3a78973762aa8b.zip
Added some code comments.
-rw-r--r--mastoapi.c80
1 files changed, 36 insertions, 44 deletions
diff --git a/mastoapi.c b/mastoapi.c
index c738841..812636f 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -191,7 +191,7 @@ int oauth_get_handler(const xs_dict *req, const char *q_path,
191 191
192 srv_debug(1, xs_fmt("oauth_get_handler %s", q_path)); 192 srv_debug(1, xs_fmt("oauth_get_handler %s", q_path));
193 193
194 if (strcmp(cmd, "/authorize") == 0) { 194 if (strcmp(cmd, "/authorize") == 0) { /** **/
195 const char *cid = xs_dict_get(msg, "client_id"); 195 const char *cid = xs_dict_get(msg, "client_id");
196 const char *ruri = xs_dict_get(msg, "redirect_uri"); 196 const char *ruri = xs_dict_get(msg, "redirect_uri");
197 const char *rtype = xs_dict_get(msg, "response_type"); 197 const char *rtype = xs_dict_get(msg, "response_type");
@@ -222,7 +222,7 @@ int oauth_get_handler(const xs_dict *req, const char *q_path,
222 srv_debug(1, xs_fmt("oauth authorize: invalid or unset arguments")); 222 srv_debug(1, xs_fmt("oauth authorize: invalid or unset arguments"));
223 } 223 }
224 else 224 else
225 if (strcmp(cmd, "/x-snac-get-token") == 0) { 225 if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/
226 const char *host = xs_dict_get(srv_config, "host"); 226 const char *host = xs_dict_get(srv_config, "host");
227 227
228 *body = xs_fmt(login_page, host, "", host, "oauth/x-snac-get-token", 228 *body = xs_fmt(login_page, host, "", host, "oauth/x-snac-get-token",
@@ -265,7 +265,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
265 265
266 srv_debug(1, xs_fmt("oauth_post_handler %s", q_path)); 266 srv_debug(1, xs_fmt("oauth_post_handler %s", q_path));
267 267
268 if (strcmp(cmd, "/x-snac-login") == 0) { 268 if (strcmp(cmd, "/x-snac-login") == 0) { /** **/
269 const char *login = xs_dict_get(args, "login"); 269 const char *login = xs_dict_get(args, "login");
270 const char *passwd = xs_dict_get(args, "passwd"); 270 const char *passwd = xs_dict_get(args, "passwd");
271 const char *redir = xs_dict_get(args, "redir"); 271 const char *redir = xs_dict_get(args, "redir");
@@ -325,7 +325,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
325 srv_debug(1, xs_fmt("oauth x-snac-login: invalid or unset arguments")); 325 srv_debug(1, xs_fmt("oauth x-snac-login: invalid or unset arguments"));
326 } 326 }
327 else 327 else
328 if (strcmp(cmd, "/token") == 0) { 328 if (strcmp(cmd, "/token") == 0) { /** **/
329 xs *wrk = NULL; 329 xs *wrk = NULL;
330 const char *gtype = xs_dict_get(args, "grant_type"); 330 const char *gtype = xs_dict_get(args, "grant_type");
331 const char *code = xs_dict_get(args, "code"); 331 const char *code = xs_dict_get(args, "code");
@@ -408,7 +408,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
408 } 408 }
409 } 409 }
410 else 410 else
411 if (strcmp(cmd, "/revoke") == 0) { 411 if (strcmp(cmd, "/revoke") == 0) { /** **/
412 const char *cid = xs_dict_get(args, "client_id"); 412 const char *cid = xs_dict_get(args, "client_id");
413 const char *csec = xs_dict_get(args, "client_secret"); 413 const char *csec = xs_dict_get(args, "client_secret");
414 const char *tokid = xs_dict_get(args, "token"); 414 const char *tokid = xs_dict_get(args, "token");
@@ -437,7 +437,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
437 status = 403; 437 status = 403;
438 } 438 }
439 } 439 }
440 if (strcmp(cmd, "/x-snac-get-token") == 0) { 440 if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/
441 const char *login = xs_dict_get(args, "login"); 441 const char *login = xs_dict_get(args, "login");
442 const char *passwd = xs_dict_get(args, "passwd"); 442 const char *passwd = xs_dict_get(args, "passwd");
443 443
@@ -590,8 +590,6 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
590 590
591 xs *acct = mastoapi_account(actor); 591 xs *acct = mastoapi_account(actor);
592 592
593 /** shave the yak converting an ActivityPub Note to a Mastodon status **/
594
595 xs *f = xs_val_new(XSTYPE_FALSE); 593 xs *f = xs_val_new(XSTYPE_FALSE);
596 xs *t = xs_val_new(XSTYPE_TRUE); 594 xs *t = xs_val_new(XSTYPE_TRUE);
597 xs *n = xs_val_new(XSTYPE_NULL); 595 xs *n = xs_val_new(XSTYPE_NULL);
@@ -890,7 +888,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
890 snac snac1 = {0}; 888 snac snac1 = {0};
891 int logged_in = process_auth_token(&snac1, req); 889 int logged_in = process_auth_token(&snac1, req);
892 890
893 if (strcmp(cmd, "/v1/accounts/verify_credentials") == 0) { 891 if (strcmp(cmd, "/v1/accounts/verify_credentials") == 0) { /** **/
894 if (logged_in) { 892 if (logged_in) {
895 xs *acct = xs_dict_new(); 893 xs *acct = xs_dict_new();
896 894
@@ -922,7 +920,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
922 } 920 }
923 } 921 }
924 else 922 else
925 if (strcmp(cmd, "/v1/accounts/relationships") == 0) { 923 if (strcmp(cmd, "/v1/accounts/relationships") == 0) { /** **/
926 /* find if an account is followed, blocked, etc. */ 924 /* find if an account is followed, blocked, etc. */
927 /* the account to get relationships about is in args "id[]" */ 925 /* the account to get relationships about is in args "id[]" */
928 926
@@ -948,7 +946,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
948 status = 422; 946 status = 422;
949 } 947 }
950 else 948 else
951 if (xs_startswith(cmd, "/v1/accounts/")) { 949 if (xs_startswith(cmd, "/v1/accounts/")) { /** **/
952 /* account-related information */ 950 /* account-related information */
953 xs *l = xs_split(cmd, "/"); 951 xs *l = xs_split(cmd, "/");
954 const char *uid = xs_list_get(l, 3); 952 const char *uid = xs_list_get(l, 3);
@@ -1015,7 +1013,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1015 } 1013 }
1016 } 1014 }
1017 else 1015 else
1018 if (strcmp(cmd, "/v1/timelines/home") == 0) { 1016 if (strcmp(cmd, "/v1/timelines/home") == 0) { /** **/
1019 /* the private timeline */ 1017 /* the private timeline */
1020 if (logged_in) { 1018 if (logged_in) {
1021 const char *max_id = xs_dict_get(args, "max_id"); 1019 const char *max_id = xs_dict_get(args, "max_id");
@@ -1097,7 +1095,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1097 } 1095 }
1098 } 1096 }
1099 else 1097 else
1100 if (strcmp(cmd, "/v1/timelines/public") == 0) { 1098 if (strcmp(cmd, "/v1/timelines/public") == 0) { /** **/
1101 /* the instance public timeline (public timelines for all users) */ 1099 /* the instance public timeline (public timelines for all users) */
1102 1100
1103 /* NOTE: this api call needs no authorization; but, 1101 /* NOTE: this api call needs no authorization; but,
@@ -1145,14 +1143,14 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1145 status = 200; 1143 status = 200;
1146 } 1144 }
1147 else 1145 else
1148 if (strcmp(cmd, "/v1/conversations") == 0) { 1146 if (strcmp(cmd, "/v1/conversations") == 0) { /** **/
1149 /* TBD */ 1147 /* TBD */
1150 *body = xs_dup("[]"); 1148 *body = xs_dup("[]");
1151 *ctype = "application/json"; 1149 *ctype = "application/json";
1152 status = 200; 1150 status = 200;
1153 } 1151 }
1154 else 1152 else
1155 if (strcmp(cmd, "/v1/notifications") == 0) { 1153 if (strcmp(cmd, "/v1/notifications") == 0) { /** **/
1156 if (logged_in) { 1154 if (logged_in) {
1157 xs *l = notify_list(&snac1, 0); 1155 xs *l = notify_list(&snac1, 0);
1158 xs *out = xs_list_new(); 1156 xs *out = xs_list_new();
@@ -1227,63 +1225,63 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1227 status = 401; 1225 status = 401;
1228 } 1226 }
1229 else 1227 else
1230 if (strcmp(cmd, "/v1/filters") == 0) { 1228 if (strcmp(cmd, "/v1/filters") == 0) { /** **/
1231 /* snac will never have filters */ 1229 /* snac will never have filters */
1232 *body = xs_dup("[]"); 1230 *body = xs_dup("[]");
1233 *ctype = "application/json"; 1231 *ctype = "application/json";
1234 status = 200; 1232 status = 200;
1235 } 1233 }
1236 else 1234 else
1237 if (strcmp(cmd, "/v1/favourites") == 0) { 1235 if (strcmp(cmd, "/v1/favourites") == 0) { /** **/
1238 /* snac will never support a list of favourites */ 1236 /* snac will never support a list of favourites */
1239 *body = xs_dup("[]"); 1237 *body = xs_dup("[]");
1240 *ctype = "application/json"; 1238 *ctype = "application/json";
1241 status = 200; 1239 status = 200;
1242 } 1240 }
1243 else 1241 else
1244 if (strcmp(cmd, "/v1/bookmarks") == 0) { 1242 if (strcmp(cmd, "/v1/bookmarks") == 0) { /** **/
1245 /* snac does not support bookmarks */ 1243 /* snac does not support bookmarks */
1246 *body = xs_dup("[]"); 1244 *body = xs_dup("[]");
1247 *ctype = "application/json"; 1245 *ctype = "application/json";
1248 status = 200; 1246 status = 200;
1249 } 1247 }
1250 else 1248 else
1251 if (strcmp(cmd, "/v1/lists") == 0) { 1249 if (strcmp(cmd, "/v1/lists") == 0) { /** **/
1252 /* snac does not support lists */ 1250 /* snac does not support lists */
1253 *body = xs_dup("[]"); 1251 *body = xs_dup("[]");
1254 *ctype = "application/json"; 1252 *ctype = "application/json";
1255 status = 200; 1253 status = 200;
1256 } 1254 }
1257 else 1255 else
1258 if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { 1256 if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/
1259 /* snac does not scheduled notes */ 1257 /* snac does not schedule notes */
1260 *body = xs_dup("[]"); 1258 *body = xs_dup("[]");
1261 *ctype = "application/json"; 1259 *ctype = "application/json";
1262 status = 200; 1260 status = 200;
1263 } 1261 }
1264 else 1262 else
1265 if (strcmp(cmd, "/v1/follow_requests") == 0) { 1263 if (strcmp(cmd, "/v1/follow_requests") == 0) { /** **/
1266 /* snac does not support optional follow confirmations */ 1264 /* snac does not support optional follow confirmations */
1267 *body = xs_dup("[]"); 1265 *body = xs_dup("[]");
1268 *ctype = "application/json"; 1266 *ctype = "application/json";
1269 status = 200; 1267 status = 200;
1270 } 1268 }
1271 else 1269 else
1272 if (strcmp(cmd, "/v1/announcements") == 0) { 1270 if (strcmp(cmd, "/v1/announcements") == 0) { /** **/
1273 /* snac has no announcements (yet?) */ 1271 /* snac has no announcements (yet?) */
1274 *body = xs_dup("[]"); 1272 *body = xs_dup("[]");
1275 *ctype = "application/json"; 1273 *ctype = "application/json";
1276 status = 200; 1274 status = 200;
1277 } 1275 }
1278 else 1276 else
1279 if (strcmp(cmd, "/v1/custom_emojis") == 0) { 1277 if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/
1280 /* are you kidding me? */ 1278 /* are you kidding me? */
1281 *body = xs_dup("[]"); 1279 *body = xs_dup("[]");
1282 *ctype = "application/json"; 1280 *ctype = "application/json";
1283 status = 200; 1281 status = 200;
1284 } 1282 }
1285 else 1283 else
1286 if (strcmp(cmd, "/v1/instance") == 0) { 1284 if (strcmp(cmd, "/v1/instance") == 0) { /** **/
1287 /* returns an instance object */ 1285 /* returns an instance object */
1288 xs *ins = xs_dict_new(); 1286 xs *ins = xs_dict_new();
1289 const char *host = xs_dict_get(srv_config, "host"); 1287 const char *host = xs_dict_get(srv_config, "host");
@@ -1363,7 +1361,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1363 status = 200; 1361 status = 200;
1364 } 1362 }
1365 else 1363 else
1366 if (xs_startswith(cmd, "/v1/statuses/")) { 1364 if (xs_startswith(cmd, "/v1/statuses/")) { /** **/
1367 /* information about a status */ 1365 /* information about a status */
1368 xs *l = xs_split(cmd, "/"); 1366 xs *l = xs_split(cmd, "/");
1369 const char *id = xs_list_get(l, 3); 1367 const char *id = xs_list_get(l, 3);
@@ -1461,31 +1459,25 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1461 } 1459 }
1462 } 1460 }
1463 else 1461 else
1464 if (strcmp(cmd, "/v1/filters") == 0) { 1462 if (strcmp(cmd, "/v1/preferences") == 0) { /** **/
1465 *body = xs_dup("[]");
1466 *ctype = "application/json";
1467 status = 200;
1468 }
1469 else
1470 if (strcmp(cmd, "/v1/preferences") == 0) {
1471 *body = xs_dup("{}"); 1463 *body = xs_dup("{}");
1472 *ctype = "application/json"; 1464 *ctype = "application/json";
1473 status = 200; 1465 status = 200;
1474 } 1466 }
1475 else 1467 else
1476 if (strcmp(cmd, "/v1/markers") == 0) { 1468 if (strcmp(cmd, "/v1/markers") == 0) { /** **/
1477 *body = xs_dup("{}"); 1469 *body = xs_dup("{}");
1478 *ctype = "application/json"; 1470 *ctype = "application/json";
1479 status = 200; 1471 status = 200;
1480 } 1472 }
1481 else 1473 else
1482 if (strcmp(cmd, "/v1/followed_tags") == 0) { 1474 if (strcmp(cmd, "/v1/followed_tags") == 0) { /** **/
1483 *body = xs_dup("[]"); 1475 *body = xs_dup("[]");
1484 *ctype = "application/json"; 1476 *ctype = "application/json";
1485 status = 200; 1477 status = 200;
1486 } 1478 }
1487 else 1479 else
1488 if (strcmp(cmd, "/v2/search") == 0) { 1480 if (strcmp(cmd, "/v2/search") == 0) { /** **/
1489 const char *q = xs_dict_get(args, "q"); 1481 const char *q = xs_dict_get(args, "q");
1490 const char *type = xs_dict_get(args, "type"); 1482 const char *type = xs_dict_get(args, "type");
1491 const char *offset = xs_dict_get(args, "offset"); 1483 const char *offset = xs_dict_get(args, "offset");
@@ -1571,7 +1563,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
1571 snac snac = {0}; 1563 snac snac = {0};
1572 int logged_in = process_auth_token(&snac, req); 1564 int logged_in = process_auth_token(&snac, req);
1573 1565
1574 if (strcmp(cmd, "/v1/apps") == 0) { 1566 if (strcmp(cmd, "/v1/apps") == 0) { /** **/
1575 const char *name = xs_dict_get(args, "client_name"); 1567 const char *name = xs_dict_get(args, "client_name");
1576 const char *ruri = xs_dict_get(args, "redirect_uris"); 1568 const char *ruri = xs_dict_get(args, "redirect_uris");
1577 const char *scope = xs_dict_get(args, "scope"); 1569 const char *scope = xs_dict_get(args, "scope");
@@ -1619,7 +1611,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
1619 } 1611 }
1620 } 1612 }
1621 else 1613 else
1622 if (strcmp(cmd, "/v1/statuses") == 0) { 1614 if (strcmp(cmd, "/v1/statuses") == 0) { /** **/
1623 if (logged_in) { 1615 if (logged_in) {
1624 /* post a new Note */ 1616 /* post a new Note */
1625/* { 1617/* {
@@ -1706,7 +1698,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
1706 status = 401; 1698 status = 401;
1707 } 1699 }
1708 else 1700 else
1709 if (xs_startswith(cmd, "/v1/statuses")) { 1701 if (xs_startswith(cmd, "/v1/statuses")) { /** **/
1710 if (logged_in) { 1702 if (logged_in) {
1711 /* operations on a status */ 1703 /* operations on a status */
1712 xs *l = xs_split(cmd, "/"); 1704 xs *l = xs_split(cmd, "/");
@@ -1798,7 +1790,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
1798 status = 401; 1790 status = 401;
1799 } 1791 }
1800 else 1792 else
1801 if (strcmp(cmd, "/v1/notifications/clear") == 0) { 1793 if (strcmp(cmd, "/v1/notifications/clear") == 0) { /** **/
1802 if (logged_in) { 1794 if (logged_in) {
1803 notify_clear(&snac); 1795 notify_clear(&snac);
1804 timeline_touch(&snac); 1796 timeline_touch(&snac);
@@ -1811,7 +1803,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
1811 status = 401; 1803 status = 401;
1812 } 1804 }
1813 else 1805 else
1814 if (strcmp(cmd, "/v1/push/subscription") == 0) { 1806 if (strcmp(cmd, "/v1/push/subscription") == 0) { /** **/
1815 /* I don't know what I'm doing */ 1807 /* I don't know what I'm doing */
1816 if (logged_in) { 1808 if (logged_in) {
1817 char *v; 1809 char *v;
@@ -1839,7 +1831,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
1839 status = 401; 1831 status = 401;
1840 } 1832 }
1841 else 1833 else
1842 if (strcmp(cmd, "/v1/media") == 0 || strcmp(cmd, "/v2/media") == 0) { 1834 if (strcmp(cmd, "/v1/media") == 0 || strcmp(cmd, "/v2/media") == 0) { /** **/
1843 if (logged_in) { 1835 if (logged_in) {
1844/* { 1836/* {
1845 xs *j = xs_json_dumps_pp(args, 4); 1837 xs *j = xs_json_dumps_pp(args, 4);
@@ -1888,7 +1880,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
1888 status = 401; 1880 status = 401;
1889 } 1881 }
1890 else 1882 else
1891 if (xs_startswith(cmd, "/v1/accounts")) { 1883 if (xs_startswith(cmd, "/v1/accounts")) { /** **/
1892 if (logged_in) { 1884 if (logged_in) {
1893 /* account-related information */ 1885 /* account-related information */
1894 xs *l = xs_split(cmd, "/"); 1886 xs *l = xs_split(cmd, "/");
@@ -1993,7 +1985,7 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
1993 snac snac = {0}; 1985 snac snac = {0};
1994 int logged_in = process_auth_token(&snac, req); 1986 int logged_in = process_auth_token(&snac, req);
1995 1987
1996 if (xs_startswith(cmd, "/v1/media") || xs_startswith(cmd, "/v2/media")) { 1988 if (xs_startswith(cmd, "/v1/media") || xs_startswith(cmd, "/v2/media")) { /** **/
1997 if (logged_in) { 1989 if (logged_in) {
1998 xs *l = xs_split(cmd, "/"); 1990 xs *l = xs_split(cmd, "/");
1999 const char *stid = xs_list_get(l, 3); 1991 const char *stid = xs_list_get(l, 3);