#pragma once

//#include "../3rd/Src/HPSocket4C-SSL.h"
#include "../HPSocket/Include/HPSocket/HPSocket-SSL.h"
#include "../HPSocket/Include/HPSocket/SocketInterface.h"
#include  <string>
#include <stdio.h>
#include <stdlib.h>

using namespace std;
class CNetHttpClientListener : public IHttpClientListener
{
public:
	CNetHttpClientListener();
	~CNetHttpClientListener();
private:
	DWORD		m_dwTotalBodyLen;
	DWORD		m_dwRecvBodyLen;

public:
	virtual EnHandleResult OnPrepareConnect(ITcpClient* pSender, CONNID dwConnID, SOCKET socket);
	virtual EnHandleResult OnConnect(ITcpClient* pSender, CONNID dwConnID);
	virtual EnHandleResult OnHandShake(ITcpClient* pSender, CONNID dwConnID);
	virtual EnHandleResult OnReceive(ITcpClient* pSender, CONNID dwConnID, int iLength);
	virtual EnHandleResult OnReceive(ITcpClient* pSender, CONNID dwConnID, const BYTE* pData, int iLength);
	virtual EnHandleResult OnSend(ITcpClient* pSender, CONNID dwConnID, const BYTE* pData, int iLength);
	virtual EnHttpParseResult OnMessageBegin(IHttpClient* pSender, CONNID dwConnID);
	virtual EnHttpParseResult OnRequestLine(IHttpClient* pSender, CONNID dwConnID, LPCSTR lpszMethod, LPCSTR lpszUrl);
	virtual EnHttpParseResult OnStatusLine(IHttpClient* pSender, CONNID dwConnID, USHORT usStatusCode, LPCSTR lpszDesc);
	virtual EnHttpParseResult OnHeader(IHttpClient* pSender, CONNID dwConnID, LPCSTR lpszName, LPCSTR lpszValue);
	virtual EnHttpParseResult OnChunkHeader(IHttpClient* pSender, CONNID dwConnID, int iLength);
	virtual EnHttpParseResult OnChunkComplete(IHttpClient* pSender, CONNID dwConnID);
	virtual EnHttpParseResult OnUpgrade(IHttpClient* pSender, CONNID dwConnID, EnHttpUpgradeType enUpgradeType);
	virtual EnHandleResult OnWSMessageHeader(IHttpClient* pSender, CONNID dwConnID, BOOL bFinal, BYTE iReserved, BYTE iOperationCode, const BYTE lpszMask[4], ULONGLONG ullBodyLen);
	virtual EnHandleResult OnWSMessageBody(IHttpClient* pSender, CONNID dwConnID, const BYTE* pData, int iLength);
	virtual EnHandleResult OnWSMessageComplete(IHttpClient* pSender, CONNID dwConnID);
	virtual EnHttpParseResult OnHeadersComplete(IHttpClient* pSender, CONNID dwConnID);
	virtual EnHttpParseResult OnBody(IHttpClient* pSender, CONNID dwConnID, const BYTE* pData, int iLength);
	virtual EnHttpParseResult OnMessageComplete(IHttpClient* pSender, CONNID dwConnID);
	virtual EnHttpParseResult OnParseError(IHttpClient* pSender, CONNID dwConnID, int iErrorCode, LPCSTR lpszErrorDesc);
	virtual EnHandleResult OnClose(ITcpClient* pSender, CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode);
};

enum HTTP_TYPE
{
	T_HTTP_REQUEST_GET,	//http헝헹(get)
	T_HTTP_REQUEST_POST,	//http헝헹(post)
	T_HTTPS_REQUEST_GET,	//https헝헹(get)
	T_HTTPS_REQUEST_POST	//https헝헹(post)
};
class CSSLAgent
{
public:
	CSSLAgent();
	~CSSLAgent();
public:
	static CSSLAgent*	GetInstance()
	{
		if (m_instance == nullptr)
		{
			m_instance = new CSSLAgent();
		}
		return m_instance;
	}
	static void Release()
	{
		if (m_instance)
		{
			delete m_instance;
			m_instance = nullptr;
		}
	}
private:
	static CSSLAgent* m_instance;
private:
	//HP_SSLPullClient m_pClient;
	//HP_TcpPullClientListener m_pListener;
	bool m_bHttps;
	DWORD dwRequestTimeout;
	int nRetryTimes;
public:
	void SendMsg(HTTP_TYPE enType,string strUrl, string strParam,string &strOut);
};
#define  HTTP_CLIENT  CSSLAgent::GetInstance()



