From b5abd3faf9edd6edc19b3b8af36b6179b4fd8fc8 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Tue, 14 Feb 2006 06:39:06 +0000 Subject: [PATCH] Minor updates --- src/conf.c | 58 +++++++++++++++++++++++++++++++++++++++++++------- src/ll.c | 18 ++++++++++++++++ src/ll.h | 1 + src/scanner.mk | 4 ++-- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/src/conf.c b/src/conf.c index f5641c8d..1e7216a7 100644 --- a/src/conf.c +++ b/src/conf.c @@ -31,6 +31,7 @@ #endif #include +#include #include "conf.h" #include "err.h" @@ -47,7 +48,8 @@ static LL_HANDLE config_main=NULL; #define CONF_T_STRING 1 /** Forwards */ -static int _ll_verify(LL_HANDLE pll); +static int _conf_verify(LL_HANDLE pll); +static int _conf_exists(LL_HANDLE pll, char *section, char *term); @@ -83,19 +85,59 @@ static CONF_ELEMENTS conf_elements[] = { { 0, 0, CONF_T_STRING,"general","ssc_prog" }, { 0, 0, CONF_T_STRING,"general","password" }, { 0, 0, CONF_T_STRING,"general","compdirs" }, - { 0, 0, CONF_T_STRING,"general","logfile" } + { 0, 0, CONF_T_STRING,"general","logfile" }, + { 0, 0, CONF_T_INT, NULL, NULL } }; +int _conf_exists(LL_HANDLE pll, char *section, char *term) { + LL_ITEM *pitem; + + if(!(pitem = ll_fetch_item(pll,section))) + return FALSE; + + if(!ll_fetch_item(pitem->value.as_ll,term)) + return FALSE; + + return TRUE; +} + + /** - * check a tree and make sure it doesn't have any obviously bad - * configuration information + * Verify that the configuration isn't obviously wrong. + * Type checking has already been done, this just checks + * required stuff isn't missing. * * @param pll tree to check + * @returns TRUE if configuration appears valid, FALSE otherwise */ -int _ll_verify(LL_HANDLE pll) { +int _conf_verify(LL_HANDLE pll) { + LL_ITEM *pi = NULL; + CONF_ELEMENTS *pce; + int is_valid=TRUE; + + /* first, walk through the elements and make sure + * all required elements are there */ + pce = &conf_elements[0]; + while(pce->section) { + if(pce->required) { + if(!_conf_exists(pll,pce->section, pce->term)) + DPRINTF(E_LOG,L_CONF,"Missing configuration entry " + " %s/%s. Please review the sample config\n", + pce->section, pce->term); + is_valid=FALSE; + } + if(pce->deprecated) { + DPRINTF(E_LOG,L_CONF,"Config entry %s/%s is deprecated. Please " + "review the sample config\n", + pce->section, pce->term); + } + pce++; + } + + /* here we would walk through derived sections, if there + * were any */ - - return LL_E_SUCCESS; + return is_valid; } @@ -207,7 +249,7 @@ int config_read(char *file) { fclose(fin); /* Sanity check */ - _ll_verify(pllnew); + _conf_verify(pllnew); ll_dump(pllnew); ll_destroy(pllnew); diff --git a/src/ll.c b/src/ll.c index 5afc0e1d..7a5d6ad0 100644 --- a/src/ll.c +++ b/src/ll.c @@ -252,3 +252,21 @@ void _ll_dump(LL *pl, int depth) { pli = pli->next; } } + + +/** + * Given an item (or NULL for first item), fetch + * the next item + * + * @param pl ll to fetch from + * @param prev last item we fetched + */ +LL_ITEM *ll_get_next(LL *pl, LL_ITEM *prev) { + if(!pl) + return NULL; + + if(!prev) + return pl->itemlist.next; + + return prev->next; +} diff --git a/src/ll.h b/src/ll.h index 10b8a7d2..31ba9676 100644 --- a/src/ll.h +++ b/src/ll.h @@ -67,6 +67,7 @@ extern int ll_set_flags(LL *pl, unsigned int flags); extern int ll_get_flags(LL *pl, unsigned int *flags); extern LL_ITEM *ll_fetch_item(LL *pl, char *key); +extern LL_ITEM *ll_get_next(LL *pl, LL_ITEM *prev); extern void ll_dump(LL *pl); diff --git a/src/scanner.mk b/src/scanner.mk index a5a172a6..75a6f93b 100644 --- a/src/scanner.mk +++ b/src/scanner.mk @@ -1,6 +1,6 @@ CC=gcc -CFLAGS := $(CFLAGS) -g -I/sw/include -DHAVE_CONFIG_H -I. -I.. -LDFLAGS := $(LDFLAGS) -L/sw/lib -lid3tag -logg -lvorbisfile -lFLAC -lvorbis -ltag_c +CFLAGS := $(CFLAGS) -g -I/opt/local/include -DHAVE_CONFIG_H -I. -I.. +LDFLAGS := $(LDFLAGS) -L/opt/local/lib -lid3tag -logg -lvorbisfile -lFLAC -lvorbis -ltag_c TARGET = scanner OBJECTS=scanner-driver.o restart.o err.o scan-wma.o scan-aac.o scan-wav.o scan-flac.o scan-ogg.o scan-mp3.o scan-url.o scan-mpc.o