Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
webui: fix --http_root issues, fixes #3035
  • Loading branch information
perexg committed Aug 6, 2015
1 parent 9be935d commit d1def08
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
11 changes: 9 additions & 2 deletions src/http.c
Expand Up @@ -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, "<P><A HREF=\"/\">Default Login</A></P>");
htsbuf_qprintf(&hc->hc_reply, "<P><A HREF=\"%s/\">Default Login</A></P>",
tvheadend_webroot ? tvheadend_webroot : "");

htsbuf_qprintf(&hc->hc_reply, "</BODY></HTML>\r\n");

Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/http.h
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/webui/simpleui.c
Expand Up @@ -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;
}

Expand Down
21 changes: 9 additions & 12 deletions src/webui/webui.c
Expand Up @@ -128,9 +128,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;
}
Expand All @@ -139,10 +139,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;
}

Expand All @@ -152,7 +149,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;
Expand All @@ -166,7 +163,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");
Expand Down Expand Up @@ -887,7 +884,7 @@ page_http_playlist(http_connection_t *hc, const char *remain, void *opaque)
if(!remain || *remain == '\0') {
http_redirect(hc, pltype == PLAYLIST_E2 ? "/playlist/e2/channels" :
"/playlist/channels",
&hc->hc_req_args);
&hc->hc_req_args, 0);
return HTTP_STATUS_FOUND;
}

Expand Down Expand Up @@ -1593,7 +1590,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;
}

Expand Down Expand Up @@ -1635,7 +1632,7 @@ http_redir(http_connection_t *hc, const char *remain, void *opaque)
snprintf(buf, sizeof(buf), "src/webui/static/intl/tvh.%s.js.gz", lang);
if (!http_file_test(buf)) {
snprintf(buf, sizeof(buf), "/static/intl/tvh.%s.js.gz", lang);
http_redirect(hc, buf, NULL);
http_redirect(hc, buf, NULL, 0);
return 0;
}
}
Expand All @@ -1655,7 +1652,7 @@ http_redir(http_connection_t *hc, const char *remain, void *opaque)
if (http_file_test(buf)) lang = "en";
snprintf(buf, sizeof(buf), "/docs/%s/%s%s%s", lang, components[1],
nc > 2 ? "/" : "", nc > 2 ? components[1] : "");
http_redirect(hc, buf, NULL);
http_redirect(hc, buf, NULL, 0);
return 0;
}
}
Expand Down

0 comments on commit d1def08

Please sign in to comment.