/*
 *	Module: 		wssoup.h
 *	Author:			TANAKA Goh <goh@yamato.ibm.co.jp>
 *	Date:			1995/07/07
 *	Description:	Declare part of wssoup class.
 */

#ifndef __WSSOUP_H__
#define __WSSOUP_H__
#include <windows.h>
#include <fstream.h>
#include <stdio.h>

#ifndef _WIN32
#define MAKEWORD(l, h)	(((WORD)(l)) | ((WORD)(h)) << 8)
#endif	// _WIN32

class wssoup_areas {
private:
	char*	filename;
	char*	group;
	char	encoding[4];
	
	friend int	compare_wssoup_areas_group(wssoup_areas**, wssoup_areas**);
	
public:
	wssoup_areas(void);
	wssoup_areas(char*, char*, char*);
	~wssoup_areas(void);
	
	void		put_filename(char*);
	char*		get_filename(void);
	void		put_group(char*);
	char*		get_group(void);
	void		put_encoding(char*);
	char*		get_encoding(void);
};

class wssoup_areas_table {
private:
#ifdef _WIN32
	wssoup_areas**	soup_areas;
#else
	wssoup_areas huge* huge*	soup_areas;
#endif
	unsigned long	soup_areas_total;
	int				rc;
	
public:
	wssoup_areas_table(void);
	wssoup_areas_table(char*);
	~wssoup_areas_table(void);
	
	operator int();
	
	void			read_wssoup_areas(char*);
	wssoup_areas**	get_wssoup_areas(void);
	wssoup_areas**	get_wssoup_areas(char*);
	unsigned long	get_wssoup_areas_total(void);
};

class wssoup_index {
private:
	unsigned long	number;
	char*			subject;
	char*			from;
	char*			date;
	char*			message_id;
	char*			references;
	unsigned long	bytes;
	unsigned long	lines;
	unsigned long	offset;
	
	friend int		compare_wssoup_index_number(wssoup_index**, wssoup_index**);
	friend int		compare_wssoup_index_message_id(wssoup_index**, wssoup_index**);
	
public:
	wssoup_index(void);
	wssoup_index(unsigned long, char*, char*, char*, char*, char*, unsigned long, unsigned long, unsigned long);
	~wssoup_index(void);
	
	void			put_number(unsigned long);
	unsigned long	get_number(void);
	void			put_subject(char*);
	char*			get_subject(void);
	void			put_from(char*);
	char*			get_from(void);
	void			put_date(char*);
	char*			get_date(void);
	void			put_message_id(char*);
	char*			get_message_id(void);
	void			put_references(char*);
	char*			get_references(void);
	void			put_bytes(unsigned long);
	unsigned long	get_bytes(void);
	void			put_lines(unsigned long);
	unsigned long	get_lines(void);
	void			put_offset(unsigned long);
	unsigned long	get_offset(void);
};

class wssoup_index_table {
private:
#ifdef _WIN32
	wssoup_index**	soup_index;
#else
	wssoup_index huge* huge*	soup_index;
#endif
	unsigned long	soup_index_total_org;
	unsigned long	soup_index_total;
	
	char			index_filename[256];
	char			message_filename[256];
	char			index_tmp_filename[256];
	char			message_tmp_filename[256];
	ifstream		index_org;
	ifstream		message_org;
	ofstream		index_tmp;
	ofstream		message_tmp;
	
	int				rc;
	
public:
	wssoup_index_table(void);
	wssoup_index_table(char*, char*, char*);
	~wssoup_index_table(void);
	
	operator int();
	
	void			read_wssoup_index_table(char*, char*, char*);
	void			write_wssoup_index_table(char*, char*, char*);
	int				write_wssoup_index(char*, char*, char*, unsigned long);
	wssoup_index**	get_wssoup_index(void);
	wssoup_index**	get_wssoup_index(unsigned long);
	wssoup_index*	get_wssoup_index(char*);
	void			delete_wssoup_index(unsigned long);
	unsigned long	get_wssoup_index_total_org(void);
	unsigned long	get_wssoup_index_total(void);
};

class wssoup {
private:
	char				inbound[256];
	char				outbound[256];
#ifdef CONTROL
	char				control[256];
#endif	// CONTROL
	
	wssoup_areas_table*	soup_areas_table;
	wssoup_index_table*	soup_index_table;
	
	char				server_command[512];
	char				server_buffer[4096];
	BOOL				server_response;
	
	wssoup_areas**		soup_areas;
	
//	ifstream			index;
	unsigned long		article_from;
	unsigned long		article_to;
	
	ofstream			data;
	
	ifstream			list;
	unsigned long		list_from;
	
	ofstream			post;
	
	unsigned long		write_from;
	unsigned long		write_to;
	
	ifstream			message;
	unsigned long		xover_from;
	unsigned long		xover_to;
	
	void	put_article_command(char*);
	void	put_data_command(char*);
	void	put_delete_command(char*);
	void	put_group_command(char*);
	void	put_list_command(char*);
	void	put_post_command(char*);
	void	put_sendme_command(char*);
	void	put_write_command(char*);
	void	put_xover_command(char*);
	
	void	get_article_response(void);
	void	get_data_response(void);
	void	get_list_response(void);
	void	get_post_response(void);
	void	get_write_response(void);
	void	get_xover_response(void);
	
protected:
	BOOL	header;
	void	put_server_response(char*);
	char*	get_server_command(void);
	
public:
	wssoup(void);
	~wssoup(void);
	
	void	put_server_command(char*);
	void	get_server_response(char*, size_t);
};
#endif	// __WSSOUP_H__
