From 14a0d1ac988fce36925b68c946dbcfc6cb0f0a14 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Mon, 14 Feb 2011 23:52:10 +0000 Subject: [PATCH] * Don't expose album art images in the content directory. * Support album art name wildcards. --- albumart.c | 13 +++++-------- image_utils.c | 2 +- minidlna.c | 6 ++++++ minidlnatypes.h | 3 ++- options.h | 2 +- scanner.c | 2 ++ utils.c | 24 ++++++++++++++++++++++++ utils.h | 3 +++ 8 files changed, 44 insertions(+), 11 deletions(-) diff --git a/albumart.c b/albumart.c index 6f1f5f4..e3be12a 100644 --- a/albumart.c +++ b/albumart.c @@ -107,7 +107,7 @@ update_if_album_art(const char * path) char * match = NULL; char * file = NULL; int ncmp = 0; - struct album_art_name_s * album_art_name; + int album_art; DIR * dh; struct dirent *dp; enum file_types type = TYPE_UNKNOWN; @@ -121,14 +121,10 @@ update_if_album_art(const char * path) } else { - ncmp = strrchr(match, '.')-match; + ncmp = strrchr(match, '.') - match; } /* Check if this file name matches one of the default album art names */ - for( album_art_name = album_art_names; album_art_name; album_art_name = album_art_name->next ) - { - if( strcmp(album_art_name->name, match) == 0 ) - break; - } + album_art = is_album_art(match); dir = dirname(strdup(path)); dh = opendir(dir); @@ -155,7 +151,7 @@ update_if_album_art(const char * path) continue; if( (*(dp->d_name) != '.') && (is_video(dp->d_name) || is_audio(dp->d_name)) && - (album_art_name || strncmp(dp->d_name, match, ncmp) == 0) ) + (album_art || strncmp(dp->d_name, match, ncmp) == 0) ) { DPRINTF(E_DEBUG, L_METADATA, "New file %s looks like cover art for %s\n", path, dp->d_name); asprintf(&file, "%s/%s", dir, dp->d_name); @@ -249,6 +245,7 @@ check_embedded_art(const char * path, const char * image_data, int image_size) fclose(dstfile); if( nwritten != image_size ) { + DPRINTF(E_WARN, L_METADATA, "Embedded art error: wrote %d/%d bytes\n", nwritten, image_size); remove(art_path); free(art_path); art_path = NULL; diff --git a/image_utils.c b/image_utils.c index d4f0c0f..8ce4bb6 100644 --- a/image_utils.c +++ b/image_utils.c @@ -475,7 +475,7 @@ image_new_from_jpeg(const char * path, int is_file, const char * buf, int size, if(cinfo.output_components == 3) { ofs = 0; - if((ptr = (unsigned char *)malloc(w * 3 * cinfo.rec_outbuf_height)) == NULL) + if((ptr = (unsigned char *)malloc(w * 3 * cinfo.rec_outbuf_height + 8)) == NULL) { DPRINTF(E_WARN, L_METADATA, "malloc failed\n"); return NULL; diff --git a/minidlna.c b/minidlna.c index c9c13df..c1b6fa2 100644 --- a/minidlna.c +++ b/minidlna.c @@ -422,6 +422,12 @@ init(int argc, char * * argv) case UPNPALBUMART_NAMES: for( string = ary_options[i].value; (word = strtok(string, "/")); string = NULL ) { struct album_art_name_s * this_name = calloc(1, sizeof(struct album_art_name_s)); + int len = strlen(word); + if( word[len-1] == '*' ) + { + word[len-1] = '\0'; + this_name->wildcard = 1; + } this_name->name = strdup(word); if( !album_art_names ) { diff --git a/minidlnatypes.h b/minidlnatypes.h index 531305d..7ded991 100644 --- a/minidlnatypes.h +++ b/minidlnatypes.h @@ -79,6 +79,7 @@ struct media_dir_s { struct album_art_name_s { char * name; /* Base path */ + uint8_t wildcard; struct album_art_name_s * next; }; @@ -86,7 +87,7 @@ struct client_cache_s { struct in_addr addr; unsigned char mac[6]; enum client_types type; - u_int32_t flags; + uint32_t flags; time_t age; }; diff --git a/options.h b/options.h index 805f541..ba58a77 100644 --- a/options.h +++ b/options.h @@ -65,7 +65,7 @@ readoptionsfile(const char * fname); void freeoptions(void); -#define MAX_OPTION_VALUE_LEN (80) +#define MAX_OPTION_VALUE_LEN (200) struct option { enum upnpconfigoptions id; diff --git a/scanner.c b/scanner.c index 3149530..225055a 100644 --- a/scanner.c +++ b/scanner.c @@ -472,6 +472,8 @@ insert_file(char * name, const char * path, const char * parentID, int object) if( is_image(name) ) { + if( is_album_art(name) ) + return -1; strcpy(base, IMAGE_DIR_ID); strcpy(class, "item.imageItem.photo"); detailID = GetImageMetadata(path, name); diff --git a/utils.c b/utils.c index 32a4755..9192d20 100644 --- a/utils.c +++ b/utils.c @@ -28,6 +28,7 @@ #include #include "minidlnatypes.h" +#include "upnpglobalvars.h" #include "log.h" int @@ -245,6 +246,29 @@ is_playlist(const char * file) return (ends_with(file, ".m3u") || ends_with(file, ".pls")); } +int +is_album_art(const char * name) +{ + struct album_art_name_s * album_art_name; + + /* Check if this file name matches one of the default album art names */ + for( album_art_name = album_art_names; album_art_name; album_art_name = album_art_name->next ) + { + if( album_art_name->wildcard ) + { + if( strncmp(album_art_name->name, name, strlen(album_art_name->name)) == 0 ) + break; + } + else + { + if( strcmp(album_art_name->name, name) == 0 ) + break; + } + } + + return (album_art_name ? 1 : 0); +} + int resolve_unknown_type(const char * path, enum media_types dir_type) { diff --git a/utils.h b/utils.h index c92a145..5d8c4b8 100644 --- a/utils.h +++ b/utils.h @@ -57,6 +57,9 @@ is_image(const char * file); int is_playlist(const char * file); +int +is_album_art(const char * name); + int resolve_unknown_type(const char * path, enum media_types dir_type);