- 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 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 01-Jun-2011: - new plugin_prefix: unconditionally prefixes outgoing
calls with a configurable prefix string calls with a configurable prefix string
29-May-2011: - added search path "/etc/siproxd/siproxd.conf" to default 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 !! # !! 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. * with "plugin_xxx", skip the rest.
* PLugins set this to load their scope * PLugins set this to load their scope
* of config options * of config options
* filter = "" - read main configuration, skipp everything * filter = "" - read main configuration, skip everything
* starting with "plugin_" (hardwired). * starting with "plugin_" (hardwired).
* *
* RETURNS * RETURNS
@ -203,7 +203,7 @@ static int parse_config (FILE *configfile, cfgopts_t configoptions[],
* with "plugin_xxx", skip the rest. * with "plugin_xxx", skip the rest.
* PLugins set this to load their scope * PLugins set this to load their scope
* of config options * of config options
* filter = "" - read main configuration, skipp everything * filter = "" - read main configuration, skip everything
* starting with "plugin_" (hardwired). * starting with "plugin_" (hardwired).
*/ */
if (filter) { if (filter) {
@ -263,19 +263,25 @@ static int parse_config (FILE *configfile, cfgopts_t configoptions[],
// String // String
// //
case TYP_STRING: case TYP_STRING:
/* the %as within sscanf seems to be not too portable. /* the %as within sscanf is not portable (%as is
* it is supposed to allocate the memory * supposed to allocate the memory within sscanf)
* num=sscanf(ptr,"%as",(char**)configoptions[k].dest); * num=sscanf(ptr,"%as",(char**)configoptions[k].dest);
*/ */
/* figure out the amount of space we need */ /* figure out the amount of space we need */
len=strlen(ptr)+1; /* include terminating zero!*/ len=strlen(ptr)+1; /* include terminating zero!*/
tmpptr=(char*)malloc(len); tmpptr=(char*)malloc(len);
memcpy(configoptions[k].dest, &tmpptr, sizeof(tmpptr)); memcpy(configoptions[k].dest, &tmpptr, sizeof(tmpptr));
num=sscanf(ptr,"%s",tmpptr); /* get full string, until a "#" or end of line */
DEBUGC(DBCLASS_BABBLE,"STRING=%s", num=sscanf(ptr,"%[^#]",tmpptr);
*(char**)configoptions[k].dest); tmpptr[len-1]='\0';
break; /* 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 // String array
@ -283,17 +289,23 @@ static int parse_config (FILE *configfile, cfgopts_t configoptions[],
case TYP_STRINGA: case TYP_STRINGA:
{ {
/* figure out the amount of space we need */ /* figure out the amount of space we need */
char **dst; char **dst;
int used=((stringa_t*)(configoptions[k].dest))->used; int used=((stringa_t*)(configoptions[k].dest))->used;
// do I hace space left? /* do I hace space left? */
if (used<=CFG_STRARR_SIZE){ if (used<=CFG_STRARR_SIZE){
len=strlen(ptr)+1; /* include terminating zero!*/ len=strlen(ptr)+1; /* include terminating zero!*/
tmpptr=(char*)malloc(len); tmpptr=(char*)malloc(len);
dst=&((stringa_t*)(configoptions[k].dest))-> dst=&((stringa_t*)(configoptions[k].dest))->
string[used]; string[used];
memcpy(dst, &tmpptr, sizeof(tmpptr)); memcpy(dst, &tmpptr, sizeof(tmpptr));
num=sscanf(ptr,"%s",tmpptr); /* get full string, until a "#" or end of line */
DEBUGC(DBCLASS_BABBLE,"STRINGA[%i]=%s", used, (char*) ( 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))->string[used]) );
((stringa_t*)(configoptions[k].dest))->used++; ((stringa_t*)(configoptions[k].dest))->used++;
} else { } else {