commit 5c6d44c

default  ·  2022-12-08 08:58:47 +0000 UTC
parent 0a0896b
Added support for /.well-known/nodeinfo.
1 files changed,  +36, -0
+36, -0
 1@@ -23,6 +23,27 @@ const char *susie =
 2     "AYTtEsDU9F34AAAAAElFTkSuQmCC";
 3 
 4 
 5+/* nodeinfo 2.0 template */
 6+const char *nodeinfo_2_0_template = ""
 7+    "{\"version\":\"2.0\","
 8+    "\"software\":{\"name\":\"snac\",\"version\":\"" VERSION "\"},"
 9+    "\"protocols\":[\"activitypub\"],"
10+    "\"services\":{\"outbound\":[],\"inbound\":[]},"
11+    "\"usage\":{\"users\":{\"total\":%d,\"activeMonth\":%d,\"activeHalfyear\":%d},"
12+    "\"localPosts\":%d},"
13+    "\"openRegistrations\":false,\"metadata\":{}}";
14+
15+d_char *nodeinfo_2_0(void)
16+/* builds a nodeinfo json object */
17+{
18+    xs *users   = user_list();
19+    int n_users = xs_list_len(users);
20+    int n_posts = 0; /* to be implemented someday */
21+
22+    return xs_fmt(nodeinfo_2_0_template, n_users, n_users, n_users, n_posts);
23+}
24+
25+
26 int server_get_handler(d_char *req, char *q_path,
27                        char **body, int *b_size, char **ctype)
28 /* basic server services */
29@@ -81,6 +102,21 @@ int server_get_handler(d_char *req, char *q_path,
30         *body  = xs_base64_dec(susie, b_size);
31         *ctype = "image/png";
32     }
33+    else
34+    if (strcmp(q_path, "/.well-known/nodeinfo") == 0) {
35+        status = 200;
36+        *ctype = "application/json; charset=utf-8";
37+        *body  = xs_fmt("{\"links\":["
38+            "{\"rel\":\"http:/" "/nodeinfo.diaspora.software/ns/schema/2.0\","
39+            "\"href\":\"%s/nodeinfo_2_0\"}]}",
40+            srv_baseurl);
41+    }
42+    else
43+    if (strcmp(q_path, "/nodeinfo_2_0") == 0) {
44+        status = 200;
45+        *ctype = "application/json; charset=utf-8";
46+        *body  = nodeinfo_2_0();
47+    }
48 
49     if (status != 0)
50         srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status));