BugSplat Native DLL  Version 3.3.1.0
BugSplat integration code for native Windows applications
 All Classes Functions Variables
GenericHTTPClientA.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 #define __SIZE_HTTP_SOAP_PACKET 4096
33 
34 #define __HTTP_VERB_GET _T("GET")
35 #define __HTTP_VERB_POST _T("POST")
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 1024
43 #define __SIZE_SMALL_BUFFER 256
44 
45  class GenericHTTPClient {
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  }
54  } GenericHTTPArgument;
55 
56  typedef struct __GENERIC_SOAP_ARGUMENT{
57  TCHAR szPacket[__SIZE_HTTP_SOAP_PACKET];
58  bool operator==(const __GENERIC_SOAP_ARGUMENT &argv){
59  return !_tcscmp(szPacket, argv.szPacket);
60  }
61  } GenericSOAPPacket;
62 
63  enum RequestMethod{ // REQUEST METHOD
64  RequestUnknown=0,
65  RequestGetMethod=1,
66  RequestPostMethod=2,
67  RequestPostMethodMultiPartsFormData=3,
68  RequestSoapMethod=4,
69  };
70 
71  enum TypePostArgument{ // POST TYPE
72  TypeUnknown=0,
73  TypeNormal=1,
74  TypeBinary=2
75  };
76 
77  // CONSTRUCTOR & DESTRUCTOR
79  virtual ~GenericHTTPClient();
80 
81  static GenericHTTPClient::RequestMethod GetMethod(int nMethod);
82  static GenericHTTPClient::TypePostArgument GetPostArgumentType(int nType);
83 
84  // Connection handler
85  BOOL Connect(LPCTSTR szAddress, LPCTSTR szAgent = __DEFAULT_AGENT_NAME, unsigned short nPort = INTERNET_DEFAULT_HTTP_PORT, LPCTSTR szUserAccount = NULL, LPCTSTR szPassword = NULL);
86  BOOL Close();
87  BOOL Reconnect(); // force a close and reopen.
88  VOID InitilizePostArguments();
89 
90  // HTTP Arguments handler
91  VOID AddPostArguments(LPCTSTR szName, DWORD nValue);
92  VOID AddPostArguments(LPCTSTR szName, LPCTSTR szValue, BOOL bBinary = FALSE);
93 
94  // SOAP Arguments handler
95  VOID SetSoapPacket(LPCTSTR szXmlSOAP);
96  VOID GetSoapPacket(LPTSTR szXmlSOAP, DWORD dwLength);
97 
98  // HTTP Method handler
99  BOOL Request(LPCTSTR szURL, int nMethod = GenericHTTPClient::RequestGetMethod, LPCTSTR szAgent = __DEFAULT_AGENT_NAME, DWORD dwPortOverride=0xffffffff);
100  BOOL RequestOfURI(LPCTSTR szURI, int nMethod = GenericHTTPClient::RequestGetMethod);
101  BOOL Response(PBYTE pHeaderBuffer, DWORD dwHeaderBufferLength, PBYTE pBuffer, DWORD dwBufferLength, DWORD &dwResultSize);
102  LPCTSTR QueryHTTPResponse();
103  LPCTSTR QueryHTTPResponseHeader();
104 
105 
106  // General Handler
107  DWORD GetLastError();
108  LPCTSTR GetContentType(LPCTSTR szName);
109  VOID ParseURL(LPCTSTR szURL, LPTSTR szProtocol, int nPrtclSize, LPTSTR szAddress, int nAddSize, DWORD &dwPort, LPTSTR szURI, int nUriSize);
110 
111 
112  protected:
113  std::vector<GenericHTTPArgument> _vArguments; // POST ARGUMENTS VECTOR
114  GenericSOAPPacket _soapPacket; // SOAP PACKET
115 
116  TCHAR _szHTTPResponseHTML[__SIZE_HTTP_BUFFER]; // RECEIVE HTTP BODY
117  TCHAR _szHTTPResponseHeader[__SIZE_HTTP_BUFFER]; // RECEIVE HTTP HEADR
118 
119  TCHAR _szCacheAddress[__SIZE_BUFFER];
120  TCHAR _szCacheAgent[__SIZE_BUFFER];
121  TCHAR _szCacheUser[__SIZE_BUFFER];
122  TCHAR _szCachePwd[__SIZE_BUFFER];
123  unsigned short _nCachePort;
124 
125  HINTERNET _hHTTPOpen; // internet open handle
126  HINTERNET _hHTTPConnection; // internet connection hadle
127  HINTERNET _hHTTPRequest; // internet request hadle
128 
129  DWORD _dwError; // LAST ERROR CODE
130  LPCTSTR _szHost; // HOST NAME
131  DWORD _dwPort; // PORT
132 
133  // HTTP Method handler
134  DWORD ResponseOfBytes(PBYTE pBuffer, DWORD dwSize);
135  DWORD GetPostArguments(LPTSTR szArguments, DWORD dwLength);
136 
137  BOOL RequestPost(LPCTSTR szURI);
138  BOOL RequestPostMultiPartsFormData(LPCTSTR szURI);
139  BOOL RequestGet(LPCTSTR szURI);
140  BOOL RequestSOAP(LPCTSTR szURI);
141 
142  DWORD AllocMultiPartsFormData(PBYTE &pInBuffer, LPCTSTR szBoundary = _T("--MULTI-PARTS-FORM-DATA-BOUNDARY-"));
143  VOID FreeMultiPartsFormData(PBYTE &pBuffer);
144  DWORD GetMultiPartsFormDataLength();
145  };
146 
147 #endif // #ifndef __GENERIC_HTTP_CLIENT