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

   1 karl  1.18 //%2005////////////////////////////////////////////////////////////////////////
   2 karl  1.1  //
   3 karl  1.12 // 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.3  // IBM Corp.; EMC Corporation, The Open Group.
   7 karl  1.12 // 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.18 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
  11 karl  1.1  //
  12            // Permission is hereby granted, free of charge, to any person obtaining a copy
  13            // 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            // 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.32 //
  19 karl          1.1  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  20                    // 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                    // 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                    // 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                    //==============================================================================
  29                    //
  30                    // Author: Karl Schopmeyer (k.schopmeyer@opengroup.org)
  31                    //
  32                    // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
  33                    //                (carolann_graves@hp.com)
  34 karl          1.8  //              Karl Schopmeyer - Created Cim_Namespace capabilities.
  35                    //              Karl Schopmeyer - added objectmanager and communication classes
  36 joyce.j       1.30 //              Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#3194
  37 david.dillard 1.32 //              David Dillard, VERITAS Software Corp.
  38                    //                  (david.dillard@veritas.com)
  39 aruran.ms     1.36 //              Aruran, IBM (ashanmug@in.ibm.com) for Bug# 3659
  40 karl          1.1  //
  41                    //%////////////////////////////////////////////////////////////////////////////
  42                    
  43                    
  44                    ///////////////////////////////////////////////////////////////////////////////
  45 karl          1.5  //  Interop Provider - This provider services those classes from the
  46                    //  DMTF Interop schema association with the CIMOM itself
  47 karl          1.1  //
  48 karl          1.5  //  This provider services the following classes:
  49                    //      CIMObjectManager
  50                    //      CIM_ObjectManagerCommunicationMechanism
  51                    //      CIM_CIMXMLCommunicationMechanism
  52 karl          1.19 //      CIM_ProtocolAdapter  (Note: Removed because deprecated class in cim 2.9)
  53 karl          1.48 //      CIM_Namespace -- Only creates are allowed directly against this class.
  54                    //              This allows the publice class CIM_Namespace to be used to
  55                    //              create namespaces.  Modifies, deletes must use the returned
  56                    //              paths. Enumerates references, etc. all use hiearchy.
  57                    //              NOTE: Changes the class to PG_Namespace and returns that
  58                    //              objectpath
  59 david.dillard 1.32 //
  60 karl          1.37 //      PG_Namespace - Pegasus particular subclass of CIM_Namespace that
  61                    //      add the parameters for shared namespaces
  62                    //
  63                    //      PG_CIMXMLCommunicationMechanism - Pegasus subclass of 
  64                    //      CIM_CIMXMLCommunicationMechanism that adds support for passing
  65                    //      additional communication parameters (ie. port, https vs. http, etc.)
  66                    //   
  67 karl          1.5  //      It also services the Interop associations tied to these classes
  68                    //      including:
  69                    //      CIM_NamespaceInManager
  70                    //      ...
  71 karl          1.48 //      Interop forces all creates to the PEGASUS_NAMESPACENAME_INTEROP 
  72 karl          1.52 //      namespace. There is a test on each operation that returns 
  73                    //      the Invalid Class CIMDError
  74 karl          1.11 //      This is a control provider and as such uses the Tracer functions
  75                    //      for data and function traces.  Since we do not expect high volume
  76 david.dillard 1.32 //      use we added a number of traces to help diagnostics.
  77 karl          1.1  ///////////////////////////////////////////////////////////////////////////////
  78 karl          1.11 /* TODO LIST:
  79                        1. Finish the association functions
  80 david.dillard 1.32 
  81 karl          1.11     2. UUID generation should become a system function since it will be used
  82                           by many providers, etc. as part of id generation.
  83 david.dillard 1.32 
  84 karl          1.11     3. Review the key parameters on create, etc. to be sort out which are
  85                           required from user and which we can supply.  I think we are asking too
  86                           much of the user right now.
  87 karl          1.53 
  88 tony          1.6  */
  89 karl          1.1  
  90                    #include <Pegasus/Common/Config.h>
  91                    #include <Pegasus/Common/PegasusVersion.h>
  92                    
  93                    #include <cctype>
  94                    #include <iostream>
  95                    
  96                    #include "InteropProvider.h"
  97 tony          1.6  #include "Guid.h"
  98 karl          1.1  #include <Pegasus/Common/String.h>
  99                    #include <Pegasus/Common/System.h>
 100                    #include <Pegasus/Common/ArrayInternal.h>
 101                    #include <Pegasus/Common/CIMName.h>
 102                    #include <Pegasus/Common/CIMType.h>
 103                    #include <Pegasus/Common/CIMInstance.h>
 104                    #include <Pegasus/Common/CIMObjectPath.h>
 105                    #include <Pegasus/Common/InternalException.h>
 106                    #include <Pegasus/Common/CIMStatusCode.h>
 107                    #include <Pegasus/Common/Tracer.h>
 108                    #include <Pegasus/Common/OperationContext.h>
 109                    #include <Pegasus/Config/ConfigManager.h>
 110 tony          1.6  #include <Pegasus/Common/XmlWriter.h>
 111 karl          1.8  #include <Pegasus/Common/StatisticalData.h>
 112                    #include <Pegasus/Common/HashTable.h>
 113 karl          1.1  
 114                    
 115 tony          1.6  #include <stdlib.h>
 116 karl          1.1  
 117 tony          1.6  //The following include is needed for gethostbyname
 118                    #if defined(PEGASUS_OS_TYPE_WINDOWS)
 119                    #include <objbase.h>
 120                    #else
 121                    #include <netdb.h>
 122                    #include <arpa/inet.h>
 123                    #endif
 124 karl          1.1  
 125                    PEGASUS_USING_STD;
 126                    
 127                    PEGASUS_NAMESPACE_BEGIN
 128                    
 129 karl          1.27 #define CDEBUG(X)
 130 karl          1.11 #define LDEBUG()
 131 karl          1.46 //#define CDEBUG(X) PEGASUS_STD(cout) << "InteropProvider (" << __LINE__ << ") " << X << PEGASUS_STD(endl)
 132 kumpf         1.35 //#define LDEBUG(X) Logger::put (Logger::DEBUG_LOG, "InteropProvider", Logger::TRACE, "$0", X)
 133 tony          1.6  
 134                    //**************************************************************************
 135                    //
 136                    //    Constants representing the class names processed
 137                    //
 138                    //**************************************************************************
 139                    
 140 karl          1.10 const char * thisProvider = "InteropProvider";
 141 karl          1.51 
 142 karl          1.56 // This Mutex serializes access to the instance change CIM requests. Keeps from mixing
 143                    // instance creates, modifications, and deletes. This keeps the provider from
 144                    // simultaneously execute creates, modifications, and deletes of instances. While
 145                    // these operations are largely protected by the locking mechanisms of the 
 146                    // repository this mutex guarantees that the provider will not simultaneously
 147                    // execute the instance change operations.
 148                    Mutex changeControlMutex;
 149 karl          1.1  /**
 150                        The constants representing the class names we process
 151                    */
 152                    static const CIMName CIM_NAMESPACE_CLASSNAME  = CIMName ("CIM_Namespace");
 153 karl          1.8  static const CIMName PG_NAMESPACE_CLASSNAME  = CIMName ("PG_Namespace");
 154                    
 155 karl          1.1  static const CIMName CIM_OBJECTMANAGER_CLASSNAME  = CIMName ("CIM_ObjectManager");
 156 david.dillard 1.32 static const CIMName CIM_OBJECTMANAGERCOMMUNICATIONMECHANISM_CLASSNAME  =
 157 karl          1.1          CIMName ("CIM_ObjectManagerCommunicationMechanism");
 158 david.dillard 1.32 static const CIMName PG_CIMXMLCOMMUNICATIONMECHANISM_CLASSNAME  =
 159 tony          1.6          CIMName ("PG_CIMXMLCommunicationMechanism");
 160 david.dillard 1.32 static const CIMName CIM_COMMMECHANISMFORMANAGER_CLASSNAME  =
 161 tony          1.6          CIMName ("CIM_CommMechanismForManager");
 162 david.dillard 1.32 static const CIMName CIM_NAMESPACEINMANAGER_CLASSNAME  =
 163 tony          1.6          CIMName ("CIM_NamespaceInManager");
 164 karl          1.1  
 165 karl          1.37 // Property Names for CIM_Namespace Class
 166 karl          1.1  static const CIMName NAMESPACE_PROPERTYNAME  = CIMName ("Name");
 167 karl          1.37 
 168                    // Root Namespace Name for test.
 169 karl          1.1  static const CIMNamespaceName ROOTNS  = CIMNamespaceName ("root");
 170                    
 171                    
 172                    // Property names for CIM_ObjectManager Class
 173                    static const CIMName OM_GATHERSTATISTICALDATA  =
 174                     CIMName ("GatherStatisticalData");
 175 karl          1.37 
 176 tony          1.6  // Property for the slp template.
 177                    static const CIMName OM_DESCRIPTIONPROPERTY =
 178                        CIMName("Description");
 179 karl          1.1  
 180                    // Property Names for ObjectManagerCommunicationMechanism Class
 181 david.dillard 1.32 static const CIMName OM_COMMUNICATIONMECHANISM  =
 182 karl          1.1          CIMName ("CommunicationMechanism");
 183                    static const CIMName OM_FUNCTIONALPROFILESSUPPORTED  =
 184                     CIMName ("FunctionalProfilesSupported");
 185                    static const CIMName OM_FUNCTIONALPROFILEDESCRIPTIONS  =
 186                     CIMName ("FunctionalProfileDescriptions");
 187                    static const CIMName OM_AUTHENTICATIONMECHANISMSSUPPORTED  =
 188                     CIMName ("AuthenticationMechanismsSupported");
 189                    static const CIMName OM_AUTHENTICATIONMECHANISMDESCRIPTIONS  =
 190                     CIMName ("AuthenticationMechanismDescriptions");
 191                    static const CIMName OM_MULTIPLEOPERATIONSSUPPORTED  =
 192                     CIMName ("MultipleOperationsSupported");
 193                    static const CIMName OM_VERSION  =
 194                     CIMName ("Version");
 195                    
 196                    // Property Names for CIMXML CommunicationMechanism
 197                    
 198                    static const CIMName CIMVALIDATED  =
 199                     CIMName ("CIMValidated");
 200                    
 201                    static const String CIMXMLProtocolVersion = "1.0";
 202                    
 203 karl          1.5  // Property names for CIM_Namespace Class
 204 karl          1.1  
 205 david.dillard 1.32 static const CIMName CIM_NAMESPACE_PROPERTY_SYSTEMCREATIONCLASSNAME =
 206 karl          1.1          CIMName ("SystemCreationClassName");
 207 david.dillard 1.32 static const CIMName CIM_NAMESPACE_PROPERTY_SYSTEMNAME =
 208 karl          1.1          CIMName ("SystemName");
 209 david.dillard 1.32 static const CIMName CIM_NAMESPACE_PROPERTY_OBJECTMANAGERCREATIONCLASSNAME =
 210 karl          1.1          CIMName ("ObjectManagerCreationClassName");
 211 david.dillard 1.32 static const CIMName CIM_NAMESPACE_PROPERTY_OBJECTMANAGERNAME =
 212 karl          1.1          CIMName ("ObjectManagerName");
 213 david.dillard 1.32 static const CIMName CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME =
 214 karl          1.1          CIMName ("CreationClassName");
 215                    static const CIMName CIM_NAMESPACE_PROPERTY_NAME  = CIMName ("Name");
 216 david.dillard 1.32 static const CIMName CIM_NAMESPACE_PROPERTY_CLASSINFO =
 217 karl          1.1          CIMName ("ClassInfo");
 218 david.dillard 1.32 static const CIMName CIM_NAMESPACE_PROPERTY_DESCRIPTIONOFCLASSINFO =
 219 karl          1.1          CIMName ("DescriptionOfClassInfo");
 220                    
 221 karl          1.8  // Additional Property names for PG_Namespace Class
 222                    
 223 david.dillard 1.32 static const CIMName PG_NAMESPACE_PROPERTY_SCHEMAUPDATESALLOWED =
 224 karl          1.8          CIMName ("SchemaUpdatesAllowed");
 225 david.dillard 1.32 static const CIMName PG_NAMESPACE_PROPERTY_ISSHAREABLE =
 226 karl          1.8          CIMName ("IsShareable");
 227 david.dillard 1.32 static const CIMName PG_NAMESPACE_PROPERTY_PARENTNAMESPACE =
 228 karl          1.8          CIMName ("ParentNamespace");
 229 david.dillard 1.32 static const CIMName PG_NAMESPACE_PROPERTY_NAME =
 230 karl          1.11         CIMName ("Name");
 231 karl          1.8  
 232 karl          1.5  // Defines to serve as the ENUM for class selection for instance
 233                    // operations.
 234                    
 235                    enum targetClass{
 236 karl          1.48         CIM_NAMESPACE = 1,
 237                            PG_NAMESPACE = 2,
 238                            CIM_OBJECTMANAGER = 3,
 239                            PG_CIMXMLCOMMUNICATIONMECHANISM = 4,
 240                            CIM_NAMESPACEINMANAGERINST =5,
 241                            CIM_COMMMECHANISMFORMANAGERINST=6,
 242                            CIM_NAMESPACEINMANAGER=7
 243 karl          1.11     };
 244 david.dillard 1.32 
 245 tony          1.6   enum targetAssocClass{
 246 karl          1.19      CIM_NAMESPACEINMANAGERASSOC = 1,
 247                         CIM_COMMMECHANISMFORMANAGERASSOC=2
 248 tony          1.6   };
 249 karl          1.5  
 250 w.white       1.34 
 251 karl          1.46 String _showPathArray(Array<CIMObjectPath>& p)
 252                    {
 253                        String rtn;
 254                        for (Uint32 i = 0 ; i < p.size() ; i++)
 255                        {
 256                            if (i > 0)
 257                                rtn.append(" ");
 258                            rtn.append(p[i].toString());
 259                        }
 260                        return(rtn);
 261                    }
 262                    
 263 w.white       1.34 //*************************************************************
 264                    //  Constructor
 265                    //**********************************************************
 266                    InteropProvider::InteropProvider(CIMRepository* repository)
 267                    {
 268                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,"InteropProvider::InteropProvider");
 269                         _repository = repository;
 270                    
 271                        //***********************************************
 272                        // This is a tempory fix untill there is a method created for the InteropProvider to 
 273 karl          1.37     // do it's inalization work. This fix sets StatisticalData::CopyGSD, enabling the 
 274 w.white       1.34     //statistical gathering function.
 275                    
 276 w.white       1.38      Boolean InstancesExists = true;
 277                         Array<CIMInstance> instance;
 278                    
 279                         try
 280 karl          1.52      { 
 281                             instance = repository->enumerateInstances(PEGASUS_NAMESPACENAME_INTEROP, 
 282                                                                       CIM_OBJECTMANAGER_CLASSNAME);
 283 w.white       1.38      }
 284                         catch(Exception e)
 285                         {
 286 karl          1.52          InstancesExists = false;
 287 w.white       1.39      }
 288                    
 289 w.white       1.38      if(instance.size() > 0 && InstancesExists)
 290                         {                               
 291 w.white       1.34         Boolean output = false;
 292                            Uint32 pos;
 293                            if ((pos = instance[0].findProperty(CIMName("GatherStatisticalData"))) != PEG_NOT_FOUND)
 294                            {
 295                                CIMConstProperty p1 = instance[0].getProperty(pos);
 296                                if (p1.getType() == CIMTYPE_BOOLEAN)
 297                                {
 298                                    CIMValue v1  = p1.getValue();
 299                                    if (!v1.isNull())
 300                                    {
 301                                        v1.get(output);
 302                                        if (v1 == true) 
 303                                        {
 304                                            StatisticalData* sd = StatisticalData::current();
 305                                            sd->setCopyGSD(true);
 306                                        }
 307                                    }
 308                                }                 
 309                            }  
 310                        }
 311                        PEG_METHOD_EXIT();
 312 w.white       1.34  }
 313                    
 314 karl          1.1  //***************************************************************
 315 karl          1.5  // Provider Utility Functions
 316 karl          1.1  //***************************************************************
 317 tony          1.6  
 318 karl          1.26 String _showBool(Boolean x)
 319                    {
 320                        return(x? "true" : "false");
 321                    }
 322                    
 323 carson.hovey  1.29 static String _toStringPropertyList(const CIMPropertyList& pl)
 324 karl          1.26 {
 325                        String tmp;
 326                        for (Uint32 i = 0; i < pl.size() ; i++)
 327                        {
 328                            if (i > 0)
 329                                tmp.append(", ");
 330                            tmp.append(pl[i].getString());
 331                        }
 332                        return(tmp);
 333                    }
 334                    
 335 karl          1.52 /** Determines if the namespace is allowable for this operation.
 336                        This provider is designed to accept either all namespaces or
 337                        limit itself to just one for operations.  In all cases, it
 338                        will provide the required answers and use the correct namespace
 339                        for any persistent information.  However, it may be configured
 340                        to either accept input operations from any namespace or simply
 341                        from one (normally the interop namespace).
 342                        @ objectReference for the operation.  This must include the
 343                        namespace and class name for the operation.
 344                        @return Returns normally if the namespace test is passed. Otherwise
 345                        it generates a CIMException (CIM_ERR_NOT_SUPPORTED)
 346                        @exception CIMException(CIM_ERR_NOT_SUPPORTED)
 347                    */
 348                    void _isNamespaceAllowed(const CIMObjectPath & path)
 349                    {
 350                        // To allow use of all namespaces, uncomment the following line
 351                        // return;
 352                        if (path.getNameSpace().getString() != PEGASUS_NAMESPACENAME_INTEROP)
 353                        {
 354 karl          1.56             throw CIMNotSupportedException(
 355 karl          1.52                           path.getClassName().getString());
 356                        }
 357                        else
 358                            return;
 359                    }
 360 karl          1.40 /* set the hostname and namespace fields into the cimobjectpath
 361                       of the defined instance
 362                    */
 363                    
 364                    void _setCompleteInstancePath(CIMInstance& instance,
 365                                               const CIMObjectPath& inputPath)
 366                    {
 367                        CIMObjectPath p = instance.getPath();
 368                        p.setHost(inputPath.getHost());
 369                        p.setNameSpace(inputPath.getNameSpace());
 370                    
 371                        instance.setPath(p);
 372                    }
 373                    
 374                    /* complete the instance by setting the complete path into the instance
 375                       and executing the instance filter to set the qualifiers, classorigin and
 376                       propertylist in accordance with the input.  Note that this can only remove
 377                       characteristics, except for the path completion so that it expects instances
 378                       with qualifiers included, class origin included and a complete property
 379                       list.
 380                    */
 381 karl          1.40 
 382                    
 383                     void _finishInstance(CIMInstance& instance, const CIMObjectPath& path, Boolean includeQualifiers,
 384                         Boolean includeClassOrigin, const CIMPropertyList& propertyList)
 385                     {
 386                         _setCompleteInstancePath( instance, path);
 387                         instance.filter(includeQualifiers,
 388                                         includeClassOrigin,
 389                                         propertyList );
 390                     }
 391 carson.hovey  1.29 static String _showPropertyList(const CIMPropertyList& pl)
 392 karl          1.26 {
 393                        if (pl.isNull())
 394                            return("NULL");
 395                    
 396                        String tmp;
 397                    
 398                        tmp.append((pl.size() == 0) ? "Empty" : _toStringPropertyList(pl));
 399                        return(tmp);
 400                    }
 401                    
 402 karl          1.8  /** get one string property from an instance. Note that these functions simply
 403                        return the default value if the property cannot be found or is of the wrong
 404 david.dillard 1.32     type thus, in reality being a maintenance problem since there is no
 405 karl          1.8      error indication.
 406 tony          1.6      @param instance CIMInstance from which we get property value
 407                        @param propertyName String name of the property containing the value
 408                        @param default String optional parameter that is substituted if the property does
 409                        not exist, is Null, or is not a string type. The substitute is String::EMPTY
 410                        @return String value found or defaultValue.
 411                    */
 412 karl          1.10 String _getPropertyValue(const CIMInstance& instance, const CIMName& propertyName, const String& defaultValue)
 413 tony          1.6  {
 414 karl          1.8      String output = defaultValue;
 415 tony          1.6      Uint32 pos;
 416                        if ((pos = instance.findProperty(propertyName)) != PEG_NOT_FOUND)
 417                        {
 418                            CIMConstProperty p1 = instance.getProperty(pos);
 419                            if (p1.getType() == CIMTYPE_STRING)
 420                            {
 421                                CIMValue v1  = p1.getValue();
 422                    
 423                                if (!v1.isNull())
 424                                    v1.get(output);
 425                            }
 426                        }
 427 karl          1.8      return(output);
 428                    }
 429                    
 430                    // Overload of _getPropertyValue for boolean type
 431 karl          1.10 Boolean _getPropertyValue(const CIMInstance& instance, const CIMName& propertyName, const Boolean defaultValue)
 432 karl          1.8  {
 433                        Boolean output = defaultValue;
 434                        Uint32 pos;
 435                        if ((pos = instance.findProperty(propertyName)) != PEG_NOT_FOUND)
 436                        {
 437                            CIMConstProperty p1 = instance.getProperty(pos);
 438                            if (p1.getType() == CIMTYPE_BOOLEAN)
 439                            {
 440                                CIMValue v1  = p1.getValue();
 441                    
 442                                if (!v1.isNull())
 443                                    v1.get(output);
 444                            }
 445 karl          1.56         else
 446                                throw CIMInvalidParameterException(
 447                                    "Incorrect Property Type for Property " + propertyName.getString());
 448 karl          1.8      }
 449 tony          1.6      return(output);
 450                    }
 451 karl          1.11 
 452 tony          1.6  /** get Host IP address from host name. If the
 453                        host name is not provided, uses internal function.
 454                        If everything fails, gets the definition normally
 455                        used for localhost (127.0.0.1).
 456 david.dillard 1.32 
 457 karl          1.53     @param hostName String with the name of the host. Allows
 458                        String:EMPTY and in that case, gets it directly from system.
 459 karl          1.41     @param namespaceType - Uint32 representing the
 460                        access protocol for this request.  This is exactly
 461                        the definition in the PG_CIMXMLCommunicationMechanism
 462                        mof for the property namespaceAccessProtocol.
 463 karl          1.53     @param port String defining the port to be used.  If 
 464                        String::EMPTY, it is not valid and the defaultPortNumber
 465                        is to be inserted.
 466                        @param defaultPortNumber Uint32 defining a default port
 467                        number to be used if port string is not provided.
 468 karl          1.41     @return String with the IP address to be used. This must
 469                        be the complete address sufficient to access the
 470                        IP address. Therefore, it includes the port number.
 471 tony          1.6  */
 472 karl          1.53 String _getHostAddress(String & hostName, Uint32  namespaceType,
 473                        const String & port, const Uint32 defaultPortNumber)
 474 david.dillard 1.32 {
 475 marek         1.14   String ipAddress;
 476 david.dillard 1.32 
 477 tony          1.6    if (hostName == String::EMPTY)
 478                        	hostName = System::getHostName();
 479                    
 480 marek         1.14   if ((ipAddress = System::getHostIP(hostName)) == String::EMPTY)
 481                      {
 482                          // set default address if everything else failed
 483                          ipAddress = String("127.0.0.1");
 484                      }
 485 karl          1.41   // Question: is there a case where we leave off the port number.
 486                      // Code to get the property service_location_tcp ( which is equivalent to "IP address:5988")
 487                    
 488 karl          1.53   // if port is valid port number, we use it.  Else use
 489                      // the default portnumber provided.
 490                      // One or the other MUST not be zero.
 491                      ipAddress.append(":");
 492                      if (port == String::EMPTY)
 493 karl          1.41   {
 494 karl          1.53       // convert portNumber to ascii
 495                          char buffer[32];
 496                          sprintf(buffer, "%u", defaultPortNumber);
 497                          ipAddress.append(buffer);
 498 karl          1.41   }
 499                      else
 500 karl          1.53       ipAddress.append(port);
 501 karl          1.41 
 502                      // now fillout the serviceIDAttribute from the object manager instance name property.
 503                      // This is a key field so must have a value.
 504                      //String strUUID = _getPropertyValue( instance_ObjMgr, namePropertyName, "DefaultEmptyUUID");
 505                    
 506 tony          1.6    return ipAddress;
 507                    }
 508 karl          1.50  /** Fills in the CIMOperation functional profiles and corresponding description
 509                         array.  This function is closely linked to compile and configuration
 510                         features in the CIM Server to determine if certain features are 
 511                         enabled and/or compiled.  Definitions correspond to the DMTF SLP template
 512                         version 1.0.
 513                         @param Array<Uint16> profiles provides an array for the profiles
 514                         @return Array<String> with the corresponding profile text descriptions
 515                    */
 516 karl          1.19  Array<String> _getFunctionalProfiles(Array<Uint16> & profiles)
 517 tony          1.6   {
 518                         Array<String> profileDescriptions;
 519 karl          1.50      // Note that zero and 1 are unknown and other. Not used by us
 520                         // 2 - 5 are not optional in Pegasus
 521 tony          1.6       profiles.append(2); profileDescriptions.append("Basic Read");
 522                         profiles.append(3); profileDescriptions.append("Basic Write");
 523                         profiles.append(4); profileDescriptions.append("Schema Manipulation");
 524                         profiles.append(5); profileDescriptions.append("Instance Manipulation");
 525 karl          1.50 
 526                         ConfigManager* configManager = ConfigManager::getInstance();
 527                         if (String::equal(configManager->getCurrentValue("enableAssociationTraversal"), "true"))
 528                         {
 529                             profiles.append(6); profileDescriptions.append("Association Traversal");
 530                         }
 531                    #ifndef PEGASUS_DISABLE_EXECQUERY
 532                         profiles.append(7); profileDescriptions.append("Query Execution");
 533                    #endif
 534 tony          1.6       profiles.append(8); profileDescriptions.append("Qualifier Declaration");
 535 karl          1.50      if (String::equal(configManager->getCurrentValue("enableIndicationService"), "true"))
 536                         {
 537                             profiles.append(9); profileDescriptions.append("Indications");
 538                         }
 539 tony          1.6       return(profileDescriptions);
 540                     }
 541                    
 542 karl          1.51 /*  get the prefix that will be part of the cimom identification.
 543                        This prefix is obtained from the Pegasus Constants.h
 544 tony          1.6      @return String containing the unique name for the CIMOM ID
 545                    */
 546                    
 547                    String getTrademarkCIMOMIDPrefix()
 548                    {
 549                    
 550 karl          1.51     return(PEGASUS_INSTANCEID_GLOBAL_PREFIX);
 551 tony          1.6  }
 552 karl          1.55 
 553 tony          1.6  /** Builds the UUID string for this CIMOM.
 554                    **/
 555                    String getUUIDString()
 556                    {
 557                        return(Guid::getGuid());
 558                    }
 559 karl          1.1  
 560                    /* Test the keys in the CIM_Namespace for valid values
 561                       This includes all of the keys above the name key.
 562                       THis is a dummy for now.
 563                       ATTN: KS Extend and finish this function.
 564                    */
 565 karl          1.5  Boolean _validateProperties(const CIMObjectPath& path)
 566 karl          1.1  {
 567                        return true;
 568                    }
 569 karl          1.28 
 570 karl          1.5  Boolean _validateProperties(const CIMInstance& instance)
 571 karl          1.1  {
 572                        return true;
 573                    }
 574                    
 575 tony          1.6  /* Validate that the property exists, is string type and
 576 karl          1.5     optionally the value itself. Note processes only String
 577 tony          1.6     properties.
 578                       @param Instance to search for property.
 579                       @param CIMName containing property Name
 580 david.dillard 1.32    @value String containing value. If not String::EMPTY, compare to
 581 karl          1.5     value in the property
 582 tony          1.6     @return True if passes all tests
 583 karl          1.5  */
 584 david.dillard 1.32 Boolean _validateRequiredProperty(const CIMInstance& instance,
 585 karl          1.5                            const CIMName& propertyName,
 586                                              const String& value)
 587                    {
 588 tony          1.6      PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
 589                                "InteropProvider::_validateRequiredProperty()");
 590 karl          1.5      Uint32 pos;
 591 tony          1.6  
 592 karl          1.5      if ((pos = instance.findProperty (propertyName)) == PEG_NOT_FOUND)
 593 tony          1.6      {
 594                            PEG_METHOD_EXIT();
 595 karl          1.5          return(false);
 596 tony          1.6      }
 597 karl          1.5      //
 598                        //  Get the property
 599                        //
 600                        CIMConstProperty theProperty = instance.getProperty(pos);
 601                        const CIMValue theValue = theProperty.getValue ();
 602                        //
 603 tony          1.6      //  ATTN: Required property must have a non-null value
 604 karl          1.5      //
 605 tony          1.6      if ((theValue.getType() != CIMTYPE_STRING) || (theValue.isNull()))
 606                        {
 607                            PEG_METHOD_EXIT();
 608 karl          1.5          return(false);
 609 tony          1.6      }
 610                    
 611                        String valueField;
 612                        theValue.get(valueField);
 613                        if ((value == String::EMPTY) || (valueField == value))
 614 karl          1.5      {
 615 tony          1.6          PEG_METHOD_EXIT();
 616                            return(true);
 617 karl          1.5      }
 618 tony          1.6      PEG_METHOD_EXIT();
 619                        return(false);
 620 karl          1.5  }
 621                    
 622 karl          1.56 /*  _CheckRequiredProperty
 623 karl          1.48     Note validate does about the same thing.
 624                    */
 625                    Boolean _checkRequiredProperty(CIMInstance& instance,
 626                        const CIMName& propertyName,
 627                        const CIMType expectedType,
 628                        const String & message)
 629                    {
 630 karl          1.54     PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
 631 karl          1.48         "_checkRequiredProperty");
 632                    
 633                        Boolean propertyError = false;
 634                    
 635                        //
 636                        //  Required property must exist in instance
 637                        //
 638                        if (instance.findProperty (propertyName) == PEG_NOT_FOUND)
 639                            propertyError = true;
 640                        else
 641                        {
 642                            //
 643                            //  Get the property
 644                            //
 645                            CIMProperty theProperty = instance.getProperty
 646                                (instance.findProperty (propertyName));
 647                            CIMValue theValue = theProperty.getValue ();
 648                    
 649                            //
 650                            //  Required property must have a non-null value
 651                            //
 652 karl          1.48         if (theValue.isNull ())
 653                                propertyError = true;
 654                            else
 655                            {
 656                                //
 657                                // Must have type defined 
 658                                //
 659                    
 660                                if ((theValue.getType ()) != expectedType)
 661                                    propertyError = true;
 662                            }
 663                        }
 664                        PEG_METHOD_EXIT ();
 665                        return(propertyError);
 666                    }
 667 karl          1.5  Boolean _validateRequiredProperty(const CIMInstance& instance,
 668                                              const CIMName& propertyName,
 669                                              const Uint16& value)
 670                    {
 671 tony          1.6      PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
 672                            "InteropProvider::_validateRequiredProperty()");
 673 david.dillard 1.32 
 674 tony          1.6      PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4, "Validate "
 675                            + propertyName.getString());
 676                    
 677 karl          1.5      Uint32 pos;
 678                        if ((pos = instance.findProperty (propertyName)) == PEG_NOT_FOUND)
 679 tony          1.6      {
 680                            PEG_METHOD_EXIT();
 681 karl          1.5          return(false);
 682 tony          1.6      }
 683 karl          1.5      //
 684                        //  Get the property
 685                        //
 686                        CIMConstProperty theProperty = instance.getProperty(pos);
 687                        CIMValue theValue = theProperty.getValue ();
 688                        //
 689 tony          1.6      //  ATTN:Required property must have a non-null value
 690 karl          1.5      //
 691 david.dillard 1.32     if ((theValue.getType() != CIMTYPE_UINT16)
 692                            || (theValue.isNull()) )
 693 tony          1.6      {
 694                            PEG_METHOD_EXIT();
 695 karl          1.5          return(false);
 696 tony          1.6      }
 697                        PEG_METHOD_EXIT();
 698 karl          1.5      return(true);
 699                    }
 700 karl          1.28 
 701 karl          1.5  Boolean _validateRequiredProperty(const CIMObjectPath& objectPath,
 702                                              const CIMName& propertyName,
 703                                              const String value)
 704                    {
 705 tony          1.6      PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
 706                                "InteropProvider::_validateRequiedProperty()");
 707 karl          1.5      Array<CIMKeyBinding> kbArray = objectPath.getKeyBindings();
 708                    
 709                        // find the correct key binding
 710                        for (Uint32 i = 0; i < kbArray.size(); i++)
 711                        {
 712                            if (kbArray[i].getName() == propertyName)
 713                            {
 714                                if (value != String::EMPTY)
 715                                {
 716                                    if (value !=kbArray[i].getValue())
 717                                    {
 718 tony          1.6                      PEG_METHOD_EXIT();
 719 karl          1.5                      return(true);
 720                                    }
 721                                }
 722                            }
 723                        }
 724 tony          1.6      PEG_METHOD_EXIT();
 725 karl          1.5      return(true);
 726                    }
 727 karl          1.1  
 728                    /* Query the repository for array of all namespacenames
 729 tony          1.6     @return Array<CIMNamespaceName> with all namespaces
 730                       @exception Passes all exception that repository may generate.
 731 david.dillard 1.32 */
 732 karl          1.1  Array<CIMNamespaceName> InteropProvider::_enumerateNameSpaces()
 733                    {
 734                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
 735                                "InteropProvider::_enumerateNameSpaces()");
 736 tony          1.6  
 737 karl          1.1      Array<CIMNamespaceName> namespaceNames;
 738 david.dillard 1.32 
 739 tony          1.6      namespaceNames = _repository->enumerateNameSpaces();
 740 karl          1.1  
 741                        PEG_METHOD_EXIT();
 742                        return(namespaceNames);
 743                    }
 744                    
 745 tony          1.6  /* get a class defintion. Gets the class defined by
 746                        the parameters. Generates exception of class not defined.
 747 karl          1.1     @param namespace in which to look for the class.
 748                       @param name of class to get.
 749                       @return the CIMClass object
 750                       @Exceptions any repository exceptions if class not found.
 751 david.dillard 1.32 */
 752 karl          1.37 CIMClass InteropProvider::_getClass(const CIMObjectPath& objectPath,
 753 tony          1.6                                      const CIMName& className)
 754 karl          1.1  {
 755                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
 756 tony          1.6              "InteropProvider::_getClass");
 757                    
 758 karl          1.37     CIMClass myClass = _repository->getClass(objectPath.getNameSpace(), className,
 759 tony          1.6                              false,true,true);
 760 karl          1.1      PEG_METHOD_EXIT();
 761                        return myClass;
 762                    }
 763                    
 764                    /* Verify that this is one of the legal classnames and
 765                       return indicator which.
 766                       @param - Classname
 767                       @return - Uint32 indicating type
 768                       @Exceptions - throws CIMNotSupportedException if invalid class.
 769                    */
 770 kumpf         1.17 static targetClass _verifyValidClassInput(const CIMName& className)
 771 karl          1.1  {
 772 karl          1.10     PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
 773                                "InteropProvider::_verifyValidClassInput");
 774 karl          1.1      if (className.equal(CIM_OBJECTMANAGER_CLASSNAME))
 775                            return CIM_OBJECTMANAGER;
 776                    
 777 tony          1.6      if (className.equal(PG_CIMXMLCOMMUNICATIONMECHANISM_CLASSNAME))
 778                            return PG_CIMXMLCOMMUNICATIONMECHANISM;
 779 karl          1.1  
 780 karl          1.19     if (className.equal(CIM_NAMESPACEINMANAGER_CLASSNAME))
 781                            return CIM_NAMESPACEINMANAGER;
 782                    
 783 karl          1.48     if (className.equal(CIM_NAMESPACE_CLASSNAME))
 784                            return CIM_NAMESPACE;
 785                    
 786 karl          1.10     // Last entry, reverse test and return OK if PG_Namespace
 787 karl          1.8      // Note: Changed to PG_Namespace for CIM 2.4
 788                        if (!className.equal(PG_NAMESPACE_CLASSNAME))
 789 karl          1.1          throw CIMNotSupportedException
 790                                (className.getString() + " not supported by Interop Provider");
 791                    
 792 karl          1.10     PEG_METHOD_EXIT();
 793 karl          1.8      return PG_NAMESPACE;
 794 karl          1.1  }
 795                    
 796 kumpf         1.17 static targetAssocClass _verifyValidAssocClassInput(const CIMName& className)
 797 tony          1.6  {
 798 karl          1.10     PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
 799                                "InteropProvider::_verifyValidAssocClassInput");
 800 tony          1.6      if (className.equal(CIM_NAMESPACEINMANAGER_CLASSNAME))
 801 karl          1.19         return CIM_NAMESPACEINMANAGERASSOC;
 802                    
 803 karl          1.8      // Last entry, reverse test and return OK if CIM_CommMech....
 804 tony          1.6      if (!className.equal(CIM_COMMMECHANISMFORMANAGER_CLASSNAME))
 805                            throw CIMNotSupportedException
 806                                (className.getString() + " not supported by Interop Provider");
 807                    
 808 karl          1.10     PEG_METHOD_EXIT();
 809 karl          1.19     return CIM_COMMMECHANISMFORMANAGERASSOC;
 810 tony          1.6  }
 811                    
 812 karl          1.1  /* validate the authorization of the user name against the namespace.
 813                    */
 814                    String _validateUserID(const OperationContext & context)
 815                    {
 816 karl          1.10     PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
 817                                "InteropProvider::_validateUserID");
 818 karl          1.1      String userName;
 819                        try
 820                        {
 821                            IdentityContainer container = context.get(IdentityContainer::NAME);
 822                            userName = container.getUserName();
 823                        }
 824 karl          1.10 
 825 karl          1.1      catch (...)
 826                        {
 827                           userName = String::EMPTY;
 828                        }
 829 karl          1.10 
 830                        PEG_METHOD_EXIT();
 831 karl          1.1      return userName;
 832                    }
 833                    
 834 karl          1.11 /** Set the value of a property defined by property name in the instance provided.
 835 tony          1.6      Sets a String into the value field unless the property name cannot be found.
 836                        If the property cannot be found, it simply returns.
 837                        ATTN: This function does not pass an error back if property not found.
 838                        @param instance CIMInstance in which to set property value
 839                        @param propertyName CIMName of property in which value will be set.
 840                        @param value String value to set into property
 841 david.dillard 1.32 
 842 tony          1.6  */
 843 karl          1.46 void _setPropertyValue(CIMInstance& instance, const CIMName& propertyName, const String& value)
 844 tony          1.6  {
 845                        Uint32 pos;
 846                        if ((pos = instance.findProperty(propertyName)) != PEG_NOT_FOUND)
 847                            instance.getProperty(pos).setValue(CIMValue(value));
 848                    }
 849                    
 850 karl          1.46 void _setPropertyValue(CIMInstance& instance, const CIMName& propertyName, const Boolean& value)
 851 tony          1.6  {
 852                        Uint32 pos;
 853                        if ((pos = instance.findProperty(propertyName)) != PEG_NOT_FOUND)
 854                            instance.getProperty(pos).setValue(CIMValue(value));
 855                    }
 856 karl          1.1  
 857 karl          1.46 void _setPropertyValue(CIMInstance& instance, const CIMName& propertyName, const Uint16& value)
 858 tony          1.6  {
 859                        Uint32 pos;
 860                        if ((pos = instance.findProperty(propertyName)) != PEG_NOT_FOUND)
 861                            instance.getProperty(pos).setValue(CIMValue(value));
 862                    }
 863                    
 864 karl          1.46 void _setPropertyValue(CIMInstance& instance, const CIMName& propertyName, const Array<String>& value)
 865 tony          1.6  {
 866                        Uint32 pos;
 867                        if ((pos = instance.findProperty(propertyName)) != PEG_NOT_FOUND)
 868                            instance.getProperty(pos).setValue(CIMValue(value));
 869                    }
 870                    
 871 karl          1.46 void _setPropertyValue(CIMInstance& instance, const CIMName& propertyName, const Array<Uint16>& value)
 872 tony          1.6  {
 873                        Uint32 pos;
 874                        if ((pos = instance.findProperty(propertyName)) != PEG_NOT_FOUND)
 875                            instance.getProperty(pos).setValue(CIMValue(value));
 876                    }
 877                    
 878 karl          1.46 void _setPropertyValue(CIMInstance& instance, const CIMName& propertyName, const CIMObjectPath& value)
 879 tony          1.6  {
 880                        Uint32 pos;
 881                        if ((pos = instance.findProperty(propertyName)) != PEG_NOT_FOUND)
 882                            instance.getProperty(pos).setValue(CIMValue(value));
 883                    }
 884                    
 885                    /** add the correct values to the common keys defined for all of the classes. This is
 886                        systemcreationclassname and systemname
 887                        Note that if the properties do not exist, we simply ignore them.
 888                    */
 889                    void _fixInstanceCommonKeys(CIMInstance& instance)
 890 karl          1.1  {
 891                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
 892 tony          1.6              "InteropProvider::_fixInstanceCommonKeys()");
 893 karl          1.1      String SystemCreationClassName = System::getSystemCreationClassName ();
 894                    
 895 karl          1.37     _setPropertyValue(instance, CIM_NAMESPACE_PROPERTY_SYSTEMCREATIONCLASSNAME,
 896                                SystemCreationClassName);
 897 karl          1.1  
 898 karl          1.5      // Add property SystemName
 899 karl          1.37     _setPropertyValue(instance, CIM_NAMESPACE_PROPERTY_SYSTEMNAME,
 900                                System::getFullyQualifiedHostName());
 901 karl          1.1      PEG_METHOD_EXIT();
 902                    }
 903                    
 904 tony          1.6  /** builds one instance of the class named className. Gets Class defintion and f
 905                        fills in the correct properties from the class.  This requires a repository
 906                        getclass request for each instance built. The skeleton is built by
 907                        creating the instance and copying qualifiers and properties from
 908                        the class. Finally the instance is cloned to separate it from the
 909                        original objects.
 910                        NOTE: This is very inefficient for anything larger than a few instances.
 911                        We should separate the get from the createSkeleton.
 912                        @param className CIMName of the class for which the instance is to be built
 913                        @return CIMInstance of this class with properties complete.
 914                        @exception passes on any exceptions received from the repository request.
 915                    */
 916 karl          1.37 CIMInstance InteropProvider::_buildInstanceSkeleton(const CIMObjectPath & objectPath,
 917 karl          1.40                                                     const CIMName& className,
 918                                                                        CIMClass& returnedClass)
 919 karl          1.1  {
 920                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
 921 tony          1.6              "InteropProvider::_buildInstanceSkeleton()");
 922 karl          1.40     // get class with lo = false, qualifier = true classorig = true
 923                        CIMClass myClass = _repository->getClass(objectPath.getNameSpace(),
 924 karl          1.37                                         className, false, true, true);
 925 karl          1.40     returnedClass = myClass;
 926                        CIMInstance skeleton = myClass.buildInstance(true,true,CIMPropertyList());
 927 karl          1.1  
 928                        PEG_METHOD_EXIT();
 929 karl          1.40     return(skeleton);
 930 karl          1.1  }
 931                    
 932 tony          1.6  /* build a single instance of the cimxmlcommunicationmechanism class
 933 karl          1.45    using the parameter provided as the name property.
 934                       Builds the complete instance and sets the path into it.
 935 tony          1.6     @parm name String representing the name to be used for this object.
 936                       @return CIMInstance of the class
 937 karl          1.5  */
 938 tony          1.6  CIMInstance InteropProvider::_buildInstancePGCIMXMLCommunicationMechanism(
 939 karl          1.37             const CIMObjectPath& objectPath,
 940                                const String& namespaceType,
 941 karl          1.41             const Uint16& accessProtocol,
 942 karl          1.46             const String& IPAddress)
 943 karl          1.1  {
 944                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
 945 tony          1.6              "InteropProvider::_buildInstancePGCIMXMLCommunicationMechanism()");
 946 karl          1.40     CIMClass targetClass;
 947 karl          1.37     CIMInstance instance = _buildInstanceSkeleton(objectPath,
 948 karl          1.40                             PG_CIMXMLCOMMUNICATIONMECHANISM_CLASSNAME,
 949                                                targetClass);
 950 karl          1.1  
 951 tony          1.6      _fixInstanceCommonKeys(instance);
 952 karl          1.1  
 953 tony          1.6      //CreationClassName
 954 karl          1.37     _setPropertyValue(instance, CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME,
 955                                PG_CIMXMLCOMMUNICATIONMECHANISM_CLASSNAME.getString());
 956 karl          1.1  
 957 karl          1.19     //Name, this CommunicationMechanism.  We need to make it unique.  To do this
 958                        // we simply append the commtype to the classname since we have max of two right
 959                        // now.
 960 karl          1.37     _setPropertyValue(instance, CIM_NAMESPACE_PROPERTY_NAME,
 961                                (String("PEGASUSCOMM") + namespaceType));
 962 karl          1.1  
 963 karl          1.19     // CommunicationMechanism Property - Force to 2.
 964 tony          1.6      _setPropertyValue(instance, OM_COMMUNICATIONMECHANISM, Uint16(2));
 965 karl          1.1  
 966                        //Functional Profiles Supported Property.
 967                        Array<Uint16> profiles;
 968 tony          1.6      Array<String> profileDescriptions = _getFunctionalProfiles(profiles);
 969 karl          1.1  
 970 tony          1.6      // Set functional profiles in instance
 971                        _setPropertyValue(instance, OM_FUNCTIONALPROFILESSUPPORTED, profiles);
 972                    
 973                        _setPropertyValue(instance, OM_FUNCTIONALPROFILEDESCRIPTIONS, profileDescriptions);
 974 karl          1.1  
 975                        // Multiple OperationsSupported Property
 976 tony          1.6      _setPropertyValue(instance, OM_MULTIPLEOPERATIONSSUPPORTED, false);
 977 karl          1.5  
 978                        // AuthenticationMechanismsSupported Property
 979 karl          1.1      Array<Uint16> authentications;
 980                        Array<String> authenticationDescriptions;
 981 karl          1.5  
 982 karl          1.46     //TODO - get from system.
 983 a.dunfey      1.49     authentications.append(3);
 984                        //authenticationDescriptions.append("Basic");
 985 karl          1.5  
 986 tony          1.6      _setPropertyValue(instance, OM_AUTHENTICATIONMECHANISMSSUPPORTED, authentications);
 987                    
 988                        _setPropertyValue(instance, OM_AUTHENTICATIONMECHANISMDESCRIPTIONS, authenticationDescriptions);
 989 david.dillard 1.32 
 990 tony          1.6      _setPropertyValue(instance, OM_VERSION, CIMXMLProtocolVersion);
 991                    
 992 marek         1.33     // Obsolete function 
 993                        _setPropertyValue(instance, "namespaceType", namespaceType);
 994 tony          1.6  
 995 karl          1.41     _setPropertyValue(instance, "namespaceAccessProtocol", accessProtocol);
 996                    
 997 tony          1.6      _setPropertyValue(instance, "IPAddress", IPAddress);
 998 karl          1.1  
 999 karl          1.45     // build the instance path and set into instance
