diff src/context.h @ 153:8d7c439bb6fa

add auto whitelisting
author carl
date Sat, 07 Jul 2007 16:10:39 -0700
parents c7fc218686f5
children a220bfb9211f
line wrap: on
line diff
--- a/src/context.h	Sat Jul 07 10:26:31 2007 -0700
+++ b/src/context.h	Sat Jul 07 16:10:39 2007 -0700
@@ -22,6 +22,7 @@
 class CONTEXT;
 class VERIFY;
 class SMTP;
+class WHITELISTER;
 class recorder;
 
 typedef map<char *, char *, ltstr>		  string_map;
@@ -30,6 +31,7 @@
 typedef list<char *>					  string_list;
 typedef DNSBL * 						  DNSBLP;
 typedef VERIFY *						  VERIFYP;
+typedef WHITELISTER *					  WHITELISTERP;
 typedef list<DNSBLP>					  dnsblp_list;
 typedef map<char *, DNSBLP, ltstr>		  dnsblp_map;
 typedef CONTEXT *						  CONTEXTP;
@@ -37,7 +39,9 @@
 typedef map<char *, CONTEXTP, ltstr>	  context_map;
 typedef map<char *, int, ltstr> 		  ns_mapper;
 typedef map<char *, int, ltstr> 		  rcpt_rates;
+typedef map<char *, int, ltstr> 		  autowhite_sent;
 typedef map<char *, VERIFYP, ltstr> 	  verify_map;
+typedef map<char *, WHITELISTERP, ltstr>  whitelister_map;
 
 class SMTP {
 	static const int maxlen = 1000;
@@ -87,6 +91,20 @@
 	bool	ok(char *from, char *to);
 };
 
+class WHITELISTER {
+	char			*fn;		// file to use
+	int 			days;		// how long do we keep entries
+	pthread_mutex_t mutex;		// protect the flag and map
+	bool			need;		// force writing on new entries
+	autowhite_sent	rcpts;		// recipient map to remember when we sent them mail
+public:
+	WHITELISTER(char *f, int d);
+	void	writer();			// dump any changes back to the file
+	void	sent(char *to);
+	bool	is_white(char *from);	// should we white list this sender (did we send them anything recently)
+	int 	get_days() {return days;};
+};
+
 struct DNSBL {
 	char	*name;		// nickname for this dns based list
 	char	*suffix;	// blacklist suffix like blackholes.five-ten-sg.com
@@ -101,6 +119,9 @@
 	context_map 	children;			// map child context names to their contexts
 	string_set		env_to; 			// this context applies to these envelope recipients
 	char *			verify_host;		// use this smtp host to verify email addresses
+	VERIFYP 		verifier;			// pointer to the verifier structure
+	char *			autowhite_file; 	// file to use for automatic whitelisting
+	WHITELISTERP	whitelister;		// pointer to the auto whitelister structure
 	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
@@ -134,10 +155,16 @@
 	bool		allow_env_to(char *to)						{return (parent) ? parent->cover_env_to(to) : true;};
 	bool		cover_env_to(char *to);
 
+	void		set_verifier(VERIFYP v) 					{verifier	 = v;};
 	void		set_verify(char *host)						{verify_host = host;};
 	char*		get_verify()								{return verify_host;};
 	VERIFYP 	find_verify(char *to);
 
+	void		set_whitelister(WHITELISTERP v) 			{whitelister	= v;};
+	void		set_autowhite(char *fn) 					{autowhite_file = fn;};
+	char*		get_autowhite() 							{return autowhite_file;};
+	WHITELISTERP find_autowhite(char *to);
+
 	void		set_default_rate(int limit) 				{default_rcpt_rate	 = limit;};
 	void		add_rate(char *user, int limit) 			{rcpt_per_hour[user] = limit;};
 	int 		find_rate(char *user);
@@ -214,6 +241,7 @@
 
 };
 
+extern char *token_autowhite;
 extern char *token_black;
 extern char *token_cctld;
 extern char *token_content;
@@ -249,18 +277,16 @@
 extern char *token_uribl;
 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
+extern pthread_mutex_t verifier_mutex;	   // protect the verifier map
+extern pthread_mutex_t whitelister_mutex;  // protect the
 
 void discard(string_set &s);
 char* register_string(string_set &s, char *name);
 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* whitelister_writer(void *arg);
 void  token_init();
 
 #endif