2 * Copyright (c) 2006-2011 Ed Schouten <ed@80386.nl>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * @brief XSPF file access.
37 #include "vfs_modules.h"
40 vfs_xspf_match(struct vfsent
*ve
, int isdir
)
42 /* In order to speed up the process, we only match *.xspf */
43 if (isdir
|| !g_str_has_suffix(ve
->name
, ".xspf"))
51 vfs_xspf_populate(struct vfsent
*ve
)
53 struct xspf_list
*slist
;
54 struct xspf_track
*strack
;
55 struct xspf_mvalue
*sloc
;
56 char *dirname
, *baseuri
, *filename
;
59 baseuri
= url_escape(ve
->filename
);
60 slist
= xspf_parse(ve
->filename
, baseuri
);
65 dirname
= g_path_get_dirname(ve
->filename
);
67 XSPF_LIST_FOREACH_TRACK(slist
, strack
) {
68 XSPF_TRACK_FOREACH_LOCATION(strack
, sloc
) {
69 /* Skip file:// part */
70 filename
= url_unescape(sloc
->value
);
72 /* Add it to the list */
73 vr
= vfs_lookup(filename
, strack
->title
, dirname
, 1);
75 vfs_list_insert_tail(&ve
->population
, vr
);
85 vfs_xspf_write(const struct vfslist
*vl
, const char *filename
)
87 struct xspf_list
*list
;
88 struct xspf_track
*track
;
89 struct xspf_mvalue
*location
;
96 VFS_LIST_FOREACH_REVERSE(vl
, vr
) {
97 /* Add a new track to the beginning of the list */
98 track
= xspf_new_track_before(&list
->tracks
);
100 /* Make sure we don't write non-UTF-8 titles to disk */
101 if (g_utf8_validate(vfs_name(vr
), -1, NULL
))
102 xspf_setvalue(&track
->title
, vfs_name(vr
));
104 location
= xspf_new_mvalue_before(&track
->locations
);
105 fn
= url_escape(vfs_filename(vr
));
106 xspf_setvalue(&location
->value
, fn
);
110 baseuri
= url_escape(filename
);
111 ret
= xspf_write(list
, filename
, baseuri
);