Fix whitespace inconsistencies.
[herrie-working.git] / herrie / src / vfs_xspf.c
blob3d2075a0cc383eb1c3c755004035b7415ffb3040
1 /*
2 * Copyright (c) 2006-2011 Ed Schouten <ed@80386.nl>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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
24 * SUCH DAMAGE.
26 /**
27 * @file vfs_xspf.c
28 * @brief XSPF file access.
31 #include "stdinc.h"
33 #include <xspf_c.h>
35 #include "util.h"
36 #include "vfs.h"
37 #include "vfs_modules.h"
39 int
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"))
44 return (-1);
46 ve->recurse = 0;
47 return (0);
50 int
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;
57 struct vfsref *vr;
59 baseuri = url_escape(ve->filename);
60 slist = xspf_parse(ve->filename, baseuri);
61 g_free(baseuri);
62 if (slist == NULL)
63 return (-1);
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);
74 if (vr != NULL)
75 vfs_list_insert_tail(&ve->population, vr);
79 g_free(dirname);
80 xspf_free(slist);
81 return (0);
84 int
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;
90 char *fn, *baseuri;
91 struct vfsref *vr;
92 int ret;
94 list = xspf_new();
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);
107 g_free(fn);
110 baseuri = url_escape(filename);
111 ret = xspf_write(list, filename, baseuri);
112 g_free(baseuri);
113 xspf_free(list);
115 return (ret);