(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                //
 31                //%/////////////////////////////////////////////////////////////////////////////
 32                
 33                #include "SLPAttrib.h"
 34                #include <string.h>
 35                #include <Pegasus/Client/CIMClient.h>
 36                #include <Pegasus/Common/System.h>
 37                #include <Pegasus/Common/Constants.h>
 38                #include <Pegasus/Common/CIMType.h>
 39                #include <Pegasus/Common/InternalException.h>
 40                
 41                PEGASUS_NAMESPACE_BEGIN
 42                
 43 mreddy 1.1.2.1 static const String SERVICE_TYPE = "service:wbem";
 44                
 45                static const String PG_INTEROP_NAMESPACE = "root/pg_interop";
 46                
 47                //property names
 48                
 49                static const String PROP_ELEMENTNAME = "ElementName";
 50                static const String PROP_DESCRIPTION = "Description";
 51                static const String PROP_NAME = "Name";
 52                static const String PROP_CLASSINFO = "Classinfo";
 53                static const String PROP_COMMUNICATIONMECHANISM = "CommunicationMechanism";
 54                static const String PROP_OTHERCOMMUNICATIONMECHANISMDESCRIPTION = "OtherCommunicationMechanismDescription";
 55                static const String PROP_INTEROPSCHEMANAMESPACE = "InteropSchemaNamespace";
 56                static const String PROP_VERSION = "Version";
 57                static const String PROP_FUNCTIONALPROFILESSUPPORTED = "FunctionalProfilesSupported";
 58                static const String PROP_FUNCTIONALPROFILEDESCRIPTIONS = "FunctionalProfileDescriptions";
 59                static const String PROP_MULTIPLEOPERATIONSSUPPORTED = "MultipleOperationsSupported";
 60                static const String PROP_AUTHENTICATIONMECHANISMSSUPPORTED = "AuthenticationMechanismsSupported";
 61                static const String PROP_AUTHENTICATIONMECHANISMDESCRIPTIONS = "AuthenticationMechanismDescriptions";
 62                static const String PROP_NAMESPACETYPE = "namespaceType";
 63                static const String PROP_IPADDRESS = "IPAddress";
 64 mreddy 1.1.2.1 
 65                static const String CIM_CLASSNAME_REGISTEREDPROFILE = "CIM_RegisteredProfile";
 66                static const String PROP_OTHERREGISTEREDORGANIZATION = "OtherRegisteredOrganization";
 67                static const String PROP_REGISTEREDNAME = "RegisteredName";
 68                static const String PROP_ADVERTISETYPES = "AdvertiseTypes";
 69                
 70                //constructor
 71                SLPAttrib::SLPAttrib():serviceType(SERVICE_TYPE)
 72                {
 73                }
 74                
 75                SLPAttrib::~SLPAttrib()
 76                {
 77                }
 78                
 79                String SLPAttrib::getAttributes(void) const 
 80                {
 81                    return attributes;
 82                }
 83                
 84                String SLPAttrib::getServiceType(void) const 
 85 mreddy 1.1.2.1 {
 86                    return serviceType;
 87                }
 88                
 89                String SLPAttrib::getServiceUrl(void) const 
 90                {
 91                    return serviceUrl;
 92                }
 93                
 94                // fill all data required for SLP.
 95                void SLPAttrib::fillData(String protocol)
 96                {
 97                    CIMClient client;
 98                    CIMClass cimClass;
 99                    //
100                    // open connection to CIMOM 
101                    //
102                    String hostStr = System::getHostName();
103                
104                    try
105                    {
106 mreddy 1.1.2.1         //
107                        client.connectLocal();
108                
109                        //
110                        Array <CIMInstance> instances;
111                        CIMValue val;
112                        Uint32 pos;
113                        Boolean localOnly=true;
114                        Boolean includeQualifiers=true;
115                        Boolean includeClassOrigin=false;
116                        Boolean deepInheritance=true;
117                        Uint32 len = 0;
118                
119                        // set to true if there is "Other" property value in FunctionsProfilesSupported value.
120                        Boolean functionaProfileDescriptions = false;
121                
122                        instances = client.enumerateInstances 
123                            (PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_OBJECTMANAGER,deepInheritance,localOnly,includeQualifiers,includeClassOrigin);
124                
125                        PEGASUS_ASSERT (instances.size () == 1);
126                
127 mreddy 1.1.2.1         pos = instances[0].findProperty(PROP_ELEMENTNAME);
128                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
129                        val = instances[0].getProperty(pos).getValue ();
130                        serviceHiName = val.toString();
131                
132                        pos = instances[0].findProperty (PROP_DESCRIPTION);
133                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
134                        val = instances[0].getProperty(pos).getValue ();
135                        serviceHiDescription = val.toString();
136                
137                        pos = instances[0].findProperty (PROP_NAME);
138                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
139                        val = instances[0].getProperty(pos).getValue ();
140                        serviceId = val.toString();
141                
142                        instances = client.enumerateInstances 
143                            (PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PG_CIMXMLCOMMUNICATIONMECHANISM,deepInheritance,localOnly,includeQualifiers,includeClassOrigin);
144                
145                        for (Uint32 n=instances.size(),i=0 ; i<n; i++)
146                        {
147                            pos = instances[i].findProperty (PROP_NAMESPACETYPE);
148 mreddy 1.1.2.1             PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
149                            val = instances[i].getProperty(pos).getValue ();
150                            if (val.toString() == protocol) 
151                            {
152                                pos = instances[i].findProperty (PROP_IPADDRESS);
153                                PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
154                                val = instances[i].getProperty(pos).getValue ();
155                                serviceUrl="service:wbem:";
156                                serviceUrl.append(protocol);
157                                serviceUrl.append("://");
158                                serviceUrl.append(val.toString());
159                                break;
160                            }
161                        }
162                
163                        cimClass = client.getClass(PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_CIMNAMESPACE);
164                        instances = client.enumerateInstances 
165                            (PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_CIMNAMESPACE,deepInheritance,localOnly,includeQualifiers,includeClassOrigin);
166                
167                        for (Uint32 n=instances.size(),i=0 ; i<n; i++)
168                        {
169 mreddy 1.1.2.1             pos = instances[i].findProperty (PROP_NAME);
170                            PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
171                            val = instances[i].getProperty(pos).getValue();
172                            nameSpaces.append(val.toString());
173                            nameSpaces.append(",");
174                
175                            pos = instances[i].findProperty (PROP_CLASSINFO);
176                            PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
177                            val = instances[i].getProperty(pos).getValue();
178                            pos = cimClass.findProperty(PROP_CLASSINFO);
179                            classes.append(getMappedValue(cimClass.getProperty(pos),val));
180                            classes.append(",");
181                        }
182                
183                        len = nameSpaces.size(); 
184                        if (len > 0)
185                            nameSpaces.remove( len-1,1);
186                
187                        len = classes.size(); 
188                        if (len > 0)
189                            classes.remove( len-1,1);
190 mreddy 1.1.2.1 
191                        cimClass = client.getClass 
192                           (PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_OBJECTMANAGERCOMMUNICATIONMECHANISM);
193                        instances = client.enumerateInstances 
194                           (PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_OBJECTMANAGERCOMMUNICATIONMECHANISM,deepInheritance,localOnly,includeQualifiers,includeClassOrigin);
195                
196                        pos = instances[0].findProperty (PROP_COMMUNICATIONMECHANISM);
197                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
198                        val = instances[0].getProperty(pos).getValue();
199                        pos = cimClass.findProperty(PROP_COMMUNICATIONMECHANISM);
200                        communicationMechanism = getMappedValue(cimClass.getProperty(pos),val);
201                        pos = instances[0].findProperty (PROP_OTHERCOMMUNICATIONMECHANISMDESCRIPTION);
202                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
203                        val = instances[0].getProperty(pos).getValue ();
204                        otherCommunicationMechanismDescription = val.toString();
205                
206                        interopSchemaNamespace = PG_INTEROP_NAMESPACE;
207                
208                        pos = instances[0].findProperty (PROP_VERSION);
209                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
210                        val = instances[0].getProperty(pos).getValue();
211 mreddy 1.1.2.1         pos = cimClass.findProperty(PROP_VERSION);
212                        protocolVersion = getMappedValue(cimClass.getProperty(pos),val);
213                
214                        pos = instances[0].findProperty (PROP_FUNCTIONALPROFILESSUPPORTED);
215                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
216                        CIMConstProperty constProperty;
217                        constProperty = instances[0].getProperty(pos);
218                        val = constProperty.getValue(); 
219                        Array<Uint16> arrayValFPS;
220                        val.get(arrayValFPS);
221                        pos = cimClass.findProperty(PROP_FUNCTIONALPROFILESSUPPORTED);
222                        for (Uint32 n=arrayValFPS.size(),i=0; i<n; i++)
223                        {
224                            String profileValue = getMappedValue(cimClass.getProperty(pos),CIMValue(arrayValFPS[i]));
225                            if (profileValue == "Other")
226                                functionaProfileDescriptions = true;
227                            functionalProfilesSupported.append(profileValue);
228                            functionalProfilesSupported.append(",");
229                        }
230                        len = functionalProfilesSupported.size(); 
231                        if (len > 0)
232 mreddy 1.1.2.1             functionalProfilesSupported.remove( len-1,1);
233                
234                       if (functionalProfileDescriptions == true)
235                       {
236                           pos = instances[0].findProperty (PROP_FUNCTIONALPROFILEDESCRIPTIONS);
237                           PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
238                           val = instances[0].getProperty(pos).getValue(); 
239                           Array<String> arrayValFPD;
240                           val.get(arrayValFPD);
241                           for (Uint32 n=arrayValFPD.size(),i=0; i<n; i++)
242                           {
243                               functionalProfileDescriptions.append(arrayValFPD[i]);
244                               functionalProfileDescriptions.append(",");
245                           }
246                           len = functionalProfileDescriptions.size(); 
247                           if (len > 0)
248                               functionalProfileDescriptions.remove( len-1,1);
249                        }
250                        pos = instances[0].findProperty (PROP_MULTIPLEOPERATIONSSUPPORTED);
251                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
252                        val = instances[0].getProperty(pos).getValue(); 
253 mreddy 1.1.2.1         Boolean value;
254                        val.get(value);
255                        if (value == true)
256                            multipleOperationsSupported.append("TRUE");
257                        else
258                            multipleOperationsSupported.append("FALSE");
259                
260                        pos = instances[0].findProperty (PROP_AUTHENTICATIONMECHANISMSSUPPORTED);
261                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
262                        val = instances[0].getProperty(pos).getValue(); 
263                        Array<Uint16> arrayValAMS;
264                        val.get(arrayValAMS);
265                        pos = cimClass.findProperty (PROP_AUTHENTICATIONMECHANISMSSUPPORTED);
266                        for (Uint32 n=arrayValAMS.size(),i=0; i<n; i++)
267                        {
268                            authenticationMechanismsSupported.append(getMappedValue(cimClass.getProperty(pos),CIMValue(arrayValAMS[i])));
269                            authenticationMechanismsSupported.append(",");
270                        }
271                        len = authenticationMechanismsSupported.size(); 
272                        if (len > 0)
273                            authenticationMechanismsSupported.remove( len-1,1);
274 mreddy 1.1.2.1 
275                        pos = instances[0].findProperty (PROP_AUTHENTICATIONMECHANISMDESCRIPTIONS);
276                        PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
277                        val = instances[0].getProperty(pos).getValue(); 
278                        Array<String> arrayValAMD;
279                        val.get(arrayValAMD);
280                        for (Uint32 n=arrayValAMD.size(),i=0; i<n; i++)
281                        {
282                            authenticationMechanismDescriptions.append(arrayValAMD[i]);
283                            authenticationMechanismDescriptions.append(",");
284                        }
285                        len = authenticationMechanismDescriptions.size(); 
286                        if (len > 0)
287                            authenticationMechanismDescriptions.remove( len-1,1);
288                        instances = client.enumerateInstances 
289                            (PEGASUS_NAMESPACENAME_INTEROP, CIM_CLASSNAME_REGISTEREDPROFILE,deepInheritance,localOnly,includeQualifiers,includeClassOrigin);
290                
291                        for (Uint32 n=instances.size(),i=0 ; i<n; i++)
292                        {
293                            pos = instances[i].findProperty (PROP_ADVERTISETYPES);
294                            PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
295 mreddy 1.1.2.1             CIMValue cAdvTypes = instances[i].getProperty(pos).getValue();
296                            Array<Uint16> advTypes;
297                            cAdvTypes.get(advTypes); 
298                            for (Uint32 n=advTypes.size(),j = 0; j < n; j++)
299                            {
300                                if(advTypes[j] == 3)
301                                {
302                                    pos = instances[i].findProperty (PROP_OTHERREGISTEREDORGANIZATION);
303                                    PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
304                                    registeredProfiles.append(instances[i].getProperty(pos).getValue().toString());
305                                    registeredProfiles.append(":");
306                                    pos = instances[i].findProperty (PROP_REGISTEREDNAME);
307                                    PEGASUS_ASSERT (pos != PEG_NOT_FOUND);
308                                    registeredProfiles.append(instances[i].getProperty(pos).getValue().toString());
309                                    registeredProfiles.append(",");
310                                    break;
311                                }
312                            }
313                        }
314                
315                        if (instances.size() > 0) 
316 mreddy 1.1.2.1         {
317                            len = registeredProfiles.size(); 
318                            registeredProfiles.remove( len-1,1);
319                        }
320                       else
321                            registeredProfiles.append("");
322                    }
323                
324                    catch(CIMException& e)
325                    {
326                        Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
327                            "SLP Registration Failed. CIMException. $0", e.getMessage());
328                    }
329                
330                    catch(Exception& e)
331                    {
332                        Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
333                            "SLP Registration Failed Startup: CIMException exception. $0", e.getMessage());
334                    }
335                    client.disconnect();
336                    return;
337 mreddy 1.1.2.1 } 
338                
339                // Map Values to ValueMap
340                String SLPAttrib::getMappedValue(const CIMProperty& cimProperty, CIMValue value)
341                {
342                    String retValue;
343                    Uint16 localValue;
344                
345                    if (strcmp(cimTypeToString(value.getType()),"string") == 0)
346                       value.get(retValue);
347                    else
348                    {
349                        value.get(localValue);
350                        retValue = Formatter::format("$0",localValue);
351                    }
352                
353                    Uint32 posValueMap;
354                
355                    if ((posValueMap = cimProperty.findQualifier(CIMName("ValueMap"))) == PEG_NOT_FOUND)
356                    {
357                        return retValue;
358 mreddy 1.1.2.1     }
359                    CIMConstQualifier qValueMap = cimProperty.getQualifier(posValueMap);
360                    if (!qValueMap.isArray() || (qValueMap.getType() != CIMTYPE_STRING))
361                    {
362                        return retValue;
363                    }
364                 
365                    CIMValue q1 = qValueMap.getValue();
366                    Array<String> val;
367                    q1.get(val);
368                
369                    Uint32 posValue;
370                    if ((posValue = cimProperty.findQualifier("Values")) == PEG_NOT_FOUND)
371                    {
372                        return retValue;
373                    }
374                
375                    CIMConstQualifier qValue = cimProperty.getQualifier(posValue);
376                    if (!qValue.isArray() || (qValue.getType() != CIMTYPE_STRING))
377                    {
378                        return retValue;
379 mreddy 1.1.2.1     }
380                
381                    CIMValue q2 = qValue.getValue();
382                    Array<String> va2;
383                    q2.get(va2);
384                
385                    if (va2.size() != val.size())
386                    {
387                        return retValue;
388                    }
389                
390                    for (Uint32 n=val.size(),i = 0; i < n; i++)
391                    {
392                        if(retValue == val[i])
393                        {
394                            return (va2[i]);
395                        }
396                    }
397                        return retValue;
398                }
399                
400 mreddy 1.1.2.1 // Form the attributes String.
401                void SLPAttrib::formAttributes()
402                {
403                
404                    attributes.append(Formatter::format(
405                                        "(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),",
406                                         serviceUrl,serviceHiName,
407                                         serviceHiDescription,serviceId,
408                                         nameSpaces,classes,
409                                         communicationMechanism,
410                                         otherCommunicationMechanismDescription,
411                                         interopSchemaNamespace,
412                                         protocolVersion));
413                
414                    attributes.append(Formatter::format(
415                                         "(FunctionalProfilesSupported=$0),(FunctionalProfileDescriptions=$1),(MultipleOperationsSupported=$2),(AuthenticationMechanismsSupported=$3),(AuthenticationMechanismDescriptions=$4),(RegisteredProfilesSupported=$5)",
416                                         functionalProfilesSupported,
417                                         functionalProfileDescriptions,
418                                         multipleOperationsSupported,
419                                         authenticationMechanismsSupported,
420                                         authenticationMechanismDescriptions,
421 mreddy 1.1.2.1                          registeredProfiles));
422                
423                    if (attributes.size() > 7900)
424                    {
425                	//truncate the attributes
426                	attributes = attributes.subString(0,7900);
427                	Uint32 index = attributes.reverseFind(')');
428                	attributes= attributes.subString(0,index+1);
429                    }
430                    return;
431                }
432                PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2