mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
New function webfinger_request() (incomplete).
This commit is contained in:
parent
6e4294f8e8
commit
00a8929581
3 changed files with 47 additions and 2 deletions
2
Makefile
2
Makefile
|
@ -21,4 +21,4 @@ httpd.o: httpd.c xs.h xs_io.h xs_encdec.h xs_json.h xs_socket.h \
|
||||||
main.o: main.c xs.h xs_encdec.h xs_json.h snac.h
|
main.o: main.c xs.h xs_encdec.h xs_json.h snac.h
|
||||||
snac.o: snac.c xs.h xs_io.h xs_encdec.h xs_json.h xs_curl.h \
|
snac.o: snac.c xs.h xs_io.h xs_encdec.h xs_json.h xs_curl.h \
|
||||||
xs_openssl.h xs_socket.h xs_httpd.h snac.h
|
xs_openssl.h xs_socket.h xs_httpd.h snac.h
|
||||||
webfinger.o: webfinger.c xs.h xs_encdec.h xs_json.h snac.h
|
webfinger.o: webfinger.c xs.h xs_encdec.h xs_json.h xs_curl.h snac.h
|
||||||
|
|
1
snac.h
1
snac.h
|
@ -70,5 +70,6 @@ d_char *http_signed_request(snac *snac, char *method, char *url,
|
||||||
|
|
||||||
void httpd(void);
|
void httpd(void);
|
||||||
|
|
||||||
|
void webfinger_request(char *qs, int *status, char **actor, char **user);
|
||||||
void webfinger_get_handler(d_char *req, char *q_path, int *status,
|
void webfinger_get_handler(d_char *req, char *q_path, int *status,
|
||||||
char **body, int *b_size, char **ctype);
|
char **body, int *b_size, char **ctype);
|
||||||
|
|
46
webfinger.c
46
webfinger.c
|
@ -4,11 +4,55 @@
|
||||||
#include "xs.h"
|
#include "xs.h"
|
||||||
#include "xs_encdec.h"
|
#include "xs_encdec.h"
|
||||||
#include "xs_json.h"
|
#include "xs_json.h"
|
||||||
|
#include "xs_curl.h"
|
||||||
|
|
||||||
#include "snac.h"
|
#include "snac.h"
|
||||||
|
|
||||||
|
void webfinger_request(char *qs, int *status, char **actor, char **user)
|
||||||
|
/* queries the webfinger for qs and fills the required fields */
|
||||||
|
{
|
||||||
|
xs *payload = NULL;
|
||||||
|
int p_size = 0;
|
||||||
|
xs *url = NULL;
|
||||||
|
xs *headers = xs_dict_new();
|
||||||
|
|
||||||
|
if (xs_startswith(qs, "https:/" "/")) {
|
||||||
|
/* actor query: pick the host */
|
||||||
|
xs *s = xs_replace(qs, "https:/" "/", "");
|
||||||
|
xs *l = xs_split_n(s, "/", 1);
|
||||||
|
|
||||||
|
url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource=%s",
|
||||||
|
xs_list_get(l, 0), qs);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* it's a user */
|
||||||
|
xs *s = xs_dup(qs);
|
||||||
|
xs *l;
|
||||||
|
|
||||||
|
if (xs_startswith(s, "@"))
|
||||||
|
s = xs_crop(s, 1, 0);
|
||||||
|
|
||||||
|
l = xs_split_n(s, "@", 1);
|
||||||
|
|
||||||
|
if (xs_list_len(l) == 2) {
|
||||||
|
url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource:acct:%s",
|
||||||
|
xs_list_get(l, 1), qs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url == NULL) {
|
||||||
|
*status = 400;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
headers = xs_dict_append(headers, "accept", "application/json");
|
||||||
|
|
||||||
|
xs_http_request("GET", url, headers, NULL, 0, status, &payload, &p_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void webfinger_get_handler(d_char *req, char *q_path, int *status,
|
void webfinger_get_handler(d_char *req, char *q_path, int *status,
|
||||||
char **body, int *b_size, char **ctype)
|
char **body, int *b_size, char **ctype)
|
||||||
/* serves webfinger queries */
|
/* serves webfinger queries */
|
||||||
{
|
{
|
||||||
if (strcmp(q_path, "/.well-known/webfinger") != 0)
|
if (strcmp(q_path, "/.well-known/webfinger") != 0)
|
||||||
|
|
Loading…
Reference in a new issue