comparison src/sm-archive.cpp @ 19:b24369330483 stable-1-0-7

Fedora 9 compile and const correctness.
author Carl Byington <carl@five-ten-sg.com>
date Thu, 12 Jun 2008 18:17:33 -0700
parents 8ebecad6530f
children 09564d4acd9e
comparison
equal deleted inserted replaced
18:e1a028daceb9 19:b24369330483
85 } 85 }
86 86
87 void mlfiPriv::reset(bool final) { 87 void mlfiPriv::reset(bool final) {
88 targets.clear(); 88 targets.clear();
89 for (string_set::iterator i=removal.begin(); i!=removal.end(); i++) { 89 for (string_set::iterator i=removal.begin(); i!=removal.end(); i++) {
90 char *remove = (*i); 90 const char *remove = (*i);
91 free(remove); 91 free((void*)remove);
92 } 92 }
93 removal.clear(); 93 removal.clear();
94 if (mailaddr) free(mailaddr); 94 if (mailaddr) free((void*)mailaddr);
95 if (queueid) free(queueid); 95 if (queueid) free((void*)queueid);
96 if (!final) { 96 if (!final) {
97 mailaddr = NULL; 97 mailaddr = NULL;
98 queueid = NULL; 98 queueid = NULL;
99 } 99 }
100 } 100 }
103 103
104 104
105 //////////////////////////////////////////////// 105 ////////////////////////////////////////////////
106 // syslog a message 106 // syslog a message
107 // 107 //
108 void my_syslog(mlfiPriv *priv, char *text) { 108 void my_syslog(mlfiPriv *priv, const char *text) {
109 char buf[maxlen]; 109 char buf[maxlen];
110 if (priv) { 110 if (priv) {
111 snprintf(buf, sizeof(buf), "%s: %s", priv->queueid, text); 111 snprintf(buf, sizeof(buf), "%s: %s", priv->queueid, text);
112 text = buf; 112 text = buf;
113 } 113 }
123 else { 123 else {
124 printf("%s \n", text); 124 printf("%s \n", text);
125 } 125 }
126 } 126 }
127 127
128 void my_syslog(char *text) { 128 void my_syslog(const char *text) {
129 my_syslog(NULL, text); 129 my_syslog(NULL, text);
130 } 130 }
131 131
132 132
133 //////////////////////////////////////////////// 133 ////////////////////////////////////////////////
134 // this email address is passed in from sendmail, and will 134 // this email address is passed in from sendmail, and will
135 // always be enclosed in <>. It may have mixed case, just 135 // always be enclosed in <>. It may have mixed case, just
136 // as the mail client sent it. We dup the string and convert 136 // as the mail client sent it. We dup the string and convert
137 // the duplicate to lower case. 137 // the duplicate to lower case.
138 // 138 //
139 char *to_lower_string(char *email); 139 const char *to_lower_string(const char *email);
140 char *to_lower_string(char *email) { 140 const char *to_lower_string(const char *email) {
141 int n = strlen(email)-2; 141 int n = strlen(email)-2;
142 if (n < 1) return strdup(email); 142 if (n < 1) return strdup(email);
143 char *key = strdup(email+1); 143 char *key = strdup(email+1);
144 key[n] = '\0'; 144 key[n] = '\0';
145 for (int i=0; i<n; i++) key[i] = tolower(key[i]); 145 for (int i=0; i<n; i++) key[i] = tolower(key[i]);
165 mlfiPriv &priv = *MLFIPRIV; 165 mlfiPriv &priv = *MLFIPRIV;
166 priv.mailaddr = to_lower_string(from[0]); 166 priv.mailaddr = to_lower_string(from[0]);
167 return SMFIS_CONTINUE; 167 return SMFIS_CONTINUE;
168 } 168 }
169 169
170 void add_target(mlfiPriv &priv, char *target); 170 void add_target(mlfiPriv &priv, const char *target);
171 void add_target(mlfiPriv &priv, char *target) 171 void add_target(mlfiPriv &priv, const char *target)
172 { 172 {
173 if (target) { 173 if (target) {
174 string_set::iterator i = priv.targets.find(target); 174 string_set::iterator i = priv.targets.find(target);
175 if (i == priv.targets.end()) priv.targets.insert(target); 175 if (i == priv.targets.end()) priv.targets.insert(target);
176 } 176 }
177 } 177 }
178 178
179 void add_remove(mlfiPriv &priv, char *remove); 179 void add_remove(mlfiPriv &priv, const char *remove);
180 void add_remove(mlfiPriv &priv, char *remove) 180 void add_remove(mlfiPriv &priv, const char *remove)
181 { 181 {
182 if (remove) { 182 if (remove) {
183 string_set::iterator i = priv.removal.find(remove); 183 string_set::iterator i = priv.removal.find(remove);
184 if (i == priv.removal.end()) priv.removal.insert(remove); 184 if (i == priv.removal.end()) priv.removal.insert(remove);
185 } 185 }
187 187
188 sfsistat mlfi_envrcpt(SMFICTX *ctx, char **rcpt) 188 sfsistat mlfi_envrcpt(SMFICTX *ctx, char **rcpt)
189 { 189 {
190 mlfiPriv &priv = *MLFIPRIV; 190 mlfiPriv &priv = *MLFIPRIV;
191 CONFIG &dc = *priv.pc; 191 CONFIG &dc = *priv.pc;
192 if (!priv.queueid) priv.queueid = strdup(smfi_getsymval(ctx, "i")); 192 if (!priv.queueid) priv.queueid = strdup(smfi_getsymval(ctx, (char*)"i"));
193 char *rcptaddr = to_lower_string(rcpt[0]); 193 const char *rcptaddr = to_lower_string(rcpt[0]);
194 if (debug_syslog > 1) { 194 if (debug_syslog > 1) {
195 char msg[maxlen]; 195 char msg[maxlen];
196 snprintf(msg, sizeof(msg), "from <%s> to <%s>", priv.mailaddr, rcptaddr); 196 snprintf(msg, sizeof(msg), "from <%s> to <%s>", priv.mailaddr, rcptaddr);
197 my_syslog(&priv, msg); 197 my_syslog(&priv, msg);
198 } 198 }
199 char *target = dc.find_to(rcptaddr); 199 const char *target = dc.find_to(rcptaddr);
200 add_target(priv, target); 200 add_target(priv, target);
201 bool remove = dc.find_remove(rcptaddr); 201 bool remove = dc.find_remove(rcptaddr);
202 if (remove) add_remove(priv, strdup(rcptaddr)); 202 if (remove) add_remove(priv, strdup(rcptaddr));
203 free(rcptaddr); 203 free((void*)rcptaddr);
204 return SMFIS_CONTINUE; 204 return SMFIS_CONTINUE;
205 } 205 }
206 206
207 sfsistat mlfi_eom(SMFICTX *ctx) 207 sfsistat mlfi_eom(SMFICTX *ctx)
208 { 208 {
209 mlfiPriv &priv = *MLFIPRIV; 209 mlfiPriv &priv = *MLFIPRIV;
210 CONFIG &dc = *priv.pc; 210 CONFIG &dc = *priv.pc;
211 char *target = dc.find_from(priv.mailaddr); 211 const char *target = dc.find_from(priv.mailaddr);
212 add_target(priv, target); 212 add_target(priv, target);
213 for (string_set::iterator i=priv.targets.begin(); i!=priv.targets.end(); i++) { 213 for (string_set::iterator i=priv.targets.begin(); i!=priv.targets.end(); i++) {
214 target = (*i); 214 target = (*i);
215 smfi_addrcpt(ctx, target); 215 smfi_addrcpt(ctx, (char*)target);
216 if (debug_syslog > 1) { 216 if (debug_syslog > 1) {
217 char msg[maxlen]; 217 char msg[maxlen];
218 snprintf(msg, sizeof(msg), "adding recipient <%s>", target); 218 snprintf(msg, sizeof(msg), "adding recipient <%s>", target);
219 my_syslog(&priv, msg); 219 my_syslog(&priv, msg);
220 } 220 }
221 } 221 }
222 for (string_set::iterator i=priv.removal.begin(); i!=priv.removal.end(); i++) { 222 for (string_set::iterator i=priv.removal.begin(); i!=priv.removal.end(); i++) {
223 char *remove = (*i); 223 const char *remove = (*i);
224 smfi_delrcpt(ctx, remove); 224 smfi_delrcpt(ctx, (char*)remove);
225 if (debug_syslog > 1) { 225 if (debug_syslog > 1) {
226 char msg[maxlen]; 226 char msg[maxlen];
227 snprintf(msg, sizeof(msg), "removing recipient <%s>", remove); 227 snprintf(msg, sizeof(msg), "removing recipient <%s>", remove);
228 my_syslog(&priv, msg); 228 my_syslog(&priv, msg);
229 } 229 }
249 return SMFIS_CONTINUE; 249 return SMFIS_CONTINUE;
250 } 250 }
251 251
252 struct smfiDesc smfilter = 252 struct smfiDesc smfilter =
253 { 253 {
254 "SM-ARCHIVE", // filter name 254 (char*)"SM-ARCHIVE",// filter name
255 SMFI_VERSION, // version code -- do not change 255 SMFI_VERSION, // version code -- do not change
256 SMFIF_ADDRCPT | \ 256 SMFIF_ADDRCPT | \
257 SMFIF_DELRCPT, // flags 257 SMFIF_DELRCPT, // flags
258 mlfi_connect, // connection info filter 258 mlfi_connect, // connection info filter
259 NULL, // SMTP HELO command filter 259 NULL, // SMTP HELO command filter
304 CONFIG &dc = *config; 304 CONFIG &dc = *config;
305 time_t then = dc.load_time; 305 time_t then = dc.load_time;
306 struct stat st; 306 struct stat st;
307 bool reload = false; 307 bool reload = false;
308 for (string_set::iterator i=dc.config_files.begin(); i!=dc.config_files.end(); i++) { 308 for (string_set::iterator i=dc.config_files.begin(); i!=dc.config_files.end(); i++) {
309 char *fn = *i; 309 const char *fn = *i;
310 if (stat(fn, &st)) reload = true; // file disappeared 310 if (stat(fn, &st)) reload = true; // file disappeared
311 else if (st.st_mtime > then) reload = true; // file modified 311 else if (st.st_mtime > then) reload = true; // file modified
312 if (reload) break; 312 if (reload) break;
313 } 313 }
314 if (reload) { 314 if (reload) {
333 } 333 }
334 return NULL; 334 return NULL;
335 } 335 }
336 336
337 337
338 void usage(char *prog); 338 void usage(const char *prog);
339 void usage(char *prog) 339 void usage(const char *prog)
340 { 340 {
341 fprintf(stderr, "Usage: %s [-d [level]] [-c] -p sm-sock-addr [-t timeout]\n", prog); 341 fprintf(stderr, "Usage: %s [-d [level]] [-c] -p sm-sock-addr [-t timeout]\n", prog);
342 fprintf(stderr, "where sm-sock-addr is for the connection to sendmail\n"); 342 fprintf(stderr, "where sm-sock-addr is for the connection to sendmail\n");
343 fprintf(stderr, " and should be one of\n"); 343 fprintf(stderr, " and should be one of\n");
344 fprintf(stderr, " inet:port@ip-address\n"); 344 fprintf(stderr, " inet:port@ip-address\n");
347 fprintf(stderr, "-d will set the syslog message level, currently 0 to 3\n"); 347 fprintf(stderr, "-d will set the syslog message level, currently 0 to 3\n");
348 } 348 }
349 349
350 350
351 351
352 void setup_socket(char *sock); 352 void setup_socket(const char *sock);
353 void setup_socket(char *sock) { 353 void setup_socket(const char *sock) {
354 unlink(sock); 354 unlink(sock);
355 // sockaddr_un addr; 355 // sockaddr_un addr;
356 // memset(&addr, '\0', sizeof addr); 356 // memset(&addr, '\0', sizeof addr);
357 // addr.sun_family = AF_UNIX; 357 // addr.sun_family = AF_UNIX;
358 // strncpy(addr.sun_path, sock, sizeof(addr.sun_path)-1); 358 // strncpy(addr.sun_path, sock, sizeof(addr.sun_path)-1);