view src/context.h @ 2:32b57406b656

initial version
author carl
date Fri, 10 Mar 2006 10:47:12 -0800
parents 616666e2f34c
children 01268466f0dc
line wrap: on
line source

#ifndef context_include
#define context_include

#include "tokenizer.h"
#include <map>


typedef map<char *, char *, ltstr>		  string_map;

struct CONFIG {
	// the only mutable stuff once it has been loaded from the config file
	int 		reference_count;	// protected by the global config_mutex
	// all the rest is constant after loading from the config file
	int 			generation;
	time_t			load_time;
	string_set		config_files;
	string_map		env_from;			// map senders to archive mailboxes
	string_map		rcpt_to;			// map recipients to archive mailboxes

	CONFIG();
	~CONFIG();
	void		add_from(char *from, char *target)		{env_from[from] = target;	 };
	void		add_to(char *to, char *target)			{rcpt_to[to]	= target;	 };
	char *		find_from(char *from)					{return find(from, env_from);};
	char *		find_to(char *to)						{return find(to, env_to);	 };
	char *		find(char *needle, &string_map haystack);
	void		dump();
};

extern char *token_envfrom;
extern char *token_lbrace;
extern char *token_rbrace;
extern char *token_rcptto;
extern char *token_semi;

extern string_set	all_strings;	// owns all the strings, only modified by the config loader thread

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  token_init();

#endif