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.

2712 lines
58 KiB

  1. //***************************************************************************
  2. //
  3. // File:
  4. //
  5. // Module: MS SNMP Provider
  6. //
  7. // Purpose:
  8. //
  9. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. #define __UNICODE
  13. #include <precomp.h>
  14. #include "csmir.h"
  15. #include "handles.h"
  16. #include "classfac.h"
  17. #include "enum.h"
  18. #include <textdef.h>
  19. #include <helper.h>
  20. #include "bstring.h"
  21. #include <scopeguard.h>
  22. #ifdef ICECAP_PROFILE
  23. #include <icapexp.h>
  24. #endif
  25. extern CRITICAL_SECTION g_CriticalSection ;
  26. /*
  27. * CSmir:: Constructor and destructor
  28. *
  29. * Purpose:
  30. * Standard constructor and destructor for CSmir object
  31. * There should only ever be one CSmir object because it holds the
  32. * connection point object and controlls the access to the database.
  33. * When the database changes it flaggs the chamce using the conenction
  34. * point object. If you have more than one CSmir object you will miss
  35. * database changes. The class factory handles all of this.
  36. * Parameters: None
  37. *
  38. * Return Value: None
  39. */
  40. #pragma warning (disable:4355)
  41. CSmir :: CSmir ()
  42. :m_Interrogator(this), m_Administrator(this),
  43. m_Configuration(this)
  44. {
  45. //init reference count
  46. m_cRef=0;
  47. //increase the reference count in the class factory
  48. CSMIRClassFactory::objectsInProgress++;
  49. }
  50. #pragma warning (default:4355)
  51. CSmir :: ~CSmir ()
  52. {
  53. //decrease the reference count in the class factory
  54. CSMIRClassFactory::objectsInProgress--;
  55. }
  56. /*
  57. * CSmir::QueryInterface
  58. *
  59. * Purpose:
  60. * Manages the interfaces for this object which supports the IUnknown,
  61. * ISmirDatabase, ISmirInterrogator, and ISmirAdministrator interfaces.
  62. *
  63. * Parameters:
  64. * riid REFIID of the interface to return.
  65. * ppv PPVOID in which to store the pointer.
  66. *
  67. * Return Value:
  68. * SCODE NOERROR on success, E_NOINTERFACE if the
  69. * interface is not supported.
  70. */
  71. STDMETHODIMP CSmir::QueryInterface(IN REFIID riid, OUT PPVOID ppv)
  72. {
  73. SetStructuredExceptionHandler seh;
  74. try
  75. {
  76. /*this lock is to protect the caller from changing his own
  77. *parameter (ppv) whilst I am using it. This is unlikely and
  78. *he deserves what he gets if he does it but it is still worth
  79. *the effort.
  80. */
  81. criticalSection.Lock () ;
  82. //Always NULL the out-parameters
  83. *ppv=NULL;
  84. /*
  85. * IUnknown comes from CSmir. Note that here we do not need
  86. * to explicitly typecast the object pointer into an interface
  87. * pointer because the vtables are identical. If we had
  88. * additional virtual member functions in the object, we would
  89. * have to cast in order to set the right vtable.
  90. */
  91. /*CLSID_ISMIR_Database serves very little purpose but it does provide
  92. *an entry point from which you can ittetate the other interfaces; it
  93. *makes sense to create an CLSID_ISMIR_Database instance and move to the
  94. *other interfaces rather than picking one of the other interfaces as the
  95. *entry point.
  96. */
  97. if ((IID_IUnknown==riid)||(IID_ISMIR_Database == riid))
  98. *ppv=this;
  99. //Other interfaces come from contained classes
  100. if (IID_ISMIR_Interrogative==riid)
  101. *ppv=&m_Interrogator;
  102. if (IID_ISMIR_Administrative==riid)
  103. *ppv=&m_Administrator;
  104. if((IID_IConnectionPointContainer == riid)||(IID_ISMIR_Notify == riid))
  105. *ppv = sm_ConnectionObjects;
  106. if(IID_ISMIRWbemConfiguration == riid)
  107. *ppv = &m_Configuration;
  108. if (NULL==*ppv)
  109. {
  110. criticalSection.Unlock () ;
  111. return E_NOINTERFACE;
  112. }
  113. //AddRef any interface we'll return.
  114. ((LPUNKNOWN)*ppv)->AddRef();
  115. criticalSection.Unlock () ;
  116. return NOERROR;
  117. }
  118. catch(Structured_Exception e_SE)
  119. {
  120. return E_UNEXPECTED;
  121. }
  122. catch(Heap_Exception e_HE)
  123. {
  124. return E_OUTOFMEMORY;
  125. }
  126. catch(...)
  127. {
  128. return E_UNEXPECTED;
  129. }
  130. }
  131. /*
  132. * CSmir ::AddRef
  133. * CSmir::Release
  134. *
  135. * Reference counting members. When Release sees a zero count
  136. * the object destroys itself.
  137. */
  138. ULONG CSmir::AddRef(void)
  139. {
  140. SetStructuredExceptionHandler seh;
  141. try
  142. {
  143. /*The CSmir object is a shared resource (as long as there is at leasr
  144. *one connection object) so I must protect the reference count.
  145. */
  146. //increase the reference
  147. return InterlockedIncrement(&m_cRef);
  148. }
  149. catch(Structured_Exception e_SE)
  150. {
  151. return 0;
  152. }
  153. catch(Heap_Exception e_HE)
  154. {
  155. return 0;
  156. }
  157. catch(...)
  158. {
  159. return 0;
  160. }
  161. }
  162. ULONG CSmir::Release(void)
  163. {
  164. SetStructuredExceptionHandler seh;
  165. try
  166. {
  167. long ret;
  168. if (0!=(ret=InterlockedDecrement(&m_cRef)))
  169. {
  170. return ret;
  171. }
  172. delete this;
  173. return 0;
  174. }
  175. catch(Structured_Exception e_SE)
  176. {
  177. return 0;
  178. }
  179. catch(Heap_Exception e_HE)
  180. {
  181. return 0;
  182. }
  183. catch(...)
  184. {
  185. return 0;
  186. }
  187. }
  188. /*
  189. * CSmir::AddNotify
  190. * CSmir::DeleteNotify
  191. *
  192. * Purpose:
  193. * These methods provide the hooks into the notification interface.
  194. * The caller implements the ISMIRNotify and passes ti to AddNotify, AddNotify
  195. * marshals the connection point interface and calls Advise to add the
  196. * callers ISMIRNotify to the collection of objects to notify when the SMIR
  197. * changes. DeleteNotify does the opposite.
  198. *
  199. * Parameters:
  200. * pNotifySink The caller's ISMIRNotify implementation
  201. * pRichTea,lRichTea Cookie used to identify the caller's
  202. * ISMIRNotify (generated by CSmir)
  203. *
  204. * Return Value:
  205. * SCODE S_OK on success, WBEM_E_FAILED of failure, E_NOINTERFACE if the
  206. * interface is not supported, E_INVALIDARG if the parameters
  207. * are invalid
  208. */
  209. STDMETHODIMP CSmir :: AddNotify(IN ISMIRNotify *pNotifySink, OUT DWORD *pRichTea)
  210. {
  211. SetStructuredExceptionHandler seh;
  212. try
  213. {
  214. EnterCriticalSection ( & g_CriticalSection );
  215. ScopeGuard t_1 = MakeGuard ( LeaveCriticalSection , &g_CriticalSection ) ;
  216. if (sm_ConnectionObjects == NULL)
  217. {
  218. sm_ConnectionObjects = new CSmirConnObject(this);
  219. sm_ConnectionObjects->AddRef ();
  220. }
  221. t_1.Dismiss () ;
  222. LeaveCriticalSection ( & g_CriticalSection );
  223. /*make sure that I don't get deleted whilst doing this. I should not have
  224. *to do this since it can only happen if the caller releases the interface
  225. *whilst making the call.
  226. */
  227. if (NULL == pNotifySink)
  228. {
  229. return WBEM_E_FAILED;
  230. }
  231. /*I do not need a lock for this piece of code; having found the interface someone
  232. *could release it from beneath me but the FindConnectionPoint causes an addref
  233. *so I can rely on m_ConnectionObjects to keep his own house in order.
  234. */
  235. IConnectionPoint *pCP = NULL ;
  236. SCODE hr = sm_ConnectionObjects->FindConnectionPoint(IID_ISMIR_Notify, &pCP);
  237. if ((S_OK != hr)||(NULL == pCP))
  238. {
  239. return WBEM_E_FAILED;
  240. }
  241. hr = ((CSmirNotifyCP*)(pCP))->Advise(this, pNotifySink, pRichTea);
  242. pCP->Release();
  243. if (S_OK != hr)
  244. {
  245. return WBEM_E_FAILED;
  246. }
  247. return ((S_OK == hr)?S_OK:WBEM_E_FAILED);
  248. }
  249. catch(Structured_Exception e_SE)
  250. {
  251. return E_UNEXPECTED;
  252. }
  253. catch(Heap_Exception e_HE)
  254. {
  255. return E_OUTOFMEMORY;
  256. }
  257. catch(...)
  258. {
  259. return E_UNEXPECTED;
  260. }
  261. }
  262. STDMETHODIMP CSmir :: DeleteNotify(IN DWORD lRichTea)
  263. {
  264. SetStructuredExceptionHandler seh;
  265. try
  266. {
  267. EnterCriticalSection ( & g_CriticalSection ) ;
  268. ScopeGuard t_1 = MakeGuard ( LeaveCriticalSection , &g_CriticalSection ) ;
  269. if (sm_ConnectionObjects == NULL)
  270. {
  271. return WBEM_E_FAILED;
  272. }
  273. t_1.Dismiss () ;
  274. LeaveCriticalSection ( & g_CriticalSection );
  275. /*I don't need to lock the SMIR object until the unadvise but it
  276. *is safer and future proof if I do it here.
  277. */
  278. SCODE hr=S_OK;
  279. /*I do not need a lock for this piece of code; having found the interface someone
  280. *could release it from beneath me but the FindConnectionPoint causes an addref
  281. *so I can rely on m_ConnectionObjects to keep his own house in order.
  282. */
  283. IConnectionPoint *pCP = NULL;
  284. hr=sm_ConnectionObjects->FindConnectionPoint(IID_ISMIR_Notify, &pCP);
  285. if (hr != S_OK||(NULL == pCP))
  286. {
  287. return CONNECT_E_NOCONNECTION;
  288. }
  289. hr=((CSmirNotifyCP*)(pCP))->Unadvise(this, lRichTea);
  290. pCP->Release();
  291. return ((S_OK == hr)?S_OK:CONNECT_E_NOCONNECTION==hr?E_INVALIDARG:WBEM_E_FAILED);
  292. }
  293. catch(Structured_Exception e_SE)
  294. {
  295. return E_UNEXPECTED;
  296. }
  297. catch(Heap_Exception e_HE)
  298. {
  299. return E_OUTOFMEMORY;
  300. }
  301. catch(...)
  302. {
  303. return E_UNEXPECTED;
  304. }
  305. }
  306. /*CSmirInterrogator interface implementation
  307. * Constructor/destructor
  308. * CSmirInterrogator::QueryInterface
  309. * CSmirInterrogator::AddRef
  310. * CSmirInterrogator::Release
  311. *
  312. * IUnknown members that delegate to m_pSmir
  313. */
  314. CSmirInterrogator :: CSmirInterrogator ( CSmir *pSmir ) : m_cRef ( 1 ) , m_pSmir ( pSmir )
  315. {
  316. }
  317. STDMETHODIMP CSmirInterrogator::QueryInterface(IN REFIID riid, OUT PPVOID ppv)
  318. {
  319. SetStructuredExceptionHandler seh;
  320. try
  321. {
  322. return m_pSmir->QueryInterface(riid, ppv);
  323. }
  324. catch(Structured_Exception e_SE)
  325. {
  326. return E_UNEXPECTED;
  327. }
  328. catch(Heap_Exception e_HE)
  329. {
  330. return E_OUTOFMEMORY;
  331. }
  332. catch(...)
  333. {
  334. return E_UNEXPECTED;
  335. }
  336. }
  337. ULONG CSmirInterrogator::AddRef(void)
  338. {
  339. SetStructuredExceptionHandler seh;
  340. try
  341. {
  342. /*
  343. * We maintain an "interface reference count" for debugging
  344. * purposes, because the client of an object should match
  345. * AddRef and Release calls through each interface pointer.
  346. */
  347. ++m_cRef;
  348. return m_pSmir->AddRef();
  349. }
  350. catch(Structured_Exception e_SE)
  351. {
  352. return 0;
  353. }
  354. catch(Heap_Exception e_HE)
  355. {
  356. return 0;
  357. }
  358. catch(...)
  359. {
  360. return 0;
  361. }
  362. }
  363. ULONG CSmirInterrogator::Release(void)
  364. {
  365. SetStructuredExceptionHandler seh;
  366. try
  367. {
  368. /*
  369. * m_cRef is again only for debugging. It doesn't affect
  370. * CSmirInterrogator although the call to m_pSmir->Release does.
  371. */
  372. --m_cRef;
  373. return m_pSmir->Release();
  374. //do not do anything after this release because you may have been deleted
  375. }
  376. catch(Structured_Exception e_SE)
  377. {
  378. return 0;
  379. }
  380. catch(Heap_Exception e_HE)
  381. {
  382. return 0;
  383. }
  384. catch(...)
  385. {
  386. return 0;
  387. }
  388. }
  389. /* Interface implementations for the enumerator access methods
  390. *
  391. * CSmirInterrogator::EnumModules
  392. * CSmirInterrogator::EnumGroups
  393. * CSmirInterrogator::EnumClasses
  394. *
  395. * Parameters:
  396. * Return Value:
  397. * SCODE S_OK on success, WBEM_E_FAILED of failure
  398. *
  399. */
  400. SCODE CSmirInterrogator::EnumModules(OUT IEnumModule **ppEnumSmirMod)
  401. {
  402. SetStructuredExceptionHandler seh;
  403. try
  404. {
  405. if(NULL == ppEnumSmirMod)
  406. return E_INVALIDARG;
  407. PENUMSMIRMOD pTmpEnumSmirMod = new CEnumSmirMod ( m_pSmir ) ;
  408. //we have an enumerator so get the interface to pass back
  409. if(NULL == pTmpEnumSmirMod)
  410. {
  411. return E_OUTOFMEMORY;
  412. }
  413. pTmpEnumSmirMod->QueryInterface(IID_ISMIR_ModuleEnumerator,(void**)ppEnumSmirMod);
  414. return S_OK;
  415. }
  416. catch(Structured_Exception e_SE)
  417. {
  418. return E_UNEXPECTED;
  419. }
  420. catch(Heap_Exception e_HE)
  421. {
  422. return E_OUTOFMEMORY;
  423. }
  424. catch(...)
  425. {
  426. return E_UNEXPECTED;
  427. }
  428. }
  429. SCODE CSmirInterrogator:: EnumGroups (OUT IEnumGroup **ppEnumSmirGroup,
  430. IN ISmirModHandle *hModule)
  431. {
  432. SetStructuredExceptionHandler seh;
  433. try
  434. {
  435. if (NULL == ppEnumSmirGroup)
  436. return E_INVALIDARG;
  437. PENUMSMIRGROUP pTmpEnumSmirGroup = new CEnumSmirGroup( m_pSmir , hModule);
  438. if(NULL == pTmpEnumSmirGroup)
  439. {
  440. return E_OUTOFMEMORY;
  441. }
  442. //we have an enumerator so get the interface to pass back
  443. pTmpEnumSmirGroup->QueryInterface(IID_ISMIR_GroupEnumerator,(void**)ppEnumSmirGroup);
  444. return S_OK;
  445. }
  446. catch(Structured_Exception e_SE)
  447. {
  448. return E_UNEXPECTED;
  449. }
  450. catch(Heap_Exception e_HE)
  451. {
  452. return E_OUTOFMEMORY;
  453. }
  454. catch(...)
  455. {
  456. return E_UNEXPECTED;
  457. }
  458. }
  459. SCODE CSmirInterrogator :: EnumAllClasses (OUT IEnumClass **ppEnumSmirclass)
  460. {
  461. SetStructuredExceptionHandler seh;
  462. try
  463. {
  464. if (NULL == ppEnumSmirclass)
  465. return E_INVALIDARG;
  466. PENUMSMIRCLASS pTmpEnumSmirClass = new CEnumSmirClass ( m_pSmir ) ;
  467. //we have an enumerator so get the interface to pass back
  468. if(NULL == pTmpEnumSmirClass)
  469. {
  470. return E_OUTOFMEMORY;
  471. }
  472. pTmpEnumSmirClass->QueryInterface(IID_ISMIR_ClassEnumerator,(void**)ppEnumSmirclass);
  473. return S_OK;
  474. }
  475. catch(Structured_Exception e_SE)
  476. {
  477. return E_UNEXPECTED;
  478. }
  479. catch(Heap_Exception e_HE)
  480. {
  481. return E_OUTOFMEMORY;
  482. }
  483. catch(...)
  484. {
  485. return E_UNEXPECTED;
  486. }
  487. }
  488. SCODE CSmirInterrogator :: EnumClassesInGroup (OUT IEnumClass **ppEnumSmirclass,
  489. IN ISmirGroupHandle *hGroup)
  490. {
  491. SetStructuredExceptionHandler seh;
  492. try
  493. {
  494. if (NULL == ppEnumSmirclass)
  495. return E_INVALIDARG;
  496. PENUMSMIRCLASS pTmpEnumSmirClass = new CEnumSmirClass(m_pSmir , NULL,hGroup);
  497. //we have an enumerator so get the interface to pass back
  498. if(NULL == pTmpEnumSmirClass)
  499. {
  500. return E_OUTOFMEMORY;
  501. }
  502. pTmpEnumSmirClass->QueryInterface(IID_ISMIR_ClassEnumerator,(void**)ppEnumSmirclass);
  503. return S_OK;
  504. }
  505. catch(Structured_Exception e_SE)
  506. {
  507. return E_UNEXPECTED;
  508. }
  509. catch(Heap_Exception e_HE)
  510. {
  511. return E_OUTOFMEMORY;
  512. }
  513. catch(...)
  514. {
  515. return E_UNEXPECTED;
  516. }
  517. }
  518. SCODE CSmirInterrogator :: EnumClassesInModule (OUT IEnumClass **ppEnumSmirclass,
  519. IN ISmirModHandle *hModule)
  520. {
  521. SetStructuredExceptionHandler seh;
  522. try
  523. {
  524. if (NULL == ppEnumSmirclass)
  525. return E_INVALIDARG;
  526. PENUMSMIRCLASS pTmpEnumSmirClass = new CEnumSmirClass(m_pSmir , NULL, hModule);
  527. //we have an enumerator so get the interface to pass back
  528. if(NULL == pTmpEnumSmirClass)
  529. {
  530. return E_OUTOFMEMORY;
  531. }
  532. pTmpEnumSmirClass->QueryInterface(IID_ISMIR_ClassEnumerator,(void**)ppEnumSmirclass);
  533. return S_OK;
  534. }
  535. catch(Structured_Exception e_SE)
  536. {
  537. return E_UNEXPECTED;
  538. }
  539. catch(Heap_Exception e_HE)
  540. {
  541. return E_OUTOFMEMORY;
  542. }
  543. catch(...)
  544. {
  545. return E_UNEXPECTED;
  546. }
  547. }
  548. SCODE CSmirInterrogator :: GetWBEMClass(OUT IWbemClassObject **ppClass, IN BSTR pszClassName)
  549. {
  550. SetStructuredExceptionHandler seh;
  551. try
  552. {
  553. if((NULL == pszClassName)||(NULL == ppClass))
  554. return E_INVALIDARG;
  555. IWbemServices * moServ = NULL ;
  556. IWbemContext *moContext = NULL ;
  557. SCODE res= CSmirAccess :: GetContext (m_pSmir , &moContext);
  558. res= CSmirAccess :: Open(m_pSmir , &moServ);
  559. if ((S_FALSE==res)||(NULL == (void*)moServ))
  560. {
  561. if ( moContext )
  562. moContext->Release () ;
  563. //we have a problem the SMIR is not there and cannot be created
  564. return WBEM_E_FAILED;
  565. }
  566. CBString t_BStr ( pszClassName ) ;
  567. res = moServ->GetObject(t_BStr.GetString (),RESERVED_WBEM_FLAG, moContext,ppClass,NULL);
  568. if ( moContext )
  569. moContext->Release () ;
  570. moServ->Release();
  571. if ((S_FALSE==res)||(NULL == *ppClass))
  572. {
  573. return WBEM_E_FAILED;
  574. }
  575. return S_OK;
  576. }
  577. catch(Structured_Exception e_SE)
  578. {
  579. return E_UNEXPECTED;
  580. }
  581. catch(Heap_Exception e_HE)
  582. {
  583. return E_OUTOFMEMORY;
  584. }
  585. catch(...)
  586. {
  587. return E_UNEXPECTED;
  588. }
  589. }
  590. SCODE CSmirInterrogator :: EnumAllNotificationClasses(IEnumNotificationClass **ppEnumSmirclass)
  591. {
  592. SetStructuredExceptionHandler seh;
  593. try
  594. {
  595. if (NULL == ppEnumSmirclass)
  596. return E_INVALIDARG;
  597. PENUMNOTIFICATIONCLASS pTmpEnumSmirClass = new CEnumNotificationClass ( m_pSmir ) ;
  598. //we have an enumerator so get the interface to pass back
  599. if(NULL == pTmpEnumSmirClass)
  600. {
  601. return E_OUTOFMEMORY;
  602. }
  603. pTmpEnumSmirClass->QueryInterface(IID_ISMIR_EnumNotificationClass,(void**)ppEnumSmirclass);
  604. return S_OK;
  605. }
  606. catch(Structured_Exception e_SE)
  607. {
  608. return E_UNEXPECTED;
  609. }
  610. catch(Heap_Exception e_HE)
  611. {
  612. return E_OUTOFMEMORY;
  613. }
  614. catch(...)
  615. {
  616. return E_UNEXPECTED;
  617. }
  618. }
  619. SCODE CSmirInterrogator :: EnumAllExtNotificationClasses(IEnumExtNotificationClass **ppEnumSmirclass)
  620. {
  621. SetStructuredExceptionHandler seh;
  622. try
  623. {
  624. if (NULL == ppEnumSmirclass)
  625. return E_INVALIDARG;
  626. PENUMEXTNOTIFICATIONCLASS pTmpEnumSmirClass = new CEnumExtNotificationClass ( m_pSmir ) ;
  627. //we have an enumerator so get the interface to pass back
  628. if(NULL == pTmpEnumSmirClass)
  629. {
  630. return E_OUTOFMEMORY;
  631. }
  632. pTmpEnumSmirClass->QueryInterface(IID_ISMIR_EnumExtNotificationClass,(void**)ppEnumSmirclass);
  633. return S_OK;
  634. }
  635. catch(Structured_Exception e_SE)
  636. {
  637. return E_UNEXPECTED;
  638. }
  639. catch(Heap_Exception e_HE)
  640. {
  641. return E_OUTOFMEMORY;
  642. }
  643. catch(...)
  644. {
  645. return E_UNEXPECTED;
  646. }
  647. }
  648. SCODE CSmirInterrogator :: EnumNotificationClassesInModule(IEnumNotificationClass **ppEnumSmirclass,
  649. ISmirModHandle *hModule)
  650. {
  651. SetStructuredExceptionHandler seh;
  652. try
  653. {
  654. if (NULL == ppEnumSmirclass)
  655. return E_INVALIDARG;
  656. PENUMNOTIFICATIONCLASS pTmpEnumSmirClass = new CEnumNotificationClass( m_pSmir , NULL, hModule);
  657. //we have an enumerator so get the interface to pass back
  658. if(NULL == pTmpEnumSmirClass)
  659. {
  660. return E_OUTOFMEMORY;
  661. }
  662. pTmpEnumSmirClass->QueryInterface(IID_ISMIR_EnumNotificationClass,(void**)ppEnumSmirclass);
  663. return S_OK;
  664. }
  665. catch(Structured_Exception e_SE)
  666. {
  667. return E_UNEXPECTED;
  668. }
  669. catch(Heap_Exception e_HE)
  670. {
  671. return E_OUTOFMEMORY;
  672. }
  673. catch(...)
  674. {
  675. return E_UNEXPECTED;
  676. }
  677. }
  678. SCODE CSmirInterrogator :: EnumExtNotificationClassesInModule(IEnumExtNotificationClass **ppEnumSmirclass,
  679. ISmirModHandle *hModule)
  680. {
  681. SetStructuredExceptionHandler seh;
  682. try
  683. {
  684. if (NULL == ppEnumSmirclass)
  685. return E_INVALIDARG;
  686. PENUMEXTNOTIFICATIONCLASS pTmpEnumSmirClass = new CEnumExtNotificationClass( m_pSmir , NULL, hModule);
  687. //we have an enumerator so get the interface to pass back
  688. if(NULL == pTmpEnumSmirClass)
  689. {
  690. return E_OUTOFMEMORY;
  691. }
  692. pTmpEnumSmirClass->QueryInterface(IID_ISMIR_EnumExtNotificationClass,(void**)ppEnumSmirclass);
  693. return S_OK;
  694. }
  695. catch(Structured_Exception e_SE)
  696. {
  697. return E_UNEXPECTED;
  698. }
  699. catch(Heap_Exception e_HE)
  700. {
  701. return E_OUTOFMEMORY;
  702. }
  703. catch(...)
  704. {
  705. return E_UNEXPECTED;
  706. }
  707. }
  708. /*
  709. * CSmirAdministrator::QueryInterface
  710. * CSmirAdministrator::AddRef
  711. * CSmirAdministrator::Release
  712. *
  713. * IUnknown members that delegate to m_pSmir
  714. */
  715. CSmirAdministrator :: CSmirAdministrator ( CSmir *pSmir ) : m_cRef ( 1 ) , m_pSmir ( pSmir )
  716. {
  717. }
  718. STDMETHODIMP CSmirAdministrator::QueryInterface(IN REFIID riid,
  719. OUT PPVOID ppv)
  720. {
  721. SetStructuredExceptionHandler seh;
  722. try
  723. {
  724. return m_pSmir->QueryInterface(riid, ppv);
  725. }
  726. catch(Structured_Exception e_SE)
  727. {
  728. return E_UNEXPECTED;
  729. }
  730. catch(Heap_Exception e_HE)
  731. {
  732. return E_OUTOFMEMORY;
  733. }
  734. catch(...)
  735. {
  736. return E_UNEXPECTED;
  737. }
  738. }
  739. ULONG CSmirAdministrator::AddRef(void)
  740. {
  741. SetStructuredExceptionHandler seh;
  742. try
  743. {
  744. /*
  745. * We maintain an "interface reference count" for debugging
  746. * purposes, because the client of an object should match
  747. * AddRef and Release calls through each interface pointer.
  748. */
  749. ++m_cRef;
  750. return m_pSmir->AddRef();
  751. }
  752. catch(Structured_Exception e_SE)
  753. {
  754. return 0;
  755. }
  756. catch(Heap_Exception e_HE)
  757. {
  758. return 0;
  759. }
  760. catch(...)
  761. {
  762. return 0;
  763. }
  764. }
  765. ULONG CSmirAdministrator::Release(void)
  766. {
  767. SetStructuredExceptionHandler seh;
  768. try
  769. {
  770. /*
  771. * m_cRef is again only for debugging. It doesn't affect
  772. * CObject2 although the call to m_pObj->Release does.
  773. */
  774. --m_cRef;
  775. return m_pSmir->Release();
  776. //do not do anything after this release because you may have been deleted
  777. }
  778. catch(Structured_Exception e_SE)
  779. {
  780. return 0;
  781. }
  782. catch(Heap_Exception e_HE)
  783. {
  784. return 0;
  785. }
  786. catch(...)
  787. {
  788. return 0;
  789. }
  790. }
  791. SCODE CSmirAdministrator :: GetSerialiseHandle(ISmirSerialiseHandle **hSerialise,BOOL bClassDefinitionsOnly)
  792. {
  793. SetStructuredExceptionHandler seh;
  794. try
  795. {
  796. if(NULL ==hSerialise)
  797. {
  798. return E_INVALIDARG;
  799. }
  800. CSmirSerialiseHandle *pSerialise = new CSmirSerialiseHandle(bClassDefinitionsOnly);
  801. //we have an enumerator so get the interface to pass back
  802. if(NULL == pSerialise)
  803. {
  804. return E_OUTOFMEMORY;
  805. }
  806. pSerialise->QueryInterface(IID_ISMIR_SerialiseHandle,(void**)hSerialise);
  807. return S_OK;
  808. }
  809. catch(Structured_Exception e_SE)
  810. {
  811. return E_UNEXPECTED;
  812. }
  813. catch(Heap_Exception e_HE)
  814. {
  815. return E_OUTOFMEMORY;
  816. }
  817. catch(...)
  818. {
  819. return E_UNEXPECTED;
  820. }
  821. }
  822. /*
  823. * CSmirAdministrator::AddModule
  824. * Purpose: Creates the module namespace in the SMIR
  825. * Parameters:
  826. * ISmirModHandle* A module handle interface obtained through ISmirModHandle and
  827. * filled in by the called
  828. * Return Value:
  829. * SCODE S_OK on success, WBEM_E_FAILED of failure
  830. */
  831. SCODE CSmirAdministrator :: AddModuleToSerialise(ISmirModHandle *hModule,
  832. ISmirSerialiseHandle *hSerialise)
  833. {
  834. SetStructuredExceptionHandler seh;
  835. try
  836. {
  837. if(NULL ==hSerialise || NULL == hModule)
  838. {
  839. return E_INVALIDARG;
  840. }
  841. if((*((CSmirModuleHandle*)hModule))!=NULL)
  842. {
  843. *((CSmirModuleHandle*)hModule)>>hSerialise;
  844. return S_OK;
  845. }
  846. else
  847. return E_INVALIDARG;
  848. }
  849. catch(Structured_Exception e_SE)
  850. {
  851. return E_UNEXPECTED;
  852. }
  853. catch(Heap_Exception e_HE)
  854. {
  855. return E_OUTOFMEMORY;
  856. }
  857. catch(...)
  858. {
  859. return E_UNEXPECTED;
  860. }
  861. }
  862. SCODE CSmirAdministrator :: AddClassToSerialise(ISmirGroupHandle *hGroup,
  863. ISmirClassHandle *hClass,
  864. ISmirSerialiseHandle *hSerialise)
  865. {
  866. SetStructuredExceptionHandler seh;
  867. try
  868. {
  869. if(NULL ==hSerialise || NULL == hClass || NULL == hGroup)
  870. {
  871. return E_INVALIDARG;
  872. }
  873. BSTR szGroupName=NULL;
  874. BSTR szModuleName=NULL;
  875. hGroup->GetName(&szGroupName);
  876. hGroup->GetModuleName(&szModuleName);
  877. hClass->SetGroupName(szGroupName);
  878. hClass->SetModuleName(szModuleName);
  879. SysFreeString(szModuleName);
  880. SysFreeString(szGroupName);
  881. if(*((CSmirClassHandle*)hClass)!=NULL )
  882. {
  883. //it is a valid handle so serialise it
  884. *((CSmirClassHandle*)hClass)>>hSerialise;
  885. return S_OK;
  886. }
  887. return E_INVALIDARG;
  888. }
  889. catch(Structured_Exception e_SE)
  890. {
  891. return E_UNEXPECTED;
  892. }
  893. catch(Heap_Exception e_HE)
  894. {
  895. return E_OUTOFMEMORY;
  896. }
  897. catch(...)
  898. {
  899. return E_UNEXPECTED;
  900. }
  901. }
  902. SCODE CSmirAdministrator :: AddGroupToSerialise(ISmirModHandle *hModule,
  903. ISmirGroupHandle *hGroup,
  904. ISmirSerialiseHandle *hSerialise)
  905. {
  906. SetStructuredExceptionHandler seh;
  907. try
  908. {
  909. if(NULL ==hSerialise || NULL == hGroup|| NULL == hModule)
  910. {
  911. return E_INVALIDARG;
  912. }
  913. BSTR szModuleName=NULL;
  914. hModule->GetName(&szModuleName);
  915. hGroup->SetModuleName(szModuleName);
  916. //clean up
  917. SysFreeString(szModuleName);
  918. if(*((CSmirGroupHandle*)hGroup)!=NULL)
  919. {
  920. //do the serialise
  921. *((CSmirGroupHandle*)hGroup)>>hSerialise;
  922. return S_OK;
  923. }
  924. //either the modfule or group name were not set so it is an error
  925. return E_INVALIDARG;
  926. }
  927. catch(Structured_Exception e_SE)
  928. {
  929. return E_UNEXPECTED;
  930. }
  931. catch(Heap_Exception e_HE)
  932. {
  933. return E_OUTOFMEMORY;
  934. }
  935. catch(...)
  936. {
  937. return E_UNEXPECTED;
  938. }
  939. }
  940. SCODE CSmirAdministrator :: AddModule(IN ISmirModHandle *hModule)
  941. {
  942. SetStructuredExceptionHandler seh;
  943. try
  944. {
  945. if (NULL == hModule)
  946. {
  947. return E_INVALIDARG;
  948. }
  949. if(S_OK==((CSmirModuleHandle*)hModule)->AddToDB(m_pSmir))
  950. {
  951. //notify people of the change
  952. return S_OK ;
  953. }
  954. return WBEM_E_FAILED ;
  955. }
  956. catch(Structured_Exception e_SE)
  957. {
  958. return E_UNEXPECTED;
  959. }
  960. catch(Heap_Exception e_HE)
  961. {
  962. return E_OUTOFMEMORY;
  963. }
  964. catch(...)
  965. {
  966. return E_UNEXPECTED;
  967. }
  968. }
  969. /*
  970. * CSmirAdministrator::DeleteModule
  971. * Purpose: Delete the module namespace from the SMIR
  972. * Parameters:
  973. * ISmirModHandle* A module handle interface obtained through ISmirModHandle and
  974. * filled in by the called
  975. * Return Value:
  976. * SCODE S_OK on success, WBEM_E_FAILED of failure
  977. */
  978. SCODE CSmirAdministrator :: DeleteModule(IN ISmirModHandle *hModule)
  979. {
  980. SetStructuredExceptionHandler seh;
  981. try
  982. {
  983. //check the arguments
  984. if(NULL == hModule)
  985. {
  986. return E_INVALIDARG;
  987. }
  988. if(S_OK==((CSmirModuleHandle *)hModule)->DeleteFromDB(m_pSmir))
  989. {
  990. return S_OK;
  991. }
  992. return WBEM_E_FAILED;
  993. }
  994. catch(Structured_Exception e_SE)
  995. {
  996. return E_UNEXPECTED;
  997. }
  998. catch(Heap_Exception e_HE)
  999. {
  1000. return E_OUTOFMEMORY;
  1001. }
  1002. catch(...)
  1003. {
  1004. return E_UNEXPECTED;
  1005. }
  1006. }
  1007. /*
  1008. * CSmirAdministrator::DeleteAllModules
  1009. * Purpose: Delete the SMIR
  1010. * Parameters:
  1011. * ISmirModHandle* A module handle interface obtained through ISmirModHandle and
  1012. * filled in by the called
  1013. * Return Value:
  1014. * SCODE S_OK on success, WBEM_E_FAILED of failure
  1015. */
  1016. SCODE CSmirAdministrator :: DeleteAllModules()
  1017. {
  1018. SetStructuredExceptionHandler seh;
  1019. try
  1020. {
  1021. //enumerate all modules and delete them...
  1022. IEnumModule *pEnumSmirMod = NULL;
  1023. SCODE result = m_pSmir->m_Interrogator.EnumModules(&pEnumSmirMod);
  1024. if((S_OK != result)||(NULL == pEnumSmirMod))
  1025. {
  1026. //no modules
  1027. return WBEM_NO_ERROR;
  1028. }
  1029. ISmirModHandle *phModule = NULL ;
  1030. for(int iCount=0;S_OK==pEnumSmirMod->Next(1, &phModule, NULL);iCount++)
  1031. {
  1032. //we have the module so delete it...
  1033. if (FAILED(DeleteModule(phModule)))
  1034. {
  1035. result = WBEM_E_FAILED;
  1036. }
  1037. phModule->Release();
  1038. }
  1039. pEnumSmirMod->Release();
  1040. return result;
  1041. }
  1042. catch(Structured_Exception e_SE)
  1043. {
  1044. return E_UNEXPECTED;
  1045. }
  1046. catch(Heap_Exception e_HE)
  1047. {
  1048. return E_OUTOFMEMORY;
  1049. }
  1050. catch(...)
  1051. {
  1052. return E_UNEXPECTED;
  1053. }
  1054. }
  1055. /*
  1056. * CSmirAdministrator::AddGroup
  1057. * Purpose: Delete the group namespace from the SMIR
  1058. * Parameters:
  1059. * ISmirModHandle* A module handle interface
  1060. * ISmirGroupHandle* A group handle interface obtained through ISmirModHandle and
  1061. * filled in by the called
  1062. * Return Value:
  1063. * SCODE S_OK on success, WBEM_E_FAILED of failure
  1064. */
  1065. SCODE CSmirAdministrator :: AddGroup(IN ISmirModHandle *hModule,
  1066. IN ISmirGroupHandle *hGroup)
  1067. {
  1068. SetStructuredExceptionHandler seh;
  1069. try
  1070. {
  1071. //check the args
  1072. if((NULL == hModule)||(NULL == hGroup))
  1073. {
  1074. //MyTraceEvent.Generate(__FILE__,__LINE__, "E_INVALIDARG");
  1075. return E_INVALIDARG;
  1076. }
  1077. if(S_OK==((CSmirGroupHandle *)hGroup)->AddToDB(m_pSmir,hModule))
  1078. {
  1079. return S_OK;
  1080. }
  1081. return WBEM_E_FAILED;
  1082. }
  1083. catch(Structured_Exception e_SE)
  1084. {
  1085. return E_UNEXPECTED;
  1086. }
  1087. catch(Heap_Exception e_HE)
  1088. {
  1089. return E_OUTOFMEMORY;
  1090. }
  1091. catch(...)
  1092. {
  1093. return E_UNEXPECTED;
  1094. }
  1095. }
  1096. SCODE CSmirAdministrator :: DeleteGroup(IN ISmirGroupHandle *hGroup)
  1097. {
  1098. SetStructuredExceptionHandler seh;
  1099. try
  1100. {
  1101. //fill in the path etc
  1102. if(NULL ==hGroup)
  1103. {
  1104. return E_INVALIDARG;
  1105. }
  1106. if ( FAILED( ((CSmirGroupHandle*)hGroup)->DeleteFromDB(m_pSmir) ) )
  1107. {
  1108. return WBEM_E_FAILED;
  1109. }
  1110. return S_OK;
  1111. }
  1112. catch(Structured_Exception e_SE)
  1113. {
  1114. return E_UNEXPECTED;
  1115. }
  1116. catch(Heap_Exception e_HE)
  1117. {
  1118. return E_OUTOFMEMORY;
  1119. }
  1120. catch(...)
  1121. {
  1122. return E_UNEXPECTED;
  1123. }
  1124. }
  1125. SCODE CSmirAdministrator :: AddClass(IN ISmirGroupHandle *hGroup,
  1126. IN ISmirClassHandle *hClass)
  1127. {
  1128. SetStructuredExceptionHandler seh;
  1129. try
  1130. {
  1131. //check the parameters
  1132. if((NULL == hGroup)||(NULL == hClass)||
  1133. (NULL == ((CSmirClassHandle*)hClass)->m_pIMosClass))
  1134. {
  1135. return E_INVALIDARG;
  1136. }
  1137. if(S_OK==((CSmirClassHandle*)hClass)->AddToDB(m_pSmir,hGroup))
  1138. {
  1139. return S_OK;
  1140. }
  1141. return WBEM_E_FAILED;
  1142. }
  1143. catch(Structured_Exception e_SE)
  1144. {
  1145. return E_UNEXPECTED;
  1146. }
  1147. catch(Heap_Exception e_HE)
  1148. {
  1149. return E_OUTOFMEMORY;
  1150. }
  1151. catch(...)
  1152. {
  1153. return E_UNEXPECTED;
  1154. }
  1155. }
  1156. SCODE CSmirAdministrator :: DeleteClass(IN ISmirClassHandle *hClass)
  1157. {
  1158. SetStructuredExceptionHandler seh;
  1159. try
  1160. {
  1161. //check the parameters
  1162. if((NULL == hClass)||(NULL == ((CSmirClassHandle*)hClass)->m_pIMosClass))
  1163. {
  1164. return E_INVALIDARG;
  1165. }
  1166. //Let the class do it's own work
  1167. ((CSmirClassHandle*)hClass)->DeleteFromDB( m_pSmir);
  1168. return S_OK;
  1169. }
  1170. catch(Structured_Exception e_SE)
  1171. {
  1172. return E_UNEXPECTED;
  1173. }
  1174. catch(Heap_Exception e_HE)
  1175. {
  1176. return E_OUTOFMEMORY;
  1177. }
  1178. catch(...)
  1179. {
  1180. return E_UNEXPECTED;
  1181. }
  1182. }
  1183. SCODE CSmirAdministrator :: AddNotificationClass(ISmirNotificationClassHandle *hClass)
  1184. {
  1185. SetStructuredExceptionHandler seh;
  1186. try
  1187. {
  1188. //check the parameter
  1189. if((NULL == hClass) ||
  1190. ((CSmirNotificationClassHandle*)NULL == *((CSmirNotificationClassHandle*)hClass)))
  1191. {
  1192. return E_INVALIDARG;
  1193. }
  1194. if(S_OK==((CSmirNotificationClassHandle*)hClass)->AddToDB(m_pSmir))
  1195. {
  1196. return S_OK;
  1197. }
  1198. return WBEM_E_FAILED;
  1199. //release the handles via the garbage collector
  1200. }
  1201. catch(Structured_Exception e_SE)
  1202. {
  1203. return E_UNEXPECTED;
  1204. }
  1205. catch(Heap_Exception e_HE)
  1206. {
  1207. return E_OUTOFMEMORY;
  1208. }
  1209. catch(...)
  1210. {
  1211. return E_UNEXPECTED;
  1212. }
  1213. }
  1214. SCODE CSmirAdministrator :: AddExtNotificationClass(ISmirExtNotificationClassHandle *hClass)
  1215. {
  1216. SetStructuredExceptionHandler seh;
  1217. try
  1218. {
  1219. //check the parameter
  1220. if((NULL == hClass) ||
  1221. ((CSmirExtNotificationClassHandle*)NULL == *((CSmirExtNotificationClassHandle*)hClass)))
  1222. {
  1223. return E_INVALIDARG;
  1224. }
  1225. if(S_OK==((CSmirExtNotificationClassHandle*)hClass)->AddToDB(m_pSmir))
  1226. {
  1227. return S_OK;
  1228. }
  1229. return WBEM_E_FAILED;
  1230. //release the handles via the garbage collector
  1231. }
  1232. catch(Structured_Exception e_SE)
  1233. {
  1234. return E_UNEXPECTED;
  1235. }
  1236. catch(Heap_Exception e_HE)
  1237. {
  1238. return E_OUTOFMEMORY;
  1239. }
  1240. catch(...)
  1241. {
  1242. return E_UNEXPECTED;
  1243. }
  1244. }
  1245. SCODE CSmirAdministrator :: DeleteNotificationClass(ISmirNotificationClassHandle *hClass)
  1246. {
  1247. SetStructuredExceptionHandler seh;
  1248. try
  1249. {
  1250. //check the parameters
  1251. if((NULL == hClass)||(NULL == ((CSmirNotificationClassHandle*)hClass)->m_pIMosClass))
  1252. {
  1253. return E_INVALIDARG;
  1254. }
  1255. //Let the class do it's own work
  1256. ((CSmirNotificationClassHandle*)hClass)->DeleteFromDB(m_pSmir);
  1257. return S_OK;
  1258. }
  1259. catch(Structured_Exception e_SE)
  1260. {
  1261. return E_UNEXPECTED;
  1262. }
  1263. catch(Heap_Exception e_HE)
  1264. {
  1265. return E_OUTOFMEMORY;
  1266. }
  1267. catch(...)
  1268. {
  1269. return E_UNEXPECTED;
  1270. }
  1271. }
  1272. SCODE CSmirAdministrator :: DeleteExtNotificationClass(ISmirExtNotificationClassHandle *hClass)
  1273. {
  1274. SetStructuredExceptionHandler seh;
  1275. try
  1276. {
  1277. //check the parameters
  1278. if((NULL == hClass)||(NULL == ((CSmirExtNotificationClassHandle*)hClass)->m_pIMosClass))
  1279. {
  1280. return E_INVALIDARG;
  1281. }
  1282. //Let the class do it's own work
  1283. ((CSmirExtNotificationClassHandle*)hClass)->DeleteFromDB(m_pSmir);
  1284. return S_OK;
  1285. }
  1286. catch(Structured_Exception e_SE)
  1287. {
  1288. return E_UNEXPECTED;
  1289. }
  1290. catch(Heap_Exception e_HE)
  1291. {
  1292. return E_OUTOFMEMORY;
  1293. }
  1294. catch(...)
  1295. {
  1296. return E_UNEXPECTED;
  1297. }
  1298. }
  1299. SCODE CSmirAdministrator :: AddNotificationClassToSerialise(ISmirNotificationClassHandle *hClass, ISmirSerialiseHandle *hSerialise)
  1300. {
  1301. SetStructuredExceptionHandler seh;
  1302. try
  1303. {
  1304. if(NULL ==hSerialise || NULL == hClass)
  1305. {
  1306. return E_INVALIDARG;
  1307. }
  1308. if(*((CSmirNotificationClassHandle*)hClass) !=NULL )
  1309. {
  1310. //it is a valid handle so serialise it
  1311. *((CSmirNotificationClassHandle*)hClass)>>hSerialise;
  1312. return S_OK;
  1313. }
  1314. return E_INVALIDARG;
  1315. }
  1316. catch(Structured_Exception e_SE)
  1317. {
  1318. return E_UNEXPECTED;
  1319. }
  1320. catch(Heap_Exception e_HE)
  1321. {
  1322. return E_OUTOFMEMORY;
  1323. }
  1324. catch(...)
  1325. {
  1326. return E_UNEXPECTED;
  1327. }
  1328. }
  1329. SCODE CSmirAdministrator :: AddExtNotificationClassToSerialise(ISmirExtNotificationClassHandle *hClass, ISmirSerialiseHandle *hSerialise)
  1330. {
  1331. SetStructuredExceptionHandler seh;
  1332. try
  1333. {
  1334. if(NULL ==hSerialise || NULL == hClass)
  1335. {
  1336. return E_INVALIDARG;
  1337. }
  1338. if(*((CSmirExtNotificationClassHandle*)hClass) !=NULL )
  1339. {
  1340. //it is a valid handle so serialise it
  1341. *((CSmirExtNotificationClassHandle*)hClass)>>hSerialise;
  1342. return S_OK;
  1343. }
  1344. return E_INVALIDARG;
  1345. }
  1346. catch(Structured_Exception e_SE)
  1347. {
  1348. return E_UNEXPECTED;
  1349. }
  1350. catch(Heap_Exception e_HE)
  1351. {
  1352. return E_OUTOFMEMORY;
  1353. }
  1354. catch(...)
  1355. {
  1356. return E_UNEXPECTED;
  1357. }
  1358. }
  1359. SCODE CSmirAdministrator :: CreateWBEMClass(
  1360. BSTR pszClassName,
  1361. ISmirClassHandle **pHandle
  1362. )
  1363. {
  1364. SetStructuredExceptionHandler seh;
  1365. try
  1366. {
  1367. if (NULL == pHandle)
  1368. return E_INVALIDARG;
  1369. *pHandle = NULL ;
  1370. //open the smir name space
  1371. IWbemServices * moServ = NULL ;
  1372. IWbemContext *moContext = NULL ;
  1373. SCODE result= CSmirAccess :: GetContext (m_pSmir, &moContext);
  1374. result= CSmirAccess :: Open(m_pSmir,&moServ);
  1375. if(FAILED(result)||(NULL == moServ))
  1376. {
  1377. if ( moContext )
  1378. moContext->Release () ;
  1379. return WBEM_E_FAILED ;
  1380. }
  1381. IWbemClassObject *baseClass = NULL ;
  1382. //OK we have the namespace so create the class
  1383. CBString t_BStr ( HMOM_SNMPOBJECTTYPE_STRING ) ;
  1384. result = moServ->GetObject(t_BStr.GetString (), RESERVED_WBEM_FLAG,
  1385. moContext,&baseClass,NULL);
  1386. //finished with this
  1387. if ( moContext )
  1388. moContext->Release () ;
  1389. moServ->Release();
  1390. if (FAILED(result)||(NULL==baseClass))
  1391. {
  1392. return WBEM_E_FAILED;
  1393. }
  1394. IWbemClassObject *t_MosClass = NULL ;
  1395. result = baseClass->SpawnDerivedClass (0 , &t_MosClass);
  1396. baseClass->Release () ;
  1397. if ( ! SUCCEEDED ( result ) )
  1398. {
  1399. return WBEM_E_FAILED;
  1400. }
  1401. //name the class __CLASS Class
  1402. VARIANT v;
  1403. VariantInit(&v);
  1404. V_VT(&v) = VT_BSTR;
  1405. V_BSTR(&v)=SysAllocString(pszClassName);
  1406. result = t_MosClass->Put(OLEMS_CLASS_PROP,RESERVED_WBEM_FLAG, &v,0);
  1407. VariantClear(&v);
  1408. if (FAILED(result))
  1409. {
  1410. t_MosClass->Release();
  1411. return WBEM_E_FAILED;
  1412. }
  1413. ISmirClassHandle *classHandle = NULL;
  1414. result = CoCreateInstance (
  1415. CLSID_SMIR_ClassHandle ,
  1416. NULL ,
  1417. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
  1418. IID_ISMIR_ClassHandle,
  1419. (PPVOID)&classHandle
  1420. );
  1421. if ( SUCCEEDED ( result ) )
  1422. {
  1423. classHandle->SetWBEMClass ( t_MosClass ) ;
  1424. *pHandle = classHandle ;
  1425. t_MosClass->Release();
  1426. }
  1427. else
  1428. {
  1429. t_MosClass->Release();
  1430. return WBEM_E_FAILED;
  1431. }
  1432. return S_OK ;
  1433. }
  1434. catch(Structured_Exception e_SE)
  1435. {
  1436. return E_UNEXPECTED;
  1437. }
  1438. catch(Heap_Exception e_HE)
  1439. {
  1440. return E_OUTOFMEMORY;
  1441. }
  1442. catch(...)
  1443. {
  1444. return E_UNEXPECTED;
  1445. }
  1446. }
  1447. SCODE CSmirAdministrator :: CreateWBEMNotificationClass(
  1448. BSTR pszClassName,
  1449. ISmirNotificationClassHandle **pHandle
  1450. )
  1451. {
  1452. SetStructuredExceptionHandler seh;
  1453. try
  1454. {
  1455. if (NULL == pHandle)
  1456. return E_INVALIDARG;
  1457. *pHandle = NULL ;
  1458. //open the smir name space
  1459. IWbemServices * moServ = NULL ;
  1460. IWbemContext *moContext = NULL ;
  1461. SCODE result= CSmirAccess :: GetContext (m_pSmir , &moContext);
  1462. result= CSmirAccess :: Open(m_pSmir, &moServ);
  1463. if(FAILED(result)||(NULL == moServ))
  1464. {
  1465. if ( moContext )
  1466. moContext->Release () ;
  1467. return WBEM_E_FAILED ;
  1468. }
  1469. IWbemClassObject *baseClass = NULL ;
  1470. //OK we have the namespace so create the class
  1471. CBString t_BStr ( NOTIFICATION_CLASS_NAME ) ;
  1472. result = moServ->GetObject(t_BStr.GetString (), RESERVED_WBEM_FLAG,
  1473. moContext,&baseClass, NULL);
  1474. //finished with this
  1475. if ( moContext )
  1476. moContext->Release () ;
  1477. moServ->Release();
  1478. if (FAILED(result)||(NULL==baseClass))
  1479. {
  1480. return WBEM_E_FAILED;
  1481. }
  1482. IWbemClassObject *t_MosClass = NULL ;
  1483. result = baseClass->SpawnDerivedClass (0 , &t_MosClass);
  1484. baseClass->Release () ;
  1485. if ( ! SUCCEEDED ( result ) )
  1486. {
  1487. return WBEM_E_FAILED;
  1488. }
  1489. //name the class __CLASS Class
  1490. VARIANT v;
  1491. VariantInit(&v);
  1492. V_VT(&v) = VT_BSTR;
  1493. V_BSTR(&v)=SysAllocString(pszClassName);
  1494. result = t_MosClass->Put(OLEMS_CLASS_PROP,RESERVED_WBEM_FLAG, &v,0);
  1495. VariantClear(&v);
  1496. if (FAILED(result))
  1497. {
  1498. t_MosClass->Release();
  1499. return WBEM_E_FAILED;
  1500. }
  1501. ISmirNotificationClassHandle *classHandle = NULL;
  1502. result = CoCreateInstance (
  1503. CLSID_SMIR_NotificationClassHandle ,
  1504. NULL ,
  1505. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
  1506. IID_ISMIR_NotificationClassHandle,
  1507. (PPVOID)&classHandle
  1508. );
  1509. if ( SUCCEEDED ( result ) )
  1510. {
  1511. classHandle->SetWBEMNotificationClass ( t_MosClass ) ;
  1512. t_MosClass->Release();
  1513. *pHandle = classHandle ;
  1514. }
  1515. else
  1516. {
  1517. t_MosClass->Release();
  1518. return WBEM_E_FAILED;
  1519. }
  1520. return S_OK;
  1521. }
  1522. catch(Structured_Exception e_SE)
  1523. {
  1524. return E_UNEXPECTED;
  1525. }
  1526. catch(Heap_Exception e_HE)
  1527. {
  1528. return E_OUTOFMEMORY;
  1529. }
  1530. catch(...)
  1531. {
  1532. return E_UNEXPECTED;
  1533. }
  1534. }
  1535. SCODE CSmirAdministrator :: CreateWBEMExtNotificationClass (
  1536. BSTR pszClassName,
  1537. ISmirExtNotificationClassHandle **pHandle
  1538. )
  1539. {
  1540. SetStructuredExceptionHandler seh;
  1541. try
  1542. {
  1543. if (NULL == pHandle)
  1544. return E_INVALIDARG;
  1545. *pHandle = NULL ;
  1546. //open the smir name space
  1547. IWbemServices * moServ = NULL ;
  1548. IWbemContext *moContext = NULL ;
  1549. SCODE result= CSmirAccess :: GetContext (m_pSmir , &moContext);
  1550. result= CSmirAccess :: Open(m_pSmir ,&moServ);
  1551. if(FAILED(result)||(NULL == moServ))
  1552. {
  1553. if ( moContext )
  1554. moContext->Release () ;
  1555. return WBEM_E_FAILED ;
  1556. }
  1557. IWbemClassObject *baseClass = NULL ;
  1558. //OK we have the namespace so create the class
  1559. CBString t_BStr ( HMOM_SNMPEXTNOTIFICATIONTYPE_STRING ) ;
  1560. result = moServ->GetObject(t_BStr.GetString () , RESERVED_WBEM_FLAG,
  1561. moContext,&baseClass, NULL);
  1562. //finished with this
  1563. if ( moContext )
  1564. moContext->Release () ;
  1565. moServ->Release();
  1566. if (FAILED(result)||(NULL==baseClass))
  1567. {
  1568. return WBEM_E_FAILED;
  1569. }
  1570. IWbemClassObject *t_MosClass = NULL ;
  1571. result = baseClass->SpawnDerivedClass (0 , &t_MosClass );
  1572. baseClass->Release () ;
  1573. if ( ! SUCCEEDED ( result ) )
  1574. {
  1575. return WBEM_E_FAILED;
  1576. }
  1577. //name the class __CLASS Class
  1578. VARIANT v;
  1579. VariantInit(&v);
  1580. V_VT(&v) = VT_BSTR;
  1581. V_BSTR(&v)=SysAllocString(pszClassName);
  1582. result = t_MosClass->Put(OLEMS_CLASS_PROP,RESERVED_WBEM_FLAG, &v,0);
  1583. VariantClear(&v);
  1584. if (FAILED(result))
  1585. {
  1586. t_MosClass->Release();
  1587. return WBEM_E_FAILED;
  1588. }
  1589. ISmirExtNotificationClassHandle *classHandle = NULL;
  1590. result = CoCreateInstance (
  1591. CLSID_SMIR_ExtNotificationClassHandle ,
  1592. NULL ,
  1593. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
  1594. IID_ISMIR_ExtNotificationClassHandle,
  1595. (PPVOID)&classHandle
  1596. );
  1597. if ( SUCCEEDED ( result ) )
  1598. {
  1599. classHandle->SetWBEMExtNotificationClass ( t_MosClass ) ;
  1600. t_MosClass->Release();
  1601. *pHandle = classHandle ;
  1602. }
  1603. else
  1604. {
  1605. t_MosClass->Release();
  1606. return WBEM_E_FAILED;
  1607. }
  1608. return S_OK;
  1609. }
  1610. catch(Structured_Exception e_SE)
  1611. {
  1612. return E_UNEXPECTED;
  1613. }
  1614. catch(Heap_Exception e_HE)
  1615. {
  1616. return E_OUTOFMEMORY;
  1617. }
  1618. catch(...)
  1619. {
  1620. return E_UNEXPECTED;
  1621. }
  1622. }
  1623. /*
  1624. * CSmirSerialiseHandle::QueryInterface
  1625. *
  1626. * Purpose:
  1627. * Manages the interfaces for this object which supports the
  1628. * IUnknown interface.
  1629. *
  1630. * Parameters:
  1631. * riid REFIID of the interface to return.
  1632. * ppv PPVOID in which to store the pointer.
  1633. *
  1634. * Return Value:
  1635. * SCODE NOERROR on success, E_NOINTERFACE if the
  1636. * interface is not supported.
  1637. */
  1638. STDMETHODIMP CSmirSerialiseHandle::QueryInterface(REFIID riid, PPVOID ppv)
  1639. {
  1640. SetStructuredExceptionHandler seh;
  1641. try
  1642. {
  1643. //Always NULL the out-parameters
  1644. *ppv=NULL;
  1645. if (IID_IUnknown==riid)
  1646. *ppv=this;
  1647. if (IID_ISMIR_SerialiseHandle==riid)
  1648. *ppv=this;
  1649. if (NULL==*ppv)
  1650. return ResultFromScode(E_NOINTERFACE);
  1651. //AddRef any interface we'll return.
  1652. ((LPUNKNOWN)*ppv)->AddRef();
  1653. return NOERROR;
  1654. }
  1655. catch(Structured_Exception e_SE)
  1656. {
  1657. return E_UNEXPECTED;
  1658. }
  1659. catch(Heap_Exception e_HE)
  1660. {
  1661. return E_OUTOFMEMORY;
  1662. }
  1663. catch(...)
  1664. {
  1665. return E_UNEXPECTED;
  1666. }
  1667. }
  1668. /*
  1669. * CSmirSerialiseHandle::AddRef
  1670. * CSmirSerialiseHandle::Release
  1671. *
  1672. * Reference counting members. When Release sees a zero count
  1673. * the object destroys itself.
  1674. */
  1675. ULONG CSmirSerialiseHandle::AddRef(void)
  1676. {
  1677. SetStructuredExceptionHandler seh;
  1678. try
  1679. {
  1680. return InterlockedIncrement(&m_cRef);
  1681. }
  1682. catch(Structured_Exception e_SE)
  1683. {
  1684. return 0;
  1685. }
  1686. catch(Heap_Exception e_HE)
  1687. {
  1688. return 0;
  1689. }
  1690. catch(...)
  1691. {
  1692. return 0;
  1693. }
  1694. }
  1695. ULONG CSmirSerialiseHandle::Release(void)
  1696. {
  1697. SetStructuredExceptionHandler seh;
  1698. try
  1699. {
  1700. long ret;
  1701. if (0!=(ret=InterlockedDecrement(&m_cRef)))
  1702. return ret;
  1703. delete this;
  1704. return 0;
  1705. }
  1706. catch(Structured_Exception e_SE)
  1707. {
  1708. return 0;
  1709. }
  1710. catch(Heap_Exception e_HE)
  1711. {
  1712. return 0;
  1713. }
  1714. catch(...)
  1715. {
  1716. return 0;
  1717. }
  1718. }
  1719. CSmirSerialiseHandle :: CSmirSerialiseHandle(BOOL bClassDefinitionsOnly)
  1720. {
  1721. m_cRef=0;
  1722. //I have two variables so that I can expand this at a later date
  1723. m_bMOFPragmas = m_bMOFAssociations = !bClassDefinitionsOnly;
  1724. m_serialiseString=QUALIFIER_PROPAGATION;
  1725. //start in the root\default namespace
  1726. if (TRUE == m_bMOFPragmas)
  1727. m_serialiseString+=CString(ROOT_DEFAULT_NAMESPACE_PRAGMA);
  1728. /**************************************************************************
  1729. * create the SMIR namespace class
  1730. **************************************************************************/
  1731. if(TRUE == m_bMOFAssociations)
  1732. {
  1733. /******************then create an instance*********************************/
  1734. m_serialiseString+=SMIR_CLASS_DEFINITION;
  1735. m_serialiseString+=SMIR_INSTANCE_DEFINITION;
  1736. }
  1737. //go to the SMIR namespace
  1738. if (TRUE == m_bMOFPragmas)
  1739. m_serialiseString+=CString(SMIR_NAMESPACE_PRAGMA);
  1740. /******************create the SnmpMacro class******************************/
  1741. m_serialiseString+=SNMPMACRO_CLASS_START;
  1742. //end the class definition
  1743. m_serialiseString+=END_OF_CLASS;
  1744. /******************create the SnmpObjectType class*************************/
  1745. m_serialiseString+=SNMPOBJECTTYPE_CLASS_START;
  1746. //end the class definition
  1747. m_serialiseString+=END_OF_CLASS;
  1748. /******************create the SnmpNotifyStatus class*************************/
  1749. m_serialiseString+=SNMPNOTIFYSTATUS_CLASS_START;
  1750. //end the class definition
  1751. m_serialiseString+=END_OF_CLASS;
  1752. /****************if asked for, create the SMIR specific stuff****************/
  1753. if(TRUE == m_bMOFAssociations)
  1754. {
  1755. /******************create the SnmpNotification class*********************/
  1756. m_serialiseString+=SNMPNOTIFICATION_CLASS_START;
  1757. //add the properties
  1758. m_serialiseString+=TIMESTAMP_QUALS_TYPE;
  1759. m_serialiseString+=CString(TIMESTAMP_PROP);
  1760. m_serialiseString+=END_OF_PROPERTY;
  1761. m_serialiseString+=TRAPOID_QUALS_TYPE;
  1762. m_serialiseString+=CString(TRAPOID_PROP);
  1763. m_serialiseString+=END_OF_PROPERTY;
  1764. m_serialiseString+=SENDER_ADDR_QUALS_TYPE;
  1765. m_serialiseString+=CString(SENDER_ADDR_PROP);
  1766. m_serialiseString+=END_OF_PROPERTY;
  1767. m_serialiseString+=SENDER_TADDR_QUALS_TYPE;
  1768. m_serialiseString+=CString(SENDER_TADDR_PROP);
  1769. m_serialiseString+=END_OF_PROPERTY;
  1770. m_serialiseString+=TRANSPORT_QUALS_TYPE;
  1771. m_serialiseString+=CString(TRANSPORT_PROP);
  1772. m_serialiseString+=END_OF_PROPERTY;
  1773. m_serialiseString+=COMMUNITY_QUALS_TYPE;
  1774. m_serialiseString+=CString(COMMUNITY_PROP);
  1775. m_serialiseString+=END_OF_PROPERTY;
  1776. //end the class definition
  1777. m_serialiseString+=END_OF_CLASS;
  1778. /******************create the SnmpExtendedNotification class*************/
  1779. m_serialiseString+=SNMPEXTNOTIFICATION_CLASS_START;
  1780. //add the properties
  1781. m_serialiseString+=TIMESTAMP_QUALS_TYPE;
  1782. m_serialiseString+=CString(TIMESTAMP_PROP);
  1783. m_serialiseString+=END_OF_PROPERTY;
  1784. m_serialiseString+=TRAPOID_QUALS_TYPE;
  1785. m_serialiseString+=CString(TRAPOID_PROP);
  1786. m_serialiseString+=END_OF_PROPERTY;
  1787. m_serialiseString+=SENDER_ADDR_QUALS_TYPE;
  1788. m_serialiseString+=CString(SENDER_ADDR_PROP);
  1789. m_serialiseString+=END_OF_PROPERTY;
  1790. m_serialiseString+=SENDER_TADDR_QUALS_TYPE;
  1791. m_serialiseString+=CString(SENDER_TADDR_PROP);
  1792. m_serialiseString+=END_OF_PROPERTY;
  1793. m_serialiseString+=TRANSPORT_QUALS_TYPE;
  1794. m_serialiseString+=CString(TRANSPORT_PROP);
  1795. m_serialiseString+=END_OF_PROPERTY;
  1796. m_serialiseString+=COMMUNITY_QUALS_TYPE;
  1797. m_serialiseString+=CString(COMMUNITY_PROP);
  1798. m_serialiseString+=END_OF_PROPERTY;
  1799. //end the class definition
  1800. m_serialiseString+=END_OF_CLASS;
  1801. /******************create the NotificationMapper class*********************/
  1802. m_serialiseString+=NOTIFICATIONMAPPER_CLASS_START;
  1803. //add the two properies..
  1804. m_serialiseString+=READ_ONLY_KEY_STRING;
  1805. m_serialiseString+=CString(SMIR_NOTIFICATION_TRAP_PROP);
  1806. m_serialiseString+=END_OF_PROPERTY;
  1807. m_serialiseString+=READONLY_STRING;
  1808. m_serialiseString+=CString(SMIR_NOTIFICATION_CLASS_PROP);
  1809. m_serialiseString+=END_OF_PROPERTY;
  1810. //end the class definition
  1811. m_serialiseString+=END_OF_CLASS;
  1812. /******************create the ExtendedNotificationMapper class*************/
  1813. m_serialiseString+=EXTNOTIFICATIONMAPPER_CLASS_START;
  1814. //add the two properies..
  1815. m_serialiseString+=READ_ONLY_KEY_STRING;
  1816. m_serialiseString+=CString(SMIR_NOTIFICATION_TRAP_PROP);
  1817. m_serialiseString+=END_OF_PROPERTY;
  1818. m_serialiseString+=READONLY_STRING;
  1819. m_serialiseString+=CString(SMIR_NOTIFICATION_CLASS_PROP);
  1820. m_serialiseString+=END_OF_PROPERTY;
  1821. //end the class definition
  1822. m_serialiseString+=END_OF_CLASS;
  1823. /******************create the module class*****************************/
  1824. m_serialiseString+=MODULE_CLASS_START;
  1825. //add the properties
  1826. //give the instance a name
  1827. m_serialiseString+=READONLY_STRING;
  1828. m_serialiseString+=CString(MODULE_NAME_PROPERTY);
  1829. m_serialiseString+=END_OF_PROPERTY;
  1830. //add the module oid property
  1831. m_serialiseString+=READONLY_STRING;
  1832. m_serialiseString+=CString(MODULE_OID_PROPERTY);
  1833. m_serialiseString+=END_OF_PROPERTY;
  1834. //add the module identity
  1835. m_serialiseString+=READONLY_STRING;
  1836. m_serialiseString+=CString(MODULE_ID_PROPERTY);
  1837. m_serialiseString+=END_OF_PROPERTY;
  1838. //add the organisation property
  1839. m_serialiseString+=READONLY_STRING;
  1840. m_serialiseString+=CString(MODULE_ORG_PROPERTY);
  1841. m_serialiseString+=END_OF_PROPERTY;
  1842. //add the contact info property
  1843. m_serialiseString+=READONLY_STRING;
  1844. m_serialiseString+=CString(MODULE_CONTACT_PROPERTY);
  1845. m_serialiseString+=END_OF_PROPERTY;
  1846. //add the Description property
  1847. m_serialiseString+=READONLY_STRING;
  1848. m_serialiseString+=CString(MODULE_DESCRIPTION_PROPERTY);
  1849. m_serialiseString+=END_OF_PROPERTY;
  1850. //add the revision property
  1851. m_serialiseString+=READONLY_STRING;
  1852. m_serialiseString+=CString(MODULE_REVISION_PROPERTY);
  1853. m_serialiseString+=END_OF_PROPERTY;
  1854. //add the last update property
  1855. m_serialiseString+=READONLY_STRING;
  1856. m_serialiseString+=CString(MODULE_LAST_UPDATE_PROPERTY);
  1857. m_serialiseString+=END_OF_PROPERTY;
  1858. //add the snmp version property
  1859. m_serialiseString+=READONLY_LONG;
  1860. m_serialiseString+=CString(MODULE_SNMP_VERSION_PROPERTY);
  1861. m_serialiseString+=END_OF_PROPERTY;
  1862. //add the module imports as an property
  1863. m_serialiseString+=READONLY_STRING;
  1864. m_serialiseString+=CString(MODULE_IMPORTS_PROPERTY);
  1865. m_serialiseString+=END_OF_PROPERTY;
  1866. //end the class definition
  1867. m_serialiseString+=END_OF_CLASS;
  1868. #if 0
  1869. //each module will create it's own instance
  1870. /**************************************************************************
  1871. * create the SMIR Associator class
  1872. *[assoc]
  1873. *class SmirToClassAssociator
  1874. *{
  1875. *[read, key] AssocName;
  1876. *[read] ClassName;
  1877. *[read] SmirName;
  1878. *};
  1879. *
  1880. **************************************************************************/
  1881. m_serialiseString+=ASSOC_QUALIFIER;
  1882. m_serialiseString+=CString(CLASS_STRING);
  1883. m_serialiseString+=CString(SMIR_ASSOC_CLASS_NAME);
  1884. m_serialiseString+=CString(NEWLINE_STR);
  1885. m_serialiseString+=CString(OPEN_BRACE_STR);
  1886. m_serialiseString+=CString(NEWLINE_STR);
  1887. m_serialiseString+=READ_ONLY_KEY_STRING;
  1888. m_serialiseString+=CString(SMIR_X_ASSOC_NAME_PROP);
  1889. m_serialiseString+=END_OF_PROPERTY;
  1890. m_serialiseString+=READ_ONLY_REF_STRING;
  1891. m_serialiseString+=CString(SMIR_X_ASSOC_CLASS_PROP);
  1892. m_serialiseString+=END_OF_PROPERTY;
  1893. m_serialiseString+=READ_ONLY_REF_STRING;
  1894. m_serialiseString+=CString(SMIR_ASSOC_SMIR_PROP);
  1895. m_serialiseString+=END_OF_PROPERTY;
  1896. m_serialiseString+=END_OF_CLASS;
  1897. #endif
  1898. /**************************************************************************
  1899. * create the Module Associator class
  1900. *[assoc]
  1901. *class SmirToClassAssociator
  1902. *{
  1903. *[read, key] AssocName;
  1904. *[read] ClassName;
  1905. *[read] SmirName;
  1906. *};
  1907. *
  1908. **************************************************************************/
  1909. m_serialiseString+=ASSOC_QUALIFIER;
  1910. m_serialiseString+=CString(CLASS_STRING);
  1911. m_serialiseString+=CString(SMIR_MODULE_ASSOC_CLASS_NAME);
  1912. m_serialiseString+=CString(NEWLINE_STR);
  1913. m_serialiseString+=CString(OPEN_BRACE_STR);
  1914. m_serialiseString+=CString(NEWLINE_STR);
  1915. m_serialiseString+=READ_ONLY_KEY_STRING;
  1916. m_serialiseString+=CString(SMIR_X_ASSOC_NAME_PROP);
  1917. m_serialiseString+=END_OF_PROPERTY;
  1918. m_serialiseString+=READ_ONLY_REF_STRING;
  1919. m_serialiseString+=CString(SMIR_X_ASSOC_CLASS_PROP);
  1920. m_serialiseString+=END_OF_PROPERTY;
  1921. m_serialiseString+=READ_ONLY_REF_STRING;
  1922. m_serialiseString+=CString(SMIR_MODULE_ASSOC_MODULE_PROP);
  1923. m_serialiseString+=END_OF_PROPERTY;
  1924. m_serialiseString+=END_OF_CLASS;
  1925. /**************************************************************************
  1926. * create the Group Associator class
  1927. *[assoc]
  1928. *class SmirToClassAssociator
  1929. *{
  1930. *[read, key] AssocName;
  1931. *[read] ClassName;
  1932. *[read] SmirName;
  1933. *};
  1934. *
  1935. **************************************************************************/
  1936. m_serialiseString+=ASSOC_QUALIFIER;
  1937. m_serialiseString+=CString(CLASS_STRING);
  1938. m_serialiseString+=CString(SMIR_GROUP_ASSOC_CLASS_NAME);
  1939. m_serialiseString+=CString(NEWLINE_STR);
  1940. m_serialiseString+=CString(OPEN_BRACE_STR);
  1941. m_serialiseString+=CString(NEWLINE_STR);
  1942. m_serialiseString+=READ_ONLY_KEY_STRING;
  1943. m_serialiseString+=CString(SMIR_X_ASSOC_NAME_PROP);
  1944. m_serialiseString+=END_OF_PROPERTY;
  1945. m_serialiseString+=READ_ONLY_REF_STRING;
  1946. m_serialiseString+=CString(SMIR_X_ASSOC_CLASS_PROP);
  1947. m_serialiseString+=END_OF_PROPERTY;
  1948. m_serialiseString+=READ_ONLY_REF_STRING;
  1949. m_serialiseString+=CString(SMIR_GROUP_ASSOC_GROUP_PROP);
  1950. m_serialiseString+=END_OF_PROPERTY;
  1951. m_serialiseString+=END_OF_CLASS;
  1952. /**************************************************************************
  1953. * create the Notification/Module Associator class
  1954. *[assoc]
  1955. *class ModToNotificationClassAssociator
  1956. *{
  1957. *[read, key] AssocName;
  1958. *[read] SmirClass;
  1959. *[read] SmirModule;
  1960. *};
  1961. *
  1962. **************************************************************************/
  1963. m_serialiseString+=ASSOC_QUALIFIER;
  1964. m_serialiseString+=CString(CLASS_STRING);
  1965. m_serialiseString+=CString(SMIR_MODULE_ASSOC_NCLASS_NAME);
  1966. m_serialiseString+=CString(NEWLINE_STR);
  1967. m_serialiseString+=CString(OPEN_BRACE_STR);
  1968. m_serialiseString+=CString(NEWLINE_STR);
  1969. m_serialiseString+=READ_ONLY_KEY_STRING;
  1970. m_serialiseString+=CString(SMIR_X_ASSOC_NAME_PROP);
  1971. m_serialiseString+=END_OF_PROPERTY;
  1972. m_serialiseString+=READ_ONLY_REF_STRING;
  1973. m_serialiseString+=CString(SMIR_X_ASSOC_CLASS_PROP);
  1974. m_serialiseString+=END_OF_PROPERTY;
  1975. m_serialiseString+=READ_ONLY_REF_STRING;
  1976. m_serialiseString+=CString(SMIR_MODULE_ASSOC_MODULE_PROP);
  1977. m_serialiseString+=END_OF_PROPERTY;
  1978. m_serialiseString+=END_OF_CLASS;
  1979. /**************************************************************************
  1980. * create the ExtNotification/Module Associator class
  1981. *[assoc]
  1982. *class ModToExtNotificationClassAssociator
  1983. *{
  1984. *[read, key] AssocName;
  1985. *[read] SmirClass;
  1986. *[read] SmirModule;
  1987. *};
  1988. *
  1989. **************************************************************************/
  1990. m_serialiseString+=ASSOC_QUALIFIER;
  1991. m_serialiseString+=CString(CLASS_STRING);
  1992. m_serialiseString+=CString(SMIR_MODULE_ASSOC_EXTNCLASS_NAME);
  1993. m_serialiseString+=CString(NEWLINE_STR);
  1994. m_serialiseString+=CString(OPEN_BRACE_STR);
  1995. m_serialiseString+=CString(NEWLINE_STR);
  1996. m_serialiseString+=READ_ONLY_KEY_STRING;
  1997. m_serialiseString+=CString(SMIR_X_ASSOC_NAME_PROP);
  1998. m_serialiseString+=END_OF_PROPERTY;
  1999. m_serialiseString+=READ_ONLY_REF_STRING;
  2000. m_serialiseString+=CString(SMIR_X_ASSOC_CLASS_PROP);
  2001. m_serialiseString+=END_OF_PROPERTY;
  2002. m_serialiseString+=READ_ONLY_REF_STRING;
  2003. m_serialiseString+=CString(SMIR_MODULE_ASSOC_MODULE_PROP);
  2004. m_serialiseString+=END_OF_PROPERTY;
  2005. m_serialiseString+=END_OF_CLASS;
  2006. }
  2007. }
  2008. SCODE CSmirSerialiseHandle :: GetText(BSTR *pszText)
  2009. {
  2010. SetStructuredExceptionHandler seh;
  2011. try
  2012. {
  2013. *pszText = m_serialiseString.AllocSysString();
  2014. return S_OK;
  2015. }
  2016. catch(Structured_Exception e_SE)
  2017. {
  2018. return E_UNEXPECTED;
  2019. }
  2020. catch(Heap_Exception e_HE)
  2021. {
  2022. return E_OUTOFMEMORY;
  2023. }
  2024. catch(...)
  2025. {
  2026. return E_UNEXPECTED;
  2027. }
  2028. }
  2029. CSmirWbemConfiguration :: CSmirWbemConfiguration ( CSmir *a_Smir ) :
  2030. m_Smir ( a_Smir ) ,
  2031. m_ReferenceCount ( 1 ) ,
  2032. m_Context ( NULL ) ,
  2033. m_Service ( NULL )
  2034. {
  2035. InterlockedIncrement ( & CSMIRClassFactory::objectsInProgress ) ;
  2036. }
  2037. CSmirWbemConfiguration :: ~CSmirWbemConfiguration ()
  2038. {
  2039. InterlockedDecrement ( & CSMIRClassFactory :: objectsInProgress ) ;
  2040. if ( m_Context )
  2041. m_Context->Release () ;
  2042. if ( m_Service )
  2043. m_Service->Release () ;
  2044. }
  2045. HRESULT CSmirWbemConfiguration :: QueryInterface(IN REFIID iid,OUT PPVOID iplpv)
  2046. {
  2047. SetStructuredExceptionHandler seh;
  2048. try
  2049. {
  2050. return m_Smir->QueryInterface(iid, iplpv);
  2051. }
  2052. catch(Structured_Exception e_SE)
  2053. {
  2054. return E_UNEXPECTED;
  2055. }
  2056. catch(Heap_Exception e_HE)
  2057. {
  2058. return E_OUTOFMEMORY;
  2059. }
  2060. catch(...)
  2061. {
  2062. return E_UNEXPECTED;
  2063. }
  2064. }
  2065. ULONG CSmirWbemConfiguration :: AddRef()
  2066. {
  2067. SetStructuredExceptionHandler seh;
  2068. try
  2069. {
  2070. InterlockedIncrement ( & m_ReferenceCount ) ;
  2071. return m_Smir->AddRef () ;
  2072. }
  2073. catch(Structured_Exception e_SE)
  2074. {
  2075. return 0;
  2076. }
  2077. catch(Heap_Exception e_HE)
  2078. {
  2079. return 0;
  2080. }
  2081. catch(...)
  2082. {
  2083. return 0;
  2084. }
  2085. }
  2086. ULONG CSmirWbemConfiguration :: Release()
  2087. {
  2088. SetStructuredExceptionHandler seh;
  2089. try
  2090. {
  2091. LONG ref ;
  2092. if ( ( ref = InterlockedDecrement ( & m_ReferenceCount ) ) == 0 )
  2093. {
  2094. }
  2095. return m_Smir->Release () ;
  2096. }
  2097. catch(Structured_Exception e_SE)
  2098. {
  2099. return 0;
  2100. }
  2101. catch(Heap_Exception e_HE)
  2102. {
  2103. return 0;
  2104. }
  2105. catch(...)
  2106. {
  2107. return 0;
  2108. }
  2109. }
  2110. HRESULT CSmirWbemConfiguration :: Authenticate (
  2111. BSTR Server,
  2112. BSTR User,
  2113. BSTR Password,
  2114. BSTR Locale,
  2115. long lSecurityFlags,
  2116. BSTR Authority ,
  2117. BOOL InProc
  2118. )
  2119. {
  2120. SetStructuredExceptionHandler seh;
  2121. try
  2122. {
  2123. IWbemLocator *t_Locator = NULL ;
  2124. HRESULT t_Result = CoCreateInstance (
  2125. CLSID_WbemLocator ,
  2126. NULL ,
  2127. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
  2128. IID_IUnknown ,
  2129. ( void ** ) & t_Locator
  2130. ) ;
  2131. if ( SUCCEEDED ( t_Result ) )
  2132. {
  2133. IWbemServices *t_Unknown = NULL ;
  2134. if ( Server )
  2135. {
  2136. CString t_BStr = CString ( BACKSLASH_STR ) ;
  2137. t_BStr += CString ( BACKSLASH_STR ) ;
  2138. t_BStr += CString ( Server ) ;
  2139. t_BStr += CString ( BACKSLASH_STR ) ;
  2140. t_BStr += CString ( SMIR_NAMESPACE ) ;
  2141. BSTR t_Str = SysAllocString ( t_BStr.GetBuffer ( 0 ) ) ;
  2142. t_Result = t_Locator->ConnectServer (
  2143. t_Str ,
  2144. Password, // Password
  2145. User, // User
  2146. Locale, // Locale id
  2147. lSecurityFlags, // Flags
  2148. Authority, // Authority
  2149. NULL, // Context
  2150. &t_Unknown
  2151. );
  2152. SysFreeString ( t_Str ) ;
  2153. }
  2154. else
  2155. {
  2156. CString t_BStr = CString ( SMIR_NAMESPACE ) ;
  2157. LPCTSTR t_Str = SysAllocString ( t_BStr.GetBuffer ( 0 ) ) ;
  2158. t_Result = t_Locator->ConnectServer (
  2159. t_Str ,
  2160. Password, // Password
  2161. User, // User
  2162. Locale, // Locale id
  2163. lSecurityFlags, // Flags
  2164. Authority, // Authority
  2165. NULL, // Context
  2166. &t_Unknown
  2167. );
  2168. SysFreeString ( t_Str ) ;
  2169. }
  2170. if ( SUCCEEDED ( t_Result ) )
  2171. {
  2172. if ( m_Service )
  2173. {
  2174. m_Service->Release () ;
  2175. }
  2176. t_Result = t_Unknown->QueryInterface (
  2177. IID_IWbemServices ,
  2178. ( void **) & m_Service
  2179. ) ;
  2180. t_Unknown->Release () ;
  2181. }
  2182. t_Locator->Release () ;
  2183. }
  2184. return t_Result ;
  2185. }
  2186. catch(Structured_Exception e_SE)
  2187. {
  2188. return WBEM_E_UNEXPECTED;
  2189. }
  2190. catch(Heap_Exception e_HE)
  2191. {
  2192. return WBEM_E_OUT_OF_MEMORY;
  2193. }
  2194. catch(...)
  2195. {
  2196. return WBEM_E_UNEXPECTED;
  2197. }
  2198. }
  2199. HRESULT CSmirWbemConfiguration :: Impersonate ( ISMIRWbemConfiguration *a_Configuration )
  2200. {
  2201. SetStructuredExceptionHandler seh;
  2202. try
  2203. {
  2204. if ( m_Context )
  2205. m_Context->Release () ;
  2206. if ( m_Service )
  2207. m_Service->Release () ;
  2208. CSmirWbemConfiguration *t_Configuration = ( CSmirWbemConfiguration * ) a_Configuration ;
  2209. m_Context = t_Configuration->m_Context ;
  2210. m_Service = t_Configuration->m_Service ;
  2211. if ( m_Context )
  2212. m_Context->AddRef () ;
  2213. if ( m_Service )
  2214. m_Service->AddRef () ;
  2215. return S_OK ;
  2216. }
  2217. catch(Structured_Exception e_SE)
  2218. {
  2219. return WBEM_E_UNEXPECTED;
  2220. }
  2221. catch(Heap_Exception e_HE)
  2222. {
  2223. return WBEM_E_OUT_OF_MEMORY;
  2224. }
  2225. catch(...)
  2226. {
  2227. return WBEM_E_UNEXPECTED;
  2228. }
  2229. }
  2230. HRESULT CSmirWbemConfiguration :: SetContext ( IWbemContext *a_Context )
  2231. {
  2232. SetStructuredExceptionHandler seh;
  2233. try
  2234. {
  2235. if ( m_Context )
  2236. {
  2237. m_Context->Release () ;
  2238. }
  2239. m_Context = a_Context ;
  2240. if ( m_Context )
  2241. {
  2242. m_Context->AddRef () ;
  2243. }
  2244. return S_OK ;
  2245. }
  2246. catch(Structured_Exception e_SE)
  2247. {
  2248. return WBEM_E_UNEXPECTED;
  2249. }
  2250. catch(Heap_Exception e_HE)
  2251. {
  2252. return WBEM_E_OUT_OF_MEMORY;
  2253. }
  2254. catch(...)
  2255. {
  2256. return WBEM_E_UNEXPECTED;
  2257. }
  2258. }
  2259. HRESULT CSmirWbemConfiguration :: GetContext ( IWbemContext **a_Context )
  2260. {
  2261. SetStructuredExceptionHandler seh;
  2262. try
  2263. {
  2264. if ( a_Context && m_Context )
  2265. {
  2266. m_Context->AddRef () ;
  2267. *a_Context = m_Context ;
  2268. return S_OK ;
  2269. }
  2270. else
  2271. {
  2272. if (a_Context)
  2273. {
  2274. *a_Context = NULL ;
  2275. }
  2276. return WBEM_E_FAILED ;
  2277. }
  2278. }
  2279. catch(Structured_Exception e_SE)
  2280. {
  2281. return WBEM_E_UNEXPECTED;
  2282. }
  2283. catch(Heap_Exception e_HE)
  2284. {
  2285. return WBEM_E_OUT_OF_MEMORY;
  2286. }
  2287. catch(...)
  2288. {
  2289. return WBEM_E_UNEXPECTED;
  2290. }
  2291. }
  2292. HRESULT CSmirWbemConfiguration :: GetServices ( IWbemServices **a_Service )
  2293. {
  2294. SetStructuredExceptionHandler seh;
  2295. try
  2296. {
  2297. if ( a_Service && m_Service )
  2298. {
  2299. m_Service->AddRef () ;
  2300. *a_Service = m_Service ;
  2301. return S_OK ;
  2302. }
  2303. else
  2304. {
  2305. *a_Service = NULL ;
  2306. return WBEM_E_FAILED ;
  2307. }
  2308. }
  2309. catch(Structured_Exception e_SE)
  2310. {
  2311. return WBEM_E_UNEXPECTED;
  2312. }
  2313. catch(Heap_Exception e_HE)
  2314. {
  2315. return WBEM_E_OUT_OF_MEMORY;
  2316. }
  2317. catch(...)
  2318. {
  2319. return WBEM_E_UNEXPECTED;
  2320. }
  2321. }