diff options
| author | 2022-09-22 10:15:24 +0200 | |
|---|---|---|
| committer | 2022-09-22 10:15:24 +0200 | |
| commit | 00a89295817dd9dc1b29f1718e1efeaa57ea5900 (patch) | |
| tree | f5bb9aaa7a244f71dfd69213b9f2dde11057cb86 /webfinger.c | |
| parent | Added a webfinger handler. (diff) | |
| download | snac2-00a89295817dd9dc1b29f1718e1efeaa57ea5900.tar.gz snac2-00a89295817dd9dc1b29f1718e1efeaa57ea5900.tar.xz snac2-00a89295817dd9dc1b29f1718e1efeaa57ea5900.zip | |
New function webfinger_request() (incomplete).
Diffstat (limited to 'webfinger.c')
| -rw-r--r-- | webfinger.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/webfinger.c b/webfinger.c index be89ea9..bcc5982 100644 --- a/webfinger.c +++ b/webfinger.c | |||
| @@ -4,11 +4,55 @@ | |||
| 4 | #include "xs.h" | 4 | #include "xs.h" |
| 5 | #include "xs_encdec.h" | 5 | #include "xs_encdec.h" |
| 6 | #include "xs_json.h" | 6 | #include "xs_json.h" |
| 7 | #include "xs_curl.h" | ||
| 7 | 8 | ||
| 8 | #include "snac.h" | 9 | #include "snac.h" |
| 9 | 10 | ||
| 11 | void webfinger_request(char *qs, int *status, char **actor, char **user) | ||
| 12 | /* queries the webfinger for qs and fills the required fields */ | ||
| 13 | { | ||
| 14 | xs *payload = NULL; | ||
| 15 | int p_size = 0; | ||
| 16 | xs *url = NULL; | ||
| 17 | xs *headers = xs_dict_new(); | ||
| 18 | |||
| 19 | if (xs_startswith(qs, "https:/" "/")) { | ||
| 20 | /* actor query: pick the host */ | ||
| 21 | xs *s = xs_replace(qs, "https:/" "/", ""); | ||
| 22 | xs *l = xs_split_n(s, "/", 1); | ||
| 23 | |||
| 24 | url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource=%s", | ||
| 25 | xs_list_get(l, 0), qs); | ||
| 26 | } | ||
| 27 | else { | ||
| 28 | /* it's a user */ | ||
| 29 | xs *s = xs_dup(qs); | ||
| 30 | xs *l; | ||
| 31 | |||
| 32 | if (xs_startswith(s, "@")) | ||
| 33 | s = xs_crop(s, 1, 0); | ||
| 34 | |||
| 35 | l = xs_split_n(s, "@", 1); | ||
| 36 | |||
| 37 | if (xs_list_len(l) == 2) { | ||
| 38 | url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource:acct:%s", | ||
| 39 | xs_list_get(l, 1), qs); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | if (url == NULL) { | ||
| 44 | *status = 400; | ||
| 45 | return; | ||
| 46 | } | ||
| 47 | |||
| 48 | headers = xs_dict_append(headers, "accept", "application/json"); | ||
| 49 | |||
| 50 | xs_http_request("GET", url, headers, NULL, 0, status, &payload, &p_size); | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 10 | void webfinger_get_handler(d_char *req, char *q_path, int *status, | 54 | void webfinger_get_handler(d_char *req, char *q_path, int *status, |
| 11 | char **body, int *b_size, char **ctype) | 55 | char **body, int *b_size, char **ctype) |
| 12 | /* serves webfinger queries */ | 56 | /* serves webfinger queries */ |
| 13 | { | 57 | { |
| 14 | if (strcmp(q_path, "/.well-known/webfinger") != 0) | 58 | if (strcmp(q_path, "/.well-known/webfinger") != 0) |