summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-07-10 07:19:51 +0200
committerGravatar default2023-07-10 07:19:51 +0200
commit1a94d7c05bfbc69be14d3e4fd53d8e95972ff007 (patch)
tree75ea66de00b3636525134e2f6eec5742f603a231
parent[examples/snac-global.service] New file. (diff)
downloadsnac2-1a94d7c05bfbc69be14d3e4fd53d8e95972ff007.tar.gz
snac2-1a94d7c05bfbc69be14d3e4fd53d8e95972ff007.tar.xz
snac2-1a94d7c05bfbc69be14d3e4fd53d8e95972ff007.zip
Revert "New server config array "webfinger_domains"."
This reverts commit f2e0b7747813445138d5b65363fd3a74c7a2454a.
Diffstat (limited to '')
-rw-r--r--snac.h2
-rw-r--r--webfinger.c31
2 files changed, 12 insertions, 21 deletions
diff --git a/snac.h b/snac.h
index f19f7e1..af6c912 100644
--- a/snac.h
+++ b/snac.h
@@ -203,7 +203,7 @@ void httpd(void);
203 203
204int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **user); 204int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **user);
205int webfinger_request(const char *qs, char **actor, char **user); 205int webfinger_request(const char *qs, char **actor, char **user);
206int webfinger_get_handler(const xs_dict *req, const char *q_path, 206int webfinger_get_handler(xs_dict *req, char *q_path,
207 char **body, int *b_size, char **ctype); 207 char **body, int *b_size, char **ctype);
208 208
209const char *default_avatar_base64(void); 209const char *default_avatar_base64(void);
diff --git a/webfinger.c b/webfinger.c
index a4e1d15..a167cd0 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
109int webfinger_get_handler(const xs_dict *req, const char *q_path, 109int webfinger_get_handler(d_char *req, 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(const xs_dict *req, const 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 const xs_dict *q_vars = xs_dict_get(req, "q_vars"); 120 char *q_vars = xs_dict_get(req, "q_vars");
121 const char *resource = xs_dict_get(q_vars, "resource"); 121 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,8 +129,7 @@ int webfinger_get_handler(const xs_dict *req, const 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 xs_list *p; 132 char *p, *uid;
133 char *uid;
134 133
135 p = list; 134 p = list;
136 while (xs_list_iter(&p, &uid)) { 135 while (xs_list_iter(&p, &uid)) {
@@ -157,22 +156,11 @@ int webfinger_get_handler(const xs_dict *req, const char *q_path,
157 l = xs_split_n(an, "@", 1); 156 l = xs_split_n(an, "@", 1);
158 157
159 if (xs_list_len(l) == 2) { 158 if (xs_list_len(l) == 2) {
160 const char *uid = xs_list_get(l, 0); 159 char *uid = xs_list_get(l, 0);
161 const char *host = xs_list_get(l, 1); 160 char *host = xs_list_get(l, 1);
162 161
163 if (strcmp(host, xs_dict_get(srv_config, "host")) == 0) 162 if (strcmp(host, xs_dict_get(srv_config, "host")) == 0)
164 found = user_open(&snac, uid); 163 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 }
176 } 164 }
177 } 165 }
178 166
@@ -182,6 +170,7 @@ int webfinger_get_handler(const xs_dict *req, const char *q_path,
182 xs *aaj = xs_dict_new(); 170 xs *aaj = xs_dict_new();
183 xs *links = xs_list_new(); 171 xs *links = xs_list_new();
184 xs *obj = xs_dict_new(); 172 xs *obj = xs_dict_new();
173 d_char *j;
185 174
186 acct = xs_fmt("acct:%s@%s", 175 acct = xs_fmt("acct:%s@%s",
187 xs_dict_get(snac.config, "uid"), xs_dict_get(srv_config, "host")); 176 xs_dict_get(snac.config, "uid"), xs_dict_get(srv_config, "host"));
@@ -195,10 +184,12 @@ int webfinger_get_handler(const xs_dict *req, const char *q_path,
195 obj = xs_dict_append(obj, "subject", acct); 184 obj = xs_dict_append(obj, "subject", acct);
196 obj = xs_dict_append(obj, "links", links); 185 obj = xs_dict_append(obj, "links", links);
197 186
187 j = xs_json_dumps_pp(obj, 4);
188
198 user_free(&snac); 189 user_free(&snac);
199 190
200 status = 200; 191 status = 200;
201 *body = xs_json_dumps_pp(obj, 4); 192 *body = j;
202 *ctype = "application/json"; 193 *ctype = "application/json";
203 } 194 }
204 else 195 else