//%2006//////////////////////////////////////////////////////////////////////// // // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.; // IBM Corp.; EMC Corporation, The Open Group. // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.; // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; // EMC Corporation; VERITAS Software Corporation; The Open Group. // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; // EMC Corporation; Symantec Corporation; The Open Group. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // //============================================================================== // // Author: Adrian Schuur, schuur@de.ibm.com // // Modified By: Robert Kieninger, kieningr@de.ibm.com, for bug#2642 // //%///////////////////////////////////////////////////////////////////////////// #include "CMPI_Version.h" #include "CMPI_Broker.h" #include "CMPI_Object.h" #include "CMPI_ContextArgs.h" #include "CMPI_Enumeration.h" #include "CMPI_Value.h" #include "CMPIProviderManager.h" #include "CMPI_String.h" #include #include #include #include #include PEGASUS_USING_STD; PEGASUS_NAMESPACE_BEGIN #define DDD(X) if (_cmpi_trace) X; extern int _cmpi_trace; static CIMPropertyList getList(const char** l) { CIMPropertyList pl; if (l) { Array n; while (*l) { n.append(*l++); } pl.set(n); } return pl; } CIMClass* mbGetClass(const CMPIBroker *mb, const CIMObjectPath &cop) { DDD(cout<<"--- mbGetClass()"<rwsemClassCache); if (xBroker->clsCache->lookup(clsId,ccp)) return ccp; } try { WriteLock writeLock (xBroker->rwsemClassCache); if (xBroker->clsCache->lookup(clsId,ccp)) return ccp; CIMClass cc=CM_CIMOM(mb)->getClass( OperationContext(), cop.getNameSpace(), cop.getClassName(), (bool)0, (bool)1, (bool)0, CIMPropertyList()); ccp=new CIMClass(cc); xBroker->clsCache->insert(clsId,ccp); return ccp; } catch (const CIMException &e) { DDD(cout<<"### exception: mbGetClass - code: "<ft->getEntry(ctx,CMPIInvocationFlags,NULL).value.uint32; const CIMPropertyList props=getList(properties); CIMObjectPath qop(String::EMPTY,CIMNamespaceName(), CM_ObjectPath(cop)->getClassName(), CM_ObjectPath(cop)->getKeyBindings()); AutoMutex mtx(((CMPI_Broker*)mb)->mtx); try { CIMInstance ci=CM_CIMOM(mb)->getInstance( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), qop, //*CM_ObjectPath(cop), CM_LocalOnly(flgs), CM_IncludeQualifiers(flgs), CM_ClassOrigin(flgs), props); ci.setPath(*CM_ObjectPath(cop)); if (rc) CMSetStatus(rc,CMPI_RC_OK); return (CMPIInstance*)new CMPI_Object(new CIMInstance(ci)); } catch (const CIMException &e) { DDD(cout<<"### exception: mbGetInstance - code: "<mtx); try { CIMObjectPath ncop=CM_CIMOM(mb)->createInstance( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), *CM_Instance(ci)); if (rc) CMSetStatus(rc,CMPI_RC_OK); return (CMPIObjectPath*)new CMPI_Object(new CIMObjectPath(ncop)); } catch (const CIMException &e) { DDD(cout<<"### exception: mbCreateInstance - code: "<ft->getEntry(ctx,CMPIInvocationFlags,NULL).value.uint32; const CIMPropertyList props=getList(properties); AutoMutex mtx(((CMPI_Broker*)mb)->mtx); try { CIMInstance cmi(*CM_Instance(ci)); cmi.setPath(*CM_ObjectPath(cop)); CM_CIMOM(mb)->modifyInstance( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), cmi, CM_IncludeQualifiers(flgs), props); CMReturn(CMPI_RC_OK); } catch (const CIMException &e) { DDD(cout<<"### exception: mbSetInstance - code: "<getClassName(), CM_ObjectPath(cop)->getKeyBindings()); AutoMutex mtx(((CMPI_Broker*)mb)->mtx); try { CM_CIMOM(mb)->deleteInstance( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), qop); //*CM_ObjectPath(cop)); CMReturn(CMPI_RC_OK); } catch (const CIMException &e) { DDD(cout<<"### exception: mbDeleteInstance - code: "<mtx); try { Array const &en=CM_CIMOM(mb)->execQuery( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), String(query), String(lang)); if (rc) CMSetStatus(rc,CMPI_RC_OK); CMPI_Object *obj = new CMPI_Object(new CMPI_ObjEnumeration(new Array(en))); return (CMPI_ObjEnumeration *)obj->getHdl(); } catch (const CIMException &e) { DDD(cout<<"### exception: mbExecQuery - code: "<ft->getEntry(ctx,CMPIInvocationFlags,NULL).value.uint32; const CIMPropertyList props=getList(properties); AutoMutex mtx(((CMPI_Broker*)mb)->mtx); try { Array const &en=CM_CIMOM(mb)->enumerateInstances( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), CM_ObjectPath(cop)->getClassName(), CM_DeepInheritance(flgs), CM_LocalOnly(flgs), CM_IncludeQualifiers(flgs), CM_ClassOrigin(flgs), props); if (rc) CMSetStatus(rc,CMPI_RC_OK); // Workaround for bugzilla 4677 // When running out of process the returned instances don't contain // a name space. Create a writable copy of the array and add the // namespace from the input parameters. Array * aInst = new Array(en); for (unsigned int index=0;index < aInst->size(); index++) { CIMInstance& myInst = (*aInst)[index]; CIMObjectPath orgCop = myInst.getPath(); orgCop.setNameSpace(CM_ObjectPath(cop)->getNameSpace()); (*aInst)[index].setPath(orgCop); } CMPI_Object *obj = new CMPI_Object(new CMPI_InstEnumeration(aInst)); /*CMPI_Object *obj = new CMPI_Object(new CMPI_InstEnumeration(new Array(en)));*/ // End of workaround for bugzilla 4677 return (CMPI_InstEnumeration*)obj->getHdl(); } catch (const CIMException &e) { DDD(cout<<"### exception: mbEnumInstances - code: "<mtx); try { Array const &en=CM_CIMOM(mb)->enumerateInstanceNames( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), CM_ObjectPath(cop)->getClassName()); if (rc) CMSetStatus(rc,CMPI_RC_OK); // When running out of process the returned instances don't contain // a name space. Create a writable copy of the array and add the // namespace from the input parameters. Array * aObj = new Array(en); for (unsigned int index=0;index < aObj->size(); index++) { (*aObj)[index].setNameSpace(CM_ObjectPath(cop)->getNameSpace()); } CMPI_Object *obj = new CMPI_Object(new CMPI_OpEnumeration(aObj)); return (CMPI_OpEnumeration *)obj->getHdl(); } catch (const CIMException &e) { DDD(cout<<"### exception: mbEnumInstances - code: "<ft->getEntry(ctx,CMPIInvocationFlags,NULL).value.uint32; const CIMPropertyList props=getList(properties); CIMObjectPath qop(String::EMPTY,CIMNamespaceName(), CM_ObjectPath(cop)->getClassName(), CM_ObjectPath(cop)->getKeyBindings()); AutoMutex mtx(((CMPI_Broker*)mb)->mtx); try { Array const &en=CM_CIMOM(mb)->associators( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), qop, assocClass ? CIMName(assocClass) : CIMName(), resultClass ? CIMName(resultClass) : CIMName(), role ? String(role) : String::EMPTY, resultRole ? String(resultRole) : String::EMPTY, CM_IncludeQualifiers(flgs), CM_ClassOrigin(flgs), props); if (rc) CMSetStatus(rc,CMPI_RC_OK); // Workaround for bugzilla 4677 // When running out of process the returned instances don't contain // a name space. Create a writable copy of the array and add the // namespace from the input parameters. Array * aInst = new Array(en); for (unsigned int index=0;index < aInst->size(); index++) { CIMObject& myInst = (*aInst)[index]; CIMObjectPath orgCop = myInst.getPath(); orgCop.setNameSpace(CM_ObjectPath(cop)->getNameSpace()); (*aInst)[index].setPath(orgCop); } CMPI_Object *obj = new CMPI_Object(new CMPI_ObjEnumeration(aInst)); /*CMPI_Object *obj = new CMPI_Object(new CMPI_ObjEnumeration(new Array(en)));*/ // End of workaround for bugzilla 4677 return (CMPI_ObjEnumeration *)obj->getHdl(); } catch (const CIMException &e) { DDD(cout<<"### exception: mbAssociators - code: "<getClassName(), CM_ObjectPath(cop)->getKeyBindings()); AutoMutex mtx(((CMPI_Broker*)mb)->mtx); try { Array const &en=CM_CIMOM(mb)->associatorNames( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), qop, assocClass ? CIMName(assocClass) : CIMName(), resultClass ? CIMName(resultClass) : CIMName(), role ? String(role) : String::EMPTY, resultRole ? String(resultRole) : String::EMPTY); if (rc) CMSetStatus(rc,CMPI_RC_OK); // When running out of process the returned instances don't contain // a name space. Create a writable copy of the array and add the // namespace from the input parameters. Array * aObj = new Array(en); for (unsigned int index=0;index < aObj->size(); index++) { (*aObj)[index].setNameSpace(CM_ObjectPath(cop)->getNameSpace()); } CMPI_Object *obj = new CMPI_Object(new CMPI_OpEnumeration(aObj)); return (CMPI_OpEnumeration *)obj->getHdl(); } catch (const CIMException &e) { DDD(cout<<"### exception: mbAssociatorsNames - code: "<ft->getEntry(ctx,CMPIInvocationFlags,NULL).value.uint32; CIMPropertyList props=getList(properties); CIMObjectPath qop(String::EMPTY,CIMNamespaceName(), CM_ObjectPath(cop)->getClassName(), CM_ObjectPath(cop)->getKeyBindings()); AutoMutex mtx(((CMPI_Broker*)mb)->mtx); try { Array const &en=CM_CIMOM(mb)->references( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), qop, resultClass ? CIMName(resultClass) : CIMName(), role ? String(role) : String::EMPTY, CM_IncludeQualifiers(flgs), CM_ClassOrigin(flgs), props); if (rc) CMSetStatus(rc,CMPI_RC_OK); // Workaround for bugzilla 4677 // When running out of process the returned instances don't contain // a name space. Create a writable copy of the array and add the // namespace from the input parameters. Array * aInst = new Array(en); for (unsigned int index=0;index < aInst->size(); index++) { CIMObject& myInst = (*aInst)[index]; CIMObjectPath orgCop = myInst.getPath(); orgCop.setNameSpace(CM_ObjectPath(cop)->getNameSpace()); (*aInst)[index].setPath(orgCop); } CMPI_Object *obj = new CMPI_Object(new CMPI_ObjEnumeration(aInst)); /*CMPI_Object *obj = new CMPI_Object(new CMPI_ObjEnumeration(new Array(en)));*/ // End of workaround for bugzilla 4677 return (CMPI_ObjEnumeration *)obj->getHdl(); } catch (const CIMException &e) { DDD(cout<<"### exception: mbReferences - code: "<getClassName(), CM_ObjectPath(cop)->getKeyBindings()); AutoMutex mtx(((CMPI_Broker*)mb)->mtx); try { Array const &en=CM_CIMOM(mb)->referenceNames( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), qop, resultClass ? CIMName(resultClass) : CIMName(), role ? String(role) : String::EMPTY); if (rc) CMSetStatus(rc,CMPI_RC_OK); // When running out of process the returned instances don't contain // a name space. Create a writable copy of the array and add the // namespace from the input parameters. Array * aObj = new Array(en); for (unsigned int index=0;index < aObj->size(); index++) { (*aObj)[index].setNameSpace(CM_ObjectPath(cop)->getNameSpace()); } CMPI_Object *obj = new CMPI_Object(new CMPI_OpEnumeration(aObj)); return (CMPI_OpEnumeration *)obj->getHdl(); } catch (const CIMException &e) { DDD(cout<<"### exception: mbReferencesNames - code: "<*)args->hdl) static CMPIData mbInvokeMethod(const CMPIBroker *mb, const CMPIContext *ctx, const CMPIObjectPath *cop, const char *method, const CMPIArgs *in, CMPIArgs *out, CMPIStatus *rc) { DDD(cout<<"--- mbInvokeMethod()"<getClassName(), CM_ObjectPath(cop)->getKeyBindings()); AutoMutex mtx(((CMPI_Broker*)mb)->mtx); try { CIMValue v=CM_CIMOM(mb)->invokeMethod( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), qop, method ? String(method) : String::EMPTY, *CM_Args(in), *CM_Args(out)); CIMType vType=v.getType(); CMPIType t=type2CMPIType(vType,v.isArray()); value2CMPIData(v,t,&data); if (rc) { CMSetStatus(rc,CMPI_RC_OK); } return data; } catch (const CIMException &e) { DDD(cout<<"### exception: mbInvokeMethod - code: "<mtx); try { CM_CIMOM(mb)->setProperty( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), *CM_ObjectPath(cop), String(name), v); CMReturn(CMPI_RC_OK); } catch (const CIMException &e) { DDD(cout<<"### exception: mbSetProperty - code: "<mtx); try { CIMValue v=CM_CIMOM(mb)->getProperty( OperationContext(*CM_Context(ctx)), CM_ObjectPath(cop)->getNameSpace(), *CM_ObjectPath(cop), String(name)); CIMType vType=v.getType(); CMPIType t=type2CMPIType(vType,v.isArray()); value2CMPIData(v,t,&data); if (rc) CMSetStatus(rc,CMPI_RC_OK); return data; } catch (const CIMException &e) { DDD(cout<<"### exception: mbGetProperty - code: "<ctx; OperationContext nctx=*ctx; CMPIContext* neCtx=new CMPI_Context(*(new OperationContext(nctx))); CMPIString *name; for (int i=0,s=CMPI_Args_Ftab->getArgCount((CMPIArgs*)eCtx,NULL); igetArgAt((CMPIArgs*)eCtx,i,&name,NULL); CMPI_Args_Ftab->addArg((CMPIArgs*)neCtx,CMGetCharPtr(name),&data.value,data.type); } return neCtx; } static CMPIStatus mbAttachThread(const CMPIBroker* mb, const CMPIContext* eCtx) { DDD(cout<<"--- mbAttachThread()"<thr=new CMPI_ThreadContext(mb,eCtx); CMReturn(CMPI_RC_OK); } static CMPIStatus mbDetachThread(const CMPIBroker* mb, const CMPIContext* eCtx) { DDD(cout<<"--- mbDetachThread()"<thr; // Delete also CMPIContext delete neCtx; CMReturn(CMPI_RC_OK); } static CMPIStatus mbDeliverIndication(const CMPIBroker* eMb, const CMPIContext* ctx, const char *ns, const CMPIInstance* ind) { DDD(cout<<"--- mbDeliverIndication()"<name,prec)) { if (prec->enabled) { try { context->get(SubscriptionInstanceNamesContainer::NAME); } catch (const Exception &) { Array subscriptionInstanceNames; context->insert(SubscriptionInstanceNamesContainer(subscriptionInstanceNames)); } CIMIndication cimIndication(*CM_Instance(ind)); AutoMutex mtx(((CMPI_Broker*)mb)->mtx); try { prec->handler->deliver( *context, // OperationContext(*CM_Context(ctx)), cimIndication); CMReturn(CMPI_RC_OK); } catch (const CIMException &e) { DDD(cout<<"### exception: mbSetProperty - code: "<