comparison 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
comparison
equal deleted inserted replaced
236:5a0e8ed56c2a 237:5f9f3a65032e
187 msgout->hdr_list = NULL; 187 msgout->hdr_list = NULL;
188 } 188 }
189 DEBUG(5) debugf("rewrite_headers() returning\n"); 189 DEBUG(5) debugf("rewrite_headers() returning\n");
190 } 190 }
191 191
192 /*
193 Split a recipient list into the three groups:
194 - local recipients
195 - local net recipients
196 - other/remote/online recipients
197 It should be possible to call the function like:
198 split_rcpts(rcpts, hostlist, local, others, others);
199 This would split online between local and localnet+online recipients.
200 (untested yet; remove this line if you saw it worked -- meillo 2010-10-21)
201 If host_list is NULL, only splitting between local and other is done.
202 */
192 void 203 void
193 rcptlist_with_one_of_hostlist(GList * rcpt_list, GList * host_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list) 204 split_rcpts(GList* rcpt_list, GList* localnets, GList** rl_local, GList** rl_localnet, GList** rl_others)
194 { 205 {
195 GList *rcpt_node; 206 GList *rcpt_node;
207 GList *host_node = NULL;
208 address *rcpt = NULL;
196 209
197 if (rcpt_list == NULL) 210 if (rcpt_list == NULL)
198 return; 211 return;
199 212
200 foreach(rcpt_list, rcpt_node) { 213 foreach(rcpt_list, rcpt_node) {
201 address *rcpt = (address *) (rcpt_node->data); 214 rcpt = (address *) (rcpt_node->data);
202 GList *host_node = NULL; 215 host_node = NULL;
203 216
204 foreach(host_list, host_node) { 217 if (addr_is_local(rcpt)) {
205 gchar *host = (gchar *) (host_node->data); 218 if (rl_local)
206 if (fnmatch(host, rcpt->domain, FNM_CASEFOLD) == 0) 219 *rl_local = g_list_append(*rl_local, rcpt);
207 break;
208 }
209 if (host_node) {
210 if (p_rcpt_list)
211 *p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
212 } else { 220 } else {
213 if (p_non_rcpt_list) 221 /* if localnets is NULL, host_node will be NULL,
214 *p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt); 222 hence all non-locals are put to others */
215 } 223 foreach(localnets, host_node) {
216 224 gchar *host = (gchar *) (host_node->data);
217 } 225 if (fnmatch(host, rcpt->domain, FNM_CASEFOLD) == 0)
218 } 226 break;
219 227 }
220 void 228 if (host_node) {
221 rcptlist_with_addr_is_local(GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list) 229 if (rl_localnet)
222 { 230 *rl_localnet = g_list_append(*rl_localnet, rcpt);
223 GList *rcpt_node; 231 } else {
224 232 if (rl_others)
225 if (rcpt_list == NULL) 233 *rl_others = g_list_append(*rl_others, rcpt);
226 return; 234 }
227 235 }
228 foreach(rcpt_list, rcpt_node) {
229 address *rcpt = (address *) (rcpt_node->data);
230 if (addr_is_local(rcpt)) {
231 if (p_rcpt_list)
232 *p_rcpt_list = g_list_append(*p_rcpt_list, rcpt);
233 } else {
234 if (p_non_rcpt_list)
235 *p_non_rcpt_list = g_list_append(*p_non_rcpt_list, rcpt);
236 }
237
238 } 236 }
239 } 237 }
240 238
241 static gint 239 static gint
242 _g_list_addrcmp(gconstpointer a, gconstpointer b) 240 _g_list_addrcmp(gconstpointer a, gconstpointer b)
295 { 293 {
296 GList *tmp_list = NULL; 294 GList *tmp_list = NULL;
297 /* sort out those domains that can be sent over this connection: */ 295 /* sort out those domains that can be sent over this connection: */
298 if (route->allowed_rcpt_domains) { 296 if (route->allowed_rcpt_domains) {
299 DEBUG(5) debugf("testing for route->allowed_rcpt_domains\n"); 297 DEBUG(5) debugf("testing for route->allowed_rcpt_domains\n");
300 rcptlist_with_one_of_hostlist(rcpt_list, route->allowed_rcpt_domains, &tmp_list, p_non_rcpt_list); 298 split_rcpts(rcpt_list, route->allowed_rcpt_domains, NULL, &tmp_list, p_non_rcpt_list);
301 } else { 299 } else {
302 DEBUG(5) debugf("route->allowed_rcpt_domains == NULL\n"); 300 DEBUG(5) debugf("route->allowed_rcpt_domains == NULL\n");
303 tmp_list = g_list_copy(rcpt_list); 301 tmp_list = g_list_copy(rcpt_list);
304 } 302 }
305 303
306 /* sort out those domains that cannot be sent over this connection: */ 304 /* sort out those domains that cannot be sent over this connection: */
307 rcptlist_with_one_of_hostlist(tmp_list, route->not_allowed_rcpt_domains, p_non_rcpt_list, p_rcpt_list); 305 split_rcpts(tmp_list, route->not_allowed_rcpt_domains, NULL, p_non_rcpt_list, p_rcpt_list);
308 g_list_free(tmp_list); 306 g_list_free(tmp_list);
309 } 307 }
310 308
311 msg_out* 309 msg_out*
312 route_prepare_msgout(connect_route * route, msg_out * msgout) 310 route_prepare_msgout(connect_route * route, msg_out * msgout)