summaryrefslogtreecommitdiffstats
path: root/audio/herrie/patches/herrie-2.1-filters.diff
blob: 36ef1fcc806f6cd7001d508b4091ed3cf23a69ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
diff -ru herrie-2.1-autoquit/herrie-2.1/src/config.c herrie-2.1-filters/herrie-2.1/src/config.c
--- herrie-2.1-autoquit/herrie-2.1/src/config.c	2008-07-18 10:40:34.000000000 -0500
+++ herrie-2.1-filters/herrie-2.1/src/config.c	2008-07-18 10:27:31.000000000 -0500
@@ -172,6 +172,8 @@
 	{ "scrobbler.username",		"",		NULL,		NULL },
 #endif /* BUILD_SCROBBLER */
 	{ "vfs.dir.hide_dotfiles",	"yes",		valid_bool,	NULL },
+        { "vfs.dir.hide_extfiles",      "no",           valid_bool,     NULL },
+        { "vfs.ext.whitelist",          "mp3 wav ogg",  NULL,           NULL },
 #ifdef G_OS_UNIX
 	{ "vfs.lockup.chroot",		"",		NULL,		NULL },
 	{ "vfs.lockup.user",		"",		NULL,		NULL },
diff -ru herrie-2.1-autoquit/herrie-2.1/src/playq.c herrie-2.1-filters/herrie-2.1/src/playq.c
--- herrie-2.1-autoquit/herrie-2.1/src/playq.c	2008-07-18 10:40:34.000000000 -0500
+++ herrie-2.1-filters/herrie-2.1/src/playq.c	2008-07-18 10:53:53.000000000 -0500
@@ -153,7 +153,7 @@
 /**
  * @brief If true, quit when end of list reached
  */
-int			playq_autoquit = 0;
+int                    playq_autoquit = 0;
 
 /**
  * @brief Infinitely play music in the playlist, honouring the
@@ -182,19 +182,19 @@
 
 			/* Try to start a new song when we're not stopped */
 			if (!(playq_flags & PF_STOP)) {
-			    if ((nvr = funcs->give()) != NULL) {
-				/* We've got work to do */
-				break;
-			    }
-			    else {
-				if (playq_autoquit_ready && playq_autoquit) {
-					/* Time to quit - Send ourself the SIGTERM */
-					int res = getpid();
-  					if (res !=0){
-    						kill(res,SIGTERM);
-  					}
-			        }
-			    }
+				if ((nvr = funcs->give()) != NULL) {
+					/* We've got work to do */
+					break;
+				}
+				else {
+					if (playq_autoquit_ready && playq_autoquit) {
+						/* Time to quit - Send ourself the SIGTERM */
+						int res = getpid();
+						if (res !=0){
+							kill(res,SIGTERM);
+						}
+					}
+				}
 			}
 
 			/* Wait for new events to occur */
@@ -282,12 +282,20 @@
 	if (autoquit || config_getopt_bool("playq.autoquit"))
 		playq_autoquit = 1;
 
+	/* Create and compile Whitelist regex */
+	vfs_create_whitelist(config_getopt("vfs.ext.whitelist"));
+
 	filename = config_getopt("playq.dumpfile");
 	if (load_dumpfile && filename[0] != '\0') {
 		/* Autoload playlist */
 		vr = vfs_lookup(filename, NULL, NULL, 0);
 		if (vr != NULL) {
-			vfs_unfold(&playq_list, vr);
+			if (config_getopt_bool("vfs.dir.hide_extfiles"))
+				vfs_unfold(&playq_list, vr, 1);
+			else {
+				/* Don't filter out files at this time */
+				vfs_unfold(&playq_list, vr, 0);
+			}
 			vfs_close(vr);
 		}
 	}
@@ -336,7 +344,7 @@
 	struct vfslist newlist = VFSLIST_INITIALIZER;
 
 	/* Recursively expand the item */
-	vfs_unfold(&newlist, vr);
+	vfs_unfold(&newlist, vr, 1);
 	if (vfs_list_empty(&newlist))
 		return;
 
@@ -359,7 +367,7 @@
 	struct vfslist newlist = VFSLIST_INITIALIZER;
 
 	/* Recursively expand the item */
-	vfs_unfold(&newlist, vr);
+	vfs_unfold(&newlist, vr, 1);
 	if (vfs_list_empty(&newlist))
 		return;
 
@@ -469,7 +477,7 @@
 	struct vfslist newlist = VFSLIST_INITIALIZER;
 
 	/* Recursively expand the item */
-	vfs_unfold(&newlist, nvr);
+	vfs_unfold(&newlist, nvr, 1);
 	if (vfs_list_empty(&newlist))
 		return;
 
@@ -491,7 +499,7 @@
 	struct vfslist newlist = VFSLIST_INITIALIZER;
 
 	/* Recursively expand the item */
-	vfs_unfold(&newlist, nvr);
+	vfs_unfold(&newlist, nvr, 1);
 	if (vfs_list_empty(&newlist))
 		return;
 
diff -ru herrie-2.1-autoquit/herrie-2.1/src/vfs.c herrie-2.1-filters/herrie-2.1/src/vfs.c
--- herrie-2.1-autoquit/herrie-2.1/src/vfs.c	2008-07-15 10:59:07.000000000 -0500
+++ herrie-2.1-filters/herrie-2.1/src/vfs.c	2008-07-18 10:27:31.000000000 -0500
@@ -185,6 +185,11 @@
 	return g_string_free(npath, FALSE);
 }
 
