(file) Return to ConfigManager.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Config

  1 martin 1.106 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.107 //
  3 martin 1.106 // Licensed to The Open Group (TOG) under one or more contributor license
  4              // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5              // this work for additional information regarding copyright ownership.
  6              // Each contributor licenses this file to you under the OpenPegasus Open
  7              // Source License; you may not use this file except in compliance with the
  8              // License.
  9 martin 1.107 //
 10 martin 1.106 // Permission is hereby granted, free of charge, to any person obtaining a
 11              // copy of this software and associated documentation files (the "Software"),
 12              // to deal in the Software without restriction, including without limitation
 13              // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14              // and/or sell copies of the Software, and to permit persons to whom the
 15              // Software is furnished to do so, subject to the following conditions:
 16 martin 1.107 //
 17 martin 1.106 // The above copyright notice and this permission notice shall be included
 18              // in all copies or substantial portions of the Software.
 19 martin 1.107 //
 20 martin 1.106 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.107 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.106 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23              // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24              // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25              // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26              // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.107 //
 28 martin 1.106 //////////////////////////////////////////////////////////////////////////
 29 mike   1.2   //
 30              //%////////////////////////////////////////////////////////////////////////////
 31              
 32              
 33              /////////////////////////////////////////////////////////////////////////////
 34 chip   1.68  //  ConfigManager
 35 mike   1.2   /////////////////////////////////////////////////////////////////////////////
 36              
 37 kumpf  1.20  #include <Pegasus/Common/Tracer.h>
 38 thilo.boehm 1.87  #include <Pegasus/Common/Logger.h>
 39 kumpf       1.12  #include <Pegasus/Common/PegasusVersion.h>
 40 tony        1.32  #include <Pegasus/Common/FileSystem.h>
 41 kumpf       1.81  #include <Pegasus/Common/Constants.h>
 42 kumpf       1.12  
 43 mike        1.2   #include "ConfigExceptions.h"
 44                   #include "ConfigManager.h"
 45                   
 46                   PEGASUS_NAMESPACE_BEGIN
 47                   
 48                   /////////////////////////////////////////////////////////////////////////////
 49                   //
 50                   //  When a new property owner is created be sure to create a static
 51                   //  object of the new property owner.
 52                   //
 53                   /////////////////////////////////////////////////////////////////////////////
 54                   
 55 kumpf       1.96  TracePropertyOwner ConfigManager::traceOwner;
 56                   LogPropertyOwner ConfigManager::logOwner;
 57                   DefaultPropertyOwner ConfigManager::defaultOwner;
 58                   SecurityPropertyOwner ConfigManager::securityOwner;
 59                   RepositoryPropertyOwner ConfigManager::repositoryOwner;
 60                   ShutdownPropertyOwner ConfigManager::shutdownOwner;
 61                   FileSystemPropertyOwner ConfigManager::fileSystemOwner;
 62                   ProviderDirPropertyOwner ConfigManager::providerDirOwner;
 63                   NormalizationPropertyOwner ConfigManager::normalizationOwner;
 64                   
 65 mike        1.2   
 66                   /////////////////////////////////////////////////////////////////////////////
 67                   //
 68 chip        1.68  //   When a new property is created be sure to add the new property name
 69 kumpf       1.10  //   and the owner object to the OwnerEntry table below.
 70 mike        1.2   //
 71                   /////////////////////////////////////////////////////////////////////////////
 72                   
 73 kumpf       1.10  struct OwnerEntry
 74                   {
 75                       const char* propertyName;
 76                       ConfigPropertyOwner* propertyOwner;
 77                   };
 78                   
 79 kumpf       1.14  static struct OwnerEntry _properties[] =
 80 mike        1.2   {
 81 kumpf       1.88      {"traceLevel",
 82 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::traceOwner},
 83 kumpf       1.88      {"traceComponents",
 84 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::traceOwner},
 85 kumpf       1.88      {"traceFilePath",
 86 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::traceOwner},
 87 r.kieninger 1.98      {"traceFacility",
 88                            (ConfigPropertyOwner*)&ConfigManager::traceOwner},
 89 thilo.boehm 1.102     {"traceMemoryBufferKbytes",
 90                            (ConfigPropertyOwner*)&ConfigManager::traceOwner},
 91 konrad.r    1.71  #if !defined(PEGASUS_USE_SYSLOGS)
 92 kumpf       1.88      {"logdir",
 93 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::logOwner},
 94 mreddy      1.103     {"maxLogFileSizeKBytes",
 95                            (ConfigPropertyOwner*)&ConfigManager::logOwner},
 96 konrad.r    1.71  #endif
 97 kumpf       1.88      {"logLevel",
 98 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::logOwner},
 99 kumpf       1.88      {"enableHttpConnection",
100 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
101 kumpf       1.88      {"enableHttpsConnection",
102 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
103 kumpf       1.88      {"httpPort",
104 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
105 kumpf       1.88      {"httpsPort",
106 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
107 kumpf       1.88      {"daemon",
108 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
109 s.kodali    1.104 #ifdef PEGASUS_ENABLE_SLP
110 kumpf       1.88      {"slp",
111 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
112 s.kodali    1.104 #endif
113 kumpf       1.88      {"enableAssociationTraversal",
114 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
115 kumpf       1.88      {"enableIndicationService",
116 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
117 kumpf       1.88      {"enableAuthentication",
118 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
119 kumpf       1.88      {"enableNamespaceAuthorization",
120 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
121 kumpf       1.88      {"httpAuthType",
122 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
123 kumpf       1.88      {"passwordFilePath",
124 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
125 kumpf       1.88      {"sslCertificateFilePath",
126 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
127 kumpf       1.88      {"sslKeyFilePath",
128 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
129 kumpf       1.88      {"sslTrustStore",
130 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
131 sushma.fernandes 1.79  #ifdef PEGASUS_ENABLE_SSL_CRL_VERIFICATION
132 kumpf            1.88      {"crlStore",
133 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
134 sushma.fernandes 1.79  #endif
135 kumpf            1.88      {"sslClientVerificationMode",
136 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
137 kumpf            1.88      {"sslTrustStoreUserName",
138 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
139 gerarda          1.42  #ifdef PEGASUS_KERBEROS_AUTHENTICATION
140 kumpf            1.88      {"kerberosServiceName",
141 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
142 gerarda          1.42  #endif
143 thilo.boehm      1.94  #ifdef PEGASUS_OS_ZOS
144                            {"enableCFZAPPLID",
145 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
146 thilo.boehm      1.94  #endif
147 kumpf            1.88      {"repositoryIsDefaultInstanceProvider",
148 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::repositoryOwner},
149 kumpf            1.88      {"enableBinaryRepository",
150 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::repositoryOwner},
151 kumpf            1.88      {"shutdownTimeout",
152 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::shutdownOwner},
153 kumpf            1.88      {"repositoryDir",
154 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::fileSystemOwner},
155 b.whiteley       1.97      {"providerManagerDir",
156                                 (ConfigPropertyOwner*)&ConfigManager::fileSystemOwner},
157 kumpf            1.88      {"providerDir",
158 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::providerDirOwner},
159 kumpf            1.88      {"enableRemotePrivilegedUserAccess",
160 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
161 kumpf            1.88      {"enableSubscriptionsForNonprivilegedUsers",
162 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
163 kumpf            1.57  #ifdef PEGASUS_ENABLE_USERGROUP_AUTHORIZATION
164 kumpf            1.88      {"authorizedUserGroups",
165 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
166 kumpf            1.57  #endif
167 kumpf            1.88      {"messageDir",
168 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::fileSystemOwner},
169 chip             1.68  #ifdef PEGASUS_ENABLE_OBJECT_NORMALIZATION
170 kumpf            1.88      {"enableNormalization",
171 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::normalizationOwner},
172 kumpf            1.88      {"excludeModulesFromNormalization",
173 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::normalizationOwner},
174 chip             1.68  #endif
175 kumpf            1.88      {"forceProviderProcesses",
176 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
177 kumpf            1.88      {"maxProviderProcesses",
178 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
179 kumpf            1.91  #ifdef PEGASUS_ENABLE_AUDIT_LOGGER
180 kumpf            1.88      {"enableAuditLog",
181 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
182 yi.zhou          1.86  #endif
183 kumpf            1.88      {"socketWriteTimeout",
184 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
185 dave.sudlik      1.95      {"idleConnectionTimeout",
186 venkat.puvvada   1.113          (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
187                            {"maxFailedProviderModuleRestarts",
188 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner}
189 mike             1.2   };
190                        
191 kumpf            1.14  const Uint32 NUM_PROPERTIES = sizeof(_properties) / sizeof(struct OwnerEntry);
192 kumpf            1.10  
193                        
194                        /////////////////////////////////////////////////////////////////////////////
195                        //
196                        //   To use a fixed value for a property rather than delegating to a property
197                        //   owner, add the property to the FixedValueEntry table below.  An entry in
198                        //   the OwnerEntry table above for this same property will be initialized
199                        //   and given the (fixed) initial current value, but will thereafter be
200                        //   ignored.
201                        //
202                        //   Fixed values are only returned by getDefaultValue(), getCurrentValue(),
203                        //   and getPlannedValue().  All other methods will treat fixed properties as
204                        //   unrecognized properties.
205                        //
206                        /////////////////////////////////////////////////////////////////////////////
207                        
208                        struct FixedValueEntry
209                        {
210                            const char* propertyName;
211                            const char* fixedValue;
212                        };
213 kumpf            1.10  
214 kumpf            1.14  static struct FixedValueEntry _fixedValues[] =
215 kumpf            1.10  {
216 kumpf            1.28  #include "FixedPropertyTable.h"
217 kumpf            1.10  };
218                        
219 chip             1.68  const Uint32 NUM_FIXED_PROPERTIES =
220 kumpf            1.14      sizeof(_fixedValues) / sizeof(struct FixedValueEntry);
221 kumpf            1.10  
222 mike             1.2   
223 kumpf            1.6   /**
224 kumpf            1.88      Initialize the default PEGASUS_HOME location, the default is set to the
225                            current directory.
226 kumpf            1.6   */
227 kumpf            1.88  const String ConfigManager::PEGASUS_HOME_DEFAULT = ".";
228 mike             1.2   
229 kumpf            1.6   String ConfigManager::_pegasusHome = PEGASUS_HOME_DEFAULT;
230 mike             1.2   
231 kumpf            1.59  //
232 kumpf            1.96  // The singleton ConfigManager instance
233 kumpf            1.59  //
234 kumpf            1.96  AutoPtr<ConfigManager> ConfigManager::_instance;
235 mike             1.2   
236                        
237                        /** Constructor. */
238 kumpf            1.59  ConfigManager::ConfigManager()
239                            : useConfigFiles(false)
240 mike             1.2   {
241                            //
242                            // Initialize the instance variables
243                            //
244 a.arora          1.58      _propertyTable.reset(new PropertyTable);
245 mike             1.2   
246                            //
247                            // Initialize the property owners
248                            //
249 kumpf            1.10      _initPropertyTable();
250 mike             1.2   }
251                        
252 konrad.r         1.75  /**
253 kumpf            1.59      Get a reference to the singleton ConfigManager instance.  If no
254                            ConfigManager instance exists, construct one.
255 mike             1.2   */
256 chip             1.68  ConfigManager* ConfigManager::getInstance()
257 mike             1.2   {
258 kumpf            1.96      if (!_instance.get())
259 mike             1.2       {
260 kumpf            1.96          _instance.reset(new ConfigManager());
261 mike             1.2       }
262 kumpf            1.96      return _instance.get();
263 mike             1.2   }
264                        
265                        
266 chip             1.68  /**
267 kumpf            1.59      Initialize the current value of a config property
268                        */
269                        Boolean ConfigManager::initCurrentValue(
270                            const String& propertyName,
271                            const String& propertyValue)
272                        {
273                            ConfigPropertyOwner* propertyOwner = 0;
274 thilo.boehm      1.109     Boolean success = true;
275 kumpf            1.59  
276                            //
277                            // get property owner object from the config table.
278                            //
279                            if (!_propertyTable->ownerTable.lookup(propertyName, propertyOwner))
280                            {
281 chip             1.68          throw UnrecognizedConfigProperty(propertyName);
282 kumpf            1.59      }
283                        
284 kumpf            1.73      if (useConfigFiles && !propertyOwner->isValid(propertyName, propertyValue))
285                            {
286                                throw InvalidPropertyValue(propertyName, propertyValue);
287                            }
288                        
289                            //
290                            // update the value with the property owner
291                            //
292                            propertyOwner->initCurrentValue(propertyName, propertyValue);
293                        
294                            if (useConfigFiles)
295 kumpf            1.59      {
296 thilo.boehm      1.109         try
297                                {
298                                    // update the value in the current config file
299                                    success = _configFileHandler->updateCurrentValue(
300 venkat.puvvada   1.111                           propertyName,
301                                                  propertyValue,
302                                                  String(),
303 venkat.puvvada   1.112                           0,
304 venkat.puvvada   1.111                           false);
305 thilo.boehm      1.109         }
306                                catch (Exception& e)
307                                {
308                                    throw FailedSaveProperties(e.getMessage());
309                                }
310 kumpf            1.59      }
311 thilo.boehm      1.109     return success;
312 kumpf            1.59  }
313                        
314 chip             1.68  /**
315 kumpf            1.88      Update current value of a property.
316 mike             1.2   */
317                        Boolean ConfigManager::updateCurrentValue(
318 chip             1.68      const String& name,
319 kumpf            1.13      const String& value,
320 venkat.puvvada   1.111     const String& userName,
321 venkat.puvvada   1.112     Uint32 timeoutSeconds,
322 kumpf            1.13      Boolean unset)
323 mike             1.2   {
324 kumpf            1.90      String prevValue;
325 mike             1.2   
326                            //
327                            // get property owner object from the config table.
328                            //
329                            ConfigPropertyOwner* propertyOwner;
330                        
331 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
332 mike             1.2       {
333 chip             1.68          throw UnrecognizedConfigProperty(name);
334 mike             1.2       }
335                        
336 kumpf            1.73      //
337                            // keep a copy of the existing config value
338                            //
339                            prevValue = propertyOwner->getCurrentValue(name);
340                        
341                            //
342                            // ask owner to update the current value
343                            //
344                            if (unset)
345 mike             1.2       {
346 venkat.puvvada   1.111         propertyOwner->updateCurrentValue(
347                                    name,
348                                    propertyOwner->getDefaultValue(name),
349 venkat.puvvada   1.112             userName,
350                                    timeoutSeconds);
351 kumpf            1.73      }
352                            else
353                            {
354                                if (useConfigFiles && !propertyOwner->isValid(name, value))
355                                {
356                                    throw InvalidPropertyValue(name, value);
357                                }
358                        
359 venkat.puvvada   1.112         propertyOwner->updateCurrentValue(
360                                    name, value, userName, timeoutSeconds);
361 kumpf            1.73      }
362 mike             1.2   
363 kumpf            1.73      if (useConfigFiles)
364                            {
365 thilo.boehm      1.109         try
366                                {
367                                    //
368                                    // update the new value in the current config file
369                                    //
370 venkat.puvvada   1.111             if (!_configFileHandler->updateCurrentValue(
371 venkat.puvvada   1.112                 name, value, userName, timeoutSeconds, unset))
372 thilo.boehm      1.109             {
373                                        // Failed to update the current value, so roll back.
374 venkat.puvvada   1.112                 propertyOwner->updateCurrentValue(
375                                            name, prevValue, userName, timeoutSeconds);
376 thilo.boehm      1.109                 return false;
377                                    }
378                                }
379                                catch (Exception& e)
380 mike             1.2           {
381 kumpf            1.73              // Failed to update the current value, so roll back.
382 venkat.puvvada   1.112             propertyOwner->updateCurrentValue(
383                                        name, prevValue, userName, timeoutSeconds);
384 thilo.boehm      1.109             throw FailedSaveProperties(e.getMessage());
385 mike             1.2           }
386                            }
387 kumpf            1.29  
388 kumpf            1.59      return true;
389 mike             1.2   }
390                        
391                        
392 chip             1.68  /**
393 mike             1.2   Update planned value of a property.
394                        */
395                        Boolean ConfigManager::updatePlannedValue(
396 chip             1.68      const String& name,
397 kumpf            1.13      const String& value,
398                            Boolean unset)
399 mike             1.2   {
400 kumpf            1.90      String prevValue;
401 mike             1.2   
402                            //
403                            // get property owner object from the config table.
404                            //
405                            ConfigPropertyOwner* propertyOwner;
406                        
407 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
408 mike             1.2       {
409 chip             1.68          throw UnrecognizedConfigProperty(name);
410 mike             1.2       }
411                        
412 kumpf            1.73      //
413                            // keep a copy of the existing config value
414                            //
415                            prevValue = propertyOwner->getPlannedValue(name);
416                        
417                            //
418                            // ask owner to update the planned value to new value
419                            //
420                            if (unset)
421                            {
422                                propertyOwner->updatePlannedValue(name,
423                                    propertyOwner->getDefaultValue(name));
424                            }
425                            else
426 mike             1.2       {
427 kumpf            1.73          if (useConfigFiles && !propertyOwner->isValid(name, value))
428                                {
429                                    throw InvalidPropertyValue(name, value);
430                                }
431                        
432                                propertyOwner->updatePlannedValue(name, value);
433                            }
434 mike             1.2   
435 kumpf            1.73      if (useConfigFiles)
436                            {
437 thilo.boehm      1.109         try
438                                {
439                                    //
440                                    // update the new value in the planned config file
441                                    //
442                                    if (!_configFileHandler->updatePlannedValue(name, value, unset))
443                                    {
444                                        // Failed to update the planned value, so roll back.
445                                        propertyOwner->updatePlannedValue(name, prevValue);
446                                        return false;
447                                    }
448                                }
449                                catch (Exception& e)
450 kumpf            1.13          {
451 kumpf            1.73              // Failed to update the planned value, so roll back.
452                                    propertyOwner->updatePlannedValue(name, prevValue);
453 thilo.boehm      1.109             throw FailedSaveProperties(e.getMessage());
454 mike             1.2           }
455                            }
456 kumpf            1.29  
457 kumpf            1.59      return true;
458 mike             1.2   }
459                        
460                        
461 chip             1.68  /**
462 mike             1.2   Validate the value of a specified property.
463                        */
464                        Boolean ConfigManager::validatePropertyValue(
465 chip             1.68      const String& name,
466 mike             1.2       const String& value)
467                        {
468                            //
469                            // get property owner object from config table
470                            //
471                            ConfigPropertyOwner* propertyOwner;
472                        
473 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
474 mike             1.2       {
475 chip             1.68          throw UnrecognizedConfigProperty(name);
476 mike             1.2       }
477                        
478 kumpf            1.88      return propertyOwner->isValid(name, value);
479 mike             1.2   }
480                        
481                        /**
482                        Get default value of the specified property.
483                        */
484 aruran.ms        1.77  String ConfigManager::getDefaultValue(const String& name) const
485 mike             1.2   {
486                            //
487 kumpf            1.10      // Check for a property with a fixed value
488                            //
489                            const char* fixedValue;
490                        
491                            if (_propertyTable->fixedValueTable.lookup(name, fixedValue))
492                            {
493                                return fixedValue;
494                            }
495                        
496                            //
497 mike             1.2       // get property owner object from config table
498                            //
499                            ConfigPropertyOwner* propertyOwner;
500                        
501 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
502 mike             1.2       {
503                                throw UnrecognizedConfigProperty(name);
504                            }
505                        
506 kumpf            1.88      return propertyOwner->getDefaultValue(name);
507 mike             1.2   }
508                        
509 chip             1.68  /**
510 kumpf            1.88      Get current value of the specified property.
511 mike             1.2   */
512 aruran.ms        1.77  String ConfigManager::getCurrentValue(const String& name) const
513 mike             1.2   {
514                            //
515 kumpf            1.10      // Check for a property with a fixed value
516                            //
517                            const char* fixedValue;
518                        
519                            if (_propertyTable->fixedValueTable.lookup(name, fixedValue))
520                            {
521                                return fixedValue;
522                            }
523                        
524                            //
525 mike             1.2       // get property owner object from config table
526                            //
527                            ConfigPropertyOwner* propertyOwner;
528                        
529 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
530 mike             1.2       {
531 chip             1.68          throw UnrecognizedConfigProperty(name);
532 mike             1.2       }
533                        
534 kumpf            1.88      return propertyOwner->getCurrentValue(name);
535 mike             1.2   }
536                        
537                        
538 chip             1.68  /**
539 mike             1.2   Get planned value of the specified property.
540                        */
541 aruran.ms        1.77  String ConfigManager::getPlannedValue(const String& name) const
542 mike             1.2   {
543                            //
544 kumpf            1.10      // Check for a property with a fixed value
545                            //
546                            const char* fixedValue;
547                        
548                            if (_propertyTable->fixedValueTable.lookup(name, fixedValue))
549                            {
550                                return fixedValue;
551                            }
552                        
553                            //
554 mike             1.2       // get property owner object from config table
555                            //
556                            ConfigPropertyOwner* propertyOwner;
557                        
558 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
559 mike             1.2       {
560 chip             1.68          throw UnrecognizedConfigProperty(name);
561 mike             1.2       }
562                        
563 kumpf            1.88      return propertyOwner->getPlannedValue(name);
564 mike             1.2   }
565                        
566                        
567 chip             1.68  /**
568 mike             1.2   Get all the attributes of the specified property.
569                        */
570                        void ConfigManager::getPropertyInfo(
571 chip             1.68      const String& name,
572 aruran.ms        1.77      Array<String>& propertyInfo) const
573 mike             1.2   {
574                            //
575                            // get property owner object from config table
576                            //
577                            ConfigPropertyOwner* propertyOwner;
578                        
579 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
580 mike             1.2       {
581 chip             1.68          throw UnrecognizedConfigProperty(name);
582 mike             1.2       }
583                        
584                            propertyOwner->getPropertyInfo(name, propertyInfo);
585                        }
586                        
587                        
588 chip             1.68  /**
589 mike             1.2   Get a list of all property names.
590                        */
591 kumpf            1.59  void ConfigManager::getAllPropertyNames(
592                            Array<String>& propertyNames,
593 aruran.ms        1.77      Boolean includeHiddenProperties) const
594 mike             1.2   {
595 kumpf            1.41      Array<String> propertyInfo;
596 mike             1.2       propertyNames.clear();
597                        
598 kumpf            1.10      for (OwnerTable::Iterator i = _propertyTable->ownerTable.start(); i; i++)
599 mike             1.2       {
600 kumpf            1.59          if (includeHiddenProperties)
601 kumpf            1.41          {
602                                    propertyNames.append(i.key());
603                                }
604 kumpf            1.59          else
605                                {
606                                    //
607                                    // Check if property is to be externally visible or not.
608                                    // If the property should not be externally visible do not list the
609                                    // property information.
610                                    //
611                                    propertyInfo.clear();
612                                    getPropertyInfo(i.key(), propertyInfo);
613                        
614                                    if (propertyInfo[5] == STRING_TRUE)
615                                    {
616                                        propertyNames.append(i.key());
617                                    }
618                                }
619 mike             1.2       }
620                        }
621                        
622                        
623 chip             1.68  /**
624 kumpf            1.88      Merge the config properties from the specified planned config file
625                            with the properties in the specified current config file.
626 mike             1.2   */
627                        void ConfigManager::mergeConfigFiles(
628 chip             1.68      const String& currentFile,
629 mike             1.2       const String& plannedFile)
630                        {
631 kumpf            1.59      PEGASUS_ASSERT(useConfigFiles);
632                        
633 kumpf            1.73      _configFileHandler.reset(new ConfigFileHandler(currentFile, plannedFile));
634 mike             1.2   
635 mateus.baur      1.89      //
636                            // copy the contents of planned config file over
637                            // the current config file
638                            //
639                            _configFileHandler->copyPlannedFileOverCurrentFile();
640                        
641 kumpf            1.73      _loadConfigProperties();
642 mike             1.2   }
643                        
644                        
645 chip             1.68  /**
646 kumpf            1.88      Merge the config properties from the default planned config file
647                            with the properties in the default current config file.
648 mike             1.2   */
649                        void ConfigManager::mergeConfigFiles()
650                        {
651 kumpf            1.59      PEGASUS_ASSERT(useConfigFiles);
652                        
653 kumpf            1.73      _configFileHandler.reset(new ConfigFileHandler());
654 mike             1.2   
655 mateus.baur      1.89      //
656                            // copy the contents of planned config file over
657                            // the current config file
658                            //
659                            _configFileHandler->copyPlannedFileOverCurrentFile();
660                        
661                            _loadConfigProperties();
662                        }
663                        
664                        
665                        /**
666                        Load the config properties from the current and planned files.
667                        */
668                        void ConfigManager::loadConfigFiles()
669                        {
670                            PEGASUS_ASSERT(useConfigFiles);
671                        
672                            _configFileHandler.reset(new ConfigFileHandler());
673                        
674 kumpf            1.73      _loadConfigProperties();
675 mike             1.2   }
676                        
677                        
678 chip             1.68  /**
679 kumpf            1.88      Merge config properties specified on the command line
680 mike             1.2   */
681                        void ConfigManager::mergeCommandLine(int& argc, char**& argv)
682                        {
683                            // Remove the command name from the command line
684 kumpf            1.3       if (argc > 0)
685                            {
686                                memmove(&argv[0], &argv[1], (argc) * sizeof(char*));
687                                argc--;
688                            }
689 mike             1.2   
690                            //
691                            //  Merge properties from the command line
692                            //
693 kumpf            1.9       for (Sint32 i = 0; i < argc; )
694 mike             1.2       {
695                                const char* arg = argv[i];
696                        
697 kumpf            1.34          if (*arg == '-')
698                                {
699                                    throw UnrecognizedCommandLineOption();
700                                }
701                        
702 thilo.boehm      1.109         // Set porperty with command line value.
703 tony             1.33          if (!_initPropertyWithCommandLineOption(arg))
704 mike             1.2           {
705 chip             1.68              throw UnrecognizedConfigProperty(arg);
706 mike             1.2           }
707                        
708                                // Remove the option from the command line
709                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
710                                argc--;
711                            }
712                        }
713                        
714                        
715 chip             1.68  /**
716 kumpf            1.88      load config properties from the file
717 mike             1.2   */
718                        void ConfigManager::_loadConfigProperties()
719                        {
720 kumpf            1.59      PEGASUS_ASSERT(useConfigFiles);
721                        
722 mike             1.2       //
723                            // load all the properties from the current and planned
724                            // config files in to tables.
725                            //
726                            _configFileHandler->loadAllConfigProperties();
727                        
728 kumpf            1.49      Array<CIMName> propertyNames;
729                            Array<String>  propertyValues;
730                        
731                            _configFileHandler->getAllCurrentProperties(propertyNames, propertyValues);
732                        
733                            Uint32 size = propertyNames.size();
734                        
735 mike             1.2       //
736                            // initialize all the property owners with the values
737                            // from the config files.
738                            //
739 kumpf            1.49      for (Uint32 i = 0; i < size; i++)
740 mike             1.2       {
741 kumpf            1.49          //
742                                // initialize the current value of the property owner
743                                // with the value from the config file handler
744                                //
745                                try
746 mike             1.2           {
747 kumpf            1.13              //
748 kumpf            1.49              // get property owner object from the config table.
749 kumpf            1.13              //
750 kumpf            1.49              ConfigPropertyOwner* propertyOwner;
751                        
752                                    String propertyName = propertyNames[i].getString();
753                        
754                                    if (_propertyTable->ownerTable.lookup(
755                                        propertyName, propertyOwner))
756 mike             1.2               {
757 kumpf            1.49                  if (propertyOwner->isValid(
758                                            propertyName, propertyValues[i]))
759                                        {
760                                            propertyOwner->initCurrentValue(
761                                                propertyName, propertyValues[i]);
762 mike             1.2   
763 kumpf            1.49                      propertyOwner->initPlannedValue(
764                                                propertyName, propertyValues[i]);
765                                        }
766                                        else
767 mike             1.2                   {
768 kumpf            1.49                      throw InvalidPropertyValue(propertyName, propertyValues[i]);
769 mike             1.2                   }
770                                    }
771 kumpf            1.49              else
772 mike             1.2               {
773 kumpf            1.88                  // if the property is a fixed property then just log that
774                                        // this property is not supported and continue.  In all other
775                                        // cases terminate the cimserver
776 thilo.boehm      1.87                  if (_propertyTable->fixedValueTable.contains(propertyName))
777                                        {
778 kumpf            1.88                      Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
779                                                Logger::WARNING,
780 kumpf            1.100                         MessageLoaderParms(
781                                                    "Config.ConfigManager.NOTSUPPORTED_CONFIG_PROPERTY",
782                                                    "Configuration property $0 is not supported. "
783                                                        "Setting ignored.",
784                                                    propertyName));
785 kumpf            1.88                  }
786                                        else
787 thilo.boehm      1.87                  {
788 kumpf            1.88                      throw UnrecognizedConfigProperty(propertyName);
789 thilo.boehm      1.87                  }
790 mike             1.2               }
791 kumpf            1.49          }
792 kumpf            1.88          catch (UnrecognizedConfigProperty& ucp)
793 kumpf            1.49          {
794 kumpf            1.108             PEG_TRACE_CSTRING(TRC_CONFIG, Tracer::LEVEL1,
795 thilo.boehm      1.101                 (const char*)ucp.getMessage().getCString());
796 kumpf            1.49              throw;
797                                }
798 kumpf            1.88          catch (InvalidPropertyValue& ipv)
799 kumpf            1.49          {
800 kumpf            1.108             PEG_TRACE_CSTRING(TRC_CONFIG, Tracer::LEVEL1,
801 thilo.boehm      1.101                 (const char*)ipv.getMessage().getCString());
802 kumpf            1.49              throw;
803 mike             1.2           }
804                            }
805                        }
806                        
807                        
808 chip             1.68  /**
809 kumpf            1.88      Initialize config property with the value specified in the command line.
810 mike             1.2   */
811                        Boolean ConfigManager::_initPropertyWithCommandLineOption(
812 chip             1.68      const String& option)
813 mike             1.2   {
814 kumpf            1.59      Uint32 pos = option.find('=');
815 thilo.boehm      1.109 
816 mike             1.2       if (pos == PEG_NOT_FOUND)
817                            {
818                                //
819                                // The property value was not specified
820                                //
821 chip             1.68          throw UnrecognizedConfigProperty(option);
822 mike             1.2       }
823                        
824                            //
825                            // Get the property name and value
826                            //
827 kumpf            1.59      String propertyName = option.subString(0, pos);
828 kumpf            1.88      String propertyValue = option.subString(pos + 1);
829 mike             1.2   
830 kumpf            1.59      return initCurrentValue(propertyName, propertyValue);
831 mike             1.2   }
832                        
833 chip             1.68  /**
834 kumpf            1.88      Initialize config property owners and add them to the property owner table
835 mike             1.2   */
836 kumpf            1.10  void ConfigManager::_initPropertyTable()
837 mike             1.2   {
838                            //
839 kumpf            1.10      // add config property and its fixed value to fixed value table
840                            //
841                            for (Uint32 i = 0; i < NUM_FIXED_PROPERTIES; i++)
842                            {
843 kumpf            1.14          _propertyTable->fixedValueTable.insert(_fixedValues[i].propertyName,
844                                    _fixedValues[i].fixedValue);
845 kumpf            1.10      }
846                        
847                            //
848                            // add config property and its owner object to owners table (but only if
849                            // the property is not also listed in the fixed value table.
850 mike             1.2       //
851                            for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
852                            {
853 w.otsuka         1.80          const char* fixedValue = 0;
854 mike             1.2   
855 kumpf            1.31          _properties[i].propertyOwner->initialize();
856                        
857 kumpf            1.10          if (!_propertyTable->fixedValueTable.lookup(
858 kumpf            1.14                  _properties[i].propertyName, fixedValue))
859 kumpf            1.10          {
860 kumpf            1.14              _propertyTable->ownerTable.insert(_properties[i].propertyName,
861                                        _properties[i].propertyOwner);
862 kumpf            1.31          }
863                                else
864                                {
865                                    //
866                                    // Set the value for the fixed properties
867                                    //
868                                    _properties[i].propertyOwner->initCurrentValue(
869                                        _properties[i].propertyName, fixedValue);
870 kumpf            1.10          }
871 mike             1.2       }
872                        }
873                        
874 kumpf            1.6   /**
875 kumpf            1.88      Get Pegasus Home
876 kumpf            1.6   */
877                        String ConfigManager::getPegasusHome()
878                        {
879                            return _pegasusHome;
880                        }
881                        
882                        /**
883 kumpf            1.88      Set Pegasus Home variable
884 kumpf            1.6   */
885 aruran.ms        1.74  void ConfigManager::setPegasusHome(const String& home)
886 kumpf            1.6   {
887 kumpf            1.88      if (home != String::EMPTY)
888 kumpf            1.6       {
889 kumpf            1.88          _pegasusHome = home;
890 kumpf            1.6       }
891                        }
892                        
893                        /**
894 kumpf            1.88      Get the homed path for a given property.
895 kumpf            1.6   */
896                        String ConfigManager::getHomedPath(const String& value)
897                        {
898 kumpf            1.90      String homedPath;
899 kumpf            1.88  
900                            if (value != String::EMPTY)
901                            {
902                                if (System::is_absolute_path((const char *)value.getCString()))
903                                {
904                                    return value;
905                                }
906 chip             1.68  
907 kumpf            1.88          //
908                                // Get the pegasusHome and prepend it
909                                //
910                        
911                                String temp = value;
912                                Uint32 pos = 0;
913                                Uint32 token = 0;
914                                do
915                                {
916                                    if ((pos = temp.find(FileSystem::getPathDelimiter())) ==
917                                            PEG_NOT_FOUND)
918                                    {
919                                        pos = temp.size();
920                                        token = 0;
921                                    }
922                                    else
923                                    {
924                                        token = 1;
925                                    }
926                        
927                                    if (System::is_absolute_path(
928 kumpf            1.88                      (const char *)temp.subString(0, pos).getCString()))
929                                    {
930                                        homedPath.append(temp.subString(0,pos));
931                                    }
932                                    else
933                                    {
934                                        homedPath.append(_pegasusHome + "/" + temp.subString(0, pos));
935                                    }
936                        
937                                    if (token == 1)
938                                        homedPath.append(FileSystem::getPathDelimiter());
939                                    temp.remove(0, pos + token);
940                                } while (temp.size() > 0);
941 konrad.r         1.50      }
942 kumpf            1.88      return homedPath;
943 kumpf            1.6   }
944 chip             1.68  
945 kumpf            1.83  Boolean ConfigManager::parseBooleanValue(const String& propertyValue)
946                        {
947                            return String::equalNoCase(propertyValue, "true");
948                        }
949                        
950 kavita.gupta     1.110 Boolean ConfigManager::isValidBooleanValue(const String& value)
951                        {
952                            if ((String::equalNoCase(value, STRING_TRUE)) ||
953                                (String::equalNoCase(value, STRING_FALSE)))
954                            {
955                                return true;
956                            }
957                            return false;
958                        }
959                        
960 mike             1.2   PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2