herrie-2.1-filters.diff 7.7 KB

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