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.

213 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. Simple.cpp
  5. Abstract:
  6. This module shows the basic functions needed for ISAPI extension
  7. --*/
  8. #include <windows.h>
  9. #include <httpext.h>
  10. BOOL WINAPI
  11. DllMain(
  12. IN HINSTANCE hinstDll,
  13. IN DWORD dwReason,
  14. IN LPVOID lpvContext
  15. )
  16. /*++
  17. Function : DllMain
  18. Description:
  19. The initialization function for this DLL.
  20. Arguments:
  21. hinstDll - Instance handle of the DLL
  22. dwReason - Reason why NT called this DLL
  23. lpvContext - Reserved parameter for future use
  24. Return Value:
  25. Returns TRUE if successfull; otherwise FALSE.
  26. --*/
  27. {
  28. // Note that appropriate initialization and termination code
  29. // would be written within the switch statement below. Because
  30. // this example is very simple, none is currently needed.
  31. switch( dwReason ) {
  32. case DLL_PROCESS_ATTACH:
  33. break;
  34. case DLL_PROCESS_DETACH:
  35. break;
  36. }
  37. return(TRUE);
  38. }
  39. BOOL WINAPI
  40. GetExtensionVersion(
  41. OUT HSE_VERSION_INFO * pVer
  42. )
  43. /*++
  44. Purpose:
  45. The first function called after IIS successfully
  46. loads the DLL. The function should use the
  47. version structure provided by IIS to set the ISAPI
  48. architectural version number of this extension.
  49. A simple text-string is also set so that
  50. administrators can identify the DLL.
  51. Note that HSE_VERSION_MINOR and HSE_VERSION_MAJOR
  52. are constants defined in httpext.h.
  53. Arguments:
  54. pVer - points to extension version structure
  55. Return Value:
  56. TRUE if successful; FALSE otherwise.
  57. --*/
  58. {
  59. pVer->dwExtensionVersion = MAKELONG( HSE_VERSION_MINOR,
  60. HSE_VERSION_MAJOR );
  61. strcpy( pVer->lpszExtensionDesc,
  62. "IIS SDK Simple ISAPI Extension" );
  63. return TRUE;
  64. }
  65. DWORD WINAPI
  66. HttpExtensionProc(
  67. IN EXTENSION_CONTROL_BLOCK * pECB
  68. )
  69. /*++
  70. Purpose:
  71. Function called by the IIS Server when a request
  72. for the ISAPI dll arrives. The HttpExtensionProc
  73. function processes the request and outputs the
  74. appropriate response to the web client using
  75. WriteClient().
  76. Argument:
  77. pECB - pointer to extention control block.
  78. Return Value:
  79. HSE_STATUS_SUCCESS
  80. --*/
  81. {
  82. static char szMessage[] =
  83. "<HTML>"
  84. "<HEAD><TITLE> Simple ISAPI Extension DLL </TITLE>"
  85. "</HEAD>\r\n"
  86. "<BODY>"
  87. "<P>Hello from Simple ISAPI Extension DLL!</P>\r\n"
  88. "</BODY></HTML>\r\n\r\n";
  89. HSE_SEND_HEADER_EX_INFO HeaderExInfo;
  90. //
  91. // prepare headers
  92. //
  93. HeaderExInfo.pszStatus = "200 OK";
  94. HeaderExInfo.pszHeader = "Content-type: text/html\r\n\r\n";
  95. HeaderExInfo.cchStatus = strlen( HeaderExInfo.pszStatus );
  96. HeaderExInfo.cchHeader = strlen( HeaderExInfo.pszHeader );
  97. HeaderExInfo.fKeepConn = FALSE;
  98. //
  99. // send headers using IIS-provided callback
  100. // (note - if we needed to keep connection open,
  101. // we would set fKeepConn to TRUE *and* we would
  102. // need to provide correct Content-Length: header)
  103. pECB->ServerSupportFunction(
  104. pECB->ConnID,
  105. HSE_REQ_SEND_RESPONSE_HEADER_EX,
  106. &HeaderExInfo,
  107. NULL,
  108. NULL
  109. );
  110. //
  111. // Calculate length of string to output to client
  112. //
  113. DWORD dwBytesToWrite = strlen( szMessage );
  114. //
  115. // send text using IIS-provied callback
  116. //
  117. pECB->WriteClient( pECB->ConnID, szMessage, &dwBytesToWrite, 0 );
  118. //
  119. // Indicate that the call to HttpExtensionProc was successful
  120. //
  121. return HSE_STATUS_SUCCESS;
  122. }
  123. BOOL WINAPI
  124. TerminateExtension(
  125. IN DWORD dwFlags
  126. )
  127. /*++
  128. Routine Description:
  129. This function is called when the WWW service is shutdown
  130. Arguments:
  131. dwFlags - HSE_TERM_ADVISORY_UNLOAD or HSE_TERM_MUST_UNLOAD
  132. Return Value:
  133. TRUE if extension is ready to be unloaded,
  134. FALSE otherwise
  135. --*/
  136. {
  137. // Note: We must not agree to be unloaded if we have
  138. // any pending requests.
  139. return TRUE;
  140. }