From e0fcde8d1add582300e12e9a6fa7b381918d1f4d Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 25 Apr 2001 20:43:31 +0000 Subject: [PATCH] better --- src/Pegasus/Common/CIMReference.cpp | 181 ++++++++++++++++++++++++++-- src/Pegasus/Common/CIMReference.h | 14 ++- src/Pegasus/Common/Exception.cpp | 5 +- src/Pegasus/Common/Exception.h | 7 +- 4 files changed, 191 insertions(+), 16 deletions(-) diff --git a/src/Pegasus/Common/CIMReference.cpp b/src/Pegasus/Common/CIMReference.cpp index d7efa7d76..6797ce63c 100644 --- a/src/Pegasus/Common/CIMReference.cpp +++ b/src/Pegasus/Common/CIMReference.cpp @@ -142,6 +142,173 @@ CIMReference::CIMReference(const CIMReference& x) _BubbleSort(_keyBindings); } +CIMReference::CIMReference(const String& objectPath) +{ + //-------------------------------------------------------------------------- + // We will extract components from an object path. Here is an sample + // object path: + // + // //atp:9999/root/cimv25:TennisPlayer.first="Patrick",last="Rafter" + //-------------------------------------------------------------------------- + + // Convert to a C String first: + + char* p = objectPath.allocateCString(); + ArrayDestroyer destroyer(p); + + // See if there is a host name (true if it begins with "//"): + // Host is of the from - and begins with "//" + // and ends with "/": + + if (p[0] == '/' && p[1] == '/') + { + p += 2; + + //---------------------------------------------------------------------- + // Validate the hostname. Hostnames must match the following + // regular expression: "[A-Za-z][A-Za-z0-9-]*" + //---------------------------------------------------------------------- + + char* q = p; + + if (!isalpha(*q)) + throw IllformedObjectPath(objectPath); + + q++; + + while (isalnum(*q) || *q == '-') + q++; + + // We now expect a colon (before the port): + + if (*q != ':') + throw IllformedObjectPath(objectPath); + + q++; + + // Check for a port number: + + if (!isdigit(*q)) + throw IllformedObjectPath(objectPath); + + while (isdigit(*q)) + q++; + + // Check for slash terminating the entire sequence: + + if (*q != '/') + throw IllformedObjectPath(objectPath); + + // Finally, assign the host name: + + _host.assign(p, q - p); + + p = ++q; + } + +OUT(_host); + +#if 0 + // Extract the class name: + + char* dot = strchr(p, '.'); + + if (!dot) + throw IllformedObjectPath(objectPath); + + String className(p, dot - p); + + // Advance past dot: + + p = dot + 1; + + // Get the key-value pairs: + + Array keyBindings; + + for (p = strtok(p, ","); p; p = strtok(NULL, ",")) + { + // Split about the equal sign: + + char* equal = strchr(p, '='); + + if (!equal) + throw IllformedObjectPath(objectPath); + + *equal = '\0'; + + // Get key part: + + String keyString(p); + + if (!CIMName::legal(keyString)) + throw IllformedObjectPath(objectPath); + + // Get the value part: + + String valueString; + char* q = equal + 1; + KeyBinding::CIMType type; + + if (*q == '"') + { + q++; + + type = KeyBinding::STRING; + + while (*q && *q != '"') + { + // ATTN: need to handle special characters here: + + if (*q == '\\') + *q++; + + valueString.append(*q++); + } + + if (*q++ != '"') + throw IllformedObjectPath(objectPath); + + if (*q) + throw IllformedObjectPath(objectPath); + } + else if (toupper(*q) == 'T' || toupper(*q) == 'F') + { + type = KeyBinding::BOOLEAN; + + char* r = q; + + while (*r) + { + *r = toupper(*r); + r++; + } + + if (strcmp(q, "TRUE") != 0 && strcmp(q, "FALSE") != 0) + throw IllformedObjectPath(objectPath); + + valueString.assign(q); + } + else + { + type = KeyBinding::NUMERIC; + + Sint64 x; + + if (!XmlReader::stringToSignedInteger(q, x)) + throw IllformedObjectPath(objectPath); + + valueString.assign(q); + } + + keyBindings.append(KeyBinding(keyString, valueString, type)); + } + + reference.set(String(), String(), className, keyBindings); + +#endif +} + CIMReference::CIMReference( const String& host, const String& nameSpace, @@ -366,7 +533,7 @@ void CIMReference::instanceNameToReference( char* dot = strchr(p, '.'); if (!dot) - throw BadInstanceName(instanceName); + throw IllformedObjectPath(instanceName); String className(p, dot - p); @@ -385,7 +552,7 @@ void CIMReference::instanceNameToReference( char* equal = strchr(p, '='); if (!equal) - throw BadInstanceName(instanceName); + throw IllformedObjectPath(instanceName); *equal = '\0'; @@ -394,7 +561,7 @@ void CIMReference::instanceNameToReference( String keyString(p); if (!CIMName::legal(keyString)) - throw BadInstanceName(instanceName); + throw IllformedObjectPath(instanceName); // Get the value part: @@ -419,10 +586,10 @@ void CIMReference::instanceNameToReference( } if (*q++ != '"') - throw BadInstanceName(instanceName); + throw IllformedObjectPath(instanceName); if (*q) - throw BadInstanceName(instanceName); + throw IllformedObjectPath(instanceName); } else if (toupper(*q) == 'T' || toupper(*q) == 'F') { @@ -437,7 +604,7 @@ void CIMReference::instanceNameToReference( } if (strcmp(q, "TRUE") != 0 && strcmp(q, "FALSE") != 0) - throw BadInstanceName(instanceName); + throw IllformedObjectPath(instanceName); valueString.assign(q); } @@ -448,7 +615,7 @@ void CIMReference::instanceNameToReference( Sint64 x; if (!XmlReader::stringToSignedInteger(q, x)) - throw BadInstanceName(instanceName); + throw IllformedObjectPath(instanceName); valueString.assign(q); } diff --git a/src/Pegasus/Common/CIMReference.h b/src/Pegasus/Common/CIMReference.h index 2f76f35d9..c961db362 100644 --- a/src/Pegasus/Common/CIMReference.h +++ b/src/Pegasus/Common/CIMReference.h @@ -167,7 +167,7 @@ class XmlWriter; called "root/cimv25". Then the namespace-path is given as:
-	//atp-9999/root/cimv25
+	//atp:9999/root/cimv25
 	
As for the model-path mentioned above, its form is defined by the CIM @@ -200,8 +200,7 @@ class XmlWriter; Now the namespace-type and model-path are combined in the following string object name. - //atp-9999/root/cimv25:TennisPlayer.first="Patrick",last="Rafter" - + //atp:9999/root/cimv25:TennisPlayer.first="Patrick",last="Rafter" Now suppose we wish to create a CIMReference from this above string. There are two constructors provided: one which takes the above string and the @@ -224,7 +223,7 @@ class XmlWriter;
 	CIMReference ref = 
-	    "//atp-9999/root/cimv25:TennisPlayer.first="Patrick",last="Rafter";
+	    "//atp:9999/root/cimv25:TennisPlayer.first="Patrick",last="Rafter";
 	
A CIMReference may also be initialized using the constituent elements @@ -234,7 +233,7 @@ class XmlWriter; way:
    -
  • host = "atp-9999"
  • +
  • host = "atp:9999"
  • nameSpace = "root/cimv25"
  • className = "TennisPlayer"
  • keyBindings = "first=\"Patrick\",last=\"Rafter\""
  • @@ -320,7 +319,10 @@ public: /** Copy constructor. */ CIMReference(const CIMReference& x); - /** Constructs a CIM Object Path from the constituent elements. + /** Initializes this object from a CIM object path. */ + CIMReference(const String& objectPath); + + /** Constructs a CIMReference from constituent elements. @param host - name of host (e.g., "nemesis-8888"). @param nameSpace - namespace (e.g., "root/cimv20"). @param className - name of a class (e.g., "MyClass"). diff --git a/src/Pegasus/Common/Exception.cpp b/src/Pegasus/Common/Exception.cpp index 40eec9826..cec174c20 100644 --- a/src/Pegasus/Common/Exception.cpp +++ b/src/Pegasus/Common/Exception.cpp @@ -23,6 +23,9 @@ // Author: // // $Log: Exception.cpp,v $ +// Revision 1.9 2001/04/25 20:43:31 mike +// better +// // Revision 1.8 2001/03/05 04:29:01 mike // renamed CimException to CIMException // @@ -172,7 +175,7 @@ const char IncompatibleTypes::MSG[] = "incompatible types"; const char BadlyFormedCGIQueryString::MSG[] = "badly formed CGI query string"; -const char BadInstanceName::MSG[] = "bad instance name: "; +const char IllformedObjectPath::MSG[] = "illformed object path: "; const char DynamicLoadFailed::MSG[] = "load of dynamic library failed: "; diff --git a/src/Pegasus/Common/Exception.h b/src/Pegasus/Common/Exception.h index 7ba58cc80..adb465d26 100644 --- a/src/Pegasus/Common/Exception.h +++ b/src/Pegasus/Common/Exception.h @@ -23,6 +23,9 @@ // Author: // // $Log: Exception.h,v $ +// Revision 1.10 2001/04/25 20:43:31 mike +// better +// // Revision 1.9 2001/03/05 19:54:49 mike // Fixed earlier boo boo (renamed CimException to CIMException). // @@ -612,13 +615,13 @@ public: BadlyFormedCGIQueryString() : Exception(MSG) { } }; -class PEGASUS_COMMON_LINKAGE BadInstanceName : public Exception +class PEGASUS_COMMON_LINKAGE IllformedObjectPath : public Exception { public: static const char MSG[]; - BadInstanceName(const String& instanceName) + IllformedObjectPath(const String& instanceName) : Exception(MSG + instanceName) { } }; -- 2.34.1