			/* ------------------------------------- */
			//										 //
			//  +-+-+-+-+-+-+ +-+-+-+-+-+ +-+-+-+-+  //
			//  |S|i|m|p|l|e| |P|r|o|x|y| |2|0|0|4|  //
			//  +-+-+-+-+-+-+ +-+-+-+-+-+ +-+-+-+-+  //
			//										 //
			//										 //
			//  AUTOR : Aymeric  //
			//  DATE  : May 2004					 //
			//  FILE  : proxy.h						 //
			//  DESC  : main library				 //
			//  									 //
			/* ------------------------------------- */


/************************************************************************/


#ifndef PROXY_H
#define PROXY_H

#define isdigit(c) (c >= '0' && c <='9')

#define BUFFERSIZE (2*1024)
#define BUFFERPAGE (2*1000*1024*1024)

#define INDEXFILE "cache/cache.txt"
#define CACHEDIR "cache/"

enum bool { false, true };

FILE *log;
FILE *access_log;

enum bool debug;

struct sConfig {
	char host[255];
	char proxyhost[255];
	int port;
	int proxyport;
	int cache;
	int proxyserv;
	int daemon;
};

struct sLog {
	char hostname[255];
	char *firstline;
};

struct headerHTTP {
	char* HTTPversion;
	int StatusCode;
	// request URI
	char* URIproto;
	char* URIserv;
	int   URIport;
	char* URIpath;
	// General
	char* CacheControl;
	time_t MaxAge;
	char* Pragma;
	time_t Date;
	// Request
	char* Host;
	// Entity
	time_t Expires;
	int ContentLength;
	// Response
	time_t Age;
};

struct sCache {
	char *url;
	char *file;
	time_t freshness;
	time_t last_access;
	enum bool cache;
};

#ifndef _TIME_H_
struct tm {
	int	tm_sec;		/* seconds after the minute [0-60] */
	int	tm_min;		/* minutes after the hour [0-59] */
	int	tm_hour;	/* hours since midnight [0-23] */
	int	tm_mday;	/* day of the month [1-31] */
	int	tm_mon;		/* months since January [0-11] */
	int	tm_year;	/* years since 1900 */
	int	tm_wday;	/* days since Sunday [0-6] */
	int	tm_yday;	/* days since January 1 [0-365] */
	int	tm_isdst;	/* Daylight Savings Time flag */
	long	tm_gmtoff;	/* offset from CUT in seconds */
	char	*tm_zone;	/* timezone abbreviation */
};

#endif

/* readConfig.c */
enum bool readConfig(char *, struct sConfig *);

/* execution.c */
enum bool execute(char *, int, char *, int, struct sConfig, struct sLog *);
void errorPage(int);

/* readHTTP.c */
char* readHTTPHeader(char *, struct headerHTTP *, struct sLog *);
enum bool checkIfRequest(char *);
enum bool checkIfResponse(char *);
enum bool checkRequestLine(char *, struct headerHTTP *);
enum bool checkResponseLine(char *, struct headerHTTP *);
enum bool getDetailsURI(struct headerHTTP *, char *);
enum bool is_number(char *);
void getRequestHeader(struct headerHTTP *, char *);
void getGeneralHeader(struct headerHTTP *, char *);
void getEntityHeader(struct headerHTTP *, char *);
void getResponseHeader(struct headerHTTP *, char *);
time_t strtotime(char *,char *);

/* proxy.c */
void init(struct headerHTTP *);
void termination_handler(int);
char *logtime();

/* getPage.c */
enum bool getPage(char *, struct sConfig, int, char *, struct sLog);
char *clearRequete(char *);
char *changeRequete(char *, struct headerHTTP);

/* cacheFiles.c */
enum bool checkCache(char *, struct sCache *);
void saveCache(struct sCache *);
int line_count(char *);
void fileCache(char *, char *, int);
void changeCache(struct sCache);
char *readFile(char *, int);
int char_count(char *);

/* cache.c */
char *CacheControlProcedure(struct sCache *, char *, time_t, enum bool);
char *PragmaProcedure(char *, struct sCache *, enum bool);
char *ExpiresProcedure(struct sCache *, time_t);

#endif
