diff options
Diffstat (limited to 'httpd.c')
| -rw-r--r-- | httpd.c | 61 |
1 files changed, 61 insertions, 0 deletions
| @@ -164,6 +164,24 @@ 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\">\n" | ||
| 173 | "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s/style.css\"/>\n" | ||
| 174 | "<style>:root {color-scheme: light dark}</style>\n" | ||
| 175 | "</head>\n" | ||
| 176 | "<body><h1>%s link share</h1>\n" | ||
| 177 | "<form method=\"get\" action=\"%s/share-bridge\">\n" | ||
| 178 | "<textarea name=\"content\" rows=\"6\" wrap=\"virtual\" required=\"required\" style=\"width: 50em\">%s</textarea>\n" | ||
| 179 | "<p>Login: <input type=\"text\" name=\"login\" autocapitalize=\"off\" required=\"required\"></p>\n" | ||
| 180 | "<input type=\"submit\" value=\"OK\">\n" | ||
| 181 | "</form><p>%s</p></body></html>\n" | ||
| 182 | ""; | ||
| 183 | |||
| 184 | |||
| 167 | int server_get_handler(xs_dict *req, const char *q_path, | 185 | int server_get_handler(xs_dict *req, const char *q_path, |
| 168 | char **body, int *b_size, char **ctype) | 186 | char **body, int *b_size, char **ctype) |
| 169 | /* basic server services */ | 187 | /* basic server services */ |
| @@ -257,6 +275,49 @@ int server_get_handler(xs_dict *req, const char *q_path, | |||
| 257 | *body = xs_str_new("User-agent: *\n" | 275 | *body = xs_str_new("User-agent: *\n" |
| 258 | "Disallow: /\n"); | 276 | "Disallow: /\n"); |
| 259 | } | 277 | } |
| 278 | else | ||
| 279 | if (strcmp(q_path, "/style.css") == 0) { | ||
| 280 | FILE *f; | ||
| 281 | xs *css_fn = xs_fmt("%s/style.css", srv_basedir); | ||
| 282 | |||
| 283 | if ((f = fopen(css_fn, "r")) != NULL) { | ||
| 284 | *body = xs_readall(f); | ||
| 285 | fclose(f); | ||
| 286 | |||
| 287 | status = HTTP_STATUS_OK; | ||
| 288 | *ctype = "text/css"; | ||
| 289 | } | ||
| 290 | } | ||
| 291 | else | ||
| 292 | if (strcmp(q_path, "/share") == 0) { | ||
| 293 | const xs_dict *q_vars = xs_dict_get(req, "q_vars"); | ||
| 294 | const char *url = xs_dict_get(q_vars, "url"); | ||
| 295 | const char *text = xs_dict_get(q_vars, "text"); | ||
| 296 | xs *s = NULL; | ||
| 297 | |||
| 298 | if (xs_type(text) == XSTYPE_STRING) { | ||
| 299 | if (xs_type(url) == XSTYPE_STRING) | ||
| 300 | s = xs_fmt("%s:\n\n%s\n", text, url); | ||
| 301 | else | ||
| 302 | s = xs_fmt("%s\n", text); | ||
| 303 | } | ||
| 304 | else | ||
| 305 | if (xs_type(url) == XSTYPE_STRING) | ||
| 306 | s = xs_fmt("%s\n", url); | ||
| 307 | else | ||
| 308 | s = xs_str_new(NULL); | ||
| 309 | |||
| 310 | status = HTTP_STATUS_OK; | ||
| 311 | *ctype = "text/html"; | ||
| 312 | *body = xs_fmt(share_page, | ||
| 313 | xs_dict_get(srv_config, "host"), | ||
| 314 | srv_baseurl, | ||
| 315 | xs_dict_get(srv_config, "host"), | ||
| 316 | srv_baseurl, | ||
| 317 | s, | ||
| 318 | USER_AGENT | ||
| 319 | ); | ||
| 320 | } | ||
| 260 | 321 | ||
| 261 | if (status != 0) | 322 | if (status != 0) |
| 262 | srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status)); | 323 | srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status)); |