Skip to content

Commit 7b5b6b1

Browse files
authored
Merge pull request #145 from jcorporation/stringnormalization
Support stringnormalization command (MPD 0.25)
2 parents 48a6c33 + f94bbe3 commit 7b5b6b1

File tree

6 files changed

+348
-0
lines changed

6 files changed

+348
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
libmpdclient 2.24 (not yet released)
2+
* support MPD protocol 0.25
3+
- stringnormalization
24

35
libmpdclient 2.23 (2025/06/24)
46
* support MPD protocol 0.24.0

include/mpd/client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "stats.h"
5858
#include "status.h"
5959
#include "sticker.h"
60+
#include "stringnormalization.h"
6061

6162
/* this is a generated header and may be installed in a different
6263
filesystem tree, therefore we can't use just "version.h" */

include/mpd/stringnormalization.h

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright The Music Player Daemon Project
3+
4+
#ifndef LIBMPDCLIENT_STRINGNORMALIZATION_H
5+
#define LIBMPDCLIENT_STRINGNORMALIZATION_H
6+
7+
#include "recv.h"
8+
#include "compiler.h"
9+
10+
#include <stdbool.h>
11+
12+
/**
13+
* @since libmpdclient 2.24
14+
*/
15+
enum mpd_stringnormalization_option
16+
{
17+
/**
18+
* Special value returned by mpd_stringnormalization_parse() when an
19+
* unknown name was passed.
20+
*/
21+
MPD_STRINGNORMALIZATION_UNKNOWN = -1,
22+
23+
MPD_STRINGNORMALIZATION_STRIP_DIACRITICS,
24+
25+
/* IMPORTANT: the ordering above must be
26+
retained, or else the libmpdclient ABI breaks */
27+
28+
MPD_STRINGNORMALIZATION_COUNT
29+
};
30+
31+
#ifdef __cplusplus
32+
extern "C" {
33+
#endif
34+
35+
/**
36+
* Looks up the name of the specified stringnormalization option.
37+
*
38+
* @return the name, or NULL if the tag type is not valid
39+
*/
40+
const char *
41+
mpd_stringnormalization_name(enum mpd_stringnormalization_option option);
42+
43+
/**
44+
* Parses a stringnormalization option name, and returns its #mpd_protocol_feature value.
45+
*
46+
* @return a #mpd_protocol_feature value, or MPD_FEATURE_UNKNOWN if the name was
47+
* not recognized
48+
*/
49+
enum mpd_stringnormalization_option
50+
mpd_stringnormalization_name_parse(const char *name);
51+
52+
/**
53+
* Requests a list of enabled stringnormalization options.
54+
* Use mpd_recv_stringnormalization_pair() to obtain the list of
55+
* "option" pairs.
56+
*
57+
* @param connection the connection to MPD
58+
* @return true on success, false on error
59+
*
60+
* @since libmpdclient 2.24, MPD 0.25
61+
*/
62+
bool
63+
mpd_send_list_stringnormalization(struct mpd_connection *connection);
64+
65+
/**
66+
* Requests a list of available protocol features.
67+
* Use mpd_recv_stringnormalization_pair() to obtain the list of
68+
* "stringnormalization option" pairs.
69+
*
70+
* @param connection the connection to MPD
71+
* @return true on success, false on error
72+
*
73+
* @since libmpdclient 2.24, MPD 0.25
74+
*/
75+
bool
76+
mpd_send_list_stringnormalization_available(struct mpd_connection *connection);
77+
78+
/**
79+
* Receives the next stringnormalization option. Call this in a loop after
80+
* mpd_send_list_stringnormalization().
81+
*
82+
* Free the return value with mpd_return_pair().
83+
*
84+
* @param connection a #mpd_connection
85+
* @returns a "stringnormalization option" pair, or NULL on error or if the end of the
86+
* response is reached
87+
*
88+
* @since libmpdclient 2.24, MPD 0.25
89+
*/
90+
mpd_malloc
91+
static inline struct mpd_pair *
92+
mpd_recv_stringnormalization_pair(struct mpd_connection *connection)
93+
{
94+
return mpd_recv_pair_named(connection, "stringnormalization");
95+
}
96+
97+
/**
98+
* Disables one or more stringnormalization option from the list of stringnormalization options.
99+
*
100+
* @param connection the connection to MPD
101+
* @param options an array of stringnormalization options to disable
102+
* @param n the number of protocol features in the array
103+
* @return true on success, false on error
104+
*
105+
* @since libmpdclient 2.24, MPD 0.25
106+
*/
107+
bool
108+
mpd_send_disable_stringnormalization(struct mpd_connection *connection,
109+
const enum mpd_stringnormalization_option *options, unsigned n);
110+
111+
/**
112+
* Shortcut for mpd_send_disable_stringnormalization() and mpd_response_finish().
113+
*
114+
* @since libmpdclient 2.24, MPD 0.25
115+
*/
116+
bool
117+
mpd_run_disable_stringnormalization(struct mpd_connection *connection,
118+
const enum mpd_stringnormalization_option *options, unsigned n);
119+
120+
/**
121+
* Re-enable one or more stringnormalization options from the list of stringnormalization options
122+
* for this client.
123+
*
124+
* @param connection the connection to MPD
125+
* @param options an array of stringnormalization options to enable
126+
* @param n the number of protocol features in the array
127+
* @return true on success, false on error
128+
*
129+
* @since libmpdclient 2.24, MPD 0.25
130+
*/
131+
bool
132+
mpd_send_enable_stringnormalization(struct mpd_connection *connection,
133+
const enum mpd_stringnormalization_option *options, unsigned n);
134+
135+
/**
136+
* Shortcut for mpd_send_enable_stringnormalization() and mpd_response_finish().
137+
*
138+
* @since libmpdclient 2.24, MPD 0.25
139+
*/
140+
bool
141+
mpd_run_enable_stringnormalization(struct mpd_connection *connection,
142+
const enum mpd_stringnormalization_option *options, unsigned n);
143+
144+
/**
145+
* Clear the list of enabled stringnormalization options for this client.
146+
*
147+
* @param connection the connection to MPD
148+
* @return true on success, false on error
149+
*
150+
* @since libmpdclient 2.24, MPD 0.25
151+
*/
152+
bool
153+
mpd_send_clear_stringnormalization(struct mpd_connection *connection);
154+
155+
/**
156+
* Shortcut for mpd_send_clear_stringnormalization() and mpd_response_finish().
157+
*
158+
* @since libmpdclient 2.24, MPD 0.25
159+
*/
160+
bool
161+
mpd_run_clear_stringnormalization(struct mpd_connection *connection);
162+
163+
/**
164+
* Enable all available stringnormalization options for this client.
165+
*
166+
* @param connection the connection to MPD
167+
* @return true on success, false on error
168+
*
169+
* @since libmpdclient 2.24, MPD 0.25
170+
*/
171+
bool
172+
mpd_send_all_stringnormalization(struct mpd_connection *connection);
173+
174+
/**
175+
* Shortcut for mpd_send_all_stringnormalization() and mpd_response_finish().
176+
*
177+
* @since libmpdclient 2.24, MPD 0.25
178+
*/
179+
bool
180+
mpd_run_all_stringnormalization(struct mpd_connection *connection);
181+
182+
#ifdef __cplusplus
183+
}
184+
#endif
185+
186+
#endif

