mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 06:25:04 +00:00
New function activitypub_get_handler().
This commit is contained in:
parent
1d694a245a
commit
6e6c315494
3 changed files with 67 additions and 2 deletions
|
@ -156,13 +156,73 @@ void process_queue(snac *snac)
|
|||
}
|
||||
|
||||
|
||||
int activitypub_get_handler(d_char *req, char *q_path,
|
||||
char **body, int *b_size, char **ctype)
|
||||
{
|
||||
int status = 200;
|
||||
char *headers = xs_dict_get(req, "headers");
|
||||
char *accept = xs_dict_get(headers, "accept");
|
||||
snac snac;
|
||||
xs *msg = xs_dict_new();
|
||||
|
||||
if (xs_str_in(accept, "application/activity+json") == -1 &&
|
||||
xs_str_in(accept, "application/ld+json") == -1)
|
||||
return 0;
|
||||
|
||||
xs *l = xs_split_n(q_path, "/", 2);
|
||||
char *uid, *p_path;
|
||||
|
||||
uid = xs_list_get(l, 1);
|
||||
if (!user_open(&snac, uid)) {
|
||||
/* invalid user */
|
||||
srv_log(xs_fmt("activitypub_get_handler bad user %s", uid));
|
||||
return 404;
|
||||
}
|
||||
|
||||
p_path = xs_list_get(l, 2);
|
||||
|
||||
if (p_path == NULL) {
|
||||
/* if there was no component after the user, it's an actor request */
|
||||
}
|
||||
else
|
||||
if (strcmp(p_path, "outbox") == 0) {
|
||||
}
|
||||
else
|
||||
if (strcmp(p_path, "followers") == 0 || strcmp(p_path, "following") == 0) {
|
||||
xs *id = xs_fmt("%s/%s", snac.actor, p_path);
|
||||
|
||||
msg = xs_dict_append(msg, "@context", "https:/" "/www.w3.org/ns/activitystreams");
|
||||
msg = xs_dict_append(msg, "attributedTo", snac.actor);
|
||||
msg = xs_dict_append(msg, "id", id);
|
||||
msg = xs_dict_append(msg, "orderedItems", xs_list_new());
|
||||
msg = xs_dict_append(msg, "totalItems", xs_number_new(0));
|
||||
msg = xs_dict_append(msg, "type", "OrderedCollection");
|
||||
}
|
||||
else
|
||||
if (xs_startswith(p_path, "p/")) {
|
||||
}
|
||||
else
|
||||
status = 404;
|
||||
|
||||
if (status == 200) {
|
||||
*body = xs_json_dumps_pp(msg, 4);
|
||||
*b_size = strlen(*body);
|
||||
}
|
||||
|
||||
user_free(&snac);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
int activitypub_post_handler(d_char *req, char *q_path,
|
||||
d_char *payload, int p_size,
|
||||
char **body, int *b_size, char **ctype)
|
||||
/* processes an input message */
|
||||
{
|
||||
int status = 200;
|
||||
char *i_ctype = xs_dict_get(req, "content-type");
|
||||
char *headers = xs_dict_get(req, "headers");
|
||||
char *i_ctype = xs_dict_get(headers, "content-type");
|
||||
snac snac;
|
||||
|
||||
if (xs_str_in(i_ctype, "application/activity+json") == -1 &&
|
||||
|
|
3
httpd.c
3
httpd.c
|
@ -131,6 +131,9 @@ void httpd_connection(int rs)
|
|||
|
||||
if (status == 0)
|
||||
status = webfinger_get_handler(req, q_path, &body, &b_size, &ctype);
|
||||
|
||||
if (status == 0)
|
||||
status = activitypub_get_handler(req, q_path, &body, &b_size, &ctype);
|
||||
}
|
||||
else
|
||||
if (strcmp(method, "POST") == 0) {
|
||||
|
|
2
snac.h
2
snac.h
|
@ -85,6 +85,8 @@ int actor_request(snac *snac, char *actor, d_char **data);
|
|||
int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size);
|
||||
int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size);
|
||||
void process_queue(snac *snac);
|
||||
int activitypub_get_handler(d_char *req, char *q_path,
|
||||
char **body, int *b_size, char **ctype);
|
||||
int activitypub_post_handler(d_char *req, char *q_path,
|
||||
char *payload, int p_size,
|
||||
char **body, int *b_size, char **ctype);
|
||||
|
|
Loading…
Reference in a new issue