commit d451af3

Giuseppe Ranieri  ·  2026-03-19 09:41:34 +0000 UTC
parent 72be32d
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
4 files changed,  +33, -11
M data.c
M snac.h
M data.c
+3, -2
 1@@ -273,8 +273,9 @@ int user_open(snac *user, const char *uid)
 2                     fclose(f);
 3 
 4                     if (user->key != NULL) {
 5-                        user->actor = xs_fmt("%s/%s", srv_baseurl, user->uid);
 6-                        user->md5   = xs_md5_hex(user->actor, strlen(user->actor));
 7+                        user->actor     = xs_fmt("%s/%s", srv_baseurl, user->uid);
 8+                        user->actor_alt = xs_fmt("%s/users/%s", srv_baseurl ,user->uid);
 9+                        user->md5       = xs_md5_hex(user->actor, strlen(user->actor));
10 
11                         /* everything is ok right now */
12                         ret = 1;
+10, -0
 1@@ -502,6 +502,13 @@ void httpd_connection(FILE *f)
 2     if (xs_startswith(q_path, p))
 3         q_path = xs_crop_i(q_path, strlen(p), 0);
 4 
 5+    /* add users endpoint redirection mimic Mastodon behaviour */
 6+    const char *users_endpoint = "/users";
 7+    if (xs_startswith(q_path, users_endpoint)) {
 8+        q_path = xs_crop_i(q_path, strlen(users_endpoint), 0);
 9+        status = HTTP_STATUS_FOUND;
10+    }
11+
12     if (strcmp(method, "GET") == 0 || strcmp(method, "HEAD") == 0) {
13         /* cascade through */
14         if (status == 0)
15@@ -607,6 +614,9 @@ void httpd_connection(FILE *f)
16     if (status == HTTP_STATUS_SEE_OTHER)
17         headers = xs_dict_append(headers, "location", body);
18 
19+    if (status == HTTP_STATUS_FOUND)
20+        headers = xs_dict_append(headers, "location", xs_fmt("%s%s", p, q_path));
21+
22     if (status == HTTP_STATUS_UNAUTHORIZED && body) {
23         xs *www_auth = xs_fmt("Basic realm=\"@%s@%s snac login\"",
24                                 body, xs_dict_get(srv_config, "host"));
M snac.h
+1, -0
1@@ -62,6 +62,7 @@ typedef struct {
2     xs_dict *key;       /* keypair */
3     xs_dict *links;     /* validated links */
4     xs_str *actor;      /* actor url */
5+    xs_str *actor_alt;  /* actor alternative url */
6     xs_str *md5;        /* actor url md5 */
7     const xs_dict *lang;/* string translation dict */
8     const char *tz;     /* configured timezone */
+19, -9
 1@@ -182,10 +182,14 @@ int webfinger_get_handler(const xs_dict *req, const char *q_path,
 2             found = user_open(&snac, uid);
 3     }
 4     else
 5-    if (xs_startswith(resource, "acct:")) {
 6-        /* it's an account name */
 7-        xs *an = xs_replace_n(resource, "acct:", "", 1);
 8-        xs *l = NULL;
 9+    {
10+	xs *an = xs_fmt("%s", resource);
11+	xs *l = NULL;
12+
13+        if (xs_startswith(resource, "acct:")) {
14+            /* it's an account name */
15+            an = xs_replace_n(resource, "acct:", "", 1);
16+        }
17 
18         /* strip a possible leading @ */
19         if (xs_startswith(an, "@"))
20@@ -205,17 +209,18 @@ int webfinger_get_handler(const xs_dict *req, const char *q_path,
21     if (found) {
22         /* build the object */
23         xs *acct;
24-        xs *aaj   = xs_dict_new();
25-        xs *prof  = xs_dict_new();
26-        xs *links = xs_list_new();
27-        xs *obj   = xs_dict_new();
28+        xs *aaj     = xs_dict_new();
29+        xs *prof    = xs_dict_new();
30+        xs *links   = xs_list_new();
31+        xs *aliases = xs_list_new();
32+        xs *obj     = xs_dict_new();
33 
34         acct = xs_fmt("acct:%s@%s",
35             xs_dict_get(snac.config, "uid"), xs_dict_get(srv_config, "host"));
36 
37         aaj = xs_dict_append(aaj, "rel",  "self");
38         aaj = xs_dict_append(aaj, "type", "application/activity+json");
39-        aaj = xs_dict_append(aaj, "href", snac.actor);
40+        aaj = xs_dict_append(aaj, "href", snac.actor_alt);
41 
42         links = xs_list_append(links, aaj);
43 
44@@ -242,7 +247,12 @@ int webfinger_get_handler(const xs_dict *req, const char *q_path,
45             links = xs_list_append(links, d);
46         }
47 
48+        aliases = xs_list_append(aliases, snac.actor);
49+        aliases = xs_list_append(aliases, snac.actor_alt);
50+
51+
52         obj = xs_dict_append(obj, "subject", acct);
53+        obj = xs_dict_append(obj, "aliases", aliases);
54         obj = xs_dict_append(obj, "links",   links);
55 
56         xs_str *j = xs_json_dumps(obj, 4);