Bladeren bron

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
Giuseppe Ranieri 4 maanden geleden
bovenliggende
commit
e21a933a6e
4 gewijzigde bestanden met toevoegingen van 33 en 11 verwijderingen
  1. 3 2
      data.c
  2. 10 0
      httpd.c
  3. 1 0
      snac.h
  4. 19 9
      webfinger.c

+ 3 - 2
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;

+ 10 - 0
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"));

+ 1 - 0
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 */

+ 19 - 9
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);