mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-25 22:55:56 -05:00
fix for ticket #7 -- empty values delete items
This commit is contained in:
parent
1b723bca94
commit
703221c715
29
src/conf.c
29
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 */
|
||||
|
30
src/ll.c
30
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
|
||||
*/
|
||||
|
2
src/ll.h
2
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user