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