summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--activitypub.c65
-rw-r--r--main.c9
-rw-r--r--snac.h2
4 files changed, 78 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 3f72197..246bbfd 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ CFLAGS=-g -Wall
2 2
3all: snac 3all: snac
4 4
5snac: snac.o main.o data.o http.o httpd.o webfinger.o 5snac: snac.o main.o data.o http.o httpd.o webfinger.o activitypub.o
6 $(CC) -L/usr/local/lib *.o -lcurl -lcrypto -o $@ 6 $(CC) -L/usr/local/lib *.o -lcurl -lcrypto -o $@
7 7
8.c.o: 8.c.o:
@@ -14,6 +14,7 @@ clean:
14dep: 14dep:
15 $(CC) -I/usr/local/include -MM *.c > makefile.depend 15 $(CC) -I/usr/local/include -MM *.c > makefile.depend
16 16
17activitypub.o: activitypub.c xs.h xs_encdec.h xs_json.h xs_curl.h snac.h
17data.o: data.c xs.h xs_io.h xs_json.h xs_openssl.h snac.h 18data.o: data.c xs.h xs_io.h xs_json.h xs_openssl.h snac.h
18http.o: http.c xs.h xs_io.h xs_encdec.h xs_openssl.h xs_curl.h snac.h 19http.o: http.c xs.h xs_io.h xs_encdec.h xs_openssl.h xs_curl.h snac.h
19httpd.o: httpd.c xs.h xs_io.h xs_encdec.h xs_json.h xs_socket.h \ 20httpd.o: httpd.c xs.h xs_io.h xs_encdec.h xs_json.h xs_socket.h \
diff --git a/activitypub.c b/activitypub.c
new file mode 100644
index 0000000..de99b75
--- /dev/null
+++ b/activitypub.c
@@ -0,0 +1,65 @@
1/* snac - A simple, minimalistic ActivityPub instance */
2/* copyright (c) 2022 grunfink - MIT license */
3
4#include "xs.h"
5#include "xs_encdec.h"
6#include "xs_json.h"
7#include "xs_curl.h"
8
9#include "snac.h"
10
11const char *public_address = "https:/" "/www.w3.org/ns/activitystreams#Public";
12
13int activitypub_request(snac *snac, char *url, d_char **data)
14/* request an object */
15{
16 int status;
17 xs *response = NULL;
18 xs *payload;
19 int p_size;
20
21 /* check if it's an url for this same site */
22 /* ... */
23
24 /* get from the net */
25 response = http_signed_request(snac, "GET", url,
26 NULL, NULL, 0, &status, &payload, &p_size);
27
28 {
29 xs *j = xs_json_loads(response);
30 printf("%s\n", j);
31 }
32
33 if (valid_status(status)) {
34 *data = xs_json_loads(payload);
35 }
36
37 return status;
38}
39
40
41#if 0
42int actor_request(snac *snac, char *actor, d_char **data)
43/* request an actor */
44{
45 int status;
46 xs *response = NULL;
47 xs *payload;
48 int p_size;
49
50 /* get from disk first */
51 status = actor_get(snac, actor, data);
52
53 if (status == 200)
54 return;
55
56 /* get from the net */
57 response = http_signed_request(snac, "GET", actor,
58 NULL, NULL, 0, &status, &payload, &p_size);
59
60// response = http_signed_request(&snac, "GET", "https://mastodon.social/users/VictorMoral",
61// headers, NULL, 0, &status, &payload, &p_size);
62
63 return status;
64}
65#endif
diff --git a/main.c b/main.c
index 2a62816..d7c1640 100644
--- a/main.c
+++ b/main.c
@@ -19,6 +19,7 @@ int main(int argc, char *argv[])
19 char *cmd; 19 char *cmd;
20 char *basedir; 20 char *basedir;
21 char *user; 21 char *user;
22 char *url;
22 int argi = 1; 23 int argi = 1;
23 24
24 argc--; 25 argc--;
@@ -67,6 +68,14 @@ int main(int argc, char *argv[])
67 return 0; 68 return 0;
68 } 69 }
69 70
71 if (argc < argi)
72 return usage();
73
74 url = argv[argi++];
75
76 if (strcmp(cmd, "request") == 0) {
77 }
78
70 return 0; 79 return 0;
71} 80}
72 81
diff --git a/snac.h b/snac.h
index 7fab1fc..ffd88dc 100644
--- a/snac.h
+++ b/snac.h
@@ -79,3 +79,5 @@ void httpd(void);
79void webfinger_request(char *qs, int *status, char **actor, char **user); 79void webfinger_request(char *qs, int *status, 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
83int activitypub_request(snac *snac, char *url, d_char **data);