#ifndef HS_PARSER__H_ #define HS_PARSER__H_ #ifdef _WIN32 #pragma once #pragma warning(disable:4996) #endif class HHsHeaderElement { public: HHsHeaderElement(const char * pszName, bool bNameMewMemory, const char * pszValue, bool bValueNewMemory); ~HHsHeaderElement(); public: char * m_pszName; size_t m_nNameLength; bool m_bNameNewMemory; char * m_pszValue; size_t m_nValueLength; bool m_bValueNewMemory; HHsHeaderElement * m_pNext; }; /////////////////////////////////////// class HHsParser { public: enum { HP_PARAMETER_ERROR = 0, HP_NOT_HTTP_PACKET = 1, HP_HEADER_REMAIN_PACKET = 2, HP_BODY_REMAIN_PACKET = 3, HP_BODYSIZE_UNKNOWN_PACKET = 4, HP_COMPLETE_PACKET = 5 }; static char * SearchBodyPtr(char * pData, unsigned int nSize); //////////// HHsParser(const char * pszProtocolName); virtual ~HHsParser(); char * GetProtocolName() { return m_szProtocolName; } char * GetMethod() { return m_pszMethod; } void SetRequestUri(const char * pszRequestUri); char * GetRequestUri() { return m_pszRequestUri; } void SetVersion(const char * pszVersion); char * GetVersion() { return m_pszVersion; } void SetStatusCode(int nStatusCode) { m_nStatusCode = nStatusCode; } int GetStatusCode() { return m_nStatusCode; } void SetReasonPhrase(const char * pszReasonPhrase); char * GetReasonPhrase() { return m_pszReasonPhrase; } size_t GetHeaderSize() { return m_nHeaderSize; } unsigned long GetContentLength() { return m_nContentLength; } void SetBody(char * pData, unsigned int nSize); char * GetBodyPtr() { return m_pBody; } size_t GetBodySize() { return m_nBodySize; } HHsHeaderElement * GetHeaderElement(const char * pszHeaderName, int nIndex = 0); const char * GetHeaderValue(const char * pszHeaderName, int nIndex = 0); bool AddHeader(const char * pszHeaderName, const char * pszHeaderValue); bool SetHeader(const char * pszHeaderName, const char * pszHeaderValue, int nIndex = 0); void RemoveHeader(const char * pszHeaderName, const char * pszHeaderValue = NULL, int nIndex = 0); size_t RefleshHeaderSize(); int Parse(char * pData, unsigned int nSize, char * pBodyPtr = NULL); bool ToString(char * pBuffer, bool bOnlyHeader); protected: bool OrganizeHeader(char * pszHeaderName, char * pszHeaderValue); private: char m_szProtocolName[8]; size_t m_nProtocolNameLength; char * m_pszMethod; char * m_pszRequestUri; bool m_bRequestUriNewMemory; char * m_pszVersion; int m_nStatusCode; char * m_pszReasonPhrase; bool m_bReasonPhraseNewMemory; HHsHeaderElement * m_pElementHead; HHsHeaderElement * m_pElementRear; size_t m_nHeaderSize; unsigned long m_nContentLength; char * m_pBody; bool m_bBodyNewMemory; size_t m_nBodySize; }; #endif // HS_PARSER__H_