BugSplat Native Windows DLL  3.6.0.0
BugSplat API reference for native Windows applications.
GenericHTTPClient.h
1 /*
2  * $ Generic HTTP Client
3  * ----------------------------------------------------------------------------------------------------------------
4  *
5  * name : GenericHTTPClient
6  *
7  * version tag : 0.1.0
8  *
9  * description : HTTP Client using WININET
10  *
11  * author : Heo Yongsun ( gooshin@opentown.net )
12  *
13  * This code distributed under BSD LICENSE STYLE.
14  */
15 
16 #ifndef __GENERIC_HTTP_CLIENT
17 #define __GENERIC_HTTP_CLIENT
18 
19 #include <windows.h>
20 #include <tchar.h>
21 #include <wininet.h>
22 
23 // use stl
24 #include <vector>
25 
26 // PRE-DEFINED CONSTANTS
27 #define __DEFAULT_AGENT_NAME _T("MERONG(0.9/;p)")
28 
29 // PRE-DEFINED BUFFER SIZE
30 #define __SIZE_HTTP_ARGUMENT_NAME 256
31 #define __SIZE_HTTP_ARGUMENT_VALUE 1024
32 
33 #define __HTTP_VERB_GET _T("GET")
34 #define __HTTP_VERB_POST _T("POST")
35 #define __HTTP_VERB_PUT _T("PUT")
36 #define __HTTP_ACCEPT_TYPE _T("*/*")
37 #define __HTTP_ACCEPT _T("Accept: */*\r\n")
38 #define __SIZE_HTTP_BUFFER 100000
39 #define __SIZE_HTTP_RESPONSE_BUFFER 100000
40 #define __SIZE_HTTP_HEAD_LINE 2048
41 
42 #define __SIZE_BUFFER 8192
43 #define __SIZE_SMALL_BUFFER 256
44 
46  public:
47  typedef struct __GENERIC_HTTP_ARGUMENT{ // ARGUMENTS STRUCTURE
48  TCHAR szName[__SIZE_HTTP_ARGUMENT_NAME];
49  TCHAR szValue[__SIZE_HTTP_ARGUMENT_VALUE];
50  DWORD dwType;
51  bool operator==(const __GENERIC_HTTP_ARGUMENT &argV){
52  return !_tcscmp(szName, argV.szName) && !_tcscmp(szValue, argV.szValue);
53  }
55 
56  enum RequestMethod{ // REQUEST METHOD
57  RequestUnknown=0,
58  RequestGetMethod=1,
59  RequestPostMethod=2,
60  RequestPutMethod=5
61  };
62 
63  enum TypePostArgument{ // POST TYPE
64  TypeUnknown=0,
65  TypeNormal=1,
66  TypeBinary=2
67  };
68 
69  // CONSTRUCTOR & DESTRUCTOR
71  virtual ~GenericHTTPClient();
72 
73  static GenericHTTPClient::RequestMethod GetMethod(int nMethod);
74  static GenericHTTPClient::TypePostArgument GetPostArgumentType(int nType);
75 
76  // Connection handler
77  BOOL Connect(CString szAddress,
78  CString szAgent = __DEFAULT_AGENT_NAME,
79  unsigned short nPort = INTERNET_DEFAULT_HTTP_PORT,
80  CString szUserAccount = _T(""),
81  CString szPassword = _T(""));
82  BOOL Close();
83  BOOL Reconnect(); // force a close and reopen.
84  VOID InitilizePutPostArguments();
85 
86  // HTTP Arguments handler
87  VOID AddPutPostArguments(LPCTSTR szName, DWORD nValue);
88  VOID AddPutPostArguments(LPCTSTR szName, LPCTSTR szValue, BOOL bBinary = FALSE);
89 
90  // HTTP Method handler
91  BOOL Request(LPCTSTR szURL, int nMethod = GenericHTTPClient::RequestGetMethod, LPCTSTR szAgent = __DEFAULT_AGENT_NAME);
92  BOOL RequestOfURI(LPCTSTR szURI, int nMethod = GenericHTTPClient::RequestGetMethod);
93  BOOL Response(LPWSTR pHeaderBuffer, DWORD dwHeaderBufferLength, LPWSTR pBuffer, DWORD dwBufferLength, DWORD &dwResultSize);
94  LPCTSTR QueryHTTPResponse();
95  LPCTSTR QueryHTTPResponseHeader();
96 
97 
98  // General Handler
99  LPCTSTR GetContentType(LPCTSTR szName);
100  VOID ParseURL(LPCTSTR szURL, LPTSTR szAddress, int nAddSize, LPTSTR szURI, int nUriSize);
101 
102 
103  protected:
104  std::vector<GenericHTTPArgument> _vArguments; // POST ARGUMENTS VECTOR
105 
106  TCHAR _szHTTPResponseHTML[__SIZE_HTTP_BUFFER]; // RECEIVE HTTP BODY
107  TCHAR _szHTTPResponseHeader[__SIZE_HTTP_BUFFER]; // RECEIVE HTTP HEADR
108 
109  TCHAR _szCacheAddress[__SIZE_BUFFER];
110  TCHAR _szCacheAgent[__SIZE_BUFFER];
111  TCHAR _szCacheUser[__SIZE_BUFFER];
112  TCHAR _szCachePwd[__SIZE_BUFFER];
113  unsigned short _nCachePort;
114 
115  HINTERNET _hHTTPOpen; // internet open handle
116  HINTERNET _hHTTPConnection; // internet connection hadle
117  HINTERNET _hHTTPRequest; // internet request hadle
118 
119  DWORD _dwError; // LAST ERROR CODE
120  LPCTSTR _szHost; // HOST NAME
121  DWORD _dwPort; // PORT
122 
123  // HTTP Method handler
124  DWORD ResponseOfBytes(PBYTE pBuffer, DWORD dwSize);
125  DWORD GetPostArguments(LPTSTR szArguments, DWORD dwLength);
126  VOID EncodePlusCharacters(LPTSTR szArguments, DWORD dwLength);
127 
128  BOOL RequestPost(LPCTSTR szURI);
129  BOOL RequestPut(LPCTSTR szURI);
130  BOOL RequestGet(LPCTSTR szURI);
131 
132  DWORD SendPutFileData();
133 
134  VOID DebuggerConsoleMessage();
135  };
136 
137 #endif // #ifndef __GENERIC_HTTP_CLIENT
Definition: GenericHTTPClient.h:47
Definition: GenericHTTPClient.h:45