commit e0c6fb7

default  ·  2023-06-13 18:36:43 +0000 UTC
parent e26d057
New function webfinger_request_signed().
3 files changed,  +47, -17
M main.c
M snac.h
M main.c
+34, -15
 1@@ -16,20 +16,21 @@ int usage(void)
 2     printf("\n");
 3     printf("Commands:\n");
 4     printf("\n");
 5-    printf("init [{basedir}]                 Initializes the data storage\n");
 6-    printf("upgrade {basedir}                Upgrade to a new version\n");
 7-    printf("adduser {basedir} [{uid}]        Adds a new user\n");
 8-    printf("httpd {basedir}                  Starts the HTTPD daemon\n");
 9-    printf("purge {basedir}                  Purges old data\n");
10-    printf("webfinger {basedir} {user}       Queries about a @user@host or actor\n");
11-    printf("queue {basedir} {uid}            Processes a user queue\n");
12-    printf("follow {basedir} {uid} {actor}   Follows an actor\n");
13-    printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n");
14-    printf("request {basedir} {uid} {url}    Requests an object\n");
15-    printf("actor {basedir} {uid} {url}      Requests an actor\n");
16-    printf("note {basedir} {uid} {'text'}    Sends a note to followers\n");
17-    printf("resetpwd {basedir} {uid}         Resets the password of a user\n");
18-    printf("ping {basedir} {uid} {actor}     Pings an actor\n");
19+    printf("init [{basedir}]                    Initializes the data storage\n");
20+    printf("upgrade {basedir}                   Upgrade to a new version\n");
21+    printf("adduser {basedir} [{uid}]           Adds a new user\n");
22+    printf("httpd {basedir}                     Starts the HTTPD daemon\n");
23+    printf("purge {basedir}                     Purges old data\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");
26+    printf("follow {basedir} {uid} {actor}      Follows an actor\n");
27+    printf("unfollow {basedir} {uid} {actor}    Unfollows an actor\n");
28+    printf("request {basedir} {uid} {url}       Requests an object\n");
29+    printf("actor {basedir} {uid} {url}         Requests an actor\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");
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");
34 /*    printf("question {basedir} {uid} 'opts'  Generates a poll (;-separated opts)\n");*/
35 
36     return 1;
37@@ -179,6 +180,22 @@ int main(int argc, char *argv[])
38     if ((url = GET_ARGV()) == NULL)
39         return usage();
40 
41+    if (strcmp(cmd, "webfinger_s") == 0) { /** **/
42+        xs *actor = NULL;
43+        xs *uid = NULL;
44+        int status;
45+
46+        status = webfinger_request_signed(&snac, url, &actor, &uid);
47+
48+        printf("status: %d\n", status);
49+        if (actor != NULL)
50+            printf("actor: %s\n", actor);
51+        if (uid != NULL)
52+            printf("uid: %s\n", uid);
53+
54+        return 0;
55+    }
56+
57     if (strcmp(cmd, "announce") == 0) { /** **/
58         xs *msg = msg_admiration(&snac, url, "Announce");
59 
60@@ -352,5 +369,7 @@ int main(int argc, char *argv[])
61         return 0;
62     }
63 
64-    return 0;
65+    fprintf(stderr, "ERROR: bad command '%s'\n", cmd);
66+
67+    return 1;
68 }
M snac.h
+1, -0
1@@ -191,6 +191,7 @@ int check_signature(snac *snac, xs_dict *req, xs_str **err);
2 
3 void httpd(void);
4 
5+int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **user);
6 int webfinger_request(const char *qs, char **actor, char **user);
7 int webfinger_get_handler(xs_dict *req, char *q_path,
8                           char **body, int *b_size, char **ctype);
+12, -2
 1@@ -7,7 +7,7 @@
 2 
 3 #include "snac.h"
 4 
 5-int webfinger_request(const char *qs, char **actor, char **user)
 6+int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **user)
 7 /* queries the webfinger for qs and fills the required fields */
 8 {
 9     int status;
10@@ -61,7 +61,10 @@ int webfinger_request(const char *qs, char **actor, char **user)
11     else {
12         xs *url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource=%s", host, resource);
13 
14-        xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0);
15+        if (snac == NULL)
16+            xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0);
17+        else
18+            http_signed_request(snac, "GET", url, headers, NULL, 0, &status, &payload, &p_size, 0);
19     }
20 
21     if (valid_status(status)) {
22@@ -96,6 +99,13 @@ int webfinger_request(const char *qs, char **actor, char **user)
23 }
24 
25 
26+int webfinger_request(const char *qs, char **actor, char **user)
27+/* queries the webfinger for qs and fills the required fields */
28+{
29+    return webfinger_request_signed(NULL, qs, actor, user);
30+}
31+
32+
33 int webfinger_get_handler(d_char *req, char *q_path,
34                            char **body, int *b_size, char **ctype)
35 /* serves webfinger queries */