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.

323 lines
8.1 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. IN DWORD dwSiteId
  30. )
  31. {
  32. ULONG rc;
  33. LPCWSTR pwszURL;
  34. if ( m_hControlChannel != NULL)
  35. {
  36. //
  37. // There is already a control channel
  38. //
  39. DBGPRINTF(( DBG_CONTEXT, "Duplicate open of control channel\n"));
  40. return ERROR_DUP_NAME;
  41. }
  42. //
  43. // 1. Open a control channel object from the UL driver
  44. //
  45. rc = HttpOpenControlChannel( &m_hControlChannel, 0);
  46. if ( NO_ERROR != rc)
  47. {
  48. IF_DEBUG( ERROR)
  49. {
  50. DBGPRINTF(( DBG_CONTEXT,
  51. "UlOpenControlChannel() failed. Error = %08x. Returning\n",
  52. rc
  53. ));
  54. }
  55. return (rc);
  56. }
  57. //
  58. // 2. Create a Config Group on this control channel
  59. //
  60. rc = HttpCreateConfigGroup( m_hControlChannel, &m_ConfigGroupId );
  61. if ( NO_ERROR != rc)
  62. {
  63. IF_DEBUG(ERROR)
  64. {
  65. DBGPRINTF(( DBG_CONTEXT,
  66. "UlCreateConfigGroup failed. Error=%08x. Returning\n",
  67. rc
  68. ));
  69. }
  70. return rc;
  71. }
  72. //
  73. // 3. Insert all specified URLs into the config group
  74. //
  75. pwszURL = mszURLList.First();
  76. while (NULL != pwszURL)
  77. {
  78. rc = AddURLToConfigGroup(pwszURL, dwSiteId);
  79. if (NO_ERROR != rc)
  80. {
  81. return rc;
  82. }
  83. pwszURL = mszURLList.Next(pwszURL);
  84. }
  85. //
  86. // 4. Activate the Control Channel and the Config Group
  87. //
  88. HTTP_ENABLED_STATE ccState = HttpEnabledStateActive;
  89. rc = HttpSetControlChannelInformation( m_hControlChannel,
  90. HttpControlChannelStateInformation,
  91. &ccState,
  92. sizeof(ccState));
  93. if ( NO_ERROR != rc)
  94. {
  95. IF_DEBUG(ERROR)
  96. {
  97. DBGPRINTF(( DBG_CONTEXT,
  98. "Unable to activate ControlChannel. Error=%08x. Returning\n", rc
  99. ));
  100. }
  101. return rc;
  102. }
  103. HTTP_CONFIG_GROUP_STATE cgState;
  104. cgState.Flags.Present = 1;
  105. cgState.State = HttpEnabledStateActive;
  106. rc = HttpSetConfigGroupInformation( m_hControlChannel,
  107. m_ConfigGroupId,
  108. HttpConfigGroupStateInformation,
  109. &cgState,
  110. sizeof(cgState));
  111. if ( NO_ERROR != rc)
  112. {
  113. IF_DEBUG(ERROR)
  114. {
  115. DBGPRINTF(( DBG_CONTEXT,
  116. "Unable to activate Config Group. Error=%08x. Returning\n", rc
  117. ));
  118. }
  119. return rc;
  120. }
  121. //
  122. // 5. Create an AppPool
  123. //
  124. rc = HttpCreateAppPool( &m_hAppPool,
  125. pwszAppPoolName,
  126. 0,
  127. 0
  128. );
  129. if ( NO_ERROR != rc)
  130. {
  131. IF_DEBUG(ERROR)
  132. {
  133. DBGPRINTF(( DBG_CONTEXT,
  134. "UlCreateAppPool failed for AppPool '%ws'. Error=%08x. Returning\n",
  135. pwszAppPoolName, rc
  136. ));
  137. }
  138. return rc;
  139. }
  140. //
  141. // 6. Associate AppPool with the config group
  142. //
  143. HTTP_CONFIG_GROUP_APP_POOL AppPoolConfig;
  144. AppPoolConfig.Flags.Present = 1;
  145. AppPoolConfig.AppPoolHandle = m_hAppPool;
  146. rc = HttpSetConfigGroupInformation( m_hControlChannel,
  147. m_ConfigGroupId,
  148. HttpConfigGroupAppPoolInformation,
  149. &AppPoolConfig,
  150. sizeof(AppPoolConfig)
  151. );
  152. if ( NO_ERROR != rc)
  153. {
  154. IF_DEBUG(ERROR)
  155. {
  156. DBGPRINTF(( DBG_CONTEXT,
  157. "UlSetConfigGroupInformation failed for AppPool '%ws'. Error=%08x. Returning\n",
  158. pwszAppPoolName, rc
  159. ));
  160. }
  161. return rc;
  162. }
  163. //
  164. // 7. Enable the app pool
  165. //
  166. HTTP_APP_POOL_ENABLED_STATE NewHttpAppPoolState = HttpAppPoolEnabled;
  167. rc = HttpSetAppPoolInformation(
  168. m_hAppPool, // app pool handle
  169. HttpAppPoolStateInformation, // information class
  170. reinterpret_cast <VOID *> ( &NewHttpAppPoolState ), // data
  171. sizeof( HTTP_APP_POOL_ENABLED_STATE ) // data length
  172. );
  173. if ( rc != NO_ERROR )
  174. {
  175. IF_DEBUG(ERROR)
  176. {
  177. DBGPRINTF(( DBG_CONTEXT,
  178. "HttpSetAppPoolInformation failed for AppPool '%ws'. Error=%08x. Returning\n",
  179. pwszAppPoolName, rc
  180. ));
  181. }
  182. return rc;
  183. }
  184. return (rc);
  185. } // UL_CONTROL_CHANNEL::Initialize()
  186. /********************************************************************++
  187. ++********************************************************************/
  188. ULONG
  189. UL_CONTROL_CHANNEL::Cleanup(void)
  190. {
  191. ULONG rc = NO_ERROR;
  192. if ( m_hControlChannel != NULL)
  193. {
  194. if ( ! HTTP_IS_NULL_ID(&m_ConfigGroupId) )
  195. {
  196. rc = HttpDeleteConfigGroup( m_hControlChannel, m_ConfigGroupId);
  197. HTTP_SET_NULL_ID(&m_ConfigGroupId);
  198. }
  199. if ( NULL != m_hAppPool )
  200. {
  201. if ( !::CloseHandle( m_hAppPool))
  202. {
  203. rc = GetLastError();
  204. }
  205. }
  206. m_hAppPool = NULL;
  207. if (!::CloseHandle( m_hControlChannel))
  208. {
  209. rc = GetLastError();
  210. }
  211. m_hControlChannel = NULL;
  212. }
  213. return (rc);
  214. } // UL_CONTROL_CHANNEL::Cleanup()
  215. /********************************************************************++
  216. ++********************************************************************/
  217. ULONG
  218. UL_CONTROL_CHANNEL::AddURLToConfigGroup( IN LPCWSTR pwszURL,
  219. IN DWORD dwSiteId )
  220. {
  221. //
  222. // Add the URL to the Config Group
  223. //
  224. ULONG rc;
  225. HTTP_URL_CONTEXT UrlContext = dwSiteId;
  226. UrlContext = UrlContext << 32;
  227. rc = HttpAddUrlToConfigGroup( m_hControlChannel,
  228. m_ConfigGroupId,
  229. pwszURL,
  230. UrlContext
  231. );
  232. if ( NO_ERROR != rc)
  233. {
  234. IF_DEBUG (ERROR)
  235. {
  236. DBGPRINTF((DBG_CONTEXT,
  237. "UlAddUrlToConfigGroup() failed. Error=%08x\n",
  238. rc));
  239. }
  240. }
  241. return (rc);
  242. }
  243. /************************ End of File ***********************/