]> git.sesse.net Git - vlc/blobdiff - modules/access/slp.c
* Massive spelling corrections.
[vlc] / modules / access / slp.c
index de05f1abdfd0e72c8b27795c1d84f45398465949..7d064877e843bcbdfb1e29c166a181b84aef27bd 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * slp.c: SLP access plugin
  *****************************************************************************
- * Copyright (C) 2001, 2002 VideoLAN
- * $Id: slp.c,v 1.13 2003/07/23 01:13:47 gbazin Exp $
+ * Copyright (C) 2002-2004 VideoLAN
+ * $Id$
  *
  * Authors: Loïc Minier <lool@videolan.org>
  *
@@ -10,7 +10,7 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *****************************************************************************/
 static int  Open  ( vlc_object_t * );
 static void Close ( vlc_object_t * );
-static ssize_t Read  ( input_thread_t *, byte_t *, size_t );
+static ssize_t Read( input_thread_t *, byte_t *, size_t );
 
 static int  Init  ( vlc_object_t * );
 static void End   ( vlc_object_t * );
 static int  Demux ( input_thread_t * );
 
+int i_group;
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
 
-#define SRVTYPE_TEXT     "SLP service type"
-#define SRVTYPE_LONGTEXT "The service type string for SLP queries, " \
-                         "including the authority string (if any) for the " \
-                         "request. May not be empty"
-#define ATTRIDS_TEXT     "SLP attribute identifiers"
-#define ATTRIDS_LONGTEXT "This string is a comma separated list of " \
-                         "attribute identifiers to search for a playlist "\
-                         "title or empty to use all attributes"
-#define SCOPELIST_TEXT     "SLP scopes list"
-#define SCOPELIST_LONGTEXT "This string is a comma separated list of scope " \
-                           "names or empty if you want to use the default "  \
-                           "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_LONGTEXT "This is a query formulated of attribute pattern " \
-                        "matching expressions in the form of an LDAPv3 "   \
-                        "search filter or empty for all answers"
-#define LANG_TEXT     "Language requested in SLP requests"
-#define LANG_LONGTEXT "RFC 1766 Language Tag for the natural language " \
-                      "locale of requests, leave empty to use the "     \
-                      "default locale; it is used in all SLP queries"
+#if 0
+#define SRVTYPE_TEXT /*N_*/("SLP service type")
+#define SRVTYPE_LONGTEXT /*N_*/( \
+    "The service type string for SLP queries, including the authority " \
+    "string (if any) for the request. May not be empty." )
+#endif
+
+#define ATTRIDS_TEXT N_("SLP attribute identifiers")
+#define ATTRIDS_LONGTEXT N_( \
+    "This string is a comma separated list of attribute identifiers to " \
+    "search for a playlist title or empty to use all attributes." )
+
+#define SCOPELIST_TEXT N_("SLP scopes list")
+#define SCOPELIST_LONGTEXT N_( \
+    "This string is a comma separated list of scope names or empty if you " \
+    "want to use the default scopes. It is used in all SLP queries." )
+
+#define NAMINGAUTHORITY_TEXT N_("SLP naming authority")
+#define NAMINGAUTHORITY_LONGTEXT N_( \
+    "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 N_("SLP LDAP filter")
+#define FILTER_LONGTEXT N_( \
+    "This is a query formulated of attribute pattern matching expressions " \
+    "in the form of an LDAPv3 search filter or empty for all answers." )
+
+#define LANG_TEXT N_("Language requested in SLP requests")
+#define LANG_LONGTEXT N_( \
+    "RFC 1766 Language tag for the natural language locale of requests, " \
+    "leave empty to use the default locale. It is used in all SLP queries." )
 
 vlc_module_begin();
     set_description( _("SLP input") );
-    add_category_hint( N_("slp"), NULL, VLC_TRUE );
-    add_string( "slp-attrids", "", NULL, ATTRIDS_TEXT, ATTRIDS_LONGTEXT, VLC_TRUE );
+
+    add_string( "slp-attrids", "", NULL, ATTRIDS_TEXT, ATTRIDS_LONGTEXT,
+                VLC_TRUE );
     add_string( "slp-scopelist", "", NULL, SCOPELIST_TEXT,
                 SCOPELIST_LONGTEXT, VLC_TRUE );
     add_string( "slp-namingauthority", "*", NULL, NAMINGAUTHORITY_TEXT,
                 NAMINGAUTHORITY_LONGTEXT, VLC_TRUE );
