masqmail

changeset 237:5f9f3a65032e

refactoring: new function split_rcpts() replaces two others split_rcpts() merges rcptlist_with_one_of_hostlist() and rcptlist_with_addr_is_local() into one with hardly adding complexity I'd actually say that the overall complexity decreased. Have a look at the comment for split_rcpts() in route.c
author markus schnalke <meillo@marmaro.de>
date Fri, 22 Oct 2010 11:56:47 -0300
parents 5a0e8ed56c2a
children ec28ce798b79
files src/deliver.c src/masqmail.h src/route.c
diffstat 3 files changed, 58 insertions(+), 72 deletions(-) [+]
line diff
     1.1 --- a/src/deliver.c	Fri Oct 22 11:15:24 2010 -0300
     1.2 +++ b/src/deliver.c	Fri Oct 22 11:56:47 2010 -0300
     1.3 @@ -668,7 +668,7 @@
     1.4  		GList *rcpt_list;
     1.5  		GList *local_rcpt_list = NULL;
     1.6  		GList *localnet_rcpt_list = NULL;
     1.7 -		GList *other_rcpt_list;
     1.8 +		GList *other_rcpt_list = NULL;
     1.9  
    1.10  		if (!spool_lock(msgout->msg->uid)) {
    1.11  			DEBUG(5) debugf("spool_lock(%s) failed.\n", msgout->msg->uid);
    1.12 @@ -689,40 +689,28 @@
    1.13  			rcpt_list = aliased_rcpt_list;
    1.14  		}
    1.15  
    1.16 +		split_rcpts(rcpt_list, conf.local_nets, &local_rcpt_list, &localnet_rcpt_list, &other_rcpt_list);
    1.17 +		g_list_free(rcpt_list);
    1.18 +
    1.19  		/* local recipients */
    1.20 -		other_rcpt_list = NULL;
    1.21 -		rcptlist_with_addr_is_local(rcpt_list, &local_rcpt_list, &other_rcpt_list);
    1.22 -
    1.23 -		if (flags & DLVR_LOCAL) {
    1.24 -			if (local_rcpt_list != NULL) {
    1.25 -				msg_out *local_msgout = clone_msg_out(msgout);
    1.26 -				local_msgout->rcpt_list = local_rcpt_list;
    1.27 -				local_msgout_list = g_list_append(local_msgout_list, local_msgout);
    1.28 -			}
    1.29 +		if ((flags & DLVR_LOCAL) && local_rcpt_list) {
    1.30 +			msg_out *local_msgout = clone_msg_out(msgout);
    1.31 +			local_msgout->rcpt_list = local_rcpt_list;
    1.32 +			local_msgout_list = g_list_append(local_msgout_list, local_msgout);
    1.33  		}
    1.34  
    1.35 -		g_list_free(rcpt_list);
    1.36 -
    1.37  		/* local net recipients */
    1.38 -		rcpt_list = other_rcpt_list;
    1.39 -		other_rcpt_list = NULL;
    1.40 -		rcptlist_with_one_of_hostlist(rcpt_list, conf.local_nets, &localnet_rcpt_list, &other_rcpt_list);
    1.41 -
    1.42 -		if (flags & DLVR_LAN) {
    1.43 -			if (localnet_rcpt_list != NULL) {
    1.44 -				msg_out *localnet_msgout = clone_msg_out(msgout);
    1.45 -				localnet_msgout->rcpt_list = localnet_rcpt_list;
    1.46 -				localnet_msgout_list = g_list_append(localnet_msgout_list, localnet_msgout);
    1.47 -			}
    1.48 +		if ((flags & DLVR_LAN) && localnet_rcpt_list) {
    1.49 +			msg_out *localnet_msgout = clone_msg_out(msgout);
    1.50 +			localnet_msgout->rcpt_list = localnet_rcpt_list;
    1.51 +			localnet_msgout_list = g_list_append(localnet_msgout_list, localnet_msgout);
    1.52  		}
    1.53  
    1.54 -		if (flags & DLVR_ONLINE) {
    1.55 -			/* the rest, this is online delivery */
    1.56 -			if (other_rcpt_list != NULL) {
    1.57 -				msg_out *other_msgout = clone_msg_out(msgout);
    1.58 -				other_msgout->rcpt_list = other_rcpt_list;
    1.59 -				other_msgout_list = g_list_append(other_msgout_list, other_msgout);
    1.60 -			}
    1.61 +		/* remote recipients (the rest), requires online delivery  */
    1.62 +		if ((flags & DLVR_ONLINE) && other_rcpt_list) {
    1.63 +			msg_out *other_msgout = clone_msg_out(msgout);
    1.64 +			other_msgout->rcpt_list = other_rcpt_list;
    1.65 +			other_msgout_list = g_list_append(other_msgout_list, other_msgout);
    1.66  		}
    1.67  	}
    1.68  
    1.69 @@ -730,7 +718,8 @@
    1.70  		destroy_table(alias_table);
    1.71  
    1.72  	/* actual delivery */
    1.73 -	if (local_msgout_list != NULL) {
    1.74 +
    1.75 +	if (local_msgout_list) {
    1.76  		DEBUG(5) debugf("local_msgout_list\n");
    1.77  		foreach(local_msgout_list, msgout_node) {
    1.78  			msg_out *msgout = (msg_out *) (msgout_node->data);
    1.79 @@ -740,7 +729,7 @@
    1.80  		destroy_msg_out_list(local_msgout_list);
    1.81  	}
    1.82  
    1.83 -	if (localnet_msgout_list != NULL) {
    1.84 +	if (localnet_msgout_list) {
    1.85  		GList *route_list = NULL;
    1.86  		GList *route_node;
    1.87  
    1.88 @@ -759,7 +748,7 @@
    1.89  		destroy_route_list(route_list);
    1.90  	}
    1.91  
    1.92 -	if (other_msgout_list != NULL) {
    1.93 +	if (other_msgout_list) {
    1.94  		DEBUG(5) debugf("other_msgout_list\n");
    1.95  		if (!deliver_msgout_list_online(other_msgout_list))
    1.96  			ok = FALSE;
     2.1 --- a/src/masqmail.h	Fri Oct 22 11:15:24 2010 -0300
     2.2 +++ b/src/masqmail.h	Fri Oct 22 11:56:47 2010 -0300
     2.3 @@ -498,8 +498,7 @@
     2.4  msgout_perhost *create_msgout_perhost(gchar * host);
     2.5  void destroy_msgout_perhost(msgout_perhost * mo_ph);
     2.6  void rewrite_headers(msg_out * msgout, connect_route * route);
     2.7 -void rcptlist_with_one_of_hostlist(GList * rcpt_list, GList * host_list, GList **, GList **);
     2.8 -void rcptlist_with_addr_is_local(GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list);
     2.9 +void split_rcpts(GList* rcpt_list, GList* localnets, GList** rl_local, GList** rl_localnet, GList** rl_others);
    2.10  gboolean route_strip_msgout(connect_route * route, msg_out * msgout);
    2.11  msg_out *route_prepare_msgout(connect_route * route, msg_out * msgout);
    2.12  GList *route_msgout_list(connect_route * route, GList * msgout_list);
     3.1 --- a/src/route.c	Fri Oct 22 11:15:24 2010 -0300
     3.2 +++ b/src/route.c	Fri Oct 22 11:56:47 2010 -0300
     3.3 @@ -189,52 +189,50 @@
     3.4  	DEBUG(5) debugf("rewrite_headers() returning\n");
     3.5  }
     3.6  
     3.7 +/*
     3.8 +Split a recipient list into the three groups:
     3.9 +- local recipients
    3.10 +- local net recipients
    3.11 +- other/remote/online recipients
    3.12 +It should be possible to call the function like:
    3.13 +	split_rcpts(rcpts, hostlist, local, others, others);
    3.14 +This would split online between local and localnet+online recipients.
    3.15 +(untested yet; remove this line if you saw it worked -- meillo 2010-10-21)
    3.16 +If host_list is NULL, only splitting between local and other is done.
    3.17 +*/
    3.18  void
    3.19 -rcptlist_with_one_of_hostlist(GList * rcpt_list, GList * host_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
    3.20 +split_rcpts(GList* rcpt_list, GList* localnets, GList** rl_local, GList** rl_localnet, GList** rl_others)
    3.21  {
    3.22  	GList *rcpt_node;
    3.23 +	GList *host_node = NULL;
    3.24 +	address *rcpt = NULL;
    3.25  
    3.26  	if (rcpt_list == NULL)
    3.27  		return;
    3.28  
    3.29  	foreach(rcpt_list, rcpt_node) {
    3.30 -		address *rcpt = (address *) (rcpt_node->data);
    3.31 -		GList *host_node = NULL;
    3.32 +		rcpt = (address *) (rcpt_node->data);
    3.33 +		host_node = NULL;
    3.34  
    3.35 -		foreach(host_list, host_node) {
    3.36 -			gchar *host = (gchar *) (host_node->data);
    3.37 -			if (fnmatch(host, rcpt->domain, FNM_CASEFOLD) == 0)
    3.38 -				break;
    3.39 +		if (addr_is_local(rcpt)) {
    3.40 +			if (rl_local)
    3.41 +				*rl_local = g_list_append(*rl_local, rcpt);
    3.42 +		} else {
    3.43 +			/* if localnets is NULL, host_node will be NULL,
    3.44 +			   hence all non-locals are put to others */
    3.45 +			foreach(localnets, host_node) {
    3.46 +				gchar *host = (gchar *) (host_node->data);
    3.47 +				if (fnmatch(host, rcpt->domain, FNM_CASEFOLD) == 0)
    3.48 +					break;
    3.49 +			}
    3.50 +			if (host_node) {
    3.51 +				if (rl_localnet)
    3.52 +					*rl_localnet = g_list_append(*rl_localnet, rcpt);
    3.53 +			} else {
    3.54 +				if (rl_others)
    3.55 +					*rl_others = g_list_append(*rl_others, rcpt);
    3.56 +			}
    3.57  		}
    3.58 -		if (host_node) {
    3.59 -			if (p_rcpt_list)
    3.60 -				*p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
    3.61 -		} else {
    3.62 -			if (p_non_rcpt_list)
    3.63 -				*p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
    3.64 -		}
    3.65 -
    3.66 -	}
    3.67 -}
    3.68 -
    3.69 -void
    3.70 -rcptlist_with_addr_is_local(GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
    3.71 -{
    3.72 -	GList *rcpt_node;
    3.73 -
    3.74 -	if (rcpt_list == NULL)
    3.75 -		return;
    3.76 -
    3.77 -	foreach(rcpt_list, rcpt_node) {
    3.78 -		address *rcpt = (address *) (rcpt_node->data);
    3.79 -		if (addr_is_local(rcpt)) {
    3.80 -			if (p_rcpt_list)
    3.81 -				*p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
    3.82 -		} else {
    3.83 -			if (p_non_rcpt_list)
    3.84 -				*p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
    3.85 -		}
    3.86 -
    3.87  	}
    3.88  }
    3.89  
    3.90 @@ -297,14 +295,14 @@
    3.91  	/* sort out those domains that can be sent over this connection: */
    3.92  	if (route->allowed_rcpt_domains) {
    3.93  		DEBUG(5) debugf("testing for route->allowed_rcpt_domains\n");
    3.94 -		rcptlist_with_one_of_hostlist(rcpt_list, route->allowed_rcpt_domains, &tmp_list, p_non_rcpt_list);
    3.95 +		split_rcpts(rcpt_list, route->allowed_rcpt_domains, NULL, &tmp_list, p_non_rcpt_list);
    3.96  	} else {
    3.97  		DEBUG(5) debugf("route->allowed_rcpt_domains == NULL\n");
    3.98  		tmp_list = g_list_copy(rcpt_list);
    3.99  	}
   3.100  
   3.101  	/* sort out those domains that cannot be sent over this connection: */
   3.102 -	rcptlist_with_one_of_hostlist(tmp_list, route->not_allowed_rcpt_domains, p_non_rcpt_list, p_rcpt_list);
   3.103 +	split_rcpts(tmp_list, route->not_allowed_rcpt_domains, NULL, p_non_rcpt_list, p_rcpt_list);
   3.104  	g_list_free(tmp_list);
   3.105  }
   3.106