Fix problems with spaces in config files
This commit is contained in:
parent
457bd13492
commit
bef2d8714c
|
@ -232,8 +232,9 @@ int config_read(char *file) {
|
||||||
char path_buffer[PATH_MAX];
|
char path_buffer[PATH_MAX];
|
||||||
CONFIGELEMENT *pce;
|
CONFIGELEMENT *pce;
|
||||||
int handled;
|
int handled;
|
||||||
|
char *term;
|
||||||
|
|
||||||
buffer=(char*)malloc(MAX_LINE);
|
buffer=(char*)malloc(MAX_LINE+1);
|
||||||
if(!buffer)
|
if(!buffer)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -278,49 +279,56 @@ int config_read(char *file) {
|
||||||
config.servername=strdup("mt-daapd " VERSION);
|
config.servername=strdup("mt-daapd " VERSION);
|
||||||
|
|
||||||
while(fgets(buffer,MAX_LINE,fin)) {
|
while(fgets(buffer,MAX_LINE,fin)) {
|
||||||
if(*buffer != '#') {
|
buffer[MAX_LINE] = '\0';
|
||||||
value=buffer;
|
|
||||||
strsep(&value,"\t ");
|
|
||||||
if(value) {
|
|
||||||
while((*value==' ')||(*value=='\t'))
|
|
||||||
value++;
|
|
||||||
|
|
||||||
comment=value;
|
comment=strchr(buffer,'#');
|
||||||
strsep(&comment,"#");
|
if(comment)
|
||||||
|
*comment = '\0';
|
||||||
|
|
||||||
if(value[strlen(value)-1] == '\n')
|
while(strlen(buffer) && (strchr("\n\r ",buffer[strlen(buffer)-1])))
|
||||||
value[strlen(value)-1] = '\0';
|
buffer[strlen(buffer)-1] = '\0';
|
||||||
|
|
||||||
pce=config_elements;
|
term=buffer;
|
||||||
handled=0;
|
|
||||||
while((!handled) && (pce->config_element != -1)) {
|
|
||||||
if((strcasecmp(buffer,pce->name)==0) && (pce->config_element)) {
|
|
||||||
/* valid config directive */
|
|
||||||
handled=1;
|
|
||||||
pce->changed=1;
|
|
||||||
|
|
||||||
DPRINTF(E_DBG,L_CONF,"Read %s: %s\n",pce->name,value);
|
while((*term=='\t') || (*term==' '))
|
||||||
|
term++;
|
||||||
|
|
||||||
switch(pce->type) {
|
value=term;
|
||||||
case CONFIG_TYPE_STRING:
|
|
||||||
/* DWB: free space to prevent small leak */
|
strsep(&value,"\t ");
|
||||||
if(*((char **)(pce->var)))
|
if((value) && (term) && (strlen(term))) {
|
||||||
free(*((char **)(pce->var)));
|
while(strlen(value) && (strchr("\t ",*value)))
|
||||||
*((char **)(pce->var)) = (void*)strdup(value);
|
value++;
|
||||||
break;
|
|
||||||
case CONFIG_TYPE_INT:
|
pce=config_elements;
|
||||||
*((int*)(pce->var)) = atoi(value);
|
handled=0;
|
||||||
break;
|
while((!handled) && (pce->config_element != -1)) {
|
||||||
}
|
if((strcasecmp(term,pce->name)==0) && (pce->config_element)) {
|
||||||
|
/* valid config directive */
|
||||||
|
handled=1;
|
||||||
|
pce->changed=1;
|
||||||
|
|
||||||
|
DPRINTF(E_DBG,L_CONF,"Read %s: %s\n",pce->name,value);
|
||||||
|
|
||||||
|
switch(pce->type) {
|
||||||
|
case CONFIG_TYPE_STRING:
|
||||||
|
/* DWB: free space to prevent small leak */
|
||||||
|
if(*((char **)(pce->var)))
|
||||||
|
free(*((char **)(pce->var)));
|
||||||
|
*((char **)(pce->var)) = (void*)strdup(value);
|
||||||
|
break;
|
||||||
|
case CONFIG_TYPE_INT:
|
||||||
|
*((int*)(pce->var)) = atoi(value);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
pce++;
|
|
||||||
}
|
}
|
||||||
|
pce++;
|
||||||
|
}
|
||||||
|
|
||||||
if(!handled) {
|
if(!handled) {
|
||||||
fprintf(stderr,"Invalid config directive: %s\n",buffer);
|
fprintf(stderr,"Invalid config directive: %s\n",buffer);
|
||||||
fclose(fin);
|
fclose(fin);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue