1 r.kieninger 1.1.2.1 //%LICENSE////////////////////////////////////////////////////////////////
2 //
3 // 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 //
10 // 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 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 r.kieninger 1.1.2.1 // 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 //
28 //////////////////////////////////////////////////////////////////////////
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include "CMPI_Version.h"
33
34 #include "CMPI_String.h"
35 #include "CMPI_Value.h"
36 #include "CMPISCMOUtilities.h"
37
|
38 r.kieninger 1.1.2.6 #include <Pegasus/Common/Tracer.h>
|
39 r.kieninger 1.1.2.11 #include <Pegasus/Common/CIMDateTimeInline.h>
40 #include <Pegasus/Common/StringConversion.h>
|
41 r.kieninger 1.1.2.6
|
42 r.kieninger 1.1.2.1 PEGASUS_USING_STD;
43 PEGASUS_NAMESPACE_BEGIN
44
45 CIMDateTimeRep* CMPISCMOUtilities::scmoDateTimeFromCMPI(CMPIDateTime* cmpidt)
46 {
47 CIMDateTimeRep* cimdt = 0;
48
49 if (cmpidt && cmpidt->hdl)
50 {
51 cimdt = ((CIMDateTime*)cmpidt->hdl)->_rep;
52 }
53 return cimdt;
54 }
55
|
56 r.kieninger 1.1.2.6
57 // Function to copy all key bindings from one SCMOInstance to another
58 CMPIrc CMPISCMOUtilities::copySCMOKeyProperties( const SCMOInstance* sourcePath,
59 SCMOInstance* targetPath )
60 {
61 PEG_METHOD_ENTER(
62 TRC_CMPIPROVIDERINTERFACE,
63 "CMPISCMOUtilities::copySCMOKeyProperties()");
64
|
65 marek 1.1.2.9 if ((0!=sourcePath) && (0!=targetPath))
|
66 r.kieninger 1.1.2.6 {
67 SCMO_RC rc;
68 const char* keyName = 0;
69 const SCMBUnion* keyValue = 0;
70 CIMType keyType;
71
72 Uint32 numKeys = sourcePath->getKeyBindingCount();
73 for (Uint32 x=0; x < numKeys; x++)
74 {
75 rc = sourcePath->getKeyBindingAt(
76 x, &keyName, keyType, &keyValue);
|
77 r.kieninger 1.1.2.10 if (rc==SCMO_OK)
|
78 r.kieninger 1.1.2.6 {
|
79 r.kieninger 1.1.2.10 rc = targetPath->setKeyBinding(
80 keyName, keyType, keyValue);
|
81 r.kieninger 1.1.2.12 if (keyType == CIMTYPE_STRING)
82 {
83 free((void*)keyValue);
84 }
|
85 r.kieninger 1.1.2.10 if (rc != SCMO_OK)
86 {
87 PEG_TRACE_CSTRING(
88 TRC_CMPIPROVIDERINTERFACE,
89 Tracer::LEVEL2,
90 "Failed to set keybinding");
91 PEG_METHOD_EXIT();
92 return CMPI_RC_ERR_FAILED;
93 }
94 }
95 else
96 {
97 if (rc!=SCMO_NULL_VALUE)
98 {
99 PEG_TRACE_CSTRING(
100 TRC_CMPIPROVIDERINTERFACE,
101 Tracer::LEVEL2,
102 "Failed to retrieve keybinding");
103 PEG_METHOD_EXIT();
104 return CMPI_RC_ERR_FAILED;
105 }
|
106 r.kieninger 1.1.2.6 }
107 }
108 }
109 else
110 {
111 PEG_TRACE_CSTRING(
112 TRC_CMPIPROVIDERINTERFACE,
113 Tracer::LEVEL1,
114 "Called with Nullpointer for source or target");
115 PEG_METHOD_EXIT();
116 return CMPI_RC_ERR_FAILED;
117 }
118
119 return CMPI_RC_OK;
120 }
121
|
122 r.kieninger 1.1.2.4 // Function to convert a CIMInstance into an SCMOInstance
123 // CAUTION: This function requires access to the CMPIClassCache, and
124 // therefore can only be called from within a CMPI provider !!!
125 SCMOInstance* CMPISCMOUtilities::getSCMOFromCIMInstance(
|
126 r.kieninger 1.1.2.5 const CIMInstance& cimInst,
127 const char* ns,
128 const char* cls)
|
129 r.kieninger 1.1.2.4 {
130 const CIMObjectPath& cimPath = cimInst.getPath();
|
131 r.kieninger 1.1.2.5
132 const CString nameSpace = cimPath.getNameSpace().getString().getCString();
133 const CString className = cimPath.getClassName().getString().getCString();
|
134 r.kieninger 1.1.2.7
|
135 marek 1.1.2.9 if (!ns)
|
136 r.kieninger 1.1.2.7 {
137 ns = (const char*)nameSpace;
138 }
|
139 marek 1.1.2.9 if (!cls)
|
140 r.kieninger 1.1.2.7 {
141 cls = (const char*)className;
142 }
143
|
144 r.kieninger 1.1.2.13 SCMOInstance* scmoInst=0;
145
|
146 r.kieninger 1.1.2.10 SCMOClass* scmoClass = mbGetSCMOClass(ns,strlen(ns),cls,strlen(cls));
|
147 r.kieninger 1.1.2.7
|
148 r.kieninger 1.1.2.13 if (0 != scmoClass)
|
149 r.kieninger 1.1.2.7 {
|
150 r.kieninger 1.1.2.13 scmoInst = new SCMOInstance(*scmoClass, cimInst);
|
151 r.kieninger 1.1.2.7 }
|
152 r.kieninger 1.1.2.13 else
|
153 r.kieninger 1.1.2.7 {
|
154 r.kieninger 1.1.2.13 SCMOClass localDirtySCMOClass(cls,ns);
155 scmoInst = new SCMOInstance(localDirtySCMOClass, cimInst);
|
156 r.kieninger 1.1.2.7 scmoInst->markAsCompromised();
157 }
158
|
159 r.kieninger 1.1.2.4 return scmoInst;
160 }
161
162 // Function to convert a CIMObjectPath into an SCMOInstance
163 // CAUTION: This function requires access to the CMPIClassCache, and
164 // therefore can only be called from within a CMPI provider !!!
165 SCMOInstance* CMPISCMOUtilities::getSCMOFromCIMObjectPath(
|
166 r.kieninger 1.1.2.5 const CIMObjectPath& cimPath,
167 const char* ns,
168 const char* cls)
|
169 r.kieninger 1.1.2.4 {
170 CString nameSpace = cimPath.getNameSpace().getString().getCString();
171 CString className = cimPath.getClassName().getString().getCString();
|
172 r.kieninger 1.1.2.12 SCMOInstance* scmoRef;
|
173 r.kieninger 1.1.2.7
|
174 marek 1.1.2.9 if (!ns)
|
175 r.kieninger 1.1.2.7 {
176 ns = (const char*)nameSpace;
177 }
|
178 marek 1.1.2.9 if (!cls)
|
179 r.kieninger 1.1.2.7 {
180 cls = (const char*)className;
181 }
182
183
|
184 r.kieninger 1.1.2.10 SCMOClass* scmoClass = mbGetSCMOClass(ns,strlen(ns),cls,strlen(cls));
|
185 r.kieninger 1.1.2.7
|
186 r.kieninger 1.1.2.13 if (0 != scmoClass)
|
187 r.kieninger 1.1.2.7 {
|
188 r.kieninger 1.1.2.13 scmoRef = new SCMOInstance(*scmoClass, cimPath);
|
189 r.kieninger 1.1.2.7 }
|
190 r.kieninger 1.1.2.12 else
|
191 r.kieninger 1.1.2.7 {
|
192 r.kieninger 1.1.2.13 SCMOClass localDirtySCMOClass(cls,ns);
193 scmoRef = new SCMOInstance(localDirtySCMOClass, cimPath);
194 scmoRef->markAsCompromised();
|
195 r.kieninger 1.1.2.7 }
|
196 r.kieninger 1.1.2.4
|
197 r.kieninger 1.1.2.12
|
198 r.kieninger 1.1.2.4 return scmoRef;
199 }
200
|
201 r.kieninger 1.1.2.11 // Converts SCMOUnion values to CMPIData for keys.
202 // Includes special handling for the following types:
203 // Real32/64 -> Converted to CMPI_String
204 // DateTime -> Converted to CMPI_String
205 CMPIrc CMPISCMOUtilities::scmoValue2CMPIKeyData(
206 const SCMBUnion* scmoValue,
207 CMPIType type,
208 CMPIData *data)
209 {
210 //Initialize CMPIData object
211 data->type = type;
212 data->value.uint64 = 0;
213 data->state = CMPI_goodValue|CMPI_keyValue;
214
215 //Check for NULL CIMValue
216 if( scmoValue == 0 )
217 {
218 data->state |= CMPI_nullValue;
219 return CMPI_RC_OK;
220 }
221
222 r.kieninger 1.1.2.11 switch (type)
223 {
224 case CMPI_uint8:
225 data->value.uint64=(CMPIUint64)scmoValue->simple.val.u8;
226 data->type=CMPI_keyInteger;
227 break;
228 case CMPI_uint16:
229 data->value.uint64=(CMPIUint64)scmoValue->simple.val.u16;
230 data->type=CMPI_keyInteger;
231 break;
232 case CMPI_uint32:
233 data->value.uint64=(CMPIUint64)scmoValue->simple.val.u32;
234 data->type=CMPI_keyInteger;
235 break;
236 case CMPI_uint64:
237 data->value.uint64=scmoValue->simple.val.u64;
238 data->type=CMPI_keyInteger;
239 break;
240 case CMPI_sint8:
241 data->value.sint64=(CMPISint64)scmoValue->simple.val.s8;
242 data->type=CMPI_keyInteger;
243 r.kieninger 1.1.2.11 break;
244 case CMPI_sint16:
245 data->value.sint64=(CMPISint64)scmoValue->simple.val.s16;
246 data->type=CMPI_keyInteger;
247 break;
248 case CMPI_sint32:
249 data->value.sint64=(CMPISint64)scmoValue->simple.val.s32;
250 data->type=CMPI_keyInteger;
251 break;
252 case CMPI_sint64:
253 data->value.sint64=scmoValue->simple.val.s64;
254 data->type=CMPI_keyInteger;
255 break;
256 case CMPI_char16:
257 data->value.uint64=(CMPIUint64)scmoValue->simple.val.c16;
258 data->type=CMPI_keyInteger;
259 break;
260 case CMPI_boolean:
261 data->value.boolean=scmoValue->simple.val.bin;
262 data->type=CMPI_keyBoolean;
263 break;
264 r.kieninger 1.1.2.11
265 case CMPI_real32:
266 {
267 char buffer[128];
268 Uint32 size=0;
269 Real32ToString(buffer, scmoValue->simple.val.r32, size);
270 data->value.string = reinterpret_cast<CMPIString*>(
271 new CMPI_Object(buffer));
272 data->type=CIMKeyBinding::STRING;
273 break;
274 }
275
276 case CMPI_real64:
277 {
278 char buffer[128];
279 Uint32 size=0;
280 Real64ToString(buffer, scmoValue->simple.val.r64, size);
281 data->value.string = reinterpret_cast<CMPIString*>(
282 new CMPI_Object(buffer));
283 data->type=CIMKeyBinding::STRING;
284 break;
285 r.kieninger 1.1.2.11 }
286
287 case CMPI_charsptr:
288 case CMPI_chars:
289 case CMPI_string:
290 {
291 if (scmoValue->extString.pchar)
292 {
293 data->value.string = reinterpret_cast<CMPIString*>(
294 new CMPI_Object(scmoValue->extString.pchar));
295 data->type = CMPI_string;
296 }
297 else
298 {
299 data->state|=CMPI_nullValue;
300 }
301 data->type=CMPI_keyString;
302 break;
303 }
304
305 case CMPI_dateTime:
306 r.kieninger 1.1.2.11 {
307 char buffer[26];
308 _DateTimetoCStr(scmoValue->dateTimeValue, buffer);
309 data->value.string = reinterpret_cast<CMPIString*>(
310 new CMPI_Object(buffer));
311 data->type=CIMKeyBinding::STRING;
312 break;
313 }
314
315 case CMPI_ref:
316 {
317 SCMOInstance* ref =
318 new SCMOInstance(*(scmoValue->extRefPtr));
319 data->value.ref = reinterpret_cast<CMPIObjectPath*>
320 (new CMPI_Object(
321 ref,
322 CMPI_Object::ObjectTypeObjectPath));
323 }
324 break;
325
326 default:
327 r.kieninger 1.1.2.11 {
328 // Not supported for this CMPItype
329 data->state = CMPI_badValue;
330 return CMPI_RC_ERR_NOT_SUPPORTED;
331 break;
332 }
333 }
334
335 if (!(type&CMPI_ENC))
336 {
337 // For non-encapsulated type simply verify that we have a valid value
338 // otherwise set to CMPI_nullValue
339 if (!scmoValue->simple.hasValue)
340 {
341 data->value.uint64 = 0;
342 data->state = CMPI_nullValue;
343 }
344 }
345
346 return CMPI_RC_OK;
347 }
348 r.kieninger 1.1.2.11
349
|
350 r.kieninger 1.1.2.1 // Function to convert a SCMO Value into a CMPIData structure
351 CMPIrc CMPISCMOUtilities::scmoValue2CMPIData(
|
352 marek 1.1.2.9 const SCMBUnion* scmoValue,
353 CMPIType type,
354 CMPIData *data,
|
355 r.kieninger 1.1.2.3 Uint32 arraySize)
|
356 r.kieninger 1.1.2.1 {
357 //Initialize CMPIData object
358 data->type = type;
359 data->value.uint64 = 0;
|
360 r.kieninger 1.1.2.3 data->state = CMPI_goodValue;
|
361 r.kieninger 1.1.2.1
362 //Check for NULL CIMValue
363 if( scmoValue == 0 )
364 {
|
365 r.kieninger 1.1.2.3 data->state = CMPI_nullValue;
|
366 r.kieninger 1.1.2.1 return CMPI_RC_OK;
367 }
368
369 if (type & CMPI_ARRAY)
370 {
|
371 r.kieninger 1.1.2.3 // Get the type of the element of the CMPIArray
372 CMPIType aType = type&~CMPI_ARRAY;
373
374 //Allocate CMPIData array to hold the values
375 CMPIData *arrayRoot = new CMPIData[arraySize+1];
376
377 // Advance array pointer to first array element
378 CMPIData *aData = arrayRoot;
379 aData++;
380
381 // Set the type, state and value of array elements
382 for( Uint32 i=0; i<arraySize; i++ )
383 {
384 CMPIrc rc = scmoValue2CMPIData(&(scmoValue[i]),aType,&(aData[i]));
385 if (rc != CMPI_RC_OK)
386 {
387 return rc;
388 }
389 }
390
391 // Create array encapsulation object
392 r.kieninger 1.1.2.3 arrayRoot->type = aType;
393 arrayRoot->value.sint32 = arraySize;
394 CMPI_Array *arr = new CMPI_Array(arrayRoot);
395
396 // Set the encapsulated array as data
|
397 marek 1.1.2.9 data->value.array =
|
398 r.kieninger 1.1.2.3 reinterpret_cast<CMPIArray*>(new CMPI_Object(arr));
|
399 r.kieninger 1.1.2.1 }
400 else
401 {
|
402 r.kieninger 1.1.2.3 // Check for encpsulated type, which need special handling
403 if (type&CMPI_ENC)
|
404 r.kieninger 1.1.2.1 {
|
405 r.kieninger 1.1.2.3 switch (type)
|
406 r.kieninger 1.1.2.1 {
|
407 r.kieninger 1.1.2.3 case CMPI_chars:
408 case CMPI_string:
|
409 r.kieninger 1.1.2.2 {
|
410 r.kieninger 1.1.2.3 if (scmoValue->extString.pchar)
411 {
412 data->value.string = reinterpret_cast<CMPIString*>(
413 new CMPI_Object(scmoValue->extString.pchar));
414 data->type = CMPI_string;
415 }
416 else
417 {
418 data->state=CMPI_nullValue;
419 }
420 break;
|
421 r.kieninger 1.1.2.2 }
|
422 r.kieninger 1.1.2.3
423 case CMPI_dateTime:
|
424 r.kieninger 1.1.2.2 {
|
425 marek 1.1.2.9 CIMDateTime* cimdt =
|
426 r.kieninger 1.1.2.3 new CIMDateTime(&scmoValue->dateTimeValue);
427 data->value.dateTime = reinterpret_cast<CMPIDateTime*>
428 (new CMPI_Object(cimdt));
429 break;
|
430 r.kieninger 1.1.2.2 }
|
431 r.kieninger 1.1.2.1
|
432 r.kieninger 1.1.2.3 case CMPI_ref:
433 {
|
434 marek 1.1.2.9 SCMOInstance* ref =
|
435 r.kieninger 1.1.2.4 new SCMOInstance(*(scmoValue->extRefPtr));
|
436 r.kieninger 1.1.2.3 data->value.ref = reinterpret_cast<CMPIObjectPath*>
|
437 r.kieninger 1.1.2.8 (new CMPI_Object(
438 ref,
439 CMPI_Object::ObjectTypeObjectPath));
|
440 r.kieninger 1.1.2.3 }
|
441 r.kieninger 1.1.2.1 break;
442
|
443 r.kieninger 1.1.2.3 case CMPI_instance:
444 {
|
445 marek 1.1.2.9 SCMOInstance* inst =
|
446 r.kieninger 1.1.2.4 new SCMOInstance(*(scmoValue->extRefPtr));
|
447 r.kieninger 1.1.2.3 data->value.inst = reinterpret_cast<CMPIInstance*>
|
448 r.kieninger 1.1.2.8 (new CMPI_Object(
|
449 marek 1.1.2.9 inst,
|
450 r.kieninger 1.1.2.8 CMPI_Object::ObjectTypeInstance));
|
451 r.kieninger 1.1.2.3 }
452 break;
453 default:
454 {
455 // Not supported for this CMPItype
456 return CMPI_RC_ERR_NOT_SUPPORTED;
457 break;
458 }
|
459 r.kieninger 1.1.2.1 }
|
460 r.kieninger 1.1.2.3 }
461 else
462 {
463 // For non-encapsulated type simply copy the first 64bit
464 // of the SCMBUnion to CMPIValue
465 if (scmoValue->simple.hasValue)
|
466 r.kieninger 1.1.2.1 {
|
467 r.kieninger 1.1.2.3 data->value.uint64 = scmoValue->simple.val.u64;
|
468 r.kieninger 1.1.2.1 }
|
469 r.kieninger 1.1.2.3 else
|
470 r.kieninger 1.1.2.1 {
|
471 r.kieninger 1.1.2.3 data->value.uint64 = 0;
472 data->state = CMPI_nullValue;
|
473 r.kieninger 1.1.2.1 }
474 }
475 }
476 return CMPI_RC_OK;
477 }
478
479 PEGASUS_NAMESPACE_END
480
|