Mercurial > dnsbl
changeset 154:89ce226e5383
add auto whitelisting
author | carl |
---|---|
date | Sat, 07 Jul 2007 21:24:38 -0700 |
parents | 8d7c439bb6fa |
children | a76a6af7ed8b |
files | src/context.cpp src/dnsbl.cpp |
diffstat | 2 files changed, 25 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/context.cpp Sat Jul 07 16:10:39 2007 -0700 +++ b/src/context.cpp Sat Jul 07 21:24:38 2007 -0700 @@ -425,6 +425,22 @@ days = d; pthread_mutex_init(&mutex, 0); need = false; + ifstream ifs; + ifs.open(fn); + if (!ifs.fail()) { + const int maxlen = 1000; + char buf[maxlen]; + while (ifs.getline(buf, maxlen)) { + char *p = strchr(buf, ' '); + if (p) { + *p = '\0'; + char *who = strdup(buf); + int when = atoi(p+1); + rcpts[who] = when; + } + } + } + ifs.close(); } @@ -434,6 +450,8 @@ for (autowhite_sent::iterator i=rcpts.begin(); i!=rcpts.end();) { time_t when = (*i).second; if (when < limit) { + char *who = (*i).first; + free(who); autowhite_sent::iterator j = i; j++; rcpts.erase(i); @@ -444,22 +462,23 @@ } if (need) { // dump the file - ofstream os; - os.open(fn); - if (!os.fail()) { + ofstream ofs; + ofs.open(fn); + if (!ofs.fail()) { for (autowhite_sent::iterator i=rcpts.begin(); i!=rcpts.end(); i++) { char *who = (*i).first; int when = (*i).second; - os << who << " " << when << endl; + ofs << who << " " << when << endl; } } - os.close(); + ofs.close(); } pthread_mutex_unlock(&mutex); } void WHITELISTER::sent(char *to) { + // we take ownership of the string pthread_mutex_lock(&mutex); need = true; rcpts[to] = time(NULL);
--- a/src/dnsbl.cpp Sat Jul 07 16:10:39 2007 -0700 +++ b/src/dnsbl.cpp Sat Jul 07 21:24:38 2007 -0700 @@ -1026,8 +1026,7 @@ WHITELISTERP w = con2.find_autowhite(priv.mailaddr); if (w) { char *loto = to_lower_string(rcptaddr); - w->sent(loto); - free(loto); + w->sent(loto); // don't free it, the whitelister takes ownership of the string } // accept the recipient if (!con.get_content_filtering()) st = white;