masqmail

diff src/route.c @ 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 a80ebfa16cd5
children 87df0aa99cc7
line diff
     1.1 --- a/src/route.c	Fri Oct 22 11:15:24 2010 -0300
     1.2 +++ b/src/route.c	Fri Oct 22 11:56:47 2010 -0300
     1.3 @@ -189,52 +189,50 @@
     1.4  	DEBUG(5) debugf("rewrite_headers() returning\n");
     1.5  }
     1.6  
     1.7 +/*
     1.8 +Split a recipient list into the three groups:
     1.9 +- local recipients
    1.10 +- local net recipients
    1.11 +- other/remote/online recipients
    1.12 +It should be possible to call the function like:
    1.13 +	split_rcpts(rcpts, hostlist, local, others, others);
    1.14 +This would split online between local and localnet+online recipients.
    1.15 +(untested yet; remove this line if you saw it worked -- meillo 2010-10-21)
    1.16 +If host_list is NULL, only splitting between local and other is done.
    1.17 +*/
    1.18  void
    1.19 -rcptlist_with_one_of_hostlist(GList * rcpt_list, GList * host_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
    1.20 +split_rcpts(GList* rcpt_list, GList* localnets, GList** rl_local, GList** rl_localnet, GList** rl_others)
    1.21  {
    1.22  	GList *rcpt_node;
    1.23 +	GList *host_node = NULL;
    1.24 +	address *rcpt = NULL;
    1.25  
    1.26  	if (rcpt_list == NULL)
    1.27  		return;
    1.28  
    1.29  	foreach(rcpt_list, rcpt_node) {
    1.30 -		address *rcpt = (address *) (rcpt_node->data);
    1.31 -		GList *host_node = NULL;
    1.32 +		rcpt = (address *) (rcpt_node->data);
    1.33 +		host_node = NULL;
    1.34  
    1.35 -		foreach(host_list, host_node) {
    1.36 -			gchar *host = (gchar *) (host_node->data);
    1.37 -			if (fnmatch(host, rcpt->domain, FNM_CASEFOLD) == 0)
    1.38 -				break;
    1.39 +		if (addr_is_local(rcpt)) {
    1.40 +			if (rl_local)
    1.41 +				*rl_local = g_list_append(*rl_local, rcpt);
    1.42 +		} else {
    1.43 +			/* if localnets is NULL, host_node will be NULL,
    1.44 +			   hence all non-locals are put to others */
    1.45 +			foreach(localnets, host_node) {
    1.46 +				gchar *host = (gchar *) (host_node->data);
    1.47 +				if (fnmatch(host, rcpt->domain, FNM_CASEFOLD) == 0)
    1.48 +					break;
    1.49 +			}
    1.50 +			if (host_node) {
    1.51 +				if (rl_localnet)
    1.52 +					*rl_localnet = g_list_append(*rl_localnet, rcpt);
    1.53 +			} else {
    1.54 +				if (rl_others)
    1.55 +					*rl_others = g_list_append(*rl_others, rcpt);
    1.56 +			}
    1.57  		}
    1.58 -		if (host_node) {
    1.59 -			if (p_rcpt_list)
    1.60 -				*p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
    1.61 -		} else {
    1.62 -			if (p_non_rcpt_list)
    1.63 -				*p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
    1.64 -		}
    1.65 -
    1.66 -	}
    1.67 -}
    1.68 -
    1.69 -void
    1.70 -rcptlist_with_addr_is_local(GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
    1.71 -{
    1.72 -	GList *rcpt_node;
    1.73 -
    1.74 -	if (rcpt_list == NULL)
    1.75 -		return;
    1.76 -
    1.77 -	foreach(rcpt_list, rcpt_node) {
    1.78 -		address *rcpt = (address *) (rcpt_node->data);
    1.79 -		if (addr_is_local(rcpt)) {
    1.80 -			if (p_rcpt_list)
    1.81 -				*p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
    1.82 -		} else {
    1.83 -			if (p_non_rcpt_list)
    1.84 -				*p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
    1.85 -		}
    1.86 -
    1.87  	}
    1.88  }
    1.89  
    1.90 @@ -297,14 +295,14 @@
    1.91  	/* sort out those domains that can be sent over this connection: */
    1.92  	if (route->allowed_rcpt_domains) {
    1.93  		DEBUG(5) debugf("testing for route->allowed_rcpt_domains\n");
    1.94 -		rcptlist_with_one_of_hostlist(rcpt_list, route->allowed_rcpt_domains, &tmp_list, p_non_rcpt_list);
    1.95 +		split_rcpts(rcpt_list, route->allowed_rcpt_domains, NULL, &tmp_list, p_non_rcpt_list);
    1.96  	} else {
    1.97  		DEBUG(5) debugf("route->allowed_rcpt_domains == NULL\n");
    1.98  		tmp_list = g_list_copy(rcpt_list);
    1.99  	}
   1.100  
   1.101  	/* sort out those domains that cannot be sent over this connection: */
   1.102 -	rcptlist_with_one_of_hostlist(tmp_list, route->not_allowed_rcpt_domains, p_non_rcpt_list, p_rcpt_list);
   1.103 +	split_rcpts(tmp_list, route->not_allowed_rcpt_domains, NULL, p_non_rcpt_list, p_rcpt_list);
   1.104  	g_list_free(tmp_list);
   1.105  }
   1.106