[activitypub.c] New file.

This commit is contained in:
default 2022-09-23 17:33:33 +02:00
parent 6281ef2c92
commit bdc166111d
4 changed files with 78 additions and 1 deletions

View File

@ -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
activitypub.c Normal file
View File

@ -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
main.c
View File

@ -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
snac.h
View File

@ -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);