Code

9090f8489c267e5cc5ca3c8b1bbd38422c3e326d
[ncmpc.git] / src / song.c
1 /* libmpdclient
2    (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
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    - Neither the name of the Music Player Daemon nor the names of its
17    contributors may be used to endorse or promote products derived from
18    this software without specific prior written permission.
20    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
24    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
33 #include "song.h"
34 #include "str_pool.h"
36 #include <stdlib.h>
38 static void mpd_initSong(struct mpd_song *song) {
39         song->file = NULL;
40         song->artist = NULL;
41         song->album = NULL;
42         song->track = NULL;
43         song->title = NULL;
44         song->name = NULL;
45         song->date = NULL;
46         /* added by Qball */
47         song->genre = NULL;
48         song->composer = NULL;
49         song->disc = NULL;
50         song->comment = NULL;
52         song->time = MPD_SONG_NO_TIME;
53         song->pos = MPD_SONG_NO_NUM;
54         song->id = MPD_SONG_NO_ID;
55 }
57 static void mpd_finishSong(struct mpd_song *song) {
58         if (song->file)
59                 str_pool_put(song->file);
60         if (song->artist)
61                 str_pool_put(song->artist);
62         if (song->album)
63                 str_pool_put(song->album);
64         if (song->title)
65                 str_pool_put(song->title);
66         if (song->track)
67                 str_pool_put(song->track);
68         if (song->name)
69                 str_pool_put(song->name);
70         if (song->date)
71                 str_pool_put(song->date);
72         if (song->genre)
73                 str_pool_put(song->genre);
74         if (song->composer)
75                 str_pool_put(song->composer);
76         if (song->disc)
77                 str_pool_put(song->disc);
78         if (song->comment)
79                 str_pool_put(song->comment);
80 }
82 struct mpd_song *mpd_newSong(void) {
83         struct mpd_song *ret = malloc(sizeof(*ret));
85         mpd_initSong(ret);
87         return ret;
88 }
90 void mpd_freeSong(struct mpd_song *song) {
91         mpd_finishSong(song);
92         free(song);
93 }
95 struct mpd_song *mpd_songDup(const struct mpd_song *song) {
96         struct mpd_song *ret = mpd_newSong();
98         if (song->file)
99                 ret->file = str_pool_dup(song->file);
100         if (song->artist)
101                 ret->artist = str_pool_dup(song->artist);
102         if (song->album)
103                 ret->album = str_pool_dup(song->album);
104         if (song->title)
105                 ret->title = str_pool_dup(song->title);
106         if (song->track)
107                 ret->track = str_pool_dup(song->track);
108         if (song->name)
109                 ret->name = str_pool_dup(song->name);
110         if (song->date)
111                 ret->date = str_pool_dup(song->date);
112         if (song->genre)
113                 ret->genre= str_pool_dup(song->genre);
114         if (song->composer)
115                 ret->composer= str_pool_dup(song->composer);
116         if (song->disc)
117                 ret->disc = str_pool_dup(song->disc);
118         if (song->comment)
119                 ret->comment = str_pool_dup(song->comment);
121         ret->time = song->time;
122         ret->pos = song->pos;
123         ret->id = song->id;
125         return ret;