From 7312f4ce51100d4ed98988cb3af0ab06e4fba53c Mon Sep 17 00:00:00 2001 From: iwojim0 Date: Sat, 9 Mar 2024 14:37:54 +0000 Subject: Ability to federate with hidden networks #93 (update for v2.49) --- mastoapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 416f96c..d702c47 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -156,7 +156,7 @@ const char *login_page = "" "\n" "

%s OAuth identify

\n" "
%s
\n" -"
\n" +"\n" "

Login:

\n" "

Password:

\n" "\n" -- cgit v1.2.3 From c9df6707abc8a8d2b7815f5210cf3667be6fb9b1 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 14 Apr 2024 18:31:53 +0200 Subject: Log status in mastoapi_post_handler(). --- mastoapi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 4d80f69..36f7238 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -2119,8 +2119,6 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) return 0; - srv_debug(1, xs_fmt("mastoapi_post_handler %s", q_path)); - int status = 404; xs *args = NULL; char *i_ctype = xs_dict_get(req, "content-type"); @@ -2626,6 +2624,8 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (logged_in) user_free(&snac); + srv_debug(1, xs_fmt("mastoapi_post_handler %s %d", q_path, status)); + return status; } -- cgit v1.2.3 From 81cf1e21a646568323681df2763e66f933bee48f Mon Sep 17 00:00:00 2001 From: default Date: Sun, 14 Apr 2024 19:24:06 +0200 Subject: Better redirection URL building in oauth_post_handler(). --- mastoapi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 36f7238..2b52972 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -289,7 +289,11 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, *body = xs_dup(code); } else { - *body = xs_fmt("%s?code=%s", redir, code); + if (xs_str_in(redir, "?")) + *body = xs_fmt("%s&code=%s", redir, code); + else + *body = xs_fmt("%s?code=%s", redir, code); + status = 303; } -- cgit v1.2.3 From 26840e0dc0e7322b2041c21b4e44ed9a34afff4b Mon Sep 17 00:00:00 2001 From: default Date: Thu, 18 Apr 2024 17:13:31 +0200 Subject: Some tweaks to previous patch. --- mastoapi.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 78fd802..b49fbca 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -156,7 +156,7 @@ const char *login_page = "" "\n" "

%s OAuth identify

\n" "
%s
\n" -"\n" +"\n" "

Login:

\n" "

Password:

