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 (2012-02-21)
parents 885e3d886199
children 7954b82040b3
files src/conf.c
diffstat 1 files changed, 16 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/conf.c	Tue Feb 21 16:11:00 2012 +0100
+++ b/src/conf.c	Tue Feb 21 16:11:28 2012 +0100
@@ -145,23 +145,24 @@
 	foreach(plain_list, node) {
 		gchar *item = (gchar *) (node->data);
 		char *at;
-		char *p;
+		char *ep;
 		address *addr = calloc(1, sizeof(address));
 
-		for (p=item+strlen(item)-1; isspace(*p) || *p=='>'; p--) {
-			*p = '\0';
-		}
-		for (p=item; isspace(*p) || *p=='<'; p++) {
+		ep = item + strlen(item) - 1;
+		if (*item == '<' && *ep == '>') {
+			*item = '\0';
+			*ep = '\0';
+			g_strstrip(item);
 		}
 
-		addr->address = strdup(p);
-		at = strrchr(p, '@');
+		addr->address = strdup(item);
+		at = strrchr(item, '@');
 		if (at) {
 			*at = '\0';
-			addr->local_part = strdup(p);
+			addr->local_part = strdup(item);
 			addr->domain = strdup(at+1);
 		} else {
-			addr->local_part = strdup(p);
+			addr->local_part = strdup(item);
 			/* No `@', thus any domain is okay. */
 			addr->domain = "*";
 		}
@@ -217,6 +218,7 @@
 	if ((cp = strchr(line, ':'))) {
 		*cp = '\0';
 	}
+	g_strstrip(line);
 	iface->address = g_strdup(line);
 	iface->port = (cp) ? atoi(++cp) : def_port;
 	DEBUG(9) fprintf(stderr,"found: address:port=%s:%u\n",
@@ -283,7 +285,8 @@
 
 	DEBUG(9) fprintf(stderr, "read_lval() 2\n");
 	while (1) {
-		if ((c = fgetc(in)) == EOF) {
+		c = fgetc(in);
+		if (c == EOF) {
 			fprintf(stderr, "unexpected EOF after %s\n", buf);
 			return FALSE;
 		}
@@ -297,6 +300,7 @@
 		*ptr++ = c;
 	}
 	*ptr = '\0';
+	g_strstrip(buf);
 	ungetc(c, in);
 	eat_spaces(in);
 	DEBUG(9) fprintf(stderr, "lval = %s\n", buf);
@@ -352,6 +356,7 @@
 		}
 		*ptr = '\0';
 	}
+	g_strstrip(buf);
 	DEBUG(9) fprintf(stderr, "rval = %s\n", buf);
 	/* eat trailing of line */
 	while ((c = fgetc(in)) != EOF && c != '\n') {
@@ -638,7 +643,7 @@
 						(gchar *) (pair->value), TRUE);
 				g_free(pair->value);
 				pair->value = (gpointer *) addr;
-				route->map_return_path_addresses = g_list_append( route->map_return_path_addresses, pair);
+				route->map_return_path_addresses = g_list_append(route->map_return_path_addresses, pair);
 				g_free(item);
 			}
 			g_list_free(list);