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

  1 karl  1.78 //%2006////////////////////////////////////////////////////////////////////////
  2 mike  1.2  //
  3 karl  1.65 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.44 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.65 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.69 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.78 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 mike  1.2  //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15 kumpf 1.21 // of this software and associated documentation files (the "Software"), to
 16            // deal in the Software without restriction, including without limitation the
 17            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18 mike  1.2  // sell copies of the Software, and to permit persons to whom the Software is
 19            // furnished to do so, subject to the following conditions:
 20 karl  1.78 // 
 21 kumpf 1.21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 mike  1.2  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24 kumpf 1.21 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27 mike  1.2  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29            //
 30 kumpf 1.21 //==============================================================================
 31 mike  1.2  //
 32            //%////////////////////////////////////////////////////////////////////////////
 33            
 34            
 35            /////////////////////////////////////////////////////////////////////////////
 36 chip  1.68 //  ConfigManager
 37 mike  1.2  /////////////////////////////////////////////////////////////////////////////
 38            
 39 kumpf 1.20 #include <Pegasus/Common/Tracer.h>
 40 kumpf 1.12 #include <Pegasus/Common/PegasusVersion.h>
 41 tony  1.32 #include <Pegasus/Common/FileSystem.h>
 42 kumpf 1.81 #include <Pegasus/Common/Constants.h>
 43 kumpf 1.12 
 44 mike  1.2  #include "ConfigExceptions.h"
 45            #include "ConfigManager.h"
 46            
 47            PEGASUS_NAMESPACE_BEGIN
 48            
 49            /////////////////////////////////////////////////////////////////////////////
 50            //
 51            //  When a new property owner is created be sure to create a static
 52            //  object of the new property owner.
 53            //
 54            /////////////////////////////////////////////////////////////////////////////
 55            
 56            TracePropertyOwner*      ConfigManager::traceOwner   = new TracePropertyOwner;
 57            LogPropertyOwner*        ConfigManager::logOwner     = new LogPropertyOwner;
 58            DefaultPropertyOwner*    ConfigManager::defaultOwner = new DefaultPropertyOwner;
 59            SecurityPropertyOwner*   ConfigManager::securityOwner= new SecurityPropertyOwner;
 60            RepositoryPropertyOwner* ConfigManager::repositoryOwner= new RepositoryPropertyOwner;
 61            ShutdownPropertyOwner*   ConfigManager::shutdownOwner= new ShutdownPropertyOwner;
 62 kumpf 1.10 FileSystemPropertyOwner* ConfigManager::fileSystemOwner= new FileSystemPropertyOwner;
 63 konrad.r 1.50 ProviderDirPropertyOwner* ConfigManager::providerDirOwner= new ProviderDirPropertyOwner;
 64 chip     1.68 NormalizationPropertyOwner* ConfigManager::normalizationOwner = new NormalizationPropertyOwner;
 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                   {"traceLevel",          (ConfigPropertyOwner* )ConfigManager::traceOwner},
 82 kumpf    1.6      {"traceComponents",     (ConfigPropertyOwner* )ConfigManager::traceOwner},
 83 mike     1.2      {"traceFilePath",       (ConfigPropertyOwner* )ConfigManager::traceOwner},
 84 konrad.r 1.71 #if !defined(PEGASUS_USE_SYSLOGS)
 85 kumpf    1.6      {"logdir",              (ConfigPropertyOwner* )ConfigManager::logOwner},
 86 konrad.r 1.71 #endif
 87 david    1.35     {"logLevel",            (ConfigPropertyOwner* )ConfigManager::logOwner},
 88 kumpf    1.30     {"enableHttpConnection", (ConfigPropertyOwner* )ConfigManager::defaultOwner},
 89                   {"enableHttpsConnection",(ConfigPropertyOwner* )ConfigManager::defaultOwner},
 90 kumpf    1.16     {"httpPort",            (ConfigPropertyOwner* )ConfigManager::defaultOwner},
 91                   {"httpsPort",           (ConfigPropertyOwner* )ConfigManager::defaultOwner},
 92 mike     1.2      {"home",                (ConfigPropertyOwner* )ConfigManager::defaultOwner},
 93                   {"daemon",              (ConfigPropertyOwner* )ConfigManager::defaultOwner},
 94                   {"slp",                 (ConfigPropertyOwner* )ConfigManager::defaultOwner},
 95 kumpf    1.19     {"enableAssociationTraversal", (ConfigPropertyOwner* )ConfigManager::defaultOwner},
 96                   {"enableIndicationService", (ConfigPropertyOwner* )ConfigManager::defaultOwner},
 97 karl     1.38     // Removed because unresolved PEP 66 KS{"maximumEnumerationBreadth", (ConfigPropertyOwner* )ConfigManager::defaultOwner},
 98 kumpf    1.17     {"enableAuthentication", (ConfigPropertyOwner* )ConfigManager::securityOwner},
 99                   {"enableNamespaceAuthorization", (ConfigPropertyOwner* )ConfigManager::securityOwner},
