summaryrefslogtreecommitdiff
path: root/webfinger.c
diff options
context:
space:
mode:
Diffstat (limited to 'webfinger.c')
-rw-r--r--webfinger.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/webfinger.c b/webfinger.c
index a883d7f..c79fd44 100644
--- a/webfinger.c
+++ b/webfinger.c
@@ -16,12 +16,13 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us
16 int p_size = 0; 16 int p_size = 0;
17 xs *headers = xs_dict_new(); 17 xs *headers = xs_dict_new();
18 xs *l = NULL; 18 xs *l = NULL;
19 xs_str *host = NULL; 19 const char *host = NULL;
20 xs *resource = NULL; 20 xs *resource = NULL;
21 21
22 if (xs_startswith(qs, "https:/" "/")) { 22 if (xs_startswith(qs, "https:/") || xs_startswith(qs, "http:/")) {
23 /* actor query: pick the host */ 23 /* actor query: pick the host */
24 xs *s = xs_replace_n(qs, "https:/" "/", "", 1); 24 xs *s1 = xs_replace_n(qs, "http:/" "/", "", 1);
25 xs *s = xs_replace_n(s1, "https:/" "/", "", 1);
25 26
26 l = xs_split_n(s, "/", 1); 27 l = xs_split_n(s, "/", 1);
27 28
@@ -69,7 +70,9 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us
69 &payload, &p_size, &ctype); 70 &payload, &p_size, &ctype);
70 } 71 }
71 else { 72 else {
72 xs *url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource=%s", host, resource); 73 const char *proto = xs_dict_get_def(srv_config, "protocol", "https");
74
75 xs *url = xs_fmt("%s:/" "/%s/.well-known/webfinger?resource=%s", proto, host, resource);
73 76
74 if (snac == NULL) 77 if (snac == NULL)
75 xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0); 78 xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0);
@@ -84,22 +87,24 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us
84 87
85 if (obj) { 88 if (obj) {
86 if (user != NULL) { 89 if (user != NULL) {
87 char *subject = xs_dict_get(obj, "subject"); 90 const char *subject = xs_dict_get(obj, "subject");
88 91
89 if (subject) 92 if (subject)
90 *user = xs_replace_n(subject, "acct:", "", 1); 93 *user = xs_replace_n(subject, "acct:", "", 1);
91 } 94 }
92 95
93 if (actor != NULL) { 96 if (actor != NULL) {
94 char *list = xs_dict_get(obj, "links"); 97 const xs_list *list = xs_dict_get(obj, "links");
95 char *v; 98 int c = 0;
99 const char *v;
96 100
97 while (xs_list_iter(&list, &v)) { 101 while (xs_list_next(list, &v, &c)) {
98 if (xs_type(v) == XSTYPE_DICT) { 102 if (xs_type(v) == XSTYPE_DICT) {
99 char *type = xs_dict_get(v, "type"); 103 const char *type = xs_dict_get(v, "type");
100 104
101 if (type && (strcmp(type, "application/activity+json") == 0 || 105 if (type && (strcmp(type, "application/activity+json") == 0 ||
102 strcmp(type, "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") == 0)) { 106 strcmp(type, "application/ld+json; profile=\"https:/"
107 "/www.w3.org/ns/activitystreams\"") == 0)) {
103 *actor = xs_dup(xs_dict_get(v, "href")); 108 *actor = xs_dup(xs_dict_get(v, "href"));
104 break; 109 break;
105 } 110 }
@@ -130,8 +135,8 @@ int webfinger_get_handler(xs_dict *req, char *q_path,
130 if (strcmp(q_path, "/.well-known/webfinger") != 0) 135 if (strcmp(q_path, "/.well-known/webfinger") != 0)
131 return 0; 136 return 0;
132 137
133 char *q_vars = xs_dict_get(req, "q_vars"); 138 const char *q_vars = xs_dict_get(req, "q_vars");
134 char *resource = xs_dict_get(q_vars, "resource"); 139 const char *resource = xs_dict_get(q_vars, "resource");
135 140
136 if (resource == NULL) 141 if (resource == NULL)
137 return 400; 142 return 400;
@@ -139,10 +144,10 @@ int webfinger_get_handler(xs_dict *req, char *q_path,
139 snac snac; 144 snac snac;
140 int found = 0; 145 int found = 0;
141 146
142 if (xs_startswith(resource, "https:/" "/")) { 147 if (xs_startswith(resource, "https:/") || xs_startswith(resource, "http:/")) {
143 /* actor search: find a user with this actor */ 148 /* actor search: find a user with this actor */
144 xs *l = xs_split(resource, "/"); 149 xs *l = xs_split(resource, "/");
145 char *uid = xs_list_get(l, -1); 150 const char *uid = xs_list_get(l, -1);
146 151
147 if (uid) 152 if (uid)
148 found = user_open(&snac, uid); 153 found = user_open(&snac, uid);
@@ -160,8 +165,8 @@ int webfinger_get_handler(xs_dict *req, char *q_path,
160 l = xs_split_n(an, "@", 1); 165 l = xs_split_n(an, "@", 1);
161 166
162 if (xs_list_len(l) == 2) { 167 if (xs_list_len(l) == 2) {
163 char *uid = xs_list_get(l, 0); 168 const char *uid = xs_list_get(l, 0);
164 char *host = xs_list_get(l, 1); 169 const char *host = xs_list_get(l, 1);
165 170
166 if (strcmp(host, xs_dict_get(srv_config, "host")) == 0) 171 if (strcmp(host, xs_dict_get(srv_config, "host")) == 0)
167 found = user_open(&snac, uid); 172 found = user_open(&snac, uid);
@@ -185,13 +190,19 @@ int webfinger_get_handler(xs_dict *req, char *q_path,
185 190
186 links = xs_list_append(links, aaj); 191 links = xs_list_append(links, aaj);
187 192
193 /* duplicate with the ld+json type */
194 aaj = xs_dict_set(aaj, "type", "application/ld+json; profile=\"https:/"
195 "/www.w3.org/ns/activitystreams\"");
196
197 links = xs_list_append(links, aaj);
198
188 prof = xs_dict_append(prof, "rel", "http://webfinger.net/rel/profile-page"); 199 prof = xs_dict_append(prof, "rel", "http://webfinger.net/rel/profile-page");
189 prof = xs_dict_append(prof, "type", "text/html"); 200 prof = xs_dict_append(prof, "type", "text/html");
190 prof = xs_dict_append(prof, "href", snac.actor); 201 prof = xs_dict_append(prof, "href", snac.actor);
191 202
192 links = xs_list_append(links, prof); 203 links = xs_list_append(links, prof);
193 204
194 char *avatar = xs_dict_get(snac.config, "avatar"); 205 const char *avatar = xs_dict_get(snac.config, "avatar");
195 if (!xs_is_null(avatar) && *avatar) { 206 if (!xs_is_null(avatar) && *avatar) {
196 xs *d = xs_dict_new(); 207 xs *d = xs_dict_new();
197 208
@@ -211,10 +222,12 @@ int webfinger_get_handler(xs_dict *req, char *q_path,
211 222
212 status = 200; 223 status = 200;
213 *body = j; 224 *body = j;
214 *ctype = "application/json"; 225 *ctype = "application/jrd+json";
215 } 226 }
216 else 227 else
217 status = 404; 228 status = 404;
218 229
230 srv_debug(1, xs_fmt("webfinger_get_handler resource=%s %d", resource, status));
231
219 return status; 232 return status;
220} 233}