void getPropertiesFromCIMServer(
    CIMClient& client,
    const CIMName& propName,
    Array <String>& propValues)
{
    CIMProperty prop;

    Array<CIMKeyBinding> kbArray;
    CIMKeyBinding        kb;
    String               _hostName;

    kb.setName(PROPERTY_NAME);
    kb.setValue(propName.getString());
    kb.setType(CIMKeyBinding::STRING);

    _hostName.assign(System::getHostName());

    kbArray.append(kb);

    CIMObjectPath reference(_hostName, PEGASUS_NAMESPACENAME_CONFIG,
                            PEGASUS_CLASSNAME_CONFIGSETTING, kbArray);

    CIMInstance cimInstance = client.getInstance(PEGASUS_NAMESPACENAME_CONFIG,
                                                 reference);

    Uint32 pos = cimInstance.findProperty(PROPERTY_NAME);
    prop = (CIMProperty)cimInstance.getProperty(pos);
    propValues.append(prop.getValue().toString());

    pos = cimInstance.findProperty(DEFAULT_VALUE);
    prop = (CIMProperty)cimInstance.getProperty(pos);
    propValues.append(prop.getValue().toString());

    pos = cimInstance.findProperty(CURRENT_VALUE);
    prop = (CIMProperty)cimInstance.getProperty(pos);
    propValues.append(prop.getValue().toString());

    pos = cimInstance.findProperty(PLANNED_VALUE);
    prop = (CIMProperty)cimInstance.getProperty(pos);
    propValues.append(prop.getValue().toString());

    pos = cimInstance.findProperty(DYNAMIC_PROPERTY);
    prop = (CIMProperty)cimInstance.getProperty(pos);
    propValues.append(prop.getValue().toString());

}
Exemplo n.º 2
0
WMIObjectPath::WMIObjectPath(const BSTR bstr)
{
    String str = WMIString(bstr);

    // autofit string
    str.remove(::wcslen((WCHAR *)((USHORT *) str.getChar16Data())));


    // <object_path> ::= \\<host>\<namespace>:<class>.<key>
    // <object_path> ::= \<namespace>:<class>.<key>
    // <object_path> ::= <class>.<key>
    // <object_path> ::= <class>

    Uint32         pos = 0;
    Uint32         len = 0;
    const Char16 * p = str.getChar16Data();

    // get namespace host (optional)
    if((p[pos] == '\\') && (p[pos + 1] == '\\'))
    {
        pos += 2;    // skip "\\\\"

        // WMI Mapper can act as proxy to get date from other windows
        // systems, The "." as system name represents localhost in WMI.
        // However, the parser was not expecting that. So, we ignore the
        // "." in order to ignore the hostname part so that it will be
        // considered a request to the localhost.
        if (p[pos]=='.')
            pos++;

        // seek to '\\'
        for(len = 0; (p[pos] != Char16(0)) && (p[pos] != '\\'); len++, pos++);

        setHost(String(&p[pos - len], len));
    }

    // get namespace path (optional)
    if(p[pos] == '\\')
    {
        pos++;        // skip '\\'

        // seek to ':'
        for(len = 0; (p[pos] != Char16(0)) && (p[pos] != ':'); len++, pos++);

        // change slashes
        String temp(String(&p[pos - len], len));

        for(Uint32 i = 0; i < temp.size(); i++)
        {
            if(temp[i] == '\\')
            {
                temp[i] = '/';
            }
        }
        setNameSpace(temp);
    }

    p[pos] == ':' ? pos++ : 0;     // skip ':'

    // get class name (required)

    // seek to '.'
    for(len = 0; (p[pos] != Char16(0)) && (p[pos] != '.'); len++, pos++);

    setClassName(String(&p[pos - len], len));

    p[pos] == '.' ? pos++ : 0;     // skip '.'

    // get model key (optional)

    // <key> ::= <name> "=" <value> ["," <name> "=" <value>](0..n)
    //
    // <name> ::= alphabetic_character(1..n)
    // <value> ::= <string> | <number> | <boolean>
    // <string> ::= """ alphabetic_character | numeric_character |
    //                      symbol_character (1..n) """
    // <number> ::= numeric_character(1..n)
    // <boolean> ::= "true" | "false"

    while(p[pos] != Char16(0))
    {
        // get keys
        CIMKeyBinding key;

        // seek to '='
        for(len = 0; (p[pos] != Char16(0)) && (p[pos] != '='); len++, pos++);

        key.setName(String(&p[pos - len], len));

        p[pos] == '=' ? pos++ : 0;     // skip '='

        // A string value may be enclosed in single quotes or double quotes
        if ((p[pos] == '\"') || (p[pos] == '\''))
        {
            char openingQuote = p[pos];

            // parse string value

            // check for embedded quotes. for example,
            // class1.property1A="class2.property2A="2A",
            // property2B="2B"",property2A="foo"
            // or class1.property1A=",",property2A="."

            bool quote = false;

            // seek to closing quote or eos

            for(len = 0;
                (p[pos] != Char16(0)) && !((p[pos] == ',') && (!quote));
                len++, pos++)
            {
                quote = (p[pos] == openingQuote) ? !quote : quote;

                // By Jair - check if it is not an 'internal' quote.
                // If it is, must be discarded in this case.
                if (!quote && len) quote = (p[pos - 1] == '\\');
            }

            // strip outer quotes
            String temp(&p[pos - len], len);
            if((temp.size() != 0) && (temp[0] == openingQuote) &&
                (temp[temp.size() - 1] == openingQuote))
            {
                temp.remove(temp.size() - 1, 1);
                temp.remove(0, 1);
            }

            // remove escape sequences (the parent class will
            //put them back later).
            for(Uint32 i = 0; i < temp.size(); i++)
            {
                if((temp[i] == '\\') &&
                   ((temp[i + 1] == '\\') ||
                    (temp[i + 1] == '"')  ||
                    (temp[i + 1] == '\n') ||
                    (temp[i + 1] == '\r') ||
                    (temp[i + 1] == '\t')))
                {
                    temp.remove(i, 1);
                }
            }

            key.setValue(temp);
            key.setType(CIMKeyBinding::STRING);
        }
        else if((p[pos] == 't') || (p[pos] == 'T') ||
            (p[pos] == 'f') || (p[pos] == 'F'))
        {
            // parse boolean value

            // seek to ',' or eos
            for(len = 0; (p[pos] != Char16(0)) && (p[pos] != ',');
                len++, pos++);

            key.setValue(String(&p[pos - len], len));

            key.setType(CIMKeyBinding::BOOLEAN);
        }
        else if(std::isdigit<wchar_t>(p[pos], std::locale()))
        {
            // parse numeric value

            // seek to ',' or eos
            for(len = 0; (p[pos] != Char16(0)) && (p[pos] != ',');
                len++, pos++);

            key.setValue(String(&p[pos - len], len));

            key.setType(CIMKeyBinding::NUMERIC);
        }
        else
        {
            throw(std::invalid_argument("unrecognized key type"));
        }

        // update key list
        Array<CIMKeyBinding> keySet = getKeyBindings();

        keySet.append(key);

        setKeyBindings(keySet);

        p[pos] == ',' ? pos++ : 0;     // skip ','
    }
}