summaryrefslogtreecommitdiff
path: root/httpd.c
diff options
context:
space:
mode:
authorGravatar default2022-12-08 09:58:47 +0100
committerGravatar default2022-12-08 09:58:47 +0100
commit5c6d44cdbc27c53f18d64c7e7008df2d8cf7d818 (patch)
treebfcf983caf3daa34bebb2467ab724b0ec432ff72 /httpd.c
parentUpdated TODO. (diff)
downloadsnac2-5c6d44cdbc27c53f18d64c7e7008df2d8cf7d818.tar.gz
snac2-5c6d44cdbc27c53f18d64c7e7008df2d8cf7d818.tar.xz
snac2-5c6d44cdbc27c53f18d64c7e7008df2d8cf7d818.zip
Added support for /.well-known/nodeinfo.
Diffstat (limited to 'httpd.c')
-rw-r--r--httpd.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/httpd.c b/httpd.c
index bfe14fe..7d76084 100644
--- a/httpd.c
+++ b/httpd.c
@@ -23,6 +23,27 @@ const char *susie =
23 "AYTtEsDU9F34AAAAAElFTkSuQmCC"; 23 "AYTtEsDU9F34AAAAAElFTkSuQmCC";
24 24
25 25
26/* nodeinfo 2.0 template */
27const char *nodeinfo_2_0_template = ""
28 "{\"version\":\"2.0\","
29 "\"software\":{\"name\":\"snac\",\"version\":\"" VERSION "\"},"
30 "\"protocols\":[\"activitypub\"],"
31 "\"services\":{\"outbound\":[],\"inbound\":[]},"
32 "\"usage\":{\"users\":{\"total\":%d,\"activeMonth\":%d,\"activeHalfyear\":%d},"
33 "\"localPosts\":%d},"
34 "\"openRegistrations\":false,\"metadata\":{}}";
35
36d_char *nodeinfo_2_0(void)
37/* builds a nodeinfo json object */
38{
39 xs *users = user_list();
40 int n_users = xs_list_len(users);
41 int n_posts = 0; /* to be implemented someday */
42
43 return xs_fmt(nodeinfo_2_0_template, n_users, n_users, n_users, n_posts);
44}
45
46
26int server_get_handler(d_char *req, char *q_path, 47int server_get_handler(d_char *req, char *q_path,
27 char **body, int *b_size, char **ctype) 48 char **body, int *b_size, char **ctype)
28/* basic server services */ 49/* basic server services */
@@ -81,6 +102,21 @@ int server_get_handler(d_char *req, char *q_path,
81 *body = xs_base64_dec(susie, b_size); 102 *body = xs_base64_dec(susie, b_size);
82 *ctype = "image/png"; 103 *ctype = "image/png";
83 } 104 }
105 else
106 if (strcmp(q_path, "/.well-known/nodeinfo") == 0) {
107 status = 200;
108 *ctype = "application/json; charset=utf-8";
109 *body = xs_fmt("{\"links\":["
110 "{\"rel\":\"http:/" "/nodeinfo.diaspora.software/ns/schema/2.0\","
111 "\"href\":\"%s/nodeinfo_2_0\"}]}",
112 srv_baseurl);
113 }
114 else
115 if (strcmp(q_path, "/nodeinfo_2_0") == 0) {
116 status = 200;
117 *ctype = "application/json; charset=utf-8";
118 *body = nodeinfo_2_0();
119 }
84 120
85 if (status != 0) 121 if (status != 0)
86 srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status)); 122 srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status));