-    add_string( "slp-filter", "", NULL, FILTER_TEXT, FILTER_LONGTEXT, VLC_TRUE );
+    add_string( "slp-filter", "", NULL, FILTER_TEXT, FILTER_LONGTEXT,
+                VLC_TRUE );
     add_string( "slp-lang", "", NULL, LANG_TEXT, LANG_LONGTEXT, VLC_TRUE );
+
     set_capability( "access", 0 );
     set_callbacks( Open, Close );
 
@@ -112,14 +123,19 @@ static SLPBoolean AttrCallback( SLPHandle slph_slp,
     /* or there was a problem with getting the data we requested */
     if( (slpe_errcode != SLP_OK) )
     {
-/*        msg_Err( (vlc_object_t*)NULL,
+#if 0
+        msg_Err( (vlc_object_t*)NULL,
                  "AttrCallback got an error %i with attribute %s",
                  slpe_errcode,
-                 psz_attrlist ); */
+                 psz_attrlist );
+#endif
         return SLP_TRUE;
     }
 
-    p_playlist_item->psz_name = strdup(psz_attrlist);     /* NULL is checked */
+    if( p_playlist_item->input.psz_name )
+        free( p_playlist_item->input.psz_name );
+
+    p_playlist_item->input.psz_name = strdup(psz_attrlist); /* NULL is checked */
     return SLP_TRUE;
 }
 
