comparison src/conf.c @ 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 6f2a8113a79e
children 9b93c0a3bd8c
comparison
equal deleted inserted replaced
401:885e3d886199 402:eedc23877cd5
143 GList *list = NULL; 143 GList *list = NULL;
144 144
145 foreach(plain_list, node) { 145 foreach(plain_list, node) {
146 gchar *item = (gchar *) (node->data); 146 gchar *item = (gchar *) (node->data);
147 char *at; 147 char *at;
148 char *p; 148 char *ep;
149 address *addr = calloc(1, sizeof(address)); 149 address *addr = calloc(1, sizeof(address));
150 150
151 for (p=item+strlen(item)-1; isspace(*p) || *p=='>'; p--) { 151 ep = item + strlen(item) - 1;
152 *p = '\0'; 152 if (*item == '<' && *ep == '>') {
153 } 153 *item = '\0';
154 for (p=item; isspace(*p) || *p=='<'; p++) { 154 *ep = '\0';
155 } 155 g_strstrip(item);
156 156 }
157 addr->address = strdup(p); 157
158 at = strrchr(p, '@'); 158 addr->address = strdup(item);
159 at = strrchr(item, '@');
159 if (at) { 160 if (at) {
160 *at = '\0'; 161 *at = '\0';
161 addr->local_part = strdup(p); 162 addr->local_part = strdup(item);
162 addr->domain = strdup(at+1); 163 addr->domain = strdup(at+1);
163 } else { 164 } else {
164 addr->local_part = strdup(p); 165 addr->local_part = strdup(item);
165 /* No `@', thus any domain is okay. */ 166 /* No `@', thus any domain is okay. */
166 addr->domain = "*"; 167 addr->domain = "*";
167 } 168 }
168 list = g_list_append(list, addr); 169 list = g_list_append(list, addr);
169 DEBUG(6) debugf("parse_address_glob_list: " 170 DEBUG(6) debugf("parse_address_glob_list: "
215 216
216 DEBUG(9) fprintf(stderr, "parse_interface: %s\n", line); 217 DEBUG(9) fprintf(stderr, "parse_interface: %s\n", line);
217 if ((cp = strchr(line, ':'))) { 218 if ((cp = strchr(line, ':'))) {
218 *cp = '\0'; 219 *cp = '\0';
219 } 220 }
221 g_strstrip(line);
220 iface->address = g_strdup(line); 222 iface->address = g_strdup(line);
221 iface->port = (cp) ? atoi(++cp) : def_port; 223 iface->port = (cp) ? atoi(++cp) : def_port;
222 DEBUG(9) fprintf(stderr,"found: address:port=%s:%u\n", 224 DEBUG(9) fprintf(stderr,"found: address:port=%s:%u\n",
223 iface->address, iface->port); 225 iface->address, iface->port);
224 return iface; 226 return iface;
281 return FALSE; 283 return FALSE;
282 } 284 }
283 285
284 DEBUG(9) fprintf(stderr, "read_lval() 2\n"); 286 DEBUG(9) fprintf(stderr, "read_lval() 2\n");
285 while (1) { 287 while (1) {
286 if ((c = fgetc(in)) == EOF) { 288 c = fgetc(in);
289 if (c == EOF) {
287 fprintf(stderr, "unexpected EOF after %s\n", buf); 290 fprintf(stderr, "unexpected EOF after %s\n", buf);
288 return FALSE; 291 return FALSE;
289 } 292 }
290 if (ptr >= buf+size-1) { 293 if (ptr >= buf+size-1) {
291 fprintf(stderr, "lval too long\n"); 294 fprintf(stderr, "lval too long\n");
295 break; 298 break;
296 } 299 }
297 *ptr++ = c; 300 *ptr++ = c;
298 } 301 }
299 *ptr = '\0'; 302 *ptr = '\0';
303 g_strstrip(buf);
300 ungetc(c, in); 304 ungetc(c, in);
301 eat_spaces(in); 305 eat_spaces(in);
302 DEBUG(9) fprintf(stderr, "lval = %s\n", buf); 306 DEBUG(9) fprintf(stderr, "lval = %s\n", buf);
303 return *buf != '\0'; 307 return *buf != '\0';
304 } 308 }
350 *ptr++ = c; 354 *ptr++ = c;
351 escape = FALSE; 355 escape = FALSE;
352 } 356 }
353 *ptr = '\0'; 357 *ptr = '\0';
354 } 358 }
359 g_strstrip(buf);
355 DEBUG(9) fprintf(stderr, "rval = %s\n", buf); 360 DEBUG(9) fprintf(stderr, "rval = %s\n", buf);
356 /* eat trailing of line */ 361 /* eat trailing of line */
357 while ((c = fgetc(in)) != EOF && c != '\n') { 362 while ((c = fgetc(in)) != EOF && c != '\n') {
358 continue; 363 continue;
359 } 364 }
636 table_pair *pair = parse_table_pair(item, ':'); 641 table_pair *pair = parse_table_pair(item, ':');
637 address *addr = create_address( 642 address *addr = create_address(
638 (gchar *) (pair->value), TRUE); 643 (gchar *) (pair->value), TRUE);
639 g_free(pair->value); 644 g_free(pair->value);
640 pair->value = (gpointer *) addr; 645 pair->value = (gpointer *) addr;
641 route->map_return_path_addresses = g_list_append( route->map_return_path_addresses, pair); 646 route->map_return_path_addresses = g_list_append(route->map_return_path_addresses, pair);
642 g_free(item); 647 g_free(item);
643 } 648 }
644 g_list_free(list); 649 g_list_free(list);
645 } else if (strcmp(lval, "map_h_from_addresses")==0) { 650 } else if (strcmp(lval, "map_h_from_addresses")==0) {
646 GList *list, *node; 651 GList *list, *node;