fix for ticket #7 -- empty values delete items

This commit is contained in:
Ron Pedde 2006-05-18 05:11:07 +00:00
parent 1b723bca94
commit 703221c715
3 changed files with 61 additions and 0 deletions

View File

@ -306,6 +306,12 @@ int _conf_verify_element(char *section, char *key, char *value) {
return CONF_E_BADELEMENT;
}
if(strcmp(value,"") == 0) {
if(!pce->required) {
return CONF_E_SUCCESS;
}
}
switch(pce->type) {
case CONF_T_MULTICOMMA: /* can't really check these */
case CONF_T_STRING:
@ -904,6 +910,29 @@ int conf_set_string(char *section, char *key, char *value, int verify) {
if(pce)
key_type = pce->type;
if(strcmp(value,"") == 0) {
/* deleting the item */
pitem = ll_fetch_item(conf_main,section);
if(!pitem) {
_conf_unlock();
return CONF_E_SUCCESS;
}
section_ll = pitem->value.as_ll;
if(!section_ll) {
_conf_unlock();
return CONF_E_SUCCESS; /* ?? deleting an already deleted item */
}
if(ll_del_item(section_ll,key) == LL_E_SUCCESS) {
_conf_unlock();
return CONF_E_SUCCESS;
}
_conf_unlock();
return CONF_E_UNKNOWN;
}
pitem = _conf_fetch_item(conf_main,section,key);
if(!pitem) {
/* fetch the section and add it to that list */

View File

@ -119,6 +119,36 @@ int ll_add_ll(LL *pl, char *key, LL *pnew) {
return result;
}
int ll_del_item(LL *pl, char *key) {
LL_ITEM *phead, *ptail;
ptail = &pl->itemlist;
phead = pl->itemlist.next;
while(phead) {
if((pl->flags & LL_FLAG_HONORCASE) &&
(strcmp(phead->key,key)==0))
break;
if((!(pl->flags & LL_FLAG_HONORCASE) &&
(strcasecmp(phead->key,key)==0)))
break;
ptail=phead;
phead=phead->next;
}
if(phead) {
/* found the item... */
if(pl->tailptr == phead)
pl->tailptr = ptail;
ptail->next = phead->next;
} else {
/* no matching item */
return LL_E_NOKEY;
}
return LL_E_SUCCESS;
}
/**
* add an item to a ll
*/

View File

@ -71,6 +71,8 @@ extern int ll_update_ll(LL_ITEM *pli, LL *pnew);
extern int ll_set_flags(LL *pl, unsigned int flags);
extern int ll_get_flags(LL *pl, unsigned int *flags);
extern int ll_del_item(LL *pl, char *key);
extern LL_ITEM *ll_fetch_item(LL *pl, char *key);
extern LL_ITEM *ll_get_next(LL *pl, LL_ITEM *prev);