comparison src/context.h @ 310:802e2b779ed1

enable smtp verify logging
author Carl Byington <carl@five-ten-sg.com>
date Sun, 18 Sep 2016 18:32:37 -0700
parents 368572c57013
children f5547e7b3a09
comparison
equal deleted inserted replaced
309:358b764a862e 310:802e2b779ed1
54 bool error; 54 bool error;
55 time_t stamp; 55 time_t stamp;
56 char efrom[maxlen]; // last envelope from sent on this socket 56 char efrom[maxlen]; // last envelope from sent on this socket
57 int pending; // unread bytes in buffer, not including the null terminator 57 int pending; // unread bytes in buffer, not including the null terminator
58 char buffer[maxlen]; 58 char buffer[maxlen];
59 const char *queueid; // last queueid for logging
59 public: 60 public:
60 SMTP(int f) {fd = f; error = false; now(); efrom[0] = '\0'; init();}; 61 SMTP(int f) {fd = f; error = false; now(); efrom[0] = '\0'; init();};
61 ~SMTP() {if (!error) quit(); closefd();}; 62 ~SMTP() {if (!error) quit(); closefd();};
62 void init() {pending = 0; buffer[0] = '\0';}; 63 void init() {pending = 0; buffer[0] = '\0'; queueid = NULL;};
63 void append(const char *c) {strncat(buffer, c, max(0, maxlen-1-(int)strlen(c)));}; 64 void append(const char *c) {strncat(buffer, c, max(0, maxlen-1-(int)strlen(c)));};
64 bool err() {return error;}; 65 bool err() {return error;};
65 void now() {stamp = time(NULL);}; 66 void now() {stamp = time(NULL);};
66 time_t get_stamp() {return stamp;}; 67 time_t get_stamp() {return stamp;};
67 int get_fd() {return fd;}; 68 int get_fd() {return fd;};
69 void set_id(const char *id) {queueid = id;};
68 int writer(); 70 int writer();
69 int reader(); 71 int reader();
70 int read_line(); 72 int read_line();
71 int read_response(); 73 int read_response();
72 void flush_line(int r); 74 void flush_line(int r);
76 int from(const char *f); 78 int from(const char *f);
77 int rcpt(const char *t); 79 int rcpt(const char *t);
78 int quit(); 80 int quit();
79 void closefd(); 81 void closefd();
80 #ifdef VERIFY_DEBUG 82 #ifdef VERIFY_DEBUG
81 static void log(const char *m, int v); 83 void log(const char *m, int v);
82 static void log(const char *m, const char *v); 84 void log(const char *m, const char *v);
83 #endif 85 #endif
84 }; 86 };
85 87
86 class VERIFY { 88 class VERIFY {
87 const char *host; // host to be used to verify recipient addresses 89 const char *host; // host to be used to verify recipient addresses
91 public: 93 public:
92 VERIFY(const char *h); 94 VERIFY(const char *h);
93 void closer(); // if the oldest socket is ancient, close it 95 void closer(); // if the oldest socket is ancient, close it
94 SMTP *get_connection(); 96 SMTP *get_connection();
95 void put_connection(SMTP *conn); 97 void put_connection(SMTP *conn);
96 bool ok(const char *from, const char *to); 98 bool ok(const char *queueid, const char *from, const char *to);
97 }; 99 };
98 100
99 class WHITELISTER { 101 class WHITELISTER {
100 const char *fn; // file to use 102 const char *fn; // file to use
101 int days; // how long do we keep entries 103 int days; // how long do we keep entries