summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c2
-rw-r--r--snac.h2
-rw-r--r--webfinger.c17
3 files changed, 11 insertions, 10 deletions
diff --git a/main.c b/main.c
index d7c1640..101c549 100644
--- a/main.c
+++ b/main.c
@@ -57,7 +57,7 @@ int main(int argc, char *argv[])
57 xs *uid = NULL; 57 xs *uid = NULL;
58 int status; 58 int status;
59 59
60 webfinger_request(user, &status, &actor, &uid); 60 status = webfinger_request(user, &actor, &uid);
61 61
62 printf("status: %d\n", status); 62 printf("status: %d\n", status);
63 if (actor != NULL) 63 if (actor != NULL)
diff --git a/snac.h b/snac.h
index ffd88dc..b181e61 100644
--- a/snac.h
+++ b/snac.h
@@ -76,7 +76,7 @@ d_char *http_signed_request(snac *snac, char *method, char *url,
76 76
77void httpd(void); 77void httpd(void);
78 78
79void webfinger_request(char *qs, int *status, char **actor, char **user); 79int webfinger_request(char *qs, char **actor, char **user);
80void webfinger_get_handler(d_char *req, char *q_path, int *status, 80void webfinger_get_handler(d_char *req, char *q_path, int *status,
81 char **body, int *b_size, char **ctype); 81 char **body, int *b_size, char **ctype);
82 82
diff --git a/webfinger.c b/webfinger.c
index 519fb67..3fc1eab 100644
--- a/webfinger.c
+++ b/webfinger.c
@@ -8,9 +8,10 @@
8 8
9#include "snac.h" 9#include "snac.h"
10 10
11void webfinger_request(char *qs, int *status, char **actor, char **user) 11int webfinger_request(char *qs, char **actor, char **user)
12/* queries the webfinger for qs and fills the required fields */ 12/* queries the webfinger for qs and fills the required fields */
13{ 13{
14 int status;
14 xs *payload = NULL; 15 xs *payload = NULL;
15 int p_size = 0; 16 int p_size = 0;
16 xs *headers = xs_dict_new(); 17 xs *headers = xs_dict_new();
@@ -42,10 +43,8 @@ void webfinger_request(char *qs, int *status, char **actor, char **user)
42 } 43 }
43 } 44 }
44 45
45 if (host == NULL || resource == NULL) { 46 if (host == NULL || resource == NULL)
46 *status = 400; 47 return 400;
47 return;
48 }
49 48
50 headers = xs_dict_append(headers, "accept", "application/json"); 49 headers = xs_dict_append(headers, "accept", "application/json");
51 50
@@ -60,15 +59,15 @@ void webfinger_request(char *qs, int *status, char **actor, char **user)
60 req = xs_dict_append(req, "q_vars", q_vars); 59 req = xs_dict_append(req, "q_vars", q_vars);
61 60
62 webfinger_get_handler(req, "/.well-known/webfinger", 61 webfinger_get_handler(req, "/.well-known/webfinger",
63 status, &payload, &p_size, &ctype); 62 &status, &payload, &p_size, &ctype);
64 } 63 }
65 else { 64 else {
66 xs *url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource=%s", host, resource); 65 xs *url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource=%s", host, resource);
67 66
68 xs_http_request("GET", url, headers, NULL, 0, status, &payload, &p_size); 67 xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size);
69 } 68 }
70 69
71 if (valid_status(*status)) { 70 if (valid_status(status)) {
72 xs *obj = xs_json_loads(payload); 71 xs *obj = xs_json_loads(payload);
73 72
74 if (user != NULL) { 73 if (user != NULL) {
@@ -94,6 +93,8 @@ void webfinger_request(char *qs, int *status, char **actor, char **user)
94 } 93 }
95 } 94 }
96 } 95 }
96
97 return status;
97} 98}
98 99
99 100