Check all parameters before writing them to the config file, send meaningful information to web client on bad update

This commit is contained in:
Ron Pedde 2006-05-31 02:33:23 +00:00
parent 5486e8c76a
commit f15d1d7d96
2 changed files with 54 additions and 7 deletions

View File

@ -128,6 +128,11 @@ static CONF_ELEMENTS conf_elements[] = {
{ 0, 0, CONF_T_MULTICOMMA,"plugins","plugins" },
{ 0, 0, CONF_T_INT,"daap","empty_strings" },
{ 0, 0, CONF_T_INT,"daap","supports_browse" },
{ 0, 0, CONF_T_INT,"daap","supports_update" },
{ 0, 0, CONF_T_INT,"scanning","process_xml" },
{ 0, 0, CONF_T_INT,"scanning","ignore_appledouble" },
{ 0, 0, CONF_T_INT,"scanning","ignore_dotfiles" },
{ 0, 0, CONF_T_INT,"scanning","concat_compilations" },
{ 0, 0, CONF_T_INT, NULL, NULL }
};
@ -541,6 +546,7 @@ int conf_read(char *file) {
if(conf_main_file) {
conf_close();
free(conf_main_file);
}
conf_main_file = strdup(file);
@ -1129,10 +1135,7 @@ int conf_iswritable(void) {
if(!conf_main_file)
return FALSE;
if((fp = fopen(conf_main_file,"r+")) != NULL) {
fclose(fp);
retval = TRUE;
}
retval = !access(conf_main_file,W_OK);
_conf_unlock();
return retval;

View File

@ -110,12 +110,15 @@ XMLSTRUCT *xml_init(WS_CONNINFO *pwsc, int emit_header) {
void xml_update_config(WS_CONNINFO *pwsc) {
char *arg, *value, *duparg;
char *ptmp;
char *badparms=NULL;
void *handle;
int has_error=0;
int badparms_len=0;
int err;
handle = NULL;
while((handle=ws_enum_var(pwsc,&arg,&value,handle)) != NULL) {
/* arg will be section:value */
duparg = strdup(arg);
@ -123,10 +126,51 @@ void xml_update_config(WS_CONNINFO *pwsc) {
if(ptmp) {
*ptmp++ = '\0';
/* this is stupidly inefficient */
err = conf_set_string(duparg,ptmp,value,TRUE);
if(err != CONF_E_SUCCESS) {
has_error = TRUE;
if(!badparms) {
badparms_len = (int)strlen(arg) + 1;
badparms = (char*)malloc(badparms_len);
if(!badparms) {
DPRINTF(E_FATAL,L_MISC,"xml_update_config: malloc\n");
}
strcpy(badparms,arg);
} else {
badparms_len += strlen(arg) + 1;
badparms = (char*)realloc(badparms,badparms_len);
if(!badparms) {
DPRINTF(E_FATAL,L_MISC,"xml_update_config: malloc\n");
}
strcat(badparms,",");
strcat(badparms,arg);
}
}
}
free(duparg);
}
if(has_error) {
DPRINTF(E_INF,L_MISC,"Bad parms; %s\n",badparms);
xml_return_error(pwsc,500,badparms);
free(badparms);
return;
}
/* now set! */
while((handle=ws_enum_var(pwsc,&arg,&value,handle)) != NULL) {
/* arg will be section:value */
duparg = strdup(arg);
ptmp = strchr(duparg,':');
if(ptmp) {
*ptmp++ = '\0';
/* this is stupidly inefficient */
err = conf_set_string(duparg,ptmp,value,FALSE);
if(err != CONF_E_SUCCESS) {
free(duparg);
xml_return_error(pwsc,500,"Bad values");
/* shouldn't happen */
xml_return_error(pwsc,500,arg);
return;
}
}