mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-15 01:55:03 +00:00
Added some code comments.
This commit is contained in:
parent
d35c949a13
commit
5325da02e6
1 changed files with 36 additions and 44 deletions
80
mastoapi.c
80
mastoapi.c
|
@ -191,7 +191,7 @@ int oauth_get_handler(const xs_dict *req, const char *q_path,
|
||||||
|
|
||||||
srv_debug(1, xs_fmt("oauth_get_handler %s", q_path));
|
srv_debug(1, xs_fmt("oauth_get_handler %s", q_path));
|
||||||
|
|
||||||
if (strcmp(cmd, "/authorize") == 0) {
|
if (strcmp(cmd, "/authorize") == 0) { /** **/
|
||||||
const char *cid = xs_dict_get(msg, "client_id");
|
const char *cid = xs_dict_get(msg, "client_id");
|
||||||
const char *ruri = xs_dict_get(msg, "redirect_uri");
|
const char *ruri = xs_dict_get(msg, "redirect_uri");
|
||||||
const char *rtype = xs_dict_get(msg, "response_type");
|
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,
|
||||||
srv_debug(1, xs_fmt("oauth authorize: invalid or unset arguments"));
|
srv_debug(1, xs_fmt("oauth authorize: invalid or unset arguments"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/x-snac-get-token") == 0) {
|
if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/
|
||||||
const char *host = xs_dict_get(srv_config, "host");
|
const char *host = xs_dict_get(srv_config, "host");
|
||||||
|
|
||||||
*body = xs_fmt(login_page, host, "", host, "oauth/x-snac-get-token",
|
*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,
|
||||||
|
|
||||||
srv_debug(1, xs_fmt("oauth_post_handler %s", q_path));
|
srv_debug(1, xs_fmt("oauth_post_handler %s", q_path));
|
||||||
|
|
||||||
if (strcmp(cmd, "/x-snac-login") == 0) {
|
if (strcmp(cmd, "/x-snac-login") == 0) { /** **/
|
||||||
const char *login = xs_dict_get(args, "login");
|
const char *login = xs_dict_get(args, "login");
|
||||||
const char *passwd = xs_dict_get(args, "passwd");
|
const char *passwd = xs_dict_get(args, "passwd");
|
||||||
const char *redir = xs_dict_get(args, "redir");
|
const char *redir = xs_dict_get(args, "redir");
|
||||||
|
@ -325,7 +325,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
|
||||||
srv_debug(1, xs_fmt("oauth x-snac-login: invalid or unset arguments"));
|
srv_debug(1, xs_fmt("oauth x-snac-login: invalid or unset arguments"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/token") == 0) {
|
if (strcmp(cmd, "/token") == 0) { /** **/
|
||||||
xs *wrk = NULL;
|
xs *wrk = NULL;
|
||||||
const char *gtype = xs_dict_get(args, "grant_type");
|
const char *gtype = xs_dict_get(args, "grant_type");
|
||||||
const char *code = xs_dict_get(args, "code");
|
const char *code = xs_dict_get(args, "code");
|
||||||
|
@ -408,7 +408,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/revoke") == 0) {
|
if (strcmp(cmd, "/revoke") == 0) { /** **/
|
||||||
const char *cid = xs_dict_get(args, "client_id");
|
const char *cid = xs_dict_get(args, "client_id");
|
||||||
const char *csec = xs_dict_get(args, "client_secret");
|
const char *csec = xs_dict_get(args, "client_secret");
|
||||||
const char *tokid = xs_dict_get(args, "token");
|
const char *tokid = xs_dict_get(args, "token");
|
||||||
|
@ -437,7 +437,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
|
||||||
status = 403;
|
status = 403;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strcmp(cmd, "/x-snac-get-token") == 0) {
|
if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/
|
||||||
const char *login = xs_dict_get(args, "login");
|
const char *login = xs_dict_get(args, "login");
|
||||||
const char *passwd = xs_dict_get(args, "passwd");
|
const char *passwd = xs_dict_get(args, "passwd");
|
||||||
|
|
||||||
|
@ -590,8 +590,6 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
|
||||||
|
|
||||||
xs *acct = mastoapi_account(actor);
|
xs *acct = mastoapi_account(actor);
|
||||||
|
|
||||||
/** shave the yak converting an ActivityPub Note to a Mastodon status **/
|
|
||||||
|
|
||||||
xs *f = xs_val_new(XSTYPE_FALSE);
|
xs *f = xs_val_new(XSTYPE_FALSE);
|
||||||
xs *t = xs_val_new(XSTYPE_TRUE);
|
xs *t = xs_val_new(XSTYPE_TRUE);
|
||||||
xs *n = xs_val_new(XSTYPE_NULL);
|
xs *n = xs_val_new(XSTYPE_NULL);
|
||||||
|
@ -890,7 +888,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
||||||
snac snac1 = {0};
|
snac snac1 = {0};
|
||||||
int logged_in = process_auth_token(&snac1, req);
|
int logged_in = process_auth_token(&snac1, req);
|
||||||
|
|
||||||
if (strcmp(cmd, "/v1/accounts/verify_credentials") == 0) {
|
if (strcmp(cmd, "/v1/accounts/verify_credentials") == 0) { /** **/
|
||||||
if (logged_in) {
|
if (logged_in) {
|
||||||
xs *acct = xs_dict_new();
|
xs *acct = xs_dict_new();
|
||||||
|
|
||||||
|
@ -922,7 +920,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/accounts/relationships") == 0) {
|
if (strcmp(cmd, "/v1/accounts/relationships") == 0) { /** **/
|
||||||
/* find if an account is followed, blocked, etc. */
|
/* find if an account is followed, blocked, etc. */
|
||||||
/* the account to get relationships about is in args "id[]" */
|
/* the account to get relationships about is in args "id[]" */
|
||||||
|
|
||||||
|
@ -948,7 +946,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
||||||
status = 422;
|
status = 422;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (xs_startswith(cmd, "/v1/accounts/")) {
|
if (xs_startswith(cmd, "/v1/accounts/")) { /** **/
|
||||||
/* account-related information */
|
/* account-related information */
|
||||||
xs *l = xs_split(cmd, "/");
|
xs *l = xs_split(cmd, "/");
|
||||||
const char *uid = xs_list_get(l, 3);
|
const char *uid = xs_list_get(l, 3);
|
||||||
|
@ -1015,7 +1013,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/timelines/home") == 0) {
|
if (strcmp(cmd, "/v1/timelines/home") == 0) { /** **/
|
||||||
/* the private timeline */
|
/* the private timeline */
|
||||||
if (logged_in) {
|
if (logged_in) {
|
||||||
const char *max_id = xs_dict_get(args, "max_id");
|
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/timelines/public") == 0) {
|
if (strcmp(cmd, "/v1/timelines/public") == 0) { /** **/
|
||||||
/* the instance public timeline (public timelines for all users) */
|
/* the instance public timeline (public timelines for all users) */
|
||||||
|
|
||||||
/* NOTE: this api call needs no authorization; but,
|
/* NOTE: this api call needs no authorization; but,
|
||||||
|
@ -1145,14 +1143,14 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/conversations") == 0) {
|
if (strcmp(cmd, "/v1/conversations") == 0) { /** **/
|
||||||
/* TBD */
|
/* TBD */
|
||||||
*body = xs_dup("[]");
|
*body = xs_dup("[]");
|
||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/notifications") == 0) {
|
if (strcmp(cmd, "/v1/notifications") == 0) { /** **/
|
||||||
if (logged_in) {
|
if (logged_in) {
|
||||||
xs *l = notify_list(&snac1, 0);
|
xs *l = notify_list(&snac1, 0);
|
||||||
xs *out = xs_list_new();
|
xs *out = xs_list_new();
|
||||||
|
@ -1227,63 +1225,63 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
||||||
status = 401;
|
status = 401;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/filters") == 0) {
|
if (strcmp(cmd, "/v1/filters") == 0) { /** **/
|
||||||
/* snac will never have filters */
|
/* snac will never have filters */
|
||||||
*body = xs_dup("[]");
|
*body = xs_dup("[]");
|
||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/favourites") == 0) {
|
if (strcmp(cmd, "/v1/favourites") == 0) { /** **/
|
||||||
/* snac will never support a list of favourites */
|
/* snac will never support a list of favourites */
|
||||||
*body = xs_dup("[]");
|
*body = xs_dup("[]");
|
||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/bookmarks") == 0) {
|
if (strcmp(cmd, "/v1/bookmarks") == 0) { /** **/
|
||||||
/* snac does not support bookmarks */
|
/* snac does not support bookmarks */
|
||||||
*body = xs_dup("[]");
|
*body = xs_dup("[]");
|
||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/lists") == 0) {
|
if (strcmp(cmd, "/v1/lists") == 0) { /** **/
|
||||||
/* snac does not support lists */
|
/* snac does not support lists */
|
||||||
*body = xs_dup("[]");
|
*body = xs_dup("[]");
|
||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/scheduled_statuses") == 0) {
|
if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/
|
||||||
/* snac does not scheduled notes */
|
/* snac does not schedule notes */
|
||||||
*body = xs_dup("[]");
|
*body = xs_dup("[]");
|
||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/follow_requests") == 0) {
|
if (strcmp(cmd, "/v1/follow_requests") == 0) { /** **/
|
||||||
/* snac does not support optional follow confirmations */
|
/* snac does not support optional follow confirmations */
|
||||||
*body = xs_dup("[]");
|
*body = xs_dup("[]");
|
||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/announcements") == 0) {
|
if (strcmp(cmd, "/v1/announcements") == 0) { /** **/
|
||||||
/* snac has no announcements (yet?) */
|
/* snac has no announcements (yet?) */
|
||||||
*body = xs_dup("[]");
|
*body = xs_dup("[]");
|
||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/custom_emojis") == 0) {
|
if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/
|
||||||
/* are you kidding me? */
|
/* are you kidding me? */
|
||||||
*body = xs_dup("[]");
|
*body = xs_dup("[]");
|
||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/instance") == 0) {
|
if (strcmp(cmd, "/v1/instance") == 0) { /** **/
|
||||||
/* returns an instance object */
|
/* returns an instance object */
|
||||||
xs *ins = xs_dict_new();
|
xs *ins = xs_dict_new();
|
||||||
const char *host = xs_dict_get(srv_config, "host");
|
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,
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (xs_startswith(cmd, "/v1/statuses/")) {
|
if (xs_startswith(cmd, "/v1/statuses/")) { /** **/
|
||||||
/* information about a status */
|
/* information about a status */
|
||||||
xs *l = xs_split(cmd, "/");
|
xs *l = xs_split(cmd, "/");
|
||||||
const char *id = xs_list_get(l, 3);
|
const char *id = xs_list_get(l, 3);
|
||||||
|
@ -1461,31 +1459,25 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/filters") == 0) {
|
if (strcmp(cmd, "/v1/preferences") == 0) { /** **/
|
||||||
*body = xs_dup("[]");
|
|
||||||
*ctype = "application/json";
|
|
||||||
status = 200;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (strcmp(cmd, "/v1/preferences") == 0) {
|
|
||||||
*body = xs_dup("{}");
|
*body = xs_dup("{}");
|
||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/markers") == 0) {
|
if (strcmp(cmd, "/v1/markers") == 0) { /** **/
|
||||||
*body = xs_dup("{}");
|
*body = xs_dup("{}");
|
||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/followed_tags") == 0) {
|
if (strcmp(cmd, "/v1/followed_tags") == 0) { /** **/
|
||||||
*body = xs_dup("[]");
|
*body = xs_dup("[]");
|
||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
status = 200;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v2/search") == 0) {
|
if (strcmp(cmd, "/v2/search") == 0) { /** **/
|
||||||
const char *q = xs_dict_get(args, "q");
|
const char *q = xs_dict_get(args, "q");
|
||||||
const char *type = xs_dict_get(args, "type");
|
const char *type = xs_dict_get(args, "type");
|
||||||
const char *offset = xs_dict_get(args, "offset");
|
const char *offset = xs_dict_get(args, "offset");
|
||||||
|
@ -1571,7 +1563,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
||||||
snac snac = {0};
|
snac snac = {0};
|
||||||
int logged_in = process_auth_token(&snac, req);
|
int logged_in = process_auth_token(&snac, req);
|
||||||
|
|
||||||
if (strcmp(cmd, "/v1/apps") == 0) {
|
if (strcmp(cmd, "/v1/apps") == 0) { /** **/
|
||||||
const char *name = xs_dict_get(args, "client_name");
|
const char *name = xs_dict_get(args, "client_name");
|
||||||
const char *ruri = xs_dict_get(args, "redirect_uris");
|
const char *ruri = xs_dict_get(args, "redirect_uris");
|
||||||
const char *scope = xs_dict_get(args, "scope");
|
const char *scope = xs_dict_get(args, "scope");
|
||||||
|
@ -1619,7 +1611,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/statuses") == 0) {
|
if (strcmp(cmd, "/v1/statuses") == 0) { /** **/
|
||||||
if (logged_in) {
|
if (logged_in) {
|
||||||
/* post a new Note */
|
/* post a new Note */
|
||||||
/* {
|
/* {
|
||||||
|
@ -1706,7 +1698,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
||||||
status = 401;
|
status = 401;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (xs_startswith(cmd, "/v1/statuses")) {
|
if (xs_startswith(cmd, "/v1/statuses")) { /** **/
|
||||||
if (logged_in) {
|
if (logged_in) {
|
||||||
/* operations on a status */
|
/* operations on a status */
|
||||||
xs *l = xs_split(cmd, "/");
|
xs *l = xs_split(cmd, "/");
|
||||||
|
@ -1798,7 +1790,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
||||||
status = 401;
|
status = 401;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/notifications/clear") == 0) {
|
if (strcmp(cmd, "/v1/notifications/clear") == 0) { /** **/
|
||||||
if (logged_in) {
|
if (logged_in) {
|
||||||
notify_clear(&snac);
|
notify_clear(&snac);
|
||||||
timeline_touch(&snac);
|
timeline_touch(&snac);
|
||||||
|
@ -1811,7 +1803,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
||||||
status = 401;
|
status = 401;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/push/subscription") == 0) {
|
if (strcmp(cmd, "/v1/push/subscription") == 0) { /** **/
|
||||||
/* I don't know what I'm doing */
|
/* I don't know what I'm doing */
|
||||||
if (logged_in) {
|
if (logged_in) {
|
||||||
char *v;
|
char *v;
|
||||||
|
@ -1839,7 +1831,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
||||||
status = 401;
|
status = 401;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(cmd, "/v1/media") == 0 || strcmp(cmd, "/v2/media") == 0) {
|
if (strcmp(cmd, "/v1/media") == 0 || strcmp(cmd, "/v2/media") == 0) { /** **/
|
||||||
if (logged_in) {
|
if (logged_in) {
|
||||||
/* {
|
/* {
|
||||||
xs *j = xs_json_dumps_pp(args, 4);
|
xs *j = xs_json_dumps_pp(args, 4);
|
||||||
|
@ -1888,7 +1880,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
||||||
status = 401;
|
status = 401;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (xs_startswith(cmd, "/v1/accounts")) {
|
if (xs_startswith(cmd, "/v1/accounts")) { /** **/
|
||||||
if (logged_in) {
|
if (logged_in) {
|
||||||
/* account-related information */
|
/* account-related information */
|
||||||
xs *l = xs_split(cmd, "/");
|
xs *l = xs_split(cmd, "/");
|
||||||
|
@ -1993,7 +1985,7 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
|
||||||
snac snac = {0};
|
snac snac = {0};
|
||||||
int logged_in = process_auth_token(&snac, req);
|
int logged_in = process_auth_token(&snac, req);
|
||||||
|
|
||||||
if (xs_startswith(cmd, "/v1/media") || xs_startswith(cmd, "/v2/media")) {
|
if (xs_startswith(cmd, "/v1/media") || xs_startswith(cmd, "/v2/media")) { /** **/
|
||||||
if (logged_in) {
|
if (logged_in) {
|
||||||
xs *l = xs_split(cmd, "/");
|
xs *l = xs_split(cmd, "/");
|
||||||
const char *stid = xs_list_get(l, 3);
|
const char *stid = xs_list_get(l, 3);
|
||||||
|
|
Loading…
Reference in a new issue