Commit ba7fd68d authored by Loïc Minier's avatar Loïc Minier

* now search all srvtypes and add all srvs of all srvtypes to the

    playlist (requires less configuration information, now zero)
  * usual cleanup and bug removal
parent 4a484a39
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* slp.c: SLP access plugin * slp.c: SLP access plugin
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: slp.c,v 1.4 2003/01/17 14:51:09 lool Exp $ * $Id: slp.c,v 1.5 2003/01/21 17:34:03 lool Exp $
* *
* Authors: Loc Minier <lool@videolan.org> * Authors: Loc Minier <lool@videolan.org>
* *
...@@ -53,7 +53,12 @@ static int Demux ( input_thread_t * ); ...@@ -53,7 +53,12 @@ static int Demux ( input_thread_t * );
#define SCOPELIST_TEXT "SLP scopes list" #define SCOPELIST_TEXT "SLP scopes list"
#define SCOPELIST_LONGTEXT "This string is a comma separated list of scope " \ #define SCOPELIST_LONGTEXT "This string is a comma separated list of scope " \
"names or empty if you want to use the default " \ "names or empty if you want to use the default " \
"scopes" "scopes; it is used in all SLP queries"
#define NAMINGAUTHORITY_TEXT "SLP naming authority"
#define NAMINGAUTHORITY_LONGTEXT "This string is a list of naming " \
"authorities to search. Use \"*\" for all " \
"and the empty string for the default of " \
"IANA"
#define FILTER_TEXT "SLP LDAP filter" #define FILTER_TEXT "SLP LDAP filter"
#define FILTER_LONGTEXT "This is a query formulated of attribute pattern " \ #define FILTER_LONGTEXT "This is a query formulated of attribute pattern " \
"matching expressions in the form of an LDAPv3 " \ "matching expressions in the form of an LDAPv3 " \
...@@ -66,10 +71,12 @@ static int Demux ( input_thread_t * ); ...@@ -66,10 +71,12 @@ static int Demux ( input_thread_t * );
vlc_module_begin(); vlc_module_begin();
set_description( _("SLP access module") ); set_description( _("SLP access module") );
add_category_hint( N_("slp"), NULL ); add_category_hint( N_("slp"), NULL );
add_string( "slp-srvtype", "service:vls.services.videolan.org:udpm", /* add_string( "slp-srvtype", "service:vls.services.videolan.org:udpm",
NULL, SRVTYPE_TEXT, SRVTYPE_LONGTEXT ); NULL, SRVTYPE_TEXT, SRVTYPE_LONGTEXT ); */
add_string( "slp-scopelist", "", NULL, SCOPELIST_TEXT, add_string( "slp-scopelist", "", NULL, SCOPELIST_TEXT,
SCOPELIST_LONGTEXT ); SCOPELIST_LONGTEXT );
add_string( "slp-namingauthority", "*", NULL, NAMINGAUTHORITY_TEXT,
NAMINGAUTHORITY_LONGTEXT );
add_string( "slp-filter", "", NULL, FILTER_TEXT, FILTER_LONGTEXT ); add_string( "slp-filter", "", NULL, FILTER_TEXT, FILTER_LONGTEXT );
add_string( "slp-lang", "", NULL, LANG_TEXT, LANG_LONGTEXT ); add_string( "slp-lang", "", NULL, LANG_TEXT, LANG_LONGTEXT );
add_submodule(); add_submodule();
...@@ -84,25 +91,31 @@ vlc_module_end(); ...@@ -84,25 +91,31 @@ vlc_module_end();
/***************************************************************************** /*****************************************************************************
* SrvUrlCallback: adds an entry to the playlist * SrvUrlCallback: adds an entry to the playlist
*****************************************************************************/ *****************************************************************************/
static SLPBoolean SrvUrlCallback( SLPHandle hslp, static SLPBoolean SrvUrlCallback( SLPHandle slph_slp,
const char * psz_srvurl, const char * psz_srvurl,
uint16_t i_lifetime, uint16_t i_lifetime,
SLPError slpe_errcode, SLPError slpe_errcode,
void * p_input ) void * p_cookie )
{ {
input_thread_t * p_input = (input_thread_t *)p_cookie;
playlist_t * p_playlist; playlist_t * p_playlist;
char psz_item[42] = "udp:@"; char psz_item[42] = "udp:@";
char * psz_s; char * psz_s;
if( slpe_errcode == SLP_OK ) /* our callback was only called to tell us there's nothing more to read */
if( slpe_errcode == SLP_LAST_CALL )
{ {
p_playlist = vlc_object_find( (input_thread_t *)p_input, return SLP_TRUE;
VLC_OBJECT_PLAYLIST, }
FIND_ANYWHERE );
if( p_playlist == NULL ) /* or there was a problem with getting the data we requested */
if( (slpe_errcode != SLP_OK) )
{ {
msg_Dbg( (input_thread_t *)p_input, "could not find playlist" ); msg_Err( p_input,
return SLP_FALSE; "SrvUrlCallback got an error %i with URL %s",
slpe_errcode,
psz_srvurl );
return SLP_TRUE;
} }
/* search the returned address after a double-slash */ /* search the returned address after a double-slash */
...@@ -111,23 +124,89 @@ static SLPBoolean SrvUrlCallback( SLPHandle hslp, ...@@ -111,23 +124,89 @@ static SLPBoolean SrvUrlCallback( SLPHandle hslp,
psz_s = &psz_s[2]; psz_s = &psz_s[2];
if( psz_s == NULL ) if( psz_s == NULL )
{ {
msg_Dbg( (input_thread_t *)p_input, msg_Err( (input_thread_t *)p_input,
"something went wrong with your libslp" ); "SrvUrlCallback got a NULL string if your libslp" );
return SLP_FALSE; return SLP_TRUE;
} }
/* add udp:@ in front of the address */ /* add udp:@ in front of the address */
psz_s = strncat( psz_item, psz_s = strncat( psz_item,
psz_s, psz_s,
sizeof(psz_item) - strlen(psz_item) - 1 ); sizeof(psz_item) - strlen(psz_item) - 1 );
/* search the main playlist object */
p_playlist = vlc_object_find( (input_thread_t *)p_input,
VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( p_playlist == NULL )
{
msg_Warn( (input_thread_t *)p_input,
"could not find playlist, not adding entries" );
return SLP_TRUE;
}
playlist_Add( p_playlist, psz_s, playlist_Add( p_playlist, psz_s,
PLAYLIST_APPEND, PLAYLIST_APPEND,
PLAYLIST_END ); PLAYLIST_END );
vlc_object_release( (vlc_object_t *)p_playlist ); vlc_object_release( (vlc_object_t *)p_playlist );
msg_Dbg( (input_thread_t *)p_input, msg_Info( (input_thread_t *)p_input,
"added %s (lifetime %i) to playlist", "added %s (lifetime %i) to playlist",
psz_srvurl, psz_srvurl,
i_lifetime ); i_lifetime );
return SLP_TRUE;
}
/*****************************************************************************
* SrvTypeCallback: searchs all servers of a certain type
*****************************************************************************/
static SLPBoolean SrvTypeCallback( SLPHandle slph_slp,
const char * psz_srvurl,
SLPError slpe_errcode,
void * p_cookie )
{
input_thread_t * p_input = (input_thread_t *)p_cookie;
SLPError slpe_result;
SLPHandle slph_slp2;
/* our callback was only called to tell us there's nothing more to read */
if( slpe_errcode == SLP_LAST_CALL )
{
return SLP_TRUE;
}
/* or there was a problem with getting the data we requested */
if( slpe_errcode != SLP_OK )
{
msg_Err( p_input,
"SrvTypeCallback got an error %i with URL %s",
slpe_errcode,
psz_srvurl );
return SLP_TRUE;
}
/* get a new handle to the library */
if( SLPOpen( config_GetPsz( p_input, "slp-lang" ),
SLP_FALSE, /* synchronous ops */
&slph_slp2 ) == SLP_OK )
{
/* search for services */
slpe_result = SLPFindSrvs( slph_slp2,
psz_srvurl,
config_GetPsz( p_input, "slp-scopelist" ),
config_GetPsz( p_input, "slp-filter" ),
SrvUrlCallback,
p_input );
SLPClose( slph_slp2 );
if( slpe_result != SLP_OK )
{
msg_Err( p_input,
"SLPFindSrvs error %i finding servers of type %s",
slpe_result,
psz_srvurl );
}
} }
return SLP_TRUE; return SLP_TRUE;
...@@ -139,7 +218,6 @@ static SLPBoolean SrvUrlCallback( SLPHandle hslp, ...@@ -139,7 +218,6 @@ static SLPBoolean SrvUrlCallback( SLPHandle hslp,
static int Open( vlc_object_t * p_this ) static int Open( vlc_object_t * p_this )
{ {
input_thread_t * p_input = (input_thread_t *)p_this; input_thread_t * p_input = (input_thread_t *)p_this;
char * psz_name = strdup(p_input->psz_name);
SLPError slpe_result; SLPError slpe_result;
SLPHandle slph_slp; SLPHandle slph_slp;
playlist_t * p_playlist; playlist_t * p_playlist;
...@@ -149,8 +227,8 @@ static int Open( vlc_object_t * p_this ) ...@@ -149,8 +227,8 @@ static int Open( vlc_object_t * p_this )
FIND_ANYWHERE ); FIND_ANYWHERE );
if( !p_playlist ) if( !p_playlist )
{ {
msg_Err( p_input, "can't find playlist" ); msg_Warn( p_input, "hey I can't find the main playlist, I need it" );
return -1; return VLC_FALSE;
} }
p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE; p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
...@@ -161,20 +239,13 @@ static int Open( vlc_object_t * p_this ) ...@@ -161,20 +239,13 @@ static int Open( vlc_object_t * p_this )
SLP_FALSE, /* synchronous ops */ SLP_FALSE, /* synchronous ops */
&slph_slp ) == SLP_OK ) &slph_slp ) == SLP_OK )
{ {
/* search for services */ /* search all service types */
slpe_result = SLPFindSrvs( slph_slp, slpe_result =
config_GetPsz( p_input, "slp-srvtype" ), SLPFindSrvTypes( slph_slp,
config_GetPsz( p_input, "slp-namingauthority" ),
config_GetPsz( p_input, "slp-scopelist" ), config_GetPsz( p_input, "slp-scopelist" ),
config_GetPsz( p_input, "slp-filter" ), SrvTypeCallback,
SrvUrlCallback,
p_input ); p_input );
if( slpe_result != SLP_OK )
{
msg_Dbg( p_input,
"slp error opening %s: %i",
psz_name,
slpe_result );
}
/* we're done, clean up */ /* we're done, clean up */
SLPClose( slph_slp ); SLPClose( slph_slp );
} }
...@@ -199,7 +270,7 @@ static int Open( vlc_object_t * p_this ) ...@@ -199,7 +270,7 @@ static int Open( vlc_object_t * p_this )
vlc_mutex_unlock( &p_input->stream.stream_lock ); vlc_mutex_unlock( &p_input->stream.stream_lock );
p_input->i_mtu = 0; p_input->i_mtu = 0;
return 0; return VLC_SUCCESS;
} }
/***************************************************************************** /*****************************************************************************
...@@ -228,13 +299,13 @@ static int Init ( vlc_object_t *p_this ) ...@@ -228,13 +299,13 @@ static int Init ( vlc_object_t *p_this )
if( p_input->stream.i_method != INPUT_METHOD_SLP ) if( p_input->stream.i_method != INPUT_METHOD_SLP )
{ {
return -1; return VLC_FALSE;
} }
p_input->pf_demux = Demux; p_input->pf_demux = Demux;
p_input->pf_rewind = NULL; p_input->pf_rewind = NULL;
return 0; return VLC_SUCCESS;
} }
/***************************************************************************** /*****************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment