Skip to content

Instantly share code, notes, and snippets.

@azechi
Last active August 29, 2015 14:03
Show Gist options
  • Save azechi/c6790e33d28af1d8759f to your computer and use it in GitHub Desktop.
Save azechi/c6790e33d28af1d8759f to your computer and use it in GitHub Desktop.
IISNativeModule W3C Log CustomField
HRESULT __stdcall RegisterModule(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo* pModuleInfo,
IHttpServer* pGlobalInfo
) {
::OutputDebugString ( TEXT("RegisterModule") );
HRESULT hr = S_OK;
hr = pModuleInfo->SetRequestNotifications(
new ModuleFactory,
RQ_SEND_RESPONSE,
0
);
hr = pModuleInfo->SetPriorityForRequestNotification(RQ_SEND_RESPONSE,PRIORITY_ALIAS_HIGH);
return hr;
}
HRESULT ModuleFactory::GetHttpModule(
CHttpModule** ppModule,
IModuleAllocator* pAllocator
){
Module* pModule = new Module;
if (!pModule) {
return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
}
*ppModule = pModule;
return S_OK;
}
void ModuleFactory::Terminate() {
delete this;
}
REQUEST_NOTIFICATION_STATUS Module::OnSendResponse(
IN IHttpContext* pHttpContext,
IN ISendResponseProvider* pProvider
){
if (TRUE == pProvider->GetReadyToLogData())
{
PHTTP_LOG_FIELDS_DATA pLogData =
(PHTTP_LOG_FIELDS_DATA) pProvider->GetLogData();
if (NULL != pLogData)
{
HRESULT hr;
PCSTR pszValue = nullptr;
DWORD dwLength = 0;
hr = pHttpContext->GetServerVariable(
"MyVariable",
&pszValue,
&dwLength);
if (FAILED( hr ))
{
pszValue = nullptr;
dwLength = 0;
}
pLogData->Cookie = (PCHAR)pszValue;
pLogData->CookieLength = dwLength;
hr = pProvider->SetLogData((HTTP_LOG_DATA *)pLogData);
if (FAILED(hr))
{
pProvider->SetErrorStatus( hr );
return RQ_NOTIFICATION_FINISH_REQUEST;
}
}
}
return RQ_NOTIFICATION_CONTINUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment