diff options
| author | Giuseppe Ranieri <giuseppe@ranieri.dev> | 2026-03-19 10:41:34 +0100 |
|---|---|---|
| committer | Giuseppe Ranieri <giuseppe@ranieri.dev> | 2026-03-19 11:50:03 +0100 |
| commit | e21a933a6ecacdc2ca3b3ed1c495714ba36afa3d (patch) | |
| tree | d45701f7beaf3863d3b8482d7db603c46b63ad76 | |
| parent | 72be32d06fc6ea5a8fba944fe9b3305873810f67 (diff) | |
Implemented tootfinder.ch compatibility mimic Mastodon Behaviour
Added aliases list on webfinger response
Return the /users/<actor> 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
| -rw-r--r-- | data.c | 5 | ||||
| -rw-r--r-- | httpd.c | 10 | ||||
| -rw-r--r-- | snac.h | 1 | ||||
| -rw-r--r-- | webfinger.c | 28 |
4 files changed, 33 insertions, 11 deletions
@@ -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; @@ -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")); @@ -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); |