Exemple #1
0
bool
mpd_entity_feed(struct mpd_entity *entity, const struct mpd_pair *pair)
{
	assert(pair != NULL);
	assert(pair->name != NULL);
	assert(pair->value != NULL);

	if (strcmp(pair->name, "file") == 0 ||
	    strcmp(pair->name, "directory") == 0 ||
	    strcmp(pair->name, "playlist") == 0)
		return false;

	switch (entity->type) {
	case MPD_ENTITY_TYPE_UNKNOWN:
		break;

	case MPD_ENTITY_TYPE_DIRECTORY:
		mpd_directory_feed(entity->info.directory, pair);
		break;

	case MPD_ENTITY_TYPE_SONG:
		mpd_song_feed(entity->info.song, pair);
		break;

	case MPD_ENTITY_TYPE_PLAYLIST:
		mpd_playlist_feed(entity->info.playlistFile, pair);
		break;
	}

	return true;
}
struct mpd_playlist *
mpd_recv_playlist(struct mpd_connection *connection)
{
	struct mpd_pair *pair;
	struct mpd_playlist *playlist;

	pair = mpd_recv_pair_named(connection, "playlist");
	if (pair == NULL)
		return NULL;

	playlist = mpd_playlist_begin(pair);
	mpd_return_pair(connection, pair);
	if (playlist == NULL) {
		mpd_error_code(&connection->error, MPD_ERROR_OOM);
		return NULL;
	}

	while ((pair = mpd_recv_pair(connection)) != NULL &&
	       mpd_playlist_feed(playlist, pair))
		mpd_return_pair(connection, pair);

	if (mpd_error_is_defined(&connection->error)) {
		assert(pair == NULL);

		mpd_playlist_free(playlist);
		return NULL;
	}

	/* unread this pair for the next mpd_recv_playlist() call */
	mpd_enqueue_pair(connection, pair);

	return playlist;
}