From 8c6ee92f3f7ca537f285666131479fa0301a89de Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Thu, 21 Apr 2016 13:39:36 +0200 Subject: [PATCH] webui: import redirected css through @import, fixes #3738 --- src/http.c | 26 +++++++++++++++++++++++--- src/http.h | 2 ++ src/webui/webui.c | 4 ++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/http.c b/src/http.c index 243c70774..60c92e883 100644 --- a/src/http.c +++ b/src/http.c @@ -635,7 +635,7 @@ http_redirect(http_connection_t *hc, const char *location, loc = htsbuf_to_string(&hq); htsbuf_queue_flush(&hq); } else if (!external && tvheadend_webroot && location[0] == '/') { - loc = malloc(strlen(location) + strlen(tvheadend_webroot) + 1); + loc = alloca(strlen(location) + strlen(tvheadend_webroot) + 1); strcpy((char *)loc, tvheadend_webroot); strcat((char *)loc, location); } @@ -650,8 +650,28 @@ http_redirect(http_connection_t *hc, const char *location, loc, loc); http_send_reply(hc, HTTP_STATUS_FOUND, "text/html", NULL, loc, 0); - if (loc != location) - free((void *)loc); +} + + +/** + * Send an CSS @import + */ +void +http_css_import(http_connection_t *hc, const char *location) +{ + const char *loc = location; + + htsbuf_queue_flush(&hc->hc_reply); + + if (tvheadend_webroot && location[0] == '/') { + loc = alloca(strlen(location) + strlen(tvheadend_webroot) + 1); + strcpy((char *)loc, tvheadend_webroot); + strcat((char *)loc, location); + } + + htsbuf_qprintf(&hc->hc_reply, "@import url('%s');\r\n", loc); + + http_send_reply(hc, HTTP_STATUS_OK, "text/css", NULL, loc, 0); } /** diff --git a/src/http.h b/src/http.h index 2a8d9b78c..b929daa6c 100644 --- a/src/http.h +++ b/src/http.h @@ -203,6 +203,8 @@ void http_output_content(http_connection_t *hc, const char *content); void http_redirect(http_connection_t *hc, const char *location, struct http_arg_list *req_args, int external); +void http_css_import(http_connection_t *hc, const char *location); + void http_send_header(http_connection_t *hc, int rc, const char *content, int64_t contentlen, const char *encoding, const char *location, int maxage, const char *range, diff --git a/src/webui/webui.c b/src/webui/webui.c index cb0918ee6..8e3edee7a 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -1794,7 +1794,7 @@ http_redir(http_connection_t *hc, const char *remain, void *opaque) snprintf(buf, sizeof(buf), "src/webui/static/tvh.%s.css.gz", theme); if (!http_file_test(buf)) { snprintf(buf, sizeof(buf), "/static/tvh.%s.css.gz", theme); - http_redirect(hc, buf, NULL, 0); + http_css_import(hc, buf); return 0; } } @@ -1806,7 +1806,7 @@ http_redir(http_connection_t *hc, const char *remain, void *opaque) snprintf(buf, sizeof(buf), "src/webui/static/extjs/resources/css/xtheme-%s.css", theme); if (!http_file_test(buf)) { snprintf(buf, sizeof(buf), "/static/extjs/resources/css/xtheme-%s.css", theme); - http_redirect(hc, buf, NULL, 0); + http_css_import(hc, buf); return 0; } } -- 2.47.3