]> git.sesse.net Git - vlc/blobdiff - modules/control/dbus.c
Do not leak the art handler from HTTP interface - fixes #1308
[vlc] / modules / control / dbus.c
index 6ee354b3d42209fdfbdaa664aa242bff17187503..85b41f9aa8bce1472d485d4ff00d5c296b09d897 100644 (file)
@@ -59,7 +59,7 @@ static void Run     ( intf_thread_t * );
 static int TrackChange( vlc_object_t *p_this, const char *psz_var,
                     vlc_value_t oldval, vlc_value_t newval, void *p_data );
 
-static int GetInputMeta ( input_item_t *p_input, 
+static int GetInputMeta ( input_item_t *p_input,
                     DBusMessageIter *args);
 
 struct intf_sys_t
@@ -83,58 +83,6 @@ vlc_module_end();
 /*****************************************************************************
  * Methods
  *****************************************************************************/
-#if 0
-DBUS_METHOD( PlaylistExport_XSPF )
-{ /*export playlist to an xspf file */
-
-  /* reads the filename to export to */
-  /* returns the status as int32:
-   *    0 : success
-   *    1 : error
-   *    2 : playlist empty
-   */
-    REPLY_INIT;
-    OUT_ARGUMENTS;
-
-    DBusError error; 
-    dbus_error_init( &error );
-
-    char *psz_file;
-    dbus_int32_t i_ret;
-
-    dbus_message_get_args( p_from, &error,
-            DBUS_TYPE_STRING, &psz_file,
-            DBUS_TYPE_INVALID );
-
-    if( dbus_error_is_set( &error ) )
-    {
-        msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
-                error.message );
-        dbus_error_free( &error );
-        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-    }
-
-    playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
-
-    if( ( !playlist_IsEmpty( p_playlist ) ) &&
-            ( p_playlist->p_root_category->i_children > 0 ) )
-    {
-        if( playlist_Export( p_playlist, psz_file,
-                         p_playlist->p_root_category->pp_children[0],
-                         "export-xspf" ) == VLC_SUCCESS )
-            i_ret = 0;
-        else
-            i_ret = 1;
-    }
-    else
-        i_ret = 2;
-
-    pl_Release( ((vlc_object_t*) p_this ) );
-
-    ADD_INT32( &i_ret );
-    REPLY_SEND;
-}
-#endif
 
 /* Player */
 
@@ -149,7 +97,7 @@ DBUS_METHOD( Quit )
 }
 
 DBUS_METHOD( PositionGet )
