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.

4577 lines
100 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. #include <precomp.h>
  13. #include "csmir.h"
  14. #include "handles.h"
  15. #include "classfac.h"
  16. #include <textdef.h>
  17. #include <helper.h>
  18. #include "bstring.h"
  19. #ifdef ICECAP_PROFILE
  20. #include <icapexp.h>
  21. #endif
  22. // A function to escape newlines, tabs etc. from a property value
  23. static BSTR EscapeSpecialCharacters(BSTR strInputString)
  24. {
  25. // Escape all the quotes - This code taken from winmgmt\common\var.cpp
  26. // =====================
  27. int nStrLen = wcslen(strInputString);
  28. LPWSTR wszValue = new WCHAR[nStrLen*2+10];
  29. LPWSTR pwc = wszValue;
  30. for(int i = 0; i < (int)nStrLen; i++)
  31. {
  32. switch(strInputString[i])
  33. {
  34. case L'\n':
  35. *(pwc++) = L'\\';
  36. *(pwc++) = L'n';
  37. break;
  38. case L'\t':
  39. *(pwc++) = L'\\';
  40. *(pwc++) = L't';
  41. break;
  42. case L'"':
  43. case L'\\':
  44. *(pwc++) = L'\\';
  45. *(pwc++) = strInputString[i];
  46. break;
  47. default:
  48. *(pwc++) = strInputString[i];
  49. break;
  50. }
  51. }
  52. *pwc = 0;
  53. BSTR retValue = SysAllocString(wszValue);
  54. delete [] wszValue;
  55. return retValue;
  56. }
  57. /*
  58. * CSmirModuleHandle::QueryInterface
  59. *
  60. * Purpose:
  61. * Manages the interfaces for this object which supports the
  62. * IUnknown interface.
  63. *
  64. * Parameters:
  65. * riid REFIID of the interface to return.
  66. * ppv PPVOID in which to store the pointer.
  67. *
  68. * Return Value:
  69. * SCODE NOERROR on success, E_NOINTERFACE if the
  70. * interface is not supported.
  71. */
  72. STDMETHODIMP CSmirModuleHandle::QueryInterface(REFIID riid, PPVOID ppv)
  73. {
  74. SetStructuredExceptionHandler seh;
  75. try
  76. {
  77. //Always NULL the out-parameters
  78. *ppv=NULL;
  79. if (IID_IUnknown==riid)
  80. *ppv=this;
  81. if (IID_ISMIR_ModHandle==riid)
  82. *ppv=this;
  83. if (NULL==*ppv)
  84. return ResultFromScode(E_NOINTERFACE);
  85. //AddRef any interface we'll return.
  86. ((LPUNKNOWN)*ppv)->AddRef();
  87. return NOERROR;
  88. }
  89. catch(Structured_Exception e_SE)
  90. {
  91. return E_UNEXPECTED;
  92. }
  93. catch(Heap_Exception e_HE)
  94. {
  95. return E_OUTOFMEMORY;
  96. }
  97. catch(...)
  98. {
  99. return E_UNEXPECTED;
  100. }
  101. }
  102. /*
  103. * CSmirModuleHandle::AddRef
  104. * CSmirModuleHandle::Release
  105. *
  106. * Reference counting members. When Release sees a zero count
  107. * the object destroys itself.
  108. */
  109. ULONG CSmirModuleHandle::AddRef(void)
  110. {
  111. SetStructuredExceptionHandler seh;
  112. try
  113. {
  114. ////CMOEvent_Trace MyTraceEvent(SMIR_STR);
  115. return InterlockedIncrement(&m_cRef);
  116. }
  117. catch(Structured_Exception e_SE)
  118. {
  119. return 0;
  120. }
  121. catch(Heap_Exception e_HE)
  122. {
  123. return 0;
  124. }
  125. catch(...)
  126. {
  127. return 0;
  128. }
  129. }
  130. ULONG CSmirModuleHandle::Release(void)
  131. {
  132. SetStructuredExceptionHandler seh;
  133. try
  134. {
  135. long ret;
  136. if (0!=(ret=InterlockedDecrement(&m_cRef)))
  137. return ret;
  138. delete this;
  139. return 0;
  140. }
  141. catch(Structured_Exception e_SE)
  142. {
  143. return 0;
  144. }
  145. catch(Heap_Exception e_HE)
  146. {
  147. return 0;
  148. }
  149. catch(...)
  150. {
  151. return 0;
  152. }
  153. }
  154. CSmirModuleHandle :: CSmirModuleHandle()
  155. : m_lSnmp_version(DEFAULT_SNMP_VERSION), m_szLastUpdate(NULL),
  156. m_szModuleOid(NULL), m_szName(NULL),
  157. m_szModuleId(NULL), m_szOrganisation(NULL),
  158. m_szContactInfo(NULL), m_szDescription(NULL),
  159. m_szRevision(NULL), m_szModImports(NULL)
  160. {
  161. //start off as a handel to nothing
  162. //init reference count
  163. m_cRef=0;
  164. CModHandleClassFactory::objectsInProgress++;
  165. }
  166. /*
  167. * CSmirGroupHandle::void* operator
  168. * validate handle
  169. */
  170. CSmirModuleHandle::operator void*()
  171. {
  172. if(NULL!=m_szName)
  173. return this;
  174. return NULL;
  175. }
  176. /**************************************************************************************
  177. *Methods not exposed by the ISmirModHandle interface.
  178. *Used to encapsulate functionality.
  179. **************************************************************************************/
  180. STDMETHODIMP CSmirModuleHandle::DeleteFromDB ( CSmir *a_Smir )
  181. {
  182. //open the smir name space
  183. IWbemServices * moServ = NULL ;
  184. IWbemContext *moContext = NULL ;
  185. SCODE res= CSmirAccess :: GetContext (a_Smir , &moContext);
  186. res= CSmirAccess :: Open(a_Smir,&moServ);
  187. if ((S_FALSE==res)||(NULL == moServ))
  188. {
  189. //we have a problem the SMIR is not there and cannot be created
  190. return WBEM_E_FAILED;
  191. }
  192. //delete all of the classes in this module
  193. ISmirInterrogator *pInterrogativeInt = NULL ;
  194. res = g_pClassFactoryHelper->CreateInstance(
  195. CLSID_SMIR_Database,
  196. IID_ISMIR_Interrogative,
  197. (PVOID *)&pInterrogativeInt
  198. );
  199. if(S_OK!=res)
  200. {
  201. if ( moContext )
  202. moContext->Release () ;
  203. moServ->Release();
  204. return S_OK;
  205. }
  206. ISMIRWbemConfiguration *t_Configuration = NULL ;
  207. res = pInterrogativeInt->QueryInterface (
  208. IID_ISMIRWbemConfiguration ,
  209. ( void ** ) &t_Configuration
  210. ) ;
  211. if ( ! SUCCEEDED ( res ) )
  212. {
  213. if ( moContext )
  214. moContext->Release () ;
  215. moServ->Release();
  216. pInterrogativeInt->Release();
  217. return S_OK;
  218. }
  219. ISMIRWbemConfiguration *t_CopyConfiguration = NULL ;
  220. res = a_Smir->QueryInterface (
  221. IID_ISMIRWbemConfiguration ,
  222. ( void ** ) &t_CopyConfiguration
  223. ) ;
  224. if ( ! SUCCEEDED ( res ) )
  225. {
  226. if ( moContext )
  227. moContext->Release () ;
  228. t_Configuration->Release () ;
  229. pInterrogativeInt->Release();
  230. return S_OK ;
  231. }
  232. t_Configuration->Impersonate ( t_CopyConfiguration ) ;
  233. if ( ! SUCCEEDED ( res ) )
  234. {
  235. if ( moContext )
  236. moContext->Release () ;
  237. t_Configuration->Release () ;
  238. t_CopyConfiguration->Release () ;
  239. pInterrogativeInt->Release();
  240. return S_OK ;
  241. }
  242. t_Configuration->Release () ;
  243. t_CopyConfiguration->Release () ;
  244. IEnumClass *pTEnumSmirClass = NULL ;
  245. res = pInterrogativeInt->EnumClassesInModule(&pTEnumSmirClass,this);
  246. if(S_OK!=res)
  247. {
  248. if ( moContext )
  249. moContext->Release () ;
  250. moServ->Release();
  251. pInterrogativeInt->Release();
  252. return S_OK;
  253. }
  254. //now use the enumerator
  255. //loop over the classes and remove them
  256. ISmirClassHandle *phClass = NULL ;
  257. for(int iCount=0;S_OK==pTEnumSmirClass->Next(1, &phClass, NULL);iCount++)
  258. {
  259. /*got one so remove it. Don't check the return because there is nothing
  260. *I can do about it.
  261. */
  262. ((CSmirClassHandle*)phClass)->DeleteFromDB(a_Smir);
  263. phClass->Release();
  264. }
  265. pTEnumSmirClass->Release();
  266. IEnumNotificationClass *pTEnumNotificationClass = NULL ;
  267. res = pInterrogativeInt->EnumNotificationClassesInModule(&pTEnumNotificationClass,this);
  268. if(S_OK!=res)
  269. {
  270. if ( moContext )
  271. moContext->Release () ;
  272. moServ->Release();
  273. pInterrogativeInt->Release();
  274. return S_OK;
  275. }
  276. //now use the enumerator
  277. //loop over the classes and remove them
  278. ISmirNotificationClassHandle *phNClass = NULL ;
  279. for(iCount=0;S_OK==pTEnumNotificationClass->Next(1, &phNClass, NULL);iCount++)
  280. {
  281. /*got one so remove it. Don't check the return because there is nothing
  282. *I can do about it.
  283. */
  284. ((CSmirNotificationClassHandle*)phNClass)->DeleteFromDB(a_Smir);
  285. phNClass->Release();
  286. }
  287. pTEnumNotificationClass->Release();
  288. IEnumExtNotificationClass *pTEnumExtNotificationClass = NULL ;
  289. res = pInterrogativeInt->EnumExtNotificationClassesInModule(&pTEnumExtNotificationClass,this);
  290. //not needed anymore...
  291. pInterrogativeInt->Release();
  292. if(S_OK!=res)
  293. {
  294. if ( moContext )
  295. moContext->Release () ;
  296. moServ->Release();
  297. return S_OK;
  298. }
  299. //now use the enumerator
  300. //loop over the classes and remove them
  301. ISmirExtNotificationClassHandle *phExtNClass = NULL ;
  302. for(iCount=0;S_OK==pTEnumExtNotificationClass->Next(1, &phExtNClass, NULL);iCount++)
  303. {
  304. /*got one so remove it. Don't check the return because there is nothing
  305. *I can do about it.
  306. */
  307. ((CSmirExtNotificationClassHandle*)phExtNClass)->DeleteFromDB(a_Smir);
  308. phExtNClass->Release();
  309. }
  310. pTEnumExtNotificationClass->Release();
  311. /********************Now delete the module********************/
  312. //create a buffer big enough
  313. wchar_t *pTstring = new wchar_t[wcslen(MODULE_NAMESPACE_NAME)+wcslen(EQUALS_STR)
  314. +wcslen(m_szName)+2+1];
  315. if(NULL == pTstring)
  316. {
  317. if ( moContext )
  318. moContext->Release () ;
  319. moServ->Release();
  320. return E_OUTOFMEMORY;
  321. }
  322. wcscpy(pTstring, MODULE_NAMESPACE_NAME);
  323. wcscat(pTstring,EQUALS_STR);
  324. wcscat(pTstring,QUOTE_STR);
  325. // module =
  326. wcscat(pTstring,m_szName);
  327. wcscat(pTstring,QUOTE_STR);
  328. // module = <module>
  329. CBString t_Str (pTstring);
  330. SCODE result = moServ->DeleteInstance(t_Str.GetString (),RESERVED_WBEM_FLAG, moContext,NULL );
  331. //clean up
  332. delete [] pTstring;
  333. if ( moContext )
  334. moContext->Release () ;
  335. moServ->Release();
  336. if (FAILED(result))
  337. {
  338. //problem!
  339. return WBEM_E_FAILED;
  340. }
  341. return S_OK;
  342. }
  343. STDMETHODIMP CSmirModuleHandle::AddToDB( CSmir *a_Smir )
  344. {
  345. /*open the smir name space this will addref it so it cannot be removed
  346. *whilst we are using it
  347. */
  348. IWbemServices * moServ = NULL ;
  349. IWbemContext *moContext = NULL ;
  350. SCODE result= CSmirAccess :: GetContext (a_Smir , &moContext);
  351. result= CSmirAccess :: Open(a_Smir,&moServ);
  352. if ((S_FALSE==result)||(NULL == (void*)moServ))
  353. {
  354. if ( moContext )
  355. moContext->Release () ;
  356. //we have a problem the SMIR is not there and cannot be created
  357. return WBEM_E_FAILED;
  358. }
  359. IWbemClassObject *pModClass = NULL ;
  360. CBString t_BStr ( MODULE_NAMESPACE_NAME ) ;
  361. result = moServ->GetObject(t_BStr.GetString () , RESERVED_WBEM_FLAG,moContext,
  362. &pModClass,NULL);
  363. if (!SUCCEEDED(result))
  364. {
  365. /*OK we have the smir namespace so create the module namespace
  366. *first create a class...
  367. */
  368. IWbemClassObject *pNewClass = NULL ;
  369. CBString t_BStr ( OLEMS_NAMESPACE_CLASS ) ;
  370. result = moServ->GetObject(t_BStr.GetString (), RESERVED_WBEM_FLAG,moContext,
  371. &pNewClass,NULL);
  372. if ((FAILED(result))||(NULL==pNewClass))
  373. {
  374. moServ->Release();
  375. if ( moContext )
  376. moContext->Release () ;
  377. return WBEM_E_FAILED;
  378. }
  379. // Spawn derived class
  380. IWbemClassObject *pNewDerivedClass = NULL ;
  381. result = pNewClass->SpawnDerivedClass ( 0 , &pNewDerivedClass ) ;
  382. if ((FAILED(result))||(NULL==pNewDerivedClass))
  383. {
  384. moServ->Release();
  385. pNewClass->Release () ;
  386. if ( moContext )
  387. moContext->Release () ;
  388. return WBEM_E_FAILED;
  389. }
  390. pNewClass->Release () ;
  391. VARIANT v;
  392. VariantInit(&v);
  393. //I now have a new class so Give it a name
  394. V_VT(&v) = VT_BSTR;
  395. V_BSTR(&v)=SysAllocString(MODULE_NAMESPACE_NAME);
  396. result = pNewDerivedClass->Put(OLEMS_CLASS_PROP,RESERVED_WBEM_FLAG, &v,0);
  397. VariantClear(&v);
  398. if (FAILED(result))
  399. {
  400. pNewDerivedClass->Release();
  401. moServ->Release();
  402. if ( moContext )
  403. moContext->Release () ;
  404. return WBEM_E_FAILED;
  405. }
  406. result = PutClassProperties(pNewDerivedClass) ;
  407. if (FAILED(result))
  408. {
  409. pNewDerivedClass->Release();
  410. moServ->Release();
  411. if ( moContext )
  412. moContext->Release () ;
  413. return WBEM_E_FAILED;
  414. }
  415. //now commit the changes
  416. result = moServ->PutClass(pNewDerivedClass, RESERVED_WBEM_FLAG,moContext,NULL);
  417. pNewDerivedClass->Release();
  418. if (FAILED(result))
  419. {
  420. moServ->Release();
  421. if ( moContext )
  422. moContext->Release () ;
  423. return WBEM_E_FAILED;
  424. }
  425. //get an object
  426. t_BStr = MODULE_NAMESPACE_NAME ;
  427. result = moServ->GetObject(t_BStr.GetString (), 0,
  428. moContext,&pModClass,NULL );
  429. if (FAILED(result))
  430. {
  431. moServ->Release();
  432. if ( moContext )
  433. moContext->Release () ;
  434. return WBEM_E_FAILED;
  435. }
  436. }
  437. //and create an instance of the module namespace
  438. // Spawn instance of class
  439. IWbemClassObject *pNewInstance = NULL ;
  440. result = pModClass->SpawnInstance ( 0 , &pNewInstance ) ;
  441. if ((FAILED(result))||(NULL==pNewInstance))
  442. {
  443. moServ->Release();
  444. if ( moContext )
  445. moContext->Release () ;
  446. pModClass->Release () ;
  447. return WBEM_E_FAILED;
  448. }
  449. pModClass->Release () ;
  450. //fill in the instance
  451. *this >> pNewInstance;
  452. //and commit it to the namespace
  453. result = moServ->PutInstance(pNewInstance, RESERVED_WBEM_FLAG, moContext,NULL );
  454. pNewInstance->Release();
  455. if (FAILED(result))
  456. {
  457. if ( moContext )
  458. moContext->Release () ;
  459. moServ->Release();
  460. return WBEM_E_FAILED;
  461. }
  462. if ( moContext )
  463. moContext->Release () ;
  464. moServ->Release();
  465. if (FAILED(result))
  466. {
  467. return WBEM_E_FAILED;
  468. }
  469. return S_OK;
  470. }
  471. const CSmirModuleHandle& CSmirModuleHandle :: operator <<(IWbemClassObject *pSmirMosClassObject)
  472. {
  473. //get the name
  474. VARIANT v;
  475. VariantInit(&v);
  476. pSmirMosClassObject->Get(MODULE_NAME_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  477. if (V_VT(&v) == VT_BSTR)
  478. {
  479. SetName(V_BSTR(&v));
  480. }
  481. VariantClear(&v);
  482. //get the object id
  483. pSmirMosClassObject->Get(MODULE_OID_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  484. if (V_VT(&v) == VT_BSTR)
  485. {
  486. SetModuleOID(V_BSTR(&v));
  487. }
  488. VariantClear(&v);
  489. //get the object imports
  490. pSmirMosClassObject->Get(MODULE_IMPORTS_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  491. if (V_VT(&v) == VT_BSTR)
  492. {
  493. SetModuleImports(V_BSTR(&v));
  494. }
  495. VariantClear(&v);
  496. //get the object id
  497. pSmirMosClassObject->Get(MODULE_ID_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  498. if (V_VT(&v) == VT_BSTR)
  499. {
  500. SetModuleIdentity(V_BSTR(&v));
  501. }
  502. VariantClear(&v);
  503. //get the organisation
  504. pSmirMosClassObject->Get(MODULE_ORG_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  505. if (V_VT(&v) == VT_BSTR)
  506. {
  507. SetOrganisation(V_BSTR(&v));
  508. }
  509. VariantClear(&v);
  510. //get the contact
  511. pSmirMosClassObject->Get(MODULE_CONTACT_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  512. if (V_VT(&v) == VT_BSTR)
  513. {
  514. SetContactInfo(V_BSTR(&v));
  515. }
  516. VariantClear(&v);
  517. //get the description
  518. pSmirMosClassObject->Get(MODULE_DESCRIPTION_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  519. if (V_VT(&v) == VT_BSTR)
  520. {
  521. SetDescription(V_BSTR(&v));
  522. }
  523. VariantClear(&v);
  524. //get the revision
  525. pSmirMosClassObject->Get(MODULE_REVISION_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  526. if (V_VT(&v) == VT_BSTR)
  527. {
  528. SetRevision(V_BSTR(&v));
  529. }
  530. VariantClear(&v);
  531. //get the version
  532. pSmirMosClassObject->Get(MODULE_SNMP_VERSION_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  533. if (V_VT(&v) == VT_I4)
  534. {
  535. SetSnmpVersion(V_I4(&v));
  536. }
  537. //get the last update value
  538. pSmirMosClassObject->Get(MODULE_LAST_UPDATE_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  539. if (V_VT(&v) == VT_BSTR)
  540. {
  541. SetLastUpdate(V_BSTR(&v));
  542. }
  543. VariantClear(&v);
  544. return *this;
  545. }
  546. const CSmirModuleHandle& CSmirModuleHandle :: operator >>(IWbemClassObject *pInst)
  547. {
  548. VARIANT v;
  549. VariantInit(&v);
  550. //give the instance a name
  551. V_VT(&v) = VT_BSTR;
  552. SCODE result;
  553. if(NULL != m_szName)
  554. {
  555. V_BSTR(&v)=SysAllocString(m_szName);
  556. result = pInst->Put(OLEMS_NAME_PROP,RESERVED_WBEM_FLAG, &v,0);
  557. VariantClear(&v);
  558. if (FAILED(result))
  559. {
  560. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  561. return *this;
  562. }
  563. }
  564. else
  565. {
  566. //must have a name
  567. return *this;
  568. }
  569. //add the module oid property
  570. V_VT(&v) = VT_BSTR;
  571. if(NULL != m_szModuleOid)
  572. {
  573. V_BSTR(&v)=SysAllocString(m_szModuleOid);
  574. result = pInst->Put(MODULE_OID_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  575. VariantClear(&v);
  576. if (FAILED(result))
  577. {
  578. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  579. return *this;
  580. }
  581. }
  582. //add the module identity
  583. V_VT(&v) = VT_BSTR;
  584. if(NULL != m_szModuleId)
  585. {
  586. V_BSTR(&v)=SysAllocString(m_szModuleId);
  587. result = pInst->Put(MODULE_ID_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  588. VariantClear(&v);
  589. if (FAILED(result))
  590. {
  591. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  592. return *this;
  593. }
  594. }
  595. //add the organisation property
  596. V_VT(&v) = VT_BSTR;
  597. if(NULL != m_szOrganisation)
  598. {
  599. V_BSTR(&v)=SysAllocString(m_szOrganisation);
  600. result = pInst->Put(MODULE_ORG_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  601. VariantClear(&v);
  602. if (FAILED(result))
  603. {
  604. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  605. return *this;
  606. }
  607. }
  608. //add the contact info property
  609. V_VT(&v) = VT_BSTR;
  610. if(NULL != m_szContactInfo)
  611. {
  612. V_BSTR(&v)=SysAllocString(m_szContactInfo);
  613. result = pInst->Put(MODULE_CONTACT_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  614. VariantClear(&v);
  615. if (FAILED(result))
  616. {
  617. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  618. return *this;
  619. }
  620. }
  621. //add the Description property
  622. V_VT(&v) = VT_BSTR;
  623. if(NULL != m_szDescription)
  624. {
  625. V_BSTR(&v)=SysAllocString(m_szDescription);
  626. result = pInst->Put(MODULE_DESCRIPTION_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  627. VariantClear(&v);
  628. if (FAILED(result))
  629. {
  630. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  631. return *this;
  632. }
  633. }
  634. //add the revision property
  635. V_VT(&v) = VT_BSTR;
  636. if(NULL != m_szRevision)
  637. {
  638. V_BSTR(&v)=SysAllocString(m_szRevision);
  639. result = pInst->Put(MODULE_REVISION_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  640. VariantClear(&v);
  641. if (FAILED(result))
  642. {
  643. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  644. return *this;
  645. }
  646. }
  647. //add the last update property
  648. V_VT(&v) = VT_BSTR;
  649. if(NULL != m_szLastUpdate)
  650. {
  651. V_BSTR(&v)=SysAllocString(m_szLastUpdate);
  652. result = pInst->Put(MODULE_LAST_UPDATE_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  653. VariantClear(&v);
  654. if (FAILED(result))
  655. {
  656. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  657. return *this;
  658. }
  659. }
  660. //add the snmp version property
  661. V_VT(&v) = VT_I4;
  662. V_I4(&v)=m_lSnmp_version;
  663. result = pInst->Put(MODULE_SNMP_VERSION_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  664. VariantClear(&v);
  665. if (FAILED(result))
  666. {
  667. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  668. return *this;
  669. }
  670. //add the module identity as an property
  671. V_VT(&v) = VT_BSTR;
  672. if(NULL != m_szModImports)
  673. {
  674. V_BSTR(&v)=SysAllocString(m_szModImports);
  675. result = pInst->Put(MODULE_IMPORTS_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  676. VariantClear(&v);
  677. if (FAILED(result))
  678. {
  679. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  680. return *this;
  681. }
  682. }
  683. return *this;
  684. }
  685. HRESULT CSmirModuleHandle :: PutClassProperties (IWbemClassObject *pClass)
  686. {
  687. HRESULT result;
  688. VARIANT v;
  689. VariantInit(&v);
  690. //give the instance a name
  691. V_VT(&v) = VT_BSTR;
  692. V_BSTR(&v)=SysAllocString(L"");
  693. result = pClass->Put(OLEMS_NAME_PROP,RESERVED_WBEM_FLAG, &v,0);
  694. VariantClear(&v);
  695. if (FAILED(result))
  696. {
  697. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  698. return result ;
  699. }
  700. //add the module oid property
  701. V_VT(&v) = VT_BSTR;
  702. V_BSTR(&v)=SysAllocString(L"");
  703. result = pClass->Put(MODULE_OID_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  704. VariantClear(&v);
  705. if (FAILED(result))
  706. {
  707. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  708. return result ;
  709. }
  710. //add the module identity
  711. V_VT(&v) = VT_BSTR;
  712. V_BSTR(&v)=SysAllocString(L"");
  713. result = pClass->Put(MODULE_ID_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  714. VariantClear(&v);
  715. if (FAILED(result))
  716. {
  717. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  718. return result ;
  719. }
  720. //add the organisation property
  721. V_VT(&v) = VT_BSTR;
  722. V_BSTR(&v)=SysAllocString(L"");
  723. result = pClass->Put(MODULE_ORG_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  724. VariantClear(&v);
  725. if (FAILED(result))
  726. {
  727. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  728. return result ;
  729. }
  730. //add the contact info property
  731. V_VT(&v) = VT_BSTR;
  732. V_BSTR(&v)=SysAllocString(L"");
  733. result = pClass->Put(MODULE_CONTACT_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  734. VariantClear(&v);
  735. if (FAILED(result))
  736. {
  737. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  738. return result ;
  739. }
  740. //add the Description property
  741. V_VT(&v) = VT_BSTR;
  742. V_BSTR(&v)=SysAllocString(L"");
  743. result = pClass->Put(MODULE_DESCRIPTION_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  744. VariantClear(&v);
  745. if (FAILED(result))
  746. {
  747. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  748. return result ;
  749. }
  750. //add the revision property
  751. V_VT(&v) = VT_BSTR;
  752. V_BSTR(&v)=SysAllocString(L"");
  753. result = pClass->Put(MODULE_REVISION_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  754. VariantClear(&v);
  755. if (FAILED(result))
  756. {
  757. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  758. return result ;
  759. }
  760. //add the last update property
  761. V_VT(&v) = VT_BSTR;
  762. V_BSTR(&v)=SysAllocString(L"");
  763. result = pClass->Put(MODULE_LAST_UPDATE_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  764. VariantClear(&v);
  765. if (FAILED(result))
  766. {
  767. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  768. return result ;
  769. }
  770. //add the snmp version property
  771. V_VT(&v) = VT_I4;
  772. V_I4(&v)=0;
  773. result = pClass->Put(MODULE_SNMP_VERSION_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  774. VariantClear(&v);
  775. if (FAILED(result))
  776. {
  777. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  778. return result ;
  779. }
  780. //add the module identity as an property
  781. V_VT(&v) = VT_BSTR;
  782. V_BSTR(&v)=SysAllocString(L"");
  783. result = pClass->Put(MODULE_IMPORTS_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  784. VariantClear(&v);
  785. if (FAILED(result))
  786. {
  787. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  788. return result ;
  789. }
  790. return result ;
  791. }
  792. const CSmirModuleHandle& CSmirModuleHandle :: operator >>(ISmirSerialiseHandle *pSHandle)
  793. {
  794. if(NULL!=pSHandle)
  795. {
  796. BOOL bMOFPragmas=((CSmirSerialiseHandle*) pSHandle)->ReturnMOFPragmas();
  797. BOOL bMOFAssociations=((CSmirSerialiseHandle*) pSHandle)->ReturnMOFAssociations();
  798. CString szTmpString;
  799. //start in the SMIR namepspace
  800. if(TRUE==bMOFPragmas)
  801. szTmpString=CString(SMIR_NAMESPACE_PRAGMA);
  802. if (TRUE == bMOFAssociations)
  803. {
  804. //create an instance of the module namespac
  805. szTmpString+=MODULE_INSTANCE_START;
  806. //add the properties
  807. //give the instance a name
  808. szTmpString+=CString(MODULE_NAME_PROPERTY);
  809. szTmpString+=START_OF_PROPERTY_VALUE;
  810. szTmpString+=CString(m_szName);
  811. szTmpString+=END_OF_PROPERTY_VALUE;
  812. //add the module oid property
  813. szTmpString+=CString(MODULE_OID_PROPERTY);
  814. szTmpString+=START_OF_PROPERTY_VALUE;
  815. szTmpString+=CString(m_szModuleOid);
  816. szTmpString+=END_OF_PROPERTY_VALUE;
  817. //add the module identity
  818. szTmpString+=CString(MODULE_ID_PROPERTY);
  819. szTmpString+=START_OF_PROPERTY_VALUE;
  820. szTmpString+=CString(m_szModuleId);
  821. szTmpString+=END_OF_PROPERTY_VALUE;
  822. //add the organisation property
  823. szTmpString+=CString(MODULE_ORG_PROPERTY);
  824. szTmpString+=START_OF_PROPERTY_VALUE;
  825. BSTR strOrganisation = EscapeSpecialCharacters(m_szOrganisation);
  826. szTmpString+=CString(strOrganisation);
  827. SysFreeString(strOrganisation);
  828. szTmpString+=END_OF_PROPERTY_VALUE;
  829. //add the contact info property
  830. szTmpString+=CString(MODULE_CONTACT_PROPERTY);
  831. szTmpString+=START_OF_PROPERTY_VALUE;
  832. BSTR strContactInfo = EscapeSpecialCharacters(m_szContactInfo);
  833. szTmpString+=CString(strContactInfo);
  834. SysFreeString(strContactInfo);
  835. szTmpString+=END_OF_PROPERTY_VALUE;
  836. //add the Description property
  837. szTmpString+=CString(MODULE_DESCRIPTION_PROPERTY);
  838. szTmpString+=START_OF_PROPERTY_VALUE;
  839. BSTR strDescription= EscapeSpecialCharacters(m_szDescription);
  840. szTmpString+=CString(strDescription);
  841. SysFreeString(strDescription);
  842. szTmpString+=END_OF_PROPERTY_VALUE;
  843. //add the revision property
  844. szTmpString+=CString(MODULE_REVISION_PROPERTY);
  845. szTmpString+=START_OF_PROPERTY_VALUE;
  846. BSTR strRevision = EscapeSpecialCharacters(m_szRevision);
  847. szTmpString+=CString(strRevision);
  848. SysFreeString(strRevision);
  849. szTmpString+=END_OF_PROPERTY_VALUE;
  850. //add the last update property
  851. szTmpString+=CString(MODULE_LAST_UPDATE_PROPERTY);
  852. szTmpString+=START_OF_PROPERTY_VALUE;
  853. szTmpString+=CString(m_szLastUpdate);
  854. szTmpString+=END_OF_PROPERTY_VALUE;
  855. //add the snmp version property
  856. szTmpString+=CString(MODULE_SNMP_VERSION_PROPERTY);
  857. szTmpString+=CString(EQUALS_STR);
  858. wchar_t szVersion[17];
  859. _itow(m_lSnmp_version,szVersion,2);
  860. szTmpString+=CString(szVersion);
  861. szTmpString+=END_OF_PROPERTY;
  862. //add the module imports as an property
  863. szTmpString+=CString(MODULE_IMPORTS_PROPERTY);
  864. szTmpString+=START_OF_PROPERTY_VALUE;
  865. szTmpString+=CString(m_szModImports);
  866. szTmpString+=END_OF_PROPERTY_VALUE;
  867. szTmpString+=END_OF_CLASS;
  868. }
  869. /*******create the group class***********/
  870. //add the group class to the module namespace
  871. if(TRUE==bMOFPragmas)
  872. {
  873. szTmpString+=CString(START_OF_SMIR_NAMESPACE_PRAGMA);
  874. szTmpString+=CString(m_szName);
  875. szTmpString+=CString(END_OF_NAMESPACE_PRAGMA);
  876. }
  877. if (TRUE == bMOFAssociations)
  878. {
  879. szTmpString+=GROUP_CLASS_START;
  880. //add the properties
  881. //give the instance a name
  882. szTmpString+=READONLY_STRING;
  883. szTmpString+=CString(GROUP_NAME_PROPERTY);
  884. szTmpString+=END_OF_PROPERTY;
  885. //give the instance a group id
  886. szTmpString+=READONLY_STRING;
  887. szTmpString+=CString(GROUP_ID_PROPERTY);
  888. szTmpString+=END_OF_PROPERTY;
  889. //give the instance a status
  890. szTmpString+=READONLY_STRING;
  891. szTmpString+=CString(GROUP_STATUS_PROPERTY);
  892. szTmpString+=END_OF_PROPERTY;
  893. //give the instance a description
  894. szTmpString+=READONLY_STRING;
  895. szTmpString+=CString(GROUP_DESCRIPTION_PROPERTY);
  896. szTmpString+=END_OF_PROPERTY;
  897. //give the instance a reference
  898. szTmpString+=READONLY_STRING;
  899. szTmpString+=CString(MODULE_REFERENCE_PROPERTY);
  900. szTmpString+=END_OF_PROPERTY;
  901. szTmpString+=END_OF_CLASS;
  902. }
  903. //and add the string to the serialise handle
  904. ((CSmirSerialiseHandle*)pSHandle)->m_serialiseString+=CString(szTmpString);
  905. //each group will create it's own instance
  906. }
  907. return *this;
  908. }
  909. SCODE CSmirModuleHandle :: GetName(BSTR *pszName)
  910. {
  911. SetStructuredExceptionHandler seh;
  912. try
  913. {
  914. if(pszName!=NULL)
  915. {
  916. *pszName=SysAllocString(m_szName);
  917. return S_OK;
  918. }
  919. else
  920. return E_INVALIDARG;
  921. }
  922. catch(Structured_Exception e_SE)
  923. {
  924. return E_UNEXPECTED;
  925. }
  926. catch(Heap_Exception e_HE)
  927. {
  928. return E_OUTOFMEMORY;
  929. }
  930. catch(...)
  931. {
  932. return E_UNEXPECTED;
  933. }
  934. }
  935. SCODE CSmirModuleHandle :: GetModuleOID(BSTR *pszModuleOid)
  936. {
  937. SetStructuredExceptionHandler seh;
  938. try
  939. {
  940. if(NULL != pszModuleOid)
  941. {
  942. *pszModuleOid=SysAllocString(m_szModuleOid);
  943. return S_OK;
  944. }
  945. else
  946. return E_INVALIDARG;
  947. }
  948. catch(Structured_Exception e_SE)
  949. {
  950. return E_UNEXPECTED;
  951. }
  952. catch(Heap_Exception e_HE)
  953. {
  954. return E_OUTOFMEMORY;
  955. }
  956. catch(...)
  957. {
  958. return E_UNEXPECTED;
  959. }
  960. }
  961. SCODE CSmirModuleHandle :: GetModuleIdentity(BSTR *pszModuleId)
  962. {
  963. SetStructuredExceptionHandler seh;
  964. try
  965. {
  966. if(NULL != pszModuleId)
  967. {
  968. *pszModuleId=SysAllocString(m_szModuleId);
  969. return S_OK;
  970. }
  971. else
  972. return E_INVALIDARG;
  973. }
  974. catch(Structured_Exception e_SE)
  975. {
  976. return E_UNEXPECTED;
  977. }
  978. catch(Heap_Exception e_HE)
  979. {
  980. return E_OUTOFMEMORY;
  981. }
  982. catch(...)
  983. {
  984. return E_UNEXPECTED;
  985. }
  986. }
  987. SCODE CSmirModuleHandle :: GetLastUpdate(BSTR *pszLastUpdate)
  988. {
  989. SetStructuredExceptionHandler seh;
  990. try
  991. {
  992. if(NULL != pszLastUpdate)
  993. {
  994. *pszLastUpdate=SysAllocString(m_szLastUpdate);
  995. return S_OK;
  996. }
  997. else
  998. return E_INVALIDARG;
  999. }
  1000. catch(Structured_Exception e_SE)
  1001. {
  1002. return E_UNEXPECTED;
  1003. }
  1004. catch(Heap_Exception e_HE)
  1005. {
  1006. return E_OUTOFMEMORY;
  1007. }
  1008. catch(...)
  1009. {
  1010. return E_UNEXPECTED;
  1011. }
  1012. }
  1013. SCODE CSmirModuleHandle :: GetOrganisation(BSTR *pszOrganisation)
  1014. {
  1015. SetStructuredExceptionHandler seh;
  1016. try
  1017. {
  1018. if(NULL != pszOrganisation)
  1019. {
  1020. *pszOrganisation=SysAllocString(m_szOrganisation);
  1021. return S_OK;
  1022. }
  1023. else
  1024. return E_INVALIDARG;
  1025. }
  1026. catch(Structured_Exception e_SE)
  1027. {
  1028. return E_UNEXPECTED;
  1029. }
  1030. catch(Heap_Exception e_HE)
  1031. {
  1032. return E_OUTOFMEMORY;
  1033. }
  1034. catch(...)
  1035. {
  1036. return E_UNEXPECTED;
  1037. }
  1038. }
  1039. SCODE CSmirModuleHandle :: GetContactInfo(BSTR *pszContactInfo)
  1040. {
  1041. SetStructuredExceptionHandler seh;
  1042. try
  1043. {
  1044. if(NULL != pszContactInfo)
  1045. {
  1046. *pszContactInfo=SysAllocString(m_szContactInfo);
  1047. return S_OK;
  1048. }
  1049. else
  1050. return E_INVALIDARG;
  1051. }
  1052. catch(Structured_Exception e_SE)
  1053. {
  1054. return E_UNEXPECTED;
  1055. }
  1056. catch(Heap_Exception e_HE)
  1057. {
  1058. return E_OUTOFMEMORY;
  1059. }
  1060. catch(...)
  1061. {
  1062. return E_UNEXPECTED;
  1063. }
  1064. }
  1065. SCODE CSmirModuleHandle :: GetDescription(BSTR *pszDescription)
  1066. {
  1067. SetStructuredExceptionHandler seh;
  1068. try
  1069. {
  1070. if(NULL != pszDescription)
  1071. {
  1072. *pszDescription=SysAllocString(m_szDescription);
  1073. return S_OK;
  1074. }
  1075. else
  1076. return E_INVALIDARG;
  1077. }
  1078. catch(Structured_Exception e_SE)
  1079. {
  1080. return E_UNEXPECTED;
  1081. }
  1082. catch(Heap_Exception e_HE)
  1083. {
  1084. return E_OUTOFMEMORY;
  1085. }
  1086. catch(...)
  1087. {
  1088. return E_UNEXPECTED;
  1089. }
  1090. }
  1091. SCODE CSmirModuleHandle :: GetRevision(BSTR *pszRevision)
  1092. {
  1093. SetStructuredExceptionHandler seh;
  1094. try
  1095. {
  1096. if(NULL != pszRevision)
  1097. {
  1098. *pszRevision=SysAllocString(m_szRevision);
  1099. return S_OK;
  1100. }
  1101. else
  1102. return E_INVALIDARG;
  1103. }
  1104. catch(Structured_Exception e_SE)
  1105. {
  1106. return E_UNEXPECTED;
  1107. }
  1108. catch(Heap_Exception e_HE)
  1109. {
  1110. return E_OUTOFMEMORY;
  1111. }
  1112. catch(...)
  1113. {
  1114. return E_UNEXPECTED;
  1115. }
  1116. }
  1117. SCODE CSmirModuleHandle :: GetSnmpVersion(ULONG *plSnmp_version)
  1118. {
  1119. SetStructuredExceptionHandler seh;
  1120. try
  1121. {
  1122. if(NULL != plSnmp_version)
  1123. {
  1124. *plSnmp_version=m_lSnmp_version;
  1125. return S_OK;
  1126. }
  1127. else
  1128. return E_INVALIDARG;
  1129. }
  1130. catch(Structured_Exception e_SE)
  1131. {
  1132. return E_UNEXPECTED;
  1133. }
  1134. catch(Heap_Exception e_HE)
  1135. {
  1136. return E_OUTOFMEMORY;
  1137. }
  1138. catch(...)
  1139. {
  1140. return E_UNEXPECTED;
  1141. }
  1142. }
  1143. SCODE CSmirModuleHandle :: GetModuleImports (BSTR* ppszModImports)
  1144. {
  1145. SetStructuredExceptionHandler seh;
  1146. try
  1147. {
  1148. if(NULL != ppszModImports)
  1149. {
  1150. *ppszModImports=SysAllocString(m_szModImports);
  1151. return S_OK;
  1152. }
  1153. else
  1154. return E_INVALIDARG;
  1155. }
  1156. catch(Structured_Exception e_SE)
  1157. {
  1158. return E_UNEXPECTED;
  1159. }
  1160. catch(Heap_Exception e_HE)
  1161. {
  1162. return E_OUTOFMEMORY;
  1163. }
  1164. catch(...)
  1165. {
  1166. return E_UNEXPECTED;
  1167. }
  1168. }
  1169. SCODE CSmirModuleHandle :: SetName(BSTR pszName)
  1170. {
  1171. SetStructuredExceptionHandler seh;
  1172. try
  1173. {
  1174. return CopyBSTR(&m_szName,&pszName);
  1175. }
  1176. catch(Structured_Exception e_SE)
  1177. {
  1178. return E_UNEXPECTED;
  1179. }
  1180. catch(Heap_Exception e_HE)
  1181. {
  1182. return E_OUTOFMEMORY;
  1183. }
  1184. catch(...)
  1185. {
  1186. return E_UNEXPECTED;
  1187. }
  1188. }
  1189. SCODE CSmirModuleHandle :: SetModuleOID(BSTR pszModuleOid)
  1190. {
  1191. SetStructuredExceptionHandler seh;
  1192. try
  1193. {
  1194. return CopyBSTR(&m_szModuleOid,&pszModuleOid);
  1195. }
  1196. catch(Structured_Exception e_SE)
  1197. {
  1198. return E_UNEXPECTED;
  1199. }
  1200. catch(Heap_Exception e_HE)
  1201. {
  1202. return E_OUTOFMEMORY;
  1203. }
  1204. catch(...)
  1205. {
  1206. return E_UNEXPECTED;
  1207. }
  1208. }
  1209. SCODE CSmirModuleHandle :: SetModuleIdentity(BSTR pszModuleId)
  1210. {
  1211. SetStructuredExceptionHandler seh;
  1212. try
  1213. {
  1214. return CopyBSTR(&m_szModuleId,&pszModuleId);
  1215. }
  1216. catch(Structured_Exception e_SE)
  1217. {
  1218. return E_UNEXPECTED;
  1219. }
  1220. catch(Heap_Exception e_HE)
  1221. {
  1222. return E_OUTOFMEMORY;
  1223. }
  1224. catch(...)
  1225. {
  1226. return E_UNEXPECTED;
  1227. }
  1228. }
  1229. SCODE CSmirModuleHandle :: SetLastUpdate(BSTR pszLastUpdate)
  1230. {
  1231. SetStructuredExceptionHandler seh;
  1232. try
  1233. {
  1234. return CopyBSTR(&m_szLastUpdate,&pszLastUpdate);
  1235. }
  1236. catch(Structured_Exception e_SE)
  1237. {
  1238. return E_UNEXPECTED;
  1239. }
  1240. catch(Heap_Exception e_HE)
  1241. {
  1242. return E_OUTOFMEMORY;
  1243. }
  1244. catch(...)
  1245. {
  1246. return E_UNEXPECTED;
  1247. }
  1248. }
  1249. SCODE CSmirModuleHandle :: SetOrganisation(BSTR pszOrganisation)
  1250. {
  1251. SetStructuredExceptionHandler seh;
  1252. try
  1253. {
  1254. return CopyBSTR(&m_szOrganisation,&pszOrganisation);
  1255. }
  1256. catch(Structured_Exception e_SE)
  1257. {
  1258. return E_UNEXPECTED;
  1259. }
  1260. catch(Heap_Exception e_HE)
  1261. {
  1262. return E_OUTOFMEMORY;
  1263. }
  1264. catch(...)
  1265. {
  1266. return E_UNEXPECTED;
  1267. }
  1268. }
  1269. SCODE CSmirModuleHandle :: SetContactInfo(BSTR pszContactInfo)
  1270. {
  1271. SetStructuredExceptionHandler seh;
  1272. try
  1273. {
  1274. return CopyBSTR(&m_szContactInfo,&pszContactInfo);
  1275. }
  1276. catch(Structured_Exception e_SE)
  1277. {
  1278. return E_UNEXPECTED;
  1279. }
  1280. catch(Heap_Exception e_HE)
  1281. {
  1282. return E_OUTOFMEMORY;
  1283. }
  1284. catch(...)
  1285. {
  1286. return E_UNEXPECTED;
  1287. }
  1288. }
  1289. SCODE CSmirModuleHandle :: SetDescription(BSTR pszDescription)
  1290. {
  1291. SetStructuredExceptionHandler seh;
  1292. try
  1293. {
  1294. return CopyBSTR(&m_szDescription,&pszDescription);
  1295. }
  1296. catch(Structured_Exception e_SE)
  1297. {
  1298. return E_UNEXPECTED;
  1299. }
  1300. catch(Heap_Exception e_HE)
  1301. {
  1302. return E_OUTOFMEMORY;
  1303. }
  1304. catch(...)
  1305. {
  1306. return E_UNEXPECTED;
  1307. }
  1308. }
  1309. SCODE CSmirModuleHandle :: SetRevision(BSTR pszRevision)
  1310. {
  1311. SetStructuredExceptionHandler seh;
  1312. try
  1313. {
  1314. return CopyBSTR(&m_szRevision,&pszRevision);
  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 CSmirModuleHandle :: SetSnmpVersion(ULONG plSnmp_version)
  1330. {
  1331. SetStructuredExceptionHandler seh;
  1332. try
  1333. {
  1334. m_lSnmp_version=plSnmp_version;
  1335. return S_OK;
  1336. }
  1337. catch(Structured_Exception e_SE)
  1338. {
  1339. return E_UNEXPECTED;
  1340. }
  1341. catch(Heap_Exception e_HE)
  1342. {
  1343. return E_OUTOFMEMORY;
  1344. }
  1345. catch(...)
  1346. {
  1347. return E_UNEXPECTED;
  1348. }
  1349. }
  1350. SCODE CSmirModuleHandle :: SetModuleImports (BSTR pszModImports)
  1351. {
  1352. SetStructuredExceptionHandler seh;
  1353. try
  1354. {
  1355. return CopyBSTR(&m_szModImports,&pszModImports);
  1356. }
  1357. catch(Structured_Exception e_SE)
  1358. {
  1359. return E_UNEXPECTED;
  1360. }
  1361. catch(Heap_Exception e_HE)
  1362. {
  1363. return E_OUTOFMEMORY;
  1364. }
  1365. catch(...)
  1366. {
  1367. return E_UNEXPECTED;
  1368. }
  1369. }
  1370. CSmirModuleHandle :: ~ CSmirModuleHandle()
  1371. {
  1372. SysFreeString(m_szModuleOid);
  1373. SysFreeString(m_szName);
  1374. SysFreeString(m_szModuleId);
  1375. SysFreeString(m_szOrganisation);
  1376. SysFreeString(m_szContactInfo);
  1377. SysFreeString(m_szDescription);
  1378. SysFreeString(m_szRevision);
  1379. SysFreeString(m_szModImports);
  1380. SysFreeString(m_szLastUpdate);
  1381. CModHandleClassFactory::objectsInProgress--;
  1382. }
  1383. /*Group handle methods
  1384. */
  1385. /*
  1386. * CSmirGroupHandle::QueryInterface
  1387. *
  1388. * Purpose:
  1389. * Manages the interfaces for this object which supports the
  1390. * IUnknown interface.
  1391. *
  1392. * Parameters:
  1393. * riid REFIID of the interface to return.
  1394. * ppv PPVOID in which to store the pointer.
  1395. *
  1396. * Return Value:
  1397. * SCODE NOERROR on success, E_NOINTERFACE if the
  1398. * interface is not supported.
  1399. */
  1400. STDMETHODIMP CSmirGroupHandle::QueryInterface(REFIID riid, PPVOID ppv)
  1401. {
  1402. SetStructuredExceptionHandler seh;
  1403. try
  1404. {
  1405. //Always NULL the out-parameters
  1406. *ppv=NULL;
  1407. if (IID_IUnknown==riid)
  1408. *ppv=this;
  1409. if (IID_ISMIR_GroupHandle==riid)
  1410. *ppv=this;
  1411. if (NULL==*ppv)
  1412. return ResultFromScode(E_NOINTERFACE);
  1413. //AddRef any interface we'll return.
  1414. ((LPUNKNOWN)*ppv)->AddRef();
  1415. return NOERROR;
  1416. }
  1417. catch(Structured_Exception e_SE)
  1418. {
  1419. return E_UNEXPECTED;
  1420. }
  1421. catch(Heap_Exception e_HE)
  1422. {
  1423. return E_OUTOFMEMORY;
  1424. }
  1425. catch(...)
  1426. {
  1427. return E_UNEXPECTED;
  1428. }
  1429. }
  1430. /*
  1431. * CSmirModuleHandle::AddRef
  1432. * CSmirModuleHandle::Release
  1433. *
  1434. * Reference counting members. When Release sees a zero count
  1435. * the object destroys itself.
  1436. */
  1437. ULONG CSmirGroupHandle::AddRef(void)
  1438. {
  1439. SetStructuredExceptionHandler seh;
  1440. try
  1441. {
  1442. //CMOEvent_Trace MyTraceEvent(SMIR_STR);
  1443. //MyTraceEvent.Generate(__FILE__,__LINE__, "CSmirGroupHandle::AddRef( %ld", m_cRef);
  1444. return InterlockedIncrement(&m_cRef);
  1445. }
  1446. catch(Structured_Exception e_SE)
  1447. {
  1448. return 0;
  1449. }
  1450. catch(Heap_Exception e_HE)
  1451. {
  1452. return 0;
  1453. }
  1454. catch(...)
  1455. {
  1456. return 0;
  1457. }
  1458. }
  1459. ULONG CSmirGroupHandle::Release(void)
  1460. {
  1461. SetStructuredExceptionHandler seh;
  1462. try
  1463. {
  1464. long ret;
  1465. if (0!=(ret=InterlockedDecrement(&m_cRef)))
  1466. return ret;
  1467. delete this;
  1468. return 0;
  1469. }
  1470. catch(Structured_Exception e_SE)
  1471. {
  1472. return 0;
  1473. }
  1474. catch(Heap_Exception e_HE)
  1475. {
  1476. return 0;
  1477. }
  1478. catch(...)
  1479. {
  1480. return 0;
  1481. }
  1482. }
  1483. CSmirGroupHandle :: CSmirGroupHandle()
  1484. : m_szModuleName(NULL), m_szName(NULL),
  1485. m_szGroupId(NULL), m_szDescription(NULL),
  1486. m_szReference(NULL),m_szStatus(NULL)
  1487. {
  1488. //init the reference count
  1489. m_cRef=0;
  1490. //start off as a handel to nothing
  1491. //inc the factory count
  1492. CGroupHandleClassFactory::objectsInProgress++;
  1493. }
  1494. CSmirGroupHandle :: ~ CSmirGroupHandle()
  1495. {
  1496. SysFreeString(m_szModuleName);
  1497. SysFreeString(m_szName);
  1498. SysFreeString(m_szGroupId);
  1499. SysFreeString(m_szDescription);
  1500. SysFreeString(m_szReference);
  1501. SysFreeString(m_szStatus);
  1502. CGroupHandleClassFactory::objectsInProgress--;
  1503. }
  1504. /*
  1505. * CSmirGroupHandle::void* operator
  1506. * validate handle
  1507. */
  1508. CSmirGroupHandle::operator void*()
  1509. {
  1510. if((NULL!=m_szModuleName)&&(NULL!=m_szName))
  1511. return this;
  1512. return NULL;
  1513. }
  1514. /**************************************************************************************
  1515. *Methods not exposed by the ISmirGroupHandle interface.
  1516. *Used to encapsulate functionality.
  1517. **************************************************************************************/
  1518. STDMETHODIMP CSmirGroupHandle::AddToDB( CSmir *a_Smir , ISmirModHandle *hModule)
  1519. {
  1520. //save the module name
  1521. BSTR szTmpStr;
  1522. hModule->GetName(&szTmpStr);
  1523. SetModuleName(szTmpStr);
  1524. SysFreeString(szTmpStr);
  1525. //open the module namespace
  1526. IWbemServices * moServ = NULL ;
  1527. IWbemContext *moContext = NULL ;
  1528. SCODE result= CSmirAccess :: GetContext (a_Smir , &moContext);
  1529. result= CSmirAccess :: Open(a_Smir,&moServ,hModule);
  1530. if (FAILED(result)||(NULL == moServ))
  1531. {
  1532. if ( moContext )
  1533. moContext->Release () ;
  1534. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  1535. return WBEM_E_FAILED;
  1536. }
  1537. //get an object
  1538. IWbemClassObject *pGrpClass = NULL ;
  1539. CBString t_BStr ( GROUP_NAMESPACE_NAME ) ;
  1540. result = moServ->GetObject(t_BStr.GetString (), 0,
  1541. moContext,&pGrpClass,NULL );
  1542. if ( !SUCCEEDED(result) )
  1543. {
  1544. //OK we have the module namespace so create the group class
  1545. IWbemClassObject *pNewClass = NULL ;
  1546. CBString t_BStr ( OLEMS_NAMESPACE_CLASS ) ;
  1547. result = moServ->GetObject(t_BStr.GetString (), RESERVED_WBEM_FLAG,
  1548. moContext, &pNewClass,NULL);
  1549. if ((FAILED(result))||(NULL==pNewClass))
  1550. {
  1551. if ( moContext )
  1552. moContext->Release () ;
  1553. moServ->Release();
  1554. return WBEM_E_FAILED;
  1555. }
  1556. // Spawn derived class
  1557. IWbemClassObject *pNewDerivedClass = NULL ;
  1558. result = pNewClass->SpawnDerivedClass ( 0 , &pNewDerivedClass ) ;
  1559. pNewClass->Release();
  1560. if ((FAILED(result))||(NULL==pNewDerivedClass))
  1561. {
  1562. if ( moContext )
  1563. moContext->Release () ;
  1564. moServ->Release();
  1565. return WBEM_E_FAILED;
  1566. }
  1567. VARIANT v;
  1568. VariantInit(&v);
  1569. //OK I have a new class so give it a name
  1570. V_VT(&v) = VT_BSTR;
  1571. V_BSTR(&v)=SysAllocString(GROUP_NAMESPACE_NAME);
  1572. result = pNewDerivedClass->Put(OLEMS_CLASS_PROP,RESERVED_WBEM_FLAG, &v,0);
  1573. VariantClear(&v);
  1574. if (FAILED(result))
  1575. {
  1576. if ( moContext )
  1577. moContext->Release () ;
  1578. moServ->Release();
  1579. pNewDerivedClass->Release();
  1580. return WBEM_E_FAILED;
  1581. }
  1582. result = PutClassProperties(pNewDerivedClass) ;
  1583. if (FAILED(result))
  1584. {
  1585. if ( moContext )
  1586. moContext->Release () ;
  1587. pNewDerivedClass->Release();
  1588. moServ->Release();
  1589. return WBEM_E_FAILED;
  1590. }
  1591. //now commit the changes
  1592. result = moServ->PutClass(pNewDerivedClass, RESERVED_WBEM_FLAG, moContext, NULL);
  1593. pNewDerivedClass->Release();
  1594. if (FAILED(result))
  1595. {
  1596. if ( moContext )
  1597. moContext->Release () ;
  1598. moServ->Release();
  1599. return WBEM_E_FAILED;
  1600. }
  1601. //and create an instance of the group namespace
  1602. //get an object
  1603. //get an object
  1604. t_BStr = GROUP_NAMESPACE_NAME ;
  1605. result = moServ->GetObject(t_BStr.GetString (), 0,
  1606. moContext, &pGrpClass,NULL );
  1607. if (FAILED(result))
  1608. {
  1609. if ( moContext )
  1610. moContext->Release () ;
  1611. moServ->Release();
  1612. return WBEM_E_FAILED;
  1613. }
  1614. }
  1615. // Spawn instance of class
  1616. IWbemClassObject *pNewInstance ;
  1617. result = pGrpClass->SpawnInstance ( 0 , &pNewInstance ) ;
  1618. if ((FAILED(result))||(NULL==pNewInstance))
  1619. {
  1620. if ( moContext )
  1621. moContext->Release () ;
  1622. moServ->Release();
  1623. pGrpClass->Release () ;
  1624. return WBEM_E_FAILED;
  1625. }
  1626. pGrpClass->Release () ;
  1627. //fill in the instance
  1628. *this >> pNewInstance;
  1629. //and commit it to the namespace
  1630. result = moServ->PutInstance(pNewInstance, RESERVED_WBEM_FLAG,moContext, NULL);
  1631. pNewInstance->Release();
  1632. if (FAILED(result))
  1633. {
  1634. if ( moContext )
  1635. moContext->Release () ;
  1636. moServ->Release();
  1637. return WBEM_E_FAILED;
  1638. }
  1639. if ( moContext )
  1640. moContext->Release () ;
  1641. moServ->Release();
  1642. if (FAILED(result))
  1643. {
  1644. return WBEM_E_FAILED;
  1645. }
  1646. return S_OK;
  1647. }
  1648. STDMETHODIMP CSmirGroupHandle::DeleteFromDB ( CSmir *a_Smir )
  1649. {
  1650. //open the smir name space
  1651. IWbemServices * moServ = NULL ;
  1652. IWbemContext *moContext = NULL ;
  1653. SCODE res= CSmirAccess :: GetContext (a_Smir , &moContext);
  1654. res= CSmirAccess :: Open(a_Smir,&moServ);
  1655. if ((S_FALSE==res)||(NULL == (void*)moServ))
  1656. {
  1657. //we have a problem the SMIR is not there and cannot be created
  1658. if ( moContext )
  1659. moContext->Release () ;
  1660. return WBEM_E_FAILED;
  1661. }
  1662. /******************delete all of the classes in this group***********************/
  1663. IEnumClass *pTEnumSmirClass = NULL ;
  1664. ISmirInterrogator *pInterrogativeInt = NULL ;
  1665. SCODE result = g_pClassFactoryHelper->CreateInstance (
  1666. CLSID_SMIR_Database,
  1667. IID_ISMIR_Interrogative,
  1668. (PVOID *)&pInterrogativeInt
  1669. );
  1670. if ( ! SUCCEEDED ( result ) )
  1671. {
  1672. if ( moContext )
  1673. moContext->Release () ;
  1674. moServ->Release();
  1675. return S_OK;
  1676. }
  1677. ISMIRWbemConfiguration *t_Configuration = NULL ;
  1678. result = pInterrogativeInt->QueryInterface (
  1679. IID_ISMIRWbemConfiguration ,
  1680. ( void ** ) &t_Configuration
  1681. ) ;
  1682. if ( ! SUCCEEDED ( result ) )
  1683. {
  1684. if ( moContext )
  1685. moContext->Release () ;
  1686. moServ->Release();
  1687. pInterrogativeInt->Release();
  1688. return S_OK;
  1689. }
  1690. ISMIRWbemConfiguration *t_CopyConfiguration = NULL ;
  1691. result = pInterrogativeInt->QueryInterface (
  1692. IID_ISMIRWbemConfiguration ,
  1693. ( void ** ) &t_CopyConfiguration
  1694. ) ;
  1695. if ( ! SUCCEEDED ( result ) )
  1696. {
  1697. t_Configuration->Release () ;
  1698. pInterrogativeInt->Release();
  1699. }
  1700. t_Configuration->Impersonate ( t_CopyConfiguration ) ;
  1701. if ( ! SUCCEEDED ( result ) )
  1702. {
  1703. t_Configuration->Release () ;
  1704. t_CopyConfiguration->Release () ;
  1705. pInterrogativeInt->Release();
  1706. }
  1707. t_Configuration->Release () ;
  1708. t_CopyConfiguration->Release () ;
  1709. res = pInterrogativeInt->EnumClassesInGroup (&pTEnumSmirClass,this);
  1710. //now use the enumerator
  1711. if(FAILED(res))
  1712. {
  1713. if ( moContext )
  1714. moContext->Release () ;
  1715. moServ->Release();
  1716. pInterrogativeInt->Release();
  1717. return S_OK;
  1718. }
  1719. //loop over the classes and remove them
  1720. ISmirClassHandle *phClass=NULL;
  1721. for(int iCount=0;S_OK==pTEnumSmirClass->Next(1, &phClass, NULL);iCount++)
  1722. {
  1723. /*got one so remove it. Don't check the return because there is nothing
  1724. *I can do about it.
  1725. */
  1726. ((CSmirClassHandle*)phClass)->DeleteClassFromGroup(a_Smir);
  1727. phClass->Release();
  1728. }
  1729. pTEnumSmirClass->Release();
  1730. pInterrogativeInt->Release();
  1731. /************************* delete the associations******************************/
  1732. //delete everthing that is associated with the group using
  1733. //references of {\\.\root\default\SMIR:<group>}
  1734. IEnumWbemClassObject *pEnum = NULL ;
  1735. CString sQuery(CString(SMIR_ASSOC_QUERY_STR2)
  1736. +CString(OPEN_BRACE_STR)
  1737. +CString(SMIR_NAMESPACE_FROM_ROOT)
  1738. +CString(BACKSLASH_STR)
  1739. +CString(m_szModuleName)
  1740. +CString(COLON_STR)
  1741. +CString(GROUP_NAMESPACE_NAME)
  1742. +CString(EQUALS_STR)
  1743. +CString(QUOTE_STR)
  1744. +CString(m_szName)
  1745. +CString(QUOTE_STR)
  1746. +CString(CLOSE_BRACE_STR)
  1747. );
  1748. BSTR szQuery = sQuery.AllocSysString();
  1749. CBString t_QueryFormat (SMIR_ASSOC_QUERY1_TYPE);
  1750. SCODE sRes = moServ->ExecQuery(t_QueryFormat.GetString (), szQuery,
  1751. RESERVED_WBEM_FLAG, moContext, &pEnum);
  1752. SysFreeString(szQuery);
  1753. if (FAILED(sRes)||(NULL==pEnum))
  1754. {
  1755. //all groups that contain classes are associated so this may not be a problem
  1756. if ( moContext )
  1757. moContext->Release () ;
  1758. moServ->Release();
  1759. return S_OK;
  1760. }
  1761. ULONG uCount=1;
  1762. IWbemClassObject *pAssocMosClass = NULL ;
  1763. ULONG puReturned;
  1764. //loop over the associations
  1765. VARIANT assocClass;
  1766. VariantInit(&assocClass);
  1767. VARIANT assocName;
  1768. VariantInit(&assocName);
  1769. for(pEnum->Reset();S_OK==pEnum->Next(-1,uCount,&pAssocMosClass,&puReturned);)
  1770. {
  1771. pAssocMosClass->Get(SMIR_X_ASSOC_NAME_PROP, RESERVED_WBEM_FLAG, &assocName,NULL,NULL);
  1772. pAssocMosClass->Get(OLEMS_CLASS_PROP, RESERVED_WBEM_FLAG, &assocClass,NULL,NULL);
  1773. pAssocMosClass->Release();
  1774. CString instString(
  1775. CString(V_BSTR(&assocClass))
  1776. +CString(EQUALS_STR)
  1777. +CString(QUOTE_STR)
  1778. +CString(V_BSTR(&assocName))
  1779. +CString(QUOTE_STR)
  1780. );
  1781. VariantClear(&assocName);
  1782. VariantClear(&assocClass);
  1783. BSTR instBString = instString.AllocSysString();
  1784. moServ->DeleteInstance(instBString, RESERVED_WBEM_FLAG, moContext,NULL);
  1785. SysFreeString(instBString);
  1786. }
  1787. pEnum->Release();
  1788. moServ->Release();
  1789. /*************************now delete the group******************************/
  1790. //open the module name space
  1791. res= CSmirAccess :: Open(a_Smir,&moServ, this,CSmirAccess::eModule);
  1792. if ((S_FALSE==res)||(NULL == (void*)moServ))
  1793. {
  1794. //we have a problem the SMIR is not there and cannot be created
  1795. if ( moContext )
  1796. moContext->Release () ;
  1797. return WBEM_E_FAILED;
  1798. }
  1799. //OK we have the module namespace so delete the group
  1800. //build the object path
  1801. wchar_t *pTString = new wchar_t[wcslen(GROUP_NAMESPACE_NAME)+wcslen(EQUALS_STR)+
  1802. wcslen(m_szName)+2+1];
  1803. if(NULL == pTString)
  1804. {
  1805. //free the string we got from hGroup
  1806. if ( moContext )
  1807. moContext->Release () ;
  1808. moServ->Release();
  1809. return E_OUTOFMEMORY;
  1810. }
  1811. wcscpy(pTString, GROUP_NAMESPACE_NAME);
  1812. wcscat(pTString,EQUALS_STR);
  1813. wcscat(pTString,QUOTE_STR);
  1814. // GROUP =
  1815. wcscat(pTString,m_szName);
  1816. wcscat(pTString,QUOTE_STR);
  1817. // GROUP = <group name>
  1818. CBString t_Str (pTString);
  1819. result = moServ->DeleteInstance(t_Str.GetString (), RESERVED_WBEM_FLAG, moContext,NULL);
  1820. moServ->Release();
  1821. if ( moContext )
  1822. moContext->Release () ;
  1823. delete [] pTString;
  1824. if (FAILED(result))
  1825. {
  1826. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  1827. return WBEM_E_FAILED;
  1828. }
  1829. return S_OK;
  1830. }
  1831. const CSmirGroupHandle& CSmirGroupHandle :: operator <<(IWbemClassObject *pSmirMosClassObject)
  1832. {
  1833. //get the name
  1834. VARIANT v;
  1835. VariantInit(&v);
  1836. pSmirMosClassObject->Get(GROUP_NAME_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  1837. if (V_VT(&v) == VT_BSTR)
  1838. {
  1839. SetName(V_BSTR(&v));
  1840. }
  1841. VariantClear(&v);
  1842. //get the group id
  1843. pSmirMosClassObject->Get(GROUP_ID_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  1844. if (V_VT(&v) == VT_BSTR)
  1845. {
  1846. SetGroupOID(V_BSTR(&v));
  1847. }
  1848. VariantClear(&v);
  1849. //get the status
  1850. pSmirMosClassObject->Get(GROUP_STATUS_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  1851. if (V_VT(&v) == VT_BSTR)
  1852. {
  1853. SetStatus(V_BSTR(&v));
  1854. }
  1855. VariantClear(&v);
  1856. //get the description
  1857. pSmirMosClassObject->Get(GROUP_DESCRIPTION_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  1858. if (V_VT(&v) == VT_BSTR)
  1859. {
  1860. SetDescription(V_BSTR(&v));
  1861. }
  1862. VariantClear(&v);
  1863. //get the reference
  1864. pSmirMosClassObject->Get(MODULE_REFERENCE_PROPERTY, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  1865. if (V_VT(&v) == VT_BSTR)
  1866. {
  1867. SetReference(V_BSTR(&v));
  1868. }
  1869. VariantClear(&v);
  1870. return *this;
  1871. }
  1872. const CSmirGroupHandle& CSmirGroupHandle :: operator >>(IWbemClassObject *pInst)
  1873. {
  1874. VARIANT v;
  1875. VariantInit(&v);
  1876. //give the instance a name
  1877. V_VT(&v) = VT_BSTR;
  1878. SCODE result;
  1879. if(NULL != m_szName)
  1880. {
  1881. V_BSTR(&v)=SysAllocString(m_szName);
  1882. result = pInst->Put(OLEMS_NAME_PROP,RESERVED_WBEM_FLAG, &v,0);
  1883. VariantClear(&v);
  1884. if (FAILED(result))
  1885. {
  1886. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  1887. return *this;
  1888. }
  1889. }
  1890. else
  1891. {
  1892. return *this;
  1893. }
  1894. //add the group oid property
  1895. V_VT(&v) = VT_BSTR;
  1896. if(NULL != m_szGroupId)
  1897. {
  1898. V_BSTR(&v)=SysAllocString(m_szGroupId);
  1899. result = pInst->Put(GROUP_ID_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  1900. VariantClear(&v);
  1901. if (FAILED(result))
  1902. {
  1903. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  1904. return *this;
  1905. }
  1906. }
  1907. //add the status property
  1908. V_VT(&v) = VT_BSTR;
  1909. if(NULL != m_szStatus)
  1910. {
  1911. V_BSTR(&v)=SysAllocString(m_szStatus);
  1912. result = pInst->Put(GROUP_STATUS_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  1913. VariantClear(&v);
  1914. if (FAILED(result))
  1915. {
  1916. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  1917. return *this;
  1918. }
  1919. }
  1920. //add the Description property
  1921. V_VT(&v) = VT_BSTR;
  1922. if(NULL != m_szDescription)
  1923. {
  1924. V_BSTR(&v)=SysAllocString(m_szDescription);
  1925. result = pInst->Put(GROUP_DESCRIPTION_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  1926. VariantClear(&v);
  1927. if (FAILED(result))
  1928. {
  1929. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  1930. return *this;
  1931. }
  1932. }
  1933. //add the reference property
  1934. V_VT(&v) = VT_BSTR;
  1935. if(NULL != m_szReference)
  1936. {
  1937. V_BSTR(&v)=SysAllocString(m_szReference);
  1938. result = pInst->Put(MODULE_REFERENCE_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  1939. VariantClear(&v);
  1940. if (FAILED(result))
  1941. {
  1942. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  1943. return *this;
  1944. }
  1945. }
  1946. //add the references to the classes
  1947. //and return
  1948. return *this;
  1949. }
  1950. HRESULT CSmirGroupHandle :: PutClassProperties (IWbemClassObject *pClass)
  1951. {
  1952. VARIANT v;
  1953. VariantInit(&v);
  1954. //give the instance a name
  1955. V_VT(&v) = VT_BSTR;
  1956. HRESULT result;
  1957. V_BSTR(&v)=SysAllocString(L"");
  1958. result = pClass->Put(OLEMS_NAME_PROP,RESERVED_WBEM_FLAG, &v,0);
  1959. VariantClear(&v);
  1960. if (FAILED(result))
  1961. {
  1962. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  1963. return result ;
  1964. }
  1965. //add the group oid property
  1966. V_VT(&v) = VT_BSTR;
  1967. V_BSTR(&v)=SysAllocString(L"");
  1968. result = pClass->Put(GROUP_ID_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  1969. VariantClear(&v);
  1970. if (FAILED(result))
  1971. {
  1972. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  1973. return result ;
  1974. }
  1975. //add the status property
  1976. V_VT(&v) = VT_BSTR;
  1977. V_BSTR(&v)=SysAllocString(L"");
  1978. result = pClass->Put(GROUP_STATUS_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  1979. VariantClear(&v);
  1980. if (FAILED(result))
  1981. {
  1982. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  1983. return result ;
  1984. }
  1985. //add the Description property
  1986. V_VT(&v) = VT_BSTR;
  1987. V_BSTR(&v)=SysAllocString(L"");
  1988. result = pClass->Put(GROUP_DESCRIPTION_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  1989. VariantClear(&v);
  1990. if (FAILED(result))
  1991. {
  1992. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  1993. return result;
  1994. }
  1995. //add the reference property
  1996. V_VT(&v) = VT_BSTR;
  1997. V_BSTR(&v)=SysAllocString(L"");
  1998. result = pClass->Put(MODULE_REFERENCE_PROPERTY,RESERVED_WBEM_FLAG, &v,0);
  1999. VariantClear(&v);
  2000. if (FAILED(result))
  2001. {
  2002. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  2003. return result ;
  2004. }
  2005. //add the references to the classes
  2006. return result ;
  2007. }
  2008. const CSmirGroupHandle& CSmirGroupHandle :: operator >>(ISmirSerialiseHandle *pSHandle)
  2009. {
  2010. if(NULL!=pSHandle)
  2011. {
  2012. CString szTmpString;
  2013. BOOL bMOFPragmas=((CSmirSerialiseHandle*) pSHandle)->ReturnMOFPragmas();
  2014. BOOL bMOFAssociations=((CSmirSerialiseHandle*) pSHandle)->ReturnMOFAssociations();
  2015. //start in the group namepspace
  2016. if(TRUE==bMOFPragmas)
  2017. {
  2018. szTmpString=CString(START_OF_SMIR_NAMESPACE_PRAGMA);
  2019. szTmpString+=CString(m_szModuleName);
  2020. szTmpString+=CString(END_OF_NAMESPACE_PRAGMA);
  2021. }
  2022. if(TRUE==bMOFAssociations)
  2023. {
  2024. //create an instance of the group namespace
  2025. szTmpString+=GROUP_INSTANCE_START;
  2026. //add the properties
  2027. //give the instance a name
  2028. szTmpString+=CString(GROUP_NAME_PROPERTY);
  2029. szTmpString+=START_OF_PROPERTY_VALUE;
  2030. szTmpString+=CString(m_szName);
  2031. szTmpString+=END_OF_PROPERTY_VALUE;
  2032. //give the instance a group id
  2033. szTmpString+=CString(GROUP_ID_PROPERTY);
  2034. szTmpString+=START_OF_PROPERTY_VALUE;
  2035. szTmpString+=CString(m_szGroupId);
  2036. szTmpString+=END_OF_PROPERTY_VALUE;
  2037. //give the instance a status
  2038. szTmpString+=CString(GROUP_STATUS_PROPERTY);
  2039. szTmpString+=START_OF_PROPERTY_VALUE;
  2040. szTmpString+=CString(m_szStatus);
  2041. szTmpString+=END_OF_PROPERTY_VALUE;
  2042. //give the instance a description
  2043. szTmpString+=CString(GROUP_DESCRIPTION_PROPERTY);
  2044. szTmpString+=START_OF_PROPERTY_VALUE;
  2045. szTmpString+=CString(m_szDescription);
  2046. szTmpString+=END_OF_PROPERTY_VALUE;
  2047. //give the instance a reference
  2048. szTmpString+=CString(MODULE_REFERENCE_PROPERTY);
  2049. szTmpString+=START_OF_PROPERTY_VALUE;
  2050. szTmpString+=CString(m_szReference);
  2051. szTmpString+=END_OF_PROPERTY_VALUE;
  2052. szTmpString+=CString(END_OF_CLASS);
  2053. }
  2054. //and add the string to the serialise handle
  2055. ((CSmirSerialiseHandle*)pSHandle)->m_serialiseString+=CString(szTmpString);
  2056. //each class will create it's self
  2057. }
  2058. return *this;
  2059. }
  2060. SCODE CSmirGroupHandle :: GetModuleName(BSTR *szName)
  2061. {
  2062. SetStructuredExceptionHandler seh;
  2063. try
  2064. {
  2065. if(NULL != szName)
  2066. {
  2067. *szName=SysAllocString(m_szModuleName);
  2068. return S_OK;
  2069. }
  2070. else
  2071. return E_INVALIDARG;
  2072. }
  2073. catch(Structured_Exception e_SE)
  2074. {
  2075. return E_UNEXPECTED;
  2076. }
  2077. catch(Heap_Exception e_HE)
  2078. {
  2079. return E_OUTOFMEMORY;
  2080. }
  2081. catch(...)
  2082. {
  2083. return E_UNEXPECTED;
  2084. }
  2085. }
  2086. SCODE CSmirGroupHandle :: GetName(BSTR *szName)
  2087. {
  2088. SetStructuredExceptionHandler seh;
  2089. try
  2090. {
  2091. if(NULL != szName)
  2092. {
  2093. *szName=SysAllocString(m_szName);
  2094. return S_OK;
  2095. }
  2096. else
  2097. return E_INVALIDARG;
  2098. }
  2099. catch(Structured_Exception e_SE)
  2100. {
  2101. return E_UNEXPECTED;
  2102. }
  2103. catch(Heap_Exception e_HE)
  2104. {
  2105. return E_OUTOFMEMORY;
  2106. }
  2107. catch(...)
  2108. {
  2109. return E_UNEXPECTED;
  2110. }
  2111. }
  2112. SCODE CSmirGroupHandle :: GetGroupOID(BSTR *szGroupId)
  2113. {
  2114. SetStructuredExceptionHandler seh;
  2115. try
  2116. {
  2117. if(NULL != szGroupId)
  2118. {
  2119. *szGroupId = SysAllocString(m_szGroupId);
  2120. return S_OK;
  2121. }
  2122. else
  2123. return E_INVALIDARG;
  2124. }
  2125. catch(Structured_Exception e_SE)
  2126. {
  2127. return E_UNEXPECTED;
  2128. }
  2129. catch(Heap_Exception e_HE)
  2130. {
  2131. return E_OUTOFMEMORY;
  2132. }
  2133. catch(...)
  2134. {
  2135. return E_UNEXPECTED;
  2136. }
  2137. }
  2138. SCODE CSmirGroupHandle :: GetStatus(BSTR *szStatus)
  2139. {
  2140. SetStructuredExceptionHandler seh;
  2141. try
  2142. {
  2143. if(NULL != szStatus)
  2144. {
  2145. *szStatus = SysAllocString(m_szStatus);
  2146. return S_OK;
  2147. }
  2148. else
  2149. return E_INVALIDARG;
  2150. }
  2151. catch(Structured_Exception e_SE)
  2152. {
  2153. return E_UNEXPECTED;
  2154. }
  2155. catch(Heap_Exception e_HE)
  2156. {
  2157. return E_OUTOFMEMORY;
  2158. }
  2159. catch(...)
  2160. {
  2161. return E_UNEXPECTED;
  2162. }
  2163. }
  2164. SCODE CSmirGroupHandle :: GetDescription(BSTR *szDescription)
  2165. {
  2166. SetStructuredExceptionHandler seh;
  2167. try
  2168. {
  2169. if(NULL != szDescription)
  2170. {
  2171. *szDescription = SysAllocString(m_szDescription);
  2172. return S_OK;
  2173. }
  2174. else
  2175. return E_INVALIDARG;
  2176. }
  2177. catch(Structured_Exception e_SE)
  2178. {
  2179. return E_UNEXPECTED;
  2180. }
  2181. catch(Heap_Exception e_HE)
  2182. {
  2183. return E_OUTOFMEMORY;
  2184. }
  2185. catch(...)
  2186. {
  2187. return E_UNEXPECTED;
  2188. }
  2189. }
  2190. SCODE CSmirGroupHandle :: GetReference(BSTR *szReference)
  2191. {
  2192. SetStructuredExceptionHandler seh;
  2193. try
  2194. {
  2195. if(NULL != szReference)
  2196. {
  2197. *szReference = SysAllocString(m_szReference);
  2198. return S_OK;
  2199. }
  2200. else
  2201. return E_INVALIDARG;
  2202. }
  2203. catch(Structured_Exception e_SE)
  2204. {
  2205. return E_UNEXPECTED;
  2206. }
  2207. catch(Heap_Exception e_HE)
  2208. {
  2209. return E_OUTOFMEMORY;
  2210. }
  2211. catch(...)
  2212. {
  2213. return E_UNEXPECTED;
  2214. }
  2215. }
  2216. SCODE CSmirGroupHandle :: SetModuleName(BSTR szName)
  2217. {
  2218. SetStructuredExceptionHandler seh;
  2219. try
  2220. {
  2221. return CopyBSTR(&m_szModuleName,&szName);
  2222. }
  2223. catch(Structured_Exception e_SE)
  2224. {
  2225. return E_UNEXPECTED;
  2226. }
  2227. catch(Heap_Exception e_HE)
  2228. {
  2229. return E_OUTOFMEMORY;
  2230. }
  2231. catch(...)
  2232. {
  2233. return E_UNEXPECTED;
  2234. }
  2235. }
  2236. SCODE CSmirGroupHandle :: SetName(BSTR szName)
  2237. {
  2238. SetStructuredExceptionHandler seh;
  2239. try
  2240. {
  2241. return CopyBSTR(&m_szName,&szName);
  2242. }
  2243. catch(Structured_Exception e_SE)
  2244. {
  2245. return E_UNEXPECTED;
  2246. }
  2247. catch(Heap_Exception e_HE)
  2248. {
  2249. return E_OUTOFMEMORY;
  2250. }
  2251. catch(...)
  2252. {
  2253. return E_UNEXPECTED;
  2254. }
  2255. }
  2256. SCODE CSmirGroupHandle :: SetGroupOID(BSTR szGroupId)
  2257. {
  2258. SetStructuredExceptionHandler seh;
  2259. try
  2260. {
  2261. return CopyBSTR(&m_szGroupId,&szGroupId);
  2262. }
  2263. catch(Structured_Exception e_SE)
  2264. {
  2265. return E_UNEXPECTED;
  2266. }
  2267. catch(Heap_Exception e_HE)
  2268. {
  2269. return E_OUTOFMEMORY;
  2270. }
  2271. catch(...)
  2272. {
  2273. return E_UNEXPECTED;
  2274. }
  2275. }
  2276. SCODE CSmirGroupHandle :: SetStatus(BSTR szStatus)
  2277. {
  2278. SetStructuredExceptionHandler seh;
  2279. try
  2280. {
  2281. return CopyBSTR(&m_szStatus,&szStatus);
  2282. }
  2283. catch(Structured_Exception e_SE)
  2284. {
  2285. return E_UNEXPECTED;
  2286. }
  2287. catch(Heap_Exception e_HE)
  2288. {
  2289. return E_OUTOFMEMORY;
  2290. }
  2291. catch(...)
  2292. {
  2293. return E_UNEXPECTED;
  2294. }
  2295. }
  2296. SCODE CSmirGroupHandle :: SetDescription(BSTR szDescription)
  2297. {
  2298. SetStructuredExceptionHandler seh;
  2299. try
  2300. {
  2301. return CopyBSTR(&m_szDescription,&szDescription);
  2302. }
  2303. catch(Structured_Exception e_SE)
  2304. {
  2305. return E_UNEXPECTED;
  2306. }
  2307. catch(Heap_Exception e_HE)
  2308. {
  2309. return E_OUTOFMEMORY;
  2310. }
  2311. catch(...)
  2312. {
  2313. return E_UNEXPECTED;
  2314. }
  2315. }
  2316. SCODE CSmirGroupHandle :: SetReference(BSTR szReference)
  2317. {
  2318. SetStructuredExceptionHandler seh;
  2319. try
  2320. {
  2321. return CopyBSTR(&m_szReference,&szReference);
  2322. }
  2323. catch(Structured_Exception e_SE)
  2324. {
  2325. return E_UNEXPECTED;
  2326. }
  2327. catch(Heap_Exception e_HE)
  2328. {
  2329. return E_OUTOFMEMORY;
  2330. }
  2331. catch(...)
  2332. {
  2333. return E_UNEXPECTED;
  2334. }
  2335. }
  2336. /*Class handle methods
  2337. */
  2338. /*
  2339. * CSmirClassHandle::QueryInterface
  2340. *
  2341. * Purpose:
  2342. * Manages the interfaces for this object which supports the
  2343. * IUnknown interface.
  2344. *
  2345. * Parameters:
  2346. * riid REFIID of the interface to return.
  2347. * ppv PPVOID in which to store the pointer.
  2348. *
  2349. * Return Value:
  2350. * SCODE NOERROR on success, E_NOINTERFACE if the
  2351. * interface is not supported.
  2352. */
  2353. STDMETHODIMP CSmirClassHandle::QueryInterface(REFIID riid, PPVOID ppv)
  2354. {
  2355. SetStructuredExceptionHandler seh;
  2356. try
  2357. {
  2358. //Always NULL the out-parameters
  2359. *ppv=NULL;
  2360. if (IID_IUnknown==riid)
  2361. *ppv=this;
  2362. if (IID_ISMIR_ClassHandle==riid)
  2363. *ppv=this;
  2364. if (NULL==*ppv)
  2365. return ResultFromScode(E_NOINTERFACE);
  2366. //AddRef any interface we'll return.
  2367. ((LPUNKNOWN)*ppv)->AddRef();
  2368. return NOERROR;
  2369. }
  2370. catch(Structured_Exception e_SE)
  2371. {
  2372. return E_UNEXPECTED;
  2373. }
  2374. catch(Heap_Exception e_HE)
  2375. {
  2376. return E_OUTOFMEMORY;
  2377. }
  2378. catch(...)
  2379. {
  2380. return E_UNEXPECTED;
  2381. }
  2382. }
  2383. /*
  2384. * CSmirModuleHandle::AddRef
  2385. * CSmirModuleHandle::Release
  2386. *
  2387. * Reference counting members. When Release sees a zero count
  2388. * the object destroys itself.
  2389. */
  2390. ULONG CSmirClassHandle::AddRef(void)
  2391. {
  2392. SetStructuredExceptionHandler seh;
  2393. try
  2394. {
  2395. //CMOEvent_Trace MyTraceEvent(SMIR_STR);
  2396. //MyTraceEvent.Generate(__FILE__,__LINE__, "CSmirClassHandle::AddRef( %ld", m_cRef);
  2397. return InterlockedIncrement(&m_cRef);
  2398. }
  2399. catch(Structured_Exception e_SE)
  2400. {
  2401. return 0;
  2402. }
  2403. catch(Heap_Exception e_HE)
  2404. {
  2405. return 0;
  2406. }
  2407. catch(...)
  2408. {
  2409. return 0;
  2410. }
  2411. }
  2412. ULONG CSmirClassHandle::Release(void)
  2413. {
  2414. SetStructuredExceptionHandler seh;
  2415. try
  2416. {
  2417. long ret;
  2418. if (0!=(ret=InterlockedDecrement(&m_cRef)))
  2419. return ret;
  2420. delete this;
  2421. return 0;
  2422. }
  2423. catch(Structured_Exception e_SE)
  2424. {
  2425. return 0;
  2426. }
  2427. catch(Heap_Exception e_HE)
  2428. {
  2429. return 0;
  2430. }
  2431. catch(...)
  2432. {
  2433. return 0;
  2434. }
  2435. }
  2436. CSmirClassHandle :: CSmirClassHandle()
  2437. : m_pIMosClass(NULL), m_szModuleName(NULL), m_szGroupName(NULL)
  2438. {
  2439. CClassHandleClassFactory::objectsInProgress++;
  2440. //init the reference count
  2441. m_cRef=0;
  2442. }
  2443. CSmirClassHandle :: ~ CSmirClassHandle()
  2444. {
  2445. if (NULL != m_pIMosClass)
  2446. m_pIMosClass->Release();
  2447. SysFreeString(m_szModuleName);
  2448. SysFreeString(m_szGroupName);
  2449. CClassHandleClassFactory::objectsInProgress--;
  2450. }
  2451. /*
  2452. * CSmirModuleHandle::void* operator
  2453. * validate handle
  2454. */
  2455. CSmirClassHandle::operator void*()
  2456. {
  2457. if((NULL!=m_szModuleName)&&(NULL!=m_szGroupName)&&(NULL!=m_pIMosClass))
  2458. return this;
  2459. return NULL;
  2460. }
  2461. SCODE CSmirClassHandle :: SetWBEMClass(IWbemClassObject *pObj)
  2462. {
  2463. SetStructuredExceptionHandler seh;
  2464. try
  2465. {
  2466. if(NULL != pObj)
  2467. {
  2468. m_pIMosClass = pObj;
  2469. m_pIMosClass->AddRef () ;
  2470. return S_OK;
  2471. }
  2472. else
  2473. return E_INVALIDARG;
  2474. }
  2475. catch(Structured_Exception e_SE)
  2476. {
  2477. return E_UNEXPECTED;
  2478. }
  2479. catch(Heap_Exception e_HE)
  2480. {
  2481. return E_OUTOFMEMORY;
  2482. }
  2483. catch(...)
  2484. {
  2485. return E_UNEXPECTED;
  2486. }
  2487. }
  2488. SCODE CSmirClassHandle :: GetWBEMClass (
  2489. IWbemClassObject **pObj
  2490. )
  2491. {
  2492. SetStructuredExceptionHandler seh;
  2493. try
  2494. {
  2495. if (NULL == pObj)
  2496. return E_INVALIDARG;
  2497. //if the class already exists return it
  2498. if(m_pIMosClass != NULL)
  2499. {
  2500. m_pIMosClass->AddRef();
  2501. *pObj=m_pIMosClass;
  2502. return S_OK;
  2503. }
  2504. else
  2505. {
  2506. *pObj= NULL ;
  2507. return WBEM_E_FAILED ;
  2508. }
  2509. }
  2510. catch(Structured_Exception e_SE)
  2511. {
  2512. return E_UNEXPECTED;
  2513. }
  2514. catch(Heap_Exception e_HE)
  2515. {
  2516. return E_OUTOFMEMORY;
  2517. }
  2518. catch(...)
  2519. {
  2520. return E_UNEXPECTED;
  2521. }
  2522. }
  2523. SCODE CSmirClassHandle :: SetModuleName(BSTR szName)
  2524. {
  2525. SetStructuredExceptionHandler seh;
  2526. try
  2527. {
  2528. return CopyBSTR(&m_szModuleName,&szName);
  2529. }
  2530. catch(Structured_Exception e_SE)
  2531. {
  2532. return E_UNEXPECTED;
  2533. }
  2534. catch(Heap_Exception e_HE)
  2535. {
  2536. return E_OUTOFMEMORY;
  2537. }
  2538. catch(...)
  2539. {
  2540. return E_UNEXPECTED;
  2541. }
  2542. }
  2543. SCODE CSmirClassHandle :: GetModuleName(BSTR *szName)
  2544. {
  2545. SetStructuredExceptionHandler seh;
  2546. try
  2547. {
  2548. if(NULL != szName)
  2549. {
  2550. *szName=SysAllocString(m_szModuleName);
  2551. return S_OK;
  2552. }
  2553. else
  2554. return E_INVALIDARG;
  2555. }
  2556. catch(Structured_Exception e_SE)
  2557. {
  2558. return E_UNEXPECTED;
  2559. }
  2560. catch(Heap_Exception e_HE)
  2561. {
  2562. return E_OUTOFMEMORY;
  2563. }
  2564. catch(...)
  2565. {
  2566. return E_UNEXPECTED;
  2567. }
  2568. }
  2569. SCODE CSmirClassHandle :: SetGroupName(BSTR szName)
  2570. {
  2571. SetStructuredExceptionHandler seh;
  2572. try
  2573. {
  2574. return CopyBSTR(&m_szGroupName,&szName);
  2575. }
  2576. catch(Structured_Exception e_SE)
  2577. {
  2578. return E_UNEXPECTED;
  2579. }
  2580. catch(Heap_Exception e_HE)
  2581. {
  2582. return E_OUTOFMEMORY;
  2583. }
  2584. catch(...)
  2585. {
  2586. return E_UNEXPECTED;
  2587. }
  2588. }
  2589. SCODE CSmirClassHandle :: GetGroupName(BSTR *szName)
  2590. {
  2591. SetStructuredExceptionHandler seh;
  2592. try
  2593. {
  2594. if(NULL != szName)
  2595. {
  2596. *szName=SysAllocString(m_szGroupName);
  2597. return S_OK;
  2598. }
  2599. else
  2600. return E_INVALIDARG;
  2601. }
  2602. catch(Structured_Exception e_SE)
  2603. {
  2604. return E_UNEXPECTED;
  2605. }
  2606. catch(Heap_Exception e_HE)
  2607. {
  2608. return E_OUTOFMEMORY;
  2609. }
  2610. catch(...)
  2611. {
  2612. return E_UNEXPECTED;
  2613. }
  2614. }
  2615. /**************************************************************************************
  2616. *Methods not exposed by the ISmirClassHandle interface.
  2617. *Used to encapsulate functionality.
  2618. **************************************************************************************/
  2619. SCODE CSmirClassHandle :: AddToDB(CSmir *a_Smir,ISmirGroupHandle *hGroup)
  2620. {
  2621. IWbemServices * moServ = NULL ;
  2622. IWbemContext *moContext = NULL ;
  2623. SCODE result= CSmirAccess :: GetContext (a_Smir , &moContext);
  2624. //open the root\default name space
  2625. result= CSmirAccess :: Open(a_Smir,&moServ);
  2626. if (FAILED(result)||(NULL == moServ))
  2627. {
  2628. if ( moContext )
  2629. moContext->Release () ;
  2630. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  2631. //if we cant open the namespace the group handle must be invalid
  2632. return WBEM_E_FAILED;
  2633. }
  2634. //now commit the changes
  2635. result = moServ->PutClass(m_pIMosClass, RESERVED_WBEM_FLAG, moContext,NULL);
  2636. if (FAILED(result))
  2637. {
  2638. if ( moContext )
  2639. moContext->Release () ;
  2640. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  2641. return E_UNEXPECTED;
  2642. }
  2643. if ( moContext )
  2644. moContext->Release () ;
  2645. moServ->Release();
  2646. //add the associations
  2647. BSTR szGroupName = NULL ;
  2648. BSTR szModuleName = NULL ;
  2649. hGroup->GetName(&szGroupName);
  2650. hGroup->GetModuleName(&szModuleName);
  2651. #if 0
  2652. CSMIRToClassAssociator :: Associate(a_Smir,this);
  2653. #endif
  2654. CGroupToClassAssociator :: Associate(a_Smir,szModuleName, szGroupName, this);
  2655. CModuleToClassAssociator :: Associate(a_Smir,szModuleName, this);
  2656. SysFreeString(szGroupName);
  2657. SysFreeString(szModuleName);
  2658. return S_OK;
  2659. }
  2660. SCODE CSmirClassHandle :: DeleteClassFromGroup( CSmir *a_Smir )
  2661. {
  2662. //get the class
  2663. IWbemClassObject *pIMosClass = NULL ;
  2664. SCODE res = GetWBEMClass(&pIMosClass);
  2665. if (FAILED(res))
  2666. {
  2667. //nothing to delete
  2668. return S_OK;
  2669. }
  2670. //open the smir name space
  2671. IWbemServices * moServ = NULL ;
  2672. IWbemContext *moContext = NULL ;
  2673. res= CSmirAccess :: GetContext (NULL, &moContext);
  2674. //SCODE result= CSmirAccess :: GetContext (a_Smir , &moContext);
  2675. res= CSmirAccess :: Open(a_Smir,&moServ);
  2676. if (FAILED(res)||(NULL == moServ))
  2677. {
  2678. //we have a problem the SMIR is not there and cannot be created
  2679. if ( moContext )
  2680. moContext->Release () ;
  2681. pIMosClass->Release();
  2682. return WBEM_E_FAILED;
  2683. }
  2684. //get the class name
  2685. VARIANT v;
  2686. VariantInit(&v);
  2687. pIMosClass->Get(OLEMS_CLASS_PROP, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  2688. if (V_VT(&v) == VT_BSTR)
  2689. {
  2690. //delete everthing that is associated with the class using
  2691. //references of {\\.\root\default\SMIR:<class>}
  2692. IEnumWbemClassObject *pEnum = NULL;
  2693. CString sQuery(CString(SMIR_ASSOC_QUERY_STR2)
  2694. +CString(OPEN_BRACE_STR)
  2695. +CString(SMIR_NAMESPACE_FROM_ROOT)
  2696. +CString(COLON_STR)
  2697. +CString(V_BSTR(&v))
  2698. +CString(CLOSE_BRACE_STR)
  2699. +CString(SPACE_STR)
  2700. +CString(SMIR_ASSOC_QUERY_STR4)
  2701. +CString(EQUALS_STR)
  2702. +CString(SMIR_GROUP_ASSOC_CLASS_NAME)
  2703. );
  2704. BSTR szQuery = sQuery.AllocSysString();
  2705. CBString t_QueryFormat (SMIR_ASSOC_QUERY1_TYPE);
  2706. SCODE sRes = moServ->ExecQuery(t_QueryFormat.GetString (), szQuery,
  2707. RESERVED_WBEM_FLAG,moContext, &pEnum);
  2708. SysFreeString(szQuery);
  2709. if (FAILED(sRes)||(NULL==pEnum))
  2710. {
  2711. //all classes are associated so this is a problem
  2712. if ( moContext )
  2713. moContext->Release () ;
  2714. moServ->Release();
  2715. pIMosClass->Release();
  2716. return WBEM_E_FAILED;
  2717. }
  2718. ULONG uCount=1;
  2719. IWbemClassObject *pAssocMosClass = NULL ;
  2720. ULONG puReturned;
  2721. //loop over the associations to see how many there are
  2722. int iAssociations=0;
  2723. for(pEnum->Reset();S_OK==pEnum->Next(-1,uCount,&pAssocMosClass,&puReturned);)
  2724. {
  2725. iAssociations++;
  2726. if(iAssociations>1)
  2727. {
  2728. break;
  2729. }
  2730. }
  2731. if(1 == iAssociations)
  2732. {
  2733. //nly one so delete it
  2734. moServ->DeleteClass(V_BSTR(&v),RESERVED_WBEM_FLAG, moContext,NULL);
  2735. }
  2736. pEnum->Release();
  2737. }
  2738. //clean up
  2739. if ( moContext )
  2740. moContext->Release () ;
  2741. moServ->Release();
  2742. pIMosClass->Release();
  2743. VariantClear(&v);
  2744. return S_OK;
  2745. }
  2746. SCODE CSmirClassHandle :: DeleteFromDB ( CSmir *a_Smir )
  2747. {
  2748. //get the class
  2749. IWbemClassObject *pIMosClass = NULL ;
  2750. SCODE res = GetWBEMClass(&pIMosClass);
  2751. if (FAILED(res))
  2752. {
  2753. //nothing to delete
  2754. return S_OK;
  2755. }
  2756. //open the smir name space
  2757. IWbemServices * moServ = NULL ;
  2758. IWbemContext *moContext = NULL ;
  2759. res= CSmirAccess :: GetContext (a_Smir, &moContext);
  2760. res= CSmirAccess :: Open(a_Smir,&moServ);
  2761. if ((S_FALSE==res)||(NULL == moServ))
  2762. {
  2763. //we have a problem the SMIR is not there and cannot be created
  2764. if ( moContext )
  2765. moContext->Release () ;
  2766. pIMosClass->Release();
  2767. return WBEM_E_FAILED;
  2768. }
  2769. //get the class name
  2770. VARIANT v;
  2771. VariantInit(&v);
  2772. pIMosClass->Get(OLEMS_CLASS_PROP, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  2773. if (V_VT(&v) == VT_BSTR)
  2774. {
  2775. //delete everthing that is associated with the class using
  2776. //references of {\\.\root\default\SMIR:<class>}
  2777. IEnumWbemClassObject *pEnum = NULL ;
  2778. CString sQuery(CString(SMIR_ASSOC_QUERY_STR2)
  2779. +CString(OPEN_BRACE_STR)
  2780. +CString(SMIR_NAMESPACE_FROM_ROOT)
  2781. +CString(COLON_STR)
  2782. +CString(V_BSTR(&v))
  2783. +CString(CLOSE_BRACE_STR)
  2784. );
  2785. BSTR szQuery = sQuery.AllocSysString();
  2786. CBString t_QueryFormat (SMIR_ASSOC_QUERY1_TYPE);
  2787. SCODE sRes = moServ->ExecQuery(t_QueryFormat.GetString (), szQuery,
  2788. RESERVED_WBEM_FLAG,moContext, &pEnum);
  2789. SysFreeString(szQuery);
  2790. if (FAILED(sRes)||(NULL==pEnum))
  2791. {
  2792. //all classes are associated so this is a problem
  2793. if ( moContext )
  2794. moContext->Release () ;
  2795. moServ->Release();
  2796. pIMosClass->Release();
  2797. return WBEM_E_FAILED;
  2798. }
  2799. ULONG uCount=1;
  2800. IWbemClassObject *pAssocMosClass = NULL ;
  2801. ULONG puReturned = 0;
  2802. //loop over the associations
  2803. VARIANT assocClass;
  2804. VariantInit(&assocClass);
  2805. VARIANT assocName;
  2806. VariantInit(&assocName);
  2807. for(pEnum->Reset();S_OK==pEnum->Next(-1,uCount,&pAssocMosClass,&puReturned);)
  2808. {
  2809. pAssocMosClass->Get(SMIR_X_ASSOC_NAME_PROP, RESERVED_WBEM_FLAG, &assocName,NULL,NULL);
  2810. pAssocMosClass->Get(OLEMS_CLASS_PROP, RESERVED_WBEM_FLAG, &assocClass,NULL,NULL);
  2811. CString instString(
  2812. CString(V_BSTR(&assocClass))
  2813. +CString(EQUALS_STR)
  2814. +CString(QUOTE_STR)
  2815. +CString(V_BSTR(&assocName))
  2816. +CString(QUOTE_STR)
  2817. );
  2818. VariantClear(&assocName);
  2819. VariantClear(&assocClass);
  2820. BSTR instBString = instString.AllocSysString();
  2821. moServ->DeleteInstance(instBString, RESERVED_WBEM_FLAG, moContext,NULL);
  2822. SysFreeString(instBString);
  2823. pAssocMosClass->Release();
  2824. }
  2825. pEnum->Release();
  2826. //and delete it
  2827. moServ->DeleteClass(V_BSTR(&v),RESERVED_WBEM_FLAG, moContext,NULL);
  2828. }
  2829. //clean up
  2830. if ( moContext )
  2831. moContext->Release () ;
  2832. moServ->Release();
  2833. pIMosClass->Release();
  2834. VariantClear(&v);
  2835. return S_OK;
  2836. }
  2837. const CSmirClassHandle& CSmirClassHandle :: operator >>(ISmirSerialiseHandle *pSHandle)
  2838. {
  2839. if (m_pIMosClass)
  2840. {
  2841. BOOL bMOFPragmas=((CSmirSerialiseHandle*) pSHandle)->ReturnMOFPragmas();
  2842. BOOL bMOFAssociations=((CSmirSerialiseHandle*) pSHandle)->ReturnMOFAssociations();
  2843. VARIANT v;
  2844. VariantInit(&v);
  2845. m_pIMosClass->Get(OLEMS_CLASS_PROP, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  2846. if (V_VT(&v) == VT_BSTR)
  2847. {
  2848. BSTR pszClassMof=NULL;
  2849. HRESULT result = m_pIMosClass->GetObjectText(WBEM_FLAG_NO_FLAVORS, &pszClassMof);
  2850. if (SUCCEEDED (result))
  2851. {
  2852. if(TRUE==bMOFPragmas)
  2853. {
  2854. //start in the SMIR namespace
  2855. ((CSmirSerialiseHandle*)pSHandle)->m_serialiseString+=CString(SMIR_NAMESPACE_PRAGMA);
  2856. }
  2857. ((CSmirSerialiseHandle*)pSHandle)->m_serialiseString+=CString(pszClassMof);
  2858. SysFreeString(pszClassMof);
  2859. if(TRUE==bMOFAssociations)
  2860. {
  2861. /*******************create the Module associations*************************/
  2862. //instance of <assoc> \n{\n
  2863. CString szTmpString =INSTANCE_START;
  2864. szTmpString+=CString(SMIR_MODULE_ASSOC_CLASS_NAME);
  2865. szTmpString+=NL_BRACE_NL_STR;
  2866. //association name
  2867. //<assoc name>=\"<name>SMIRAssociation\";\n
  2868. szTmpString+=CString(SMIR_X_ASSOC_NAME_PROP);
  2869. szTmpString+=START_OF_PROPERTY_VALUE;
  2870. szTmpString+=CString(V_BSTR(&v));
  2871. szTmpString+=CString(SMIR_MODULE_ASSOC_CLASS_NAME_POSTFIX);
  2872. szTmpString+=END_OF_PROPERTY_VALUE;
  2873. //smir name
  2874. //SmirGroup="\\\\.\\root\\default\\SMIR\\<module>:Module="<Group>"";
  2875. szTmpString+=CString(SMIR_MODULE_ASSOC_MODULE_PROP);
  2876. szTmpString+=START_OF_PROPERTY_VALUE;
  2877. szTmpString+=CString(SMIR_NAMESPACE_STR);
  2878. szTmpString+=CString(COLON_STR);
  2879. szTmpString+=CString(MODULE_NAMESPACE_NAME);
  2880. szTmpString+=CString(DOT_STR);
  2881. szTmpString+=CString(OLEMS_NAME_PROP);
  2882. szTmpString+=CString(EQUALS_STR);
  2883. szTmpString+=CString(ESCAPED_QUOTE_STR);
  2884. szTmpString+=CString(m_szModuleName);
  2885. szTmpString+=CString(ESCAPED_QUOTE_STR);
  2886. szTmpString+=END_OF_PROPERTY_VALUE;
  2887. //class name
  2888. //SmirClass="\\\\.\\root\\default\\SMIR:MS_SNMP_RFC1213-MIB_udpTable";
  2889. szTmpString+=CString(SMIR_X_ASSOC_CLASS_PROP);
  2890. szTmpString+=START_OF_PROPERTY_VALUE;
  2891. szTmpString+=CString(SMIR_NAMESPACE_STR);
  2892. szTmpString+=CString(COLON_STR);
  2893. szTmpString+=CString(V_BSTR(&v));
  2894. szTmpString+=END_OF_PROPERTY_VALUE;
  2895. szTmpString+=END_OF_CLASS;
  2896. /*******************create the Group associations*************************/
  2897. //instance of <assoc> \n{\n
  2898. szTmpString+=INSTANCE_START;
  2899. szTmpString+=CString(SMIR_GROUP_ASSOC_CLASS_NAME);
  2900. szTmpString+=NL_BRACE_NL_STR;
  2901. //association name
  2902. //<assoc name>=\"<name>SMIRAssociation\";\n
  2903. szTmpString+=CString(SMIR_X_ASSOC_NAME_PROP);
  2904. szTmpString+=START_OF_PROPERTY_VALUE;
  2905. szTmpString+=CString(V_BSTR(&v));
  2906. szTmpString+=CString(SMIR_GROUP_ASSOC_CLASS_NAME_POSTFIX);
  2907. szTmpString+=END_OF_PROPERTY_VALUE;
  2908. //smir name
  2909. //SmirGroup="\\\\.\\root\\default\\SMIR\\<module>:Group="<Group>"";
  2910. szTmpString+=CString(SMIR_GROUP_ASSOC_GROUP_PROP);
  2911. szTmpString+=START_OF_PROPERTY_VALUE;
  2912. szTmpString+=CString(SMIR_NAMESPACE_STR);
  2913. szTmpString+=CString(L"\\\\");
  2914. szTmpString+=CString(m_szModuleName);
  2915. szTmpString+=CString(COLON_STR);
  2916. szTmpString+=CString(GROUP_NAMESPACE_NAME);
  2917. szTmpString+=CString(DOT_STR);
  2918. szTmpString+=CString(OLEMS_NAME_PROP);
  2919. szTmpString+=CString(EQUALS_STR);
  2920. szTmpString+=CString(ESCAPED_QUOTE_STR);
  2921. szTmpString+=CString(m_szGroupName);
  2922. szTmpString+=CString(ESCAPED_QUOTE_STR);
  2923. szTmpString+=END_OF_PROPERTY_VALUE;
  2924. //class name
  2925. //SmirClass="\\\\.\\root\\default\\SMIR:MS_SNMP_RFC1213-MIB_udpTable";
  2926. szTmpString+=CString(SMIR_X_ASSOC_CLASS_PROP);
  2927. szTmpString+=START_OF_PROPERTY_VALUE;
  2928. szTmpString+=CString(SMIR_NAMESPACE_STR);
  2929. szTmpString+=CString(COLON_STR);
  2930. szTmpString+=CString(V_BSTR(&v));
  2931. szTmpString+=END_OF_PROPERTY_VALUE;
  2932. szTmpString+=END_OF_CLASS;
  2933. ((CSmirSerialiseHandle*)pSHandle)->m_serialiseString+=szTmpString;
  2934. }
  2935. }
  2936. }
  2937. VariantClear(&v);
  2938. }
  2939. return *this;
  2940. }
  2941. /*NotificationClass handle methods
  2942. */
  2943. /*
  2944. * CSmirNotificationClassHandle::QueryInterface
  2945. *
  2946. * Purpose:
  2947. * Manages the interfaces for this object which supports the
  2948. * IUnknown interface.
  2949. *
  2950. * Parameters:
  2951. * riid REFIID of the interface to return.
  2952. * ppv PPVOID in which to store the pointer.
  2953. *
  2954. * Return Value:
  2955. * SCODE NOERROR on success, E_NOINTERFACE if the
  2956. * interface is not supported.
  2957. */
  2958. STDMETHODIMP CSmirNotificationClassHandle::QueryInterface(REFIID riid, PPVOID ppv)
  2959. {
  2960. SetStructuredExceptionHandler seh;
  2961. try
  2962. {
  2963. //Always NULL the out-parameters
  2964. *ppv=NULL;
  2965. if (IID_IUnknown==riid)
  2966. *ppv=this;
  2967. if (IID_ISMIR_NotificationClassHandle==riid)
  2968. *ppv=this;
  2969. if (NULL==*ppv)
  2970. return ResultFromScode(E_NOINTERFACE);
  2971. //AddRef any interface we'll return.
  2972. ((LPUNKNOWN)*ppv)->AddRef();
  2973. return NOERROR;
  2974. }
  2975. catch(Structured_Exception e_SE)
  2976. {
  2977. return E_UNEXPECTED;
  2978. }
  2979. catch(Heap_Exception e_HE)
  2980. {
  2981. return E_OUTOFMEMORY;
  2982. }
  2983. catch(...)
  2984. {
  2985. return E_UNEXPECTED;
  2986. }
  2987. }
  2988. /*
  2989. * CSmirNotificationClassHandle::AddRef
  2990. * CSmirNotificationClassHandle::Release
  2991. *
  2992. * Reference counting members. When Release sees a zero count
  2993. * the object destroys itself.
  2994. */
  2995. ULONG CSmirNotificationClassHandle::AddRef(void)
  2996. {
  2997. SetStructuredExceptionHandler seh;
  2998. try
  2999. {
  3000. //CMOEvent_Trace MyTraceEvent(SMIR_STR);
  3001. //MyTraceEvent.Generate(__FILE__,__LINE__, "CSmirClassHandle::AddRef( %ld", m_cRef);
  3002. return InterlockedIncrement(&m_cRef);
  3003. }
  3004. catch(Structured_Exception e_SE)
  3005. {
  3006. return E_UNEXPECTED;
  3007. }
  3008. catch(Heap_Exception e_HE)
  3009. {
  3010. return E_OUTOFMEMORY;
  3011. }
  3012. catch(...)
  3013. {
  3014. return E_UNEXPECTED;
  3015. }
  3016. }
  3017. ULONG CSmirNotificationClassHandle::Release(void)
  3018. {
  3019. SetStructuredExceptionHandler seh;
  3020. try
  3021. {
  3022. long ret;
  3023. if (0!=(ret=InterlockedDecrement(&m_cRef)))
  3024. return ret;
  3025. delete this;
  3026. return 0;
  3027. }
  3028. catch(Structured_Exception e_SE)
  3029. {
  3030. return E_UNEXPECTED;
  3031. }
  3032. catch(Heap_Exception e_HE)
  3033. {
  3034. return E_OUTOFMEMORY;
  3035. }
  3036. catch(...)
  3037. {
  3038. return E_UNEXPECTED;
  3039. }
  3040. }
  3041. CSmirNotificationClassHandle :: CSmirNotificationClassHandle()
  3042. : m_pIMosClass(NULL), m_szModuleName(NULL)
  3043. {
  3044. CNotificationClassHandleClassFactory::objectsInProgress++;
  3045. //init the reference count
  3046. m_cRef=0;
  3047. }
  3048. CSmirNotificationClassHandle :: ~CSmirNotificationClassHandle()
  3049. {
  3050. if (NULL != m_pIMosClass)
  3051. m_pIMosClass->Release();
  3052. SysFreeString(m_szModuleName);
  3053. CNotificationClassHandleClassFactory::objectsInProgress--;
  3054. }
  3055. /*
  3056. * CSmirModuleHandle::void* operator
  3057. * validate handle
  3058. */
  3059. CSmirNotificationClassHandle::operator void*()
  3060. {
  3061. if((NULL!=m_szModuleName) && (NULL!=m_pIMosClass))
  3062. return this;
  3063. return NULL;
  3064. }
  3065. SCODE CSmirNotificationClassHandle :: GetWBEMNotificationClass(
  3066. IWbemClassObject **pObj
  3067. )
  3068. {
  3069. SetStructuredExceptionHandler seh;
  3070. try
  3071. {
  3072. if (NULL == pObj)
  3073. return E_INVALIDARG;
  3074. //if the class already exists return it
  3075. if(m_pIMosClass)
  3076. {
  3077. m_pIMosClass->AddRef();
  3078. *pObj=m_pIMosClass;
  3079. return S_OK;
  3080. }
  3081. else
  3082. {
  3083. *pObj=NULL ;
  3084. return WBEM_E_FAILED;
  3085. }
  3086. }
  3087. catch(Structured_Exception e_SE)
  3088. {
  3089. return E_UNEXPECTED;
  3090. }
  3091. catch(Heap_Exception e_HE)
  3092. {
  3093. return E_OUTOFMEMORY;
  3094. }
  3095. catch(...)
  3096. {
  3097. return E_UNEXPECTED;
  3098. }
  3099. }
  3100. SCODE CSmirNotificationClassHandle :: SetWBEMNotificationClass(IWbemClassObject *pObj)
  3101. {
  3102. SetStructuredExceptionHandler seh;
  3103. try
  3104. {
  3105. if(NULL != pObj)
  3106. {
  3107. m_pIMosClass = pObj;
  3108. m_pIMosClass->AddRef () ;
  3109. return S_OK;
  3110. }
  3111. else
  3112. return E_INVALIDARG;
  3113. }
  3114. catch(Structured_Exception e_SE)
  3115. {
  3116. return E_UNEXPECTED;
  3117. }
  3118. catch(Heap_Exception e_HE)
  3119. {
  3120. return E_OUTOFMEMORY;
  3121. }
  3122. catch(...)
  3123. {
  3124. return E_UNEXPECTED;
  3125. }
  3126. }
  3127. SCODE CSmirNotificationClassHandle :: SetModule(BSTR szName)
  3128. {
  3129. SetStructuredExceptionHandler seh;
  3130. try
  3131. {
  3132. return CopyBSTR(&m_szModuleName,&szName);
  3133. }
  3134. catch(Structured_Exception e_SE)
  3135. {
  3136. return E_UNEXPECTED;
  3137. }
  3138. catch(Heap_Exception e_HE)
  3139. {
  3140. return E_OUTOFMEMORY;
  3141. }
  3142. catch(...)
  3143. {
  3144. return E_UNEXPECTED;
  3145. }
  3146. }
  3147. SCODE CSmirNotificationClassHandle :: GetModule(BSTR *szName)
  3148. {
  3149. SetStructuredExceptionHandler seh;
  3150. try
  3151. {
  3152. if(NULL != szName)
  3153. {
  3154. if (NULL == m_szModuleName)
  3155. {
  3156. *szName = NULL;
  3157. }
  3158. else
  3159. {
  3160. *szName=SysAllocString(m_szModuleName);
  3161. }
  3162. return S_OK;
  3163. }
  3164. else
  3165. return E_INVALIDARG;
  3166. }
  3167. catch(Structured_Exception e_SE)
  3168. {
  3169. return E_UNEXPECTED;
  3170. }
  3171. catch(Heap_Exception e_HE)
  3172. {
  3173. return E_OUTOFMEMORY;
  3174. }
  3175. catch(...)
  3176. {
  3177. return E_UNEXPECTED;
  3178. }
  3179. }
  3180. /**************************************************************************************
  3181. *Methods not exposed by the ISmirClassHandle interface.
  3182. *Used to encapsulate functionality.
  3183. **************************************************************************************/
  3184. SCODE CSmirNotificationClassHandle :: AddToDB(CSmir *a_Smir)
  3185. {
  3186. BSTR szModuleName = NULL ;
  3187. GetModule(&szModuleName);
  3188. if (NULL == szModuleName)
  3189. {
  3190. FormatProviderErrorMsg(__FILE__,__LINE__,E_INVALIDARG);
  3191. return WBEM_E_FAILED;
  3192. }
  3193. //open the root\default name space
  3194. IWbemServices * moServ = NULL ;
  3195. IWbemContext *moContext = NULL ;
  3196. SCODE result= CSmirAccess :: GetContext (a_Smir , &moContext);
  3197. result= CSmirAccess :: Open(a_Smir,&moServ);
  3198. if (FAILED(result)||(NULL == moServ))
  3199. {
  3200. if ( moContext )
  3201. moContext->Release () ;
  3202. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  3203. return WBEM_E_FAILED;
  3204. }
  3205. //now commit the changes
  3206. result = moServ->PutClass(m_pIMosClass, RESERVED_WBEM_FLAG, moContext,NULL);
  3207. if (FAILED(result))
  3208. {
  3209. if ( moContext )
  3210. moContext->Release () ;
  3211. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  3212. return E_UNEXPECTED;
  3213. }
  3214. if ( moContext )
  3215. moContext->Release () ;
  3216. moServ->Release();
  3217. //add the associations
  3218. CModuleToNotificationClassAssociator :: Associate(a_Smir,szModuleName, this);
  3219. SysFreeString(szModuleName);
  3220. CNotificationMapper :: Map(a_Smir,m_pIMosClass, SNMP_NOTIFICATION_CLASS);
  3221. return S_OK;
  3222. }
  3223. SCODE CSmirNotificationClassHandle :: DeleteFromDB ( CSmir *a_Smir )
  3224. {
  3225. //get the class
  3226. IWbemClassObject *pIMosClass = NULL ;
  3227. SCODE res = GetWBEMNotificationClass(&pIMosClass);
  3228. if (FAILED(res))
  3229. {
  3230. //nothing to delete
  3231. return S_OK;
  3232. }
  3233. //open the smir name space
  3234. IWbemServices * moServ = NULL ;
  3235. IWbemContext *moContext = NULL ;
  3236. res= CSmirAccess :: GetContext (a_Smir, &moContext);
  3237. res= CSmirAccess :: Open(a_Smir,&moServ);
  3238. if ((S_FALSE==res)||(NULL == moServ))
  3239. {
  3240. //we have a problem the SMIR is not there and cannot be created
  3241. if ( moContext )
  3242. moContext->Release () ;
  3243. pIMosClass->Release();
  3244. return WBEM_E_FAILED;
  3245. }
  3246. //get the class name
  3247. VARIANT v;
  3248. VariantInit(&v);
  3249. pIMosClass->Get(OLEMS_CLASS_PROP, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  3250. if (V_VT(&v) == VT_BSTR)
  3251. {
  3252. CString classnamestr(V_BSTR(&v));
  3253. //delete everthing that is associated with the class using
  3254. //references of {\\.\root\default\SMIR:<class>}
  3255. IEnumWbemClassObject *pEnum = 0;
  3256. CString sQuery(CString(SMIR_ASSOC_QUERY_STR2)
  3257. +CString(OPEN_BRACE_STR)
  3258. +CString(SMIR_NAMESPACE_FROM_ROOT)
  3259. +CString(COLON_STR)
  3260. +classnamestr
  3261. +CString(CLOSE_BRACE_STR)
  3262. );
  3263. BSTR szQuery = sQuery.AllocSysString();
  3264. CBString t_QueryFormat (SMIR_ASSOC_QUERY1_TYPE);
  3265. SCODE sRes = moServ->ExecQuery(t_QueryFormat.GetString (), szQuery,
  3266. RESERVED_WBEM_FLAG,moContext, &pEnum);
  3267. SysFreeString(szQuery);
  3268. if (FAILED(sRes)||(NULL==pEnum))
  3269. {
  3270. //all classes are associated so this is a problem
  3271. if ( moContext )
  3272. moContext->Release () ;
  3273. moServ->Release();
  3274. pIMosClass->Release();
  3275. return WBEM_E_FAILED;
  3276. }
  3277. ULONG uCount=1;
  3278. IWbemClassObject *pAssocMosClass = NULL ;
  3279. ULONG puReturned = 0;
  3280. //loop over the associations
  3281. VARIANT assocClass;
  3282. VariantInit(&assocClass);
  3283. VARIANT assocName;
  3284. VariantInit(&assocName);
  3285. for(pEnum->Reset();S_OK==pEnum->Next(-1,uCount,&pAssocMosClass,&puReturned);)
  3286. {
  3287. pAssocMosClass->Get(SMIR_X_ASSOC_NAME_PROP, RESERVED_WBEM_FLAG, &assocName,NULL,NULL);
  3288. pAssocMosClass->Get(OLEMS_CLASS_PROP, RESERVED_WBEM_FLAG, &assocClass,NULL,NULL);
  3289. CString instString(CString(V_BSTR(&assocClass))
  3290. +CString(EQUALS_STR)
  3291. +CString(V_BSTR(&assocName))
  3292. );
  3293. VariantClear(&assocName);
  3294. VariantClear(&assocClass);
  3295. BSTR instBString = instString.AllocSysString();
  3296. moServ->DeleteInstance(instBString, RESERVED_WBEM_FLAG, moContext,NULL);
  3297. SysFreeString(instBString);
  3298. pAssocMosClass->Release();
  3299. }
  3300. pEnum->Release();
  3301. pEnum = NULL;
  3302. //now get the mapper instance and delete that too.
  3303. sQuery = CString(SQL_QUERY_STR1) +
  3304. CString(SMIR_NOTIFICATION_MAPPER) +
  3305. CString(SQL_QUERY_STR2) +
  3306. CString(SMIR_NOTIFICATION_CLASS_PROP) +
  3307. CString(EQUALS_STR) +
  3308. CString(QUOTE_STR) +
  3309. classnamestr +
  3310. CString(QUOTE_STR);
  3311. BSTR szQuery2 = sQuery.AllocSysString();
  3312. t_QueryFormat = SMIR_ASSOC_QUERY2_TYPE ;
  3313. sRes = moServ->ExecQuery(t_QueryFormat.GetString (), szQuery2,
  3314. RESERVED_WBEM_FLAG,moContext, &pEnum);
  3315. SysFreeString(szQuery2);
  3316. if (FAILED(sRes)||(NULL==pEnum))
  3317. {
  3318. //all classes are associated so this is a problem
  3319. if ( moContext )
  3320. moContext->Release () ;
  3321. moServ->Release();
  3322. pIMosClass->Release();
  3323. return WBEM_E_FAILED;
  3324. }
  3325. uCount=1;
  3326. pAssocMosClass = NULL;
  3327. puReturned = 0;
  3328. VariantClear(&assocClass);
  3329. //loop over the associations and delete them
  3330. for(pEnum->Reset();S_OK==pEnum->Next(-1,uCount,&pAssocMosClass,&puReturned);)
  3331. {
  3332. sRes = pAssocMosClass->Get(OLEMS_PATH_PROP, RESERVED_WBEM_FLAG,
  3333. &assocClass, NULL, NULL);
  3334. pAssocMosClass->Release();
  3335. if (FAILED(sRes) && (VT_BSTR == assocClass.vt))
  3336. {
  3337. CString instString(V_BSTR(&assocClass));
  3338. VariantClear(&assocClass);
  3339. BSTR instBString = instString.AllocSysString();
  3340. moServ->DeleteInstance(instBString, RESERVED_WBEM_FLAG, moContext,NULL);
  3341. SysFreeString(instBString);
  3342. }
  3343. }
  3344. pEnum->Release();
  3345. //now delete the class
  3346. moServ->DeleteClass(V_BSTR(&v),RESERVED_WBEM_FLAG, moContext,NULL);
  3347. }
  3348. //clean up
  3349. moServ->Release();
  3350. if ( moContext )
  3351. moContext->Release () ;
  3352. pIMosClass->Release();
  3353. VariantClear(&v);
  3354. return S_OK;
  3355. }
  3356. const CSmirNotificationClassHandle& CSmirNotificationClassHandle :: operator >>(ISmirSerialiseHandle *pSHandle)
  3357. {
  3358. if (m_pIMosClass)
  3359. {
  3360. BOOL bMOFPragmas=((CSmirSerialiseHandle*) pSHandle)->ReturnMOFPragmas();
  3361. BOOL bMOFAssociations=((CSmirSerialiseHandle*) pSHandle)->ReturnMOFAssociations();
  3362. VARIANT vclass;
  3363. VariantInit(&vclass);
  3364. VARIANT vtrapoid;
  3365. VariantInit(&vtrapoid);
  3366. m_pIMosClass->Get(OLEMS_CLASS_PROP, RESERVED_WBEM_FLAG, &vclass,NULL,NULL);
  3367. m_pIMosClass->Get(TRAPOID_PROP, RESERVED_WBEM_FLAG, &vtrapoid,NULL,NULL);
  3368. if ((V_VT(&vclass) == VT_BSTR) && (V_VT(&vtrapoid) == VT_BSTR))
  3369. {
  3370. BSTR pszClassMof = NULL ;
  3371. m_pIMosClass->GetObjectText(WBEM_FLAG_NO_FLAVORS, &pszClassMof);
  3372. if (pszClassMof)
  3373. {
  3374. if(TRUE==bMOFPragmas)
  3375. {
  3376. //start in the SMIR namespace
  3377. ((CSmirSerialiseHandle*)pSHandle)->m_serialiseString+=CString(SMIR_NAMESPACE_PRAGMA);
  3378. }
  3379. ((CSmirSerialiseHandle*)pSHandle)->m_serialiseString+=CString(pszClassMof);
  3380. SysFreeString(pszClassMof);
  3381. /*******************create the TrapNotificationMapper*************************/
  3382. //instance of TrapNotificationMapper \n{\n
  3383. CString tmpString=INSTANCE_START;
  3384. tmpString+=CString(SMIR_NOTIFICATION_MAPPER);
  3385. tmpString+=NL_BRACE_NL_STR;
  3386. //SnmpTrapOID
  3387. tmpString+=CString(SMIR_NOTIFICATION_TRAP_PROP);
  3388. tmpString+=START_OF_PROPERTY_VALUE;
  3389. tmpString+=CString(V_BSTR(&vtrapoid));
  3390. tmpString+=END_OF_PROPERTY_VALUE;
  3391. //Eventclass
  3392. tmpString+=CString(SMIR_NOTIFICATION_CLASS_PROP);
  3393. tmpString+=START_OF_PROPERTY_VALUE;
  3394. tmpString+=CString(V_BSTR(&vclass));
  3395. tmpString+=END_OF_PROPERTY_VALUE;
  3396. tmpString+=END_OF_CLASS;
  3397. ((CSmirSerialiseHandle*)pSHandle)->m_serialiseString+=tmpString;
  3398. if(TRUE==bMOFAssociations)
  3399. {
  3400. /*******************create the SMIR associations*************************/
  3401. /*******************create the Module associations***********************/
  3402. //instance of <assoc> \n{\n
  3403. CString szTmpString=INSTANCE_START;
  3404. szTmpString+=CString(SMIR_MODULE_ASSOC_NCLASS_NAME);
  3405. szTmpString+=NL_BRACE_NL_STR;
  3406. //association name
  3407. //<assoc name>=\"<name>SMIRAssociation\";\n
  3408. szTmpString+=CString(SMIR_X_ASSOC_NAME_PROP);
  3409. szTmpString+=START_OF_PROPERTY_VALUE;
  3410. szTmpString+=CString(V_BSTR(&vclass));
  3411. szTmpString+=CString(SMIR_MODULE_ASSOC_CLASS_NAME_POSTFIX);
  3412. szTmpString+=END_OF_PROPERTY_VALUE;
  3413. //smir name
  3414. //SmirGroup="\\\\.\\root\\default\\SMIR\\<module>:Module="<Group>"";
  3415. szTmpString+=CString(SMIR_MODULE_ASSOC_MODULE_PROP);
  3416. szTmpString+=START_OF_PROPERTY_VALUE;
  3417. szTmpString+=CString(SMIR_NAMESPACE_STR);
  3418. szTmpString+=CString(COLON_STR);
  3419. szTmpString+=CString(MODULE_NAMESPACE_NAME);
  3420. szTmpString+=CString(DOT_STR);
  3421. szTmpString+=CString(OLEMS_NAME_PROP);
  3422. szTmpString+=CString(EQUALS_STR);
  3423. szTmpString+=CString(ESCAPED_QUOTE_STR);
  3424. szTmpString+=CString(m_szModuleName);
  3425. szTmpString+=CString(ESCAPED_QUOTE_STR);
  3426. szTmpString+=END_OF_PROPERTY_VALUE;
  3427. //class name
  3428. //SmirClass="\\\\.\\root\\default\\SMIR:MS_SNMP_RFC1213-MIB_udpTable";
  3429. szTmpString+=CString(SMIR_X_ASSOC_CLASS_PROP);
  3430. szTmpString+=START_OF_PROPERTY_VALUE;
  3431. szTmpString+=CString(SMIR_NAMESPACE_STR);
  3432. szTmpString+=CString(COLON_STR);
  3433. szTmpString+=CString(V_BSTR(&vclass));
  3434. szTmpString+=END_OF_PROPERTY_VALUE;
  3435. szTmpString+=END_OF_CLASS;
  3436. ((CSmirSerialiseHandle*)pSHandle)->m_serialiseString+=szTmpString;
  3437. }
  3438. }
  3439. }
  3440. VariantClear(&vclass);
  3441. VariantClear(&vtrapoid);
  3442. }
  3443. return *this;
  3444. }
  3445. /*ExtNotificationClass handle methods
  3446. */
  3447. /*
  3448. * CSmirExtNotificationClassHandle::QueryInterface
  3449. *
  3450. * Purpose:
  3451. * Manages the interfaces for this object which supports the
  3452. * IUnknown interface.
  3453. *
  3454. * Parameters:
  3455. * riid REFIID of the interface to return.
  3456. * ppv PPVOID in which to store the pointer.
  3457. *
  3458. * Return Value:
  3459. * SCODE NOERROR on success, E_NOINTERFACE if the
  3460. * interface is not supported.
  3461. */
  3462. STDMETHODIMP CSmirExtNotificationClassHandle::QueryInterface(REFIID riid, PPVOID ppv)
  3463. {
  3464. SetStructuredExceptionHandler seh;
  3465. try
  3466. {
  3467. //Always NULL the out-parameters
  3468. *ppv=NULL;
  3469. if (IID_IUnknown==riid)
  3470. *ppv=this;
  3471. if (IID_ISMIR_ExtNotificationClassHandle==riid)
  3472. *ppv=this;
  3473. if (NULL==*ppv)
  3474. return ResultFromScode(E_NOINTERFACE);
  3475. //AddRef any interface we'll return.
  3476. ((LPUNKNOWN)*ppv)->AddRef();
  3477. return NOERROR;
  3478. }
  3479. catch(Structured_Exception e_SE)
  3480. {
  3481. return E_UNEXPECTED;
  3482. }
  3483. catch(Heap_Exception e_HE)
  3484. {
  3485. return E_OUTOFMEMORY;
  3486. }
  3487. catch(...)
  3488. {
  3489. return E_UNEXPECTED;
  3490. }
  3491. }
  3492. /*
  3493. * CSmirExtNotificationClassHandle::AddRef
  3494. * CSmirExtNotificationClassHandle::Release
  3495. *
  3496. * Reference counting members. When Release sees a zero count
  3497. * the object destroys itself.
  3498. */
  3499. ULONG CSmirExtNotificationClassHandle::AddRef(void)
  3500. {
  3501. SetStructuredExceptionHandler seh;
  3502. try
  3503. {
  3504. //CMOEvent_Trace MyTraceEvent(SMIR_STR);
  3505. //MyTraceEvent.Generate(__FILE__,__LINE__, "CSmirClassHandle::AddRef( %ld", m_cRef);
  3506. return InterlockedIncrement(&m_cRef);
  3507. }
  3508. catch(Structured_Exception e_SE)
  3509. {
  3510. return 0;
  3511. }
  3512. catch(Heap_Exception e_HE)
  3513. {
  3514. return 0;
  3515. }
  3516. catch(...)
  3517. {
  3518. return 0;
  3519. }
  3520. }
  3521. ULONG CSmirExtNotificationClassHandle::Release(void)
  3522. {
  3523. SetStructuredExceptionHandler seh;
  3524. try
  3525. {
  3526. long ret;
  3527. if (0!=(ret=InterlockedDecrement(&m_cRef)))
  3528. return ret;
  3529. delete this;
  3530. return 0;
  3531. }
  3532. catch(Structured_Exception e_SE)
  3533. {
  3534. return 0;
  3535. }
  3536. catch(Heap_Exception e_HE)
  3537. {
  3538. return 0;
  3539. }
  3540. catch(...)
  3541. {
  3542. return 0;
  3543. }
  3544. }
  3545. CSmirExtNotificationClassHandle :: CSmirExtNotificationClassHandle()
  3546. : m_pIMosClass (NULL), m_szModuleName(NULL)
  3547. {
  3548. CExtNotificationClassHandleClassFactory::objectsInProgress++;
  3549. //init the reference count
  3550. m_cRef=0;
  3551. }
  3552. CSmirExtNotificationClassHandle :: ~CSmirExtNotificationClassHandle()
  3553. {
  3554. if (NULL != m_pIMosClass)
  3555. m_pIMosClass->Release();
  3556. SysFreeString(m_szModuleName);
  3557. CExtNotificationClassHandleClassFactory::objectsInProgress--;
  3558. }
  3559. /*
  3560. * CSmirModuleHandle::void* operator
  3561. * validate handle
  3562. */
  3563. CSmirExtNotificationClassHandle::operator void*()
  3564. {
  3565. if((NULL!=m_szModuleName) && (NULL!=m_pIMosClass))
  3566. return this;
  3567. return NULL;
  3568. }
  3569. SCODE CSmirExtNotificationClassHandle :: GetWBEMExtNotificationClass (
  3570. IWbemClassObject **pObj
  3571. )
  3572. {
  3573. SetStructuredExceptionHandler seh;
  3574. try
  3575. {
  3576. if (NULL == pObj)
  3577. return E_INVALIDARG;
  3578. //if the class already exists return it
  3579. if(m_pIMosClass)
  3580. {
  3581. m_pIMosClass->AddRef();
  3582. *pObj=m_pIMosClass;
  3583. return S_OK;
  3584. }
  3585. else
  3586. {
  3587. *pObj=NULL;
  3588. return WBEM_E_FAILED;
  3589. }
  3590. }
  3591. catch(Structured_Exception e_SE)
  3592. {
  3593. return E_UNEXPECTED;
  3594. }
  3595. catch(Heap_Exception e_HE)
  3596. {
  3597. return E_OUTOFMEMORY;
  3598. }
  3599. catch(...)
  3600. {
  3601. return E_UNEXPECTED;
  3602. }
  3603. }
  3604. SCODE CSmirExtNotificationClassHandle :: SetWBEMExtNotificationClass(IWbemClassObject *pObj)
  3605. {
  3606. SetStructuredExceptionHandler seh;
  3607. try
  3608. {
  3609. if(NULL != pObj)
  3610. {
  3611. m_pIMosClass = pObj;
  3612. m_pIMosClass->AddRef () ;
  3613. return S_OK;
  3614. }
  3615. else
  3616. return E_INVALIDARG;
  3617. }
  3618. catch(Structured_Exception e_SE)
  3619. {
  3620. return E_UNEXPECTED;
  3621. }
  3622. catch(Heap_Exception e_HE)
  3623. {
  3624. return E_OUTOFMEMORY;
  3625. }
  3626. catch(...)
  3627. {
  3628. return E_UNEXPECTED;
  3629. }
  3630. }
  3631. SCODE CSmirExtNotificationClassHandle :: SetModule(BSTR szName)
  3632. {
  3633. SetStructuredExceptionHandler seh;
  3634. try
  3635. {
  3636. return CopyBSTR(&m_szModuleName,&szName);
  3637. }
  3638. catch(Structured_Exception e_SE)
  3639. {
  3640. return E_UNEXPECTED;
  3641. }
  3642. catch(Heap_Exception e_HE)
  3643. {
  3644. return E_OUTOFMEMORY;
  3645. }
  3646. catch(...)
  3647. {
  3648. return E_UNEXPECTED;
  3649. }
  3650. }
  3651. SCODE CSmirExtNotificationClassHandle :: GetModule(BSTR *szName)
  3652. {
  3653. SetStructuredExceptionHandler seh;
  3654. try
  3655. {
  3656. if(NULL != szName)
  3657. {
  3658. if (NULL == m_szModuleName)
  3659. {
  3660. *szName = NULL;
  3661. }
  3662. else
  3663. {
  3664. *szName=SysAllocString(m_szModuleName);
  3665. }
  3666. return S_OK;
  3667. }
  3668. else
  3669. return E_INVALIDARG;
  3670. }
  3671. catch(Structured_Exception e_SE)
  3672. {
  3673. return E_UNEXPECTED;
  3674. }
  3675. catch(Heap_Exception e_HE)
  3676. {
  3677. return E_OUTOFMEMORY;
  3678. }
  3679. catch(...)
  3680. {
  3681. return E_UNEXPECTED;
  3682. }
  3683. }
  3684. /**************************************************************************************
  3685. *Methods not exposed by the ISmirClassHandle interface.
  3686. *Used to encapsulate functionality.
  3687. **************************************************************************************/
  3688. SCODE CSmirExtNotificationClassHandle :: AddToDB ( CSmir *a_Smir )
  3689. {
  3690. BSTR szModuleName = NULL ;
  3691. GetModule(&szModuleName);
  3692. if (NULL == szModuleName)
  3693. {
  3694. FormatProviderErrorMsg(__FILE__,__LINE__,E_INVALIDARG);
  3695. return WBEM_E_FAILED;
  3696. }
  3697. //open the root\default name space
  3698. IWbemServices * moServ = NULL ;
  3699. IWbemContext *moContext = NULL ;
  3700. SCODE result= CSmirAccess :: GetContext (a_Smir , &moContext);
  3701. result= CSmirAccess :: Open(a_Smir,&moServ);
  3702. if (FAILED(result)||(NULL == moServ))
  3703. {
  3704. if ( moContext )
  3705. moContext->Release () ;
  3706. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  3707. return WBEM_E_FAILED;
  3708. }
  3709. //now commit the changes
  3710. result = moServ->PutClass(m_pIMosClass, RESERVED_WBEM_FLAG, moContext,NULL);
  3711. if (FAILED(result))
  3712. {
  3713. if ( moContext )
  3714. moContext->Release () ;
  3715. moServ->Release () ;
  3716. return E_UNEXPECTED;
  3717. }
  3718. if ( moContext )
  3719. moContext->Release () ;
  3720. moServ->Release();
  3721. if (FAILED(result))
  3722. {
  3723. FormatProviderErrorMsg(__FILE__,__LINE__,result);
  3724. return E_UNEXPECTED;
  3725. }
  3726. //add the associations
  3727. CModuleToExtNotificationClassAssociator :: Associate(a_Smir,szModuleName, this);
  3728. SysFreeString(szModuleName);
  3729. CNotificationMapper :: Map(a_Smir,m_pIMosClass, SNMP_EXT_NOTIFICATION_CLASS);
  3730. return S_OK;
  3731. }
  3732. SCODE CSmirExtNotificationClassHandle :: DeleteFromDB ( CSmir *a_Smir )
  3733. {
  3734. //get the class
  3735. IWbemClassObject *pIMosClass = NULL ;
  3736. SCODE res = GetWBEMExtNotificationClass(&pIMosClass);
  3737. if (FAILED(res))
  3738. {
  3739. //nothing to delete
  3740. return S_OK;
  3741. }
  3742. //open the smir name space
  3743. IWbemServices * moServ = NULL ;
  3744. IWbemContext *moContext = NULL ;
  3745. res= CSmirAccess :: GetContext (a_Smir , &moContext);
  3746. res= CSmirAccess :: Open(a_Smir,&moServ);
  3747. if ((S_FALSE==res)||(NULL == moServ))
  3748. {
  3749. //we have a problem the SMIR is not there and cannot be created
  3750. pIMosClass->Release();
  3751. return WBEM_E_FAILED;
  3752. }
  3753. //get the class name
  3754. VARIANT v;
  3755. VariantInit(&v);
  3756. pIMosClass->Get(OLEMS_CLASS_PROP, RESERVED_WBEM_FLAG, &v,NULL,NULL);
  3757. if (V_VT(&v) == VT_BSTR)
  3758. {
  3759. CString classnamestr(V_BSTR(&v));
  3760. //delete everthing that is associated with the class using
  3761. //references of {\\.\root\default\SMIR:<class>}
  3762. IEnumWbemClassObject *pEnum = NULL ;
  3763. CString sQuery(CString(SMIR_ASSOC_QUERY_STR2)
  3764. +CString(OPEN_BRACE_STR)
  3765. +CString(SMIR_NAMESPACE_FROM_ROOT)
  3766. +CString(COLON_STR)
  3767. +classnamestr
  3768. +CString(CLOSE_BRACE_STR)
  3769. );
  3770. BSTR szQuery = sQuery.AllocSysString();
  3771. CBString t_QueryFormat (SMIR_ASSOC_QUERY1_TYPE);
  3772. SCODE sRes = moServ->ExecQuery(t_QueryFormat.GetString (), szQuery,
  3773. RESERVED_WBEM_FLAG,moContext, &pEnum);
  3774. SysFreeString(szQuery);
  3775. if (FAILED(sRes)||(NULL==pEnum))
  3776. {
  3777. //all classes are associated so this is a problem
  3778. if ( moContext )
  3779. moContext->Release () ;
  3780. moServ->Release();
  3781. pIMosClass->Release();
  3782. return WBEM_E_FAILED;
  3783. }
  3784. ULONG uCount=1;
  3785. IWbemClassObject *pAssocMosClass = NULL ;
  3786. ULONG puReturned = 0;
  3787. //loop over the associations
  3788. VARIANT assocClass;
  3789. VariantInit(&assocClass);
  3790. VARIANT assocName;
  3791. VariantInit(&assocName);
  3792. for(pEnum->Reset();S_OK==pEnum->Next(-1,uCount,&pAssocMosClass,&puReturned);)
  3793. {
  3794. pAssocMosClass->Get(SMIR_X_ASSOC_NAME_PROP, RESERVED_WBEM_FLAG, &assocName,NULL,NULL);
  3795. pAssocMosClass->Get(OLEMS_CLASS_PROP, RESERVED_WBEM_FLAG, &assocClass,NULL,NULL);
  3796. CString instString(CString(V_BSTR(&assocClass))
  3797. +CString(EQUALS_STR)
  3798. +CString(V_BSTR(&assocName))
  3799. );
  3800. VariantClear(&assocName);
  3801. VariantClear(&assocClass);
  3802. BSTR instBString = instString.AllocSysString();
  3803. moServ->DeleteInstance(instBString, RESERVED_WBEM_FLAG, moContext,NULL);
  3804. SysFreeString(instBString);
  3805. pAssocMosClass->Release();
  3806. }
  3807. pEnum->Release();
  3808. pEnum = NULL;
  3809. //now get the mapper instance and delete that too.
  3810. sQuery = CString(SQL_QUERY_STR1) +
  3811. CString(SMIR_EXT_NOTIFICATION_MAPPER) +
  3812. CString(SQL_QUERY_STR2) +
  3813. CString(SMIR_NOTIFICATION_CLASS_PROP) +
  3814. CString(EQUALS_STR) +
  3815. CString(QUOTE_STR) +
  3816. classnamestr +
  3817. CString(QUOTE_STR);
  3818. BSTR szQuery2 = sQuery.AllocSysString();
  3819. t_QueryFormat = SMIR_ASSOC_QUERY2_TYPE;
  3820. sRes = moServ->ExecQuery(t_QueryFormat.GetString (), szQuery2,
  3821. RESERVED_WBEM_FLAG,moContext, &pEnum);
  3822. SysFreeString(szQuery2);
  3823. if (FAILED(sRes)||(NULL==pEnum))
  3824. {
  3825. //all classes are associated so this is a problem
  3826. if ( moContext )
  3827. moContext->Release () ;
  3828. moServ->Release();
  3829. pIMosClass->Release();
  3830. return WBEM_E_FAILED;
  3831. }
  3832. uCount=1;
  3833. pAssocMosClass = NULL;
  3834. puReturned = 0;
  3835. VariantClear(&assocClass);
  3836. //loop over the associations and delete them
  3837. for(pEnum->Reset();S_OK==pEnum->Next(-1,uCount,&pAssocMosClass,&puReturned);)
  3838. {
  3839. sRes = pAssocMosClass->Get(OLEMS_PATH_PROP, RESERVED_WBEM_FLAG,
  3840. &assocClass, NULL, NULL);
  3841. pAssocMosClass->Release();
  3842. if (FAILED(sRes) && (VT_BSTR == assocClass.vt))
  3843. {
  3844. CString instString(V_BSTR(&assocClass));
  3845. VariantClear(&assocClass);
  3846. BSTR instBString = instString.AllocSysString();
  3847. moServ->DeleteInstance(instBString, RESERVED_WBEM_FLAG, moContext,NULL);
  3848. SysFreeString(instBString);
  3849. }
  3850. }
  3851. pEnum->Release();
  3852. //now delete the class
  3853. moServ->DeleteClass(V_BSTR(&v),RESERVED_WBEM_FLAG, moContext,NULL);
  3854. }
  3855. //clean up
  3856. if ( moContext )
  3857. moContext->Release () ;
  3858. moServ->Release();
  3859. pIMosClass->Release();
  3860. VariantClear(&v);
  3861. return S_OK;
  3862. }
  3863. const CSmirExtNotificationClassHandle& CSmirExtNotificationClassHandle :: operator >>(ISmirSerialiseHandle *pSHandle)
  3864. {
  3865. if (m_pIMosClass)
  3866. {
  3867. BOOL bMOFPragmas=((CSmirSerialiseHandle*) pSHandle)->ReturnMOFPragmas();
  3868. BOOL bMOFAssociations=((CSmirSerialiseHandle*) pSHandle)->ReturnMOFAssociations();
  3869. VARIANT vclass;
  3870. VariantInit(&vclass);
  3871. VARIANT vtrapoid;
  3872. VariantInit(&vtrapoid);
  3873. m_pIMosClass->Get(OLEMS_CLASS_PROP, RESERVED_WBEM_FLAG, &vclass,NULL,NULL);
  3874. m_pIMosClass->Get(TRAPOID_PROP, RESERVED_WBEM_FLAG, &vtrapoid,NULL,NULL);
  3875. if ((V_VT(&vclass) == VT_BSTR) && (V_VT(&vtrapoid) == VT_BSTR))
  3876. {
  3877. BSTR pszClassMof = NULL ;
  3878. m_pIMosClass->GetObjectText(WBEM_FLAG_NO_FLAVORS, &pszClassMof);
  3879. if (pszClassMof)
  3880. {
  3881. if(TRUE==bMOFPragmas)
  3882. {
  3883. //start in the SMIR namespace
  3884. ((CSmirSerialiseHandle*)pSHandle)->m_serialiseString+=CString(SMIR_NAMESPACE_PRAGMA);
  3885. }
  3886. ((CSmirSerialiseHandle*)pSHandle)->m_serialiseString+=CString(pszClassMof);
  3887. SysFreeString(pszClassMof);
  3888. /*******************create the ExtNotificationMapper*************************/
  3889. //instance of ExtNotificationMapper \n{\n
  3890. CString tmpString=INSTANCE_START;
  3891. tmpString+=CString(SMIR_EXT_NOTIFICATION_MAPPER);
  3892. tmpString+=NL_BRACE_NL_STR;
  3893. //SnmpTrapOID
  3894. tmpString+=CString(SMIR_NOTIFICATION_TRAP_PROP);
  3895. tmpString+=START_OF_PROPERTY_VALUE;
  3896. tmpString+=CString(V_BSTR(&vtrapoid));
  3897. tmpString+=END_OF_PROPERTY_VALUE;
  3898. //Eventclass
  3899. tmpString+=CString(SMIR_NOTIFICATION_CLASS_PROP);
  3900. tmpString+=START_OF_PROPERTY_VALUE;
  3901. tmpString+=CString(V_BSTR(&vclass));
  3902. tmpString+=END_OF_PROPERTY_VALUE;
  3903. tmpString+=END_OF_CLASS;
  3904. ((CSmirSerialiseHandle*)pSHandle)->m_serialiseString+=tmpString;
  3905. if(TRUE==bMOFAssociations)
  3906. {
  3907. /*******************create the SMIR associations*************************/
  3908. /*******************create the Module associations***********************/
  3909. //instance of <assoc> \n{\n
  3910. CString szTmpString=INSTANCE_START;
  3911. szTmpString+=CString(SMIR_MODULE_ASSOC_EXTNCLASS_NAME);
  3912. szTmpString+=NL_BRACE_NL_STR;
  3913. //association name
  3914. //<assoc name>=\"<name>SMIRAssociation\";\n
  3915. szTmpString+=CString(SMIR_X_ASSOC_NAME_PROP);
  3916. szTmpString+=START_OF_PROPERTY_VALUE;
  3917. szTmpString+=CString(V_BSTR(&vclass));
  3918. szTmpString+=CString(SMIR_MODULE_ASSOC_CLASS_NAME_POSTFIX);
  3919. szTmpString+=END_OF_PROPERTY_VALUE;
  3920. //smir name
  3921. //SmirGroup="\\\\.\\root\\default\\SMIR\\<module>:Module="<Group>"";
  3922. szTmpString+=CString(SMIR_MODULE_ASSOC_MODULE_PROP);
  3923. szTmpString+=START_OF_PROPERTY_VALUE;
  3924. szTmpString+=CString(SMIR_NAMESPACE_STR);
  3925. szTmpString+=CString(COLON_STR);
  3926. szTmpString+=CString(MODULE_NAMESPACE_NAME);
  3927. szTmpString+=CString(DOT_STR);
  3928. szTmpString+=CString(OLEMS_NAME_PROP);
  3929. szTmpString+=CString(EQUALS_STR);
  3930. szTmpString+=CString(ESCAPED_QUOTE_STR);
  3931. szTmpString+=CString(m_szModuleName);
  3932. szTmpString+=CString(ESCAPED_QUOTE_STR);
  3933. szTmpString+=END_OF_PROPERTY_VALUE;
  3934. //class name
  3935. //SmirClass="\\\\.\\root\\default\\SMIR:MS_SNMP_RFC1213-MIB_udpTable";
  3936. szTmpString+=CString(SMIR_X_ASSOC_CLASS_PROP);
  3937. szTmpString+=START_OF_PROPERTY_VALUE;
  3938. szTmpString+=CString(SMIR_NAMESPACE_STR);
  3939. szTmpString+=CString(COLON_STR);
  3940. szTmpString+=CString(V_BSTR(&vclass));
  3941. szTmpString+=END_OF_PROPERTY_VALUE;
  3942. szTmpString+=END_OF_CLASS;
  3943. ((CSmirSerialiseHandle*)pSHandle)->m_serialiseString+=szTmpString;
  3944. }
  3945. }
  3946. }
  3947. VariantClear(&vclass);
  3948. VariantClear(&vtrapoid);
  3949. }
  3950. return *this;
  3951. }