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.

505 lines
13 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. ISAPIinstance.cpp
  5. Abstract:
  6. This file contains the implementation of the CISAPIinstance class,
  7. the support class for accessing and modifying the configuration of the
  8. ISAPI extension used by the Upload Library.
  9. Revision History:
  10. Davide Massarenti (Dmassare) 04/28/99
  11. created
  12. ******************************************************************************/
  13. #include "stdafx.h"
  14. static WCHAR text_QUEUE_LOCATIONS [] = L"QUEUE_LOCATIONS" ;
  15. static WCHAR text_QUEUE_SIZE_MAX [] = L"QUEUE_SIZE_MAX" ;
  16. static WCHAR text_QUEUE_SIZE_THRESHOLD[] = L"QUEUE_SIZE_THRESHOLD";
  17. static WCHAR text_MAXIMUM_JOB_AGE [] = L"MAXIMUM_JOB_AGE" ;
  18. static WCHAR text_MAXIMUM_PACKET_SIZE [] = L"MAXIMUM_PACKET_SIZE" ;
  19. static WCHAR text_LOG_LOCATION [] = L"LOG_LOCATION" ;
  20. CISAPIinstance::CISAPIinstance( /*[in]*/ MPC::wstring szURL ) : m_flLogHandle(false) // Don't keep the log file opened.
  21. {
  22. __ULT_FUNC_ENTRY( "CISAPIinstance::CISAPIinstance" );
  23. m_szURL = szURL; // MPC::wstring m_szURL;
  24. //
  25. // ProvMap m_mapProviders;
  26. // PathList m_lstQueueLocations;
  27. //
  28. m_dwQueueSizeMax = 0; // DWORD m_dwQueueSizeMax;
  29. m_dwQueueSizeThreshold = 0; // DWORD m_dwQueueSizeThreshold;
  30. m_dwMaximumJobAge = 7; // DWORD m_dwMaximumJobAge;
  31. m_dwMaximumPacketSize = 64*1024; // DWORD m_dwMaximumPacketSize;
  32. //
  33. // MPC::wstring m_szLogLocation;
  34. // MPC::FileLog m_flLogHandle;
  35. }
  36. bool CISAPIinstance::operator==( /*[in]*/ const MPC::wstring& rhs )
  37. {
  38. __ULT_FUNC_ENTRY("CISAPIinstance::operator==");
  39. MPC::NocaseCompare cmp;
  40. bool fRes;
  41. fRes = cmp( m_szURL, rhs );
  42. __ULT_FUNC_EXIT(fRes);
  43. }
  44. /////////////////////////////////////////////////////////////////////////////
  45. HRESULT CISAPIinstance::Load( /*[in]*/ MPC::RegKey& rkBase )
  46. {
  47. __ULT_FUNC_ENTRY( "CISAPIinstance::Load" );
  48. HRESULT hr;
  49. MPC::RegKey rkRoot;
  50. MPC::WStringList lstKeys;
  51. MPC::WStringIter itKey;
  52. CComVariant vValue;
  53. bool fFound;
  54. __MPC_EXIT_IF_METHOD_FAILS(hr, rkBase.SubKey( m_szURL.c_str(), rkRoot ));
  55. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.EnumerateSubKeys( lstKeys ));
  56. m_mapProviders .clear();
  57. m_lstQueueLocations.clear();
  58. for(itKey=lstKeys.begin(); itKey != lstKeys.end(); itKey++)
  59. {
  60. CISAPIprovider isapiProvider( *itKey );
  61. __MPC_EXIT_IF_METHOD_FAILS(hr, isapiProvider.Load( rkRoot ));
  62. m_mapProviders[*itKey] = isapiProvider;
  63. }
  64. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.get_Value( vValue, fFound, text_QUEUE_SIZE_MAX ));
  65. if(fFound && vValue.vt == VT_I4) m_dwQueueSizeMax = vValue.lVal;
  66. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.get_Value( vValue, fFound, text_QUEUE_SIZE_THRESHOLD ));
  67. if(fFound && vValue.vt == VT_I4) m_dwQueueSizeThreshold = vValue.lVal;
  68. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.get_Value( vValue, fFound, text_MAXIMUM_JOB_AGE ));
  69. if(fFound && vValue.vt == VT_I4) m_dwMaximumJobAge = vValue.lVal;
  70. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.get_Value( vValue, fFound, text_MAXIMUM_PACKET_SIZE ));
  71. if(fFound && vValue.vt == VT_I4) m_dwMaximumPacketSize = vValue.lVal;
  72. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.get_Value( vValue, fFound, text_LOG_LOCATION ));
  73. if(fFound && vValue.vt == VT_BSTR)
  74. {
  75. m_szLogLocation = SAFEBSTR( vValue.bstrVal );
  76. if(m_szLogLocation.length())
  77. {
  78. __MPC_EXIT_IF_METHOD_FAILS(hr, m_flLogHandle.SetLocation( m_szLogLocation.c_str() ));
  79. }
  80. }
  81. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.get_Value( vValue, fFound, text_QUEUE_LOCATIONS ));
  82. if(fFound && vValue.vt == VT_BSTR)
  83. {
  84. //
  85. // Split the registry value, a semicolon-separated list of paths, into individual paths.
  86. //
  87. MPC::wstring szQueueLocations = SAFEBSTR( vValue.bstrVal );
  88. MPC::wstring::size_type iPos = 0;
  89. MPC::wstring::size_type iEnd;
  90. while(1)
  91. {
  92. iEnd = szQueueLocations.find( L";", iPos );
  93. if(iEnd == MPC::string::npos) // Last component.
  94. {
  95. m_lstQueueLocations.push_back( MPC::wstring( &szQueueLocations[iPos] ) );
  96. break;
  97. }
  98. else
  99. {
  100. m_lstQueueLocations.push_back( MPC::wstring( &szQueueLocations[iPos], &szQueueLocations[iEnd] ) );
  101. iPos = iEnd+1;
  102. }
  103. }
  104. }
  105. hr = S_OK;
  106. __ULT_FUNC_CLEANUP;
  107. __ULT_FUNC_EXIT(hr);
  108. }
  109. HRESULT CISAPIinstance::Save( /*[in]*/ MPC::RegKey& rkBase )
  110. {
  111. __ULT_FUNC_ENTRY( "CISAPIinstance::Save" );
  112. HRESULT hr;
  113. MPC::RegKey rkRoot;
  114. ProvIter itInstance;
  115. CComVariant vValue;
  116. __MPC_EXIT_IF_METHOD_FAILS(hr, rkBase.SubKey( m_szURL.c_str(), rkRoot ));
  117. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.Create( ));
  118. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.DeleteSubKeys());
  119. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.DeleteValues ());
  120. for(itInstance=m_mapProviders.begin(); itInstance != m_mapProviders.end(); itInstance++)
  121. {
  122. __MPC_EXIT_IF_METHOD_FAILS(hr, (*itInstance).second.Save( rkRoot ));
  123. }
  124. vValue = (long)m_dwQueueSizeMax;
  125. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.put_Value( vValue, text_QUEUE_SIZE_MAX ));
  126. vValue = (long)m_dwQueueSizeThreshold;
  127. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.put_Value( vValue, text_QUEUE_SIZE_THRESHOLD ));
  128. vValue = (long)m_dwMaximumJobAge;
  129. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.put_Value( vValue, text_MAXIMUM_JOB_AGE ));
  130. vValue = (long)m_dwMaximumPacketSize;
  131. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.put_Value( vValue, text_MAXIMUM_PACKET_SIZE ));
  132. vValue = m_szLogLocation.c_str();
  133. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.put_Value( vValue, text_LOG_LOCATION ));
  134. {
  135. MPC::wstring szQueueLocations;
  136. PathIter it = m_lstQueueLocations.begin();
  137. while(it != m_lstQueueLocations.end())
  138. {
  139. szQueueLocations.append( *it++ );
  140. if(it != m_lstQueueLocations.end()) szQueueLocations.append( L";" );
  141. }
  142. if(szQueueLocations.length() != 0)
  143. {
  144. vValue = szQueueLocations.c_str();
  145. __MPC_EXIT_IF_METHOD_FAILS(hr, rkRoot.put_Value( vValue, text_QUEUE_LOCATIONS ));
  146. }
  147. }
  148. hr = S_OK;
  149. __ULT_FUNC_CLEANUP;
  150. __ULT_FUNC_EXIT(hr);
  151. }
  152. /////////////////////////////////////////////////////////////////////////////
  153. HRESULT CISAPIinstance::GetProviders( /*[out]*/ ProvIter& itBegin ,
  154. /*[out]*/ ProvIter& itEnd )
  155. {
  156. __ULT_FUNC_ENTRY( "CISAPIinstance::GetProviders" );
  157. HRESULT hr;
  158. itBegin = m_mapProviders.begin();
  159. itEnd = m_mapProviders.end ();
  160. hr = S_OK;
  161. __ULT_FUNC_EXIT(hr);
  162. }
  163. HRESULT CISAPIinstance::GetProvider( /*[out]*/ ProvIter& itOld ,
  164. /*[out]*/ bool& fFound ,
  165. /*[in] */ const MPC::wstring& szName )
  166. {
  167. __ULT_FUNC_ENTRY( "CISAPIinstance::GetProvider" );
  168. HRESULT hr;
  169. itOld = m_mapProviders.find( szName );
  170. if(itOld == m_mapProviders.end())
  171. {
  172. fFound = false;
  173. }
  174. else
  175. {
  176. fFound = true;
  177. }
  178. hr = S_OK;
  179. __ULT_FUNC_EXIT(hr);
  180. }
  181. HRESULT CISAPIinstance::NewProvider( /*[out]*/ ProvIter& itNew ,
  182. /*[in] */ const MPC::wstring& szName )
  183. {
  184. __ULT_FUNC_ENTRY( "CISAPIinstance::NewProvider" );
  185. HRESULT hr;
  186. std::pair<ProvIter, bool> res;
  187. bool fFound;
  188. //
  189. // First of all, check if the given URL already exists.
  190. //
  191. __MPC_EXIT_IF_METHOD_FAILS(hr, GetProvider( itNew, fFound, szName ));
  192. if(fFound == false)
  193. {
  194. //
  195. // If not, create it.
  196. //
  197. res = m_mapProviders.insert( ProvMap::value_type( szName, CISAPIprovider( szName ) ) );
  198. itNew = res.first;
  199. }
  200. hr = S_OK;
  201. __ULT_FUNC_CLEANUP;
  202. __ULT_FUNC_EXIT(hr);
  203. }
  204. HRESULT CISAPIinstance::DelProvider( /*[in]*/ ProvIter& itOld )
  205. {
  206. __ULT_FUNC_ENTRY( "CISAPIinstance::DelProvider" );
  207. HRESULT hr;
  208. m_mapProviders.erase( itOld );
  209. hr = S_OK;
  210. __ULT_FUNC_EXIT(hr);
  211. }
  212. /////////////////////////////////////////////////////////////////////////////
  213. HRESULT CISAPIinstance::GetLocations( /*[out]*/ PathIter& itBegin ,
  214. /*[out]*/ PathIter& itEnd )
  215. {
  216. __ULT_FUNC_ENTRY( "CISAPIinstance::GetLocations" );
  217. HRESULT hr;
  218. itBegin = m_lstQueueLocations.begin();
  219. itEnd = m_lstQueueLocations.end ();
  220. hr = S_OK;
  221. __ULT_FUNC_EXIT(hr);
  222. }
  223. HRESULT CISAPIinstance::NewLocation( /*[out]*/ PathIter& itNew ,
  224. /*[in] */ const MPC::wstring& szPath )
  225. {
  226. __ULT_FUNC_ENTRY( "CISAPIinstance::NewLocation" );
  227. HRESULT hr;
  228. bool fFound;
  229. __MPC_EXIT_IF_METHOD_FAILS(hr, GetLocation( itNew, fFound, szPath ));
  230. if(fFound == false)
  231. {
  232. itNew = m_lstQueueLocations.insert( m_lstQueueLocations.end(), szPath );
  233. }
  234. hr = S_OK;
  235. __ULT_FUNC_CLEANUP;
  236. __ULT_FUNC_EXIT(hr);
  237. }
  238. HRESULT CISAPIinstance::GetLocation( /*[out]*/ PathIter& itOld ,
  239. /*[out]*/ bool& fFound ,
  240. /*[in] */ const MPC::wstring& szPath )
  241. {
  242. __ULT_FUNC_ENTRY( "CISAPIinstance::GetLocation" );
  243. HRESULT hr;
  244. itOld = std::find( m_lstQueueLocations.begin(), m_lstQueueLocations.end(), szPath );
  245. if(itOld == m_lstQueueLocations.end())
  246. {
  247. fFound = false;
  248. }
  249. else
  250. {
  251. fFound = true;
  252. }
  253. hr = S_OK;
  254. __ULT_FUNC_EXIT(hr);
  255. }
  256. HRESULT CISAPIinstance::DelLocation( /*[in]*/ PathIter& itOld )
  257. {
  258. __ULT_FUNC_ENTRY( "CISAPIinstance::DelLocation" );
  259. HRESULT hr;
  260. m_lstQueueLocations.erase( itOld );
  261. hr = S_OK;
  262. __ULT_FUNC_EXIT(hr);
  263. }
  264. /////////////////////////////////////////////////////////////////////////////
  265. /////////////////////////////////////////////////////////////////////////////
  266. /////////////////////////////////////////////////////////////////////////////
  267. HRESULT CISAPIinstance::get_URL( /*[out]*/ MPC::wstring& szURL )
  268. {
  269. szURL = m_szURL;
  270. return S_OK;
  271. }
  272. HRESULT CISAPIinstance::get_QueueSizeMax( /*[out]*/ DWORD& dwQueueSizeMax )
  273. {
  274. dwQueueSizeMax = m_dwQueueSizeMax;
  275. return S_OK;
  276. }
  277. HRESULT CISAPIinstance::get_QueueSizeThreshold( /*[out]*/ DWORD& dwQueueSizeThreshold )
  278. {
  279. dwQueueSizeThreshold = m_dwQueueSizeThreshold;
  280. return S_OK;
  281. }
  282. HRESULT CISAPIinstance::get_MaximumJobAge( /*[out]*/ DWORD& dwMaximumJobAge )
  283. {
  284. dwMaximumJobAge = m_dwMaximumJobAge;
  285. return S_OK;
  286. }
  287. HRESULT CISAPIinstance::get_MaximumPacketSize( /*[out]*/ DWORD& dwMaximumPacketSize )
  288. {
  289. dwMaximumPacketSize = m_dwMaximumPacketSize;
  290. return S_OK;
  291. }
  292. HRESULT CISAPIinstance::get_LogLocation( /*[out]*/ MPC::wstring& szLogLocation )
  293. {
  294. szLogLocation = m_szLogLocation;
  295. return S_OK;
  296. }
  297. HRESULT CISAPIinstance::get_LogHandle( /*[out]*/ MPC::FileLog*& flLogHandle )
  298. {
  299. HRESULT hr;
  300. if(m_szLogLocation.length())
  301. {
  302. flLogHandle = &m_flLogHandle;
  303. //
  304. // Check if it's been more than one day since the last time we rotated the log file.
  305. //
  306. hr = m_flLogHandle.Rotate( 1 );
  307. }
  308. else
  309. {
  310. flLogHandle = NULL;
  311. hr = E_INVALIDARG;
  312. }
  313. return hr;
  314. }
  315. /////////////////////////////////////////////////////////////////////////////
  316. HRESULT CISAPIinstance::put_QueueSizeMax( /*[in]*/ DWORD dwQueueSizeMax )
  317. {
  318. m_dwQueueSizeMax = dwQueueSizeMax;
  319. return S_OK;
  320. }
  321. HRESULT CISAPIinstance::put_QueueSizeThreshold( /*[in]*/ DWORD dwQueueSizeThreshold )
  322. {
  323. m_dwQueueSizeThreshold = dwQueueSizeThreshold;
  324. return S_OK;
  325. }
  326. HRESULT CISAPIinstance::put_MaximumJobAge( /*[in]*/ DWORD dwMaximumJobAge )
  327. {
  328. m_dwMaximumJobAge = dwMaximumJobAge;
  329. return S_OK;
  330. }
  331. HRESULT CISAPIinstance::put_MaximumPacketSize( /*[in]*/ DWORD dwMaximumPacketSize )
  332. {
  333. m_dwMaximumPacketSize = dwMaximumPacketSize;
  334. return S_OK;
  335. }
  336. HRESULT CISAPIinstance::put_LogLocation( /*[in]*/ const MPC::wstring& szLogLocation )
  337. {
  338. HRESULT hr;
  339. m_szLogLocation = szLogLocation;
  340. if(m_szLogLocation.length())
  341. {
  342. hr = m_flLogHandle.SetLocation( m_szLogLocation.c_str() );
  343. }
  344. else
  345. {
  346. hr = S_OK;
  347. }
  348. return hr;
  349. }