From bdc166111df38377e0fdcffe386715d1c33c7ef2 Mon Sep 17 00:00:00 2001 From: default Date: Fri, 23 Sep 2022 17:33:33 +0200 Subject: [PATCH] [activitypub.c] New file. --- Makefile | 3 ++- activitypub.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ main.c | 9 +++++++ snac.h | 2 ++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 activitypub.c diff --git a/Makefile b/Makefile index 3f72197..246bbfd 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CFLAGS=-g -Wall all: snac -snac: snac.o main.o data.o http.o httpd.o webfinger.o +snac: snac.o main.o data.o http.o httpd.o webfinger.o activitypub.o $(CC) -L/usr/local/lib *.o -lcurl -lcrypto -o $@ .c.o: @@ -14,6 +14,7 @@ clean: dep: $(CC) -I/usr/local/include -MM *.c > makefile.depend +activitypub.o: activitypub.c xs.h xs_encdec.h xs_json.h xs_curl.h snac.h data.o: data.c xs.h xs_io.h xs_json.h xs_openssl.h snac.h http.o: http.c xs.h xs_io.h xs_encdec.h xs_openssl.h xs_curl.h snac.h httpd.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 @@ +/* snac - A simple, minimalistic ActivityPub instance */ +/* copyright (c) 2022 grunfink - MIT license */ + +#include "xs.h" +#include "xs_encdec.h" +#include "xs_json.h" +#include "xs_curl.h" + +#include "snac.h" + +const char *public_address = "https:/" "/www.w3.org/ns/activitystreams#Public"; + +int activitypub_request(snac *snac, char *url, d_char **data) +/* request an object */ +{ + int status; + xs *response = NULL; + xs *payload; + int p_size; + + /* check if it's an url for this same site */ + /* ... */ + + /* get from the net */ + response = http_signed_request(snac, "GET", url, + NULL, NULL, 0, &status, &payload, &p_size); + + { + xs *j = xs_json_loads(response); + printf("%s\n", j); + } + + if (valid_status(status)) { + *data = xs_json_loads(payload); + } + + return status; +} + + +#if 0 +int actor_request(snac *snac, char *actor, d_char **data) +/* request an actor */ +{ + int status; + xs *response = NULL; + xs *payload; + int p_size; + + /* get from disk first */ + status = actor_get(snac, actor, data); + + if (status == 200) + return; + + /* get from the net */ + response = http_signed_request(snac, "GET", actor, + NULL, NULL, 0, &status, &payload, &p_size); + +// response = http_signed_request(&snac, "GET", "https://mastodon.social/users/VictorMoral", +// headers, NULL, 0, &status, &payload, &p_size); + + return status; +} +#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[]) char *cmd; char *basedir; char *user; + char *url; int argi = 1; argc--; @@ -67,6 +68,14 @@ int main(int argc, char *argv[]) return 0; } + if (argc < argi) + return usage(); + + url = argv[argi++]; + + if (strcmp(cmd, "request") == 0) { + } + return 0; } 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); void webfinger_request(char *qs, int *status, char **actor, char **user); void webfinger_get_handler(d_char *req, char *q_path, int *status, char **body, int *b_size, char **ctype); + +int activitypub_request(snac *snac, char *url, d_char **data);