STDMETHODIMP CMKSDataFilter::CompleteAsyncIO(BOOL fSuccess,
DWORD Win32ErrorCode,
IFWXIOBuffer * pIOBuffer,
UserContextType UserData, //Enum-Variable Direction
LPSOCKADDR ExternalAddress,
INT ExternalAddressLength)
{
// We did not ask for notifications on completion of send
ATLASSERT((UserData == ocReadFromInternal) ||
(UserData == ocReadFromExternal));
//--------------------------------------------------------------------------------------
char *pchDataBuffer = NULL;//Temporary Buffer to store current data
//--------------------------------------------------------------------------------------
HRESULT hr; //Used for checking return values
DBGTRACE("MKSDataFilter::CompleteAsyncIO\n");
// Handle failures on receive
if ((!fSuccess) || (pIOBuffer == NULL)) {
DBGTRACE("Exit Error(CompleteAsyncIO! Error code is :%d\n",Win32ErrorCode);
CloseSockets(true);
return S_OK;
}
// Dump the data and drive the data-pump
BYTE* pBuffer = NULL;
DWORD dwBuffSize = 0;
//Gets the actual data from the memory buffer, and the actual size (not the allocated size) of the buffer.
hr = pIOBuffer->GetBufferAndSize(&pBuffer,&dwBuffSize);
//If the buffer exists,
if (SUCCEEDED(hr) && (dwBuffSize > 0))
{
//-------------------------------------------
Lock();
CComPtr<CMKSPerRulePolicy> spPerRulePolicy(m_spPerRulePolicy);
bool fEnableDump = (spPerRulePolicy != NULL) ? spPerRulePolicy->EnableDump() : false;
Unlock();
//--------------------------------------------------
//Transmission of data from internal-> external / external-> internal
if (UserData == ocReadFromInternal)
{
hr = WriteToExternal(pIOBuffer);
if SUCCEEDED(hr)
{
hr = ReadFromInternal();
}
}
else
{
hr = WriteToInternal(pIOBuffer);
if (SUCCEEDED(hr))
{
hr = ReadFromExternal();
}
}
if (FAILED(hr))
{
// We close the two sockets on any failure
CloseSockets(true);
}
//-----------------------------------------------------
DBGTRACE("Create Temparery buffer\n\n");
//Create a temparery buffer
pchDataBuffer= new char[dwBuffSize+1];
if(pchDataBuffer==NULL)
{
hr = E_OUTOFMEMORY;
delete [] pchDataBuffer;
if (FAILED(hr))
CloseSockets(true);
return hr;
}
//Copy the data to the buffer
memcpy(pchDataBuffer,pBuffer,dwBuffSize);
//Add \0 at the end of the buffer so it can be manipulated
//as a string
pchDataBuffer[dwBuffSize]='\0';
//Set pointer to make the work with this buffer easier
//pchStart = pchDataBuffer;
//pchLast = pchStart + dwBuffSize-1;
//pchCurrent = pchStart;
if (strstr(pchDataBuffer,"beep"))
{
DBGTRACE("Java Client\n\n");
if (fEnableDump)//Looging Enable btw. or activ
{
// Dump data from IOBuffer in hex & text formats, with direction flag
// and source/dest information.
(void) DumpBuffer(pIOBuffer, (UserData == ocReadFromInternal),ocJavaClient);
}
}
else if (strstr(pchDataBuffer,"HTTP"))
{
DBGTRACE("Browser client\n\n");
if (fEnableDump)//Looging Enable btw. or activ
{
// Dump data from IOBuffer in hex & text formats, with direction flag
// and source/dest information.
(void) DumpBuffer(pIOBuffer, (UserData == ocReadFromInternal),ocBrowserClient);
}
}
else
{
DBGTRACE("Keyword not found\n\n");
if (fEnableDump)//Looging Enable btw. or activ
{
// Dump data from IOBuffer in hex & text formats, with direction flag
// and source/dest information.
(void) DumpBuffer(pIOBuffer, (UserData == ocReadFromInternal),ocNoClient);
}
}
//--------------------------------------------------
}
else
{
// If we got a zero sized buffer, than socket has no
// more data and we should end the data pump and delete the
// temporary Buffer
delete [] pchDataBuffer;
CloseSockets(false);
}
return S_OK;
}