diff options
| author | 2023-06-13 20:36:43 +0200 | |
|---|---|---|
| committer | 2023-06-13 20:36:43 +0200 | |
| commit | e0c6fb786c3b72b8a789041db2909fa7d1d880de (patch) | |
| tree | 40b4b9af3f6de66ffe5cf839a5e603963344a4bd | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | snac2-e0c6fb786c3b72b8a789041db2909fa7d1d880de.tar.gz snac2-e0c6fb786c3b72b8a789041db2909fa7d1d880de.tar.xz snac2-e0c6fb786c3b72b8a789041db2909fa7d1d880de.zip | |
New function webfinger_request_signed().
| -rw-r--r-- | main.c | 49 | ||||
| -rw-r--r-- | snac.h | 1 | ||||
| -rw-r--r-- | webfinger.c | 14 |
3 files changed, 47 insertions, 17 deletions
| @@ -16,20 +16,21 @@ int usage(void) | |||
| 16 | printf("\n"); | 16 | printf("\n"); |
| 17 | printf("Commands:\n"); | 17 | printf("Commands:\n"); |
| 18 | printf("\n"); | 18 | printf("\n"); |
| 19 | printf("init [{basedir}] Initializes the data storage\n"); | 19 | printf("init [{basedir}] Initializes the data storage\n"); |
| 20 | printf("upgrade {basedir} Upgrade to a new version\n"); | 20 | printf("upgrade {basedir} Upgrade to a new version\n"); |
| 21 | printf("adduser {basedir} [{uid}] Adds a new user\n"); | 21 | printf("adduser {basedir} [{uid}] Adds a new user\n"); |
| 22 | printf("httpd {basedir} Starts the HTTPD daemon\n"); | 22 | printf("httpd {basedir} Starts the HTTPD daemon\n"); |
| 23 | printf("purge {basedir} Purges old data\n"); | 23 | printf("purge {basedir} Purges old data\n"); |
| 24 | printf("webfinger {basedir} {user} Queries about a @user@host or actor\n"); | 24 | printf("webfinger {basedir} {actor} Queries about an actor (@user@host or actor url)\n"); |
| 25 | printf("queue {basedir} {uid} Processes a user queue\n"); | 25 | printf("queue {basedir} {uid} Processes a user queue\n"); |
| 26 | printf("follow {basedir} {uid} {actor} Follows an actor\n"); | 26 | printf("follow {basedir} {uid} {actor} Follows an actor\n"); |
| 27 | printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n"); | 27 | printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n"); |
| 28 | printf("request {basedir} {uid} {url} Requests an object\n"); | 28 | printf("request {basedir} {uid} {url} Requests an object\n"); |
| 29 | printf("actor {basedir} {uid} {url} Requests an actor\n"); | 29 | printf("actor {basedir} {uid} {url} Requests an actor\n"); |
| 30 | printf("note {basedir} {uid} {'text'} Sends a note to followers\n"); | 30 | printf("note {basedir} {uid} {'text'} Sends a note to followers\n"); |
| 31 | printf("resetpwd {basedir} {uid} Resets the password of a user\n"); | 31 | printf("resetpwd {basedir} {uid} Resets the password of a user\n"); |
| 32 | printf("ping {basedir} {uid} {actor} Pings an actor\n"); | 32 | printf("ping {basedir} {uid} {actor} Pings an actor\n"); |
| 33 | printf("webfinger_s {basedir} {uid} {actor} Queries about an actor (@user@host or actor url)\n"); | ||
| 33 | /* printf("question {basedir} {uid} 'opts' Generates a poll (;-separated opts)\n");*/ | 34 | /* printf("question {basedir} {uid} 'opts' Generates a poll (;-separated opts)\n");*/ |
| 34 | 35 | ||
| 35 | return 1; | 36 | return 1; |
| @@ -179,6 +180,22 @@ int main(int argc, char *argv[]) | |||
| 179 | if ((url = GET_ARGV()) == NULL) | 180 | if ((url = GET_ARGV()) == NULL) |
| 180 | return usage(); | 181 | return usage(); |
| 181 | 182 | ||
| 183 | if (strcmp(cmd, "webfinger_s") == 0) { /** **/ | ||
| 184 | xs *actor = NULL; | ||
| 185 | xs *uid = NULL; | ||
| 186 | int status; | ||
| 187 | |||
| 188 | status = webfinger_request_signed(&snac, url, &actor, &uid); | ||
| 189 | |||
| 190 | printf("status: %d\n", status); | ||
| 191 | if (actor != NULL) | ||
| 192 | printf("actor: %s\n", actor); | ||
| 193 | if (uid != NULL) | ||
| 194 | printf("uid: %s\n", uid); | ||
| 195 | |||
| 196 | return 0; | ||
| 197 | } | ||
| 198 | |||
| 182 | if (strcmp(cmd, "announce") == 0) { /** **/ | 199 | if (strcmp(cmd, "announce") == 0) { /** **/ |
| 183 | xs *msg = msg_admiration(&snac, url, "Announce"); | 200 | xs *msg = msg_admiration(&snac, url, "Announce"); |
| 184 | 201 | ||
| @@ -352,5 +369,7 @@ int main(int argc, char *argv[]) | |||
| 352 | return 0; | 369 | return 0; |
| 353 | } | 370 | } |
| 354 | 371 | ||
| 355 | return 0; | 372 | fprintf(stderr, "ERROR: bad command '%s'\n", cmd); |
| 373 | |||
| 374 | return 1; | ||
| 356 | } | 375 | } |
| @@ -191,6 +191,7 @@ int check_signature(snac *snac, xs_dict *req, xs_str **err); | |||
| 191 | 191 | ||
| 192 | void httpd(void); | 192 | void httpd(void); |
| 193 | 193 | ||
| 194 | int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **user); | ||
| 194 | int webfinger_request(const char *qs, char **actor, char **user); | 195 | int webfinger_request(const char *qs, char **actor, char **user); |
| 195 | int webfinger_get_handler(xs_dict *req, char *q_path, | 196 | int webfinger_get_handler(xs_dict *req, char *q_path, |
| 196 | char **body, int *b_size, char **ctype); | 197 | char **body, int *b_size, char **ctype); |
diff --git a/webfinger.c b/webfinger.c index ca4ed71..a167cd0 100644 --- a/webfinger.c +++ b/webfinger.c | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | #include "snac.h" | 8 | #include "snac.h" |
| 9 | 9 | ||
| 10 | int webfinger_request(const char *qs, char **actor, char **user) | 10 | int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **user) |
| 11 | /* queries the webfinger for qs and fills the required fields */ | 11 | /* queries the webfinger for qs and fills the required fields */ |
| 12 | { | 12 | { |
| 13 | int status; | 13 | int status; |
| @@ -61,7 +61,10 @@ int webfinger_request(const char *qs, char **actor, char **user) | |||
| 61 | else { | 61 | else { |
| 62 | xs *url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource=%s", host, resource); | 62 | xs *url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource=%s", host, resource); |
| 63 | 63 | ||
| 64 | xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0); | 64 | if (snac == NULL) |
| 65 | xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0); | ||
| 66 | else | ||
| 67 | http_signed_request(snac, "GET", url, headers, NULL, 0, &status, &payload, &p_size, 0); | ||
| 65 | } | 68 | } |
| 66 | 69 | ||
| 67 | if (valid_status(status)) { | 70 | if (valid_status(status)) { |
| @@ -96,6 +99,13 @@ int webfinger_request(const char *qs, char **actor, char **user) | |||
| 96 | } | 99 | } |
| 97 | 100 | ||
| 98 | 101 | ||
| 102 | int webfinger_request(const char *qs, char **actor, char **user) | ||
| 103 | /* queries the webfinger for qs and fills the required fields */ | ||
| 104 | { | ||
| 105 | return webfinger_request_signed(NULL, qs, actor, user); | ||
| 106 | } | ||
| 107 | |||
| 108 | |||
| 99 | int webfinger_get_handler(d_char *req, char *q_path, | 109 | int webfinger_get_handler(d_char *req, char *q_path, |
| 100 | char **body, int *b_size, char **ctype) | 110 | char **body, int *b_size, char **ctype) |
| 101 | /* serves webfinger queries */ | 111 | /* serves webfinger queries */ |