]> git.sesse.net Git - vlc/commitdiff
Add a libdsm based service discovery module to find CIFS speaking host on LAN
authorJulien 'Lta' BALLET <contact@lta.io>
Wed, 2 Jul 2014 11:58:40 +0000 (11:58 +0000)
committerJean-Baptiste Kempf <jb@videolan.org>
Fri, 4 Jul 2014 18:10:56 +0000 (20:10 +0200)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
NEWS
modules/access/Makefile.am
modules/access/dsm/access.c
modules/access/dsm/common.h
modules/access/dsm/sd.c [new file with mode: 0644]
modules/services_discovery/Makefile.am

diff --git a/NEWS b/NEWS
index 6c6a745743cce381111269542f739fb172bb5522..759efce79330ecc72507172d258d608b7bb102ff 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,10 @@ Access:
  * Support HDS (Http Dynamic Streaming) from Adobe (f4m, f4v, etc.)
  * New SMB access module using libdsm
 
+Service Discovery:
+ * New NetBios service discovery using libdsm
+
+
 Changes between 2.1.x and 2.2.0:
 --------------------------------
 
index 1f7b3fdffeb78684f5a66e88211830a738eb9ae8..efc0ae68771b1e0c4b84f798462491802e942690 100644 (file)
@@ -387,7 +387,7 @@ access_LTLIBRARIES += $(LTLIBsmb)
 EXTRA_LTLIBRARIES += libsmb_plugin.la
 
 libdsm_plugin_la_SOURCES = access/dsm/access.c access/dsm/common.h \
-       access/bdsm/browser.c
+       access/bdsm/browser.c access/bdsm/sd.c
 libdsm_plugin_la_CFLAGS = $(AM_CFLAGS) $(DSM_CFLAGS)
 libdsm_plugin_la_LIBADD = $(DSM_LIBS)
 libdsm_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(sddir)'
index 3b23f1dffd7f2ed3ee99b6d53189d0288fa4a8b0..6269b7739cc29b408774e1e34576f05aacfba3dd 100644 (file)
@@ -69,6 +69,15 @@ vlc_module_begin ()
     add_string( "smb-domain", NULL, DOMAIN_TEXT, DOMAIN_LONGTEXT, false )
     add_shortcut( "smb", "cifs" )
     set_callbacks( Open, Close )
+
+    add_submodule()
+        set_category( CAT_PLAYLIST )
+        set_subcategory( SUBCAT_PLAYLIST_SD )
+        set_capability( "services_discovery", 0 )
+        set_callbacks( SdOpen, SdClose )
+
+        VLC_SD_PROBE_SUBMODULE
+
 vlc_module_end ()
 
 /*****************************************************************************
index 7b61d9f7af5aac6444c7973a47c6c18af39eb5b5..cae5ab7e7947b6d0da9e0d8fedb843af17169f0c 100644 (file)
 int Open( vlc_object_t * );
 void Close( vlc_object_t * );
 
+int SdOpen( vlc_object_t * );
+void SdClose( vlc_object_t * );
+int vlc_sd_probe_Open( vlc_object_t * );
+
 int BrowserInit( access_t *p_access );
 
 struct access_sys_t
diff --git a/modules/access/dsm/sd.c b/modules/access/dsm/sd.c
new file mode 100644 (file)
index 0000000..ad2c5a0
--- /dev/null
@@ -0,0 +1,111 @@
+/**
+ * @file bdsm/sd.c
+ * @brief List host supporting NETBIOS on the local network
+ */
+/*****************************************************************************
+ * Copyright © 2014 Authors and the VideoLAN team
+ *
+ * Authors: - Julien 'Lta' BALLET <contact # lta 'dot' io>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "common.h"
+
+struct services_discovery_sys_t
+{
+    netbios_ns      *ns;
+};
+
+int vlc_sd_probe_Open (vlc_object_t *p_this)
+{
+    vlc_probe_t *p_probe = (vlc_probe_t *)p_this;
+
+    vlc_sd_probe_Add( p_probe, "dsm{longname=\"Windows networks\"}",
+                      N_( "Windows networks" ), SD_CAT_LAN );
+
+    return VLC_PROBE_CONTINUE;
+}
+
+int SdOpen (vlc_object_t *p_this)
+{
+    services_discovery_t *p_sd = (services_discovery_t *)p_this;
+    services_discovery_sys_t *p_sys = malloc (sizeof (*p_sys));
+
+    if( p_sys == NULL )
+        return VLC_ENOMEM;
+    p_sd->p_sys = p_sys;
+
+    /* Let's create a NETBIOS name service object */
+    p_sys->ns = netbios_ns_new();
+    if( p_sys->ns == NULL )
+        goto error;
+
+    if( !netbios_ns_discover( p_sys->ns ) )
+        goto error;
+
+    for( ssize_t i = 0; i < netbios_ns_entry_count( p_sys->ns ); i++ )
+    {
+        netbios_ns_entry *p_entry = netbios_ns_entry_at( p_sys->ns, i );
+
+        if( p_entry->type == 0x20 )
+        {
+            input_item_t *p_item;
+            char *psz_mrl;
+
+            if( asprintf(&psz_mrl, "smb://%s", p_entry->name) < 0 )
+                goto error;
+
+            p_item = input_item_NewWithType( psz_mrl, p_entry->name, 0, NULL,
+                                             0, -1, ITEM_TYPE_NODE );
+            msg_Dbg( p_sd, "Adding item %s", psz_mrl );
+
+            services_discovery_AddItem( p_sd, p_item, NULL );
+
+            free( psz_mrl );
+        }
+    }
+
+    return VLC_SUCCESS;
+
+    error:
+        if( p_sys->ns != NULL )
+            netbios_ns_destroy( p_sys->ns );
+        free( p_sys );
+        p_sd->p_sys = NULL;
+
+        return VLC_EGENERIC;
+}
+
+void SdClose (vlc_object_t *p_this)
+{
+    services_discovery_t *sd = (services_discovery_t *)p_this;
+    services_discovery_sys_t *p_sys = sd->p_sys;
+
+    if( p_sys == NULL )
+        return;
+
+    if( p_sys->ns != NULL )
+        netbios_ns_destroy( p_sys->ns );
+}
+
index 11fca94cb33da463ec7ce67cd65c28a633689c38..b526338946e2629e5649cc87b1567f6897fcf514 100644 (file)
@@ -68,3 +68,5 @@ libos2drive_plugin_la_SOURCES = services_discovery/os2drive.c
 if HAVE_OS2
 sd_LTLIBRARIES += libos2drive_plugin.la
 endif
+
+sd_LTLIBRARIES += $(LTLIBdsm)