From 5c330660cda0bb7423d7e3f07924e56941455599 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 31 Dec 2024 17:01:08 +0100 Subject: Started support for Mastodon-like /share endpoint. --- httpd.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/httpd.c b/httpd.c index 11e4d17..f567d17 100644 --- a/httpd.c +++ b/httpd.c @@ -164,6 +164,23 @@ static xs_str *greeting_html(void) } +const char *share_page = "" +"\n" +"\n" +"
\n" +"%s
\n" +""; + + int server_get_handler(xs_dict *req, const char *q_path, char **body, int *b_size, char **ctype) /* basic server services */ @@ -257,6 +274,28 @@ int server_get_handler(xs_dict *req, const char *q_path, *body = xs_str_new("User-agent: *\n" "Disallow: /\n"); } + else + if (strcmp(q_path, "/share") == 0) { + const xs_dict *q_vars = xs_dict_get(req, "q_vars"); + const char *url = xs_dict_get(q_vars, "url"); + const char *text = xs_dict_get(q_vars, "text"); + xs *s = NULL; + + if (xs_type(text) == XSTYPE_STRING) + s = xs_fmt("%s\n\n%s\n", text, url); + else + s = xs_fmt("%s\n", url); + + status = HTTP_STATUS_OK; + *ctype = "text/html"; + *body = xs_fmt(share_page, + xs_dict_get(srv_config, "host"), + xs_dict_get(srv_config, "host"), + srv_baseurl, + s, + USER_AGENT + ); + } if (status != 0) srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status)); -- cgit v1.2.3