diff options
| author | 2024-04-18 17:13:31 +0200 | |
|---|---|---|
| committer | 2024-04-18 17:13:31 +0200 | |
| commit | 26840e0dc0e7322b2041c21b4e44ed9a34afff4b (patch) | |
| tree | 096c8e9c65df453f5e45bfde8ca8662b9a82c899 | |
| parent | Merge pull request 'Ability to federate with hidden networks #93 (update for ... (diff) | |
| download | penes-snac2-26840e0dc0e7322b2041c21b4e44ed9a34afff4b.tar.gz penes-snac2-26840e0dc0e7322b2041c21b4e44ed9a34afff4b.tar.xz penes-snac2-26840e0dc0e7322b2041c21b4e44ed9a34afff4b.zip | |
Some tweaks to previous patch.
| -rw-r--r-- | activitypub.c | 4 | ||||
| -rw-r--r-- | data.c | 6 | ||||
| -rw-r--r-- | html.c | 2 | ||||
| -rw-r--r-- | mastoapi.c | 20 | ||||
| -rw-r--r-- | 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) | |||
| 1277 | xs *k2 = encode_html(k); | 1277 | xs *k2 = encode_html(k); |
| 1278 | xs *v2 = NULL; | 1278 | xs *v2 = NULL; |
| 1279 | 1279 | ||
| 1280 | if (xs_startswith(v, "http")) { | 1280 | if (xs_startswith(v, "https:/") || xs_startswith(v, "http:/")) { |
| 1281 | xs *t = encode_html(v); | 1281 | xs *t = encode_html(v); |
| 1282 | v2 = xs_fmt("<a href=\"%s\" rel=\"me\">%s</a>", t, t); | 1282 | v2 = xs_fmt("<a href=\"%s\" rel=\"me\">%s</a>", t, t); |
| 1283 | } | 1283 | } |
| @@ -1369,7 +1369,7 @@ xs_dict *msg_follow(snac *snac, const char *q) | |||
| 1369 | 1369 | ||
| 1370 | xs *url_or_uid = xs_strip_i(xs_str_new(q)); | 1370 | xs *url_or_uid = xs_strip_i(xs_str_new(q)); |
| 1371 | 1371 | ||
| 1372 | if (xs_startswith(url_or_uid, "http")) | 1372 | if (xs_startswith(url_or_uid, "https:/") || xs_startswith(url_or_uid, "http:/")) |
| 1373 | actor = xs_dup(url_or_uid); | 1373 | actor = xs_dup(url_or_uid); |
| 1374 | else | 1374 | else |
| 1375 | if (!valid_status(webfinger_request(url_or_uid, &actor, NULL)) || actor == NULL) { | 1375 | if (!valid_status(webfinger_request(url_or_uid, &actor, NULL)) || actor == NULL) { |
| @@ -60,15 +60,17 @@ int srv_open(char *basedir, int auto_upgrade) | |||
| 60 | char *host; | 60 | char *host; |
| 61 | char *prefix; | 61 | char *prefix; |
| 62 | char *dbglvl; | 62 | char *dbglvl; |
| 63 | char *proto; | ||
| 63 | 64 | ||
| 64 | host = xs_dict_get(srv_config, "host"); | 65 | host = xs_dict_get(srv_config, "host"); |
| 65 | prefix = xs_dict_get(srv_config, "prefix"); | 66 | prefix = xs_dict_get(srv_config, "prefix"); |
| 66 | dbglvl = xs_dict_get(srv_config, "dbglevel"); | 67 | dbglvl = xs_dict_get(srv_config, "dbglevel"); |
| 68 | proto = xs_dict_get_def(srv_config, "protocol", "https"); | ||
| 67 | 69 | ||
| 68 | if (host == NULL || prefix == NULL) | 70 | if (host == NULL || prefix == NULL) |
| 69 | error = xs_str_new("ERROR: cannot get server data"); | 71 | error = xs_str_new("ERROR: cannot get server data"); |
| 70 | else { | 72 | else { |
| 71 | srv_baseurl = xs_fmt("http://%s%s", host, prefix); | 73 | srv_baseurl = xs_fmt("%s:/" "/%s%s", proto, host, prefix); |
| 72 | 74 | ||
| 73 | dbglevel = (int) xs_number_get(dbglvl); | 75 | dbglevel = (int) xs_number_get(dbglvl); |
| 74 | 76 | ||
| @@ -1990,7 +1992,7 @@ xs_list *inbox_list(void) | |||
| 1990 | 1992 | ||
| 1991 | xs_str *_instance_block_fn(const char *instance) | 1993 | xs_str *_instance_block_fn(const char *instance) |
| 1992 | { | 1994 | { |
| 1993 | xs *s = xs_replace(instance, "http:/" "/", ""); | 1995 | xs *s = xs_replace(instance, "http:/" "/", ""); |
| 1994 | xs *s1 = xs_replace(s, "https:/" "/", ""); | 1996 | xs *s1 = xs_replace(s, "https:/" "/", ""); |
| 1995 | xs *l = xs_split(s1, "/"); | 1997 | xs *l = xs_split(s1, "/"); |
| 1996 | char *p = xs_list_get(l, 0); | 1998 | char *p = xs_list_get(l, 0); |
| @@ -813,7 +813,7 @@ static xs_html *html_user_body(snac *user, int read_only) | |||
| 813 | while (xs_dict_next(metadata, &k, &v, &c)) { | 813 | while (xs_dict_next(metadata, &k, &v, &c)) { |
| 814 | xs_html *value; | 814 | xs_html *value; |
| 815 | 815 | ||
| 816 | if (xs_startswith(v, "http")) { | 816 | if (xs_startswith(v, "https:/") || xs_startswith(v, "http:/")) { |
| 817 | /* is this link validated? */ | 817 | /* is this link validated? */ |
| 818 | xs *verified_link = NULL; | 818 | xs *verified_link = NULL; |
| 819 | xs_number *val_time = xs_dict_get(val_links, v); | 819 | xs_number *val_time = xs_dict_get(val_links, v); |
| @@ -156,7 +156,7 @@ const char *login_page = "" | |||
| 156 | "</head>\n" | 156 | "</head>\n" |
| 157 | "<body><h1>%s OAuth identify</h1>\n" | 157 | "<body><h1>%s OAuth identify</h1>\n" |
| 158 | "<div style=\"background-color: red; color: white\">%s</div>\n" | 158 | "<div style=\"background-color: red; color: white\">%s</div>\n" |
| 159 | "<form method=\"post\" action=\"http:/" "/%s/%s\">\n" | 159 | "<form method=\"post\" action=\"%s:/" "/%s/%s\">\n" |
| 160 | "<p>Login: <input type=\"text\" name=\"login\"></p>\n" | 160 | "<p>Login: <input type=\"text\" name=\"login\"></p>\n" |
| 161 | "<p>Password: <input type=\"password\" name=\"passwd\"></p>\n" | 161 | "<p>Password: <input type=\"password\" name=\"passwd\"></p>\n" |
| 162 | "<input type=\"hidden\" name=\"redir\" value=\"%s\">\n" | 162 | "<input type=\"hidden\" name=\"redir\" value=\"%s\">\n" |
| @@ -193,11 +193,12 @@ int oauth_get_handler(const xs_dict *req, const char *q_path, | |||
| 193 | 193 | ||
| 194 | if (app != NULL) { | 194 | if (app != NULL) { |
| 195 | const char *host = xs_dict_get(srv_config, "host"); | 195 | const char *host = xs_dict_get(srv_config, "host"); |
| 196 | const char *proto = xs_dict_get_def(srv_config, "protocol", "https"); | ||
| 196 | 197 | ||
| 197 | if (xs_is_null(state)) | 198 | if (xs_is_null(state)) |
| 198 | state = ""; | 199 | state = ""; |
| 199 | 200 | ||
| 200 | *body = xs_fmt(login_page, host, host, "", host, "oauth/x-snac-login", | 201 | *body = xs_fmt(login_page, host, host, "", proto, host, "oauth/x-snac-login", |
| 201 | ruri, cid, state, USER_AGENT); | 202 | ruri, cid, state, USER_AGENT); |
| 202 | *ctype = "text/html"; | 203 | *ctype = "text/html"; |
| 203 | status = 200; | 204 | status = 200; |
| @@ -213,8 +214,9 @@ int oauth_get_handler(const xs_dict *req, const char *q_path, | |||
| 213 | else | 214 | else |
| 214 | if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/ | 215 | if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/ |
| 215 | const char *host = xs_dict_get(srv_config, "host"); | 216 | const char *host = xs_dict_get(srv_config, "host"); |
| 217 | const char *proto = xs_dict_get_def(srv_config, "protocol", "https"); | ||
| 216 | 218 | ||
| 217 | *body = xs_fmt(login_page, host, host, "", host, "oauth/x-snac-get-token", | 219 | *body = xs_fmt(login_page, host, host, "", proto, host, "oauth/x-snac-get-token", |
| 218 | "", "", "", USER_AGENT); | 220 | "", "", "", USER_AGENT); |
| 219 | *ctype = "text/html"; | 221 | *ctype = "text/html"; |
| 220 | status = 200; | 222 | status = 200; |
| @@ -265,11 +267,11 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, | |||
| 265 | const char *redir = xs_dict_get(args, "redir"); | 267 | const char *redir = xs_dict_get(args, "redir"); |
| 266 | const char *cid = xs_dict_get(args, "cid"); | 268 | const char *cid = xs_dict_get(args, "cid"); |
| 267 | const char *state = xs_dict_get(args, "state"); | 269 | const char *state = xs_dict_get(args, "state"); |
| 268 | 270 | const char *host = xs_dict_get(srv_config, "host"); | |
| 269 | const char *host = xs_dict_get(srv_config, "host"); | 271 | const char *proto = xs_dict_get_def(srv_config, "protocol", "https"); |
| 270 | 272 | ||
| 271 | /* by default, generate another login form with an error */ | 273 | /* by default, generate another login form with an error */ |
| 272 | *body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", host, "oauth/x-snac-login", | 274 | *body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", proto, host, "oauth/x-snac-login", |
| 273 | redir, cid, state, USER_AGENT); | 275 | redir, cid, state, USER_AGENT); |
| 274 | *ctype = "text/html"; | 276 | *ctype = "text/html"; |
| 275 | status = 200; | 277 | status = 200; |
| @@ -450,11 +452,11 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, | |||
| 450 | if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/ | 452 | if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/ |
| 451 | const char *login = xs_dict_get(args, "login"); | 453 | const char *login = xs_dict_get(args, "login"); |
| 452 | const char *passwd = xs_dict_get(args, "passwd"); | 454 | const char *passwd = xs_dict_get(args, "passwd"); |
| 453 | 455 | const char *host = xs_dict_get(srv_config, "host"); | |
| 454 | const char *host = xs_dict_get(srv_config, "host"); | 456 | const char *proto = xs_dict_get_def(srv_config, "protocol", "https"); |
| 455 | 457 | ||
| 456 | /* by default, generate another login form with an error */ | 458 | /* by default, generate another login form with an error */ |
| 457 | *body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", host, "oauth/x-snac-get-token", | 459 | *body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", proto, host, "oauth/x-snac-get-token", |
| 458 | "", "", "", USER_AGENT); | 460 | "", "", "", USER_AGENT); |
| 459 | *ctype = "text/html"; | 461 | *ctype = "text/html"; |
| 460 | status = 200; | 462 | 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 | |||
| 19 | xs_str *host = NULL; | 19 | xs_str *host = NULL; |
| 20 | xs *resource = NULL; | 20 | xs *resource = NULL; |
| 21 | 21 | ||
| 22 | if (xs_startswith(qs, "http")) { | 22 | if (xs_startswith(qs, "https:/") || xs_startswith(qs, "http:/")) { |
| 23 | /* actor query: pick the host */ | 23 | /* actor query: pick the host */ |
| 24 | xs *s1 = xs_replace_n(qs, "http:/" "/", "", 1); | 24 | xs *s1 = xs_replace_n(qs, "http:/" "/", "", 1); |
| 25 | xs *s = xs_replace_n(s1, "https:/" "/", "", 1); | 25 | 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 | |||
| 70 | &payload, &p_size, &ctype); | 70 | &payload, &p_size, &ctype); |
| 71 | } | 71 | } |
| 72 | else { | 72 | else { |
| 73 | xs *url = xs_fmt("http:/" "/%s/.well-known/webfinger?resource=%s", host, resource); | 73 | const char *proto = xs_dict_get_def(srv_config, "protocol", "https"); |
| 74 | |||
| 75 | xs *url = xs_fmt("%s:/" "/%s/.well-known/webfinger?resource=%s", proto, host, resource); | ||
| 74 | 76 | ||
| 75 | if (snac == NULL) | 77 | if (snac == NULL) |
| 76 | xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0); | 78 | 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, | |||
| 140 | snac snac; | 142 | snac snac; |
| 141 | int found = 0; | 143 | int found = 0; |
| 142 | 144 | ||
| 143 | if (xs_startswith(resource, "https")) { | 145 | if (xs_startswith(resource, "https:/") || xs_startswith(resource, "http:/")) { |
| 144 | /* actor search: find a user with this actor */ | 146 | /* actor search: find a user with this actor */ |
| 145 | xs *l = xs_split(resource, "/"); | 147 | xs *l = xs_split(resource, "/"); |
| 146 | char *uid = xs_list_get(l, -1); | 148 | char *uid = xs_list_get(l, -1); |