version 1.2.2.1, 2009/08/17 13:47:46
|
version 1.2.2.11, 2009/10/20 16:20:51
|
|
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include "CIMResponseData.h" | #include "CIMResponseData.h" |
#include "XmlWriter.h" |
#include <Pegasus/Common/Tracer.h> |
#include "XmlReader.h" |
#include <Pegasus/Common/XmlWriter.h> |
#include "Tracer.h" |
#include <Pegasus/Common/SCMOXmlWriter.h> |
|
#include <Pegasus/Common/XmlReader.h> |
|
#include <Pegasus/Common/SCMOClassCache.h> |
| |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
//----------------------------------------------------------------------------- |
// C++ objects interface handling |
// |
|
// CIMInstanceNamesResponseData |
// Instance Names handling |
// |
Array<CIMObjectPath>& CIMResponseData::getInstanceNames() |
//----------------------------------------------------------------------------- |
{ |
|
PEGASUS_DEBUG_ASSERT( |
//------------------------------------------------------------------------------ |
(_dataType==RESP_INSTNAMES || _dataType==RESP_OBJECTPATHS)); |
// Takes a binary stream of object paths from a CIMBuffer and stores it in the |
_resolveToCIM(); |
// responsedata. |
PEGASUS_DEBUG_ASSERT(_encoding==RESP_ENC_CIM || _encoding == 0); |
// @param hasLen Indicates if the binary object path stream is prepended with an |
return _instanceNames; |
// Uint32 value indicating the number of paths in the stream. |
} |
//------------------------------------------------------------------------------ |
|
bool CIMInstanceNamesResponseData::setBinaryCimInstanceNames( |
// Instance handling |
CIMBuffer& in, bool hasLen) |
CIMInstance& CIMResponseData::getInstance() |
|
{ |
|
PEGASUS_DEBUG_ASSERT(_dataType == RESP_INSTANCE); |
|
_resolveToCIM(); |
|
return _instances[0]; |
|
} |
|
|
|
// Instances handling |
|
Array<CIMInstance>& CIMResponseData::getInstances() |
|
{ |
|
PEGASUS_DEBUG_ASSERT(_dataType == RESP_INSTANCES); |
|
_resolveToCIM(); |
|
return _instances; |
|
} |
|
|
|
// Objects handling |
|
Array<CIMObject>& CIMResponseData::getObjects() |
|
{ |
|
PEGASUS_DEBUG_ASSERT(_dataType == RESP_OBJECTS); |
|
_resolveToCIM(); |
|
return _objects; |
|
} |
|
|
|
// SCMO representation, single instance stored as one element array |
|
// object paths are represented as SCMOInstance |
|
Array<SCMOInstance>& CIMResponseData::getSCMO() |
|
{ |
|
_resolveToSCMO(); |
|
return _scmoInstances; |
|
} |
|
|
|
void CIMResponseData::setSCMO(const Array<SCMOInstance>& x) |
|
{ |
|
// Just assignment bears danger of us being dependent on the original array |
|
// content staying valid |
|
_scmoInstances=x; |
|
/* |
|
for (Uint32 loop=0, max=x.size(); loop<max; loop++) |
|
{ |
|
_scmoInstances.append(x[loop]); |
|
} |
|
*/ |
|
// _scmoInstances.appendArray(x); |
|
_encoding |= RESP_ENC_SCMO; |
|
} |
|
|
|
|
|
// Binary data is just a data stream |
|
Array<Uint8>& CIMResponseData::getBinary() |
|
{ |
|
PEGASUS_DEBUG_ASSERT(_encoding == RESP_ENC_BINARY || _encoding == 0); |
|
return _binaryData; |
|
} |
|
|
|
bool CIMResponseData::setBinary(CIMBuffer& in, bool hasLen) |
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, | PEG_METHOD_ENTER(TRC_DISPATCHER, |
"CIMInstanceNamesResponseData::setBinaryCimInstanceNames"); |
"CIMResponseData::setBinary"); |
| |
if (hasLen) | if (hasLen) |
{ | { |
|
|
size_t remainingDataLength = in.capacity() - in.size(); | size_t remainingDataLength = in.capacity() - in.size(); |
_binaryData.append((Uint8*)in.getPtr(), remainingDataLength); | _binaryData.append((Uint8*)in.getPtr(), remainingDataLength); |
} | } |
|
_encoding |= RESP_ENC_BINARY; |
_resolveCallback = _resolveBinaryInstanceNames; |
|
_encoding = RESP_ENC_BINARY; |
|
|
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; | return true; |
}; |
} |
| |
bool CIMInstanceNamesResponseData::setXmlCimInstanceNames(CIMBuffer& in) |
bool CIMResponseData::setXml(CIMBuffer& in) |
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, | PEG_METHOD_ENTER(TRC_DISPATCHER, |
"CIMInstanceNamesResponseData::setXmlCimInstanceNames"); |
"CIMResponseData::setXml"); |
| |
|
if (_dataType == RESP_INSTNAMES) |
|
{ |
Uint32 count; | Uint32 count; |
| |
if (!in.getUint32(count)) | if (!in.getUint32(count)) |
|
|
_hostsData.append(host); | _hostsData.append(host); |
_nameSpacesData.append(ns); | _nameSpacesData.append(ns); |
} | } |
|
} |
|
// TODO: Code the left out types |
| |
_resolveCallback = _resolveXMLInstanceNames; |
_encoding |= RESP_ENC_XML; |
_encoding = RESP_ENC_XML; |
|
|
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; | return true; |
}; |
} |
| |
|
// function used by OperationAggregator to aggregate response data in a |
|
// single ResponseData object |
|
void CIMResponseData::appendResponseData(const CIMResponseData & x) |
|
{ |
|
// as the Messages set the data types, this should be impossible |
|
PEGASUS_DEBUG_ASSERT(_dataType == x._dataType); |
|
_encoding |= x._encoding; |
|
|
|
// add all binary data |
|
_binaryData.appendArray(x._binaryData); |
| |
|
// add all the C++ stuff |
|
_instanceNames.appendArray(x._instanceNames); |
|
_instances.appendArray(x._instances); |
|
_objects.appendArray(x._objects); |
| |
|
// add the SCMO instances |
|
_scmoInstances.appendArray(x._scmoInstances); |
|
|
|
// add Xml encodings too |
|
_referencesData.appendArray(x._referencesData); |
|
_instanceData.appendArray(x._instanceData); |
|
_hostsData.appendArray(x._hostsData); |
|
_nameSpacesData.appendArray(x._nameSpacesData); |
|
} |
| |
//------------------------------------------------------------------------------ |
// Encoding responses into output format |
// Encodes the array of CIMObjectPath representation contained in the current |
void CIMResponseData::encodeBinaryResponse(CIMBuffer& out) |
// CIMResponseData object in binary response message format. |
|
// This code corresponds to method _resolveBinaryInstanceNames, which is used |
|
// revert a binary objectpath array representation back into an array of |
|
// CIMInstance |
|
//------------------------------------------------------------------------------ |
|
void CIMInstanceNamesResponseData::encodeBinaryResponse(CIMBuffer& out) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, | PEG_METHOD_ENTER(TRC_DISPATCHER, |
"CIMInstanceNamesResponseData::encodeBinaryResponse"); |
"CIMResponseData::encodeBinaryResponse"); |
| |
if (_resolveCallback && (_encoding == RESP_ENC_BINARY)) |
// Need to do a complete job here by transferring all contained data |
|
// into binary format and handing it out in the CIMBuffer |
|
if (RESP_ENC_BINARY == (_encoding & RESP_ENC_BINARY)) |
{ | { |
|
// Binary does NOT need a marker as it consists of C++ and SCMO |
const Array<Uint8>& data = _binaryData; | const Array<Uint8>& data = _binaryData; |
out.putBytes(data.getData(), data.size()); | out.putBytes(data.getData(), data.size()); |
} | } |
else |
if (RESP_ENC_CIM == (_encoding & RESP_ENC_CIM)) |
|
{ |
|
// TODO: Set Marker for C++ data |
|
switch (_dataType) |
|
{ |
|
case RESP_INSTNAMES: |
{ | { |
_resolve(); |
|
out.putObjectPathA(_instanceNames, false); | out.putObjectPathA(_instanceNames, false); |
|
break; |
} | } |
PEG_METHOD_EXIT(); |
case RESP_INSTANCE: |
} |
|
|
|
//------------------------------------------------------------------------------ |
|
// Encodes the array of CIMObjectPath representation contained in the current |
|
// CIMResponseData object in xml response message format. |
|
// This code corresponds to method _resolveXmlInstanceNames, which is used |
|
// revert a CIM-XML objectpath array representation back into an array of |
|
// CIMObjectPath. |
|
//------------------------------------------------------------------------------ |
|
void CIMInstanceNamesResponseData::encodeXmlResponse(Buffer& out) |
|
{ |
|
PEG_METHOD_ENTER(TRC_DISPATCHER, |
|
"CIMInstanceNamesResponseData::encodeXmlResponse"); |
|
|
|
if (_resolveCallback && (_encoding == RESP_ENC_XML)) |
|
{ | { |
const Array<ArraySint8>& a = _referencesData; |
if (0 != _instances.size()) |
|
|
for (Uint32 i = 0, n = a.size(); i < n; i++) |
|
{ | { |
out.append((char*)a[i].getData(), a[i].size() - 1); |
out.putInstance(_instances[0], false, false); |
} | } |
|
break; |
} | } |
else |
case RESP_INSTANCES: |
{ | { |
_resolve(); |
out.putInstanceA(_instances, false); |
for (Uint32 i = 0, n = _instanceNames.size(); i < n; i++) |
break; |
XmlWriter::appendInstanceNameElement(out,_instanceNames[i]); |
|
} | } |
PEG_METHOD_EXIT(); |
case RESP_OBJECTS: |
|
{ |
|
out.putObjectA(_objects); |
|
break; |
} | } |
|
case RESP_OBJECTPATHS: |
//------------------------------------------------------------------------------ |
|
// Instantiates an array of ObjectPath from a binary representation created by |
|
// the CIMBinMessageSerializer. |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMInstanceNamesResponseData::_resolveBinaryInstanceNames( |
|
CIMInstanceNamesResponseData* data, |
|
Array<CIMObjectPath>& cops) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
// TODO: Determine what to do here |
"CIMInstanceNamesResponseData::_resolveBinaryInstanceNames"); |
break; |
|
} |
cops.clear(); |
default: |
|
|
CIMBuffer in((char*)data->_binaryData.getData(), data->_binaryData.size()); |
|
|
|
while (in.more()) |
|
{ | { |
if (!in.getObjectPathA(cops)) |
PEGASUS_DEBUG_ASSERT(false); |
|
} |
|
} |
|
} |
|
if (RESP_ENC_SCMO == (_encoding & RESP_ENC_SCMO)) |
{ | { |
in.release(); |
// TODO: Set Marker for SCMO data |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to resolve binary objectpath!"); |
// Call magic here to transform a SCMO object into binary format |
PEG_METHOD_EXIT(); |
fprintf(stderr, "Watch wat ya do'n! SCMO to binary ? NO OOP yet.\n"); |
return false; |
fflush(stderr); |
} | } |
|
if (RESP_ENC_XML == (_encoding & RESP_ENC_XML)) |
|
{ |
|
// This actually should not happen following general code logic |
|
PEGASUS_DEBUG_ASSERT(false); |
} | } |
| |
in.release(); |
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; |
|
} | } |
| |
|
void CIMResponseData::completeHostNameAndNamespace( |
|
const String & hn, |
//------------------------------------------------------------------------------ |
const CIMNamespaceName & ns) |
// Instantiates an array of CIMObjectPath from an xml representation created by |
|
// the CIMBinMessageSerializer. |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMInstanceNamesResponseData::_resolveXMLInstanceNames( |
|
CIMInstanceNamesResponseData* data, |
|
Array<CIMObjectPath>& cops) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
// Internal XML always has host name and namespace |
"CIMInstanceNamesResponseData::_resolveXMLInstanceNames"); |
// binary data shhould not ever be present here |
|
PEGASUS_DEBUG_ASSERT((RESP_ENC_BINARY != (_encoding & RESP_ENC_BINARY))); |
| |
cops.clear(); |
if (RESP_ENC_CIM == (_encoding & RESP_ENC_CIM)) |
|
|
for (Uint32 i = 0; i < data->_referencesData.size(); i++) |
|
{ | { |
CIMObjectPath cop; |
switch (_dataType) |
|
|
// Deserialize path: |
|
{ | { |
XmlParser parser((char*)data->_referencesData[i].getData()); |
case RESP_OBJECTS: |
|
|
if (XmlReader::getInstanceNameElement(parser, cop)) |
|
{ | { |
if (!data->_nameSpacesData[i].isNull()) |
for (Uint32 j = 0, n = _objects.size(); j < n; j++) |
cop.setNameSpace(data->_nameSpacesData[i]); |
{ |
|
const CIMObject& object = _objects[j]; |
if (data->_hostsData[i].size()) |
CIMObjectPath& p = |
cop.setHost(data->_hostsData[i]); |
const_cast<CIMObjectPath&>(object.getPath()); |
|
if (p.getHost().size()==0) |
|
{ |
|
p.setHost(hn); |
} | } |
|
if (p.getNameSpace().isNull()) |
|
{ |
|
p.setNameSpace(ns); |
} | } |
|
|
cops.append(cop); |
|
} | } |
|
break; |
PEG_METHOD_EXIT(); |
|
return true; |
|
} | } |
|
case RESP_OBJECTPATHS: |
//------------------------------------------------------------------------------ |
|
// Instantiates an array of CIMObjectPath from an array of SCMOInstances |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMInstanceNamesResponseData::_resolveSCMOInstanceNames( |
|
CIMInstanceNamesResponseData* data, |
|
Array<CIMObjectPath>& cops) |
|
{ |
|
PEG_METHOD_ENTER(TRC_DISPATCHER, |
|
"CIMInstanceNamesResponseData::_resolveSCMOInstanceNames"); |
|
|
|
cops.clear(); |
|
|
|
//--rk-->TBD: Do the actual coding here |
|
|
|
fprintf(stderr,"CIMInstanceNamesResponseData::_resolveSCMOInstanceNames() " |
|
"Poorly implemented!!!\n"); |
|
try |
|
{ | { |
for (Uint32 x=0; x < data->_scmoInstanceNames.size(); x++) |
for (Uint32 j = 0, n = _instanceNames.size(); j < n; j++) |
{ | { |
/*SCMODump dmp; |
CIMObjectPath& p = _instanceNames[j]; |
dmp.dumpSCMOInstanceKeyBindings(data->_scmoInstanceNames[x]);*/ |
if (p.getHost().size() == 0) |
CIMObjectPath cop; |
p.setHost(hn); |
data->_scmoInstanceNames[x].getCIMObjectPath(cop); |
if (p.getNameSpace().isNull()) |
cops.append(cop); |
p.setNameSpace(ns); |
} | } |
|
break; |
} | } |
catch (CIMException& ex) |
default: |
{ | { |
fprintf(stderr, |
PEGASUS_DEBUG_ASSERT(false); |
"CIMInstanceNamesResponseData::_resolveSCMOInstanceNames() " |
} |
"Exception:\n%s\n",(const char*)ex.getMessage().getCString()); |
|
} | } |
catch (Exception& ex) |
} |
|
if (RESP_ENC_SCMO == (_encoding & RESP_ENC_SCMO)) |
|
{ |
|
CString hnCString=hn.getCString(); |
|
const char* hnChars = hnCString; |
|
Uint32 hnLen = strlen(hnChars); |
|
CString nsCString=ns.getString().getCString(); |
|
const char* nsChars=nsCString; |
|
Uint32 nsLen = strlen(nsChars); |
|
switch (_dataType) |
{ | { |
fprintf(stderr, |
case RESP_OBJECTS: |
"CIMInstanceNamesResponseData::_resolveSCMOInstanceNames() " |
case RESP_OBJECTPATHS: |
"Exception:\n%s\n",(const char*)ex.getMessage().getCString()); |
{ |
|
for (Uint32 j = 0, n = _scmoInstances.size(); j < n; j++) |
|
{ |
|
SCMOInstance & scmoInst=_scmoInstances[j]; |
|
if (0 == scmoInst.getHostName()) |
|
{ |
|
scmoInst.setHostName_l(hnChars,hnLen); |
} | } |
catch (exception& ex) |
if (0 == scmoInst.getNameSpace()) |
{ | { |
fprintf(stderr, |
scmoInst.setNameSpace_l(nsChars,nsLen); |
"CIMInstanceNamesResponseData::_resolveSCMOInstanceNames() " |
} |
"exception:\n%s\n",(const char*)ex.what()); |
|
} | } |
catch (...) |
break; |
|
} |
|
default: |
{ | { |
fprintf(stderr, |
PEGASUS_DEBUG_ASSERT(false); |
"CIMInstanceNamesResponseData::_resolveSCMOInstanceNames() " |
} |
"Exception: UNKNOWN\n"); |
} |
} | } |
data->_resolveCallback = 0; |
|
|
|
PEG_METHOD_EXIT(); |
|
return true; |
|
} | } |
| |
|
void CIMResponseData::encodeXmlResponse(Buffer& out) |
//----------------------------------------------------------------------------- |
|
// |
|
// CIMInstanceResponseData |
|
// |
|
//----------------------------------------------------------------------------- |
|
|
|
//------------------------------------------------------------------------------ |
|
// Takes a binary stream representing an instances from a CIMBuffer and stores |
|
// it in the responsedata. |
|
// @param hasLen Indicates if the binary instance stream is prepended with an |
|
// Uint32 value indicating the number of instances in the stream. |
|
//------------------------------------------------------------------------------ |
|
bool CIMInstanceResponseData::setBinaryCimInstance(CIMBuffer& in, bool hasLen) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
PEG_TRACE((TRC_XML, Tracer::LEVEL3, |
"CIMInstanceResponseData::setBinaryCimInstance"); |
"CIMResponseData::encodeXmlResponse(encoding=%X,content=%X)\n", |
|
_encoding, |
|
_dataType)); |
| |
if (hasLen) |
if (RESP_ENC_XML == (_encoding & RESP_ENC_XML)) |
{ | { |
if (!in.getUint8A(_binaryData)) |
switch (_dataType) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
case RESP_INSTNAMES: |
"Failed to get binary instance data!"); |
{ |
PEG_METHOD_EXIT(); |
const Array<ArraySint8>& a = _referencesData; |
return false; |
for (Uint32 i = 0, n = a.size(); i < n; i++) |
|
{ |
|
out.append((char*)a[i].getData(), a[i].size() - 1); |
} | } |
|
break; |
} | } |
else |
case RESP_INSTANCE: |
{ | { |
size_t remainingDataLength = in.capacity() - in.size(); |
out.append( |
|
(char*)_instanceData.getData(), |
_binaryData.append((Uint8*)in.getPtr(), remainingDataLength); |
_instanceData.size()-1); |
|
break; |
} | } |
|
case RESP_INSTANCES: |
_resolveCallback = _resolveBinaryInstance; |
|
_binaryEncoding = true; |
|
|
|
PEG_METHOD_EXIT(); |
|
return true; |
|
}; |
|
|
|
bool CIMInstanceResponseData::setXmlCimInstance(CIMBuffer& in) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
const Array<ArraySint8>& a = _instanceData; |
"CIMInstanceResponseData::setXmlCimInstance"); |
const Array<ArraySint8>& b = _referencesData; |
| |
if (!in.getSint8A(_instanceData)) |
for (Uint32 i = 0, n = a.size(); i < n; i++) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
out << STRLIT("<VALUE.NAMEDINSTANCE>\n"); |
"Failed to get XML instance data!"); |
out.append((char*)b[i].getData(), b[i].size() - 1); |
PEG_METHOD_EXIT(); |
out.append((char*)a[i].getData(), a[i].size() - 1); |
return false; |
out << STRLIT("</VALUE.NAMEDINSTANCE>\n"); |
|
} |
|
break; |
} | } |
|
case RESP_OBJECTS: |
|
{ |
|
const Array<ArraySint8>& a = _instanceData; |
|
const Array<ArraySint8>& b = _referencesData; |
| |
if (!in.getSint8A(_referenceData)) |
for (Uint32 i = 0, n = a.size(); i < n; i++) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
out << STRLIT("<VALUE.OBJECTWITHPATH>\n"); |
"Failed to get XML instance data (reference)!"); |
out.append((char*)b[i].getData(), b[i].size() - 1); |
PEG_METHOD_EXIT(); |
out.append((char*)a[i].getData(), a[i].size() - 1); |
return false; |
out << STRLIT("</VALUE.OBJECTWITHPATH>\n"); |
} | } |
|
break; |
|
} |
|
case RESP_OBJECTPATHS: |
|
{ |
|
// TODO: Check what to do in this case |
|
const Array<ArraySint8>& a = _instanceData; |
|
const Array<ArraySint8>& b = _referencesData; |
| |
if (!in.getString(_hostData)) |
for (Uint32 i = 0, n = a.size(); i < n; i++) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
out << STRLIT("<VALUE.OBJECTWITHPATH>\n"); |
"Failed to get XML instance data (host)!"); |
out.append((char*)b[i].getData(), b[i].size() - 1); |
PEG_METHOD_EXIT(); |
out.append((char*)a[i].getData(), a[i].size() - 1); |
return false; |
out << STRLIT("</VALUE.OBJECTWITHPATH>\n"); |
} | } |
|
} |
if (!in.getNamespaceName(_nameSpaceData)) |
default: |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
PEGASUS_DEBUG_ASSERT(false); |
"Failed to get XML instance data (namespace)!"); |
} |
PEG_METHOD_EXIT(); |
} |
return false; |
|
} | } |
| |
_resolveCallback = _resolveXMLInstance; |
if (RESP_ENC_CIM == (_encoding & RESP_ENC_CIM)) |
|
|
PEG_METHOD_EXIT(); |
|
return true; |
|
}; |
|
|
|
//------------------------------------------------------------------------------ |
|
// Encodes the CIMInstance representation contained in the current |
|
// CIMResponseData object in binary response message format. |
|
// This code corresponds to method _resolveBinaryInstance, which is used |
|
// revert a binary instance representation back into a CIMInstance |
|
//------------------------------------------------------------------------------ |
|
void CIMInstanceResponseData::encodeBinaryResponse(CIMBuffer& out) const |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
switch (_dataType) |
"CIMInstanceResponseData::encodeBinaryResponse"); |
|
|
|
if (_resolveCallback && _binaryEncoding) |
|
{ | { |
const Array<Uint8>& data = _binaryData; |
case RESP_INSTNAMES: |
out.putBytes(data.getData(), data.size()); |
{ |
|
for (Uint32 i = 0, n = _instanceNames.size(); i < n; i++) |
|
{ |
|
XmlWriter::appendInstanceNameElement(out,_instanceNames[i]); |
} | } |
else |
break; |
|
} |
|
case RESP_INSTANCE: |
{ | { |
out.putInstance(_cimInstance, false, false); |
if (_instances.size()>0) |
|
{ |
|
XmlWriter::appendInstanceElement(out, _instances[0]); |
} | } |
PEG_METHOD_EXIT(); |
break; |
} | } |
|
case RESP_INSTANCES: |
//------------------------------------------------------------------------------ |
|
// Encodes the CIMInstanc representation contained in the current |
|
// CIMResponseData object in xml response message format. |
|
// This code corresponds to method _resolveXmlInstance, which is used |
|
// revert a CIM-XML instance representation back into a CIMInstance. |
|
//------------------------------------------------------------------------------ |
|
void CIMInstanceResponseData::encodeXmlResponse(Buffer& out) const |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
for (Uint32 i = 0, n = _instances.size(); i < n; i++) |
"CIMInstanceResponseData::encodeXmlResponse"); |
|
|
|
if (_resolveCallback && !_binaryEncoding) |
|
{ | { |
out.append( (char*)_instanceData.getData(),_instanceData.size()-1); |
XmlWriter::appendValueNamedInstanceElement( |
|
out, _instances[i]); |
} | } |
else |
break; |
|
} |
|
case RESP_OBJECTS: |
{ | { |
XmlWriter::appendInstanceElement(out, _cimInstance); |
for (Uint32 i = 0; i < _objects.size(); i++) |
|
{ |
|
XmlWriter::appendValueObjectWithPathElement( |
|
out, |
|
_objects[i]); |
} | } |
PEG_METHOD_EXIT(); |
break; |
} | } |
|
case RESP_OBJECTPATHS: |
//------------------------------------------------------------------------------ |
|
// Instantiates a CIMInstance from a binary representation created by |
|
// the CIMBinMessageSerializer. |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMInstanceResponseData::_resolveBinaryInstance( |
|
CIMInstanceResponseData* data, |
|
CIMInstance& instance) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
for (Uint32 i = 0, n = _instanceNames.size(); i < n; i++) |
"CIMInstanceResponseData::_resolveBinaryInstance"); |
|
|
|
CIMBuffer in((char*)data->_binaryData.getData(), data->_binaryData.size()); |
|
|
|
if (!in.getInstance(instance)) |
|
{ | { |
instance = CIMInstance(); |
out << "<OBJECTPATH>\n"; |
in.release(); |
XmlWriter::appendValueReferenceElement( |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
out, |
"Failed to resolve binary instance!"); |
_instanceNames[i], |
PEG_METHOD_EXIT(); |
false); |
return false; |
out << "</OBJECTPATH>\n"; |
} | } |
|
break; |
in.release(); |
|
PEG_METHOD_EXIT(); |
|
return true; |
|
} | } |
|
default: |
//------------------------------------------------------------------------------ |
|
// Instantiates a CIMInstance from an xml representation created by |
|
// the CIMBinMessageSerializer. |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMInstanceResponseData::_resolveXMLInstance( |
|
CIMInstanceResponseData* data, |
|
CIMInstance& cimInstance) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
PEGASUS_DEBUG_ASSERT(false); |
"CIMInstanceResponseData::_resolveXMLInstance"); |
} |
|
} |
// Deserialize instance: |
} |
|
if (RESP_ENC_SCMO == (_encoding & RESP_ENC_SCMO)) |
{ | { |
XmlParser parser((char*)data->_instanceData.getData()); |
switch (_dataType) |
|
|
if (!XmlReader::getInstanceElement(parser, cimInstance)) |
|
{ | { |
cimInstance = CIMInstance(); |
case RESP_INSTNAMES: |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
{ |
"Failed to resolve XML instance, parser error!"); |
for (Uint32 i = 0, n = _scmoInstances.size(); i < n; i++) |
PEG_METHOD_EXIT(); |
{ |
return false; |
SCMOXmlWriter::appendInstanceNameElement( |
|
out, |
|
_scmoInstances[i]); |
} | } |
|
break; |
} | } |
|
case RESP_INSTANCE: |
// Deserialize path: |
|
{ | { |
XmlParser parser((char*)data->_referenceData.getData()); |
if (_scmoInstances.size() > 0) |
CIMObjectPath cimObjectPath; |
|
|
|
if (XmlReader::getValueReferenceElement(parser, cimObjectPath)) |
|
{ | { |
if (data->_hostData.size()) |
SCMOXmlWriter::appendInstanceElement(out,_scmoInstances[0]); |
cimObjectPath.setHost(data->_hostData); |
|
|
|
if (!data->_nameSpaceData.isNull()) |
|
cimObjectPath.setNameSpace(data->_nameSpaceData); |
|
|
|
cimInstance.setPath(cimObjectPath); |
|
} | } |
|
break; |
} | } |
|
case RESP_INSTANCES: |
PEG_METHOD_EXIT(); |
{ |
return true; |
for (Uint32 i = 0, n = _scmoInstances.size(); i < n; i++) |
|
{ |
|
SCMOXmlWriter::appendValueSCMOInstanceElement( |
|
out, |
|
_scmoInstances[i]); |
} | } |
|
break; |
|
} |
|
case RESP_OBJECTS: |
//----------------------------------------------------------------------------- |
|
// |
|
// CIMInstancesResponseData |
|
// |
|
//----------------------------------------------------------------------------- |
|
|
|
//------------------------------------------------------------------------------ |
|
// Takes a binary stream of instances from a CIMBuffer and stores it in the |
|
// responsedata. |
|
// @param hasLen Indicates if the binary instance stream is prepended with an |
|
// Uint32 value indicating the number of instances in the stream. |
|
//------------------------------------------------------------------------------ |
|
bool CIMInstancesResponseData::setBinaryCimInstances(CIMBuffer& in, bool hasLen) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
for (Uint32 i = 0; i < _scmoInstances.size(); i++) |
"CIMInstancesResponseData::setBinaryCimInstances"); |
|
|
|
if (hasLen) |
|
{ | { |
if (!in.getUint8A(_binaryData)) |
SCMOXmlWriter::appendValueObjectWithPathElement( |
|
out, |
|
_scmoInstances[i]); |
|
} |
|
break; |
|
} |
|
case RESP_OBJECTPATHS: |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
for (Uint32 i = 0, n = _scmoInstances.size(); i < n; i++) |
"Failed to get binary instance data!"); |
{ |
PEG_METHOD_EXIT(); |
out << "<OBJECTPATH>\n"; |
return false; |
SCMOXmlWriter::appendValueReferenceElement( |
|
out, |
|
_scmoInstances[i], |
|
false); |
|
out << "</OBJECTPATH>\n"; |
} | } |
|
break; |
} | } |
else |
default: |
{ | { |
size_t remainingDataLength = in.capacity() - in.size(); |
PEGASUS_DEBUG_ASSERT(false); |
_binaryData.append((Uint8*)in.getPtr(), remainingDataLength); |
} |
|
} |
|
} |
} | } |
| |
_resolveCallback = _resolveBinaryInstances; |
// contrary to encodeXmlResponse this function encodes the Xml in a format |
_encoding = RESP_ENC_BINARY; |
// not usable by clients |
|
void CIMResponseData::encodeInternalXmlResponse(CIMBuffer& out) |
PEG_METHOD_EXIT(); |
|
return true; |
|
}; |
|
|
|
bool CIMInstancesResponseData::setXmlCimInstances(CIMBuffer& in) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
// TODO: Implement |
"CIMInstancesResponseData::setXmlCimInstances"); |
// Need the full switch here again |
|
// Should use the internal data available SCMO, C++ and InternalXML |
Uint32 count; |
// to generate the InternalXML by CIMInternalEncoder and SCMOInternalEncoder |
|
fprintf(stderr, "Watch wat ya do'n! SCMO to InternalXml ? NO OOP yet.\n"); |
if (!in.getUint32(count)) |
fflush(stderr); |
{ |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to get XML instance data (number of instance)!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
| |
for (Uint32 i = 0; i < count; i++) |
void CIMResponseData::_resolveToCIM() |
{ | { |
Array<Sint8> inst; |
PEG_TRACE((TRC_XML, Tracer::LEVEL2, |
Array<Sint8> ref; |
"CIMResponseData::_resolveToCIM(encoding=%X,content=%X)\n", |
CIMNamespaceName ns; |
_encoding, |
String host; |
_dataType)); |
| |
if (!in.getSint8A(inst)) |
if (RESP_ENC_XML == (_encoding & RESP_ENC_XML)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
_resolveXmlToCIM(); |
"Failed to get XML instance data (instances)!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
|
if (RESP_ENC_BINARY == (_encoding & RESP_ENC_BINARY)) |
if (!in.getSint8A(ref)) |
|
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
_resolveBinary(); |
"Failed to get XML instance data (references)!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} |
|
|
|
if (!in.getString(host)) |
|
{ |
|
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to get XML instance data (host)!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
|
if (RESP_ENC_SCMO == (_encoding & RESP_ENC_SCMO)) |
if (!in.getNamespaceName(ns)) |
|
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
_resolveSCMOToCIM(); |
"Failed to get XML instance data (namespace)!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
|
PEGASUS_DEBUG_ASSERT(_encoding == RESP_ENC_CIM || _encoding == 0); |
_instancesData.append(inst); |
|
_referencesData.append(ref); |
|
_hostsData.append(host); |
|
_nameSpacesData.append(ns); |
|
} | } |
| |
_resolveCallback = _resolveXMLInstances; |
void CIMResponseData::_resolveToSCMO() |
_encoding = RESP_ENC_XML; |
|
|
|
PEG_METHOD_EXIT(); |
|
return true; |
|
}; |
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
// Encodes the array of CIMInstance representation contained in the current |
|
// CIMResponseData object in binary response message format. |
|
// This code corresponds to method _resolveBinaryInstances, which is used |
|
// revert a binary instance array representation back into an array of |
|
// CIMInstance |
|
//------------------------------------------------------------------------------ |
|
void CIMInstancesResponseData::encodeBinaryResponse(CIMBuffer& out) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
PEG_TRACE((TRC_XML, Tracer::LEVEL2, |
"CIMInstancesResponseData::encodeBinaryResponse"); |
"CIMResponseData::_resolveToSCMO(encoding=%X,content=%X)\n", |
|
_encoding, |
|
_dataType)); |
| |
if (_resolveCallback && (_encoding == RESP_ENC_BINARY)) |
if (RESP_ENC_XML == (_encoding & RESP_ENC_XML)) |
{ | { |
const Array<Uint8>& data = _binaryData; |
_resolveXmlToSCMO(); |
out.putBytes(data.getData(), data.size()); |
|
} | } |
else |
if (RESP_ENC_BINARY == (_encoding & RESP_ENC_BINARY)) |
{ | { |
_resolve(); |
_resolveBinary(); |
out.putInstanceA(_namedInstances, false); |
|
} | } |
PEG_METHOD_EXIT(); |
if (RESP_ENC_CIM == (_encoding & RESP_ENC_CIM)) |
|
{ |
|
_resolveCIMToSCMO(); |
|
} |
|
PEGASUS_DEBUG_ASSERT(_encoding == RESP_ENC_SCMO || _encoding == 0); |
} | } |
| |
//------------------------------------------------------------------------------ |
// helper functions to transform different formats into one-another |
// Encodes the array of CIMInstance representation contained in the current |
// functions work on the internal data and calling of them should be |
// CIMResponseData object in xml response message format. |
// avoided whenever possible |
// This code corresponds to method _resolveXmlInstances, which is used |
void CIMResponseData::_resolveBinary() |
// revert a CIM-XML object array representation back into an array of |
|
// CIMInstance. |
|
//------------------------------------------------------------------------------ |
|
void CIMInstancesResponseData::encodeXmlResponse(Buffer& out) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
// Call magic here to resolve binary format |
"CIMInstancesResponseData::encodeXmlResponse"); |
fprintf(stderr, "Watch wat ya do'n! binary ? NO OOP yet.\n"); |
|
fflush(stderr); |
| |
if (_resolveCallback && (_encoding == RESP_ENC_XML)) |
switch (_dataType) |
{ | { |
const Array<ArraySint8>& a = _instancesData; |
case RESP_INSTNAMES: |
const Array<ArraySint8>& b = _referencesData; |
|
|
|
for (Uint32 i = 0, n = a.size(); i < n; i++) |
|
{ | { |
out << STRLIT("<VALUE.NAMEDINSTANCE>\n"); |
break; |
out.append((char*)b[i].getData(), b[i].size() - 1); |
|
out.append((char*)a[i].getData(), a[i].size() - 1); |
|
out << STRLIT("</VALUE.NAMEDINSTANCE>\n"); |
|
} | } |
|
case RESP_INSTANCE: |
|
{ |
|
break; |
} | } |
else |
case RESP_INSTANCES: |
{ | { |
_resolve(); |
break; |
for (Uint32 i = 0, n = _namedInstances.size(); i < n; i++) |
|
XmlWriter::appendValueNamedInstanceElement( |
|
out, _namedInstances[i]); |
|
} | } |
PEG_METHOD_EXIT(); |
case RESP_OBJECTS: |
|
{ |
|
break; |
} | } |
|
case RESP_OBJECTPATHS: |
//------------------------------------------------------------------------------ |
|
// Instantiates an array of CIMInstances from a binary representation created by |
|
// the CIMBinMessageSerializer. |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMInstancesResponseData::_resolveBinaryInstances( |
|
CIMInstancesResponseData* data, |
|
Array<CIMInstance>& instances) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
break; |
"CIMInstancesResponseData::_resolveBinaryInstances"); |
} |
|
default: |
|
{ |
|
PEGASUS_DEBUG_ASSERT(false); |
|
} |
|
} |
|
} |
| |
instances.clear(); |
void CIMResponseData::_resolveXmlToCIM() |
|
{ |
|
switch (_dataType) |
|
{ |
|
// same encoding for instance names and object paths |
|
case RESP_OBJECTPATHS: |
|
case RESP_INSTNAMES: |
|
{ |
|
for (Uint32 i = 0; i < _referencesData.size(); i++) |
|
{ |
|
CIMObjectPath cop; |
|
// Deserialize path: |
|
{ |
|
XmlParser parser((char*)_referencesData[i].getData()); |
| |
CIMBuffer in((char*)data->_binaryData.getData(), data->_binaryData.size()); |
if (XmlReader::getInstanceNameElement(parser, cop)) |
|
{ |
|
if (!_nameSpacesData[i].isNull()) |
|
cop.setNameSpace(_nameSpacesData[i]); |
| |
while (in.more()) |
if (_hostsData[i].size()) |
|
cop.setHost(_hostsData[i]); |
|
} |
|
} |
|
_instanceNames.append(cop); |
|
} |
|
break; |
|
} |
|
case RESP_INSTANCE: |
{ | { |
if (!in.getInstanceA(instances)) |
CIMInstance cimInstance; |
|
// Deserialize instance: |
{ | { |
in.release(); |
XmlParser parser((char*)_instanceData[0].getData()); |
|
|
|
if (!XmlReader::getInstanceElement(parser, cimInstance)) |
|
{ |
|
cimInstance = CIMInstance(); |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, | PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
"Failed to remove binary instance!"); |
"Failed to resolve XML instance, parser error!"); |
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
} | } |
|
// Deserialize path: |
|
{ |
|
XmlParser parser((char*)_referencesData[0].getData()); |
|
CIMObjectPath cimObjectPath; |
| |
in.release(); |
if (XmlReader::getValueReferenceElement(parser, cimObjectPath)) |
PEG_METHOD_EXIT(); |
{ |
return true; |
if (_hostsData.size()) |
|
{ |
|
cimObjectPath.setHost(_hostsData[0]); |
} | } |
|
if (!_nameSpacesData[0].isNull()) |
|
|
|
|
//------------------------------------------------------------------------------ |
|
// Instantiates an array of CIMInstances from an xml representation created by |
|
// the CIMBinMessageSerializer. |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMInstancesResponseData::_resolveXMLInstances( |
|
CIMInstancesResponseData* data, |
|
Array<CIMInstance>& instances) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
cimObjectPath.setNameSpace(_nameSpacesData[0]); |
"CIMInstancesResponseData::_resolveXMLInstances"); |
} |
|
cimInstance.setPath(cimObjectPath); |
instances.clear(); |
// only if everything works we add the CIMInstance to the |
|
// array |
for (Uint32 i = 0; i < data->_instancesData.size(); i++) |
_instances.append(cimInstance); |
|
} |
|
} |
|
break; |
|
} |
|
case RESP_INSTANCES: |
|
{ |
|
for (Uint32 i = 0; i < _instanceData.size(); i++) |
{ | { |
CIMInstance cimInstance; | CIMInstance cimInstance; |
|
|
// Deserialize instance: | // Deserialize instance: |
{ | { |
XmlParser parser((char*)data->_instancesData[i].getData()); |
XmlParser parser((char*)_instanceData[i].getData()); |
| |
if (!XmlReader::getInstanceElement(parser, cimInstance)) | if (!XmlReader::getInstanceElement(parser, cimInstance)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, | PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
"Failed to resolve XML instance. Creating empty instance!"); |
"Failed to resolve XML instance." |
|
" Creating empty instance!"); |
cimInstance = CIMInstance(); | cimInstance = CIMInstance(); |
} | } |
} | } |
| |
// Deserialize path: | // Deserialize path: |
{ | { |
XmlParser parser((char*)data->_referencesData[i].getData()); |
XmlParser parser((char*)_referencesData[i].getData()); |
CIMObjectPath cimObjectPath; | CIMObjectPath cimObjectPath; |
| |
if (XmlReader::getInstanceNameElement(parser, cimObjectPath)) | if (XmlReader::getInstanceNameElement(parser, cimObjectPath)) |
{ | { |
if (!data->_nameSpacesData[i].isNull()) |
if (!_nameSpacesData[i].isNull()) |
cimObjectPath.setNameSpace(data->_nameSpacesData[i]); |
cimObjectPath.setNameSpace(_nameSpacesData[i]); |
| |
if (data->_hostsData[i].size()) |
if (_hostsData[i].size()) |
cimObjectPath.setHost(data->_hostsData[i]); |
cimObjectPath.setHost(_hostsData[i]); |
| |
cimInstance.setPath(cimObjectPath); | cimInstance.setPath(cimObjectPath); |
} | } |
} | } |
| |
instances.append(cimInstance); |
_instances.append(cimInstance); |
} | } |
|
break; |
PEG_METHOD_EXIT(); |
|
return true; |
|
} | } |
|
case RESP_OBJECTS: |
//------------------------------------------------------------------------------ |
|
// Instantiates an array of CIMInstances from an array of SCMOInstances |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMInstancesResponseData::_resolveSCMOInstances( |
|
CIMInstancesResponseData* data, |
|
Array<CIMInstance>& instances) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
for (Uint32 i=0, n=_instanceData.size(); i<n; i++) |
"CIMInstancesResponseData::_resolveSCMOInstances"); |
{ |
|
CIMObject cimObject; |
| |
instances.clear(); |
// Deserialize Objects: |
|
{ |
|
XmlParser parser((char*)_instanceData[i].getData()); |
| |
//--rk-->TBD: Do the actual coding here |
CIMInstance cimInstance; |
|
CIMClass cimClass; |
| |
fprintf(stderr,"CIMInstancesResponseData::_resolveSCMOInstances() " |
if (XmlReader::getInstanceElement(parser, cimInstance)) |
"Poorly implemented!!!\n"); |
|
try |
|
{ |
|
for (Uint32 x=0; x < data->_scmoInstances.size(); x++) |
|
{ |
|
/*SCMODump dmp; |
|
dmp.dumpSCMOInstanceKeyBindings(data->_scmoInstances[x]); |
|
dmp.dumpInstanceProperties(data->_scmoInstances[x]);*/ |
|
CIMInstance newInstance; |
|
data->_scmoInstances[x].getCIMInstance(newInstance); |
|
instances.append(newInstance); |
|
} |
|
} |
|
catch (CIMException& ex) |
|
{ |
|
fprintf(stderr,"CIMInstancesResponseData::_resolveSCMOInstances() " |
|
"Exception:\n%s\n",(const char*)ex.getMessage().getCString()); |
|
} |
|
catch (Exception& ex) |
|
{ | { |
fprintf(stderr,"CIMInstancesResponseData::_resolveSCMOInstances() " |
cimObject = CIMObject(cimInstance); |
"Exception:\n%s\n",(const char*)ex.getMessage().getCString()); |
|
} | } |
catch (exception& ex) |
else if (XmlReader::getClassElement(parser, cimClass)) |
{ | { |
fprintf(stderr,"CIMInstancesResponseData::_resolveSCMOInstances() " |
cimObject = CIMObject(cimClass); |
"exception:\n%s\n",(const char*)ex.what()); |
|
} | } |
catch (...) |
else |
{ | { |
fprintf(stderr,"CIMInstancesResponseData::_resolveSCMOInstances() " |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
"Exception: UNKNOWN\n"); |
"Failed to get XML object data!"); |
} | } |
data->_resolveCallback = 0; |
|
|
|
PEG_METHOD_EXIT(); |
|
return true; |
|
} | } |
| |
|
// Deserialize paths: |
//----------------------------------------------------------------------------- |
|
// |
|
// CIMObjectsResponseData |
|
// |
|
//----------------------------------------------------------------------------- |
|
|
|
|
|
//------------------------------------------------------------------------------ |
|
// Takes a binary stream of objects from a CIMBuffer and stores |
|
// it in the responsedata. |
|
// @param hasLen Indicates if the binary object stream is prepended with an |
|
// Uint32 value indicating the number of objects in the stream. |
|
//------------------------------------------------------------------------------ |
|
bool CIMObjectsResponseData::setBinaryCimObjects(CIMBuffer& in, bool hasLen) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
XmlParser parser((char*)_referencesData[i].getData()); |
"CIMObjectsResponseData::setBinaryCimObjects"); |
CIMObjectPath cimObjectPath; |
| |
if (hasLen) |
if (XmlReader::getValueReferenceElement( |
{ |
parser, |
if (!in.getUint8A(_binaryData)) |
cimObjectPath)) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
if (!_nameSpacesData[i].isNull()) |
"Failed to get binary object data!"); |
cimObjectPath.setNameSpace(_nameSpacesData[i]); |
PEG_METHOD_EXIT(); |
|
return false; |
if (_hostsData[i].size()) |
|
cimObjectPath.setHost(_hostsData[i]); |
|
|
|
cimObject.setPath(cimObjectPath); |
} | } |
} | } |
else |
_objects.append(cimObject); |
|
} |
|
break; |
|
} |
|
default: |
{ | { |
size_t remainingDataLength = in.capacity() - in.size(); |
PEGASUS_DEBUG_ASSERT(false); |
_binaryData.append((Uint8*)in.getPtr(), remainingDataLength); |
} |
|
} |
|
// Xml was resolved, release Xml content now |
|
_referencesData.clear(); |
|
_hostsData.clear(); |
|
_nameSpacesData.clear(); |
|
_instanceData.clear(); |
|
// remove Xml Encoding flag |
|
_encoding &=(~RESP_ENC_XML); |
|
// add CIM Encoding flag |
|
_encoding |=RESP_ENC_CIM; |
} | } |
| |
_resolveCallback = _resolveBinaryObjects; |
void CIMResponseData::_resolveXmlToSCMO() |
_binaryEncoding = true; |
|
|
|
PEG_METHOD_EXIT(); |
|
return true; |
|
}; |
|
|
|
bool CIMObjectsResponseData::setXmlCimObjects(CIMBuffer& in) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
// Not optimal, can probably be improved |
"CIMObjectsResponseData::setXmlCimObjects"); |
// but on the other hand, since using the binary format this case should |
|
// actually not ever happen. |
Uint32 count; |
_resolveXmlToCIM(); |
|
_resolveCIMToSCMO(); |
|
} |
| |
if (!in.getUint32(count)) |
void CIMResponseData::_resolveSCMOToCIM() |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
switch(_dataType) |
"Failed to get XML object data (number of objects)!"); |
{ |
PEG_METHOD_EXIT(); |
case RESP_INSTNAMES: |
return false; |
case RESP_OBJECTPATHS: |
|
{ |
|
for (Uint32 x=0, n=_scmoInstances.size(); x < n; x++) |
|
{ |
|
CIMObjectPath newObjectPath; |
|
_scmoInstances[x].getCIMObjectPath(newObjectPath); |
|
_instanceNames.append(newObjectPath); |
} | } |
|
break; |
for (Uint32 i = 0; i < count; i++) |
} |
|
case RESP_INSTANCE: |
{ | { |
Array<Sint8> obj; |
if (_scmoInstances.size() > 0) |
Array<Sint8> ref; |
|
CIMNamespaceName ns; |
|
String host; |
|
|
|
if (!in.getSint8A(obj)) |
|
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
CIMInstance newInstance; |
"Failed to get XML object data (object)!"); |
_scmoInstances[0].getCIMInstance(newInstance); |
PEG_METHOD_EXIT(); |
_instances.append(newInstance); |
return false; |
|
} | } |
|
break; |
if (!in.getSint8A(ref)) |
} |
|
case RESP_INSTANCES: |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
for (Uint32 x=0, n=_scmoInstances.size(); x < n; x++) |
"Failed to get XML object data (reference)!"); |
{ |
PEG_METHOD_EXIT(); |
CIMInstance newInstance; |
return false; |
_scmoInstances[x].getCIMInstance(newInstance); |
|
_instances.append(newInstance); |
} | } |
|
break; |
if (!in.getString(host)) |
} |
|
case RESP_OBJECTS: |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
for (Uint32 x=0, n=_scmoInstances.size(); x < n; x++) |
"Failed to get XML object data (host)!"); |
{ |
PEG_METHOD_EXIT(); |
CIMInstance newInstance; |
return false; |
_scmoInstances[x].getCIMInstance(newInstance); |
|
_objects.append(CIMObject(newInstance)); |
} | } |
|
break; |
if (!in.getNamespaceName(ns)) |
} |
|
default: |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
PEGASUS_DEBUG_ASSERT(false); |
"Failed to get XML object data (namespace)!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
|
|
_cimObjectsData.append(obj); |
|
_referencesData.append(ref); |
|
_hostsData.append(host); |
|
_nameSpacesData.append(ns); |
|
} | } |
|
_scmoInstances.clear(); |
_resolveCallback = _resolveXMLObjects; |
// remove CIM Encoding flag |
_binaryEncoding = false; |
_encoding &=(~RESP_ENC_SCMO); |
|
// add SCMO Encoding flag |
PEG_METHOD_EXIT(); |
_encoding |=RESP_ENC_CIM; |
return true; |
|
} | } |
| |
//------------------------------------------------------------------------------ |
void CIMResponseData::_resolveCIMToSCMO() |
// Encodes the array of CIMObject representation contained in the current |
|
// CIMResponseData object in binary response message format. |
|
// This code corresponds to method _resolveBinaryObjects, which is used |
|
// revert a binary object array representation back into an array of |
|
// CIMObject. |
|
//------------------------------------------------------------------------------ |
|
void CIMObjectsResponseData::encodeBinaryResponse(CIMBuffer& out) const |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
switch (_dataType) |
"CIMObjectsResponseData::encodeBinaryResponse"); |
|
|
|
if (_resolveCallback && _binaryEncoding) |
|
{ | { |
const Array<Uint8>& data = _binaryData; |
case RESP_INSTNAMES: |
out.putBytes(data.getData(), data.size()); |
|
} |
|
else |
|
{ | { |
out.putObjectA(_cimObjects); |
for (Uint32 i=0,n=_instanceNames.size();i<n;i++) |
|
{ |
|
SCMOInstance addme = |
|
_getSCMOFromCIMObjectPath(_instanceNames[i]); |
|
_scmoInstances.append(addme); |
} | } |
PEG_METHOD_EXIT(); |
_instanceNames.clear(); |
|
break; |
} | } |
|
case RESP_INSTANCE: |
//------------------------------------------------------------------------------ |
|
// Encodes the array of CIMObject representation contained in the current |
|
// CIMResponseData object in xml response message format. |
|
// This code corresponds to method _resolveXmlObjects, which is used |
|
// revert a CIM-XML object array representation back into an array of |
|
// CIMObject. |
|
//------------------------------------------------------------------------------ |
|
void CIMObjectsResponseData::encodeXmlResponse(Buffer& out) const |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
if (_instances.size() > 0) |
"CIMObjectsResponseData::encodeXmlResponse"); |
|
|
|
if (_resolveCallback && !_binaryEncoding) |
|
{ | { |
const Array<ArraySint8>& a = _cimObjectsData; |
SCMOInstance addme = |
const Array<ArraySint8>& b = _referencesData; |
_getSCMOFromCIMInstance(_instances[0]); |
|
_scmoInstances.append(addme); |
for (Uint32 i = 0, n = a.size(); i < n; i++) |
_instances.clear(); |
{ |
|
out << STRLIT("<VALUE.OBJECTWITHPATH>\n"); |
|
out.append((char*)b[i].getData(), b[i].size() - 1); |
|
out.append((char*)a[i].getData(), a[i].size() - 1); |
|
out << STRLIT("</VALUE.OBJECTWITHPATH>\n"); |
|
} | } |
|
break; |
} | } |
else |
case RESP_INSTANCES: |
{ | { |
for (Uint32 i = 0; i < _cimObjects.size(); i++) |
for (Uint32 i=0,n=_instances.size();i<n;i++) |
{ | { |
XmlWriter::appendValueObjectWithPathElement(out, _cimObjects[i]); |
SCMOInstance addme = _getSCMOFromCIMInstance(_instances[i]); |
|
_scmoInstances.append(addme); |
} | } |
|
_instances.clear(); |
|
break; |
} | } |
PEG_METHOD_EXIT(); |
case RESP_OBJECTS: |
|
{ |
|
for (Uint32 i=0,n=_objects.size();i<n;i++) |
|
{ |
|
SCMOInstance addme= _getSCMOFromCIMObject(_objects[i]); |
|
_scmoInstances.append(addme); |
} | } |
|
_objects.clear(); |
//------------------------------------------------------------------------------ |
break; |
// Instantiates an array of CIMObjects from a binary representation created by |
} |
// the CIMBinMessageSerializer. |
case RESP_OBJECTPATHS: |
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMObjectsResponseData::_resolveBinaryObjects( |
|
CIMObjectsResponseData* data, |
|
Array<CIMObject>& cimObjects) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
for (Uint32 i=0,n=_instanceNames.size();i<n;i++) |
"CIMObjectsResponseData::_resolveBinaryObjects"); |
|
|
|
cimObjects.clear(); |
|
|
|
CIMBuffer in((char*)data->_binaryData.getData(), data->_binaryData.size()); |
|
|
|
while (in.more()) |
|
{ | { |
if (!in.getObjectA(cimObjects)) |
SCMOInstance addme = |
|
_getSCMOFromCIMObjectPath(_instanceNames[i]); |
|
if (0 == _instanceNames[i].getKeyBindings().size()) |
{ | { |
in.release(); |
// if there is no keybinding, this is a class |
|
addme.setIsClassOnly(true); |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Failed to resolve binary data!"); |
|
PEG_METHOD_EXIT(); |
|
return false; |
|
} | } |
|
_scmoInstances.append(addme); |
} | } |
|
_instanceNames.clear(); |
in.release(); |
break; |
PEG_METHOD_EXIT(); |
|
return true; |
|
} | } |
|
default: |
//------------------------------------------------------------------------------ |
|
// Instantiates an array of CIMObjects from an xml representation created by |
|
// the CIMBinMessageSerializer. |
|
// Returns true on success. |
|
//------------------------------------------------------------------------------ |
|
Boolean CIMObjectsResponseData::_resolveXMLObjects( |
|
CIMObjectsResponseData* data, |
|
Array<CIMObject>& cimObjects) |
|
{ | { |
PEG_METHOD_ENTER(TRC_DISPATCHER, |
PEGASUS_DEBUG_ASSERT(false); |
"CIMObjectsResponseData::_resolveXMLObjects"); |
} |
|
} |
| |
cimObjects.clear(); |
// remove CIM Encoding flag |
|
_encoding &=(~RESP_ENC_CIM); |
|
// add SCMO Encoding flag |
|
_encoding |=RESP_ENC_SCMO; |
|
} |
| |
for (Uint32 i=0, n=data->_cimObjectsData.size(); i<n; i++) |
|
{ |
|
CIMObject cimObject; |
|
| |
// Deserialize Objects: |
// Function to convert a CIMInstance into an SCMOInstance |
|
SCMOInstance CIMResponseData::_getSCMOFromCIMInstance( |
|
const CIMInstance& cimInst) |
{ | { |
XmlParser parser((char*)data->_cimObjectsData[i].getData()); |
bool isDirty=false; |
|
const CIMObjectPath& cimPath = cimInst.getPath(); |
| |
CIMInstance cimInstance; |
const CString nameSpace = cimPath.getNameSpace().getString().getCString(); |
CIMClass cimClass; |
const CString className = cimPath.getClassName().getString().getCString(); |
| |
if (XmlReader::getInstanceElement(parser, cimInstance)) |
SCMOClass * scmoClass = _getSCMOClass( |
|
(const char*)nameSpace, |
|
(const char*)className); |
|
// if class cannot be found we get 0 back from class cache |
|
if (0 == scmoClass) |
{ | { |
cimObject = CIMObject(cimInstance); |
PEG_TRACE((TRC_XML, Tracer::LEVEL2, |
|
"In _getSCMOFromCIMInstance() could not resolve class for " |
|
"nameSpace=\"%s\", className=\"%s\"\n", |
|
(const char*) nameSpace, |
|
(const char*) className)); |
|
|
|
isDirty=true; |
|
scmoClass = new SCMOClass("",""); |
} | } |
else if (XmlReader::getClassElement(parser, cimClass)) |
SCMOInstance scmoInst = SCMOInstance(*scmoClass, cimInst); |
|
|
|
if (isDirty) |
{ | { |
cimObject = CIMObject(cimClass); |
scmoInst.markAsCompromised(); |
} | } |
else |
return scmoInst; |
|
} |
|
|
|
SCMOInstance CIMResponseData::_getSCMOFromCIMObject( |
|
const CIMObject& cimObj) |
{ | { |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
if (cimObj.isClass()) |
"Failed to get XML object data!"); |
{ |
|
CIMClass retClass(cimObj); |
|
SCMOInstance theInstance(retClass); |
|
theInstance.setIsClassOnly(true); |
|
return theInstance; |
} | } |
|
return _getSCMOFromCIMInstance(CIMInstance(cimObj)); |
} | } |
| |
// Deserialize paths: |
// Function to convert a CIMObjectPath into an SCMOInstance |
|
SCMOInstance CIMResponseData::_getSCMOFromCIMObjectPath( |
|
const CIMObjectPath& cimPath) |
{ | { |
XmlParser parser((char*)data->_referencesData[i].getData()); |
bool isDirty=false; |
CIMObjectPath cimObjectPath; |
CString nameSpace = cimPath.getNameSpace().getString().getCString(); |
|
CString className = cimPath.getClassName().getString().getCString(); |
| |
if (XmlReader::getValueReferenceElement(parser, cimObjectPath)) |
SCMOClass * scmoClass = _getSCMOClass( |
{ |
(const char*)nameSpace, |
if (!data->_nameSpacesData[i].isNull()) |
(const char*)className); |
cimObjectPath.setNameSpace(data->_nameSpacesData[i]); |
|
| |
if (data->_hostsData[i].size()) |
// if class cannot be found we get 0 back from class cache |
cimObjectPath.setHost(data->_hostsData[i]); |
if (0 == scmoClass) |
|
{ |
|
PEG_TRACE((TRC_XML, Tracer::LEVEL2, |
|
"In _getSCMOFromCIMObjectPath() could not resolve class for " |
|
"nameSpace=\"%s\", className=\"%s\"\n", |
|
(const char*) nameSpace, |
|
(const char*) className)); |
| |
cimObject.setPath(cimObjectPath); |
isDirty=true; |
|
scmoClass = new SCMOClass("",""); |
} | } |
|
SCMOInstance scmoRef = SCMOInstance(*scmoClass, cimPath); |
|
if (isDirty) |
|
{ |
|
scmoRef.markAsCompromised(); |
} | } |
|
return scmoRef; |
cimObjects.append(cimObject); |
|
} | } |
| |
PEG_METHOD_EXIT(); |
SCMOClass* CIMResponseData::_getSCMOClass( |
return true; |
const char* nameSpace, |
|
const char* cls) |
|
{ |
|
SCMOClassCache* local = SCMOClassCache::getInstance(); |
|
return local->getSCMOClass( |
|
nameSpace, |
|
strlen(nameSpace), |
|
cls, |
|
strlen(cls)); |
} | } |
| |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |