Mercurial > dnsbl
diff src/context.h @ 92:505e77188317
optimize verification step, cleanup documentation
author | carl |
---|---|
date | Wed, 21 Sep 2005 08:00:08 -0700 |
parents | 962a1f8f1d9f |
children | e107ade3b1c0 |
line wrap: on
line diff
--- a/src/context.h Sun Sep 18 10:46:31 2005 -0700 +++ b/src/context.h Wed Sep 21 08:00:08 2005 -0700 @@ -13,12 +13,12 @@ class DNSBL; class CONTEXT; class VERIFY; +class SMTP; class recorder; typedef map<char *, char *, ltstr> string_map; typedef set<int> int_set; -typedef list<int> fd_list; -typedef list<time_t> time_list; +typedef list<SMTP *> smtp_list; typedef list<char *> string_list; typedef DNSBL * DNSBLP; typedef VERIFY * VERIFYP; @@ -34,13 +34,19 @@ static const int maxlen = 1000; int fd; bool error; + time_t stamp; + char efrom[maxlen]; // last envelope from sent on this socket int pending; // unread bytes in buffer, not including the null terminator char buffer[maxlen]; public: - SMTP(int f) {fd = f; error = false;}; + SMTP(int f) {fd = f; error = false; efrom[0] = '\0';}; + ~SMTP() {if (!error) quit(); closefd();}; void init() {pending = 0; buffer[0] = '\0';}; void append(char *c) {strncat(buffer, c, max(0, maxlen-1-(int)strlen(c)));}; bool err() {return error;}; + void now() {stamp = time(NULL);}; + time_t get_stamp() {return stamp;}; + int get_fd() {return fd;}; int writer(); int reader(); int read_line(); @@ -52,21 +58,23 @@ int from(char *f); int rcpt(char *t); int quit(); - // static void log(char *m, int v); - // static void log(char *m, char *v); + void closefd(); +#ifdef VERIFY_DEBUG + static void log(char *m, int v); + static void log(char *m, char *v); +#endif }; class VERIFY { char *host; // host to be used to verify recipient addresses time_t last_err; // time of last socket error pthread_mutex_t mutex; // protect the lists of sockets and timestamps - fd_list sockets; // open sockets, ready to be used - time_list times; // last timestamp when this socket was used + smtp_list connections;// open sockets, ready to be used public: VERIFY(char *h); void closer(); // if the oldest socket is ancient, close it - int get_socket(); - void put_socket(int fd, bool err); + SMTP *get_connection(); + void put_connection(SMTP *conn); bool ok(char *from, char *to); };