masqmail

diff src/conf.c @ 393:5e728dd64c1b

Various refactoring and code layouting in the second half of conf.c.
author markus schnalke <meillo@marmaro.de>
date Sat, 18 Feb 2012 18:48:19 +0100
parents c5fd796ea06e
children c8e3d1a79313
line diff
     1.1 --- a/src/conf.c	Sat Feb 18 18:07:55 2012 +0100
     1.2 +++ b/src/conf.c	Sat Feb 18 18:48:19 2012 +0100
     1.3 @@ -376,30 +376,31 @@
     1.4  	DEBUG(9) fprintf(stderr, "read_statement()\n");
     1.5  
     1.6  	/* eat comments and empty lines: */
     1.7 -	if (!eat_comments(in))
     1.8 +	if (!eat_comments(in)) {
     1.9  		return FALSE;
    1.10 -
    1.11 +	}
    1.12  	if (!read_lval(in, lval, lsize)) {
    1.13  		return FALSE;
    1.14  	}
    1.15  
    1.16  	DEBUG(9) fprintf(stderr, "  lval = %s\n", lval);
    1.17 -	if ((c = fgetc(in) == '=')) {
    1.18 -		if (read_rval(in, rval, rsize)) {
    1.19 -			DEBUG(9) fprintf(stderr, "  rval = %s\n", rval);
    1.20 -			return TRUE;
    1.21 -		}
    1.22 -	} else {
    1.23 -		DEBUG(9) fprintf(stderr,"  '=' expected after %s, char was '%c'\n", lval, c);
    1.24 -		fprintf(stderr, "'=' expected after %s, char was '%c'\n", lval, c);
    1.25 +	if ((c = fgetc(in) != '=')) {
    1.26 +		fprintf(stderr, "'=' expected after %s, char was '%c'\n",
    1.27 +				lval, c);
    1.28  	}
    1.29 -	return FALSE;
    1.30 +	if (!read_rval(in, rval, rsize)) {
    1.31 +		return FALSE;
    1.32 +	}
    1.33 +	DEBUG(9) fprintf(stderr, "  rval = %s\n", rval);
    1.34 +	return TRUE;
    1.35  }
    1.36  
    1.37  gboolean
    1.38  read_conf(gchar *filename)
    1.39  {
    1.40  	FILE *in;
    1.41 +	gchar lval[256], rval[2048];
    1.42 +	GList *listen_addrs_tmp = NULL;
    1.43  
    1.44  	conf.log_max_pri = 7;
    1.45  	conf.do_relay = TRUE;
    1.46 @@ -408,143 +409,146 @@
    1.47  	conf.max_msg_size = 0; /* no limit on msg size */
    1.48  	conf.spool_dir = SPOOL_DIR;
    1.49  	conf.mail_dir = "/var/mail";
    1.50 -	conf.listen_addresses = g_list_append(NULL, parse_interface("localhost", 25));
    1.51  
    1.52 -	if ((in = fopen(filename, "r")) == NULL) {
    1.53 -		logwrite(LOG_ALERT, "could not open config file %s: %s\n", filename, strerror(errno));
    1.54 +	if (!(in = fopen(filename, "r"))) {
    1.55 +		logwrite(LOG_ALERT, "could not open config file %s: %s\n",
    1.56 +				filename, strerror(errno));
    1.57  		return FALSE;
    1.58  	}
    1.59  
    1.60 -	gchar lval[256], rval[2048];
    1.61  	while (read_statement(in, lval, sizeof lval, rval, sizeof rval)) {
    1.62  		DEBUG(9) fprintf(stderr,"read_conf(): lval=%s\n", lval);
    1.63 -		if (strcmp(lval, "debug_level") == 0)
    1.64 +		if (strcmp(lval, "debug_level")==0) {
    1.65  			conf.debug_level = atoi(rval);
    1.66 -		else if (strcmp(lval, "run_as_user") == 0) {
    1.67 -			if (!conf.run_as_user)  /* you should not be able to reset that flag */
    1.68 +		} else if (strcmp(lval, "run_as_user")==0) {
    1.69 +			if (!conf.run_as_user) {
    1.70 +				/* you should not be able to reset that flag */
    1.71  				conf.run_as_user = parse_boolean(rval);
    1.72 -		} else if (strcmp(lval, "use_syslog") == 0)
    1.73 +			}
    1.74 +		} else if (strcmp(lval, "use_syslog")==0) {
    1.75  			conf.use_syslog = parse_boolean(rval);
    1.76 -		else if (strcmp(lval, "mail_dir") == 0)
    1.77 +		} else if (strcmp(lval, "mail_dir")==0) {
    1.78  			conf.mail_dir = g_strdup(rval);
    1.79 -		else if (strcmp(lval, "lock_dir") == 0)
    1.80 +		} else if (strcmp(lval, "lock_dir")==0) {
    1.81  			conf.lock_dir = g_strdup(rval);
    1.82 -		else if (strcmp(lval, "spool_dir") == 0)
    1.83 +		} else if (strcmp(lval, "spool_dir")==0) {
    1.84  			conf.spool_dir = g_strdup(rval);
    1.85 -		else if (strcmp(lval, "log_dir") == 0)
    1.86 +		} else if (strcmp(lval, "log_dir")==0) {
    1.87  			conf.log_dir = g_strdup(rval);
    1.88 -		else if (strcmp(lval, "host_name") == 0) {
    1.89 -			if (rval[0] != '/')
    1.90 +		} else if (strcmp(lval, "host_name")==0) {
    1.91 +			if (rval[0] != '/') {
    1.92  				conf.host_name = g_strdup(rval);
    1.93 -			else {
    1.94 +			} else {
    1.95  				char buf[256];
    1.96  				FILE *fptr = fopen(rval, "rt");
    1.97  				if (!fptr) {
    1.98 -					logwrite(LOG_ALERT, "could not open %s: %s\n", rval, strerror(errno));
    1.99 +					logwrite(LOG_ALERT, "could not open "
   1.100 +							"%s: %s\n", rval,
   1.101 +							strerror(errno));
   1.102  					return FALSE;
   1.103  				}
   1.104 -				fgets(buf, 255, fptr);
   1.105 -				g_strchomp(buf);
   1.106 +				fgets(buf, sizeof buf, fptr);
   1.107 +				g_strstrip(buf);
   1.108  				conf.host_name = g_strdup(buf);
   1.109  				fclose(fptr);
   1.110  			}
   1.111 -		} else if (strcmp(lval, "local_hosts") == 0)
   1.112 +		} else if (strcmp(lval, "local_hosts")==0) {
   1.113  			conf.local_hosts = parse_list(rval, TRUE);
   1.114 -		else if (strcmp(lval, "local_addresses") == 0)
   1.115 +		} else if (strcmp(lval, "local_addresses")==0) {
   1.116  			conf.local_addresses = parse_list(rval, TRUE);
   1.117 -		else if (strcmp(lval, "not_local_addresses") == 0)
   1.118 +		} else if (strcmp(lval, "not_local_addresses")==0) {
   1.119  			conf.not_local_addresses = parse_list(rval, TRUE);
   1.120 -		else if (strcmp(lval, "do_save_envelope_to") == 0)
   1.121 +		} else if (strcmp(lval, "do_save_envelope_to")==0) {
   1.122  			conf.do_save_envelope_to = parse_boolean(rval);
   1.123 -		else if (strcmp(lval, "defer_all") == 0)
   1.124 +		} else if (strcmp(lval, "defer_all")==0) {
   1.125  			conf.defer_all = parse_boolean(rval);
   1.126 -		else if (strcmp(lval, "do_relay") == 0)
   1.127 +		} else if (strcmp(lval, "do_relay")==0) {
   1.128  			conf.do_relay = parse_boolean(rval);
   1.129 -		else if (strcmp(lval, "alias_file") == 0) {
   1.130 +		} else if (strcmp(lval, "alias_file")==0) {
   1.131  			conf.alias_file = g_strdup(rval);
   1.132 -		} else if (strcmp(lval, "globalias_file") == 0) {
   1.133 +		} else if (strcmp(lval, "globalias_file")==0) {
   1.134  			conf.globalias_file = g_strdup(rval);
   1.135 -		} else if (strcmp(lval, "caseless_matching") == 0) {
   1.136 -			conf.localpartcmp = parse_boolean(rval) ? strcasecmp : strcmp;
   1.137 -		} else if (strcmp(lval, "mbox_default") == 0) {
   1.138 +		} else if (strcmp(lval, "caseless_matching")==0) {
   1.139 +			conf.localpartcmp = parse_boolean(rval) ?
   1.140 +					strcasecmp : strcmp;
   1.141 +		} else if (strcmp(lval, "mbox_default")==0) {
   1.142  			conf.mbox_default = g_strdup(rval);
   1.143 -		} else if (strcmp(lval, "mbox_users") == 0) {
   1.144 +		} else if (strcmp(lval, "mbox_users")==0) {
   1.145  			conf.mbox_users = parse_list(rval, TRUE);
   1.146 -		} else if (strcmp(lval, "mda_users") == 0) {
   1.147 +		} else if (strcmp(lval, "mda_users")==0) {
   1.148  			conf.mda_users = parse_list(rval, TRUE);
   1.149 -		} else if (strcmp(lval, "mda") == 0) {
   1.150 +		} else if (strcmp(lval, "mda")==0) {
   1.151  			conf.mda = g_strdup(rval);
   1.152 -		} else if (strcmp(lval, "mda_fromline") == 0) {
   1.153 +		} else if (strcmp(lval, "mda_fromline")==0) {
   1.154  			conf.mda_fromline = parse_boolean(rval);
   1.155 -		} else if (strcmp(lval, "mda_fromhack") == 0) {
   1.156 +		} else if (strcmp(lval, "mda_fromhack")==0) {
   1.157  			conf.mda_fromhack = parse_boolean(rval);
   1.158 -		} else if (strcmp(lval, "pipe_fromline") == 0) {
   1.159 +		} else if (strcmp(lval, "pipe_fromline")==0) {
   1.160  			conf.pipe_fromline = parse_boolean(rval);
   1.161 -		} else if (strcmp(lval, "pipe_fromhack") == 0) {
   1.162 +		} else if (strcmp(lval, "pipe_fromhack")==0) {
   1.163  			conf.pipe_fromhack = parse_boolean(rval);
   1.164 -		} else if (strcmp(lval, "listen_addresses") == 0) {
   1.165 -			GList *node;
   1.166 -			GList *tmp_list = parse_list(rval, TRUE);
   1.167 -
   1.168 -			conf.listen_addresses = NULL;
   1.169 -			foreach(tmp_list, node) {
   1.170 -				conf.listen_addresses = g_list_append(conf.listen_addresses, parse_interface((gchar *) (node-> data), 25));
   1.171 -				g_free(node->data);
   1.172 -			}
   1.173 -			g_list_free(tmp_list);
   1.174 -		} else if (strncmp(lval, "query_routes.", 13) == 0) {
   1.175 +		} else if (strcmp(lval, "listen_addresses")==0) {
   1.176 +			listen_addrs_tmp = parse_list(rval, TRUE);
   1.177 +		} else if (strncmp(lval, "query_routes.", 13)==0) {
   1.178  			GList *file_list = parse_list(rval, FALSE);
   1.179  			table_pair *pair = create_pair(lval+13, file_list);
   1.180 -			conf.query_routes = g_list_append(conf.query_routes, pair);
   1.181 -		} else if (strcmp(lval, "permanent_routes") == 0) {
   1.182 +			conf.query_routes = g_list_append(conf.query_routes,
   1.183 +					pair);
   1.184 +		} else if (strcmp(lval, "permanent_routes")==0) {
   1.185  			conf.perma_routes = parse_list(rval, FALSE);
   1.186 -		} else if (strcmp(lval, "online_query") == 0)
   1.187 +		} else if (strcmp(lval, "online_query")==0) {
   1.188  			conf.online_query = g_strdup(rval);
   1.189 -		else if (strcmp(lval, "do_queue") == 0)
   1.190 +		} else if (strcmp(lval, "do_queue")==0) {
   1.191  			conf.do_queue = parse_boolean(rval);
   1.192 -		else if (strcmp(lval, "errmsg_file") == 0)
   1.193 +		} else if (strcmp(lval, "errmsg_file")==0) {
   1.194  			conf.errmsg_file = g_strdup(rval);
   1.195 -		else if (strcmp(lval, "warnmsg_file") == 0)
   1.196 +		} else if (strcmp(lval, "warnmsg_file")==0) {
   1.197  			conf.warnmsg_file = g_strdup(rval);
   1.198 -		else if (strcmp(lval, "warn_intervals") == 0)
   1.199 +		} else if (strcmp(lval, "warn_intervals")==0) {
   1.200  			conf.warn_intervals = parse_list(rval, TRUE);
   1.201 -		else if (strcmp(lval, "max_defer_time") == 0) {
   1.202 +		} else if (strcmp(lval, "max_defer_time")==0) {
   1.203  			gint ival = time_interval(rval);
   1.204 -			if (ival < 0)
   1.205 -				logwrite(LOG_WARNING, "invalid time interval for 'max_defer_time': %s\n", rval);
   1.206 -			else
   1.207 +			if (ival < 0) {
   1.208 +				logwrite(LOG_WARNING, "invalid time interval "
   1.209 +						"for 'max_defer_time': %s\n",
   1.210 +						rval);
   1.211 +			} else {
   1.212  				conf.max_defer_time = ival;
   1.213 -		} else if (strcmp(lval, "log_user") == 0)
   1.214 +			}
   1.215 +		} else if (strcmp(lval, "log_user")==0) {
   1.216  			conf.log_user = g_strdup(rval);
   1.217 -		else if(strcmp(lval, "max_msg_size") == 0) {
   1.218 +		} else if(strcmp(lval, "max_msg_size")==0) {
   1.219  			conf.max_msg_size = atol(rval);
   1.220 -			DEBUG(9) fprintf(stderr,"rval=%s, conf.max_msg_size=%ld\n",
   1.221 +			DEBUG(9) fprintf(stderr,
   1.222 +					"rval=%s, conf.max_msg_size=%ld\n",
   1.223  			                 rval, conf.max_msg_size);
   1.224 +		} else {
   1.225 +			logwrite(LOG_WARNING, "var '%s' unknown: ignored\n",
   1.226 +					lval);
   1.227  		}
   1.228 -		else
   1.229 -			logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval);
   1.230  	}
   1.231  	fclose(in);
   1.232  
   1.233  	if (!conf.host_name) {
   1.234 -		logwrite(LOG_ALERT, "`host_name' MUST be set in masqmail.conf. See man page\n");
   1.235 +		logwrite(LOG_ALERT, "`host_name' MUST be set in "
   1.236 +				"masqmail.conf. See man page\n");
   1.237  		return FALSE;
   1.238  	}
   1.239 -
   1.240 -	if (conf.errmsg_file == NULL)
   1.241 +	if (!conf.errmsg_file) {
   1.242  		conf.errmsg_file = g_strdup(DATA_DIR "/tpl/failmsg.tpl");
   1.243 -	if (conf.warnmsg_file == NULL)
   1.244 +	}
   1.245 +	if (!conf.warnmsg_file) {
   1.246  		conf.warnmsg_file = g_strdup(DATA_DIR "/tpl/warnmsg.tpl");
   1.247 -
   1.248 -	if (conf.lock_dir == NULL)
   1.249 +	}
   1.250 +	if (!conf.lock_dir) {
   1.251  		conf.lock_dir = g_strdup_printf("%s/lock/", conf.spool_dir);
   1.252 -
   1.253 -	if (conf.mbox_default == NULL)
   1.254 +	}
   1.255 +	if (!conf.mbox_default) {
   1.256  		conf.mbox_default = g_strdup("mbox");
   1.257 -
   1.258 -	if (conf.warn_intervals == NULL)
   1.259 +	}
   1.260 +	if (!conf.warn_intervals) {
   1.261  		conf.warn_intervals = parse_list("1h;4h;8h;1d;2d;3d", TRUE);
   1.262 -
   1.263 +	}
   1.264  	if (!conf.local_hosts) {
   1.265  		char *shortname = strdup(conf.host_name);
   1.266  		char *p = strchr(shortname, '.');
   1.267 @@ -558,7 +562,21 @@
   1.268  		free(shortname);
   1.269  		free(local_hosts_str);
   1.270  	}
   1.271 +	if (!listen_addrs_tmp) {
   1.272 +		conf.listen_addresses = g_list_append(NULL,
   1.273 +				parse_interface("localhost", 25));
   1.274 +	} else {
   1.275 +		GList *node;
   1.276  
   1.277 +		foreach(listen_addrs_tmp, node) {
   1.278 +			conf.listen_addresses =
   1.279 +					g_list_append(conf.listen_addresses,
   1.280 +					parse_interface((gchar *) node->data,
   1.281 +					25));
   1.282 +			g_free(node->data);
   1.283 +		}
   1.284 +		g_list_free(listen_addrs_tmp);
   1.285 +	}
   1.286  
   1.287  	return TRUE;
   1.288  }
   1.289 @@ -566,76 +584,73 @@
   1.290  connect_route*
   1.291  read_route(gchar *filename, gboolean is_perma)
   1.292  {
   1.293 -	gboolean ok = FALSE;
   1.294  	FILE *in;
   1.295 -
   1.296 -	connect_route *route = g_malloc(sizeof(connect_route));
   1.297 -	memset(route, 0, sizeof(connect_route));
   1.298 +	connect_route *route;
   1.299 +	gchar lval[256], rval[2048];
   1.300  
   1.301  	DEBUG(5) debugf("read_route, filename = %s\n", filename);
   1.302  
   1.303 -	route->filename = g_strdup(filename);
   1.304 -	route->name = route->filename;  /* quick hack */
   1.305 -
   1.306 -	route->expand_h_sender_address = TRUE;
   1.307 -
   1.308 -	route->is_perma = is_perma;
   1.309 -
   1.310 -	route->do_pipelining = TRUE;
   1.311 -
   1.312 -	if ((in = fopen(route->filename, "r")) == NULL) {
   1.313 -		logwrite(LOG_ALERT, "could not open route file %s: %s\n", route->filename, strerror(errno));
   1.314 -		g_free(route);
   1.315 +	if (!(in = fopen(filename, "r"))) {
   1.316 +		logwrite(LOG_ALERT, "could not open route file %s: %s\n",
   1.317 +				filename, strerror(errno));
   1.318  		return NULL;
   1.319  	}
   1.320  
   1.321 -	gchar lval[256], rval[2048];
   1.322 +	route = g_malloc(sizeof(connect_route));
   1.323 +	memset(route, 0, sizeof(connect_route));
   1.324 +	route->filename = g_strdup(filename);
   1.325 +	route->name = route->filename;  /* quick hack */
   1.326 +	route->expand_h_sender_address = TRUE;
   1.327 +	route->is_perma = is_perma;
   1.328 +	route->do_pipelining = TRUE;
   1.329 +
   1.330  	while (read_statement(in, lval, sizeof lval, rval, sizeof rval)) {
   1.331 -		if (strcmp(lval, "mail_host") == 0)
   1.332 +		if (strcmp(lval, "mail_host")==0) {
   1.333  			route->mail_host = parse_interface(rval, 25);
   1.334 -		else if (strcmp(lval, "helo_name") == 0)
   1.335 +		} else if (strcmp(lval, "helo_name")==0) {
   1.336  			route->helo_name = g_strdup(rval);
   1.337 -		else if (strcmp(lval, "wrapper") == 0)
   1.338 +		} else if (strcmp(lval, "wrapper")==0) {
   1.339  			route->wrapper = g_strdup(rval);
   1.340 -		else if (strcmp(lval, "connect_error_fail") == 0)
   1.341 +		} else if (strcmp(lval, "connect_error_fail")==0) {
   1.342  			route->connect_error_fail = parse_boolean(rval);
   1.343 -		else if (strcmp(lval, "do_correct_helo") == 0)
   1.344 +		} else if (strcmp(lval, "do_correct_helo")==0) {
   1.345  			route->do_correct_helo = parse_boolean(rval);
   1.346 -		else if (strcmp(lval, "instant_helo") == 0)
   1.347 +		} else if (strcmp(lval, "instant_helo")==0) {
   1.348  			route->instant_helo = parse_boolean(rval);
   1.349 -		else if (strcmp(lval, "do_pipelining") == 0)
   1.350 +		} else if (strcmp(lval, "do_pipelining")==0) {
   1.351  			route->do_pipelining = parse_boolean(rval);
   1.352  
   1.353 -		else if (strcmp(lval, "allowed_senders") == 0)
   1.354 +		} else if (strcmp(lval, "allowed_senders")==0) {
   1.355  			route->allowed_senders = parse_address_glob_list(rval);
   1.356 -		else if (strcmp(lval, "denied_senders") == 0)
   1.357 +		} else if (strcmp(lval, "denied_senders")==0) {
   1.358  			route->denied_senders = parse_address_glob_list(rval);
   1.359 -		else if (strcmp(lval, "allowed_recipients") == 0)
   1.360 +		} else if (strcmp(lval, "allowed_recipients")==0) {
   1.361  			route->allowed_recipients = parse_address_glob_list(rval);
   1.362 -		else if (strcmp(lval, "denied_recipients") == 0)
   1.363 +		} else if (strcmp(lval, "denied_recipients")==0) {
   1.364  			route->denied_recipients = parse_address_glob_list(rval);
   1.365  
   1.366 -		else if (strcmp(lval, "set_h_from_domain") == 0)
   1.367 +		} else if (strcmp(lval, "set_h_from_domain")==0) {
   1.368  			route->set_h_from_domain = g_strdup(rval);
   1.369 -		else if (strcmp(lval, "set_h_reply_to_domain") == 0)
   1.370 +		} else if (strcmp(lval, "set_h_reply_to_domain")==0) {
   1.371  			route->set_h_reply_to_domain = g_strdup(rval);
   1.372 -		else if (strcmp(lval, "set_return_path_domain") == 0)
   1.373 +		} else if (strcmp(lval, "set_return_path_domain")==0) {
   1.374  			route->set_return_path_domain = g_strdup(rval);
   1.375 -		else if (strcmp(lval, "map_return_path_addresses") == 0) {
   1.376 +		} else if (strcmp(lval, "map_return_path_addresses")==0) {
   1.377  			GList *node, *list;
   1.378  
   1.379  			list = parse_list(rval, TRUE);
   1.380  			foreach(list, node) {
   1.381  				gchar *item = (gchar *) (node->data);
   1.382  				table_pair *pair = parse_table_pair(item, ':');
   1.383 -				address *addr = create_address((gchar *) (pair->value), TRUE);
   1.384 +				address *addr = create_address(
   1.385 +						(gchar *) (pair->value), TRUE);
   1.386  				g_free(pair->value);
   1.387  				pair->value = (gpointer *) addr;
   1.388 -				route->map_return_path_addresses = g_list_append(route->map_return_path_addresses, pair);
   1.389 +				route->map_return_path_addresses = g_list_append( route->map_return_path_addresses, pair);
   1.390  				g_free(item);
   1.391  			}
   1.392  			g_list_free(list);
   1.393 -		} else if (strcmp(lval, "map_h_from_addresses") == 0) {
   1.394 +		} else if (strcmp(lval, "map_h_from_addresses")==0) {
   1.395  			GList *list, *node;
   1.396  
   1.397  			list = parse_list(rval, TRUE);
   1.398 @@ -646,7 +661,7 @@
   1.399  				g_free(item);
   1.400  			}
   1.401  			g_list_free(list);
   1.402 -		} else if (strcmp(lval, "map_h_reply_to_addresses") == 0) {
   1.403 +		} else if (strcmp(lval, "map_h_reply_to_addresses")==0) {
   1.404  			GList *list, *node;
   1.405  
   1.406  			list = parse_list(rval, TRUE);
   1.407 @@ -657,7 +672,7 @@
   1.408  				g_free(item);
   1.409  			}
   1.410  			g_list_free(list);
   1.411 -		} else if (strcmp(lval, "map_h_mail_followup_to_addresses") == 0) {
   1.412 +		} else if (strcmp(lval, "map_h_mail_followup_to_addresses")==0) {
   1.413  			GList *list, *node;
   1.414  
   1.415  			list = parse_list(rval, TRUE);
   1.416 @@ -668,70 +683,70 @@
   1.417  				g_free(item);
   1.418  			}
   1.419  			g_list_free(list);
   1.420 -		} else if (strcmp(lval, "expand_h_sender_domain") == 0) {
   1.421 +		} else if (strcmp(lval, "expand_h_sender_domain")==0) {
   1.422  			route->expand_h_sender_domain = parse_boolean(rval);
   1.423 -		} else if (strcmp(lval, "expand_h_sender_address") == 0) {
   1.424 +		} else if (strcmp(lval, "expand_h_sender_address")==0) {
   1.425  			route->expand_h_sender_address = parse_boolean(rval);
   1.426 -		} else if (strcmp(lval, "resolve_list") == 0)
   1.427 +		} else if (strcmp(lval, "resolve_list")==0) {
   1.428  			route->resolve_list = parse_resolve_list(rval);
   1.429 -		else if (strcmp(lval, "do_ssl") == 0) {
   1.430 +		} else if (strcmp(lval, "do_ssl")==0) {
   1.431  			/* we ignore this. This option is used by sqilconf */
   1.432  			;
   1.433 -		}
   1.434  #ifdef ENABLE_AUTH
   1.435 -		else if (strcmp(lval, "auth_name") == 0) {
   1.436 +		} else if (strcmp(lval, "auth_name")==0) {
   1.437  			route->auth_name = g_strdup(rval);
   1.438 -		} else if (strcmp(lval, "auth_login") == 0) {
   1.439 +		} else if (strcmp(lval, "auth_login")==0) {
   1.440  			route->auth_login = g_strdup(rval);
   1.441 -		} else if (strcmp(lval, "auth_secret") == 0) {
   1.442 +		} else if (strcmp(lval, "auth_secret")==0) {
   1.443  			route->auth_secret = g_strdup(rval);
   1.444 -		}
   1.445  #else
   1.446 -		else if ((strcmp(lval, "auth_name") == 0)
   1.447 -		         || (strcmp(lval, "auth_login") == 0)
   1.448 -		         || (strcmp(lval, "auth_secret") == 0)) {
   1.449 -			logwrite(LOG_WARNING, "%s ignored: not compiled with auth support.\n", lval);
   1.450 +		} else if ((strcmp(lval, "auth_name")==0) ||
   1.451 +				(strcmp(lval, "auth_login")==0) ||
   1.452 +				(strcmp(lval, "auth_secret")==0)) {
   1.453 +			logwrite(LOG_WARNING, "%s ignored: not compiled with "
   1.454 +					"auth support.\n", lval);
   1.455  		}
   1.456  #endif
   1.457 -		else if (strcmp(lval, "pipe") == 0) {
   1.458 +		} else if (strcmp(lval, "pipe")==0) {
   1.459  			route->pipe = g_strdup(rval);
   1.460 -		} else if (strcmp(lval, "pipe_fromline") == 0) {
   1.461 +		} else if (strcmp(lval, "pipe_fromline")==0) {
   1.462  			route->pipe_fromline = parse_boolean(rval);
   1.463 -		} else if (strcmp(lval, "pipe_fromhack") == 0) {
   1.464 +		} else if (strcmp(lval, "pipe_fromhack")==0) {
   1.465  			route->pipe_fromhack = parse_boolean(rval);
   1.466 -		} else if (strcmp(lval, "last_route") == 0) {
   1.467 +		} else if (strcmp(lval, "last_route")==0) {
   1.468  			route->last_route = parse_boolean(rval);
   1.469 -		} else
   1.470 -			logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval);
   1.471 +		} else {
   1.472 +			logwrite(LOG_WARNING, "var '%s' unknown: ignored\n",
   1.473 +					lval);
   1.474 +		}
   1.475  	}
   1.476  
   1.477  	if (!route->resolve_list) {
   1.478  #ifdef ENABLE_RESOLVER
   1.479 -		route->resolve_list = g_list_append(route->resolve_list, resolve_dns_mx);
   1.480 -		route->resolve_list = g_list_append(route->resolve_list, resolve_dns_a);
   1.481 +		route->resolve_list = g_list_append(route->resolve_list,
   1.482 +				resolve_dns_mx);
   1.483 +		route->resolve_list = g_list_append(route->resolve_list,
   1.484 +				resolve_dns_a);
   1.485  #endif
   1.486 -		route->resolve_list = g_list_append(route->resolve_list, resolve_byname);
   1.487 +		route->resolve_list = g_list_append(route->resolve_list,
   1.488 +				resolve_byname);
   1.489  	}
   1.490  	fclose(in);
   1.491 -	ok = TRUE;
   1.492  
   1.493 -	/* warn user about misconfigurations: */
   1.494 -	if ((route->map_h_from_addresses != NULL) && (route->set_h_from_domain != NULL)) {
   1.495 -		logwrite(LOG_WARNING, "'map_h_from_addresses' overrides 'set_h_from_domain'\n");
   1.496 +	/* warn user about mis-configurations: */
   1.497 +	if (route->map_h_from_addresses && route->set_h_from_domain) {
   1.498 +		logwrite(LOG_WARNING, "'map_h_from_addresses' overrides "
   1.499 +				"'set_h_from_domain'\n");
   1.500  		g_free(route->set_h_from_domain);
   1.501  		route->set_h_from_domain = NULL;
   1.502  	}
   1.503 -	if ((route->map_h_reply_to_addresses != NULL) && (route->set_h_reply_to_domain != NULL)) {
   1.504 -		logwrite(LOG_WARNING, "'map_h_reply_to_addresses' overrides 'set_h_reply_to_domain'\n");
   1.505 +	if (route->map_h_reply_to_addresses && route->set_h_reply_to_domain) {
   1.506 +		logwrite(LOG_WARNING, "'map_h_reply_to_addresses' overrides "
   1.507 +				"'set_h_reply_to_domain'\n");
   1.508  		g_free(route->set_h_reply_to_domain);
   1.509  		route->set_h_reply_to_domain = NULL;
   1.510  	}
   1.511  
   1.512 -	if (!ok) {
   1.513 -		g_free(route);
   1.514 -		route = NULL;
   1.515 -	}
   1.516 -
   1.517  	return route;
   1.518  }
   1.519  
   1.520 @@ -739,50 +754,64 @@
   1.521  _g_list_free_all(GList *list)
   1.522  {
   1.523  	GList *node;
   1.524 -	if (list) {
   1.525 -		foreach(list, node)
   1.526 -			g_free(node->data);
   1.527 -		g_list_free(list);
   1.528 +	if (!list) {
   1.529 +		return;
   1.530  	}
   1.531 +	foreach(list, node) {
   1.532 +		g_free(node->data);
   1.533 +	}
   1.534 +	g_list_free(list);
   1.535  }
   1.536  
   1.537  void
   1.538  destroy_route(connect_route *r)
   1.539  {
   1.540 -	if (r->filename)
   1.541 +	if (r->filename) {
   1.542  		g_free(r->filename);
   1.543 +	}
   1.544  	if (r->mail_host) {
   1.545  		g_free(r->mail_host->address);
   1.546  		g_free(r->mail_host);
   1.547  	}
   1.548 -	if (r->wrapper)
   1.549 +	if (r->wrapper) {
   1.550  		g_free(r->wrapper);
   1.551 -	if (r->helo_name)
   1.552 +	}
   1.553 +	if (r->helo_name) {
   1.554  		g_free(r->helo_name);
   1.555 +	}
   1.556  	_g_list_free_all(r->allowed_senders);
   1.557  	_g_list_free_all(r->denied_senders);
   1.558  	_g_list_free_all(r->allowed_recipients);
   1.559  	_g_list_free_all(r->denied_recipients);
   1.560 -	if (r->set_h_from_domain)
   1.561 +	if (r->set_h_from_domain) {
   1.562  		g_free(r->set_h_from_domain);
   1.563 -	if (r->set_h_reply_to_domain)
   1.564 +	}
   1.565 +	if (r->set_h_reply_to_domain) {
   1.566  		g_free(r->set_h_reply_to_domain);
   1.567 -	if (r->set_return_path_domain)
   1.568 +	}
   1.569 +	if (r->set_return_path_domain) {
   1.570  		g_free(r->set_return_path_domain);
   1.571 -	if (r->map_h_reply_to_addresses)
   1.572 +	}
   1.573 +	if (r->map_h_reply_to_addresses) {
   1.574  		destroy_table(r->map_h_reply_to_addresses);
   1.575 -	if (r->resolve_list)
   1.576 +	}
   1.577 +	if (r->resolve_list) {
   1.578  		g_list_free(r->resolve_list);
   1.579 +	}
   1.580  #ifdef ENABLE_AUTH
   1.581 -	if (r->auth_name)
   1.582 +	if (r->auth_name) {
   1.583  		g_free(r->auth_name);
   1.584 -	if (r->auth_login)
   1.585 +	}
   1.586 +	if (r->auth_login) {
   1.587  		g_free(r->auth_login);
   1.588 -	if (r->auth_secret)
   1.589 +	}
   1.590 +	if (r->auth_secret) {
   1.591  		g_free(r->auth_secret);
   1.592 +	}
   1.593  #endif
   1.594 -	if (r->pipe)
   1.595 +	if (r->pipe) {
   1.596  		g_free(r->pipe);
   1.597 +	}
   1.598  	g_free(r);
   1.599  }
   1.600  
   1.601 @@ -796,21 +825,20 @@
   1.602  	if (!conf.run_as_user) {
   1.603  		set_euidgid(0, 0, &saved_uid, &saved_gid);
   1.604  	}
   1.605 -
   1.606  	foreach(rf_list, node) {
   1.607  		gchar *fname = (gchar *) (node->data);
   1.608  		connect_route *route = read_route(fname, is_perma);
   1.609 -		if (route)
   1.610 +		if (route) {
   1.611  			list = g_list_append(list, route);
   1.612 -		else
   1.613 -			logwrite(LOG_ALERT, "could not read route configuration %s\n", fname);
   1.614 +		} else {
   1.615 +			logwrite(LOG_ALERT, "could not read route "
   1.616 +					"configuration %s\n", fname);
   1.617 +		}
   1.618  	}
   1.619 -
   1.620  	/* set uid and gid back */
   1.621  	if (!conf.run_as_user) {
   1.622  		set_euidgid(saved_uid, saved_gid, NULL, NULL);
   1.623  	}
   1.624 -
   1.625  	return list;
   1.626  }
   1.627