ReactOS 0.4.15-dev-8052-gc0e3179
CWebService Class Reference

#include <CWebService.h>

Collaboration diagram for CWebService:

Public Member Functions

 CWebService ()
 
 ~CWebService ()
 
void Finish (const char *TestType)
 
void Submit (const char *TestType, CTestInfo *TestInfo)
 

Private Member Functions

PCHAR DoRequest (const string &InputData)
 
void GetTestID (const char *TestType)
 
PCHAR GetSuiteID (const char *TestType, CTestInfo *TestInfo)
 

Private Attributes

HINTERNET m_hInet
 
HINTERNET m_hHTTP
 
HINTERNET m_hHTTPRequest
 
PCHAR m_TestID
 

Detailed Description

Definition at line 8 of file CWebService.h.

Constructor & Destructor Documentation

◆ CWebService()

CWebService::CWebService ( )

Constructs a CWebService object and immediately establishes a connection to the "testman" Web Service.

Definition at line 17 of file CWebService.cpp.

18{
19 /* Zero-initialize variables */
20 m_hHTTP = NULL;
22 m_TestID = NULL;
23
24 /* Establish an internet connection to the "testman" server */
26
27 if(!m_hInet)
28 FATAL("InternetOpenW failed\n");
29
31
32 if(!m_hHTTP)
33 FATAL("InternetConnectW failed\n");
34}
static const WCHAR szHostname[]
Definition: CWebService.cpp:10
static const INTERNET_PORT ServerPort
Definition: CWebService.cpp:11
HINTERNET m_hHTTP
Definition: CWebService.h:12
HINTERNET m_hHTTPRequest
Definition: CWebService.h:13
PCHAR m_TestID
Definition: CWebService.h:14
HINTERNET m_hInet
Definition: CWebService.h:11
#define NULL
Definition: types.h:112
HINTERNET WINAPI InternetConnectW(HINTERNET hInternet, LPCWSTR lpszServerName, INTERNET_PORT nServerPort, LPCWSTR lpszUserName, LPCWSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:1258
HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType, LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
Definition: internet.c:979
#define FATAL(Message)
Definition: precomp.h:57
#define L(x)
Definition: ntvdm.h:50
#define INTERNET_OPEN_TYPE_PRECONFIG
Definition: wininet.h:521
#define INTERNET_SERVICE_HTTP
Definition: wininet.h:562

◆ ~CWebService()

CWebService::~CWebService ( )

Destructs a CWebService object and closes all connections to the Web Service.

Definition at line 39 of file CWebService.cpp.

40{
41 if(m_hInet)
43
44 if(m_hHTTP)
46
49
50 if(m_TestID)
51 delete m_TestID;
52}
BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
Definition: internet.c:1414

Member Function Documentation

◆ DoRequest()

PCHAR CWebService::DoRequest ( const string InputData)
private

Sends data to the Web Service.

Parameters
InputDataA std::string containing all the data, which is going to be submitted as HTTP POST data.
Returns
Returns a pointer to a char array containing the data received from the Web Service. The caller needs to free that pointer.

Definition at line 65 of file CWebService.cpp.

66{
67 const WCHAR szHeaders[] = L"Content-Type: application/x-www-form-urlencoded";
68
71
72 /* Post our test results to the web service */
74
76 FATAL("HttpOpenRequestW failed\n");
77
78 Data.reset(new char[InputData.size() + 1]);
79 strcpy(Data, InputData.c_str());
80
81 if(!HttpSendRequestW(m_hHTTPRequest, szHeaders, lstrlenW(szHeaders), Data, (DWORD)InputData.size()))
82 FATAL("HttpSendRequestW failed\n");
83
84 /* Get the response */
86 FATAL("InternetQueryDataAvailable failed\n");
87
88 Data.reset(new char[DataLength + 1]);
89
91 FATAL("InternetReadFile failed\n");
92
93 Data[DataLength] = 0;
94
95 return Data.release();
96}
static const WCHAR szServerFile[]
Definition: CWebService.cpp:12
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
_In_ ULONG _In_opt_ WDFREQUEST _In_opt_ PVOID _In_ size_t _In_ PVOID _In_ size_t _Out_ size_t * DataLength
Definition: cdrom.h:1444
const _CharT * c_str() const
Definition: _string.h:949
size_type size() const
Definition: _string.h:400
#define lstrlenW
Definition: compat.h:750
BOOL WINAPI HttpSendRequestW(HINTERNET hHttpRequest, LPCWSTR lpszHeaders, DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength)
Definition: http.c:5595
HINTERNET WINAPI HttpOpenRequestW(HINTERNET hHttpSession, LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion, LPCWSTR lpszReferrer, LPCWSTR *lpszAcceptTypes, DWORD dwFlags, DWORD_PTR dwContext)
Definition: http.c:3469
BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer, DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
Definition: internet.c:2154
BOOL WINAPI InternetQueryDataAvailable(HINTERNET hFile, LPDWORD lpdwNumberOfBytesAvailable, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:3959
unsigned long DWORD
Definition: ntddk_ex.h:95
#define INTERNET_FLAG_RELOAD
Definition: wininet.h:61
#define INTERNET_FLAG_NO_COOKIES
Definition: wininet.h:75
#define INTERNET_FLAG_NO_CACHE_WRITE
Definition: wininet.h:66
#define INTERNET_FLAG_SECURE
Definition: wininet.h:71
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by Finish(), GetSuiteID(), GetTestID(), and Submit().

◆ Finish()

void CWebService::Finish ( const char TestType)

Interface to other classes for finishing this test run

Parameters
TestTypeConstant pointer to a char array containing the test type to be run (i.e. "wine")

Definition at line 105 of file CWebService.cpp.

106{
108 string Data;
110
111 if (!m_TestID)
112 EXCEPTION("CWebService::Finish was called, but not a single result had been submitted!\n");
113
114 Data = "action=finish";
115 Data += Configuration.GetAuthenticationRequestString();
116 Data += "&testtype=";
117 Data += TestType;
118 Data += "&testid=";
119 Data += m_TestID;
120
121 Response.reset(DoRequest(Data));
122
123 if (strcmp(Response, "OK"))
124 {
125 ss << "When finishing the test run, the server responded:" << endl << Response << endl;
127 }
128}
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
PCHAR DoRequest(const string &InputData)
Definition: CWebService.cpp:65
#define ss
Definition: i386-dis.c:441
#define SSEXCEPTION
Definition: precomp.h:58
#define EXCEPTION(Message)
Definition: precomp.h:56
Definition: ncftp.h:89
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_INTERRUPT_CONFIG Configuration
Definition: wdfinterrupt.h:374

◆ GetSuiteID()

PCHAR CWebService::GetSuiteID ( const char TestType,
CTestInfo TestInfo 
)
private

Gets a Suite ID from the Web Service for this module/test combination.

Parameters
TestTypeConstant pointer to a char array containing the test type to be run (i.e. "wine")
TestInfoPointer to a CTestInfo object containing information about the test
Returns
Returns a pointer to a char array containing the Suite ID received from the Web Service. The caller needs to free that pointer.

Definition at line 179 of file CWebService.cpp.

180{
181 auto_array_ptr<char> SuiteID;
182 string Data;
183
184 Data = "action=getsuiteid";
185 Data += Configuration.GetAuthenticationRequestString();
186 Data += "&testtype=";
187 Data += TestType;
188 Data += "&module=";
189 Data += TestInfo->Module;
190 Data += "&test=";
191 Data += TestInfo->Test;
192
193 SuiteID.reset(DoRequest(Data));
194
195 /* Verify that this is really a number */
196 if(!IsNumber(SuiteID))
197 {
199
200 ss << "Expected Suite ID, but received:" << endl << SuiteID << endl;
202 }
203
204 return SuiteID.release();
205}
string Module
Definition: CTestInfo.h:12
string Test
Definition: CTestInfo.h:13
Type * release()
void reset(Type *Ptr=0)
bool IsNumber(const char *Input)
Definition: tools.cpp:74

Referenced by Submit().

◆ GetTestID()

void CWebService::GetTestID ( const char TestType)
private

Requests a Test ID from the Web Service for our test run.

Parameters
TestTypeConstant pointer to a char array containing the test type to be run (i.e. "wine")

Definition at line 137 of file CWebService.cpp.

138{
139 string Data;
140
141 Data = "action=gettestid";
142 Data += Configuration.GetAuthenticationRequestString();
143 Data += Configuration.GetSystemInfoRequestString();
144 Data += "&testtype=";
145 Data += TestType;
146
147 if(!Configuration.GetComment().empty())
148 {
149 Data += "&comment=";
150 Data += Configuration.GetComment();
151 }
152
154
155 /* Verify that this is really a number */
156 if(!IsNumber(m_TestID))
157 {
159
160 ss << "Expected Test ID, but received:" << endl << m_TestID << endl;
162 }
163}

Referenced by Submit().

◆ Submit()

void CWebService::Submit ( const char TestType,
CTestInfo TestInfo 
)

Interface to other classes for submitting a result of one test

Parameters
TestTypeConstant pointer to a char array containing the test type to be run (i.e. "wine")
TestInfoPointer to a CTestInfo object containing information about the test

Definition at line 217 of file CWebService.cpp.

218{
220 auto_array_ptr<char> SuiteID;
221 string Data;
223
224 if(!m_TestID)
225 GetTestID(TestType);
226
227 SuiteID.reset(GetSuiteID(TestType, TestInfo));
228
229 Data = "action=submit";
230 Data += Configuration.GetAuthenticationRequestString();
231 Data += "&testtype=";
232 Data += TestType;
233 Data += "&testid=";
234 Data += m_TestID;
235 Data += "&suiteid=";
236 Data += SuiteID;
237 Data += "&log=";
238 Data += EscapeString(TestInfo->Log);
239
240 Response.reset(DoRequest(Data));
241
242 if (strcmp(Response, "OK"))
243 {
244 ss << "When submitting the result, the server responded:" << endl << Response << endl;
246 }
247}
string Log
Definition: CTestInfo.h:14
void GetTestID(const char *TestType)
PCHAR GetSuiteID(const char *TestType, CTestInfo *TestInfo)
string EscapeString(const char *Input)
Definition: tools.cpp:24

Member Data Documentation

◆ m_hHTTP

HINTERNET CWebService::m_hHTTP
private

Definition at line 12 of file CWebService.h.

Referenced by CWebService(), DoRequest(), and ~CWebService().

◆ m_hHTTPRequest

HINTERNET CWebService::m_hHTTPRequest
private

Definition at line 13 of file CWebService.h.

Referenced by CWebService(), DoRequest(), and ~CWebService().

◆ m_hInet

HINTERNET CWebService::m_hInet
private

Definition at line 11 of file CWebService.h.

Referenced by CWebService(), and ~CWebService().

◆ m_TestID

PCHAR CWebService::m_TestID
private

Definition at line 14 of file CWebService.h.

Referenced by CWebService(), Finish(), GetTestID(), Submit(), and ~CWebService().


The documentation for this class was generated from the following files: