masqmail

diff src/alias.c @ 390:68ae9182059c

Refactoring and code layouting.
author markus schnalke <meillo@marmaro.de>
date Sat, 18 Feb 2012 13:50:02 +0100
parents a408411ff8df
children c7cc3c03193c
line diff
     1.1 --- a/src/alias.c	Sat Feb 18 13:43:30 2012 +0100
     1.2 +++ b/src/alias.c	Sat Feb 18 13:50:02 2012 +0100
     1.3 @@ -28,22 +28,24 @@
     1.4  	GList *addr_node;
     1.5  	address *a;
     1.6  
     1.7 -	if (addr->domain == NULL) {
     1.8 +	if (!addr->domain) {
     1.9  		return TRUE;
    1.10  	}
    1.11  	foreach(conf.local_hosts, dom_node) {
    1.12  		/* Note: FNM_CASEFOLD is a GNU extension */
    1.13 -		if (fnmatch(dom_node->data, addr->domain, FNM_CASEFOLD) != 0) {
    1.14 +		if (fnmatch(dom_node->data, addr->domain, FNM_CASEFOLD)!=0) {
    1.15  			/* no match, try next */
    1.16  			continue;
    1.17  		}
    1.18  		foreach(conf.not_local_addresses, addr_node) {
    1.19 -			a = create_address_qualified(addr_node->data, TRUE, conf.host_name);
    1.20 -			DEBUG(6) debugf("not_local_addresses: addr_node->data=%s a->address=%s\n",
    1.21 +			a = create_address_qualified(addr_node->data, TRUE,
    1.22 +					conf.host_name);
    1.23 +			DEBUG(6) debugf("not_local_addresses: "
    1.24 +					"addr_node->data=%s a->address=%s\n",
    1.25  			                addr_node->data, a->address);
    1.26  			if (addr_isequal(a, addr, conf.localpartcmp)) {
    1.27 +				/* also in not_local_addresses */
    1.28  				destroy_address(a);
    1.29 -				/* in local_hosts but also in not_local_addresses */
    1.30  				return FALSE;
    1.31  			}
    1.32  			destroy_address(a);
    1.33 @@ -52,12 +54,14 @@
    1.34  		return TRUE;
    1.35  	}
    1.36  	foreach(conf.local_addresses, addr_node) {
    1.37 -		a = create_address_qualified(addr_node->data, TRUE, conf.host_name);
    1.38 -		DEBUG(6) debugf("local_addresses: addr_node->data=%s a->address=%s\n",
    1.39 +		a = create_address_qualified(addr_node->data, TRUE,
    1.40 +				conf.host_name);
    1.41 +		DEBUG(6) debugf("local_addresses: addr_node->data=%s "
    1.42 +				"a->address=%s\n",
    1.43  		                addr_node->data, a->address);
    1.44  		if (addr_isequal(a, addr, conf.localpartcmp)) {
    1.45 +			/* in local_addresses */
    1.46  			destroy_address(a);
    1.47 -			/* in local_addresses */
    1.48  			return TRUE;
    1.49  		}
    1.50  		destroy_address(a);
    1.51 @@ -73,33 +77,37 @@
    1.52  	gchar *p, *q;
    1.53  
    1.54  	p = line;
    1.55 -	while (*p != '\0') {
    1.56 +	while (*p) {
    1.57  		q = buf;
    1.58 -		while (isspace(*p))
    1.59 +		while (isspace(*p)) {
    1.60  			p++;
    1.61 +		}
    1.62  		if (*p != '"') {
    1.63 -			while (*p && (*p != ',') && (q < buf + 255))
    1.64 +			while (*p && (*p != ',') && (q < buf + 255)) {
    1.65  				*(q++) = *(p++);
    1.66 +			}
    1.67  			*q = '\0';
    1.68  		} else {
    1.69  			gboolean escape = FALSE;
    1.70  			p++;
    1.71 -			while (*p && (*p != '"' || escape) && (q < buf + 255)) {
    1.72 -				if ((*p == '\\') && !escape)
    1.73 +			while (*p && (*p != '"' || escape) && (q < buf+255)) {
    1.74 +				if ((*p == '\\') && !escape) {
    1.75  					escape = TRUE;
    1.76 -				else {
    1.77 +				} else {
    1.78  					escape = FALSE;
    1.79  					*(q++) = *p;
    1.80  				}
    1.81  				p++;
    1.82  			}
    1.83  			*q = '\0';
    1.84 -			while (*p && (*p != ','))
    1.85 +			while (*p && (*p != ',')) {
    1.86  				p++;
    1.87 +			}
    1.88  		}
    1.89  		list = g_list_append(list, g_strdup(g_strchomp(buf)));
    1.90 -		if (*p)
    1.91 +		if (*p) {
    1.92  			p++;
    1.93 +		}
    1.94  	}
    1.95  	return list;
    1.96  }
    1.97 @@ -107,13 +115,11 @@
    1.98  static int
    1.99  globaliascmp(const char *pattern, const char *addr)
   1.100  {
   1.101 -	if (conf.localpartcmp==strcasecmp) {
   1.102 +	if (conf.localpartcmp == strcasecmp) {
   1.103  		return fnmatch(pattern, addr, FNM_CASEFOLD);
   1.104  	} else if (strncasecmp(addr, "postmaster", 10)==0) {
   1.105 -		/*
   1.106 -		**  postmaster must always be matched caseless
   1.107 -		**  see RFC 822 and RFC 5321
   1.108 -		*/
   1.109 +		/* postmaster must always be matched caseless
   1.110 +		** see RFC 822 and RFC 5321 */
   1.111  		return fnmatch(pattern, addr, FNM_CASEFOLD);
   1.112  	} else {
   1.113  		/* case-sensitive */
   1.114 @@ -142,10 +148,8 @@
   1.115  				globaliascmp);
   1.116  
   1.117  	} else if (strcasecmp(addr->local_part, "postmaster") == 0) {
   1.118 -		/*
   1.119 -		**  postmaster must always be matched caseless
   1.120 -		**  see RFC 822 and RFC 5321
   1.121 -		*/
   1.122 +		/* postmaster must always be matched caseless
   1.123 +		** see RFC 822 and RFC 5321 */
   1.124  		val = (gchar *) table_find_func(alias_table, addr->local_part,
   1.125  				strcasecmp);
   1.126  	} else {
   1.127 @@ -171,8 +175,10 @@
   1.128  		DEBUG(6) debugf("alias: processing '%s'\n", val);
   1.129  
   1.130  		if (val[0] == '\\') {
   1.131 -			DEBUG(5) debugf("alias: '%s' is marked as final, hence completed\n", val);
   1.132 -			alias_addr = create_address_qualified(val+1, TRUE, conf.host_name);
   1.133 +			DEBUG(5) debugf("alias: '%s' is marked as final, "
   1.134 +					"hence completed\n", val);
   1.135 +			alias_addr = create_address_qualified(val+1, TRUE,
   1.136 +					conf.host_name);
   1.137  			g_free(val);
   1.138  			DEBUG(6) debugf("alias:     address generated: '%s'\n",
   1.139  			                alias_addr->address);
   1.140 @@ -181,7 +187,8 @@
   1.141  		}
   1.142  	
   1.143  		if (val[0] == '|') {
   1.144 -			DEBUG(5) debugf("alias: '%s' is a pipe address\n", val);
   1.145 +			DEBUG(5) debugf("alias: '%s' is a pipe address\n",
   1.146 +					val);
   1.147  			alias_addr = create_address_pipe(val);
   1.148  			g_free(val);
   1.149  			DEBUG(6) debugf("alias:     pipe generated: %s\n",
   1.150 @@ -190,11 +197,13 @@
   1.151  			continue;
   1.152  		}
   1.153  
   1.154 -		alias_addr = create_address_qualified(val, TRUE, conf.host_name);
   1.155 +		alias_addr = create_address_qualified(val, TRUE,
   1.156 +				conf.host_name);
   1.157  		g_free(val);
   1.158  
   1.159  		if (!addr_is_local(alias_addr)) {
   1.160 -			DEBUG(5) debugf("alias: '%s' is non-local, hence completed\n",
   1.161 +			DEBUG(5) debugf("alias: '%s' is non-local, "
   1.162 +					"hence completed\n",
   1.163  					alias_addr->address);
   1.164  			alias_list = g_list_append(alias_list, alias_addr);
   1.165  			continue;
   1.166 @@ -204,8 +213,9 @@
   1.167  		/* but first ... search in parents for loops: */
   1.168  		if (addr_isequal_parent(addr, alias_addr, conf.localpartcmp)) {
   1.169  			/* loop detected, ignore this path */
   1.170 -			logwrite(LOG_ALERT, "alias: detected loop, hence ignoring '%s'\n",
   1.171 -			         alias_addr->local_part);
   1.172 +			logwrite(LOG_ALERT, "alias: detected loop, "
   1.173 +				"hence ignoring '%s'\n",
   1.174 +				alias_addr->local_part);
   1.175  			continue;
   1.176  		}
   1.177  		alias_addr->parent = addr;
   1.178 @@ -240,14 +250,18 @@
   1.179  
   1.180  		addr = (address *) (rcpt_node->data);
   1.181  		if (addr_is_local(addr)) {
   1.182 -			DEBUG(5) debugf("alias: (orig rcpt addr) expand local '%s'\n",
   1.183 -			                doglob ? addr->address : addr->local_part);
   1.184 +			DEBUG(5) debugf("alias: (orig rcpt addr) "
   1.185 +					"expand local '%s'\n",
   1.186 +			                doglob ? addr->address :
   1.187 +					addr->local_part);
   1.188  			alias_list = expand_one(alias_table, addr, doglob);
   1.189  			if (alias_list) {
   1.190 -				done_list = g_list_concat(done_list, alias_list);
   1.191 +				done_list = g_list_concat(done_list,
   1.192 +						alias_list);
   1.193  			}
   1.194  		} else {
   1.195 -			DEBUG(5) debugf("alias: (orig rcpt addr) don't expand non-local '%s'\n",
   1.196 +			DEBUG(5) debugf("alias: (orig rcpt addr) don't "
   1.197 +					"expand non-local '%s'\n",
   1.198  					addr->address);
   1.199  			done_list = g_list_append(done_list, addr);
   1.200  		}
   1.201 @@ -259,7 +273,8 @@
   1.202  	}
   1.203  
   1.204  	/* delete addresses of non_rcpt_list from done_list */
   1.205 -	for (rcpt_node = g_list_first(done_list); rcpt_node; rcpt_node = rcpt_node_next) {
   1.206 +	for (rcpt_node = g_list_first(done_list); rcpt_node;
   1.207 +			rcpt_node = rcpt_node_next) {
   1.208  		address *addr = (address *) (rcpt_node->data);
   1.209  		GList *non_node;
   1.210  
   1.211 @@ -267,7 +282,8 @@
   1.212  		foreach(non_rcpt_list, non_node) {
   1.213  			address *non_addr = (address *) (non_node->data);
   1.214  			if (addr_isequal(addr, non_addr, conf.localpartcmp)) {
   1.215 -				done_list = g_list_remove_link(done_list, rcpt_node);
   1.216 +				done_list = g_list_remove_link(done_list,
   1.217 +						rcpt_node);
   1.218  				g_list_free_1(rcpt_node);
   1.219  				/*
   1.220  				**  this address is still in the children