\n" "\n" @@ -193,11 +193,12 @@ int oauth_get_handler(const xs_dict *req, const char *q_path, if (app != NULL) { const char *host = xs_dict_get(srv_config, "host"); + const char *proto = xs_dict_get_def(srv_config, "protocol", "https"); if (xs_is_null(state)) state = ""; - *body = xs_fmt(login_page, host, host, "", host, "oauth/x-snac-login", + *body = xs_fmt(login_page, host, host, "", proto, host, "oauth/x-snac-login", ruri, cid, state, USER_AGENT); *ctype = "text/html"; status = 200; @@ -213,8 +214,9 @@ int oauth_get_handler(const xs_dict *req, const char *q_path, else if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/ const char *host = xs_dict_get(srv_config, "host"); + const char *proto = xs_dict_get_def(srv_config, "protocol", "https"); - *body = xs_fmt(login_page, host, host, "", host, "oauth/x-snac-get-token", + *body = xs_fmt(login_page, host, host, "", proto, host, "oauth/x-snac-get-token", "", "", "", USER_AGENT); *ctype = "text/html"; status = 200; @@ -265,11 +267,11 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, const char *redir = xs_dict_get(args, "redir"); const char *cid = xs_dict_get(args, "cid"); const char *state = xs_dict_get(args, "state"); - - const char *host = xs_dict_get(srv_config, "host"); + const char *host = xs_dict_get(srv_config, "host"); + const char *proto = xs_dict_get_def(srv_config, "protocol", "https"); /* by default, generate another login form with an error */ - *body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", host, "oauth/x-snac-login", + *body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", proto, host, "oauth/x-snac-login", redir, cid, state, USER_AGENT); *ctype = "text/html"; status = 200; @@ -450,11 +452,11 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/ const char *login = xs_dict_get(args, "login"); const char *passwd = xs_dict_get(args, "passwd"); - - const char *host = xs_dict_get(srv_config, "host"); + const char *host = xs_dict_get(srv_config, "host"); + const char *proto = xs_dict_get_def(srv_config, "protocol", "https"); /* by default, generate another login form with an error */ - *body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", host, "oauth/x-snac-get-token", + *body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", proto, host, "oauth/x-snac-get-token", "", "", "", USER_AGENT); *ctype = "text/html"; status = 200; -- cgit v1.2.3 From be935b32c6a83de5ec39519bcb06e37edc373a2f Mon Sep 17 00:00:00 2001 From: default Date: Sat, 27 Apr 2024 08:02:47 +0200 Subject: mastoapi: minor tweaks. --- mastoapi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index b49fbca..fa01680 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -550,6 +550,9 @@ xs_dict *mastoapi_account(const xs_dict *actor) acct = xs_dict_append(acct, "created_at", date); } + xs *last_status_at = xs_str_utctime(0, "%Y-%m-%d"); + acct = xs_dict_append(acct, "last_status_at", last_status_at); + const char *note = xs_dict_get(actor, "summary"); if (xs_is_null(note)) note = ""; @@ -1000,7 +1003,10 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) st = xs_dict_append(st, "reblog", xs_stock(XSTYPE_NULL)); st = xs_dict_append(st, "card", xs_stock(XSTYPE_NULL)); - st = xs_dict_append(st, "language", xs_stock(XSTYPE_NULL)); + st = xs_dict_append(st, "language", "en"); + + st = xs_dict_append(st, "filtered", xs_stock(XSTYPE_LIST)); + st = xs_dict_append(st, "muted", xs_stock(XSTYPE_FALSE)); tmp = xs_dict_get(msg, "sourceContent"); if (xs_is_null(tmp)) -- cgit v1.2.3 From 6bcb248254b32f86e6f07a73ef2db632e79a01d7 Mon Sep 17 00:00:00 2001 From: default Date: Sat, 27 Apr 2024 08:30:56 +0200 Subject: mastoapi: Fixed login bug. --- mastoapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index fa01680..7ffcbce 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -291,7 +291,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, *body = xs_dup(code); } else { - if (xs_str_in(redir, "?")) + if (xs_str_in(redir, "?") != -1) *body = xs_fmt("%s&code=%s", redir, code); else *body = xs_fmt("%s?code=%s", redir, code); -- cgit v1.2.3 From 8275a5f4d8764ebc9f9f82a4db377bacfa9fbc75 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 29 Apr 2024 07:43:01 +0200 Subject: Start of list support. --- mastoapi.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 7ffcbce..20d6208 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1767,9 +1767,27 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, else if (strcmp(cmd, "/v1/lists") == 0) { /** **/ /* snac does not support lists */ - *body = xs_dup("[]"); - *ctype = "application/json"; - status = 200; + if (logged_in) { + xs *lol = list_maint(&snac1, NULL, 0); + xs *l = xs_list_new(); + int c = 0; + xs_list *li; + + while (xs_list_next(lol, &li, &c)) { + xs *d = xs_dict_new(); + + d = xs_dict_append(d, "id", xs_list_get(li, 0)); + d = xs_dict_append(d, "title", xs_list_get(li, 1)); + d = xs_dict_append(d, "replies_policy", "list"); + d = xs_dict_append(d, "exclusive", xs_stock(XSTYPE_FALSE)); + + l = xs_list_append(l, d); + } + + *body = xs_json_dumps(l, 4); + *ctype = "application/json"; + status = 200; + } } else if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/ @@ -2631,6 +2649,29 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, else status = 401; } + else + if (strcmp(cmd, "/v1/lists") == 0) { + if (logged_in) { + const char *title = xs_dict_get(args, "title"); + + if (xs_type(title) == XSTYPE_STRING) { + /* add the list */ + list_maint(&snac, title, 1); + + xs *out = xs_dict_new(); + + out = xs_dict_append(out, "title", title); + out = xs_dict_append(out, "replies_policy", xs_dict_get_def(args, "replies_policy", "list")); + out = xs_dict_append(out, "exclusive", xs_stock(XSTYPE_FALSE)); + + *body = xs_json_dumps(out, 4); + *ctype = "application/json"; + status = 200; + } + else + status = 422; + } + } /* user cleanup */ if (logged_in) -- cgit v1.2.3 From 9a13e330f12aaf0fc1535e922efbf315308d252b Mon Sep 17 00:00:00 2001 From: default Date: Mon, 29 Apr 2024 08:29:18 +0200 Subject: More work in lists. --- mastoapi.c | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 20d6208..54d2777 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1766,7 +1766,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, } else if (strcmp(cmd, "/v1/lists") == 0) { /** **/ - /* snac does not support lists */ if (logged_in) { xs *lol = list_maint(&snac1, NULL, 0); xs *l = xs_list_new(); @@ -2656,17 +2655,22 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (xs_type(title) == XSTYPE_STRING) { /* add the list */ - list_maint(&snac, title, 1); - xs *out = xs_dict_new(); - out = xs_dict_append(out, "title", title); - out = xs_dict_append(out, "replies_policy", xs_dict_get_def(args, "replies_policy", "list")); - out = xs_dict_append(out, "exclusive", xs_stock(XSTYPE_FALSE)); + if (xs_type(list_maint(&snac, title, 1)) == XSTYPE_TRUE) { + out = xs_dict_append(out, "title", title); + out = xs_dict_append(out, "replies_policy", xs_dict_get_def(args, "replies_policy", "list")); + out = xs_dict_append(out, "exclusive", xs_stock(XSTYPE_FALSE)); + + status = 200; + } + else { + out = xs_dict_append(out, "error", "cannot create list"); + status = 422; + } *body = xs_json_dumps(out, 4); *ctype = "application/json"; - status = 200; } else status = 422; @@ -2691,16 +2695,43 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path, (void)b_size; (void)ctype; + int status = 404; + if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) return 0; - srv_debug(1, xs_fmt("mastoapi_delete_handler %s", q_path)); + snac snac = {0}; + int logged_in = process_auth_token(&snac, req); + xs *cmd = xs_replace_n(q_path, "/api", "", 1); + if (xs_startswith(cmd, "/v1/push/subscription") || xs_startswith(cmd, "/v2/push/subscription")) { /** **/ // pretend we deleted it, since it doesn't exist anyway - return 200; + status = 200; } - return 0; + else + if (xs_startswith(cmd, "/v1/lists/")) { + if (logged_in) { + xs *l = xs_split(cmd, "/"); + char *id = xs_list_get(l, -1); + + if (xs_is_hex(id)) { + list_maint(&snac, id, 2); + } + + status = 200; + } + else + status = 401; + } + + /* user cleanup */ + if (logged_in) + user_free(&snac); + + srv_debug(1, xs_fmt("mastoapi_delete_handler %s %d", q_path, status)); + + return status; } -- cgit v1.2.3 From 29fb43079761796e34209611ec93bd651b871cab Mon Sep 17 00:00:00 2001 From: default Date: Mon, 29 Apr 2024 09:26:37 +0200 Subject: More work in lists. --- mastoapi.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 100 insertions(+), 10 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 54d2777..8c41efb 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1765,7 +1765,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, status = 200; } else - if (strcmp(cmd, "/v1/lists") == 0) { /** **/ + if (strcmp(cmd, "/v1/lists") == 0) { /** list of lists **/ if (logged_in) { xs *lol = list_maint(&snac1, NULL, 0); xs *l = xs_list_new(); @@ -1789,6 +1789,36 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, } } else + if (xs_startswith(cmd, "/v1/lists/")) { /** list information **/ + if (logged_in) { + xs *l = xs_split(cmd, "/"); + char *op = xs_list_get(l, -1); + char *id = xs_list_get(l, -2); + + if (op && id && xs_is_hex(id)) { + if (strcmp(op, "accounts") == 0) { + xs *actors = list_content(&snac1, id, NULL, 0); + xs *out = xs_list_new(); + int c = 0; + char *v; + + while (xs_list_next(actors, &v, &c)) { + xs *actor = NULL; + + if (valid_status(object_get_by_md5(v, &actor))) { + xs *acct = mastoapi_account(actor); + out = xs_list_append(out, acct); + } + } + + *body = xs_json_dumps(out, 4); + *ctype = "application/json"; + status = 200; + } + } + } + } + else if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/ /* snac does not schedule notes */ *body = xs_dup("[]"); @@ -2676,6 +2706,29 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, status = 422; } } + if (xs_startswith(cmd, "/v1/lists/")) { /** list maintenance **/ + if (logged_in) { + xs *l = xs_split(cmd, "/"); + char *op = xs_list_get(l, -1); + char *id = xs_list_get(l, -2); + + if (op && id && xs_is_hex(id)) { + if (strcmp(op, "accounts") == 0) { + xs_list *accts = xs_dict_get(args, "account_ids[]"); + int c = 0; + char *v; + + while (xs_list_next(accts, &v, &c)) { + list_content(&snac, id, v, 1); + } + + status = 200; + } + } + } + else + status = 422; + } /* user cleanup */ if (logged_in) @@ -2688,18 +2741,39 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, int mastoapi_delete_handler(const xs_dict *req, const char *q_path, - char **body, int *b_size, char **ctype) { - - (void)req; + const char *payload, int p_size, + char **body, int *b_size, char **ctype) +{ + (void)p_size; (void)body; (void)b_size; (void)ctype; - int status = 404; - if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) return 0; + int status = 404; + xs *args = NULL; + char *i_ctype = xs_dict_get(req, "content-type"); + + if (i_ctype && xs_startswith(i_ctype, "application/json")) { + if (!xs_is_null(payload)) + args = xs_json_loads(payload); + } + else if (i_ctype && xs_startswith(i_ctype, "application/x-www-form-urlencoded")) + { + // Some apps send form data instead of json so we should cater for those + if (!xs_is_null(payload)) { + xs *upl = xs_url_dec(payload); + args = xs_url_vars(upl); + } + } + else + args = xs_dup(xs_dict_get(req, "p_vars")); + + if (args == NULL) + return 400; + snac snac = {0}; int logged_in = process_auth_token(&snac, req); @@ -2713,10 +2787,26 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path, if (xs_startswith(cmd, "/v1/lists/")) { if (logged_in) { xs *l = xs_split(cmd, "/"); - char *id = xs_list_get(l, -1); - - if (xs_is_hex(id)) { - list_maint(&snac, id, 2); + char *p = xs_list_get(l, -1); + + if (p) { + if (strcmp(p, "accounts") == 0) { + /* delete account from list */ + p = xs_list_get(l, -2); + xs_list *accts = xs_dict_get(args, "account_ids[]"); + int c = 0; + char *v; + + while (xs_list_next(accts, &v, &c)) { + list_content(&snac, p, v, 2); + } + } + else { + /* delete list */ + if (xs_is_hex(p)) { + list_maint(&snac, p, 2); + } + } } status = 200; -- cgit v1.2.3 From f1221808a858b0d205f3acdb028d58d362ef22e6 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 29 Apr 2024 10:15:04 +0200 Subject: More work in lists. --- mastoapi.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 8c41efb..6316951 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1647,6 +1647,77 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, status = 200; } else + if (xs_startswith(cmd, "/v1/timelines/list/")) { /** **/ + /* get the list id */ + if (logged_in) { + xs *l = xs_split(cmd, "/"); + char *list = xs_list_get(l, -1); + + xs *timeline = list_content(&snac1, list, NULL, 3); + xs *out = xs_list_new(); + int c = 0; + char *md5; + + while (xs_list_next(timeline, &md5, &c)) { + xs *msg = NULL; + + /* get the entry */ + if (!valid_status(timeline_get_by_md5(&snac1, md5, &msg))) + continue; + + /* discard non-Notes */ + const char *id = xs_dict_get(msg, "id"); + const char *type = xs_dict_get(msg, "type"); + if (!xs_match(type, "Note|Question|Page|Article|Video")) + continue; + + const char *from = NULL; + if (strcmp(type, "Page") == 0) + from = xs_dict_get(msg, "audience"); + + if (from == NULL) + from = get_atto(msg); + + if (from == NULL) + continue; + + /* is this message from a person we don't follow? */ + if (strcmp(from, snac1.actor) && !following_check(&snac1, from)) { + /* discard if it was not boosted */ + xs *idx = object_announces(id); + + if (xs_list_len(idx) == 0) + continue; + } + + /* discard notes from muted morons */ + if (is_muted(&snac1, from)) + continue; + + /* discard hidden notes */ + if (is_hidden(&snac1, id)) + continue; + + /* if it has a name and it's not a Page or a Video, + it's a poll vote, so discard it */ + if (!xs_is_null(xs_dict_get(msg, "name")) && !xs_match(type, "Page|Video")) + continue; + + /* convert the Note into a Mastodon status */ + xs *st = mastoapi_status(&snac1, msg); + + if (st != NULL) + out = xs_list_append(out, st); + } + + *body = xs_json_dumps(out, 4); + *ctype = "application/json"; + status = 200; + } + else + status = 421; + } + else if (strcmp(cmd, "/v1/conversations") == 0) { /** **/ /* TBD */ *body = xs_dup("[]"); -- cgit v1.2.3 From da18efd288bc8e69a0f755e576e3ba14dfedbcb3 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 29 Apr 2024 10:48:48 +0200 Subject: More tweaks to mastoapi lists. --- mastoapi.c | 52 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 6316951..0cdb4bf 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1863,22 +1863,52 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (xs_startswith(cmd, "/v1/lists/")) { /** list information **/ if (logged_in) { xs *l = xs_split(cmd, "/"); - char *op = xs_list_get(l, -1); - char *id = xs_list_get(l, -2); + char *p = xs_list_get(l, -1); - if (op && id && xs_is_hex(id)) { - if (strcmp(op, "accounts") == 0) { - xs *actors = list_content(&snac1, id, NULL, 0); + if (p) { + if (strcmp(p, "accounts") == 0) { + p = xs_list_get(l, -2); + + if (p && xs_is_hex(p)) { + xs *actors = list_content(&snac1, p, NULL, 0); + xs *out = xs_list_new(); + int c = 0; + char *v; + + while (xs_list_next(actors, &v, &c)) { + xs *actor = NULL; + + if (valid_status(object_get_by_md5(v, &actor))) { + xs *acct = mastoapi_account(actor); + out = xs_list_append(out, acct); + } + } + + *body = xs_json_dumps(out, 4); + *ctype = "application/json"; + status = 200; + } + } + else + if (xs_is_hex(p)) { xs *out = xs_list_new(); + xs *lol = list_maint(&snac1, NULL, 0); int c = 0; - char *v; + xs_list *v; + + while (xs_list_next(lol, &v, &c)) { + char *id = xs_list_get(v, 0); + + if (id && strcmp(id, p) == 0) { + xs *d = xs_dict_new(); - while (xs_list_next(actors, &v, &c)) { - xs *actor = NULL; + d = xs_dict_append(d, "id", p); + d = xs_dict_append(d, "title", xs_list_get(v, 1)); + d = xs_dict_append(d, "replies_policy", "list"); + d = xs_dict_append(d, "exclusive", xs_stock(XSTYPE_FALSE)); - if (valid_status(object_get_by_md5(v, &actor))) { - xs *acct = mastoapi_account(actor); - out = xs_list_append(out, acct); + out = xs_list_append(out, d); + break; } } -- cgit v1.2.3 From c884f7081ab679014d05ebb6ad6add2315584e84 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 6 May 2024 05:54:46 +0200 Subject: mastoapi: also fix polls from Pleroma. --- mastoapi.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 0cdb4bf..e435ce9 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -716,10 +716,23 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg) xs *options = xs_list_new(); poll = xs_dict_append(poll, "id", mid); - xs *fd = mastoapi_date(xs_dict_get(msg, "endTime")); + char *date = xs_dict_get(msg, "endTime"); + if (date == NULL) + date = xs_dict_get(msg, "closed"); + if (date == NULL) + return NULL; + + xs *fd = mastoapi_date(date); poll = xs_dict_append(poll, "expires_at", fd); + + date = xs_dict_get(msg, "closed"); + time_t t = 0; + + if (date != NULL) + t = xs_parse_iso_date(date, 0); + poll = xs_dict_append(poll, "expired", - xs_dict_get(msg, "closed") != NULL ? xs_stock(XSTYPE_TRUE) : xs_stock(XSTYPE_FALSE)); + t < time(NULL) ? xs_stock(XSTYPE_FALSE) : xs_stock(XSTYPE_TRUE)); if ((opts = xs_dict_get(msg, "oneOf")) != NULL) poll = xs_dict_append(poll, "multiple", xs_stock(XSTYPE_FALSE)); -- cgit v1.2.3 From f67c4cf7d95739fb5cfa7e6644565ba9fe4c925c Mon Sep 17 00:00:00 2001 From: default Date: Mon, 6 May 2024 06:40:07 +0200 Subject: More logging! --- mastoapi.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index e435ce9..e9b3993 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1467,6 +1467,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (limit == 0) limit = 20; + snac_debug(&snac1, 1, + xs_fmt("/v1/timelines/home: max_id=%s since_id=%s min_id=%s limit=%s", + max_id, since_id, min_id, limit_s)); + xs *timeline = timeline_simple_list(&snac1, "private", 0, 2048); xs *out = xs_list_new(); -- cgit v1.2.3 From 7df69f8f1288290a8b948f33ac2368aa456b999e Mon Sep 17 00:00:00 2001 From: default Date: Mon, 6 May 2024 09:04:46 +0200 Subject: Logging, logging, logging everywhere. --- mastoapi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index e9b3993..1f7f0b2 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1467,9 +1467,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (limit == 0) limit = 20; - snac_debug(&snac1, 1, - xs_fmt("/v1/timelines/home: max_id=%s since_id=%s min_id=%s limit=%s", - max_id, since_id, min_id, limit_s)); + xs *ja = xs_json_dumps(args, 0); + snac_debug(&snac1, 1, xs_fmt("/v1/timelines/home: args='%s'", ja)); xs *timeline = timeline_simple_list(&snac1, "private", 0, 2048); -- cgit v1.2.3 From 6b1721c977294ee28f54150579c36514aa3ee62a Mon Sep 17 00:00:00 2001 From: default Date: Tue, 7 May 2024 19:40:28 +0200 Subject: List timelines can now be (manually) navigated from the web UI. URLs are {srv_baseurl}/{user}/list/{list_id} (you must know the list id). --- mastoapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 1f7f0b2..d39a6f9 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1669,7 +1669,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *l = xs_split(cmd, "/"); char *list = xs_list_get(l, -1); - xs *timeline = list_content(&snac1, list, NULL, 3); + xs *timeline = list_timeline(&snac1, list, 0, 2048); xs *out = xs_list_new(); int c = 0; char *md5; -- cgit v1.2.3 From 2c8d4ce6bd227377fbfa02d92abdbff8a65150c3 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 9 May 2024 09:09:22 +0200 Subject: mastoapi: Added content search. --- mastoapi.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index d39a6f9..e4bc116 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -2228,8 +2228,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, /* reply something only for offset 0; otherwise, apps like Tusky keep asking again and again */ - if (!xs_is_null(q) && !xs_is_null(type)) { - if (strcmp(type, "accounts") == 0) { + if (!xs_is_null(q)) { + if (xs_is_null(type) || strcmp(type, "accounts") == 0) { /* do a webfinger query */ char *actor = NULL; char *user = NULL; @@ -2244,8 +2244,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, } } } - else - if (strcmp(type, "hashtags") == 0) { + + if (xs_is_null(type) || strcmp(type, "hashtags") == 0) { /* search this tag */ xs *tl = tag_search((char *)q, 0, 1); @@ -2260,6 +2260,28 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, htl = xs_list_append(htl, d); } } + + if (xs_is_null(type) || strcmp(type, "statuses") == 0) { + int to = 0; + xs *tl = content_search(&snac1, q, 1, 0, &to); + int c = 0; + char *v; + + while (xs_list_next(tl, &v, &c)) { + xs *post = NULL; + + if (!valid_status(timeline_get_by_md5(&snac1, v, &post))) + continue; + + char *type = xs_dict_get_def(post, "type", "-"); + if (!xs_match(type, "Note|Article|Question|Page|Video")) + continue; + + xs *s = mastoapi_status(&snac1, post); + + stl = xs_list_append(stl, s); + } + } } } -- cgit v1.2.3 From 8de93b9cd72ef0cde8b5bb620f376e9b926354dd Mon Sep 17 00:00:00 2001 From: default Date: Thu, 9 May 2024 09:24:39 +0200 Subject: mastoapi: some search by content tweaks. --- mastoapi.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index e4bc116..253021b 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1467,9 +1467,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (limit == 0) limit = 20; - xs *ja = xs_json_dumps(args, 0); - snac_debug(&snac1, 1, xs_fmt("/v1/timelines/home: args='%s'", ja)); - xs *timeline = timeline_simple_list(&snac1, "private", 0, 2048); xs *out = xs_list_new(); @@ -2266,20 +2263,18 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *tl = content_search(&snac1, q, 1, 0, &to); int c = 0; char *v; + int cnt = 40; - while (xs_list_next(tl, &v, &c)) { + while (xs_list_next(tl, &v, &c) && --cnt) { xs *post = NULL; if (!valid_status(timeline_get_by_md5(&snac1, v, &post))) continue; - char *type = xs_dict_get_def(post, "type", "-"); - if (!xs_match(type, "Note|Article|Question|Page|Video")) - continue; - xs *s = mastoapi_status(&snac1, post); - stl = xs_list_append(stl, s); + if (!xs_is_null(s)) + stl = xs_list_append(stl, s); } } } -- cgit v1.2.3 From cccc5454c259d0d4ca600b3e1165979c352be54f Mon Sep 17 00:00:00 2001 From: default Date: Thu, 9 May 2024 09:31:10 +0200 Subject: Added a maximum results argument to content_search(). --- mastoapi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 253021b..cbc965c 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -2260,10 +2260,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (xs_is_null(type) || strcmp(type, "statuses") == 0) { int to = 0; - xs *tl = content_search(&snac1, q, 1, 0, &to); + int cnt = 40; + xs *tl = content_search(&snac1, q, 1, 0, cnt, &to); int c = 0; char *v; - int cnt = 40; while (xs_list_next(tl, &v, &c) && --cnt) { xs *post = NULL; -- cgit v1.2.3 From 1531e81a310311656d06c9ee0d31da31493e6de2 Mon Sep 17 00:00:00 2001 From: default Date: Fri, 10 May 2024 11:29:18 +0200 Subject: Added a skip argument to content_search(). --- mastoapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index cbc965c..1071bfd 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -2261,7 +2261,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (xs_is_null(type) || strcmp(type, "statuses") == 0) { int to = 0; int cnt = 40; - xs *tl = content_search(&snac1, q, 1, 0, cnt, &to); + xs *tl = content_search(&snac1, q, 1, 0, cnt, 0, &to); int c = 0; char *v; -- cgit v1.2.3 From e1ce85debd5b192b5dc56a4e9810839cc52b0f8b Mon Sep 17 00:00:00 2001 From: default Date: Sat, 11 May 2024 18:46:15 +0200 Subject: Unified post-like object type match. --- mastoapi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 1071bfd..2bf5fdc 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1504,7 +1504,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, /* discard non-Notes */ const char *id = xs_dict_get(msg, "id"); const char *type = xs_dict_get(msg, "type"); - if (!xs_match(type, "Note|Question|Page|Article|Video")) + if (!xs_match(type, POSTLIKE_OBJECT_TYPE)) continue; const char *from = NULL; @@ -1681,7 +1681,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, /* discard non-Notes */ const char *id = xs_dict_get(msg, "id"); const char *type = xs_dict_get(msg, "type"); - if (!xs_match(type, "Note|Question|Page|Article|Video")) + if (!xs_match(type, POSTLIKE_OBJECT_TYPE)) continue; const char *from = NULL; -- cgit v1.2.3 From 4777fc86cb962917a8f34afb3bfa40f26290815d Mon Sep 17 00:00:00 2001 From: default Date: Tue, 21 May 2024 14:12:15 +0200 Subject: Added const everywhere. --- mastoapi.c | 109 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 57 insertions(+), 52 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 2bf5fdc..852713e 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -175,7 +175,7 @@ int oauth_get_handler(const xs_dict *req, const char *q_path, return 0; int status = 404; - xs_dict *msg = xs_dict_get(req, "q_vars"); + const xs_dict *msg = xs_dict_get(req, "q_vars"); xs *cmd = xs_replace_n(q_path, "/oauth", "", 1); srv_debug(1, xs_fmt("oauth_get_handler %s", q_path)); @@ -239,7 +239,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, int status = 404; - char *i_ctype = xs_dict_get(req, "content-type"); + const char *i_ctype = xs_dict_get(req, "content-type"); xs *args = NULL; if (i_ctype && xs_startswith(i_ctype, "application/json")) { @@ -568,10 +568,10 @@ xs_dict *mastoapi_account(const xs_dict *actor) acct = xs_dict_append(acct, "uri", id); xs *avatar = NULL; - xs_dict *av = xs_dict_get(actor, "icon"); + const xs_dict *av = xs_dict_get(actor, "icon"); if (xs_type(av) == XSTYPE_DICT) { - char *url = xs_dict_get(av, "url"); + const char *url = xs_dict_get(av, "url"); if (url != NULL) avatar = xs_dup(url); @@ -584,7 +584,7 @@ xs_dict *mastoapi_account(const xs_dict *actor) acct = xs_dict_append(acct, "avatar_static", avatar); xs *header = NULL; - xs_dict *hd = xs_dict_get(actor, "image"); + const xs_dict *hd = xs_dict_get(actor, "image"); if (xs_type(hd) == XSTYPE_DICT) header = xs_dup(xs_dict_get(hd, "url")); @@ -596,12 +596,13 @@ xs_dict *mastoapi_account(const xs_dict *actor) acct = xs_dict_append(acct, "header_static", header); /* emojis */ - xs_list *p; + const xs_list *p; if (!xs_is_null(p = xs_dict_get(actor, "tag"))) { xs *eml = xs_list_new(); xs_dict *v; + int c = 0; - while (xs_list_iter(&p, &v)) { + while (xs_list_next(p, &v, &c)) { const char *type = xs_dict_get(v, "type"); if (!xs_is_null(type) && strcmp(type, "Emoji") == 0) { @@ -640,7 +641,7 @@ xs_dict *mastoapi_account(const xs_dict *actor) /* dict of validated links */ xs_dict *val_links = NULL; - xs_dict *metadata = xs_stock(XSTYPE_DICT); + const xs_dict *metadata = xs_stock(XSTYPE_DICT); snac user = {0}; if (xs_startswith(id, srv_baseurl)) { @@ -654,19 +655,20 @@ xs_dict *mastoapi_account(const xs_dict *actor) if (xs_is_null(val_links)) val_links = xs_stock(XSTYPE_DICT); - while (xs_list_iter(&p, &v)) { - char *type = xs_dict_get(v, "type"); - char *name = xs_dict_get(v, "name"); - char *value = xs_dict_get(v, "value"); + int c = 0; + while (xs_list_next(p, &v, &c)) { + const char *type = xs_dict_get(v, "type"); + const char *name = xs_dict_get(v, "name"); + const char *value = xs_dict_get(v, "value"); if (!xs_is_null(type) && !xs_is_null(name) && !xs_is_null(value) && strcmp(type, "PropertyValue") == 0) { xs *val_date = NULL; - char *url = xs_dict_get(metadata, name); + const char *url = xs_dict_get(metadata, name); if (!xs_is_null(url) && xs_startswith(url, "https:/" "/")) { - xs_number *verified_time = xs_dict_get(val_links, url); + const xs_number *verified_time = xs_dict_get(val_links, url); if (xs_type(verified_time) == XSTYPE_NUMBER) { time_t t = xs_number_get(verified_time); @@ -695,7 +697,7 @@ xs_dict *mastoapi_account(const xs_dict *actor) } -xs_str *mastoapi_date(char *date) +xs_str *mastoapi_date(const char *date) /* converts an ISO 8601 date to whatever format Mastodon uses */ { xs_str *s = xs_crop_i(xs_dup(date), 0, 19); @@ -710,13 +712,13 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg) { xs_dict *poll = xs_dict_new(); xs *mid = mastoapi_id(msg); - xs_list *opts = NULL; + const xs_list *opts = NULL; xs_val *v; int num_votes = 0; xs *options = xs_list_new(); poll = xs_dict_append(poll, "id", mid); - char *date = xs_dict_get(msg, "endTime"); + const char *date = xs_dict_get(msg, "endTime"); if (date == NULL) date = xs_dict_get(msg, "closed"); if (date == NULL) @@ -741,7 +743,8 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg) poll = xs_dict_append(poll, "multiple", xs_stock(XSTYPE_TRUE)); } - while (xs_list_iter(&opts, &v)) { + int c = 0; + while (xs_list_next(opts, &v, &c)) { const char *title = xs_dict_get(v, "name"); const char *replies = xs_dict_get(v, "replies"); @@ -794,7 +797,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) xs *idx = NULL; xs *ixc = NULL; - char *tmp; + const char *tmp; xs *mid = mastoapi_id(msg); xs_dict *st = xs_dict_new(); @@ -851,9 +854,9 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) xs *matt = xs_list_new(); while (xs_list_iter(&p, &v)) { - char *type = xs_dict_get(v, "type"); - char *href = xs_dict_get(v, "href"); - char *name = xs_dict_get(v, "name"); + const char *type = xs_dict_get(v, "type"); + const char *href = xs_dict_get(v, "href"); + const char *name = xs_dict_get(v, "name"); if (xs_match(type, "image/*|video/*|Image|Video")) { /* */ xs *matteid = xs_fmt("%s_%d", id, xs_list_len(matt)); @@ -879,7 +882,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) xs *ml = xs_list_new(); xs *htl = xs_list_new(); xs *eml = xs_list_new(); - xs_list *tag = xs_dict_get(msg, "tag"); + const xs_list *tag = xs_dict_get(msg, "tag"); int n = 0; xs *tag_list = NULL; @@ -897,7 +900,8 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) tag = tag_list; xs_dict *v; - while (xs_list_iter(&tag, &v)) { + int c = 0; + while (xs_list_next(tag, &v, &c)) { const char *type = xs_dict_get(v, "type"); if (xs_is_null(type)) @@ -1006,7 +1010,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) xs *irt_mid = mastoapi_id(irto); st = xs_dict_set(st, "in_reply_to_id", irt_mid); - char *at = NULL; + const char *at = NULL; if (!xs_is_null(at = get_atto(irto))) { xs *at_md5 = xs_md5_hex(at, strlen(at)); st = xs_dict_set(st, "in_reply_to_account_id", at_md5); @@ -1118,7 +1122,7 @@ int process_auth_token(snac *snac, const xs_dict *req) /* processes an authorization token, if there is one */ { int logged_in = 0; - char *v; + const char *v; /* if there is an authorization field, try to validate it */ if (!xs_is_null(v = xs_dict_get(req, "authorization")) && xs_startswith(v, "Bearer ")) { @@ -1156,7 +1160,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, return 0; int status = 404; - xs_dict *args = xs_dict_get(req, "q_vars"); + const xs_dict *args = xs_dict_get(req, "q_vars"); xs *cmd = xs_replace_n(q_path, "/api", "", 1); snac snac1 = {0}; @@ -1182,7 +1186,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, acct = xs_dict_append(acct, "source", src); xs *avatar = NULL; - char *av = xs_dict_get(snac1.config, "avatar"); + const char *av = xs_dict_get(snac1.config, "avatar"); if (xs_is_null(av) || *av == '\0') avatar = xs_fmt("%s/susie.png", srv_baseurl); @@ -1193,7 +1197,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, acct = xs_dict_append(acct, "avatar_static", avatar); xs *header = NULL; - char *hd = xs_dict_get(snac1.config, "header"); + const char *hd = xs_dict_get(snac1.config, "header"); if (!xs_is_null(hd)) header = xs_dup(hd); @@ -1203,7 +1207,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, acct = xs_dict_append(acct, "header", header); acct = xs_dict_append(acct, "header_static", header); - xs_dict *metadata = xs_dict_get(snac1.config, "metadata"); + const xs_dict *metadata = xs_dict_get(snac1.config, "metadata"); if (xs_type(metadata) == XSTYPE_DICT) { xs *fields = xs_list_new(); xs_str *k; @@ -1217,7 +1221,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, while (xs_dict_next(metadata, &k, &v, &c)) { xs *val_date = NULL; - xs_number *verified_time = xs_dict_get(val_links, v); + const xs_number *verified_time = xs_dict_get(val_links, v); if (xs_type(verified_time) == XSTYPE_NUMBER) { time_t t = xs_number_get(verified_time); @@ -1283,13 +1287,13 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, else if (strcmp(cmd, "/v1/accounts/lookup") == 0) { /** **/ /* lookup an account */ - char *acct = xs_dict_get(args, "acct"); + const char *acct = xs_dict_get(args, "acct"); if (!xs_is_null(acct)) { xs *s = xs_strip_chars_i(xs_dup(acct), "@"); xs *l = xs_split_n(s, "@", 1); - char *uid = xs_list_get(l, 0); - char *host = xs_list_get(l, 1); + const char *uid = xs_list_get(l, 0); + const char *host = xs_list_get(l, 1); if (uid && (!host || strcmp(host, xs_dict_get(srv_config, "host")) == 0)) { snac user; @@ -1624,7 +1628,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, /* get the tag */ xs *l = xs_split(cmd, "/"); - char *tag = xs_list_get(l, -1); + const char *tag = xs_list_get(l, -1); xs *timeline = tag_search(tag, 0, limit); xs *out = xs_list_new(); @@ -1664,7 +1668,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, /* get the list id */ if (logged_in) { xs *l = xs_split(cmd, "/"); - char *list = xs_list_get(l, -1); + const char *list = xs_list_get(l, -1); xs *timeline = list_timeline(&snac1, list, 0, 2048); xs *out = xs_list_new(); @@ -1744,7 +1748,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *out = xs_list_new(); xs_list *p = l; xs_dict *v; - xs_list *excl = xs_dict_get(args, "exclude_types[]"); + const xs_list *excl = xs_dict_get(args, "exclude_types[]"); while (xs_list_iter(&p, &v)) { xs *noti = notify_get(&snac1, v); @@ -1876,7 +1880,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (xs_startswith(cmd, "/v1/lists/")) { /** list information **/ if (logged_in) { xs *l = xs_split(cmd, "/"); - char *p = xs_list_get(l, -1); + const char *p = xs_list_get(l, -1); if (p) { if (strcmp(p, "accounts") == 0) { @@ -1910,7 +1914,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs_list *v; while (xs_list_next(lol, &v, &c)) { - char *id = xs_list_get(v, 0); + const char *id = xs_list_get(v, 0); if (id && strcmp(id, p) == 0) { xs *d = xs_dict_new(); @@ -2314,7 +2318,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, int status = 404; xs *args = NULL; - char *i_ctype = xs_dict_get(req, "content-type"); + const char *i_ctype = xs_dict_get(req, "content-type"); if (i_ctype && xs_startswith(i_ctype, "application/json")) { if (!xs_is_null(payload)) @@ -2487,7 +2491,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, mid = MID_TO_MD5(mid); if (valid_status(timeline_get_by_md5(&snac, mid, &msg))) { - char *id = xs_dict_get(msg, "id"); + const char *id = xs_dict_get(msg, "id"); if (op == NULL) { /* no operation (?) */ @@ -2593,7 +2597,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (strcmp(cmd, "/v1/push/subscription") == 0) { /** **/ /* I don't know what I'm doing */ if (logged_in) { - char *v; + const char *v; xs *wpush = xs_dict_new(); @@ -2765,7 +2769,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, const char *id = xs_dict_get(msg, "id"); const char *atto = get_atto(msg); - xs_list *opts = xs_dict_get(msg, "oneOf"); + const xs_list *opts = xs_dict_get(msg, "oneOf"); if (opts == NULL) opts = xs_dict_get(msg, "anyOf"); @@ -2773,7 +2777,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, } else if (strcmp(op, "votes") == 0) { - xs_list *choices = xs_dict_get(args, "choices[]"); + const xs_list *choices = xs_dict_get(args, "choices[]"); if (xs_is_null(choices)) choices = xs_dict_get(args, "choices"); @@ -2781,7 +2785,8 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (xs_type(choices) == XSTYPE_LIST) { xs_str *v; - while (xs_list_iter(&choices, &v)) { + int c = 0; + while (xs_list_next(choices, &v, &c)) { int io = atoi(v); const xs_dict *o = xs_list_get(opts, io); @@ -2843,12 +2848,12 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (xs_startswith(cmd, "/v1/lists/")) { /** list maintenance **/ if (logged_in) { xs *l = xs_split(cmd, "/"); - char *op = xs_list_get(l, -1); - char *id = xs_list_get(l, -2); + const char *op = xs_list_get(l, -1); + const char *id = xs_list_get(l, -2); if (op && id && xs_is_hex(id)) { if (strcmp(op, "accounts") == 0) { - xs_list *accts = xs_dict_get(args, "account_ids[]"); + const xs_list *accts = xs_dict_get(args, "account_ids[]"); int c = 0; char *v; @@ -2888,7 +2893,7 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path, int status = 404; xs *args = NULL; - char *i_ctype = xs_dict_get(req, "content-type"); + const char *i_ctype = xs_dict_get(req, "content-type"); if (i_ctype && xs_startswith(i_ctype, "application/json")) { if (!xs_is_null(payload)) @@ -2921,13 +2926,13 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path, if (xs_startswith(cmd, "/v1/lists/")) { if (logged_in) { xs *l = xs_split(cmd, "/"); - char *p = xs_list_get(l, -1); + const char *p = xs_list_get(l, -1); if (p) { if (strcmp(p, "accounts") == 0) { /* delete account from list */ p = xs_list_get(l, -2); - xs_list *accts = xs_dict_get(args, "account_ids[]"); + const xs_list *accts = xs_dict_get(args, "account_ids[]"); int c = 0; char *v; @@ -2971,7 +2976,7 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path, int status = 404; xs *args = NULL; - char *i_ctype = xs_dict_get(req, "content-type"); + const char *i_ctype = xs_dict_get(req, "content-type"); if (i_ctype && xs_startswith(i_ctype, "application/json")) { if (!xs_is_null(payload)) -- cgit v1.2.3 From 8cf7559a7e21c5757455b948814d61e6e96f08f1 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 23 May 2024 10:01:37 +0200 Subject: Added more const. --- mastoapi.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 852713e..3936c2a 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -599,7 +599,7 @@ xs_dict *mastoapi_account(const xs_dict *actor) const xs_list *p; if (!xs_is_null(p = xs_dict_get(actor, "tag"))) { xs *eml = xs_list_new(); - xs_dict *v; + const xs_dict *v; int c = 0; while (xs_list_next(p, &v, &c)) { @@ -637,7 +637,7 @@ xs_dict *mastoapi_account(const xs_dict *actor) xs *fields = xs_list_new(); p = xs_dict_get(actor, "attachment"); - xs_dict *v; + const xs_dict *v; /* dict of validated links */ xs_dict *val_links = NULL; @@ -713,7 +713,7 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg) xs_dict *poll = xs_dict_new(); xs *mid = mastoapi_id(msg); const xs_list *opts = NULL; - xs_val *v; + const xs_val *v; int num_votes = 0; xs *options = xs_list_new(); @@ -849,7 +849,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) { xs_list *p = attach; - xs_dict *v; + const xs_dict *v; xs *matt = xs_list_new(); @@ -898,7 +898,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) tag_list = xs_list_new(); tag = tag_list; - xs_dict *v; + const xs_dict *v; int c = 0; while (xs_list_next(tag, &v, &c)) { @@ -1210,8 +1210,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, const xs_dict *metadata = xs_dict_get(snac1.config, "metadata"); if (xs_type(metadata) == XSTYPE_DICT) { xs *fields = xs_list_new(); - xs_str *k; - xs_str *v; + const xs_str *k; + const xs_str *v; xs_dict *val_links = snac1.links; if (xs_is_null(val_links)) @@ -1334,7 +1334,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *wers = follower_list(&snac1); xs *ulst = user_list(); xs_list *p; - xs_str *v; + const xs_str *v; xs_set seen; xs_set_init(&seen); @@ -1410,7 +1410,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, /* the public list of posts of a user */ xs *timeline = timeline_simple_list(&snac2, "public", 0, 256); xs_list *p = timeline; - xs_str *v; + const xs_str *v; out = xs_list_new(); @@ -1475,7 +1475,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *out = xs_list_new(); xs_list *p = timeline; - xs_str *v; + const xs_str *v; while (xs_list_iter(&p, &v) && cnt < limit) { xs *msg = NULL; @@ -1579,7 +1579,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *timeline = timeline_instance_list(0, limit); xs *out = xs_list_new(); xs_list *p = timeline; - xs_str *md5; + const xs_str *md5; snac *user = NULL; if (logged_in) @@ -1633,7 +1633,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *timeline = tag_search(tag, 0, limit); xs *out = xs_list_new(); xs_list *p = timeline; - xs_str *md5; + const xs_str *md5; while (xs_list_iter(&p, &md5) && cnt < limit) { xs *msg = NULL; @@ -1673,7 +1673,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *timeline = list_timeline(&snac1, list, 0, 2048); xs *out = xs_list_new(); int c = 0; - char *md5; + const char *md5; while (xs_list_next(timeline, &md5, &c)) { xs *msg = NULL; @@ -1747,7 +1747,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *l = notify_list(&snac1, 0, 64); xs *out = xs_list_new(); xs_list *p = l; - xs_dict *v; + const xs_dict *v; const xs_list *excl = xs_dict_get(args, "exclude_types[]"); while (xs_list_iter(&p, &v)) { @@ -1858,7 +1858,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *lol = list_maint(&snac1, NULL, 0); xs *l = xs_list_new(); int c = 0; - xs_list *li; + const xs_list *li; while (xs_list_next(lol, &li, &c)) { xs *d = xs_dict_new(); @@ -1890,7 +1890,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *actors = list_content(&snac1, p, NULL, 0); xs *out = xs_list_new(); int c = 0; - char *v; + const char *v; while (xs_list_next(actors, &v, &c)) { xs *actor = NULL; @@ -1911,7 +1911,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *out = xs_list_new(); xs *lol = list_maint(&snac1, NULL, 0); int c = 0; - xs_list *v; + const xs_list *v; while (xs_list_next(lol, &v, &c)) { const char *id = xs_list_get(v, 0); @@ -2105,7 +2105,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *anc = xs_list_new(); xs *des = xs_list_new(); xs_list *p; - xs_str *v; + const xs_str *v; char pid[64]; /* build the [grand]parent list, moving up */ @@ -2159,7 +2159,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, l = object_likes(xs_dict_get(msg, "id")); xs_list *p = l; - xs_str *v; + const xs_str *v; while (xs_list_iter(&p, &v)) { xs *actor2 = NULL; @@ -2267,7 +2267,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, int cnt = 40; xs *tl = content_search(&snac1, q, 1, 0, cnt, 0, &to); int c = 0; - char *v; + const char *v; while (xs_list_next(tl, &v, &c) && --cnt) { xs *post = NULL; @@ -2433,7 +2433,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, } xs_list *p = mi; - xs_str *v; + const xs_str *v; while (xs_list_iter(&p, &v)) { xs *l = xs_list_new(); @@ -2783,7 +2783,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, choices = xs_dict_get(args, "choices"); if (xs_type(choices) == XSTYPE_LIST) { - xs_str *v; + const xs_str *v; int c = 0; while (xs_list_next(choices, &v, &c)) { @@ -2855,7 +2855,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (strcmp(op, "accounts") == 0) { const xs_list *accts = xs_dict_get(args, "account_ids[]"); int c = 0; - char *v; + const char *v; while (xs_list_next(accts, &v, &c)) { list_content(&snac, id, v, 1); @@ -2934,7 +2934,7 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path, p = xs_list_get(l, -2); const xs_list *accts = xs_dict_get(args, "account_ids[]"); int c = 0; - char *v; + const char *v; while (xs_list_next(accts, &v, &c)) { list_content(&snac, p, v, 2); @@ -3083,7 +3083,7 @@ void mastoapi_purge(void) xs *spec = xs_fmt("%s/app/" "*.json", srv_basedir); xs *files = xs_glob(spec, 1, 0); xs_list *p = files; - xs_str *v; + const xs_str *v; time_t mt = time(NULL) - 3600; -- cgit v1.2.3