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

  1 mreddy 1.1.2.1 //%2005////////////////////////////////////////////////////////////////////////
  2                //
  3                // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4                // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5                // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6                // IBM Corp.; EMC Corporation, The Open Group.
  7                // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8                // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9                // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10                // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11                //
 12                // Permission is hereby granted, free of charge, to any person obtaining a copy
 13                // of this software and associated documentation files (the "Software"), to
 14                // deal in the Software without restriction, including without limitation the
 15                // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16                // sell copies of the Software, and to permit persons to whom the Software is
 17                // furnished to do so, subject to the following conditions:
 18                // 
 19                // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20                // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21                // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22 mreddy 1.1.2.1 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23                // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24                // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25                // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26                // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27                //
 28                //==============================================================================
 29                //
 30                // Author: carolyne Edward (cshyla@us.ibm.com)
 31                //
 32                // Modified By:
 33                //
 34                //%/////////////////////////////////////////////////////////////////////////////
 35                
 36                #include "SLPAttrib.h"
 37                #include <string.h>
 38                #include <Pegasus/Client/CIMClient.h>
 39                #include <Pegasus/Common/System.h>
 40                #include <Pegasus/Common/Constants.h>
 41                #include <Pegasus/Common/CIMType.h>
 42                #include <Pegasus/Common/InternalException.h>
 43 mreddy 1.1.2.1 
 44                PEGASUS_NAMESPACE_BEGIN
 45                
 46                static const String SERVICE_TYPE = "service:wbem";
 47                
 48                static const String PG_INTEROP_NAMESPACE = "root/pg_interop";
 49                
 50                //property names
 51                
 52                static const String PROP_ELEMENTNAME = "ElementName";
 53                static const String PROP_DESCRIPTION = "Description";
 54                static const String PROP_NAME = "Name";
 55                static const String PROP_CLASSINFO = "Classinfo";
 56                static const String PROP_COMMUNICATIONMECHANISM = "CommunicationMechanism";
 57                static const String PROP_OTHERCOMMUNICATIONMECHANISMDESCRIPTION = "OtherCommunicationMechanismDescription";
 58                static const String PROP_INTEROPSCHEMANAMESPACE = "InteropSchemaNamespace";
 59                static const String PROP_VERSION = "Version";
 60                static const String PROP_FUNCTIONALPROFILESSUPPORTED = "FunctionalProfilesSupported";
 61                static const String PROP_FUNCTIONALPROFILEDESCRIPTIONS = "FunctionalProfileDescriptions";
 62                static const String PROP_MULTIPLEOPERATIONSSUPPORTED = "MultipleOperationsSupported";
 63                static const String PROP_AUTHENTICATIONMECHANISMSSUPPORTED = "AuthenticationMechanismsSupported";
 64 mreddy 1.1.2.1 static const String PROP_AUTHENTICATIONMECHANISMDESCRIPTIONS = "AuthenticationMechanismDescriptions";
 65                static const String PROP_NAMESPACETYPE = "namespaceType";
 66                static const String PROP_IPADDRESS = "IPAddress";
 67                
 68                static const String CIM_CLASSNAME_REGISTEREDPROFILE = "CIM_RegisteredProfile";
 69                static const String PROP_OTHERREGISTEREDORGANIZATION = "OtherRegisteredOrganization";
 70                static const String PROP_REGISTEREDNAME = "RegisteredName";
 71                static const String PROP_ADVERTISETYPES = "AdvertiseTypes";
 72                
 73                //constructor
 74                SLPAttrib::SLPAttrib():serviceType(SERVICE_TYPE)
 75                {
 76                }
 77                
 78                SLPAttrib::~SLPAttrib()
 79                {
 80                }
 81                
 82                String SLPAttrib::getAttributes(void) const 
 83                {
 84                    return attributes;
 85 mreddy 1.1.2.1 }
 86                
 87                String SLPAttrib::getServiceType(void) const 
 88                {
 89                    return serviceType;
 90                }
 91                
 92                String SLPAttrib::getServiceUrl(void) const 
 93                {
 94                    return serviceUrl;
 95                }
 96                
 97                // fill all data required for SLP.
 98                void SLPAttrib::fillData(String protocol)
 99                {
100                    CIMClient client;
101                    CIMClass cimClass;
102                    //
103                    // open connection to CIMOM 
104                    //
105                    String hostStr = System::getHostName();
106 mreddy 1.1.2.1 
107                    try
108                    {
109                        //
110                        client.connectLocal();
111                
112                        //
113                        Array <CIMInstance> instances;
114                        CIMValue val;
115                        Uint32 pos;
116                        Boolean localOnly=true;
117                        Boolean includeQualifiers=true;
118                        Boolean includeClassOrigin=false;
119                        Boolean deepInheritance=true;
120                        Uint32 len = 0;
121                
122                        // set to true if there is "Other" property value in FunctionsProfilesSupported value.
123                        Boolean functionaProfileDescriptions = false;
124                
125                        instances = client.enumerateInstances 
126                            (PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_OBJECTMANAGER,deepInheritance,localOnly,includeQualifiers,includeClassOrigin);
127 mreddy 1.1.2.1 
128                        PEGASUS_ASSERT (instances.size () == 1);
129                
130                        pos = instances[0].findProperty(PROP_ELEMENTNAME);
131                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
132                        val = instances[0].getProperty(pos).getValue ();
133                        serviceHiName = val.toString();
134                
135                        pos = instances[0].findProperty (PROP_DESCRIPTION);
136                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
137                        val = instances[0].getProperty(pos).getValue ();
138                        serviceHiDescription = val.toString();
139                
140                        pos = instances[0].findProperty (PROP_NAME);
141                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
142                        val = instances[0].getProperty(pos).getValue ();
143                        serviceId = val.toString();
144                
145                        instances = client.enumerateInstances 
146                            (PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PG_CIMXMLCOMMUNICATIONMECHANISM,deepInheritance,localOnly,includeQualifiers,includeClassOrigin);
147                
148 mreddy 1.1.2.1         for (Uint32 n=instances.size(),i=0 ; i<n; i++)
149                        {
150                            pos = instances[i].findProperty (PROP_NAMESPACETYPE);
151                            PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
152                            val = instances[i].getProperty(pos).getValue ();
153                            if (val.toString() == protocol) 
154                            {
155                                pos = instances[i].findProperty (PROP_IPADDRESS);
156                                PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
157                                val = instances[i].getProperty(pos).getValue ();
158                                serviceUrl="service:wbem:";
159                                serviceUrl.append(protocol);
160                                serviceUrl.append("://");
161                                serviceUrl.append(val.toString());
162                                break;
163                            }
164                        }
165                
166                        cimClass = client.getClass(PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_CIMNAMESPACE);
167                        instances = client.enumerateInstances 
168                            (PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_CIMNAMESPACE,deepInheritance,localOnly,includeQualifiers,includeClassOrigin);
169 mreddy 1.1.2.1 
170                        for (Uint32 n=instances.size(),i=0 ; i<n; i++)
171                        {
172                            pos = instances[i].findProperty (PROP_NAME);
173                            PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
174                            val = instances[i].getProperty(pos).getValue();
175                            nameSpaces.append(val.toString());
176                            nameSpaces.append(",");
177                
178                            pos = instances[i].findProperty (PROP_CLASSINFO);
179                            PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
180                            val = instances[i].getProperty(pos).getValue();
181                            pos = cimClass.findProperty(PROP_CLASSINFO);
182                            classes.append(getMappedValue(cimClass.getProperty(pos),val));
183                            classes.append(",");
184                        }
185                
186                        len = nameSpaces.size(); 
187                        if (len > 0)
188                            nameSpaces.remove( len-1,1);
189                
190 mreddy 1.1.2.1         len = classes.size(); 
191                        if (len > 0)
192                            classes.remove( len-1,1);
193                
194                        cimClass = client.getClass 
195                           (PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_OBJECTMANAGERCOMMUNICATIONMECHANISM);
196                        instances = client.enumerateInstances 
197                           (PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_OBJECTMANAGERCOMMUNICATIONMECHANISM,deepInheritance,localOnly,includeQualifiers,includeClassOrigin);
198                
199                        pos = instances[0].findProperty (PROP_COMMUNICATIONMECHANISM);
200                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
201                        val = instances[0].getProperty(pos).getValue();
202                        pos = cimClass.findProperty(PROP_COMMUNICATIONMECHANISM);
203                        communicationMechanism = getMappedValue(cimClass.getProperty(pos),val);
204                        pos = instances[0].findProperty (PROP_OTHERCOMMUNICATIONMECHANISMDESCRIPTION);
205                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
206                        val = instances[0].getProperty(pos).getValue ();
207                        otherCommunicationMechanismDescription = val.toString();
208                
209                        interopSchemaNamespace = PG_INTEROP_NAMESPACE;
210                
211 mreddy 1.1.2.1         pos = instances[0].findProperty (PROP_VERSION);
212                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
213                        val = instances[0].getProperty(pos).getValue();
214                        pos = cimClass.findProperty(PROP_VERSION);
215                        protocolVersion = getMappedValue(cimClass.getProperty(pos),val);
216                
217                        pos = instances[0].findProperty (PROP_FUNCTIONALPROFILESSUPPORTED);
218                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
219                        CIMConstProperty constProperty;
220                        constProperty = instances[0].getProperty(pos);
221                        val = constProperty.getValue(); 
222                        Array<Uint16> arrayValFPS;
223                        val.get(arrayValFPS);
224                        pos = cimClass.findProperty(PROP_FUNCTIONALPROFILESSUPPORTED);
225                        for (Uint32 n=arrayValFPS.size(),i=0; i<n; i++)
226                        {
227                            String profileValue = getMappedValue(cimClass.getProperty(pos),CIMValue(arrayValFPS[i]));
228                            if (profileValue == "Other")
229                                functionaProfileDescriptions = true;
230                            functionalProfilesSupported.append(profileValue);
231                            functionalProfilesSupported.append(",");
232 mreddy 1.1.2.1         }
233                        len = functionalProfilesSupported.size(); 
234                        if (len > 0)
235                            functionalProfilesSupported.remove( len-1,1);
236                
237                       if (functionalProfileDescriptions == true)
238                       {
239                           pos = instances[0].findProperty (PROP_FUNCTIONALPROFILEDESCRIPTIONS);
240                           PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
241                           val = instances[0].getProperty(pos).getValue(); 
242                           Array<String> arrayValFPD;
243                           val.get(arrayValFPD);
244                           for (Uint32 n=arrayValFPD.size(),i=0; i<n; i++)
245                           {
246                               functionalProfileDescriptions.append(arrayValFPD[i]);
247                               functionalProfileDescriptions.append(",");
248                           }
249                           len = functionalProfileDescriptions.size(); 
250                           if (len > 0)
251                               functionalProfileDescriptions.remove( len-1,1);
252                        }
253 mreddy 1.1.2.1         pos = instances[0].findProperty (PROP_MULTIPLEOPERATIONSSUPPORTED);
254                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
255                        val = instances[0].getProperty(pos).getValue(); 
256                        Boolean value;
257                        val.get(value);
258                        if (value == true)
259                            multipleOperationsSupported.append("TRUE");
260                        else
261                            multipleOperationsSupported.append("FALSE");
262                
263                        pos = instances[0].findProperty (PROP_AUTHENTICATIONMECHANISMSSUPPORTED);
264                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
265                        val = instances[0].getProperty(pos).getValue(); 
266                        Array<Uint16> arrayValAMS;
267                        val.get(arrayValAMS);
268                        pos = cimClass.findProperty (PROP_AUTHENTICATIONMECHANISMSSUPPORTED);
269                        for (Uint32 n=arrayValAMS.size(),i=0; i<n; i++)
270                        {
271                            authenticationMechanismsSupported.append(getMappedValue(cimClass.getProperty(pos),CIMValue(arrayValAMS[i])));
272                            authenticationMechanismsSupported.append(",");
273                        }
274 mreddy 1.1.2.1         len = authenticationMechanismsSupported.size(); 
275                        if (len > 0)
276                            authenticationMechanismsSupported.remove( len-1,1);
277                
278                        pos = instances[0].findProperty (PROP_AUTHENTICATIONMECHANISMDESCRIPTIONS);
279                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
280                        val = instances[0].getProperty(pos).getValue(); 
281                        Array<String> arrayValAMD;
282                        val.get(arrayValAMD);
283                        for (Uint32 n=arrayValAMD.size(),i=0; i<n; i++)
284                        {
285                            authenticationMechanismDescriptions.append(arrayValAMD[i]);
286                            authenticationMechanismDescriptions.append(",");
287                        }
288                        len = authenticationMechanismDescriptions.size(); 
289                        if (len > 0)
290                            authenticationMechanismDescriptions.remove( len-1,1);
291                        instances = client.enumerateInstances 
292                            (PEGASUS_NAMESPACENAME_INTEROP, CIM_CLASSNAME_REGISTEREDPROFILE,deepInheritance,localOnly,includeQualifiers,includeClassOrigin);
293                
294                        for (Uint32 n=instances.size(),i=0 ; i<n; i++)
295 mreddy 1.1.2.1         {
296                            pos = instances[i].findProperty (PROP_ADVERTISETYPES);
297                            PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
298                            CIMValue cAdvTypes = instances[i].getProperty(pos).getValue();
299                            Array<Uint16> advTypes;
300                            cAdvTypes.get(advTypes); 
301                            for (Uint32 n=advTypes.size(),j = 0; j < n; j++)
302                            {
303                                if(advTypes[j] == 3)
304                                {
305                                    pos = instances[i].findProperty (PROP_OTHERREGISTEREDORGANIZATION);
306                                    PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
307                                    registeredProfiles.append(instances[i].getProperty(pos).getValue().toString());
308                                    registeredProfiles.append(":");
309                                    pos = instances[i].findProperty (PROP_REGISTEREDNAME);
310                                    PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
311                                    registeredProfiles.append(instances[i].getProperty(pos).getValue().toString());
312                                    registeredProfiles.append(",");
313                                    break;
314                                }
315                            }
316 mreddy 1.1.2.1         }
317                
318                        if (instances.size() > 0) 
319                        {
320                            len = registeredProfiles.size(); 
321                            registeredProfiles.remove( len-1,1);
322                        }
323                       else
324                            registeredProfiles.append("");
325                    }
326                
327                    catch(CIMException& e)
328                    {
329                        Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
330                            "SLP Registration Failed. CIMException. $0", e.getMessage());
331                    }
332                
333                    catch(Exception& e)
334                    {
335                        Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
336                            "SLP Registration Failed Startup: CIMException exception. $0", e.getMessage());
337 mreddy 1.1.2.1     }
338                
339                    client.disconnect();
340                    return;
341                } 
342                
343                // Map Values to ValueMap
344                String SLPAttrib::getMappedValue(const CIMProperty& cimProperty, CIMValue value)
345                {
346                    String retValue;
347                    Uint16 localValue;
348                
349                    if (strcmp(cimTypeToString(value.getType()),"string") == 0)
350                       value.get(retValue);
351                    else
352                    {
353                        value.get(localValue);
354                        retValue = Formatter::format("$0",localValue);
355                    }
356                
357                    Uint32 posValueMap;
358 mreddy 1.1.2.1 
359                    if ((posValueMap = cimProperty.findQualifier(CIMName("ValueMap"))) == PEG_NOT_FOUND)
360                    {
361                        return retValue;
362                    }
363                    CIMConstQualifier qValueMap = cimProperty.getQualifier(posValueMap);
364                    if (!qValueMap.isArray() || (qValueMap.getType() != CIMTYPE_STRING))
365                    {
366                        return retValue;
367                    }
368                 
369                    CIMValue q1 = qValueMap.getValue();
370                    Array<String> val;
371                    q1.get(val);
372                
373                    Uint32 posValue;
374                    if ((posValue = cimProperty.findQualifier("Values")) == PEG_NOT_FOUND)
375                    {
376                        return retValue;
377                    }
378                
379 mreddy 1.1.2.1     CIMConstQualifier qValue = cimProperty.getQualifier(posValue);
380                    if (!qValue.isArray() || (qValue.getType() != CIMTYPE_STRING))
381                    {
382                        return retValue;
383                    }
384                
385                    CIMValue q2 = qValue.getValue();
386                    Array<String> va2;
387                    q2.get(va2);
388                
389                    if (va2.size() != val.size())
390                    {
391                        return retValue;
392                    }
393                
394                    for (Uint32 n=val.size(),i = 0; i < n; i++)
395                    {
396                        if(retValue == val[i])
397                        {
398                            return (va2[i]);
399                        }
400 mreddy 1.1.2.1     }
401                        return retValue;
402                }
403                
404                // Form the attributes String.
405                void SLPAttrib::formAttributes()
406                {
407                
408                    attributes.append(Formatter::format(
409                                        "(template-url-syntax=$0),(service-hi-name=$1),(service-hi-description=$2),(service-id=$3),(Namespace=$4),(Classinfo=$5),(CommunicationMechanism=$6),(OtherCommunicationMechanismDescription=$7),(InteropSchemaNamespace=$8),(ProtocolVersion=$9),",
410                                         serviceUrl,serviceHiName,
411                                         serviceHiDescription,serviceId,
412                                         nameSpaces,classes,
413                                         communicationMechanism,
414                                         otherCommunicationMechanismDescription,
415                                         interopSchemaNamespace,
416                                         protocolVersion));
417                
418                    attributes.append(Formatter::format(
419                                         "(FunctionalProfilesSupported=$0),(FunctionalProfileDescriptions=$1),(MultipleOperationsSupported=$2),(AuthenticationMechanismsSupported=$3),(AuthenticationMechanismDescriptions=$4),(RegisteredProfilesSupported=$5)",
420                                         functionalProfilesSupported,
421 mreddy 1.1.2.1                          functionalProfileDescriptions,
422                                         multipleOperationsSupported,
423                                         authenticationMechanismsSupported,
424                                         authenticationMechanismDescriptions,
425                                         registeredProfiles));
426                
427                    if (attributes.size() > 7900)
428                    {
429                	//truncate the attributes
430                	attributes = attributes.subString(0,7900);
431                	Uint32 index = attributes.reverseFind(')');
432                	attributes= attributes.subString(0,index+1);
433                    }
434                    return;
435                }
436                PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2