Added support for /.well-known/nodeinfo.

This commit is contained in:
default 2022-12-08 09:58:47 +01:00
parent 0a0896b77b
commit 5c6d44cdbc

36
httpd.c
View File

@ -23,6 +23,27 @@ const char *susie =
"AYTtEsDU9F34AAAAAElFTkSuQmCC";
/* nodeinfo 2.0 template */
const char *nodeinfo_2_0_template = ""
"{\"version\":\"2.0\","
"\"software\":{\"name\":\"snac\",\"version\":\"" VERSION "\"},"
"\"protocols\":[\"activitypub\"],"
"\"services\":{\"outbound\":[],\"inbound\":[]},"
"\"usage\":{\"users\":{\"total\":%d,\"activeMonth\":%d,\"activeHalfyear\":%d},"
"\"localPosts\":%d},"
"\"openRegistrations\":false,\"metadata\":{}}";
d_char *nodeinfo_2_0(void)
/* builds a nodeinfo json object */
{
xs *users = user_list();
int n_users = xs_list_len(users);
int n_posts = 0; /* to be implemented someday */
return xs_fmt(nodeinfo_2_0_template, n_users, n_users, n_users, n_posts);
}
int server_get_handler(d_char *req, char *q_path,
char **body, int *b_size, char **ctype)
/* basic server services */
@ -81,6 +102,21 @@ int server_get_handler(d_char *req, char *q_path,
*body = xs_base64_dec(susie, b_size);
*ctype = "image/png";
}
else
if (strcmp(q_path, "/.well-known/nodeinfo") == 0) {
status = 200;
*ctype = "application/json; charset=utf-8";
*body = xs_fmt("{\"links\":["
"{\"rel\":\"http:/" "/nodeinfo.diaspora.software/ns/schema/2.0\","
"\"href\":\"%s/nodeinfo_2_0\"}]}",
srv_baseurl);
}
else
if (strcmp(q_path, "/nodeinfo_2_0") == 0) {
status = 200;
*ctype = "application/json; charset=utf-8";
*body = nodeinfo_2_0();
}
if (status != 0)
srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status));