start on validating single items
This commit is contained in:
parent
11fa293e41
commit
c99e0c23dc
48
src/conf.c
48
src/conf.c
|
@ -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.
|
||||
* 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;
|
||||
|
||||
_conf_lock();
|
||||
|
||||
/* verify the item */
|
||||
|
||||
pce = _conf_get_keyinfo(section,key);
|
||||
if(pce)
|
||||
key_type = pce->type;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
o/*
|
||||
* $Id$
|
||||
* Functions for reading and writing the config file
|
||||
*
|
||||
|
@ -31,6 +31,9 @@
|
|||
#define CONF_E_NOCONF 6 /** <No open config file */
|
||||
#define CONF_E_NOTFOUND 7
|
||||
#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_reload(void);
|
||||
|
@ -55,5 +58,6 @@ extern char *conf_get_filename(void);
|
|||
/* FIXME: get enum functions and move to xml-rpc */
|
||||
#include "webserver.h"
|
||||
extern int conf_xml_dump(WS_CONNINFO *pwsc);
|
||||
extern int conf_verify_element(char *section, char *key, char *value);
|
||||
|
||||
#endif /* _CONFIG_H_ */
|
||||
|
|
Loading…
Reference in New Issue