Esempio n. 1
0
BOOL CNetMgr::Cleanup()
{_STT();
	// Acquire lock
	CTlLocalLock ll( *this );
	if ( !ll.IsLocked() ) return FALSE;

	BOOL bChanged = FALSE;
	
	// Get the first object
	THList< GUID, CNetCom >::iterator it = NULL;
	while ( ( it = m_lstSession.next( it ) ) != NULL )
	{
		CNetCom* pNc = (*it);

		// Erase this session if invalid
		if ( !pNc || !pNc->IsValid() )
		{
			bChanged = TRUE;

			it = RemoveNode( it );

		} // end if

	} // end while

	return bChanged;
}
Esempio n. 2
0
long CNetCom::NetMsg( LPVOID pData, WPARAM wParam, LPARAM lParam )
{_STT();

	// Get a pointer to the class
	CNetCom *pNc = (CNetCom*)pData;
	if ( pNc == NULL ) return FALSE;

	// Let the instance handle it
	return pNc->OnNetMsg( wParam, lParam );
}
Esempio n. 3
0
long CNetMgr::OnNetMsg(WPARAM wParam, LPARAM lParam, const GUID *pGuid)
{_STT();
	CNetCom *pNc = (CNetCom*)lParam;
	if ( pNc == NULL ) return E_FAIL;

	// Authenticate the connection
	if ( !OnAuthenticate( pNc ) ) return E_FAIL;
	
	// Hook NetCmd messages
	if ( pGuid != NULL && IsEqualGUID( NetCmd::IID, *pGuid ) )
	{
		// Save network error if any
		if ( pNc->GetNetError() )
			SetNetError( pNc->GetNetError() );

		// Cleanup if node is disconnecting
		// +++ This doesn't work because it causes the calling 
		// class to delete itself.  For now, Cleanup() must be 
		// called from the outside.  This is just to remind me 
		// to come up with something.
//		if ( wParam == NetCmd::efDisconnect ) Cleanup();

	} // end if

	// Check for update request
	if ( ( wParam & CNetMsg::fWantUpdate ) != 0 )
	{	AddUpdateNotification(	pNc->Tx()->GetConnectionId(), pGuid, 
								wParam & CNetMsg::fMask );

	} // end if

	// Check for remove notification command
	if ( ( wParam & CNetMsg::fCancelUpdate ) != 0 )
	{	RemoveUpdateNotification(	pNc->Tx()->GetConnectionId(), pGuid, 
									wParam & CNetMsg::fMask );

		// Don't process this message
		return S_OK;

	} // end if

	// Turn off internal flags
	wParam &= CNetMsg::fCmdMask;
	pNc->SMsg().dwFunction &= CNetMsg::fCmdMask;

	// Pass on the message
	return MMessage( wParam, lParam, pGuid );
}
Esempio n. 4
0
BOOL CNetCmd::vMsg( const GUID *pNode, const GUID *pClass, DWORD dwFunction, CReg *pParams, DWORD dwBuffers, LPVOID *pArgs )
{_STT();
	// Verify we have authority to send this message
	if ( !OnTxAuthenticate( pNode, pClass, dwFunction ) )
		return FALSE;

	// Get destination
	CNetCom *pNc = GetNode( pNode );
	if ( pNc == NULL || !pNc->IsValid() ) 
		return FALSE;

	// Copy message data
	CNetMsg::SMsg msg;
	ZeroMemory( &msg, sizeof( msg ) );
	msg.dwFunction = dwFunction;
	
	// Encode params
	CPipe params;
	if ( pParams ) pParams->SaveRegFile( &params, NULL, "" );

	// Calculate the total size needed
	DWORD dwBlocks = 3; if ( params.GetBufferSize() ) dwBlocks++;
	DWORD dwTotalSize = ( sizeof( CNetMsg::SAddress ) * 2 ) +  
						sizeof( CNetMsg::SMsg ) +
						params.GetBufferSize();

	DWORD i;
	LPVOID *ptrExtra = pArgs;
	for ( i = 0; i < dwBuffers; i++ )
	{	RULIB_TRY 
		{	DWORD	dwType = *(LPDWORD)( ptrExtra );
			LPBYTE	pPtr = *(LPBYTE*)( ptrExtra + 1 );
			DWORD 	dwSize = *(LPDWORD)( ptrExtra + 2 );
			dwBlocks++;

			// Zero means NULL terminated
			if ( dwSize == 0 && pPtr != NULL ) dwSize = strlen( (LPCTSTR)pPtr );

			dwTotalSize += dwSize;

			ptrExtra += 3;
		} // end try
		RULIB_CATCH_ALL { return FALSE; }
	} // end for

	// Lock the tx buffer
	CTlLocalLock ll( *pNc->Tx() );
	if ( !ll.IsLocked() ) return FALSE;

	// Initialze the packet
	pNc->Tx()->InitPacket( NETMSG_PACKETTYPE, dwBlocks, dwTotalSize );

	CNetMsg::SAddress addr;

	// Destination information	
	memcpy( &addr.guidNode, pNc->Rx()->Address(), sizeof( GUID ) );
	if ( pClass ) memcpy( &addr.guidClass, pClass, sizeof( GUID ) );
	else ZeroMemory( &addr.guidClass, sizeof( addr.guidClass ) );
	pNc->Tx()->AddPacketData( NETMSGDT_DSTADDRESS, &addr, sizeof( addr ) );
	
	// Source information	
	memcpy( &addr.guidNode, pNc->Tx()->Address(), sizeof( GUID ) );
	ZeroMemory( &addr.guidClass, sizeof( addr.guidClass ) );
	pNc->Tx()->AddPacketData( NETMSGDT_SRCADDRESS, &addr, sizeof( addr ) );

	// Add message
	pNc->Tx()->AddPacketData( NETMSGDT_MSG, &msg, sizeof( msg ) );

	// Add params if any
	if ( params.GetBufferSize() )
		pNc->Tx()->AddPacketData( NETMSGDT_PARAMS, params.GetBuffer(), params.GetBufferSize() );

	// Add the data to the packet
	ptrExtra = pArgs;
	for ( i = 0; i < dwBuffers; i++ )
	{	RULIB_TRY 
		{	DWORD	dwType = *(LPDWORD)( ptrExtra );
			LPBYTE	pPtr = *(LPBYTE*)( ptrExtra + 1 );
			DWORD 	dwSize = *(LPDWORD)( ptrExtra + 2 );

			// Zero means NULL terminated
			if ( dwSize == 0 && pPtr != NULL ) dwSize = strlen( (LPCTSTR)pPtr );

			// Add packet data block
			pNc->Tx()->AddPacketData( dwType, pPtr, dwSize );

			ptrExtra += 3;
		} // end try
		RULIB_CATCH_ALL { return FALSE; }
	} // end for

	// Make it official
	return pNc->Tx()->EndPacket();
}