2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "song_sticker.h"
23 #include "directory.h"
32 sticker_song_get_value(const struct song
*song
, const char *name
)
37 assert(song_in_database(song
));
39 uri
= song_get_uri(song
);
40 value
= sticker_load_value("song", uri
, name
);
47 sticker_song_set_value(const struct song
*song
,
48 const char *name
, const char *value
)
54 assert(song_in_database(song
));
56 uri
= song_get_uri(song
);
57 ret
= sticker_store_value("song", uri
, name
, value
);
64 sticker_song_delete(const struct song
*song
)
70 assert(song_in_database(song
));
72 uri
= song_get_uri(song
);
73 ret
= sticker_delete("song", uri
);
80 sticker_song_delete_value(const struct song
*song
, const char *name
)
86 assert(song_in_database(song
));
88 uri
= song_get_uri(song
);
89 success
= sticker_delete_value("song", uri
, name
);
96 sticker_song_get(const struct song
*song
)
99 struct sticker
*sticker
;
101 assert(song
!= NULL
);
102 assert(song_in_database(song
));
104 uri
= song_get_uri(song
);
105 sticker
= sticker_load("song", uri
);
111 struct sticker_song_find_data
{
112 struct directory
*directory
;
113 const char *base_uri
;
114 size_t base_uri_length
;
116 void (*func
)(struct song
*song
, const char *value
,
122 sticker_song_find_cb(const char *uri
, const char *value
, gpointer user_data
)
124 struct sticker_song_find_data
*data
= user_data
;
127 if (memcmp(uri
, data
->base_uri
, data
->base_uri_length
) != 0)
128 /* should not happen, ignore silently */
131 song
= directory_lookup_song(data
->directory
,
132 uri
+ data
->base_uri_length
);
134 data
->func(song
, value
, data
->user_data
);
138 sticker_song_find(struct directory
*directory
, const char *name
,
139 void (*func
)(struct song
*song
, const char *value
,
143 struct sticker_song_find_data data
= {
144 .directory
= directory
,
146 .user_data
= user_data
,
151 data
.base_uri
= directory_get_path(directory
);
152 if (*data
.base_uri
!= 0)
153 /* append slash to base_uri */
154 data
.base_uri
= allocated
=
155 g_strconcat(data
.base_uri
, "/", NULL
);
157 /* searching in root directory - no trailing slash */
160 data
.base_uri_length
= strlen(data
.base_uri
);
162 success
= sticker_find("song", data
.base_uri
, name
,
163 sticker_song_find_cb
, &data
);