commit f2e0b77

default  ·  2023-07-08 07:57:40 +0000 UTC
parent 321d9fb
New server config array "webfinger_domains".
2 files changed,  +21, -12
M snac.h
M snac.h
+1, -1
1@@ -202,7 +202,7 @@ void httpd(void);
2 
3 int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **user);
4 int webfinger_request(const char *qs, char **actor, char **user);
5-int webfinger_get_handler(xs_dict *req, char *q_path,
6+int webfinger_get_handler(const xs_dict *req, const char *q_path,
7                           char **body, int *b_size, char **ctype);
8 
9 const char *default_avatar_base64(void);
+20, -11
 1@@ -106,8 +106,8 @@ int webfinger_request(const char *qs, char **actor, char **user)
 2 }
 3 
 4 
 5-int webfinger_get_handler(d_char *req, char *q_path,
 6-                           char **body, int *b_size, char **ctype)
 7+int webfinger_get_handler(const xs_dict *req, const char *q_path,
 8+                          char **body, int *b_size, char **ctype)
 9 /* serves webfinger queries */
10 {
11     int status;
12@@ -117,8 +117,8 @@ int webfinger_get_handler(d_char *req, char *q_path,
13     if (strcmp(q_path, "/.well-known/webfinger") != 0)
14         return 0;
15 
16-    char *q_vars   = xs_dict_get(req, "q_vars");
17-    char *resource = xs_dict_get(q_vars, "resource");
18+    const xs_dict *q_vars = xs_dict_get(req, "q_vars");
19+    const char *resource  = xs_dict_get(q_vars, "resource");
20 
21     if (resource == NULL)
22         return 400;
23@@ -129,7 +129,8 @@ int webfinger_get_handler(d_char *req, char *q_path,
24     if (xs_startswith(resource, "https:/" "/")) {
25         /* actor search: find a user with this actor */
26         xs *list = user_list();
27-        char *p, *uid;
28+        xs_list *p;
29+        char *uid;
30 
31         p = list;
32         while (xs_list_iter(&p, &uid)) {
33@@ -156,11 +157,22 @@ int webfinger_get_handler(d_char *req, char *q_path,
34         l = xs_split_n(an, "@", 1);
35 
36         if (xs_list_len(l) == 2) {
37-            char *uid  = xs_list_get(l, 0);
38-            char *host = xs_list_get(l, 1);
39+            const char *uid  = xs_list_get(l, 0);
40+            const char *host = xs_list_get(l, 1);
41 
42             if (strcmp(host, xs_dict_get(srv_config, "host")) == 0)
43                 found = user_open(&snac, uid);
44+
45+            if (!found) {
46+                /* get the list of possible domain aliases */
47+                xs_list *domains = xs_dict_get(srv_config, "webfinger_domains");
48+                char *v;
49+
50+                while (!found && xs_list_iter(&domains, &v)) {
51+                    if (strcmp(host, v) == 0)
52+                        found = user_open(&snac, uid);
53+                }
54+            }
55         }
56     }
57 
58@@ -170,7 +182,6 @@ int webfinger_get_handler(d_char *req, char *q_path,
59         xs *aaj   = xs_dict_new();
60         xs *links = xs_list_new();
61         xs *obj   = xs_dict_new();
62-        d_char *j;
63 
64         acct = xs_fmt("acct:%s@%s",
65             xs_dict_get(snac.config, "uid"), xs_dict_get(srv_config, "host"));
66@@ -184,12 +195,10 @@ int webfinger_get_handler(d_char *req, char *q_path,
67         obj = xs_dict_append(obj, "subject", acct);
68         obj = xs_dict_append(obj, "links",   links);
69 
70-        j = xs_json_dumps_pp(obj, 4);
71-
72         user_free(&snac);
73 
74         status = 200;
75-        *body  = j;
76+        *body  = xs_json_dumps_pp(obj, 4);
77         *ctype = "application/json";
78     }
79     else