Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 735 lines (635 sloc) 19.069 kb
b0d0f276 »
2005-03-09 Initial revision
1
2 /*
3 * objectpath.c
4 *
07007cc9 »
2007-03-23 [ 1686170 ] sfcb:instance comparision in queries do not work as expected
5 * © Copyright IBM Corp. 2005, 2007
b0d0f276 »
2005-03-09 Initial revision
6 *
01521fc8 »
2005-11-20 Changed all license references to Eclipse Public lecense
7 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
b0d0f276 »
2005-03-09 Initial revision
8 * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
9 * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
10 *
01521fc8 »
2005-11-20 Changed all license references to Eclipse Public lecense
11 * You can obtain a current copy of the Eclipse Public License from
12 * http://www.opensource.org/licenses/eclipse-1.0.php
b0d0f276 »
2005-03-09 Initial revision
13 *
14 * Author: Frank Scheffler
15 * Contributions: Adrian Schuur <schuur@de.ibm.com>
16 *
17 * Description:
18 *
19 * CMPIObjectPath implementation.
20 *
21 */
22
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <ctype.h>
298736cb »
2005-03-21 Added cmpiftx.h for sfcb MI extensions
28 #include "constClass.h"
29 #include "objectImpl.h"
b0d0f276 »
2005-03-09 Initial revision
30
31 #include "native.h"
32 #include "msgqueue.h"
2e3b17c2 »
2007-02-22 [ 1665255 ] sfcb: providergrouping may fail
33 #include "utilft.h"
34
35 extern UtilStringBuffer *newStringBuffer(int s);
b0d0f276 »
2005-03-09 Initial revision
36
f4a65765 »
2005-06-13 Fixed [ 1219651 ] Qualifiers with array values not correctly handled
37 extern CMPIArray *native_make_CMPIArray(CMPIData * av, CMPIStatus * rc,ClObjectHdr * hdr);
b0d0f276 »
2005-03-09 Initial revision
38 extern CMPIObjectPath *interal_new_CMPIObjectPath(int mode, const char *,
39 const char *, CMPIStatus *);
40 extern CMPIBroker *Broker;
41
42 CMPIObjectPath *getObjectPath(char *path, char **msg);
43
44 struct native_cop {
45 CMPIObjectPath cop;
72525049 »
2006-04-26 Streamlined memory management and removed memory leaks
46 int refCount;
b0d0f276 »
2005-03-09 Initial revision
47 int mem_state;
48 };
49
50
51 static struct native_cop *__new_empty_cop(int, CMPIStatus *);
52
53 void memLinkObjectPath(CMPIObjectPath *cop)
54 {
55 struct native_cop *o = (struct native_cop *) cop;
56 memLinkEncObj(o,&o->mem_state);
57 }
58
59 /****************************************************************************/
60
61
62 static CMPIStatus __oft_release(CMPIObjectPath * cop)
63 {
64 struct native_cop *o = (struct native_cop *) cop;
65
66 // printf("__oft_release %d %d %p\n",getpid(),o->mem_state,cop);
67 if (o->mem_state && o->mem_state != MEM_RELEASED) {
68 ClObjectPathFree((ClObjectPath *) cop->hdl);
69 memUnlinkEncObj(o->mem_state);
70 o->mem_state = MEM_RELEASED;
71 free(cop);
72 CMReturn(CMPI_RC_OK);
73 }
74
75 CMReturn(CMPI_RC_ERR_FAILED);
76 }
77
78
74a635e1 »
2005-12-13 [ 1379315 ] sfcb CMPI version outdated. Changed a bunch of function s…
79 static CMPIObjectPath *__oft_clone(const CMPIObjectPath * op, CMPIStatus * rc)
b0d0f276 »
2005-03-09 Initial revision
80 {
81 CMPIStatus tmp;
82 struct native_cop *ncop = __new_empty_cop(MEM_NOT_TRACKED, &tmp);
83 ClObjectPath *cop = (ClObjectPath *) op->hdl;
84 ncop->cop.hdl = ClObjectPathRebuild(cop, NULL);
85
86 return (CMPIObjectPath *) ncop;
87 }
88
89
90 static CMPIStatus __oft_setNameSpace(CMPIObjectPath * op, const char *nameSpace)
91 {
92 ClObjectPath *cop = (ClObjectPath *) op->hdl;
93 ClObjectPathSetNameSpace(cop, nameSpace);
94 CMReturn(CMPI_RC_OK);
95 }
96
74a635e1 »
2005-12-13 [ 1379315 ] sfcb CMPI version outdated. Changed a bunch of function s…
97 CMPIString *__oft_getNameSpace(const CMPIObjectPath * op, CMPIStatus * rc)
b0d0f276 »
2005-03-09 Initial revision
98 {
99 ClObjectPath *cop = (ClObjectPath *) op->hdl;
f1bcd436 »
2007-10-02 [ 1805644 ] sfcb http performance needs improvement
100 return sfcb_native_new_CMPIString(ClObjectPathGetNameSpace(cop), rc, 0);
b0d0f276 »
2005-03-09 Initial revision
101 }
102
103
104 static CMPIStatus __oft_setHostName(CMPIObjectPath * op, const char *hostName)
105 {
106 ClObjectPath *cop = (ClObjectPath *) op->hdl;
107 ClObjectPathSetHostName(cop, hostName);
108 CMReturn(CMPI_RC_OK);
109 }
110
45e919e1 »
2006-07-19 #1296278 Added SLP support
111 static CMPIString *__oft_getHostName(const CMPIObjectPath * op, CMPIStatus * rc)
b0d0f276 »
2005-03-09 Initial revision
112 {
113 ClObjectPath *cop = (ClObjectPath *) op->hdl;
f1bcd436 »
2007-10-02 [ 1805644 ] sfcb http performance needs improvement
114 return sfcb_native_new_CMPIString(ClObjectPathGetHostName(cop), rc, 0);
b0d0f276 »
2005-03-09 Initial revision
115 }
116
117
118
119 static CMPIStatus __oft_setClassName(CMPIObjectPath * op, const char *className)
120 {
121 ClObjectPath *cop = (ClObjectPath *) op->hdl;
122 ClObjectPathSetClassName(cop, className);
123 CMReturn(CMPI_RC_OK);
124 }
125
45e919e1 »
2006-07-19 #1296278 Added SLP support
126 static CMPIString *__oft_getClassName(const CMPIObjectPath * op, CMPIStatus * rc)
b0d0f276 »
2005-03-09 Initial revision
127 {
128 ClObjectPath *cop = (ClObjectPath *) op->hdl;
f1bcd436 »
2007-10-02 [ 1805644 ] sfcb http performance needs improvement
129 return sfcb_native_new_CMPIString(ClObjectPathGetClassName(cop), rc, 0);
b0d0f276 »
2005-03-09 Initial revision
130 }
131
74a635e1 »
2005-12-13 [ 1379315 ] sfcb CMPI version outdated. Changed a bunch of function s…
132 const char *opGetClassNameChars(const CMPIObjectPath * op)
b0d0f276 »
2005-03-09 Initial revision
133 {
134 ClObjectPath *cop = (ClObjectPath *) op->hdl;
135 return ClObjectPathGetClassName(cop);
136 }
137
74a635e1 »
2005-12-13 [ 1379315 ] sfcb CMPI version outdated. Changed a bunch of function s…
138 const char *opGetNameSpaceChars(const CMPIObjectPath * op)
b0d0f276 »
2005-03-09 Initial revision
139 {
140 ClObjectPath *cop = (ClObjectPath *) op->hdl;
141 return ClObjectPathGetNameSpace(cop);
142 }
143
144
74a635e1 »
2005-12-13 [ 1379315 ] sfcb CMPI version outdated. Changed a bunch of function s…
145 CMPIData opGetKeyCharsAt(const CMPIObjectPath * op,
b0d0f276 »
2005-03-09 Initial revision
146 unsigned int i, char **name, CMPIStatus * rc)
147 {
148 ClObjectPath *cop = (ClObjectPath *) op->hdl;
149 CMPIData rv = { 0, CMPI_notFound, {0} };
150
2f9e7574 »
2005-04-25 Updated createClass support - classes can be dynamically added and wi…
151 if (ClObjectPathGetKeyAt(cop, i, &rv, name ? name : NULL)) {
b0d0f276 »
2005-03-09 Initial revision
152 if (rc)
153 CMSetStatus(rc, CMPI_RC_ERR_NOT_FOUND);
154 return rv;
155 }
2f9e7574 »
2005-04-25 Updated createClass support - classes can be dynamically added and wi…
156
b0d0f276 »
2005-03-09 Initial revision
157 if (rv.type == CMPI_chars) {
f1bcd436 »
2007-10-02 [ 1805644 ] sfcb http performance needs improvement
158 rv.value.string = sfcb_native_new_CMPIString(rv.value.chars, NULL, 0);
b0d0f276 »
2005-03-09 Initial revision
159 rv.type = CMPI_string;
160 }
161 else if (rv.type == CMPI_ref) {
58ee8aee »
2005-04-26 Fixed [ 1185287 ] remove sfcb compile warnings
162 rv.value.ref = getObjectPath(
db8bfa8a »
2010-03-08 2948647 getObjectPath may dereference NULL pointer
163 (char*)ClObjectGetClString(&cop->hdr, (ClString *) & rv.value.chars), NULL);
b0d0f276 »
2005-03-09 Initial revision
164 }
785b0cf1 »
2005-12-22 [ 1387264 ] sfcb enumerateinstances fails on PPC .
165 else if (rv.type & CMPI_ARRAY && rv.value.array) { // should nor occcur
b0d0f276 »
2005-03-09 Initial revision
166 rv.value.array =
785b0cf1 »
2005-12-22 [ 1387264 ] sfcb enumerateinstances fails on PPC .
167 native_make_CMPIArray((CMPIData *) rv.value.array, NULL,&cop->hdr);
b0d0f276 »
2005-03-09 Initial revision
168 }
169
170 if (rc)
171 CMSetStatus(rc, CMPI_RC_OK);
172 return rv;
173 }
174
175
45e919e1 »
2006-07-19 #1296278 Added SLP support
176 static CMPIData __oft_getKeyAt(const CMPIObjectPath * op, CMPICount i, CMPIString ** name,
b0d0f276 »
2005-03-09 Initial revision
177 CMPIStatus * rc)
178 {
179 char *n;
180 CMPIData rv = opGetKeyCharsAt(op, i, &n, rc);
181
182 if (name)
f1bcd436 »
2007-10-02 [ 1805644 ] sfcb http performance needs improvement
183 *name = sfcb_native_new_CMPIString(n, NULL, 0);
b0d0f276 »
2005-03-09 Initial revision
184
58ee8aee »
2005-04-26 Fixed [ 1185287 ] remove sfcb compile warnings
185 return rv;
b0d0f276 »
2005-03-09 Initial revision
186 }
187
45e919e1 »
2006-07-19 #1296278 Added SLP support
188 static CMPIData __oft_getKey(const CMPIObjectPath * op, const char *id, CMPIStatus * rc)
b0d0f276 »
2005-03-09 Initial revision
189 {
190 ClObjectPath *cop = (ClObjectPath *) op->hdl;
191 ClSection *prps = &cop->properties;
192 CMPIData rv = { 0, CMPI_notFound, {0} };
193 int i;
194
195 if ((i = ClObjectLocateProperty(&cop->hdr, prps, id)) != 0) {
196 return __oft_getKeyAt(op, i - 1, NULL, rc);
197 }
198
199 if (rc)
200 CMSetStatus(rc, CMPI_RC_ERR_NOT_FOUND);
201 return rv;
202 }
203
74a635e1 »
2005-12-13 [ 1379315 ] sfcb CMPI version outdated. Changed a bunch of function s…
204 static CMPICount __oft_getKeyCount(const CMPIObjectPath * op, CMPIStatus * rc)
b0d0f276 »
2005-03-09 Initial revision
205 {
206 ClObjectPath *cop = (ClObjectPath *) op->hdl;
207 if (rc)
208 CMSetStatus(rc, CMPI_RC_OK);
209 return (CMPICount) ClObjectPathGetKeyCount(cop);
210 }
211
212 static CMPIStatus __oft_addKey(CMPIObjectPath * op,
213 const char *name,
74a635e1 »
2005-12-13 [ 1379315 ] sfcb CMPI version outdated. Changed a bunch of function s…
214 const CMPIValue * value, CMPIType type)
b0d0f276 »
2005-03-09 Initial revision
215 {
216 ClObjectPath *cop = (ClObjectPath *) op->hdl;
d13a40e0 »
2006-11-22 [ 1600707 ] sfcb null CMPI_chars will crash providers
217 CMPIData data = { type, CMPI_goodValue, {0LL} };
b0d0f276 »
2005-03-09 Initial revision
218
d13a40e0 »
2006-11-22 [ 1600707 ] sfcb null CMPI_chars will crash providers
219 if (type == CMPI_chars) {
5f930a84 »
2007-07-03 unapplied [ 1745103 ] bad key property when addKey done with type CMP…
220 data.value.chars = (char*) value;
d13a40e0 »
2006-11-22 [ 1600707 ] sfcb null CMPI_chars will crash providers
221 } else if (type == CMPI_string) {
222 if (value && value->string) {
223 data.value.chars = (char *) value->string->hdl;
224 } else {
225 data.value.chars = NULL;
226 }
227 data.type=CMPI_chars;
228 } else if (value) {
15b34e79 »
2007-03-16 [ 1682388 ] sfcb too picky about CMPIValue ptr alignments
229 sfcb_setAlignedValue(&data.value,value,type);
d13a40e0 »
2006-11-22 [ 1600707 ] sfcb null CMPI_chars will crash providers
230 }
231
232 if (((type & CMPI_ENCA) && data.value.chars == NULL) || value == NULL) {
233 data.state=CMPI_nullValue;
b0d0f276 »
2005-03-09 Initial revision
234 }
235
236 ClObjectPathAddKey(cop, name, data);
237
238 CMReturn(CMPI_RC_OK);
239 }
240
fd2d7d27 »
2006-11-22 [ 1601005 ] sfcb objectpath function table is missing a function
241 static CMPIStatus __oft_setHostAndNameSpaceFromObjectPath(CMPIObjectPath * op,
242 const CMPIObjectPath * src)
243 {
244 ClObjectPath *s = (ClObjectPath *) src->hdl;
245 CMPIStatus st = {CMPI_RC_OK, NULL};
246 st = __oft_setHostName(op, ClObjectPathGetHostName(s));
247 if (st.rc == CMPI_RC_OK) {
248 st = __oft_setNameSpace(op, ClObjectPathGetNameSpace(s));
249 }
250 return st;
251 }
b0d0f276 »
2005-03-09 Initial revision
252
253 static CMPIStatus __oft_setNameSpaceFromObjectPath(CMPIObjectPath * op,
74a635e1 »
2005-12-13 [ 1379315 ] sfcb CMPI version outdated. Changed a bunch of function s…
254 const CMPIObjectPath * src)
b0d0f276 »
2005-03-09 Initial revision
255 {
256 ClObjectPath *s = (ClObjectPath *) src->hdl;
257 return __oft_setNameSpace(op, ClObjectPathGetNameSpace(s));
258 }
259
45e919e1 »
2006-07-19 #1296278 Added SLP support
260 extern char *sfcb_value2Chars(CMPIType type, CMPIValue * value);
b0d0f276 »
2005-03-09 Initial revision
261
45e919e1 »
2006-07-19 #1296278 Added SLP support
262 char *sfcb_pathToChars(const CMPIObjectPath * cop, CMPIStatus * rc, char *str)
b0d0f276 »
2005-03-09 Initial revision
263 {
264 // "//atp:9999/root/cimv25:TennisPlayer.first="Patrick",last="Rafter";
265
266 CMPIString *ns;
267 CMPIString *cn;
268 CMPIString *hn;
269 CMPIString *name;
270 CMPIData data;
271 unsigned int i, m;
272 char *v;
273 *str = 0;
274
275 hn = cop->ft->getHostname(cop, rc);
276 ns = cop->ft->getNameSpace(cop, rc);
277 cn = cop->ft->getClassName(cop, rc);
278 if (ns && ns->hdl && *(char*)ns->hdl) {
279 strcat(str,(char*)ns->hdl);
280 strcat(str,":");
281 }
282 strcat(str, (char *) cn->hdl);
283 for (i = 0, m = cop->ft->getKeyCount(cop, rc); i < m; i++) {
284 data = cop->ft->getKeyAt(cop, i, &name, rc);
285 if (i)
286 strcat(str, ",");
287 else
288 strcat(str, ".");
289 strcat(str, (char *) name->hdl);
bfa41f3d »
2007-07-03 [ 1745103 ] bad key property when addKey done with type CMPI_chars
290 if (name) CMRelease(name);
b0d0f276 »
2005-03-09 Initial revision
291 strcat(str, "=");
45e919e1 »
2006-07-19 #1296278 Added SLP support
292 v = sfcb_value2Chars(data.type, &data.value);
bfa41f3d »
2007-07-03 [ 1745103 ] bad key property when addKey done with type CMPI_chars
293 if (data.type==CMPI_string) CMRelease(data.value.string);
b0d0f276 »
2005-03-09 Initial revision
294 strcat(str, v);
295 free(v);
296 };
bfa41f3d »
2007-07-03 [ 1745103 ] bad key property when addKey done with type CMPI_chars
297 if (ns) CMRelease(ns);
298 if (cn) CMRelease(cn);
299 if (hn) CMRelease(hn);
b0d0f276 »
2005-03-09 Initial revision
300 return str;
301 }
302
45e919e1 »
2006-07-19 #1296278 Added SLP support
303 static CMPIString *__oft_toString(const CMPIObjectPath * cop, CMPIStatus * rc)
b0d0f276 »
2005-03-09 Initial revision
304 {
305 char str[4096] = { 0 };
45e919e1 »
2006-07-19 #1296278 Added SLP support
306 sfcb_pathToChars(cop, rc, str);
f1bcd436 »
2007-10-02 [ 1805644 ] sfcb http performance needs improvement
307 return sfcb_native_new_CMPIString(str, rc, 0);
b0d0f276 »
2005-03-09 Initial revision
308 }
309
74a635e1 »
2005-12-13 [ 1379315 ] sfcb CMPI version outdated. Changed a bunch of function s…
310 char *oft_toCharsNormalized(const CMPIObjectPath * cop, CMPIConstClass * cls,
b0d0f276 »
2005-03-09 Initial revision
311 int full, CMPIStatus * rc)
312 {
313 char str[2048] = { 0 };
314 CMPIString *cn;
315 CMPIString *name;
316 CMPIData data;
317 CMPIStatus irc;
318 unsigned long quals;
319 unsigned int i, n, m;
320 char *v;
321
322 cn = __oft_getClassName(cop, rc);
323 strcat(str, (char *) cn->hdl);
324
325 for (n = 0, i = 0, m = cls->ft->getPropertyCount(cls, rc); i < m; i++) {
a6b503fb »
2007-08-28 [ 1685254 ] sfcb does not return REFERENCECLASS in GetClass
326 getPropertyQualsAt(cls, i, &name, &quals, NULL, NULL);
b0d0f276 »
2005-03-09 Initial revision
327 if (quals & 1) {
328 data = __oft_getKey(cop, (const char *) name->hdl, &irc);
329 if (irc.rc == CMPI_RC_OK) {
9b24443f »
2006-03-06 [ 1443861 ] sfcb does not support local clients
330 if (n) strcat(str, ",");
331 else strcat(str, ".");
b0d0f276 »
2005-03-09 Initial revision
332 strcat(str, (char *) name->hdl);
333 strcat(str, "=");
45e919e1 »
2006-07-19 #1296278 Added SLP support
334 v = sfcb_value2Chars(data.type, &data.value);
b0d0f276 »
2005-03-09 Initial revision
335 strcat(str, v);
336 free(v);
337 }
338 }
339 }
340 return strdup(str);
341 }
342
343 static CMPIObjectPathFT oft = {
344 NATIVE_FT_VERSION,
345 __oft_release,
346 __oft_clone,
347 __oft_setNameSpace,
348 __oft_getNameSpace,
349 __oft_setHostName,
350 __oft_getHostName,
351 __oft_setClassName,
352 __oft_getClassName,
353 __oft_addKey,
354 __oft_getKey,
355 __oft_getKeyAt,
356 __oft_getKeyCount,
357 __oft_setNameSpaceFromObjectPath,
fd2d7d27 »
2006-11-22 [ 1601005 ] sfcb objectpath function table is missing a function
358 __oft_setHostAndNameSpaceFromObjectPath,
b0d0f276 »
2005-03-09 Initial revision
359 NULL,
360 NULL,
361 NULL,
362 NULL,
363 __oft_toString
364 };
365
366 CMPIObjectPathFT *CMPI_ObjectPath_FT = &oft;
367
74a635e1 »
2005-12-13 [ 1379315 ] sfcb CMPI version outdated. Changed a bunch of function s…
368 unsigned long getObjectPathSerializedSize(const CMPIObjectPath * op)
b0d0f276 »
2005-03-09 Initial revision
369 {
370 ClObjectPath *cop = (ClObjectPath *) op->hdl;
371 return ClSizeObjectPath(cop) + sizeof(struct native_cop);
372 }
373
74a635e1 »
2005-12-13 [ 1379315 ] sfcb CMPI version outdated. Changed a bunch of function s…
374 void getSerializedObjectPath(const CMPIObjectPath * op, void *area)
b0d0f276 »
2005-03-09 Initial revision
375 {
376 memcpy(area, op, sizeof(struct native_cop));
377 ClObjectPathRebuild((ClObjectPath *) op->hdl,
378 (void *) ((char *) area + sizeof(struct native_cop)));
379 }
380
381 CMPIObjectPath *relocateSerializedObjectPath(void *area)
382 {
383 struct native_cop *cop = (struct native_cop *) area;
384 cop->cop.hdl = cop + 1;
385 cop->mem_state=MEM_RELEASED;
386 cop->cop.ft = &oft;
387 ClObjectPathRelocateObjectPath((ClObjectPath *) cop->cop.hdl);
388 return (CMPIObjectPath *) cop;
389 }
390
74a635e1 »
2005-12-13 [ 1379315 ] sfcb CMPI version outdated. Changed a bunch of function s…
391 MsgSegment setObjectPathMsgSegment(const CMPIObjectPath * op)
b0d0f276 »
2005-03-09 Initial revision
392 {
393 MsgSegment s;
74a635e1 »
2005-12-13 [ 1379315 ] sfcb CMPI version outdated. Changed a bunch of function s…
394 s.data = (CMPIObjectPath*)op;
b0d0f276 »
2005-03-09 Initial revision
395 s.type = MSG_SEG_OBJECTPATH;
396 s.length = getObjectPathSerializedSize(op);
397 return s;
398 }
399
400 static struct native_cop *__new_empty_cop(int mm_add, CMPIStatus * rc)
401 {
402 static CMPIObjectPath o = {
403 "CMPIObjectPath",
404 &oft
405 };
406 struct native_cop cop,*tCop;
407 int state;
408
409 cop.cop = o;
410 tCop=memAddEncObj(mm_add, &cop, sizeof(cop),&state);
411 tCop->mem_state = state;
72525049 »
2006-04-26 Streamlined memory management and removed memory leaks
412 tCop->refCount=0;
b0d0f276 »
2005-03-09 Initial revision
413 if (rc) CMSetStatus(rc, CMPI_RC_OK);
414
415 return (struct native_cop*)tCop;
416 }
417
418
419
420 CMPIObjectPath *internal_new_CMPIObjectPath(int mode, const char *nameSpace,
421 const char *className,
422 CMPIStatus * rc)
423 {
424 struct native_cop *cop = __new_empty_cop(mode, rc);
425 cop->cop.hdl = ClObjectPathNew(nameSpace, className);
426 return (CMPIObjectPath *) cop;
427 }
428
429 CMPIObjectPath *TrackedCMPIObjectPath(const char *nameSpace,
430 const char *className, CMPIStatus * rc)
431 {
432 return internal_new_CMPIObjectPath(MEM_TRACKED, nameSpace, className, rc);
433 }
434
435 CMPIObjectPath *NewCMPIObjectPath(const char *nameSpace, const char *className,
436 CMPIStatus * rc)
437 {
438 return internal_new_CMPIObjectPath(MEM_NOT_TRACKED, nameSpace, className, rc);
439 }
440
441 static int refLookAhead(char *u, char **nu)
442 {
443 int state = 0, i;
444 char *pu = NULL;
445 for (i = 0; u[i] != 0; i++) {
446 switch (state) {
cad0e8a8 »
2005-12-18 [ 1381312 ] sfcb XML generation for association objectpathes incorrect.
447 case 0: /* start */
b0d0f276 »
2005-03-09 Initial revision
448 if (isalnum(u[i]))
449 state = 1;
450 break;
cad0e8a8 »
2005-12-18 [ 1381312 ] sfcb XML generation for association objectpathes incorrect.
451 case 1: /* lhs: key property name */
b0d0f276 »
2005-03-09 Initial revision
452 if (u[i] == '=')
453 state = 2;
454 break;
cad0e8a8 »
2005-12-18 [ 1381312 ] sfcb XML generation for association objectpathes incorrect.
455 case 2: /* rhs: value */
b0d0f276 »
2005-03-09 Initial revision
456 if (isalnum(u[i]))
457 state = 3;
458 else
459 return 0;
460 break;
cad0e8a8 »
2005-12-18 [ 1381312 ] sfcb XML generation for association objectpathes incorrect.
461 case 3: /* rhs: some identifier or value */
462 if (u[i] == ',')
b0d0f276 »
2005-03-09 Initial revision
463 return 0;
464 if (u[i] == '.') {
465 state = 4;
466 }
467 break;
cad0e8a8 »
2005-12-18 [ 1381312 ] sfcb XML generation for association objectpathes incorrect.
468 case 4: /* rhs: start of key property of an ref value */
b0d0f276 »
2005-03-09 Initial revision
469 if (!isalnum(u[i]))
470 return 0;
cad0e8a8 »
2005-12-18 [ 1381312 ] sfcb XML generation for association objectpathes incorrect.
471 state = 5;
472 break;
473 case 5: /* rhs: key property of an ref value */
474 if (u[i] == '=') {
475 state = 6;
476 if (u[i+1]==0) {
477 *nu = u + i;
478 return 1;
479 }
480 }
481 break;
482 case 6: /* rhs: key property of a ref value's key property */
483 if (u[i] == ',') {
484 if (refLookAhead(u+i,&pu)) {
485 *nu = u + i;
486 return 1;
487 }
488 }
489 break;
b0d0f276 »
2005-03-09 Initial revision
490 }
491 }
cad0e8a8 »
2005-12-18 [ 1381312 ] sfcb XML generation for association objectpathes incorrect.
492 if (state>4) {
493 *nu = u + i;
494 return 1;
495 } else {
496 return 0;
497 }
b0d0f276 »
2005-03-09 Initial revision
498 }
499
500
501 static char *strnDup(const char *n, int l)
502 {
503 char *tmp = (char *) malloc(l + 2);
504 strncpy(tmp, n, l);
505 tmp[l] = 0;
506 return tmp;
507 }
508
509 static void addKey(CMPIObjectPath * op, char *kd, int ref)
510 {
511 char *val = strchr(kd, '=');
512 *val = 0;
513 val++;
cad0e8a8 »
2005-12-18 [ 1381312 ] sfcb XML generation for association objectpathes incorrect.
514 if (ref) {
db8bfa8a »
2010-03-08 2948647 getObjectPath may dereference NULL pointer
515 CMPIObjectPath *keyOp = getObjectPath(val, NULL);
cad0e8a8 »
2005-12-18 [ 1381312 ] sfcb XML generation for association objectpathes incorrect.
516 op->ft->addKey(op, kd, (CMPIValue*)&keyOp, CMPI_ref);
517 } else if (*val == '"') {
b0d0f276 »
2005-03-09 Initial revision
518 val++;
519 val[strlen(val) - 1] = 0;
520 op->ft->addKey(op, kd, (CMPIValue *) val, CMPI_chars);
521 }
511768de »
2009-10-29 [ 2888178 ] getObjectPath() ignores numeric types
522 else if (val[0] == '-' || val[0] == '+') {
523 CMPISint64 vali = atol(val);
524 CMPIValue v = (CMPIValue)vali;
525 op->ft->addKey(op, kd, &v, CMPI_sint64);
526 }
b0d0f276 »
2005-03-09 Initial revision
527 else if (isdigit(*val)) {
511768de »
2009-10-29 [ 2888178 ] getObjectPath() ignores numeric types
528 CMPIUint64 vali = atol(val);
529 CMPIValue v = (CMPIValue)vali;
530 op->ft->addKey(op, kd, &v, CMPI_uint64);
b0d0f276 »
2005-03-09 Initial revision
531 }
532 else {
533 }
534 }
535
536 CMPIObjectPath *getObjectPath(char *path, char **msg)
537 {
d97d4b78 »
2007-10-02 [ 1751084 ] sfcb does not support a hostname in an objectpath
538 char *p, *pp, *last, *un, *cname, *nname=NULL;
539 char *origu, *u;
b0d0f276 »
2005-03-09 Initial revision
540 int ref = 0;
541 CMPIObjectPath *op;
542
6e53a512 »
2006-12-18 [ 1618216 ] sfcb method parameter and return value handling problems
543 if (path == NULL) {
544 return NULL;
545 }
d97d4b78 »
2007-10-02 [ 1751084 ] sfcb does not support a hostname in an objectpath
546 u = origu = strdup(path);
b0d0f276 »
2005-03-09 Initial revision
547 last = u + strlen(u);
511768de »
2009-10-29 [ 2888178 ] getObjectPath() ignores numeric types
548 if (msg) *msg = NULL;
b0d0f276 »
2005-03-09 Initial revision
549
550 p = strchr(u, '.');
551 if (!p) {
552 if (u) {
553 if ((pp=strchr(u,':'))!=NULL) {
554 nname=strnDup(u,pp-u);
555 u=pp+1;
556 }
557 cname = strdup(u);
d97d4b78 »
2007-10-02 [ 1751084 ] sfcb does not support a hostname in an objectpath
558 // op = Broker->eft->newObjectPath(Broker, nname ? nname : "root/cimv2", cname, NULL);
b0d0f276 »
2005-03-09 Initial revision
559 op = Broker->eft->newObjectPath(Broker, nname , cname, NULL);
560 free(cname);
d97d4b78 »
2007-10-02 [ 1751084 ] sfcb does not support a hostname in an objectpath
561 free(origu);
b0d0f276 »
2005-03-09 Initial revision
562 if (nname) free(nname);
563 return op;
564 }
db8bfa8a »
2010-03-08 2948647 getObjectPath may dereference NULL pointer
565 if (msg) *msg = "No className found";
d97d4b78 »
2007-10-02 [ 1751084 ] sfcb does not support a hostname in an objectpath
566 free(origu);
b0d0f276 »
2005-03-09 Initial revision
567 if (nname) free(nname);
568 return NULL;
569 }
570
571 if ((pp=strchr(u,':'))!=NULL) {
572 nname=strnDup(u,pp-u);
573 u=pp+1;
574 }
575
576 cname = strnDup(u, p - u);
d97d4b78 »
2007-10-02 [ 1751084 ] sfcb does not support a hostname in an objectpath
577 // op = Broker->eft->newObjectPath(Broker, nname ? nname : "root/cimv2", cname, NULL);
b0d0f276 »
2005-03-09 Initial revision
578 op = Broker->eft->newObjectPath(Broker, nname , cname, NULL);
579 free(cname);
580 if (nname) free(nname);
581
582 for (u = p + 1; ; u = p + 1) {
583 if ((ref = refLookAhead(u, &un))) {
cad0e8a8 »
2005-12-18 [ 1381312 ] sfcb XML generation for association objectpathes incorrect.
584 char *t;
585 p = un;
586 if (*p == 0) {
587 break;
588 }
589 t = strnDup(u, un - u);
590 addKey(op, t, ref);
591 free(t);
592 continue;
b0d0f276 »
2005-03-09 Initial revision
593 }
594 if ((p = strpbrk(u, ",\"")) == NULL)
595 break;
596 if (*p == '"') {
597 if (*(p - 1) != '=') {
db8bfa8a »
2010-03-08 2948647 getObjectPath may dereference NULL pointer
598 if (msg) *msg = "Incorrectly quoted string 1";
d97d4b78 »
2007-10-02 [ 1751084 ] sfcb does not support a hostname in an objectpath
599 free(origu);
b0d0f276 »
2005-03-09 Initial revision
600 return NULL;
601 }
602 p++;
603 if ((p = strchr(p, '"')) == NULL) {
db8bfa8a »
2010-03-08 2948647 getObjectPath may dereference NULL pointer
604 if (msg) *msg = "Unbalanced quoted string";
d97d4b78 »
2007-10-02 [ 1751084 ] sfcb does not support a hostname in an objectpath
605 free(origu);
b0d0f276 »
2005-03-09 Initial revision
606 return NULL;
607 }
608 p++;
609 if (*p != ',' && *p != 0) {
db8bfa8a »
2010-03-08 2948647 getObjectPath may dereference NULL pointer
610 if (msg) *msg = "Incorrectly quoted string 2";
d97d4b78 »
2007-10-02 [ 1751084 ] sfcb does not support a hostname in an objectpath
611 free(origu);
b0d0f276 »
2005-03-09 Initial revision
612 return NULL;
613 }
614 if (*p == 0)
615 break;
616 }
617 char *t = strnDup(u, p - u);
618 addKey(op, t, ref);
619 free(t);
620 }
621 if (last > u) {
622 char *t = strnDup(u, last - u);
623 addKey(op, t, ref);
624 free(t);
625 }
d97d4b78 »
2007-10-02 [ 1751084 ] sfcb does not support a hostname in an objectpath
626 free(origu);
b0d0f276 »
2005-03-09 Initial revision
627 return op;
628 }
629
2e3b17c2 »
2007-02-22 [ 1665255 ] sfcb: providergrouping may fail
630 typedef struct keyIds {
631 CMPIString *key;
632 CMPIData data;
633 } KeyIds;
634
635 static int qCompare(const void *arg1, const void *arg2)
636 {
637 return strcasecmp((char *) ((KeyIds *) arg1)->key->hdl,
638 (char *) ((KeyIds *) arg2)->key->hdl);
639 }
640
641 static char copKey[8192];
642
643 UtilStringBuffer *normalizeObjectPathStrBuf(const CMPIObjectPath * cop)
644 {
645 int c = CMGetKeyCount(cop, NULL);
646 int i;
647 char pc = 0,*cp;
648 UtilStringBuffer *sb=newStringBuffer(512);
b0d0f276 »
2005-03-09 Initial revision
649
2e3b17c2 »
2007-02-22 [ 1665255 ] sfcb: providergrouping may fail
650 KeyIds *ids = (KeyIds *) malloc(sizeof(KeyIds) * c);
651
652 for (i = 0; i < c; i++) {
653 ids[i].data = CMGetKeyAt(cop, i, &ids[i].key, NULL);
654 cp=ids[i].key->hdl;
655 while (*cp) {
656 *cp=tolower(*cp);
657 cp++;
658 }
659 }
660 qsort(ids, c, sizeof(KeyIds), qCompare);
661
662 for (i = 0; i < c; i++) {
f1bcd436 »
2007-10-02 [ 1805644 ] sfcb http performance needs improvement
663 if (pc) SFCB_APPENDCHARS_BLOCK(sb,",");
2e3b17c2 »
2007-02-22 [ 1665255 ] sfcb: providergrouping may fail
664 sb->ft->appendChars(sb,(char*)ids[i].key->hdl);
f1bcd436 »
2007-10-02 [ 1805644 ] sfcb http performance needs improvement
665 SFCB_APPENDCHARS_BLOCK(sb,"=");
2e3b17c2 »
2007-02-22 [ 1665255 ] sfcb: providergrouping may fail
666 if (ids[i].data.type==CMPI_ref) {
667 CMPIString *cn=CMGetClassName(ids[i].data.value.ref,NULL);
668 CMPIString *ns=CMGetNameSpace(ids[i].data.value.ref,NULL);
669 UtilStringBuffer *sbt= normalizeObjectPathStrBuf(ids[i].data.value.ref);
670 char *nss;
671 cp=(char*)cn->hdl;
672 while (*cp) {
673 *cp=tolower(*cp);
674 cp++;
675 }
676 if (ns==NULL) {
677 nss = CMGetCharPtr(CMGetNameSpace(cop,NULL));
678 } else {
679 nss = CMGetCharPtr(ns);
680 }
681 if (nss) {
682 sb->ft->appendChars(sb,nss);
f1bcd436 »
2007-10-02 [ 1805644 ] sfcb http performance needs improvement
683 SFCB_APPENDCHARS_BLOCK(sb,":");
2e3b17c2 »
2007-02-22 [ 1665255 ] sfcb: providergrouping may fail
684 }
685 sb->ft->appendChars(sb,(char*)cn->hdl);
f1bcd436 »
2007-10-02 [ 1805644 ] sfcb http performance needs improvement
686 SFCB_APPENDCHARS_BLOCK(sb,".");
2e3b17c2 »
2007-02-22 [ 1665255 ] sfcb: providergrouping may fail
687 sb->ft->appendChars(sb,sbt->ft->getCharPtr(sbt));
688 sbt->ft->release(sbt);
689 }
690 else {
691 char *v = sfcb_value2Chars(ids[i].data.type, &ids[i].data.value);
692 sb->ft->appendChars(sb,v);
693 free(v);
694 }
695 pc = ',';
696 }
697 free(ids);
698
699
700 return(sb);
701 }
702
703 char *normalizeObjectPathChars(const CMPIObjectPath *cop)
704 {
705 UtilStringBuffer *sb=normalizeObjectPathStrBuf(cop);
706 strcpy(copKey,sb->ft->getCharPtr(sb));
707 sb->ft->release(sb);
708 return copKey;
709 }
710
711 char *normalizeObjectPathCharsDup(const CMPIObjectPath *cop)
712 {
713 char *n;
714 UtilStringBuffer *sb=normalizeObjectPathStrBuf(cop);
715 n=strdup(sb->ft->getCharPtr(sb));
716 sb->ft->release(sb);
717 return n;
718 }
07007cc9 »
2007-03-23 [ 1686170 ] sfcb:instance comparision in queries do not work as expected
719
720 int objectpathCompare(const CMPIObjectPath *cop1, const CMPIObjectPath *cop2)
721 {
722 UtilStringBuffer *sb1, *sb2;
723 int result;
724
725 sb1=normalizeObjectPathStrBuf(cop1);
726 sb2=normalizeObjectPathStrBuf(cop2);
727
728 result = strcmp(sb1->ft->getCharPtr(sb1), sb2->ft->getCharPtr(sb2));
729
730 sb1->ft->release(sb1);
731 sb2->ft->release(sb2);
732
733 return result;
734 }
Something went wrong with that request. Please try again.