Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rewrite 'Search' interface

This patch removes CamelCase, removes some useless methods that could be added
in the future in the higher level library (like getNextArtist replaced by
get_next_tag), gives more intuitive names to methods, moves them to search.h and
adds doxygen documentation.
  • Loading branch information...
commit 11cfd40e39109d6f580fd1829dece46a2b3353eb 1 parent c4cc4f5
Marc Pavot authored
View
2  Makefile.am
@@ -20,6 +20,7 @@ mpdinclude_HEADERS = \
include/mpd/tag.h \
include/mpd/output.h \
include/mpd/pair.h \
+ include/mpd/search.h \
include/mpd/song.h \
include/mpd/stored_playlist.h
@@ -39,6 +40,7 @@ src_libmpdclient_la_SOURCES = \
src/pair.c \
src/entity.c \
src/idle.c \
+ src/search.c \
src/send.c \
src/socket.c src/socket.h \
src/song.c \
View
68 include/mpd/client.h
@@ -38,7 +38,6 @@
#include <mpd/command.h>
#include <mpd/song.h>
#include <mpd/directory.h>
-#include <mpd/tag.h>
#include <mpd/pair.h>
#include <mpd/stored_playlist.h>
@@ -52,23 +51,6 @@ extern "C" {
/* INFO COMMANDS AND STUFF */
-void mpd_sendSearchCommand(struct mpd_connection *connection, enum mpd_tag_type table,
- const char * str);
-
-void mpd_send_find(struct mpd_connection *connection, enum mpd_tag_type table,
- const char * str);
-
-/* LIST TAG COMMANDS */
-
-/* use this function fetch next artist entry, be sure to free the returned
- * string. NULL means there are no more. Best used with sendListArtists
- */
-char * mpd_getNextArtist(struct mpd_connection *connection);
-
-char * mpd_getNextAlbum(struct mpd_connection *connection);
-
-char * mpd_getNextTag(struct mpd_connection *connection, enum mpd_tag_type type);
-
/* SIMPLE COMMANDS */
int mpd_sendAddIdCommand(struct mpd_connection *connection, const char *file);
@@ -104,55 +86,7 @@ char *mpd_getNextCommand(struct mpd_connection *connection);
char *mpd_getNextHandler(struct mpd_connection *connection);
-char *mpd_getNextTagType(struct mpd_connection *connection);
-
-/**
- * @param connection a #mpd_connection
- * @param exact if to match exact
- *
- * starts a search, use mpd_addConstraintSearch to add
- * a constraint to the search, and mpd_commitSearch to do the actual search
- */
-void mpd_startSearch(struct mpd_connection *connection, int exact);
-
-/**
- * @param connection a #mpd_connection
- * @param type
- * @param name
- */
-void mpd_addConstraintSearch(struct mpd_connection *connection, enum mpd_tag_type type, const char *name);
-
-/**
- * @param connection a #mpd_connection
- */
-void mpd_commitSearch(struct mpd_connection *connection);
-
-/**
- * @param connection a #mpd_connection
- * @param type The type to search for
- *
- * starts a search for fields... f.e. get a list of artists would be:
- * @code
- * mpd_startFieldSearch(connection, MPD_TAG_ITEM_ARTIST);
- * mpd_commitSearch(connection);
- * @endcode
- *
- * or get a list of artist in genre "jazz" would be:
- * @code
- * mpd_startFieldSearch(connection, MPD_TAG_ITEM_ARTIST);
- * mpd_addConstraintSearch(connection, MPD_TAG_ITEM_GENRE, "jazz")
- * mpd_commitSearch(connection);
- * @endcode
- *
- * mpd_startSearch will return a list of songs (and you need mpd_getNextInfoEntity)
- * this one will return a list of only one field (the one specified with type) and you need
- * mpd_getNextTag to get the results
- */
-void mpd_startFieldSearch(struct mpd_connection *connection, enum mpd_tag_type type);
-
-void mpd_startPlaylistSearch(struct mpd_connection *connection, int exact);
-
-void mpd_startStatsSearch(struct mpd_connection *connection);
+char *mpd_get_next_tag_type(struct mpd_connection *connection);
#ifdef __cplusplus
}
View
12 include/mpd/command.h
@@ -237,18 +237,6 @@ mpd_send_listallinfo(struct mpd_connection *connection, const char *dir);
bool
mpd_send_lsinfo(struct mpd_connection *connection, const char *dir);
-/**
- * Request a list of all artists.
- */
-bool
-mpd_send_list_artist(struct mpd_connection *connection);
-
-/**
- * Request a list of all albums of an artist.
- */
-bool
-mpd_send_list_album(struct mpd_connection *connection, const char *artist);
-
bool
mpd_send_update(struct mpd_connection *connection, const char *path);
View
7 include/mpd/connection.h
@@ -105,7 +105,12 @@ mpd_get_server_version(const struct mpd_connection *connection);
#define COMMAND_LIST 1
#define COMMAND_LIST_OK 2
-void mpd_get_next_return_element(struct mpd_connection *connection);
+void
+mpd_get_next_return_element(struct mpd_connection *connection);
+
+char *
+mpd_get_next_return_element_named(struct mpd_connection *connection,
+ const char *name);
#ifdef __cplusplus
}
View
120 include/mpd/search.h
@@ -0,0 +1,120 @@
+/* libmpdclient
+ (c) 2003-2008 The Music Player Daemon Project
+ This project's homepage is: http://www.musicpd.org
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ - Neither the name of the Music Player Daemon nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef MPD_DB_H
+#define MPD_DB_H
+
+#include <mpd/connection.h>
+#include <mpd/tag.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @param connection a #mpd_connection
+ * @param type The type of the tag to get
+ *
+ * Use this function to get the next tagi of o given type.
+ * NULL means there are no more.
+ */
+char *mpd_get_next_tag(struct mpd_connection *connection,
+ enum mpd_tag_type type);
+
+/**
+ * @param connection a #mpd_connection
+ * @param type The tag type of the constraint
+ * @param value The value of the constaint
+ *
+ * Add a constraint to a search.
+ */
+void mpd_search_add_constraint(struct mpd_connection *connection,
+ enum mpd_tag_type type,
+ const char *value);
+
+/**
+ * @param connection a #mpd_connection
+ *
+ * Starts the real search with constraints added with
+ * mpd_search_add_constraint.
+ */
+void mpd_search_commit(struct mpd_connection *connection);
+
+
+/**
+ * @param connection a #mpd_connection
+ * @param exact if to match exact
+ *
+ * Search for songs in the db given certain constraints
+ * Use this method with mpd_search_add_constraint and mpd_search_commit
+ * Use mpd_getNextInfoEntity to get results of this method
+ */
+void mpd_search_db_songs(struct mpd_connection *connection,
+ int exact);
+
+/**
+ * @param connection a #mpd_connection
+ * @param exact if to match exact
+ *
+ * Search for songs in the playlist given certain constraints
+ * Use this method with mpd_search_add_constraint and mpd_search_commit
+ * Use mpd_getNextInfoEntity to get results of this method
+ */
+void mpd_search_playlist_songs(struct mpd_connection *connection,
+ int exact);
+
+/**
+ * @param connection a #mpd_connection
+ * @param type The type of the tags to search for
+ *
+ * Search for tags in the db given certain constraints
+ * Use this method with mpd_search_add_constraint and mpd_search_commit
+ * Use mpd_get_next_tag to get results of this method
+ */
+void mpd_search_db_tags(struct mpd_connection *connection,
+ enum mpd_tag_type type);
+
+/**
+ * @param connection a #mpd_connection
+ *
+ * Counts the number of songs and the total playtime given certain constraints
+ * Use this method with mpd_search_add_constraint and mpd_search_commit
+ * Use mpd_get_stats to get results of this method
+ */
+void mpd_count_db_songs(struct mpd_connection *connection);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
View
19 src/command.c
@@ -358,25 +358,6 @@ mpd_send_lsinfo(struct mpd_connection *connection, const char *dir)
return mpd_send_command(connection, "lsinfo", dir, NULL);
}
-static bool
-mpd_send_list(struct mpd_connection *connection,
- const char *table, const char *arg)
-{
- return mpd_send_command(connection, "list", table, arg, NULL);
-}
-
-bool
-mpd_send_list_artist(struct mpd_connection *connection)
-{
- return mpd_send_list(connection, "artist", NULL);
-}
-
-bool
-mpd_send_list_album(struct mpd_connection *connection, const char *artist)
-{
- return mpd_send_list(connection, "album", artist);
-}
-
bool
mpd_send_update(struct mpd_connection *connection, const char *path)
{
View
23 src/connection.c
@@ -335,3 +335,26 @@ void mpd_get_next_return_element(struct mpd_connection *connection)
}
}
+char *
+mpd_get_next_return_element_named(struct mpd_connection *connection,
+ const char *name)
+{
+ if (connection->doneProcessing || (connection->listOks &&
+ connection->doneListOk))
+ {
+ return NULL;
+ }
+
+ mpd_get_next_return_element(connection);
+ while (connection->pair != NULL) {
+ const struct mpd_pair *pair = connection->pair;
+
+ if (strcmp(pair->name, name) == 0)
+ return strdup(pair->value);
+
+ mpd_get_next_return_element(connection);
+ }
+
+ return NULL;
+}
+
View
7 src/example.c
@@ -33,6 +33,8 @@
#include <mpd/client.h>
#include <mpd/status.h>
#include <mpd/entity.h>
+#include <mpd/search.h>
+#include <mpd/tag.h>
#include <stdio.h>
#include <string.h>
@@ -218,14 +220,15 @@ int main(int argc, char ** argv) {
else if(argc==2 && strcmp(argv[1],"artists")==0) {
char * artist;
- mpd_send_list_artist(conn);
+ mpd_search_db_tags(conn, MPD_TAG_TYPE_ARTIST);
+ mpd_search_commit(conn);
if (mpd_get_error(conn) != MPD_ERROR_SUCCESS) {
fprintf(stderr,"%s\n", mpd_get_error_string(conn));
mpd_connection_close(conn);
return -1;
}
- while((artist = mpd_getNextArtist(conn))) {
+ while((artist = mpd_get_next_tag(conn, MPD_TAG_TYPE_ARTIST))) {
printf("%s\n",artist);
free(artist);
}
View
221 src/libmpdclient.c
@@ -51,28 +51,6 @@
#define INTLEN ((sizeof(int) * CHAR_BIT + 1) / 3 + 1)
#define LONGLONGLEN ((sizeof(long long) * CHAR_BIT + 1) / 3 + 1)
-static char * mpd_sanitizeArg(const char * arg) {
- size_t i;
- char * ret;
- register const char *c;
- register char *rc;
-
- /* instead of counting in that loop above, just
- * use a bit more memory and half running time
- */
- ret = malloc(strlen(arg) * 2 + 1);
-
- c = arg;
- rc = ret;
- for (i = strlen(arg)+1; i != 0; --i) {
- if (*c=='"' || *c=='\\')
- *rc++ = '\\';
- *(rc++) = *(c++);
- }
-
- return ret;
-}
-
void mpd_finishCommand(struct mpd_connection *connection)
{
while (!connection->doneProcessing) {
@@ -98,72 +76,6 @@ int mpd_nextListOkCommand(struct mpd_connection *connection)
return 0;
}
-static void
-mpd_sendInfoCommand(struct mpd_connection *connection, char *command)
-{
- mpd_send_command(connection, command, NULL);
-}
-
-static char *
-mpd_get_next_return_elementNamed(struct mpd_connection *connection,
- const char *name)
-{
- if (connection->doneProcessing || (connection->listOks &&
- connection->doneListOk))
- {
- return NULL;
- }
-
- mpd_get_next_return_element(connection);
- while (connection->pair != NULL) {
- const struct mpd_pair *pair = connection->pair;
-
- if (strcmp(pair->name, name) == 0)
- return strdup(pair->value);
-
- mpd_get_next_return_element(connection);
- }
-
- return NULL;
-}
-
-char *mpd_getNextTag(struct mpd_connection *connection, enum mpd_tag_type type)
-{
- if (type >= MPD_TAG_TYPE_COUNT ||
- type == MPD_TAG_TYPE_ANY)
- return NULL;
- if (type == MPD_TAG_TYPE_FILENAME)
- return mpd_get_next_return_elementNamed(connection, "file");
- return mpd_get_next_return_elementNamed(connection, mpdTagItemKeys[type]);
-}
-
-char * mpd_getNextArtist(struct mpd_connection *connection)
-{
- return mpd_get_next_return_elementNamed(connection,"Artist");
-}
-
-char * mpd_getNextAlbum(struct mpd_connection *connection)
-{
- return mpd_get_next_return_elementNamed(connection,"Album");
-}
-
-void
-mpd_sendSearchCommand(struct mpd_connection *connection, enum mpd_tag_type table,
- const char *str)
-{
- mpd_startSearch(connection, 0);
- mpd_addConstraintSearch(connection, table, str);
- mpd_commitSearch(connection);
-}
-
-void mpd_send_find(struct mpd_connection *connection, enum mpd_tag_type table,
- const char * str)
-{
- mpd_startSearch(connection, 1);
- mpd_addConstraintSearch(connection, table, str);
- mpd_commitSearch(connection);
-}
-
int
mpd_sendAddIdCommand(struct mpd_connection *connection, const char *file)
{
@@ -175,7 +87,7 @@ mpd_sendAddIdCommand(struct mpd_connection *connection, const char *file)
if (!ret)
return -1;
- string = mpd_get_next_return_elementNamed(connection, "Id");
+ string = mpd_get_next_return_element_named(connection, "Id");
if (string) {
retval = atoi(string);
free(string);
@@ -189,7 +101,7 @@ int mpd_getUpdateId(struct mpd_connection *connection)
char * jobid;
int ret = 0;
- jobid = mpd_get_next_return_elementNamed(connection,"updating_db");
+ jobid = mpd_get_next_return_element_named(connection,"updating_db");
if (jobid) {
ret = atoi(jobid);
free(jobid);
@@ -240,137 +152,16 @@ void mpd_sendCommandListEnd(struct mpd_connection *connection)
*/
char * mpd_getNextCommand(struct mpd_connection *connection)
{
- return mpd_get_next_return_elementNamed(connection, "command");
+ return mpd_get_next_return_element_named(connection, "command");
}
char * mpd_getNextHandler(struct mpd_connection *connection)
{
- return mpd_get_next_return_elementNamed(connection, "handler");
-}
-
-char * mpd_getNextTagType(struct mpd_connection *connection)
-{
- return mpd_get_next_return_elementNamed(connection, "tagtype");
-}
-
-void mpd_startSearch(struct mpd_connection *connection, int exact)
-{
- if (connection->request) {
- mpd_error_code(&connection->error, MPD_ERROR_STATE);
- mpd_error_message(&connection->error,
- "search already in progress");
- return;
- }
-
- if (exact) connection->request = strdup("find");
- else connection->request = strdup("search");
-}
-
-void mpd_startStatsSearch(struct mpd_connection *connection)
-{
- if (connection->request) {
- mpd_error_code(&connection->error, MPD_ERROR_STATE);
- mpd_error_message(&connection->error,
- "search already in progress");
- return;
- }
-
- connection->request = strdup("count");
-}
-
-void mpd_startPlaylistSearch(struct mpd_connection *connection, int exact)
-{
- if (connection->request) {
- mpd_error_code(&connection->error, MPD_ERROR_STATE);
- mpd_error_message(&connection->error,
- "search already in progress");
- return;
- }
-
- if (exact) connection->request = strdup("playlistfind");
- else connection->request = strdup("playlistsearch");
+ return mpd_get_next_return_element_named(connection, "handler");
}
-void mpd_startFieldSearch(struct mpd_connection *connection, enum mpd_tag_type type)
+char * mpd_get_next_tag_type(struct mpd_connection *connection)
{
- const char *strtype;
- int len;
-
- if (connection->request) {
- mpd_error_code(&connection->error, MPD_ERROR_STATE);
- mpd_error_message(&connection->error,
- "search already in progress");
- return;
- }
-
- if (type >= MPD_TAG_TYPE_COUNT) {
- mpd_error_code(&connection->error, MPD_ERROR_ARG);
- mpd_error_message(&connection->error,
- "invalid type specified");
- return;
- }
-
- strtype = mpdTagItemKeys[type];
-
- len = 5+strlen(strtype)+1;
- connection->request = malloc(len);
-
- snprintf(connection->request, len, "list %c%s",
- tolower(strtype[0]), strtype+1);
+ return mpd_get_next_return_element_named(connection, "tagtype");
}
-void
-mpd_addConstraintSearch(struct mpd_connection *connection,
- enum mpd_tag_type type, const char *name)
-{
- const char *strtype;
- char *arg;
- int len;
- char *string;
-
- if (!connection->request) {
- mpd_error_code(&connection->error, MPD_ERROR_STATE);
- mpd_error_message(&connection->error,
- "no search in progress");
- return;
- }
-
- if (type >= MPD_TAG_TYPE_COUNT) {
- mpd_error_code(&connection->error, MPD_ERROR_ARG);
- mpd_error_message(&connection->error,
- "invalid type specified");
- return;
- }
-
- if (name == NULL) {
- mpd_error_code(&connection->error, MPD_ERROR_ARG);
- mpd_error_message(&connection->error, "no name specified");
- return;
- }
-
- string = strdup(connection->request);
- strtype = mpdTagItemKeys[type];
- arg = mpd_sanitizeArg(name);
-
- len = strlen(string)+1+strlen(strtype)+2+strlen(arg)+2;
- connection->request = realloc(connection->request, len);
- snprintf(connection->request, len, "%s %c%s \"%s\"",
- string, tolower(strtype[0]), strtype+1, arg);
-
- free(string);
- free(arg);
-}
-
-void mpd_commitSearch(struct mpd_connection *connection)
-{
- if (!connection->request) {
- mpd_error_code(&connection->error, MPD_ERROR_STATE);
- mpd_error_message(&connection->error,
- "no search in progress");
- return;
- }
-
- mpd_sendInfoCommand(connection, connection->request);
-
- connection->request = NULL;
-}
View
211 src/search.c
@@ -0,0 +1,211 @@
+/* libmpdclient
+ (c) 2003-2008 The Music Player Daemon Project
+ This project's homepage is: http://www.musicpd.org
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ - Neither the name of the Music Player Daemon nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <mpd/search.h>
+#include <mpd/send.h>
+#include "internal.h"
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+static char *
+mpd_sanitize_arg(const char * arg)
+{
+ size_t i;
+ char * ret;
+ register const char *c;
+ register char *rc;
+
+ /* instead of counting in that loop above, just
+ * use a bit more memory and half running time
+ */
+ ret = malloc(strlen(arg) * 2 + 1);
+
+ c = arg;
+ rc = ret;
+ for (i = strlen(arg)+1; i != 0; --i) {
+ if (*c=='"' || *c=='\\')
+ *rc++ = '\\';
+ *(rc++) = *(c++);
+ }
+
+ return ret;
+}
+
+char *mpd_get_next_tag(struct mpd_connection *connection,
+ enum mpd_tag_type type)
+{
+ if (type >= MPD_TAG_TYPE_COUNT ||
+ type == MPD_TAG_TYPE_ANY)
+ return NULL;
+ if (type == MPD_TAG_TYPE_FILENAME)
+ return mpd_get_next_return_element_named(connection, "file");
+ return mpd_get_next_return_element_named(connection, mpdTagItemKeys[type]);
+}
+
+void
+mpd_search_add_constraint(struct mpd_connection *connection,
+ enum mpd_tag_type type,
+ const char *name)
+{
+ const char *strtype;
+ char *arg;
+ int len;
+ char *string;
+
+ if (!connection->request) {
+ mpd_error_code(&connection->error, MPD_ERROR_STATE);
+ mpd_error_message(&connection->error,
+ "no search in progress");
+ return;
+ }
+
+ if (type >= MPD_TAG_TYPE_COUNT) {
+ mpd_error_code(&connection->error, MPD_ERROR_ARG);
+ mpd_error_message(&connection->error,
+ "invalid type specified");
+ return;
+ }
+
+ if (name == NULL) {
+ mpd_error_code(&connection->error, MPD_ERROR_ARG);
+ mpd_error_message(&connection->error, "no name specified");
+ return;
+ }
+
+ string = strdup(connection->request);
+ strtype = mpdTagItemKeys[type];
+ arg = mpd_sanitize_arg(name);
+
+ len = strlen(string)+1+strlen(strtype)+2+strlen(arg)+2;
+ connection->request = realloc(connection->request, len);
+ snprintf(connection->request, len, "%s %c%s \"%s\"",
+ string, tolower(strtype[0]), strtype+1, arg);
+
+ free(string);
+ free(arg);
+}
+
+void
+mpd_search_commit(struct mpd_connection *connection)
+{
+ if (!connection->request) {
+ mpd_error_code(&connection->error, MPD_ERROR_STATE);
+ mpd_error_message(&connection->error,
+ "no search in progress");
+ return;
+ }
+
+ mpd_send_command(connection, connection->request, NULL);
+
+ connection->request = NULL;
+}
+
+void
+mpd_search_db_songs(struct mpd_connection *connection,
+ int exact)
+{
+ if (connection->request) {
+ mpd_error_code(&connection->error, MPD_ERROR_STATE);
+ mpd_error_message(&connection->error,
+ "search already in progress");
+ return;
+ }
+
+ if (exact)
+ connection->request = strdup("find");
+ else
+ connection->request = strdup("search");
+}
+
+void
+mpd_count_db_songs(struct mpd_connection *connection)
+{
+ if (connection->request) {
+ mpd_error_code(&connection->error, MPD_ERROR_STATE);
+ mpd_error_message(&connection->error,
+ "search already in progress");
+ return;
+ }
+
+ connection->request = strdup("count");
+}
+
+void
+mpd_search_playlist_songs(struct mpd_connection *connection,
+ int exact)
+{
+ if (connection->request) {
+ mpd_error_code(&connection->error, MPD_ERROR_STATE);
+ mpd_error_message(&connection->error,
+ "search already in progress");
+ return;
+ }
+
+ if (exact)
+ connection->request = strdup("playlistfind");
+ else
+ connection->request = strdup("playlistsearch");
+}
+
+void
+mpd_search_db_tags(struct mpd_connection *connection,
+ enum mpd_tag_type type)
+{
+ const char *strtype;
+ int len;
+
+ if (connection->request) {
+ mpd_error_code(&connection->error, MPD_ERROR_STATE);
+ mpd_error_message(&connection->error,
+ "search already in progress");
+ return;
+ }
+
+ if (type >= MPD_TAG_TYPE_COUNT) {
+ mpd_error_code(&connection->error, MPD_ERROR_ARG);
+ mpd_error_message(&connection->error,
+ "invalid type specified");
+ return;
+ }
+
+ strtype = mpdTagItemKeys[type];
+
+ len = 5+strlen(strtype)+1;
+ connection->request = malloc(len);
+
+ snprintf(connection->request, len, "list %c%s",
+ tolower(strtype[0]), strtype+1);
+}
+
View
7 test/main.c
@@ -34,6 +34,8 @@
#include <mpd/status.h>
#include <mpd/song.h>
#include <mpd/entity.h>
+#include <mpd/search.h>
+#include <mpd/tag.h>
#include <stdio.h>
#include <string.h>
@@ -304,11 +306,12 @@ test_list_artists(struct mpd_connection *conn)
char *artist;
int first = 1;
- mpd_send_list_artist(conn);
+ mpd_search_db_tags(conn, MPD_TAG_TYPE_ARTIST);
+ mpd_search_commit(conn);
CHECK_CONNECTION(conn);
LOG_INFO("%s: ", "Artists list");
- while ((artist = mpd_getNextArtist(conn))) {
+ while ((artist = mpd_get_next_tag(conn, MPD_TAG_TYPE_ARTIST))) {
if (first) {
printf(" %s", artist);
first = 0;
Please sign in to comment.
Something went wrong with that request. Please try again.