]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
SAT>IP: Add --satip_xml option to reach tuners behind routers or local blocked UPnP...
authorJaroslav Kysela <perex@perex.cz>
Wed, 23 Apr 2014 18:55:28 +0000 (20:55 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 5 May 2014 20:00:38 +0000 (22:00 +0200)
src/input/mpegts.c
src/input/mpegts.h
src/input/mpegts/satip/satip.c
src/input/mpegts/satip/satip.h
src/main.c

index 51117107bf19daf072eaeaa6a32cb55e22f7186f..87d341a4d8e81da9dabe3e6445fc5a4cca90a536 100644 (file)
@@ -19,7 +19,8 @@
 #include "input.h"
 
 void
-mpegts_init ( int linuxdvb_mask, str_list_t *tsfiles, int tstuners )
+mpegts_init ( int linuxdvb_mask, str_list_t *satip_client,
+              str_list_t *tsfiles, int tstuners )
 {
   /* Register classes (avoid API 400 errors due to not yet defined) */
   idclass_register(&mpegts_network_class);
@@ -53,7 +54,7 @@ mpegts_init ( int linuxdvb_mask, str_list_t *tsfiles, int tstuners )
 
   /* SAT>IP DVB client */
 #if ENABLE_SATIP_CLIENT
-  satip_init();
+  satip_init(satip_client);
 #endif
 
   /* Mux schedulers */
index 85493faaa4708c98e1c4275abb8d307f5295af42..ffc0fe1ca0f8d970a8d658f22aefbc06eeafb65d 100644 (file)
@@ -68,7 +68,8 @@ extern const idclass_t mpegts_input_class;
  * Setup / Tear down
  * *************************************************************************/
 
-void mpegts_init ( int linuxdvb_mask, str_list_t *tsfiles, int tstuners );
+void mpegts_init ( int linuxdvb_mask, str_list_t *satip_client,
+                   str_list_t *tsfiles, int tstuners );
 void mpegts_done ( void );
 
 /* **************************************************************************
index 9a238543314e80e1caa676bb478c639128689569..313ed747c7eea01451f5bd40c899531e3414cf17 100644 (file)
@@ -390,6 +390,19 @@ satip_device_find( const char *satip_uuid )
   return NULL;
 }
 
+static satip_device_t *
+satip_device_find_by_descurl( const char *descurl )
+{
+  tvh_hardware_t *th;
+
+  TVH_HARDWARE_FOREACH(th) {
+    if (idnode_is_instance(&th->th_id, &satip_device_class) &&
+        strcmp(((satip_device_t *)th)->sd_info.location, descurl) == 0)
+      return (satip_device_t *)th;
+  }
+  return NULL;
+}
+
 void
 satip_device_save( satip_device_t *sd )
 {
@@ -483,6 +496,7 @@ static struct satip_discovery_queue satip_discoveries;
 static upnp_service_t *satip_discovery_service;
 static gtimer_t satip_discovery_timer;
 static gtimer_t satip_discovery_timerq;
+static str_list_t *satip_static_clients;
 
 static void
 satip_discovery_destroy(satip_discovery_t *d, int unlink)
@@ -525,10 +539,12 @@ satip_discovery_http_closed(http_client_t *hc, int errn)
   htsmsg_t *xml = NULL, *tags, *root, *device;
   const char *friendlyname, *manufacturer, *manufacturerURL, *modeldesc;
   const char *modelname, *modelnum, *serialnum;
-  const char *presentation, *tunercfg;
+  const char *presentation, *tunercfg, *udn, *uuid;
   const char *cs;
   satip_device_info_t info;
   char errbuf[100];
+  char *argv[10];
+  int i, n;
 
   s = http_arg_get(&hc->hc_args, "Content-Type");
   if (s && strcasecmp(s, "text/xml")) {
@@ -590,11 +606,24 @@ satip_discovery_http_closed(http_client_t *hc, int errn)
     goto finish;
   if ((presentation = htsmsg_xml_get_cdata_str(device, "presentationURL")) == NULL)
     goto finish;
+  if ((udn          = htsmsg_xml_get_cdata_str(device, "UDN")) == NULL)
+    goto finish;
   if ((tunercfg     = htsmsg_xml_get_cdata_str(device, "urn:ses-com:satipX_SATIPCAP")) == NULL)
     goto finish;
+
+  uuid = NULL;
+  n = http_tokenize((char *)udn, argv, ARRAY_SIZE(argv), ':');
+  for (i = 0; i < n+1; i++)
+    if (argv[i] && strcmp(argv[i], "uuid") == 0) {
+      uuid = argv[++i];
+      break;
+    }
+  if (uuid == NULL || (d->uuid[0] && strcmp(uuid, d->uuid)))
+    goto finish;
+
   info.myaddr = strdup(d->myaddr);
   info.addr = strdup(d->url.host);
-  info.uuid = strdup(d->uuid);
+  info.uuid = strdup(uuid);
   info.bootid = strdup(d->bootid);
   info.configid = strdup(d->configid);
   info.deviceid = strdup(d->deviceid);
@@ -732,7 +761,7 @@ satip_discovery_service_received
       else if (strcmp(argv[0], "DEVICEID.SES.COM:") == 0)
         deviceid = argv[1];
       else if (strcmp(argv[0], "USN:") == 0) {
-        n = http_tokenize(argv[1], argv, 10, ':');
+        n = http_tokenize(argv[1], argv, ARRAY_SIZE(argv), ':');
         for (i = 0; i < n+1; i++)
           if (argv[i] && strcmp(argv[i], "uuid") == 0) {
             uuid = argv[++i];
@@ -785,6 +814,32 @@ satip_discovery_service_received
     satip_discovery_destroy(d, 0);
 }
 
+static void
+satip_discovery_static(const char *descurl)
+{
+  satip_discovery_t *d;
+
+  lock_assert(&global_lock);
+
+  if (satip_device_find_by_descurl(descurl))
+    return;
+  d = calloc(1, sizeof(satip_discovery_t));
+  if (urlparse(descurl, &d->url)) {
+    satip_discovery_destroy(d, 0);
+    return;
+  }
+  d->myaddr   = strdup(d->url.host);
+  d->location = strdup(descurl);
+  d->server   = strdup("");
+  d->uuid     = strdup("");
+  d->bootid   = strdup("");
+  d->configid = strdup("");
+  d->deviceid = strdup("");
+  TAILQ_INSERT_TAIL(&satip_discoveries, d, disc_link);
+  satip_discoveries_count++;
+  satip_discovery_timerq_cb(NULL);
+}
+
 static void
 satip_discovery_service_destroy(upnp_service_t *us)
 {
@@ -801,7 +856,7 @@ MAN: \"ssdp:discover\"\r\n\
 MX: 2\r\n\
 ST: urn:ses-com:device:SatIPServer:1\r\n\
 \r\n"
-  htsbuf_queue_t q;
+  int i;
 
   if (!tvheadend_running)
     return;
@@ -811,13 +866,20 @@ ST: urn:ses-com:device:SatIPServer:1\r\n\
   }
   if (satip_discovery_service == NULL) {
     satip_discovery_service              = upnp_service_create(upnp_service);
-    satip_discovery_service->us_received = satip_discovery_service_received;
-    satip_discovery_service->us_destroy  = satip_discovery_service_destroy;
+    if (satip_discovery_service) {
+      satip_discovery_service->us_received = satip_discovery_service_received;
+      satip_discovery_service->us_destroy  = satip_discovery_service_destroy;
+    }
+  }
+  if (satip_discovery_service) {
+    htsbuf_queue_t q;
+    htsbuf_queue_init(&q, 0);
+    htsbuf_append(&q, MSG, sizeof(MSG)-1);
+    upnp_send(&q, NULL);
+    htsbuf_queue_flush(&q);
   }
-  htsbuf_queue_init(&q, 0);
-  htsbuf_append(&q, MSG, sizeof(MSG)-1);
-  upnp_send(&q, NULL);
-  htsbuf_queue_flush(&q); 
+  for (i = 0; i < satip_static_clients->num; i++)
+    satip_discovery_static(satip_static_clients->str[i]);
   gtimer_arm(&satip_discovery_timer, satip_discovery_timer_cb, NULL, 3600);
 #undef MSG
 }
@@ -832,9 +894,10 @@ satip_device_discovery_start( void )
  * Initialization
  */
 
-void satip_init ( void )
+void satip_init ( str_list_t *clients )
 {
   TAILQ_INIT(&satip_discoveries);
+  satip_static_clients = clients;
   satip_device_discovery_start();
 }
 
index 6e994c82b9a2daf5e2b22b87da2e58f1338527a0..59d035ebf40c8a7a497e75ea4ca8a568673b411d 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef __TVH_SATIP_H__
 #define __TVH_SATIP_H__
 
-void satip_init( void );
+void satip_init( str_list_t *clients );
 void satip_done( void );
 
 #endif /* __TVH_SATIP_H__ */
index fba0b10ca9c9729a741ef335382e92565cfe83c6..8d4add02f3f56c6f76015897a6ad3e6e01d60c5e 100644 (file)
@@ -476,6 +476,7 @@ main(int argc, char **argv)
 #endif
              *opt_bindaddr     = NULL,
              *opt_subscribe    = NULL;
+  str_list_t  opt_satip_xml    = { .max = 10, .num = 0, .str = calloc(10, sizeof(char*)) };
   str_list_t  opt_tsfile       = { .max = 10, .num = 0, .str = calloc(10, sizeof(char*)) };
   cmdline_opt_t cmdline_opts[] = {
     {   0, NULL,        "Generic Options",         OPT_BOOL, NULL         },
@@ -497,6 +498,10 @@ main(int argc, char **argv)
 #if ENABLE_LINUXDVB
     { 'a', "adapters",  "Only use specified DVB adapters (comma separated)",
       OPT_STR, &opt_dvb_adapters },
+#endif
+#if ENABLE_SATIP_CLIENT
+    {   0, "satip_xml", "URL with the SAT>IP server XML location",
+      OPT_STR_LIST, &opt_satip_xml },
 #endif
     {   0, NULL,         "Server Connectivity",    OPT_BOOL, NULL         },
     { '6', "ipv6",       "Listen on IPv6",         OPT_BOOL, &opt_ipv6    },
@@ -766,7 +771,7 @@ main(int argc, char **argv)
   service_init();
 
 #if ENABLE_MPEGTS
-  mpegts_init(adapter_mask, &opt_tsfile, opt_tsfile_tuner);
+  mpegts_init(adapter_mask, &opt_satip_xml, &opt_tsfile, opt_tsfile_tuner);
 #endif
 
   channel_init();
@@ -881,6 +886,7 @@ main(int argc, char **argv)
     unlink(opt_pidpath);
     
   free(opt_tsfile.str);
+  free(opt_satip_xml.str);
 
   /* OpenSSL - welcome to the "cleanup" hell */
   ENGINE_cleanup();