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) --- webfinger.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'webfinger.c') diff --git a/webfinger.c b/webfinger.c index a883d7f..331191b 100644 --- a/webfinger.c +++ b/webfinger.c @@ -19,9 +19,10 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us xs_str *host = NULL; xs *resource = NULL; - if (xs_startswith(qs, "https:/" "/")) { + if (xs_startswith(qs, "http")) { /* actor query: pick the host */ - xs *s = xs_replace_n(qs, "https:/" "/", "", 1); + xs *s1 = xs_replace_n(qs, "http:/" "/", "", 1); + xs *s = xs_replace_n(s1, "https:/" "/", "", 1); l = xs_split_n(s, "/", 1); @@ -69,7 +70,7 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us &payload, &p_size, &ctype); } else { - xs *url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource=%s", host, resource); + xs *url = xs_fmt("http:/" "/%s/.well-known/webfinger?resource=%s", host, resource); if (snac == NULL) xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0); @@ -139,7 +140,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")) { /* actor search: find a user with this actor */ xs *l = xs_split(resource, "/"); char *uid = xs_list_get(l, -1); -- 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. --- webfinger.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'webfinger.c') 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); -- cgit v1.2.3 From b4293f3c38f5395d31ef3aef78a46e4c9148ea0a Mon Sep 17 00:00:00 2001 From: default Date: Sun, 5 May 2024 09:30:24 +0200 Subject: More logging. --- webfinger.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'webfinger.c') diff --git a/webfinger.c b/webfinger.c index 5b13d2f..50600b0 100644 --- a/webfinger.c +++ b/webfinger.c @@ -219,5 +219,7 @@ int webfinger_get_handler(xs_dict *req, char *q_path, else status = 404; + srv_debug(1, xs_fmt("webfinger_get_handler: resource=%s", resource)); + return status; } -- cgit v1.2.3 From aa95a45a7f0e5d98f673b782821163081a491f43 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 5 May 2024 09:34:14 +0200 Subject: More logging. --- webfinger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webfinger.c') diff --git a/webfinger.c b/webfinger.c index 50600b0..7255ae2 100644 --- a/webfinger.c +++ b/webfinger.c @@ -219,7 +219,7 @@ int webfinger_get_handler(xs_dict *req, char *q_path, else status = 404; - srv_debug(1, xs_fmt("webfinger_get_handler: resource=%s", resource)); + srv_debug(1, xs_fmt("webfinger_get_handler resource=%s %d", resource, status)); return status; } -- 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. --- webfinger.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'webfinger.c') diff --git a/webfinger.c b/webfinger.c index 7255ae2..a12134d 100644 --- a/webfinger.c +++ b/webfinger.c @@ -16,7 +16,7 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us int p_size = 0; xs *headers = xs_dict_new(); xs *l = NULL; - xs_str *host = NULL; + const char *host = NULL; xs *resource = NULL; if (xs_startswith(qs, "https:/") || xs_startswith(qs, "http:/")) { @@ -87,19 +87,20 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us if (obj) { if (user != NULL) { - char *subject = xs_dict_get(obj, "subject"); + const char *subject = xs_dict_get(obj, "subject"); if (subject) *user = xs_replace_n(subject, "acct:", "", 1); } if (actor != NULL) { - char *list = xs_dict_get(obj, "links"); + const xs_list *list = xs_dict_get(obj, "links"); + int c = 0; char *v; - while (xs_list_iter(&list, &v)) { + while (xs_list_next(list, &v, &c)) { if (xs_type(v) == XSTYPE_DICT) { - char *type = xs_dict_get(v, "type"); + const char *type = xs_dict_get(v, "type"); if (type && (strcmp(type, "application/activity+json") == 0 || strcmp(type, "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") == 0)) { @@ -133,8 +134,8 @@ int webfinger_get_handler(xs_dict *req, char *q_path, if (strcmp(q_path, "/.well-known/webfinger") != 0) return 0; - char *q_vars = xs_dict_get(req, "q_vars"); - char *resource = xs_dict_get(q_vars, "resource"); + const char *q_vars = xs_dict_get(req, "q_vars"); + const char *resource = xs_dict_get(q_vars, "resource"); if (resource == NULL) return 400; @@ -145,7 +146,7 @@ int webfinger_get_handler(xs_dict *req, char *q_path, 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); + const char *uid = xs_list_get(l, -1); if (uid) found = user_open(&snac, uid); @@ -163,8 +164,8 @@ int webfinger_get_handler(xs_dict *req, char *q_path, l = xs_split_n(an, "@", 1); if (xs_list_len(l) == 2) { - 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 (strcmp(host, xs_dict_get(srv_config, "host")) == 0) found = user_open(&snac, uid); @@ -194,7 +195,7 @@ int webfinger_get_handler(xs_dict *req, char *q_path, links = xs_list_append(links, prof); - char *avatar = xs_dict_get(snac.config, "avatar"); + const char *avatar = xs_dict_get(snac.config, "avatar"); if (!xs_is_null(avatar) && *avatar) { xs *d = xs_dict_new(); -- cgit v1.2.3 From 59bdaca3a87189bd6f634716e4d7ccf85081ff89 Mon Sep 17 00:00:00 2001 From: Steve Bate Date: Wed, 22 May 2024 09:43:36 +0200 Subject: Change WebFinger content type to RFC-required type --- webfinger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webfinger.c') diff --git a/webfinger.c b/webfinger.c index 7255ae2..2e5ec29 100644 --- a/webfinger.c +++ b/webfinger.c @@ -214,7 +214,7 @@ int webfinger_get_handler(xs_dict *req, char *q_path, status = 200; *body = j; - *ctype = "application/json"; + *ctype = "application/jrd+json"; } else status = 404; -- cgit v1.2.3 From 63e0ca5abac0f00121f724927c25edaf822097a9 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 22 May 2024 16:14:58 +0200 Subject: Also return an application/ld+json object in webfinger. --- webfinger.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'webfinger.c') diff --git a/webfinger.c b/webfinger.c index cad86e4..b1d85e9 100644 --- a/webfinger.c +++ b/webfinger.c @@ -103,7 +103,8 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us const char *type = xs_dict_get(v, "type"); if (type && (strcmp(type, "application/activity+json") == 0 || - strcmp(type, "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") == 0)) { + strcmp(type, "application/ld+json; profile=\"https:/" + "/www.w3.org/ns/activitystreams\"") == 0)) { *actor = xs_dup(xs_dict_get(v, "href")); break; } @@ -189,6 +190,12 @@ int webfinger_get_handler(xs_dict *req, char *q_path, links = xs_list_append(links, aaj); + /* duplicate with the ld+json type */ + aaj = xs_dict_set(aaj, "type", "application/ld+json; profile=\"https:/" + "/www.w3.org/ns/activitystreams\""); + + links = xs_list_append(links, aaj); + prof = xs_dict_append(prof, "rel", "http://webfinger.net/rel/profile-page"); prof = xs_dict_append(prof, "type", "text/html"); prof = xs_dict_append(prof, "href", snac.actor); -- 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. --- webfinger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webfinger.c') diff --git a/webfinger.c b/webfinger.c index b1d85e9..c79fd44 100644 --- a/webfinger.c +++ b/webfinger.c @@ -96,7 +96,7 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us if (actor != NULL) { const xs_list *list = xs_dict_get(obj, "links"); int c = 0; - char *v; + const char *v; while (xs_list_next(list, &v, &c)) { if (xs_type(v) == XSTYPE_DICT) { -- cgit v1.2.3