//----------------------- CSPCookies.h ------------------------

//*************************************************************
//*****       Copyright ©2002 - 2004 Micronovae Ltd       *****
//*****                All rights reserved                *****
//*************************************************************

#ifndef _CSPCOOKIES
#define _CSPCOOKIES

#include "CSPConf.h"
#include "CSPLib.h"
#include "CSPString.h"
#include "CSPTime.h"
#include "CSPMap.h"
#include <httpext.h>

class CSPOBJ_CLASS_EXPORT CSPRequest;


//---------------------CSPCookie---------------------------

class CSPOBJ_CLASS_EXPORT CSPCookie : public CSPObject
{
public:
	CSPString Value;
	CSPString Name;

	CSPCookie( const CSPString& strName );
	virtual ~CSPCookie();	
	operator const CSPString&() const;
};



//---------------------CSPSetCookie---------------------


class CSPOBJ_CLASS_EXPORT CSPSetCookie : public CSPCookie
{
	friend class CSPSetCookieSet;
	friend class CSPResponse;

	public:
		CSPString Domain;
		CSPDateTime Expires;
		CSPString Path;
		bool Secure;
		
		CSPSetCookie( const CSPString& strName );
		virtual ~CSPSetCookie();

		void operator = ( const CSPString& strValue );
		void operator = ( const char* pszValue );
};




//--------------------CSPGetCookie---------------------


class CSPOBJ_CLASS_EXPORT CSPGetCookie : public CSPCookie
{
	friend class CSPGetCookieSet;
	friend class CSPRequest;

	public:
		bool IsNull() const;
		CSPGetCookie( const CSPString& strName = CSPString() );
		virtual ~CSPGetCookie();

	protected:
		bool bIsNull;
		
		char* InitCookie( char* pszString );
};



//---------------------CSPSetCookieSet----------------------

class CSPOBJ_CLASS_EXPORT CSPSetCookieSet : public CSPObject
{
	typedef CSPMap< CSPString, CSPSetCookie > CSPSetCookieMap;
	friend class CSPResponse;

	public:	
		CSPSetCookieSet();
		virtual ~CSPSetCookieSet();
		CSPSetCookie& operator ()( const CSPString& strName );
		CSPSetCookie& CSPSetCookieSet::GetCookie( const CSPString& strName );
		CSPSetCookie& operator []( unsigned long ulIndex );
		CSPSetCookie& CSPSetCookieSet::GetCookie( unsigned long ulIndex );

		unsigned long GetCount() const;

	protected:
		CSPSetCookieMap CookiesMap;
		CSPSetCookie DeadCookie;
};


//---------------------CSPGetCookies----------------------


class CSPOBJ_CLASS_EXPORT CSPGetCookieSet : public CSPObject
{
	friend class CSPRequest;
	friend class CSPGetCookie;
	typedef CSPMap< CSPString, CSPGetCookie > CSPGetCookieMap;

	public:
		CSPGetCookieSet( const CSPRequest& Request );
		virtual ~CSPGetCookieSet();
		const CSPGetCookie& operator ()( const CSPString& strName ) const;
		const CSPGetCookie& operator []( unsigned long ulIndex ) const;
		const CSPGetCookie& GetCookie( const CSPString& strName ) const;
		const CSPGetCookie& GetCookie( unsigned long ulIndex ) const;
		unsigned long GetCount() const;

	protected:
		CSPGetCookieMap CookiesMap;
		CSPGetCookie DeadCookie;
		bool bParsed;
		const CSPRequest& ParentRequest;


		void InitCookies();

private:
		CSPGetCookieSet( const CSPGetCookieSet& GetCookies );
		CSPGetCookieSet& operator = ( const CSPGetCookieSet& GetCookies );

};

#endif 
