/* * xfmedia-test * Test app to show Xfmedia exit on invalid utf-8 filename * * Compile with: * gcc xfmedia-test.c -o xfmedia-test $(pkg-config --cflags --libs dbus-1 glib-2.0) $(pkg-config --cflags xfmedia-plugin) * * Instructions: * Start playing a file with non-ascii filename (i.e. contains ä) * Execute ./xfmedia-test and see Xfmedia exit */ #include #include #define DBUS_API_SUBJECT_TO_CHANGE 1 #include #include int main( int argc, char *argv ) { DBusConnection *connection; DBusError error; DBusMessage *message, *reply; int i; gchar name[64], path[64], *unique_name = NULL; dbus_error_init( &error ); connection = dbus_bus_get( DBUS_BUS_SESSION, &error ); if ( !connection ) { g_critical( "Failed to connect D-BUS: %s", error.message ); exit( 1 ); } for ( i = 0; i < MAX_INSTANCES && !unique_name; i++ ) { gchar *p; dbus_error_init( &error ); g_snprintf( name, 64, XFMEDIA_DBUS_SERVICE_FMT, i ); g_snprintf( path, 64, XFMEDIA_DBUS_PATH_FMT, i ); p = name; message = dbus_message_new_method_call( DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetNameOwner" ); if ( !message ) { g_critical( "%s", error.message ); dbus_connection_unref( connection ); exit( 1 ); } dbus_message_set_auto_start( message, FALSE ); dbus_message_append_args( message, DBUS_TYPE_STRING, &p, DBUS_TYPE_INVALID ); reply = dbus_connection_send_with_reply_and_block( connection, message, -1, &error ); if ( !reply || dbus_message_get_type( reply ) == DBUS_MESSAGE_TYPE_ERROR ) { dbus_error_free( &error ); } else { dbus_message_get_args( reply, &error, DBUS_TYPE_STRING, &unique_name, DBUS_TYPE_INVALID ); unique_name = g_strdup( unique_name ); } if ( reply ) { dbus_message_unref( reply ); } dbus_message_unref( message ); } if ( !unique_name ) { g_critical( "Oops! No Xfmedia." ); dbus_connection_unref( connection ); exit( 1 ); } dbus_error_init( &error ); message = dbus_message_new_method_call( unique_name, path, XFMEDIA_DBUS_INTERFACE, XFMEDIA_REMOTE_NOW_PLAYING ); if ( !message ) { g_critical( "%s", error.message ); dbus_connection_unref( connection ); exit( 1 ); } dbus_message_set_auto_start( message, FALSE ); reply = dbus_connection_send_with_reply_and_block( connection, message, -1, &error ); if ( !reply || dbus_message_get_type( reply ) == DBUS_MESSAGE_TYPE_ERROR ) { g_critical( "Failed to get currently playing song: %s", error.message ); dbus_error_free( &error ); } else { gint32 song_index, song_length; gchar *song_title, *song_fn; g_message( "Got currently playing song!" ); dbus_message_get_args( reply, &error, DBUS_TYPE_INT32, &song_index, DBUS_TYPE_STRING, &song_title, DBUS_TYPE_INT32, &song_length, DBUS_TYPE_STRING, &song_fn, DBUS_TYPE_INVALID ); g_message( "#%d %s [%s] (%.2d:%.2d)", song_index, song_title, song_fn, song_length / 60, song_length % 60 ); } if ( reply ) { dbus_message_unref( reply ); } dbus_message_unref( message ); dbus_connection_unref( connection ); return ( EXIT_SUCCESS ); }