Leaked source code of windows server 2003
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.

182 lines
4.2 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation
  6. //
  7. // File: kpexport.cxx
  8. //
  9. // Contents: kproxy exported ISAPI entrypoints
  10. //
  11. // History: 10-Jul-2001 t-ryanj Created
  12. //
  13. //------------------------------------------------------------------------
  14. #include "kpcommon.h"
  15. #include "kpinit.h"
  16. #include "kphttp.h"
  17. #include "kpcore.h"
  18. //
  19. // Exported Functions
  20. //
  21. extern "C"{
  22. BOOL WINAPI GetExtensionVersion(
  23. HSE_VERSION_INFO* VerInfo
  24. );
  25. ULONG WINAPI HttpExtensionProc(
  26. LPEXTENSION_CONTROL_BLOCK pECB
  27. );
  28. BOOL WINAPI TerminateExtension(
  29. ULONG Flags
  30. );
  31. }
  32. //+-------------------------------------------------------------------------
  33. //
  34. // Function: GetExtensionVersion
  35. //
  36. // Synopsis: Called when IIS loads the extension.
  37. // Reports the ISAPI version used to build this dll, also
  38. // gives a chance to do startup initialization.
  39. //
  40. // Effects:
  41. //
  42. // Arguments:
  43. //
  44. // Requires:
  45. //
  46. // Returns: Indicates if startup was successful. When startup fails,
  47. // FALSE is returned, and IIS will refuse to use the extension.
  48. //
  49. // Notes:
  50. //
  51. //
  52. //--------------------------------------------------------------------------
  53. BOOL WINAPI GetExtensionVersion(
  54. HSE_VERSION_INFO* pVer
  55. )
  56. {
  57. BOOL result;
  58. //
  59. // Report our ISAPI version and description.
  60. //
  61. pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
  62. lstrcpyA(pVer->lpszExtensionDesc, "Desc from resource file.");
  63. //
  64. // Do global initialization.
  65. //
  66. result = KpStartup();
  67. return result;
  68. }
  69. //+-------------------------------------------------------------------------
  70. //
  71. // Function: HttpExtensionProc
  72. //
  73. // Synopsis: Entrypoint called by IIS when a request is made for us.
  74. //
  75. // Effects:
  76. //
  77. // Arguments: pECB - contains all relevant info about the request
  78. //
  79. // Requires:
  80. //
  81. // Returns: One of:
  82. // HSE_STATUS_SUCCESS
  83. // HSE_STATUS_SUCCESS_AND_KEEP_CONN
  84. // HSE_STATUS_PENDING
  85. // HSE_STATUS_ERROR
  86. //
  87. // Notes:
  88. //
  89. //
  90. //--------------------------------------------------------------------------
  91. ULONG WINAPI HttpExtensionProc(
  92. LPEXTENSION_CONTROL_BLOCK pECB
  93. )
  94. {
  95. ULONG result = HSE_STATUS_PENDING;
  96. BOOL IocpSuccess;
  97. PKPCONTEXT pContext;
  98. //
  99. // Acquire a context.
  100. //
  101. pContext = KpAcquireContext( pECB );
  102. if( !pContext )
  103. {
  104. //
  105. // Allocation failed. Ummm. Bad.
  106. //
  107. DebugLog( DEB_ERROR, "%s(%d): Could not get context. Punting connection 0x%x.\n", __FILE__, __LINE__, pECB->ConnID );
  108. goto Error;
  109. }
  110. //
  111. // Let's not waste our time handling this - post it to the completion port.
  112. //
  113. IocpSuccess = QueueUserWorkItem( KpThreadCore,
  114. (PVOID)pContext,
  115. 0 );
  116. if( !IocpSuccess )
  117. {
  118. //
  119. // Posting to the iocp failed. We're not going to be able to handle
  120. // this request.
  121. //
  122. DebugLog( DEB_ERROR, "%s(%d): Failed to post to completion port: 0x%x.\n", __FILE__, __LINE__, GetLastError() );
  123. goto Error;
  124. }
  125. Cleanup:
  126. return result;
  127. Error:
  128. result = HSE_STATUS_ERROR;
  129. goto Cleanup;
  130. }
  131. //+-------------------------------------------------------------------------
  132. //
  133. // Function: TerminateExtension
  134. //
  135. // Synopsis: IIS telling us to shut down. We free our resources first.
  136. // Note that IIS will never call this until all pending requests
  137. // have been finished, so there is no need to check for and
  138. // close/finish pending requests.
  139. //
  140. // Effects:
  141. //
  142. // Arguments: Flags - this is always HSE_TERM_MUST_UNLOAD
  143. //
  144. // Requires:
  145. //
  146. // Returns: TRUE
  147. //
  148. // Notes:
  149. //
  150. //
  151. //--------------------------------------------------------------------------
  152. BOOL WINAPI TerminateExtension(
  153. ULONG Flags
  154. )
  155. {
  156. KpShutdown();
  157. return TRUE;
  158. }