]> git.sesse.net Git - vlc/blob - modules/access/slp.c
* removed VLC_GO to avoid skipping to the last program
[vlc] / modules / access / slp.c
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 $
6  *
7  * Authors: Loïc Minier <lool@videolan.org>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28 #include <vlc/input.h>
29
30 #include <slp.h>
31
32 /*****************************************************************************
33  * Local prototypes
34  *****************************************************************************/
35 static int  Open       ( vlc_object_t * );
36 static void Close      ( vlc_object_t * );
37
38 /*****************************************************************************
39  * Module descriptor
40  *****************************************************************************/
41
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 "  \
49                            "scopes"
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 "     \
57                       "default locale"
58
59 vlc_module_begin();
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,
67                 SCOPELIST_LONGTEXT );
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 );
71 vlc_module_end();
72
73 /*****************************************************************************
74  * SrvUrlCallback: adds an entry to the playlist
75  *****************************************************************************/
76 static SLPBoolean SrvUrlCallback( SLPHandle hslp,
77                            const char * psz_srvurl,
78                            uint16_t i_lifetime,
79                            SLPError slpe_errcode,
80                            void * p_input )
81 {
82     playlist_t * p_playlist;
83     char psz_item[42] = "udp:@";
84     char * psz_s;
85
86     if( slpe_errcode == SLP_OK )
87     {
88         p_playlist = vlc_object_find( (input_thread_t *)p_input,
89                                       VLC_OBJECT_PLAYLIST,
90                                       FIND_ANYWHERE );
91         if( p_playlist == NULL )
92         {
93             msg_Dbg( (input_thread_t *)p_input, "could not find playlist" );
94             return SLP_FALSE;
95         }
96
97         /* search the returned address after a double-slash */
98         psz_s = strstr( psz_srvurl, "//" );
99         /* skip the slashes */
100         psz_s = &psz_s[2];
101         if( psz_s == NULL )
102         {
103             msg_Dbg( (input_thread_t *)p_input,
104                      "something went wrong with your libslp" );
105             return SLP_FALSE;
106         }
107         /* add udp:@ in front of the address */
108         psz_s = strncat( psz_item,
109                          psz_s,
110                          sizeof(psz_item) - strlen(psz_item) - 1 );
111         playlist_Add( p_playlist, psz_s,
112                       PLAYLIST_APPEND,
113                       PLAYLIST_END );
114         vlc_object_release( (vlc_object_t *)p_playlist );
115
116         msg_Dbg( (input_thread_t *)p_input,
117                  "added « %s » (lifetime %i) to playlist",
118                  psz_srvurl,
119                  i_lifetime );
120     }
121
122     return SLP_TRUE;
123 }
124
125 /*****************************************************************************
126  * Open: initialize library
127  *****************************************************************************/
128 static int Open( vlc_object_t * p_this )
129 {
130     input_thread_t * p_input = (input_thread_t *)p_this;
131     char *           psz_name = strdup(p_input->psz_name);
132     SLPError         slpe_result;
133     SLPHandle        slph_slp;
134
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 )
139     {
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" ),
145                                    SrvUrlCallback,
146                                    p_input );
147         if( slpe_result != SLP_OK )
148         {
149             msg_Dbg( p_input,
150                      "slp error opening %s: %i",
151                      psz_name,
152                      slpe_result );
153         }
154         /* we're done, clean up */
155         SLPClose( slph_slp );
156     }
157
158     return( -1 );
159 }
160
161 /*****************************************************************************
162  * Close: free unused data structures
163  *****************************************************************************/
164 static void Close( vlc_object_t * p_this )
165 {
166
167 }
168