comparison 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
comparison
equal deleted inserted replaced
91:ca46fafc6621 92:505e77188317
11 reject}; // rejected by a dns list 11 reject}; // rejected by a dns list
12 12
13 class DNSBL; 13 class DNSBL;
14 class CONTEXT; 14 class CONTEXT;
15 class VERIFY; 15 class VERIFY;
16 class SMTP;
16 class recorder; 17 class recorder;
17 18
18 typedef map<char *, char *, ltstr> string_map; 19 typedef map<char *, char *, ltstr> string_map;
19 typedef set<int> int_set; 20 typedef set<int> int_set;
20 typedef list<int> fd_list; 21 typedef list<SMTP *> smtp_list;
21 typedef list<time_t> time_list;
22 typedef list<char *> string_list; 22 typedef list<char *> string_list;
23 typedef DNSBL * DNSBLP; 23 typedef DNSBL * DNSBLP;
24 typedef VERIFY * VERIFYP; 24 typedef VERIFY * VERIFYP;
25 typedef list<DNSBLP> dnsblp_list; 25 typedef list<DNSBLP> dnsblp_list;
26 typedef map<char *, DNSBLP, ltstr> dnsblp_map; 26 typedef map<char *, DNSBLP, ltstr> dnsblp_map;
30 typedef map<char *, int, ltstr> ns_mapper; 30 typedef map<char *, int, ltstr> ns_mapper;
31 typedef map<char *, VERIFYP, ltstr> verify_map; 31 typedef map<char *, VERIFYP, ltstr> verify_map;
32 32
33 class SMTP { 33 class SMTP {
34 static const int maxlen = 1000; 34 static const int maxlen = 1000;
35 int fd; 35 int fd;
36 bool error; 36 bool error;
37 int pending; // unread bytes in buffer, not including the null terminator 37 time_t stamp;
38 char buffer[maxlen]; 38 char efrom[maxlen]; // last envelope from sent on this socket
39 int pending; // unread bytes in buffer, not including the null terminator
40 char buffer[maxlen];
39 public: 41 public:
40 SMTP(int f) {fd = f; error = false;}; 42 SMTP(int f) {fd = f; error = false; efrom[0] = '\0';};
41 void init() {pending = 0; buffer[0] = '\0';}; 43 ~SMTP() {if (!error) quit(); closefd();};
42 void append(char *c) {strncat(buffer, c, max(0, maxlen-1-(int)strlen(c)));}; 44 void init() {pending = 0; buffer[0] = '\0';};
43 bool err() {return error;}; 45 void append(char *c) {strncat(buffer, c, max(0, maxlen-1-(int)strlen(c)));};
44 int writer(); 46 bool err() {return error;};
45 int reader(); 47 void now() {stamp = time(NULL);};
46 int read_line(); 48 time_t get_stamp() {return stamp;};
47 int read_response(); 49 int get_fd() {return fd;};
48 int flush_line(int r); 50 int writer();
49 int cmd(char *c); 51 int reader();
50 int helo(); 52 int read_line();
51 int rset(); 53 int read_response();
52 int from(char *f); 54 int flush_line(int r);
53 int rcpt(char *t); 55 int cmd(char *c);
54 int quit(); 56 int helo();
55 // static void log(char *m, int v); 57 int rset();
56 // static void log(char *m, char *v); 58 int from(char *f);
59 int rcpt(char *t);
60 int quit();
61 void closefd();
62 #ifdef VERIFY_DEBUG
63 static void log(char *m, int v);
64 static void log(char *m, char *v);
65 #endif
57 }; 66 };
58 67
59 class VERIFY { 68 class VERIFY {
60 char *host; // host to be used to verify recipient addresses 69 char *host; // host to be used to verify recipient addresses
61 time_t last_err; // time of last socket error 70 time_t last_err; // time of last socket error
62 pthread_mutex_t mutex; // protect the lists of sockets and timestamps 71 pthread_mutex_t mutex; // protect the lists of sockets and timestamps
63 fd_list sockets; // open sockets, ready to be used 72 smtp_list connections;// open sockets, ready to be used
64 time_list times; // last timestamp when this socket was used
65 public: 73 public:
66 VERIFY(char *h); 74 VERIFY(char *h);
67 void closer(); // if the oldest socket is ancient, close it 75 void closer(); // if the oldest socket is ancient, close it
68 int get_socket(); 76 SMTP *get_connection();
69 void put_socket(int fd, bool err); 77 void put_connection(SMTP *conn);
70 bool ok(char *from, char *to); 78 bool ok(char *from, char *to);
71 }; 79 };
72 80
73 struct DNSBL { 81 struct DNSBL {
74 char *name; // nickname for this dns based list 82 char *name; // nickname for this dns based list
75 char *suffix; // blacklist suffix like blackholes.five-ten-sg.com 83 char *suffix; // blacklist suffix like blackholes.five-ten-sg.com