- readconf: allow spaces within string values.

Note that leading and trailing spaces are removed.
This commit is contained in:
Thomas Ries 2011-06-05 16:21:48 +00:00
parent 5f28e20fe8
commit 7ece7c5cb6
3 changed files with 36 additions and 22 deletions

View File

@ -1,5 +1,7 @@
0.8.1
=====
05-Jun-2011: - readconf: allow spaces within string values.
Note that leading and trailing spaces are removed.
01-Jun-2011: - new plugin_prefix: unconditionally prefixes outgoing
calls with a configurable prefix string
29-May-2011: - added search path "/etc/siproxd/siproxd.conf" to default

View File

@ -3,7 +3,7 @@
#
# !! This is a sample file, adapt it to your needs before using it !!
#
# !! Strings MUST NOT contain spaces !!
# !! Strings may contain spaces (since 0.8.1)
#
######################################################################

View File

@ -149,7 +149,7 @@ int read_config(char *name, int search, cfgopts_t cfgopts[], char *filter) {
* with "plugin_xxx", skip the rest.
* PLugins set this to load their scope
* of config options
* filter = "" - read main configuration, skipp everything
* filter = "" - read main configuration, skip everything
* starting with "plugin_" (hardwired).
*
* RETURNS
@ -203,7 +203,7 @@ static int parse_config (FILE *configfile, cfgopts_t configoptions[],
* with "plugin_xxx", skip the rest.
* PLugins set this to load their scope
* of config options
* filter = "" - read main configuration, skipp everything
* filter = "" - read main configuration, skip everything
* starting with "plugin_" (hardwired).
*/
if (filter) {
@ -263,8 +263,8 @@ static int parse_config (FILE *configfile, cfgopts_t configoptions[],
// String
//
case TYP_STRING:
/* the %as within sscanf seems to be not too portable.
* it is supposed to allocate the memory
/* the %as within sscanf is not portable (%as is
* supposed to allocate the memory within sscanf)
* num=sscanf(ptr,"%as",(char**)configoptions[k].dest);
*/
@ -272,8 +272,14 @@ static int parse_config (FILE *configfile, cfgopts_t configoptions[],
len=strlen(ptr)+1; /* include terminating zero!*/
tmpptr=(char*)malloc(len);
memcpy(configoptions[k].dest, &tmpptr, sizeof(tmpptr));
num=sscanf(ptr,"%s",tmpptr);
DEBUGC(DBCLASS_BABBLE,"STRING=%s",
/* get full string, until a "#" or end of line */
num=sscanf(ptr,"%[^#]",tmpptr);
tmpptr[len-1]='\0';
/* strip trailing spaces */
i = strlen(tmpptr);
do {i--;} while (i>0 && tmpptr[i] == ' ');
tmpptr[i+1]='\0';
DEBUGC(DBCLASS_BABBLE,"STRING=\"%s\"",
*(char**)configoptions[k].dest);
break;
@ -285,15 +291,21 @@ static int parse_config (FILE *configfile, cfgopts_t configoptions[],
/* figure out the amount of space we need */
char **dst;
int used=((stringa_t*)(configoptions[k].dest))->used;
// do I hace space left?
/* do I hace space left? */
if (used<=CFG_STRARR_SIZE){
len=strlen(ptr)+1; /* include terminating zero!*/
tmpptr=(char*)malloc(len);
dst=&((stringa_t*)(configoptions[k].dest))->
string[used];
memcpy(dst, &tmpptr, sizeof(tmpptr));
num=sscanf(ptr,"%s",tmpptr);
DEBUGC(DBCLASS_BABBLE,"STRINGA[%i]=%s", used, (char*) (
/* get full string, until a "#" or end of line */
num=sscanf(ptr,"%[^#]",tmpptr);
tmpptr[len-1]='\0';
/* strip trailing spaces */
i = strlen(tmpptr);
do {i--;} while (i>0 && tmpptr[i] == ' ');
tmpptr[i+1]='\0';
DEBUGC(DBCLASS_BABBLE,"STRINGA[%i]=\"%s\"", used, (char*) (
((stringa_t*)(configoptions[k].dest))->string[used]) );
((stringa_t*)(configoptions[k].dest))->used++;
} else {