From: Jaroslav Kysela Date: Thu, 6 Aug 2015 13:41:33 +0000 (+0200) Subject: webui: fix --http_root issues, fixes #3035 X-Git-Tag: v4.0.6~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=574aad91085aee250eb779075038efbbe5b8e0ae;p=thirdparty%2Ftvheadend.git webui: fix --http_root issues, fixes #3035 --- diff --git a/src/http.c b/src/http.c index 205a992de..2a418bbb0 100644 --- a/src/http.c +++ b/src/http.c @@ -407,7 +407,8 @@ http_error(http_connection_t *hc, int error) error, errtxt, error, errtxt); if (error == HTTP_STATUS_UNAUTHORIZED) - htsbuf_qprintf(&hc->hc_reply, "

Default Login

"); + htsbuf_qprintf(&hc->hc_reply, "

Default Login

", + tvheadend_webroot ? tvheadend_webroot : ""); htsbuf_qprintf(&hc->hc_reply, "\r\n"); @@ -444,7 +445,7 @@ http_output_content(http_connection_t *hc, const char *content) */ void http_redirect(http_connection_t *hc, const char *location, - http_arg_list_t *req_args) + http_arg_list_t *req_args, int external) { const char *loc = location; htsbuf_queue_flush(&hc->hc_reply); @@ -454,6 +455,8 @@ http_redirect(http_connection_t *hc, const char *location, htsbuf_queue_t hq; int first = 1; htsbuf_queue_init(&hq, 0); + if (!external && tvheadend_webroot && location[0] == '/') + htsbuf_append(&hq, tvheadend_webroot, strlen(tvheadend_webroot)); htsbuf_append(&hq, location, strlen(location)); htsbuf_append(&hq, "?", 1); TAILQ_FOREACH(ra, req_args, link) { @@ -466,6 +469,10 @@ 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); + strcpy((char *)loc, tvheadend_webroot); + strcat((char *)loc, location); } htsbuf_qprintf(&hc->hc_reply, diff --git a/src/http.h b/src/http.h index 8df736e8b..2326618d8 100644 --- a/src/http.h +++ b/src/http.h @@ -191,7 +191,7 @@ void http_output_html(http_connection_t *hc); 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); + struct http_arg_list *req_args, int external); void http_send_header(http_connection_t *hc, int rc, const char *content, int64_t contentlen, const char *encoding, diff --git a/src/webui/simpleui.c b/src/webui/simpleui.c index ad4f7c136..4a71f664f 100644 --- a/src/webui/simpleui.c +++ b/src/webui/simpleui.c @@ -409,7 +409,7 @@ page_pvrinfo(http_connection_t *hc, const char *remain, void *opaque) if(de == NULL) { pthread_mutex_unlock(&global_lock); - http_redirect(hc, "/simple.html", &hc->hc_req_args); + http_redirect(hc, "/simple.html", &hc->hc_req_args, 0); return 0; } diff --git a/src/webui/webui.c b/src/webui/webui.c index c144c1a36..340749631 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -92,9 +92,9 @@ static int page_root(http_connection_t *hc, const char *remain, void *opaque) { if(is_client_simple(hc)) { - http_redirect(hc, "simple.html", &hc->hc_req_args); + http_redirect(hc, "simple.html", &hc->hc_req_args, 0); } else { - http_redirect(hc, "extjs.html", &hc->hc_req_args); + http_redirect(hc, "extjs.html", &hc->hc_req_args, 0); } return 0; } @@ -103,10 +103,7 @@ static int page_root2(http_connection_t *hc, const char *remain, void *opaque) { if (!tvheadend_webroot) return 1; - char *tmp = malloc(strlen(tvheadend_webroot) + 2); - sprintf(tmp, "%s/", tvheadend_webroot); - http_redirect(hc, tmp, &hc->hc_req_args); - free(tmp); + http_redirect(hc, "/", &hc->hc_req_args, 0); return 0; } @@ -116,7 +113,7 @@ page_login(http_connection_t *hc, const char *remain, void *opaque) if (hc->hc_access != NULL && hc->hc_access->aa_username != NULL && hc->hc_access->aa_username != '\0') { - http_redirect(hc, "/", &hc->hc_req_args); + http_redirect(hc, "/", &hc->hc_req_args, 0); return 0; } else { return HTTP_STATUS_UNAUTHORIZED; @@ -130,7 +127,7 @@ page_logout(http_connection_t *hc, const char *remain, void *opaque) hc->hc_access->aa_username == NULL || hc->hc_access->aa_username == '\0') { redirect: - http_redirect(hc, "/", &hc->hc_req_args); + http_redirect(hc, "/", &hc->hc_req_args, 0); return 0; } else { const char *s = http_arg_get(&hc->hc_args, "Cookie"); @@ -1406,7 +1403,7 @@ webui_static_content(const char *http_path, const char *source) static int favicon(http_connection_t *hc, const char *remain, void *opaque) { - http_redirect(hc, "static/htslogo.png", NULL); + http_redirect(hc, "static/htslogo.png", NULL, 0); return 0; }