Mercurial > masqmail
comparison src/address.c @ 366:41958685480d
Switched to `type *name' style
Andrew Koenig's ``C Traps and Pitfalls'' (Ch.2.1) convinced
me that it is best to go with the way C had been designed.
The ``declaration reflects use'' concept conflicts with a
``type* name'' notation. Hence I switched.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 22 Sep 2011 15:07:40 +0200 |
parents | 55b7bde95d37 |
children | b27f66555ba8 |
comparison
equal
deleted
inserted
replaced
365:934a223e4ee8 | 366:41958685480d |
---|---|
17 */ | 17 */ |
18 | 18 |
19 #include "masqmail.h" | 19 #include "masqmail.h" |
20 | 20 |
21 address* | 21 address* |
22 create_address(gchar * path, gboolean is_rfc821) | 22 create_address(gchar *path, gboolean is_rfc821) |
23 { | 23 { |
24 address *addr; | 24 address *addr; |
25 addr = _create_address(path, NULL, is_rfc821); | 25 addr = _create_address(path, NULL, is_rfc821); |
26 | 26 |
27 if (addr != NULL) { | 27 if (addr != NULL) { |
29 } | 29 } |
30 return addr; | 30 return addr; |
31 } | 31 } |
32 | 32 |
33 address* | 33 address* |
34 create_address_qualified(gchar * path, gboolean is_rfc821, gchar * domain) | 34 create_address_qualified(gchar *path, gboolean is_rfc821, gchar *domain) |
35 { | 35 { |
36 address *addr = create_address(path, is_rfc821); | 36 address *addr = create_address(path, is_rfc821); |
37 | 37 |
38 if (addr != NULL && addr->domain == NULL) { | 38 if (addr != NULL && addr->domain == NULL) { |
39 addr->domain = g_strdup(domain); | 39 addr->domain = g_strdup(domain); |
41 return addr; | 41 return addr; |
42 } | 42 } |
43 | 43 |
44 /* nothing special about pipes here, but its only called for that purpose */ | 44 /* nothing special about pipes here, but its only called for that purpose */ |
45 address* | 45 address* |
46 create_address_pipe(gchar * path) | 46 create_address_pipe(gchar *path) |
47 { | 47 { |
48 address *addr = g_malloc(sizeof(address)); | 48 address *addr = g_malloc(sizeof(address)); |
49 | 49 |
50 if (addr) { | 50 if (addr) { |
51 memset(addr, 0, sizeof(address)); | 51 memset(addr, 0, sizeof(address)); |
56 } | 56 } |
57 return addr; | 57 return addr; |
58 } | 58 } |
59 | 59 |
60 void | 60 void |
61 destroy_address(address * addr) | 61 destroy_address(address *addr) |
62 { | 62 { |
63 DEBUG(6) debugf("destroy_address entered\n"); | 63 DEBUG(6) debugf("destroy_address entered\n"); |
64 | 64 |
65 g_free(addr->address); | 65 g_free(addr->address); |
66 g_free(addr->local_part); | 66 g_free(addr->local_part); |
68 | 68 |
69 g_free(addr); | 69 g_free(addr); |
70 } | 70 } |
71 | 71 |
72 address* | 72 address* |
73 copy_modify_address(const address * orig, gchar * l_part, gchar * dom) | 73 copy_modify_address(const address *orig, gchar *l_part, gchar *dom) |
74 { | 74 { |
75 address *addr = NULL; | 75 address *addr = NULL; |
76 | 76 |
77 if (!orig) { | 77 if (!orig) { |
78 return NULL; | 78 return NULL; |
99 addr->parent = NULL; | 99 addr->parent = NULL; |
100 return addr; | 100 return addr; |
101 } | 101 } |
102 | 102 |
103 gboolean | 103 gboolean |
104 addr_isequal(address * addr1, address * addr2, int (*cmpfunc) (const char*, const char*)) | 104 addr_isequal(address *addr1, address *addr2, int (*cmpfunc) (const char*, const char*)) |
105 { | 105 { |
106 return (cmpfunc(addr1->local_part, addr2->local_part) == 0) | 106 return (cmpfunc(addr1->local_part, addr2->local_part) == 0) |
107 && (strcasecmp(addr1->domain, addr2->domain) == 0); | 107 && (strcasecmp(addr1->domain, addr2->domain) == 0); |
108 } | 108 } |
109 | 109 |
110 /* searches in ancestors of addr1 */ | 110 /* searches in ancestors of addr1 */ |
111 gboolean | 111 gboolean |
112 addr_isequal_parent(address* addr1, address* addr2, int (*cmpfunc) (const char*, const char*)) | 112 addr_isequal_parent(address *addr1, address *addr2, int (*cmpfunc) (const char*, const char*)) |
113 { | 113 { |
114 address *addr; | 114 address *addr; |
115 | 115 |
116 for (addr = addr1; addr; addr = addr->parent) | 116 for (addr = addr1; addr; addr = addr->parent) |
117 if (addr_isequal(addr, addr2, cmpfunc)) | 117 if (addr_isequal(addr, addr2, cmpfunc)) |
121 } | 121 } |
122 | 122 |
123 /* careful, this is recursive */ | 123 /* careful, this is recursive */ |
124 /* returns TRUE if ALL children have been delivered */ | 124 /* returns TRUE if ALL children have been delivered */ |
125 gboolean | 125 gboolean |
126 addr_is_delivered_children(address * addr) | 126 addr_is_delivered_children(address *addr) |
127 { | 127 { |
128 GList *addr_node; | 128 GList *addr_node; |
129 | 129 |
130 if (addr->children == NULL) | 130 if (addr->children == NULL) |
131 return addr_is_delivered(addr); | 131 return addr_is_delivered(addr); |
139 } | 139 } |
140 | 140 |
141 /* careful, this is recursive */ | 141 /* careful, this is recursive */ |
142 /* returns TRUE if ALL children have been either delivered or have failed */ | 142 /* returns TRUE if ALL children have been either delivered or have failed */ |
143 gboolean | 143 gboolean |
144 addr_is_finished_children(address * addr) | 144 addr_is_finished_children(address *addr) |
145 { | 145 { |
146 GList *addr_node; | 146 GList *addr_node; |
147 | 147 |
148 if (addr->children == NULL) | 148 if (addr->children == NULL) |
149 return (addr_is_failed(addr) || addr_is_delivered(addr)); | 149 return (addr_is_failed(addr) || addr_is_delivered(addr)); |
156 return TRUE; | 156 return TRUE; |
157 } | 157 } |
158 | 158 |
159 /* find original address */ | 159 /* find original address */ |
160 address* | 160 address* |
161 addr_find_ancestor(address * addr) | 161 addr_find_ancestor(address *addr) |
162 { | 162 { |
163 while (addr->parent) | 163 while (addr->parent) |
164 addr = addr->parent; | 164 addr = addr->parent; |
165 return addr; | 165 return addr; |
166 } | 166 } |
167 | 167 |
168 gchar* | 168 gchar* |
169 addr_string(address * addr) | 169 addr_string(address *addr) |
170 { | 170 { |
171 static gchar *buffer = NULL; | 171 static gchar *buffer = NULL; |
172 | 172 |
173 if (addr == NULL) { | 173 if (addr == NULL) { |
174 g_free(buffer); | 174 g_free(buffer); |