Microsoft Internet Security and Acceleration Server 2000

Add the Definition and Implementation of IFWXSessionFilter Methods

Now add the code to define and implement the IFWXSessionFilter methods. The methods are:

To define and implement the IFWXSessionFilter methods

  1. Add the IFWXSessionFilter Method definitions:

    Use wspfwext.h to get the prototypes of the methods of IFWXSessionFilter and add them to fwxsessionfilter.h.

    Add the declaration of the methods to fwxsessionfilter.h, in the public section of the CFWXSessionFilter. The code should be:

    HRESULT STDMETHODCALLTYPE FirewallEventHandler( 
    		/* [ref][in] */ const FwxFirewallEvent __RPC_FAR *pFirewallEvent);
    
    HRESULT STDMETHODCALLTYPE Detach( void);
    
  2. Add the IFWXSessionFilter method implementations:

    Copy the prototypes of the IFWXSessionFilter methods from wspfwext.h, and add them to fwxsessionfilter.cpp with implementation code.

    Start with a simple implementation in FWXSessionFilter.cpp; for example,

    return E_NOTIMPL;
    

    The implementation code should look like this:

    HRESULT STDMETHODCALLTYPE CFWXSessionFilter::FirewallEventHandler( 
    		/* [ref][in] */ const FwxFirewallEvent __RPC_FAR *pFirewallEvent)
    {
    	return E_NOTIMPL;
    
    }
    
    HRESULT STDMETHODCALLTYPE CFWXSessionFilter::Detach( void)
    {
    	return E_NOTIMPL;
    
    }
    
  3. Build the project.
  4. Implement IFWXSessionFilter::FwxFirewallEventHandler:

    Add the IFWXSessionFilter::FwxFirewallEventHandler implementation to FWXSessionFilter.cpp, in place of the simple implementation:

    HRESULT STDMETHODCALLTYPE CFWXSessionFilter::FirewallEventHandler( 
    	/* [ref][in] */ const FwxFirewallEvent __RPC_FAR *pFirewallEvent)
    {
    	HRESULT hr = S_OK;
     
    	switch (pFirewallEvent->EventType)
    	{
    	// Bind request for TCP sockets
    	case fwx_Bind_Tcp:
    		OutputDebugString ("IFWXSessionFilter::FirewallEventHandler – fwx_Bind_Tcp\n");
    		OutputDebugString (FilterAccessString(
    						 pFirewallEvent->
    						 Parameters.Bind.FilterAccess));
     
     
    		break;
    	
    	// Inbound connection on a listening TCP socket
    	case fwx_AcceptedConnection:
    		OutputDebugString ("IFWXSessionFilter::FirewallEventHandler – fwx_AcceptedConnection\n");
    		OutputDebugString (FilterAccessString(pFirewallEvent->
     Parameters.Accept.FilterAccess));
    		// The code for attaching a data filter that will do the actual 
    		//work will be placed here.
    		break;
     
    // Unexpected EventType
    	default:
    	OutputDebugString ("Error - FWXSessionFilter::FirewallEventHandler –Unexpected Event Type\n ");
    		return E_FAIL;
    }
    
    	return  hr;
    }
    

    Also, add the FilterAccessString definition to FWXSessionFilter.cpp, immediately after the #include statements, as follows:

    // This function converts enum value to a corresponding string
    static const char* FilterAccessString (int FwxFilterAccess)
    {
    	switch (FwxFilterAccess)
    	{
    		case FWX_ALLOW:
    			return "Filter Access: FWX_ALLOW\n";
    		case FWX_DENY:
    			return "Filter Access: FWX_DENY\n";
    		case FWX_PASS:
    			return "Filter Access: FWX_PASS\n";
    		case FWX_EMULATE:
    			return "Filter Access: FWX_EMULATE\n";
    }
    	return "Invalid Filter Access";
    }
    
  5. Implement the IFWXSessionFilter::Detach method, in place of the simple implementation:

    Typically, the IFWXSessionFilter::Detach method is used to release references to other objects that must be released when the session ends. In this case, there are none:

    // Detach should return S_OK
    HRESULT STDMETHODCALLTYPE CFWXSessionFilter::Detach( void)
    {
    	return S_OK;
    }
    
  6. Build the project.