📄 cgiclient.cpp
字号:
// Loop for each property for (Uint32 i = 0, n = object.getPropertyCount(); i < n; i++) { // KSREVIEW: All of this can become PrintProperty() CIMProperty property = object.getProperty(i); const CIMValue& value = property.getValue(); // Define href with the property name //ALAGS : FIX done - call func BuildOperationHref() with correct arguments String href = BuildOperationHref("GetPropertyDeclaration", nameSpace); href.append("ClassName="); href.append(object.getClassName().getString()); href.append("&"); href.append("PropertyName="); href.append(property.getName().getString()); href.append("&"); cout << "<tr>\n"; cout << "<td>"; PrintAHref(href, property.getName().getString()); cout << "</td>"; cout << "<td>" << cimTypeToString (value.getType ()) << "</td>\n"; String valueString = value.toString(); if (valueString.size()) cout << "<td>" << valueString << "</td>\n"; else cout << "<td>null</td>\n"; // Output the ClassOrigin // KSREVIEW: Make this optional cout << "<td>" << property.getClassOrigin() << "</td>\n"; // Output the Propagated field cout << "<td>" << (property.getPropagated() ? "true" : "false"); cout << "</td>\n"; cout << "<tr>\n"; } PrintTableTrailer();}template<class OBJECT>void PrintQualifiers(OBJECT& object){ PrintTableHeader("Qualifiers:"); for (Uint32 i = 0, n = object.getQualifierCount(); i < n; i++) { CIMConstQualifier qualifier = object.getQualifier(i); const CIMValue& value = qualifier.getValue(); PrintRow( qualifier.getName(), cimTypeToString (value.getType ()), value.toString()); } PrintTableTrailer();}/** Prepare an HTML table with a header and an entry for each method defined in the class with the CIMName and type of the CIMMethod in each entry @param cimClass - Class for which methods to be output KSREVIEWKS: this is here temporarily. Should be moved to more common client library so generally available*/void mofFormat( PEGASUS_STD(ostream)& os, const char* text, Uint32 indentChars){ char* var = new char[strlen(text)+1]; char* tmp = strcpy(var, text); //const char* tmp = x.getData(); Uint32 count = 0; Uint32 indent = 0; Boolean quoteState = false; char c; while ((c = *tmp++)) { count++; switch (c) { case '\n': os << Sint8(c); count = 0; indent = 0; break; case '\"': // quote os <<Sint8(c); quoteState = !quoteState; break; case ' ': os <<Sint8(c); if (count > 70) { if (quoteState) os <<"\"\n \""; else os <<"\n "; count = 0 - indent; } break; default: os <<Sint8(c); } } delete [] var;}/** PrintClassMethods - Print a table of the methods for the class*/void PrintClassMethods(CIMClass& cimClass){ // KSREVIEW:If there are no methods. State that rather than empty table cout << "<h2>Methods:</h2>\n"; // Create the table cout << "<table border=1 width=\"50%\">\n"; cout << "<tr>\n"; cout << "<th>CIMName</th>\n"; cout << "<th>CIMType</th>\n"; cout << "</tr>\n"; for (Uint32 i = 0, n = cimClass.getMethodCount(); i < n; i++) { CIMMethod method = cimClass.getMethod(i); CIMType type = method.getType(); cout << "<tr>\n"; cout << "<td>" << method.getName() << "</td>\n"; cout << "<td>" << cimTypeToString (type) << "</td>\n"; cout << "<tr>\n"; } cout << "</table>\n";}/** PrintClass - Print an HTML page with the characteristics of the Class defined in the call including: <UL> <LI>ClassName <LI> SuperClass Name <LI>Qualifiers <LI>Properties <LI>Methods <UL> @param CIMNamespaceName with nameSpace @param pointer to class @param localOnly @param includeQualifiers @param includClassOrigin @param showMof*/void PrintClass( const CIMNamespaceName& nameSpace, CIMClass& cimClass, Boolean localOnly, Boolean includeQualifiers, Boolean includeClassOrigin, Boolean showMof){ //KSREVIEW: Should say GetClass and then classname //Argument for combining to one parm PrintHTMLHead("GetClass", cimClass.getClassName().getString()); //Consider short table of request parameters cout << "\n<B>SuperClass Name: </b>"; if (cimClass.getSuperClassName().isNull()) cout << "No Super Class" <<endl; else { //cout << cimClass.getSuperClassName() << endl; // output the superclass name as an href String href = createGetClassHref(nameSpace, cimClass.getSuperClassName()); // KSREVIEWKS (localOnly)?" ": " "; // KSREVIEWKS (includeQualifiers)? "%IncludeQualifiers=true" : ""; PrintAHref(href, cimClass.getSuperClassName().getString()); //ANNTTNKS 26 Jan 2002 - Add the options params to this call //ALAGS : commented statement below as it is of no use //String hrefenumInstance = // BuildOperationHref("enumerateInstanceNames", nameSpace); } // Output the href so user can get to instance names in one click PrintSpaces(4); //ALAGS : commented Statement below //PrintEnumInstanceNameHref(nameSpace, cimClass.getClassName()); if (includeQualifiers) PrintQualifiers(cimClass); // KSREVIEWKS: Delete this optionelse // cout << "\n\nQualifier Parameters Not Requested" << endl; PrintObjectProperties(nameSpace, cimClass,includeClassOrigin); PrintClassMethods(cimClass); if (showMof) { cout << "<h2>Display MOF for Class " << cimClass.getClassName() << "</h2>"; cout << "<pre>"; Buffer x; MofWriter::appendClassElement(x, cimClass); x.append('\0'); mofFormat(cout, x.getData(), 4); //MofWriter::printClassElement(cimClass); cout << "</pre>"; // Now show the XML for this entity /* note that XML formatting is real mess. Hard to reformat as HTML without cleaning up the XML tags, etc. cout << "\n<h2>XML</h2>\n"; cout << "<pre>"; XmlWriter::printClassElement(cimClass); cout << "</pre>\n"; */ } cout << "</body>\n" << "</html>\n";}/* PrintInstanceBody - Prints the body of an instance withoutthe headers and trailers. Needed because we use both for getInstanceand EnumerateInstance.*/void PrintInstanceBody(const CIMNamespaceName& nameSpace, CIMInstance& cimInstance, Boolean localOnly){ PrintQualifiers(cimInstance); PrintObjectProperties(nameSpace, cimInstance, localOnly);}/** PrintInstance - Print an HTML page with the instance and its properties, etc. of the instance including: <UL> <LI>ClassName <LI>Qualifiers <LI>Properties </UL> Note that methods are at the class level, not the instance level so they do not appear in the Instance page.*/void PrintInstance(const CIMNamespaceName& nameSpace, CIMInstance& cimInstance, Boolean localOnly, Boolean includeQualifiers, Boolean includeClassOrigin){ PrintHTMLHead("GetInstance", cimInstance.getClassName().getString()); PrintInstanceBody(nameSpace, cimInstance,localOnly); //KSREVIEWKS: Add showMof here cout << "<h2>Display MOF for Instance</h2>"; cout << "<pre>"; Buffer x; MofWriter::appendInstanceElement(x, cimInstance); x.append('\0'); mofFormat(cout, x.getData(), 4); cout << "</body>\n" << "</html>\n";}void PrintPropertyDeclaration(CIMProperty& property){ PrintHTMLHead("GetPropertyDeclaration", property.getName().getString()); PrintQualifiers(property); PrintSingleProperty(property); cout << "</body>\n"; cout << "</html>\n";}/*************************************************************************** GetClass Function***************************************************************************//** Function GetClass Peforms the getClass request and prints the result as an HTML page*/void GetClass(const CGIQueryString& qs){ CIMNamespaceName nameSpace = GetNameSpaceQueryField(qs); DDD(cout << "GetClass" << endl;) // Get ClassName: const char* tmp; if (!(tmp = qs.findValue("ClassName"))) ErrorExit("Missing ClassName field"); CIMName className = CIMName (tmp); if (className.isNull()) ErrorExit("ClassName parameter is null"); // Process Checkbox items that become call opptions // Set the Defaults Boolean localOnly = true; Boolean includeQualifiers = true; Boolean includeClassOrigin = false; Boolean showMof = true; // Process possible input fields // Wierd because the form entry only sends info if // if (!(tmp = qs.findValue("LocalOnly"))) localOnly = false; if (!(tmp = qs.findValue("IncludeQualifiers"))) includeQualifiers = false; if ((tmp = qs.findValue("IncludeClassOrigin"))) includeClassOrigin = true; // KSREVIEW: KS - Just delete thisif ((tmp = qs.findValue("ShowMof"))) // showMof = true; CIMClass cimClass; try { CIMClient client; String host; Uint32 portNumber; getHostAndPort (host, portNumber); client.connect (host, portNumber, String::EMPTY, String::EMPTY); cimClass = client.getClass(nameSpace, className, localOnly, includeQualifiers, includeClassOrigin); PrintClass(nameSpace, cimClass,localOnly, includeQualifiers, includeClassOrigin, showMof); } catch(Exception& e) { ErrorExit(e.getMessage()); }}/** Function GetPropertyDeclaration This function is NOT a a WBEM Function. It is used by the Get Class function to get properties for the getClass presentation. This function uses the getClass with the PropertyName parameter to find each property get the property and Print each property.*/void GetPropertyDeclaration(const CGIQueryString& qs){ CIMNamespaceName nameSpace = GetNameSpaceQueryField(qs); // Get ClassName: const char* tmp; if (!(tmp = qs.findValue("ClassName"))) ErrorExit("Missing ClassName field"); CIMName className = CIMName (tmp); if (className.isNull()) ErrorExit("ClassName parameter is null"); // Get PropertyName: if (!(tmp = qs.findValue("PropertyName"))) ErrorExit("Missing ClassName field"); CIMName propertyName = CIMName (tmp); if (propertyName.isNull()) ErrorExit("PropertyName parameter is null"); // try { CIMClient client; String host; Uint32 portNumber; getHostAndPort (host, portNumber); client.connect (host, portNumber, String::EMPTY, String::EMPTY); // get the class CIMClass cimClass = client.getClass( nameSpace, className, false, true, true); // Uint32 pos = cimClass.findProperty(propertyName); if (pos == PEG_NOT_FOUND) { ErrorExit("No such property"); return; } // Now Get the property CIMProperty property = cimClass.getProperty(pos); PrintPropertyDeclaration(property); } catch(Exception& e) { ErrorExit(e.getMessage()); }}/** PrintClassNames - Generates a table with the class names*/void PrintClassNames( const CIMNamespaceName& nameSpace, const Array<CIMName>& classNames, double elapsedTime){ PrintHTMLHead("GetClassNames", "EnumerateClassNames Result"); cout << "<table border=1>\n"; cout << "<tr><th>Class Names</th><tr>\n"; for (Uint32 i = 0, n = classNames.size(); i < n; i++) { cout << "<tr><td>\n"; String href = createGetClassHref(nameSpace, classNames[i]); PrintAHref(href, classNames[i].getString()); cout << " "; // Build href for enumerate instance names PrintEnumInstanceNameHref(nameSpace,classNames[i]); cout << "</tr></td>\n"; } // Close the Table cout << "</table>\n"; // Close the Page cout << "<p>Returned " << classNames.size() << " ClassNames "; cout << " in " << elapsedTime << " Seconds</p>\n"; cout << "</body>\n" << "</html>\n";}/*************************************************************************** EnumerateClassNames Function***************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -