⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cgiclient.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================//// Author: Karl Schopmeyer (k.schopmeyer@opengroup.org)//// Modified By:  Carol Ann Krug Graves, Hewlett-Packard Company//                   (carolann_graves@hp.com)//               Amit K Arora (amita@in.ibm.com) for Bug# 1081 (mofFormat())//               Alagaraja Ramasubramanian (alags_raj@in.ibm.com)//               David Dillard, VERITAS Software Corp.//                   (david.dillard@veritas.com)//               Aruran, IBM (ashanmug@in.ibm.com) for Bug#4295////%//////////////////////////////////////////////////////////////////////////////* CGIClient - This is a CGI driven test program that1. Makes calls to Pegasus CIMOperations client functionsusing paramaters derived from an environment variabledefined using CGI specifications.2. Analyzes the results and prints an HTML pagewith the results for the funtion defined.NOTE: The functions in this program are largelymade up of single CIM Operation functions (ex. getclass)so the parameters for each function match the parametersdefined for the CIM Operation iteslf.This Program was intended to be a test and demonstration tool forPegasus.*/#include <Pegasus/Common/Config.h>#include <Pegasus/Common/AutoPtr.h>#include <Pegasus/Common/PegasusAssert.h>#include <cctype>#include <cstdlib>#include <cstdio>#include <errno.h>#include <Pegasus/Client/CIMClient.h>#include <Pegasus/Common/Stopwatch.h>#include <Pegasus/Common/Logger.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Common/MofWriter.h>#include <Pegasus/Common/CIMMethod.h>#include "CGIQueryString.h"#define PEGASUS_SINT64_MIN (PEGASUS_SINT64_LITERAL(0x8000000000000000))#define PEGASUS_UINT64_MAX PEGASUS_UINT64_LITERAL(0xFFFFFFFFFFFFFFFF)PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;#define DDD(X) X//#define DDD(X) /* X *//*class operationhRef{public:    hRef(const String& operation)    appendPair (const String& key, const String& value    appendKey  (const String& key)    appendValue(const String& value)private:}void operationhRef:appendKey(const String& key){}*//** Class to hold, get, put, etc. the host info.This info must be maintained between calls to CGI clientso is maintained in a configuration file for the client.These are set initially to localhost and 5988.HostInfo is defined as those parameters associated with a particularCIMOM CIMServer and user of that serverKSREVIEW: Under Construction*/class HostInfo{public:    void setHostName(const char* str);    const char* getAddress();private:    char _address[128];};//    sprintf(address, "%s:%d",//      hostinfo.getHostName(), hostinfo.getHostPort());void HostInfo::setHostName( const char* str){  ///KSREVIEW: to be done.}const char* HostInfo::getAddress(){    const char* tmp = getenv("QUERY_STRING");    AutoPtr<char> queryString (strcpy(new char[strlen(tmp) + 1], tmp));    CGIQueryString qs(queryString.get());    if ((tmp = qs.findValue("hostaddress")))    return tmp;    else    return("localhost:5988");}void getHostAndPort (String & host, Uint32 & portNumber){    const char* tmp = getenv ("QUERY_STRING");    AutoPtr<char> queryString (strcpy(new char[strlen(tmp) + 1], tmp));    CGIQueryString qs (queryString.get());    String tmpStr= qs.findValue ("hostaddress");    if (tmpStr.size () > 0)    {        Uint32 index = tmpStr.find (':');        host = tmpStr.subString (0, index);        portNumber = 0;        if (index != PEG_NOT_FOUND)        {            String portStr = tmpStr.subString (index + 1, tmpStr.size ());            sscanf (portStr.getCString (), "%u", &portNumber);        }    }    else    {        host = "localhost";        portNumber = 5988;    }}CIMName PrintSuperClassName(CIMName superClassName){    if (superClassName.isNull ())    return CIMName ("No_Superclass");    else    return superClassName;}void PrintRule(){    cout << "<hr></hr>";}void PrintHead(const String& title){    cout << "<head>\n";    cout << "  <title>" << title << "</title>\n";    cout << "</head>\n";}/** PrintHeader - Print the HTML banner. THis is a table with    the text definition for the page and the TOG logo.    @param - Text for the title*/void PrintHeader(const String& title){    String img = "/pegasus/icons/OpenGroupLogo.gif";    cout << "<table width=\"100%\">\n";    cout << "<tr>\n";    cout << "<td width=\"50%\" align=\"bottom\"><h1>" << title << "</h1><td>\n";    cout << "<td width=\"50%\" align=\"right\">\n";    cout << "<img border=1 src=\"" << img << "\">\n";    cout << "</td>\n";    cout << "</tr>\n";    cout << "</table>\n";}/** PrintHTMLHead - Prints the HTML opening, document title    and the page banner informatio    @param string title - The text for the title field    @param string header - The text for the banner line. This string    identifies the function of the page.*/void PrintHTMLHead(const String& title, const String& header){     cout << "<html>\n";     PrintHead(title);     cout << "<body bgcolor=\"#CCCCCC\">\n";     PrintHeader(header);     PrintRule();}/** ErrorExit - Print out the error message as an    HTML page and get out.    @param - Text for error message    @return - None, Terminates the program    @execption - This function terminates the program*/void ErrorExit(const String& message){    PrintHTMLHead("Message", "Error in CGIClient");    cout << "    <h1>" << "CIM Error" << "</h1>\n";    cout << "    <p><B>" << " Error Message " << "</B></p>\n";    cout << "    <p>" << message << "</p>\n";    //KSREVIEWKS: Define standard ender instead of this special    cout << "  </body>\n";    cout << "</html>\n";    exit(1);}CIMNamespaceName GetNameSpaceQueryField(const CGIQueryString& qs){    const char* tmp;    if (!(tmp = qs.findValue("NameSpace")))    ErrorExit("Missing NameSpace field");    String nameSpace = tmp;    if (!nameSpace.size())    ErrorExit("NameSpace parameter is null");    return CIMNamespaceName (nameSpace);}String EncodeQueryStringValue(const String& x){    String result;    for (Uint32 j = 0, m = x.size(); j < m; j++)    {    //ALAGS : Typecast to avoid compiler warning    char c = (char)x[j];    if (c == '/')        result.append("%2F");    else if  (c == ':')        result.append("%3A");    else        result.append(c);    }    return result;}/** PrintAHref - Prints a single href    @param href - the reference for building the href    @param content - The content of the reference*/void PrintAHref(const String& href, const String& content){    cout << "<a href=\"" << href << "\">\n" << content << "</a>\n";}/* just prints HTML form spaces. Count is number of spaces*/void PrintSpaces(Uint32 count){    for (Uint32 i = 0; i < count; i++)    {        cout << "&nbsp;";    }}void PrintTableHeader(const String& tableName){    cout << "<h2>" << tableName << "</h2>\n";    cout << "<table border=1 width=\"90%\">\n";    cout << "<tr>\n";    cout << "<th>CIMName</th>\n";    cout << "<th>CIMType</th>\n";    cout << "<th>CIMValue</th>\n";    cout << "</tr>\n";}/** Header for the Properties HTML tableColumns in the table are CIMProperty CIMName, type, Vlaue, ClassOrigin,Propogated indicator.*/void PrintPropertiesTableHeader(const String& tableName){    cout << "<h2>" << tableName << "</h2>\n";    cout << "<table border=1 width=\"90%\">\n";    cout << "<tr>\n";    cout << "<th>CIMName</th>\n";    cout << "<th>CIMType</th>\n";    cout << "<th>CIMValue</th>\n";    cout << "<th>ClassOrigin</th>\n";    cout << "<th>Propagated</th>\n";    cout << "</tr>\n";}/** Create an href to call CGIClient with the namespace and    operation field set up.    @return - The result string*///KSREVIEW: Why do we not do the EncodeQueryStringValue//KSREVIEW: Why is host address part of this?String BuildOperationHref(String operation, const CIMNamespaceName & nameSpace){    String result = "/pegasus/cgi-bin/CGIClient?";    result.append("Operation=");    result.append(operation);    result.append("&");    result.append("NameSpace=");    result.append(EncodeQueryStringValue(nameSpace.getString()));    result.append("&");    HostInfo hostinfo;    result.append("hostaddress=");    result.append(EncodeQueryStringValue(hostinfo.getAddress()));    result.append("&");    return(result);}/** AppendHrefField - Install a single key/value pair in an href.KSREVIEW: this should have been an object href with the constructors, etc.Constructs the string key=value& and appends to the href.*/String AppendHrefField(String& href, String key, String value){    href.append(key);    href.append("=");    href.append(value);    href.append("&");    return href;}/** createClassHref - Builds a HTML href from the class name input to provide    click to the defined class*/String createGetClassHref(const CIMNamespaceName & nameSpace,    const CIMName & className){    String href = BuildOperationHref("GetClass", nameSpace);    href.append("ClassName=");    href.append(className.getString());    href.append("&");    // KSREVIEWKS: The following is probably duplicate.  See BuildOperationHref above    HostInfo hostinfo;    href.append("hostaddress=");    href.append(EncodeQueryStringValue(hostinfo.getAddress()));    href.append("&");    return(href);}/** PrintEnumInstanceNameHref - Put out a link to the enumerateinstance Names function for this class.@return - void*/void PrintEnumInstanceNameHref(const CIMNamespaceName & nameSpace,    const CIMName & className){    String href = BuildOperationHref("EnumerateInstanceNames", nameSpace);    AppendHrefField(href,"ClassName",className.getString());    PrintAHref(href, "<BOLD Align=right>Instance Names</BOLD>");}void PrintTableTrailer(){    cout << "</table>\n";}/** PrintRow - Prints a single table row with 3 entires    The entries are name, type, value*/void PrintRow(    const CIMName& name,    const String& type,    const String& value){    cout << "<tr>\n";    cout << "<td>" << name << "</td>\n";    cout << "<td>" << type << "</td>\n";    if (value.size())    cout << "<td>" << value << "</td>\n";    else    cout << "<td>null</td>\n";    cout << "<tr>\n";}void PrintLogo(){    cout << "<table border=2>\n";    cout << "<tr>\n";    cout <<    "<td><img src=\"/pegasus/icons/OpenGroupLogo.gif\"></td>\n";    cout << "</tr>\n";    cout << "</table>\n";}void PrintSingleProperty(CIMProperty& property){    PrintTableHeader("CIMProperty:");    const CIMValue& value = property.getValue();    PrintRow(    property.getName(),    cimTypeToString (value.getType ()),    value.toString());    PrintTableTrailer();}/** PrintObjectProperties - Template for a functionthat prints the Properties information for either Classesor instances.    This prints an HTML table of the propertiesfields including name, type, value, ClassOrigin, and propagated.The name is wrapped in an href so a click will get detailedproperty information.This is a template function so that it can be used with both instanceand class definitions.@param nameSpace. Used to query for namespace value.  WHY???@param object Either the class or instance object address@param includeClassOrigin to be used to define tests on getting this field*/template<class OBJECT>void PrintObjectProperties(    const CIMNamespaceName& nameSpace,    OBJECT& object,    Boolean includeClassOrigin){    PrintPropertiesTableHeader("Properties:");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -