From: Jaroslav Kysela Date: Wed, 29 Nov 2017 09:43:03 +0000 (+0100) Subject: allow to disable http/htsp servers (set TCP port to zero), fixes #4734 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4e3359a2d018e075a7372a6a533b0bdf79dcaef4;p=thirdparty%2Ftvheadend.git allow to disable http/htsp servers (set TCP port to zero), fixes #4734 From: Mono Polimorph --- diff --git a/src/avahi.c b/src/avahi.c index 64be54178..2b65cf101 100644 --- a/src/avahi.c +++ b/src/avahi.c @@ -62,6 +62,12 @@ static int avahi_do_restart = 0; static void create_services(AvahiClient *c); +static inline int +avahi_required(void) +{ + return http_webui_port > 0 || tvheadend_htsp_port > 0; +} + static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) @@ -123,7 +129,7 @@ create_services(AvahiClient *c) if (!group) if (!(group = avahi_entry_group_new(c, entry_group_callback, NULL))) { tvherror(LS_AVAHI, - "avahi_enty_group_new() failed: %s", + "avahi_entry_group_new() failed: %s", avahi_strerror(avahi_client_errno(c))); goto fail; } @@ -135,47 +141,52 @@ create_services(AvahiClient *c) tvhdebug(LS_AVAHI, "Adding service '%s'", name); /* Add the service for HTSP */ - if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, - AVAHI_PROTO_UNSPEC, 0, name, - "_htsp._tcp", NULL, NULL,tvheadend_htsp_port, - NULL)) < 0) { - - if (ret == AVAHI_ERR_COLLISION) - goto collision; - - tvherror(LS_AVAHI, - "Failed to add _htsp._tcp service: %s", - avahi_strerror(ret)); - goto fail; - } - - if (tvheadend_webroot) { - path = malloc(strlen(tvheadend_webroot) + 6); - sprintf(path, "path=%s", tvheadend_webroot); - } else { - path = strdup("path=/"); + if (tvheadend_htsp_port > 0) { + if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, + AVAHI_PROTO_UNSPEC, 0, name, + "_htsp._tcp", NULL, NULL, + tvheadend_htsp_port, + NULL)) < 0) { + + if (ret == AVAHI_ERR_COLLISION) + goto collision; + + tvherror(LS_AVAHI, + "Failed to add _htsp._tcp service: %s", + avahi_strerror(ret)); + goto fail; + } } /* Add the service for HTTP */ - if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, - AVAHI_PROTO_UNSPEC, 0, name, - "_http._tcp", NULL, NULL, tvheadend_webui_port, - path, - NULL)) < 0) { - - if (ret == AVAHI_ERR_COLLISION) - goto collision; - - tvherror(LS_AVAHI, - "Failed to add _http._tcp service: %s", - avahi_strerror(ret)); - goto fail; + if (tvheadend_webui_port > 0) { + if (tvheadend_webroot) { + path = malloc(strlen(tvheadend_webroot) + 6); + sprintf(path, "path=%s", tvheadend_webroot); + } else { + path = strdup("path=/"); + } + + if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, + AVAHI_PROTO_UNSPEC, 0, name, + "_http._tcp", NULL, NULL, tvheadend_webui_port, + path, + NULL)) < 0) { + + if (ret == AVAHI_ERR_COLLISION) + goto collision; + + tvherror(LS_AVAHI, + "Failed to add _http._tcp service: %s", + avahi_strerror(ret)); + goto fail; + } } /* Tell the server to register the service */ if ((ret = avahi_entry_group_commit(group)) < 0) { tvherror(LS_AVAHI, - "Failed to commit entry group: %s", + "Failed to commit entry group: %s", avahi_strerror(ret)); goto fail; } @@ -299,12 +310,16 @@ pthread_t avahi_tid; void avahi_init(void) { + if (!avahi_required()) + return; tvhthread_create(&avahi_tid, NULL, avahi_thread, NULL, "avahi"); } void avahi_done(void) { + if (!avahi_required()) + return; avahi_simple_poll_quit(avahi_asp); pthread_kill(avahi_tid, SIGTERM); pthread_join(avahi_tid, NULL); @@ -314,6 +329,8 @@ avahi_done(void) void avahi_restart(void) { + if (!avahi_required()) + return; avahi_do_restart = 1; avahi_simple_poll_quit(avahi_asp); } diff --git a/src/bonjour.c b/src/bonjour.c index 5e4eb0f50..e6e48315e 100644 --- a/src/bonjour.c +++ b/src/bonjour.c @@ -33,6 +33,12 @@ typedef struct { pthread_t bonjour_tid; CFNetServiceRef svc_http, svc_htsp; +static inline int +bonjour_required(void) +{ + return http_webui_port > 0 || tvheadend_htsp_port > 0; +} + static void bonjour_callback(CFNetServiceRef theService, CFStreamError* error, void* info) { @@ -107,7 +113,9 @@ bonjour_init(void) { "path", tvheadend_webroot ? tvheadend_webroot : "/" }, { .key = NULL } }; - + + if (!bonjour_required()) + return; bonjour_start_service(&svc_http, "_http._tcp", tvheadend_webui_port, txt_rec_http); @@ -117,6 +125,8 @@ bonjour_init(void) void bonjour_done(void) { + if (!bonjour_required()) + return; bonjour_stop_service(&svc_http); bonjour_stop_service(&svc_htsp); } diff --git a/src/htsp_server.c b/src/htsp_server.c index cd8a9735e..342ee68cb 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -3495,8 +3495,9 @@ htsp_init(const char *bindaddr) .stop = NULL, .cancel = htsp_server_cancel }; - htsp_server = tcp_server_create(LS_HTSP, "HTSP", bindaddr, tvheadend_htsp_port, &ops, NULL); - if(tvheadend_htsp_port_extra) + if (tvheadend_htsp_port > 0) + htsp_server = tcp_server_create(LS_HTSP, "HTSP", bindaddr, tvheadend_htsp_port, &ops, NULL); + if (tvheadend_htsp_port_extra > 0) htsp_server_2 = tcp_server_create(LS_HTSP, "HTSP2", bindaddr, tvheadend_htsp_port_extra, &ops, NULL); } @@ -3506,7 +3507,8 @@ htsp_init(const char *bindaddr) void htsp_register(void) { - tcp_server_register(htsp_server); + if (htsp_server) + tcp_server_register(htsp_server); if (htsp_server_2) tcp_server_register(htsp_server_2); } diff --git a/src/http.c b/src/http.c index 3c8d95a0e..a298ba776 100644 --- a/src/http.c +++ b/src/http.c @@ -1993,8 +1993,10 @@ http_server_init(const char *bindaddr) .cancel = http_cancel }; RB_INIT(&http_nonces); - http_server = tcp_server_create(LS_HTTP, "HTTP", bindaddr, tvheadend_webui_port, &ops, NULL); - atomic_set(&http_server_running, 1); + if (tvheadend_webui_port > 0) { + http_server = tcp_server_create(LS_HTTP, "HTTP", bindaddr, tvheadend_webui_port, &ops, NULL); + atomic_set(&http_server_running, 1); + } } void