ReactOS 0.4.15-dev-7942-gd23573b
CWebService.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Automatic Testing Utility
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Class implementing the interface to the "testman" Web Service
5 * COPYRIGHT: Copyright 2009-2020 Colin Finck (colin@reactos.org)
6 */
7
8#include "precomp.h"
9
10static const WCHAR szHostname[] = L"reactos.org";
11static const INTERNET_PORT ServerPort = 8443;
12static const WCHAR szServerFile[] = L"testman/webservice/";
13
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}
35
40{
41 if(m_hInet)
43
44 if(m_hHTTP)
46
49
50 if(m_TestID)
51 delete m_TestID;
52}
53
65CWebService::DoRequest(const string& InputData)
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}
97
104void
105CWebService::Finish(const char* TestType)
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}
129
136void
137CWebService::GetTestID(const char* TestType)
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}
164
178PCHAR
179CWebService::GetSuiteID(const char* TestType, CTestInfo* TestInfo)
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}
206
216void
217CWebService::Submit(const char* TestType, CTestInfo* TestInfo)
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}
static const WCHAR szHostname[]
Definition: CWebService.cpp:10
static const WCHAR szServerFile[]
Definition: CWebService.cpp:12
static const INTERNET_PORT ServerPort
Definition: CWebService.cpp:11
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
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
string Log
Definition: CTestInfo.h:14
string Module
Definition: CTestInfo.h:12
string Test
Definition: CTestInfo.h:13
void GetTestID(const char *TestType)
HINTERNET m_hHTTP
Definition: CWebService.h:12
void Finish(const char *TestType)
HINTERNET m_hHTTPRequest
Definition: CWebService.h:13
void Submit(const char *TestType, CTestInfo *TestInfo)
PCHAR GetSuiteID(const char *TestType, CTestInfo *TestInfo)
PCHAR m_TestID
Definition: CWebService.h:14
HINTERNET m_hInet
Definition: CWebService.h:11
PCHAR DoRequest(const string &InputData)
Definition: CWebService.cpp:65
Type * release()
void reset(Type *Ptr=0)
#define NULL
Definition: types.h:112
#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 InternetCloseHandle(HINTERNET hInternet)
Definition: internet.c:1414
BOOL WINAPI InternetQueryDataAvailable(HINTERNET hFile, LPDWORD lpdwNumberOfBytesAvailable, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:3959
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
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ss
Definition: i386-dis.c:441
#define SSEXCEPTION
Definition: precomp.h:58
#define EXCEPTION(Message)
Definition: precomp.h:56
bool IsNumber(const char *Input)
Definition: tools.cpp:74
string EscapeString(const char *Input)
Definition: tools.cpp:24
#define FATAL(Message)
Definition: precomp.h:57
#define L(x)
Definition: ntvdm.h:50
Definition: ncftp.h:89
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_INTERRUPT_CONFIG Configuration
Definition: wdfinterrupt.h:374
WORD INTERNET_PORT
Definition: winhttp.h:38
#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
#define INTERNET_OPEN_TYPE_PRECONFIG
Definition: wininet.h:521
#define INTERNET_SERVICE_HTTP
Definition: wininet.h:562
__wchar_t WCHAR
Definition: xmlstorage.h:180