{
const WCHAR Headers[] = L"Content-Type: application/x-www-form-urlencoded";
- HINTERNET hHTTP;
- HINTERNET hHTTPRequest;
- HINTERNET hInet;
+ BOOL ReturnValue = FALSE;
+ HINTERNET hHTTP = NULL;
+ HINTERNET hHTTPRequest = NULL;
+ HINTERNET hInet = NULL;
/* Establish an internet connection to the "testman" server */
hInet = InternetOpenW(L"rosautotest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if(!hInet)
{
StringOut("InternetOpenW failed\n");
- return FALSE;
+ goto Cleanup;
}
hHTTP = InternetConnectW(hInet, SERVER_HOSTNAME, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if(!hHTTP)
{
StringOut("InternetConnectW failed\n");
- return FALSE;
+ goto Cleanup;
}
/* Post our test results to the web service */
if(!hHTTPRequest)
{
StringOut("HttpOpenRequestW failed\n");
- return FALSE;
+ goto Cleanup;
}
if(!HttpSendRequestW(hHTTPRequest, Headers, wcslen(Headers), *Data, *DataLength))
{
StringOut("HttpSendRequestW failed\n");
- return FALSE;
+ goto Cleanup;
}
HeapFree(hProcessHeap, 0, *Data);
+ *Data = NULL;
/* Get the response */
if(!InternetQueryDataAvailable(hHTTPRequest, DataLength, 0, 0))
{
StringOut("InternetQueryDataAvailable failed\n");
- return FALSE;
+ goto Cleanup;
}
*Data = HeapAlloc(hProcessHeap, 0, *DataLength + 1);
if(!InternetReadFile(hHTTPRequest, *Data, *DataLength, DataLength))
{
StringOut("InternetReadFile failed\n");
- return FALSE;
+ goto Cleanup;
}
(*Data)[*DataLength] = 0;
+ ReturnValue = TRUE;
- InternetCloseHandle(hHTTPRequest);
- InternetCloseHandle(hHTTP);
- InternetCloseHandle(hInet);
+Cleanup:
+ if(hHTTPRequest)
+ InternetCloseHandle(hHTTPRequest);
- return TRUE;
+ if(hHTTP)
+ InternetCloseHandle(hHTTP);
+
+ if(hInet)
+ InternetCloseHandle(hInet);
+
+ return ReturnValue;
}
/**
*
* @return
* Returns the Test ID as a CHAR array if successful or NULL otherwise.
+ * The caller needs to HeapFree the returned pointer in case of success.
*/
PCHAR
GetTestID(TESTTYPES TestType)
{
const CHAR GetTestIDAction[] = "gettestid";
+ const CHAR CommentProp[] = "&comment=";
DWORD DataLength;
PCHAR Data;
+ PCHAR ReturnValue = NULL;
/* Build the full request string */
DataLength = sizeof(ActionProp) - 1 + sizeof(GetTestIDAction) - 1;
DataLength += strlen(AuthenticationRequestString) + strlen(SystemInfoRequestString);
+
+ if(AppOptions.Comment)
+ DataLength += sizeof(CommentProp) - 1 + strlen(AppOptions.Comment);
+
DataLength += sizeof(TestTypeProp) - 1;
switch(TestType)
strcat(Data, GetTestIDAction);
strcat(Data, AuthenticationRequestString);
strcat(Data, SystemInfoRequestString);
+
+ if(AppOptions.Comment)
+ {
+ strcat(Data, CommentProp);
+ strcat(Data, AppOptions.Comment);
+ }
+
strcat(Data, TestTypeProp);
switch(TestType)
}
if(!IntDoRequest(&Data, &DataLength))
- return NULL;
+ goto Cleanup;
/* Verify that this is really a number */
if(!IsNumber(Data))
{
StringOut("Expected Test ID, but received:\n");
StringOut(Data);
- HeapFree(hProcessHeap, 0, Data);
- return NULL;
+ StringOut("\n");
+ goto Cleanup;
}
- return Data;
+ ReturnValue = Data;
+
+Cleanup:
+ if(Data && ReturnValue != Data)
+ HeapFree(hProcessHeap, 0, Data);
+
+ return ReturnValue;
}
/**
*
* @return
* Returns the Suite ID as a CHAR array if successful or NULL otherwise.
+ * The caller needs to HeapFree the returned pointer in case of success.
*/
PCHAR
GetSuiteID(TESTTYPES TestType, const PVOID TestData)
DWORD DataLength;
PCHAR Data;
+ PCHAR ReturnValue = NULL;
PWINE_GETSUITEID_DATA WineData;
DataLength = sizeof(ActionProp) - 1 + sizeof(GetSuiteIDAction) - 1;
}
if(!IntDoRequest(&Data, &DataLength))
- return NULL;
+ goto Cleanup;
/* Verify that this is really a number */
if(!IsNumber(Data))
{
StringOut("Expected Suite ID, but received:\n");
StringOut(Data);
- HeapFree(hProcessHeap, 0, Data);
- return NULL;
+ StringOut("\n");
+ goto Cleanup;
}
- return Data;
+ ReturnValue = Data;
+
+Cleanup:
+ if(Data && ReturnValue != Data)
+ HeapFree(hProcessHeap, 0, Data);
+
+ return ReturnValue;
}
/**
const CHAR SuiteIDProp[] = "&suiteid=";
const CHAR LogProp[] = "&log=";
+ BOOL ReturnValue = FALSE;
DWORD DataLength;
PCHAR Data;
PCHAR pData;
/* Send all the stuff */
if(!IntDoRequest(&Data, &DataLength))
- return FALSE;
+ goto Cleanup;
/* Output the response */
StringOut("The server responded:\n");
StringOut("\n");
if(!strcmp(Data, "OK"))
- return TRUE;
+ ReturnValue = TRUE;
+
+Cleanup:
+ if(Data)
+ HeapFree(hProcessHeap, 0, Data);
- return FALSE;
+ return ReturnValue;
}
/**
{
const CHAR FinishAction[] = "finish";
+ BOOL ReturnValue = FALSE;
DWORD DataLength;
PCHAR Data;
PGENERAL_FINISH_DATA GeneralData;
}
if(!IntDoRequest(&Data, &DataLength))
- return FALSE;
+ goto Cleanup;
if(!strcmp(Data, "OK"))
- return TRUE;
+ ReturnValue = TRUE;
+
+Cleanup:
+ if(Data)
+ HeapFree(hProcessHeap, 0, Data);
- return FALSE;
+ return ReturnValue;
}