summaryrefslogtreecommitdiff
path: root/apps/metadata.c
diff options
context:
space:
mode:
authorMichael Hohmuth <sideral@rockbox.org>2011-02-11 00:20:03 +0000
committerMichael Hohmuth <sideral@rockbox.org>2011-02-11 00:20:03 +0000
commita5303765eca19e2c0ecfe7281a7e1cfaafc23a13 (patch)
tree24eaddd45e98a48e19d36f3fc336d658244b8429 /apps/metadata.c
parentbdec638b9ba8c6a65f51ca72755b0e5d62edd7f4 (diff)
downloadrockbox-a5303765eca19e2c0ecfe7281a7e1cfaafc23a13.tar.gz
rockbox-a5303765eca19e2c0ecfe7281a7e1cfaafc23a13.zip
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
Diffstat (limited to 'apps/metadata.c')
-rw-r--r--apps/metadata.c60
1 files changed, 38 insertions, 22 deletions
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 };
435 435
436bool autoresumable(struct mp3entry *id3) 436bool autoresumable(struct mp3entry *id3)
437{ 437{
438 unsigned char search[MAX_PATHNAME+1]; 438 char *endp, *path;
439 char *saveptr, *substr; 439 size_t len;
440 bool is_resumable; 440 bool is_resumable;
441 441
442 if (id3->autoresumable) /* result cached? */ 442 if (id3->autoresumable) /* result cached? */
443 return id3->autoresumable == AUTORESUMABLE_TRUE; 443 return id3->autoresumable == AUTORESUMABLE_TRUE;
444 444
445 is_resumable = true; 445 is_resumable = false;
446 446
447 strcpy(search, global_settings.autoresume_strpat); 447 if (id3->path)
448
449 for (substr = strtok_r(search, ",", &saveptr);
450 substr;
451 substr = strtok_r(NULL, ",", &saveptr))
452 { 448 {
453 if (id3->path && strcasestr(id3->path, substr)) 449 for (path = global_settings.autoresume_paths;
454 goto out; 450 *path; /* search terms left? */
455 if (id3->genre_string && strcasestr(id3->genre_string, substr)) 451 path++)
456 goto out; 452 {
453 if (*path == ':') /* Skip empty search patterns */
454 continue;
455
456 /* FIXME: As soon as strcspn or strchrnul are made available in
457 the core, the following can be made more efficient. */
458 endp = strchr(path, ':');
459 if (endp)
460 len = endp - path;
461 else
462 len = strlen(path);
463
464 /* Note: At this point, len is always > 0 */
465
466 if (strncasecmp(id3->path, path, len) == 0)
467 {
468 /* Full directory-name matches only. Trailing '/' in
469 search path OK. */
470 if (id3->path[len] == '/' || id3->path[len - 1] == '/')
471 {
472 is_resumable = true;
473 break;
474 }
475 }
476 path += len - 1;
477 }
457 } 478 }
458
459 is_resumable = false;
460 479
461 out:
462 /* cache result */ 480 /* cache result */
463 id3->autoresumable = 481 id3->autoresumable =
464 is_resumable ? AUTORESUMABLE_TRUE : AUTORESUMABLE_FALSE; 482 is_resumable ? AUTORESUMABLE_TRUE : AUTORESUMABLE_FALSE;
465 483
466 logf("autoresumable: %s with genre %s is%s resumable", 484 logf("autoresumable: %s is%s resumable",
467 id3->path, 485 id3->path, is_resumable ? "" : " not");
468 id3->genre_string ? id3->genre_string : "(NULL)", 486
469 is_resumable ? "" : " not");
470
471 return is_resumable; 487 return is_resumable;
472} 488}
473 489