ICCItem *CCodeChain::CreateVectorOld (int iSize) // CreateVectorOld // // Creates a vector of the given number of elements { CCVectorOld *pVector; ICCItem *pError; pVector = new CCVectorOld(this); if (pVector == NULL) return CreateMemoryError(); pError = pVector->SetSize(this, iSize); if (pError->IsError()) { delete pVector; return pError; } pError->Discard(this); // Done return pVector->Reference(); }
MI_Boolean IsMatchedKeyProperties( _In_ MI_Instance* instance0, _In_ MI_Instance* instance1, _Outptr_result_maybenull_z_ MI_Char** keywords, _Out_ MI_Result* miResult, _Outptr_result_maybenull_ MI_Instance **extendedError) { MI_Uint32 i, j; MI_Result result0, result1; MI_Value value0, value1; MI_Type type0, type1; Intlstr intlstr = Intlstr_Null; MI_Char* tempKeywords = NULL; MI_Char* tempKeywordsBackup = NULL; size_t length; MI_PropertyDecl** properties; if (extendedError == NULL) { return MI_RESULT_INVALID_PARAMETER; } *extendedError = NULL; // Explicitly set *extendedError to NULL as _Outptr_ requires setting this at least once. *miResult = MI_RESULT_OK; *keywords = NULL; properties = (MI_PropertyDecl**)instance0->classDecl->properties; for (i = 0; i < instance0->classDecl->numProperties; i++) { for (j = 0; j < properties[i]->numQualifiers; j++) { if (Tcscasecmp(properties[i]->qualifiers[j]->name, MI_T("Key")) == 0) { result0 = DSC_MI_Instance_GetElement(instance0, properties[i]->name, &value0, &type0, NULL, NULL); result1 = DSC_MI_Instance_GetElement(instance1, properties[i]->name, &value1, &type1, NULL, NULL); if (result0 == MI_RESULT_OK && result1 == MI_RESULT_OK && type0 == type1 && IsSameMiValue(&value0, &value1, type0)) { // key is the same, building keywords list. length = Tcslen(properties[i]->name) + 1; if (tempKeywords == NULL) { // the first keyword. tempKeywords = (MI_Char*)DSC_malloc(length * sizeof (MI_Char), NitsHere()); if (tempKeywords == NULL) { *miResult = CreateMemoryError(extendedError); return MI_TRUE; } memcpy(tempKeywords, properties[i]->name, length * sizeof(MI_Char) ); } else { // the second or more keywords. if (intlstr.str == NULL) { // create separator string once. GetResourceString(ID_CA_COMMA_SEPARATOR, &intlstr); if (intlstr.str == NULL) { *miResult = CreateMemoryError(extendedError); DSC_free(tempKeywords); return MI_TRUE; } } length += Tcslen(tempKeywords) + Tcslen(intlstr.str); tempKeywordsBackup = tempKeywords; tempKeywords = (MI_Char*)DSC_realloc(tempKeywordsBackup, length * sizeof (MI_Char), NitsHere()); if (tempKeywords == NULL) { *miResult = CreateMemoryError(extendedError); DSC_free(tempKeywordsBackup); Intlstr_Free(intlstr); return MI_TRUE; } Stprintf(tempKeywords, length, MI_T("%T%T"), intlstr.str, properties[i]->name); } } else { if (tempKeywords) { DSC_free(tempKeywords); } if (intlstr.str) { Intlstr_Free(intlstr); } if(result0 != MI_RESULT_OK) { *miResult = result0; } else if(result1 != MI_RESULT_OK) { *miResult = result1; } return MI_FALSE; } break; } } } if (intlstr.str) { Intlstr_Free(intlstr); } // at least one key was found, and all matched. if (tempKeywords) { *keywords = tempKeywords; return MI_TRUE; } return MI_FALSE; }
ICCItem *CCodeChain::UnstreamItem (IReadStream *pStream) // UnstreamItem // // Load the item from an open stream { ALERROR error; DWORD dwClass; ICCItem *pItem; ICCItem *pError; // Read the object class if (error = pStream->Read((char *)&dwClass, sizeof(dwClass), NULL)) return CreateSystemError(error); // Instantiation an object of the right class if (dwClass == OBJID_CCINTEGER) pItem = m_IntegerPool.CreateItem(this); else if (dwClass == OBJID_CCDOUBLE) pItem = m_DoublePool.CreateItem(this); else if (dwClass == OBJID_CCSTRING) pItem = m_StringPool.CreateItem(this); else if (dwClass == OBJID_CCLINKEDLIST) pItem = m_ListPool.CreateItem(this); else if (dwClass == OBJID_CCPRIMITIVE) pItem = m_PrimitivePool.CreateItem(this); else if (dwClass == OBJID_CCNIL) pItem = m_pNil; else if (dwClass == OBJID_CCTRUE) pItem = m_pTrue; else if (dwClass == OBJID_CCSYMBOLTABLE) pItem = m_SymbolTablePool.CreateItem(this); else if (dwClass == OBJID_CCLAMBDA) pItem = m_LambdaPool.CreateItem(this); else if (dwClass == OBJID_CCATOMTABLE) pItem = m_AtomTablePool.CreateItem(this); else if (dwClass == OBJID_CCVECTOROLD) { pItem = new CCVectorOld(this); if (pItem == NULL) pItem = CreateMemoryError(); } else if (dwClass == OBJID_CCVECTOR) pItem = m_VectorPool.CreateItem(this); else return CreateError(LITERAL("Unknown item type"), NULL); // Check for error if (pItem->IsError()) return pItem; // We need to increment the reference here because the native // create does not. pItem->Reset(); pItem->Reference(); // Let the item load the rest pError = pItem->Unstream(this, pStream); if (pError->IsError()) { pItem->Discard(this); return pError; } pError->Discard(this); // Done return pItem; }
MI_Result ValidateIfDuplicatedInstances( _In_ MI_InstanceA *instanceA, _Outptr_result_maybenull_ MI_Instance **extendedError) { MI_Result miResult = MI_RESULT_OK; MI_Instance* instance0; MI_Instance* instance1; MI_Char* keywords; const MI_Char* resourceId0; const MI_Char* resourceId1; MI_Uint32 i, j; if (extendedError == NULL) { return MI_RESULT_INVALID_PARAMETER; } *extendedError = NULL; // Explicitly set *extendedError to NULL as _Outptr_ requires setting this at least once. for (i = 0; i < instanceA->size; i++) { instance0 = instanceA->data[i]; if (instance0->classDecl->superClass != NULL &&Tcscasecmp(instance0->classDecl->superClass, BASE_RESOURCE_CLASSNAME) == 0) { for (j = i + 1; j < instanceA->size; j++) { instance1 = instanceA->data[j]; if (Tcscasecmp(instance0->classDecl->name, instance1->classDecl->name) == 0 && IsMatchedKeyProperties(instance0, instance1, &keywords, &miResult, extendedError)) { if (miResult != MI_RESULT_OK && *extendedError) { return miResult; } resourceId0 = GetResourceId(instance0); resourceId1 = GetResourceId(instance1); if (resourceId0 == NULL || resourceId1 == NULL) { miResult = CreateMemoryError(extendedError); DSC_free(keywords); return miResult; } miResult = GetCimMIError4Params(MI_RESULT_ALREADY_EXISTS, extendedError, ID_CA_DUPLICATE_KEYS, instance0->classDecl->name, resourceId0, resourceId1, keywords); if (keywords) { DSC_free(keywords); } return miResult; } else if (miResult != MI_RESULT_OK) { return miResult; } } } } return MI_RESULT_OK; }