1 /*****************************************************************************
2 * slp.c: SLP access plugin
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: slp.c,v 1.16 2003/09/14 16:41:48 zorglub Exp $
7 * Authors: Loïc Minier <lool@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc */
30 #include <vlc/input.h>
32 #include <vlc_playlist.h>
36 /*****************************************************************************
38 *****************************************************************************/
39 static int Open ( vlc_object_t * );
40 static void Close ( vlc_object_t * );
41 static ssize_t Read ( input_thread_t *, byte_t *, size_t );
43 static int Init ( vlc_object_t * );
44 static void End ( vlc_object_t * );
45 static int Demux ( input_thread_t * );
47 /*****************************************************************************
49 *****************************************************************************/
51 #define SRVTYPE_TEXT "SLP service type"
52 #define SRVTYPE_LONGTEXT "The service type string for SLP queries, " \
53 "including the authority string (if any) for the " \
54 "request. May not be empty"
55 #define ATTRIDS_TEXT "SLP attribute identifiers"
56 #define ATTRIDS_LONGTEXT "This string is a comma separated list of " \
57 "attribute identifiers to search for a playlist "\
58 "title or empty to use all attributes"
59 #define SCOPELIST_TEXT "SLP scopes list"
60 #define SCOPELIST_LONGTEXT "This string is a comma separated list of scope " \
61 "names or empty if you want to use the default " \
62 "scopes; it is used in all SLP queries"
63 #define NAMINGAUTHORITY_TEXT "SLP naming authority"
64 #define NAMINGAUTHORITY_LONGTEXT "This string is a list of naming " \
65 "authorities to search. Use \"*\" for all " \
66 "and the empty string for the default of " \
68 #define FILTER_TEXT "SLP LDAP filter"
69 #define FILTER_LONGTEXT "This is a query formulated of attribute pattern " \
70 "matching expressions in the form of an LDAPv3 " \
71 "search filter or empty for all answers"
72 #define LANG_TEXT "Language requested in SLP requests"
73 #define LANG_LONGTEXT "RFC 1766 Language Tag for the natural language " \
74 "locale of requests, leave empty to use the " \
75 "default locale; it is used in all SLP queries"
78 set_description( _("SLP input") );
79 add_category_hint( N_("slp"), NULL, VLC_TRUE );
80 add_string( "slp-attrids", "", NULL, ATTRIDS_TEXT, ATTRIDS_LONGTEXT, VLC_TRUE );
81 add_string( "slp-scopelist", "", NULL, SCOPELIST_TEXT,
82 SCOPELIST_LONGTEXT, VLC_TRUE );
83 add_string( "slp-namingauthority", "*", NULL, NAMINGAUTHORITY_TEXT,
84 NAMINGAUTHORITY_LONGTEXT, VLC_TRUE );
85 add_string( "slp-filter", "", NULL, FILTER_TEXT, FILTER_LONGTEXT, VLC_TRUE );
86 add_string( "slp-lang", "", NULL, LANG_TEXT, LANG_LONGTEXT, VLC_TRUE );
87 set_capability( "access", 0 );
88 set_callbacks( Open, Close );
91 add_shortcut( "demux_slp" );
92 set_capability( "demux", 0 );
93 set_callbacks( Init, End );
96 /*****************************************************************************
97 * AttrCallback: updates the description of a playlist item
98 *****************************************************************************/
99 static SLPBoolean AttrCallback( SLPHandle slph_slp,
100 const char * psz_attrlist,
101 SLPError slpe_errcode,
104 playlist_item_t * p_playlist_item = (playlist_item_t *)p_cookie;
106 /* our callback was only called to tell us there's nothing more to read */
107 if( slpe_errcode == SLP_LAST_CALL )
112 /* or there was a problem with getting the data we requested */
113 if( (slpe_errcode != SLP_OK) )
115 /* msg_Err( (vlc_object_t*)NULL,
116 "AttrCallback got an error %i with attribute %s",
122 p_playlist_item->psz_name = strdup(psz_attrlist); /* NULL is checked */
126 /*****************************************************************************
127 * SrvUrlCallback: adds an entry to the playlist
128 *****************************************************************************/
129 static SLPBoolean SrvUrlCallback( SLPHandle slph_slp,
130 const char * psz_srvurl,
132 SLPError slpe_errcode,
135 input_thread_t * p_input = (input_thread_t *)p_cookie;
136 playlist_t * p_playlist;
137 char psz_item[42] = ""; //"udp:@";
138 char * psz_s; /* to hold the uri of the stream */
140 SLPError slpe_result;
141 playlist_item_t * p_playlist_item;
143 /* our callback was only called to tell us there's nothing more to read */
144 if( slpe_errcode == SLP_LAST_CALL )
149 msg_Dbg(p_input,"URL: %s",psz_srvurl);
151 /* or there was a problem with getting the data we requested */
152 if( (slpe_errcode != SLP_OK) )
155 "SrvUrlCallback got an error %i with URL %s",
161 /* search the returned address after a double-slash */
162 psz_s = strstr( psz_srvurl, "//" );
165 msg_Err( (input_thread_t *)p_input,
166 "SrvUrlCallback got a strange string of your libslp" );
169 /* skip the slashes */
171 /* add udp:@ in front of the address */
172 psz_s = strncat( psz_item,
174 sizeof(psz_item) - strlen(psz_item) - 1 );
176 /* create a playlist item */
177 p_playlist_item = malloc( sizeof( playlist_item_t ) );
178 if( p_playlist_item == NULL )
180 msg_Err( p_input, "out of memory" );
184 p_playlist_item->psz_name = NULL;
185 p_playlist_item->psz_uri = strdup( psz_s );
186 p_playlist_item->i_type = 0;
187 p_playlist_item->i_status = 0;
188 p_playlist_item->b_autodeletion = VLC_FALSE;
189 p_playlist_item->i_options = 0;
190 p_playlist_item->ppsz_options = 0;
192 /* search the description of the stream */
193 if( SLPOpen( config_GetPsz( p_input, "slp-lang" ),
194 SLP_FALSE, /* synchronous ops */
195 &slph_slp3 ) == SLP_OK )
197 /* search all attributes */
198 slpe_result = SLPFindAttrs( slph_slp3,
200 config_GetPsz( p_input, "slp-scopelist" ),
201 config_GetPsz( p_input, "slp-attrids" ),
206 /* we're done, clean up */
207 SLPClose( slph_slp3 );
210 /* add a default name if we found no attribute */
211 if( p_playlist_item->psz_name == NULL )
213 p_playlist_item->psz_name = strdup( psz_s );
216 /* search the main playlist object */
217 p_playlist = vlc_object_find( (input_thread_t *)p_input,
220 if( p_playlist == NULL )
222 msg_Warn( (input_thread_t *)p_input,
223 "could not find playlist, not adding entries" );
227 playlist_AddItem( p_playlist,
231 vlc_object_release( (vlc_object_t *)p_playlist );
233 msg_Info( (input_thread_t *)p_input,
234 "added « %s » (lifetime %i) to playlist",
241 /*****************************************************************************
242 * SrvTypeCallback: searchs all servers of a certain type
243 *****************************************************************************/
244 static SLPBoolean SrvTypeCallback( SLPHandle slph_slp,
245 const char * psz_srvurl,
246 SLPError slpe_errcode,
249 input_thread_t * p_input = (input_thread_t *)p_cookie;
250 SLPError slpe_result;
255 msg_Dbg(p_input,"Services: %s",psz_srvurl);
256 /* our callback was only called to tell us there's nothing more to read */
257 if( slpe_errcode == SLP_LAST_CALL )
262 msg_Dbg(p_input,"Services: %s",psz_srvurl);
264 /* or there was a problem with getting the data we requested */
265 if( slpe_errcode != SLP_OK )
268 "SrvTypeCallback got an error %i with URL %s",
274 /* get a new handle to the library */
275 if( SLPOpen( config_GetPsz( p_input, "slp-lang" ),
276 SLP_FALSE, /* synchronous ops */
277 &slph_slp2 ) == SLP_OK )
279 /* search for services */
282 if( *psz_srvurl == '\0') break;
284 if( !strncasecmp( psz_srvurl, "service:", 8 ) )
288 psz_eos = strchr( psz_srvurl, ',');
290 if(!strncasecmp(psz_eos+1,"service:",8)) break;
296 psz_service = strdup( psz_srvurl);
298 msg_Dbg(p_input,"Getting details for %s",psz_service);
300 slpe_result = SLPFindSrvs( slph_slp2,
302 config_GetPsz( p_input, "slp-scopelist" ),
303 config_GetPsz( p_input, "slp-filter" ),
308 psz_srvurl = psz_eos;
310 // SLPClose( slph_slp2 );
312 if( slpe_result != SLP_OK )
315 "SLPFindSrvs error %i finding servers of type %s",
323 SLPClose( slph_slp2 );
328 /*****************************************************************************
329 * Open: initialize library for the access module
330 *****************************************************************************/
331 static int Open( vlc_object_t * p_this )
333 input_thread_t * p_input = (input_thread_t *)p_this;
334 SLPError slpe_result;
336 playlist_t * p_playlist;
338 /* remove the "slp:" entry of the playlist */
339 p_playlist = (playlist_t *) vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
343 msg_Warn( p_input, "hey I can't find the main playlist, I need it" );
347 p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
348 vlc_object_release( (vlc_object_t *)p_playlist );
350 /* get a new handle to the library */
351 if( SLPOpen( config_GetPsz( p_input, "slp-lang" ),
352 SLP_FALSE, /* synchronous ops */
353 &slph_slp ) == SLP_OK )
355 /* search all service types */
357 SLPFindSrvTypes( slph_slp,
358 config_GetPsz( p_input, "slp-namingauthority" ),
359 config_GetPsz( p_input, "slp-scopelist" ),
362 /* we're done, clean up */
363 SLPClose( slph_slp );
366 if( !p_input->psz_demux || !*p_input->psz_demux )
368 p_input->psz_demux = "demux_slp";
371 p_input->pf_read = Read;
372 p_input->pf_set_program = NULL;
373 p_input->pf_set_area = NULL;
374 p_input->pf_seek = NULL;
376 vlc_mutex_lock( &p_input->stream.stream_lock );
377 p_input->stream.b_pace_control = VLC_FALSE;
378 p_input->stream.b_seekable = VLC_FALSE;
379 p_input->stream.p_selected_area->i_tell = 0;
380 p_input->stream.p_selected_area->i_size = 0;
381 p_input->stream.i_method = INPUT_METHOD_SLP;
382 vlc_mutex_unlock( &p_input->stream.stream_lock );
388 /*****************************************************************************
389 * Close: close access
390 *****************************************************************************/
391 static void Close( vlc_object_t * p_this )
396 /*****************************************************************************
397 * Read: should fill but zeroes the buffer
398 *****************************************************************************/
399 static ssize_t Read ( input_thread_t *p_input, byte_t *p_buffer, size_t s )
401 memset( p_buffer, 0, s );
405 /*****************************************************************************
406 * Init: initialize demux
407 *****************************************************************************/
408 static int Init ( vlc_object_t *p_this )
410 input_thread_t *p_input = (input_thread_t *)p_this;
412 if( p_input->stream.i_method != INPUT_METHOD_SLP )
417 p_input->pf_demux = Demux;
418 p_input->pf_demux_control = demux_vaControlDefault;
419 p_input->pf_rewind = NULL;
424 /*****************************************************************************
425 * Demux: should demux but does nothing
426 *****************************************************************************/
427 static int Demux ( input_thread_t * p_input )
432 /*****************************************************************************
434 *****************************************************************************/
435 static void End ( vlc_object_t *p_this )