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
17 KiB

  1. //******************************************************************************
  2. //
  3. // PROVREG.H
  4. //
  5. // Copyright (C) 1996-1999 Microsoft Corporation
  6. //
  7. //******************************************************************************
  8. #ifndef __EVENTPROV_REG__H_
  9. #define __EVENTPROV_REG__H_
  10. #include <time.h>
  11. #include <wbemidl.h>
  12. #include <arrtempl.h>
  13. #include <analyser.h>
  14. #include <evaltree.h>
  15. #include <sync.h>
  16. #include <filtprox.h>
  17. #include <unload.h>
  18. #include <postpone.h>
  19. #include <mtgtpckt.h>
  20. class CEventProviderCache;
  21. class CEventProviderWatchInstruction : public CBasicUnloadInstruction
  22. {
  23. protected:
  24. CEventProviderCache* m_pCache;
  25. static CWbemInterval mstatic_Interval;
  26. public:
  27. CEventProviderWatchInstruction(CEventProviderCache* pCache);
  28. static void staticInitialize(IWbemServices* pRoot);
  29. HRESULT Fire(long lNumTimes, CWbemTime NextFiringTime);
  30. };
  31. class CProviderSinkServer;
  32. class CFilterStub : public IWbemFilterStub, public IWbemMultiTarget,
  33. public IWbemFetchSmartMultiTarget, public IWbemSmartMultiTarget,
  34. public IWbemEventProviderRequirements
  35. {
  36. protected:
  37. CProviderSinkServer* m_pSink;
  38. CWbemClassCache m_ClassCache;
  39. public:
  40. CFilterStub(CProviderSinkServer* pSink) : m_pSink(pSink){}
  41. ULONG STDMETHODCALLTYPE AddRef();
  42. ULONG STDMETHODCALLTYPE Release();
  43. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv);
  44. HRESULT STDMETHODCALLTYPE RegisterProxy(IWbemFilterProxy* pProxy);
  45. HRESULT STDMETHODCALLTYPE UnregisterProxy(IWbemFilterProxy* pProxy);
  46. HRESULT STDMETHODCALLTYPE DeliverEvent(DWORD dwNumEvents,
  47. IWbemClassObject** apEvents,
  48. WBEM_REM_TARGETS* aTargets,
  49. long lSDLength, BYTE* pSD);
  50. HRESULT STDMETHODCALLTYPE DeliverStatus(long lFlags, HRESULT hresStatus,
  51. LPCWSTR wszStatus, IWbemClassObject* pErrorObj,
  52. WBEM_REM_TARGETS* aTargets,
  53. long lSDLength, BYTE* pSD);
  54. HRESULT STDMETHODCALLTYPE GetSmartMultiTarget(
  55. IWbemSmartMultiTarget** ppSmartMultiTarget );
  56. HRESULT STDMETHODCALLTYPE DeliverEvent(DWORD dwNumEvents, DWORD dwBuffSize,
  57. BYTE* pBuffer,
  58. WBEM_REM_TARGETS* aTargets,
  59. long lSDLength, BYTE* pSD);
  60. HRESULT STDMETHODCALLTYPE DeliverProviderRequest(long lFlags);
  61. };
  62. class CEssMetaData;
  63. class CProviderSinkServer : public IUnknown
  64. {
  65. public:
  66. struct CEventDestination
  67. {
  68. private:
  69. CEventDestination& operator=( const CEventDestination& ); // not impl
  70. public:
  71. WBEM_REMOTE_TARGET_ID_TYPE m_id;
  72. CAbstractEventSink* m_pSink;
  73. CEventDestination(WBEM_REMOTE_TARGET_ID_TYPE Id,
  74. CAbstractEventSink* pSink);
  75. CEventDestination(const CEventDestination& Other);
  76. ~CEventDestination();
  77. };
  78. typedef CUniquePointerArray<CEventDestination> TDestinationArray;
  79. protected:
  80. long m_lRef;
  81. CRefedPointerArray<IWbemFilterProxy> m_apProxies;
  82. TDestinationArray m_apDestinations;
  83. TDestinationArray m_apPreviousDestinations;
  84. WBEM_REMOTE_TARGET_ID_TYPE m_idNext;
  85. CWStringArray m_awsDefinitionQueries;
  86. IWbemLocalFilterProxy* m_pPseudoProxy;
  87. IWbemEventSink* m_pPseudoSink;
  88. CEssMetaData* m_pMetaData;
  89. CEssNamespace* m_pNamespace;
  90. IWbemEventProviderRequirements* m_pReqSink;
  91. CCritSec m_cs;
  92. long m_lLocks;
  93. protected:
  94. CFilterStub m_Stub;
  95. public:
  96. CProviderSinkServer();
  97. HRESULT Initialize(CEssNamespace* pNamespace,
  98. IWbemEventProviderRequirements* pReqSink);
  99. ~CProviderSinkServer();
  100. void Clear();
  101. HRESULT GetMainProxy(IWbemEventSink** ppSink);
  102. void GetStatistics(long* plProxies, long* plDestinations,
  103. long* plFilters, long* plTargetLists, long* plTargets,
  104. long* plPostponed);
  105. HRESULT GetDestinations(
  106. TDestinationArray& apDestinations);
  107. INTERNAL CEssNamespace* GetNamespace() {return m_pNamespace;}
  108. protected:
  109. HRESULT AddDestination(CAbstractEventSink* pDest,
  110. WBEM_REMOTE_TARGET_ID_TYPE* pID);
  111. BOOL GetProxies(CRefedPointerArray<IWbemFilterProxy>& apProxies);
  112. HRESULT FindDestinations(long lNum,
  113. IN WBEM_REMOTE_TARGET_ID_TYPE* aidTargets,
  114. RELEASE_ME CAbstractEventSink** apSinks);
  115. public:
  116. ULONG STDMETHODCALLTYPE AddRef();
  117. ULONG STDMETHODCALLTYPE Release();
  118. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv);
  119. HRESULT AddFilter(LPCWSTR wszQuery, QL_LEVEL_1_RPN_EXPRESSION* pExp,
  120. CAbstractEventSink* pDest,
  121. WBEM_REMOTE_TARGET_ID_TYPE* pidRequest = NULL);
  122. HRESULT RemoveFilter(CAbstractEventSink* pDest,
  123. WBEM_REMOTE_TARGET_ID_TYPE* pidRequest = NULL);
  124. void RemoveAllFilters();
  125. HRESULT AddDefinitionQuery(LPCWSTR wszQuery);
  126. HRESULT AllowUtilizeGuarantee();
  127. void RemoveAllDefinitionQueries();
  128. HRESULT Lock();
  129. void Unlock();
  130. public: // IWbemMultiTarget (forwarded)
  131. HRESULT STDMETHODCALLTYPE DeliverEvent(DWORD dwNumEvents,
  132. IWbemClassObject** apEvents,
  133. WBEM_REM_TARGETS* aTargets,
  134. CEventContext* pContext);
  135. HRESULT DeliverOneEvent(IWbemClassObject* pEvent,
  136. WBEM_REM_TARGETS* pTargets,
  137. CEventContext* pContext);
  138. HRESULT STDMETHODCALLTYPE DeliverStatus(long lFlags, HRESULT hresStatus,
  139. LPCWSTR wszStatus, IWbemClassObject* pErrorObj,
  140. WBEM_REM_TARGETS* aTargets,
  141. CEventContext* pContext);
  142. HRESULT MultiTargetDeliver(IWbemEvent* pEvent, WBEM_REM_TARGETS* pTargets,
  143. CEventContext* pContext);
  144. public: // IWbemFilterStub (forwarded)
  145. HRESULT STDMETHODCALLTYPE RegisterProxy(IWbemFilterProxy* pProxy);
  146. HRESULT STDMETHODCALLTYPE UnregisterProxy(IWbemFilterProxy* pProxy);
  147. public: // IWbemEventProviderRequirements (forwarded)
  148. HRESULT STDMETHODCALLTYPE DeliverProviderRequest(long lFlags);
  149. };
  150. class CEventProviderCache
  151. {
  152. private:
  153. class CRequest
  154. {
  155. private:
  156. CAbstractEventSink* m_pDest;
  157. LPWSTR m_wszQuery;
  158. QL_LEVEL_1_RPN_EXPRESSION* m_pExpr;
  159. IWbemClassObject* m_pEventClass;
  160. DWORD m_dwEventMask;
  161. CClassInfoArray* m_papInstanceClasses;
  162. public:
  163. CRequest(IN CAbstractEventSink* pDest, LPWSTR wszQuery,
  164. QL_LEVEL_1_RPN_EXPRESSION* pExp);
  165. ~CRequest();
  166. INTERNAL LPWSTR GetQuery() {return m_wszQuery;}
  167. INTERNAL CAbstractEventSink* GetDest() {return m_pDest;}
  168. INTERNAL QL_LEVEL_1_RPN_EXPRESSION* GetQueryExpr();
  169. DWORD GetEventMask();
  170. HRESULT GetInstanceClasses(CEssNamespace* pNamespace,
  171. INTERNAL CClassInfoArray** ppClasses);
  172. INTERNAL IWbemClassObject* GetEventClass(CEssNamespace* pNamespace);
  173. HRESULT CheckValidity(CEssNamespace* pNamespace);
  174. };
  175. class CRecord : IWbemEventProviderRequirements
  176. {
  177. class CQueryRecord
  178. {
  179. BSTR m_strQuery;
  180. IWbemClassObject* m_pEventClass;
  181. DWORD m_dwEventMask;
  182. CClassInfoArray* m_paInstanceClasses;
  183. QL_LEVEL_1_RPN_EXPRESSION* m_pExpr;
  184. public:
  185. CQueryRecord();
  186. HRESULT Initialize( COPY LPCWSTR wszQuery,
  187. LPCWSTR wszProvName,
  188. CEssNamespace* pNamespace,
  189. bool bSystem);
  190. ~CQueryRecord();
  191. HRESULT Update(LPCWSTR wszClassName, IWbemClassObject* pClass);
  192. HRESULT DoesIntersectWithQuery(CRequest& Request,
  193. CEssNamespace* pNamespace);
  194. DWORD GetProvidedEventMask(IWbemClassObject* pClass,
  195. BSTR strClassName);
  196. LPCWSTR GetQuery() {return m_strQuery;}
  197. HRESULT EnsureClasses( CEssNamespace* pNamespace );
  198. void ReleaseClasses();
  199. };
  200. friend class CEventProviderCache;
  201. public:
  202. long m_lRef;
  203. BSTR m_strNamespace;
  204. BSTR m_strName;
  205. BOOL m_bProviderSet;
  206. CUniquePointerArray<CQueryRecord> m_apQueries;
  207. long m_lUsageCount;
  208. long m_lPermUsageCount;
  209. BOOL m_bRecorded;
  210. BOOL m_bNeedsResync;
  211. CWbemTime m_LastUse;
  212. IWbemEventProvider* m_pProvider;
  213. IWbemEventProviderQuerySink* m_pQuerySink;
  214. IWbemEventProviderSecurity* m_pSecurity;
  215. CExecLine m_Line;
  216. bool m_bStarted;
  217. CEssNamespace* m_pNamespace;
  218. CProviderSinkServer* m_pMainSink;
  219. public:
  220. CRecord();
  221. HRESULT Initialize( LPCWSTR wszName, CEssNamespace* pNamespace );
  222. HRESULT SetProvider(IWbemClassObject* pWin32Prov);
  223. HRESULT SetProviderPointer(CEssNamespace* pNamespace,
  224. IWbemEventProvider* pProvider);
  225. HRESULT ResetProvider();
  226. HRESULT SetQueries(CEssNamespace* pNamespace,
  227. IWbemClassObject* pRegistration);
  228. HRESULT SetQueries(CEssNamespace* pNamespace, long lNumQueries,
  229. LPCWSTR* awszQueries);
  230. HRESULT ResetQueries();
  231. HRESULT Load(CEssNamespace* pNamespace);
  232. HRESULT DeactivateFilter(CAbstractEventSink* pDest);
  233. HRESULT CancelAllQueries();
  234. HRESULT STDMETHODCALLTYPE DeliverProviderRequest(long lFlags);
  235. static HRESULT GetProviderInfo(IWbemClassObject* pWin32Prov,
  236. BSTR& strName);
  237. static HRESULT GetRegistrationInfo(IWbemClassObject* pRegistration,
  238. BSTR& strName);
  239. HRESULT ActivateIfNeeded(IN CRequest& Request,
  240. IN CEssNamespace* pNamespace);
  241. BOOL NeedsResync() { return m_bNeedsResync; }
  242. void ResetNeedsResync() { m_bNeedsResync = FALSE; }
  243. BOOL IsEmpty();
  244. void ResetUsage();
  245. void CheckPermanentUsage();
  246. virtual bool DeactivateIfNotUsed();
  247. virtual bool IsUnloadable();
  248. HRESULT Update(LPCWSTR wszClassName, IWbemClassObject* pClass);
  249. DWORD GetProvidedEventMask(IWbemClassObject* pClass, BSTR strClassName);
  250. INTERNAL CProviderSinkServer* GetMainSink() {return m_pMainSink;}
  251. void Lock() {m_pMainSink->Lock();}
  252. void Unlock() {m_pMainSink->Unlock();}
  253. BOOL IsActive() {return (m_pProvider != NULL);}
  254. long GetUsageCount() {return m_lUsageCount;}
  255. ULONG STDMETHODCALLTYPE AddRef();
  256. ULONG STDMETHODCALLTYPE Release();
  257. STDMETHOD(QueryInterface)(REFIID riid, void** ppv) {return E_FAIL;}
  258. ~CRecord();
  259. protected:
  260. HRESULT Activate(CEssNamespace* pNamespace, CRequest* pRequest,
  261. WBEM_REMOTE_TARGET_ID_TYPE idRequest);
  262. HRESULT Deactivate( CAbstractEventSink* pDest,
  263. WBEM_REMOTE_TARGET_ID_TYPE idRequest);
  264. HRESULT AddActiveProviderEntryToRegistry();
  265. HRESULT RemoveActiveProviderEntryFromRegistry();
  266. HRESULT AddDefinitionQuery(CEssNamespace* pNamespace, LPCWSTR wszQuery);
  267. HRESULT Exec_LoadProvider(CEssNamespace* pNamespace);
  268. HRESULT Exec_StartProvider(CEssNamespace* pNamespace);
  269. HRESULT Exec_NewQuery(CEssNamespace* pNamespace,
  270. CExecLine::CTurn* pTurn, DWORD dwID,
  271. LPCWSTR wszLanguage, LPCWSTR wszQuery,
  272. CAbstractEventSink* pDest);
  273. HRESULT ActualExecNewQuery(CEssNamespace* pNamespace,
  274. DWORD dwID, LPCWSTR wszLanguage, LPCWSTR wszQuery,
  275. CAbstractEventSink* pDest);
  276. HRESULT Exec_CancelQuery(CEssNamespace* pNamespace,
  277. CExecLine::CTurn* pTurn, DWORD dwId);
  278. CExecLine::CTurn* GetInLine();
  279. void DiscardTurn(CExecLine::CTurn* pTurn);
  280. virtual HRESULT PostponeNewQuery(CExecLine::CTurn* pTurn, DWORD dwId,
  281. LPCWSTR wszQueryLanguage, LPCWSTR wszQuery,
  282. CAbstractEventSink* pDest);
  283. virtual HRESULT PostponeCancelQuery(CExecLine::CTurn* pTurn,
  284. DWORD dwId);
  285. void UnloadProvider();
  286. virtual bool IsSystem() {return false;}
  287. friend class CPostponedNewQuery;
  288. friend class CPostponedCancelQuery;
  289. friend class CPostponedProvideEvents;
  290. protected:
  291. };
  292. class CSystemRecord : public CRecord
  293. {
  294. public:
  295. virtual bool DeactivateIfNotUsed();
  296. virtual bool IsUnloadable();
  297. /* HRESULT PostponeNewQuery(CExecLine::CTurn* pTurn, DWORD dwId,
  298. LPCWSTR wszQueryLanguage, LPCWSTR wszQuery,
  299. CAbstractEventSink* pDest);
  300. HRESULT PostponeCancelQuery(CExecLine::CTurn* pTurn, DWORD dwId); */
  301. virtual bool IsSystem() {return true;}
  302. };
  303. friend class CPostponedNewQuery;
  304. friend class CPostponedCancelQuery;
  305. friend class CEventProviderWatchInstruction;
  306. friend class CPostponedProvideEvents;
  307. CRefedPointerArray<CRecord> m_aRecords;
  308. CEssNamespace* m_pNamespace;
  309. CEventProviderWatchInstruction* m_pInstruction;
  310. BOOL m_bInResync;
  311. protected:
  312. long FindRecord(LPCWSTR wszName);
  313. public:
  314. CEventProviderCache(CEssNamespace* pNamespace);
  315. ~CEventProviderCache();
  316. HRESULT Shutdown();
  317. HRESULT AddProvider(IWbemClassObject* pWin32Prov);
  318. HRESULT AddSystemProvider(IWbemEventProvider* pProvider, LPCWSTR wszName,
  319. long lNumQueries, LPCWSTR* awszQueries);
  320. HRESULT RemoveProvider(IWbemClassObject* pWin32Prov);
  321. HRESULT CheckProviderRegistration(IWbemClassObject* pRegistration);
  322. HRESULT AddProviderRegistration(IWbemClassObject* pRegistration);
  323. HRESULT RemoveProviderRegistration(IWbemClassObject* pRegistration);
  324. HRESULT LoadProvidersForQuery(LPWSTR wszQuery,
  325. QL_LEVEL_1_RPN_EXPRESSION* pExp,
  326. CAbstractEventSink* pDest);
  327. HRESULT ReleaseProvidersForQuery(CAbstractEventSink* pDest);
  328. DWORD GetProvidedEventMask(IWbemClassObject* pClass);
  329. HRESULT VirtuallyReleaseProviders();
  330. HRESULT CommitProviderUsage();
  331. HRESULT UnloadUnusedProviders(CWbemInterval Interval);
  332. void EnsureUnloadInstruction();
  333. void DumpStatistics(FILE* f, long lFlags);
  334. };
  335. class CPostponedNewQuery : public CPostponedRequest
  336. {
  337. protected:
  338. CEventProviderCache::CRecord* m_pRecord;
  339. DWORD m_dwId;
  340. CCompressedString* m_pcsQuery;
  341. CExecLine::CTurn* m_pTurn;
  342. CAbstractEventSink* m_pDest;
  343. public:
  344. CPostponedNewQuery(CEventProviderCache::CRecord* pRecord, DWORD dwId,
  345. LPCWSTR wszQueryLanguage, LPCWSTR wszQuery,
  346. CExecLine::CTurn* pTurn, CAbstractEventSink* pDest);
  347. ~CPostponedNewQuery();
  348. HRESULT Execute(CEssNamespace* pNamespace);
  349. BOOL DoesHoldTurn() { return TRUE; }
  350. void* operator new(size_t nSize);
  351. void operator delete(void* p);
  352. };
  353. class CPostponedCancelQuery : public CPostponedRequest
  354. {
  355. protected:
  356. DWORD m_dwId;
  357. CEventProviderCache::CRecord* m_pRecord;
  358. CExecLine::CTurn* m_pTurn;
  359. public:
  360. CPostponedCancelQuery(CEventProviderCache::CRecord* pRecord,
  361. CExecLine::CTurn* pTurn, DWORD dwId)
  362. : m_pRecord(pRecord), m_dwId(dwId), m_pTurn(pTurn)
  363. {
  364. m_pRecord->AddRef();
  365. }
  366. ~CPostponedCancelQuery()
  367. {
  368. if(m_pTurn)
  369. m_pRecord->DiscardTurn(m_pTurn);
  370. m_pRecord->Release();
  371. }
  372. HRESULT Execute(CEssNamespace* pNamespace)
  373. {
  374. HRESULT hres = m_pRecord->Exec_CancelQuery(pNamespace, m_pTurn, m_dwId);
  375. m_pTurn = NULL;
  376. return hres;
  377. }
  378. BOOL DoesHoldTurn() { return TRUE; }
  379. };
  380. class CPostponedProvideEvents : public CPostponedRequest
  381. {
  382. protected:
  383. DWORD m_dwId;
  384. CEventProviderCache::CRecord* m_pRecord;
  385. CExecLine::CTurn* m_pTurn;
  386. public:
  387. CPostponedProvideEvents(CEventProviderCache::CRecord* pRecord)
  388. : m_pRecord(pRecord)
  389. {
  390. m_pRecord->AddRef();
  391. }
  392. ~CPostponedProvideEvents()
  393. {
  394. m_pRecord->Release();
  395. }
  396. HRESULT Execute(CEssNamespace* pNamespace)
  397. {
  398. HRESULT hres = m_pRecord->Exec_StartProvider(pNamespace);
  399. return hres;
  400. }
  401. BOOL DoesHoldTurn() { return TRUE; }
  402. };
  403. class CPostponedSinkServerShutdown : public CPostponedRequest
  404. {
  405. protected:
  406. CWbemPtr<CProviderSinkServer> m_pSinkServer;
  407. public:
  408. CPostponedSinkServerShutdown( CProviderSinkServer* pSinkServer )
  409. : m_pSinkServer( pSinkServer ) { }
  410. HRESULT Execute( CEssNamespace* pNamespace )
  411. {
  412. m_pSinkServer->Clear();
  413. return WBEM_S_NO_ERROR;
  414. }
  415. };
  416. #endif