libmpdclient.ld

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,20 @@ global:
468468
mpd_lookup_consume_state;
469469
mpd_parse_consume_state;
470470

471+
/* mpd/stringnormalization.h */
472+
mpd_stringnormalization_name;
473+
mpd_stringnormalization_name_parse;
474+
mpd_send_list_stringnormalization;
475+
mpd_send_list_stringnormalization_available;
476+
mpd_send_disable_stringnormalization;
477+
mpd_run_disable_stringnormalization;
478+
mpd_send_enable_stringnormalization;
479+
mpd_run_enable_stringnormalization;
480+
mpd_send_clear_stringnormalization;
481+
mpd_run_clear_stringnormalization;
482+
mpd_send_all_stringnormalization;
483+
mpd_run_all_stringnormalization;
484+
471485
/* mpd/tag.h */
472486
mpd_tag_name;
473487
mpd_tag_name_parse;

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ libmpdclient = library('mpdclient',
155155
'src/albumart.c',
156156
'src/readpicture.c',
157157
'src/position.c',
158+
'src/stringnormalization.c',
158159
link_depends: [
159160
'libmpdclient.ld'
160161
],

src/stringnormalization.c

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright The Music Player Daemon Project
3+
4+
#include <mpd/stringnormalization.h>
5+
#include <mpd/send.h>
6+
#include <mpd/recv.h>
7+
#include <mpd/response.h>
8+
#include "internal.h"
9+
10+
#include <assert.h>
11+
#include <stddef.h>
12+
#include <string.h>
13+
14+
static const char *const mpd_stringnormalization_options[MPD_STRINGNORMALIZATION_COUNT] =
15+
{
16+
[MPD_STRINGNORMALIZATION_STRIP_DIACRITICS] = "strip_diacritics",
17+
};
18+
19+
const char *
20+
mpd_stringnormalization_name(enum mpd_stringnormalization_option option)
21+
{
22+
if ((unsigned)option >= MPD_STRINGNORMALIZATION_COUNT)
23+
return NULL;
24+
25+
return mpd_stringnormalization_options[option];
26+
}
27+
28+
enum mpd_stringnormalization_option
29+
mpd_stringnormalization_name_parse(const char *name)
30+
{
31+
assert(name != NULL);
32+
33+
for (unsigned i = 0; i < MPD_STRINGNORMALIZATION_COUNT; ++i)
34+
if (strcmp(name, mpd_stringnormalization_options[i]) == 0)
35+
return (enum mpd_stringnormalization_option)i;
36+
37+
return MPD_STRINGNORMALIZATION_UNKNOWN;
38+
}
39+
40+
bool
41+
mpd_send_list_stringnormalization(struct mpd_connection *connection)
42+
{
43+
return mpd_send_command(connection, "stringnormalization", NULL);
44+
}
45+
46+
bool
47+
mpd_send_list_stringnormalization_available(struct mpd_connection *connection)
48+
{
49+
return mpd_send_command(connection, "stringnormalization", "available", NULL);
50+
}
51+
52+
static bool
53+
mpd_send_stringnormalization_v(struct mpd_connection *connection,
54+
const char *sub_command,
55+
const enum mpd_stringnormalization_option *options, unsigned n)
56+
{
57+
assert(connection != NULL);
58+
assert(options != NULL);
59+
assert(n > 0);
60+
61+
if (mpd_error_is_defined(&connection->error))
62+
return false;
63+
64+
char buffer[1024] = "stringnormalization ";
65+
strcat(buffer, sub_command);
66+
size_t length = strlen(buffer);
67+
68+
for (unsigned i = 0; i < n; ++i) {
69+
const char *t = mpd_stringnormalization_name(options[i]);
70+
assert(t != NULL);
71+
size_t t_length = strlen(t);
72+
73+
if (length + 1 + t_length + 1 > sizeof(buffer)) {
74+
mpd_error_code(&connection->error, MPD_ERROR_ARGUMENT);
75+
mpd_error_message(&connection->error,
76+
"Stringnormalization list is too long");
77+
return false;
78+
}
79+
80+
buffer[length++] = ' ';
81+
memcpy(buffer + length, t, t_length);
82+
length += t_length;
83+
}
84+
85+
buffer[length] = 0;
86+
87+
return mpd_send_command(connection, buffer, NULL);
88+
}
89+
90+
bool
91+
mpd_send_disable_stringnormalization(struct mpd_connection *connection,
92+
const enum mpd_stringnormalization_option *options, unsigned n)
93+
{
94+
return mpd_send_stringnormalization_v(connection, "disable", options, n);
95+
}
96+
97+
bool
98+
mpd_run_disable_stringnormalization(struct mpd_connection *connection,
99+
const enum mpd_stringnormalization_option *options, unsigned n)
100+
{
101+
return mpd_send_disable_stringnormalization(connection, options, n) &&
102+
mpd_response_finish(connection);
103+
}
104+
105+
bool
106+
mpd_send_enable_stringnormalization(struct mpd_connection *connection,
107+
const enum mpd_stringnormalization_option *options, unsigned n)
108+
{
109+
return mpd_send_stringnormalization_v(connection, "enable", options, n);
110+
}
111+
112+
bool
113+
mpd_run_enable_stringnormalization(struct mpd_connection *connection,
114+
const enum mpd_stringnormalization_option *options, unsigned n)
115+
{
116+
return mpd_send_enable_stringnormalization(connection, options, n) &&
117+
mpd_response_finish(connection);
118+
}
119+
120+
bool
121+
mpd_send_clear_stringnormalization(struct mpd_connection *connection)
122+
{
123+
return mpd_send_command(connection, "stringnormalization", "clear", NULL);
124+
}
125+
126+
bool
127+
mpd_run_clear_stringnormalization(struct mpd_connection *connection)
128+
{
129+
return mpd_send_clear_stringnormalization(connection) &&
130+
mpd_response_finish(connection);
131+
}
132+
133+
bool
134+
mpd_send_all_stringnormalization(struct mpd_connection *connection)
135+
{
136+
return mpd_send_command(connection, "stringnormalization", "all", NULL);
137+
}
138+
139+
bool
140+
mpd_run_all_stringnormalization(struct mpd_connection *connection)
141+
{
142+
return mpd_send_all_stringnormalization(connection) &&
143+
mpd_response_finish(connection);
144+
}

0 commit comments

Comments
 (0)