1 karl 1.28 //%2006////////////////////////////////////////////////////////////////////////
|
2 schuur 1.1 //
|
3 karl 1.14 // 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 schuur 1.1 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.14 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.16 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.28 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 schuur 1.1 //
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 karl 1.28 //
|
21 schuur 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // 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 r.kieninger 1.27 #include <Pegasus/Common/CIMNameUnchecked.h>
|
35 mike 1.29 #include <Pegasus/Common/AutoPtr.h>
|
36 schuur 1.4 #include "CMPI_Version.h"
|
37 schuur 1.2
|
38 schuur 1.1 #include "CMPI_Instance.h"
39 #include "CMPI_Broker.h"
40 #include "CMPI_Value.h"
41 #include "CMPI_String.h"
42
43 #include <Pegasus/Common/InternalException.h>
|
44 konrad.r 1.18 #include <Pegasus/Common/System.h>
|
45 mike 1.29 #include <Pegasus/Common/Mutex.h>
|
46 schuur 1.1 #include <string.h>
|
47 dave.sudlik 1.23 #include <new>
|
48 schuur 1.1
49 PEGASUS_USING_STD;
50 PEGASUS_NAMESPACE_BEGIN
51
|
52 konrad.r 1.26 extern int _cmpi_trace;
53
|
54 schuur 1.12 extern "C" {
55
56 static CMPIStatus instRelease(CMPIInstance* eInst) {
57 CIMInstance* inst=(CIMInstance*)eInst->hdl;
58 if (inst) {
59 delete inst;
60 (reinterpret_cast<CMPI_Object*>(eInst))->unlinkAndDelete();
61 }
62 CMReturn(CMPI_RC_OK);
|
63 schuur 1.1 }
64
|
65 schuur 1.12 static CMPIStatus instReleaseNop(CMPIInstance* eInst) {
66 CMReturn(CMPI_RC_OK);
67 }
|
68 schuur 1.1
|
69 konrad.r 1.19 static CMPIInstance* instClone(const CMPIInstance* eInst, CMPIStatus* rc) {
|
70 david.dillard 1.21 if (!eInst->hdl) {
71 if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
72 return NULL;
73 }
|
74 schuur 1.12 CIMInstance* inst=(CIMInstance*)eInst->hdl;
|
75 vijay.eli 1.22 try {
76 AutoPtr<CIMInstance> cInst(new CIMInstance(inst->clone()));
77 AutoPtr<CMPI_Object> obj(new CMPI_Object(cInst.get()));
78 cInst.release();
79 obj->unlink();
80 if (rc) CMSetStatus(rc,CMPI_RC_OK);
81 return reinterpret_cast<CMPIInstance *>(obj.release());
|
82 dave.sudlik 1.23 } catch(const PEGASUS_STD(bad_alloc)&) {
|
83 vijay.eli 1.22 if (rc) CMSetStatus(rc, CMPI_RC_ERROR_SYSTEM);
84 return NULL;
85 }
|
86 schuur 1.1 }
87
|
88 mike 1.32.4.1 static CMPIData instGetPropertyAt(
89 const CMPIInstance* eInst,
90 CMPICount pos,
91 CMPIString** name,
92 CMPIStatus* rc)
93 {
|
94 schuur 1.12 CIMInstance* inst=(CIMInstance*)eInst->hdl;
95 CMPIData data={0,CMPI_nullValue,{0}};
|
96 schuur 1.1
|
97 david.dillard 1.21 if (!inst) {
98 if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
99 return data;
100 }
|
101 konrad.r 1.15
|
102 schuur 1.12 if (pos>inst->getPropertyCount()) {
103 if (rc) CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
104 CMPIData data={0,CMPI_nullValue|CMPI_notFound,{0}};
105 return data;
106 }
107 const CIMProperty& p=inst->getProperty(pos);
108 const CIMValue& v=p.getValue();
109 CIMType pType=p.getType();
110 CMPIType t=type2CMPIType(pType,p.isArray());
|
111 schuur 1.1
|
112 schuur 1.12 value2CMPIData(v,t,&data);
|
113 schuur 1.1
|
114 schuur 1.12 if (name) {
115 String str=p.getName().getString();
116 *name=(CMPIString*)string2CMPIString(str);
117 }
|
118 schuur 1.1
119 if (rc) CMSetStatus(rc,CMPI_RC_OK);
|
120 schuur 1.12 return data;
|
121 schuur 1.1 }
122
|
123 mike 1.32.4.1 static CMPIData instGetProperty(
124 const CMPIInstance* eInst,
125 const char *name,
126 CMPIStatus* rc)
127 {
|
128 konrad.r 1.15
129 CMPIData data={0,CMPI_nullValue|CMPI_notFound,{0}};
130
|
131 david.dillard 1.21 if (!eInst->hdl) {
132 if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
133 return data;
134 }
|
135 schuur 1.12 CIMInstance* inst=(CIMInstance*)eInst->hdl;
136 Uint32 pos=inst->findProperty(String(name));
137
138 if (pos!=PEG_NOT_FOUND) {
139 if (rc) CMSetStatus(rc,CMPI_RC_OK);
140 return instGetPropertyAt(eInst,pos,NULL,rc);
141 }
142 if (rc) CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
143 return data;
144 }
|
145 schuur 1.1
146
|
147 mike 1.32.4.1 static CMPICount instGetPropertyCount(
148 const CMPIInstance* eInst,
149 CMPIStatus* rc)
150 {
|
151 schuur 1.12 CIMInstance* inst=(CIMInstance*)eInst->hdl;
|
152 david.dillard 1.21 if (!inst) {
153 if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
154 return 0;
155 }
|
156 schuur 1.12 if (rc) CMSetStatus(rc,CMPI_RC_OK);
157 return inst->getPropertyCount();
|
158 schuur 1.1 }
159
|
160 dave.sudlik 1.31 static CMPIStatus instSetPropertyWithOrigin(const CMPIInstance* eInst,
161 const char* name, const CMPIValue* data, const CMPIType type,
162 const char* origin)
163 {
|
164 schuur 1.12 CIMInstance *inst=(CIMInstance*)eInst->hdl;
|
165 david.dillard 1.21 if (!inst) {
166 CMReturn(CMPI_RC_ERR_INVALID_PARAMETER);
167 }
|
168 konrad.r 1.19 char **list=(char**)(reinterpret_cast<const CMPI_Object*>(eInst))->priv;
|
169 schuur 1.12 CMPIrc rc;
170
171 if (list) {
172 while (*list) {
|
173 konrad.r 1.18 if (System::strcasecmp(name,*list)==0) goto ok;
|
174 schuur 1.12 list++;
175 }
176 CMReturn(CMPI_RC_OK);
177 }
178
179 ok:
180 CIMValue v=value2CIMValue(data,type,&rc);
|
181 r.kieninger 1.27 CIMNameUnchecked sName(name);
|
182 schuur 1.12 Uint32 pos;
183 int count=0;
184
|
185 mike 1.32.4.1 if ((pos=inst->findProperty(sName))!=PEG_NOT_FOUND)
186 {
|
187 schuur 1.12 CIMProperty cp=inst->getProperty(pos);
|
188 mike 1.32.4.1
189 // The CMPI interface uses the type "CMPI_instance" to represent both
190 // embedded objects and embedded instances. CMPI has no "CMPI_object"
191 // type. So when converting a CMPIValue with type "CMPI_instance" to
192 // a CIMValue (see value2CIMValue) the type CIMTYPE_OBJECT is always
193 // used. If the property's type is CIMTYPE_INSTANCE, and the value's
194 // type is CIMTYPE_OBJECT, then we convert the value's type to match
195 // the property's type.
|
196 venkat.puvvada 1.32.4.3 if (cp.getType() == CIMTYPE_INSTANCE &&
197 v.getType() == CIMTYPE_OBJECT)
|
198 mike 1.32.4.1 {
|
199 venkat.puvvada 1.32.4.3 if (cp.isArray())
200 {
201 if (!v.isArray())
202 {
203 CMReturn(CMPI_RC_ERR_TYPE_MISMATCH);
204 }
205 Array<CIMObject> tmpObjs;
206 Array<CIMInstance> tmpInsts;
207 v.get(tmpObjs);
208 for (Uint32 i = 0; i < tmpObjs.size() ; ++i)
209 {
210 tmpInsts.append(CIMInstance(tmpObjs[i]));
211 }
212 v.set(tmpInsts);
213 }
214 else
215 {
216 CIMObject co;
217 v.get(co);
218 if (co.isInstance())
219 v.set(CIMInstance(co));
220 venkat.puvvada 1.32.4.3 }
|
221 mike 1.32.4.1 }
222
223 try
224 {
|
225 schuur 1.12 cp.setValue(v);
|
226 dave.sudlik 1.31 if (origin)
227 {
228 CIMName oName(origin);
229 cp.setClassOrigin(oName);
230 }
|
231 schuur 1.12 }
|
232 konrad.r 1.20 catch (const TypeMismatchException &) {
|
233 mike 1.32.4.1 if (_cmpi_trace) {
|
234 schuur 1.13 cerr<<"-+- TypeMisMatch exception for: "<<name<<endl;
|
235 konrad.r 1.26 if (getenv("PEGASUS_CMPI_CHECKTYPES")!=NULL) {
|
236 schuur 1.12 cerr<<"-+- Aborting because of CMPI_CHECKTYPES"<<endl;
|
237 schuur 1.13 abort();
|
238 konrad.r 1.26 }
|
239 mike 1.32.4.1 }
|
240 schuur 1.12 CMReturn(CMPI_RC_ERR_TYPE_MISMATCH);
241 }
|
242 dave.sudlik 1.31 catch (const InvalidNameException &) {
|
243 mike 1.32.4.1 if (_cmpi_trace) {
|
244 dave.sudlik 1.31 cerr<<"-+- InvalidName exception for: "<<origin<<endl;
|
245 mike 1.32.4.1 }
|
246 dave.sudlik 1.31 CMReturn(CMPI_RC_ERR_INVALID_PARAMETER);
247 }
|
248 konrad.r 1.19 catch (const Exception &e) {
|
249 mike 1.32.4.1 if (_cmpi_trace) {
|
250 konrad.r 1.26 cerr<<"-+- "<<e.getMessage()<<" exception for: "<<name<<endl;
251 if (getenv("PEGASUS_CMPI_CHECKTYPES")!=NULL) {
252 cerr<<"-+- Aborting because of CMPI_CHECKTYPES"<<endl;
253 abort();
254 }
|
255 schuur 1.13 }
|
256 schuur 1.12 CMReturnWithString(CMPI_RC_ERR_FAILED,
|
257 david.dillard 1.21 reinterpret_cast<CMPIString*>(new CMPI_Object(e.getMessage())));
|
258 schuur 1.12 }
259 }
260 else {
|
261 dave.sudlik 1.31 if (type==CMPI_ref)
262 {
263 CIMObjectPath *ref=(CIMObjectPath*)(data->ref->hdl);
264 if (origin)
265 {
266 CIMName oName(origin);
267 inst->addProperty(CIMProperty(sName,v,count,
268 ref->getClassName(),oName));
269 }
270 else
271 {
272 inst->addProperty(CIMProperty(sName,v,count,
273 ref->getClassName()));
274 }
275 }
276 else
277 {
278 if (origin)
279 {
280 CIMName oName(origin);
281 inst->addProperty(CIMProperty(sName,v,count,CIMName(),oName));
282 dave.sudlik 1.31 }
283 else
284 {
285 inst->addProperty(CIMProperty(sName,v,count));
286 }
|
287 schuur 1.12 }
|
288 schuur 1.1 }
|
289 schuur 1.12 CMReturn(CMPI_RC_OK);
|
290 schuur 1.1 }
|
291 schuur 1.12
|
292 dave.sudlik 1.31 static CMPIStatus instSetProperty(const CMPIInstance* eInst,
293 const char *name, const CMPIValue* data, CMPIType type)
294 {
295 return instSetPropertyWithOrigin(eInst, name, data, type, NULL);
296 }
297
|
298 vijay.eli 1.22 static CMPIObjectPath* instGetObjectPath(const CMPIInstance* eInst,
299 CMPIStatus* rc) {
|
300 schuur 1.12 CIMInstance* inst=(CIMInstance*)eInst->hdl;
|
301 david.dillard 1.21 if (!inst) {
302 if (rc) CMSetStatus(rc, CMPI_RC_ERR_INVALID_PARAMETER);
303 return NULL;
304 }
|
305 schuur 1.12 const CIMObjectPath &clsRef=inst->getPath();
|
306 vijay.eli 1.22 AutoPtr<CIMObjectPath> objPath(NULL);
307 AutoPtr<CMPI_Object> obj(NULL);
308 try {
|
309 venkat.puvvada 1.32.4.2 /* Check if NameSpace is NULL before calling GetClass. When
310 providers run out-of-process and getClass request is made
311 through CIMClient, CIMOperationRequestEncoder tries to
312 encode the request and finds the namespace is invalid
313 (empty) and throws InvalidNamespaceNameException.
314 */
315
316 if (clsRef.getKeyBindings().size()==0 &&
317 !clsRef.getNameSpace().isNull())
318 {
|
319 vijay.eli 1.22 CIMClass *cc=mbGetClass(CMPI_ThreadContext::getBroker(),clsRef);
|
320 mike 1.32.4.1 // It seems that when converting the CIMInstnace to XML form, we
321 // miss CIMObjectPath from it. When we don't have namespace we
322 // may not get class, so make ObjectPath with class-name only.
323 // TODO: This will create problems when passing the
324 // EmbeddedInstances as arguements to MethodProviders, where it
325 // needs to get ObjectPath from instance. Shall we need to
326 // include CIMObjectPath in CIMInstance while converting to XML
327 // form ??? ...
|
328 dave.sudlik 1.30 if (!cc)
329 {
330 objPath.reset(new CIMObjectPath(clsRef));
331 }
332 else
333 {
334 const CIMObjectPath &ref=inst->buildPath(
335 *(reinterpret_cast<const CIMConstClass*>(cc)));
336 objPath.reset(new CIMObjectPath(ref));
337 }
|
338 vijay.eli 1.22 }
339 else
340 objPath.reset(new CIMObjectPath(clsRef));
341 obj.reset(new CMPI_Object(objPath.get()));
342 objPath.release();
343 if (rc) CMSetStatus(rc,CMPI_RC_OK);
344 return reinterpret_cast<CMPIObjectPath*> (obj.release());
|
345 dave.sudlik 1.23 } catch(const PEGASUS_STD(bad_alloc)&) {
|
346 vijay.eli 1.22 if (rc) CMSetStatus(rc, CMPI_RC_ERROR_SYSTEM);
347 return NULL;
|
348 schuur 1.1 }
349 }
|
350 vijay.eli 1.22
|
351 mike 1.32.4.1 static CMPIStatus instSetObjectPath(
352 CMPIInstance* eInst,
353 const CMPIObjectPath *obj)
|
354 konrad.r 1.19 {
|
355 konrad.r 1.24 CIMInstance* inst=(CIMInstance*)eInst->hdl;
356 if ((inst==NULL) || (obj==NULL)) {
357 CMReturn ( CMPI_RC_ERR_INVALID_PARAMETER);
358 }
359 CIMObjectPath &ref = *(CIMObjectPath*)(obj->hdl);
|
360 mike 1.32.4.1 try {
361 inst->setPath(ref);
|
362 konrad.r 1.24 } catch (const TypeMismatchException &e) {
|
363 mike 1.32.4.1 CMReturnWithString(CMPI_RC_ERR_FAILED,
|
364 konrad.r 1.24 reinterpret_cast<CMPIString*>(new CMPI_Object(e.getMessage())));
|
365 mike 1.32.4.1 }
|
366 konrad.r 1.24 CMReturn ( CMPI_RC_OK);
|
367 konrad.r 1.19 }
|
368 schuur 1.1
|
369 schuur 1.12 static CMPIStatus instSetPropertyFilter(CMPIInstance* eInst,
|
370 konrad.r 1.19 const char** propertyList, const char **keys){
|
371 david.dillard 1.21 if (!eInst->hdl) {
372 CMReturn(CMPI_RC_ERR_INVALID_PARAMETER);
373 }
|
374 konrad.r 1.19
|
375 schuur 1.12 CMPI_Object *inst=reinterpret_cast<CMPI_Object*>(eInst);
376 char **list=(char**)inst->priv; // Thank you Warren !
377 int i,s;
378
379 if (inst->priv) {
380 while (*list) {
381 free (*list);
382 list++;
383 }
384 free(inst->priv);
385 }
386 inst->priv=NULL;
387
388 if (propertyList==NULL) CMReturn(CMPI_RC_OK);
389 if (keys==NULL) CMReturn(CMPI_RC_ERR_FAILED);
390
391 for (s=0,i=0; propertyList[i]; i++,s++);
392 for (i=0; keys[i]; i++,s++);
|
393 marek 1.32 list = (char**) calloc(s+1, sizeof(char*));
|
394 schuur 1.12 for (s=0,i=0; propertyList[i]; i++,s++) list[s]=strdup(propertyList[i]);
395 for (i=0; keys[i]; i++,s++) list[s]=strdup(keys[i]);
396 inst->priv=(void*)list;
|
397 kumpf 1.6
|
398 schuur 1.12 CMReturn(CMPI_RC_OK);
|
399 schuur 1.1 }
400
|
401 schuur 1.12 static CMPIStatus instSetPropertyFilterIgnore(CMPIInstance* eInst,
|
402 konrad.r 1.19 const char** propertyList, const char **keys){
|
403 david.dillard 1.21 /* We ignore it. */
|
404 konrad.r 1.19 CMReturn ( CMPI_RC_OK);
|
405 schuur 1.12 }
|
406 schuur 1.1
|
407 dave.sudlik 1.31
|
408 schuur 1.1 }
409
410 static CMPIInstanceFT instance_FT={
411 CMPICurrentVersion,
412 instRelease,
413 instClone,
414 instGetProperty,
415 instGetPropertyAt,
416 instGetPropertyCount,
417 instSetProperty,
418 instGetObjectPath,
419 instSetPropertyFilter,
|
420 konrad.r 1.19 #if defined(CMPI_VER_100)
421 instSetObjectPath,
422 #endif
|
423 dave.sudlik 1.31 #if defined(CMPI_VER_200)
424 instSetPropertyWithOrigin,
425 #endif
|
426 schuur 1.1 };
427
428 static CMPIInstanceFT instanceOnStack_FT={
429 CMPICurrentVersion,
430 instReleaseNop,
431 instClone,
432 instGetProperty,
433 instGetPropertyAt,
434 instGetPropertyCount,
435 instSetProperty,
436 instGetObjectPath,
437 instSetPropertyFilterIgnore,
|
438 konrad.r 1.19 #if defined(CMPI_VER_100)
439 instSetObjectPath,
440 #endif
|
441 dave.sudlik 1.31 #if defined(CMPI_VER_200)
442 instSetPropertyWithOrigin,
443 #endif
|
444 schuur 1.1 };
445
446 CMPIInstanceFT *CMPI_Instance_Ftab=&instance_FT;
447 CMPIInstanceFT *CMPI_InstanceOnStack_Ftab=&instanceOnStack_FT;
448
449
450 CMPI_InstanceOnStack::CMPI_InstanceOnStack(const CIMInstance& ci) {
451 hdl=(void*)&ci;
452 ft=CMPI_InstanceOnStack_Ftab;
453 }
454
455
456 PEGASUS_NAMESPACE_END
|