TagCommands.cxx 1.96 KB
Newer Older
1
/*
2
 * Copyright 2003-2018 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * 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 "TagCommands.hxx"
21
#include "Request.hxx"
22
#include "client/Client.hxx"
23
#include "client/Response.hxx"
24
#include "tag/ParseName.hxx"
25
#include "Partition.hxx"
26
#include "util/ConstBuffer.hxx"
27 28

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

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

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

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

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

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

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