start on validating single items

This commit is contained in:
Ron Pedde 2006-05-16 06:22:32 +00:00
parent 11fa293e41
commit c99e0c23dc
2 changed files with 53 additions and 1 deletions

View File

@ -285,6 +285,51 @@ int _conf_exists(LL_HANDLE pll, char *section, char *key) {
} }
/**
* verify a specific element, that is, see if changing a specific
* element, in a vacuum, would be problematic
*
* @param section section to test
* @param key key to test
* @param value value to test
* @returns CONF_E_SUCCESS on success
*/
int _conf_verify_element(char *section, char *key, char *value) {
CONF_ELEMENTS *pce;
pce = _conf_get_keyinfo(section, key);
if(!pce) {
return CONF_E_BADELEMENT;
}
switch(pce->conf_elements) {
case CONF_T_MULTICOMMA: /* can't really check these */
case CONF_T_STRING:
return CONF_E_SUCCESS;
break;
case CONF_T_INT:
if((atoi(value) || (strcmp(value,"0")==0)))
return CONF_E_SUCCESS;
return CONF_E_INTEXPECTED;
break;
case CONF_T_EXISTPATH:
if(!_conf_existdir(value))
return CONF_E_PATHEXPECTED;
return CONF_E_SUCCESS;
break;
default:
DPRINTF(E_LOG,L_CONF,"Bad config type: %d\n",pce->type);
break;
}
return CONF_E_SUCCESS;
}
/** /**
* Verify that the configuration isn't obviously wrong. * Verify that the configuration isn't obviously wrong.
* Type checking has already been done, this just checks * Type checking has already been done, this just checks
@ -839,6 +884,9 @@ int conf_set_string(char *section, char *key, char *value) {
int err; int err;
_conf_lock(); _conf_lock();
/* verify the item */
pce = _conf_get_keyinfo(section,key); pce = _conf_get_keyinfo(section,key);
if(pce) if(pce)
key_type = pce->type; key_type = pce->type;

View File

@ -1,4 +1,4 @@
/* o/*
* $Id$ * $Id$
* Functions for reading and writing the config file * Functions for reading and writing the config file
* *
@ -31,6 +31,9 @@
#define CONF_E_NOCONF 6 /** <No open config file */ #define CONF_E_NOCONF 6 /** <No open config file */
#define CONF_E_NOTFOUND 7 #define CONF_E_NOTFOUND 7
#define CONF_E_NOTWRITABLE 8 #define CONF_E_NOTWRITABLE 8
#define CONF_E_BADELEMENT 9
#define CONF_E_PATHEXPECTED 10
#define CONF_E_INTEXPECTED 11
extern int conf_read(char *file); extern int conf_read(char *file);
extern int conf_reload(void); extern int conf_reload(void);
@ -55,5 +58,6 @@ extern char *conf_get_filename(void);
/* FIXME: get enum functions and move to xml-rpc */ /* FIXME: get enum functions and move to xml-rpc */
#include "webserver.h" #include "webserver.h"
extern int conf_xml_dump(WS_CONNINFO *pwsc); extern int conf_xml_dump(WS_CONNINFO *pwsc);
extern int conf_verify_element(char *section, char *key, char *value);
#endif /* _CONFIG_H_ */ #endif /* _CONFIG_H_ */