commit 26840e0
default
·
2024-04-18 15:13:31 +0000 UTC
parent 100c9cf
Some tweaks to previous patch.
5 files changed,
+23,
-17
+2,
-2
1@@ -1277,7 +1277,7 @@ xs_dict *msg_actor(snac *snac)
2 xs *k2 = encode_html(k);
3 xs *v2 = NULL;
4
5- if (xs_startswith(v, "http")) {
6+ if (xs_startswith(v, "https:/") || xs_startswith(v, "http:/")) {
7 xs *t = encode_html(v);
8 v2 = xs_fmt("<a href=\"%s\" rel=\"me\">%s</a>", t, t);
9 }
10@@ -1369,7 +1369,7 @@ xs_dict *msg_follow(snac *snac, const char *q)
11
12 xs *url_or_uid = xs_strip_i(xs_str_new(q));
13
14- if (xs_startswith(url_or_uid, "http"))
15+ if (xs_startswith(url_or_uid, "https:/") || xs_startswith(url_or_uid, "http:/"))
16 actor = xs_dup(url_or_uid);
17 else
18 if (!valid_status(webfinger_request(url_or_uid, &actor, NULL)) || actor == NULL) {
M
data.c
+4,
-2
1@@ -60,15 +60,17 @@ int srv_open(char *basedir, int auto_upgrade)
2 char *host;
3 char *prefix;
4 char *dbglvl;
5+ char *proto;
6
7 host = xs_dict_get(srv_config, "host");
8 prefix = xs_dict_get(srv_config, "prefix");
9 dbglvl = xs_dict_get(srv_config, "dbglevel");
10+ proto = xs_dict_get_def(srv_config, "protocol", "https");
11
12 if (host == NULL || prefix == NULL)
13 error = xs_str_new("ERROR: cannot get server data");
14 else {
15- srv_baseurl = xs_fmt("http://%s%s", host, prefix);
16+ srv_baseurl = xs_fmt("%s:/" "/%s%s", proto, host, prefix);
17
18 dbglevel = (int) xs_number_get(dbglvl);
19
20@@ -1990,7 +1992,7 @@ xs_list *inbox_list(void)
21
22 xs_str *_instance_block_fn(const char *instance)
23 {
24- xs *s = xs_replace(instance, "http:/" "/", "");
25+ xs *s = xs_replace(instance, "http:/" "/", "");
26 xs *s1 = xs_replace(s, "https:/" "/", "");
27 xs *l = xs_split(s1, "/");
28 char *p = xs_list_get(l, 0);
M
html.c
+1,
-1
1@@ -813,7 +813,7 @@ static xs_html *html_user_body(snac *user, int read_only)
2 while (xs_dict_next(metadata, &k, &v, &c)) {
3 xs_html *value;
4
5- if (xs_startswith(v, "http")) {
6+ if (xs_startswith(v, "https:/") || xs_startswith(v, "http:/")) {
7 /* is this link validated? */
8 xs *verified_link = NULL;
9 xs_number *val_time = xs_dict_get(val_links, v);
+11,
-9
1@@ -156,7 +156,7 @@ const char *login_page = ""
2 "</head>\n"
3 "<body><h1>%s OAuth identify</h1>\n"
4 "<div style=\"background-color: red; color: white\">%s</div>\n"
5-"<form method=\"post\" action=\"http:/" "/%s/%s\">\n"
6+"<form method=\"post\" action=\"%s:/" "/%s/%s\">\n"
7 "<p>Login: <input type=\"text\" name=\"login\"></p>\n"
8 "<p>Password: <input type=\"password\" name=\"passwd\"></p>\n"
9 "<input type=\"hidden\" name=\"redir\" value=\"%s\">\n"
10@@ -193,11 +193,12 @@ int oauth_get_handler(const xs_dict *req, const char *q_path,
11
12 if (app != NULL) {
13 const char *host = xs_dict_get(srv_config, "host");
14+ const char *proto = xs_dict_get_def(srv_config, "protocol", "https");
15
16 if (xs_is_null(state))
17 state = "";
18
19- *body = xs_fmt(login_page, host, host, "", host, "oauth/x-snac-login",
20+ *body = xs_fmt(login_page, host, host, "", proto, host, "oauth/x-snac-login",
21 ruri, cid, state, USER_AGENT);
22 *ctype = "text/html";
23 status = 200;
24@@ -213,8 +214,9 @@ int oauth_get_handler(const xs_dict *req, const char *q_path,
25 else
26 if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/
27 const char *host = xs_dict_get(srv_config, "host");
28+ const char *proto = xs_dict_get_def(srv_config, "protocol", "https");
29
30- *body = xs_fmt(login_page, host, host, "", host, "oauth/x-snac-get-token",
31+ *body = xs_fmt(login_page, host, host, "", proto, host, "oauth/x-snac-get-token",
32 "", "", "", USER_AGENT);
33 *ctype = "text/html";
34 status = 200;
35@@ -265,11 +267,11 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
36 const char *redir = xs_dict_get(args, "redir");
37 const char *cid = xs_dict_get(args, "cid");
38 const char *state = xs_dict_get(args, "state");
39-
40- const char *host = xs_dict_get(srv_config, "host");
41+ const char *host = xs_dict_get(srv_config, "host");
42+ const char *proto = xs_dict_get_def(srv_config, "protocol", "https");
43
44 /* by default, generate another login form with an error */
45- *body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", host, "oauth/x-snac-login",
46+ *body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", proto, host, "oauth/x-snac-login",
47 redir, cid, state, USER_AGENT);
48 *ctype = "text/html";
49 status = 200;
50@@ -450,11 +452,11 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
51 if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/
52 const char *login = xs_dict_get(args, "login");
53 const char *passwd = xs_dict_get(args, "passwd");
54-
55- const char *host = xs_dict_get(srv_config, "host");
56+ const char *host = xs_dict_get(srv_config, "host");
57+ const char *proto = xs_dict_get_def(srv_config, "protocol", "https");
58
59 /* by default, generate another login form with an error */
60- *body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", host, "oauth/x-snac-get-token",
61+ *body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", proto, host, "oauth/x-snac-get-token",
62 "", "", "", USER_AGENT);
63 *ctype = "text/html";
64 status = 200;
+5,
-3
1@@ -19,7 +19,7 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us
2 xs_str *host = NULL;
3 xs *resource = NULL;
4
5- if (xs_startswith(qs, "http")) {
6+ if (xs_startswith(qs, "https:/") || xs_startswith(qs, "http:/")) {
7 /* actor query: pick the host */
8 xs *s1 = xs_replace_n(qs, "http:/" "/", "", 1);
9 xs *s = xs_replace_n(s1, "https:/" "/", "", 1);
10@@ -70,7 +70,9 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us
11 &payload, &p_size, &ctype);
12 }
13 else {
14- xs *url = xs_fmt("http:/" "/%s/.well-known/webfinger?resource=%s", host, resource);
15+ const char *proto = xs_dict_get_def(srv_config, "protocol", "https");
16+
17+ xs *url = xs_fmt("%s:/" "/%s/.well-known/webfinger?resource=%s", proto, host, resource);
18
19 if (snac == NULL)
20 xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0);
21@@ -140,7 +142,7 @@ int webfinger_get_handler(xs_dict *req, char *q_path,
22 snac snac;
23 int found = 0;
24
25- if (xs_startswith(resource, "https")) {
26+ if (xs_startswith(resource, "https:/") || xs_startswith(resource, "http:/")) {
27 /* actor search: find a user with this actor */
28 xs *l = xs_split(resource, "/");
29 char *uid = xs_list_get(l, -1);