diff options
Diffstat (limited to 'httpd.c')
| -rw-r--r-- | httpd.c | 36 |
1 files changed, 36 insertions, 0 deletions
| @@ -23,6 +23,27 @@ const char *susie = | |||
| 23 | "AYTtEsDU9F34AAAAAElFTkSuQmCC"; | 23 | "AYTtEsDU9F34AAAAAElFTkSuQmCC"; |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | /* nodeinfo 2.0 template */ | ||
| 27 | const 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 | |||
| 36 | d_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 | |||
| 26 | int server_get_handler(d_char *req, char *q_path, | 47 | int 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)); |