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;
}
示例#2
0
文件: entity.c 项目: Fyzick/capstone
static bool
mpd_entity_feed_first(struct mpd_entity *entity, const struct mpd_pair *pair)
{
	if (strcmp(pair->name, "file") == 0) {
		entity->type = MPD_ENTITY_TYPE_SONG;
		entity->info.song = mpd_song_begin(pair);
		if (entity->info.song == NULL)
			return false;
	} else if (strcmp(pair->name, "directory") == 0) {
		entity->type = MPD_ENTITY_TYPE_DIRECTORY;
		entity->info.directory = mpd_directory_begin(pair);
		if (entity->info.directory == NULL)
			return false;
	} else if (strcmp(pair->name, "playlist") == 0) {
		entity->type = MPD_ENTITY_TYPE_PLAYLIST;
		entity->info.playlistFile = mpd_playlist_begin(pair);
		if (entity->info.playlistFile == NULL)
			return false;
	} else {
		entity->type = MPD_ENTITY_TYPE_UNKNOWN;
	}

	return true;
}