12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #include "xs.h"
- #include "xs_encdec.h"
- #include "xs_json.h"
- #include "snac.h"
- void webfinger_get_handler(d_char *req, char *q_path, int *status,
- char **body, int *b_size, char **ctype)
- {
- if (strcmp(q_path, "/.well-known/webfinger") != 0)
- return;
- char *q_vars = xs_dict_get(req, "q_vars");
- char *resource = xs_dict_get(q_vars, "resource");
- if (resource == NULL) {
- *status = 400;
- return;
- }
- snac snac;
- int found = 0;
- if (xs_startswith(resource, "https:/" "/")) {
-
- xs *list = user_list();
- char *p, *uid;
- p = list;
- while (xs_list_iter(&p, &uid)) {
- if (user_open(&snac, uid)) {
- if (strcmp(snac.actor, resource) == 0) {
- found = 1;
- break;
- }
- user_free(&snac);
- }
- }
- }
- else
- if (xs_startswith(resource, "acct:")) {
-
- xs *an = xs_replace(resource, "acct:", "");
- xs *l = NULL;
-
- if (xs_startswith(an, "@"))
- an = xs_crop(an, 1, 0);
- l = xs_split_n(an, "@", 1);
- if (xs_list_len(l) == 2) {
- char *uid = xs_list_get(l, 0);
- char *host = xs_list_get(l, 1);
- if (strcmp(host, xs_dict_get(srv_config, "host")) == 0)
- found = user_open(&snac, uid);
- }
- }
- if (found) {
-
- xs *acct;
- xs *aaj = xs_dict_new();
- xs *links = xs_list_new();
- xs *obj = xs_dict_new();
- d_char *j;
- acct = xs_fmt("acct:%s@%s",
- xs_dict_get(snac.config, "uid"), xs_dict_get(srv_config, "host"));
- aaj = xs_dict_append(aaj, "rel", "self");
- aaj = xs_dict_append(aaj, "type", "application/activity+json");
- aaj = xs_dict_append(aaj, "href", snac.actor);
- links = xs_list_append(links, aaj);
- obj = xs_dict_append(obj, "subject", acct);
- obj = xs_dict_append(obj, "links", links);
- j = xs_json_dumps_pp(obj, 4);
- user_free(&snac);
- *status = 200;
- *body = j;
- *ctype = "application/json";
- }
- }
|