masqmail

changeset 402:eedc23877cd5

Ensure lval and rval are always stripped. Plus minor refactoring.
author markus schnalke <meillo@marmaro.de>
date Tue, 21 Feb 2012 16:11:28 +0100
parents 885e3d886199
children 7954b82040b3
files src/conf.c
diffstat 1 files changed, 16 insertions(+), 11 deletions(-) [+]
line diff
     1.1 --- a/src/conf.c	Tue Feb 21 16:11:00 2012 +0100
     1.2 +++ b/src/conf.c	Tue Feb 21 16:11:28 2012 +0100
     1.3 @@ -145,23 +145,24 @@
     1.4  	foreach(plain_list, node) {
     1.5  		gchar *item = (gchar *) (node->data);
     1.6  		char *at;
     1.7 -		char *p;
     1.8 +		char *ep;
     1.9  		address *addr = calloc(1, sizeof(address));
    1.10  
    1.11 -		for (p=item+strlen(item)-1; isspace(*p) || *p=='>'; p--) {
    1.12 -			*p = '\0';
    1.13 -		}
    1.14 -		for (p=item; isspace(*p) || *p=='<'; p++) {
    1.15 +		ep = item + strlen(item) - 1;
    1.16 +		if (*item == '<' && *ep == '>') {
    1.17 +			*item = '\0';
    1.18 +			*ep = '\0';
    1.19 +			g_strstrip(item);
    1.20  		}
    1.21  
    1.22 -		addr->address = strdup(p);
    1.23 -		at = strrchr(p, '@');
    1.24 +		addr->address = strdup(item);
    1.25 +		at = strrchr(item, '@');
    1.26  		if (at) {
    1.27  			*at = '\0';
    1.28 -			addr->local_part = strdup(p);
    1.29 +			addr->local_part = strdup(item);
    1.30  			addr->domain = strdup(at+1);
    1.31  		} else {
    1.32 -			addr->local_part = strdup(p);
    1.33 +			addr->local_part = strdup(item);
    1.34  			/* No `@', thus any domain is okay. */
    1.35  			addr->domain = "*";
    1.36  		}
    1.37 @@ -217,6 +218,7 @@
    1.38  	if ((cp = strchr(line, ':'))) {
    1.39  		*cp = '\0';
    1.40  	}
    1.41 +	g_strstrip(line);
    1.42  	iface->address = g_strdup(line);
    1.43  	iface->port = (cp) ? atoi(++cp) : def_port;
    1.44  	DEBUG(9) fprintf(stderr,"found: address:port=%s:%u\n",
    1.45 @@ -283,7 +285,8 @@
    1.46  
    1.47  	DEBUG(9) fprintf(stderr, "read_lval() 2\n");
    1.48  	while (1) {
    1.49 -		if ((c = fgetc(in)) == EOF) {
    1.50 +		c = fgetc(in);
    1.51 +		if (c == EOF) {
    1.52  			fprintf(stderr, "unexpected EOF after %s\n", buf);
    1.53  			return FALSE;
    1.54  		}
    1.55 @@ -297,6 +300,7 @@
    1.56  		*ptr++ = c;
    1.57  	}
    1.58  	*ptr = '\0';
    1.59 +	g_strstrip(buf);
    1.60  	ungetc(c, in);
    1.61  	eat_spaces(in);
    1.62  	DEBUG(9) fprintf(stderr, "lval = %s\n", buf);
    1.63 @@ -352,6 +356,7 @@
    1.64  		}
    1.65  		*ptr = '\0';
    1.66  	}
    1.67 +	g_strstrip(buf);
    1.68  	DEBUG(9) fprintf(stderr, "rval = %s\n", buf);
    1.69  	/* eat trailing of line */
    1.70  	while ((c = fgetc(in)) != EOF && c != '\n') {
    1.71 @@ -638,7 +643,7 @@
    1.72  						(gchar *) (pair->value), TRUE);
    1.73  				g_free(pair->value);
    1.74  				pair->value = (gpointer *) addr;
    1.75 -				route->map_return_path_addresses = g_list_append( route->map_return_path_addresses, pair);
    1.76 +				route->map_return_path_addresses = g_list_append(route->map_return_path_addresses, pair);
    1.77  				g_free(item);
    1.78  			}
    1.79  			g_list_free(list);