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.

288 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name :
  4. ControlChannel.cxx
  5. Abstract:
  6. Defines the functions used to access the control channel.
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 15-Oct-1998
  9. Lei Jin ( leijin ) 13-Apr-1999 Porting
  10. Project:
  11. IIS Worker Process
  12. --*/
  13. # include "precomp.hxx"
  14. # include "ControlChannel.hxx"
  15. /********************************************************************++
  16. UL_CONTROL_CHANNEL::Initialize()
  17. Description:
  18. This function initializes the control channel for given address, NSGO,
  19. and host name. It opens the control channel, registers a virtual host,
  20. and NSGO. After that it registers the URL for which notifications are
  21. to be handled within the NSGO.
  22. Arguments:
  23. Returns:
  24. ++********************************************************************/
  25. ULONG
  26. UL_CONTROL_CHANNEL::Initialize(
  27. IN MULTISZ& mszURLList,
  28. IN LPCWSTR pwszAppPoolName
  29. )
  30. {
  31. ULONG rc;
  32. LPCWSTR pwszURL;
  33. if ( m_hControlChannel != NULL)
  34. {
  35. //
  36. // There is already a control channel
  37. //
  38. DBGPRINTF(( DBG_CONTEXT, "Duplicate open of control channel\n"));
  39. return ERROR_DUP_NAME;
  40. }
  41. //
  42. // 1. Open a control channel object from the UL driver
  43. //
  44. rc = HttpOpenControlChannel( &m_hControlChannel, 0);
  45. if ( NO_ERROR != rc)
  46. {
  47. IF_DEBUG( ERROR)
  48. {
  49. DBGPRINTF(( DBG_CONTEXT,
  50. "UlOpenControlChannel() failed. Error = %08x. Returning\n",
  51. rc
  52. ));
  53. }
  54. return (rc);
  55. }
  56. //
  57. // 2. Create a Config Group on this control channel
  58. //
  59. rc = HttpCreateConfigGroup( m_hControlChannel, &m_ConfigGroupId );
  60. if ( NO_ERROR != rc)
  61. {
  62. IF_DEBUG(ERROR)
  63. {
  64. DBGPRINTF(( DBG_CONTEXT,
  65. "UlCreateConfigGroup failed. Error=%08x. Returning\n",
  66. rc
  67. ));
  68. }
  69. return rc;
  70. }
  71. //
  72. // 3. Insert all specified URLs into the config group
  73. //
  74. pwszURL = mszURLList.First();
  75. while (NULL != pwszURL)
  76. {
  77. rc = AddURLToConfigGroup(pwszURL);
  78. if (NO_ERROR != rc)
  79. {
  80. return rc;
  81. }
  82. pwszURL = mszURLList.Next(pwszURL);
  83. }
  84. //
  85. // 4. Activate the Control Channel and the Config Group
  86. //
  87. HTTP_ENABLED_STATE ccState = HttpEnabledStateActive;
  88. rc = HttpSetControlChannelInformation( m_hControlChannel,
  89. HttpControlChannelStateInformation,
  90. &ccState,
  91. sizeof(ccState));
  92. if ( NO_ERROR != rc)
  93. {
  94. IF_DEBUG(ERROR)
  95. {
  96. DBGPRINTF(( DBG_CONTEXT,
  97. "Unable to activate ControlChannel. Error=%08x. Returning\n", rc
  98. ));
  99. }
  100. return rc;
  101. }
  102. HTTP_CONFIG_GROUP_STATE cgState;
  103. cgState.Flags.Present = 1;
  104. cgState.State = HttpEnabledStateActive;
  105. rc = HttpSetConfigGroupInformation( m_hControlChannel,
  106. m_ConfigGroupId,
  107. HttpConfigGroupStateInformation,
  108. &cgState,
  109. sizeof(cgState));
  110. if ( NO_ERROR != rc)
  111. {
  112. IF_DEBUG(ERROR)
  113. {
  114. DBGPRINTF(( DBG_CONTEXT,
  115. "Unable to activate Config Group. Error=%08x. Returning\n", rc
  116. ));
  117. }
  118. return rc;
  119. }
  120. //
  121. // 5. Create an AppPool
  122. //
  123. rc = HttpCreateAppPool( &m_hAppPool,
  124. pwszAppPoolName,
  125. 0,
  126. HTTP_OPTION_OVERLAPPED
  127. );
  128. if ( NO_ERROR != rc)
  129. {
  130. IF_DEBUG(ERROR)
  131. {
  132. DBGPRINTF(( DBG_CONTEXT,
  133. "UlCreateAppPool failed for AppPool '%ws'. Error=%08x. Returning\n",
  134. pwszAppPoolName, rc
  135. ));
  136. }
  137. return rc;
  138. }
  139. //
  140. // 6. Associate AppPool with the config group
  141. //
  142. HTTP_CONFIG_GROUP_APP_POOL AppPoolConfig;
  143. AppPoolConfig.Flags.Present = 1;
  144. AppPoolConfig.AppPoolHandle = m_hAppPool;
  145. rc = HttpSetConfigGroupInformation( m_hControlChannel,
  146. m_ConfigGroupId,
  147. HttpConfigGroupAppPoolInformation,
  148. &AppPoolConfig,
  149. sizeof(AppPoolConfig)
  150. );
  151. if ( NO_ERROR != rc)
  152. {
  153. IF_DEBUG(ERROR)
  154. {
  155. DBGPRINTF(( DBG_CONTEXT,
  156. "UlSetConfigGroupInformation failed for AppPool '%ws'. Error=%08x. Returning\n",
  157. pwszAppPoolName, rc
  158. ));
  159. }
  160. }
  161. return (rc);
  162. } // UL_CONTROL_CHANNEL::Initialize()
  163. /********************************************************************++
  164. ++********************************************************************/
  165. ULONG
  166. UL_CONTROL_CHANNEL::Cleanup(void)
  167. {
  168. ULONG rc = NO_ERROR;
  169. if ( m_hControlChannel != NULL)
  170. {
  171. if ( ! HTTP_IS_NULL_ID(&m_ConfigGroupId) )
  172. {
  173. rc = HttpDeleteConfigGroup( m_hControlChannel, m_ConfigGroupId);
  174. HTTP_SET_NULL_ID(&m_ConfigGroupId);
  175. }
  176. if ( NULL != m_hAppPool )
  177. {
  178. if ( !::CloseHandle( m_hAppPool))
  179. {
  180. rc = GetLastError();
  181. }
  182. }
  183. m_hAppPool = NULL;
  184. if (!::CloseHandle( m_hControlChannel))
  185. {
  186. rc = GetLastError();
  187. }
  188. m_hControlChannel = NULL;
  189. }
  190. return (rc);
  191. } // UL_CONTROL_CHANNEL::Cleanup()
  192. /********************************************************************++
  193. ++********************************************************************/
  194. ULONG
  195. UL_CONTROL_CHANNEL::AddURLToConfigGroup( IN LPCWSTR pwszURL)
  196. {
  197. //
  198. // Add the URL to the Config Group
  199. //
  200. ULONG rc;
  201. rc = HttpAddUrlToConfigGroup( m_hControlChannel,
  202. m_ConfigGroupId,
  203. pwszURL,
  204. 0
  205. );
  206. if ( NO_ERROR != rc)
  207. {
  208. IF_DEBUG (ERROR)
  209. {
  210. DBGPRINTF((DBG_CONTEXT,
  211. "UlAddUrlToConfigGroup() failed. Error=%08x\n",
  212. rc));
  213. }
  214. }
  215. return (rc);
  216. }
  217. /************************ End of File ***********************/