Browse Source

[activitypub.c] New file.

default 2 years ago
parent
commit
bdc166111d
4 changed files with 78 additions and 1 deletions
  1. 2 1
      Makefile
  2. 65 0
      activitypub.c
  3. 9 0
      main.c
  4. 2 0
      snac.h

+ 2 - 1
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 \

+ 65 - 0
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

+ 9 - 0
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;
 }
 

+ 2 - 0
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);