示例#1
0
文件: entity.c 项目: Fyzick/capstone
struct mpd_entity *
mpd_recv_entity(struct mpd_connection *connection)
{
	struct mpd_pair *pair;
	struct mpd_entity *entity;

	pair = mpd_recv_pair(connection);
	if (pair == NULL)
		return NULL;

	entity = mpd_entity_begin(pair);
	mpd_return_pair(connection, pair);
	if (entity == NULL) {
		mpd_error_entity(&connection->error);
		return NULL;
	}

	while ((pair = mpd_recv_pair(connection)) != NULL &&
	       mpd_entity_feed(entity, pair))
		mpd_return_pair(connection, pair);

	if (mpd_error_is_defined(&connection->error)) {
		mpd_entity_free(entity);
		return NULL;
	}

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

	return entity;
}
示例#2
0
文件: cstats.c 项目: Fyzick/capstone
struct mpd_stats *
mpd_recv_stats(struct mpd_connection *connection)
{
	struct mpd_stats * stats;
	struct mpd_pair *pair;

	assert(connection != NULL);

	if (mpd_error_is_defined(&connection->error))
		/* refuse to receive a response if the connection's
		   state is not clean */
		return NULL;

	stats = mpd_stats_begin();
	if (stats == NULL) {
		mpd_error_code(&connection->error, MPD_ERROR_OOM);
		return NULL;
	}

	/* read and parse all response lines */
	while ((pair = mpd_recv_pair(connection)) != NULL) {
		mpd_stats_feed(stats, pair);
		mpd_return_pair(connection, pair);
	}

	if (mpd_error_is_defined(&connection->error)) {
		/* an error has occurred; roll back */
		mpd_stats_free(stats);
		return NULL;
	}

	return stats;
}
示例#3
0
文件: song.c 项目: Fyzick/capstone
struct mpd_song *
mpd_recv_song(struct mpd_connection *connection)
{
	struct mpd_pair *pair;
	struct mpd_song *song;

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

	song = mpd_song_begin(pair);
	mpd_return_pair(connection, pair);
	if (song == NULL) {
		mpd_error_entity(&connection->error);
		return NULL;
	}

	while ((pair = mpd_recv_pair(connection)) != NULL &&
	       mpd_song_feed(song, pair))
		mpd_return_pair(connection, pair);

	if (mpd_error_is_defined(&connection->error)) {
		mpd_song_free(song);
		return NULL;
	}

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

	return song;
}
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;
}
示例#5
0
struct mpd_directory *
mpd_recv_directory(struct mpd_connection *connection)
{
	struct mpd_pair *pair;
	struct mpd_directory *directory;

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

	directory = mpd_directory_begin(pair);
	mpd_return_pair(connection, pair);
	if (directory == NULL) {
		mpd_error_entity(&connection->error);
		return NULL;
	}

	while ((pair = mpd_recv_pair(connection)) != NULL &&
	       mpd_directory_feed(directory, pair))
		mpd_return_pair(connection, pair);

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

		mpd_directory_free(directory);
		return NULL;
	}

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

	return directory;
}
示例#6
0
文件: command.c 项目: somecommand/mpc
int
cmd_replaygain(int argc, char **argv, struct mpd_connection *connection)
{
	/* libmpdclient 2.0 doesn't support these commands yet, we
	   have to roll our own with mpd_send_command() */

	if (mpd_connection_cmp_server_version(connection, 0, 16, 0) < 0)
		fprintf(stderr, "warning: MPD 0.16 required for this command\n");

	if (argc == 0) {
		struct mpd_pair *pair;

		mpd_send_command(connection, "replay_gain_status", NULL);
		while ((pair = mpd_recv_pair(connection)) != NULL) {
			printf("%s: %s\n", pair->name, pair->value);
			mpd_return_pair(connection, pair);
		}

		my_finishCommand(connection);
	} else {
		mpd_send_command(connection, "replay_gain_mode",
				 argv[0], NULL);
		my_finishCommand(connection);
	}

	return 0;
}
示例#7
0
文件: recv.c 项目: Fyzick/capstone
struct mpd_pair *
mpd_recv_pair_named(struct mpd_connection *connection, const char *name)
{
	struct mpd_pair *pair;

	while ((pair = mpd_recv_pair(connection)) != NULL) {
		if (strcmp(pair->name, name) == 0)
			return pair;

		mpd_return_pair(connection, pair);
	}

	return NULL;
}
示例#8
0
struct mpd_message *
mpd_recv_message(struct mpd_connection *connection)
{
	struct mpd_message *message;
	struct mpd_pair *pair;

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

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

	while ((pair = mpd_recv_pair(connection)) != NULL &&
	       mpd_message_feed(message, pair))
		mpd_return_pair(connection, pair);

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

		mpd_message_free(message);
		return NULL;
	}

	mpd_enqueue_pair(connection, pair);

	if (mpd_message_get_text(message) == NULL) {
		mpd_error_code(&connection->error, MPD_ERROR_MALFORMED);
		mpd_error_message(&connection->error,
				  "No 'message' line received");
		mpd_message_free(message);
		return NULL;
	}

	return message;
}
示例#9
0
文件: command.c 项目: daaang/mpc
int
cmd_replaygain(int argc, char **argv, struct mpd_connection *connection)
{
	/* libmpdclient 2.0 doesn't support these commands yet, we
	   have to roll our own with mpd_send_command() */

	if (argc == 0) {
		mpd_send_command(connection, "replay_gain_status", NULL);

		struct mpd_pair *pair;
		while ((pair = mpd_recv_pair(connection)) != NULL) {
			printf("%s: %s\n", pair->name, pair->value);
			mpd_return_pair(connection, pair);
		}

		my_finishCommand(connection);
	} else {
		mpd_send_command(connection, "replay_gain_mode",
				 argv[0], NULL);
		my_finishCommand(connection);
	}

	return 0;
}