From 2b0e495b7bdf908389a9b1214a7ee1798092e6a1 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Tue, 1 Jan 2013 09:05:37 +0000 Subject: [PATCH] webui: simplification of the tvheadend_webroot processing. --- src/http.c | 8 ++------ src/main.c | 14 ++++++++++++-- src/tvheadend.h | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/http.c b/src/http.c index 7610adf1..dee8e1f8 100644 --- a/src/http.c +++ b/src/http.c @@ -607,16 +607,12 @@ http_path_add(const char *path, void *opaque, http_callback_t *callback, uint32_t accessmask) { http_path_t *hp = malloc(sizeof(http_path_t)); + char *tmp; if (tvheadend_webroot) { - char *tmp; const char *pre = ""; size_t len = strlen(tvheadend_webroot) + strlen(path) + 1; - if (*tvheadend_webroot != '/') { - len++; - pre = "/"; - } hp->hp_path = tmp = malloc(len); - sprintf(tmp, "%s%s%s", pre, tvheadend_webroot, path); + sprintf(tmp, "%s/%s", tvheadend_webroot, path); } else hp->hp_path = strdup(path); hp->hp_len = strlen(hp->hp_path); diff --git a/src/main.c b/src/main.c index baae957c..73afb075 100644 --- a/src/main.c +++ b/src/main.c @@ -76,7 +76,7 @@ int log_debug_to_console; int webui_port; int htsp_port; int htsp_port_extra; -char *tvheadend_cwd; +const char *tvheadend_cwd; const char *tvheadend_webroot; const char *tvheadend_capabilities[] = { @@ -270,6 +270,7 @@ main(int argc, char **argv) const char *pidpath = "/var/run/tvheadend.pid"; struct group *grp; struct passwd *pw; + char *webroot; const char *usernam = NULL; const char *groupnam = NULL; int logfacility = LOG_DAEMON; @@ -369,7 +370,16 @@ main(int argc, char **argv) join_transport = optarg; break; case 'W': - tvheadend_webroot = optarg; + webroot = malloc(strlen(optarg) + (*optarg == '/' ? 0 : 1)); + if (*optarg != '/') { + *webroot = '/'; + strcpy(webroot+1, optarg); + } else { + strcpy(webroot, optarg); + } + if (webroot[strlen(webroot)-1] == '/') + webroot[strlen(webroot)-1] = '\0'; + tvheadend_webroot = webroot; break; default: usage(argv[0]); diff --git a/src/tvheadend.h b/src/tvheadend.h index a601f80e..9bdaf1f2 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -35,7 +35,7 @@ #include "redblack.h" extern const char *tvheadend_version; -extern char *tvheadend_cwd; +extern const char *tvheadend_cwd; extern const char *tvheadend_capabilities[]; extern const char *tvheadend_webroot;