From ede4d6f2dc8f862337724054dcfeb31cbaa89bcc Mon Sep 17 00:00:00 2001 From: default Date: Sun, 30 Apr 2023 06:39:55 +0200 Subject: Some instance timeline work. --- mastoapi.c | 52 +++++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 29 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 001c0bc..92acd41 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1038,9 +1038,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (strcmp(cmd, "/v1/timelines/public") == 0) { /* the public timeline (public timelines for all users) */ - /* this is an ugly kludge: first users in the list get all the fame */ - - const char *limit_s = xs_dict_get(args, "limit"); + const char *limit_s = xs_dict_get(args, "limit"); int limit = 0; int cnt = 0; @@ -1050,44 +1048,40 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (limit == 0) limit = 20; - xs *out = xs_list_new(); - xs *users = user_list(); - xs_list *p = users; - xs_str *uid; - - while (xs_list_iter(&p, &uid) && cnt < limit) { - snac user; + xs *timeline = timeline_instance_list(0, limit); + xs *out = xs_list_new(); + xs_list *p = timeline; + xs_str *md5; - if (user_open(&user, uid)) { - xs *timeline = timeline_simple_list(&user, "public", 0, 4); - xs_list *p2 = timeline; - xs_str *v; + while (xs_list_iter(&p, &md5) && cnt < limit) { + xs *msg = NULL; - while (xs_list_iter(&p2, &v) && cnt < limit) { - xs *msg = NULL; + /* get the entry */ + if (!valid_status(object_get_by_md5(md5, &msg))) + continue; - /* get the entry */ - if (!valid_status(timeline_get_by_md5(&user, v, &msg))) - continue; + /* discard non-Notes */ + if (strcmp(xs_dict_get(msg, "type"), "Note") != 0) + continue; - /* discard non-Notes */ - if (strcmp(xs_dict_get(msg, "type"), "Note") != 0) - continue; + /* get the uid */ + xs *l = xs_split(xs_dict_get(msg, "attributedTo"), "/"); + const char *uid = xs_list_get(l, -1); - /* discard entries not by this user */ - if (!xs_startswith(xs_dict_get(msg, "id"), user.actor)) - continue; + if (!xs_is_null(uid)) { + snac user; + if (user_open(&user, uid)) { /* convert the Note into a Mastodon status */ xs *st = mastoapi_status(&user, msg); - if (st != NULL) { + if (st != NULL) out = xs_list_append(out, st); - cnt++; - } + + user_free(&user); } - user_free(&user); + cnt++; } } -- cgit v1.2.3 From cfa0df3ac5a8b62539a3d1830414ec3d81d24f5d Mon Sep 17 00:00:00 2001 From: default Date: Sun, 30 Apr 2023 07:00:49 +0200 Subject: The instance timeline now works. --- mastoapi.c | 29 +++++++++++------------------ snac.h | 4 ++-- 2 files changed, 13 insertions(+), 20 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 92acd41..5c4e27f 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1036,7 +1036,12 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, } else if (strcmp(cmd, "/v1/timelines/public") == 0) { - /* the public timeline (public timelines for all users) */ + /* the instance public timeline (public timelines for all users) */ + + /* NOTE: this api call needs no authorization; but, + I need a logged-in user in mastoapi_status() for + is_msg_public() and the liked/boosted flags, + so it will silently fail for pure public access */ const char *limit_s = xs_dict_get(args, "limit"); int limit = 0; @@ -1053,7 +1058,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs_list *p = timeline; xs_str *md5; - while (xs_list_iter(&p, &md5) && cnt < limit) { + while (logged_in && xs_list_iter(&p, &md5) && cnt < limit) { xs *msg = NULL; /* get the entry */ @@ -1064,23 +1069,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (strcmp(xs_dict_get(msg, "type"), "Note") != 0) continue; - /* get the uid */ - xs *l = xs_split(xs_dict_get(msg, "attributedTo"), "/"); - const char *uid = xs_list_get(l, -1); - - if (!xs_is_null(uid)) { - snac user; - - if (user_open(&user, uid)) { - /* convert the Note into a Mastodon status */ - xs *st = mastoapi_status(&user, msg); - - if (st != NULL) - out = xs_list_append(out, st); - - user_free(&user); - } + /* convert the Note into a Mastodon status */ + xs *st = mastoapi_status(&snac1, msg); + if (st != NULL) { + out = xs_list_append(out, st); cnt++; } } diff --git a/snac.h b/snac.h index 5478933..10e8c4c 100644 --- a/snac.h +++ b/snac.h @@ -127,8 +127,8 @@ int is_muted(snac *snac, const char *actor); void hide(snac *snac, const char *id); int is_hidden(snac *snac, const char *id); -int actor_add(snac *snac, const char *actor, d_char *msg); -int actor_get(snac *snac, const char *actor, d_char **data); +int actor_add(snac *snac, const char *actor, xs_dict *msg); +int actor_get(snac *snac, const char *actor, xs_dict **data); int static_get(snac *snac, const char *id, d_char **data, int *size); void static_put(snac *snac, const char *id, const char *data, int size); -- cgit v1.2.3 From a7d4513f776f831c36058dfb9b86e80438d16d26 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 1 May 2023 07:35:26 +0200 Subject: In /api/v1/statuses, get the object from the storage instead of from the timeline. This was affecting clicking on posts from the instance timeline, that were not in the logged-in user timeline. --- mastoapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 5c4e27f..3d0a939 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1313,7 +1313,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, /* skip the 'fake' part of the id */ id = MID_TO_MD5(id); - if (valid_status(timeline_get_by_md5(&snac1, id, &msg))) { + if (valid_status(object_get_by_md5(id, &msg))) { if (op == NULL) { if (!is_muted(&snac1, xs_dict_get(msg, "attributedTo"))) { /* return the status itself */ -- cgit v1.2.3 From 4595a3685992a8f31b86cca0ecf10e286dec52eb Mon Sep 17 00:00:00 2001 From: default Date: Mon, 1 May 2023 17:20:49 +0200 Subject: Partial support for mastoapi unfavourite / unreblog. --- data.c | 2 +- mastoapi.c | 9 +++++++-- snac.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'mastoapi.c') diff --git a/data.c b/data.c index e038f81..67f5751 100644 --- a/data.c +++ b/data.c @@ -827,7 +827,7 @@ int object_unadmire(const char *id, const char *actor, int like) status = index_del(fn, actor); - srv_debug(1, + srv_debug(0, xs_fmt("object_unadmire (%s) %s %s %d", like ? "Like" : "Announce", actor, fn, status)); return status; diff --git a/mastoapi.c b/mastoapi.c index 3d0a939..72d9579 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1670,7 +1670,11 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, } else if (strcmp(op, "unfavourite") == 0) { - /* snac does not support Undo+Like */ + /* partial support: as the original Like message + is not stored anywhere here, it's not possible + to send an Undo + Like; the only thing done here + is to delete the actor from the list of likes */ + object_unadmire(id, snac.actor, 1); } else if (strcmp(op, "reblog") == 0) { @@ -1685,7 +1689,8 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, } else if (strcmp(op, "unreblog") == 0) { - /* snac does not support Undo+Announce */ + /* partial support: see comment in 'unfavourite' */ + object_unadmire(id, snac.actor, 0); } else if (strcmp(op, "bookmark") == 0) { diff --git a/snac.h b/snac.h index 10e8c4c..a162618 100644 --- a/snac.h +++ b/snac.h @@ -83,6 +83,7 @@ int object_del_if_unref(const char *id); double object_ctime_by_md5(const char *md5); double object_ctime(const char *id); int object_admire(const char *id, const char *actor, int like); +int object_unadmire(const char *id, const char *actor, int like); int object_likes_len(const char *id); int object_announces_len(const char *id); -- cgit v1.2.3 From be5f08e6c3d605fb2beb1fdd1c2f10818b1e1812 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 2 May 2023 06:49:00 +0200 Subject: Use xs_replace_n() where it suits. --- http.c | 2 +- mastoapi.c | 14 +++++++------- webfinger.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'mastoapi.c') diff --git a/http.c b/http.c index ae46001..58d188c 100644 --- a/http.c +++ b/http.c @@ -33,7 +33,7 @@ xs_dict *http_signed_request_raw(const char *keyid, const char *seckey, date = xs_str_utctime(0, "%a, %d %b %Y %H:%M:%S GMT"); { - xs *s = xs_replace(url, "https:/" "/", ""); + xs *s = xs_replace_n(url, "https:/" "/", "", 1); l1 = xs_split_n(s, "/", 1); } diff --git a/mastoapi.c b/mastoapi.c index 72d9579..f7e101d 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -185,7 +185,7 @@ int oauth_get_handler(const xs_dict *req, const char *q_path, int status = 404; xs_dict *msg = xs_dict_get(req, "q_vars"); - xs *cmd = xs_replace(q_path, "/oauth", ""); + xs *cmd = xs_replace_n(q_path, "/oauth", "", 1); srv_debug(1, xs_fmt("oauth_get_handler %s", q_path)); @@ -245,7 +245,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, else args = xs_dup(xs_dict_get(req, "p_vars")); - xs *cmd = xs_replace(q_path, "/oauth", ""); + xs *cmd = xs_replace_n(q_path, "/oauth", "", 1); srv_debug(1, xs_fmt("oauth_post_handler %s", q_path)); @@ -328,7 +328,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, const char *auhdr = xs_dict_get(req, "authorization"); if (!xs_is_null(auhdr) && xs_startswith(auhdr, "Basic ")) { - xs *s1 = xs_replace(auhdr, "Basic ", ""); + xs *s1 = xs_replace_n(auhdr, "Basic ", "", 1); int size; xs *s2 = xs_base64_dec(s1, &size); @@ -787,7 +787,7 @@ int process_auth_token(snac *snac, const xs_dict *req) /* if there is an authorization field, try to validate it */ if (!xs_is_null(v = xs_dict_get(req, "authorization")) && xs_startswith(v, "Bearer ")) { - xs *tokid = xs_replace(v, "Bearer ", ""); + xs *tokid = xs_replace_n(v, "Bearer ", "", 1); xs *token = token_get(tokid); if (token != NULL) { @@ -826,7 +826,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, int status = 404; xs_dict *args = xs_dict_get(req, "q_vars"); - xs *cmd = xs_replace(q_path, "/api", ""); + xs *cmd = xs_replace_n(q_path, "/api", "", 1); snac snac1 = {0}; int logged_in = process_auth_token(&snac1, req); @@ -1500,7 +1500,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, printf("%s\n", j); }*/ - xs *cmd = xs_replace(q_path, "/api", ""); + xs *cmd = xs_replace_n(q_path, "/api", "", 1); snac snac = {0}; int logged_in = process_auth_token(&snac, req); @@ -1916,7 +1916,7 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path, if (args == NULL) return 400; - xs *cmd = xs_replace(q_path, "/api", ""); + xs *cmd = xs_replace_n(q_path, "/api", "", 1); snac snac = {0}; int logged_in = process_auth_token(&snac, req); diff --git a/webfinger.c b/webfinger.c index eb6b2ad..f56b6f2 100644 --- a/webfinger.c +++ b/webfinger.c @@ -21,7 +21,7 @@ int webfinger_request(const char *qs, char **actor, char **user) if (xs_startswith(qs, "https:/" "/")) { /* actor query: pick the host */ - xs *s = xs_replace(qs, "https:/" "/", ""); + xs *s = xs_replace_n(qs, "https:/" "/", "", 1); l = xs_split_n(s, "/", 1); @@ -74,7 +74,7 @@ int webfinger_request(const char *qs, char **actor, char **user) char *subject = xs_dict_get(obj, "subject"); if (subject) - *user = xs_replace(subject, "acct:", ""); + *user = xs_replace_n(subject, "acct:", "", 1); } if (actor != NULL) { @@ -136,7 +136,7 @@ int webfinger_get_handler(d_char *req, char *q_path, else if (xs_startswith(resource, "acct:")) { /* it's an account name */ - xs *an = xs_replace(resource, "acct:", ""); + xs *an = xs_replace_n(resource, "acct:", "", 1); xs *l = NULL; /* strip a possible leading @ */ -- cgit v1.2.3 From 0bd609f5be9aa24bced629273ff2428058388ac3 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 3 May 2023 07:57:10 +0200 Subject: Fixed missing notifications in certain circunstancies. --- html.c | 2 +- mastoapi.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'mastoapi.c') diff --git a/html.c b/html.c index 5f57262..9d6fbc6 100644 --- a/html.c +++ b/html.c @@ -1226,7 +1226,7 @@ xs_str *html_notifications(snac *snac) const char *actor_id = xs_dict_get(noti, "actor"); xs *actor = NULL; - if (!valid_status(object_get(actor_id, &actor))) + if (!valid_status(actor_get(snac, actor_id, &actor))) continue; xs *a_name = actor_name(actor); diff --git a/mastoapi.c b/mastoapi.c index f7e101d..7324bed 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1108,7 +1108,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *actor = NULL; xs *entry = NULL; - if (!valid_status(object_get(xs_dict_get(noti, "actor"), &actor))) + if (!valid_status(actor_get(&snac1, xs_dict_get(noti, "actor"), &actor))) continue; if (objid != NULL && !valid_status(object_get(objid, &entry))) -- cgit v1.2.3 From a9f0f2f695d653a2ca58057837fae6b8bc4dc13f Mon Sep 17 00:00:00 2001 From: default Date: Thu, 4 May 2023 06:27:13 +0200 Subject: Avoid crash in optional mastoapi argument. --- mastoapi.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 7324bed..c51c933 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1569,6 +1569,9 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (xs_is_null(media_ids)) media_ids = xs_dict_get(args, "media_ids[]"); + if (xs_is_null(visibility)) + visibility = "public"; + xs *attach_list = xs_list_new(); xs *irt = NULL; -- cgit v1.2.3 From 185aac23876f9ae5d9b613f8b9abd517c3ab3b4d Mon Sep 17 00:00:00 2001 From: default Date: Thu, 4 May 2023 09:28:36 +0200 Subject: Added -Wextra to C flags. --- Makefile | 2 +- activitypub.c | 2 ++ html.c | 3 +++ httpd.c | 6 ++++++ mastoapi.c | 13 +++++++++++++ webfinger.c | 2 ++ 6 files changed, 27 insertions(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/Makefile b/Makefile index 710d61f..7dbd9e7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PREFIX=/usr/local PREFIX_MAN=$(PREFIX)/man -CFLAGS?=-g -Wall +CFLAGS?=-g -Wall -Wextra all: snac diff --git a/activitypub.c b/activitypub.c index 86d33df..c25b733 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1524,6 +1524,8 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path, char **body, int *b_size, char **ctype) /* processes an input message */ { + (void)b_size; + int status = 202; /* accepted */ char *i_ctype = xs_dict_get(req, "content-type"); snac snac; diff --git a/html.c b/html.c index 3ba7930..3ebe70d 100644 --- a/html.c +++ b/html.c @@ -1551,6 +1551,9 @@ int html_post_handler(const xs_dict *req, const char *q_path, char *payload, int p_size, char **body, int *b_size, char **ctype) { + (void)p_size; + (void)ctype; + int status = 0; snac snac; char *uid, *p_path; diff --git a/httpd.c b/httpd.c index 5520457..fe93727 100644 --- a/httpd.c +++ b/httpd.c @@ -49,6 +49,8 @@ int server_get_handler(xs_dict *req, char *q_path, { int status = 0; + (void)req; + /* is it the server root? */ if (*q_path == '\0') { /* try to open greeting.html */ @@ -285,6 +287,8 @@ static jmp_buf on_break; void term_handler(int s) { + (void)s; + longjmp(on_break, 1); } @@ -401,6 +405,8 @@ static void *background_thread(void *arg) { time_t purge_time; + (void)arg; + /* first purge time */ purge_time = time(NULL) + 10 * 60; diff --git a/mastoapi.c b/mastoapi.c index c51c933..2413edb 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -175,6 +175,8 @@ const char *login_page = "" int oauth_get_handler(const xs_dict *req, const char *q_path, char **body, int *b_size, char **ctype) { + (void)b_size; + if (!xs_startswith(q_path, "/oauth/")) return 0; @@ -227,6 +229,9 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, const char *payload, int p_size, char **body, int *b_size, char **ctype) { + (void)p_size; + (void)b_size; + if (!xs_startswith(q_path, "/oauth/")) return 0; @@ -815,6 +820,8 @@ int process_auth_token(snac *snac, const xs_dict *req) int mastoapi_get_handler(const xs_dict *req, const char *q_path, char **body, int *b_size, char **ctype) { + (void)b_size; + if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) return 0; @@ -1474,6 +1481,9 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, const char *payload, int p_size, char **body, int *b_size, char **ctype) { + (void)p_size; + (void)b_size; + if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) return 0; @@ -1898,6 +1908,9 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path, const char *payload, int p_size, char **body, int *b_size, char **ctype) { + (void)p_size; + (void)b_size; + if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) return 0; diff --git a/webfinger.c b/webfinger.c index f56b6f2..765c469 100644 --- a/webfinger.c +++ b/webfinger.c @@ -104,6 +104,8 @@ int webfinger_get_handler(d_char *req, char *q_path, { int status; + (void)b_size; + if (strcmp(q_path, "/.well-known/webfinger") != 0) return 0; -- cgit v1.2.3 From 980a8d524fae11d17366e7aea56206d13f278e31 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 4 May 2023 09:34:33 +0200 Subject: Fixed more warnings. --- activitypub.c | 3 ++- html.c | 1 + mastoapi.c | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'mastoapi.c') diff --git a/activitypub.c b/activitypub.c index c25b733..0d5439d 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1384,8 +1384,9 @@ void process_queue_item(xs_dict *q_item) xs *headers = xs_dict_new(); headers = xs_dict_append(headers, "content-type", "application/json"); - xs *rsp = xs_http_request("POST", url, headers, + xs *rsp = xs_http_request("POST", url, headers, body, strlen(body), &status, NULL, NULL, 0); + rsp = xs_free(rsp); srv_debug(0, xs_fmt("telegram post %d", status)); } diff --git a/html.c b/html.c index 3ebe70d..8d4203d 100644 --- a/html.c +++ b/html.c @@ -1282,6 +1282,7 @@ xs_str *html_notifications(snac *snac) /* set the check time to now */ xs *dummy = notify_check_time(snac, 1); + dummy = xs_free(dummy); timeline_touch(snac); diff --git a/mastoapi.c b/mastoapi.c index 2413edb..c333573 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -542,7 +542,6 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) xs *f = xs_val_new(XSTYPE_FALSE); xs *t = xs_val_new(XSTYPE_TRUE); xs *n = xs_val_new(XSTYPE_NULL); - xs *el = xs_list_new(); xs *idx = NULL; xs *ixc = NULL; -- cgit v1.2.3 From f6ef275fa3dfd0e74093a5eb74a5167f7be4ece0 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 4 May 2023 11:08:35 +0200 Subject: Made the post action configurable in login_page. --- mastoapi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index c333573..4396155 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -162,7 +162,7 @@ const char *login_page = "" "\n" "

%s OAuth identify

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

Login:

\n" "

Password:

\n" "\n" @@ -208,7 +208,8 @@ int oauth_get_handler(const xs_dict *req, const char *q_path, if (xs_is_null(state)) state = ""; - *body = xs_fmt(login_page, host, "", host, ruri, cid, state, USER_AGENT); + *body = xs_fmt(login_page, host, "", host, "oauth/x-snac-login", + ruri, cid, state, USER_AGENT); *ctype = "text/html"; status = 200; @@ -264,7 +265,8 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, const char *host = xs_dict_get(srv_config, "host"); /* by default, generate another login form with an error */ - *body = xs_fmt(login_page, host, "LOGIN INCORRECT", host, redir, cid, state, USER_AGENT); + *body = xs_fmt(login_page, host, "LOGIN INCORRECT", host, "oauth/x-snac-login", + redir, cid, state, USER_AGENT); *ctype = "text/html"; status = 200; @@ -273,8 +275,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, if (user_open(&snac, login)) { /* check the login + password */ - if (check_password(login, passwd, - xs_dict_get(snac.config, "passwd"))) { + if (check_password(login, passwd, xs_dict_get(snac.config, "passwd"))) { /* success! redirect to the desired uri */ xs *code = random_str(); -- cgit v1.2.3 From ec6f94e27ed0bfb5f8dd029f372cf4fe060ca19f Mon Sep 17 00:00:00 2001 From: default Date: Thu, 4 May 2023 11:52:04 +0200 Subject: New url /oauth/x-snac-get-token. --- mastoapi.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 4396155..6729cf7 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -221,6 +221,16 @@ int oauth_get_handler(const xs_dict *req, const char *q_path, else srv_debug(0, xs_fmt("oauth authorize: invalid or unset arguments")); } + else + if (strcmp(cmd, "/x-snac-get-token") == 0) { + const char *host = xs_dict_get(srv_config, "host"); + + *body = xs_fmt(login_page, host, "", host, "oauth/x-snac-get-token", + "", "", "", USER_AGENT); + *ctype = "text/html"; + status = 200; + + } return status; } @@ -427,6 +437,48 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, status = 403; } } + 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"); + + /* by default, generate another login form with an error */ + *body = xs_fmt(login_page, host, "LOGIN INCORRECT", host, "oauth/x-snac-get-token", + "", "", "", USER_AGENT); + *ctype = "text/html"; + status = 200; + + if (login && passwd) { + snac user; + + if (user_open(&user, login)) { + /* check the login + password */ + if (check_password(login, passwd, xs_dict_get(user.config, "passwd"))) { + /* success! create a new token */ + xs *tokid = random_str(); + + srv_debug(1, xs_fmt("x-snac-new-token: " + "successful login for %s, new token %s", login, tokid)); + + xs *token = xs_dict_new(); + token = xs_dict_append(token, "token", tokid); + token = xs_dict_append(token, "client_id", "snac-client"); + token = xs_dict_append(token, "client_secret", ""); + token = xs_dict_append(token, "uid", login); + token = xs_dict_append(token, "code", ""); + + token_add(tokid, token); + + *ctype = "text/plain"; + xs_free(*body); + *body = xs_dup(tokid); + } + + user_free(&user); + } + } + } return status; } -- cgit v1.2.3 From 212d1350fe261dbc04eb8cc9a9462c5ce5747597 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 4 May 2023 11:53:17 +0200 Subject: Fixed mastoapi debug levels. --- mastoapi.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 6729cf7..3c4be5a 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -213,13 +213,13 @@ int oauth_get_handler(const xs_dict *req, const char *q_path, *ctype = "text/html"; status = 200; - srv_debug(0, xs_fmt("oauth authorize: generating login page")); + srv_debug(1, xs_fmt("oauth authorize: generating login page")); } else - srv_debug(0, xs_fmt("oauth authorize: bad client_id %s", cid)); + srv_debug(1, xs_fmt("oauth authorize: bad client_id %s", cid)); } else - srv_debug(0, xs_fmt("oauth authorize: invalid or unset arguments")); + srv_debug(1, xs_fmt("oauth authorize: invalid or unset arguments")); } else if (strcmp(cmd, "/x-snac-get-token") == 0) { @@ -389,7 +389,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, const char *uid = xs_dict_get(app, "uid"); - srv_debug(0, xs_fmt("oauth token: " + srv_debug(1, xs_fmt("oauth token: " "successful login for %s, new token %s", uid, tokid)); xs *token = xs_dict_new(); @@ -403,7 +403,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, } } else { - srv_debug(0, xs_fmt("oauth token: invalid or unset arguments")); + srv_debug(1, xs_fmt("oauth token: invalid or unset arguments")); status = 400; } } @@ -425,7 +425,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, } else { token_del(tokid); - srv_debug(0, xs_fmt("oauth revoke: revoked token %s", tokid)); + srv_debug(1, xs_fmt("oauth revoke: revoked token %s", tokid)); status = 200; /* also delete the app, as it serves no purpose from now on */ @@ -433,7 +433,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, } } else { - srv_debug(0, xs_fmt("oauth revoke: invalid or unset arguments")); + srv_debug(1, xs_fmt("oauth revoke: invalid or unset arguments")); status = 403; } } @@ -1611,7 +1611,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, app_add(cid, app); - srv_debug(0, xs_fmt("mastoapi apps: new app %s", cid)); + srv_debug(1, xs_fmt("mastoapi apps: new app %s", cid)); } } else -- cgit v1.2.3 From eed24fde1a9c3577cc2d41dfdb25c13ea816dd42 Mon Sep 17 00:00:00 2001 From: default Date: Sat, 6 May 2023 11:10:08 +0200 Subject: Fixed a bug in Tusky's image send. --- mastoapi.c | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 3c4be5a..b82ecfa 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1333,25 +1333,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, cfg = xs_dict_append(cfg, "statuses", d11); } - { - xs *d11 = xs_dict_new(); - xs *mt = xs_list_new(); - - mt = xs_list_append(mt, "image/jpeg"); - mt = xs_list_append(mt, "image/png"); - mt = xs_list_append(mt, "image/gif"); - - d11 = xs_dict_append(d11, "supported_mime_types", mt); - - d11 = xs_dict_append(d11, "image_size_limit", z); - d11 = xs_dict_append(d11, "image_matrix_limit", z); - d11 = xs_dict_append(d11, "video_size_limit", z); - d11 = xs_dict_append(d11, "video_matrix_limit", z); - d11 = xs_dict_append(d11, "video_frame_rate_limit", z); - - cfg = xs_dict_append(cfg, "media_attachments", d11); - } - ins = xs_dict_append(ins, "configuration", cfg); *body = xs_json_dumps_pp(ins, 4); -- cgit v1.2.3