1000                        instance.setPath(instance.buildPath(targetClass));
1001                    
1002 karl          1.1      PEG_METHOD_EXIT();
1003                        return(instance);
1004                    }
1005 tony          1.6  
1006                    Array<CIMInstance> InteropProvider::_buildInstancesPGCIMXMLCommunicationMechanism(
1007 karl          1.46                                             const CIMObjectPath& objectPath)
1008 tony          1.6  {
1009 karl          1.10     PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1010                                "InteropProvider::_buildInstancesPGCIMXMLCommunicationMechanism");
1011 david.dillard 1.32 
1012 tony          1.6      ConfigManager* configManager = ConfigManager::getInstance();
1013                        Boolean enableHttpConnection = String::equal(
1014                            configManager->getCurrentValue("enableHttpConnection"), "true");
1015                        Boolean enableHttpsConnection = String::equal(
1016                            configManager->getCurrentValue("enableHttpsConnection"), "true");
1017                    
1018                        Array<CIMInstance> instances;
1019 karl          1.41     Uint32 namespaceAccessProtocol;
1020                        String namespaceType;
1021 tony          1.6  
1022 karl          1.41     // for each type, create the instance if that type is defined.
1023 karl          1.42     String hostName = System::getHostName();
1024 tony          1.6      if (enableHttpConnection)
1025                        {
1026 karl          1.41         namespaceAccessProtocol = 2;
1027                            namespaceType = "http";
1028 karl          1.53         Uint32 portNumberHttp;
1029                            String httpPort = configManager->getCurrentValue("httpPort");
1030                            if (httpPort == String::EMPTY)
1031                            {
1032                                portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);
1033                            }
1034 karl          1.41         CIMInstance instance = 
1035                                _buildInstancePGCIMXMLCommunicationMechanism(
1036                                    objectPath,
1037                                    namespaceType,
1038                                    namespaceAccessProtocol,
1039 karl          1.53                 _getHostAddress(hostName, namespaceAccessProtocol, httpPort, portNumberHttp));
1040 tony          1.6          instances.append(instance);
1041                        }
1042                    
1043                        if (enableHttpsConnection)
1044                        {
1045 karl          1.41         namespaceAccessProtocol = 3;
1046                            namespaceType = "https";
1047 karl          1.53         Uint32 portNumberHttps;
1048                            String httpsPort = configManager->getCurrentValue("httpsPort");
1049                            if (httpsPort == String::EMPTY)
1050                            {
1051                                portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);
1052                            }
1053 karl          1.41         CIMInstance instance = 
1054                                _buildInstancePGCIMXMLCommunicationMechanism(
1055                                    objectPath,
1056                                    namespaceType,
1057                                    namespaceAccessProtocol,
1058 karl          1.53                 _getHostAddress(hostName, namespaceAccessProtocol, httpsPort, portNumberHttps));
1059 karl          1.46 
1060 tony          1.6          instances.append(instance);
1061                        }
1062 karl          1.40 
1063 karl          1.41 
1064 karl          1.10     PEG_METHOD_EXIT();
1065 tony          1.6      return(instances);
1066                    }
1067 karl          1.46 
1068 tony          1.6  /*  Gets the value for the CIMObjectManager name.  This is a key
1069                        property with the following characteristics.
1070                        1. It is persistent. This must be persistent through CIMOM
1071 david.dillard 1.32     restarts.  We will save it in the instance database to achieve this.
1072 tony          1.6      2. It must be unique. We cannot create duplicate CIMOM names
1073                        3. It is based on the DMTF description of how unique InstanceIds
1074                        are defined (Trademark/etc followed by unique identification.
1075                        Use the Global constant PegasusInstanceIDGlobalPrefix as the
1076                        prefix allowing this to be changed.
1077                    */
1078                    String buildObjectManagerName()
1079                    {
1080                        return(getTrademarkCIMOMIDPrefix() + ":" + getUUIDString());
1081 karl          1.1  }
1082                    
1083 karl          1.10 /** get either the local or disk CIMObjectmanager instance.
1084 david.dillard 1.32     @return Boolean true if already exists. False if
1085 karl          1.10     not initialized. Also returns with the current version set
1086                        into local parameter.
1087                    */
1088 karl          1.26 Boolean InteropProvider::_getInstanceFromRepositoryCIMObjectManager(
1089 karl          1.37                         const CIMObjectPath& objectPath,
1090 karl          1.26                         CIMInstance& rtnInstance,
1091 karl          1.10                         const Boolean includeQualifiers,
1092                                            const Boolean includeClassOrigin,
1093                                            const CIMPropertyList& propertyList)
1094                    {
1095                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1096 karl          1.54             "InteropProvider::_getInstanceFromRepositoryCIMObjectManager");
1097 karl          1.41 
1098 karl          1.10     // Try to get persistent instance from repository
1099                        Array<CIMInstance> instances;
1100                        try
1101                        {
1102 karl          1.37         instances = _repository->enumerateInstances(
1103                                    objectPath.getNameSpace(),
1104                                    CIM_OBJECTMANAGER_CLASSNAME, true, false, includeQualifiers,
1105                                    includeClassOrigin, propertyList);
1106 karl          1.26 
1107 karl          1.10         if (instances.size() >= 1)
1108                            {
1109                                // set this instance into global variable.
1110 karl          1.26             rtnInstance = instances[0];
1111 david.dillard 1.32 
1112 karl          1.10             // log entry if there is more than one instance.
1113                                // Some day we may support multiple entries to see other CIMOMs but
1114                                // for now this should be illegal and represent an internal error.
1115                                // but we will still continue to use the first entry.
1116                                if (instances.size() > 1)
1117                                {
1118 karl          1.37                 Logger::put(Logger::ERROR_LOG,
1119                                        System::CIMSERVER, Logger::INFORMATION,
1120                                        "Error. Multiple definitons of : $0",
1121                                        CIM_OBJECTMANAGER_CLASSNAME.getString());
1122 karl          1.10             }
1123                                return(true);
1124                            }
1125                            else
1126 karl          1.26         {
1127 karl          1.10             return(false);
1128 karl          1.26         }
1129 karl          1.10     }
1130 david.dillard 1.32     catch(const CIMException&)
1131 karl          1.10     {
1132                            Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
1133 karl          1.37             "Error. Cannot access $0 in repository", 
1134                                CIM_OBJECTMANAGER_CLASSNAME.getString());
1135 karl          1.10         PEG_METHOD_EXIT();
1136 david.dillard 1.32         throw;
1137 karl          1.10     }
1138 david.dillard 1.32     catch(const Exception&)
1139 karl          1.10     {
1140                            Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
1141 karl          1.37             "Error. Cannot access $0 in repository", 
1142                                CIM_OBJECTMANAGER_CLASSNAME.getString());
1143 karl          1.10         PEG_METHOD_EXIT();
1144 david.dillard 1.32         throw;
1145 karl          1.10     }
1146                    }
1147                    
1148 karl          1.54 /** get an instance of the CIM_ObjectManager class filling out
1149 karl          1.26     the required properties if one does not already exist in the
1150                        repository. This function will either return an instance
1151                        or throw an exception.
1152 tony          1.6      @param includeQualifiers Boolean
1153                        @param includeClassOrigin Boolean
1154 david.dillard 1.32     @param propertylist CIMPropertyList
1155 tony          1.6      @return CIMInstance with a single built instance of the class
1156                        @exception repository instances if exception to enumerateInstances
1157                            for this class.
1158                    */
1159 karl          1.26 CIMInstance InteropProvider::_getInstanceCIMObjectManager(
1160 karl          1.37                         const CIMObjectPath& objectPath,
1161 tony          1.6                          const Boolean includeQualifiers,
1162                                            const Boolean includeClassOrigin,
1163                                            const CIMPropertyList& propertyList)
1164 karl          1.1  {
1165                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1166 karl          1.10             "InteropProvider::_buildInstanceCIMObjectManager");
1167 karl          1.1  
1168 karl          1.10     // Try to get the current object.  If true then it is already created.
1169 karl          1.24     CIMInstance instance;
1170 karl          1.37     if (!_getInstanceFromRepositoryCIMObjectManager(objectPath,
1171                                    instance, includeQualifiers,includeClassOrigin,propertyList))
1172 karl          1.24     {
1173                            //
1174                            // No instance in the repository. Build new instance and save it.
1175                            //
1176 karl          1.40         CIMClass targetClass;
1177                            instance = _buildInstanceSkeleton(objectPath, CIM_OBJECTMANAGER_CLASSNAME,
1178                                        targetClass);
1179 david.dillard 1.32 
1180 karl          1.24         _fixInstanceCommonKeys(instance);
1181 david.dillard 1.32 
1182 karl          1.37         _setPropertyValue(instance, CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME,
1183                                    CIM_OBJECTMANAGER_CLASSNAME.getString());
1184 karl          1.54 
1185                            _objectManagerName = buildObjectManagerName();
1186                            _setPropertyValue(instance, CIM_NAMESPACE_PROPERTY_NAME,_objectManagerName);
1187 karl          1.24         _setPropertyValue(instance, CIMName("ElementName"), String("Pegasus"));
1188 david.dillard 1.32 
1189 karl          1.24         //
1190                            //Description property this object manager instance
1191 karl          1.43         // default is Pegasus CIM_Server Version. Get from
1192                            // fields defined in PegasusVersion.
1193                            // TODO. Add as an alternative the capability to get this
1194                            // from config parameters.
1195                            // If PEGASUS_CIMOM_DESCRIPTION is non-zero length, use it.
1196                            // Otherwise build form the components below.
1197                    
1198                            String description = (String(PEGASUS_CIMOM_DESCRIPTION).size() != 0) ?
1199                                    String(PEGASUS_CIMOM_DESCRIPTION)
1200                                :
1201                                    String(PEGASUS_CIMOM_GENERIC_NAME) + " " +
1202                                    String(PEGASUS_PRODUCT_NAME) + " Version " +
1203                                    String(PEGASUS_PRODUCT_VERSION) + " " +
1204                                    String(PEGASUS_PRODUCT_STATUS);
1205 david.dillard 1.32 
1206 karl          1.24         _setPropertyValue(instance, CIMName("Description"), description);
1207 david.dillard 1.32 
1208 karl          1.24         //Property GatherStatisticalData. Initially this is set to false
1209                            // and can then be modified by a modify instance on the instance.
1210 david.dillard 1.32 
1211 karl          1.24         Boolean gatherStatDataFlag = false;
1212 david.dillard 1.32 
1213 karl          1.24         _setPropertyValue(instance, OM_GATHERSTATISTICALDATA, Boolean(gatherStatDataFlag));
1214 david.dillard 1.32 
1215 karl          1.54         // Set the statistics property into the Statisticaldata class so that
1216                            // it can perform statistics gathering if necessary.
1217 karl          1.24     #ifndef PEGASUS_DISABLE_PERFINST
1218                            StatisticalData* sd = StatisticalData::current();
1219                            sd->setCopyGSD(gatherStatDataFlag);
1220                        #endif
1221 david.dillard 1.32 
1222 karl          1.24         // write instance to the repository
1223                            CIMObjectPath instancePath;
1224 karl          1.46 
1225 karl          1.24         try
1226                            {
1227 karl          1.37             instancePath = _repository->createInstance(objectPath.getNameSpace(),
1228 karl          1.24                            instance );
1229                            }
1230 david.dillard 1.32         catch(const CIMException&)
1231 karl          1.24         {
1232 karl          1.46             // TODO ATTN: KS generate log error if this not possible
1233 karl          1.24             PEG_METHOD_EXIT();
1234 david.dillard 1.32             throw;
1235 karl          1.24         }
1236 david.dillard 1.32         catch(const Exception&)
1237 karl          1.24         {
1238                                // ATTN: Generate log error.
1239                                PEG_METHOD_EXIT();
1240 david.dillard 1.32             throw;
1241 karl          1.24         }
1242                            instance.setPath(instancePath);
1243 karl          1.5      }
1244 karl          1.56 
1245 karl          1.5      PEG_METHOD_EXIT();
1246 karl          1.20     return(instance);
1247 karl          1.1  }
1248                    
1249 karl          1.54 /** getObjectNamagerName returns the name property for this object manager
1250                        return String name of this object manager.  This is a convience function
1251                        to deliver only the name field from the CIM_ObjectManager object.
1252                        If the object Manager has been created and the name saved in this 
1253                        provider, that name is returned.  Else it calls the function to
1254                        get the instance of the Object Manager.
1255                        @return String containing the persistent name property for this
1256                        object manager
1257                        
1258                    */
1259                    
1260                    String InteropProvider::_getObjectManagerName()
1261                    {
1262                        if (_objectManagerName != String::EMPTY)
1263                        {
1264                            return _objectManagerName;
1265                        }
1266                        else
1267                        {
1268                            CIMObjectPath path;
1269                            path.setNameSpace(PEGASUS_NAMESPACENAME_INTEROP);
1270 karl          1.54         CIMInstance instance = _getInstanceCIMObjectManager(path, true, true, CIMPropertyList());
1271                            // get the property name.
1272                            String name = _getPropertyValue(instance, CIM_NAMESPACE_PROPERTY_NAME,
1273                                                                    String::EMPTY);
1274                            return name;
1275                        }
1276                    
1277                    }
1278                    
1279 karl          1.8  /** Get the instances of CIM_Namespace. Gets all instances of the namespace from
1280 karl          1.40     the repository namespace management functions. Builds instances that
1281                        match all of the request attributes.
1282 tony          1.6  */
1283 karl          1.37 Array<CIMInstance> InteropProvider::_getInstancesCIMNamespace(
1284 karl          1.46                             const CIMObjectPath& objectPath)
1285 tony          1.6  {
1286                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1287                                "InteropProvider::_getInstancesCIMNamespace()");
1288 karl          1.8  
1289 tony          1.6      Array<CIMNamespaceName> namespaceNames = _enumerateNameSpaces();
1290                        Array<CIMInstance> instanceArray;
1291                    
1292 karl          1.40     // Build instances of PG namespace since that is the leaf class
1293 tony          1.6      for (Uint32 i = 0; i < namespaceNames.size(); i++)
1294                        {
1295 karl          1.37        instanceArray.append( _buildInstancePGNamespace(objectPath, namespaceNames[i]));
1296 tony          1.6      }
1297                        PEG_METHOD_EXIT();
1298                        return(instanceArray);
1299                    }
1300                    
1301                    /** get the instance of namespace defined by the input parameter which is the object path
1302                        for the instance required.
1303                        ATTN: Note that this is incorrect. We are supplying the namespace name and need to supply
1304                        the objectpath
1305 karl          1.37     @param objectPath CIMObjectPath from request
1306                        @param nameSpace CIMNamespaceName for instance to get
1307 tony          1.6      @return CIMInstance with the found instance or CIMInstance() if nothing found.
1308                    */
1309 karl          1.37 CIMInstance InteropProvider::_getInstanceCIMNamespace(const CIMObjectPath& objectPath)
1310 tony          1.6  {
1311                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1312                                "InteropProvider::_getInstancesCIMNamespace()");
1313                    
1314 karl          1.46     Array<CIMInstance> instances = _getInstancesCIMNamespace(objectPath);
1315 tony          1.6  
1316 karl          1.37     CIMNamespaceName nameSpace = objectPath.getNameSpace();
1317 karl          1.8      // search the instances for one with the name property value = input parameter.
1318 tony          1.6      for (Uint32 i = 0 ; i < instances.size() ; i++)
1319                        {
1320 karl          1.8          if (_getPropertyValue(instances[i], CIMName("name"), String::EMPTY) == nameSpace.getString())
1321 tony          1.6          {
1322                                PEG_METHOD_EXIT();
1323                                return(instances[i]);
1324                            }
1325                        }
1326                        PEG_METHOD_EXIT();
1327                        CIMInstance nullInstance;
1328                        return(nullInstance);
1329                    }
1330 karl          1.46 /* build the full instances set of of the association class NamespacInManager.
1331 tony          1.6  
1332 karl          1.46     NOTE: THe input object path is not really use at this point.
1333                    */
1334                    Array<CIMInstance> InteropProvider::_buildInstancesNamespaceInManager(
1335                                                const CIMObjectPath& objectPath)
1336 tony          1.6  {
1337 karl          1.10     PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1338                                "InteropProvider::_buildInstancesNamespaceInManager");
1339 tony          1.6  
1340 karl          1.46     Array<CIMInstance> namespaceInstances = _getInstancesCIMNamespace(objectPath);
1341                    
1342                        CIMInstance instanceObjMgr = _getInstanceCIMObjectManager(objectPath,
1343                            true, true, CIMPropertyList());
1344 tony          1.6  
1345 karl          1.46     CIMObjectPath refObjMgr = instanceObjMgr.getPath();
1346 tony          1.6  
1347 karl          1.46     refObjMgr.setHost(objectPath.getHost());
1348                        refObjMgr.setNameSpace(objectPath.getNameSpace());
1349 tony          1.6  
1350                        Array<CIMInstance> assocInstances;
1351 karl          1.40     CIMClass targetClass;
1352 tony          1.6  
1353 karl          1.46     CIMInstance instanceskel = _buildInstanceSkeleton(objectPath, 
1354                            CIM_NAMESPACEINMANAGER_CLASSNAME,
1355                                                targetClass);
1356                        // Build and instance for each namespace instance.
1357 tony          1.6      for (Uint32 i = 0 ; i < namespaceInstances.size() ; i++)
1358                        {
1359 karl          1.46         CIMInstance instance = instanceskel.clone();
1360                            _setPropertyValue(instance, CIMName("Antecedent"), refObjMgr);
1361                    
1362                            CIMObjectPath temp = namespaceInstances[i].getPath(); 
1363                            temp.setHost(objectPath.getHost());
1364                            temp.setNameSpace(objectPath.getNameSpace());
1365                            _setPropertyValue(instance, CIMName("Dependent"), temp); 
1366 tony          1.6  
1367 karl          1.40         instance.setPath(instance.buildPath(targetClass));
1368 tony          1.6          assocInstances.append(instance);
1369                        }
1370 karl          1.10     PEG_METHOD_EXIT();
1371 tony          1.6      return(assocInstances);
1372                    }
1373 karl          1.46 /* build the instances of the defined association.
1374                    */
1375 karl          1.37 Array<CIMInstance> InteropProvider::_buildInstancesCommMechanismForManager(
1376                        const CIMObjectPath& objectPath)
1377 tony          1.6  {
1378 karl          1.10     PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1379                                "InteropProvider::_buildInstancesCommMechanismForManager");
1380 tony          1.6  
1381 karl          1.37     Array<CIMInstance> commInstances = _buildInstancesPGCIMXMLCommunicationMechanism(
1382 karl          1.46          objectPath);
1383 tony          1.6  
1384 karl          1.46     CIMInstance instanceObjMgr = _getInstanceCIMObjectManager(objectPath,
1385                            true, true, CIMPropertyList());
1386 tony          1.6  
1387 karl          1.46     CIMObjectPath refObjMgr = instanceObjMgr.getPath();
1388 karl          1.40 
1389 tony          1.6      Array<CIMInstance> assocInstances;
1390 karl          1.40     CIMClass targetClass;
1391 karl          1.46     CIMInstance instanceskel = _buildInstanceSkeleton(objectPath, 
1392                            CIM_NAMESPACEINMANAGER_CLASSNAME, targetClass);
1393 tony          1.6      for (Uint32 i = 0 ; i < commInstances.size() ; i++)
1394                        {
1395 karl          1.46         CIMInstance instance = instanceskel.clone();
1396 david.dillard 1.32 
1397 karl          1.46         _setPropertyValue(instance, CIMName("Antecedent"), refObjMgr);
1398 tony          1.6  
1399 karl          1.46         _setPropertyValue(instance, CIMName("Dependent"), commInstances[i].getPath());
1400 karl          1.40 
1401                            instance.setPath(instance.buildPath(targetClass));
1402 tony          1.6          assocInstances.append(instance);
1403                        }
1404 karl          1.10 
1405                        PEG_METHOD_EXIT();
1406 tony          1.6      return(assocInstances);
1407                    }
1408                    
1409 karl          1.1  /* generate one instance of the CIM_Namespace class with the
1410                       properties
1411 karl          1.8     NOTE: CIM 2.4 - Changed to build PG namespace
1412 karl          1.37    @param objectPath
1413 karl          1.1     @param namespace name to put into the class
1414                       @exceptions - exceptions carried forward from create instance
1415                       and addProperty.
1416                    */
1417 karl          1.37 CIMInstance InteropProvider::_buildInstancePGNamespace(const CIMObjectPath& objectPath,
1418                            CIMNamespaceName& nameSpace)
1419 karl          1.1  {
1420                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1421 karl          1.10             "InteropProvider::_buildInstancePGNamespace");
1422 david.dillard 1.32 
1423 tony          1.6      // ATTN: KS need to get the real objectManager name from elsewhere.  the only place
1424 david.dillard 1.32     // this exists is through the objectmanager object.
1425 karl          1.54     String ObjectManagerName = _getObjectManagerName();
1426 david.dillard 1.32 
1427 karl          1.40     CIMClass targetClass;
1428                        CIMInstance instance = _buildInstanceSkeleton(objectPath, PG_NAMESPACE_CLASSNAME,
1429                                                                      targetClass);
1430 karl          1.1  
1431 tony          1.6      _fixInstanceCommonKeys(instance);
1432 karl          1.1  
1433                        //ObjectManagerCreationClassName
1434 tony          1.6      _setPropertyValue(instance, CIM_NAMESPACE_PROPERTY_OBJECTMANAGERCREATIONCLASSNAME, CIM_OBJECTMANAGER_CLASSNAME.getString());
1435                    
1436 karl          1.1      //ObjectManagerName
1437 tony          1.6      _setPropertyValue(instance, CIM_NAMESPACE_PROPERTY_OBJECTMANAGERNAME, ObjectManagerName);
1438                    
1439 karl          1.1      //CreationClassName
1440 david.dillard 1.32     // Class in which this was created,
1441 tony          1.6      _setPropertyValue(instance, CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME, CIM_NAMESPACE_CLASSNAME.getString());
1442 karl          1.1      //Name
1443 tony          1.6      // This is the namespace name itself
1444                        _setPropertyValue(instance, CIM_NAMESPACE_PROPERTY_NAME, nameSpace.getString());
1445 karl          1.1  
1446                        //ClassInfo
1447 tony          1.6      // Set the classinfo to unknown and the description to namespace.
1448                        _setPropertyValue(instance, CIM_NAMESPACE_PROPERTY_CLASSINFO, Uint16(0));
1449                        _setPropertyValue(instance, CIM_NAMESPACE_PROPERTY_DESCRIPTIONOFCLASSINFO, String("namespace"));
1450                    
1451 karl          1.8      //
1452                        //  Everything above was commmon to CIM Namespace.  The following is PG_Namespace Properties
1453                        //
1454                        // ATTN: KS Get the correct values for these entities from repository interface.
1455 karl          1.28 
1456                        CIMRepository::NameSpaceAttributes attributes;
1457 karl          1.8      _repository->getNameSpaceAttributes(nameSpace.getString(), attributes);
1458                        String parent="";
1459 karl          1.11 	String name = "";
1460 karl          1.8      Boolean shareable=false;
1461                        Boolean updatesAllowed=true;
1462 david.dillard 1.32     for (CIMRepository::NameSpaceAttributes::Iterator i = attributes.start(); i; i++)
1463 karl          1.8      {
1464                           String key=i.key();
1465 karl          1.10        String value = i.value();
1466 karl          1.28 
1467 karl          1.8         if (String::equalNoCase(key,"shareable"))
1468 karl          1.11 	   {
1469 karl          1.10           if (String::equalNoCase(value,"true"))
1470                                  shareable=true;
1471 karl          1.11 	   }
1472 david.dillard 1.32        else if (String::equalNoCase(key,"updatesAllowed"))
1473 karl          1.11 	   {
1474 karl          1.10           if (String::equalNoCase(value,"false"))
1475                                  updatesAllowed=false;
1476 karl          1.11 	   }
1477 karl          1.10        // Test to be sure we are returning proper namespace name
1478                           else if (String::equalNoCase(key,"name"))
1479 karl          1.8         {
1480 karl          1.10           if (!String::equalNoCase(value, nameSpace.getString()))
1481                              {
1482                                  PEG_METHOD_EXIT();
1483                                  // This is poor exception since it reflects internal error. Do error log
1484 karl          1.56               throw CIMNotSupportedException(
1485 karl          1.10                   "Namespace attribute rtnd error for key " + key + "expected " +
1486                                       nameSpace.getString()+ value + " in " + String(thisProvider));
1487                              }
1488 karl          1.11 
1489                    		  name = value;
1490 karl          1.8         }
1491                           else if (String::equalNoCase(key,"parent"))
1492 karl          1.11 	   {
1493 karl          1.10           parent=value;
1494 karl          1.11 	   }
1495 david.dillard 1.32        else
1496 karl          1.8         {
1497                              PEG_METHOD_EXIT();
1498 karl          1.10           // Poor error definition since it reflects internal error. do error log
1499 karl          1.8            throw PEGASUS_CIM_EXCEPTION (CIM_ERR_NOT_SUPPORTED, nameSpace.getString()+
1500 karl          1.10               " namespace attribute " + key + " option not supported in"+ String(thisProvider));
1501 karl          1.8         }
1502                        }
1503                        _setPropertyValue(instance, PG_NAMESPACE_PROPERTY_SCHEMAUPDATESALLOWED, updatesAllowed);
1504                        _setPropertyValue(instance, PG_NAMESPACE_PROPERTY_ISSHAREABLE, shareable);
1505                        _setPropertyValue(instance, PG_NAMESPACE_PROPERTY_PARENTNAMESPACE, parent);
1506 karl          1.11 	_setPropertyValue(instance, PG_NAMESPACE_PROPERTY_NAME, name);
1507 karl          1.8  
1508 karl          1.40     instance.setPath(instance.buildPath(targetClass));
1509 karl          1.1      PEG_METHOD_EXIT();
1510                        return(instance);
1511                    }
1512 karl          1.37 
1513 karl          1.5  void _validateCIMNamespaceKeys(const CIMObjectPath& objectPath)
1514                    {
1515 tony          1.6      PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1516                                "InteropProvider::_validateCIMNamespaceKeys");
1517                    
1518 karl          1.5      Boolean valid = true;
1519                        CIMName propertyName;
1520                        if (!_validateRequiredProperty(objectPath,
1521                                    CIM_NAMESPACE_PROPERTY_SYSTEMCREATIONCLASSNAME,
1522                                    System::getSystemCreationClassName ()))
1523                        {
1524                            propertyName = CIM_NAMESPACE_PROPERTY_SYSTEMCREATIONCLASSNAME;
1525                            valid = false;
1526                        }
1527                        if (!_validateRequiredProperty(objectPath,
1528                                    CIM_NAMESPACE_PROPERTY_SYSTEMNAME,
1529 joyce.j       1.30                 System::getFullyQualifiedHostName()))
1530 karl          1.5      {
1531                            propertyName = CIM_NAMESPACE_PROPERTY_SYSTEMNAME;
1532                            valid = false;
1533                        }
1534                        if (!_validateRequiredProperty(objectPath,
1535                                    CIM_NAMESPACE_PROPERTY_OBJECTMANAGERCREATIONCLASSNAME,
1536                                    CIM_OBJECTMANAGER_CLASSNAME.getString()))
1537                        {
1538                            propertyName = CIM_NAMESPACE_PROPERTY_OBJECTMANAGERCREATIONCLASSNAME;
1539                            valid = false;
1540                        }
1541                    
1542                        // ATTN: This one still a problem.  We have to get the name first
1543                        if (!_validateRequiredProperty(objectPath,
1544                                    CIM_NAMESPACE_PROPERTY_OBJECTMANAGERNAME,
1545                                    String::EMPTY))
1546                        {
1547                            propertyName = CIM_NAMESPACE_PROPERTY_OBJECTMANAGERNAME;
1548                            valid = false;
1549                        }
1550                        if (!_validateRequiredProperty(objectPath,
1551 karl          1.5                  CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME,
1552                                    System::getHostName()))
1553                        {
1554                            propertyName = CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME;
1555                            valid = false;
1556                        }
1557                    
1558                        if (!_validateRequiredProperty(objectPath,
1559                                    CIM_NAMESPACE_PROPERTY_NAME,
1560                                    String::EMPTY))
1561                        {
1562                            propertyName = CIM_NAMESPACE_PROPERTY_NAME;
1563                            valid = false;
1564                        }
1565                    
1566                        if (false)
1567                        {
1568 tony          1.6          PEG_METHOD_EXIT();
1569 karl          1.5          throw CIMInvalidParameterException(
1570                                "Invalid key property: " + propertyName.getString());
1571                        }
1572 tony          1.6      PEG_METHOD_EXIT();
1573                    }
1574 karl          1.11 /** completes a property in the defined instance either
1575                        by adding the complete property if it does not exist
1576                        or by adding the value if the property does exist.
1577                        Used to make sure that key properties for things
1578 david.dillard 1.32     like systemcreationclass are included in the
1579 karl          1.11     creation of new instances and that the
1580                        values are logical for the CIMOM.
1581                    */
1582                    Boolean _completeProperty(CIMInstance& instance,
1583                        const CIMName& propertyName,
1584                        const String& value)
1585                    {
1586                    
1587                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1588                                "InteropProvider::_completeProperty()");
1589                    
1590                        Uint32 pos;
1591                    
1592                        if (!_validateRequiredProperty(instance,
1593                                    propertyName,
1594                                    value))
1595                        {
1596                            if ((pos = instance.findProperty (propertyName)) == PEG_NOT_FOUND)
1597                            {
1598                                // Add the property.  Should be from the class.
1599                                PEG_METHOD_EXIT();
1600 karl          1.11             return(false);
1601                            }
1602                            else
1603                            {
1604                                _setPropertyValue(instance, propertyName, value);
1605                            }
1606                        }
1607                    
1608                        PEG_METHOD_EXIT();
1609                        return(true);
1610                    }
1611                    Boolean _completeCIMNamespaceKeys(CIMInstance& instance)
1612                    {
1613                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1614                                "InteropProvider::_completeCIMNamespaceKeys");
1615                    
1616                        Boolean valid = true;
1617                        CIMName propertyName;
1618                    
1619                        if (!_completeProperty(instance,
1620                                    CIM_NAMESPACE_PROPERTY_SYSTEMCREATIONCLASSNAME,
1621 karl          1.11                 System::getSystemCreationClassName ()))
1622                        {
1623                            propertyName = CIM_NAMESPACE_PROPERTY_SYSTEMCREATIONCLASSNAME;
1624                            valid = false;
1625                        }
1626                    
1627                        if (!_completeProperty(instance,
1628                                    CIM_NAMESPACE_PROPERTY_SYSTEMNAME,
1629 joyce.j       1.30                 System::getFullyQualifiedHostName()))
1630 karl          1.11     {
1631                            propertyName = CIM_NAMESPACE_PROPERTY_SYSTEMNAME;
1632                            valid = false;
1633                        }
1634                    
1635                        if (!_completeProperty(instance,
1636                                    CIM_NAMESPACE_PROPERTY_OBJECTMANAGERCREATIONCLASSNAME,
1637                                    CIM_OBJECTMANAGER_CLASSNAME.getString()))
1638                        {
1639                            propertyName = CIM_NAMESPACE_PROPERTY_OBJECTMANAGERCREATIONCLASSNAME;
1640                            valid = false;
1641                        }
1642                    
1643                        if (!_completeProperty(instance,
1644                                    CIM_NAMESPACE_PROPERTY_OBJECTMANAGERNAME,
1645                                    String::EMPTY))
1646                        {
1647                            propertyName = CIM_NAMESPACE_PROPERTY_OBJECTMANAGERNAME;
1648                            valid = false;
1649                        }
1650                        if (!_completeProperty(instance,
1651 karl          1.11                 CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME,
1652                                    System::getHostName()))
1653                        {
1654                            propertyName = CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME;
1655                            valid = false;
1656                        }
1657                    
1658                        if (!_completeProperty(instance,
1659                                    CIM_NAMESPACE_PROPERTY_NAME,
1660                                    String::EMPTY))
1661                        {
1662                            propertyName = CIM_NAMESPACE_PROPERTY_NAME;
1663                            valid = false;
1664                        }
1665                    
1666                        if (!valid)
1667                        {
1668                            PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
1669                                "Invalid CIM_Namespace Key Property " +  propertyName.getString());
1670                            PEG_METHOD_EXIT();
1671                            throw CIMInvalidParameterException(
1672 karl          1.11             "Invalid CIM_Namespace key property: " + propertyName.getString());
1673                        }
1674                        PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4, "CIM_Namespace Keys Valid");
1675                        PEG_METHOD_EXIT();
1676                        return(valid);
1677                    }
1678                    
1679                    
1680 karl          1.5  void _validateCIMNamespaceKeys(const CIMInstance& instance)
1681                    {
1682 tony          1.6      PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1683                                "InteropProvider::_validateCIMNamespaceKeys");
1684 karl          1.5      Boolean valid = true;
1685                        CIMName propertyName;
1686                        if (!_validateRequiredProperty(instance,
1687                                    CIM_NAMESPACE_PROPERTY_SYSTEMCREATIONCLASSNAME,
1688                                    System::getSystemCreationClassName ()))
1689                        {
1690                            propertyName = CIM_NAMESPACE_PROPERTY_SYSTEMCREATIONCLASSNAME;
1691                            valid = false;
1692                        }
1693                    
1694                        if (!_validateRequiredProperty(instance,
1695                                    CIM_NAMESPACE_PROPERTY_SYSTEMNAME,
1696 joyce.j       1.30                 System::getFullyQualifiedHostName ()))
1697 karl          1.5      {
1698                            propertyName = CIM_NAMESPACE_PROPERTY_SYSTEMNAME;
1699                            valid = false;
1700                        }
1701                    
1702                        if (!_validateRequiredProperty(instance,
1703                                    CIM_NAMESPACE_PROPERTY_OBJECTMANAGERCREATIONCLASSNAME,
1704                                    CIM_OBJECTMANAGER_CLASSNAME.getString()))
1705                        {
1706                            propertyName = CIM_NAMESPACE_PROPERTY_OBJECTMANAGERCREATIONCLASSNAME;
1707                            valid = false;
1708                        }
1709                    
1710                        // ATTN: This one still a problem.  We have to get the name first
1711                        if (!_validateRequiredProperty(instance,
1712                                    CIM_NAMESPACE_PROPERTY_OBJECTMANAGERNAME,
1713                                    String::EMPTY))
1714                        {
1715                            propertyName = CIM_NAMESPACE_PROPERTY_OBJECTMANAGERNAME;
1716                            valid = false;
1717                        }
1718 karl          1.5      if (!_validateRequiredProperty(instance,
1719                                    CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME,
1720                                    System::getHostName()))
1721                        {
1722                            propertyName = CIM_NAMESPACE_PROPERTY_CREATIONCLASSNAME;
1723                            valid = false;
1724                        }
1725                    
1726                        if (!_validateRequiredProperty(instance,
1727                                    CIM_NAMESPACE_PROPERTY_NAME,
1728                                    String::EMPTY))
1729                        {
1730                            propertyName = CIM_NAMESPACE_PROPERTY_NAME;
1731                            valid = false;
1732                        }
1733                    
1734                        if (false)
1735                        {
1736 tony          1.6          PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
1737                                "Invalid CIM_Namespace Key Property " +  propertyName.getString());
1738                            PEG_METHOD_EXIT();
1739 karl          1.5          throw CIMInvalidParameterException(
1740 tony          1.6              "Invalid CIM_Namespace key property: " + propertyName.getString());
1741 karl          1.5      }
1742 tony          1.6      PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4, "CIM_Namespace Keys Valid");
1743                        PEG_METHOD_EXIT();
1744                    }
1745                    
1746                    /** builds complete object path from instance and classinfo by building the full path
1747                        with host and namespace names included.
1748                    */
1749 karl          1.37 CIMObjectPath InteropProvider::_buildObjectPath(const CIMObjectPath& objectPath,
1750 tony          1.6                                                  const CIMName& className,
1751                                                                    const CIMInstance& instance)
1752                    {
1753 karl          1.10     PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1754                                "InteropProvider::_buildObjectPath");
1755                    
1756 karl          1.37     CIMObjectPath rtnObjectPath;
1757                        rtnObjectPath = _buildInstancePath(objectPath,className,instance);
1758 tony          1.6  
1759 karl          1.37     rtnObjectPath.setHost(objectPath.getHost());
1760 tony          1.6  
1761 karl          1.37     rtnObjectPath.setNameSpace(objectPath.getNameSpace());
1762 karl          1.10 
1763                        PEG_METHOD_EXIT();
1764 karl          1.37     return(rtnObjectPath);
1765 karl          1.5  }
1766                    
1767 tony          1.6  /* Given a class and instance build the instance path for a
1768 karl          1.1     the object.  This builds all components of the path
1769                       @param namespace name to build
1770 david.dillard 1.32    @return CIMObjectPath containing namespace, class and keybinding
1771 karl          1.1     components of path
1772 tony          1.6     @exceptions - Passes repository exceptions.
1773 karl          1.1  */
1774                    
1775 karl          1.37 CIMObjectPath InteropProvider::_buildInstancePath(const CIMObjectPath& objectPath,
1776 david.dillard 1.32                                            const CIMName& className,
1777 karl          1.1                                             const CIMInstance& instance)
1778                    {
1779                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1780 tony          1.6              "InteropProvider::_buildInstancePath");
1781 karl          1.1  
1782 karl          1.46     // get the class  to use in building path
1783                        // Exception if Class does not exist in this namespace
1784 karl          1.37     CIMClass thisClass = _getClass(objectPath, className);
1785 karl          1.1  
1786                        CIMObjectPath ref = instance.buildPath(thisClass);
1787 david.dillard 1.32 
1788 karl          1.1      PEG_METHOD_EXIT();
1789                        return(ref);
1790                    }
1791                    
1792                    //**************************************************************
1793                    // Overloaded functions to get key value with different params
1794                    //**************************************************************
1795                    
1796 tony          1.6  /*  find the name key in the keybindings and return the value.
1797 karl          1.1      Executes exception if the key not found
1798                        @param object path we will search
1799                        @param keyName - Name of the key to find.
1800                        @return value of name property
1801                        @exceptions CIMInvalidParameterException
1802                    */
1803                    String _getKeyValue(const CIMObjectPath& instanceName, const CIMName& keyName)
1804                    {
1805                        Array<CIMKeyBinding> kbArray = instanceName.getKeyBindings();
1806                    
1807                        // find the correct key binding
1808                        for (Uint32 i = 0; i < kbArray.size(); i++)
1809                        {
1810                            if (kbArray[i].getName() == keyName)
1811                                return (kbArray[i].getValue());
1812                        }
1813 tony          1.6  
1814 karl          1.1      throw CIMInvalidParameterException("Invalid key property: " + keyName.getString());
1815                    }
1816                    
1817                    String _getKeyValue(const CIMInstance& instance, const CIMName& keyName)
1818                    {
1819                        Uint32 pos;
1820                        CIMValue propertyValue;
1821                    
1822                        pos = instance.findProperty(keyName);
1823                        if (pos == PEG_NOT_FOUND)
1824                           throw CIMPropertyNotFoundException
1825                               (NAMESPACE_PROPERTYNAME.getString());
1826 david.dillard 1.32 
1827 karl          1.1      propertyValue = instance.getProperty(pos).getValue();
1828                        if (propertyValue.getType() != CIMTYPE_STRING)
1829                           throw CIMInvalidParameterException("Invalid type for property: "
1830                                                 + NAMESPACE_PROPERTYNAME.getString());
1831                        String name;
1832                        propertyValue.get(name);
1833                        return(name);
1834                    }
1835                    
1836 karl          1.46 /** Test for valid CIMReferences from an association instance. If there is a role 
1837                        property, tests if there is a match for this role and the target object.
1838                        Confirms that this role and this reference exist in the target instance.
1839                     
1840                        @param target - The target path for the association. Localization assumed.
1841                        @param instance - The association class instance we are searching for references
1842                        @param role - The role we require. I there is no role, this is String::EMPTY
1843                        @return - returns Boolean true if target is found in a reference that is
1844                        the same role
1845                     */
1846                    Boolean _isInstanceValidReference(const CIMObjectPath& target,
1847                                                      const CIMInstance& instance,
1848                                                      const String& role)
1849                    {
1850                        // Test if role parameter is valid property.
1851                        Uint32 pos;
1852                        if (role != String::EMPTY)
1853                        {
1854                            // Test if property with this role exists.
1855                            if ((pos = instance.findProperty(role)) == PEG_NOT_FOUND)
1856                                throw CIMException(CIM_ERR_INVALID_PARAMETER);
1857 karl          1.46      
1858                             // Check to be sure this is a reference property
1859                             // This test may not be necessary. Combine it into the loop.
1860                             if (instance.getProperty(pos).getType() != CIMTYPE_REFERENCE)
1861                                 throw CIMException(CIM_ERR_INVALID_PARAMETER);
1862                        }
1863                        //Search instance for all reference properties
1864                        for (Uint32 j = 0; j < instance.getPropertyCount() ; j++)
1865                        {
1866                            const CIMConstProperty p = instance.getProperty(j);
1867                            if (p.getType() == CIMTYPE_REFERENCE)
1868                            {
1869                                // If there is no role or the role is the same as this property name
1870                                CIMValue v = p.getValue();
1871                                CIMObjectPath path;
1872                                v.get(path);
1873                    
1874                                // if no role or role ==this role and target = this path, rtn true.
1875 karl          1.55             if ((role == String::EMPTY) || (CIMName(role) == p.getName()))
1876 karl          1.46             {
1877 karl          1.55                 // and if target is identical to reference path
1878 karl          1.46                 if (target.identical(path))
1879                                        return(true);
1880                                }
1881                            }
1882                        }
1883                        return( false );
1884                    }
1885                    /** Filters the input of instances (which contain path info)
1886                        using the assocClassName, assocRole, ResultClassName and
1887                        resultRole. Removes any instances from the list that
1888                        do not match the filters.
1889                        @instances Array<CIMInstance to filter.
1890                        @
1891                     * TODO - Shouldn't we remove rather than copy??? faster.
1892                     * TODO - why extra check for no resultClass??
1893                    */
1894                    Array<CIMObject> _filterReferenceInstances(Array<CIMInstance>& instances,
1895                                          const CIMObjectPath& targetobjectName,
1896                                          const CIMName& resultClass,
1897                                          const String& resultRole)
1898                    {
1899 karl          1.46     PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
1900                                "_filterReferenceInstances()");
1901 karl          1.55 
1902 karl          1.46     CIMObjectPath targetReference = CIMObjectPath(
1903                                                String(),
1904                                                CIMNamespaceName(),
1905                                                targetobjectName.getClassName(),
1906                                                targetobjectName.getKeyBindings());
1907                        Array<CIMObject> rtnObjects;
1908                        for (Uint32 i = 0 ; i < instances.size() ; i++)
1909                        {
1910                            if (resultClass.isNull() || resultClass.equal(instances[i].getClassName()))
1911                            {
1912                                // if this association instance has this role in targetReference, true
1913                                if (_isInstanceValidReference(targetobjectName, instances[i], resultRole))
1914                                    {
1915                                        rtnObjects.append(instances[i]);
1916                                    }
1917                            }
1918                        }
1919                        PEG_METHOD_EXIT();
1920                        return( rtnObjects );
1921                    }
1922 karl          1.1  //***************************************************************************
1923                    //  The following section is the Instance Operation processors
1924                    //***************************************************************************
1925                    //                createInstance
1926                    //***************************************************************************
1927                    void InteropProvider::createInstance(
1928                    	const OperationContext & context,
1929                    	const CIMObjectPath & instanceReference,
1930                        const CIMInstance& myInstance,
1931                    	ObjectPathResponseHandler & handler)
1932                        {
1933                            PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::createInstance()");
1934 david.dillard 1.32 
1935 karl          1.56         AutoMutex autoMut(changeControlMutex);
1936                    
1937 david.dillard 1.32         Tracer::trace(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
1938 karl          1.26             "%s createInstance. InstanceReference= %s",
1939                                thisProvider,
1940                                (const char *) instanceReference.toString().getCString());
1941                    
1942 karl          1.52         // test for legal namespace for this provider. Exception if not
1943                            _isNamespaceAllowed(instanceReference);
1944                    
1945 karl          1.11         handler.processing();
1946 karl          1.26 
1947 karl          1.1          // Verify that ClassName is correct and get value
1948 karl          1.11         targetClass classEnum  = _verifyValidClassInput(instanceReference.getClassName());
1949                    
1950 karl          1.1          String userName = _validateUserID(context);
1951                            CIMObjectPath newInstanceReference;
1952 karl          1.11 
1953 karl          1.37         CIMNamespaceName newNamespaceName;
1954 karl          1.48         CIMInstance localInstance;
1955                            CIMObjectPath localInstanceReference = instanceReference;
1956                    
1957                            if (classEnum == CIM_NAMESPACE)
1958                            {
1959                                // create instance of PG_Namespace and continue.
1960                                CIMInstance localPGInstance(PG_NAMESPACE_CLASSNAME);
1961                                for (Uint32 i = 0 ; i < myInstance.getQualifierCount() ; i++)
1962                                {
1963                                    localInstance.addQualifier(myInstance.getQualifier(i).clone());
1964                                }
1965                    
1966                                for (Uint32 i = 0 ; i < myInstance.getPropertyCount() ; i++)
1967                                {
1968                                    localInstance.addProperty(myInstance.getProperty(i).clone());
1969                                }
1970                                //TODO set path in instance???
1971                                localInstanceReference.setNameSpace(PEGASUS_NAMESPACENAME_INTEROP);
1972                                // set classEnum so next if interprets this as PG_Namespace
1973                                classEnum = PG_NAMESPACE;
1974                            }
1975 karl          1.8          if (classEnum == PG_NAMESPACE)
1976 karl          1.1          {
1977 humberto      1.23 #ifdef PEGASUS_OS_OS400
1978 karl          1.37             MessageLoaderParms mparms(
1979                                    "ControlProviders.InteropProvider.CREATE_INSTANCE_NOT_ALLOWED",
1980                                    "Create instance operation not allowed by Interop Provider for class $0.",
1981                                    PG_NAMESPACE_CLASSNAME.getString());
1982 humberto      1.23             throw CIMNotSupportedException(mparms);
1983                    #else
1984 karl          1.48             // Create local instance to complete any keys if not created above.
1985                                if (localInstance.isUninitialized())
1986                                {
1987                                    localInstance = myInstance.clone();
1988                                }
1989 karl          1.11 
1990                                _completeCIMNamespaceKeys(localInstance);
1991 tony          1.6              // Validate that keys are as required. Does its own exception.
1992 karl          1.11             newNamespaceName = _getKeyValue(myInstance, CIM_NAMESPACE_PROPERTY_NAME);
1993                    
1994 karl          1.48             newInstanceReference = _buildInstancePath(localInstanceReference,
1995 karl          1.11                                         PG_NAMESPACE_CLASSNAME, localInstance);
1996 humberto      1.23 #endif
1997 karl          1.1          }
1998 tony          1.6  
1999 karl          1.37         else if ((classEnum == CIM_OBJECTMANAGER) ||
2000                                (classEnum == PG_CIMXMLCOMMUNICATIONMECHANISM))
2001                            {
2002                                PEG_METHOD_EXIT();
2003                                throw CIMNotSupportedException("InteropProvider, Create Not allowed");
2004                            }
2005                    
2006 karl          1.11         else   // Invalid class for the create functions.
2007 karl          1.1          {
2008 karl          1.10             PEGASUS_ASSERT(false);
2009 karl          1.1          }
2010 karl          1.10 
2011 karl          1.1          // Create the new namespace
2012                            try
2013                            {
2014 tony          1.6              PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2015 david.dillard 1.32                 "Namespace = " + newNamespaceName.getString() +
2016 tony          1.6                      " to be created.");
2017 karl          1.10             Boolean updatesAllowed = false;
2018                                Boolean shareable = false;
2019                                String parent = String::EMPTY;
2020 karl          1.11 
2021 karl          1.8              CIMRepository::NameSpaceAttributes attributes;
2022 karl          1.10             // optional property.  Set false if not found.
2023                                // ATTN: Should set to class default.
2024 karl          1.8              if (myInstance.findProperty(PG_NAMESPACE_PROPERTY_ISSHAREABLE) != PEG_NOT_FOUND)
2025                                {
2026                                    if (_getPropertyValue(myInstance, PG_NAMESPACE_PROPERTY_ISSHAREABLE, false))
2027 karl          1.10                 {
2028 karl          1.8                      attributes.insert("shareable","true");
2029 karl          1.10                     shareable = true;
2030                                    }
2031 karl          1.8                  else
2032 karl          1.10                     attributes.insert("shareable", "false");
2033 karl          1.8              }
2034                                else
2035 karl          1.10                 attributes.insert("shareable", "false");
2036 karl          1.8  
2037 karl          1.10             // Optional property.  Set false if not found.
2038 karl          1.8              if (myInstance.findProperty(PG_NAMESPACE_PROPERTY_SCHEMAUPDATESALLOWED) != PEG_NOT_FOUND)
2039                                {
2040                                    if (_getPropertyValue(myInstance, PG_NAMESPACE_PROPERTY_SCHEMAUPDATESALLOWED, false))
2041 karl          1.10                 {
2042 karl          1.8                      attributes.insert("updatesAllowed","true");
2043 karl          1.10                     updatesAllowed = true;
2044                                    }
2045 karl          1.8                  else
2046                                        attributes.insert("updatesAllowed", "false");
2047                                }
2048                                else
2049                                    attributes.insert("updatesAllowed", "false");
2050                    
2051 karl          1.10             // ATTN: Need to reflect and dependencies between these properties. Right now
2052                                // this lets anything happen.
2053 karl          1.8              if (myInstance.findProperty(PG_NAMESPACE_PROPERTY_PARENTNAMESPACE) != PEG_NOT_FOUND)
2054                                {
2055                                    String parent = _getPropertyValue(myInstance, PG_NAMESPACE_PROPERTY_PARENTNAMESPACE, String::EMPTY);
2056                                    if (parent != String::EMPTY)
2057 karl          1.10                     attributes.insert("parent",parent);
2058 karl          1.8              }
2059                                _repository->createNameSpace(newNamespaceName, attributes);
2060 david.dillard 1.32 
2061 karl          1.1              PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2062 david.dillard 1.32                 "Namespace = " + newNamespaceName.getString() +
2063 karl          1.1                      " successfully created.");
2064 kumpf         1.35             Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,
2065 karl          1.37                 "Create Namespace: Shareable = $0, Updates allowed: $1,  Parent: $2",
2066                                    newNamespaceName.getString(), shareable? 
2067                                            "true" : "false", shareable? "true" : "false", parent );
2068 karl          1.11 
2069 karl          1.1          }
2070 david.dillard 1.32         catch(const CIMException&)
2071 karl          1.1          {
2072                               PEG_METHOD_EXIT();
2073 david.dillard 1.32            throw;
2074 karl          1.1          }
2075 david.dillard 1.32         catch(const Exception&)
2076 karl          1.1          {
2077                               PEG_METHOD_EXIT();
2078 david.dillard 1.32            throw;
2079 karl          1.1          }
2080 david.dillard 1.32 
2081 karl          1.1          // begin processing the request
2082                    
2083                           handler.deliver(newInstanceReference);
2084                    
2085                           // complete processing the request
2086                           handler.complete();
2087                    
2088                           PEG_METHOD_EXIT();
2089                           return;
2090                       }
2091                    
2092                    //***************************************************************************
2093                    //                deleteInstance
2094                    //***************************************************************************
2095                    void InteropProvider::deleteInstance(
2096                    	const OperationContext & context,
2097                    	const CIMObjectPath & instanceName,
2098                    	ResponseHandler & handler)
2099                        {
2100                            PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::deleteInstance");
2101 tony          1.6  
2102 karl          1.56         AutoMutex autoMut(changeControlMutex);
2103                    
2104 david.dillard 1.32         Tracer::trace(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2105 karl          1.26             "%s deleteInstance. instanceName= %s",
2106                                thisProvider,
2107                                (const char *) instanceName.toString().getCString());
2108                    
2109 karl          1.52         // test for legal namespace for this provider. Exception if not
2110                            _isNamespaceAllowed(instanceName);
2111                    
2112 tony          1.6          handler.processing();
2113 karl          1.1          // Verify that ClassName is correct and get value
2114 david.dillard 1.32         targetClass classEnum  = _verifyValidClassInput(instanceName.getClassName());
2115                    
2116 karl          1.1          String userName = _validateUserID(context);
2117 david.dillard 1.32 
2118 tony          1.6          // Delete the instance since it may be in persistent storage
2119                            if ((classEnum == CIM_OBJECTMANAGER))
2120                            {
2121                                try
2122                                {
2123 karl          1.37                 _repository->deleteInstance(instanceName.getNameSpace(),instanceName);
2124 tony          1.6              }
2125 david.dillard 1.32             catch(const CIMException&)
2126 tony          1.6              {
2127                                    PEG_METHOD_EXIT();
2128 david.dillard 1.32                 throw;
2129 tony          1.6              }
2130                            }
2131 karl          1.26         else if (classEnum == PG_NAMESPACE)
2132 karl          1.1          {
2133 karl          1.26             CIMNamespaceName deleteNamespaceName;
2134 humberto      1.23 #ifdef PEGASUS_OS_OS400
2135 karl          1.37             MessageLoaderParms mparms(
2136                                    "ControlProviders.InteropProvider.DELETE_INSTANCE_NOT_ALLOWED",
2137                                    "Delete instance operation not allowed by Interop Provider for class $0.",
2138                                    PG_NAMESPACE_CLASSNAME.getString());
2139 humberto      1.23             throw CIMNotSupportedException(mparms);
2140                    #else
2141 karl          1.5              // validate requred keys.  Exception out if not valid
2142                                _validateCIMNamespaceKeys(instanceName);
2143 david.dillard 1.32 
2144 karl          1.1              deleteNamespaceName = _getKeyValue(instanceName, CIM_NAMESPACE_PROPERTY_NAME);
2145 humberto      1.23 #endif
2146 karl          1.1  
2147 karl          1.26             Array<CIMNamespaceName> namespaceNames;
2148                                namespaceNames = _enumerateNameSpaces();
2149 karl          1.1  
2150 karl          1.26             if (deleteNamespaceName.equal (ROOTNS))
2151                                {
2152                                   throw CIMNotSupportedException("root namespace cannot be deleted.");
2153                                }
2154 david.dillard 1.32 
2155 karl          1.26             _repository->deleteNameSpace(deleteNamespaceName);
2156 david.dillard 1.32 
2157 karl          1.26             PEG_TRACE_STRING(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2158 david.dillard 1.32                "Namespace = " + deleteNamespaceName.getString() +
2159 karl          1.26                    " successfully deleted.");
2160 david.dillard 1.32 
2161 kumpf         1.35             Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,
2162 karl          1.26                "Interop Provider Delete Namespace: $0",
2163                                   deleteNamespaceName.getString());
2164                            }
2165                            else
2166                            {
2167                                throw CIMNotSupportedException("Delete Not allowed for " + instanceName.getClassName().getString());
2168                            }
2169 karl          1.1  
2170 karl          1.26         handler.complete();
2171 karl          1.5  
2172 karl          1.26         PEG_METHOD_EXIT();
2173                            return ;
2174 karl          1.1      }
2175                    
2176 karl          1.46 /** Local version of getInstance to be used by other functions in the
2177                        the provider.  Returns a single instance.  Note that it always
2178                        returns an instance.  If none was found, it is unitinialitized.
2179                    */
2180                    CIMInstance InteropProvider::localGetInstance(
2181                        const OperationContext & context,
2182                        const CIMObjectPath & instanceName,
2183                        const Boolean includeQualifiers,
2184                        const Boolean includeClassOrigin,
2185                        const CIMPropertyList & propertyList)
2186                    {
2187                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::localGetInstance");
2188                        
2189                        Tracer::trace(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2190                            "%s getInstance. instanceName= %s , includeQualifiers= %s, includeClassOrigin= %s, PropertyList= %s",
2191                            thisProvider,
2192                            (const char *)instanceName.toString().getCString(),
2193                            (const char *)_showBool(includeQualifiers).getCString(),
2194                            (const char*) _showBool(includeClassOrigin).getCString(),
2195                            (const char *)_showPropertyList(propertyList).getCString());
2196                        
2197 karl          1.46     // Verify that ClassName is correct and get value
2198                        targetClass classEnum  = _verifyValidClassInput(instanceName.getClassName());
2199                        
2200                        String userName = _validateUserID(context);
2201                        
2202                        // create reference from host, namespace, class components of
2203                        // instance name
2204 karl          1.56 
2205 karl          1.46     CIMObjectPath ref;
2206                        ref.setHost(instanceName.getHost());
2207                        ref.setClassName(instanceName.getClassName());
2208                        ref.setNameSpace(instanceName.getNameSpace());
2209                        
2210                        // Enumerate instances for this class. Returns all instances
2211                        // Note that this returns paths setup and instances already
2212                        // filtered per the input criteria.
2213                        
2214                        Array<CIMInstance> instances =  localEnumerateInstances(
2215                                context,
2216                                ref,
2217                                includeQualifiers,
2218                                includeClassOrigin,
2219                                propertyList);
2220                        
2221                        // deliver a single instance if found.
2222                        CIMInstance rtnInstance;
2223 karl          1.56 
2224 karl          1.46     for (Uint32 i = 0 ; i < instances.size() ; i++)
2225                        {
2226                           if (instanceName == instances[i].getPath())
2227                           {
2228 karl          1.47            /* DEBUG SUPPORT
2229 karl          1.46            Tracer::trace(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2230                                   "%s getInstance return instance number %u\npath: %s\n %s\n",thisProvider, i,
2231                                   (instances[i].getPath().toString().getCString()),
2232                                   ( ( CIMObject) instances[i]).toString().getCString());
2233 karl          1.47            *****/
2234 karl          1.46           rtnInstance = instances[i];
2235                              break;
2236                              // TODO Add test for duplicates somewhere.
2237                           }
2238                        }
2239                        PEG_METHOD_EXIT();
2240                        return(rtnInstance);
2241                    }
2242 karl          1.1  //***************************************************************************
2243                    //                getInstance
2244                    //***************************************************************************
2245                    void InteropProvider::getInstance(
2246                        const OperationContext & context,
2247                        const CIMObjectPath & instanceName,
2248                        const Boolean includeQualifiers,
2249                        const Boolean includeClassOrigin,
2250 tony          1.6      const CIMPropertyList & propertyList,
2251 karl          1.1      InstanceResponseHandler & handler)
2252 karl          1.46 {
2253 karl          1.52     // test for legal namespace for this provider. Exception if not
2254                        _isNamespaceAllowed(instanceName);
2255                    
2256 karl          1.46     handler.processing();
2257 karl          1.52 
2258 karl          1.46     CIMInstance myInstance = localGetInstance(
2259                                        context,
2260                                        instanceName,
2261                                        includeQualifiers,
2262                                        includeClassOrigin,
2263                                        propertyList);
2264 david.dillard 1.32 
2265 karl          1.46     if (!myInstance.isUninitialized())
2266                            handler.deliver(myInstance);
2267 karl          1.56     else
2268                            throw CIMObjectNotFoundException(instanceName.toString());
2269 karl          1.45     
2270 karl          1.46     handler.complete();
2271                    }
2272 karl          1.45 
2273 karl          1.46 //*****************************************************************************************
2274                    //   localEnumerateInstances 
2275                    //   EnumerateInstances equivalent to external but returns instances
2276                    //   Used by other operations to build instances for processing
2277                    //   Note that this delivers instances as a group rather than incrementally.
2278                    //    This technique should only be used for small groups of instances.
2279                    //****************************************************************************************
2280 karl          1.1  
2281 karl          1.46 Array<CIMInstance> InteropProvider::localEnumerateInstances(
2282 karl          1.1      const OperationContext & context,
2283                        const CIMObjectPath & ref,
2284                        const Boolean includeQualifiers,
2285                        const Boolean includeClassOrigin,
2286 karl          1.46     const CIMPropertyList& propertyList)
2287 karl          1.1      {
2288 karl          1.46         PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::localEnumerateInstances()");
2289                    
2290 david.dillard 1.32         Tracer::trace(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2291 karl          1.46             "%s enumerateInstances. referenc= %s , includeQualifiers= %s, includeClassOrigin= %s, PropertyList= %s",
2292 karl          1.26             thisProvider,
2293 karl          1.46             (const char *)ref.toString().getCString(),
2294                                (const char *)_showBool(includeQualifiers).getCString(),
2295                                (const char*) _showBool(includeClassOrigin).getCString(),
2296                                (const char *)_showPropertyList(propertyList).getCString());
2297                    
2298 karl          1.1          // Verify that ClassName is correct and get value
2299 david.dillard 1.32         targetClass classEnum  = _verifyValidClassInput(ref.getClassName());
2300                    
2301 karl          1.48         String userName = _validateUserID(context);
2302 david.dillard 1.32 
2303 karl          1.40         Array<CIMInstance> instances;
2304 karl          1.1          if (classEnum == CIM_OBJECTMANAGER)
2305                            {
2306 karl          1.37             CIMInstance instance = _getInstanceCIMObjectManager(
2307                                                        ref,
2308                                                        includeQualifiers,
2309 tony          1.6                                      includeClassOrigin,
2310                                                        propertyList);
2311 karl          1.40             instances.append(instance);
2312 karl          1.1          }
2313 david.dillard 1.32 
2314 karl          1.26         else if (classEnum == PG_CIMXMLCOMMUNICATIONMECHANISM)
2315 karl          1.1          {
2316 karl          1.48             instances = _buildInstancesPGCIMXMLCommunicationMechanism(ref);
2317 karl          1.46         }
2318                    
2319                            else if (classEnum == CIM_NAMESPACEINMANAGER)
2320                            {
2321                                instances = _buildInstancesNamespaceInManager(ref);
2322 karl          1.1          }
2323                    
2324 karl          1.48         else if (classEnum == CIM_COMMMECHANISMFORMANAGERINST)
2325 karl          1.19         {
2326 karl          1.46             instances = _buildInstancesCommMechanismForManager(ref);
2327 karl          1.19         }
2328                    
2329 karl          1.26         else if (classEnum == PG_NAMESPACE)
2330 karl          1.1          {
2331 karl          1.46             instances = _getInstancesCIMNamespace(ref);
2332 karl          1.26         }
2333 karl          1.48         else if (classEnum == CIM_NAMESPACE)
2334                            {
2335                                // returns nothing if CIM_Namespace
2336                                // This class used only to create. Enumerates
2337                                // automatically get the hiearchy.
2338                            }
2339 karl          1.26         else
2340                            {
2341 karl          1.37             PEG_METHOD_EXIT();
2342 karl          1.26             throw CIMNotSupportedException
2343 karl          1.48                 (ref.getClassName().getString() + " not supported by Interop Provider enumerate");
2344 karl          1.1          }
2345                    
2346 karl          1.40         // Filter and deliver the resulting instances
2347                            for (Uint32 i = 0 ; i < instances.size() ; i++)
2348                            {
2349 karl          1.46             _finishInstance(instances[i],
2350                                                ref,
2351                                                includeQualifiers,
2352                                                includeClassOrigin,
2353                                                propertyList );
2354                    
2355 karl          1.47             /* Debug Trace of the Instances generated
2356 karl          1.40             Tracer::trace(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2357 karl          1.46                 "%s enumerateInstances return instance number %u\npath: %s\n %s\n",thisProvider, i,
2358 karl          1.40                 (instances[i].getPath().toString().getCString()),
2359                                    ( ( CIMObject) instances[i]).toString().getCString());
2360 karl          1.47             ****/
2361 karl          1.40 
2362                            }
2363 karl          1.46         return(instances);
2364                            PEG_METHOD_EXIT();
2365                        }
2366                    
2367                    //***************************************************************************
2368 karl          1.48 //                EnumerateInstances - External Operation call
2369 karl          1.46 //    Delivers instances back through response handler.
2370                    //***************************************************************************
2371                    void InteropProvider::enumerateInstances(
2372                        const OperationContext & context,
2373                        const CIMObjectPath & ref,
2374                        const Boolean includeQualifiers,
2375                        const Boolean includeClassOrigin,
2376                        const CIMPropertyList& propertyList,
2377                        InstanceResponseHandler & handler)
2378                        {
2379                            PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::enumerateInstances()");
2380                    
2381 karl          1.52         // test for legal namespace for this provider. Exception if not
2382                            _isNamespaceAllowed(ref);
2383                    
2384 karl          1.46         handler.processing();
2385                    
2386                            // Call the internal enumerateInstances to generate instances of defined
2387                            // class.  This expects the instances to be returned complete including
2388                            // complete path.
2389                            Array<CIMInstance> instances =  localEnumerateInstances(
2390                                    context,
2391                                    ref,
2392                                    includeQualifiers,
2393                                    includeClassOrigin,
2394                                    propertyList);
2395                    
2396                            handler.deliver(instances);
2397 karl          1.1          handler.complete();
2398 karl          1.46         
2399 karl          1.1          PEG_METHOD_EXIT();
2400 karl          1.46     }   
2401 karl          1.1  
2402 karl          1.56 /** Determies if an instance modification is to be allowed. This includes
2403                        tests to determine the validity of the modified instance, the property
2404                        list provided, if qualifier modification was requested.
2405                        @param context
2406                        @param instanceReference CIMObjectPath defining the path of the instance
2407                        to be modified.
2408                        @param modifiedIns CIMInstance containing the modifications
2409                        @param includeQualifiers Boolean defining if qualifiers are to be modified.
2410                        @param propertyList CIMPropertyList provided with the request
2411                        @param allowedModifyProperties CIMPropertyList defining properties that
2412                        are allowed to be modified by the provider
2413                        @return true if there are modifications that can be made.  Note that there
2414                        is an additional decision to be made by the user whether the modifiedIns
2415                        includes all of the properties or they are to be set to default.
2416                        @exception CIM_ERR_NOT_SUPPORTED if the specified modification is not supported
2417                        @exception CIM_ERR_INVALID_PARAMETER  if the modifiedInstance is invalid
2418                     */
2419                    Boolean InteropProvider::isModifyAllowed(const OperationContext & context,
2420                        const CIMObjectPath & instanceReference,
2421                        const CIMInstance& modifiedIns,
2422                        const Boolean includeQualifiers,
2423 karl          1.56     const CIMPropertyList& propertyList,
2424                        const CIMPropertyList& allowedModifyProperties)
2425                    {
2426                        // if property list size does not match allowed list.
2427                        if ((propertyList.size() > allowedModifyProperties.size())
2428                               || (propertyList.isNull())
2429                           )
2430                        {
2431                            throw CIMNotSupportedException(
2432                                "Only Modification of " + _toStringPropertyList(allowedModifyProperties)
2433                                 + " allowed");
2434                        }
2435                        // property list indicates nothing to modify return false
2436                        if (propertyList.size() == 0)
2437                        {
2438                            return(false);
2439                        }
2440                    
2441                        // DO NOT allow any qualifier modifications.
2442                        if (includeQualifiers)
2443                        {
2444 karl          1.56         throw CIMNotSupportedException(
2445                                "Qualifier Modification not allowed");
2446                        }
2447                    
2448                        // Assure that nothing is in the propertylist and NOT in
2449                        // the allowed list.
2450                        Array<CIMName> allowedArray = allowedModifyProperties.getPropertyNameArray();
2451                        for (Uint32 i = 0 ; i < propertyList.size() ; i++)
2452                        {
2453                            if (!Contains(allowedArray, propertyList[i]))
2454                            {
2455                                throw CIMNotSupportedException(
2456                                    "Only Modification of " + _toStringPropertyList(allowedModifyProperties)
2457                                     + " allowed");
2458                            }
2459                        }
2460                        // We have something to modify. Property List is valid
2461                        return(true);
2462                    }
2463                    /** Modify the existing object Manager Object.  Only a single property modification
2464                        is allowed, the statistical data setting.  Any other change is rejected
2465 karl          1.56     with an exception
2466                        @param instanceReference - Reference for the instance to be modified.
2467                        @param modifiedIns CIMInstance defining the change. If this includes more than
2468                        a single property, the propertyList must specify modification only of the
2469                        statisticaldata property.
2470                        @includeQualifiers Boolean which must be false unless there are no qualifiers
2471                        in the modifiedIns.
2472                        @propertyList CIMPropertyList defining the property to be modified if there
2473                        is more than one property in the modifiedIns.
2474                        @Exceptions CIMInvalidParameterException if the parameters are not valid for
2475                        the modification.
2476                     */
2477 karl          1.10 void InteropProvider::modifyObjectManagerInstance(const OperationContext & context,
2478                        const CIMObjectPath & instanceReference,
2479                        const CIMInstance& modifiedIns,
2480                        const Boolean includeQualifiers,
2481 karl          1.56     const CIMPropertyList& propertyList)
2482 karl          1.10 {
2483                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
2484 karl          1.54             "InteropProvider::modifyObjectManagerInstance");
2485 karl          1.37 
2486 karl          1.56     // Modification only allowed when Performance staticistics are active
2487                    #ifndef PEGASUS_DISABLE_PERFINST
2488                        // the only allowed modification is one property, statistical data
2489                        Array<CIMName> plA;
2490                        plA.append(CIMName(OM_GATHERSTATISTICALDATA));
2491                        CIMPropertyList allowedModifyPropertyList(plA);
2492                    
2493                        // returns only if no exception and there is property to modify.
2494                        if (isModifyAllowed(context, instanceReference, modifiedIns,
2495                            includeQualifiers, propertyList, allowedModifyPropertyList))
2496 karl          1.10     {
2497 karl          1.26         CIMInstance instance;
2498 karl          1.40         instance = _getInstanceCIMObjectManager(instanceReference,
2499                                    true, true, CIMPropertyList());
2500 karl          1.10 
2501 karl          1.56         CIMObjectPath tmpPath;
2502                            tmpPath.setClassName(instanceReference.getClassName());
2503                            tmpPath.setKeyBindings(instanceReference.getKeyBindings());
2504                            if (!(tmpPath == instance.getPath()) )
2505                                throw CIMObjectNotFoundException(instanceReference.toString());
2506                        }
2507                        else    // nothing to modify. return
2508                        {
2509 karl          1.10         return;
2510 karl          1.56     }
2511                        Boolean statisticsFlag;
2512                        CIMInstance myInstance;
2513 karl          1.8  
2514 karl          1.56     // We modify only if this property exists.
2515                        // could either use the property from modifiedIns or simply replace
2516                        // value in property from object manager.
2517                        if (modifiedIns.findProperty(OM_GATHERSTATISTICALDATA) != PEG_NOT_FOUND)
2518                        {
2519                            myInstance = _getInstanceCIMObjectManager(instanceReference,
2520                                                        false, false, propertyList);
2521                            statisticsFlag = _getPropertyValue(modifiedIns, OM_GATHERSTATISTICALDATA, false);
2522                            // set the changed property into the instance
2523                            _setPropertyValue(myInstance, OM_GATHERSTATISTICALDATA, statisticsFlag);
2524 karl          1.10     }
2525 karl          1.56     else
2526                        {
2527                            // if statistics property not in place, simply exit. Nothing to do
2528                            // not considered an error
2529                            PEG_METHOD_EXIT();
2530                            return;
2531                        }
2532                        // Modify the instance on disk
2533                        try
2534                        {
2535                            _repository->modifyInstance(instanceReference.getNameSpace(),
2536                                           myInstance, false,  propertyList);
2537                        }
2538                        catch(const CIMException&)
2539                        {
2540                            PEG_METHOD_EXIT();
2541                            throw;
2542                        }
2543                        catch(const Exception&)
2544                        {
2545                            PEG_METHOD_EXIT();
2546 karl          1.56         throw;
2547                        }
2548                        Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,
2549                            "Interop Provider Set Statistics gathering in CIM_ObjectManager: $0",
2550                            (statisticsFlag? "true" : "false"));
2551                        StatisticalData* sd = StatisticalData::current();
2552                        sd->setCopyGSD(statisticsFlag);
2553                        PEG_METHOD_EXIT();
2554                        return;
2555                    
2556                    #else
2557 karl          1.10     PEG_METHOD_EXIT();
2558                        throw CIMNotSupportedException
2559 karl          1.40         (OM_GATHERSTATISTICALDATA.getString() + 
2560                                    " modify operation not supported by Interop Provider");
2561 karl          1.56 #endif
2562 karl          1.10 }
2563 karl          1.1  //***************************************************************************
2564 karl          1.46 //***************************************************************************
2565 karl          1.10 //                modifyInstance
2566 karl          1.1  //***************************************************************************
2567 karl          1.46 //***************************************************************************
2568 karl          1.8  void InteropProvider::modifyInstance(const OperationContext & context,
2569                        const CIMObjectPath & instanceReference,
2570                        const CIMInstance& modifiedIns,
2571                        const Boolean includeQualifiers,
2572                        const CIMPropertyList& propertyList,
2573                        ResponseHandler & handler)
2574                    {
2575                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
2576 karl          1.10             "InteropProvider::modifyInstance");
2577 karl          1.8  
2578 karl          1.56     AutoMutex autoMut(changeControlMutex);
2579                    
2580 david.dillard 1.32     Tracer::trace(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2581 karl          1.26         "%s modifyInstance. instanceReference= %s, includeQualifiers= %s, PropertyList= %s",
2582                            thisProvider,
2583                            (const char *) instanceReference.toString().getCString(),
2584                            (const char *) _showBool(includeQualifiers).getCString(),
2585                            (const char *) _showPropertyList(propertyList).getCString());
2586 karl          1.10 
2587 karl          1.52     // test for legal namespace for this provider. Exception if not
2588                        _isNamespaceAllowed(instanceReference);
2589                    
2590 karl          1.10     // ATTN: KS 31 August 2004. This must test for privileged user.
2591 karl          1.37 
2592 karl          1.8      CIMName className =  instanceReference.getClassName();
2593 karl          1.37     targetClass classEnum  = _verifyValidClassInput(className);
2594 karl          1.8  
2595                        String userName = _validateUserID(context);
2596                        // begin processing the request
2597                        handler.processing();
2598                    
2599                        if (classEnum == CIM_OBJECTMANAGER)
2600                        {
2601 karl          1.10         modifyObjectManagerInstance(context, instanceReference,modifiedIns,
2602 karl          1.56             includeQualifiers, propertyList);
2603 karl          1.8          // for the moment allow modification of the statistics property only
2604                        }
2605                    
2606 karl          1.10     else if (classEnum == PG_CIMXMLCOMMUNICATIONMECHANISM)
2607 karl          1.8      {
2608                            PEG_METHOD_EXIT();
2609                            throw CIMNotSupportedException
2610 karl          1.56             (" Modification of " + className.getString() + " not supported by Interop Provider");
2611 karl          1.8      }
2612 karl          1.10     else if (classEnum == PG_NAMESPACE)
2613 karl          1.8      {
2614 humberto      1.23 #ifdef PEGASUS_OS_OS400
2615 karl          1.40             MessageLoaderParms mparms(
2616                                    "ControlProviders.InteropProvider.MODIFY_INSTANCE_NOT_ALLOWED",
2617                                    "Modify instance operation not allowed by Interop Provider for class $0.",
2618                                    PG_NAMESPACE_CLASSNAME.getString());
2619 humberto      1.23             throw CIMNotSupportedException(mparms);
2620                    #else
2621 karl          1.10         // for the moment allow modification of the statistics property only
2622 karl          1.8          PEG_METHOD_EXIT();
2623                            throw CIMNotSupportedException
2624                                (className.getString() + " not supported by Interop Provider");
2625 humberto      1.23 #endif
2626 karl          1.8      }
2627 karl          1.10     else
2628                        {
2629 karl          1.37         PEG_METHOD_EXIT();
2630                            throw CIMNotSupportedException(
2631                                className.getString() + " not supported by Interop Provider");
2632 karl          1.10     }
2633 karl          1.8  
2634 karl          1.10     handler.complete();
2635 karl          1.8      PEG_METHOD_EXIT();
2636                        return;
2637                    }
2638                    
2639 karl          1.10 //***************************************************************************
2640 karl          1.46 //***************************************************************************
2641 karl          1.10 //                enumerateInstanceNames
2642                    //***************************************************************************
2643 karl          1.46 //***************************************************************************
2644                    
2645 karl          1.1  void InteropProvider::enumerateInstanceNames(
2646                    	const OperationContext & context,
2647                    	const CIMObjectPath & classReference,
2648                            ObjectPathResponseHandler & handler)
2649                        {
2650                        	PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
2651                                    "InteropProvider::enumerateInstanceNames()");
2652                    
2653 karl          1.37         Tracer::trace(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2654                                "%s enumerateInstanceNames. classReference= %s",
2655                                thisProvider,
2656                                (const char *) classReference.toString().getCString());
2657 karl          1.1  
2658 karl          1.52         // test for legal namespace for this provider. Exception if not
2659                            _isNamespaceAllowed(classReference);
2660                    
2661 karl          1.40         targetClass classEnum  = 
2662                                    _verifyValidClassInput(classReference.getClassName());
2663 david.dillard 1.32 
2664 tony          1.6          String userName = _validateUserID(context);
2665 karl          1.11 
2666 karl          1.1          // begin processing the request
2667                            handler.processing();
2668 david.dillard 1.32 
2669 karl          1.46         Boolean includeQualifiers = true;
2670                            Boolean includeClassOrigin = true;
2671                            
2672                            Array<CIMInstance> instances =  localEnumerateInstances(
2673                                    context,
2674                                    classReference,
2675                                    includeQualifiers,
2676                                    includeClassOrigin,
2677                                    CIMPropertyList());
2678 karl          1.37 
2679 karl          1.46         for (Uint32 i = 0 ; i < instances.size() ; i++)
2680 karl          1.1          {
2681 karl          1.46             handler.deliver(instances[i].getPath());
2682 karl          1.1          }
2683                    
2684 karl          1.46         handler.complete();
2685                            PEG_METHOD_EXIT();
2686                        }
2687 karl          1.19 
2688 karl          1.46 //**************************************************************
2689                    //**************************************************************
2690                    // Association Functions
2691                    //**************************************************************
2692                    //**************************************************************
2693 karl          1.37 
2694 karl          1.46 /** _filterInstancesToTargetPaths - Filters one associaton and returns references that represent the result of
2695                        filtering on resultclass and role.  Any reference that matches the resultclass and role
2696                        and not the target is returned
2697                        @param assocInstance - The association instance being processed.
2698                        @param targetObjectPath - The original target. This is required since this is the one reference
2699                        we don't want.
2700                        @resultClass - The resultClass we want to filter on
2701                        @resultRole  - The result role we want to filter on
2702                        @return - returns the CIMObjectPaths that represent the other side of the association that pass 
2703                        the resultClass and resultRole filters.
2704                     */
2705                    
2706                    // TODO convert the CIMOBjectPath back to const.
2707                    Array<CIMObjectPath> _filterAssocInstanceToTargetPaths(const CIMObject& assocInstance,
2708                                        const CIMObjectPath& targetObjectPath,
2709                                        const CIMName resultClass,
2710                                        const String resultRole)
2711                    {
2712                        Array<CIMObjectPath> returnPaths;
2713                        // get all reference properties except for target.
2714                        for (Uint32 i = 0 ; i < assocInstance.getPropertyCount() ; i++)
2715 karl          1.46     {
2716                            CIMConstProperty p = assocInstance.getProperty(i);
2717                    
2718                            if (p.getType() == CIMTYPE_REFERENCE)
2719                            {
2720                                CIMValue v = p.getValue();
2721                                CIMObjectPath path;
2722                                v.get(path);
2723                                
2724                                if (!targetObjectPath.identical(path))
2725 tony          1.6              {
2726 karl          1.46                 if (resultClass.isNull() || resultClass == path.getClassName())
2727                                    {
2728 karl          1.55                     if ((resultRole == String::EMPTY) || (p.getName() == CIMName(resultRole)))
2729 karl          1.46                         returnPaths.append(path);
2730                                    }
2731 tony          1.6              }
2732 karl          1.1          }
2733 karl          1.46     }
2734                        CDEBUG("_filterAssoc PathsReturned. Count = " << returnPaths.size() 
2735                    	   << "\n" << _showPathArray(returnPaths));
2736                        return( returnPaths );
2737                    }
2738 karl          1.1  
2739                    
2740                    //**************************************************************
2741                    //**************************************************************
2742 karl          1.46 // Associators Operation Call
2743 karl          1.1  //**************************************************************
2744                    //**************************************************************
2745                    
2746                    void InteropProvider::associators(
2747                    	const OperationContext & context,
2748                    	const CIMObjectPath & objectName,
2749                    	const CIMName & associationClass,
2750                    	const CIMName & resultClass,
2751                    	const String & role,
2752                    	const String & resultRole,
2753                    	const Boolean includeQualifiers,
2754                    	const Boolean includeClassOrigin,
2755                    	const CIMPropertyList & propertyList,
2756                    	ObjectResponseHandler & handler)
2757                    {
2758 tony          1.6      PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
2759 karl          1.54             "InteropProvider::associators()");
2760 karl          1.46     Tracer::trace(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2761 karl          1.54         "%s associators. objectName= %s , assocClass= %s resultClass= %s role= %s resultRole %includeQualifiers= %s, includeClassOrigin= %s, PropertyList= %s",
2762 karl          1.46         thisProvider,
2763                            (const char *)objectName.toString().getCString(),
2764                            (const char *)associationClass.getString().getCString(),
2765                            (const char *)resultClass.getString().getCString(),
2766                            (const char *)role.getCString(),
2767                            (const char *)resultRole.getCString(),
2768                            (const char *)_showBool(includeQualifiers).getCString(),
2769                            (const char*) _showBool(includeClassOrigin).getCString(),
2770                            (const char *)_showPropertyList(propertyList).getCString());
2771 karl          1.52 
2772                        // test for legal namespace for this provider. Exception if not
2773                        _isNamespaceAllowed(objectName);
2774                    
2775 karl          1.46     handler.processing();
2776                        // Get references for this object. Note that this
2777                        // uses the associationClass as resultClass.
2778                        Array<CIMObject> referenceObjects = localReferences(
2779                                context,
2780                                objectName,
2781                                associationClass,
2782                                role,
2783                                includeQualifiers,
2784                                includeClassOrigin,
2785                                propertyList);
2786                     
2787                        // Note that Result Class is not always there.  We need to account for
2788                        // both case where it exists and where it does not exist.
2789                        // enumerate all reference instances of the resultClass (i.e. the association)
2790                        // create path for resultClass
2791                    
2792                        // for each reference object, get all non-target references
2793                        Array<CIMObjectPath> resultPaths;
2794                        for (Uint32 i = 0 ; i < referenceObjects.size() ; i++)
2795                        {
2796 karl          1.46         // get Other references from each reference object.
2797                            Array<CIMObjectPath> tempPath =
2798                                _filterAssocInstanceToTargetPaths(
2799                                                    referenceObjects[i],
2800                                                    objectName,
2801                                                    resultClass,
2802                                                    resultRole);
2803                            for (Uint32 i = 0 ; i < tempPath.size() ; i++)
2804                            {
2805                                resultPaths.append(tempPath[i]);
2806                            }
2807                        }
2808                    
2809                        // get the instance using getInstance.
2810                        for (Uint32 i = 0 ; i < resultPaths.size() ; i++)
2811                        {
2812                            CIMInstance thisInstance = localGetInstance(context, resultPaths[i],
2813                                                            includeQualifiers,
2814                                                            includeClassOrigin, propertyList);
2815                            if (!thisInstance.isUninitialized())
2816                            {
2817 karl          1.46             handler.deliver(thisInstance);
2818                            }
2819                        }
2820                        handler.processing();
2821                        handler.complete();
2822                        PEG_METHOD_EXIT();
2823 karl          1.1  }
2824                    
2825 karl          1.46 //**************************************************************
2826                    //**************************************************************
2827                    // AssociatorNames Operation Function
2828                    //**************************************************************
2829                    //**************************************************************
2830 karl          1.1  void InteropProvider::associatorNames(
2831                    	const OperationContext & context,
2832                    	const CIMObjectPath & objectName,
2833                    	const CIMName & associationClass,
2834                    	const CIMName & resultClass,
2835                    	const String & role,
2836                    	const String & resultRole,
2837                    	ObjectPathResponseHandler & handler)
2838                    {
2839 tony          1.6      PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
2840                                "InteropProvider::associatorNames()");
2841 karl          1.16 	//throw CIMNotSupportedException("AssociationProvider::associatorNames");
2842 karl          1.46 
2843 karl          1.52     // test for legal namespace for this provider. Exception if not
2844                        _isNamespaceAllowed(objectName);
2845                    
2846 karl          1.46     Tracer::trace(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2847                            "%s associatorNames. objectName= %s , assocClass= %s resultClass= %s role= %s resultRole",
2848                            thisProvider,
2849                            (const char *)objectName.toString().getCString(),
2850                            (const char *)associationClass.getString().getCString(),
2851                            (const char *)resultClass.getString().getCString(),
2852                            (const char *)role.getCString(),
2853                            (const char *)resultRole.getCString());
2854                    
2855                        handler.processing();
2856                        // Get references for this object. Note that this
2857                        // uses the associationClass as resultClass.
2858                        Array<CIMObject> referenceObjects = localReferences(
2859                                context,
2860                                objectName,
2861                                associationClass,
2862                                role,
2863                                false,
2864                                false,
2865                                CIMPropertyList());
2866                     
2867 karl          1.46     // Note that Result Class is not always there.  We need to account for
2868                        // both case where it exists and where it does not exist.
2869                        // enumerate all reference instances of the resultClass (i.e. the association)
2870                        // create path for resultClass
2871                    
2872                        // for each reference object, get all non-target references
2873                        Array<CIMObjectPath> resultPaths;
2874                        for (Uint32 i = 0 ; i < referenceObjects.size() ; i++)
2875                        {
2876                            // get Other references from each association object.
2877                            Array<CIMObjectPath> tempPath = 
2878                                _filterAssocInstanceToTargetPaths(referenceObjects[i],
2879                                objectName, resultClass, resultRole);
2880                    
2881                            for (Uint32 i = 0 ; i < tempPath.size() ; i++)
2882                            {
2883                                resultPaths.append(tempPath[i]);
2884                            }
2885                        }
2886                        handler.deliver(resultPaths);
2887                    
2888 karl          1.46     handler.processing();
2889                        handler.complete();
2890                        PEG_METHOD_EXIT();
2891 karl          1.1  }
2892                    
2893 karl          1.46 
2894                    Array<CIMObject> InteropProvider::localReferences(
2895                    	const OperationContext & context,
2896                    	const CIMObjectPath & objectName,
2897                    	const CIMName & resultClass,
2898                    	const String & role,
2899                    	const Boolean includeQualifiers,
2900                    	const Boolean includeClassOrigin,
2901                    	const CIMPropertyList & propertyList)
2902                    {
2903                    
2904                        PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
2905 karl          1.54             "InteropProvider::localReferences()");
2906 karl          1.46     Tracer::trace(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2907                            "%s references. objectName= %s , resultClass= %s role= %s includeQualifiers= %s, includeClassOrigin= %s, PropertyList= %s",
2908                            thisProvider,
2909                            (const char *)objectName.toString().getCString(),
2910                            (const char *)resultClass.getString().getCString(),
2911                            (const char *)role.getCString(),
2912                            (const char *)_showBool(includeQualifiers).getCString(),
2913                            (const char*) _showBool(includeClassOrigin).getCString(),
2914                            (const char *)_showPropertyList(propertyList).getCString());
2915                    
2916                        Array<CIMInstance> rtnInstances;
2917                    
2918                        // operation namespace needed internally to get class.
2919                        String userName = _validateUserID(context);
2920                    
2921                        // determine if valid class result class
2922                        CIMName targetAssocClassName = resultClass;
2923                    
2924                        targetAssocClass classEnum  = _verifyValidAssocClassInput(targetAssocClassName);
2925                    
2926                        // resultClass should NEVER be NULL in Pegasus.
2927 karl          1.46     assert(!resultClass.isNull());
2928                    
2929                        // enumerate all reference instances of the resultClass (i.e. the association)
2930                        CIMObjectPath classReference(objectName.getHost(), objectName.getNameSpace(),
2931                                                     resultClass);
2932                    
2933                        Array<CIMInstance> assocInstances = 
2934                            localEnumerateInstances(context,
2935                                                    classReference,
2936                                                    true, true, CIMPropertyList());
2937                    
2938                        Array<CIMObject> rtnObjects = _filterReferenceInstances(
2939                                        assocInstances, objectName, resultClass, role);
2940                    
2941                        PEG_METHOD_EXIT();
2942                        return(rtnObjects);
2943                    }
2944 karl          1.1  void InteropProvider::references(
2945                    	const OperationContext & context,
2946                    	const CIMObjectPath & objectName,
2947                    	const CIMName & resultClass,
2948                    	const String & role,
2949                    	const Boolean includeQualifiers,
2950                    	const Boolean includeClassOrigin,
2951                    	const CIMPropertyList & propertyList,
2952                    	ObjectResponseHandler & handler)
2953                    {
2954 tony          1.6      PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
2955                                "InteropProvider::references()");
2956 karl          1.1  
2957 karl          1.52     // test for legal namespace for this provider. Exception if not
2958                        _isNamespaceAllowed(objectName);
2959                    
2960 karl          1.46     Tracer::trace(TRC_CONTROLPROVIDER, Tracer::LEVEL4,
2961                            "%s references. objectName= %s , resultClass= %s role= %s includeQualifiers= %s, includeClassOrigin= %s, PropertyList= %s",
2962                            thisProvider,
2963                            (const char *)objectName.toString().getCString(),
2964                            (const char *)resultClass.getString().getCString(),
2965                            (const char *)role.getCString(),
2966                            (const char *)_showBool(includeQualifiers).getCString(),
2967                            (const char*) _showBool(includeClassOrigin).getCString(),
2968                            (const char *)_showPropertyList(propertyList).getCString());
2969                    
2970                        handler.processing();
2971                        Array<CIMObject> rtnObjects =
2972                                        localReferences(context,
2973                                                        objectName,
2974                                                        resultClass,
2975                                                        role,
2976                                                        includeQualifiers,
2977                                                        includeClassOrigin,
2978                                                        propertyList);
2979                    
2980                        handler.deliver(rtnObjects);
2981 karl          1.46     handler.complete();
2982                        PEG_METHOD_EXIT();
2983 tony          1.6  }
2984 karl          1.1  void InteropProvider::referenceNames(
2985                    	const OperationContext & context,
2986                    	const CIMObjectPath & objectName,
2987                    	const CIMName & resultClass,
2988                    	const String & role,
2989                    	ObjectPathResponseHandler & handler)
2990                    {
2991 tony          1.6      PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
2992                                "InteropProvider::referenceNames()");
2993 karl          1.52 
2994                        // test for legal namespace for this provider. Exception if not
2995                        _isNamespaceAllowed(objectName);
2996                    
2997 tony          1.6      CDEBUG("::referenceNames(): object= " << objectName.toString() << " result Class= " << resultClass.getString());
2998 david.dillard 1.32 
2999 tony          1.6      // operation namespace needed internally to get class.
3000                        String userName = _validateUserID(context);
3001 karl          1.46 
3002 tony          1.6      // begin processing the request
3003                        handler.processing();
3004                    
3005 karl          1.46     Array<CIMObject> rtnObjects =
3006                            localReferences(context,
3007                                            objectName,
3008                                            resultClass,
3009                                            role,
3010                                            true,
3011                                            true,
3012                                            CIMPropertyList());
3013 tony          1.6  
3014 karl          1.46     for (Uint32 i = 0 ; i < rtnObjects.size() ; i++ )
3015 tony          1.6      {
3016 karl          1.46         CIMObjectPath ref = rtnObjects[i].getPath();
3017 tony          1.6          CDEBUG("referenceNames returns: " << ref.toString());
3018                            handler.deliver(ref);
3019 karl          1.11     }
3020 tony          1.6  
3021                        handler.complete();
3022                    
3023                        PEG_METHOD_EXIT();
3024 karl          1.1  }
3025                    
3026                    PEGASUS_NAMESPACE_END
3027                    // END_OF_FILE

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2