]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
allow to disable http/htsp servers (set TCP port to zero), fixes #4734
authorJaroslav Kysela <perex@perex.cz>
Wed, 29 Nov 2017 09:43:03 +0000 (10:43 +0100)
committerJaroslav Kysela <perex@perex.cz>
Wed, 29 Nov 2017 09:43:03 +0000 (10:43 +0100)
From: Mono Polimorph

src/avahi.c
src/bonjour.c
src/htsp_server.c
src/http.c

index 64be541784ffdc14cd9446e4ba6abdc7eec21b2c..2b65cf10101951d2e3fa9436364e27022450ad23 100644 (file)
@@ -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);
 }
index 5e4eb0f5003284b411c343b602600a1bd13b3ffc..e6e48315e6f8d7aba1ce7b576d4a52cc888f90e2 100644 (file)
@@ -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);
 }
index cd8a9735e27e9fcd65520c02ef5d9e1e6831c642..342ee68cbf99531ba23b06726e410b097b33c57f 100644 (file)
@@ -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);
 }
index 3c8d95a0e1217a13b7257dcad8ed31d2a0f73018..a298ba776562a3e5a4447d9d5937cff92c1d5696 100644 (file)
@@ -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