New function webfinger_request_signed().

This commit is contained in:
default 2023-06-13 20:36:43 +02:00
parent e26d05746c
commit e0c6fb786c
3 changed files with 47 additions and 17 deletions

23
main.c
View file

@ -21,7 +21,7 @@ int usage(void)
printf("adduser {basedir} [{uid}] Adds a new user\n"); printf("adduser {basedir} [{uid}] Adds a new user\n");
printf("httpd {basedir} Starts the HTTPD daemon\n"); printf("httpd {basedir} Starts the HTTPD daemon\n");
printf("purge {basedir} Purges old data\n"); printf("purge {basedir} Purges old data\n");
printf("webfinger {basedir} {user} Queries about a @user@host or actor\n"); printf("webfinger {basedir} {actor} Queries about an actor (@user@host or actor url)\n");
printf("queue {basedir} {uid} Processes a user queue\n"); printf("queue {basedir} {uid} Processes a user queue\n");
printf("follow {basedir} {uid} {actor} Follows an actor\n"); printf("follow {basedir} {uid} {actor} Follows an actor\n");
printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n"); printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n");
@ -30,6 +30,7 @@ int usage(void)
printf("note {basedir} {uid} {'text'} Sends a note to followers\n"); printf("note {basedir} {uid} {'text'} Sends a note to followers\n");
printf("resetpwd {basedir} {uid} Resets the password of a user\n"); printf("resetpwd {basedir} {uid} Resets the password of a user\n");
printf("ping {basedir} {uid} {actor} Pings an actor\n"); printf("ping {basedir} {uid} {actor} Pings an actor\n");
printf("webfinger_s {basedir} {uid} {actor} Queries about an actor (@user@host or actor url)\n");
/* printf("question {basedir} {uid} 'opts' Generates a poll (;-separated opts)\n");*/ /* printf("question {basedir} {uid} 'opts' Generates a poll (;-separated opts)\n");*/
return 1; return 1;
@ -179,6 +180,22 @@ int main(int argc, char *argv[])
if ((url = GET_ARGV()) == NULL) if ((url = GET_ARGV()) == NULL)
return usage(); return usage();
if (strcmp(cmd, "webfinger_s") == 0) { /** **/
xs *actor = NULL;
xs *uid = NULL;
int status;
status = webfinger_request_signed(&snac, url, &actor, &uid);
printf("status: %d\n", status);
if (actor != NULL)
printf("actor: %s\n", actor);
if (uid != NULL)
printf("uid: %s\n", uid);
return 0;
}
if (strcmp(cmd, "announce") == 0) { /** **/ if (strcmp(cmd, "announce") == 0) { /** **/
xs *msg = msg_admiration(&snac, url, "Announce"); xs *msg = msg_admiration(&snac, url, "Announce");
@ -352,5 +369,7 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
return 0; fprintf(stderr, "ERROR: bad command '%s'\n", cmd);
return 1;
} }

1
snac.h
View file

@ -191,6 +191,7 @@ int check_signature(snac *snac, xs_dict *req, xs_str **err);
void httpd(void); void httpd(void);
int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **user);
int webfinger_request(const char *qs, char **actor, char **user); int webfinger_request(const char *qs, char **actor, char **user);
int webfinger_get_handler(xs_dict *req, char *q_path, int webfinger_get_handler(xs_dict *req, char *q_path,
char **body, int *b_size, char **ctype); char **body, int *b_size, char **ctype);

View file

@ -7,7 +7,7 @@
#include "snac.h" #include "snac.h"
int webfinger_request(const char *qs, char **actor, char **user) int webfinger_request_signed(snac *snac, const 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; int status;
@ -61,7 +61,10 @@ int webfinger_request(const char *qs, char **actor, char **user)
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);
if (snac == NULL)
xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0); xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0);
else
http_signed_request(snac, "GET", url, headers, NULL, 0, &status, &payload, &p_size, 0);
} }
if (valid_status(status)) { if (valid_status(status)) {
@ -96,6 +99,13 @@ int webfinger_request(const char *qs, char **actor, char **user)
} }
int webfinger_request(const char *qs, char **actor, char **user)
/* queries the webfinger for qs and fills the required fields */
{
return webfinger_request_signed(NULL, qs, actor, user);
}
int webfinger_get_handler(d_char *req, char *q_path, int webfinger_get_handler(d_char *req, char *q_path,
char **body, int *b_size, char **ctype) char **body, int *b_size, char **ctype)
/* serves webfinger queries */ /* serves webfinger queries */