(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 thilo.boehm 1.87 #include <Pegasus/Common/Logger.h>
 41 kumpf       1.12 #include <Pegasus/Common/PegasusVersion.h>
 42 tony        1.32 #include <Pegasus/Common/FileSystem.h>
 43 kumpf       1.81 #include <Pegasus/Common/Constants.h>
 44 kumpf       1.12 
 45 mike        1.2  #include "ConfigExceptions.h"
 46                  #include "ConfigManager.h"
 47                  
 48                  PEGASUS_NAMESPACE_BEGIN
 49                  
 50                  /////////////////////////////////////////////////////////////////////////////
 51                  //
 52                  //  When a new property owner is created be sure to create a static
 53                  //  object of the new property owner.
 54                  //
 55                  /////////////////////////////////////////////////////////////////////////////
 56                  
 57 kumpf       1.96 TracePropertyOwner ConfigManager::traceOwner;
 58                  LogPropertyOwner ConfigManager::logOwner;
 59                  DefaultPropertyOwner ConfigManager::defaultOwner;
 60                  SecurityPropertyOwner ConfigManager::securityOwner;
 61                  RepositoryPropertyOwner ConfigManager::repositoryOwner;
 62                  ShutdownPropertyOwner ConfigManager::shutdownOwner;
 63                  FileSystemPropertyOwner ConfigManager::fileSystemOwner;
 64                  ProviderDirPropertyOwner ConfigManager::providerDirOwner;
 65                  NormalizationPropertyOwner ConfigManager::normalizationOwner;
 66                  
 67 mike        1.2  
 68                  /////////////////////////////////////////////////////////////////////////////
 69                  //
 70 chip        1.68 //   When a new property is created be sure to add the new property name
 71 kumpf       1.10 //   and the owner object to the OwnerEntry table below.
 72 mike        1.2  //
 73                  /////////////////////////////////////////////////////////////////////////////
 74                  
 75 kumpf       1.10 struct OwnerEntry
 76                  {
 77                      const char* propertyName;
 78                      ConfigPropertyOwner* propertyOwner;
 79                  };
 80                  
 81 kumpf       1.14 static struct OwnerEntry _properties[] =
 82 mike        1.2  {
 83 kumpf       1.88     {"traceLevel",
 84 kumpf       1.96          (ConfigPropertyOwner*)&ConfigManager::traceOwner},
 85 kumpf       1.88     {"traceComponents",
 86 kumpf       1.96          (ConfigPropertyOwner*)&ConfigManager::traceOwner},
 87 kumpf       1.88     {"traceFilePath",
 88 kumpf       1.96          (ConfigPropertyOwner*)&ConfigManager::traceOwner},
 89 r.kieninger 1.98     {"traceFacility",
 90                           (ConfigPropertyOwner*)&ConfigManager::traceOwner},
 91 thilo.boehm 1.102     {"traceMemoryBufferKbytes",
 92                            (ConfigPropertyOwner*)&ConfigManager::traceOwner},
 93 konrad.r    1.71  #if !defined(PEGASUS_USE_SYSLOGS)
 94 kumpf       1.88      {"logdir",
 95 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::logOwner},
 96 mreddy      1.103     {"maxLogFileSizeKBytes",
 97                            (ConfigPropertyOwner*)&ConfigManager::logOwner},
 98 konrad.r    1.71  #endif
 99 kumpf       1.88      {"logLevel",
100 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::logOwner},
101 kumpf       1.88      {"enableHttpConnection",
102 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
103 kumpf       1.88      {"enableHttpsConnection",
104 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
105 kumpf       1.88      {"httpPort",
106 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
107 kumpf       1.88      {"httpsPort",
108 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
109 kumpf       1.88      {"home",
110 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
111 kumpf       1.88      {"daemon",
112 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
113 kumpf       1.88      {"slp",
114 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
115 kumpf       1.88      {"enableAssociationTraversal",
116 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
117 kumpf       1.88      {"enableIndicationService",
118 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
119 kumpf       1.88      {"enableAuthentication",
120 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
121 kumpf       1.88      {"enableNamespaceAuthorization",
122 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
123 kumpf       1.88      {"httpAuthType",
124 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
125 kumpf       1.88      {"passwordFilePath",
126 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
127 kumpf       1.88      {"sslCertificateFilePath",
128 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
129 kumpf       1.88      {"sslKeyFilePath",
130 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
131 kumpf       1.88      {"sslTrustStore",
132 kumpf       1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
133 sushma.fernandes 1.79  #ifdef PEGASUS_ENABLE_SSL_CRL_VERIFICATION
134 kumpf            1.88      {"crlStore",
135 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
136 sushma.fernandes 1.79  #endif
137 kumpf            1.88      {"sslClientVerificationMode",
138 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
139 kumpf            1.88      {"sslTrustStoreUserName",
140 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
141 gerarda          1.42  #ifdef PEGASUS_KERBEROS_AUTHENTICATION
142 kumpf            1.88      {"kerberosServiceName",
143 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
144 gerarda          1.42  #endif
145 thilo.boehm      1.94  #ifdef PEGASUS_OS_ZOS
146                            {"enableCFZAPPLID",
147 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
148 thilo.boehm      1.94  #endif
149 kumpf            1.88      {"repositoryIsDefaultInstanceProvider",
150 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::repositoryOwner},
151 kumpf            1.88      {"enableBinaryRepository",
152 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::repositoryOwner},
153 kumpf            1.88      {"shutdownTimeout",
154 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::shutdownOwner},
155 kumpf            1.88      {"repositoryDir",
156 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::fileSystemOwner},
157 b.whiteley       1.97      {"providerManagerDir",
158                                 (ConfigPropertyOwner*)&ConfigManager::fileSystemOwner},
159 kumpf            1.88      {"providerDir",
160 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::providerDirOwner},
161 kumpf            1.88      {"enableRemotePrivilegedUserAccess",
162 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
163 kumpf            1.88      {"enableSubscriptionsForNonprivilegedUsers",
164 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
165 kumpf            1.57  #ifdef PEGASUS_ENABLE_USERGROUP_AUTHORIZATION
166 kumpf            1.88      {"authorizedUserGroups",
167 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::securityOwner},
168 kumpf            1.57  #endif
169 kumpf            1.88      {"messageDir",
170 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::fileSystemOwner},
171 chip             1.68  #ifdef PEGASUS_ENABLE_OBJECT_NORMALIZATION
172 kumpf            1.88      {"enableNormalization",
173 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::normalizationOwner},
174 kumpf            1.88      {"excludeModulesFromNormalization",
175 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::normalizationOwner},
176 chip             1.68  #endif
177 kumpf            1.88      {"forceProviderProcesses",
178 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
179 kumpf            1.88      {"maxProviderProcesses",
180 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
181 kumpf            1.91  #ifdef PEGASUS_ENABLE_AUDIT_LOGGER
182 kumpf            1.88      {"enableAuditLog",
183 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
184 yi.zhou          1.86  #endif
185 kumpf            1.88      {"socketWriteTimeout",
186 kumpf            1.96           (ConfigPropertyOwner*)&ConfigManager::defaultOwner},
187 dave.sudlik      1.95      {"idleConnectionTimeout",
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                        
275                            //
276                            // get property owner object from the config table.
277                            //
278                            if (!_propertyTable->ownerTable.lookup(propertyName, propertyOwner))
279                            {
280 chip             1.68          throw UnrecognizedConfigProperty(propertyName);
281 kumpf            1.59      }
282                        
283 kumpf            1.73      if (useConfigFiles && !propertyOwner->isValid(propertyName, propertyValue))
284                            {
285                                throw InvalidPropertyValue(propertyName, propertyValue);
286                            }
287                        
288                            //
289                            // update the value with the property owner
290                            //
291                            propertyOwner->initCurrentValue(propertyName, propertyValue);
292                        
293                            if (useConfigFiles)
294 kumpf            1.59      {
295                                //
296 kumpf            1.73          // update the value in the current config file
297 kumpf            1.59          //
298 kumpf            1.88          return _configFileHandler->updateCurrentValue(
299                                    propertyName, propertyValue, false);
300 kumpf            1.59      }
301                        
302                            return true;
303                        }
304                        
305 chip             1.68  /**
306 kumpf            1.88      Update current value of a property.
307 mike             1.2   */
308                        Boolean ConfigManager::updateCurrentValue(
309 chip             1.68      const String& name,
310 kumpf            1.13      const String& value,
311                            Boolean unset)
312 mike             1.2   {
313 kumpf            1.90      String prevValue;
314 mike             1.2   
315                            //
316                            // get property owner object from the config table.
317                            //
318                            ConfigPropertyOwner* propertyOwner;
319                        
320 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
321 mike             1.2       {
322 chip             1.68          throw UnrecognizedConfigProperty(name);
323 mike             1.2       }
324                        
325 kumpf            1.73      //
326                            // keep a copy of the existing config value
327                            //
328                            prevValue = propertyOwner->getCurrentValue(name);
329                        
330                            //
331                            // ask owner to update the current value
332                            //
333                            if (unset)
334 mike             1.2       {
335 kumpf            1.73          propertyOwner->updateCurrentValue(name,
336                                    propertyOwner->getDefaultValue(name));
337                            }
338                            else
339                            {
340                                if (useConfigFiles && !propertyOwner->isValid(name, value))
341                                {
342                                    throw InvalidPropertyValue(name, value);
343                                }
344                        
345                                propertyOwner->updateCurrentValue(name, value);
346                            }
347 mike             1.2   
348 kumpf            1.73      if (useConfigFiles)
349                            {
350 mike             1.2           //
351 kumpf            1.73          // update the new value in the current config file
352 mike             1.2           //
353 kumpf            1.73          if (!_configFileHandler->updateCurrentValue(name, value, unset))
354 mike             1.2           {
355 kumpf            1.73              // Failed to update the current value, so roll back.
356                                    propertyOwner->updateCurrentValue(name, prevValue);
357                                    return false;
358 mike             1.2           }
359                            }
360 kumpf            1.29  
361 kumpf            1.59      return true;
362 mike             1.2   }
363                        
364                        
365 chip             1.68  /**
366 mike             1.2   Update planned value of a property.
367                        */
368                        Boolean ConfigManager::updatePlannedValue(
369 chip             1.68      const String& name,
370 kumpf            1.13      const String& value,
371                            Boolean unset)
372 mike             1.2   {
373 kumpf            1.90      String prevValue;
374 mike             1.2   
375                            //
376                            // get property owner object from the config table.
377                            //
378                            ConfigPropertyOwner* propertyOwner;
379                        
380 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
381 mike             1.2       {
382 chip             1.68          throw UnrecognizedConfigProperty(name);
383 mike             1.2       }
384                        
385 kumpf            1.73      //
386                            // keep a copy of the existing config value
387                            //
388                            prevValue = propertyOwner->getPlannedValue(name);
389                        
390                            //
391                            // ask owner to update the planned value to new value
392                            //
393                            if (unset)
394                            {
395                                propertyOwner->updatePlannedValue(name,
396                                    propertyOwner->getDefaultValue(name));
397                            }
398                            else
399 mike             1.2       {
400 kumpf            1.73          if (useConfigFiles && !propertyOwner->isValid(name, value))
401                                {
402                                    throw InvalidPropertyValue(name, value);
403                                }
404                        
405                                propertyOwner->updatePlannedValue(name, value);
406                            }
407 mike             1.2   
408 kumpf            1.73      if (useConfigFiles)
409                            {
410 mike             1.2           //
411 kumpf            1.73          // update the new value in the planned config file
412 mike             1.2           //
413 kumpf            1.73          if (!_configFileHandler->updatePlannedValue(name, value, unset))
414 kumpf            1.13          {
415 kumpf            1.73              // Failed to update the planned value, so roll back.
416                                    propertyOwner->updatePlannedValue(name, prevValue);
417                                    return false;
418 mike             1.2           }
419                            }
420 kumpf            1.29  
421 kumpf            1.59      return true;
422 mike             1.2   }
423                        
424                        
425 chip             1.68  /**
426 mike             1.2   Validate the value of a specified property.
427                        */
428                        Boolean ConfigManager::validatePropertyValue(
429 chip             1.68      const String& name,
430 mike             1.2       const String& value)
431                        {
432                            //
433                            // get property owner object from config table
434                            //
435                            ConfigPropertyOwner* propertyOwner;
436                        
437 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
438 mike             1.2       {
439 chip             1.68          throw UnrecognizedConfigProperty(name);
440 mike             1.2       }
441                        
442 kumpf            1.88      return propertyOwner->isValid(name, value);
443 mike             1.2   }
444                        
445                        /**
446                        Get default value of the specified property.
447                        */
448 aruran.ms        1.77  String ConfigManager::getDefaultValue(const String& name) const
449 mike             1.2   {
450                            //
451 kumpf            1.10      // Check for a property with a fixed value
452                            //
453                            const char* fixedValue;
454                        
455                            if (_propertyTable->fixedValueTable.lookup(name, fixedValue))
456                            {
457                                return fixedValue;
458                            }
459                        
460                            //
461 mike             1.2       // get property owner object from config table
462                            //
463                            ConfigPropertyOwner* propertyOwner;
464                        
465 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
466 mike             1.2       {
467                                throw UnrecognizedConfigProperty(name);
468                            }
469                        
470 kumpf            1.88      return propertyOwner->getDefaultValue(name);
471 mike             1.2   }
472                        
473 chip             1.68  /**
474 kumpf            1.88      Get current value of the specified property.
475 mike             1.2   */
476 aruran.ms        1.77  String ConfigManager::getCurrentValue(const String& name) const
477 mike             1.2   {
478                            //
479 kumpf            1.10      // Check for a property with a fixed value
480                            //
481                            const char* fixedValue;
482                        
483                            if (_propertyTable->fixedValueTable.lookup(name, fixedValue))
484                            {
485                                return fixedValue;
486                            }
487                        
488                            //
489 mike             1.2       // get property owner object from config table
490                            //
491                            ConfigPropertyOwner* propertyOwner;
492                        
493 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
494 mike             1.2       {
495 chip             1.68          throw UnrecognizedConfigProperty(name);
496 mike             1.2       }
497                        
498 kumpf            1.88      return propertyOwner->getCurrentValue(name);
499 mike             1.2   }
500                        
501                        
502 chip             1.68  /**
503 mike             1.2   Get planned value of the specified property.
504                        */
505 aruran.ms        1.77  String ConfigManager::getPlannedValue(const String& name) const
506 mike             1.2   {
507                            //
508 kumpf            1.10      // Check for a property with a fixed value
509                            //
510                            const char* fixedValue;
511                        
512                            if (_propertyTable->fixedValueTable.lookup(name, fixedValue))
513                            {
514                                return fixedValue;
515                            }
516                        
517                            //
518 mike             1.2       // get property owner object from config table
519                            //
520                            ConfigPropertyOwner* propertyOwner;
521                        
522 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
523 mike             1.2       {
524 chip             1.68          throw UnrecognizedConfigProperty(name);
525 mike             1.2       }
526                        
527 kumpf            1.88      return propertyOwner->getPlannedValue(name);
528 mike             1.2   }
529                        
530                        
531 chip             1.68  /**
532 mike             1.2   Get all the attributes of the specified property.
533                        */
534                        void ConfigManager::getPropertyInfo(
535 chip             1.68      const String& name,
536 aruran.ms        1.77      Array<String>& propertyInfo) const
537 mike             1.2   {
538                            //
539                            // get property owner object from config table
540                            //
541                            ConfigPropertyOwner* propertyOwner;
542                        
543 kumpf            1.10      if (!_propertyTable->ownerTable.lookup(name, propertyOwner))
544 mike             1.2       {
545 chip             1.68          throw UnrecognizedConfigProperty(name);
546 mike             1.2       }
547                        
548                            propertyOwner->getPropertyInfo(name, propertyInfo);
549                        }
550                        
551                        
552 chip             1.68  /**
553 mike             1.2   Get a list of all property names.
554                        */
555 kumpf            1.59  void ConfigManager::getAllPropertyNames(
556                            Array<String>& propertyNames,
557 aruran.ms        1.77      Boolean includeHiddenProperties) const
558 mike             1.2   {
559 kumpf            1.41      Array<String> propertyInfo;
560 mike             1.2       propertyNames.clear();
561                        
562 kumpf            1.10      for (OwnerTable::Iterator i = _propertyTable->ownerTable.start(); i; i++)
563 mike             1.2       {
564 kumpf            1.59          if (includeHiddenProperties)
565 kumpf            1.41          {
566                                    propertyNames.append(i.key());
567                                }
568 kumpf            1.59          else
569                                {
570                                    //
571                                    // Check if property is to be externally visible or not.
572                                    // If the property should not be externally visible do not list the
573                                    // property information.
574                                    //
575                                    propertyInfo.clear();
576                                    getPropertyInfo(i.key(), propertyInfo);
577                        
578                                    if (propertyInfo[5] == STRING_TRUE)
579                                    {
580                                        propertyNames.append(i.key());
581                                    }
582                                }
583 mike             1.2       }
584                        }
585                        
586                        
587 chip             1.68  /**
588 kumpf            1.88      Merge the config properties from the specified planned config file
589                            with the properties in the specified current config file.
590 mike             1.2   */
591                        void ConfigManager::mergeConfigFiles(
592 chip             1.68      const String& currentFile,
593 mike             1.2       const String& plannedFile)
594                        {
595 kumpf            1.59      PEGASUS_ASSERT(useConfigFiles);
596                        
597 kumpf            1.73      _configFileHandler.reset(new ConfigFileHandler(currentFile, plannedFile));
598 mike             1.2   
599 mateus.baur      1.89      //
600                            // copy the contents of planned config file over
601                            // the current config file
602                            //
603                            _configFileHandler->copyPlannedFileOverCurrentFile();
604                        
605 kumpf            1.73      _loadConfigProperties();
606 mike             1.2   }
607                        
608                        
609 chip             1.68  /**
610 kumpf            1.88      Merge the config properties from the default planned config file
611                            with the properties in the default current config file.
612 mike             1.2   */
613                        void ConfigManager::mergeConfigFiles()
614                        {
615 kumpf            1.59      PEGASUS_ASSERT(useConfigFiles);
616                        
617 kumpf            1.73      _configFileHandler.reset(new ConfigFileHandler());
618 mike             1.2   
619 mateus.baur      1.89      //
620                            // copy the contents of planned config file over
621                            // the current config file
622                            //
623                            _configFileHandler->copyPlannedFileOverCurrentFile();
624                        
625                            _loadConfigProperties();
626                        }
627                        
628                        
629                        /**
630                        Load the config properties from the current and planned files.
631                        */
632                        void ConfigManager::loadConfigFiles()
633                        {
634                            PEGASUS_ASSERT(useConfigFiles);
635                        
636                            _configFileHandler.reset(new ConfigFileHandler());
637                        
638 kumpf            1.73      _loadConfigProperties();
639 mike             1.2   }
640                        
641                        
642 chip             1.68  /**
643 kumpf            1.88      Merge config properties specified on the command line
644 mike             1.2   */
645                        void ConfigManager::mergeCommandLine(int& argc, char**& argv)
646                        {
647                            // Remove the command name from the command line
648 kumpf            1.3       if (argc > 0)
649                            {
650                                memmove(&argv[0], &argv[1], (argc) * sizeof(char*));
651                                argc--;
652                            }
653 mike             1.2   
654                            //
655                            //  Merge properties from the command line
656                            //
657 kumpf            1.9       for (Sint32 i = 0; i < argc; )
658 mike             1.2       {
659                                const char* arg = argv[i];
660                        
661 kumpf            1.34          if (*arg == '-')
662                                {
663                                    throw UnrecognizedCommandLineOption();
664                                }
665                        
666 tony             1.33          // Get the config option
667                                //const char* configOption = argv[i];
668                                if (!_initPropertyWithCommandLineOption(arg))
669 mike             1.2           {
670 chip             1.68              throw UnrecognizedConfigProperty(arg);
671 mike             1.2           }
672                        
673                                // Remove the option from the command line
674                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
675                                argc--;
676                            }
677                        }
678                        
679                        
680 chip             1.68  /**
681 kumpf            1.88      load config properties from the file
682 mike             1.2   */
683                        void ConfigManager::_loadConfigProperties()
684                        {
685 kumpf            1.59      PEGASUS_ASSERT(useConfigFiles);
686                        
687 mike             1.2       //
688                            // load all the properties from the current and planned
689                            // config files in to tables.
690                            //
691                            _configFileHandler->loadAllConfigProperties();
692                        
693 kumpf            1.49      Array<CIMName> propertyNames;
694                            Array<String>  propertyValues;
695                        
696                            _configFileHandler->getAllCurrentProperties(propertyNames, propertyValues);
697                        
698                            Uint32 size = propertyNames.size();
699                        
700 mike             1.2       //
701                            // initialize all the property owners with the values
702                            // from the config files.
703                            //
704 kumpf            1.49      for (Uint32 i = 0; i < size; i++)
705 mike             1.2       {
706 kumpf            1.49          //
707                                // initialize the current value of the property owner
708                                // with the value from the config file handler
709                                //
710                                try
711 mike             1.2           {
712 kumpf            1.13              //
713 kumpf            1.49              // get property owner object from the config table.
714 kumpf            1.13              //
715 kumpf            1.49              ConfigPropertyOwner* propertyOwner;
716                        
717                                    String propertyName = propertyNames[i].getString();
718                        
719                                    if (_propertyTable->ownerTable.lookup(
720                                        propertyName, propertyOwner))
721 mike             1.2               {
722 kumpf            1.49                  if (propertyOwner->isValid(
723                                            propertyName, propertyValues[i]))
724                                        {
725                                            propertyOwner->initCurrentValue(
726                                                propertyName, propertyValues[i]);
727 mike             1.2   
728 kumpf            1.49                      propertyOwner->initPlannedValue(
729                                                propertyName, propertyValues[i]);
730                                        }
731                                        else
732 mike             1.2                   {
733 kumpf            1.49                      throw InvalidPropertyValue(propertyName, propertyValues[i]);
734 mike             1.2                   }
735                                    }
736 kumpf            1.49              else
737 mike             1.2               {
738 kumpf            1.88                  // if the property is a fixed property then just log that
739                                        // this property is not supported and continue.  In all other
740                                        // cases terminate the cimserver
741 thilo.boehm      1.87                  if (_propertyTable->fixedValueTable.contains(propertyName))
742                                        {
743 kumpf            1.88                      Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
744                                                Logger::WARNING,
745 kumpf            1.100                         MessageLoaderParms(
746                                                    "Config.ConfigManager.NOTSUPPORTED_CONFIG_PROPERTY",
747                                                    "Configuration property $0 is not supported. "
748                                                        "Setting ignored.",
749                                                    propertyName));
750 kumpf            1.88                  }
751                                        else
752 thilo.boehm      1.87                  {
753 kumpf            1.88                      throw UnrecognizedConfigProperty(propertyName);
754 thilo.boehm      1.87                  }
755 mike             1.2               }
756 kumpf            1.49          }
757 kumpf            1.88          catch (UnrecognizedConfigProperty& ucp)
758 kumpf            1.49          {
759 thilo.boehm      1.101             PEG_TRACE_CSTRING(TRC_CONFIG, Tracer::LEVEL1, 
760                                        (const char*)ucp.getMessage().getCString());
761 kumpf            1.49              throw;
762                                }
763 kumpf            1.88          catch (InvalidPropertyValue& ipv)
764 kumpf            1.49          {
765 thilo.boehm      1.101             PEG_TRACE_CSTRING(TRC_CONFIG, Tracer::LEVEL1, 
766                                        (const char*)ipv.getMessage().getCString());
767 kumpf            1.49              throw;
768 mike             1.2           }
769                            }
770                        }
771                        
772                        
773 chip             1.68  /**
774 kumpf            1.88      Initialize config property with the value specified in the command line.
775 mike             1.2   */
776                        Boolean ConfigManager::_initPropertyWithCommandLineOption(
777 chip             1.68      const String& option)
778 mike             1.2   {
779 kumpf            1.59      Uint32 pos = option.find('=');
780 mike             1.2       if (pos == PEG_NOT_FOUND)
781                            {
782                                //
783                                // The property value was not specified
784                                //
785 chip             1.68          throw UnrecognizedConfigProperty(option);
786 mike             1.2       }
787                        
788                            //
789                            // Get the property name and value
790                            //
791 kumpf            1.59      String propertyName = option.subString(0, pos);
792 kumpf            1.88      String propertyValue = option.subString(pos + 1);
793 mike             1.2   
794 kumpf            1.59      return initCurrentValue(propertyName, propertyValue);
795 mike             1.2   }
796                        
797 chip             1.68  /**
798 kumpf            1.88      Initialize config property owners and add them to the property owner table
799 mike             1.2   */
800 kumpf            1.10  void ConfigManager::_initPropertyTable()
801 mike             1.2   {
802                            //
803 kumpf            1.10      // add config property and its fixed value to fixed value table
804                            //
805                            for (Uint32 i = 0; i < NUM_FIXED_PROPERTIES; i++)
806                            {
807 kumpf            1.14          _propertyTable->fixedValueTable.insert(_fixedValues[i].propertyName,
808                                    _fixedValues[i].fixedValue);
809 kumpf            1.10      }
810                        
811                            //
812                            // add config property and its owner object to owners table (but only if
813                            // the property is not also listed in the fixed value table.
814 mike             1.2       //
815                            for (Uint32 i = 0; i < NUM_PROPERTIES; i++)
816                            {
817 w.otsuka         1.80          const char* fixedValue = 0;
818 mike             1.2   
819 kumpf            1.31          _properties[i].propertyOwner->initialize();
820                        
821 kumpf            1.10          if (!_propertyTable->fixedValueTable.lookup(
822 kumpf            1.14                  _properties[i].propertyName, fixedValue))
823 kumpf            1.10          {
824 kumpf            1.14              _propertyTable->ownerTable.insert(_properties[i].propertyName,
825                                        _properties[i].propertyOwner);
826 kumpf            1.31          }
827                                else
828                                {
829                                    //
830                                    // Set the value for the fixed properties
831                                    //
832                                    _properties[i].propertyOwner->initCurrentValue(
833                                        _properties[i].propertyName, fixedValue);
834 kumpf            1.10          }
835 mike             1.2       }
836                        }
837                        
838 kumpf            1.6   /**
839 kumpf            1.88      Get Pegasus Home
840 kumpf            1.6   */
841                        String ConfigManager::getPegasusHome()
842                        {
843                            return _pegasusHome;
844                        }
845                        
846                        /**
847 kumpf            1.88      Set Pegasus Home variable
848 kumpf            1.6   */
849 aruran.ms        1.74  void ConfigManager::setPegasusHome(const String& home)
850 kumpf            1.6   {
851 kumpf            1.88      if (home != String::EMPTY)
852 kumpf            1.6       {
853 kumpf            1.88          _pegasusHome = home;
854 kumpf            1.6       }
855                        }
856                        
857                        /**
858 kumpf            1.88      Get the homed path for a given property.
859 kumpf            1.6   */
860                        String ConfigManager::getHomedPath(const String& value)
861                        {
862 kumpf            1.90      String homedPath;
863 kumpf            1.88  
864                            if (value != String::EMPTY)
865                            {
866                                if (System::is_absolute_path((const char *)value.getCString()))
867                                {
868                                    return value;
869                                }
870 chip             1.68  
871 kumpf            1.88          //
872                                // Get the pegasusHome and prepend it
873                                //
874                        
875                                String temp = value;
876                                Uint32 pos = 0;
877                                Uint32 token = 0;
878                                do
879                                {
880                                    if ((pos = temp.find(FileSystem::getPathDelimiter())) ==
881                                            PEG_NOT_FOUND)
882                                    {
883                                        pos = temp.size();
884                                        token = 0;
885                                    }
886                                    else
887                                    {
888                                        token = 1;
889                                    }
890                        
891                                    if (System::is_absolute_path(
892 kumpf            1.88                      (const char *)temp.subString(0, pos).getCString()))
893                                    {
894                                        homedPath.append(temp.subString(0,pos));
895                                    }
896                                    else
897                                    {
898                                        homedPath.append(_pegasusHome + "/" + temp.subString(0, pos));
899                                    }
900                        
901                                    if (token == 1)
902                                        homedPath.append(FileSystem::getPathDelimiter());
903                                    temp.remove(0, pos + token);
904                                } while (temp.size() > 0);
905 konrad.r         1.50      }
906 kumpf            1.88      return homedPath;
907 kumpf            1.6   }
908 chip             1.68  
909 kumpf            1.83  Boolean ConfigManager::parseBooleanValue(const String& propertyValue)
910                        {
911                            return String::equalNoCase(propertyValue, "true");
912                        }
913                        
914 mike             1.2   PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2