Blame iis/mymodulefactory.h

Packit 284210
/*
Packit 284210
* ModSecurity for Apache 2.x, http://www.modsecurity.org/
Packit 284210
* Copyright (c) 2004-2013 Trustwave Holdings, Inc. (http://www.trustwave.com/)
Packit 284210
*
Packit 284210
* You may not use this file except in compliance with
Packit 284210
* the License.  You may obtain a copy of the License at
Packit 284210
*
Packit 284210
*     http://www.apache.org/licenses/LICENSE-2.0
Packit 284210
*
Packit 284210
* If any of the files related to licensing are missing or if you have any
Packit 284210
* other questions related to licensing please contact Trustwave Holdings, Inc.
Packit 284210
* directly using the email address security@modsecurity.org.
Packit 284210
*/
Packit 284210

Packit 284210
#ifndef __MODULE_FACTORY_H__
Packit 284210
#define __MODULE_FACTORY_H__
Packit 284210

Packit 284210
// Factory class for CMyHttpModule.
Packit 284210
// This class is responsible for creating instances
Packit 284210
// of CMyHttpModule for each request.
Packit 284210
class CMyHttpModuleFactory : public IHttpModuleFactory
Packit 284210
{
Packit 284210
        CMyHttpModule *				m_pModule;
Packit 284210
		CRITICAL_SECTION			m_csLock;
Packit 284210

Packit 284210
public:
Packit 284210
	CMyHttpModuleFactory()
Packit 284210
	{
Packit 284210
		m_pModule = NULL;
Packit 284210

Packit 284210
		InitializeCriticalSection(&m_csLock);
Packit 284210
	}
Packit 284210

Packit 284210
	virtual
Packit 284210
    HRESULT
Packit 284210
    GetHttpModule(
Packit 284210
        OUT CHttpModule            **ppModule, 
Packit 284210
        IN IModuleAllocator        *
Packit 284210
    )
Packit 284210
    {
Packit 284210
        HRESULT                    hr = S_OK;
Packit 284210

Packit 284210
	    if ( ppModule == NULL )
Packit 284210
        {
Packit 284210
            hr = HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER );
Packit 284210
            goto Finished;
Packit 284210
        }
Packit 284210

Packit 284210
		EnterCriticalSection(&m_csLock);
Packit 284210

Packit 284210
		if(m_pModule == NULL)
Packit 284210
		{
Packit 284210
			m_pModule = new CMyHttpModule();
Packit 284210

Packit 284210
			if ( m_pModule == NULL )
Packit 284210
			{
Packit 284210
				hr = HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
Packit 284210
				goto Finished;
Packit 284210
			}
Packit 284210
		}
Packit 284210

Packit 284210
		LeaveCriticalSection(&m_csLock);
Packit 284210

Packit 284210
        *ppModule = m_pModule;
Packit 284210

Packit 284210
	Finished:
Packit 284210

Packit 284210
        return hr;
Packit 284210
    }
Packit 284210

Packit 284210
    virtual 
Packit 284210
    void
Packit 284210
    Terminate()
Packit 284210
    {
Packit 284210
        if ( m_pModule != NULL )
Packit 284210
        {
Packit 284210
			//m_pModule->WriteEventViewerLog("Module terminated.");
Packit 284210
            delete m_pModule;
Packit 284210
            m_pModule = NULL;
Packit 284210
        }
Packit 284210

Packit 284210
        delete this;
Packit 284210
    }
Packit 284210
};
Packit 284210

Packit 284210
#endif