1 /*
2 * ModSecurity for Apache 2.x, http://www.modsecurity.org/
3 * Copyright (c) 2004-2013 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4 *
5 * You may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * If any of the files related to licensing are missing or if you have any
11 * other questions related to licensing please contact Trustwave Holdings, Inc.
12 * directly using the email address security@modsecurity.org.
13 */
14
15 #define WIN32_LEAN_AND_MEAN
16
17 #undef inline
18 #define inline inline
19
20 // IIS7 Server API header file
21 #include "httpserv.h"
22
23 // Project header files
24 #include "mymodule.h"
25 #include "mymodulefactory.h"
26
27 // Global server instance
28 IHttpServer * g_pHttpServer = NULL;
29
30 // Global module context id
31 PVOID g_pModuleContext = NULL;
32
33 // The RegisterModule entrypoint implementation.
34 // This method is called by the server when the module DLL is
35 // loaded in order to create the module factory,
36 // and register for server events.
37 HRESULT
38 __stdcall
RegisterModule(DWORD dwServerVersion,IHttpModuleRegistrationInfo * pModuleInfo,IHttpServer * pHttpServer)39 RegisterModule(
40 DWORD dwServerVersion,
41 IHttpModuleRegistrationInfo * pModuleInfo,
42 IHttpServer * pHttpServer
43 )
44 {
45 HRESULT hr = S_OK;
46 CMyHttpModuleFactory * pFactory = NULL;
47 //IHttpModuleRegistrationInfo2 * pModuleInfo2;
48
49 if ( pModuleInfo == NULL || pHttpServer == NULL )
50 {
51 hr = HRESULT_FROM_WIN32( ERROR_INVALID_PARAMETER );
52 goto Finished;
53 }
54
55 /*hr = HttpGetExtendedInterface( g_pGlobalInfo,
56 pModuleInfo,
57 &pModuleInfo2 );
58 if ( FAILED ( hr ) )
59 {
60 goto Finished;
61 }*/
62
63 // step 1: save the IHttpServer and the module context id for future use
64 //
65 g_pModuleContext = pModuleInfo->GetId();
66 g_pHttpServer = pHttpServer;
67
68 // step 2: create the module factory
69 //
70 pFactory = new CMyHttpModuleFactory();
71 if ( pFactory == NULL )
72 {
73 hr = HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
74 goto Finished;
75 }
76
77 // step 3: register for server events
78 //
79 hr = pModuleInfo->SetRequestNotifications( pFactory, /* module factory */
80 RQ_BEGIN_REQUEST | RQ_SEND_RESPONSE /* server event mask */,
81 RQ_END_REQUEST /* server post event mask */);
82 if ( FAILED( hr ) )
83 {
84 goto Finished;
85 }
86
87 hr = pModuleInfo->SetPriorityForRequestNotification(RQ_BEGIN_REQUEST, PRIORITY_ALIAS_FIRST);
88 hr = pModuleInfo->SetPriorityForRequestNotification(RQ_SEND_RESPONSE, PRIORITY_ALIAS_LAST); // reverted!
89 //hr = pModuleInfo2->SetPriorityForPostRequestNotification(RQ_END_REQUEST, PRIORITY_ALIAS_LAST);
90
91 pFactory = NULL;
92
93 Finished:
94
95 /* if ( pFactory != NULL )
96 {
97 delete pFactory;
98 pFactory = NULL;
99 } */
100
101 return hr;
102 }
103