//---------------------------------------------------------------------------- // // Copyright (C) Intel Corporation, 2007 - 2008. // // File: ConfigFormat.cpp // // Contents: Configures the formats needed to configure the MPS. // // Notes: //---------------------------------------------------------------------------- #include "ConfigFormat.h" #include // Static initialization. ConfigFormats *ConfigFormats::instance_ = NULL; ConfigFormats::ConfigFormats() : format_static_mandatory_(NULL), format_static_optional_(NULL), format_dynamic_mandatory_(NULL), format_dynamic_optional_(NULL) { // Start configuring all the data members // Set format_static_mandatory_ format_static_mandatory_ = new Format(); // Set Network section format_static_mandatory_->addOuter(ACE_TString(NETWORK_SECTION)); format_static_mandatory_->addInner(ACE_TString(NETWORK_SECTION), ACE_TString(AMT_LISTEN_IP_ELEMENT), new Element_Type_Enum(IP_TYPE)); //format_static_mandatory_->addInner(ACE_TString(NETWORK_SECTION), ACE_TString(AMT_LISTEN_IPv6_ELEMENT), // new Element_Type_Enum(IP_TYPE)); format_static_mandatory_->addInner(ACE_TString(NETWORK_SECTION), ACE_TString(AMT_LISTEN_PORT_ELEMENT), new Element_Type_Enum(PORT_TYPE)); format_static_mandatory_->addInner(ACE_TString(NETWORK_SECTION), ACE_TString(MC_SOCKS_LISTEN_IP_ELEMENT), new Element_Type_Enum(IP_TYPE)); format_static_mandatory_->addInner(ACE_TString(NETWORK_SECTION), ACE_TString(MC_SOCKS_LISTEN_PORT_ELEMENT), new Element_Type_Enum(PORT_TYPE)); //format_static_mandatory_->addInner(ACE_TString(NETWORK_SECTION), ACE_TString(MC_SOCKS_LISTEN_INET_ELEMENT), // new Element_Type_Enum(INET_TYPE)); format_static_mandatory_->addInner(ACE_TString(NETWORK_SECTION), ACE_TString(MC_HTTP_LISTEN_PORT_ELEMENT), new Element_Type_Enum(PORT_TYPE)); // Set AuthenticateConnections section format_static_mandatory_->addOuter(ACE_TString(AMT_AUTHENTICATE_SECTION)); format_static_mandatory_->addInner(ACE_TString(AMT_AUTHENTICATE_SECTION), ACE_TString(NEED_AUTHENTICATE_ELEMENT), new Element_Type_Enum(BOOL_TYPE)); // Set Socks Authenticate section format_static_mandatory_->addOuter(ACE_TString(SOCKS_AUTHENTICATE_SECTION)); format_static_mandatory_->addInner(ACE_TString(SOCKS_AUTHENTICATE_SECTION), ACE_TString(NEED_AUTHENTICATE_ELEMENT), new Element_Type_Enum(BOOL_TYPE)); // Set SOAP Authenticate section format_static_mandatory_->addOuter(ACE_TString(SOAP_AUTHENTICATE_SECTION)); format_static_mandatory_->addInner(ACE_TString(SOAP_AUTHENTICATE_SECTION), ACE_TString(NEED_AUTHENTICATE_ELEMENT), new Element_Type_Enum(BOOL_TYPE)); // Set MC Authenticate section format_static_mandatory_->addOuter(ACE_TString(NOTIFICATION_AUTHENTICATION_SECTION)); format_static_mandatory_->addInner(ACE_TString(NOTIFICATION_AUTHENTICATION_SECTION), ACE_TString(NEED_NOTIFICATION_AUTH_ELEMENT), new Element_Type_Enum(BOOL_TYPE)); // Set Filtering section format_static_mandatory_->addOuter(ACE_TString(FILTERING_SECTION)); format_static_mandatory_->addInner(ACE_TString(FILTERING_SECTION), ACE_TString(FILTER_UNAUTHORIZED_SERVERS_ELEMENT), new Element_Type_Enum(BOOL_TYPE)); // Set format_static_optional_ format_static_optional_ = new Format(); //Set Network section format_static_optional_->addOuter(ACE_TString(NETWORK_SECTION)); format_static_optional_->addInner(ACE_TString(NETWORK_SECTION), ACE_TString(MC_HTTP_LISTEN_IP_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, MC_HTTP_LISTEN_IP_DEFAULT)); format_static_optional_->addInner(ACE_TString(NETWORK_SECTION), ACE_TString(MC_SOAP_LISTEN_IP_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, MC_SOAP_LISTEN_IP_DEFAULT)); format_static_optional_->addInner(ACE_TString(NETWORK_SECTION), ACE_TString(MC_SOAP_LISTEN_PORT_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, MC_SOAP_LISTEN_PORT_DEFAULT)); // Set Logger section format_static_optional_->addOuter(ACE_TString(LOGGER_SECTION)); format_static_optional_->addInner(ACE_TString(LOGGER_SECTION), ACE_TString(LOG_FILE_PATH_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, ACE_TString(LOG_FILE_PATH_DEFAULT))); format_static_optional_->addInner(ACE_TString(LOGGER_SECTION), ACE_TString(LOG_FILE_NAME_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, ACE_TString(LOG_FILE_NAME_DEFAULT))); format_static_optional_->addInner(ACE_TString(LOGGER_SECTION), ACE_TString(LOG_FILE_SIZE_ELEMENT), new Element_Type_Enum_and_Default_Val(UNSIGNED_INT_TYPE, ACE_TString(LOG_FILE_SIZE_DEFAULT))); format_static_optional_->addInner(ACE_TString(LOGGER_SECTION), ACE_TString(LOG_FILE_MAX_FILES_ELEMENT), new Element_Type_Enum_and_Default_Val(UNSIGNED_INT_TYPE, ACE_TString(LOG_FILE_MAX_FILES_DEFAULT))); // Set AuthenticateConnections section format_static_optional_->addOuter(ACE_TString(AMT_AUTHENTICATE_SECTION)); format_static_optional_->addInner(ACE_TString(AMT_AUTHENTICATE_SECTION), ACE_TString(DLL_NAME_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, ACE_TString(AMT_DLL_NAME_DEFAULT))); format_static_optional_->addInner(ACE_TString(AMT_AUTHENTICATE_SECTION), ACE_TString(DLL_PARAMETERS_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, ACE_TString(AMT_DLL_PARAMETERS_DEFAULT))); // Set Socks Authenticate section format_static_optional_->addOuter(ACE_TString(SOCKS_AUTHENTICATE_SECTION)); format_static_optional_->addInner(ACE_TString(SOCKS_AUTHENTICATE_SECTION), ACE_TString(DLL_NAME_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, ACE_TString(SOCKS_DLL_NAME_DEFAULT))); format_static_optional_->addInner(ACE_TString(SOCKS_AUTHENTICATE_SECTION), ACE_TString(DLL_PARAMETERS_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, ACE_TString(SOCKS_DLL_PARAMETERS_DEFAULT))); // Set Soap Authenticate section format_static_optional_->addOuter(ACE_TString(SOAP_AUTHENTICATE_SECTION)); format_static_optional_->addInner(ACE_TString(SOAP_AUTHENTICATE_SECTION), ACE_TString(DLL_NAME_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, ACE_TString(SOAP_DLL_NAME_DEFAULT))); format_static_optional_->addInner(ACE_TString(SOAP_AUTHENTICATE_SECTION), ACE_TString(DLL_PARAMETERS_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, ACE_TString(SOAP_DLL_PARAMETERS_DEFAULT))); // Set MC Authenticate section format_static_optional_->addOuter(ACE_TString(NOTIFICATION_AUTHENTICATION_SECTION)); format_static_optional_->addInner(ACE_TString(NOTIFICATION_AUTHENTICATION_SECTION), ACE_TString(USERNAME_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, ACE_TString(NOTIFICATION_USERNAME_DEFAULT))); format_static_optional_->addInner(ACE_TString(NOTIFICATION_AUTHENTICATION_SECTION), ACE_TString(PASSWORD_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, ACE_TString(NOTIFICATION_PASSWORD_DEFAULT))); // Set Advanced section format_static_optional_->addOuter(ACE_TString(ADVANCED_SECTION)); format_static_optional_->addInner(ACE_TString(ADVANCED_SECTION), ACE_TString(THREAD_NUMBER_ELEMENT), new Element_Type_Enum_and_Default_Val(UNSIGNED_INT_TYPE, ACE_TString(THREAD_NUMBER_DEFAULT))); format_static_optional_->addInner(ACE_TString(ADVANCED_SECTION), ACE_TString(MAXIMUM_WINDOW_SIZE_ELEMENT), new Element_Type_Enum_and_Default_Val(UNSIGNED_INT_TYPE, ACE_TString(MAXIMUM_WINDOW_SIZE_DEFAULT))); format_static_optional_->addInner(ACE_TString(ADVANCED_SECTION), ACE_TString(MINIMUM_WINDOW_SIZE_ELEMENT), new Element_Type_Enum_and_Default_Val(UNSIGNED_INT_TYPE, ACE_TString(MINIMUM_WINDOW_SIZE_DEFAULT))); format_static_optional_->addInner(ACE_TString(ADVANCED_SECTION), ACE_TString(MAX_QUEUE_SIZE_ELEMENT), new Element_Type_Enum_and_Default_Val(UNSIGNED_INT_TYPE, ACE_TString(MAX_QUEUE_SIZE_DEFAULT))); format_static_optional_->addInner(ACE_TString(ADVANCED_SECTION), ACE_TString(MAX_CHANNELS_ELEMENT), new Element_Type_Enum_and_Default_Val(UNSIGNED_INT_TYPE, ACE_TString(MAX_CHANNELS_DEFAULT))); format_static_optional_->addInner(ACE_TString(ADVANCED_SECTION), ACE_TString(MAX_TUNNEL_TIMEOUT_ELEMENT), new Element_Type_Enum_and_Default_Val(TIME_T_TYPE, ACE_TString(MAX_TUNNEL_TIMEOUT_DEFAULT))); format_static_optional_->addInner(ACE_TString(ADVANCED_SECTION), ACE_TString(MAX_BUFFER_SIZE_ELEMENT), new Element_Type_Enum_and_Default_Val(UNSIGNED_INT_TYPE, ACE_TString(MAX_BUFFER_SIZE_DEFAULT))); // Set Files section format_static_optional_->addOuter(ACE_TString(FILES_SECTION)); format_static_optional_->addInner(ACE_TString(FILES_SECTION), ACE_TString(NOTIFICATION_LIST_ELEMENT), new Element_Type_Enum_and_Default_Val(MC_LIST_TYPE, NOTIFICATION_LIST_DEFAULT)); format_static_optional_->addInner(ACE_TString(FILES_SECTION), ACE_TString(AUTHORIZED_SERVERS_LIST_ELEMENT), new Element_Type_Enum_and_Default_Val(AUTHERIZED_SERVERS_LIST_TYPE, AUTHORIZED_SERVERS_LIST_DEFAULT)); // Set Management Interface section format_static_optional_->addOuter(ACE_TString(MANAGEMENT_INTERFACE_SECTION)); format_static_optional_->addInner(ACE_TString(MANAGEMENT_INTERFACE_SECTION), ACE_TString(MAX_ENUM_ELEMENTS_ELEMENT), new Element_Type_Enum_and_Default_Val(UNSIGNED_INT_TYPE, MAX_ENUM_ELEMENTS_DEFAULT)); format_static_optional_->addInner(ACE_TString(MANAGEMENT_INTERFACE_SECTION), ACE_TString(ENUM_CTX_TIMEOUT_ELEMENT), new Element_Type_Enum_and_Default_Val(UNSIGNED_INT_TYPE, ENUM_CTX_TIMEOUT_DEFAULT)); format_static_optional_->addInner(ACE_TString(MANAGEMENT_INTERFACE_SECTION), ACE_TString(MAX_CONCURRENT_ENUMS_ELEMENT), new Element_Type_Enum_and_Default_Val(UNSIGNED_INT_TYPE, MAX_CONCURRENT_ENUMS_DEFAULT)); format_static_optional_->addInner(ACE_TString(MANAGEMENT_INTERFACE_SECTION), ACE_TString(MAX_SUBSCRIBERS_ELEMENT), new Element_Type_Enum_and_Default_Val(UNSIGNED_INT_TYPE, MAX_SUBSCRIBERS_DEFAULT)); // Set format_dynamic_mandatory_ format_dynamic_mandatory_ = new Format(); // Set format_dynamic_optional_ format_dynamic_optional_ = new Format(); // Set Logger section format_dynamic_optional_->addOuter(ACE_TString(LOGGER_SECTION)); format_dynamic_optional_->addInner(ACE_TString(LOGGER_SECTION), ACE_TString(TRACE_LEVEL_ELEMENT), new Element_Type_Enum_and_Default_Val(STRING_TYPE, TRACE_LEVEL_DEFAULT)); } ConfigFormats::~ConfigFormats() { cleanFormat(format_static_mandatory_); delete format_static_mandatory_; format_static_mandatory_ = NULL; cleanFormat(format_static_optional_); delete format_static_optional_; format_static_optional_ = NULL; cleanFormat(format_dynamic_mandatory_); delete format_dynamic_mandatory_; format_dynamic_mandatory_ = NULL; cleanFormat(format_dynamic_optional_); delete format_dynamic_optional_; format_dynamic_optional_ = NULL; } void ConfigFormats::cleanFormat(Format * format) { ACE_TString sectionName, elementName; auto_ptr hashOuterP_begin(format->beginOuters()); auto_ptr hashOuterP_end(format->endOuters()); if ((hashOuterP_begin.get() == NULL) || (hashOuterP_end.get() == NULL)) { return; } Format::constOuterIter hashOuterIter = * hashOuterP_begin; for (; hashOuterIter != *hashOuterP_end; hashOuterIter++) { auto_ptr hashInnerIterP_begin (format->beginInners(hashOuterIter->first)); auto_ptr hashInnerIterP_end (format->endInners(hashOuterIter->first)); sectionName = hashOuterIter->first; // Do not exit, it may happen that next iteration will work if ((hashInnerIterP_begin.get() != NULL) && (hashInnerIterP_end.get() != NULL)) { Format::constInnerIter hashInnerIter = * hashInnerIterP_begin; for (; hashInnerIter != *hashInnerIterP_end; hashInnerIter++) { elementName = hashInnerIter->first; Element_Type_Enum * element = NULL; format->getValue(sectionName, elementName, &element); delete element; } } } format->cleanHash(); } const ConfigFormats * ConfigFormats::instance() { if (instance_ == NULL) { instance_ = new ConfigFormats(); } return instance_; } const Format * ConfigFormats::getFormat(FORMAT_TYPES type) const { switch(type) { case STATIC_OPTIONAL: return format_static_optional_; case DYNAMIC_OPTIONAL: return format_dynamic_optional_; case STATIC_MANDATORY: return format_static_mandatory_; case DYNAMIC_MANDATORY: return format_dynamic_mandatory_; } ACE_ERROR ((MY_ERROR ACE_TEXT ("ConfigFormats have been given a bad format to retrieve: %d\n"), type)); return NULL; }