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

📄 cliclientlib.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.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/PegasusAssert.h>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Common/MofWriter.h>#include <Pegasus/Common/Tracer.h>#include "CLIClientLib.h"#include <Pegasus/Common/PegasusVersion.h>PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGINconst String DEFAULT_NAMESPACE = "root/cimv2";String _toString(Boolean x){    return(x ? "true" : "false");}/** Select one item from an array of items presented to    the user. This prints the list and requests user input for    the response.    @param selectList Array<String> list of items from which the    user has to select one.  Each item should be a printable string.    @param what String that defines for the output string what type    of items the select is based on (ex: "Instance Names");    @return Uint32 representing the item to be selected.    TODO: Find a way to do a reject.*/Uint32 _selectStringItem(const Array<String>& selectList, const String& what){    Uint32 rtn = 0;	char str[255];    for (Uint32 i = 0 ; i < selectList.size() ; i++)	{        cout << i + 1 << ": " << selectList[i] << endl;	}        while (rtn < 1 || rtn > selectList.size())    {        cout << "Select " << what << " (1.." << selectList.size() << ")? "              << flush;        cin.getline (str,sizeof(str),'\n');        Uint32 i = 0;        while ( str[i] )        {            if (! isdigit (str[i++]) )            {                break;            }        }        if (! str[i] )        {            rtn = (int) atoi (str);        }    }    return (rtn - 1);}/** Allow user to select one instance name. Enumerates names given className and    requests input of one index    @param    @param    @param className CIMName for the class to enumerate.    @param instancePath CIMObjectPath of instance found    @return True if instance provided and the path is in instancePath.  Else False    and there is nothing in the instancePath*/Boolean _selectInstance(CIMClient& client, Options& opts, const CIMName& className,    CIMObjectPath & instancePath){    Array<CIMObjectPath> instanceNames =        client.enumerateInstanceNames(opts.nameSpace,                                      className);    Array<String> list;    for (Uint32 i = 0 ; i < instanceNames.size() ; i++)        list.append(instanceNames[i].toString());    if (list.size() == 0)    {        return(false);    }    Uint32 rtn = _selectStringItem(list, "an Instance");    instancePath = instanceNames[rtn];    return(true);}/** Use the interactive selection mechanism to get the instance if    the input object is a class AND if the opts.interactive flag is    set.  This function is used by the association functions because    just the existence of the object as class is insufficient since    these functions accept both class and instance input for processing.    If the tests are passed this function calls the server to enumerate    the instance names possible and displays them for the user to    select one.    @param client CIMClient context for the operation required    @param opts the context structure for this operaiton    @param name String of the object that is the target of the request.    @param instancePath CIMObjectPath of instance selected if return    is true.  Else, unchanged.    @return Boolean True if an instance path is to be returned. If nothing    is selected, returns False.*/Boolean _conditionalSelectInstance(CIMClient& client, Options& opts,    CIMObjectPath & instancePath){    // if class level and interactive set.    if ((instancePath.getKeyBindings().size() == 0) && opts.interactive)    {        // Ask the user to select an instance        return(_selectInstance(client, opts, CIMName(opts.objectName), instancePath));    }    return(true);}// Character sequences used in help/usage output.String buildPropertyListString(CIMPropertyList& pl){    String rtn;    Array<CIMName> pls = pl.getPropertyNameArray();    if (pl.isNull())        return("NULL");    if (pl.size() == 0)        return("EMPTY");    for (Uint32 i = 0 ; i < pls.size() ; i++)    {        if (i != 0)            rtn.append(", ");        rtn.append(pls[i].getString());    }    return(rtn);}void printPropertyList(CIMPropertyList& pl){    cout << buildPropertyListString(pl);}static const char * version = "2.2";static const char * usage = "This command executes single CIM Operations.";static const char* optionText = "Valid options for this command are : ";static const char* commonOptions = "    -count, -d, -delay, -p, -l, -u, -o, -x,\ -v, --sum, --timeout, -r, --t ";const char *examples[] = {"cimcli ni -n test/TestProvider TEST_Person -- enumerateinstancenames of class \n","    -n, classname \n","cimcli niall -n root/cimv2     \n        -- enumerateinstancenames of \all classes under the namespace root/cimv2 \n","    -n, -di, classname \n","cimcli ei PG_ComputerSystem   -- enumerateinstances of class \n","    -n, -di, -lo, -iq, -pl, classname, includeClassOrigin \n","cimcli nc -- Enumerate class names from root/cimv2. \n","    -n, -di, classname \n","cimcli ec -n root/cimv2 -- Enumerate classes from namespace root/cimv2. \n","    -n, -di, -lo, -iq, includeClassOrigin \n","cimcli gc CIM_door -u guest -p guest\n    -- Get class \user = guest and password = guest. \n","    -n, -lo, -iq, -pl, className, includeClassOrigin \n","cimcli gi -n test/TestProvider TEST_Person    ---  getInstance of class \n","    -n, -lo, -iq, -pl, includeClassOrigin \n","cimcli ci -n test/TestProvider TEST_Person Name=Michael -- createInstance of" " class \n","    -n \n","cimcli di -n test/TestProvider TEST_Person    ---  deleteInstance of class"" interactively \n","    -n \n","Operation Not supported.. \n"," \n","Operation Not supported.. \n"," \n","cimcli dc -n test/TestProvider TEST_Person  \n     --- deletes the Class when"" there are no instance and sub-class for this class \n","    -n \n","Operation Not supported.. \n"," \n","Operation Not supported.. \n"," \n","cimcli gq Association -- Get the qualifiers in mof output format \n","    -n, qualifierName \n","Operation Not supported.. \n"," \n","cimcli eq -n test/TestProvider  ---  enumerateQualifiers of namespace""\n     test/TestProvider \n","    -n \n","cimcli dq -n test/TestProvider ASSOCIATION  --- deleteQualifier Association in"" namespace test/TestProvider \n","    -n, qualifierName \n","cimcli a TST_Person.name=\\\"Mike\\\" -n test/TestProvider -ac TST_Lineage \n  or""\ncimcli a TST_Person -n test/TestProvider -ac TST_Lineage \n","    -n, -ac, -rc, -r, -rr, -iq, -pl, includeClassOrigin, -i \n","cimcli an TST_Person.name=\\\"Mike\\\" -n test/TestProvider -ac TST_Lineage \n or""\ncimcli an TST_Person -n test/TestProvider -ac TST_Lineage \n","    -n, -ac, -rc, -r, -rr, -i \n","cimcli r TST_Person.name=\\\"Mike\\\" -n test/TestProvider -rc TST_Lineage \n  or""\ncimcli r TST_Person -n test/TestProvider -rc TST_Lineage \n","    -n, -rc, -r, -iq, -pl, includeClassOrigin, -i \n","cimcli rn TST_Person.name=\\\"Mike\\\" -n test/TestProvider -rc TST_Lineage \n or""\ncimcli rn TST_Person -n test/TestProvider -rc TST_Lineage \n","    -n, -rc, -r, -i \n","cimcli im Sample_MethodProviderClass.Name=\\\"mooo\\\" SayHello""\n   -n root/SampleProvider -ip p1=fred \n","    -n, -ip \n","cimcli xq \"select * from CIM_ComputerSystem\"   \n   ---- ""This command will work when the code is compiled with ExecQuery enabled \n","    -n, queryLanguage, query \n","cimcli ns    ---  enumerate all Namespaces in repository \n"," No options Required \n","cimcli son   --- Switch On's the statistical information on CIMServer \n"," No options Required \n","cimcli soff  --- Switch OFF's the statistical information on CIMServer \n"," No options Required \n","cimcli ?     --- Displays help command \n"," No options Required"};void showExamples(){    Uint32 numExamples = sizeof(examples) / sizeof(char *);    cout << "Examples : " << endl;    for (Uint32 i=0; i < numExamples; i++)    {        cout << examples[i++] << endl;    }}void _displaySummary(Uint32 count, String& description, String item, Options& opts){        cout << count << " " << description            << " " << item << " returned. ";        if (opts.repeat > 0)            cout << opts.repeat;        if(opts.time && opts.repeat)            cout << " " << opts.saveElapsedTime;        cout << endl;        if ((opts.count) != 29346 && (opts.count != count))        {            cout << "Failed count test. Expected= " << opts.count << " Actual rcvd= " << count << endl;            opts.termCondition = 1;        }}/**** NOT TESTEDString _nextToken(String& input, Uint32 start, Char16 separator){    String rtn;    Uint32 end;    end = input.find(input.find(start, separator));    if (end == PEG_NOT_FOUND)    {        start = PEG_NOT_FOUND        rtn = input.subString(start,(input.size() - start);    }    else    {        rtn = input.subString(start,end);        start = end + 1;    }    return(rtn);}*//** tokenize an input string into an array of Strings, * separating the tokens at the separator character * provided * @param input String * @param separator character * @returns Array of separated strings * */Array<String> _tokenize(const String& input, const Char16 separator){    Array<String> tokens;    if (input.size() != 0)    {        Uint32 start = 0;        Uint32 length = 0;        Uint32 end = 0;        while ((end = input.find(start, separator)) != PEG_NOT_FOUND)        {            length = end - start;            tokens.append(input.subString(start, length));            start += (length + 1);        }        //Replaced < with <= to consider input param like A="" as valid param.        //key in this param is 'A'and value is NULL. It also takes care of A= param.        if(start <= input.size())        {            tokens.append(input.subString(start));        }    }    return tokens;}Boolean _tokenPair(const String& input, String& key, String& value){    Array<String> pair = _tokenize(input, '=');    if (pair.size() < 2)    {        cout << "Input Parameter error. Expected name=value. Received  " << input << endl;        return(false);    }    // If there is more than 1 "=" it is part of the reference and we    // rebuild the reference.    if (pair.size() > 2)    {        for (Uint32 i = 2 ; i < pair.size() ; i++)        {            pair[1].append("=");            pair[1].append(pair[i]);        }    }    key = pair[0];    value = pair[1];    return(true);}void _nextParamToken(String& input, String& token){    unsigned int end;    // Check for Character Literal    if (input.find('\'') == 0)    {        input.remove(0,1);  // remove quote        if ((end = input.find("\'")) != PEG_NOT_FOUND)        {            token = input.subString(0, end);            input.remove(0, end + 1);   // +1 to delete final quote char        }        else        {            printf(" ERROR -- no matching quote!");        }        return;    }    // Check for String Literal    if (input.find('\"') == 0)    {        input.remove(0,1);  // remove quote        if ((end = input.find("\"")) != PEG_NOT_FOUND)        {            token = input.subString(0, end);            input.remove(0, end + 1);   // +1 to delete final quote char        }        else        {            printf("ERROR -- no matching quote!");        }        return;    }    // Take line up to separator (, or }) as token    if ((end = input.find(',')) != PEG_NOT_FOUND)    {        token = input.subString(0, end);        input.remove(0, end+1); // +1 to capture the comma        return;    }    if ((end = input.find('}')) != PEG_NOT_FOUND)    {        token = input.subString(0, end);        input.remove(0, end+1); // +1 to capture the brace        return;    }    if((end = input.find(']')) != PEG_NOT_FOUND)    {        token = input.subString(0, end);        input.remove(0, end+1); // +1 to capture the bracket        return;    }    // Fall through.. take entire input as token    token = input;    input = "";    return;}CIMParamValue _createMethodParamValue(const String& input, const Options& opts){    String key;    String value;    if (!_tokenPair(input, key, value))    {        cout <<"Error in param parsing with input " << input << endl;

⌨️ 快捷键说明

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