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.
 
 
 
 
 
 

171 lines
4.4 KiB

// Condition.cpp: implementation of the CCondition class.
//
// Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
//
//////////////////////////////////////////////////////////////////////
#include "precomp.h"
#include "Condition.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCondition::CCondition(CRequestObject *pObj, IWbemServices *pNamespace,
IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
{
}
CCondition::~CCondition()
{
}
HRESULT CCondition::CreateObject(IWbemObjectSink *pHandler, ACTIONTYPE atAction)
{
HRESULT hr = WBEM_S_NO_ERROR;
MSIHANDLE hView = NULL;
MSIHANDLE hRecord = NULL;
int i = -1;
WCHAR wcBuf[BUFF_SIZE];
WCHAR wcQuery[BUFF_SIZE];
WCHAR wcProductCode[39];
WCHAR wcProp[BUFF_SIZE];
DWORD dwBufSize;
bool bMatch = false;
UINT uiStatus;
//These will change from class to class
bool bCheck;
if ( atAction != ACTIONTYPE_ENUM )
{
// we are doing GetObject so we need to be reinitialized
hr = WBEM_E_NOT_FOUND;
}
// safe operation
// lenght is smaller than BUFF_SIZE ( 512 )
wcscpy(wcQuery, L"select distinct `Feature_`, `Level`, `Condition` from Condition");
SetSinglePropertyPath(L"CheckID");
LPWSTR Buffer = NULL;
LPWSTR dynBuffer = NULL;
DWORD dwDynBuffer = 0L;
while(!bMatch && m_pRequest->Package(++i) && (hr != WBEM_E_CALL_CANCELLED))
{
// safe operation:
// Package ( i ) returns NULL ( tested above ) or valid WCHAR [39]
wcscpy(wcProductCode, m_pRequest->Package(i));
//Open our database
try
{
if ( GetView ( &hView, wcProductCode, wcQuery, L"Condition", TRUE, FALSE ) )
{
uiStatus = g_fpMsiViewFetch(hView, &hRecord);
while(!bMatch && (uiStatus != ERROR_NO_MORE_ITEMS) && (hr != WBEM_E_CALL_CANCELLED)){
CheckMSI(uiStatus);
if(FAILED(hr = SpawnAnInstance(&m_pObj))) throw hr;
//----------------------------------------------------
dwBufSize = BUFF_SIZE;
GetBufferToPut ( hRecord, 1, dwBufSize, wcProp, dwDynBuffer, dynBuffer, Buffer );
PutProperty(m_pObj, pName, Buffer);
PutProperty(m_pObj, pFeature, Buffer);
PutProperty(m_pObj, pCaption, Buffer);
PutProperty(m_pObj, pDescription, Buffer);
if ( ValidateFeatureName ( Buffer, wcProductCode ) )
{
CheckMSI(g_fpMsiRecordGetStringW(hRecord, 2, wcBuf, &dwBufSize));
PutKeyProperty ( m_pObj, pCheckID, Buffer, &bCheck, m_pRequest, 2, wcBuf, wcProductCode);
if ( dynBuffer && dynBuffer [ 0 ] != 0 )
{
dynBuffer [ 0 ] = 0;
}
//====================================================
PutProperty(m_pObj, pLevel, g_fpMsiRecordGetInteger(hRecord, 2));
dwBufSize = BUFF_SIZE;
PutPropertySpecial ( hRecord, 3, dwBufSize, wcBuf, dwDynBuffer, dynBuffer, pCondition, FALSE );
//----------------------------------------------------
if(bCheck) bMatch = true;
if((atAction != ACTIONTYPE_GET) || bMatch){
hr = pHandler->Indicate(1, &m_pObj);
}
}
else
{
if ( dynBuffer && dynBuffer [ 0 ] != 0 )
{
dynBuffer [ 0 ] = 0;
}
}
m_pObj->Release();
m_pObj = NULL;
g_fpMsiCloseHandle(hRecord);
uiStatus = g_fpMsiViewFetch(hView, &hRecord);
}
}
}
catch(...)
{
if ( dynBuffer )
{
delete [] dynBuffer;
dynBuffer = NULL;
}
g_fpMsiCloseHandle(hRecord);
g_fpMsiViewClose(hView);
g_fpMsiCloseHandle(hView);
msidata.CloseDatabase ();
if(m_pObj)
{
m_pObj->Release();
m_pObj = NULL;
}
throw;
}
g_fpMsiCloseHandle(hRecord);
g_fpMsiViewClose(hView);
g_fpMsiCloseHandle(hView);
msidata.CloseDatabase ();
}
if ( dynBuffer )
{
delete [] dynBuffer;
dynBuffer = NULL;
}
return hr;
}