TagCommands.cxx 1.98 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"
#include "TagCommands.hxx"
22
#include "Request.hxx"
23
#include "client/Client.hxx"
24
#include "client/Response.hxx"
25
#include "tag/ParseName.hxx"
26
#include "Partition.hxx"
27
#include "util/ConstBuffer.hxx"
28 29

CommandResult
30
handle_addtagid(Client &client, Request args, Response &r)
31
{
32
	unsigned song_id = args.ParseUnsigned(0);
33

34
	const char *const tag_name = args[1];
35 36
	const TagType tag_type = tag_name_parse_i(tag_name);
	if (tag_type == TAG_NUM_OF_ITEM_TYPES) {
37
		r.FormatError(ACK_ERROR_ARG, "Unknown tag type: %s", tag_name);
38 39 40
		return CommandResult::ERROR;
	}

41
	const char *const value = args[2];
42

43
	client.GetPlaylist().AddSongIdTag(song_id, tag_type, value);
44 45 46 47
	return CommandResult::OK;
}

CommandResult
48
handle_cleartagid(Client &client, Request args, Response &r)
49
{
50
	unsigned song_id = args.ParseUnsigned(0);
51 52

	TagType tag_type = TAG_NUM_OF_ITEM_TYPES;
53 54
	if (args.size >= 2) {
		const char *const tag_name = args[1];
55 56
		tag_type = tag_name_parse_i(tag_name);
		if (tag_type == TAG_NUM_OF_ITEM_TYPES) {
57
			r.FormatError(ACK_ERROR_ARG,
58 59 60 61 62
				      "Unknown tag type: %s", tag_name);
			return CommandResult::ERROR;
		}
	}

63
	client.GetPlaylist().ClearSongIdTag(song_id, tag_type);
64 65
	return CommandResult::OK;
}