1 /*****************************************************************************
2 * slp.c: SLP access plugin
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: slp.c,v 1.3 2003/01/16 23:25:55 lool 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 *****************************************************************************/
28 #include <vlc/input.h>
30 #include <vlc_playlist.h>
34 /*****************************************************************************
36 *****************************************************************************/
37 static int Open ( vlc_object_t * );
38 static void Close ( vlc_object_t * );
39 static ssize_t Read ( input_thread_t *, byte_t *, size_t );
41 static int Init ( vlc_object_t * );
42 static void End ( vlc_object_t * );
43 static int Demux ( input_thread_t * );
45 /*****************************************************************************
47 *****************************************************************************/
49 #define SRVTYPE_TEXT "SLP service type"
50 #define SRVTYPE_LONGTEXT "The service type string for SLP queries, " \
51 "including the authority string (if any) for the " \
52 "request. May not be empty"
53 #define SCOPELIST_TEXT "SLP scopes list"
54 #define SCOPELIST_LONGTEXT "This string is a comma separated list of scope " \
55 "names or empty if you want to use the default " \
57 #define FILTER_TEXT "SLP LDAP filter"
58 #define FILTER_LONGTEXT "This is a query formulated of attribute pattern " \
59 "matching expressions in the form of an LDAPv3 " \
60 "search filter or empty for all answers"
61 #define LANG_TEXT "language asked in SLP requests"
62 #define LANG_LONGTEXT "RFC 1766 Language Tag for the natural language " \
63 "locale of requests, leave empty to use the " \
67 set_description( _("SLP access module") );
68 add_category_hint( N_("slp"), NULL );
69 add_string( "slp-srvtype", "service:vls.services.videolan.org:udpm",
70 NULL, SRVTYPE_TEXT, SRVTYPE_LONGTEXT );
71 add_string( "slp-scopelist", "", NULL, SCOPELIST_TEXT,
73 add_string( "slp-filter", "", NULL, FILTER_TEXT, FILTER_LONGTEXT );
74 add_string( "slp-lang", "", NULL, LANG_TEXT, LANG_LONGTEXT );
76 set_capability( "access", 0 );
77 set_callbacks( Open, Close );
79 add_shortcut( "demux_slp" );
80 set_capability( "demux", 0 );
81 set_callbacks( Init, End );
84 /*****************************************************************************
85 * SrvUrlCallback: adds an entry to the playlist
86 *****************************************************************************/
87 static SLPBoolean SrvUrlCallback( SLPHandle hslp,
88 const char * psz_srvurl,
90 SLPError slpe_errcode,
93 playlist_t * p_playlist;
94 char psz_item[42] = "udp:@";
97 if( slpe_errcode == SLP_OK )
99 p_playlist = vlc_object_find( (input_thread_t *)p_input,
102 if( p_playlist == NULL )
104 msg_Dbg( (input_thread_t *)p_input, "could not find playlist" );
108 /* search the returned address after a double-slash */
109 psz_s = strstr( psz_srvurl, "//" );
110 /* skip the slashes */
114 msg_Dbg( (input_thread_t *)p_input,
115 "something went wrong with your libslp" );
118 /* add udp:@ in front of the address */
119 psz_s = strncat( psz_item,
121 sizeof(psz_item) - strlen(psz_item) - 1 );
122 playlist_Add( p_playlist, psz_s,
125 vlc_object_release( (vlc_object_t *)p_playlist );
127 msg_Dbg( (input_thread_t *)p_input,
128 "added « %s » (lifetime %i) to playlist",
136 /*****************************************************************************
137 * Open: initialize library for the access module
138 *****************************************************************************/
139 static int Open( vlc_object_t * p_this )
141 input_thread_t * p_input = (input_thread_t *)p_this;
142 char * psz_name = strdup(p_input->psz_name);
143 SLPError slpe_result;
145 playlist_t * p_playlist;
147 /* remove the "slp:" entry of the playlist */
148 p_playlist = (playlist_t *) vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
152 msg_Err( p_input, "can't find playlist" );
156 p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
157 vlc_object_release( (vlc_object_t *)p_playlist );
159 /* get a new handle to the library */
160 if( SLPOpen( config_GetPsz( p_input, "slp-lang" ),
161 SLP_FALSE, /* synchronous ops */
162 &slph_slp ) == SLP_OK )
164 /* search for services */
165 slpe_result = SLPFindSrvs( slph_slp,
166 config_GetPsz( p_input, "slp-srvtype" ),
167 config_GetPsz( p_input, "slp-scopelist" ),
168 config_GetPsz( p_input, "slp-filter" ),
171 if( slpe_result != SLP_OK )
174 "slp error opening %s: %i",
178 /* we're done, clean up */
179 SLPClose( slph_slp );
182 if( !p_input->psz_demux || !*p_input->psz_demux )
184 p_input->psz_demux = "demux_slp";
187 p_input->pf_read = Read;
188 p_input->pf_set_program = NULL;
189 p_input->pf_set_area = NULL;
190 p_input->pf_seek = NULL;
192 vlc_mutex_lock( &p_input->stream.stream_lock );
193 p_input->stream.b_pace_control = VLC_FALSE;
194 p_input->stream.b_seekable = VLC_FALSE;
195 p_input->stream.b_connected = VLC_TRUE;
196 p_input->stream.p_selected_area->i_tell = 0;
197 p_input->stream.p_selected_area->i_size = 0;
198 p_input->stream.i_method = INPUT_METHOD_SLP;
199 vlc_mutex_unlock( &p_input->stream.stream_lock );
205 /*****************************************************************************
206 * Close: close access
207 *****************************************************************************/
208 static void Close( vlc_object_t * p_this )
213 /*****************************************************************************
214 * Read: should fill but zeroes the buffer
215 *****************************************************************************/
216 static ssize_t Read ( input_thread_t *p_input, byte_t *p_buffer, size_t s )
218 memset( p_buffer, 0, s );
222 /*****************************************************************************
223 * Init: initialize demux
224 *****************************************************************************/
225 int Init ( vlc_object_t *p_this )
227 input_thread_t *p_input = (input_thread_t *)p_this;
229 if( p_input->stream.i_method != INPUT_METHOD_SLP )
234 p_input->pf_demux = Demux;
235 p_input->pf_rewind = NULL;
240 /*****************************************************************************
241 * Demux: should demux but does nothing
242 *****************************************************************************/
243 static int Demux ( input_thread_t * p_input )
248 /*****************************************************************************
250 *****************************************************************************/
251 static void End ( vlc_object_t *p_this )