#ifndef _glirc_dcc_h
#define _glirc_dcc_h

#include "dcc_gui.h"


extern int iActiveDCC_count;
typedef struct{
	char empty;
	FD_active_dcc_get *form;
}ActiveDCC;
extern ActiveDCC *aActiveDCC;
typedef struct TDCCFileR{			/* file requests that u /receive */
	int		id;
	char		*filename;
	off_t		size;	/* <0--> size not given*/
	u_long		checksum;
	char		resume;	/* !0 ->have sent resume request*/
	/*off_t		offset;*//* necessary to catch incompatible clients*/
	char		*nick;
	char		*email;
	time_t		starttime;	
	u_short		port;
	u_long		inetaddr;	
	struct TDCCFileR *next;
} DCCFileR;
DCCFileR	*filegetStart, *filegetEnd;/* requests that u receive */
typedef struct TDCCFileS{			/* file requests that u send */
	int		id;
	int	 	fd;
	char		*filename;
	char		accept;		/* sent DCC ACCEPT */
	off_t		offset;
	off_t		size;
	u_long		checksum;
	char		*nick;
	char		*email;
	time_t		starttime;
	u_short		port;	
	struct TDCCFileS *next;
} DCCFileS;
DCCFileS	*filesendStart, *filesendEnd;/* requests that u send */
typedef struct TDCCFile{			/* file transfers inprogress */
	int		id;
	int		fd;
	int		fp;			/* local file */
	int		w;			/* file transfer display*/
	char		*filename;
	off_t		size;
	off_t		offset;
	char		flag;			/* 0=> receiving */
	char 		*nick;
	char		*host;			/*(todo:remove;use getpeername) hostname (inet_ntoa!) */
	char		*email;			/*(todo:remove;use getpeername)*/
	off_t		read;			/* progress (read or sent)*/
	struct timeval	lasttime;		/* when the last read(if GETting)/write(SEND) occured */
	struct timeval	starttime;	
	struct TDCCFile *next;
} DCCFile;
DCCFile	*DCCfileStart, *DCCfileEnd;/* transfers in progress */


typedef struct TChatReqRecvd{/* chat requests receieved */
	int		id;	/* use /chat <id> to reply */
	char		*nick;
	char		*email;	
	time_t		starttime;	
	u_short		port;
	u_long		inetaddr;
	struct TChatReqRecvd	*next;
}ChatReqRecvd;
ChatReqRecvd		*chatreqStart, *chatreqEnd;/* chat requests receieved */
typedef struct TChatReqSent{/* chat requests sent */
	int		id;	
	char		*nick;
	char		*email;	/* null */
	int		fd;	/* local server; applies only to sent requests */
	char		*server;	/* '' */
	Winstruct	*win;		/* window where chat will be; NULL->create one */
	time_t		starttime;
	struct TChatReqSent	*next;
}ChatReqSent;
ChatReqSent	*chatsentStart, *chatsentEnd; /* chat requests sent */


extern 	int ctcp_cmd(void);
typedef struct TKey{
	char *who;
	char *key;
	char flag;	/* decrypt or not */
	struct TKey *next;
} Key;
Key *keys;
extern void do_encrypt(int ,char **, Winstruct *);
extern char *ctcp_quote_it(char *,int len);
extern void encrypt_str(char *,int,char *);
#define ENCRYPT 0
#define DECRYPT 1
extern char *have_key(char *who, int action);
/*
extern int ctcp_notice_cmd(const char *nick, const char *email,const  char *dest, 
		const char *msg);
  */

/*FD_dcc *dcc_form;*/

extern void achat(int ,char **, Winstruct *);
extern void get(int ,char **, Winstruct *);
extern void remove_from_chat_requests_recvd(int id);
extern int remove_dccchat(int   id, char *reason) ;
extern int dcc_create_chatwin(int , char *, char *,char *, Winstruct *,int id);
extern int dcc_sendchatreq(Winstruct *win, Winstruct *w, const char *nick);

extern void remove_sentchatreq(int id);
extern void remove_file_offer(int id);

int sendto_dcc_chat(Winstruct *, DCCChat *, const char *);
extern DCCChatWin *search_dccwinsbyid(int id);

extern dcc_getfile(int fd, DCCFileR *q, Winstruct *win);
extern int dcc_sendfilereq(const char *nick);

/*extern void remove_getfile(int id);*/
extern void close_getfile(int id, Winstruct *win);

extern int addto_sentfileoffer(const char *nick,char *file, off_t size,Winstruct *win);

/*-----accept DCCs-----------*/
extern void receive_send_req(const char *nick,const char * email,char *fname,
	u_long inaddr, u_short port, off_t filesize, u_long checksum);
extern void accept_request(const char *nick, const char *email,
			     u_short port, off_t offset);
extern void resume_request(const char *nick, const char *email,
			     u_short port, off_t offset, u_long checksum);

extern void rename_request(const char *, const char *, u_short port);
extern void reject_request(const char *, const char *, u_short port);
extern void receive_chat_req(const char *nick,const char *email, 
		u_long inaddr,u_short port);

extern void offer(int, char **, Winstruct *);


u_short		chat_id;
int		dcc_get_id;
/*u_short		dcc_send_id; declared static*/
int		dcc_file_id;


u_short		dcc_timeout;
char		*chat_quit_text;
char		*userinfo;	/* ctcp */
char		*finger_reply;	/* finger reply */
u_int		max_sendbuf;	/* dcc send file; buffer suze*/


#endif

