diff options
Diffstat (limited to 'src/sticker')
-rw-r--r-- | src/sticker/Match.hxx | 31 | ||||
-rw-r--r-- | src/sticker/SongSticker.cxx | 3 | ||||
-rw-r--r-- | src/sticker/SongSticker.hxx | 5 | ||||
-rw-r--r-- | src/sticker/StickerDatabase.cxx | 17 | ||||
-rw-r--r-- | src/sticker/StickerDatabase.hxx | 4 |
5 files changed, 55 insertions, 5 deletions
diff --git a/src/sticker/Match.hxx b/src/sticker/Match.hxx new file mode 100644 index 000000000..f91e70b40 --- /dev/null +++ b/src/sticker/Match.hxx @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * 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. + */ + +#ifndef MPD_STICKER_MATCH_HXX +#define MPD_STICKER_MATCH_HXX + +enum class StickerOperator { + /** + * Matches if a sticker with the specified name exists. The + * "value" parameter is ignored (must be nullptr). + */ + EXISTS, +}; + +#endif diff --git a/src/sticker/SongSticker.cxx b/src/sticker/SongSticker.cxx index 0b317bf9e..5e5793b70 100644 --- a/src/sticker/SongSticker.cxx +++ b/src/sticker/SongSticker.cxx @@ -97,6 +97,7 @@ sticker_song_find_cb(const char *uri, const char *value, void *user_data) bool sticker_song_find(const Database &db, const char *base_uri, const char *name, + StickerOperator op, const char *value, void (*func)(const LightSong &song, const char *value, void *user_data), void *user_data, @@ -119,7 +120,7 @@ sticker_song_find(const Database &db, const char *base_uri, const char *name, data.base_uri_length = strlen(data.base_uri); - bool success = sticker_find("song", data.base_uri, name, + bool success = sticker_find("song", data.base_uri, name, op, value, sticker_song_find_cb, &data, error); free(allocated); diff --git a/src/sticker/SongSticker.hxx b/src/sticker/SongSticker.hxx index 918046d0e..ec4f1b344 100644 --- a/src/sticker/SongSticker.hxx +++ b/src/sticker/SongSticker.hxx @@ -20,6 +20,7 @@ #ifndef MPD_SONG_STICKER_HXX #define MPD_SONG_STICKER_HXX +#include "Match.hxx" #include "Compiler.h" #include <string> @@ -30,7 +31,8 @@ class Database; class Error; /** - * Returns one value from a song's sticker record. + * Returns one value from a song's sticker record. The caller must + * free the return value with g_free(). */ gcc_pure std::string @@ -81,6 +83,7 @@ sticker_song_get(const LightSong &song, Error &error); */ bool sticker_song_find(const Database &db, const char *base_uri, const char *name, + StickerOperator op, const char *value, void (*func)(const LightSong &song, const char *value, void *user_data), void *user_data, diff --git a/src/sticker/StickerDatabase.cxx b/src/sticker/StickerDatabase.cxx index e1e5d76ab..3c1245a6e 100644 --- a/src/sticker/StickerDatabase.cxx +++ b/src/sticker/StickerDatabase.cxx @@ -370,6 +370,7 @@ sticker_load(const char *type, const char *uri, Error &error) static sqlite3_stmt * BindFind(const char *type, const char *base_uri, const char *name, + StickerOperator op, const char *value, Error &error) { assert(type != nullptr); @@ -378,12 +379,21 @@ BindFind(const char *type, const char *base_uri, const char *name, if (base_uri == nullptr) base_uri = ""; - return BindAllOrNull(error, sticker_stmt[STICKER_SQL_FIND], - type, base_uri, name); + switch (op) { + case StickerOperator::EXISTS: + return BindAllOrNull(error, sticker_stmt[STICKER_SQL_FIND], + type, base_uri, name); + } + + (void)value; + + assert(false); + gcc_unreachable(); } bool sticker_find(const char *type, const char *base_uri, const char *name, + StickerOperator op, const char *value, void (*func)(const char *uri, const char *value, void *user_data), void *user_data, @@ -392,7 +402,8 @@ sticker_find(const char *type, const char *base_uri, const char *name, assert(func != nullptr); assert(sticker_enabled()); - sqlite3_stmt *const stmt = BindFind(type, base_uri, name, error); + sqlite3_stmt *const stmt = BindFind(type, base_uri, name, op, value, + error); if (stmt == nullptr) return false; diff --git a/src/sticker/StickerDatabase.hxx b/src/sticker/StickerDatabase.hxx index 38c7d6f95..d3cfe885e 100644 --- a/src/sticker/StickerDatabase.hxx +++ b/src/sticker/StickerDatabase.hxx @@ -42,6 +42,7 @@ #ifndef MPD_STICKER_DATABASE_HXX #define MPD_STICKER_DATABASE_HXX +#include "Match.hxx" #include "Compiler.h" #include <string> @@ -154,11 +155,14 @@ sticker_load(const char *type, const char *uri, * @param base_uri the URI prefix of the resources, or nullptr if all * resources should be searched * @param name the name of the sticker + * @param op the comparison operator + * @param value the operand * @return true on success (even if no sticker was found), false on * failure */ bool sticker_find(const char *type, const char *base_uri, const char *name, + StickerOperator op, const char *value, void (*func)(const char *uri, const char *value, void *user_data), void *user_data, |