diff --git a/ChangeLog b/ChangeLog index acf6fb2..1ca3c9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/doc/siproxd.conf.example b/doc/siproxd.conf.example index 1892696..b05ebf5 100644 --- a/doc/siproxd.conf.example +++ b/doc/siproxd.conf.example @@ -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) # ###################################################################### diff --git a/src/readconf.c b/src/readconf.c index 06ac964..47a22a0 100644 --- a/src/readconf.c +++ b/src/readconf.c @@ -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,19 +263,25 @@ 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); */ /* figure out the amount of space we need */ - 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", - *(char**)configoptions[k].dest); - break; + len=strlen(ptr)+1; /* include terminating zero!*/ + tmpptr=(char*)malloc(len); + memcpy(configoptions[k].dest, &tmpptr, sizeof(tmpptr)); + /* 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; // // String array @@ -283,17 +289,23 @@ static int parse_config (FILE *configfile, cfgopts_t configoptions[], case TYP_STRINGA: { /* figure out the amount of space we need */ - char **dst; - int used=((stringa_t*)(configoptions[k].dest))->used; - // do I hace space left? - if (used<=CFG_STRARR_SIZE){ - len=strlen(ptr)+1; /* include terminating zero!*/ - tmpptr=(char*)malloc(len); + char **dst; + int used=((stringa_t*)(configoptions[k].dest))->used; + /* 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*) ( + string[used]; + memcpy(dst, &tmpptr, sizeof(tmpptr)); + /* 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 {