-{ /* returns position as an int in the range [0;1000] */
+{ /* returns position in milliseconds */
     REPLY_INIT;
     OUT_ARGUMENTS;
     vlc_value_t position;
@@ -162,8 +110,8 @@ DBUS_METHOD( PositionGet )
         i_pos = 0;
     else
     {
-        var_Get( p_input, "position", &position );
-        i_pos = position.f_float * 1000 ;
+        var_Get( p_input, "time", &position );
+        i_pos = position.i_time / 1000;
     }
     pl_Release( ((vlc_object_t*) p_this) );
     ADD_INT32( &i_pos );
@@ -171,7 +119,7 @@ DBUS_METHOD( PositionGet )
 }
 
 DBUS_METHOD( PositionSet )
-{ /* set position from an int in the range [0;1000] */
+{ /* set position in milliseconds */
 
     REPLY_INIT;
     vlc_value_t position;
@@ -197,8 +145,8 @@ DBUS_METHOD( PositionSet )
 
     if( p_input )
     {
-        position.f_float = ((float)i_pos) / 1000;
-        var_Set( p_input, "position", position );
+        position.i_time = i_pos * 1000;
+        var_Set( p_input, "time", position );
     }
     pl_Release( ((vlc_object_t*) p_this) );
     REPLY_SEND;
@@ -317,29 +265,14 @@ DBUS_METHOD( Play )
     REPLY_SEND;
 }
 
-DBUS_METHOD( Disconnect )
-{
-    REPLY_INIT;
-    DBusError error;
-    int i;
-    dbus_error_init( &error );
-    i = dbus_bus_release_name( p_conn, VLC_MPRIS_DBUS_SERVICE, &error );
-    if( ( i == -1 ) && ( dbus_error_is_set( &error ) ) )
-    {
-        msg_Err( (vlc_object_t*) p_this, "D-Bus disconnection failed : %s\n",
-            error.message );
-        dbus_error_free( &error );
-    }
-    REPLY_SEND;
-}
-
 DBUS_METHOD( GetCurrentMetadata )
 {
     REPLY_INIT;
     OUT_ARGUMENTS;
     playlist_t* p_playlist = pl_Yield( (vlc_object_t*) p_this );
 
-    GetInputMeta( p_playlist->status.p_item->p_input, &args );
+    if( p_playlist->status.p_item )
+        GetInputMeta( p_playlist->status.p_item->p_input, &args );
 
     pl_Release( p_playlist );
     REPLY_SEND;
@@ -351,7 +284,7 @@ DBUS_METHOD( Identity )
 {
     REPLY_INIT;
     OUT_ARGUMENTS;
-    char *psz_identity = malloc( strlen( PACKAGE ) + strlen( VERSION ) + 1 );
+    char *psz_identity = malloc( strlen( PACKAGE ) + strlen( VERSION ) + 2 );
     sprintf( psz_identity, "%s %s", PACKAGE, VERSION );
     ADD_STRING( &psz_identity );
     free( psz_identity );
@@ -397,17 +330,20 @@ DBUS_METHOD( GetCurrentTrack )
 {
     REPLY_INIT;
     OUT_ARGUMENTS;
+    /* FIXME 0 indicates the first item,
+     * what to do if we're stopped, or empty ? */
     dbus_int32_t i_position = 0;
     playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
     playlist_item_t* p_tested_item = p_playlist->p_root_onelevel;
 
-    while ( p_tested_item->p_input->i_id !=
-                    p_playlist->status.p_item->p_input->i_id )
-    {
-        i_position++;
-        TEST_NEXT;
-    }
-
+    if( p_playlist->status.p_item )
+        while ( p_tested_item && p_tested_item->p_input->i_id !=
+                p_playlist->status.p_item->p_input->i_id )
+        {
+            i_position++;
+            TEST_NEXT_ITEM;
+        }
+    /* FIXME if p_tested_item is NULL at that point, what do we do ? */
     pl_Release( p_playlist );
 
     ADD_INT32( &i_position );
@@ -427,8 +363,8 @@ DBUS_METHOD( GetMetadata )
     playlist_item_t* p_tested_item = p_playlist->p_root_onelevel;
 
     dbus_message_get_args( p_from, &error,
-            DBUS_TYPE_INT32, &i_position,
-            DBUS_TYPE_INVALID );
+           DBUS_TYPE_INT32, &i_position,
+           DBUS_TYPE_INVALID );
 
     if( dbus_error_is_set( &error ) )
     {
@@ -438,13 +374,14 @@ DBUS_METHOD( GetMetadata )
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
     }
 
-    while ( i_count < i_position ) 
+    while ( p_tested_item && ( i_count < i_position ) )
     {
         i_count++;
-        TEST_NEXT;
+        TEST_NEXT_ITEM;
     }
 
-    GetInputMeta ( p_tested_item->p_input, &args );
+    if( p_tested_item )
+        GetInputMeta ( p_tested_item->p_input, &args );
 
     pl_Release( p_playlist );
     REPLY_SEND;
@@ -459,12 +396,13 @@ DBUS_METHOD( GetLength )
     playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
     playlist_item_t* p_tested_item = p_playlist->p_root_onelevel;
     playlist_item_t* p_last_item = playlist_GetLastLeaf( p_playlist,
-                    p_playlist->p_root_onelevel ); 
+                    p_playlist->p_root_onelevel );
 
-    while ( p_tested_item->p_input->i_id != p_last_item->p_input->i_id )
+    while ( p_tested_item &&
+               ( p_tested_item->p_input->i_id != p_last_item->p_input->i_id ) )
     {
         i_elements++;
-        TEST_NEXT;
+        TEST_NEXT_ITEM;
     }
 
     pl_Release( p_playlist );
@@ -496,17 +434,20 @@ DBUS_METHOD( DelTrack )
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
     }
 
-    while ( i_count < i_position ) 
+    while ( p_tested_item && ( i_count < i_position ) )
     {
         i_count++;
-        TEST_NEXT;
+        TEST_NEXT_ITEM;
     }
 
-    PL_LOCK; 
-    playlist_DeleteFromInput( p_playlist,
-        p_tested_item->p_input->i_id,
-        VLC_TRUE );
-    PL_UNLOCK;
+    if( p_tested_item )
+    {
+        PL_LOCK;
+        playlist_DeleteFromInput( p_playlist,
+            p_tested_item->p_input->i_id,
+            VLC_TRUE );
+        PL_UNLOCK;
+    }
 
     pl_Release( p_playlist );
 
@@ -585,12 +526,12 @@ DBUS_METHOD( Random )
     dbus_bool_t b_random;
     vlc_value_t val;
     playlist_t* p_playlist = NULL;
-    
     dbus_error_init( &error );
     dbus_message_get_args( p_from, &error,
             DBUS_TYPE_BOOLEAN, &b_random,
             DBUS_TYPE_INVALID );
-    
     if( dbus_error_is_set( &error ) )
     {
         msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
@@ -600,7 +541,7 @@ DBUS_METHOD( Random )
     }
 
     val.b_bool = ( b_random == TRUE ) ? VLC_TRUE : VLC_FALSE ;
-    
     p_playlist = pl_Yield( (vlc_object_t*) p_this );
     var_Set ( p_playlist, "random", val );
     pl_Release( ((vlc_object_t*) p_this) );
@@ -673,7 +614,6 @@ DBUS_METHOD( handle_player )
     METHOD_FUNC( "Play",                    Play );
     METHOD_FUNC( "Pause",                   Pause );
     METHOD_FUNC( "Repeat",                  Repeat );
-    METHOD_FUNC( "Disconnect",              Disconnect );
     METHOD_FUNC( "VolumeSet",               VolumeSet );
     METHOD_FUNC( "VolumeGet",               VolumeGet );
     METHOD_FUNC( "PositionSet",             PositionSet );
@@ -737,8 +677,8 @@ static int Open( vlc_object_t *p_this )
     dbus_bus_request_name( p_conn, VLC_MPRIS_DBUS_SERVICE, 0, &error );
     if( dbus_error_is_set( &error ) )
     {
-        msg_Err( p_this, "Error requesting % service: %s\n"
-        VLC_MPRIS_DBUS_SERVICE, error.message );
+        msg_Err( p_this, "Error requesting service " VLC_MPRIS_DBUS_SERVICE
+                 ": %s", error.message );
         dbus_error_free( &error );
         free( p_sys );
         return VLC_EGENERIC;
@@ -792,7 +732,7 @@ static void Close   ( vlc_object_t *p_this )
 
 static void Run          ( intf_thread_t *p_intf )
 {
-    while( !p_intf->b_die )
+    while( !intf_ShouldDie( p_intf ) )
     {
         msleep( INTF_IDLE_SLEEP );
         dbus_connection_read_write_dispatch( p_intf->p_sys->p_conn, 0 );
@@ -877,10 +817,9 @@ static int GetInputMeta( input_item_t* p_input,
     DBusMessageIter dict, dict_entry, variant;
     /* We need the track length to be expressed in seconds
      * instead of milliseconds */
-    dbus_int64_t i_length = (p_input->i_duration / 1000);
+    dbus_int64_t i_length = ( input_item_GetDuration( p_input ) / 1000 );
 
-
-    const char* ppsz_meta_items[] = 
+    const char* ppsz_meta_items[] =
     {
     "title", "artist", "genre", "copyright", "album", "tracknum",
     "description", "rating", "date", "setting", "url", "language",
@@ -907,10 +846,14 @@ static int GetInputMeta( input_item_t* p_input,
     ADD_VLC_META_STRING( 13, Publisher );
     ADD_VLC_META_STRING( 14, EncodedBy );
     ADD_VLC_META_STRING( 15, ArtURL );
-    ADD_VLC_META_STRING( 16, TrackID ); 
+    ADD_VLC_META_STRING( 16, TrackID );
+
+    vlc_mutex_lock( &p_input->lock );
+    if( p_input->p_meta )
+        ADD_META( 17, DBUS_TYPE_INT32, p_input->p_meta->i_status );
+    vlc_mutex_unlock( &p_input->lock );
 
-    ADD_META( 17, DBUS_TYPE_INT32, p_input->p_meta->i_status );
-    ADD_META( 18, DBUS_TYPE_STRING, p_input->psz_uri );
+    ADD_VLC_META_STRING( 18, URI );
     ADD_META( 19, DBUS_TYPE_INT64, i_length );
 
     dbus_message_iter_close_container( args, &dict );