Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cHttpHeader.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cHttpHeader_H
7 #define _INC_cHttpHeader_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cHttpCommon.h"
17 
18 namespace GrayLib
19 {
21 
22  enum HTF_TYPE
23  {
26  HTF_Get = 1,
27  HTF_Resp = 2,
28  HTF_Comma = 4,
29  HTF_Semi = 8,
30  HTF_X = 16,
31  };
32 
34  {
38 #define cHttpTag(a,b,c,d,e) HTTP_TAG_##a,
39 #include "cHttpTags.tbl"
40 #undef cHttpTag
42  };
43 
45  {
51  };
52 
54  {
59  };
60 
62  {
69 
70  public:
71  static const char* const k_aszTags[HTTP_TAG_QTY + 1];
74 
75  public:
76  cHttpHeadTag(HTTP_TAG_TYPE eTag = HTTP_TAG_UNK, cStringA sVal = "") noexcept
77  : m_eTag(eTag), m_sVal(sVal)
78  {
79  }
80  HTTP_TAG_TYPE get_HashCode() const noexcept
81  {
82  return m_eTag;
83  }
84 
85  static StrLen_t GRAYCALL GetSizeWriteTag(HTTP_TAG_TYPE eTag, cStringA sTag);
86  static HRESULT GRAYCALL WriteTag(cStreamOutput* pOut, HTTP_TAG_TYPE eTag, cStringA sTag);
87  };
88 
90  {
97 
98  friend class cHttpHeadTag;
99 
100  public:
101  static const int k_MaxTags = 256;
102  protected:
104 
105  protected:
106  HRESULT ReadHeadLine(const char* pData, StrLen_t iLen);
107  HRESULT WriteHeadTags(cStreamOutput* pClient) const;
108 
109  protected:
110  cHttpHeader() noexcept;
111  ~cHttpHeader();
112 
113  public:
114  ITERATE_t get_HeadTagQty() const
115  {
116  return m_aTags.GetSize();
117  }
118  bool HasHeadTag(HTTP_TAG_TYPE eTag) const
119  {
120  return(m_aTags.FindIForKey(eTag) >= 0);
121  }
122 
123  cStringA FindHeadTag(HTTP_TAG_TYPE eTag) const;
124  cTimeInt FindHeadTagTime(HTTP_TAG_TYPE eTag) const;
125  int FindHeadTagInt(HTTP_TAG_TYPE eTag) const;
126 
127  ITERATE_t AddHeadTag(HTTP_TAG_TYPE eTag, cStringA sVal);
128  ITERATE_t AddHeadTagTime(HTTP_TAG_TYPE eTag, cTimeInt tTime);
129  ITERATE_t AddHeadTagInt(HTTP_TAG_TYPE eTag, int iVal);
130 
131  HRESULT ReadHeader(cStreamInput* pInp, OUT cStringA& sHeadVerb);
132 
134  };
135 
137  {
140  public:
143  // cStringA m_sBodyPost; //!< The body if this is a HTTPVERB_POST. NOT USED
144  public:
145  cHttpHeaderClient(HTTPVERB_TYPE eVerb = HTTPVERB_TRACE, cStringA sUrlObject = "") noexcept
146  : m_eVerb(eVerb)
147  , m_sURLObject(sUrlObject)
148  {
149  }
150 
151  void SetGETDefaults();
152  void SetPOSTDefaults();
153 
154  HRESULT SetClientVerb(const char* pszPrefixData, StrLen_t iPrefixLen, bool bReadURL = true);
155  HRESULT WriteHeadClient(cStreamOutput* pClient) const;
156  // void GetCookies( cIniMap& cookies );
157  };
158 
160  {
163  public:
165  public:
166  cHttpHeaderServer(HTTPRET_TYPE eRetCode = HTTPRET_OK_DATA)
167  : m_eRetCode(eRetCode)
168  {
169  }
170  // void SetCookies( cIniMap& cookies );
171  HRESULT SetServerRetCode(const char* pszPrefixData, StrLen_t iPrefixLen);
172  HRESULT WriteHeadServer(cStreamOutput* pClient) const;
173  };
174 };
175 
176 #endif
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cHttpHeader.h:54
Definition: cHttpHeader.h:62
HTTP_TAG_TYPE m_eTag
What tag type? one of each per header. order is not important.
Definition: cHttpHeader.h:72
cStringA m_sVal
The string may evaluate to int,'string' or enum constant.
Definition: cHttpHeader.h:73
HTTP_TAG_TYPE get_HashCode() const noexcept
Definition: cHttpHeader.h:80
cHttpHeadTag(HTTP_TAG_TYPE eTag=HTTP_TAG_UNK, cStringA sVal="") noexcept
Definition: cHttpHeader.h:76
Definition: cHttpHeader.h:137
HTTPVERB_TYPE m_eVerb
What does the client want ?
Definition: cHttpHeader.h:141
cHttpHeaderClient(HTTPVERB_TYPE eVerb=HTTPVERB_TRACE, cStringA sUrlObject="") noexcept
Definition: cHttpHeader.h:145
cStringA m_sURLObject
the requested URL object. cNetURL::DeCode already called.
Definition: cHttpHeader.h:142
Definition: cHttpHeader.h:160
cHttpHeaderServer(HTTPRET_TYPE eRetCode=HTTPRET_OK_DATA)
Definition: cHttpHeader.h:166
HTTPRET_TYPE m_eRetCode
What does the server respond with?
Definition: cHttpHeader.h:164
Definition: cHttpHeader.h:90
cArraySortStructHash< cHttpHeadTag > m_aTags
Tags in the HTTP header.
Definition: cHttpHeader.h:103
UNITTEST_FRIEND(cHttpHeader)
bool HasHeadTag(HTTP_TAG_TYPE eTag) const
Definition: cHttpHeader.h:118
ITERATE_t GetSize() const noexcept
Definition: cArray.h:137
Definition: cArraySort.h:363
ITERATE_t FindIForKey(KEY_t key) const
Definition: cArraySort.h:68
Definition: cIniMap.h:18
Definition: cStream.h:306
Definition: cStream.h:126
< similar to the MFC CTime and cTimeSpan, not as accurate or large ranged as COleDateTime
Definition: cTimeInt.h:101
Definition: cMesh.h:22
HTTPRET_TYPE
Definition: cHttpCommon.h:24
HTTPVERB_TYPE
Definition: cHttpCommon.h:36
UNITTEST2_PREDEF(cQuadtree)
HTTP_TAG_TYPE
Definition: cHttpHeader.h:34
@ HTTP_TAG_QTY
Definition: cHttpHeader.h:41
@ HTTP_TAG_UNK
Definition: cHttpHeader.h:37
HTTP_Connection_TYPE
Definition: cHttpHeader.h:45
@ HTTP_Connection_Close
"Close" = just close when done with this transaction.
Definition: cHttpHeader.h:49
@ HTTP_Connection_KeepAlive
"Keep-Alive"
Definition: cHttpHeader.h:50
@ HTTP_Connection_DK
don't care. default = keep alive.
Definition: cHttpHeader.h:48
HTF_TYPE
Definition: cHttpHeader.h:23
@ HTF_Resp
Sent by server to client as a response.
Definition: cHttpHeader.h:27
@ HTF_Get
Sent by client to the server.
Definition: cHttpHeader.h:26
@ HTF_Comma
Takes comma separated args.
Definition: cHttpHeader.h:28
@ HTF_X
Non HTML standard tag.
Definition: cHttpHeader.h:30
@ HTF_Semi
Semicolon separated flags. e.g. "windows-1252,utf-8;q=0.7,*;q=0.3".
Definition: cHttpHeader.h:29
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
int ITERATE_t
like size_t but signed
Definition: Index.h:28