mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-13 07:53:23 -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;
|
return CONF_E_BADELEMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(strcmp(value,"") == 0) {
|
||||||
|
if(!pce->required) {
|
||||||
|
return CONF_E_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch(pce->type) {
|
switch(pce->type) {
|
||||||
case CONF_T_MULTICOMMA: /* can't really check these */
|
case CONF_T_MULTICOMMA: /* can't really check these */
|
||||||
case CONF_T_STRING:
|
case CONF_T_STRING:
|
||||||
@ -904,6 +910,29 @@ int conf_set_string(char *section, char *key, char *value, int verify) {
|
|||||||
if(pce)
|
if(pce)
|
||||||
key_type = pce->type;
|
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);
|
pitem = _conf_fetch_item(conf_main,section,key);
|
||||||
if(!pitem) {
|
if(!pitem) {
|
||||||
/* fetch the section and add it to that list */
|
/* 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;
|
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
|
* 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_set_flags(LL *pl, unsigned int flags);
|
||||||
extern int ll_get_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_fetch_item(LL *pl, char *key);
|
||||||
extern LL_ITEM *ll_get_next(LL *pl, LL_ITEM *prev);
|
extern LL_ITEM *ll_get_next(LL *pl, LL_ITEM *prev);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user