ReactOS  0.4.15-dev-425-gc40b086
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 }
#define FATAL(Message)
Definition: precomp.h:57
static const INTERNET_PORT ServerPort
Definition: CWebService.cpp:11
HINTERNET m_hHTTPRequest
Definition: CWebService.h:13
static const WCHAR szHostname[]
Definition: CWebService.cpp:10
HINTERNET m_hInet
Definition: CWebService.h:11
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1250
HINTERNET m_hHTTP
Definition: CWebService.h:12
PCHAR m_TestID
Definition: CWebService.h:14
#define INTERNET_OPEN_TYPE_PRECONFIG
Definition: wininet.h:521
HINTERNET WINAPI InternetConnectW(HINTERNET hInternet, LPCWSTR lpszServerName, INTERNET_PORT nServerPort, LPCWSTR lpszUserName, LPCWSTR lpszPassword, DWORD dwService, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:1280
HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType, LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
Definition: internet.c:1001
#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 
47  if(m_hHTTPRequest)
49 
50  if(m_TestID)
51  delete m_TestID;
52 }
HINTERNET m_hHTTPRequest
Definition: CWebService.h:13
BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
Definition: internet.c:1436
HINTERNET m_hInet
Definition: CWebService.h:11
HINTERNET m_hHTTP
Definition: CWebService.h:12
PCHAR m_TestID
Definition: CWebService.h:14

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 
75  if(!m_hHTTPRequest)
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 }
#define FATAL(Message)
Definition: precomp.h:57
#define INTERNET_FLAG_NO_CACHE_WRITE
Definition: wininet.h:66
#define INTERNET_FLAG_SECURE
Definition: wininet.h:71
#define INTERNET_FLAG_RELOAD
Definition: wininet.h:61
HINTERNET m_hHTTPRequest
Definition: CWebService.h:13
#define lstrlenW
Definition: compat.h:416
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI InternetQueryDataAvailable(HINTERNET hFile, LPDWORD lpdwNumberOfBytesAvailable, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:3842
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
BOOL WINAPI HttpSendRequestW(HINTERNET hHttpRequest, LPCWSTR lpszHeaders, DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength)
Definition: http.c:5631
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR szServerFile[]
Definition: CWebService.cpp:12
static const WCHAR L[]
Definition: oid.c:1250
HINTERNET m_hHTTP
Definition: CWebService.h:12
BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer, DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
Definition: internet.c:2174
#define INTERNET_FLAG_NO_COOKIES
Definition: wininet.h:75
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
HINTERNET WINAPI HttpOpenRequestW(HINTERNET hHttpSession, LPCWSTR lpszVerb, LPCWSTR lpszObjectName, LPCWSTR lpszVersion, LPCWSTR lpszReferrer, LPCWSTR *lpszAcceptTypes, DWORD dwFlags, DWORD_PTR dwContext)
Definition: http.c:3481
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG DataLength
Definition: hidpi.h:333

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";
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;
126  SSEXCEPTION;
127  }
128 }
PCHAR DoRequest(const string &InputData)
Definition: CWebService.cpp:65
const string & GetAuthenticationRequestString() const
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
#define EXCEPTION(Message)
Definition: precomp.h:56
Definition: ncftp.h:89
CConfiguration Configuration
Definition: main.cpp:11
#define SSEXCEPTION
Definition: precomp.h:58
PCHAR m_TestID
Definition: CWebService.h:14
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
struct Response Response
#define ss
Definition: i386-dis.c:432

Referenced by CWineTest::Run().

◆ 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";
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;
201  SSEXCEPTION;
202  }
203 
204  return SuiteID.release();
205 }
PCHAR DoRequest(const string &InputData)
Definition: CWebService.cpp:65
const string & GetAuthenticationRequestString() const
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
Type * release()
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
void reset(Type *Ptr=0)
string Module
Definition: CTestInfo.h:12
CConfiguration Configuration
Definition: main.cpp:11
#define SSEXCEPTION
Definition: precomp.h:58
bool IsNumber(const char *Input)
Definition: tools.cpp:74
string Test
Definition: CTestInfo.h:13
#define ss
Definition: i386-dis.c:432

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";
144  Data += "&testtype=";
145  Data += TestType;
146 
147  if(!Configuration.GetComment().empty())
148  {
149  Data += "&comment=";
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;
161  SSEXCEPTION;
162  }
163 }
PCHAR DoRequest(const string &InputData)
Definition: CWebService.cpp:65
const string & GetAuthenticationRequestString() const
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
const string & GetSystemInfoRequestString() const
const string & GetComment() const
CConfiguration Configuration
Definition: main.cpp:11
#define SSEXCEPTION
Definition: precomp.h:58
PCHAR m_TestID
Definition: CWebService.h:14
bool IsNumber(const char *Input)
Definition: tools.cpp:74
#define ss
Definition: i386-dis.c:432

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";
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;
245  SSEXCEPTION;
246  }
247 }
PCHAR DoRequest(const string &InputData)
Definition: CWebService.cpp:65
const string & GetAuthenticationRequestString() const
void GetTestID(const char *TestType)
string Log
Definition: CTestInfo.h:14
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
void reset(Type *Ptr=0)
string EscapeString(const char *Input)
Definition: tools.cpp:24
Definition: ncftp.h:89
CConfiguration Configuration
Definition: main.cpp:11
#define SSEXCEPTION
Definition: precomp.h:58
PCHAR m_TestID
Definition: CWebService.h:14
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
struct Response Response
PCHAR GetSuiteID(const char *TestType, CTestInfo *TestInfo)
#define ss
Definition: i386-dis.c:432

Referenced by CWineTest::Run().

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: