summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkarl <karl>2004-08-16 16:52:38 +0000
committerkarl <karl>2004-08-16 16:52:38 +0000
commit36f076c937eb48982b723e4bb0baaef6a8d05de1 (patch)
tree52246aa74eb4a88ab477797b0b052b3e8594b1a6
parent6c75fc90a2745a93c6ab4c13f6676c13f5f6443f (diff)
downloadtog-pegasus-LIFECYCLE_PEP172-branch.zip
tog-pegasus-LIFECYCLE_PEP172-branch.tar.gz
tog-pegasus-LIFECYCLE_PEP172-branch.tar.xz
TITLE: Embedded Object Encoding. DESCRIPTION: Update to reflect &quote escape character processing.
-rw-r--r--src/Pegasus/Common/CIMEmbeddedObject.cpp89
-rw-r--r--src/Pegasus/Common/tests/EmbeddedObject/EmbeddedObject.cpp77
-rw-r--r--src/Pegasus/Common/tests/Makefile2
3 files changed, 161 insertions, 7 deletions
diff --git a/src/Pegasus/Common/CIMEmbeddedObject.cpp b/src/Pegasus/Common/CIMEmbeddedObject.cpp
index 36b42b3..da71dfe 100644
--- a/src/Pegasus/Common/CIMEmbeddedObject.cpp
+++ b/src/Pegasus/Common/CIMEmbeddedObject.cpp
@@ -42,14 +42,47 @@
PEGASUS_USING_STD;
PEGASUS_NAMESPACE_BEGIN
+Boolean _transformString(const String& input, String& output, const String& from, const String& to)
+{
+ String work = input;
+ Uint32 index;
+
+ // No replacements necessary. Return false
+ if(work.find(from) == PEG_NOT_FOUND)
+ return false;
+ // Replace any instances of from with to
+ while ((index = work.find(from)) != PEG_NOT_FOUND)
+ {
+ output.append(work.subString(0, index));
+ output.append(to);
+ work.remove(0, (index + from.size()));
+ }
+ output.append(work);
+ return(true);
+}
CIMInstance CIMEmbeddedObject::decodeEmbeddedObject(const String& xmlStr)
{
CIMInstance inst;
- CString content(xmlStr.getCString());
+
+ // Map any escaped quote characters since we have a differnece
+ // between the platforms on the concept of escaping the quote
+ // character.
+ String tmp;
+ if (_transformString(xmlStr, tmp, "\\&quot;", "\""));
+
+ else if(_transformString(xmlStr, tmp, "\\\"", "\""));
+
+ else
+ tmp = xmlStr;
+
+ CString content(tmp.getCString());
+ // decode the required characters
+ //cout << "Content Before parser " << content << endl;
XmlParser parser((char*)(const char*)content);
- // Decode the Instance. Note that a false
+ //parser._substituteReferences((char*)(const char*)content);
+ // Decode the Instance. False
// return indicates that there was no instance
// decoded.
if (!XmlReader::getInstanceElement(parser, inst))
@@ -61,12 +94,12 @@ CIMInstance CIMEmbeddedObject::decodeEmbeddedObject(const String& xmlStr)
String CIMEmbeddedObject::encodeToEmbeddedObject (const CIMInstance& instance)
{
- static const String _lt("&lt;");
+ /* static const String _lt("&lt;");
static const String _gt("&gt;");
static const String _amp("&amp;");
static const String _quot("&quot;");
static const String _apos("&apos;");
- static const String _num("&#");
+ static const String _num("&#"); */
Array<Sint8> tmp;
XmlWriter::appendInstanceElement(tmp,instance);
@@ -74,4 +107,52 @@ String CIMEmbeddedObject::encodeToEmbeddedObject (const CIMInstance& instance)
String rtnStr(tmp.getData());
return(rtnStr);
}
+/****
+struct EntityReference
+{
+ const char* match;
+ Uint32 length;
+ char replacement;
+};
+
+// ATTN: Add support for more entity references
+static EntityReference _references[] =
+{
+ { "&amp;", 5, '&' },
+ { "&lt;", 4, '<' },
+ { "&gt;", 4, '>' },
+ { "&quot;", 6, '"' },
+ { "&apos;", 6, '\'' }
+};
+
+static Uint32 _REFERENCES_SIZE = (sizeof(_references) / sizeof(_references[0]));
+
+String CIMEmbeddedObject::unquote(const String& input)
+{
+ String return;
+
+ // Check for entity reference
+ // ATTN: Inefficient if many entity references are supported
+ Uint32 i;
+ for (i = 0; i < _REFERENCES_SIZE; i++)
+ {
+ Uint32 length = _references[i].length;
+ const char* match = _references[i].match;
+
+ if (strncmp(p, _references[i].match, length) == 0)
+ {
+ referenceChar = _references[i].replacement;
+ referenceLength = length;
+ break;
+ }
+ }
+
+ if (i == _REFERENCES_SIZE)
+ {
+ // Didn't recognize the entity reference
+ // ATTN: Is there a good way to say "unsupported"?
+ throw XmlException(code, _line);
+ }
+}
+*/
PEGASUS_NAMESPACE_END
diff --git a/src/Pegasus/Common/tests/EmbeddedObject/EmbeddedObject.cpp b/src/Pegasus/Common/tests/EmbeddedObject/EmbeddedObject.cpp
index 4590907..321a711 100644
--- a/src/Pegasus/Common/tests/EmbeddedObject/EmbeddedObject.cpp
+++ b/src/Pegasus/Common/tests/EmbeddedObject/EmbeddedObject.cpp
@@ -57,7 +57,6 @@ int main(int argc, char** argv)
{
verbose = getenv("PEGASUS_TEST_VERBOSE");
-
// Create a repository context in which to test the creation and
// decode functions.
const CIMNamespaceName NAMESPACE = CIMNamespaceName ("/root/test");
@@ -243,15 +242,89 @@ int main(int argc, char** argv)
XmlWriter::printInstanceElement(instance1);
}
+ assert(instance1.identical(instance));
+
+ // Test 3 - Embedded object with quote mark in a string value.
+
+ if (verbose)
+ {
+ cout << "Test with quote embedded in string." << endl;
+ }
+
+ // replace property in message property with one with quote.
+ String test="Single double Quote Mark \" . Single left carot <, Single right carot >, Single single-quote \'";
+ if (verbose)
+ {
+ cout << "Test String " << test << endl;
+ }
+
+ Uint32 pos;
+ pos = instance.findProperty(CIMName("message"));
+ assert(pos != PEG_NOT_FOUND);
+ instance.removeProperty(pos);
+
+ instance.addProperty(CIMProperty(CIMName ("message"), test));
+
+ testEmbeddedObject =
+ CIMEmbeddedObject::encodeToEmbeddedObject(instance);
+
+ if(verbose)
+ {
+ cout << "String of Embedded Instance: " << testEmbeddedObject << endl;
+ }
+
+ cout << "Decode the encoded object" << endl;
+ instance1 = CIMEmbeddedObject::decodeEmbeddedObject(testEmbeddedObject);
+
+ if(verbose)
+ {
+ cout << "return from decode with instance recreated:" << endl;
+ XmlWriter::printInstanceElement(instance1);
+ }
assert(instance1.identical(instance));
+
+ //Test 4 - String form
+ //cout << "Test 4" << endl;
+
+ String test4 = "<INSTANCE CLASSNAME=\"Test_Karl\"><PROPERTY NAME=\"k\" TYPE=\"string\"><QUALIFIER OVERRIDABLE=\"false\" NAME=\"key\" TYPE=\"boolean\"><VALUE>true</VALUE></QUALIFIER><VALUE>Filterwsindicationtest1089760576</VALUE></PROPERTY><PROPERTY PROPAGATED=\"true\" NAME=\"s\" TYPE=\"string\"></PROPERTY></INSTANCE></VALUE>";
+ if(verbose)
+ {
+ cout << "Test 4 String= " << test4 << endl;
+ }
+
+ instance1 = CIMEmbeddedObject::decodeEmbeddedObject(test4);
+
+ //Test 4a - replacement of \" with "
+ //cout << "Test 4a" << endl;
+
+ String test4a = "<INSTANCE CLASSNAME=\\\"Test_Karl\\\"><PROPERTY NAME=\\\"k\\\" TYPE=\\\"string\\\"><QUALIFIER OVERRIDABLE=\\\"false\\\" NAME=\\\"key\\\" TYPE=\\\"boolean\\\"><VALUE>true</VALUE></QUALIFIER><VALUE>Filterwsindicationtest1089760576</VALUE></PROPERTY><PROPERTY PROPAGATED=\\\"true\\\" NAME=\\\"s\\\" TYPE=\\\"string\\\"></PROPERTY></INSTANCE></VALUE>";
+
+ if(verbose)
+ {
+ cout << "Test 4a String= " << test4a << endl;
+ }
+
+ instance1 = CIMEmbeddedObject::decodeEmbeddedObject(test4a);
+
+ //Test 4b - Replacement of &quote; with "
+
+ String test4b = "<INSTANCE CLASSNAME=\\&quot;Test_Karl\\&quot;><PROPERTY NAME=\\&quot;k\\&quot; TYPE=\\&quot;string\\&quot;><QUALIFIER OVERRIDABLE=\\&quot;false\\&quot; NAME=\\&quot;key\\&quot; TYPE=\\&quot;boolean\\&quot;><VALUE>true</VALUE></QUALIFIER><VALUE>Filterwsindicationtest1089760576</VALUE></PROPERTY><PROPERTY PROPAGATED=\\&quot;true\\&quot; NAME=\\&quot;s\\&quot; TYPE=\\&quot;string\\&quot;></PROPERTY></INSTANCE></VALUE>";
+
+ if(verbose)
+ {
+ cout << "Test 4b String= " << test4b << endl;
+ }
+
+ instance1 = CIMEmbeddedObject::decodeEmbeddedObject(test4b);
+
}
// Catch all exceptions.
catch (Exception& e)
{
- cout << "Exception: " << e.getMessage() << endl;
+ cout << "Exception: " << e.getMessage() << endl;
exit(1);
}
cout << argv[0] << " +++++ passed all tests" << endl;
diff --git a/src/Pegasus/Common/tests/Makefile b/src/Pegasus/Common/tests/Makefile
index 6daa1a8..7be2f66 100644
--- a/src/Pegasus/Common/tests/Makefile
+++ b/src/Pegasus/Common/tests/Makefile
@@ -46,7 +46,7 @@ DIRS = \
DynLoad \
DynamicLibrary \
Logger \
- EmbeddedObject \
+ EmbeddedObject \
WebClient \
ParamValue \
L10N \