#ifndef HTTP_HANDLER__H #define HTTP_HANDLER__H #ifdef _WIN32 #pragma once #endif #define ON_HTTP_REQUEST(RURI, FN) if (HHttpHandler::UriCmp(m_pHttpParser->GetRequestUri(), RURI)) { return FN(pBodyData, nBodySize); } class HHttpHandler : public HProtocolHandler { public: static bool UriCmp(const char * pszRequestUri, const char * pszPrefix); static bool GetParamValue(const char * pszString, const char * pszKey, char * pszValue); static bool GetCookieValue(const char * pszCookie, const char * pszKeyName, char * pszValue); static bool SetCookieValue(char * pszNewCookie, const char * pszCookie, const char * pszKeyName, const char * pszValue); static int RemoveCookieValue(char * pszCookie, const char * pszKeyName, int nIndex = 0); // return 0 : not found key, 1 : delete, 2 : delete and empty cookie string static int MakeCookie(char * pszSetCookie, const char * pszKeyName, const char * pszKeyValue, const char * pszDomain, const char * pszPath, long nExpireMinute = 0); // nExpireMinute = -1 : delete, 0 : not set expire, (86400 * 10) : 10 days static const char * EnumExtractCookie(const char * pszCookie, char ** ppName, char ** ppValue); static int MakeResponse(char * pszResponse, const char * pszResponseType, const char * pszHtml); static int Make200Header(char * pszResponse, const char * pszContentType, unsigned long nBodySize, const char * pszAddtionalHeaders = NULL); static int Make302Response(char * pszResponse, const char * pszLocation, const char * pszSetCookie = NULL); static int Make307Response(char * pszResponse, const char * pszLocation, const char * pszSetCookie = NULL); static void MakeRedirectBody(HString * pstrBody, const char * pszUrl); // HHttpHandler(); ~HHttpHandler(); protected: void InitParser(); void WriteStreamPacket(const char * pszDir, const char * pszPrefix); virtual void OnReceivedStatusFromTransport(int nStatus) {} bool OnPrepareReceive() { return true; } virtual int OnReceivedFromTransport(const char * pData, int nSize); virtual int OnPacketProcessing(const char * pBodyData, int nBodySize) { return -1; } virtual int OnReceivedBodyStream(const char * pData, int nSize) { return -1; } protected: HHsParser * m_pHttpParser; int m_nProtocolStatus; long m_nRemainBodySize; private: HStreamBuffer * m_pRecvStreamBuffer; }; #endif // HTTP_HANDLER__H