mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 05:15:04 +00:00
webfinger_request() returns the status.
This commit is contained in:
parent
bdc166111d
commit
40193b1320
3 changed files with 11 additions and 10 deletions
2
main.c
2
main.c
|
@ -57,7 +57,7 @@ int main(int argc, char *argv[])
|
||||||
xs *uid = NULL;
|
xs *uid = NULL;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
webfinger_request(user, &status, &actor, &uid);
|
status = webfinger_request(user, &actor, &uid);
|
||||||
|
|
||||||
printf("status: %d\n", status);
|
printf("status: %d\n", status);
|
||||||
if (actor != NULL)
|
if (actor != NULL)
|
||||||
|
|
2
snac.h
2
snac.h
|
@ -76,7 +76,7 @@ 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);
|
int webfinger_request(char *qs, 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);
|
||||||
|
|
||||||
|
|
17
webfinger.c
17
webfinger.c
|
@ -8,9 +8,10 @@
|
||||||
|
|
||||||
#include "snac.h"
|
#include "snac.h"
|
||||||
|
|
||||||
void webfinger_request(char *qs, int *status, char **actor, char **user)
|
int webfinger_request(char *qs, char **actor, char **user)
|
||||||
/* queries the webfinger for qs and fills the required fields */
|
/* queries the webfinger for qs and fills the required fields */
|
||||||
{
|
{
|
||||||
|
int status;
|
||||||
xs *payload = NULL;
|
xs *payload = NULL;
|
||||||
int p_size = 0;
|
int p_size = 0;
|
||||||
xs *headers = xs_dict_new();
|
xs *headers = xs_dict_new();
|
||||||
|
@ -42,10 +43,8 @@ void webfinger_request(char *qs, int *status, char **actor, char **user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (host == NULL || resource == NULL) {
|
if (host == NULL || resource == NULL)
|
||||||
*status = 400;
|
return 400;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
headers = xs_dict_append(headers, "accept", "application/json");
|
headers = xs_dict_append(headers, "accept", "application/json");
|
||||||
|
|
||||||
|
@ -60,15 +59,15 @@ void webfinger_request(char *qs, int *status, char **actor, char **user)
|
||||||
req = xs_dict_append(req, "q_vars", q_vars);
|
req = xs_dict_append(req, "q_vars", q_vars);
|
||||||
|
|
||||||
webfinger_get_handler(req, "/.well-known/webfinger",
|
webfinger_get_handler(req, "/.well-known/webfinger",
|
||||||
status, &payload, &p_size, &ctype);
|
&status, &payload, &p_size, &ctype);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
xs *url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource=%s", host, resource);
|
xs *url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource=%s", host, resource);
|
||||||
|
|
||||||
xs_http_request("GET", url, headers, NULL, 0, status, &payload, &p_size);
|
xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid_status(*status)) {
|
if (valid_status(status)) {
|
||||||
xs *obj = xs_json_loads(payload);
|
xs *obj = xs_json_loads(payload);
|
||||||
|
|
||||||
if (user != NULL) {
|
if (user != NULL) {
|
||||||
|
@ -94,6 +93,8 @@ void webfinger_request(char *qs, int *status, char **actor, char **user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue