Changes due to continue development. Switched to using calls to a single Servlet and telling it what method to execute. The test application was also updated to be more flexible.
This commit is contained in:
@@ -25,23 +25,139 @@
|
||||
#include <windows.h>
|
||||
#include "casa_c_authtoken.h"
|
||||
|
||||
// Globals
|
||||
char usageString[] = "usage: test -a serverAddress -p serverPort [-h]\n";
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
char *pServerAddress = NULL;
|
||||
int serverPort = 0;
|
||||
BOOLEAN execHttpTest = FALSE;
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* dtoul()
|
||||
*
|
||||
***********************************************************************/
|
||||
int
|
||||
dtoul(
|
||||
IN char *cp,
|
||||
IN int len)
|
||||
{
|
||||
int retStatus;
|
||||
char authToken[4096];
|
||||
int authTokenLen = sizeof(authToken);
|
||||
int n = 0;
|
||||
int i;
|
||||
|
||||
// Now lets obtain a token for our service
|
||||
retStatus = ObtainAuthToken("testService@137.65.132.44", authToken, &authTokenLen);
|
||||
if (retStatus)
|
||||
printf("ObtainAuthToken failed with status %d\n", retStatus);
|
||||
for (i = 0; i < len; i++, cp++)
|
||||
{
|
||||
// Verify that we are dealing with a valid digit
|
||||
if (*cp >= '0' && *cp <= '9')
|
||||
{
|
||||
n = 10 * n + (*cp - '0');
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-dtoul- Found invalid digit\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* EncodeData()
|
||||
*
|
||||
***********************************************************************/
|
||||
int
|
||||
EncodeData(
|
||||
IN const void *pData,
|
||||
IN const int32_t dataLen,
|
||||
INOUT char **ppEncodedData,
|
||||
INOUT int32_t *pEncodedDataLen)
|
||||
{
|
||||
int8_t base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
int retStatus;
|
||||
int encodedSize;
|
||||
|
||||
char *pTmp;
|
||||
|
||||
// Determine the encoded size and allocate a buffer to hold the encoded data
|
||||
encodedSize = ((dataLen * 4 + 2) / 3) - (dataLen % 3 ) + 4;
|
||||
pTmp = (char*) malloc(encodedSize);
|
||||
*ppEncodedData = pTmp;
|
||||
if (*ppEncodedData)
|
||||
{
|
||||
uint8_t *pOut, *pIn;
|
||||
int i;
|
||||
|
||||
// Setup pointers to move through the buffers
|
||||
pIn = (uint8_t*) pData;
|
||||
pOut = (uint8_t*) *ppEncodedData;
|
||||
|
||||
// Perform the encoding
|
||||
for (i = 0; i < dataLen - 2; i += 3)
|
||||
{
|
||||
*pOut++ = base64[(pIn[i] >> 2) & 0x3F];
|
||||
*pOut++ = base64[((pIn[i] & 0x3) << 4) |
|
||||
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
|
||||
*pOut++ = base64[((pIn[i + 1] & 0xF) << 2) |
|
||||
((int32_t)(pIn[i + 2] & 0xC0) >> 6)];
|
||||
*pOut++ = base64[pIn[i + 2] & 0x3F];
|
||||
}
|
||||
if (i < dataLen)
|
||||
{
|
||||
*pOut++ = base64[(pIn[i] >> 2) & 0x3F];
|
||||
if (i == (dataLen - 1))
|
||||
{
|
||||
*pOut++ = base64[((pIn[i] & 0x3) << 4)];
|
||||
*pOut++ = '=';
|
||||
}
|
||||
else
|
||||
{
|
||||
*pOut++ = base64[((pIn[i] & 0x3) << 4) |
|
||||
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
|
||||
*pOut++ = base64[((pIn[i + 1] & 0xF) << 2)];
|
||||
}
|
||||
*pOut++ = '=';
|
||||
}
|
||||
*pOut++ = '\0';
|
||||
|
||||
// Return the encoded data length
|
||||
*pEncodedDataLen = (int32_t)(pOut - (uint8_t*)*ppEncodedData);
|
||||
|
||||
// Success
|
||||
retStatus = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-EncodeData- Buffer allocation failure\n");
|
||||
retStatus = -1;
|
||||
}
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* NonHttpTest()
|
||||
*
|
||||
***********************************************************************/
|
||||
void NonHttpTest(void)
|
||||
{
|
||||
CasaStatus retStatus;
|
||||
char authToken[4096];
|
||||
int authTokenLen = sizeof(authToken);
|
||||
|
||||
// Obtain an authentication token for the testService
|
||||
retStatus = ObtainAuthToken("testService", pServerAddress, authToken, &authTokenLen);
|
||||
if (!CASA_SUCCESS(retStatus))
|
||||
{
|
||||
printf("-NonHttpTest- ObtainAuthToken failed with status %d\n", retStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
char serverAddr[] = "137.65.132.44";
|
||||
char *pServerAddress = serverAddr;
|
||||
// int serverPort = htons(4444);
|
||||
int serverPort = 27008;
|
||||
SOCKET sock;
|
||||
struct sockaddr_in localAddr = {0};
|
||||
struct sockaddr_in remoteAddr = {0};
|
||||
@@ -50,8 +166,7 @@ int main(int argc, char* argv[])
|
||||
int winsockStartupResult;
|
||||
WSADATA winsockData;
|
||||
|
||||
//printf("ObtainAuthToken succedded, token = %s\n", authToken);
|
||||
printf("ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
|
||||
printf("-NonHttpTest- ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
|
||||
|
||||
// Send the token to the server
|
||||
//
|
||||
@@ -86,7 +201,6 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
//printf("Found %d addresses\n", numAddressesFound);
|
||||
|
||||
|
||||
// Setup the remote address structure with the lookup results
|
||||
remoteAddr.sin_family = AF_INET;
|
||||
remoteAddr.sin_port = serverPort;
|
||||
@@ -98,19 +212,13 @@ int main(int argc, char* argv[])
|
||||
(struct sockaddr*) &remoteAddr,
|
||||
sizeof(struct sockaddr_in)) == SOCKET_ERROR)
|
||||
{
|
||||
printf("main()- Connection creation failed, error = %d\n", WSAGetLastError());
|
||||
printf("-NonHttpTest- Connection creation failed, error = %d\n", WSAGetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Now the connection is setup, send the credentials to the server as one line.
|
||||
// using our cheesy protocol followed by a hello string.
|
||||
|
||||
// Send the username to the server (including NULL terminator)
|
||||
//send(sock, userName, userNameBufLen, 0);
|
||||
|
||||
// Send new line
|
||||
//send(sock, "\n", 1, MSG_NOSIGNAL);
|
||||
|
||||
//
|
||||
// Send the token to the server (including NULL terminator)
|
||||
send(sock, authToken, (int) strlen(authToken) + 1, 0);
|
||||
|
||||
@@ -129,17 +237,17 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- Unsupported address type returned %08X\n", pLookupResult->h_addrtype);
|
||||
printf("-NonHttpTest- Unsupported address type returned %08X\n", pLookupResult->h_addrtype);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- Lookup for %s failed\n", pServerAddress);
|
||||
printf("-NonHttpTest- Lookup for %s failed\n", pServerAddress);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- Unable to bind socket, error = %d", errno);
|
||||
printf("-NonHttpTest- Unable to bind socket, error = %d", errno);
|
||||
}
|
||||
|
||||
// Close the socket
|
||||
@@ -148,7 +256,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- Unable to open socket, error = %d\n", errno);
|
||||
printf("-NonHttpTest- Unable to open socket, error = %d\n", errno);
|
||||
}
|
||||
|
||||
// Close winsock
|
||||
@@ -156,104 +264,31 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- WSAStartup failed, error = %d\n", winsockStartupResult);
|
||||
printf("-NonHttpTest- WSAStartup failed, error = %d\n", winsockStartupResult);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Enter to exit application\n");
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
int
|
||||
EncodeData(
|
||||
IN const void *pData,
|
||||
IN const int32_t dataLen,
|
||||
INOUT char **ppEncodedData,
|
||||
INOUT int32_t *pEncodedDataLen)
|
||||
{
|
||||
int8_t g_Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
int retStatus;
|
||||
int encodedSize;
|
||||
|
||||
char *pTmp;
|
||||
|
||||
// Determine the encoded size and allocate a buffer to hold the encoded data
|
||||
encodedSize = ((dataLen * 4 + 2) / 3) - (dataLen % 3 ) + 4;
|
||||
pTmp = (char*) malloc(encodedSize);
|
||||
*ppEncodedData = pTmp;
|
||||
if (*ppEncodedData)
|
||||
{
|
||||
uint8_t *pOut, *pIn;
|
||||
int i;
|
||||
|
||||
// Setup pointers to move through the buffers
|
||||
pIn = (uint8_t*) pData;
|
||||
pOut = (uint8_t*) *ppEncodedData;
|
||||
|
||||
// Perform the encoding
|
||||
for (i = 0; i < dataLen - 2; i += 3)
|
||||
{
|
||||
*pOut++ = g_Base64[(pIn[i] >> 2) & 0x3F];
|
||||
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4) |
|
||||
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
|
||||
*pOut++ = g_Base64[((pIn[i + 1] & 0xF) << 2) |
|
||||
((int32_t)(pIn[i + 2] & 0xC0) >> 6)];
|
||||
*pOut++ = g_Base64[pIn[i + 2] & 0x3F];
|
||||
}
|
||||
if (i < dataLen)
|
||||
{
|
||||
*pOut++ = g_Base64[(pIn[i] >> 2) & 0x3F];
|
||||
if (i == (dataLen - 1))
|
||||
{
|
||||
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4)];
|
||||
*pOut++ = '=';
|
||||
}
|
||||
else
|
||||
{
|
||||
*pOut++ = g_Base64[((pIn[i] & 0x3) << 4) |
|
||||
((int32_t)(pIn[i + 1] & 0xF0) >> 4)];
|
||||
*pOut++ = g_Base64[((pIn[i + 1] & 0xF) << 2)];
|
||||
}
|
||||
*pOut++ = '=';
|
||||
}
|
||||
*pOut++ = '\0';
|
||||
|
||||
// Return the encoded data length
|
||||
*pEncodedDataLen = (int32_t)(pOut - (uint8_t*)*ppEncodedData);
|
||||
|
||||
// Success
|
||||
retStatus = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("-EncodeData- Buffer allocation failure\n");
|
||||
|
||||
retStatus = -1;
|
||||
}
|
||||
|
||||
return retStatus;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
/***********************************************************************
|
||||
*
|
||||
* HttpTest()
|
||||
*
|
||||
***********************************************************************/
|
||||
void HttpTest(void)
|
||||
{
|
||||
int retStatus;
|
||||
char authToken[4096];
|
||||
int authTokenLen = sizeof(authToken);
|
||||
CasaStatus retStatus;
|
||||
char authToken[4096];
|
||||
int authTokenLen = sizeof(authToken);
|
||||
|
||||
// Now lets obtain a token for our service
|
||||
retStatus = ObtainAuthToken("testService@137.65.132.44", authToken, &authTokenLen);
|
||||
if (retStatus)
|
||||
printf("ObtainAuthToken failed with status %d\n", retStatus);
|
||||
// Obtain an authentication token for the testService
|
||||
retStatus = ObtainAuthToken("testService", pServerAddress, authToken, &authTokenLen);
|
||||
if (!CASA_SUCCESS(retStatus))
|
||||
{
|
||||
printf("-HttpTest- ObtainAuthToken failed with status %d\n", retStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
char serverAddr[] = "137.65.132.44";
|
||||
char *pServerAddress = serverAddr;
|
||||
// int serverPort = htons(4444);
|
||||
int serverPort = htons(4096);
|
||||
SOCKET sock;
|
||||
struct sockaddr_in localAddr = {0};
|
||||
struct sockaddr_in remoteAddr = {0};
|
||||
@@ -263,7 +298,7 @@ int main(int argc, char* argv[])
|
||||
WSADATA winsockData;
|
||||
|
||||
//printf("ObtainAuthToken succedded, token = %s\n", authToken);
|
||||
printf("ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
|
||||
printf("-HttpTest- ObtainAuthToken succedded, tokenlen = %d\n", authTokenLen);
|
||||
|
||||
// Send the token to the server
|
||||
//
|
||||
@@ -310,7 +345,7 @@ int main(int argc, char* argv[])
|
||||
(struct sockaddr*) &remoteAddr,
|
||||
sizeof(struct sockaddr_in)) == SOCKET_ERROR)
|
||||
{
|
||||
printf("main()- Connection creation failed, error = %d\n", WSAGetLastError());
|
||||
printf("-HttpTest- Connection creation failed, error = %d\n", WSAGetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -346,7 +381,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error encoding credentials\n");
|
||||
printf("-HttpTest- Error encoding credentials\n");
|
||||
}
|
||||
|
||||
// Free the buffer containing the basic credentials
|
||||
@@ -354,7 +389,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Buffer allocation failure\n");
|
||||
printf("-HttpTest- Buffer allocation failure\n");
|
||||
}
|
||||
|
||||
// Shutdown the connection
|
||||
@@ -363,17 +398,17 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- Unsupported address type returned %08X\n", pLookupResult->h_addrtype);
|
||||
printf("-HttpTest- Unsupported address type returned %08X\n", pLookupResult->h_addrtype);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- Lookup for %s failed\n", pServerAddress);
|
||||
printf("-HttpTest- Lookup for %s failed\n", pServerAddress);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- Unable to bind socket, error = %d", errno);
|
||||
printf("-HttpTest- Unable to bind socket, error = %d", errno);
|
||||
}
|
||||
|
||||
// Close the socket
|
||||
@@ -382,7 +417,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- Unable to open socket, error = %d\n", errno);
|
||||
printf("-HttpTest- Unable to open socket, error = %d\n", errno);
|
||||
}
|
||||
|
||||
// Close winsock
|
||||
@@ -390,12 +425,89 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("main()- WSAStartup failed, error = %d\n", winsockStartupResult);
|
||||
printf("-HttpTest- WSAStartup failed, error = %d\n", winsockStartupResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* main()
|
||||
*
|
||||
***********************************************************************/
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Process input parameters
|
||||
int i = 1;
|
||||
while(argv[i] != NULL)
|
||||
{
|
||||
if (stricmp(argv[i], "-a") == 0)
|
||||
{
|
||||
// Server Address option, the next argument should
|
||||
// contain the address.
|
||||
i++;
|
||||
if (argv[i] != NULL)
|
||||
{
|
||||
pServerAddress = argv[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(usageString);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (stricmp(argv[i], "-p") == 0)
|
||||
{
|
||||
// Server port option, the next argument should
|
||||
// contain the port.
|
||||
i++;
|
||||
if (argv[i] != NULL)
|
||||
{
|
||||
serverPort = htons(dtoul(argv[i], strlen(argv[i])));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(usageString);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (stricmp(argv[i], "-h") == 0)
|
||||
{
|
||||
// Perform http test option
|
||||
execHttpTest = TRUE;
|
||||
}
|
||||
|
||||
// Advance to the next argument
|
||||
i++;
|
||||
}
|
||||
|
||||
// Verify that the server address and port were specified
|
||||
if (pServerAddress && serverPort != 0)
|
||||
{
|
||||
// Repeat the test when indicated
|
||||
printf("Press 'Enter' to run test or 'n + Enter' to stop.\n");
|
||||
while(getchar() != 'n')
|
||||
{
|
||||
// Execute the appropriate test
|
||||
if (execHttpTest)
|
||||
{
|
||||
HttpTest();
|
||||
}
|
||||
else
|
||||
{
|
||||
NonHttpTest();
|
||||
}
|
||||
printf("Press 'Enter' to run test or 'n + Enter' to stop.\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(usageString);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Enter to exit application\n");
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
AdditionalDependencies="authtoken.lib ws2_32.lib"
|
||||
OutputFile="$(OutDir)/test.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\client\win32\Debug"
|
||||
AdditionalLibraryDirectories=""C:\Program Files\novell\CASA\lib""
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/test.pdb"
|
||||
SubSystem="1"
|
||||
@@ -44,7 +44,7 @@
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
CommandLine="copy ..\win32\debug\authtoken.dll debug\authtoken.dll"/>
|
||||
CommandLine="copy ..\windows\debug\authtoken.dll debug\authtoken.dll"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
|
||||
Reference in New Issue
Block a user