diff src/context.h @ 90:962a1f8f1d9f stable-5-4

add verify statement to verify addresses with better mx host
author carl
date Sun, 18 Sep 2005 10:19:58 -0700
parents c1280cd3e248
children 505e77188317
line wrap: on
line diff
--- a/src/context.h	Sun Aug 07 11:26:37 2005 -0700
+++ b/src/context.h	Sun Sep 18 10:19:58 2005 -0700
@@ -12,18 +12,63 @@
 
 class DNSBL;
 class CONTEXT;
+class VERIFY;
 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<char *>                      string_list;
 typedef DNSBL *                           DNSBLP;
+typedef VERIFY *						  VERIFYP;
 typedef list<DNSBLP>                      dnsblp_list;
 typedef map<char *, DNSBLP, ltstr>        dnsblp_map;
 typedef CONTEXT *                         CONTEXTP;
 typedef list<CONTEXTP>                    context_list;
 typedef map<char *, CONTEXTP, ltstr>      context_map;
 typedef map<char *, int, ltstr>           ns_mapper;
+typedef map<char *, VERIFYP, ltstr> 	  verify_map;
+
+class SMTP {
+	static const int maxlen = 1000;
+	int  fd;
+	bool error;
+	int  pending;		// unread bytes in buffer, not including the null terminator
+	char buffer[maxlen];
+public:
+	SMTP(int f) 			{fd = f; error = false;};
+	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;};
+	int  writer();
+	int  reader();
+	int  read_line();
+	int  read_response();
+	int  flush_line(int r);
+	int  cmd(char *c);
+	int  helo();
+	int  rset();
+	int  from(char *f);
+	int  rcpt(char *t);
+	int  quit();
+	// static void log(char *m, int v);
+	// static void log(char *m, char *v);
+};
+
+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
+public:
+	VERIFY(char *h);
+	void closer();			// if the oldest socket is ancient, close it
+	int  get_socket();
+	void put_socket(int fd, bool err);
+	bool ok(char *from, char *to);
+};
 
 struct DNSBL {
     char    *name;      // nickname for this dns based list
@@ -37,7 +82,8 @@
     CONTEXTP        parent;
     char *          name;
     context_map     children;           // map child context names to their contexts
-    string_set      env_to;             //
+	string_set		env_to; 			// this context applies to these envelope recipients
+	char *			verify_host;		// use this smtp host to verify email addresses
     string_map      env_from;           // map senders to white/black/unknown
     context_map     env_from_context;   // map senders to a child context
     char *          env_from_default;   // default value for senders that are not found in the map white/black/unknown/inherit
@@ -65,6 +111,10 @@
     bool        allow_env_to(char *to)                      {return (parent) ? parent->cover_env_to(to) : true;};
     bool        cover_env_to(char *to);
 
+	void		set_verify(char *host)						{verify_host = host;};
+	char*		get_verify()								{return verify_host;};
+	VERIFYP 	find_verify(char *to);
+
     void        add_to(char *to)                            {env_to.insert(to);};
     void        add_from(char *from, char *status)          {env_from[from] = status;};
     void        add_from_context(char *from, CONTEXTP con)  {env_from_context[from] = con;};
@@ -159,6 +209,9 @@
 extern char *token_unknown;
 extern char *token_white;
 
+extern char *token_myhostname;
+
+extern verify_map	verifiers;		// map of smtp hosts to verify structures, owns all the verify structures
 extern string_set all_strings;      // owns all the strings, only modified by the config loader thread
 
 void discard(string_set &s);
@@ -166,6 +219,8 @@
 char* register_string(char *name);
 CONFIG *parse_config(char *fn);
 bool load_conf(CONFIG &dc, char *fn);
+void  add_verify_host(char *host);
+void* verify_closer(void *arg);
 void token_init();
 
 #endif