comparison src/context.h @ 311:f5547e7b3a09

enable smtp verify logging
author Carl Byington <carl@five-ten-sg.com>
date Mon, 19 Sep 2016 09:11:30 -0700
parents 802e2b779ed1
children e27c24c1974a
comparison
equal deleted inserted replaced
310:802e2b779ed1 311:f5547e7b3a09
48 typedef map<const char *, WHITELISTERP, ltstr> whitelister_map; 48 typedef map<const char *, WHITELISTERP, ltstr> whitelister_map;
49 typedef list<DELAYWHITEP> delay_whitelist; 49 typedef list<DELAYWHITEP> delay_whitelist;
50 50
51 class SMTP { 51 class SMTP {
52 static const int maxlen = 1000; 52 static const int maxlen = 1000;
53 static const int qlen = 20;
53 int fd; 54 int fd;
54 bool error; 55 bool error;
55 time_t stamp; 56 time_t stamp;
56 char efrom[maxlen]; // last envelope from sent on this socket 57 char efrom[maxlen]; // last envelope from sent on this socket
57 int pending; // unread bytes in buffer, not including the null terminator 58 int pending; // unread bytes in buffer, not including the null terminator
58 char buffer[maxlen]; 59 char buffer[maxlen];
59 const char *queueid; // last queueid for logging 60 char queueid[qlen]; // last queueid for logging
60 public: 61 public:
61 SMTP(int f) {fd = f; error = false; now(); efrom[0] = '\0'; init();}; 62 SMTP(int f) {fd = f; error = false; now(); efrom[0] = '\0'; queueid[0] = '\0'; init();};
62 ~SMTP() {if (!error) quit(); closefd();}; 63 ~SMTP() {if (!error) quit(); closefd();};
63 void init() {pending = 0; buffer[0] = '\0'; queueid = NULL;}; 64 void init() {pending = 0; buffer[0] = '\0';};
64 void append(const char *c) {strncat(buffer, c, max(0, maxlen-1-(int)strlen(c)));}; 65 void append(const char *c) {strncat(buffer, c, max(0, maxlen-1-(int)strlen(c)));};
65 bool err() {return error;}; 66 bool err() {return error;};
66 void now() {stamp = time(NULL);}; 67 void now() {stamp = time(NULL);};
67 time_t get_stamp() {return stamp;}; 68 time_t get_stamp() {return stamp;};
68 int get_fd() {return fd;}; 69 int get_fd() {return fd;};
69 void set_id(const char *id) {queueid = id;}; 70 void set_id(const char *id) {strncpy(queueid, id, qlen); queueid[qlen-1] = '\0';};
70 int writer(); 71 int writer();
71 int reader(); 72 int reader();
72 int read_line(); 73 int read_line();
73 int read_response(); 74 int read_response();
74 void flush_line(int r); 75 void flush_line(int r);
77 int rset(); 78 int rset();
78 int from(const char *f); 79 int from(const char *f);
79 int rcpt(const char *t); 80 int rcpt(const char *t);
80 int quit(); 81 int quit();
81 void closefd(); 82 void closefd();
82 #ifdef VERIFY_DEBUG 83 void log(const char *m, int v);
83 void log(const char *m, int v); 84 void log(const char *m, const char *v);
84 void log(const char *m, const char *v);
85 #endif
86 }; 85 };
87 86
88 class VERIFY { 87 class VERIFY {
89 const char *host; // host to be used to verify recipient addresses 88 const char *host; // host to be used to verify recipient addresses
90 time_t last_err; // time of last socket error 89 time_t last_err; // time of last socket error
91 pthread_mutex_t mutex; // protect the lists of sockets and timestamps 90 pthread_mutex_t mutex; // protect the lists of sockets and timestamps
92 smtp_list connections;// open sockets, ready to be used 91 smtp_list connections;// open sockets, ready to be used
93 public: 92 public:
94 VERIFY(const char *h); 93 VERIFY(const char *h);
95 void closer(); // if the oldest socket is ancient, close it 94 void closer(); // if the oldest socket is ancient, close it
96 SMTP *get_connection(); 95 SMTP *get_connection(const char *queueid);
97 void put_connection(SMTP *conn); 96 void put_connection(SMTP *conn);
98 bool ok(const char *queueid, const char *from, const char *to); 97 bool ok(const char *queueid, const char *from, const char *to);
99 }; 98 };
100 99
101 class WHITELISTER { 100 class WHITELISTER {