From 26840e0dc0e7322b2041c21b4e44ed9a34afff4b Mon Sep 17 00:00:00 2001 From: default Date: Thu, 18 Apr 2024 17:13:31 +0200 Subject: [PATCH] Some tweaks to previous patch. --- activitypub.c | 4 ++-- data.c | 6 ++++-- html.c | 2 +- mastoapi.c | 20 +++++++++++--------- webfinger.c | 8 +++++--- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/activitypub.c b/activitypub.c index 53f102e..c05e3f3 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1277,7 +1277,7 @@ xs_dict *msg_actor(snac *snac) xs *k2 = encode_html(k); xs *v2 = NULL; - if (xs_startswith(v, "http")) { + if (xs_startswith(v, "https:/") || xs_startswith(v, "http:/")) { xs *t = encode_html(v); v2 = xs_fmt("%s", t, t); } @@ -1369,7 +1369,7 @@ xs_dict *msg_follow(snac *snac, const char *q) xs *url_or_uid = xs_strip_i(xs_str_new(q)); - if (xs_startswith(url_or_uid, "http")) + if (xs_startswith(url_or_uid, "https:/") || xs_startswith(url_or_uid, "http:/")) actor = xs_dup(url_or_uid); else if (!valid_status(webfinger_request(url_or_uid, &actor, NULL)) || actor == NULL) { diff --git a/data.c b/data.c index d3045f4..1e46395 100644 --- a/data.c +++ b/data.c @@ -60,15 +60,17 @@ int srv_open(char *basedir, int auto_upgrade) char *host; char *prefix; char *dbglvl; + char *proto; host = xs_dict_get(srv_config, "host"); prefix = xs_dict_get(srv_config, "prefix"); dbglvl = xs_dict_get(srv_config, "dbglevel"); + proto = xs_dict_get_def(srv_config, "protocol", "https"); if (host == NULL || prefix == NULL) error = xs_str_new("ERROR: cannot get server data"); else { - srv_baseurl = xs_fmt("http://%s%s", host, prefix); + srv_baseurl = xs_fmt("%s:/" "/%s%s", proto, host, prefix); dbglevel = (int) xs_number_get(dbglvl); @@ -1990,7 +1992,7 @@ xs_list *inbox_list(void) xs_str *_instance_block_fn(const char *instance) { - xs *s = xs_replace(instance, "http:/" "/", ""); + xs *s = xs_replace(instance, "http:/" "/", ""); xs *s1 = xs_replace(s, "https:/" "/", ""); xs *l = xs_split(s1, "/"); char *p = xs_list_get(l, 0); diff --git a/html.c b/html.c index a251e21..d52ef03 100644 --- a/html.c +++ b/html.c @@ -813,7 +813,7 @@ static xs_html *html_user_body(snac *user, int read_only) while (xs_dict_next(metadata, &k, &v, &c)) { xs_html *value; - if (xs_startswith(v, "http")) { + if (xs_startswith(v, "https:/") || xs_startswith(v, "http:/")) { /* is this link validated? */ xs *verified_link = NULL; xs_number *val_time = xs_dict_get(val_links, v); 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; diff --git a/webfinger.c b/webfinger.c index 331191b..5b13d2f 100644 --- a/webfinger.c +++ b/webfinger.c @@ -19,7 +19,7 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us xs_str *host = NULL; xs *resource = NULL; - if (xs_startswith(qs, "http")) { + if (xs_startswith(qs, "https:/") || xs_startswith(qs, "http:/")) { /* actor query: pick the host */ xs *s1 = xs_replace_n(qs, "http:/" "/", "", 1); xs *s = xs_replace_n(s1, "https:/" "/", "", 1); @@ -70,7 +70,9 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us &payload, &p_size, &ctype); } else { - xs *url = xs_fmt("http:/" "/%s/.well-known/webfinger?resource=%s", host, resource); + const char *proto = xs_dict_get_def(srv_config, "protocol", "https"); + + xs *url = xs_fmt("%s:/" "/%s/.well-known/webfinger?resource=%s", proto, host, resource); if (snac == NULL) xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0); @@ -140,7 +142,7 @@ int webfinger_get_handler(xs_dict *req, char *q_path, snac snac; int found = 0; - if (xs_startswith(resource, "https")) { + if (xs_startswith(resource, "https:/") || xs_startswith(resource, "http:/")) { /* actor search: find a user with this actor */ xs *l = xs_split(resource, "/"); char *uid = xs_list_get(l, -1);