From 7f3c4349f44863ce757bf3fdc3c06ee844d946a3 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Tue, 28 Feb 2012 07:36:14 +0000 Subject: [PATCH] * Improve handling of the media_dir setting. --- minidlna.c | 81 +++++++++++++++++++++++++++--------------------------- options.c | 3 +- utils.h | 2 ++ 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/minidlna.c b/minidlna.c index 57b0613..958e315 100644 --- a/minidlna.c +++ b/minidlna.c @@ -447,52 +447,51 @@ init(int argc, char * * argv) break; case UPNPMEDIADIR: type = ALL_MEDIA; - char * myval = NULL; - switch( ary_options[i].value[0] ) + path = ary_options[i].value; + if( *path && (path[1] == ',') && (access(path, F_OK) != 0) ) { - case 'A': - case 'a': - if( ary_options[i].value[0] == 'A' || ary_options[i].value[0] == 'a' ) - type = AUDIO_ONLY; - case 'V': - case 'v': - if( ary_options[i].value[0] == 'V' || ary_options[i].value[0] == 'v' ) - type = VIDEO_ONLY; - case 'P': - case 'p': - if( ary_options[i].value[0] == 'P' || ary_options[i].value[0] == 'p' ) - type = IMAGES_ONLY; - myval = index(ary_options[i].value, '/'); - case '/': - path = realpath(myval ? myval:ary_options[i].value, buf); - if( !path ) - path = (myval ? myval:ary_options[i].value); - if( access(path, F_OK) != 0 ) + switch( *path ) { - DPRINTF(E_ERROR, L_GENERAL, "Media directory \"%s\" not accessible! [%s]\n", - path, strerror(errno)); + case 'A': + case 'a': + type = AUDIO_ONLY; + break; + case 'V': + case 'v': + type = VIDEO_ONLY; + break; + case 'P': + case 'p': + type = IMAGES_ONLY; + break; + default: + DPRINTF(E_FATAL, L_GENERAL, "Media directory entry not understood [%s]\n", + ary_options[i].value); break; } - struct media_dir_s * this_dir = calloc(1, sizeof(struct media_dir_s)); - this_dir->path = strdup(path); - this_dir->type = type; - if( !media_dirs ) - { - media_dirs = this_dir; - } - else - { - struct media_dir_s * all_dirs = media_dirs; - while( all_dirs->next ) - all_dirs = all_dirs->next; - all_dirs->next = this_dir; - } - break; - default: - DPRINTF(E_ERROR, L_GENERAL, "Media directory entry not understood! [%s]\n", - ary_options[i].value); + path += 2; + } + path = realpath(path, buf); + if( !path || access(path, F_OK) != 0 ) + { + DPRINTF(E_ERROR, L_GENERAL, "Media directory \"%s\" not accessible [%s]\n", + ary_options[i].value, strerror(errno)); break; } + struct media_dir_s * this_dir = calloc(1, sizeof(struct media_dir_s)); + this_dir->path = strdup(path); + this_dir->type = type; + if( !media_dirs ) + { + media_dirs = this_dir; + } + else + { + struct media_dir_s * all_dirs = media_dirs; + while( all_dirs->next ) + all_dirs = all_dirs->next; + all_dirs->next = this_dir; + } break; case UPNPALBUMART_NAMES: for( string = ary_options[i].value; (word = strtok(string, "/")); string = NULL ) @@ -1037,7 +1036,7 @@ main(int argc, char * * argv) } else { - /* the comparaison is not very precise but who cares ? */ + /* the comparison is not very precise but who cares ? */ if(timeofday.tv_sec >= (lastnotifytime.tv_sec + runtime_vars.notify_interval)) { SendSSDPNotifies2(snotify, diff --git a/options.c b/options.c index 74b8254..fa28f0b 100644 --- a/options.c +++ b/options.c @@ -32,6 +32,7 @@ #include #include #include "options.h" +#include "utils.h" #include "upnpglobalvars.h" struct option * ary_options = NULL; @@ -169,7 +170,7 @@ readoptionsfile(const char * fname) ary_options = (struct option *)t; ary_options[num_options-1].id = id; - strncpy(ary_options[num_options-1].value, value, MAX_OPTION_VALUE_LEN); + strncpyt(ary_options[num_options-1].value, value, MAX_OPTION_VALUE_LEN); } } diff --git a/utils.h b/utils.h index fbd0a91..48954bc 100644 --- a/utils.h +++ b/utils.h @@ -24,6 +24,8 @@ #ifndef __UTILS_H__ #define __UTILS_H__ +#include "minidlnatypes.h" + int strcatf(struct string_s *str, char *fmt, ...);