From a5303765eca19e2c0ecfe7281a7e1cfaafc23a13 Mon Sep 17 00:00:00 2001 From: Michael Hohmuth Date: Fri, 11 Feb 2011 00:20:03 +0000 Subject: autoresume: Match full directory path names only in autoresumable() Removed genre-tag matching (considered too fragile for real-world use). Removed substring matching for file names. To avoid unintended matches, the search pattern now must match the file's full dir name (or a parent directory thereof), anchored in the root directory. Search strings now must be delimited with ":" rather than ",". The default list of directories is "/podcast:/podcasts" (case-insensitive). Made implementation somewhat more efficient (don't use strtok -> no need to copy the string to private storage (stack) before tokenizing it). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29280 a1c6a512-1295-4272-9138-f99709370657 --- apps/metadata.c | 60 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 22 deletions(-) (limited to 'apps/metadata.c') diff --git a/apps/metadata.c b/apps/metadata.c index 9403625eda..12bea286d0 100644 --- a/apps/metadata.c +++ b/apps/metadata.c @@ -435,39 +435,55 @@ enum { AUTORESUMABLE_UNKNOWN = 0, AUTORESUMABLE_TRUE, AUTORESUMABLE_FALSE }; bool autoresumable(struct mp3entry *id3) { - unsigned char search[MAX_PATHNAME+1]; - char *saveptr, *substr; - bool is_resumable; - + char *endp, *path; + size_t len; + bool is_resumable; + if (id3->autoresumable) /* result cached? */ return id3->autoresumable == AUTORESUMABLE_TRUE; - is_resumable = true; + is_resumable = false; - strcpy(search, global_settings.autoresume_strpat); - - for (substr = strtok_r(search, ",", &saveptr); - substr; - substr = strtok_r(NULL, ",", &saveptr)) + if (id3->path) { - if (id3->path && strcasestr(id3->path, substr)) - goto out; - if (id3->genre_string && strcasestr(id3->genre_string, substr)) - goto out; + for (path = global_settings.autoresume_paths; + *path; /* search terms left? */ + path++) + { + if (*path == ':') /* Skip empty search patterns */ + continue; + + /* FIXME: As soon as strcspn or strchrnul are made available in + the core, the following can be made more efficient. */ + endp = strchr(path, ':'); + if (endp) + len = endp - path; + else + len = strlen(path); + + /* Note: At this point, len is always > 0 */ + + if (strncasecmp(id3->path, path, len) == 0) + { + /* Full directory-name matches only. Trailing '/' in + search path OK. */ + if (id3->path[len] == '/' || id3->path[len - 1] == '/') + { + is_resumable = true; + break; + } + } + path += len - 1; + } } - - is_resumable = false; - out: /* cache result */ id3->autoresumable = is_resumable ? AUTORESUMABLE_TRUE : AUTORESUMABLE_FALSE; - logf("autoresumable: %s with genre %s is%s resumable", - id3->path, - id3->genre_string ? id3->genre_string : "(NULL)", - is_resumable ? "" : " not"); - + logf("autoresumable: %s is%s resumable", + id3->path, is_resumable ? "" : " not"); + return is_resumable; } -- cgit v1.2.3