From: Damjan Marion Date: Sun, 31 May 2015 15:21:36 +0000 (+0200) Subject: config: make server name configureable (avahi, satips) X-Git-Tag: v4.2.1~2384 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=057a006c91ce6d2acd4bde03ea06ae62a36eb9e3;p=thirdparty%2Ftvheadend.git config: make server name configureable (avahi, satips) --- diff --git a/src/avahi.c b/src/avahi.c index 4cd000de9..43dba8b40 100644 --- a/src/avahi.c +++ b/src/avahi.c @@ -52,11 +52,13 @@ #include "tvheadend.h" #include "avahi.h" +#include "config.h" static AvahiEntryGroup *group = NULL; static char *name = NULL; static AvahiSimplePoll *avahi_asp = NULL; static const AvahiPoll *avahi_poll = NULL; +static int avahi_do_restart = 0; static void create_services(AvahiClient *c); @@ -261,20 +263,34 @@ avahi_thread(void *aux) AvahiClient *ac; char *name2; - name = name2 = avahi_strdup("Tvheadend"); + do { + if (avahi_poll) + avahi_simple_poll_free((AvahiSimplePoll *)avahi_poll); - ac = avahi_client_new(avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, NULL, NULL); - - while(avahi_simple_poll_iterate(avahi_asp, -1) == 0); + avahi_asp = avahi_simple_poll_new(); + avahi_poll = avahi_simple_poll_get(avahi_asp); - avahi_client_free(ac); + if(avahi_do_restart) { + tvhlog(LOG_INFO, "AVAHI", "Service restarted."); + avahi_do_restart = 0; + group = NULL; + } - name = NULL; - free(name2); + name = name2 = avahi_strdup(config_get_server_name()); - return NULL; - + ac = avahi_client_new(avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, NULL, NULL); + + while((avahi_do_restart == 0) && + (avahi_simple_poll_iterate(avahi_asp, -1) == 0)); + + avahi_client_free(ac); + + name = NULL; + free(name2); + + } while (tvheadend_running && avahi_do_restart); + return NULL; } /** @@ -285,8 +301,6 @@ pthread_t avahi_tid; void avahi_init(void) { - avahi_asp = avahi_simple_poll_new(); - avahi_poll = avahi_simple_poll_get(avahi_asp); tvhthread_create(&avahi_tid, NULL, avahi_thread, NULL); } @@ -298,3 +312,10 @@ avahi_done(void) pthread_join(avahi_tid, NULL); avahi_simple_poll_free((AvahiSimplePoll *)avahi_poll); } + +void +avahi_restart(void) +{ + avahi_do_restart = 1; + avahi_simple_poll_quit(avahi_asp); +} diff --git a/src/avahi.h b/src/avahi.h index ca10aa01d..0aa0a2cd7 100644 --- a/src/avahi.h +++ b/src/avahi.h @@ -1,7 +1,9 @@ #ifdef CONFIG_AVAHI void avahi_init(void); void avahi_done(void); +void avahi_restart(void); #else static inline void avahi_init(void) { } static inline void avahi_done(void) { } +static inline void avahi_restart(void) {} #endif diff --git a/src/config.c b/src/config.c index 0de63576a..e3b4472bd 100644 --- a/src/config.c +++ b/src/config.c @@ -28,6 +28,7 @@ #include "spawn.h" #include "lock.h" #include "profile.h" +#include "avahi.h" /* ************************************************************************* * Global data @@ -1520,6 +1521,7 @@ config_init ( int backup ) if (config_newcfg) { htsmsg_set_u32(config, "version", ARRAY_SIZE(config_migrate_table)); htsmsg_set_str(config, "fullversion", tvheadend_version); + htsmsg_set_str(config, "server_name", "Tvheadend"); config_save(); /* Perform migrations */ @@ -1589,6 +1591,21 @@ config_set_int ( const char *fld, int val ) return 0; } +const char *config_get_server_name ( void ) +{ + const char *s = htsmsg_get_str(config, "server_name"); + if (s == NULL || *s == '\0') + return "Tvheadend"; + return s; +} + +int config_set_server_name ( const char *name ) +{ + int r = config_set_str("server_name", name); + avahi_restart(); + return r; +} + const char *config_get_language ( void ) { const char *s = htsmsg_get_str(config, "language"); diff --git a/src/config.h b/src/config.h index 3add6b9ce..5c3c78da5 100644 --- a/src/config.h +++ b/src/config.h @@ -36,6 +36,10 @@ int config_set_str ( const char *fld, const char *val ); int config_get_int ( const char *fld, int dflt ); int config_set_int ( const char *fld, int val ); +const char *config_get_server_name ( void ); +int config_set_server_name ( const char *str ) + __attribute__((warn_unused_result)); + const char *config_get_muxconfpath ( void ); int config_set_muxconfpath ( const char *str ) __attribute__((warn_unused_result)); diff --git a/src/satip/server.c b/src/satip/server.c index 62ea07277..5ca1152b0 100644 --- a/src/satip/server.c +++ b/src/satip/server.c @@ -61,7 +61,7 @@ satip_server_http_xml(http_connection_t *hc) 11\n\ \n\ urn:ses-com:device:SatIPServer:1\n\ -TVHeadend%s\n\ +%s%s\n\ TVHeadend Team\n\ http://tvheadend.org\n\ TVHeadend %s\n\ @@ -172,6 +172,7 @@ satip_server_http_xml(http_connection_t *hc) snprintf(buf2, sizeof(buf2), " %s", satip_server_uuid + 26); snprintf(buf, sizeof(buf), MSG, + config_get_server_name(), buf2, tvheadend_version, satip_server_uuid, http_server_ip, http_server_port, diff --git a/src/webui/extjs.c b/src/webui/extjs.c index 45206dcd8..f0b033278 100644 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -478,6 +478,8 @@ extjs_config(http_connection_t *hc, const char *remain, void *opaque) /* Misc settings */ pthread_mutex_lock(&global_lock); + if ((str = http_arg_get(&hc->hc_req_args, "server_name"))) + save |= config_set_server_name(str); if ((str = http_arg_get(&hc->hc_req_args, "muxconfpath"))) save |= config_set_muxconfpath(str); if ((str = http_arg_get(&hc->hc_req_args, "language"))) diff --git a/src/webui/static/app/config.js b/src/webui/static/app/config.js index b4c120a6a..ecbabe20d 100644 --- a/src/webui/static/app/config.js +++ b/src/webui/static/app/config.js @@ -41,7 +41,7 @@ tvheadend.miscconf = function(panel, index) { root: 'config' }, [ - 'muxconfpath', 'language', + 'server_name', 'muxconfpath', 'language', 'tvhtime_update_enabled', 'tvhtime_ntp_enabled', 'tvhtime_tolerance', 'prefer_picon', 'chiconpath', 'piconpath', @@ -58,6 +58,22 @@ tvheadend.miscconf = function(panel, index) { * DVB path */ + var serverName = new Ext.form.TextField({ + fieldLabel: 'Tvheadend server name', + name: 'server_name', + allowBlank: true, + width: 400 + }); + + var serverWrap = new Ext.form.FieldSet({ + title: 'Server', + width: 700, + autoHeight: true, + collapsible: true, + animCollapse: true, + items : [ serverName ] + }); + var dvbscanPath = new Ext.form.TextField({ fieldLabel: 'DVB scan files path', name: 'muxconfpath', @@ -322,7 +338,7 @@ tvheadend.miscconf = function(panel, index) { } }); - var _items = [languageWrap, dvbscanWrap, tvhtimePanel, piconPanel]; + var _items = [serverWrap, languageWrap, dvbscanWrap, tvhtimePanel, piconPanel]; if (satipPanel) _items.push(satipPanel);