summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-09-23 17:33:33 +0200
committerdefault <nobody@localhost>2022-09-23 17:33:33 +0200
commitbdc166111df38377e0fdcffe386715d1c33c7ef2 (patch)
treeb13a3ec860b38abe4b599e4f6a8f65f5031c8e60
parent6281ef2c92ef8b28e688a99908c4372bd9ba7777 (diff)
[activitypub.c] New file.
-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
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);