1 /*****************************************************************************
2 * slp.c: SLP access plugin
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: slp.c,v 1.2 2003/01/10 06:16: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>
32 /*****************************************************************************
34 *****************************************************************************/
35 static int Open ( vlc_object_t * );
36 static void Close ( vlc_object_t * );
38 /*****************************************************************************
40 *****************************************************************************/
42 #define SRVTYPE_TEXT "SLP service type"
43 #define SRVTYPE_LONGTEXT "The service type string for SLP queries, " \
44 "including the authority string (if any) for the " \
45 "request. May not be empty"
46 #define SCOPELIST_TEXT "SLP scopes list"
47 #define SCOPELIST_LONGTEXT "This string is a comma separated list of scope " \
48 "names or empty if you want to use the default " \
50 #define FILTER_TEXT "SLP LDAP filter"
51 #define FILTER_LONGTEXT "This is a query formulated of attribute pattern " \
52 "matching expressions in the form of an LDAPv3 " \
53 "search filter or empty for all answers"
54 #define LANG_TEXT "language asked in SLP requests"
55 #define LANG_LONGTEXT "RFC 1766 Language Tag for the natural language " \
56 "locale of requests, leave empty to use the " \
60 set_description( _("SLP access module") );
61 add_category_hint( N_("slp"), NULL );
62 set_capability( "access", 0 );
63 add_shortcut( "slp" );
64 add_string( "slp-srvtype", "service:vls.services.videolan.org:udpm",
65 NULL, SRVTYPE_TEXT, SRVTYPE_LONGTEXT );
66 add_string( "slp-scopelist", "", NULL, SCOPELIST_TEXT,
68 add_string( "slp-filter", "", NULL, FILTER_TEXT, FILTER_LONGTEXT );
69 add_string( "slp-lang", "", NULL, LANG_TEXT, LANG_LONGTEXT );
70 set_callbacks( Open, Close );
73 /*****************************************************************************
74 * SrvUrlCallback: adds an entry to the playlist
75 *****************************************************************************/
76 static SLPBoolean SrvUrlCallback( SLPHandle hslp,
77 const char * psz_srvurl,
79 SLPError slpe_errcode,
82 playlist_t * p_playlist;
83 char psz_item[42] = "udp:@";
86 if( slpe_errcode == SLP_OK )
88 p_playlist = vlc_object_find( (input_thread_t *)p_input,
91 if( p_playlist == NULL )
93 msg_Dbg( (input_thread_t *)p_input, "could not find playlist" );
97 /* search the returned address after a double-slash */
98 psz_s = strstr( psz_srvurl, "//" );
99 /* skip the slashes */
103 msg_Dbg( (input_thread_t *)p_input,
104 "something went wrong with your libslp" );
107 /* add udp:@ in front of the address */
108 psz_s = strncat( psz_item,
110 sizeof(psz_item) - strlen(psz_item) - 1 );
111 playlist_Add( p_playlist, psz_s,
114 vlc_object_release( (vlc_object_t *)p_playlist );
116 msg_Dbg( (input_thread_t *)p_input,
117 "added « %s » (lifetime %i) to playlist",
125 /*****************************************************************************
126 * Open: initialize library
127 *****************************************************************************/
128 static int Open( vlc_object_t * p_this )
130 input_thread_t * p_input = (input_thread_t *)p_this;
131 char * psz_name = strdup(p_input->psz_name);
132 SLPError slpe_result;
135 /* get a new handle to the library */
136 if( SLPOpen( config_GetPsz( p_input, "slp-lang" ),
137 SLP_FALSE, /* synchronous ops */
138 &slph_slp ) == SLP_OK )
140 /* search for services */
141 slpe_result = SLPFindSrvs( slph_slp,
142 config_GetPsz( p_input, "slp-srvtype" ),
143 config_GetPsz( p_input, "slp-scopelist" ),
144 config_GetPsz( p_input, "slp-filter" ),
147 if( slpe_result != SLP_OK )
150 "slp error opening %s: %i",
154 /* we're done, clean up */
155 SLPClose( slph_slp );
161 /*****************************************************************************
162 * Close: free unused data structures
163 *****************************************************************************/
164 static void Close( vlc_object_t * p_this )