webui: simplification of the tvheadend_webroot processing.

This commit is contained in:
Adam Sutton 2013-01-01 09:05:37 +00:00
parent 2488fe70b3
commit 2b0e495b7b
3 changed files with 15 additions and 9 deletions

View file

@ -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);

View file

@ -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]);

View file

@ -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;