summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e2cbb9b)
raw | patch | inline | side by side (parent: e2cbb9b)
author | Max Kellermann <max@duempel.org> | |
Sat, 17 Oct 2009 22:32:37 +0000 (00:32 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Sat, 17 Oct 2009 22:32:37 +0000 (00:32 +0200) |
When leaving idle mode, the idle callback (which is invoked indirectly
by mpdclient_get_connection()) may close the connection. Checking
mpdclient_is_connected() before mpdclient_get_connection() is
pointless for that reason.
by mpdclient_get_connection()) may close the connection. Checking
mpdclient_is_connected() before mpdclient_get_connection() is
pointless for that reason.
diff --git a/src/player_command.c b/src/player_command.c
index 3b8476daf3924b08aec875c17ac8c74f5a7c876e..54664e58e9bdb8c6a5ccc78a7ec0f4f0a505d5ff 100644 (file)
--- a/src/player_command.c
+++ b/src/player_command.c
if (seek_id < 0)
return;
- if (!mpdclient_is_connected(c)) {
+ connection = mpdclient_get_connection(c);
+ if (connection == NULL) {
seek_id = -1;
return;
}
- connection = mpdclient_get_connection(c);
-
if (c->song != NULL && (unsigned)seek_id == mpd_song_get_id(c->song))
if (!mpd_run_seek_id(connection, seek_id, seek_target_time))
mpdclient_handle_error(c);
*/
case CMD_PAUSE:
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ break;
+
if (!mpd_run_pause(connection,
mpd_status_get_state(c->status) != MPD_STATE_PAUSE))
mpdclient_handle_error(c);
break;
case CMD_STOP:
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ break;
+
if (!mpd_run_stop(connection))
mpdclient_handle_error(c);
break;
break;
case CMD_TRACK_NEXT:
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ break;
+
if (!mpd_run_next(connection))
mpdclient_handle_error(c);
break;
break;
case CMD_TRACK_PREVIOUS:
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ break;
+
if (!mpd_run_previous(connection))
mpdclient_handle_error(c);
break;
case CMD_SHUFFLE:
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ break;
+
if (mpd_run_shuffle(connection))
screen_status_message(_("Shuffled playlist"));
else
break;
case CMD_CLEAR:
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ break;
+
if (mpdclient_cmd_clear(c))
screen_status_message(_("Cleared playlist"));
break;
case CMD_REPEAT:
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ break;
+
if (!mpd_run_repeat(connection,
!mpd_status_get_repeat(c->status)))
mpdclient_handle_error(c);
break;
case CMD_RANDOM:
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ break;
+
if (!mpd_run_random(connection,
!mpd_status_get_random(c->status)))
mpdclient_handle_error(c);
break;
case CMD_SINGLE:
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ break;
+
if (!mpd_run_single(connection,
!mpd_status_get_single(c->status)))
mpdclient_handle_error(c);
break;
case CMD_CONSUME:
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ break;
+
if (!mpd_run_consume(connection,
!mpd_status_get_consume(c->status)))
mpdclient_handle_error(c);
break;
case CMD_CROSSFADE:
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ break;
+
if (!mpd_run_crossfade(connection,
mpd_status_get_crossfade(c->status) > 0
? 0 : options.crossfade_time))
diff --git a/src/screen_artist.c b/src/screen_artist.c
index a3bda330ef9fb22877fe6ce3347418d46837cfe1..892587bcf03ee25f32c3d4fe736e5e76ae1bd474 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
assert(filter != NULL);
+ if (connection == NULL)
+ return;
+
str = utf8_to_locale(_filter);
if (table == MPD_TAG_ALBUM)
screen_status_printf("Adding album %s...", str);
diff --git a/src/screen_browser.c b/src/screen_browser.c
index 8802e5f93bb1eab29ed8d8ace445048a8fea495f..45b782a079378b5d2c3fbe84cae10e211c727fd2 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.c
{
struct mpd_connection *connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return false;
+
if (mpd_run_load(connection, mpd_playlist_get_path(playlist))) {
char *filename = utf8_to_locale(mpd_playlist_get_path(playlist));
screen_status_printf(_("Loading playlist %s..."),
diff --git a/src/screen_client.c b/src/screen_client.c
index 90364c0af0df2506daba2839a171beb385de7482..0b3484e3a371582f7590092055f8d3a00bd6886c 100644 (file)
--- a/src/screen_client.c
+++ b/src/screen_client.c
char *password;
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return false;
mpd_connection_clear_error(connection);
if (recursion > 2)
assert(mpdclient_is_connected(c));
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return;
id = mpd_run_update(connection, path);
if (id == 0) {
diff --git a/src/screen_file.c b/src/screen_file.c
index d9faa69ac66430032a736b971de0211b9a8db7dc..67dc3e081182da8addac2436b3b77b54103b1e8b 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
{
struct mpd_connection *connection;
- if (!mpdclient_is_connected(c))
- return;
-
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return;
mpd_send_list_meta(connection, current_path);
filelist_recv(filelist, connection);
char *str, *buf;
int key;
+ if (connection == NULL)
+ return;
+
list_window_get_range(browser.lw, &range);
for (unsigned i = range.start; i < range.end; ++i) {
struct filelist_entry *entry =
diff --git a/src/screen_outputs.c b/src/screen_outputs.c
index 22337da61f8920e554ce9fc109f5ad02ea8016bf..4a5b2f4cdaf4d9a24d2396ff26a6d0e59f6271ed 100644 (file)
--- a/src/screen_outputs.c
+++ b/src/screen_outputs.c
assert(mpd_outputs != NULL);
- if (!mpdclient_is_connected(c) ||
- output_index >= mpd_outputs->len)
+ if (output_index >= mpd_outputs->len)
return false;
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return false;
+
output = g_ptr_array_index(mpd_outputs, output_index);
if (!mpd_output_get_enabled(output)) {
assert(mpd_outputs != NULL);
- if (!mpdclient_is_connected(c))
+ connection = mpdclient_get_connection(c);
+ if (connection == NULL)
return;
- connection = mpdclient_get_connection(c);
mpd_send_outputs(connection);
while ((output = mpd_recv_output(connection)) != NULL) {
g_ptr_array_add(mpd_outputs, output);
diff --git a/src/screen_queue.c b/src/screen_queue.c
index 750abb01d451b784bb1256c532406748d1a9f5dd..7275734d08c70ce2ebe05555a855303c489098f3 100644 (file)
--- a/src/screen_queue.c
+++ b/src/screen_queue.c
/* send save command to mpd */
- filename_utf8 = locale_to_utf8(filename);
-
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return -1;
+
+ filename_utf8 = locale_to_utf8(filename);
if (!mpd_run_save(connection, filename_utf8)) {
if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_EXIST &&
break;
connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return true;
+
if (mpd_run_shuffle_range(connection, range.start, range.end))
screen_status_message(_("Shuffled playlist"));
else
diff --git a/src/screen_song.c b/src/screen_song.c
index 3696cd23957fe6ca30efa88a74b0fa25995078b2..4c774e8833b8fe30ece23b47d4c7eb063276b8d0 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.c
static void
screen_song_update(struct mpdclient *c)
{
+ struct mpd_connection *connection;
+
/* Clear all lines */
for (guint i = 0; i < current.lines->len; ++i)
g_free(g_ptr_array_index(current.lines, i));
}
/* Add some statistics about mpd */
- if (mpdclient_is_connected(c) &&
- !screen_song_add_stats(mpdclient_get_connection(c)))
+ connection = mpdclient_get_connection(c);
+ if (connection != NULL && !screen_song_add_stats(connection))
mpdclient_handle_error(c);
list_window_set_length(lw, current.lines->len);
diff --git a/src/utils.c b/src/utils.c
index 6042848bced918cab0378fdd4764a7014f7c826b..84db64a5b122211081fc0df2a02e206411befb51 100644 (file)
--- a/src/utils.c
+++ b/src/utils.c
struct mpd_connection *connection;
struct mpd_entity *entity;
- if (!mpdclient_is_connected(c))
+ connection = mpdclient_get_connection(c);
+ if (connection == NULL)
return list;
- connection = mpdclient_get_connection(c);
mpd_send_list_meta(connection, path);
while ((entity = mpd_recv_entity(connection)) != NULL) {