summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-08-12 13:46:32 +0200
committerKjetil Ørbekk <orbekk@pvv.ntnu.no>2008-08-12 13:48:09 +0200
commit959488a96664e7b2246f62c5106028ef7291168b (patch)
tree69f8daad2a45e5c11e8008b3a50f8148c954c518
parentc9b61f8df8a7cccb0768fd6ec6d1585ef3366743 (diff)
- Added mp3_file_data_for_path, to reuse code for opening and reading
a given path.
-rw-r--r--include/mp3fs.h1
-rw-r--r--src/mp3_subr.c85
2 files changed, 86 insertions, 0 deletions
diff --git a/include/mp3fs.h b/include/mp3fs.h
index 9436966..adc41db 100644
--- a/include/mp3fs.h
+++ b/include/mp3fs.h
@@ -55,5 +55,6 @@ void mp3_lookup_genre(const char *, struct filler_data *);
void mp3_lookup_album(const char *, struct filler_data *);
char *mp3_gettoken(const char *, int);
int mp3_numtoken(const char *);
+int mp3_file_data_for_path(const char *, void *);
#endif
diff --git a/src/mp3_subr.c b/src/mp3_subr.c
index a56e696..24ca7c7 100644
--- a/src/mp3_subr.c
+++ b/src/mp3_subr.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* Miscellaneous subroutines for mp3fs. */
#define FUSE_USE_VERSION 26
#include <stdio.h>
@@ -334,6 +335,90 @@ mp3_lookup_finish(struct lookuphandle *lh)
}
/*
+ * Build a file_data struct for a path.
+ *
+ * data should be a pointer to a file handle
+ * returns 0 on success
+ */
+int
+mp3_file_data_for_path(const char *path, void *data) {
+ struct file_data *fd;
+ fd = (struct file_data *)data;
+ struct lookuphandle *lh;
+ char *artist, *album, *title;
+
+ lh = NULL;
+ fd->fd = -1;
+ fd->found = 0;
+
+ /* Open a specific track. */
+ if (strncmp(path, "/Tracks", 7) == 0) {
+ switch (mp3_numtoken(path)) {
+ case 2:
+ title = mp3_gettoken(path, 2);
+ if (title == NULL)
+ break;
+ lh = mp3_lookup_start(0, fd, mp3_lookup_open,
+ "SELECT filepath FROM song WHERE title LIKE ?");
+ if (lh == NULL)
+ return (-EIO);
+ mp3_lookup_insert(lh, title, LIST_DATATYPE_STRING);
+ break;
+ default:
+ return (-ENOENT);
+ }
+ } else if (strncmp(path, "/Albums", 7) == 0) {
+ switch (mp3_numtoken(path)) {
+ case 3:
+ album = mp3_gettoken(path, 2);
+ if (album == NULL)
+ break;
+ title = mp3_gettoken(path, 3);
+ if (title == NULL)
+ break;
+ lh = mp3_lookup_start(0, fd, mp3_lookup_open,
+ "SELECT filepath FROM song WHERE title LIKE ? AND "
+ "album LIKE ?");
+ if (lh == NULL)
+ return (-EIO);
+ mp3_lookup_insert(lh, title, LIST_DATATYPE_STRING);
+ mp3_lookup_insert(lh, album, LIST_DATATYPE_STRING);
+ break;
+ default:
+ return (-ENOENT);
+ }
+ } else if (strncmp(path, "/Artists", 8) == 0) {
+ switch (mp3_numtoken(path)) {
+ case 4:
+ artist = mp3_gettoken(path, 2);
+ album = mp3_gettoken(path, 3);
+ title = mp3_gettoken(path, 4);
+ DEBUG("artist(%s) album(%s) title(%s)\n", artist, album, title);
+ if (!(artist && album && title)) {
+ break;
+ }
+ lh = mp3_lookup_start(0, fd, mp3_lookup_open,
+ "SELECT filepath FROM song WHERE artistname LIKE ? AND "
+ "album LIKE ? AND title LIKE ?");
+ if (lh == NULL)
+ return (-EIO);
+ mp3_lookup_insert(lh, artist, LIST_DATATYPE_STRING);
+ mp3_lookup_insert(lh, album, LIST_DATATYPE_STRING);
+ mp3_lookup_insert(lh, title, LIST_DATATYPE_STRING);
+ break;
+ default:
+ return (-ENOENT);
+ }
+ }
+
+ if (lh) {
+ mp3_lookup_finish(lh);
+ }
+
+ return 0;
+}
+
+/*
* Count number of tokens in pathname.
* XXX: should we strip the first and last?
*/