@@ -132,9 +148,9 @@ static SLPBoolean SrvUrlCallback( SLPHandle slph_slp,
                            SLPError slpe_errcode,
                            void * p_cookie )
 {
-    input_thread_t * p_input = (input_thread_t  *)p_cookie;
+    input_thread_t *p_input = (input_thread_t  *)p_cookie;
     playlist_t * p_playlist;
-    char psz_item[42] = "udp:@";
+    char psz_item[42] = ""; //"udp:@";
     char * psz_s;                           /* to hold the uri of the stream */
     SLPHandle slph_slp3;
     SLPError slpe_result;
@@ -146,13 +162,13 @@ static SLPBoolean SrvUrlCallback( SLPHandle slph_slp,
         return SLP_TRUE;
     }
 
+    msg_Dbg( p_input,"URL: %s", psz_srvurl );
+
     /* or there was a problem with getting the data we requested */
     if( (slpe_errcode != SLP_OK) )
     {
-        msg_Err( p_input,
-                 "SrvUrlCallback got an error %i with URL %s",
-                 slpe_errcode,
-                 psz_srvurl );
+        msg_Err( p_input, "SrvUrlCallback got an error %i with URL %s",
+                 slpe_errcode, psz_srvurl );
         return SLP_TRUE;
     }
 
@@ -160,7 +176,7 @@ static SLPBoolean SrvUrlCallback( SLPHandle slph_slp,
     psz_s = strstr( psz_srvurl, "//" );
     if( psz_s == NULL )
     {
-        msg_Err( (input_thread_t *)p_input,
+        msg_Err( p_input,
                  "SrvUrlCallback got a strange string of your libslp" );
         return SLP_TRUE;
     }
@@ -172,20 +188,15 @@ static SLPBoolean SrvUrlCallback( SLPHandle slph_slp,
                      sizeof(psz_item) - strlen(psz_item) - 1 );
 
     /* create a playlist  item */
-    p_playlist_item = malloc( sizeof( playlist_item_t ) );
+    p_playlist_item = playlist_ItemNew( p_input, psz_s, NULL );
     if( p_playlist_item == NULL )
     {
         msg_Err( p_input, "out of memory" );
         return SLP_TRUE;
     }
 
-    p_playlist_item->psz_name = NULL;
-    p_playlist_item->psz_uri  = strdup( psz_s );
-    p_playlist_item->i_type = 0;
-    p_playlist_item->i_status = 0;
-    p_playlist_item->b_autodeletion = VLC_FALSE;
-    p_playlist_item->i_options = 0;
-    p_playlist_item->ppsz_options = 0;
+    p_playlist_item->i_group = i_group;
+    p_playlist_item->b_enabled = VLC_TRUE;
 
     /* search the description of the stream */
     if( SLPOpen( config_GetPsz( p_input, "slp-lang" ),
@@ -205,33 +216,21 @@ static SLPBoolean SrvUrlCallback( SLPHandle slph_slp,
         SLPClose( slph_slp3 );
     }
 
-    /* add a default name if we found no attribute */
-    if( p_playlist_item->psz_name == NULL )
-    {
-        p_playlist_item->psz_name = strdup( psz_s );
-    }
-
     /* search the main playlist object */
-    p_playlist = vlc_object_find( (input_thread_t *)p_input,
-                                  VLC_OBJECT_PLAYLIST,
+    p_playlist = vlc_object_find( 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" );
+        msg_Warn( p_input, "could not find playlist, not adding entries" );
         return SLP_TRUE;
     }
 
-    playlist_AddItem( p_playlist,
-                      p_playlist_item,
-                      PLAYLIST_APPEND,
-                      PLAYLIST_END );
-    vlc_object_release( (vlc_object_t *)p_playlist );
+    playlist_AddItem( p_playlist, p_playlist_item,
+                      PLAYLIST_APPEND, PLAYLIST_END );
+    vlc_object_release( p_playlist );
 
-    msg_Info( (input_thread_t *)p_input,
-             "added « %s » (lifetime %i) to playlist",
-             psz_srvurl,
-             i_lifetime );
+    msg_Info( p_input, "added « %s » (lifetime %i) to playlist",
+              psz_srvurl, i_lifetime );
 
     return SLP_TRUE;
 }
@@ -247,20 +246,23 @@ static SLPBoolean SrvTypeCallback( SLPHandle slph_slp,
     input_thread_t * p_input = (input_thread_t  *)p_cookie;
     SLPError slpe_result;
     SLPHandle slph_slp2;
+    char *psz_eos;
+    char *psz_service;
 
+    msg_Dbg( p_input, "services: %s", psz_srvurl );
     /* our callback was only called to tell us there's nothing more to read */
     if( slpe_errcode == SLP_LAST_CALL )
     {
         return SLP_TRUE;
     }
 
+    msg_Dbg( p_input, "services: %s", psz_srvurl );
+
     /* 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 );
+        msg_Err( p_input, "SrvTypeCallback got an error %i with URL %s",
+                 slpe_errcode, psz_srvurl );
         return SLP_TRUE;
     }
 
@@ -270,23 +272,50 @@ static SLPBoolean SrvTypeCallback( SLPHandle slph_slp,
                  &slph_slp2 ) == SLP_OK )
     {
         /* search for services */
-        slpe_result = SLPFindSrvs( slph_slp2,
-                                   psz_srvurl,
+        while(1)
+        {
+            if( *psz_srvurl == '\0')  break;
+
+            if( !strncasecmp( psz_srvurl, "service:", 8 ) )
+            {
+                while(1)
+                {
+                    psz_eos = strchr( psz_srvurl, ',');
+                    if(!psz_eos) break;
+                    if(!strncasecmp(psz_eos+1,"service:",8)) break;
+                }
+
+                if(psz_eos)
+                    *psz_eos = '\0';
+
+                psz_service = strdup( psz_srvurl);
+
+                msg_Dbg( p_input, "getting details for %s", psz_service );
+
+                slpe_result = SLPFindSrvs( slph_slp2,
+                                   psz_service,
                                    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 );
+                if(psz_eos)
+                    psz_srvurl = psz_eos;
+
+#if 0
+                SLPClose( slph_slp2 );
+#endif
+                if( slpe_result != SLP_OK )
+                {
+                   msg_Err( p_input,
+                           "SLPFindSrvs error %i finding servers of type %s",
+                           slpe_result, psz_service );
+                }
+            }
+            psz_srvurl++;
         }
     }
+                SLPClose( slph_slp2 );
 
     return SLP_TRUE;
 }
@@ -296,10 +325,11 @@ static SLPBoolean SrvTypeCallback( SLPHandle slph_slp,
  *****************************************************************************/
 static int Open( vlc_object_t * p_this )
 {
-    input_thread_t * p_input = (input_thread_t *)p_this;
-    SLPError         slpe_result;
-    SLPHandle        slph_slp;
-    playlist_t *     p_playlist;
+    input_thread_t *   p_input = (input_thread_t *)p_this;
+    SLPError           slpe_result;
+    SLPHandle          slph_slp;
+    playlist_t *       p_playlist;
+    playlist_group_t * p_group;
 
     /* remove the "slp:" entry of the playlist */
     p_playlist = (playlist_t *) vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
@@ -310,6 +340,8 @@ static int Open( vlc_object_t * p_this )
         return VLC_FALSE;
     }
 
+    p_group = playlist_CreateGroup( p_playlist , "SLP" );
+    i_group = p_group->i_id;
     p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
     vlc_object_release( (vlc_object_t *)p_playlist );
 
@@ -381,6 +413,7 @@ static int Init ( vlc_object_t *p_this )
     }
 
     p_input->pf_demux  = Demux;
+    p_input->pf_demux_control = demux_vaControlDefault;
     p_input->pf_rewind = NULL;
 
     return VLC_SUCCESS;
@@ -401,4 +434,3 @@ static void End ( vlc_object_t *p_this )
 {
     return;
 }
-