100 mike     1.2      {"httpAuthType",        (ConfigPropertyOwner* )ConfigManager::securityOwner},
101 kumpf    1.6      {"passwordFilePath",    (ConfigPropertyOwner* )ConfigManager::securityOwner},
102 kumpf    1.18     {"sslCertificateFilePath", (ConfigPropertyOwner* )ConfigManager::securityOwner},
103 kumpf    1.39     {"sslKeyFilePath",      (ConfigPropertyOwner* )ConfigManager::securityOwner},
104 h.sterling 1.55     {"sslTrustStore",      (ConfigPropertyOwner* )ConfigManager::securityOwner},
105 sushma.fernandes 1.79 #ifdef PEGASUS_ENABLE_SSL_CRL_VERIFICATION
106 h.sterling       1.66     {"crlStore",      (ConfigPropertyOwner* )ConfigManager::securityOwner},
107 sushma.fernandes 1.79 #endif
108 h.sterling       1.55     {"sslClientVerificationMode", (ConfigPropertyOwner* )ConfigManager::securityOwner},
109 h.sterling       1.61 	{"sslTrustStoreUserName", (ConfigPropertyOwner* )ConfigManager::securityOwner},
110 gerarda          1.42 #ifdef PEGASUS_KERBEROS_AUTHENTICATION
111                           {"kerberosServiceName", (ConfigPropertyOwner* )ConfigManager::securityOwner},
112                       #endif
113 mike             1.2      {"repositoryIsDefaultInstanceProvider", (ConfigPropertyOwner* )ConfigManager::repositoryOwner},
114 dave.sudlik      1.62     {"enableBinaryRepository", (ConfigPropertyOwner* )ConfigManager::repositoryOwner}, // PEP 164
115 kumpf            1.5      {"shutdownTimeout",     (ConfigPropertyOwner* )ConfigManager::shutdownOwner},
116 kumpf            1.17     {"repositoryDir",       (ConfigPropertyOwner* )ConfigManager::fileSystemOwner},
117 konrad.r         1.50     {"providerDir",         (ConfigPropertyOwner* )ConfigManager::providerDirOwner},
118 kumpf            1.7      {"enableRemotePrivilegedUserAccess", (ConfigPropertyOwner* )ConfigManager::securityOwner},
119 kumpf            1.43     {"enableSubscriptionsForNonprivilegedUsers", (ConfigPropertyOwner* )ConfigManager::securityOwner},
120 kumpf            1.57 #ifdef PEGASUS_ENABLE_USERGROUP_AUTHORIZATION
121                           {"authorizedUserGroups", (ConfigPropertyOwner* )ConfigManager::securityOwner},
122                       #endif
123 david            1.52     {"messageDir",          (ConfigPropertyOwner* )ConfigManager::fileSystemOwner},
124 chip             1.68 #ifdef PEGASUS_ENABLE_OBJECT_NORMALIZATION
125                           { "enableNormalization", (ConfigPropertyOwner *)ConfigManager::normalizationOwner },
126                           { "excludeModulesFromNormalization", (ConfigPropertyOwner *)ConfigManager::normalizationOwner },
127                       #endif
128 kumpf            1.67     {"forceProviderProcesses", (ConfigPropertyOwner* )ConfigManager::defaultOwner},
129 marek            1.82     {"maxProviderProcesses", (ConfigPropertyOwner* )ConfigManager::defaultOwner},
130 yi.zhou          1.86 #ifndef PEGASUS_DISABLE_AUDIT_LOGGER
131 yi.zhou          1.85     {"enableAuditLog", (ConfigPropertyOwner* )ConfigManager::defaultOwner},
132 yi.zhou          1.86 #endif
133 marek            1.82     {"socketWriteTimeout", (ConfigPropertyOwner* )ConfigManager::defaultOwner}
134 mike             1.2  };
135                       
136 kumpf            1.14 const Uint32 NUM_PROPERTIES = sizeof(_properties) / sizeof(struct OwnerEntry);
137 kumpf            1.10 
138                       
139                       /////////////////////////////////////////////////////////////////////////////
140                       //
141                       //   To use a fixed value for a property rather than delegating to a property
142                       //   owner, add the property to the FixedValueEntry table below.  An entry in
143                       //   the OwnerEntry table above for this same property will be initialized
144                       //   and given the (fixed) initial current value, but will thereafter be
145                       //   ignored.
146                       //
147                       //   Fixed values are only returned by getDefaultValue(), getCurrentValue(),
148                       //   and getPlannedValue().  All other methods will treat fixed properties as
149                       //   unrecognized properties.
150                       //
151                       /////////////////////////////////////////////////////////////////////////////
152                       
153                       struct FixedValueEntry
154                       {
155                           const char* propertyName;
156                           const char* fixedValue;
157                       };
158 kumpf            1.10 
159 kumpf            1.14 static struct FixedValueEntry _fixedValues[] =
160 kumpf            1.10 {
161 kumpf            1.28 #include "FixedPropertyTable.h"
162 kumpf            1.10 };
163                       
164 chip             1.68 const Uint32 NUM_FIXED_PROPERTIES =
165 kumpf            1.14     sizeof(_fixedValues) / sizeof(struct FixedValueEntry);
166 kumpf            1.10 
167 mike             1.2  
168 kumpf            1.6  /**
169                       Initialize the default PEGASUS_HOME location, the default is set to the current directory.
170                       */
171                       const String ConfigManager::PEGASUS_HOME_DEFAULT  = ".";
172 mike             1.2  
173 kumpf            1.6  String ConfigManager::_pegasusHome = PEGASUS_HOME_DEFAULT;
174 mike             1.2  
175 kumpf            1.59 //
176 chip             1.68 // Initialize ConfigManager instance
177 kumpf            1.59 //
178 mike             1.2  ConfigManager* ConfigManager::_instance = 0;
179                       
180                       
181                       /** Constructor. */
182 kumpf            1.59 ConfigManager::ConfigManager()
183                           : useConfigFiles(false)
184 mike             1.2  {
185                           //
186                           // Initialize the instance variables
187                           //
188 a.arora          1.58     _propertyTable.reset(new PropertyTable);
189 mike             1.2  
190                           //
191                           // Initialize the property owners
192                           //
193 kumpf            1.10     _initPropertyTable();
194 mike             1.2  }
195                       
196 konrad.r         1.75 /**
197                        Terminate the ConfigManager
198                       */
199                       void
200 konrad.r         1.76 ConfigManager::destroy( void )
201 konrad.r         1.75 {
202                          if (_instance)
203                          {
204                              delete _instance->traceOwner;
205                              delete _instance->logOwner;
206                              delete _instance->defaultOwner;
207                              delete _instance->securityOwner;
208                              delete _instance->repositoryOwner;
209                              delete _instance->shutdownOwner;
210                              delete _instance->fileSystemOwner;
211                              delete _instance->providerDirOwner;
212                              delete _instance->normalizationOwner;
213                              delete _instance;
214                              _instance = 0;	
215                          }
216                       }
217 chip             1.68 /**
218 kumpf            1.59     Get a reference to the singleton ConfigManager instance.  If no
219                           ConfigManager instance exists, construct one.
220 mike             1.2  */
221 chip             1.68 ConfigManager* ConfigManager::getInstance()
222 mike             1.2  {
223 chip             1.68     if (!_instance)
224 mike             1.2      {
225                               _instance = new ConfigManager();
226                           }
227                           return _instance;
228                       }
229                       
230                       
231 chip             1.68 /**
232 kumpf            1.59     Initialize the current value of a config property
233                       */
234                       Boolean ConfigManager::initCurrentValue(
235                           const String& propertyName,
236                           const String& propertyValue)
237                       {
238                           ConfigPropertyOwner* propertyOwner = 0;
239                       
240                           //
241                           // get property owner object from the config table.
242                           //
243                           if (!_propertyTable->ownerTable.lookup(propertyName, propertyOwner))
244                           {
245 chip             1.68         throw UnrecognizedConfigProperty(propertyName);
246 kumpf            1.59     }
247                       
248 kumpf            1.73     if (useConfigFiles && !propertyOwner->isValid(propertyName, propertyValue))
249                           {
250                               throw InvalidPropertyValue(propertyName, propertyValue);
251                           }
252                       
253                           //
254                           // update the value with the property owner
255                           //
256                           propertyOwner->initCurrentValue(propertyName, propertyValue);
257                       
258                           if (useConfigFiles)
259 kumpf            1.59     {
260                               //
261 kumpf            1.73         // update the value in the current config file
262 kumpf            1.59         //
263 kumpf            1.73         return (_configFileHandler->updateCurrentValue(
264                                   propertyName, propertyValue, false));
265 kumpf            1.59     }
266                       
267                           return true;
268                       }
269                       
270 chip             1.68 /**
271 mike             1.2  Update current value of a property.
272                       */
273                       Boolean ConfigManager::updateCurrentValue(
274 chip             1.68     const String& name,
275 kumpf            1.13     const String& value,
276                           Boolean unset)
277 mike             1.2  {
278                           String prevValue = String::EMPTY;
279                       
280                           //
281                           // get property owner object from the config table.
282                           //
283                           ConfigPropertyOwner* propertyOwner;
284                       
285 kumpf            1.10     if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
286 mike             1.2      {
287 chip             1.68         throw UnrecognizedConfigProperty(name);
288 mike             1.2      }
289                       
290 kumpf            1.73     //
291                           // keep a copy of the existing config value
292                           //
293                           prevValue = propertyOwner->getCurrentValue(name);
294                       
295                           //
296                           // ask owner to update the current value
297                           //
298                           if (unset)
299 mike             1.2      {
300 kumpf            1.73         propertyOwner->updateCurrentValue(name,
301                                   propertyOwner->getDefaultValue(name));
302                           }
303                           else
304                           {
305                               if (useConfigFiles && !propertyOwner->isValid(name, value))
306                               {
307                                   throw InvalidPropertyValue(name, value);
308                               }
309                       
310                               propertyOwner->updateCurrentValue(name, value);
311                           }
312 mike             1.2  
313 kumpf            1.73     if (useConfigFiles)
314                           {
315 mike             1.2          //
316 kumpf            1.73         // update the new value in the current config file
317 mike             1.2          //
318 kumpf            1.73         if (!_configFileHandler->updateCurrentValue(name, value, unset))
319 mike             1.2          {
320 kumpf            1.73             // Failed to update the current value, so roll back.
321                                   propertyOwner->updateCurrentValue(name, prevValue);
322                                   return false;
323 mike             1.2          }
324                           }
325 kumpf            1.29 
326 kumpf            1.59     return true;
327 mike             1.2  }
328                       
329                       
330 chip             1.68 /**
331 mike             1.2  Update planned value of a property.
332                       */
333                       Boolean ConfigManager::updatePlannedValue(
334 chip             1.68     const String& name,
335 kumpf            1.13     const String& value,
336                           Boolean unset)
337 mike             1.2  {
338                           String prevValue = String::EMPTY;
339                       
340                           //
341                           // get property owner object from the config table.
342                           //
343                           ConfigPropertyOwner* propertyOwner;
344                       
345 kumpf            1.10     if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
346 mike             1.2      {
347 chip             1.68         throw UnrecognizedConfigProperty(name);
348 mike             1.2      }
349                       
350 kumpf            1.73     //
351                           // keep a copy of the existing config value
352                           //
353                           prevValue = propertyOwner->getPlannedValue(name);
354                       
355                           //
356                           // ask owner to update the planned value to new value
357                           //
358                           if (unset)
359                           {
360                               propertyOwner->updatePlannedValue(name,
361                                   propertyOwner->getDefaultValue(name));
362                           }
363                           else
364 mike             1.2      {
365 kumpf            1.73         if (useConfigFiles && !propertyOwner->isValid(name, value))
366                               {
367                                   throw InvalidPropertyValue(name, value);
368                               }
369                       
370                               propertyOwner->updatePlannedValue(name, value);
371                           }
372 mike             1.2  
373 kumpf            1.73     if (useConfigFiles)
374                           {
375 mike             1.2          //
376 kumpf            1.73         // update the new value in the planned config file
377 mike             1.2          //
378 kumpf            1.73         if (!_configFileHandler->updatePlannedValue(name, value, unset))
379 kumpf            1.13         {
380 kumpf            1.73             // Failed to update the planned value, so roll back.
381                                   propertyOwner->updatePlannedValue(name, prevValue);
382                                   return false;
383 mike             1.2          }
384                           }
385 kumpf            1.29 
386 kumpf            1.59     return true;
387 mike             1.2  }
388                       
389                       
390 chip             1.68 /**
391 mike             1.2  Validate the value of a specified property.
392                       */
393                       Boolean ConfigManager::validatePropertyValue(
394 chip             1.68     const String& name,
395 mike             1.2      const String& value)
396                       {
397                           //
398                           // get property owner object from config table
399                           //
400                           ConfigPropertyOwner* propertyOwner;
401                       
402 kumpf            1.10     if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
403 mike             1.2      {
404 chip             1.68         throw UnrecognizedConfigProperty(name);
405 mike             1.2      }
406                       
407                           return (propertyOwner->isValid(name, value));
408                       }
409                       
410                       /**
411                       Get default value of the specified property.
412                       */
413 aruran.ms        1.77 String ConfigManager::getDefaultValue(const String& name) const
414 mike             1.2  {
415                           //
416 kumpf            1.10     // Check for a property with a fixed value
417                           //
418                           const char* fixedValue;
419                       
420                           if (_propertyTable->fixedValueTable.lookup(name, fixedValue))
421                           {
422                               return fixedValue;
423                           }
424                       
425                           //
426 mike             1.2      // get property owner object from config table
427                           //
428                           ConfigPropertyOwner* propertyOwner;
429                       
430 kumpf            1.10     if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
431 mike             1.2      {
432                               throw UnrecognizedConfigProperty(name);
433                           }
434                       
435                           return (propertyOwner->getDefaultValue(name));
436                       }
437                       
438 chip             1.68 /**
439 mike             1.2  Get current value of the specified property.
440                       */
441 aruran.ms        1.77 String ConfigManager::getCurrentValue(const String& name) const
442 mike             1.2  {
443                           //
444 kumpf            1.10     // Check for a property with a fixed value
445                           //
446                           const char* fixedValue;
447                       
448                           if (_propertyTable->fixedValueTable.lookup(name, fixedValue))
449                           {
450                               return fixedValue;
451                           }
452                       
453                           //
454 mike             1.2      // get property owner object from config table
455                           //
456                           ConfigPropertyOwner* propertyOwner;
457                       
458 kumpf            1.10     if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
459 mike             1.2      {
460 chip             1.68         throw UnrecognizedConfigProperty(name);
461 mike             1.2      }
462                       
463                           return (propertyOwner->getCurrentValue(name));
464                       }
465                       
466                       
467 chip             1.68 /**
468 mike             1.2  Get planned value of the specified property.
469                       */
470 aruran.ms        1.77 String ConfigManager::getPlannedValue(const String& name) const
471 mike             1.2  {
472                           //
473 kumpf            1.10     // Check for a property with a fixed value
474                           //
475                           const char* fixedValue;
476                       
477                           if (_propertyTable->fixedValueTable.lookup(name, fixedValue))
478                           {
479                               return fixedValue;
480                           }
481                       
482                           //
483 mike             1.2      // get property owner object from config table
484                           //
485                           ConfigPropertyOwner* propertyOwner;
486                       
487 kumpf            1.10     if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
488 mike             1.2      {
489 chip             1.68         throw UnrecognizedConfigProperty(name);
490 mike             1.2      }
491                       
492                           return (propertyOwner->getPlannedValue(name));
493                       }
494                       
495                       
496 chip             1.68 /**
497 mike             1.2  Get all the attributes of the specified property.
498                       */
499                       void ConfigManager::getPropertyInfo(
500 chip             1.68     const String& name,
501 aruran.ms        1.77     Array<String>& propertyInfo) const
502 mike             1.2  {
503                           //
504                           // get property owner object from config table
505                           //
506                           ConfigPropertyOwner* propertyOwner;
507                       
508 kumpf            1.10     if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
509 mike             1.2      {
510 chip             1.68         throw UnrecognizedConfigProperty(name);
511 mike             1.2      }
512                       
513                           propertyOwner->getPropertyInfo(name, propertyInfo);
514                       }
515                       
516                       
517 chip             1.68 /**
518 mike             1.2  Get a list of all property names.
519                       */
520 kumpf            1.59 void ConfigManager::getAllPropertyNames(
521                           Array<String>& propertyNames,
522 aruran.ms        1.77     Boolean includeHiddenProperties) const
523 mike             1.2  {
524 kumpf            1.41     Array<String> propertyInfo;
525 mike             1.2      propertyNames.clear();
526                       
527 kumpf            1.10     for (OwnerTable::Iterator i = _propertyTable->ownerTable.start(); i; i++)
528 mike             1.2      {
529 kumpf            1.59         if (includeHiddenProperties)
530 kumpf            1.41         {
531                                   propertyNames.append(i.key());
532                               }
533 kumpf            1.59         else
534                               {
535                                   //
536                                   // Check if property is to be externally visible or not.
537                                   // If the property should not be externally visible do not list the
538                                   // property information.
539                                   //
540                                   propertyInfo.clear();
541                                   getPropertyInfo(i.key(), propertyInfo);
542                       
543                                   if (propertyInfo[5] == STRING_TRUE)
544                                   {
545                                       propertyNames.append(i.key());
546                                   }
547                               }
548 mike             1.2      }
549                       }
550                       
551                       
552 chip             1.68 /**
553 mike             1.2  Merge the config properties from the specified planned config file
554                       with the properties in the specified current config file.
555                       */
556                       void ConfigManager::mergeConfigFiles(
557 chip             1.68     const String& currentFile,
558 mike             1.2      const String& plannedFile)
559                       {
560 kumpf            1.59     PEGASUS_ASSERT(useConfigFiles);
561                       
562 kumpf            1.73     _configFileHandler.reset(new ConfigFileHandler(currentFile, plannedFile));
563 mike             1.2  
564 kumpf            1.73     _loadConfigProperties();
565 mike             1.2  }
566                       
567                       
568 chip             1.68 /**
569 mike             1.2  Merge the config properties from the default planned config file
570                       with the properties in the default current config file.
571                       */
572                       void ConfigManager::mergeConfigFiles()
573                       {
574 kumpf            1.59     PEGASUS_ASSERT(useConfigFiles);
575                       
576 kumpf            1.73     _configFileHandler.reset(new ConfigFileHandler());
577 mike             1.2  
578 kumpf            1.73     _loadConfigProperties();
579 mike             1.2  }
580                       
581                       
582 chip             1.68 /**
583                       Merge config properties specified on the command line
584 mike             1.2  */
585                       void ConfigManager::mergeCommandLine(int& argc, char**& argv)
586                       {
587                           // Remove the command name from the command line
588 kumpf            1.3      if (argc > 0)
589                           {
590                               memmove(&argv[0], &argv[1], (argc) * sizeof(char*));
591                               argc--;
592                           }
593 mike             1.2  
594                           //
595                           //  Merge properties from the command line
596                           //
597 kumpf            1.9      for (Sint32 i = 0; i < argc; )
598 mike             1.2      {
599                               const char* arg = argv[i];
600                       
601 kumpf            1.34         if (*arg == '-')
602                               {
603                                   throw UnrecognizedCommandLineOption();
604                               }
605                       
606 tony             1.33         // Get the config option
607                               //const char* configOption = argv[i];
608                               if (!_initPropertyWithCommandLineOption(arg))
609 mike             1.2          {
610 chip             1.68             throw UnrecognizedConfigProperty(arg);
611 mike             1.2          }
612                       
613                               // Remove the option from the command line
614                               memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
615                               argc--;
616                           }
617                       }
618                       
619                       
620 chip             1.68 /**
621                       load config properties from the file
622 mike             1.2  */
623                       void ConfigManager::_loadConfigProperties()
624                       {
625 kumpf            1.59     PEGASUS_ASSERT(useConfigFiles);
626                       
627 mike             1.2      //
628                           // copy the contents of planned config file over
629                           // the current config file
630                           //
631                           _configFileHandler->copyPlannedFileOverCurrentFile();
632                       
633                           //
634                           // load all the properties from the current and planned
635                           // config files in to tables.
636                           //
637                           _configFileHandler->loadAllConfigProperties();
638                       
639 kumpf            1.49     Array<CIMName> propertyNames;
640                           Array<String>  propertyValues;
641                       
642                           _configFileHandler->getAllCurrentProperties(propertyNames, propertyValues);
643                       
644                           Uint32 size = propertyNames.size();
645                       
646 mike             1.2      //
647                           // initialize all the property owners with the values
648                           // from the config files.
649                           //
650 kumpf            1.49     for (Uint32 i = 0; i < size; i++)
651 mike             1.2      {
652 kumpf            1.49         //
653                               // initialize the current value of the property owner
654                               // with the value from the config file handler
655                               //
656                               try
657 mike             1.2          {
658 kumpf            1.13             //
659 kumpf            1.49             // get property owner object from the config table.
660 kumpf            1.13             //
661 kumpf            1.49             ConfigPropertyOwner* propertyOwner;
662                       
663                                   String propertyName = propertyNames[i].getString();
664                       
665                                   if (_propertyTable->ownerTable.lookup(
666                                       propertyName, propertyOwner))
667 mike             1.2              {
668 kumpf            1.49                 if (propertyOwner->isValid(
669                                           propertyName, propertyValues[i]))
670                                       {
671                                           propertyOwner->initCurrentValue(
672                                               propertyName, propertyValues[i]);
673 mike             1.2  
674 kumpf            1.49                     propertyOwner->initPlannedValue(
675                                               propertyName, propertyValues[i]);
676                                       }
677                                       else
678 mike             1.2                  {
679 kumpf            1.49                     throw InvalidPropertyValue(propertyName, propertyValues[i]);
680 mike             1.2                  }
681                                   }
682 kumpf            1.49             else
683 mike             1.2              {
684 kumpf            1.49                 throw UnrecognizedConfigProperty(propertyName);
685 mike             1.2              }
686 kumpf            1.49         }
687                               catch(UnrecognizedConfigProperty& ucp)
688                               {
689                                   PEG_TRACE_STRING(TRC_CONFIG, Tracer::LEVEL2, ucp.getMessage());
690                                   throw;
691                               }
692                               catch(InvalidPropertyValue& ipv)
693                               {
694                                   PEG_TRACE_STRING(TRC_CONFIG, Tracer::LEVEL2, ipv.getMessage());
695                                   throw;
696 mike             1.2          }
697                           }
698                       }
699                       
700                       
701 chip             1.68 /**
702                       Initialize config property with the value specified
703 mike             1.2  in the command line.
704                       */
705                       Boolean ConfigManager::_initPropertyWithCommandLineOption(
706 chip             1.68     const String& option)
707 mike             1.2  {
708 kumpf            1.59     Uint32 pos = option.find('=');
709 mike             1.2      if (pos == PEG_NOT_FOUND)
710                           {
711                               //
712                               // The property value was not specified
713                               //
714 chip             1.68         throw UnrecognizedConfigProperty(option);
715 mike             1.2      }
716                       
717                           //
718                           // Get the property name and value
719                           //
720 kumpf            1.59     String propertyName = option.subString(0, pos);
721                           String propertyValue = option.subString(pos+1);
722 mike             1.2  
723 kumpf            1.59     return initCurrentValue(propertyName, propertyValue);
724 mike             1.2  }
725                       
726 chip             1.68 /**
727 mike             1.2  Initialize config property owners and add them to the property owner table
728                       */
729 kumpf            1.10 void ConfigManager::_initPropertyTable()
730 mike             1.2  {
731                           //
732 kumpf            1.10     // add config property and its fixed value to fixed value table
733                           //
734                           for (Uint32 i = 0; i < NUM_FIXED_PROPERTIES; i++)
735                           {
736 kumpf            1.14         _propertyTable->fixedValueTable.insert(_fixedValues[i].propertyName,
737                                   _fixedValues[i].fixedValue);
738 kumpf            1.10     }
739                       
740                           //
741                           // add config property and its owner object to owners table (but only if
742                           // the property is not also listed in the fixed value table.
743 mike             1.2      //
744                           for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
745                           {
746 w.otsuka         1.80         const char* fixedValue = 0;
747 mike             1.2  
748 kumpf            1.31         _properties[i].propertyOwner->initialize();
749                       
750 kumpf            1.10         if (!_propertyTable->fixedValueTable.lookup(
751 kumpf            1.14                 _properties[i].propertyName, fixedValue))
752 kumpf            1.10         {
753 kumpf            1.14             _propertyTable->ownerTable.insert(_properties[i].propertyName,
754                                       _properties[i].propertyOwner);
755 kumpf            1.31         }
756                               else
757                               {
758                                   //
759                                   // Set the value for the fixed properties
760                                   //
761                                   _properties[i].propertyOwner->initCurrentValue(
762                                       _properties[i].propertyName, fixedValue);
763 kumpf            1.10         }
764 mike             1.2      }
765                       }
766                       
767 kumpf            1.6  /**
768                       Get Pegasus Home
769                       */
770                       String ConfigManager::getPegasusHome()
771                       {
772                           return _pegasusHome;
773                       }
774                       
775                       /**
776                       Set Pegasus Home variable
777                       */
778 aruran.ms        1.74 void ConfigManager::setPegasusHome(const String& home)
779 kumpf            1.6  {
780                           if ( home != String::EMPTY )
781                           {
782                              _pegasusHome = home;
783                           }
784                       }
785                       
786                       /**
787 chip             1.68 Get the homed path for a given property.
788 kumpf            1.6  */
789                       String ConfigManager::getHomedPath(const String& value)
790                       {
791 tony             1.32   String homedPath = String::EMPTY;
792 chip             1.68 
793 tony             1.32   if ( value != String::EMPTY )
794                         {
795                           if ( System::is_absolute_path((const char *)value.getCString()) )
796                             {
797 chip             1.68         return value;
798 tony             1.32       }
799                       
800                           //
801                           // Get the pegasusHome and prepend it
802                           //
803 konrad.r         1.50 
804                           String temp = value;
805                           Uint32 pos =0;
806                           Uint32 token=0;
807                           do {
808 konrad.r         1.51       if (( pos = temp.find(FileSystem::getPathDelimiter())) == PEG_NOT_FOUND) {
809 konrad.r         1.50 	pos = temp.size();
810                       	token = 0;
811                             }
812                             else {
813                       	  token = 1;
814                             }
815 chip             1.68       if  (System::is_absolute_path((const char *)temp.subString(0,pos).getCString()))
816 konrad.r         1.50       {
817                       	homedPath.append(temp.subString(0,pos));
818                             } else
819                                homedPath.append( _pegasusHome + "/" + temp.subString(0, pos));
820                       
821                             if (token == 1)
822 konrad.r         1.51 	homedPath.append(FileSystem::getPathDelimiter());
823 chip             1.68       temp.remove(0,pos+token);
824 konrad.r         1.50     }
825 chip             1.68     while ( temp.size() > 0 );
826                       
827 tony             1.32   }
828                         return homedPath;
829 kumpf            1.6  }
830 chip             1.68 
831 kumpf            1.83 Boolean ConfigManager::parseBooleanValue(const String& propertyValue)
832                       {
833                           return String::equalNoCase(propertyValue, "true");
834                       }
835                       
836 mike             1.2  PEGASUS_NAMESPACE_END
837                       

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2