3 * @brief List host supporting NETBIOS on the local network
5 /*****************************************************************************
6 * Copyright © 2014 Authors and the VideoLAN team
8 * Authors: - Julien 'Lta' BALLET <contact # lta 'dot' io>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
33 #include <vlc_common.h>
34 #include <vlc_atomic.h>
35 #include <vlc_services_discovery.h>
36 #include <bdsm/bdsm.h>
38 int bdsm_SdOpen( vlc_object_t * );
39 void bdsm_SdClose( vlc_object_t * );
40 int bdsm_sd_probe_Open( vlc_object_t * );
42 struct services_discovery_sys_t
50 int bdsm_sd_probe_Open (vlc_object_t *p_this)
52 vlc_probe_t *p_probe = (vlc_probe_t *)p_this;
54 vlc_sd_probe_Add( p_probe, "dsm{longname=\"Windows networks\"}",
55 N_( "Windows networks" ), SD_CAT_LAN );
57 return VLC_PROBE_CONTINUE;
60 static void *Run( void *data )
62 services_discovery_t *p_sd = data;
63 services_discovery_sys_t *p_sys = p_sd->p_sys;
65 if( !netbios_ns_discover( p_sys->p_ns ) )
68 if (atomic_load(&p_sys->stop))
71 for( ssize_t i = 0; i < netbios_ns_entry_count( p_sys->p_ns ); i++ )
73 netbios_ns_entry *p_entry = netbios_ns_entry_at( p_sys->p_ns, i );
74 char type = netbios_ns_entry_type( p_entry );
80 const char *name = netbios_ns_entry_name( p_entry );
82 if( asprintf(&psz_mrl, "smb://%s", name) < 0 )
85 p_item = input_item_NewWithType( psz_mrl, name, 0, NULL,
86 0, -1, ITEM_TYPE_NODE );
87 msg_Dbg( p_sd, "Adding item %s", psz_mrl );
89 services_discovery_AddItem( p_sd, p_item, NULL );
96 int bdsm_SdOpen (vlc_object_t *p_this)
98 services_discovery_t *p_sd = (services_discovery_t *)p_this;
99 services_discovery_sys_t *p_sys = calloc (1, sizeof (*p_sys));
106 p_sys->p_ns = netbios_ns_new();
107 if( p_sys->p_ns == NULL )
110 atomic_store(&p_sys->stop, false);
112 if( vlc_clone( &p_sys->thread, Run, p_sd, VLC_THREAD_PRIORITY_LOW ) )
121 bdsm_SdClose( p_this );
125 void bdsm_SdClose (vlc_object_t *p_this)
127 services_discovery_t *sd = (services_discovery_t *)p_this;
128 services_discovery_sys_t *p_sys = sd->p_sys;
133 if( p_sys->thread ) {
134 atomic_store(&p_sys->stop, true);
137 netbios_ns_abort( p_sys->p_ns );
138 vlc_join( p_sys->thread, NULL );
141 netbios_ns_destroy( p_sys->p_ns );