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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2