diff options
| author | 2023-07-08 09:57:40 +0200 | |
|---|---|---|
| committer | 2023-07-08 09:57:40 +0200 | |
| commit | f2e0b7747813445138d5b65363fd3a74c7a2454a (patch) | |
| tree | 4912445a5d4faf854faa9a4f6d3ea65780f91d2d /webfinger.c | |
| parent | Version 2.36 RELEASED. (diff) | |
| download | penes-snac2-f2e0b7747813445138d5b65363fd3a74c7a2454a.tar.gz penes-snac2-f2e0b7747813445138d5b65363fd3a74c7a2454a.tar.xz penes-snac2-f2e0b7747813445138d5b65363fd3a74c7a2454a.zip | |
New server config array "webfinger_domains".
Diffstat (limited to '')
| -rw-r--r-- | webfinger.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/webfinger.c b/webfinger.c index a167cd0..a4e1d15 100644 --- a/webfinger.c +++ b/webfinger.c | |||
| @@ -106,8 +106,8 @@ int webfinger_request(const char *qs, char **actor, char **user) | |||
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | 108 | ||
| 109 | int webfinger_get_handler(d_char *req, char *q_path, | 109 | int webfinger_get_handler(const xs_dict *req, const char *q_path, |
| 110 | char **body, int *b_size, char **ctype) | 110 | char **body, int *b_size, char **ctype) |
| 111 | /* serves webfinger queries */ | 111 | /* serves webfinger queries */ |
| 112 | { | 112 | { |
| 113 | int status; | 113 | int status; |
| @@ -117,8 +117,8 @@ int webfinger_get_handler(d_char *req, char *q_path, | |||
| 117 | if (strcmp(q_path, "/.well-known/webfinger") != 0) | 117 | if (strcmp(q_path, "/.well-known/webfinger") != 0) |
| 118 | return 0; | 118 | return 0; |
| 119 | 119 | ||
| 120 | char *q_vars = xs_dict_get(req, "q_vars"); | 120 | const xs_dict *q_vars = xs_dict_get(req, "q_vars"); |
| 121 | char *resource = xs_dict_get(q_vars, "resource"); | 121 | const char *resource = xs_dict_get(q_vars, "resource"); |
| 122 | 122 | ||
| 123 | if (resource == NULL) | 123 | if (resource == NULL) |
| 124 | return 400; | 124 | return 400; |
| @@ -129,7 +129,8 @@ int webfinger_get_handler(d_char *req, char *q_path, | |||
| 129 | if (xs_startswith(resource, "https:/" "/")) { | 129 | if (xs_startswith(resource, "https:/" "/")) { |
| 130 | /* actor search: find a user with this actor */ | 130 | /* actor search: find a user with this actor */ |
| 131 | xs *list = user_list(); | 131 | xs *list = user_list(); |
| 132 | char *p, *uid; | 132 | xs_list *p; |
| 133 | char *uid; | ||
| 133 | 134 | ||
| 134 | p = list; | 135 | p = list; |
| 135 | while (xs_list_iter(&p, &uid)) { | 136 | while (xs_list_iter(&p, &uid)) { |
| @@ -156,11 +157,22 @@ int webfinger_get_handler(d_char *req, char *q_path, | |||
| 156 | l = xs_split_n(an, "@", 1); | 157 | l = xs_split_n(an, "@", 1); |
| 157 | 158 | ||
| 158 | if (xs_list_len(l) == 2) { | 159 | if (xs_list_len(l) == 2) { |
| 159 | char *uid = xs_list_get(l, 0); | 160 | const char *uid = xs_list_get(l, 0); |
| 160 | char *host = xs_list_get(l, 1); | 161 | const char *host = xs_list_get(l, 1); |
| 161 | 162 | ||
| 162 | if (strcmp(host, xs_dict_get(srv_config, "host")) == 0) | 163 | if (strcmp(host, xs_dict_get(srv_config, "host")) == 0) |
| 163 | found = user_open(&snac, uid); | 164 | found = user_open(&snac, uid); |
| 165 | |||
| 166 | if (!found) { | ||
| 167 | /* get the list of possible domain aliases */ | ||
| 168 | xs_list *domains = xs_dict_get(srv_config, "webfinger_domains"); | ||
| 169 | char *v; | ||
| 170 | |||
| 171 | while (!found && xs_list_iter(&domains, &v)) { | ||
| 172 | if (strcmp(host, v) == 0) | ||
| 173 | found = user_open(&snac, uid); | ||
| 174 | } | ||
| 175 | } | ||
| 164 | } | 176 | } |
| 165 | } | 177 | } |
| 166 | 178 | ||
| @@ -170,7 +182,6 @@ int webfinger_get_handler(d_char *req, char *q_path, | |||
| 170 | xs *aaj = xs_dict_new(); | 182 | xs *aaj = xs_dict_new(); |
| 171 | xs *links = xs_list_new(); | 183 | xs *links = xs_list_new(); |
| 172 | xs *obj = xs_dict_new(); | 184 | xs *obj = xs_dict_new(); |
| 173 | d_char *j; | ||
| 174 | 185 | ||
| 175 | acct = xs_fmt("acct:%s@%s", | 186 | acct = xs_fmt("acct:%s@%s", |
| 176 | xs_dict_get(snac.config, "uid"), xs_dict_get(srv_config, "host")); | 187 | xs_dict_get(snac.config, "uid"), xs_dict_get(srv_config, "host")); |
| @@ -184,12 +195,10 @@ int webfinger_get_handler(d_char *req, char *q_path, | |||
| 184 | obj = xs_dict_append(obj, "subject", acct); | 195 | obj = xs_dict_append(obj, "subject", acct); |
| 185 | obj = xs_dict_append(obj, "links", links); | 196 | obj = xs_dict_append(obj, "links", links); |
| 186 | 197 | ||
| 187 | j = xs_json_dumps_pp(obj, 4); | ||
| 188 | |||
| 189 | user_free(&snac); | 198 | user_free(&snac); |
| 190 | 199 | ||
| 191 | status = 200; | 200 | status = 200; |
| 192 | *body = j; | 201 | *body = xs_json_dumps_pp(obj, 4); |
| 193 | *ctype = "application/json"; | 202 | *ctype = "application/json"; |
| 194 | } | 203 | } |
| 195 | else | 204 | else |