void ComputerSystemProvider::getInstance( const OperationContext& context, const CIMObjectPath& ref, const Boolean includeQualifiers, const Boolean includeClassOrigin, const CIMPropertyList& propertyList, InstanceResponseHandler &handler) { CIMName className = ref.getClassName(); _checkClass(className); Array<CIMKeyBinding> keys = ref.getKeyBindings(); //-- make sure we're the right instance unsigned int keyCount = NUMKEYS_COMPUTER_SYSTEM; CIMName keyName; String keyValue; if (keys.size() != keyCount) { throw CIMInvalidParameterException("Wrong number of keys"); } for (unsigned int ii = 0; ii < keys.size(); ii++) { keyName = keys[ii].getName(); keyValue = keys[ii].getValue(); //Put CLASS_EXTENDED_COMPUTER_SYSTEM in front CLASS_CIM_COMPUTER_SYSTEM //to prefer CLASS_EXTENDED_COMPUTER_SYSTEM as class being served first //followed by CLASS_CIM_UNITARY_COMPUTER_SYSTEM if (keyName.equal(PROPERTY_CREATION_CLASS_NAME) && (String::equalNoCase(keyValue,CLASS_EXTENDED_COMPUTER_SYSTEM) || String::equalNoCase(keyValue,CLASS_CIM_UNITARY_COMPUTER_SYSTEM) || String::equalNoCase(keyValue,CLASS_CIM_COMPUTER_SYSTEM) || String::equalNoCase(keyValue,String::EMPTY))) { keyCount--; } else if (keyName.equal("Name") && String::equalNoCase(keyValue,_cs.getHostName())) { keyCount--; } } if (keyCount) { throw CIMInvalidParameterException(String::EMPTY); } // return instance of specified class CIMInstance instance = _cs.buildInstance(ref.getClassName()); handler.processing(); handler.deliver(instance); handler.complete(); return; }
void _getKeyValue ( const CIMObjectPath& instanceName, CIMNamespaceName& childNamespaceName, Boolean& isRelativeName) { Array<CIMKeyBinding> kbArray = instanceName.getKeyBindings(); if ((kbArray.size() == 1) && (kbArray[0].getName() == NAMESPACE_PROPERTYNAME)) { String childNamespaceString = kbArray[0].getValue(); if (childNamespaceString != String::EMPTY) { childNamespaceName = childNamespaceString; } isRelativeName = !(childNamespaceName.isNull()); } else { //l10n //throw CIMInvalidParameterException("Invalid key property: "); throw CIMInvalidParameterException(MessageLoaderParms( "ControlProviders.NamespaceProvider.NamespaceProvider.INVALID_KEY_PROPERTY", "Invalid key property: ")); } }
void InstanceProvider::createInstance( const OperationContext & context, const CIMObjectPath & instanceReference, const CIMInstance & instanceObject, ObjectPathResponseHandler & handler) { // Validate the class name if (!instanceObject.getClassName().equal("Sample_InstanceProviderClass")) { throw CIMNotSupportedException( instanceObject.getClassName().getString()); } // Find the key property Uint32 idIndex = instanceObject.findProperty("Identifier"); if (idIndex == PEG_NOT_FOUND) { throw CIMInvalidParameterException("Missing key value"); } CIMInstance cimInstance = instanceObject.clone(); // Create the new instance name CIMValue idValue = instanceObject.getProperty(idIndex).getValue(); Array<CIMKeyBinding> keys; keys.append(CIMKeyBinding("Identifier", idValue)); CIMObjectPath instanceName = CIMObjectPath( String(), CIMNamespaceName(), instanceObject.getClassName(), keys); cimInstance.setPath(instanceName); // Determine whether this instance already exists for(Uint32 i = 0, n = _instances.size(); i < n; i++) { if(instanceName == _instances[i].getPath()) { throw CIMObjectAlreadyExistsException(instanceName.toString()); } } // begin processing the request handler.processing(); // add the new instance to the array _instances.append(cimInstance); // deliver the new instance name handler.deliver(instanceName); // complete processing the request handler.complete(); }
void _getKeyValue ( const CIMInstance& namespaceInstance, CIMNamespaceName& childNamespaceName, Boolean& isRelativeName) { //Validate key property Uint32 pos; CIMValue propertyValue; // [Key, MaxLen (256), Description ( // "A string that uniquely identifies the Namespace " // "within the ObjectManager.") ] // string Name; pos = namespaceInstance.findProperty(NAMESPACE_PROPERTYNAME); if (pos == PEG_NOT_FOUND) { throw CIMPropertyNotFoundException (NAMESPACE_PROPERTYNAME.getString()); } propertyValue = namespaceInstance.getProperty(pos).getValue(); if (propertyValue.getType() != CIMTYPE_STRING) { //l10n //throw CIMInvalidParameterException("Invalid type for property: " //+ NAMESPACE_PROPERTYNAME.getString()); throw CIMInvalidParameterException(MessageLoaderParms( "ControlProviders.NamespaceProvider.NamespaceProvider.INVALID_TYPE_FOR_PROPERTY", "Invalid type for property: $0", NAMESPACE_PROPERTYNAME.getString())); } String cnsName; propertyValue.get(cnsName); if (cnsName == String::EMPTY) { childNamespaceName = CIMNamespaceName(); } else { childNamespaceName = CIMNamespaceName(cnsName); } isRelativeName = !(childNamespaceName.isNull()); }
void OperatingSystemProvider::getInstance(const OperationContext& context, const CIMObjectPath& ref, const Boolean includeQualifiers, const Boolean includeClassOrigin, const CIMPropertyList& propertyList, InstanceResponseHandler &handler) { Array<CIMKeyBinding> keys; CIMInstance instance; OperatingSystem os; CIMName className; String csName; String name; //-- make sure we're working on the right class className = ref.getClassName(); if (!(className.equal (STANDARDOPERATINGSYSTEMCLASS)) && !(className.equal (EXTENDEDOPERATINGSYSTEMCLASS))) throw CIMNotSupportedException("OperatingSystemProvider does not support class " + className.getString()); //-- make sure we're the right instance int keyCount; CIMName keyName; keyCount = 4; keys = ref.getKeyBindings(); if ((unsigned int)keys.size() != (unsigned int)keyCount) throw CIMInvalidParameterException("Wrong number of keys"); // doesn't seem as though this code will handle duplicate keys, // but it appears as though the CIMOM strips those out for us. // Despite test cases, don't get invoked with 2 keys of the same // name. if (!os.getCSName(csName)) { throw CIMOperationFailedException("OperatingSystemProvider " "Can't determine name of computer system"); } if (!os.getName(name)) { throw CIMOperationFailedException("OperatingSystemProvider " "Can't determine name of Operating System"); } for (unsigned int ii = 0; ii < keys.size(); ii++) { keyName = keys[ii].getName(); if ((keyName.equal ("CSCreationClassName")) && String::equalNoCase(keys[ii].getValue(), CSCREATIONCLASSNAME.getString())) { keyCount--; } else if ((keyName.equal ("CSName")) && String::equalNoCase(keys[ii].getValue(), csName)) { keyCount--; } else if ((keyName.equal ("CreationClassName")) && String::equalNoCase(keys[ii].getValue(), STANDARDOPERATINGSYSTEMCLASS.getString())) { keyCount--; } else if ((keyName.equal ("Name")) && String::equalNoCase(keys[ii].getValue(), name)) { keyCount--; } else { throw CIMInvalidParameterException("OperatingSystemProvider" " unrecognized key " + keyName.getString()); } } if (keyCount) { throw CIMInvalidParameterException("Wrong keys"); } OSP_DEBUG("losp-> getInstance got the right keys"); handler.processing(); //-- fill 'er up... instance = _build_instance(ref); instance.setPath(ref); OSP_DEBUG("losp-> getInstance built an instance"); handler.deliver(instance); handler.complete(); OSP_DEBUG("losp-> getInstance done"); return; }
/* ================================================================================ NAME : _goodPERefKeys DESCRIPTION : Checks to see if this is a value reference to a : Protocol Endpoint with good values for SCCN, SN, : and CCN. If it is, it returns the Name; : otherwise, it returns false. ASSUMPTIONS : None PRE-CONDITIONS : POST-CONDITIONS : NOTES : ================================================================================ */ Boolean BIPTLEpProvider::_goodPERefKeys(const CIMObjectPath &instName, String &rccn, // CreationClassName String &rname) // Name { #ifdef DEBUG cout << "BIPTLEpProvider::_goodPERefKeys(" << instName.toString() << ")" << endl; #endif int keysFound, // this will be used as a bit array i; Array<CIMKeyBinding> kbArray = instName.getKeyBindings(); if ( kbArray.size() != NUMKEYS_CIM_PROTOCOL_ENDPOINT) throw CIMInvalidParameterException("Wrong number of keys in reference"); for (i=0, keysFound=0; i < NUMKEYS_CIM_PROTOCOL_ENDPOINT; i++) { CIMKeyBinding kb = kbArray[i]; CIMName keyName = kb.getName(); String keyValue = kb.getValue(); // SystemCreationClassName if (keyName.equal (PROPERTY_SYSTEM_CREATION_CLASS_NAME)) { if (String::equalNoCase(keyValue, CLASS_CIM_UNITARY_COMPUTER_SYSTEM.getString()) || String::equal(keyValue, String::EMPTY) ) keysFound |= 1; else return false; // invalid value for SystemCreationClassName } // SystemName else if (keyName.equal (PROPERTY_SYSTEM_NAME)) { String sn; // System Name if (IPInterface::getSystemName(sn) == false) sn = String::EMPTY; if (String::equalNoCase(keyValue,sn) || String::equal(keyValue, String::EMPTY) ) keysFound |= 2; else return false; // invalid value for SystemName } // CreationClassName else if (keyName.equal (PROPERTY_CREATION_CLASS_NAME)) { rccn = keyValue; keysFound |= 4; } // Name must be a valid IP interface, but we will know that later // For now, just verify that it's present else if (keyName.equal (PROPERTY_NAME)) { rname = keyValue; keysFound |= 8; } // Key name was not recognized by any of the above tests else return false; } // for // We could get here if we didn't get all the keys, which // could happen if the right number of keys were supplied, // and they all had valid names and values, but there were // any duplicates (e.g., two Names, no SystemName) if (keysFound != (1<<NUMKEYS_CIM_PROTOCOL_ENDPOINT)-1) return false; #ifdef DEBUG cout << "BIPTLEpProvider::_goodPERefKeys() - success!" << endl; #endif return true; }
/* ================================================================================ NAME : getInstance DESCRIPTION : Returns a single instance. ASSUMPTIONS : None PRE-CONDITIONS : POST-CONDITIONS : NOTES : LocalOnly, DeepInheritance and propertyList are not : respected by this provider. Localization is not supported PARAMETERS : ================================================================================ */ void BIPTLEpProvider::getInstance(const OperationContext &ctx, const CIMObjectPath &instanceName, const Boolean includeQualifiers, const Boolean includeClassOrigin, const CIMPropertyList &propertyList, InstanceResponseHandler &handler) { #ifdef DEBUG cout << "BIPTLEpProvider::getInstance(" << instanceName.toString() << ")" << endl; #endif CIMKeyBinding kb; CIMName className = instanceName.getClassName(); CIMNamespaceName nameSpace = instanceName.getNameSpace(); int i; int keysFound; // this will be used as a bit array String sn; // system name String lepName, // LAN Endpoint Name ipeName, // IP Protocol Endpoint Name refCCN, // Reference's Creation Class Name refName; // Reference's Name // Grab the system name if (IPInterface::getSystemName(sn) == false) sn = String::EMPTY; // Validate the classname _checkClass(className); // Extract the key values Array<CIMKeyBinding> kbArray = instanceName.getKeyBindings(); // Leave immediately if wrong number of keys if ( kbArray.size() != NUMKEYS_PG_BINDS_IP_TO_LAN_ENDPOINT ) throw CIMInvalidParameterException("Wrong number of keys"); // Validate the keys. // Each loop iteration will set a bit in keysFound when a valid // key is found. If the expected bits aren't all set when // the loop finishes, it's a problem for (i=0, keysFound=0; i < NUMKEYS_PG_BINDS_IP_TO_LAN_ENDPOINT; i++) { kb = kbArray[i]; CIMName keyName = kb.getName(); String keyValue = kb.getValue(); // Antecedent must match if (keyName.equal (PROPERTY_ANTECEDENT)) { if (_goodPERefKeys(keyValue, refCCN, refName) && String::equalNoCase(refCCN, CLASS_CIM_LAN_ENDPOINT.getString())) { keysFound |= 1; lepName = refName; } else throw CIMInvalidParameterException(keyValue+": bad value for key "+ keyName.getString()); } // Dependent must match else if (keyName.equal (PROPERTY_DEPENDENT)) { if (_goodPERefKeys(keyValue, refCCN, refName) && String::equalNoCase(refCCN, CLASS_CIM_IP_PROTOCOL_ENDPOINT.getString())) { keysFound |= 2; ipeName = refName; } else throw CIMInvalidParameterException(keyValue+": bad value for key "+ keyName.getString()); } // Key name was not recognized by any of the above tests else throw CIMInvalidParameterException(keyName.getString()+ ": Unrecognized key"); } // for // We could get here if we didn't get all the keys, which // could happen if the right number of keys were supplied, // and they all had valid names and values, but there were // any duplicates (e.g., two Names, no SystemName) if (keysFound != (1<<NUMKEYS_PG_BINDS_IP_TO_LAN_ENDPOINT)-1) throw CIMInvalidParameterException("Bad object name"); // Get the Interface List InterfaceList _ifList; IPInterface _ipif; // Make sure the LAN Endpoint name is embedded in the IP Protocol Endpoint // name. If we can find the request interface and if it's one that // binds to a LAN Interface, then we've found the right one, so // return it to the client. if (ipeName.find(lepName) != PEG_NOT_FOUND && _ifList.findInterface(ipeName, _ipif) && _ipif.bindsToLANInterface()) { /* Notify processing is starting. */ handler.processing(); /* Return the instance. */ handler.deliver(_constructInstance(className, nameSpace, _ipif)); /* Notify processing is complete. */ handler.complete(); return; } throw CIMObjectNotFoundException(ipeName+": No such IP Interface"); return; // can never execute, but required to keep compiler happy }
void UNIX_PROVIDER::getInstance(const OperationContext &ctx, const CIMObjectPath &instanceName, const Boolean includeQualifiers, const Boolean includeClassOrigin, const CIMPropertyList &propertyList, InstanceResponseHandler &handler) { CIMKeyBinding kb; CIMName className = instanceName.getClassName(); CIMNamespaceName nameSpace = instanceName.getNameSpace(); String handle; int i; int keysFound = 0; // this will be used as a bit array CLASS_IMPLEMENTATION _p; // Validate the classname _checkClass(className); // Extract the key values Array<CIMKeyBinding> kbArray = instanceName.getKeyBindings(); // Leave immediately if wrong number of keys if ( kbArray.size() != NUMKEYS_CLASS_IMPLEMENTATION ) throw CIMInvalidParameterException("Wrong number of keys"); // Validate the keys. // Each loop iteration will set a bit in keysFound when a valid // key is found. If the expected bits aren't all set when // the loop finishes, it's a problem for(i=0, keysFound=0; i<NUMKEYS_CLASS_IMPLEMENTATION; i++) { kb = kbArray[i]; if (_p.validateKey(kb)) { keysFound++; _p.buildKeyHandle(kb, handle); } // Key name was not recognized by any of the above tests else throw CIMInvalidParameterException(kb.getName().getString() + ": Unrecognized key"); } // for // We could get here if we didn't get all the keys, which // could happen if the right number of keys were supplied, // and they all had valid names and values, but there were // any duplicates (e.g., two Handles, no OSName) if(keysFound != NUMKEYS_CLASS_IMPLEMENTATION) throw CIMInvalidParameterException("Bad object name"); /* Find the instance. First convert the instance id which is the */ /* process handle to an integer. This is necessary because the */ /* handle is the process id on HP-UX which must be passed to */ /* pstat_getproc() as an integer. */ /* Get the process information. */ if (_p.find(handle)) { /* Notify processing is starting. */ handler.processing(); /* Return the instance. */ handler.deliver(_constructInstance(className, nameSpace, _p)); /* Notify processing is complete. */ handler.complete(); return; } throw CIMObjectNotFoundException(handle+": No such process"); return; // can never execute, but required to keep compiler happy }
void LifecycleIndicationProvider::createInstance( const OperationContext & context, const CIMObjectPath & instanceReference, const CIMInstance & instanceObject, ObjectPathResponseHandler & handler) { // cout << "LifecycleIndicationProvider::createInstance()" << endl; // Validate the class name if(!instanceObject.getClassName().equal( "Sample_LifecycleIndicationProviderClass")) { throw CIMNotSupportedException( instanceObject.getClassName().getString()); } // Find the key property Uint32 idIndex = instanceObject.findProperty("uniqueId"); if(idIndex == PEG_NOT_FOUND) { throw CIMInvalidParameterException("Missing key value"); } CIMInstance cimInstance = instanceObject.clone(); // Create the new instance name CIMValue idValue = instanceObject.getProperty(idIndex).getValue(); Array<CIMKeyBinding> keys; keys.append(CIMKeyBinding("uniqueId", idValue)); CIMObjectPath instanceName = CIMObjectPath( String(), CIMNamespaceName(), instanceObject.getClassName(), keys); cimInstance.setPath(instanceName); // Determine whether this instance already exists for(Uint32 i = 0, n = _instances.size(); i < n; i++) { if(instanceName == _instances[i].getPath()) { throw CIMObjectAlreadyExistsException(instanceName.toString()); } } // begin processing the request handler.processing(); // add the new instance to the array _instances.append(cimInstance); // deliver the new instance name handler.deliver(instanceName); // complete processing the request handler.complete(); // If there is at least one subscription active for the lifecycle indication // InstCreation_for_Sample_LifecycleIndicationProviderClass, then generate // that indication here, embedding the newly-created instance as // the SourceInstance property. See LifecycleIndicationProviderR.mof. if (_lifecycle_indications_enabled) { CIMInstance indicationInstance( CIMName( "InstCreation_for_Sample_LifecycleIndicationProviderClass")); CIMObjectPath path; path.setNameSpace("root/SampleProvider"); path.setClassName( "InstCreation_for_Sample_LifecycleIndicationProviderClass"); indicationInstance.setPath(path); char buffer[32]; sprintf(buffer, "%d", _nextUID++); indicationInstance.addProperty (CIMProperty ("IndicationIdentifier",String(buffer))); CIMDateTime currentDateTime = CIMDateTime::getCurrentDateTime (); indicationInstance.addProperty (CIMProperty ("IndicationTime", currentDateTime)); indicationInstance.addProperty (CIMProperty ("SourceInstance",CIMObject(cimInstance))); _indication_handler->deliver (indicationInstance); // cout << "LifecycleIndicationProvider::createInstance() sent " // "InstCreation_for_Sample_LifecycleIndicationProviderClass" // << endl; } }
/* ================================================================================ NAME : getInstance DESCRIPTION : Returns a single instance. ASSUMPTIONS : None PRE-CONDITIONS : POST-CONDITIONS : NOTES : LocalOnly, DeepInheritance and propertyList are not : respected by this provider. Localization is not supported PARAMETERS : ================================================================================ */ void IPPEpProvider::getInstance(const OperationContext &ctx, const CIMObjectPath &instanceName, const Boolean includeQualifiers, const Boolean includeClassOrigin, const CIMPropertyList &propertyList, InstanceResponseHandler &handler) { #ifdef DEBUG cout << "IPPEpProvider::getInstance(" << instanceName.toString() << ")" << endl; #endif CIMKeyBinding kb; CIMName className = instanceName.getClassName(); CIMNamespaceName nameSpace = instanceName.getNameSpace(); int i; int keysFound; // this will be used as a bit array String sn; // system name String ifName; // Grab the system name if (IPInterface::getSystemName(sn) == false) sn = String::EMPTY; // Validate the classname _checkClass(className); // Extract the key values Array<CIMKeyBinding> kbArray = instanceName.getKeyBindings(); // Leave immediately if wrong number of keys if ( kbArray.size() != NUMKEYS_IP_PROTOCOL_ENDPOINT ) throw CIMInvalidParameterException("Wrong number of keys"); // Validate the keys. // Each loop iteration will set a bit in keysFound when a valid // key is found. If the expected bits aren't all set when // the loop finishes, it's a problem for (i=0, keysFound=0; i < NUMKEYS_IP_PROTOCOL_ENDPOINT; i++) { kb = kbArray[i]; CIMName keyName = kb.getName(); String keyValue = kb.getValue(); // SystemCreationClassName can be empty or must match if (keyName.equal (PROPERTY_SYSTEM_CREATION_CLASS_NAME)) { if (String::equal(keyValue, String::EMPTY) || String::equalNoCase(keyValue, CLASS_CIM_UNITARY_COMPUTER_SYSTEM.getString())) keysFound |= 1; else throw CIMInvalidParameterException(keyValue+": bad value for key "+ keyName.getString()); } // SystemName can be empty or must match else if (keyName.equal (PROPERTY_SYSTEM_NAME)) { if (String::equal(keyValue, String::EMPTY) || String::equalNoCase(keyValue, sn) ) keysFound |= 2; else throw CIMInvalidParameterException(keyValue+": bad value for key "+ keyName.getString()); } // CreationClassName can be empty or must match else if (keyName.equal (PROPERTY_CREATION_CLASS_NAME)) { if (String::equal(keyValue, String::EMPTY) || String::equalNoCase(keyValue, CLASS_CIM_IP_PROTOCOL_ENDPOINT.getString())) keysFound |= 4; else throw CIMInvalidParameterException(keyValue+": bad value for key "+ keyName.getString()); } // Name must be a valid IP interface, but we will know that later // For now, just verify that it's present else if (keyName.equal (PROPERTY_NAME)) { ifName = keyValue; keysFound |= 8; } // Key name was not recognized by any of the above tests else throw CIMInvalidParameterException(keyName.getString() + ": Unrecognized key"); } // for // We could get here if we didn't get all the keys, which // could happen if the right number of keys were supplied, // and they all had valid names and values, but there were // any duplicates (e.g., two Names, no SystemName) if (keysFound != (1<<NUMKEYS_IP_PROTOCOL_ENDPOINT)-1) throw CIMInvalidParameterException("Bad object name"); /* Find the instance. First convert the instance id which is the */ /* process handle to an integer. This is necessary because the */ /* handle is the process id on HP-UX which must be passed to */ /* pstat_getproc() as an integer. */ /* Get the Interface List. */ InterfaceList _ifList; IPInterface _ipif; if (_ifList.findInterface(ifName, _ipif)) { /* Notify processing is starting. */ handler.processing(); /* Return the instance. */ handler.deliver(_constructInstance(className, nameSpace, _ipif)); /* Notify processing is complete. */ handler.complete(); return; } throw CIMObjectNotFoundException(ifName+": No such IP Interface"); return; // can never execute, but required to keep compiler happy }