* Add support for user-configurable log level settings.

This commit is contained in:
Justin Maggard 2012-02-14 18:25:39 +00:00
parent 774d8f9f6e
commit ba7e33a062
8 changed files with 53 additions and 16 deletions

7
log.c
View File

@ -62,11 +62,11 @@ log_init(const char *fname, const char *debug)
if (debug) if (debug)
{ {
char *rhs, *lhs, *p; const char *rhs, *lhs, *nlhs, *p;
int n; int n;
int level, facility; int level, facility;
memset(&log_level_set, 0, sizeof(log_level_set)); memset(&log_level_set, 0, sizeof(log_level_set));
rhs = lhs = (char*) debug; rhs = nlhs = debug;
while (rhs && (rhs = strchr(rhs, '='))) { while (rhs && (rhs = strchr(rhs, '='))) {
rhs++; rhs++;
p = strchr(rhs, ','); p = strchr(rhs, ',');
@ -75,7 +75,8 @@ log_init(const char *fname, const char *debug)
if (!(strncasecmp(level_name[level], rhs, n))) if (!(strncasecmp(level_name[level], rhs, n)))
break; break;
} }
rhs = p; lhs = nlhs;
rhs = nlhs = p;
if (!(level_name[level])) { if (!(level_name[level])) {
// unknown level // unknown level
continue; continue;

View File

@ -350,6 +350,7 @@ init(int argc, char * * argv)
char buf[PATH_MAX]; char buf[PATH_MAX];
char ip_addr[INET_ADDRSTRLEN + 3] = {'\0'}; char ip_addr[INET_ADDRSTRLEN + 3] = {'\0'};
char log_str[72] = "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn"; char log_str[72] = "general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn";
char *log_level = NULL;
/* first check if "-f" option is used */ /* first check if "-f" option is used */
for(i=2; i<argc; i++) for(i=2; i<argc; i++)
@ -541,6 +542,9 @@ init(int argc, char * * argv)
} }
strncpyt(log_path, path, PATH_MAX); strncpyt(log_path, path, PATH_MAX);
break; break;
case UPNPLOGLEVEL:
log_level = ary_options[i].value;
break;
case UPNPINOTIFY: case UPNPINOTIFY:
if( (strcmp(ary_options[i].value, "yes") != 0) && !atoi(ary_options[i].value) ) if( (strcmp(ary_options[i].value, "yes") != 0) && !atoi(ary_options[i].value) )
CLEARFLAG(INOTIFY_MASK); CLEARFLAG(INOTIFY_MASK);
@ -777,22 +781,29 @@ init(int argc, char * * argv)
} }
if( verbose_flag ) if( verbose_flag )
{
strcpy(log_str+65, "debug"); strcpy(log_str+65, "debug");
log_level = log_str;
}
else if( !log_level )
{
log_level = log_str;
}
if(debug_flag) if(debug_flag)
{ {
pid = getpid(); pid = getpid();
log_init(NULL, log_str); log_init(NULL, log_level);
} }
else else
{ {
pid = daemonize(); pid = daemonize();
#ifdef READYNAS #ifdef READYNAS
log_init("/var/log/upnp-av.log", log_str); log_init("/var/log/upnp-av.log", log_level);
#else #else
if( access(db_path, F_OK) != 0 ) if( access(db_path, F_OK) != 0 )
make_dir(db_path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO); make_dir(db_path, S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO);
sprintf(buf, "%s/minidlna.log", log_path); sprintf(buf, "%s/minidlna.log", log_path);
log_init(buf, log_str); log_init(buf, log_level);
#endif #endif
} }

View File

@ -22,6 +22,10 @@ media_dir=/opt
# set this if you would like to specify the directory where you want MiniDLNA to store its log file # set this if you would like to specify the directory where you want MiniDLNA to store its log file
#log_dir=/var/log #log_dir=/var/log
# set this to change the verbosity of the information that is logged
# each section can use a different level: off, fatal, error, warn, info, or debug
#log_level=general,artwork,database,inotify,scanner,metadata,http,ssdp,tivo=warn
# this should be a list of file names to check for when searching for album art # this should be a list of file names to check for when searching for album art
# note: names should be delimited with a forward slash ("/") # note: names should be delimited with a forward slash ("/")
album_art_names=Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg album_art_names=Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg

View File