+struct vfsmatch * vfs_get_vm_whitelist()
+{
+	return vm_whitelist;
+}
+
 const char *
 vfs_lockup(void)
 {
@@ -245,6 +250,27 @@
 	g_slice_free(struct vfsent, ve);
 }
 
+void
+vfs_create_whitelist(const char* whitelist)
+{
+	char res[128] = "";
+	char *expr = "|[.]";
+	strcat(res, "[.]");
+
+	int i,j;
+	for (i=0,j=strlen(res); i < strlen(whitelist); i++) {
+		if (whitelist[i] == ' ') {
+			strcat(res, expr);
+			j+=strlen(expr);
+		}
+		else
+			res[j++] = whitelist[i];
+	}
+	res[j] = '\0';
+
+	vm_whitelist = vfs_match_new(res);
+}
+
 struct vfsref *
 vfs_lookup(const char *filename, const char *name, const char *basepath,
     int strict)
@@ -363,7 +389,7 @@
 }
 
 void
-vfs_unfold(struct vfslist *vl, const struct vfsref *vr)
+vfs_unfold(struct vfslist *vl, const struct vfsref *vr, int useWhiteList)
 {
 	struct vfsref *cvr;
 
@@ -374,8 +400,14 @@
 		/* See if we can recurse it */
 		vfs_populate(vr);
 		VFS_LIST_FOREACH(&vr->ent->population, cvr) {
-			if (cvr->ent->recurse)
-				vfs_unfold(vl, cvr);
+			if (cvr->ent->recurse) {
+				/* Ignore Whitelist if it is not valid
+				 * Make sure directories aren't filtered
+				 */
+				if (!useWhiteList || vm_whitelist == NULL || !vfs_playable(cvr) ||
+				   vfs_match_compare(vm_whitelist, vfs_filename(cvr)))
+					vfs_unfold(vl, cvr, useWhiteList);
+			}
 		}
 	}
 }
diff -ru herrie-2.1-autoquit/herrie-2.1/src/vfs.h herrie-2.1-filters/herrie-2.1/src/vfs.h
--- herrie-2.1-autoquit/herrie-2.1/src/vfs.h	2008-07-15 10:59:07.000000000 -0500
+++ herrie-2.1-filters/herrie-2.1/src/vfs.h	2008-07-18 10:27:31.000000000 -0500
@@ -164,11 +164,21 @@
 };
 
 /**
+ * @brief The compiled regex for the whitelist
+ */
+static struct vfsmatch                *vm_whitelist;
+
+/**
  * @brief Contents of an empty VFS list structure.
  */
 #define VFSLIST_INITIALIZER { NULL, NULL, 0 }
 
 /**
+ * @brief Returns the whitelist
+ */
+struct vfsmatch * vfs_get_vm_whitelist();
+
+/**
  * @brief Run-time initialize a VFS list structure.
  */
 static inline void
@@ -362,6 +372,14 @@
 const char	*vfs_lockup(void);
 
 /**
+ * @brief Create the compiled regex for the whitelist.
+ * The input string should be formatted similar to
+ * "ext1 ext2 ext3" and this will be converted into a 
+ * Regular Expr like "[.]ext1|[.]ext2|[.]ext3".
+ */
+void vfs_create_whitelist(const char* whitelist);
+
+/**
  * @brief Create a VFS reference from a filename. The name argument is
  *        optional. It only allows you to display entities with a
  *        different name (inside playlists). When setting the basepath
@@ -390,7 +408,7 @@
  * @brief Recursively expand a VFS reference to all their usable
  *        children and append them to the specified list.
  */
-void		vfs_unfold(struct vfslist *vl, const struct vfsref *vr);
+void            vfs_unfold(struct vfslist *vl, const struct vfsref *vr, int useWhiteList);
 /**
  * @brief Recursively search through a VFS reference and add all
  *        matching objects to a list. The VFS reference itself will be
diff -ru herrie-2.1-autoquit/herrie-2.1/src/vfs_regular.c herrie-2.1-filters/herrie-2.1/src/vfs_regular.c
--- herrie-2.1-autoquit/herrie-2.1/src/vfs_regular.c	2008-07-15 10:59:07.000000000 -0500
+++ herrie-2.1-filters/herrie-2.1/src/vfs_regular.c	2008-07-18 10:27:31.000000000 -0500
@@ -73,9 +73,13 @@
 	GDir *dir;
 	const char *sfn;
 	struct vfsref *nvr, *svr;
-	int hide_dotfiles;
+	struct vfsmatch *whitelist;
+	int hide_dotfiles, hide_extfiles;
 
 	hide_dotfiles = config_getopt_bool("vfs.dir.hide_dotfiles");
+	hide_extfiles = config_getopt_bool("vfs.dir.hide_extfiles");
+
+	whitelist = vfs_get_vm_whitelist();
 
 	if ((dir = g_dir_open(ve->filename, 0, NULL)) == NULL)
 		return (-1);
@@ -88,6 +92,11 @@
 		if ((nvr = vfs_lookup(sfn, NULL, ve->filename, 1)) == NULL)
 			continue;
 
+		/* Hide files (not directories) that are not whitelisted */
+		if (hide_extfiles && whitelist != NULL && vfs_playable(nvr) && 
+		   !vfs_match_compare(whitelist, vfs_filename(nvr)))
+			continue;
+
 		/*
 		 * Add the items to the tailq in a sorted manner.
 		 */