Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
config: make server name configureable (avahi, satips)
  • Loading branch information
dmarion authored and perexg committed Jun 2, 2015
1 parent beb8b99 commit 057a006
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 14 deletions.
43 changes: 32 additions & 11 deletions src/avahi.c
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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);
}

Expand All @@ -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);
}
2 changes: 2 additions & 0 deletions 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
17 changes: 17 additions & 0 deletions src/config.c
Expand Up @@ -28,6 +28,7 @@
#include "spawn.h"
#include "lock.h"
#include "profile.h"
#include "avahi.h"

/* *************************************************************************
* Global data
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions src/config.h
Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion src/satip/server.c
Expand Up @@ -61,7 +61,7 @@ satip_server_http_xml(http_connection_t *hc)
<specVersion><major>1</major><minor>1</minor></specVersion>\n\
<device>\n\
<deviceType>urn:ses-com:device:SatIPServer:1</deviceType>\n\
<friendlyName>TVHeadend%s</friendlyName>\n\
<friendlyName>%s%s</friendlyName>\n\
<manufacturer>TVHeadend Team</manufacturer>\n\
<manufacturerURL>http://tvheadend.org</manufacturerURL>\n\
<modelDescription>TVHeadend %s</modelDescription>\n\
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/webui/extjs.c
Expand Up @@ -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")))
Expand Down
20 changes: 18 additions & 2 deletions src/webui/static/app/config.js
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 057a006

Please sign in to comment.