@ -516,8 +516,6 @@ close:
* process SSDP M-SEARCH requests and responds to them */ * process SSDP M-SEARCH requests and responds to them */
void void
ProcessSSDPRequest(int s, unsigned short port) ProcessSSDPRequest(int s, unsigned short port)
/*ProcessSSDPRequest(int s, struct lan_addr_s * lan_addr, int n_lan_addr,
unsigned short port)*/
{ {
int n; int n;
char bufr[1500]; char bufr[1500];
@ -547,10 +545,8 @@ ProcessSSDPRequest(int s, unsigned short port)
if( bufr[i] == '*' ) if( bufr[i] == '*' )
break; break;
} }
if( !strcasestr(bufr+i, "HTTP/1.1") ) if( !strcasestrc(bufr+i, "HTTP/1.1", '\r') )
{
return; return;
}
while(i < n) while(i < n)
{ {
while((i < n - 2) && (bufr[i] != '\r' || bufr[i+1] != '\n')) while((i < n - 2) && (bufr[i] != '\r' || bufr[i+1] != '\n'))
@ -601,7 +597,6 @@ ProcessSSDPRequest(int s, unsigned short port)
} }
ParseUPnPClient(loc); ParseUPnPClient(loc);
} }
return;
} }
else if(memcmp(bufr, "M-SEARCH", 8) == 0) else if(memcmp(bufr, "M-SEARCH", 8) == 0)
{ {
@ -612,10 +607,8 @@ ProcessSSDPRequest(int s, unsigned short port)
if( bufr[i] == '*' ) if( bufr[i] == '*' )
break; break;
} }
if( !strcasestr(bufr+i, "HTTP/1.1") ) if( !strcasestrc(bufr+i, "HTTP/1.1", '\r') )
{
return; return;
}
while(i < n) while(i < n)
{ {
while((i < n - 2) && (bufr[i] != '\r' || bufr[i+1] != '\n')) while((i < n - 2) && (bufr[i] != '\r' || bufr[i+1] != '\n'))

View File

@ -57,6 +57,7 @@ static const struct {
{ UPNPINOTIFY, "inotify" }, { UPNPINOTIFY, "inotify" },
{ UPNPDBDIR, "db_dir" }, { UPNPDBDIR, "db_dir" },
{ UPNPLOGDIR, "log_dir" }, { UPNPLOGDIR, "log_dir" },
{ UPNPLOGLEVEL, "log_level" },
{ UPNPMINISSDPDSOCKET, "minissdpdsocket"}, { UPNPMINISSDPDSOCKET, "minissdpdsocket"},
{ ENABLE_TIVO, "enable_tivo" }, { ENABLE_TIVO, "enable_tivo" },
{ ENABLE_DLNA_STRICT, "strict_dlna" }, { ENABLE_DLNA_STRICT, "strict_dlna" },

View File

@ -51,6 +51,7 @@ enum upnpconfigoptions {
UPNPINOTIFY, /* enable inotify on the media directories */ UPNPINOTIFY, /* enable inotify on the media directories */
UPNPDBDIR, /* base directory to store the database and album art cache */ UPNPDBDIR, /* base directory to store the database and album art cache */
UPNPLOGDIR, /* base directory to store the log file */ UPNPLOGDIR, /* base directory to store the log file */
UPNPLOGLEVEL, /* logging verbosity */
UPNPMINISSDPDSOCKET, /* minissdpdsocket */ UPNPMINISSDPDSOCKET, /* minissdpdsocket */
ENABLE_TIVO, /* enable support for streaming images and music to TiVo */ ENABLE_TIVO, /* enable support for streaming images and music to TiVo */
ENABLE_DLNA_STRICT, /* strictly adhere to DLNA specs */ ENABLE_DLNA_STRICT, /* strictly adhere to DLNA specs */

25
utils.c
View File

@ -106,7 +106,7 @@ strstrc(const char *s, const char *p, const char t)
endptr = strchr(s, t); endptr = strchr(s, t);
if (!endptr) if (!endptr)
return NULL; return strstr(s, p);
plen = strlen(p); plen = strlen(p);
slen = endptr - s; slen = endptr - s;
@ -121,6 +121,29 @@ strstrc(const char *s, const char *p, const char t)
return NULL; return NULL;
} }
char *
strcasestrc(const char *s, const char *p, const char t)
{
char *endptr;
size_t slen, plen;
endptr = strchr(s, t);
if (!endptr)
return strcasestr(s, p);
plen = strlen(p);
slen = endptr - s;
while (slen >= plen)
{
if (*s == *p && strncasecmp(s+1, p+1, plen-1) == 0)
return (char*)s;
s++;
slen--;
}
return NULL;
}
char * char *
modifyString(char * string, const char * before, const char * after, short like) modifyString(char * string, const char * before, const char * after, short like)
{ {

View File

@ -39,6 +39,9 @@ trim(char *str);
char * char *
strstrc(const char *s, const char *p, const char t); strstrc(const char *s, const char *p, const char t);
char *
strcasestrc(const char *s, const char *p, const char t);
char * char *
modifyString(char * string, const char * before, const char * after, short like); modifyString(char * string, const char * before, const char * after, short like);