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

📄 configmanager.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//%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.////==============================================================================////%///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  ConfigManager/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Tracer.h>#include <Pegasus/Common/Logger.h>#include <Pegasus/Common/PegasusVersion.h>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/Common/Constants.h>#include "ConfigExceptions.h"#include "ConfigManager.h"PEGASUS_NAMESPACE_BEGIN/////////////////////////////////////////////////////////////////////////////////  When a new property owner is created be sure to create a static//  object of the new property owner.///////////////////////////////////////////////////////////////////////////////TracePropertyOwner* ConfigManager::traceOwner =    new TracePropertyOwner;LogPropertyOwner* ConfigManager::logOwner =    new LogPropertyOwner;DefaultPropertyOwner* ConfigManager::defaultOwner =    new DefaultPropertyOwner;SecurityPropertyOwner* ConfigManager::securityOwner =    new SecurityPropertyOwner;RepositoryPropertyOwner* ConfigManager::repositoryOwner =    new RepositoryPropertyOwner;ShutdownPropertyOwner* ConfigManager::shutdownOwner =    new ShutdownPropertyOwner;FileSystemPropertyOwner* ConfigManager::fileSystemOwner =    new FileSystemPropertyOwner;ProviderDirPropertyOwner* ConfigManager::providerDirOwner =    new ProviderDirPropertyOwner;NormalizationPropertyOwner* ConfigManager::normalizationOwner =    new NormalizationPropertyOwner;/////////////////////////////////////////////////////////////////////////////////   When a new property is created be sure to add the new property name//   and the owner object to the OwnerEntry table below.///////////////////////////////////////////////////////////////////////////////struct OwnerEntry{    const char* propertyName;    ConfigPropertyOwner* propertyOwner;};static struct OwnerEntry _properties[] ={    {"traceLevel",         (ConfigPropertyOwner*)ConfigManager::traceOwner},    {"traceComponents",         (ConfigPropertyOwner*)ConfigManager::traceOwner},    {"traceFilePath",         (ConfigPropertyOwner*)ConfigManager::traceOwner},#if !defined(PEGASUS_USE_SYSLOGS)    {"logdir",         (ConfigPropertyOwner*)ConfigManager::logOwner},#endif    {"logLevel",         (ConfigPropertyOwner*)ConfigManager::logOwner},    {"enableHttpConnection",         (ConfigPropertyOwner*)ConfigManager::defaultOwner},    {"enableHttpsConnection",         (ConfigPropertyOwner*)ConfigManager::defaultOwner},    {"httpPort",         (ConfigPropertyOwner*)ConfigManager::defaultOwner},    {"httpsPort",         (ConfigPropertyOwner*)ConfigManager::defaultOwner},    {"home",         (ConfigPropertyOwner*)ConfigManager::defaultOwner},    {"daemon",         (ConfigPropertyOwner*)ConfigManager::defaultOwner},    {"slp",         (ConfigPropertyOwner*)ConfigManager::defaultOwner},    {"enableAssociationTraversal",         (ConfigPropertyOwner*)ConfigManager::defaultOwner},    {"enableIndicationService",         (ConfigPropertyOwner*)ConfigManager::defaultOwner},    {"enableAuthentication",         (ConfigPropertyOwner*)ConfigManager::securityOwner},    {"enableNamespaceAuthorization",         (ConfigPropertyOwner*)ConfigManager::securityOwner},    {"httpAuthType",         (ConfigPropertyOwner*)ConfigManager::securityOwner},    {"passwordFilePath",         (ConfigPropertyOwner*)ConfigManager::securityOwner},    {"sslCertificateFilePath",         (ConfigPropertyOwner*)ConfigManager::securityOwner},    {"sslKeyFilePath",         (ConfigPropertyOwner*)ConfigManager::securityOwner},    {"sslTrustStore",         (ConfigPropertyOwner*)ConfigManager::securityOwner},#ifdef PEGASUS_ENABLE_SSL_CRL_VERIFICATION    {"crlStore",         (ConfigPropertyOwner*)ConfigManager::securityOwner},#endif    {"sslClientVerificationMode",         (ConfigPropertyOwner*)ConfigManager::securityOwner},    {"sslTrustStoreUserName",         (ConfigPropertyOwner*)ConfigManager::securityOwner},#ifdef PEGASUS_KERBEROS_AUTHENTICATION    {"kerberosServiceName",         (ConfigPropertyOwner*)ConfigManager::securityOwner},#endif    {"repositoryIsDefaultInstanceProvider",         (ConfigPropertyOwner*)ConfigManager::repositoryOwner},    {"enableBinaryRepository",         (ConfigPropertyOwner*)ConfigManager::repositoryOwner},    {"shutdownTimeout",         (ConfigPropertyOwner*)ConfigManager::shutdownOwner},    {"repositoryDir",         (ConfigPropertyOwner*)ConfigManager::fileSystemOwner},    {"providerDir",         (ConfigPropertyOwner*)ConfigManager::providerDirOwner},    {"enableRemotePrivilegedUserAccess",         (ConfigPropertyOwner*)ConfigManager::securityOwner},    {"enableSubscriptionsForNonprivilegedUsers",         (ConfigPropertyOwner*)ConfigManager::securityOwner},#ifdef PEGASUS_ENABLE_USERGROUP_AUTHORIZATION    {"authorizedUserGroups",         (ConfigPropertyOwner*)ConfigManager::securityOwner},#endif    {"messageDir",         (ConfigPropertyOwner*)ConfigManager::fileSystemOwner},#ifdef PEGASUS_ENABLE_OBJECT_NORMALIZATION    {"enableNormalization",         (ConfigPropertyOwner*)ConfigManager::normalizationOwner},    {"excludeModulesFromNormalization",         (ConfigPropertyOwner*)ConfigManager::normalizationOwner},#endif    {"forceProviderProcesses",         (ConfigPropertyOwner*)ConfigManager::defaultOwner},    {"maxProviderProcesses",         (ConfigPropertyOwner*)ConfigManager::defaultOwner},#ifndef PEGASUS_DISABLE_AUDIT_LOGGER    {"enableAuditLog",         (ConfigPropertyOwner*)ConfigManager::defaultOwner},#endif    {"socketWriteTimeout",         (ConfigPropertyOwner*)ConfigManager::defaultOwner}};const Uint32 NUM_PROPERTIES = sizeof(_properties) / sizeof(struct OwnerEntry);/////////////////////////////////////////////////////////////////////////////////   To use a fixed value for a property rather than delegating to a property//   owner, add the property to the FixedValueEntry table below.  An entry in//   the OwnerEntry table above for this same property will be initialized//   and given the (fixed) initial current value, but will thereafter be//   ignored.////   Fixed values are only returned by getDefaultValue(), getCurrentValue(),//   and getPlannedValue().  All other methods will treat fixed properties as//   unrecognized properties.///////////////////////////////////////////////////////////////////////////////struct FixedValueEntry{    const char* propertyName;    const char* fixedValue;};static struct FixedValueEntry _fixedValues[] ={#include "FixedPropertyTable.h"};const Uint32 NUM_FIXED_PROPERTIES =    sizeof(_fixedValues) / sizeof(struct FixedValueEntry);/**    Initialize the default PEGASUS_HOME location, the default is set to the    current directory.*/const String ConfigManager::PEGASUS_HOME_DEFAULT = ".";String ConfigManager::_pegasusHome = PEGASUS_HOME_DEFAULT;//// Initialize ConfigManager instance//ConfigManager* ConfigManager::_instance = 0;/** Constructor. */ConfigManager::ConfigManager()    : useConfigFiles(false){    //    // Initialize the instance variables    //    _propertyTable.reset(new PropertyTable);    //    // Initialize the property owners    //    _initPropertyTable();}/** Terminate the ConfigManager*/voidConfigManager::destroy(){   if (_instance)   {       delete _instance->traceOwner;       delete _instance->logOwner;       delete _instance->defaultOwner;       delete _instance->securityOwner;       delete _instance->repositoryOwner;       delete _instance->shutdownOwner;       delete _instance->fileSystemOwner;       delete _instance->providerDirOwner;       delete _instance->normalizationOwner;       delete _instance;       _instance = 0;   }}/**    Get a reference to the singleton ConfigManager instance.  If no    ConfigManager instance exists, construct one.*/ConfigManager* ConfigManager::getInstance(){    if (!_instance)    {        _instance = new ConfigManager();    }    return _instance;}/**    Initialize the current value of a config property*/Boolean ConfigManager::initCurrentValue(    const String& propertyName,    const String& propertyValue){    ConfigPropertyOwner* propertyOwner = 0;    //    // get property owner object from the config table.    //    if (!_propertyTable->ownerTable.lookup(propertyName, propertyOwner))    {        throw UnrecognizedConfigProperty(propertyName);    }    if (useConfigFiles && !propertyOwner->isValid(propertyName, propertyValue))    {        throw InvalidPropertyValue(propertyName, propertyValue);    }    //    // update the value with the property owner    //    propertyOwner->initCurrentValue(propertyName, propertyValue);    if (useConfigFiles)    {        //        // update the value in the current config file        //        return _configFileHandler->updateCurrentValue(            propertyName, propertyValue, false);    }    return true;}/**    Update current value of a property.*/Boolean ConfigManager::updateCurrentValue(    const String& name,    const String& value,    Boolean unset){    String prevValue = String::EMPTY;    //    // get property owner object from the config table.    //    ConfigPropertyOwner* propertyOwner;    if (!_propertyTable->ownerTable.lookup(name, propertyOwner))    {        throw UnrecognizedConfigProperty(name);    }    //    // keep a copy of the existing config value    //    prevValue = propertyOwner->getCurrentValue(name);    //    // ask owner to update the current value    //    if (unset)    {        propertyOwner->updateCurrentValue(name,            propertyOwner->getDefaultValue(name));    }    else    {        if (useConfigFiles && !propertyOwner->isValid(name, value))        {            throw InvalidPropertyValue(name, value);        }        propertyOwner->updateCurrentValue(name, value);    }    if (useConfigFiles)    {        //        // update the new value in the current config file        //        if (!_configFileHandler->updateCurrentValue(name, value, unset))        {            // Failed to update the current value, so roll back.            propertyOwner->updateCurrentValue(name, prevValue);            return false;        }    }    return true;}/**Update planned value of a property.*/Boolean ConfigManager::updatePlannedValue(    const String& name,    const String& value,    Boolean unset){    String prevValue = String::EMPTY;    //    // get property owner object from the config table.    //    ConfigPropertyOwner* propertyOwner;    if (!_propertyTable->ownerTable.lookup(name, propertyOwner))    {        throw UnrecognizedConfigProperty(name);    }    //    // keep a copy of the existing config value    //    prevValue = propertyOwner->getPlannedValue(name);    //    // ask owner to update the planned value to new value    //    if (unset)    {        propertyOwner->updatePlannedValue(name,            propertyOwner->getDefaultValue(name));    }    else    {        if (useConfigFiles && !propertyOwner->isValid(name, value))        {            throw InvalidPropertyValue(name, value);        }        propertyOwner->updatePlannedValue(name, value);    }    if (useConfigFiles)    {        //        // update the new value in the planned config file        //        if (!_configFileHandler->updatePlannedValue(name, value, unset))        {            // Failed to update the planned value, so roll back.            propertyOwner->updatePlannedValue(name, prevValue);            return false;        }    }    return true;}/**Validate the value of a specified property.*/Boolean ConfigManager::validatePropertyValue(    const String& name,    const String& value){    //    // get property owner object from config table    //    ConfigPropertyOwner* propertyOwner;    if (!_propertyTable->ownerTable.lookup(name, propertyOwner))    {        throw UnrecognizedConfigProperty(name);

⌨️ 快捷键说明

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