From 9e854347fa3318a51148d78e89d1936ffebe11f4 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Sat, 5 Jan 2013 15:27:39 +0000 Subject: [PATCH] Minor addition to the way the server capabilities are checked. --- src/htsp_server.c | 12 ++++-------- src/main.c | 13 ++++++------- src/tvheadend.h | 28 ++++++++++++++++++++++++---- src/webui/extjs.c | 8 +------- 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/htsp_server.c b/src/htsp_server.c index dece14a59..4b6ab6a30 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -695,10 +695,9 @@ htsp_build_event static htsmsg_t * htsp_method_hello(htsp_connection_t *htsp, htsmsg_t *in) { - htsmsg_t *l, *r = htsmsg_create_map(); + htsmsg_t *r; uint32_t v; const char *name; - int i = 0; if(htsmsg_get_u32(in, "htspversion", &v)) return htsp_error("Missing argument 'htspversion'"); @@ -706,6 +705,8 @@ htsp_method_hello(htsp_connection_t *htsp, htsmsg_t *in) if((name = htsmsg_get_str(in, "clientname")) == NULL) return htsp_error("Missing argument 'clientname'"); + r = htsmsg_create_map(); + tvh_str_update(&htsp->htsp_clientname, htsmsg_get_str(in, "clientname")); tvhlog(LOG_INFO, "htsp", "%s: Welcomed client software: %s (HTSPv%d)", @@ -717,12 +718,7 @@ htsp_method_hello(htsp_connection_t *htsp, htsmsg_t *in) htsmsg_add_bin(r, "challenge", htsp->htsp_challenge, 32); /* Capabilities */ - l = htsmsg_create_list(); - while (tvheadend_capabilities[i]) { - htsmsg_add_str(l, NULL, tvheadend_capabilities[i]); - i++; - } - htsmsg_add_msg(r, "servercapability", l); + htsmsg_add_msg(r, "servercapability", tvheadend_capabilities_list(1)); /* Set version to lowest num */ htsp->htsp_version = MIN(HTSP_PROTO_VERSION, v); diff --git a/src/main.c b/src/main.c index d56c63cb8..704f6e4b4 100644 --- a/src/main.c +++ b/src/main.c @@ -79,21 +79,20 @@ int htsp_port; int htsp_port_extra; const char *tvheadend_cwd; const char *tvheadend_webroot; - -const char *tvheadend_capabilities[] = { +const tvh_caps_t tvheadend_capabilities[] = { #if ENABLE_CWC - "cwc", + { "cwc", NULL }, #endif #if ENABLE_V4L - "v4l", + { "v4l", NULL }, #endif #if ENABLE_LINUXDVB - "linuxdvb", + { "linuxdvb", NULL }, #endif #if ENABLE_IMAGECACHE - "imagecache", + { "imagecache", &imagecache_enabled }, #endif - NULL + { NULL, NULL } }; static void diff --git a/src/tvheadend.h b/src/tvheadend.h index 9bdaf1f24..b5d54c47e 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -31,13 +31,32 @@ #include "queue.h" #include "avg.h" #include "hts_strtab.h" +#include "htsmsg.h" #include "redblack.h" -extern const char *tvheadend_version; -extern const char *tvheadend_cwd; -extern const char *tvheadend_capabilities[]; -extern const char *tvheadend_webroot; +typedef struct { + const char *name; + const uint32_t *enabled; +} tvh_caps_t; +extern const char *tvheadend_version; +extern const char *tvheadend_cwd; +extern const char *tvheadend_webroot; +extern const tvh_caps_t tvheadend_capabilities[]; + +static inline htsmsg_t *tvheadend_capabilities_list(int check) +{ + int i = 0; + htsmsg_t *r = htsmsg_create_list(); + while (tvheadend_capabilities[i].name) { + if (!check || + !tvheadend_capabilities[i].enabled || + *tvheadend_capabilities[i].enabled) + htsmsg_add_str(r, NULL, tvheadend_capabilities[i].name); + i++; + } + return r; +} #define PTS_UNSET INT64_C(0x8000000000000000) @@ -369,6 +388,7 @@ static inline unsigned int tvh_strhash(const char *s, unsigned int mod) #define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MAX(a,b) ((a) > (b) ? (a) : (b)) +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) void tvh_str_set(char **strp, const char *src); int tvh_str_update(char **strp, const char *src); diff --git a/src/webui/extjs.c b/src/webui/extjs.c index 1fc3a8bfd..deca304b4 100644 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -1986,13 +1986,7 @@ static int extjs_capabilities(http_connection_t *hc, const char *remain, void *opaque) { htsbuf_queue_t *hq = &hc->hc_reply; - htsmsg_t *l; - int i = 0; - l = htsmsg_create_list(); - while (tvheadend_capabilities[i]) { - htsmsg_add_str(l, NULL, tvheadend_capabilities[i]); - i++; - } + htsmsg_t *l = tvheadend_capabilities_list(0); htsmsg_json_serialize(l, hq, 0); htsmsg_destroy(l); http_output_content(hc, "text/x-json; charset=UTF-8"); -- 2.47.2