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

📄 indicationformatter.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//%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/Exception.h>#include <Pegasus/Common/Tracer.h>#include <Pegasus/Common/CommonUTF.h>#include "IndicationFormatter.h"PEGASUS_NAMESPACE_BEGINvoid IndicationFormatter::validateTextFormat(    const String& textStr,    const CIMClass& indicationClass,    const Array<String>& textFormatParams){    PEG_METHOD_ENTER(TRC_IND_FORMATTER,        "IndicationFormatter::validateTextFormat");    String textFormatStr = textStr;    String textFormatSubStr;    String exceptionStr;    Uint32 leftBrace = textFormatStr.find("{");    Uint32 rightBrace;    do    {        textFormatSubStr.clear();        if (leftBrace != PEG_NOT_FOUND)        {            // Do not expect a right brace before the left            // brace. e.g An invalid text format string could be:            // "Indication occurred at 2, datetime} with            // identify ID {3, string}"            textFormatSubStr = textFormatStr.subString(0, leftBrace);            Uint32 rightBrace2 = textFormatSubStr.find("}");            if (rightBrace2 != PEG_NOT_FOUND)            {                textFormatSubStr = textFormatStr.subString(                    0, (rightBrace2 + 1));                MessageLoaderParms parms(                    "IndicationFormatter.IndicationFormatter."                        "_MSG_INVALID_SYNTAX_OF_FOR_PROPERTY",                    "Invalid syntax at $0 in property $1",                    textFormatSubStr,                    _PROPERTY_TEXTFORMAT.getString());                exceptionStr.append(MessageLoader::getMessage(parms));                PEG_METHOD_EXIT();                throw PEGASUS_CIM_EXCEPTION(                    CIM_ERR_INVALID_PARAMETER, exceptionStr);            }            // expect right brace            textFormatStr = textFormatStr.subString(leftBrace+1, PEG_NOT_FOUND);            rightBrace = textFormatStr.find("}");            // Do not expect a left brace between left and right            // braces. e.g A text string: "Indication occurred            // at {2, datetime with identify ID {3, string}" is            // an invalid format.            if (rightBrace != PEG_NOT_FOUND)            {                textFormatSubStr.clear();                textFormatSubStr = textFormatStr.subString(0, rightBrace);                Uint32 leftBrace2 = textFormatSubStr.find("{");                if (leftBrace2 != PEG_NOT_FOUND)                {                    textFormatSubStr = textFormatStr.subString(                        0, (leftBrace2 + 1));                    MessageLoaderParms parms(                        "IndicationFormatter.IndicationFormatter."                            "_MSG_INVALID_SYNTAX_OF_FOR_PROPERTY",                        "Invalid syntax at $0 in property $1",                        textFormatSubStr,                        _PROPERTY_TEXTFORMAT.getString());                    exceptionStr.append(MessageLoader::getMessage(parms));                    PEG_METHOD_EXIT();                    throw PEGASUS_CIM_EXCEPTION(                        CIM_ERR_INVALID_PARAMETER, exceptionStr);                }                String propertyParam;                String propertyTypeStr;                String propertyIndexStr;                char propertyIndexBuffer[32];                Sint32 propertyIndex;                Uint32 comma;                Uint32 leftBracket;                Uint32 rightBracket;                Boolean isArray = false;                comma = textFormatSubStr.find(",");                // A dynamic content can have format either                // {index} or {index[x]}                if (comma == PEG_NOT_FOUND)                {                    propertyParam =                        textFormatSubStr.subString(0, PEG_NOT_FOUND);                    propertyTypeStr = String::EMPTY;                    leftBracket = textFormatSubStr.find("[");                    rightBracket = textFormatSubStr.find("]");                }                // A dynamic content can have format either                // {index, type} or {index[x], type}                else                {                    propertyParam = textFormatSubStr.subString(0, comma);                    propertyTypeStr = textFormatSubStr.subString(                        comma +1, PEG_NOT_FOUND);                    leftBracket = propertyParam.find("[");                        rightBracket = propertyParam.find("]");                }                // A dynamic content has syntax either {index} or {index, type}                if (leftBracket == PEG_NOT_FOUND)                {                    // there is no left bracket, do not expect a right bracket                    if (rightBracket != PEG_NOT_FOUND)                    {                        textFormatSubStr = textFormatStr.subString(                            0, (rightBracket + 1));                        MessageLoaderParms parms(                            "IndicationFormatter.IndicationFormatter."                                "_MSG_INVALID_SYNTAX_OF_FOR_PROPERTY",                            "Invalid syntax at $0 in property $1",                            textFormatSubStr,                            _PROPERTY_TEXTFORMAT.getString());                        exceptionStr.append(MessageLoader::getMessage(parms));                        PEG_METHOD_EXIT();                        throw PEGASUS_CIM_EXCEPTION(                            CIM_ERR_INVALID_PARAMETER, exceptionStr);                    }                    propertyIndexStr = propertyParam;                    isArray = false;                }                // A dynamic content has syntax either                // {index[]} or {index[], type}                else                {                    // there is a left bracket, expect a right bracket                    if (rightBracket == PEG_NOT_FOUND)                    {                        MessageLoaderParms parms(                            "IndicationFormatter.IndicationFormatter."                                "_MSG_INVALID_SYNTAX_OF_FOR_PROPERTY",                            "Invalid syntax at $0 in property $1",                            textFormatSubStr,                            _PROPERTY_TEXTFORMAT.getString());                        exceptionStr.append(MessageLoader::getMessage(parms));                        PEG_METHOD_EXIT();                        throw PEGASUS_CIM_EXCEPTION(                            CIM_ERR_INVALID_PARAMETER, exceptionStr);                    }                    propertyIndexStr = propertyParam.subString(0, leftBracket);                    isArray = true;                }                sprintf(propertyIndexBuffer, "%s",                    (const char *)propertyIndexStr.getCString());                // skip white space                char* indexStr = propertyIndexBuffer;                while (*indexStr && isspace(*indexStr))                {                    *indexStr++;                }                _isValidIndex(indexStr);                propertyIndex = atoi(indexStr);                // check the property index                if ((propertyIndex < 0) ||                    ((Uint32)propertyIndex >= textFormatParams.size()))                {                    // property index is out of bounds                    MessageLoaderParms parms(                    "IndicationFormatter.IndicationFormatter."                        "_MSG_INDEX_IS_OUT_OF_BOUNDS",                    "The value of index $0 in property $1 is out of bounds",                    propertyIndex,                    _PROPERTY_TEXTFORMATPARAMETERS.getString());                    exceptionStr.append(MessageLoader::getMessage(parms));                    PEG_METHOD_EXIT();                    throw PEGASUS_CIM_EXCEPTION(                        CIM_ERR_INVALID_PARAMETER, exceptionStr);                }                if (propertyTypeStr != String::EMPTY)                {                    _validatePropertyType(indicationClass,                        textFormatParams[propertyIndex],                        propertyTypeStr, isArray);                }                textFormatStr = textFormatStr.subString(                    rightBrace+1, PEG_NOT_FOUND);            }            else // no right brace            {                MessageLoaderParms parms(                    "IndicationFormatter.IndicationFormatter."                        "_MSG_INVALID_SYNTAX_OF_FOR_PROPERTY",                    "Invalid syntax at $0 in property $1",                    textFormatSubStr,                    _PROPERTY_TEXTFORMAT.getString());                exceptionStr.append(MessageLoader::getMessage(parms));                PEG_METHOD_EXIT();                throw PEGASUS_CIM_EXCEPTION(                    CIM_ERR_INVALID_PARAMETER, exceptionStr);            }        }        else // no left brace        {            // does not expect right brace            rightBrace = textFormatStr.find("}");            if (rightBrace != PEG_NOT_FOUND)            {                textFormatSubStr = textFormatStr.subString(0, rightBrace + 1);                MessageLoaderParms parms(                    "IndicationFormatter.IndicationFormatter."                        "_MSG_INVALID_SYNTAX_OF_FOR_PROPERTY",                    "Invalid syntax at $0 in property $1",                    textFormatSubStr,                    _PROPERTY_TEXTFORMAT.getString());                    exceptionStr.append(MessageLoader::getMessage(parms));                    PEG_METHOD_EXIT();                    throw PEGASUS_CIM_EXCEPTION(                        CIM_ERR_INVALID_PARAMETER, exceptionStr);            }            break;        }        leftBrace = textFormatStr.find("{");    } while (textFormatStr.size() > 0);    PEG_METHOD_EXIT();}void IndicationFormatter::_validatePropertyType(    const CIMClass& indicationClass,    const String& propertyParam,    const String& typeStr,    const Boolean& isArray){    PEG_METHOD_ENTER (TRC_IND_FORMATTER,        "IndicationFormatter::_validatePropertyType");    String exceptionStr;    char propertyTypeBuffer[32];    char * providedPropertyType;    Array <String> validPropertyTypes;    String propertyTypeStr = typeStr;    validPropertyTypes.append("boolean");    validPropertyTypes.append("uint8");    validPropertyTypes.append("sint8");    validPropertyTypes.append("uint16");    validPropertyTypes.append("sint16");    validPropertyTypes.append("uint32");    validPropertyTypes.append("sint32");    validPropertyTypes.append("uint64");    validPropertyTypes.append("sint64");    validPropertyTypes.append("real32");    validPropertyTypes.append("real64");    validPropertyTypes.append("char16");    validPropertyTypes.append("string");    validPropertyTypes.append("datetime");    validPropertyTypes.append("reference");    propertyTypeStr.toLower();    sprintf(propertyTypeBuffer, "%s",        (const char *)propertyTypeStr.getCString());    // skip white space    providedPropertyType = propertyTypeBuffer;    while (*providedPropertyType && isspace(*providedPropertyType))    {        providedPropertyType++;    }    String providedTypeStr = providedPropertyType;    Uint32 space = providedTypeStr.find(" ");    if (space != PEG_NOT_FOUND)    {        // skip the appended space from the providedTypeStr        // e.g {1, string  }        String restTypeStr = providedTypeStr.subString(space, PEG_NOT_FOUND);        Uint32 i = 0;        while (restTypeStr[i] == ' ')        {            i++;        }        restTypeStr = restTypeStr.subString(i, PEG_NOT_FOUND);        if (strlen(restTypeStr.getCString()) == 0)        {            providedTypeStr = providedTypeStr.subString(0, space);        }        else        {            // the provided property type is not a valid type            // e.g. {1, string  xxx}            MessageLoaderParms parms(                "IndicationFormatter.IndicationFormatter."                    "_MSG_INVALID_TYPE_OF_FOR_PROPERTY",                "Invalid property type of $0 in property $1",                providedPropertyType,                _PROPERTY_TEXTFORMAT.getString());        }    }    //    // Checks if the provided property type is a valid type    //    if (!(Contains(validPropertyTypes, providedTypeStr)))    {        // the provided property type is not valid type        MessageLoaderParms parms(            "IndicationFormatter.IndicationFormatter."                "_MSG_INVALID_TYPE_OF_FOR_PROPERTY",            "Invalid property type of $0 in property $1",            providedPropertyType,            _PROPERTY_TEXTFORMAT.getString());        exceptionStr.append(MessageLoader::getMessage(parms));        PEG_METHOD_EXIT();        throw PEGASUS_CIM_EXCEPTION(            CIM_ERR_INVALID_PARAMETER, exceptionStr);    }    for (Uint32 i = 0; i < indicationClass.getPropertyCount(); i++)    {        CIMName propertyName = indicationClass.getProperty(i).getName();        if (String::equalNoCase(propertyParam, propertyName.getString()))        {            // get the property type;            CIMType propertyType = indicationClass.getProperty(i).getType();            // Check if the property is an array type            if ((isArray && !(indicationClass.getProperty(i).isArray())) ||                (!isArray && indicationClass.getProperty(i).isArray()))            {                MessageLoaderParms parms(                    "IndicationFormatter.IndicationFormatter."                        "_MSG_PROPERTY_IS_NOT_AN_ARRAY_TYPE",                    "The property $0 is not an array type",                    propertyName.getString());                exceptionStr.append(MessageLoader::getMessage(parms));                PEG_METHOD_EXIT();                throw PEGASUS_CIM_EXCEPTION(                    CIM_ERR_INVALID_PARAMETER, exceptionStr);            }            // property type matchs            if (String::equalNoCase(providedTypeStr,                cimTypeToString(propertyType)))            {                break;            }            else            {                MessageLoaderParms parms(                    "IndicationFormatter.IndicationFormatter."                        "_MSG_MISS_MATCHED_TYPE_OF_FOR_PROPERTY",                    "The provided property type of $0 in $1 does not match "                        "the property type $2",                    providedPropertyType,                    cimTypeToString(propertyType),                    _PROPERTY_TEXTFORMAT.getString());                exceptionStr.append(MessageLoader::getMessage(parms));                PEG_METHOD_EXIT();                throw PEGASUS_CIM_EXCEPTION(                    CIM_ERR_INVALID_PARAMETER, exceptionStr);            }        }    }    PEG_METHOD_EXIT();}void IndicationFormatter::validateTextFormatParameters(    const CIMPropertyList& propertyList,    const CIMClass& indicationClass,    const Array<String>& textFormatParams){    PEG_METHOD_ENTER(TRC_IND_FORMATTER,        "IndicationFormatter::validateTextFormatParameters");    Array<String> indicationClassProperties;    String exceptionStr;    // All the properties are selected    if (propertyList.isNull())

⌨️ 快捷键说明

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