masqmail-0.2

diff src/address.c @ 10:26e34ae9a3e3

changed indention and line wrapping to a more consistent style
author meillo@marmaro.de
date Mon, 27 Oct 2008 16:23:10 +0100
parents 08114f7dcc23
children 49dab67fe461
line diff
     1.1 --- a/src/address.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/address.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -19,171 +19,182 @@
     1.4  #include "masqmail.h"
     1.5  #include <fnmatch.h>
     1.6  
     1.7 -address *create_address(gchar *path, gboolean is_rfc821)
     1.8 +address*
     1.9 +create_address(gchar * path, gboolean is_rfc821)
    1.10  {
    1.11 -  address *addr;
    1.12 -  addr = _create_address(path, NULL, is_rfc821);
    1.13 -  
    1.14 -  if(addr != NULL){
    1.15 -    addr_unmark_delivered(addr);
    1.16 -  }
    1.17 -  return addr;
    1.18 +	address *addr;
    1.19 +	addr = _create_address(path, NULL, is_rfc821);
    1.20 +
    1.21 +	if (addr != NULL) {
    1.22 +		addr_unmark_delivered(addr);
    1.23 +	}
    1.24 +	return addr;
    1.25  }
    1.26  
    1.27 -address *create_address_qualified(gchar *path, gboolean is_rfc821,
    1.28 -				  gchar *domain)
    1.29 +address*
    1.30 +create_address_qualified(gchar * path, gboolean is_rfc821, gchar * domain)
    1.31  {
    1.32 -  address *addr = create_address(path, is_rfc821);
    1.33 -  if(addr != NULL){
    1.34 -    if(addr->domain == NULL)
    1.35 -      addr->domain = g_strdup(domain);
    1.36 -  }
    1.37 +	address *addr = create_address(path, is_rfc821);
    1.38 +	if (addr != NULL) {
    1.39 +		if (addr->domain == NULL)
    1.40 +			addr->domain = g_strdup(domain);
    1.41 +	}
    1.42  
    1.43 -  return addr;
    1.44 +	return addr;
    1.45  }
    1.46  
    1.47  /* nothing special about pipes here,
    1.48     but its only called for that purpose */
    1.49 -address *create_address_pipe(gchar *path)
    1.50 +address*
    1.51 +create_address_pipe(gchar * path)
    1.52  {
    1.53 -  address *addr = g_malloc(sizeof(address));
    1.54 +	address *addr = g_malloc(sizeof(address));
    1.55  
    1.56 -  if(addr){
    1.57 -    memset(addr, 0, sizeof(address));
    1.58 -    addr->address = g_strchomp(g_strdup(path));
    1.59 -    addr->local_part = g_strdup(addr->address);
    1.60 -  
    1.61 -    addr->domain = g_strdup("localhost"); /* quick hack */
    1.62 -  }
    1.63 -  return addr;
    1.64 +	if (addr) {
    1.65 +		memset(addr, 0, sizeof(address));
    1.66 +		addr->address = g_strchomp(g_strdup(path));
    1.67 +		addr->local_part = g_strdup(addr->address);
    1.68 +
    1.69 +		addr->domain = g_strdup("localhost");  /* quick hack */
    1.70 +	}
    1.71 +	return addr;
    1.72  }
    1.73  
    1.74 -void destroy_address(address *addr)
    1.75 +void
    1.76 +destroy_address(address * addr)
    1.77  {
    1.78 -  DEBUG(6) debugf("destroy_address entered\n");
    1.79 +	DEBUG(6) debugf("destroy_address entered\n");
    1.80  
    1.81 -  g_free(addr->address);
    1.82 -  g_free(addr->local_part);
    1.83 -  g_free(addr->domain);
    1.84 +	g_free(addr->address);
    1.85 +	g_free(addr->local_part);
    1.86 +	g_free(addr->domain);
    1.87  
    1.88 -  g_free(addr);
    1.89 +	g_free(addr);
    1.90  }
    1.91  
    1.92 -address *copy_modify_address(const address *orig, gchar *l_part, gchar *dom)
    1.93 +address*
    1.94 +copy_modify_address(const address * orig, gchar * l_part, gchar * dom)
    1.95  {
    1.96 -  address *addr = NULL;
    1.97 +	address *addr = NULL;
    1.98  
    1.99 -  if(orig){
   1.100 -    addr = g_malloc(sizeof(address));
   1.101 -    if(addr){
   1.102 -      addr->address = g_strdup(orig->address);
   1.103 +	if (orig) {
   1.104 +		addr = g_malloc(sizeof(address));
   1.105 +		if (addr) {
   1.106 +			addr->address = g_strdup(orig->address);
   1.107  
   1.108 -      if(l_part == NULL)
   1.109 -	addr->local_part = g_strdup(orig->local_part);
   1.110 -      else
   1.111 -	addr->local_part = g_strdup(l_part);
   1.112 +			if (l_part == NULL)
   1.113 +				addr->local_part = g_strdup(orig->local_part);
   1.114 +			else
   1.115 +				addr->local_part = g_strdup(l_part);
   1.116  
   1.117 -      if(dom == NULL)
   1.118 -	addr->domain = g_strdup(orig->domain);
   1.119 -      else
   1.120 -	addr->domain = g_strdup(dom);
   1.121 +			if (dom == NULL)
   1.122 +				addr->domain = g_strdup(orig->domain);
   1.123 +			else
   1.124 +				addr->domain = g_strdup(dom);
   1.125  
   1.126 -      addr->flags = 0;
   1.127 -      addr->children = NULL;
   1.128 -      addr->parent = NULL;
   1.129 -    }
   1.130 -  }
   1.131 -  return addr;
   1.132 +			addr->flags = 0;
   1.133 +			addr->children = NULL;
   1.134 +			addr->parent = NULL;
   1.135 +		}
   1.136 +	}
   1.137 +	return addr;
   1.138  }
   1.139  
   1.140 -gboolean addr_isequal(address *addr1, address *addr2)
   1.141 +gboolean
   1.142 +addr_isequal(address * addr1, address * addr2)
   1.143  {
   1.144 -  return
   1.145 -    (strcmp(addr1->local_part, addr2->local_part) == 0) &&
   1.146 -    (strcasecmp(addr1->domain, addr2->domain) == 0);
   1.147 +	return
   1.148 +		(strcmp(addr1->local_part, addr2->local_part) == 0) &&
   1.149 +		(strcasecmp(addr1->domain, addr2->domain) == 0);
   1.150  }
   1.151  
   1.152  /* searches in ancestors of addr1 */
   1.153 -gboolean addr_isequal_parent(address *addr1, address *addr2)
   1.154 +gboolean
   1.155 +addr_isequal_parent(address * addr1, address * addr2)
   1.156  {
   1.157 -  address *addr;
   1.158 +	address *addr;
   1.159  
   1.160 -  for(addr = addr1; addr; addr = addr->parent)
   1.161 -    if(addr_isequal(addr, addr2))
   1.162 -      return TRUE;
   1.163 +	for (addr = addr1; addr; addr = addr->parent)
   1.164 +		if (addr_isequal(addr, addr2))
   1.165 +			return TRUE;
   1.166  
   1.167 -  return FALSE;
   1.168 +	return FALSE;
   1.169  }
   1.170  
   1.171  /* careful, this is recursive */
   1.172  /* returns TRUE if ALL children have been delivered */
   1.173 -gboolean addr_is_delivered_children(address *addr)
   1.174 +gboolean
   1.175 +addr_is_delivered_children(address * addr)
   1.176  {
   1.177 -  GList *addr_node;
   1.178 +	GList *addr_node;
   1.179  
   1.180 -  if(addr->children == NULL) return addr_is_delivered(addr);
   1.181 +	if (addr->children == NULL)
   1.182 +		return addr_is_delivered(addr);
   1.183  
   1.184 -  foreach(addr->children, addr_node){
   1.185 -    address *addr = (address *)(addr_node->data);
   1.186 -    if(!addr_is_delivered_children(addr))
   1.187 -      return FALSE;
   1.188 -  }
   1.189 -  return TRUE;
   1.190 +	foreach(addr->children, addr_node) {
   1.191 +		address *addr = (address *) (addr_node->data);
   1.192 +		if (!addr_is_delivered_children(addr))
   1.193 +			return FALSE;
   1.194 +	}
   1.195 +	return TRUE;
   1.196  }
   1.197  
   1.198  /* careful, this is recursive */
   1.199  /* returns TRUE if ALL children have been either delivered or have failed */
   1.200 -gboolean addr_is_finished_children(address *addr)
   1.201 +gboolean
   1.202 +addr_is_finished_children(address * addr)
   1.203  {
   1.204 -  GList *addr_node;
   1.205 +	GList *addr_node;
   1.206  
   1.207 -  if(addr->children == NULL) return (addr_is_failed(addr) || addr_is_delivered(addr));
   1.208 +	if (addr->children == NULL)
   1.209 +		return (addr_is_failed(addr) || addr_is_delivered(addr));
   1.210  
   1.211 -  foreach(addr->children, addr_node){
   1.212 -    address *addr = (address *)(addr_node->data);
   1.213 -    if(!addr_is_finished_children(addr))
   1.214 -      return FALSE;
   1.215 -  }
   1.216 -  return TRUE;
   1.217 +	foreach(addr->children, addr_node) {
   1.218 +		address *addr = (address *) (addr_node->data);
   1.219 +		if (!addr_is_finished_children(addr))
   1.220 +			return FALSE;
   1.221 +	}
   1.222 +	return TRUE;
   1.223  }
   1.224  
   1.225  /* find original address */
   1.226 -address *addr_find_ancestor(address *addr)
   1.227 +address*
   1.228 +addr_find_ancestor(address * addr)
   1.229  {
   1.230 -  while(addr->parent) addr = addr->parent;
   1.231 -  return addr;
   1.232 +	while (addr->parent)
   1.233 +		addr = addr->parent;
   1.234 +	return addr;
   1.235  }
   1.236  
   1.237 -gchar *addr_string(address *addr)
   1.238 +gchar*
   1.239 +addr_string(address * addr)
   1.240  {
   1.241 -  static gchar *buffer = NULL;
   1.242 +	static gchar *buffer = NULL;
   1.243  
   1.244 -  if(addr == NULL){
   1.245 -    g_free(buffer);
   1.246 -    buffer = NULL;
   1.247 -    return NULL;
   1.248 -  }
   1.249 -  if(buffer)
   1.250 -    g_free(buffer);
   1.251 +	if (addr == NULL) {
   1.252 +		g_free(buffer);
   1.253 +		buffer = NULL;
   1.254 +		return NULL;
   1.255 +	}
   1.256 +	if (buffer)
   1.257 +		g_free(buffer);
   1.258  
   1.259 -  if(addr->local_part[0] == 0){
   1.260 -    buffer = g_strdup("<>");
   1.261 -  }else{
   1.262 -    buffer = g_strdup_printf("<%s@%s>",
   1.263 -			     addr->local_part ? addr->local_part : "",
   1.264 -			     addr->domain ? addr->domain : "");
   1.265 -  }
   1.266 -  return buffer;
   1.267 +	if (addr->local_part[0] == 0) {
   1.268 +		buffer = g_strdup("<>");
   1.269 +	} else {
   1.270 +		buffer = g_strdup_printf("<%s@%s>", addr->local_part ? addr->local_part : "", addr->domain ? addr->domain : "");
   1.271 +	}
   1.272 +	return buffer;
   1.273  }
   1.274  
   1.275 -gint addr_match(address *addr1, address *addr2)
   1.276 +gint
   1.277 +addr_match(address * addr1, address * addr2)
   1.278  {
   1.279 -  int res;
   1.280 +	int res;
   1.281  
   1.282 -  if((res = fnmatch(addr1->local_part, addr2->local_part, 0)) == 0){
   1.283 -    if((res = fnmatch(addr1->domain, addr2->domain, FNM_CASEFOLD)) == 0)
   1.284 -      return 0;
   1.285 -  }
   1.286 -  return res;
   1.287 +	if ((res = fnmatch(addr1->local_part, addr2->local_part, 0)) == 0) {
   1.288 +		if ((res = fnmatch(addr1->domain, addr2->domain, FNM_CASEFOLD)) == 0)
   1.289 +			return 0;
   1.290 +	}
   1.291 +	return res;
   1.292  }
   1.293 -