Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
webui: import redirected css through @import, fixes #3738
  • Loading branch information
perexg committed Apr 21, 2016
1 parent ac2d90e commit 8c6ee92
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
26 changes: 23 additions & 3 deletions src/http.c
Expand Up @@ -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);
}
Expand All @@ -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);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/http.h
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/webui/webui.c
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 8c6ee92

Please sign in to comment.