diff options
| -rw-r--r-- | html.c | 20 |
1 files changed, 17 insertions, 3 deletions
| @@ -9,6 +9,7 @@ | |||
| 9 | #include "xs_set.h" | 9 | #include "xs_set.h" |
| 10 | #include "xs_openssl.h" | 10 | #include "xs_openssl.h" |
| 11 | #include "xs_time.h" | 11 | #include "xs_time.h" |
| 12 | #include "xs_mime.h" | ||
| 12 | 13 | ||
| 13 | #include "snac.h" | 14 | #include "snac.h" |
| 14 | 15 | ||
| @@ -716,12 +717,15 @@ d_char *html_timeline(snac *snac, char *list, int local) | |||
| 716 | 717 | ||
| 717 | int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype) | 718 | int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype) |
| 718 | { | 719 | { |
| 719 | int status = 404; | 720 | int status; |
| 720 | snac snac; | 721 | snac snac; |
| 721 | char *uid, *p_path; | 722 | char *uid, *p_path; |
| 722 | int cache = 1; | 723 | int cache = 1; |
| 723 | char *v; | 724 | char *v; |
| 724 | 725 | ||
| 726 | status = 404; | ||
| 727 | *ctype = NULL; | ||
| 728 | |||
| 725 | xs *l = xs_split_n(q_path, "/", 2); | 729 | xs *l = xs_split_n(q_path, "/", 2); |
| 726 | 730 | ||
| 727 | uid = xs_list_get(l, 1); | 731 | uid = xs_list_get(l, 1); |
| @@ -803,11 +807,21 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char * | |||
| 803 | else | 807 | else |
| 804 | if (xs_startswith(p_path, "s/")) { | 808 | if (xs_startswith(p_path, "s/")) { |
| 805 | /* a static file */ | 809 | /* a static file */ |
| 810 | xs *l = xs_split(p_path, "/"); | ||
| 811 | char *id = xs_list_get(l, 1); | ||
| 812 | int sz; | ||
| 813 | |||
| 814 | if (valid_status(static_get(&snac, id, body, &sz))) { | ||
| 815 | *b_size = sz; | ||
| 816 | *ctype = xs_mime_by_ext(id); | ||
| 817 | status = 200; | ||
| 818 | } | ||
| 806 | } | 819 | } |
| 807 | else | 820 | else |
| 808 | if (xs_startswith(p_path, "h/")) { | 821 | if (xs_startswith(p_path, "h/")) { |
| 809 | /* an entry from the history */ | 822 | /* an entry from the history */ |
| 810 | xs *id = xs_replace(p_path, "h/", ""); | 823 | xs *l = xs_split(p_path, "/"); |
| 824 | char *id = xs_list_get(l, 1); | ||
| 811 | 825 | ||
| 812 | if ((*body = history_get(&snac, id)) != NULL) { | 826 | if ((*body = history_get(&snac, id)) != NULL) { |
| 813 | *b_size = strlen(*body); | 827 | *b_size = strlen(*body); |
| @@ -819,7 +833,7 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char * | |||
| 819 | 833 | ||
| 820 | user_free(&snac); | 834 | user_free(&snac); |
| 821 | 835 | ||
| 822 | if (valid_status(status)) { | 836 | if (valid_status(status) && *ctype == NULL) { |
| 823 | *ctype = "text/html; charset=utf-8"; | 837 | *ctype = "text/html; charset=utf-8"; |
| 824 | } | 838 | } |
| 825 | 839 | ||