Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
4.3 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. UploadServer.cpp
  5. Abstract:
  6. This file contains the implementation of the stubs needed
  7. by an ISAPI extension.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 04/20/99
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. #include <initguid.h>
  14. #include "UploadServerCustom_i.c"
  15. ////////////////////////////////////////////////////////////////////////////////
  16. CComModule _Module;
  17. BEGIN_OBJECT_MAP(ObjectMap)
  18. END_OBJECT_MAP()
  19. ////////////////////////////////////////////////////////////////////////////////
  20. HANDLE g_Heap;
  21. CISAPIconfig g_Config;
  22. MPC::NTEvent g_NTEvents;
  23. static CRITICAL_SECTION g_CritSec;
  24. static BOOL g_Initialized;
  25. static WCHAR g_AppName [] = L"UploadServer";
  26. static WCHAR g_RegistryBase[] = L"SOFTWARE\\Microsoft\\UploadLibrary\\Settings";
  27. BOOL WINAPI DllMain( HINSTANCE hinstDLL ,
  28. DWORD fdwReason ,
  29. LPVOID lpvReserved )
  30. {
  31. switch( fdwReason )
  32. {
  33. case DLL_PROCESS_ATTACH:
  34. g_Heap = HeapCreate( 0, 0, 0 ); if(g_Heap == NULL) return FALSE;
  35. InitializeCriticalSection( &g_CritSec );
  36. g_Initialized = false;
  37. _Module.Init( ObjectMap, hinstDLL );
  38. break;
  39. case DLL_PROCESS_DETACH:
  40. _Module.Term();
  41. if(g_Initialized)
  42. {
  43. ;
  44. }
  45. DeleteCriticalSection( &g_CritSec );
  46. HeapDestroy( g_Heap );
  47. break;
  48. }
  49. return TRUE;
  50. }
  51. DWORD WINAPI HttpExtensionProc( LPEXTENSION_CONTROL_BLOCK pECB )
  52. {
  53. __ULT_FUNC_ENTRY("HttpExtensionProc");
  54. DWORD dwRes;
  55. if(pECB->lpszQueryString)
  56. {
  57. //
  58. // Exit if there's a query string beginning with DEBUG
  59. //
  60. if(!strncmp( pECB->lpszQueryString, "DEBUG", 5 ))
  61. {
  62. return HSE_STATUS_ERROR;
  63. }
  64. }
  65. //
  66. // Process the request.
  67. //
  68. try
  69. {
  70. MPCHttpContext* ptr = new MPCHttpContext();
  71. dwRes = ptr->Init( pECB );
  72. }
  73. catch(...)
  74. {
  75. __ULT_TRACE_ERROR( UPLOADLIBID, "Upload Server raised an exception. Gracefully exiting..." );
  76. (void)g_NTEvents.LogEvent( EVENTLOG_ERROR_TYPE, PCHUL_ERR_EXCEPTION,
  77. L"" , // %1 = SERVER
  78. L"HttpExtensionProc", // %2 = CLIENT
  79. NULL );
  80. dwRes = HSE_STATUS_ERROR;
  81. }
  82. return dwRes;
  83. }
  84. BOOL WINAPI GetExtensionVersion( HSE_VERSION_INFO* pVer )
  85. {
  86. BOOL fRes = TRUE;
  87. // Create the extension version string, and
  88. // copy string to HSE_VERSION_INFO structure
  89. pVer->dwExtensionVersion = MAKELONG( HSE_VERSION_MINOR, HSE_VERSION_MAJOR );
  90. // Copy description string into HSE_VERSION_INFO structure
  91. strcpy( pVer->lpszExtensionDesc, "My ISAPI Extension" );
  92. //
  93. // Load config settings if it's the first time we are invoked.
  94. //
  95. if(g_Initialized == FALSE)
  96. {
  97. EnterCriticalSection( &g_CritSec );
  98. if(g_Initialized == FALSE)
  99. {
  100. g_Initialized = TRUE;
  101. __MPC_TRACE_INIT();
  102. (void)g_NTEvents.Init ( g_AppName );
  103. (void)g_Config .SetRoot( g_RegistryBase );
  104. if(FAILED(g_Config.Load()))
  105. {
  106. (void)g_NTEvents.LogEvent( EVENTLOG_ERROR_TYPE, PCHUL_ERR_NOCONFIG, NULL );
  107. fRes = FALSE;
  108. }
  109. }
  110. LeaveCriticalSection( &g_CritSec );
  111. }
  112. (void)g_NTEvents.LogEvent( EVENTLOG_INFORMATION_TYPE, PCHUL_SUCCESS_STARTED, NULL );
  113. return fRes;
  114. }
  115. BOOL WINAPI TerminateExtension( DWORD dwFlags )
  116. {
  117. (void)g_NTEvents.LogEvent( EVENTLOG_INFORMATION_TYPE, PCHUL_SUCCESS_STOPPED, NULL );
  118. __MPC_TRACE_TERM();
  119. return TRUE;
  120. }
  121. /////////////////////////////////////////////////////////////////////////////
  122. void WINAPI PurgeEngine(void)
  123. {
  124. __MPC_TRACE_INIT();
  125. (void)g_NTEvents.Init ( g_AppName );
  126. (void)g_Config .SetRoot( g_RegistryBase );
  127. if(FAILED(g_Config.Load()))
  128. {
  129. (void)g_NTEvents.LogEvent( EVENTLOG_ERROR_TYPE, PCHUL_ERR_NOCONFIG, NULL );
  130. }
  131. else
  132. {
  133. MPCPurgeEngine mpcpe;
  134. mpcpe.Process();
  135. }
  136. __MPC_TRACE_TERM();
  137. }