diff --git a/src/conf.c b/src/conf.c index 21df0f07..ab6668b7 100644 --- a/src/conf.c +++ b/src/conf.c @@ -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 */ diff --git a/src/ll.c b/src/ll.c index b14153d3..5816343f 100644 --- a/src/ll.c +++ b/src/ll.c @@ -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 */ diff --git a/src/ll.h b/src/ll.h index 83909187..c4f89257 100644 --- a/src/ll.h +++ b/src/ll.h @@ -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);