(file) Return to SLPProvider.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Providers / slp

   1 martin 1.49 //%LICENSE////////////////////////////////////////////////////////////////
   2 martin 1.50 //
   3 martin 1.49 // Licensed to The Open Group (TOG) under one or more contributor license
   4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
   5             // this work for additional information regarding copyright ownership.
   6             // Each contributor licenses this file to you under the OpenPegasus Open
   7             // Source License; you may not use this file except in compliance with the
   8             // License.
   9 martin 1.50 //
  10 martin 1.49 // Permission is hereby granted, free of charge, to any person obtaining a
  11             // copy of this software and associated documentation files (the "Software"),
  12             // to deal in the Software without restriction, including without limitation
  13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14             // and/or sell copies of the Software, and to permit persons to whom the
  15             // Software is furnished to do so, subject to the following conditions:
  16 martin 1.50 //
  17 martin 1.49 // The above copyright notice and this permission notice shall be included
  18             // in all copies or substantial portions of the Software.
  19 martin 1.50 //
  20 martin 1.49 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21 martin 1.50 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22 martin 1.49 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27 martin 1.50 //
  28 martin 1.49 //////////////////////////////////////////////////////////////////////////
  29 a.dunfey 1.34 
  30 mday     1.1  
  31 marek    1.37 /* Description: this provider manages the SLP advertisements for Pegasus.
  32                  It gets information from other sources within the Pegasus environment
  33                  (primarily the Interop Classes such as CIM_ObjectManager,
  34 kumpf    1.51    CIM_ObjectManagerCommunicationMechanism, CIM_Namespaces, etc. and generates
  35 marek    1.37    the corresponding registrations.
  36 kumpf    1.51    It also maintains a single Class, PG_WBEMSlpTemplate that defines what is
  37 marek    1.37    in the template.
  38                  NOTE: This provider should NEVER be getting information itself but simply
  39                  using other classes in the environment to generate information.
  40 tony     1.5     The intrinistic operations that exist include:
  41                  enumerateInstances
  42                  enumerateInstanceNames
  43                  getInstance
  44 david.dillard 1.15 
  45 tony          1.5     This module provides an SLP service agent that is activited once the first
  46 kumpf         1.51    registration is created.  This service agent provides either the normal
  47 marek         1.37    SA functions or provides the registration to a DA if required.
  48                       That set of functions in in the Pegasus service agent code.
  49                    
  50 kumpf         1.51    To initiate the SA within Pegasus, the system must make a first
  51                       PEG_WBEMSLPTemplate enumerateInstances call to this provider or execute
  52 marek         1.37    the register method.
  53 kumpf         1.51    That initiates the build of the registration information and
  54 marek         1.37    the startup of the SA.
  55 karl          1.11 
  56 kumpf         1.51    Note that this providers sets itself so that it cannot be removed
  57 marek         1.37    once started.
  58 tony          1.5  */
  59                    
  60 kumpf         1.51 /*
  61 venkat.puvvada 1.42     1. Currently SLP readvertisement happens in the following condtions.
  62                             (a) When PG_ProviderProfileCapabilities instance is created or deleted.
  63                             (b) When PG_Provider and PG_ProviderCapabilities instances are
  64                                 created.
  65                             (c) When PG_Provider, PG_ProviderModule and PG_ProviderCapabilities
  66                                 instances are deleted.
  67                             (d) When PG_ProviderModule is disabled or enabled.
  68                         2. SLP advertisements for both EmbeddedSLP and External SLP will happen
  69                            from this provider using slp_agent.
  70                         TODO:
  71 karl           1.7      3. Consider seriously the concept of instance creation where the instance
  72 marek          1.37     is provided and that instance is registered as a profile.
  73                         Not sure today what the level of validation, etc. would be required.
  74 kumpf          1.51     4. We would like separate this function completely from the CIMOM so that
  75 marek          1.37     the registration it could operate as first a separate process and second as
  76                         a separte executable.
  77                         5. Look at getting certain parameters as the default from the class.
  78                         This way we could use the class definition for defaults.
  79 kumpf          1.51     6. Determine if we really want to get enumerated  attribute strings from
  80                         the class or from a string tied to the template.  If we get them from
  81 marek          1.37     the class we are committed to whatever is in the class.
  82 kumpf          1.51     However, in reality, the class and the template could be different
  83 marek          1.37     in some cases.  For the moment we are getting them from the class
  84 karl           1.11     and the template and class enumerations do match.
  85 tony           1.5  */
  86 mday           1.1  
  87                     #include "SLPProvider.h"
  88                     #include <stdio.h>
  89                     #include <stdlib.h>
  90 david.dillard  1.6  #include <iostream>
  91 mday           1.1  
  92 tony           1.5  #include <Pegasus/Common/Constants.h>
  93 venkat.puvvada 1.40 #include <Pegasus/Common/HostLocator.h>
  94 mday           1.1  
  95                     #include <set>
  96                     #include <sys/types.h>
  97                     #include <sys/stat.h>
  98                     #include <time.h>
  99 karl           1.4  
 100 venkat.puvvada 1.44 #include <Pegasus/Common/HashTable.h>
 101 tony           1.5  #include <Pegasus/Common/XmlWriter.h>
 102                     #include <Pegasus/Common/Tracer.h>
 103                     #include <Pegasus/Common/Logger.h> // for Logger
 104 thilo.boehm    1.56 #include <Pegasus/Common/System.h>
 105 marek          1.63 #include <Pegasus/Common/StringConversion.h>
 106                     #include <Pegasus/Config/ConfigManager.h>
 107 tony           1.5  
 108 mday           1.1  PEGASUS_NAMESPACE_BEGIN
 109 karl           1.4  
 110 karl           1.46 PEGASUS_USING_PEGASUS;
 111 tony           1.5  PEGASUS_USING_STD;
 112 karl           1.11 
 113 karl           1.4  //******************************************************************
 114                     //
 115                     // Constants
 116                     //
 117                     //*****************************************************************
 118                     
 119 david.dillard  1.15 const char SlpProvider[] = "SlpProvider";
 120                     const char SlpTemplateClassName[] = "PG_WBEMSLPTemplate";
 121 tony           1.5  
 122 karl           1.9  // This SLP service is named wbem.
 123                     // Internally the serviceName is wbem (in the template) and the serviceID is
 124                     // service:wbem for registration.
 125 david.dillard  1.15 const char serviceIDPrefix[] = "service";
 126                     const char serviceName[] = "wbem";
 127 tony           1.5  
 128 david.dillard  1.15 const char elementNamePropertyName[] = "ElementName";
 129                     const char descriptionPropertyName[] = "Description";
 130                     const char instanceIDPropertyName[] = "InstanceID";
 131 karl           1.4  
 132 marek          1.37 ////////////////////////////////////////////////////////////////////////////////
 133                     // Predefined Values that are part of the SLP template. These values are defined
 134                     // as part of the DMTF SLP template.
 135                     ////////////////////////////////////////////////////////////////////////////////
 136 karl           1.7  
 137 marek          1.37 // This is the current template version.  Should change only if there is a new
 138                     // template specification released.
 139 david.dillard  1.15 const char templateVersion[] = "1.0";
 140 karl           1.7  
 141                     // Fixed test to be inserted in the templateDescription attribute.
 142 david.dillard  1.15 const char templateDescription[] =
 143 marek          1.37     "This template describes the attributes used for advertising "
 144                             "Pegasus CIM Servers.";
 145 karl           1.7  
 146 dave.sudlik    1.24 // Default list of Registered Profiles is empty
 147                     const char defaultRegisteredProfilesList[] = "";
 148 karl           1.7  
 149 marek          1.37 ////////////////////////////////////////////////////////////////////////////////
 150                     //  Names for attributes of SLP template and corresponding PG_WbemSLPtemplate
 151                     //  class.
 152                     ////////////////////////////////////////////////////////////////////////////////
 153 karl           1.7  //
 154                     // Template attribute name constants This set of constants comes from the
 155 marek          1.37 // DMTF wbem template definition. The ...attribute variables are the character
 156                     // constants that define the template attributes.  Note that we build an
 157                     // instance of the wbemslpTemplate class for each created template and that
 158                     // class contains names similar to the attribute names.
 159                     // The attributename is used for that also unless the property name
 160                     // in the class is different.  At this point, there are no differences except
 161                     // that all of the attribute names with dash in the name need
 162                     // a separate property name because dash is not a legal CIMName.
 163                     // We used "_" instead of "-" for the property names.
 164 karl           1.4  
 165 david.dillard  1.15 const char templateTypeProperty[] = "template_type";
 166                     const char templateTypeAttribute[] = "template-type";
 167 karl           1.7  
 168 david.dillard  1.15 const char templateVersionProperty[] = "template_version";
 169                     const char templateVersionAttribute[] = "template-version";
 170 karl           1.7  
 171 david.dillard  1.15 const char templateDescriptionProperty[] = "template_description";
 172                     const char templateDescriptionAttribute[] = "template-description";
 173 karl           1.7  
 174 david.dillard  1.15 const char serviceUrlSyntaxProperty[] = "template_url_syntax";
 175                     const char serviceUrlSyntaxAttribute[] = "template-url-syntax";
 176 karl           1.7  
 177 david.dillard  1.15 const char serviceHiDescriptionProperty[] = "service_hi_description";
 178                     const char serviceHiDescriptionAttribute[] = "service-hi-description";
 179 tony           1.5  
 180 david.dillard  1.15 const char serviceHiNameProperty[] = "service_hi_name";
 181                     const char serviceHiNameAttribute[] = "service-hi-name";
 182 tony           1.5  
 183 david.dillard  1.15 const char serviceIDProperty[] = "service_id";
 184                     const char serviceIDAttribute[] = "service-id";
 185 tony           1.5  
 186 david.dillard  1.15 const char communicationMechanismAttribute[] = "CommunicationMechanism";
 187 karl           1.7  
 188 kumpf          1.51 const char otherCommunicationMechanismDescriptionAttribute[] =
 189 marek          1.37                "OtherCommunicationMechanismDescription";
 190 tony           1.5  
 191 david.dillard  1.15 const char InteropSchemaNamespaceAttribute[] = "InteropSchemaNamespace";
 192 karl           1.7  
 193 david.dillard  1.15 const char protocolVersionAttribute[] = "ProtocolVersion";
 194 karl           1.7  
 195 marek          1.37 const char functionalProfilesSupportedAttribute[] =
 196                                    "FunctionalProfilesSupported";
 197 karl           1.7  
 198 marek          1.37 const char functionalProfileDescriptionsAttribute[] =
 199                                    "FunctionalProfileDescriptions";
 200 karl           1.7  
 201 marek          1.37 const char otherProfileDescriptionAttribute[] =
 202                                    "OtherProfileDescription";
 203 karl           1.7  
 204 kumpf          1.51 const char multipleOperationsSupportedAttribute[] =
 205 marek          1.37                "MultipleOperationsSupported";
 206 karl           1.7  
 207 kumpf          1.51 const char authenticationMechanismsSupportedAttribute[] =
 208 marek          1.37                "AuthenticationMechanismsSupported";
 209 karl           1.7  
 210 kumpf          1.51 const char otherAuthenticationDescriptionsAttribute[] =
 211 marek          1.37                "OtherAuthenticationDescription";
 212 karl           1.7  
 213 kumpf          1.51 const char authenticationMechanismDescriptionsAttribute[] =
 214 marek          1.37                "AuthenticationMechanismDescriptions";
 215 karl           1.7  
 216 david.dillard  1.15 const char namespaceAttribute[] = "Namespace";
 217 tony           1.5  
 218 david.dillard  1.15 const char classinfoAttribute[] =  "Classinfo";
 219 tony           1.5  
 220 marek          1.37 const char registeredProfilesSupportedAttribute[]="RegisteredProfilesSupported";
 221 karl           1.7  
 222 tony           1.5  CIMNamespaceName _interopNamespace = PEGASUS_NAMESPACENAME_INTEROP;
 223                     
 224                     CIMName namePropertyName = "name";
 225                     
 226                     // This is the dynamic entry point into this dynamic module. The name of
 227 jim.wunderlich 1.16 // this provider is "FamilyProvider" which is appened to
 228 tony           1.5  // "PegasusCreateProvider_" to form a symbol name. This function is called
 229                     // by the ProviderModule to load this provider.
 230                     //
 231                     // NOTE: The name of the provider must be correct to be loadable.
 232                     
 233 r.kieninger    1.47 #ifdef PEGASUS_OS_ZOS
 234 dave.sudlik    1.24 const int MAXPATHLEN=2000;
 235 tony           1.5  #endif
 236 karl           1.4  
 237 marek          1.37 extern "C" PEGASUS_EXPORT CIMProvider * PegasusCreateProvider(
 238                         const String & name)
 239 mday           1.1  {
 240 david.dillard  1.15 
 241 dave.sudlik    1.24     if (String::equalNoCase(name, "SLPProvider") ||
 242                             String::equalNoCase(name, "SLPProvider(PROVIDER)"))
 243 tony           1.5      {
 244                             return(new SLPProvider());
 245                         }
 246                         return(0);
 247 mday           1.1  }
 248                     
 249 karl           1.4  //********************************************************************
 250                     //
 251                     //     Support functions
 252                     //
 253                     //********************************************************************
 254 tony           1.5  
 255 karl           1.18 String _showStringArray(const Array<String>& s)
 256                     {
 257                         String o;
 258                         for (Uint32 i = 0 ; i < s.size() ; i++)
 259                         {
 260 dave.sudlik    1.24         if (i > 0)
 261                             {
 262                                 o.append(" ");
 263                             }
 264 karl           1.18         o.append(s[i]);
 265                         }
 266                         return o;
 267                     }
 268 karl           1.11 /** Returns value string from the value qualifier for
 269 david.dillard  1.15     the current value of an enumerated property. This function assumes
 270 karl           1.11     that the qualifiers are in the property in the instance itself. The
 271                         function determines if the qualifiers value and valuemap exist and
 272                         are valid and then uses the property value to find the value
 273                         and get the corresponding valueMap string.
 274                         NOTE: Today this function assumes that the qualifiers are in the
 275                         instance.  In the long term this is incorrect.  We need to get the
 276                         class
 277                         @param myInstance CIMInstance containing the property and with
 278                         the qualifiers in the instance.
 279                         @return String The value from the qualifier.
 280                         @exception throws CIM_ERR_FAILED error if the value and
 281                         value map information is not correct.
 282                     */
 283 dave.sudlik    1.24 String _getValueQualifier(
 284 kumpf          1.51     const CIMConstProperty& instanceProperty,
 285 dave.sudlik    1.24     const CIMClass& thisClass)
 286 karl           1.11 {
 287 karl           1.18     CIMName propertyName = instanceProperty.getName();
 288                         CIMValue propertyValue = instanceProperty.getValue();
 289                     
 290                         Uint32 pos;
 291                         CIMConstProperty classProperty;
 292                     
 293 dave.sudlik    1.24     if ((pos = thisClass.findProperty(propertyName)) != PEG_NOT_FOUND)
 294 karl           1.11     {
 295 karl           1.18         classProperty = thisClass.getProperty(pos);
 296 karl           1.11     }
 297 karl           1.18     else
 298 kumpf          1.51         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
 299 jim.wunderlich 1.22             "SLPProvider Property find error. Class " +
 300 karl           1.18             thisClass.getClassName().getString() + " Property "
 301                                 + propertyName.getString());
 302                     
 303                         // validate the valueMap qualifiers in the Class Property
 304 karl           1.11 
 305                         Uint32 posValueMap;
 306 kumpf          1.45     String errorMessage;
 307 karl           1.11     Array<String> va1;
 308 karl           1.18     Array<String> va2;
 309 karl           1.11 
 310 marek          1.37     if ((posValueMap=classProperty.findQualifier("valueMap")) != PEG_NOT_FOUND)
 311 karl           1.11     {
 312 karl           1.18         CIMConstQualifier qValueMap = classProperty.getQualifier(posValueMap);
 313 karl           1.11 
 314 karl           1.18         if (!qValueMap.isArray() || (qValueMap.getType() != CIMTYPE_STRING))
 315                             {
 316 kumpf          1.45             errorMessage = "Error in valueMap Qualifier";
 317 karl           1.18         }
 318                             else
 319                             {
 320                                 CIMValue q1 = qValueMap.getValue();
 321                                 q1.get(va1);
 322 karl           1.11 
 323 karl           1.18             // validate the value qualifier
 324                                 Uint32 posValue;
 325 marek          1.37             if ((posValue=classProperty.findQualifier("values"))==PEG_NOT_FOUND)
 326 kumpf          1.45                 errorMessage = "No value Qualifier";
 327 karl           1.18             else
 328                                 {
 329                                     CIMConstQualifier qValue = classProperty.getQualifier(posValue);
 330                                     if (!qValue.isArray() || (qValue.getType() != CIMTYPE_STRING))
 331                                     {
 332 kumpf          1.45                     errorMessage = "Invalid value Qualifier";
 333 karl           1.18                 }
 334                                     else
 335                                     {
 336                                         CIMValue q2 = qValue.getValue();
 337                                         q2.get(va2);
 338                     
 339                                         // Test if the array size for the two values is the same.
 340                                         if (va2.size() != va1.size())
 341 kumpf          1.45                         errorMessage = "Size error on value Qualifier";
 342 karl           1.18                 }
 343                                 }
 344                             }
 345 karl           1.11     }
 346 karl           1.18     else
 347 karl           1.11     {
 348 kumpf          1.45         errorMessage = "No valueMap Qualifier";
 349 karl           1.11     }
 350                     
 351 dev.meetei     1.61     if (errorMessage.size() != 0)
 352 karl           1.11     {
 353 marek          1.37         throw PEGASUS_CIM_EXCEPTION(
 354 kumpf          1.51             CIM_ERR_FAILED,
 355 marek          1.37             " Qualifier Value mapping error. "
 356 kumpf          1.51                 + errorMessage + " "
 357 marek          1.37                 + propertyName.getString());
 358 karl           1.11     }
 359 a.dunfey       1.23     // Need to find the values of the property in the ValueMap. If the
 360                         // property is an array, then all of the elements need to be converted
 361                         // and a concatenated string should be returned. If it is not an array
 362                         // then just the one value needs to be found in the ValueMap qualifier
 363                         // and returned.
 364 dave.sudlik    1.24     if (propertyValue.isArray())
 365 a.dunfey       1.23     {
 366 dave.sudlik    1.24         // TBD: Need to handle generic property values
 367                             if (propertyValue.getType() == CIMTYPE_UINT16)
 368                             {
 369                                 Array<Uint16> values;
 370                                 propertyValue.get(values);
 371                                 String convertedValues;
 372                                 bool found = true;
 373                                 for (Uint32 i = 0, size = values.size(); i < size && found; i++)
 374 a.dunfey       1.23             {
 375 dave.sudlik    1.24                 if (i != 0)
 376                                         convertedValues.append(Char16(','));
 377                     
 378                                     String currentValueString = CIMValue(values[i]).toString();
 379                                     found = false;
 380                                     for (Uint32 j = 0, qSize = va1.size(); j < qSize && !found; j++)
 381                                     {
 382                                         if (currentValueString == va1[j])
 383                                         {
 384                                             convertedValues.append(va2[j]);
 385                                             found = true;
 386                                         }
 387                                     }
 388 a.dunfey       1.23             }
 389 karl           1.11 
 390 dave.sudlik    1.24             if (found)
 391                                 {
 392                                     return convertedValues;
 393                                 }
 394 karl           1.11         }
 395 a.dunfey       1.23     }
 396                         else
 397                         {
 398 dave.sudlik    1.24         String targetValueString = propertyValue.toString();
 399 a.dunfey       1.23 
 400 dave.sudlik    1.24         // find this valueMap and get corresponding value
 401                             for (Uint32 i = 0 ; i < va1.size() ; i++)
 402                             {
 403                                 if (targetValueString == va1[i])
 404                                 {
 405                                     // Return corresponding value in value qualifier
 406                                     return(va2[i]);
 407                                 }
 408                             }
 409 karl           1.11     }
 410 dave.sudlik    1.24 
 411 a.dunfey       1.23     throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
 412 kumpf          1.51         " Qualifier Value mapping error. Invalid property value "
 413 dave.sudlik    1.24         + propertyName.getString());
 414 karl           1.11 }
 415                     
 416 tony           1.5  /** convert an array of strings to a CSV string.
 417                         @param s Array<String> with input strings
 418                         @return String with CSV String from array
 419                     */
 420                     String _arrayToString(const Array<String>& s)
 421                     {
 422 david.dillard  1.15     String output;
 423 karl           1.11     for (Uint32 i = 0 ; i < s.size() ; i++)
 424 dave.sudlik    1.24     {
 425                             if (i > 0)
 426                                 output.append(",");
 427                             output.append(s[i]);
 428                         }
 429                         return(output);
 430 tony           1.5  }
 431 karl           1.7  
 432 karl           1.17 String _arrayToString(const Array<Uint16>& s)
 433                     {
 434                         String output;
 435                         for (Uint32 i = 0 ; i < s.size() ; i++)
 436 dave.sudlik    1.24     {
 437                             if (i > 0)
 438                                 output.append(",");
 439                             char buffer[128];
 440                             sprintf(buffer,"%i", s[i]);
 441                             output.append(String(buffer));
 442                         }
 443                         return(output);
 444 karl           1.17 }
 445                     
 446 tony           1.5  /** append the input string and if output not empty a comma separator
 447                         param s String to which we will append s1.
 448                         param s1 String to be appended
 449                     */
 450                     void _appendCSV(String& s, const String& s1)
 451 mday           1.1  {
 452 tony           1.5      if (s.size() != 0)
 453                             s.append(",");
 454                         s.append(s1);
 455                     }
 456                     
 457                     /** get one string property from an instance.
 458                         @param instance CIMInstance from which we get property value
 459                         @param propertyName String name of the property containing the value
 460 marek          1.37     @param default String optional parameter that is substituted if the property
 461                                does not exist, is Null, or is not a string type.
 462                                The substitute is String::EMPTY
 463 tony           1.5      @return String value found or defaultValue.
 464                     */
 465 dave.sudlik    1.24 String _getPropertyValueString(
 466 kumpf          1.51     const CIMInstance& instance,
 467 dave.sudlik    1.24     const CIMName& propertyName,
 468                         const String& defaultValue = String::EMPTY)
 469 tony           1.5  {
 470                         String output;
 471                         Uint32 pos;
 472 marek          1.58 
 473                         PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
 474                             "_getPropertyValue String for name= %s default= %s",
 475                             (const char*) propertyName.getString().getCString(),
 476                             (const char*) defaultValue.getCString()));
 477                     
 478 tony           1.5      if ((pos = instance.findProperty(propertyName)) != PEG_NOT_FOUND)
 479                         {
 480                             CIMConstProperty p1 = instance.getProperty(pos);
 481                             if (p1.getType() == CIMTYPE_STRING)
 482                             {
 483                                 CIMValue v1  = p1.getValue();
 484                     
 485                                 if (!v1.isNull())
 486                                     v1.get(output);
 487                                 else
 488                                     output = defaultValue;
 489                             }
 490                             else
 491                                 output = defaultValue;
 492                         }
 493                         else
 494                             output = defaultValue;
 495 marek          1.58     return output;
 496 tony           1.5  }
 497                     
 498 karl           1.17 
 499 dave.sudlik    1.24 Uint16 _getPropertyValueUint16(
 500 kumpf          1.51     const CIMInstance& instance,
 501 dave.sudlik    1.24     const CIMName& propertyName,
 502                         const Uint16& defaultValue = 0)
 503 karl           1.17 {
 504                         Uint16 output;
 505                         Uint32 pos;
 506 marek          1.58     
 507                         PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
 508                             "_getPropertyValue Uint16 for name= %s default= %uh",
 509                             (const char*) propertyName.getString().getCString(),
 510                             defaultValue));
 511                     
 512 karl           1.17     if ((pos = instance.findProperty(propertyName)) != PEG_NOT_FOUND)
 513                         {
 514                             CIMConstProperty p1 = instance.getProperty(pos);
 515                             if (p1.getType() == CIMTYPE_UINT16)
 516                             {
 517                                 CIMValue v1  = p1.getValue();
 518                     
 519                                 if (!v1.isNull())
 520                                     v1.get(output);
 521                                 else
 522                                     output = defaultValue;
 523                             }
 524                             else
 525                                 output = defaultValue;
 526                         }
 527                         else
 528                             output = defaultValue;
 529                         return(output);
 530                     }
 531 kumpf          1.41 
 532                     /**
 533 kumpf          1.51     Set the value of a property defined by property name in
 534 marek          1.37     the instance provided.
 535 tony           1.5      Sets a String into the value field unless the property name cannot be found.
 536                         If the property cannot be found, it simply returns.
 537                         ATTN: This function does not pass an error back if property not found.
 538                         @param instance CIMInstance in which to set property value
 539                         @param propertyName CIMName of property in which value will be set.
 540                         @param value String value to set into property
 541                     */
 542 dave.sudlik    1.24 void _setPropertyValue(
 543 kumpf          1.51     CIMInstance& instance,
 544                         const CIMName& propertyName,
 545 dave.sudlik    1.24     const String& value)
 546 tony           1.5  {
 547                         Uint32 pos;
 548                         if ((pos = instance.findProperty(propertyName)) != PEG_NOT_FOUND)
 549                             instance.getProperty(pos).setValue(CIMValue(value));
 550                     }
 551                     
 552                     //*******************************************************************
 553                     //
 554                     // SLPProvider Protected and private methods
 555                     //
 556                     //*******************************************************************
 557                     
 558                     /** builds one instance of the class named className. Gets Class definition and
 559                         fills in the correct properties from the class.  This requires a repository
 560                         getclass request for each instance built. The skeleton is built by
 561                         creating the instance and copying qualifiers and properties from
 562                         the class. Finally the instance is cloned to separate it from the
 563                         original objects.
 564                         NOTE: This is very inefficient for anything larger than a few instances.
 565                         We should separate the get from the createSkeleton.
 566                         @param className CIMName of the class for which the instance is to be built
 567 tony           1.5      @return CIMInstance of this class with properties complete.
 568                         @exception passes on any exceptions received from the repository request.
 569                     */
 570                     CIMInstance SLPProvider::_buildInstanceSkeleton(const CIMName& className)
 571                     {
 572                         CIMClass myClass;
 573                     
 574                         CIMInstance skeleton(className);
 575 dave.sudlik    1.24     myClass = _cimomHandle.getClass(OperationContext(), _nameSpace,
 576                             className, false, true, true,CIMPropertyList());
 577 david.dillard  1.15 
 578 tony           1.5      // copy the qualifiers
 579                         for (Uint32 i = 0 ; i < myClass.getQualifierCount() ; i++)
 580                             skeleton.addQualifier(myClass.getQualifier(i));
 581                     
 582                         // copy the properties
 583                         for (Uint32 i = 0 ; i < myClass.getPropertyCount() ; i++)
 584                             skeleton.addProperty(myClass.getProperty(i));
 585                     
 586 marek          1.58     return skeleton.clone();
 587 tony           1.5  }
 588 karl           1.11 /* Remove the instances created as part of the registration and unregister.
 589 tony           1.5    This is completely unregisters this this provider and disconnects it
 590                       from the slp agent.
 591                       ATTN: We could also change status so it could be unloaded.
 592                     */
 593                     void SLPProvider::deregisterSLP()
 594                     {
 595                         // clear existing instances
 596                         _instanceNames.clear();
 597                         _instances.clear();
 598 david.dillard  1.15 
 599 tony           1.5      // unregister from the agent
 600                         slp_agent.unregister();
 601                         initFlag = false;
 602 david.dillard  1.15 
 603 tony           1.5  }
 604 karl           1.7  
 605 dev.meetei     1.61 /*
 606                      * This checks whether a registerred profile has to be advertised
 607                      * through SLP or not
 608                     */
 609                     Boolean SLPProvider::_checkProfileToAdvertise(
 610                         const CIMInstance &cimInstance,
 611                         const Uint32 &index_AT)
 612                     {
 613                         CIMConstProperty AT_Property = 
 614                             cimInstance.getProperty(index_AT);
 615                     
 616                         CIMValue AT_value = AT_Property.getValue ();
 617                         Array<Uint16> valAdvTypes;
 618                         if ((AT_value.isArray()) && (!AT_value.isNull()))
 619                         {
 620                             AT_value.get(valAdvTypes);
 621                         }
 622                         for(Uint16 i = 0, n = valAdvTypes.size(); i < n; ++i)
 623                         {
 624                             //SLP AdvertiseTypes has value 3 
 625                             if( 3 == valAdvTypes[i])
 626 dev.meetei     1.61         {
 627                                 return true;
 628                             }
 629                         }
 630                         return false;
 631                     }
 632                     
 633                     
 634                     
 635 karl           1.11 /** get the list of registered profiles for the SLP template.
 636 tony           1.5      Until we start using CIM 28, there are no template classes
 637                         and no templates.  We are doing a temporary hack here of
 638                         (1) getting from an environment variable or (2) if this does
 639                         not exist, simply getting from a fixed field in this provider
 640 david.dillard  1.15 
 641 tony           1.5      @return String containing the list of registered profiles.
 642 david.dillard  1.15 
 643 tony           1.5      ATTN: KS 8 Feb 2004.  Replace this with function that gets
 644                         the registered profiles from the correct classes when those
 645                         classes begin to exist in the environment.
 646                     */
 647 thilo.boehm    1.56 String SLPProvider::getRegisteredProfileList(const OperationContext & context)
 648 tony           1.5  {
 649 kumpf          1.36     const CIMName CLASSNAME = CIMName("CIM_RegisteredProfile");
 650                         String regitem;
 651                         String reglist;
 652 jim.wunderlich 1.20 
 653 kumpf          1.51     typedef HashTable<String, String,
 654 venkat.puvvada 1.44         EqualFunc<String>, HashFunc<String> > RegProfileIdTable;
 655                         RegProfileIdTable regProfileIdTable;
 656                     
 657 dave.sudlik    1.24     Array<CIMInstance>  cimInstances;
 658 a.dunfey       1.34     CIMName registeredProfileClassName("CIM_RegisteredProfile");
 659 jim.wunderlich 1.19     CIMClass RO_Class;
 660                     
 661 venkat.puvvada 1.44     const CIMName subProfileRequiresProfileClassName(
 662                             "CIM_SubProfileRequiresProfile");
 663                         const CIMName referencedProfileClassName(
 664                             "CIM_ReferencedProfile");
 665                         const CIMName propRegName("RegisteredName");
 666                         const CIMName propRegOrg("RegisteredOrganization");
 667                         const String propDependent("Dependent");
 668                         const String propAntecedent("Antecedent");
 669                         const String strColon(":");
 670                         const String strDMTF("DMTF");
 671 jim.wunderlich 1.20 
 672 marek          1.37 // No reason to use deepInheritance for now as we do not support sub-classes
 673 marek          1.29     Boolean         deepInheritance = false;
 674 cheng.sp       1.53     Boolean         localOnly = false;
 675 a.dunfey       1.27     Boolean         includeQualifiers = true;
 676 dave.sudlik    1.24     Boolean         includeClassOrigin = false;
 677                     
 678 jim.wunderlich 1.19     try
 679 dave.sudlik    1.24     {
 680 marek          1.37         // include the qualifiers, required for ValueMap mapping
 681 dave.sudlik    1.24         RO_Class = _cimomHandle.getClass(
 682 thilo.boehm    1.56             context,
 683 kumpf          1.51             PEGASUS_NAMESPACENAME_INTEROP,
 684                                 CLASSNAME,
 685                                 localOnly,
 686 marek          1.37             includeQualifiers,
 687 dave.sudlik    1.24             includeClassOrigin,
 688                                 CIMPropertyList());
 689                         }
 690 jim.wunderlich 1.19 
 691 karl           1.26     catch (Exception &)
 692 dave.sudlik    1.24     {
 693 jim.wunderlich 1.20         Logger::put(Logger::ERROR_LOG, SlpProvider, Logger::SEVERE,
 694 jim.wunderlich 1.21             "getRegisteredProfiles: get class error");
 695 jim.wunderlich 1.20 
 696 marek          1.58         return defaultRegisteredProfilesList;
 697 dave.sudlik    1.24     }
 698 jim.wunderlich 1.19 
 699                     
 700                         try
 701                         {
 702                             //
 703                             // Enumerate Instances.
 704                             //
 705 dave.sudlik    1.24         cimInstances = _cimomHandle.enumerateInstances(
 706 thilo.boehm    1.56             context,
 707 kumpf          1.51             PEGASUS_NAMESPACENAME_INTEROP,
 708                                 CLASSNAME,
 709 dave.sudlik    1.24             deepInheritance,
 710 kumpf          1.51             localOnly,
 711 marek          1.29             !includeQualifiers,
 712 dave.sudlik    1.24             includeClassOrigin,
 713                                 CIMPropertyList());
 714 jim.wunderlich 1.19 
 715                     
 716                         }
 717 kumpf          1.32     catch (Exception&)
 718 jim.wunderlich 1.19     {
 719 jim.wunderlich 1.20         Logger::put(Logger::ERROR_LOG, SlpProvider, Logger::SEVERE,
 720 marek          1.58             "getRegisteredProfiles: enum instances error");
 721 jim.wunderlich 1.20 
 722 kumpf          1.51         return(defaultRegisteredProfilesList);
 723 jim.wunderlich 1.19     }
 724                     
 725 marek          1.58     PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
 726                             "SLPProvider::getRegisteredProfiles: Total Number of Instances: %u",
 727                             cimInstances.size()));
 728 jim.wunderlich 1.19 
 729 dev.meetei     1.61     try
 730 dave.sudlik    1.24     {
 731 dev.meetei     1.61         Uint32 j = 0;
 732                             const CIMName propAdvertTypes("AdvertiseTypes");
 733                             for (Uint32 i = 0, n = cimInstances.size(); i < n; i++)
 734                             {
 735 jim.wunderlich 1.20 
 736 dev.meetei     1.61             // same can be done by not using deepInheritance 
 737                                 // on the enumInstances call  thus I commented it out here
 738                                 //    if (cimInstances[i].getClassName() != "CIM_RegisteredProfile")
 739                                 //        continue;
 740                                 Uint32 index_AT=cimInstances[i].findProperty(propAdvertTypes);
 741                                 Uint32 index_RO=cimInstances[i].findProperty(propRegOrg);
 742                                 Uint32 index_RN=cimInstances[i].findProperty(propRegName);
 743                                 if (index_RO == PEG_NOT_FOUND || index_RN == PEG_NOT_FOUND || 
 744                                         index_AT == PEG_NOT_FOUND)
 745                                 {
 746                                     continue;
 747                                 }
 748                     
 749                                 //Check if the advertiseTypes is SLP,
 750                                 if(!_checkProfileToAdvertise(cimInstances[i], index_AT))
 751                                 {
 752                                     continue;
 753                                 }
 754                                 
 755                                 //String isSLPAd = _getValueQualifier(AT_Property, RO_Class);
 756                                 //if(!String::equalNoCase(isSLPAd, "SLP"))
 757 dev.meetei     1.61             //{
 758                                  //   continue;
 759                                 //}
 760                     
 761                                 CIMConstProperty RO_Property = 
 762                                     cimInstances[i].getProperty(index_RO);
 763                                 String RegOrg = _getValueQualifier(RO_Property, RO_Class);
 764                                 PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
 765                                             "Value of RegOrg=%s",
 766                                             (const char*) RegOrg.getCString()));
 767 marek          1.58 
 768 dev.meetei     1.61             if (RegOrg.size() == 0)
 769                                 {
 770                                     RegOrg = "Unknown";
 771                                 }
 772                                 else
 773 marek          1.29             {
 774 dev.meetei     1.61                 if (String::equalNoCase(RegOrg,"Other"))
 775 marek          1.29                 {
 776 dev.meetei     1.61                     //use the OtherRegisteredOrganization value if available
 777                                         Uint32 index_ORO = cimInstances[i].findProperty(
 778                                                 "OtherRegisteredOrganization");
 779                                         if (index_ORO != PEG_NOT_FOUND)
 780 marek          1.29                     {
 781 dev.meetei     1.61                         String OthRegOrg;
 782                                             // lets get the property
 783                                             CIMConstProperty ORO_Property =
 784                                                 cimInstances[i].getProperty(index_ORO);
 785                                             // see if there is a String value on it and if so,
 786                                             // use that as organisation
 787                                             CIMValue ORO_value = ORO_Property.getValue ();
 788                                             if ((ORO_value.getType () == CIMTYPE_STRING) &&
 789                                                     (!ORO_value.isNull ()))
 790 marek          1.29                         {
 791 dev.meetei     1.61                             ORO_value.get(OthRegOrg);
 792                                                 if (OthRegOrg != String::EMPTY)
 793                                                 {
 794                                                     RegOrg.assign(OthRegOrg);
 795                                                 }
 796 marek          1.29                         }
 797 kumpf          1.51                     }
 798 marek          1.29                 }
 799                                 }
 800 dev.meetei     1.61             CIMConstProperty RN_Property = 
 801                                     cimInstances[i].getProperty(index_RN);
 802                                 String RegName;
 803                                 CIMValue RN_value = RN_Property.getValue ();
 804                                 if ((RN_value.getType () == CIMTYPE_STRING) && (!RN_value.isNull()))
 805                                 {
 806                                     RN_value.get(RegName);
 807                                 }
 808                     
 809                                 // Check whether the profile is top-level.
 810                                 Array<CIMObject> subProfiles;
 811                                 CIMObjectPath objectPath = cimInstances[i].getPath();
 812                                 CIMName className = objectPath.getClassName();
 813 venkat.puvvada 1.52 
 814 dev.meetei     1.61             // Check for DMTF profiles
 815                                 if (RegOrg == strDMTF)
 816 venkat.puvvada 1.52             {
 817 dev.meetei     1.61                 // Check if this profile is sub-profile.
 818                                     Array<CIMObject> profiles = _cimomHandle.associators(
 819                                             context,
 820                                             PEGASUS_NAMESPACENAME_INTEROP,
 821                                             objectPath,
 822                                             referencedProfileClassName,
 823                                             CIMName(),
 824                                             propAntecedent,
 825                                             String::EMPTY,
 826                                             includeQualifiers,
 827                                             includeClassOrigin,
 828                                             CIMPropertyList());
 829                     
 830                                     if (profiles.size())
 831                                     {
 832                                         continue;
 833                                     }
 834                     
 835                                     subProfiles = _cimomHandle.associators(
 836                                             context,
 837                                             PEGASUS_NAMESPACENAME_INTEROP,
 838 dev.meetei     1.61                         objectPath,
 839                                             referencedProfileClassName,
 840                                             CIMName(),
 841                                             propDependent,
 842                                             String::EMPTY,
 843                                             includeQualifiers,
 844                                             includeClassOrigin,
 845                                             CIMPropertyList());
 846 venkat.puvvada 1.52             }
 847 dev.meetei     1.61             else
 848                                 {
 849                                     // check for SNIA or Other profiles
 850                                     // Check if this profile is sub-profile.
 851                                     Array<CIMObject> profiles = _cimomHandle.associators(
 852                                             context,
 853                                             PEGASUS_NAMESPACENAME_INTEROP,
 854                                             objectPath,
 855                                             subProfileRequiresProfileClassName,
 856                                             CIMName(),
 857                                             propDependent,
 858                                             String::EMPTY,
 859                                             includeQualifiers,
 860                                             includeClassOrigin,
 861                                             CIMPropertyList());
 862                     
 863                                     if (profiles.size())
 864                                     {
 865                                         continue;
 866                                     }
 867 venkat.puvvada 1.52 
 868 dev.meetei     1.61                 subProfiles = _cimomHandle.associators(
 869                                             context,
 870                                             PEGASUS_NAMESPACENAME_INTEROP,
 871                                             objectPath,
 872                                             subProfileRequiresProfileClassName,
 873                                             CIMName(),
 874                                             propAntecedent,
 875                                             String::EMPTY,
 876                                             includeQualifiers,
 877                                             includeClassOrigin,
 878                                             CIMPropertyList());
 879                                 }
 880 venkat.puvvada 1.52 
 881 dev.meetei     1.61             PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
 882                                             "Value of RegName=%s ; Value of regitem=%s",
 883                                             (const char*) RegName.getCString(),
 884                                             (const char*) regitem.getCString()));
 885                     
 886                                 regitem.assign(RegOrg);
 887                                 regitem.append(strColon);
 888                                 regitem.append(RegName);
 889                                 regProfileIdTable.insert(regitem, regitem);
 890                                 for (Uint32 k = 0, n = subProfiles.size(); k < n; k++)
 891 venkat.puvvada 1.44             {
 892 dev.meetei     1.61                 Uint32 pos = subProfiles[k].findProperty(propRegName);
 893                                     String pName =
 894                                         subProfiles[k].getProperty(pos).getValue().toString();
 895                                     String subRegItem = regitem;
 896                                     subRegItem.append(strColon);
 897                                     subRegItem.append(pName);
 898                                     regProfileIdTable.insert(subRegItem, subRegItem);
 899 venkat.puvvada 1.44             }
 900 dev.meetei     1.61             j++;
 901 venkat.puvvada 1.44         }
 902 dev.meetei     1.61         if (j > 0)
 903                             {
 904                                 const String strComma(",");
 905                                 for (RegProfileIdTable::Iterator i = regProfileIdTable.start(); i;)
 906 venkat.puvvada 1.44             {
 907 dev.meetei     1.61                 reglist.append(i.value());
 908                                     i++;
 909                                     if (i)
 910                                     {
 911                                         reglist.append(strComma);
 912                                     }
 913 venkat.puvvada 1.44             }
 914                             }
 915 dev.meetei     1.61         PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
 916                                         "Value of reglist=%s",
 917                                         (const char*) reglist.getCString()));
 918                     
 919                         } catch(Exception &exc)
 920                         {
 921                             PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL2,
 922                                         "Exception caught in enumInst processing:%s",
 923                                         (const char*) exc.getMessage().getCString()));
 924 dave.sudlik    1.24     }
 925 marek          1.58     return reglist;
 926 karl           1.4  }
 927                     
 928                     /** get the list of valid namespaces and supporting info.
 929 tony           1.5      Function builds an array of namespace names and a parallel
 930                         array of classinfo information
 931                         @param nameSpace in which to find CIM_namespace class
 932                         @param, classInfo, anArray of strings for classinfo on return
 933                         @return array of namespaces names
 934                         ATTN: KS 5 Feb 2004.Today we get complete namespace list.  We need to modify
 935                         to use the CIM_ObjectManager to CIM_Namespace association to get
 936                         the information.  KS will do this when association added to interop
 937 karl           1.4  */
 938 marek          1.37 String SLPProvider::getNameSpaceInfo(
 939                         const CIMNamespaceName& nameSpace,
 940 thilo.boehm    1.56     String& classInfo,
 941                         const OperationContext & context)
 942 karl           1.4  {
 943 tony           1.5      String names;
 944 karl           1.4      Array<CIMInstance> CIMNamespaceInstances;
 945                         try
 946                         {
 947 kumpf          1.51         // ATTN: KS In the future get only the fields we want based on property
 948 marek          1.37         //       list.
 949 tony           1.5          CIMNamespaceInstances = _cimomHandle.enumerateInstances(
 950 thilo.boehm    1.56             context,
 951 dave.sudlik    1.24             PEGASUS_NAMESPACENAME_INTEROP,
 952 a.dunfey       1.34             PEGASUS_CLASSNAME_PGNAMESPACE,
 953 dave.sudlik    1.24             true, true, true, true,
 954                                 CIMPropertyList());
 955 karl           1.4      }
 956 marek          1.58     catch (Exception& exc)
 957 karl           1.4      {
 958 marek          1.58         PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL2,
 959                                 "Error on Namespaces acquisition:%s",
 960                                 (const char*) exc.getMessage().getCString()));
 961                             return names;
 962                         }
 963                         PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
 964                             "Namespaces found. Count=%u",
 965                             CIMNamespaceInstances.size()));
 966 karl           1.7  
 967 karl           1.25     // Determine if there are any classInfo attributes available.
 968                         Boolean classInfoFound = false;
 969                         for (Uint32 i = 0 ; i < CIMNamespaceInstances.size() ; i++)
 970                         {
 971 marek          1.37         if (_getPropertyValueUint16(
 972                                     CIMNamespaceInstances[i],
 973                                     CIMName(classinfoAttribute)) != 0)
 974 karl           1.25         {
 975                                 classInfoFound = true;
 976                                 break;
 977                             }
 978                         }
 979 tony           1.5      // Extract the namespace names and class info from the objects.
 980 karl           1.4      for (Uint32 i = 0 ; i < CIMNamespaceInstances.size() ; i++)
 981                         {
 982 karl           1.26         String temp = _getPropertyValueString(CIMNamespaceInstances[i],
 983                                                                   CIMName(namePropertyName), "");
 984 tony           1.5          if (temp != String::EMPTY)
 985 karl           1.4          {
 986 dave.sudlik    1.24             _appendCSV(names, temp);
 987 marek          1.37             // Append to ClassInfo only if at least one valid classinfo property
 988                                 // provided
 989 karl           1.25             if (classInfoFound)
 990                                 {
 991 kumpf          1.51                 // Append the Classinfo property value into the string for the
 992 marek          1.37                 // attribute.
 993 karl           1.26                 char buffer[32];
 994 marek          1.37                 sprintf(
 995                                         buffer,
 996 kumpf          1.43                     "%hu",
 997 marek          1.37                     _getPropertyValueUint16(
 998                                             CIMNamespaceInstances[i],
 999 kumpf          1.51                         CIMName(classinfoAttribute)));
1000 karl           1.26                 _appendCSV(classInfo, buffer);
1001 karl           1.25             }
1002 tony           1.5          }
1003                             else
1004 marek          1.37             Logger::put(
1005                                     Logger::ERROR_LOG,
1006                                     SlpProvider,
1007                                     Logger::WARNING,
1008                                     "SLP Registration bypassed Namespace attribute: $0 property "
1009                                         "error in CIM_Namespace class.");
1010 karl           1.4  
1011                         }
1012 marek          1.58     return names;
1013 karl           1.4  }
1014                     
1015 marek          1.37 /** populate a single field in the template and the corresponding template
1016                         instance.
1017                         This function assumes that both the instance object and the template object
1018                         have been created already. There is no error test for this at this point.
1019                         It adds a property to the instance with the defined fieldname and value and
1020                         also adds a line to the slp template with the field name and value.
1021                         NOTE: There are two fieldName parameters because there may be different
1022                         names for these fields in the instance and registration (this is due to the
1023                         fact that the - used in slp templates is illegal in CIMNames.
1024                         This uses the SLPProvider objects for the reference to the current instance
1025                         and the SLP template string being built.
1026 kumpf          1.51     @param slpTemplateInstance string for registration information.
1027 marek          1.37     Each call adds the defined attribute to this string.
1028 kumpf          1.51     @param instance CIMInstance being created. This is an instance of
1029                         WBEMSlpTemplate. Each call adds the defined property value to the instance
1030 marek          1.37     in the property defined by instanceFieldName
1031 kumpf          1.51     @param regfieldName String defining the name of the field to populate
1032 marek          1.37     in the registration
1033 karl           1.4      @param value String defining the value with which to populate the field
1034 marek          1.37     @param insstanceFieldName (Optional) String defining the name of the field
1035                         to populate in the instance.
1036 karl           1.4  */
1037 karl           1.7  void _addSeparator(String& s)
1038                     {
1039                         // if not first entry, set newline
1040                         if (s != String::EMPTY)
1041 dave.sudlik    1.24         // bug 1737  EOL between attributes confuses some UA
1042 karl           1.8          // s(",\n");
1043                             s.append(",");
1044 karl           1.7  }
1045 karl           1.4  
1046 dave.sudlik    1.24 void SLPProvider::populateTemplateField(
1047                         CIMInstance& instance,
1048                         const String& attributeFieldName,
1049                         const String& value,
1050                         const String& instancePropertyName)
1051 karl           1.4  {
1052 karl           1.7      String localInstancePropertyName = ((instancePropertyName == String::EMPTY)?
1053 dave.sudlik    1.24         attributeFieldName : instancePropertyName);
1054 marek          1.58 
1055                         PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
1056                             "input Property name=%s, Populate TemplateField name=%s, %s. Value=%s",
1057                             (const char*) instancePropertyName.getCString(),
1058                             (const char*) localInstancePropertyName.getCString(),
1059                             (const char*) attributeFieldName.getCString(),
1060                             (const char*) value.getCString()));
1061 karl           1.7  
1062                         // Add the property to the instance.
1063 marek          1.37     instance.addProperty(
1064                             CIMProperty(
1065                                 CIMName(localInstancePropertyName),
1066                                 value));
1067 karl           1.4  
1068 tony           1.5      // if not first entry, set newline
1069 karl           1.7  
1070                         _addSeparator(_currentSLPTemplateString);
1071                         //if (_currentSLPTemplateString != String::EMPTY)
1072                         //// bug 1737  EOL confuses some UA _currentSLPTemplateStringappend(",\n");
1073                         //    _currentSLPTemplateString.append(",\n");
1074 tony           1.5  
1075                         // Add entry as (name=value)
1076 marek          1.37     _currentSLPTemplateString.append("("+attributeFieldName+"="+value+")");
1077 dave.sudlik    1.24 }
1078 karl           1.7  
1079                     /** populate a template filed using a string array as input rather than
1080                         a single String.  The parameters are the same as the other overload
1081                         except that this defines an array of strings rather than a single string.
1082                     */
1083 dave.sudlik    1.24 void SLPProvider::populateTemplateField(
1084                         CIMInstance& instance,
1085                         const String& attributeFieldName,
1086                         const Array<String>& value,
1087                         const String& instancePropertyName)
1088 karl           1.7  {
1089                         String localInstancePropertyName = ((instancePropertyName == String::EMPTY)?
1090 dave.sudlik    1.24         attributeFieldName : instancePropertyName);
1091 karl           1.7  
1092                         String accumulatedValue = _arrayToString(value);
1093                     
1094 marek          1.58     PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
1095                             "Populate TemplateField name=%s, %s. Value=%s",
1096                             (const char*) localInstancePropertyName.getCString(),
1097                             (const char*) attributeFieldName.getCString(),
1098                             (const char*) accumulatedValue.getCString()));
1099 karl           1.7  
1100                         // Add the property to the instance.
1101 marek          1.37     instance.addProperty(
1102                             CIMProperty(
1103                                 CIMName(instancePropertyName),
1104                                 accumulatedValue));
1105 tony           1.5  
1106 karl           1.7      // if not first entry, set newline
1107                         _addSeparator(_currentSLPTemplateString);
1108                     
1109                         // Add entry as (name=value)
1110 kumpf          1.51     _currentSLPTemplateString.append("(" +
1111                                                              attributeFieldName + "=" +
1112 marek          1.37                                              accumulatedValue + ")");
1113 dave.sudlik    1.24 }
1114 karl           1.4  
1115 tony           1.5  /** populates the SLP template and its corresponding instance. Creates one
1116                         instance of slp registration data, tests the registration and registers
1117 marek          1.37     the information. The corresponding instance of PG_WBEMSLPTemplate represents
1118 tony           1.5      the data in the registration. It uses largely information from the
1119                         CIM_ObjectManager and its corresponding communication classes plus
1120                         information for namespaces from CIM_Namespace.
1121 karl           1.18     @param protocol String defining http or https. This will become the
1122                         namespaceComponent part of the address in the template.
1123                         @IPAddress - IP address we are to register. This should be a complete
1124                         address minus the namespaceType component
1125 tony           1.5      @param instance_ObgMgr CIMInstance of CIM_ObjectManager
1126                         @param instance-ObjMgrComm CIMInstance of Interop communication class.
1127 karl           1.18     @return - Boolean - True if successful
1128 karl           1.4  */
1129 dave.sudlik    1.24 Boolean SLPProvider::populateRegistrationData(
1130                         const String &protocol,
1131                         const String& IPAddress,
1132                         const CIMInstance& instance_ObjMgr,
1133                         const CIMInstance& instance_ObjMgrComm,
1134 venkat.puvvada 1.55     const CIMClass& commMechClass,
1135 thilo.boehm    1.56     const String &registeredProfiles,
1136                         const OperationContext & context )
1137 karl           1.4  {
1138 tony           1.5      // Clear the template instance
1139 karl           1.7      _currentSLPTemplateString.clear();
1140                     
1141 dave.sudlik    1.24     CIMInstance templateInstance(SlpTemplateClassName);
1142 tony           1.5  
1143                         // template-url-syntax=string
1144                         // #The template-url-syntax MUST be the WBEM URI Mapping of
1145 david.dillard  1.15     // #the location of one service access point offered by the WBEM Server
1146                         // #over TCP transport. This attribute must provide sufficient addressing
1147                         // #information so that the WBEM Server can be addressed directly using
1148                         // #the URL.  The WBEM URI Mapping is defined in the WBEM URI Mapping
1149 tony           1.5      // #Specification 1.0.0 (DSP0207).
1150                         // # Example: (template-url-syntax=https://localhost:5989)
1151                     
1152 karl           1.17     String serviceUrlSyntaxValue = protocol + "://" + IPAddress;
1153                     
1154 kumpf          1.51     // Fillout the serviceIDAttribute from the
1155 marek          1.37     // object manager instance name property.
1156 karl           1.17     // This is a key field so must have a value.
1157                     
1158 marek          1.37     String strUUID = _getPropertyValueString(
1159                                              instance_ObjMgr,
1160                                              namePropertyName,
1161                                              "DefaultEmptyUUID");
1162                     
1163                         populateTemplateField(
1164                             templateInstance,
1165                             serviceUrlSyntaxAttribute,
1166                             serviceUrlSyntaxValue,
1167 karl           1.7          serviceUrlSyntaxProperty);
1168 tony           1.5  
1169                         //service-id=string L
1170 david.dillard  1.15     //# The ID of this WBEM Server. The value MUST be the
1171 tony           1.5      //# CIM_ObjectManager.Name property value.
1172 karl           1.18     populateTemplateField(templateInstance, serviceIDAttribute, strUUID,
1173 karl           1.7          serviceIDProperty);
1174 karl           1.4  
1175 karl           1.18     // get service-hi-name and description from the instance of the
1176                         // objectmanager class
1177 venkat.puvvada 1.55     String elementName = _getPropertyValueString(
1178                             instance_ObjMgr,
1179                             elementNamePropertyName);
1180                     
1181                         populateTemplateField(
1182                             templateInstance,
1183                             serviceHiNameAttribute,
1184                             elementName,
1185                             serviceHiNameProperty);
1186                     
1187                         String description = _getPropertyValueString(
1188                             instance_ObjMgr,
1189                             descriptionPropertyName);
1190                     
1191                         populateTemplateField(
1192                             templateInstance,
1193                             serviceHiDescriptionAttribute,
1194                             description,
1195                             serviceHiDescriptionProperty);
1196 karl           1.4  
1197 karl           1.9      //    templateTypeProperty);
1198 marek          1.37     populateTemplateField(
1199                             templateInstance,
1200                             templateTypeAttribute,
1201                             String(serviceName),
1202 karl           1.7          templateTypeProperty);
1203 david.dillard  1.15 
1204 marek          1.37     populateTemplateField(
1205                             templateInstance,
1206                             templateVersionAttribute,
1207                             String(templateVersion),
1208 karl           1.7          templateVersionProperty);
1209 david.dillard  1.15 
1210 marek          1.37     populateTemplateField(
1211                             templateInstance,
1212                             templateDescriptionAttribute,
1213                             String(templateDescription),
1214 dave.sudlik    1.24         templateDescriptionProperty);
1215 david.dillard  1.15 
1216 karl           1.33     // populate name of InterOp Namespace attribute
1217 marek          1.37     populateTemplateField(
1218                             templateInstance,
1219                             InteropSchemaNamespaceAttribute,
1220                             PEGASUS_NAMESPACENAME_INTEROP.getString(),
1221                             String::EMPTY);
1222 karl           1.18 
1223                         // Loop through all properties and process each.
1224 marek          1.37     // Note: This does not make it easy to distinguish
1225                         // required vs. optional but works.
1226 dave.sudlik    1.24     for (Uint32 j = 0;  j < instance_ObjMgrComm.getPropertyCount(); j++)
1227 tony           1.5      {
1228 karl           1.18         // get the property value
1229                             CIMConstProperty thisProperty = instance_ObjMgrComm.getProperty(j);
1230                             CIMName propertyName = thisProperty.getName();
1231                             CIMValue v1= thisProperty.getValue();
1232 karl           1.4  
1233 karl           1.18         if (propertyName.equal(communicationMechanismAttribute))
1234                             {
1235 karl           1.10 
1236 karl           1.18             String thisValue = _getValueQualifier(thisProperty, commMechClass);
1237 s.kodali       1.54             Uint16 communicationType;
1238 karl           1.11             if (thisValue == String::EMPTY)
1239                                 {
1240                                     thisValue = "Unknown";
1241                                 }
1242 marek          1.37             populateTemplateField(
1243                                     templateInstance,
1244                                     communicationMechanismAttribute,
1245                                     thisValue);
1246 s.kodali       1.54             v1.get(communicationType);
1247                                 if (communicationType == 1)
1248 tony           1.5              {
1249 dave.sudlik    1.24                 String tmp = _getPropertyValueString(
1250                                         instance_ObjMgrComm,
1251                                         CIMName(otherCommunicationMechanismDescriptionAttribute),
1252                                         String::EMPTY);
1253 marek          1.37                 populateTemplateField(
1254                                         templateInstance,
1255                                         otherCommunicationMechanismDescriptionAttribute,
1256                                         tmp);
1257 tony           1.5              }
1258                             }
1259 karl           1.18         else if (propertyName.equal("Version"))
1260 marek          1.37             populateTemplateField(
1261                                     templateInstance,
1262                                     protocolVersionAttribute,
1263                                     v1.toString());
1264 tony           1.5  
1265 karl           1.18         else if (propertyName.equal("FunctionalProfileDescriptions"))
1266 david.dillard  1.15         {
1267 tony           1.5              Array<String> descriptions;
1268                                 v1.get(descriptions);
1269                     
1270                                 String desList = _arrayToString(descriptions);
1271 marek          1.37             populateTemplateField(
1272                                     templateInstance,
1273                                     functionalProfilesSupportedAttribute,
1274                                     desList);
1275 karl           1.7  
1276 tony           1.5              if (String::equalNoCase(v1.toString(),"Other"))
1277                                 {
1278 marek          1.37                 Uint32 pos = instance_ObjMgrComm.findProperty(
1279                                                      CIMName(otherProfileDescriptionAttribute));
1280 karl           1.17                 CIMConstProperty temppr = instance_ObjMgrComm.getProperty(pos);
1281 marek          1.37                 String tmp = _getPropertyValueString(
1282 kumpf          1.51                                   instance_ObjMgrComm,
1283 marek          1.37                                  CIMName(otherProfileDescriptionAttribute),
1284                                                       String::EMPTY);
1285                                     populateTemplateField(
1286                                         templateInstance,
1287                                         otherProfileDescriptionAttribute,
1288                                         tmp);
1289 tony           1.5              }
1290                             }
1291 mday           1.1  
1292 karl           1.18         else if (propertyName.equal(multipleOperationsSupportedAttribute))
1293 marek          1.37             populateTemplateField(
1294                                     templateInstance,
1295                                     multipleOperationsSupportedAttribute,
1296 kumpf          1.38                 v1.toString());
1297 david.dillard  1.15 
1298 karl           1.18         else if (propertyName.equal(authenticationMechanismsSupportedAttribute))
1299 karl           1.17         {
1300 a.dunfey       1.23             String thisValue = _getValueQualifier(thisProperty, commMechClass);
1301 karl           1.18             populateTemplateField(templateInstance,
1302 dave.sudlik    1.24                 authenticationMechanismsSupportedAttribute,
1303                                     thisValue);
1304 karl           1.17         }
1305 marek          1.37         else if (propertyName.equal(
1306                                          authenticationMechanismDescriptionsAttribute))
1307 tony           1.5          {
1308                                 Array<String> authenticationDescriptions;
1309                                 v1.get(authenticationDescriptions);
1310 dave.sudlik    1.24             if (authenticationDescriptions.size() > 0)
1311 a.dunfey       1.23             {
1312                                     String authDesList = _arrayToString(authenticationDescriptions);
1313 tony           1.5  
1314 a.dunfey       1.23                 populateTemplateField(templateInstance,
1315                                         authenticationMechanismDescriptionsAttribute,
1316                                         authDesList);
1317                                 }
1318 tony           1.5          }
1319                         }
1320 david.dillard  1.15 
1321 tony           1.5      // fill in the classname information (namespace and classinfo).
1322                         String classInfoList;
1323 kumpf          1.51     String nameSpaceList = getNameSpaceInfo(
1324 marek          1.37                                PEGASUS_NAMESPACENAME_INTEROP,
1325 thilo.boehm    1.56                                classInfoList,
1326                                                    context);
1327 marek          1.37 
1328                         populateTemplateField(
1329                             templateInstance,
1330                             namespaceAttribute,
1331                             nameSpaceList);
1332 karl           1.7  
1333 karl           1.25     if (classInfoList.size() != 0)
1334                         {
1335 marek          1.37         populateTemplateField(
1336                                 templateInstance,
1337                                 classinfoAttribute,
1338                                 classInfoList);
1339 karl           1.25     }
1340 mday           1.1  
1341 tony           1.5      // set the current time into the instance
1342 marek          1.37     templateInstance.addProperty(
1343                             CIMProperty(
1344 kumpf          1.51             CIMName("registeredTime"),
1345 marek          1.37             CIMDateTime::getCurrentDateTime()));
1346 mday           1.1  
1347 tony           1.5      // populate the RegisteredProfiles Supported attribute.
1348 mday           1.1  
1349 karl           1.18     populateTemplateField(templateInstance,
1350 venkat.puvvada 1.55         registeredProfilesSupportedAttribute, registeredProfiles);
1351 mday           1.1  
1352 tony           1.5      //Begin registering the service. Keep this debug.
1353 marek          1.58     PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL3,
1354                             "Template:\n%s",
1355                             (const char*) _currentSLPTemplateString.getCString()));
1356                     
1357 david.dillard  1.15 
1358 tony           1.5      // Add the template to the instance as a diagnostic for the moment.
1359 marek          1.37     templateInstance.addProperty(
1360                             CIMProperty(
1361                                 CIMName("RegisteredTemplate"),
1362                                 _currentSLPTemplateString));
1363 mday           1.1  
1364 karl           1.9  
1365                         String fullServiceName = serviceIDPrefix + String(":") + serviceName;
1366 david.dillard  1.15     // generate the serviceID which is prefix:serviceName:serviceUrl
1367 karl           1.9      String ServiceID = fullServiceName + String(":") + serviceUrlSyntaxValue;
1368                     
1369                         //String ServiceID = serviceName + String(":") + serviceUrlSyntaxValue;
1370 karl           1.4  
1371 marek          1.58     PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
1372                             "Service URL: %s",
1373                             (const char*) ServiceID.getCString()));
1374 mday           1.1  
1375 kumpf          1.51     // Fill out the CIMObjectpath for the slp instance.
1376 marek          1.37     // The key for this class is the instanceID.
1377 tony           1.5      // Simply use the count of instances as the ID for the moment.
1378 mday           1.1  
1379 tony           1.5      Array<CIMKeyBinding> keyBindings;
1380 mday           1.1  
1381 marek          1.37     keyBindings.append(
1382                             CIMKeyBinding(
1383                                 instanceIDPropertyName,
1384                                 ServiceID,
1385                                 CIMKeyBinding::STRING));
1386                         CIMObjectPath reference1  = CIMObjectPath(
1387                                                         "localhost",
1388                                                         PEGASUS_NAMESPACENAME_INTEROP,
1389 dave.sudlik    1.24         CIMName(SlpTemplateClassName),
1390                             keyBindings);
1391 tony           1.5      // set the key property into the instance.
1392 marek          1.37     templateInstance.addProperty(
1393                             CIMProperty(
1394                                 CIMName(instanceIDPropertyName),
1395                                 ServiceID));
1396 david.dillard  1.15 
1397 karl           1.9      // Make a Cstring from the registration information, etc for api
1398                         CString CfullServiceName = fullServiceName.getCString();
1399 tony           1.5      CString CServiceID = ServiceID.getCString();
1400 karl           1.7      CString CstrRegistration = _currentSLPTemplateString.getCString();
1401 david.dillard  1.15 
1402 tony           1.5      // Test the registration
1403 karl           1.4  
1404 marek          1.58     PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
1405                             "TEST_REG: ServiceId %s\n serviceName: %s\n TEMPLATE = %s",
1406                             (const char *)CServiceID,
1407                             (const char *) serviceName,
1408                             (const char *) CstrRegistration));
1409 karl           1.9  
1410 david.dillard  1.15     Uint32 errorCode = slp_agent.test_registration((const char *)CServiceID ,
1411 dave.sudlik    1.24         (const char *)CstrRegistration,
1412                             (const char*)CfullServiceName,
1413                             "DEFAULT");
1414 karl           1.4  
1415 tony           1.5      if (errorCode != 0)
1416 karl           1.4      {
1417 tony           1.5          Logger::put(Logger::ERROR_LOG, SlpProvider, Logger::SEVERE,
1418                                 "SLP Registration Failed: test_registration. Code $0", errorCode);
1419                             return(false);
1420                         }
1421 karl           1.9  
1422 tony           1.5      // register this information.
1423                         Boolean goodRtn = slp_agent.srv_register((const char *)CServiceID ,
1424 dave.sudlik    1.24         (const char *)CstrRegistration,
1425                             (const char *)CfullServiceName,
1426                             "DEFAULT",
1427 dev.meetei     1.59 #if defined( PEGASUS_USE_EXTERNAL_SLP ) && defined( PEGASUS_SLP_REG_TIMEOUT )
1428 dave.sudlik    1.35         PEGASUS_SLP_REG_TIMEOUT  * 60);
1429                     #else
1430 dave.sudlik    1.24         0xffff);
1431 dave.sudlik    1.35 #endif
1432 karl           1.4  
1433 tony           1.5      if (!goodRtn)
1434                         {
1435                             Logger::put(Logger::ERROR_LOG, SlpProvider, Logger::SEVERE,
1436                                 "SLP Registration Failed: srv_registration.");
1437                             return(false);
1438 karl           1.4      }
1439 kumpf          1.51 
1440 karl           1.46     // register for service-agent on each ip interface with SA
1441 venkat.puvvada 1.42 #ifndef PEGASUS_SLP_REG_TIMEOUT
1442 venkat.puvvada 1.40     HostLocator locator(IPAddress);
1443                         String agentURL = "service:service-agent://";
1444                         agentURL.append(locator.getHost());
1445 karl           1.46 
1446 marek          1.58     PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
1447                             "REGISTER SVC %s,(service-type=*),service:service-agent,DEFAULT,0xffff",
1448                             (const char *) agentURL.getCString()));
1449 karl           1.46 
1450 venkat.puvvada 1.40     slp_agent.srv_register((const char *)agentURL.getCString(),
1451                             (const char *)"(service-type=*)",
1452                             (const char *)"service:service-agent",
1453                             "DEFAULT",
1454                             0xffff);
1455                     #endif
1456                     
1457 tony           1.5      // Add the registered instance to the current active list.
1458 karl           1.18     _instances.append(templateInstance);
1459 tony           1.5      _instanceNames.append(reference1);
1460 marek          1.58     return true;
1461 dev.meetei     1.59 } 
1462                     
1463                     //This function checks for Link-local ipv6 address(LLA),
1464                     //If the address is LLA, it removes the zone id and return the
1465                     //LLA, otherwise, no change in the address 
1466                     void SLPProvider::_processLinkLocalAddress( String &ip6add2check)
1467                     {
1468                     
1469                      Uint32 percentPos = 0;
1470                      if ((ip6add2check.size() >= 6) && (ip6add2check[0] == Char16('[')) &&
1471                          (ip6add2check[1] == Char16('f') || ip6add2check[1] == Char16('F')) &&
1472                          (ip6add2check[2] == Char16('e') || ip6add2check[2] == Char16('E')) &&
1473                          (ip6add2check[3] == Char16('8') && (ip6add2check[4] == Char16('0')) &&
1474                          (PEG_NOT_FOUND != (percentPos = ip6add2check.find(5,Char16('%'))))))
1475                          {
1476                               Uint32 closingSq = ip6add2check.find(']');
1477                               PEGASUS_ASSERT(closingSq !=PEG_NOT_FOUND);
1478                               ip6add2check.remove(percentPos, closingSq - percentPos);
1479                     
1480                               PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
1481                                   "Processed LLA %s", (const char *) ip6add2check.getCString()));
1482 dev.meetei     1.59     }
1483 tony           1.5  }
1484 mday           1.1  
1485 tony           1.5  /** issue all necessary SLP registrations. Gets the objects that are required to
1486 marek          1.37     provide information for registration and calls populate function to create
1487 tony           1.5      a registration for each communication adapter represented by a communication
1488                         object.
1489                     */
1490 thilo.boehm    1.56 Uint32 SLPProvider::populateSLPRegistrations(const OperationContext & context)
1491 tony           1.5  {
1492 venkat.puvvada 1.57     // clear existing instances
1493                         _instanceNames.clear();
1494                         _instances.clear();
1495                     
1496 karl           1.18     // get the PG communication mechanism class.  Used as part of the populate
1497                         // An exception here is caught in the facade.
1498                         CIMClass pg_CIMXMLClass = _cimomHandle.getClass(
1499 thilo.boehm    1.56         context,
1500 dave.sudlik    1.24         PEGASUS_NAMESPACENAME_INTEROP,
1501 a.dunfey       1.34         PEGASUS_CLASSNAME_PG_CIMXMLCOMMUNICATIONMECHANISM,
1502 dave.sudlik    1.24         false, true, true, CIMPropertyList());
1503 karl           1.18 
1504 tony           1.5      // Get the CIM_ObjectManager instance
1505 marek          1.13     Array<CIMInstance> instancesObjMgr;
1506 dave.sudlik    1.24     try
1507 karl           1.18     {
1508                             instancesObjMgr = _cimomHandle.enumerateInstances(
1509 thilo.boehm    1.56             context,
1510 dave.sudlik    1.24             PEGASUS_NAMESPACENAME_INTEROP,
1511 a.dunfey       1.34             PEGASUS_CLASSNAME_PG_OBJECTMANAGER,
1512 dave.sudlik    1.24             false, false, false,false, CIMPropertyList());
1513                         }
1514 marek          1.29     catch (const Exception & e)
1515 dave.sudlik    1.24     {
1516 marek          1.58         PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL2,
1517                                 "Exception caught on enumerateInstances(CIM_ObjectManager):=%s",
1518                                 (const char*) e.getMessage().getCString()));
1519 marek          1.13     }
1520 karl           1.18 
1521 thilo.boehm    1.56     String registeredProfiles = getRegisteredProfileList(context);
1522 venkat.puvvada 1.55 
1523 dave.sudlik    1.24     // get instances of CIM_ObjectManagerCommMechanism and subclasses directly
1524 karl           1.8      Array<CIMInstance> instancesObjMgrComm = _cimomHandle.enumerateInstances(
1525 thilo.boehm    1.56         context,
1526 dave.sudlik    1.24         PEGASUS_NAMESPACENAME_INTEROP,
1527 a.dunfey       1.34         PEGASUS_CLASSNAME_OBJECTMANAGERCOMMUNICATIONMECHANISM,
1528 dave.sudlik    1.24         true, false, true,true, CIMPropertyList());
1529 mday           1.1  
1530 tony           1.5      //Loop to create an SLP registration for each communication mechanism
1531 karl           1.8      // Note that this depends on getting from the PG_Class for communication.
1532 tony           1.5      Uint32 itemsRegistered = 0;
1533 karl           1.8  
1534                         for (Uint32 i = 0; i < instancesObjMgrComm.size(); i++)
1535 tony           1.5      {
1536                             // get protocol property
1537 karl           1.18         String protocol  = _getPropertyValueString(instancesObjMgrComm[i],
1538 dave.sudlik    1.24             CIMName("namespaceType"), "http");
1539 david.dillard  1.15 
1540 tony           1.5          // get ipaddress property
1541 karl           1.18         String IPAddress = _getPropertyValueString(instancesObjMgrComm[i],
1542 dave.sudlik    1.24             CIMName("IPAddress"), "127.0.0.1");
1543 dev.meetei     1.59 
1544 dev.meetei     1.60         _processLinkLocalAddress(IPAddress);
1545 tony           1.5          // create a registration instance, test and register it.
1546 karl           1.18         if (populateRegistrationData(protocol,
1547 dave.sudlik    1.24             IPAddress,
1548                                 instancesObjMgr[0],
1549                                 instancesObjMgrComm[i],
1550 venkat.puvvada 1.55             pg_CIMXMLClass,
1551 thilo.boehm    1.56             registeredProfiles,
1552                                 context))
1553 karl           1.18         {
1554 tony           1.5              itemsRegistered++;
1555 karl           1.18         }
1556 tony           1.5      }
1557 venkat.puvvada 1.42     return itemsRegistered;
1558                     }
1559                     
1560                     /** issue all necessary SLP registrations. Gets the objects that are required to
1561                         provide information for registration and calls populate function to create
1562                         a registration for each communication adapter represented by a communication
1563                         object using populateSLPRegistrations() method and starts service listener.
1564                         return: Boolean.  Indicates if there was an error in the registration.
1565                     */
1566 karl           1.8  
1567 thilo.boehm    1.56 Boolean SLPProvider::issueSLPRegistrations(const OperationContext & context)
1568 venkat.puvvada 1.42 {
1569                         // populate all SLP registrations.
1570 thilo.boehm    1.56     Uint32 itemsRegistered = populateSLPRegistrations(context);
1571 kumpf          1.51     // Start the Service Agent.  Note that the actual registrations are part of
1572                         // the populatetemplate function so that the various templates
1573 marek          1.37     // are already created.
1574 tony           1.5      if (itemsRegistered != 0)
1575                         {
1576                             try
1577                             {
1578                                 slp_agent.start_listener();
1579                             }
1580 dave.sudlik    1.24         catch (...)
1581 tony           1.5          {
1582                                 throw CIMOperationFailedException("Start SLP Listener Failed");
1583                             }
1584 david.dillard  1.15 
1585 tony           1.5          Uint32 finish, now, msec;
1586                             System::getCurrentTime(now, msec);
1587                             finish = now + 10;
1588 david.dillard  1.15 
1589 marek          1.37         // wait for 10 seconds.
1590                             // Earlier wait for 30 secs caused the client to timeout !
1591 dave.sudlik    1.24         while (finish > now)
1592 tony           1.5          {
1593 mike           1.31             Threads::sleep(1000);
1594 dave.sudlik    1.24             System::getCurrentTime(now, msec);
1595 tony           1.5          }
1596                             initFlag=true;
1597 karl           1.8          // Log slp agent started.
1598 marek          1.58         return true;
1599 tony           1.5      }
1600 karl           1.8  
1601                         // ATTN: Log failure to register because no communication mechanisms found.
1602 kumpf          1.51     // This error reflects NO communications mechanism objects found.
1603                         // We assume that we MUST always have at least
1604 marek          1.37     // one communication mechanism object for a registration and for a CIMOM.
1605                         // Anything else should be considered an error.  Reflect this in the log.
1606 marek          1.58     return false;
1607 mday           1.1  }
1608                     
1609                     void SLPProvider::initialize(CIMOMHandle & handle)
1610                     {
1611 dave.sudlik    1.24     _cimomHandle = handle;
1612                         initFlag = false;
1613 tony           1.5  
1614 dave.sudlik    1.24     // Do not allow unload.
1615                         _cimomHandle.disallowProviderUnload();
1616 mday           1.1  }
1617                     
1618 tony           1.5  //***************************************************************************
1619                     //
1620                     //   SLPProvider Public methods, intrinstic and extrinstic methods
1621                     //      This includes getInstance, enumerateInstance, enumerateInstanceNames
1622                     //      Today the other functions return NOT_SUPPORTED.
1623                     //
1624                     //***************************************************************************
1625                     
1626 venkat.puvvada 1.42 SLPProvider* SLPProvider::_this;
1627                     
1628 kumpf          1.51 SLPProvider::SLPProvider()
1629 mday           1.1  {
1630 venkat.puvvada 1.42     _this = this;
1631                         slp_agent.set_registration_callback((&updateProfileRegistration));
1632                     }
1633                     
1634                     void SLPProvider::updateProfileRegistration()
1635                     {
1636 thilo.boehm    1.56     OperationContext context;
1637                         context.insert(IdentityContainer(System::getEffectiveUserName()));
1638                         _this->populateSLPRegistrations(context);
1639 mday           1.1  }
1640                     
1641 kumpf          1.51 SLPProvider::~SLPProvider()
1642 mday           1.1  {
1643                     }
1644                     
1645 tony           1.5  /** gets a single instance. Note that this function uses the initFlag
1646                         to determine if the instance has to be built and registered before
1647                         it can return the instance.
1648                     */
1649 mday           1.1  void SLPProvider::getInstance(
1650 dave.sudlik    1.24     const OperationContext & context,
1651                         const CIMObjectPath & instanceReference,
1652                         const Boolean includeQualifiers,
1653                         const Boolean includeClassOrigin,
1654                         const CIMPropertyList & propertyList,
1655                         InstanceResponseHandler & handler)
1656 mday           1.1  {
1657 david.dillard  1.15     // if this is the first call, create the registration.
1658 tony           1.5      //if(initFlag == false)
1659                         //    issueSLPRegistrations();
1660 david.dillard  1.15 
1661 tony           1.5      // convert a potential fully qualified reference into a local reference
1662                         // (class name and keys only).
1663                         CIMObjectPath localReference = CIMObjectPath(
1664 dave.sudlik    1.24         String(),
1665                             CIMNamespaceName(),
1666                             instanceReference.getClassName(),
1667                             instanceReference.getKeyBindings());
1668                         // begin processing the request
1669                     
1670                         handler.processing();
1671                     
1672                         // instance index corresponds to reference index
1673                         for (Uint32 i = 0, n = _instances.size(); i < n; i++)
1674                         {
1675                             CIMObjectPath localReference_frominstanceNames = CIMObjectPath(
1676                                 String(),
1677                                 CIMNamespaceName(),
1678                                 _instanceNames[i].getClassName(),
1679                                 _instanceNames[i].getKeyBindings());
1680                     
1681                             if (localReference == localReference_frominstanceNames)
1682                             {
1683                                 // deliver requested instance
1684                                 handler.deliver(_instances[i]);
1685 dave.sudlik    1.24             break;
1686                             }
1687                         }
1688                         //complete processing the request
1689                         handler.complete();
1690 mday           1.1  }
1691                     
1692                     void SLPProvider::enumerateInstances(
1693 dave.sudlik    1.24     const OperationContext & context,
1694                         const CIMObjectPath & classReference,
1695                         const Boolean includeQualifiers,
1696                         const Boolean includeClassOrigin,
1697                         const CIMPropertyList & propertyList,
1698                         InstanceResponseHandler & handler)
1699 mday           1.1  {
1700 karl           1.4      // begin processing the request
1701                         handler.processing();
1702 tony           1.5  
1703 marek          1.58     PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
1704                             "enumerateInstances. count instances=%u",
1705                             _instances.size()));
1706                     
1707 dave.sudlik    1.24     for (Uint32 i = 0, n = _instances.size(); i < n; i++)
1708 karl           1.4      {
1709 dave.sudlik    1.24         // deliver instance
1710                             handler.deliver(_instances[i]);
1711 karl           1.4      }
1712 david.dillard  1.15 
1713 karl           1.4      // complete processing the request
1714 tony           1.5      handler.complete();
1715 mday           1.1  }
1716                     
1717                     void SLPProvider::enumerateInstanceNames(
1718 dave.sudlik    1.24     const OperationContext & context,
1719                         const CIMObjectPath & classReference,
1720                         ObjectPathResponseHandler & handler)
1721 mday           1.1  {
1722 david.dillard  1.15     // if this is the first call, create the registration.
1723 tony           1.5      //if(initFlag == false)
1724                         //    issueSLPRegistrations();
1725 david.dillard  1.15 
1726 karl           1.4      // begin processing the request
1727                         handler.processing();
1728 david.dillard  1.15 
1729 dave.sudlik    1.24     for (Uint32 i = 0, n =_instances.size(); i < n; i++)
1730 karl           1.4      {
1731 tony           1.5          // deliver reference
1732                             handler.deliver(_instanceNames[i]);
1733 karl           1.4      }
1734                         // complete processing the request
1735                         handler.complete();
1736 mday           1.1  }
1737 david.dillard  1.15 
1738 mday           1.1  void SLPProvider::modifyInstance(
1739 dave.sudlik    1.24     const OperationContext & context,
1740                         const CIMObjectPath & instanceReference,
1741                         const CIMInstance & instanceObject,
1742                         const Boolean includeQualifiers,
1743                         const CIMPropertyList & propertyList,
1744                         ResponseHandler & handler)
1745 mday           1.1  {
1746                         throw CIMNotSupportedException("SLPServiceProvider "
1747 dave.sudlik    1.24         "does not support modifyInstance");
1748 mday           1.1  }
1749                     
1750                     void SLPProvider::createInstance(
1751 dave.sudlik    1.24     const OperationContext & context,
1752                         const CIMObjectPath & instanceReference,
1753                         const CIMInstance & instanceObject,
1754                         ObjectPathResponseHandler & handler)
1755 mday           1.1  {
1756                         throw CIMNotSupportedException("SLPServiceProvider "
1757 dave.sudlik    1.24         "does not support createInstance");
1758 mday           1.1  }
1759                     
1760                     void SLPProvider::deleteInstance(
1761 dave.sudlik    1.24     const OperationContext & context,
1762                         const CIMObjectPath & instanceReference,
1763                         ResponseHandler & handler)
1764 mday           1.1  {
1765                         throw CIMNotSupportedException("SLPServiceProvider "
1766 dave.sudlik    1.24         "does not support deleteInstance");
1767 mday           1.1  }
1768                     
1769 tony           1.5  /* process the invokemethods defined for this class. The methods include
1770                        register - forces registration of the CIMOM characteristics as a template.
1771                        This function can also be done by issuing enumerateinstance calls but the
1772                        register is more precise.
1773                        unregister - Forces any registrations to be deregistered and the slp-agen
1774                        to be closed.
1775                        update - causes the existing registration to be updated with new information
1776                     */
1777                     void SLPProvider::invokeMethod(
1778 dave.sudlik    1.24     const OperationContext & context,
1779                         const CIMObjectPath & objectReference,
1780                         const CIMName & methodName,
1781                         const Array<CIMParamValue> & inParameters,
1782                         MethodResultResponseHandler & handler)
1783 tony           1.5  {
1784 marek          1.58     PEG_TRACE((TRC_INTERNALPROVIDER,Tracer::LEVEL4,
1785                             "invokeMethod. method=%s",
1786                             (const char*) methodName.getString().getCString()));
1787 tony           1.5  
1788                         _nameSpace = objectReference.getNameSpace();
1789                         // convert a fully qualified reference into a local reference
1790                         // (class name and keys only).
1791                         CIMObjectPath localReference = CIMObjectPath(
1792                             String(),
1793                             CIMNamespaceName(),
1794                             objectReference.getClassName(),
1795                             objectReference.getKeyBindings());
1796 david.dillard  1.15 
1797 tony           1.5      handler.processing();
1798 karl           1.7      Uint32 response = 0;
1799 dave.sudlik    1.24     if (objectReference.getClassName().equal(SlpTemplateClassName))
1800 tony           1.5      {
1801 dave.sudlik    1.24         if (methodName.equal("register"))
1802 tony           1.5          {
1803 dave.sudlik    1.24             if (initFlag == false)
1804 dave.sudlik    1.35             {
1805 marek          1.63                 OperationContext myCopy = context;
1806                                     String timeoutStr=
1807                                         ConfigManager::getInstance()->getCurrentValue(
1808                                             "slpProviderStartupTimeout");
1809                                     Uint64 timeOut;
1810                                     
1811                                     StringConversion::decimalStringToUint64(
1812                                         timeoutStr.getCString(),
1813                                         timeOut);
1814                     
1815                                     myCopy.insert(TimeoutContainer(timeOut & 0xFFFFFFFF));
1816                     
1817                                     if (issueSLPRegistrations(myCopy))
1818 dave.sudlik    1.35                 {
1819                                     // PEP 267 ifdef is added to allow reregistrations.
1820 kumpf          1.51                 // issueRegistration sets initFlag to true.
1821 karl           1.46 #if defined( PEGASUS_USE_EXTERNAL_SLP ) && defined ( PEGASUS_SLP_REG_TIMEOUT )
1822 dave.sudlik    1.35                    initFlag = false;
1823                     #endif
1824 tony           1.5                      response = 0;
1825 dave.sudlik    1.35                 }
1826 tony           1.5                  else
1827 dave.sudlik    1.35                 {
1828 karl           1.7                      response = 2;
1829 kumpf          1.51                 }
1830 dave.sudlik    1.35              }
1831 tony           1.5              else
1832 dave.sudlik    1.35              {
1833 tony           1.5                  response = 1;
1834 venkat.puvvada 1.42              }
1835 dave.sudlik    1.35         }
1836 dave.sudlik    1.24         else if (methodName.equal("unregister"))
1837 tony           1.5          {
1838 dave.sudlik    1.24             if (initFlag == true)
1839 tony           1.5              {
1840                                     deregisterSLP();
1841                                 }
1842                             }
1843 dave.sudlik    1.24         else if (methodName.equal("update"))
1844 tony           1.5          {
1845 venkat.puvvada 1.42 #ifdef PEGASUS_SLP_REG_TIMEOUT
1846                                 // Signal agents semaphore
1847                                 slp_agent.get_update_reg_semaphore().signal();
1848                     #else
1849                                 // increment update registrations count.
1850                                 slp_agent.update_reg_count();
1851                     #endif
1852 tony           1.5          }
1853                             else
1854                             {
1855                                 // ATTN: Not sure that this is correct exception
1856                                 // for illegal method name.
1857                                 String e =  "SLPServiceProvider does not support" +
1858                                     methodName.getString() + " method.";
1859                                 throw CIMNotSupportedException( e);
1860                             }
1861                         }
1862                         handler.deliver(CIMValue(response));
1863                         handler.complete();
1864                     }
1865                     
1866 dave.sudlik    1.24 void SLPProvider::terminate()
1867 mday           1.1  {
1868 tony           1.5      deregisterSLP();
1869 mday           1.1      delete this;
1870                     }
1871                     
1872                     PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2