Code

check the return value of mpdclient_get_connection()
[ncmpc.git] / src / player_command.c
index 3b8476daf3924b08aec875c17ac8c74f5a7c876e..54664e58e9bdb8c6a5ccc78a7ec0f4f0a505d5ff 100644 (file)
@@ -37,13 +37,12 @@ commit_seek(struct mpdclient *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);
@@ -102,12 +101,18 @@ handle_player_command(struct mpdclient *c, command_t cmd)
                */
        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;
@@ -129,6 +134,9 @@ handle_player_command(struct mpdclient *c, command_t cmd)
                break;
        case CMD_TRACK_NEXT:
                connection = mpdclient_get_connection(c);
+               if (connection == NULL)
+                       break;
+
                if (!mpd_run_next(connection))
                        mpdclient_handle_error(c);
                break;
@@ -147,11 +155,17 @@ handle_player_command(struct mpdclient *c, command_t cmd)
                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
@@ -159,35 +173,53 @@ handle_player_command(struct mpdclient *c, command_t cmd)
                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))