From d451af3faa0ddba0a4d07b5625e6c73ea7f1b947 Mon Sep 17 00:00:00 2001 From: Giuseppe Ranieri Date: Thu, 19 Mar 2026 10:41:34 +0100 Subject: Implemented tootfinder.ch compatibility mimic Mastodon Behaviour Added aliases list on webfinger response Return the /users/ in the webfinger response ( mimic Mastodon ) Implemented /users endpoint redirect to access actor profile Files changed: modified: data.c modified: httpd.c modified: snac.h modified: webfinger.c --- data.c | 5 +++-- httpd.c | 10 ++++++++++ snac.h | 1 + webfinger.c | 28 +++++++++++++++++++--------- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/data.c b/data.c index 1aac759..7610ff4 100644 --- a/data.c +++ b/data.c @@ -273,8 +273,9 @@ int user_open(snac *user, const char *uid) fclose(f); if (user->key != NULL) { - user->actor = xs_fmt("%s/%s", srv_baseurl, user->uid); - user->md5 = xs_md5_hex(user->actor, strlen(user->actor)); + user->actor = xs_fmt("%s/%s", srv_baseurl, user->uid); + user->actor_alt = xs_fmt("%s/users/%s", srv_baseurl ,user->uid); + user->md5 = xs_md5_hex(user->actor, strlen(user->actor)); /* everything is ok right now */ ret = 1; diff --git a/httpd.c b/httpd.c index 219af19..f4f772c 100644 --- a/httpd.c +++ b/httpd.c @@ -502,6 +502,13 @@ void httpd_connection(FILE *f) if (xs_startswith(q_path, p)) q_path = xs_crop_i(q_path, strlen(p), 0); + /* add users endpoint redirection mimic Mastodon behaviour */ + const char *users_endpoint = "/users"; + if (xs_startswith(q_path, users_endpoint)) { + q_path = xs_crop_i(q_path, strlen(users_endpoint), 0); + status = HTTP_STATUS_FOUND; + } + if (strcmp(method, "GET") == 0 || strcmp(method, "HEAD") == 0) { /* cascade through */ if (status == 0) @@ -607,6 +614,9 @@ void httpd_connection(FILE *f) if (status == HTTP_STATUS_SEE_OTHER) headers = xs_dict_append(headers, "location", body); + if (status == HTTP_STATUS_FOUND) + headers = xs_dict_append(headers, "location", xs_fmt("%s%s", p, q_path)); + if (status == HTTP_STATUS_UNAUTHORIZED && body) { xs *www_auth = xs_fmt("Basic realm=\"@%s@%s snac login\"", body, xs_dict_get(srv_config, "host")); diff --git a/snac.h b/snac.h index 390b852..579fe9c 100644 --- a/snac.h +++ b/snac.h @@ -62,6 +62,7 @@ typedef struct { xs_dict *key; /* keypair */ xs_dict *links; /* validated links */ xs_str *actor; /* actor url */ + xs_str *actor_alt; /* actor alternative url */ xs_str *md5; /* actor url md5 */ const xs_dict *lang;/* string translation dict */ const char *tz; /* configured timezone */ diff --git a/webfinger.c b/webfinger.c index 264cb85..921a848 100644 --- a/webfinger.c +++ b/webfinger.c @@ -182,10 +182,14 @@ int webfinger_get_handler(const xs_dict *req, const char *q_path, found = user_open(&snac, uid); } else - if (xs_startswith(resource, "acct:")) { - /* it's an account name */ - xs *an = xs_replace_n(resource, "acct:", "", 1); - xs *l = NULL; + { + xs *an = xs_fmt("%s", resource); + xs *l = NULL; + + if (xs_startswith(resource, "acct:")) { + /* it's an account name */ + an = xs_replace_n(resource, "acct:", "", 1); + } /* strip a possible leading @ */ if (xs_startswith(an, "@")) @@ -205,17 +209,18 @@ int webfinger_get_handler(const xs_dict *req, const char *q_path, if (found) { /* build the object */ xs *acct; - xs *aaj = xs_dict_new(); - xs *prof = xs_dict_new(); - xs *links = xs_list_new(); - xs *obj = xs_dict_new(); + xs *aaj = xs_dict_new(); + xs *prof = xs_dict_new(); + xs *links = xs_list_new(); + xs *aliases = xs_list_new(); + xs *obj = xs_dict_new(); acct = xs_fmt("acct:%s@%s", xs_dict_get(snac.config, "uid"), xs_dict_get(srv_config, "host")); aaj = xs_dict_append(aaj, "rel", "self"); aaj = xs_dict_append(aaj, "type", "application/activity+json"); - aaj = xs_dict_append(aaj, "href", snac.actor); + aaj = xs_dict_append(aaj, "href", snac.actor_alt); links = xs_list_append(links, aaj); @@ -242,7 +247,12 @@ int webfinger_get_handler(const xs_dict *req, const char *q_path, links = xs_list_append(links, d); } + aliases = xs_list_append(aliases, snac.actor); + aliases = xs_list_append(aliases, snac.actor_alt); + + obj = xs_dict_append(obj, "subject", acct); + obj = xs_dict_append(obj, "aliases", aliases); obj = xs_dict_append(obj, "links", links); xs_str *j = xs_json_dumps(obj, 4); -- cgit