diff options
Diffstat (limited to 'httpd.c')
| -rw-r--r-- | httpd.c | 39 |
1 files changed, 39 insertions, 0 deletions
| @@ -164,6 +164,23 @@ static xs_str *greeting_html(void) | |||
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | 166 | ||
| 167 | const char *share_page = "" | ||
| 168 | "<!DOCTYPE html>\n" | ||
| 169 | "<html>\n" | ||
| 170 | "<head>\n" | ||
| 171 | "<title>%s - snac</title>\n" | ||
| 172 | "<meta content=\"width=device-width, initial-scale=1, minimum-scale=1, user-scalable=no\" name=\"viewport\">" | ||
| 173 | "<style>:root {color-scheme: light dark}</style>\n" | ||
| 174 | "</head>\n" | ||
| 175 | "<body><h1>%s link share</h1>\n" | ||
| 176 | "<form method=\"post\" action=\"%s/share-bridge\">\n" | ||
| 177 | "<textarea name=\"content\" rows=\"6\" wrap=\"virtual\" required=\"required\" style=\"width: 50em\">%s</textarea>\n" | ||
| 178 | "<p>Login: <input type=\"text\" name=\"login\" autocapitalize=\"off\" required=\"required\"></p>\n" | ||
| 179 | "<input type=\"submit\" value=\"OK\">\n" | ||
| 180 | "</form><p>%s</p></body></html>\n" | ||
| 181 | ""; | ||
| 182 | |||
| 183 | |||
| 167 | int server_get_handler(xs_dict *req, const char *q_path, | 184 | int server_get_handler(xs_dict *req, const char *q_path, |
| 168 | char **body, int *b_size, char **ctype) | 185 | char **body, int *b_size, char **ctype) |
| 169 | /* basic server services */ | 186 | /* basic server services */ |
| @@ -257,6 +274,28 @@ int server_get_handler(xs_dict *req, const char *q_path, | |||
| 257 | *body = xs_str_new("User-agent: *\n" | 274 | *body = xs_str_new("User-agent: *\n" |
| 258 | "Disallow: /\n"); | 275 | "Disallow: /\n"); |
| 259 | } | 276 | } |
| 277 | else | ||
| 278 | if (strcmp(q_path, "/share") == 0) { | ||
| 279 | const xs_dict *q_vars = xs_dict_get(req, "q_vars"); | ||
| 280 | const char *url = xs_dict_get(q_vars, "url"); | ||
| 281 | const char *text = xs_dict_get(q_vars, "text"); | ||
| 282 | xs *s = NULL; | ||
| 283 | |||
| 284 | if (xs_type(text) == XSTYPE_STRING) | ||
| 285 | s = xs_fmt("%s\n\n%s\n", text, url); | ||
| 286 | else | ||
| 287 | s = xs_fmt("%s\n", url); | ||
| 288 | |||
| 289 | status = HTTP_STATUS_OK; | ||
| 290 | *ctype = "text/html"; | ||
| 291 | *body = xs_fmt(share_page, | ||
| 292 | xs_dict_get(srv_config, "host"), | ||
| 293 | xs_dict_get(srv_config, "host"), | ||
| 294 | srv_baseurl, | ||
| 295 | s, | ||
| 296 | USER_AGENT | ||
| 297 | ); | ||
| 298 | } | ||
| 260 | 299 | ||
| 261 | if (status != 0) | 300 | if (status != 0) |
| 262 | srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status)); | 301 | srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status)); |