output: add _get_plugin()
[libmpdclient.git] / src / capabilities.c
bloba9f4572882684d70a0aebba5670c3449d6b398f4
1 /* libmpdclient
2 (c) 2003-2017 The Music Player Daemon Project
3 This project's homepage is: http://www.musicpd.org
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
9 - Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
12 - Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <mpd/capabilities.h>
30 #include <mpd/send.h>
31 #include <mpd/recv.h>
32 #include <mpd/response.h>
33 #include "internal.h"
35 #include <assert.h>
36 #include <stddef.h>
37 #include <string.h>
39 bool
40 mpd_send_allowed_commands(struct mpd_connection *connection)
42 return mpd_send_command(connection, "commands", NULL);
45 bool
46 mpd_send_disallowed_commands(struct mpd_connection *connection)
48 return mpd_send_command(connection, "notcommands", NULL);
51 bool
52 mpd_send_list_url_schemes(struct mpd_connection *connection)
54 return mpd_send_command(connection, "urlhandlers", NULL);
57 bool
58 mpd_send_list_tag_types(struct mpd_connection *connection)
60 return mpd_send_command(connection, "tagtypes", NULL);
63 static bool
64 mpd_send_tag_types_v(struct mpd_connection *connection,
65 const char *sub_command,
66 const enum mpd_tag_type *types, unsigned n)
68 assert(connection != NULL);
69 assert(types != NULL);
70 assert(n > 0);
72 if (mpd_error_is_defined(&connection->error))
73 return false;
75 char buffer[1024] = "tagtypes ";
76 strcat(buffer, sub_command);
77 size_t length = strlen(buffer);
79 for (unsigned i = 0; i < n; ++i) {
80 const char *t = mpd_tag_name(types[i]);
81 assert(t != NULL);
82 size_t t_length = strlen(t);
84 if (length + 1 + t_length + 1 > sizeof(buffer)) {
85 mpd_error_code(&connection->error, MPD_ERROR_ARGUMENT);
86 mpd_error_message(&connection->error,
87 "Tag list is too long");
88 return false;
91 buffer[length++] = ' ';
92 memcpy(buffer + length, t, t_length);
93 length += t_length;
96 buffer[length] = 0;
98 return mpd_send_command(connection, buffer, NULL);
101 bool
102 mpd_send_disable_tag_types(struct mpd_connection *connection,
103 const enum mpd_tag_type *types, unsigned n)
105 return mpd_send_tag_types_v(connection, "disable", types, n);
108 bool
109 mpd_run_disable_tag_types(struct mpd_connection *connection,
110 const enum mpd_tag_type *types, unsigned n)
112 return mpd_send_disable_tag_types(connection, types, n) &&
113 mpd_response_finish(connection);
116 bool
117 mpd_send_enable_tag_types(struct mpd_connection *connection,
118 const enum mpd_tag_type *types, unsigned n)
120 return mpd_send_tag_types_v(connection, "enable", types, n);
123 bool
124 mpd_run_enable_tag_types(struct mpd_connection *connection,
125 const enum mpd_tag_type *types, unsigned n)
127 return mpd_send_enable_tag_types(connection, types, n) &&
128 mpd_response_finish(connection);
131 bool
132 mpd_send_clear_tag_types(struct mpd_connection *connection)
134 return mpd_send_command(connection, "tagtypes", "clear", NULL);
137 bool
138 mpd_run_clear_tag_types(struct mpd_connection *connection)
140 return mpd_send_clear_tag_types(connection) &&
141 mpd_response_finish(connection);