1 mike 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
|
6 krisbash 1.3 ** Copyright (c)Microsoft Corporation
|
7 mike 1.1 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 **==============================================================================
23 */
24
25 #include <common.h>
26 #include "wsbuf.h"
27 #include <base/log.h>
28 mike 1.1 #include <base/result.h>
29 #include <base/instance.h>
|
30 krisbash 1.3 #include <pal/strings.h>
|
31 mike 1.1 #include <base/field.h>
32 #include <base/messages.h>
33 #include <base/helpers.h>
|
34 krisbash 1.3 #include <pal/sleep.h>
35 #include <pal/format.h>
|
36 mike 1.1 #include <base/base64.h>
|
37 krisbash 1.3 #include <xmlserializer/xmlserializer.h>
38 #include <omi_error/omierror.h>
39
|
40 mike 1.1
41 #if defined(WSBUF_DISABLE_INLINING)
42 # include "wsbufinline.h"
43 #endif
44
45 #if 0
46 #define ENABLE_TRACING
47 #endif
48
49 #ifdef ENABLE_TRACING
|
50 krisbash 1.3 #define PRINTF(a)printf a
|
51 mike 1.1 #else
52 #define PRINTF(a)
53 #endif
54
|
55 krisbash 1.3 #define XML_CR ZT("\n")
|
56 mike 1.1
57 /*
58 **==============================================================================
59 **
60 ** Local datatypes:
61 **
62 **==============================================================================
63 */
64 typedef struct _BUF_FaultItem
65 {
|
66 krisbash 1.3 const ZChar* action;
|
67 mike 1.1 MI_Uint32 actionSize;
68 const char* code; /* sender/receiver */
69 const char* subCode; /* wsa:XXX */
|
70 krisbash 1.3 const ZChar* defaultText;
|
71 mike 1.1 }
72 BUF_FaultItem;
73
74 typedef struct _BUF_CIMErrorItem
75 {
76 WSBUF_FAULT_CODE faultCode;
|
77 krisbash 1.3 const ZChar* description;
|
78 mike 1.1 }
79 BUF_CIMErrorItem;
80
81 /*
82 **==============================================================================
83 **
84 ** Forward declarations:
85 **
86 **==============================================================================
87 */
88 static MI_Result _PackInstance(
89 WSBuf* buf,
|
90 krisbash 1.3 UserAgent userAgent,
|
91 mike 1.1 const MI_Instance* instance,
|
92 krisbash 1.3 MI_Boolean(*filterProperty)(const ZChar* name, void* data),
|
93 mike 1.1 void* filterPropertyData,
94 const MI_ClassDecl* castToClassDecl,
95 MI_Uint32 flags,
|
96 krisbash 1.3 MI_Boolean embedded,
97 const ZChar* propName,
98 MI_Uint32 *lastPrefixIndex,
99 const ZChar* parentNSPrefix); //optional
|
100 mike 1.1
101 static MI_Result _PackEPR(
102 WSBuf* buf,
|
103 krisbash 1.3 UserAgent userAgent,
104 const MI_Instance* instance,
105 MI_Uint32 flags);
|
106 mike 1.1
107 /*
108 **==============================================================================
109 **
110 ** Static data:
111 **
112 **==============================================================================
113 */
114
115 static const BUF_FaultItem s_faults[] = {
116 /* WSBUF_FAULT_INTERNAL_ERROR */
117 {
|
118 krisbash 1.3 LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
|
119 mike 1.1 "SOAP-ENV:Receiver",
120 "wsman:InternalError",
|
121 krisbash 1.3 ZT("The service cannot comply with the request due to internal processing errors.")
|
122 mike 1.1 },
123 /* WSBUF_FAULT_NOT_SUPPORTED */
124 {
|
125 krisbash 1.3 LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
|
126 mike 1.1 "SOAP-ENV:Sender",
127 "wsman:UnsupportedFeature",
|
128 krisbash 1.3 ZT("not supported")
|
129 mike 1.1 },
130 /* WSBUF_FAULT_NOT_UNDERSTOOD */
131 {
|
132 krisbash 1.3 LIT(ZT("http://schemas.xmlsoap.org/ws/2004/08/addressing/fault")),
|
133 mike 1.1 "SOAP-ENV:MustUnderstand",
134 0,
|
135 krisbash 1.3 ZT("Header not understood")
|
136 mike 1.1 },
137 /* WSBUF_FAULT_DESTINATION_UNREACHABLE */
138 {
|
139 krisbash 1.3 LIT(ZT("http://schemas.xmlsoap.org/ws/2004/08/addressing/fault")),
|
140 mike 1.1 "SOAP-ENV:Sender",
141 "wsa:DestinationUnreachable",
|
142 krisbash 1.3 ZT("No route can be determined to reach the destination role defined by the Addressing To header.")
|
143 mike 1.1 },
144 /* WSBUF_FAULT_ACCESS_DENIED */
145 {
|
146 krisbash 1.3 LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
|
147 mike 1.1 "SOAP-ENV:Sender",
148 "wsman:AccessDenied",
|
149 krisbash 1.3 ZT("The sender was not authorized to access the resource.")
|
150 mike 1.1 },
151 /* WSBUF_FAULT_ENCODING_LIMIT */
152 {
|
153 krisbash 1.3 LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
|
154 mike 1.1 "SOAP-ENV:Sender",
155 "wsman:EncodingLimit",
|
156 krisbash 1.3 ZT("An internal encoding limit was exceeded in a request or would be violated if the message were processed.")
157 },
158 /* WSBUF_FAULT_INVALID_EXPIRATION_TIME */
159 {
160 LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
161 "SOAP-ENV:Sender",
162 "wsman:InvalidExpirationTime",
163 ZT("The request specified an invalid expiration time that cannot be supported (zero or in the past).")
164 },
165 /* WSBUF_FAULT_UNSUPPORTED_EXPIRATION_TIME */
166 {
167 LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
168 "SOAP-ENV:Sender",
169 "wsman:UnsupportedExpirationTime",
170 ZT("Only xs:duration expiration values are supported.")
171 },
172 /* WSBUF_FAULT_TIMED_OUT */
173 {
174 LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/fault")),
175 "SOAP-ENV:Receiver",
176 "wsman:TimedOut",
177 krisbash 1.3 ZT("The operation has timed out.")
178 },
179 /* WSBUF_FAULT_INVALID_MESSAGE_INFORMATION_HEADER */
180 {
181 LIT(ZT("http://schemas.xmlsoap.org/ws/2004/08/addressing/fault")),
182 "SOAP-ENV:Sender",
183 "wsa:InvalidMessageInformationHeader",
184 ZT("The request specified an invalid header property.")
185 },
186 /* WSBUF_FAULT_INVALID_HEARTBEAT */
187 {
188 LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/Heartbeats")),
189 "SOAP-ENV:Sender",
190 "wsman:UnsupportedFeature",
191 ZT("The request specified an invalid heartbeat.")
192 },
193 /* WSBUF_FAULT_ACTION_NOT_SUPPORTED */
194 {
195 LIT(ZT("http://schemas.xmlsoap.org/ws/2004/08/addressing/fault")),
196 "SOAP-ENV:Sender",
197 "wsa:ActionNotSupported",
198 krisbash 1.3 ZT("The request specified an unsupported action.")
199 },
200 /* WSBUF_FAULT_CONNECTION_RETRY_NOT_SUPPORTED */
201 {
202 LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/DeliveryRetries")),
203 "SOAP-ENV:Sender",
204 "wsman:UnsupportedFeature",
205 ZT("Connection retry is not supported.")
206 },
207 /* WSBUF_FAULT_BOOKMARK_INVALID_FORMAT */
208 {
209 LIT(ZT("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InvalidFormat")),
210 "SOAP-ENV:Sender",
211 "wsman:InvalidBookmark",
212 ZT("Bookmark must be non-empty if specified.")
213 }
|
214 mike 1.1 };
215
216 static const BUF_CIMErrorItem s_cimerrors[] = {
217 /* MI_RESULT_OK = 0, */
218 {
219 0,
220 0
221 },
222 /* MI_RESULT_FAILED = 1, */
223 {
224 WSBUF_FAULT_INTERNAL_ERROR,
|
225 krisbash 1.3 ZT("CIM ERROR:FAILED: A general error occurred, not covered by a more specific error code.")
|
226 mike 1.1 },
227
228 /* MI_RESULT_ACCESS_DENIED = 2, */
229 {
230 WSBUF_FAULT_ACCESS_DENIED,
|
231 krisbash 1.3 ZT("CIM ERROR:ACCESS_DENIED: Access to a CIM resource is not available to the client.")
|
232 mike 1.1 },
233
234 /* MI_RESULT_INVALID_NAMESPACE = 3, */
235 {
236 WSBUF_FAULT_DESTINATION_UNREACHABLE,
|
237 krisbash 1.3 ZT("CIM ERROR:INVALID_NAMESPACE: The target namespace does not exist.")
|
238 mike 1.1 },
239
240 /* MI_RESULT_INVALID_PARAMETER = 4,*/
241 {
242 WSBUF_FAULT_INTERNAL_ERROR,
|
243 krisbash 1.3 ZT("CIM ERROR:INVALID_PARAMETER: One or more parameter values passed to the method are not valid.")
|
244 mike 1.1 },
245
246 /* MI_RESULT_INVALID_CLASS = 5, */
247 {
248 WSBUF_FAULT_DESTINATION_UNREACHABLE,
|
249 krisbash 1.3 ZT("CIM ERROR:INVALID_CLASS: The specified class does not exist.")
|
250 mike 1.1 },
251
252 /* MI_RESULT_NOT_FOUND = 6,*/
253 {
254 WSBUF_FAULT_DESTINATION_UNREACHABLE,
|
255 krisbash 1.3 ZT("CIM ERROR:NOT_FOUND: The requested object cannot be found.")
|
256 mike 1.1 },
257
258 /* MI_RESULT_NOT_SUPPORTED = 7, */
259 {
260 WSBUF_FAULT_NOT_SUPPORTED,
|
261 krisbash 1.3 ZT("CIM ERROR:NOT_SUPPORTED: The requested operation is not supported.")
|
262 mike 1.1 }
263
264 #if 0
265 /* The operation cannot be invoked because the class has subclasses. */
266 MI_RESULT_CLASS_HAS_CHILDREN = 8,
267
268 /* The operation cannot be invoked because the class has instances. */
269 MI_RESULT_CLASS_HAS_INSTANCES = 9,
270
271 /* The operation cannot be invoked because the superclass does not exist. */
272 MI_RESULT_INVALID_SUPERCLASS = 10,
273
274 /* The operation cannot be invoked because an object already exists. */
275 MI_RESULT_ALREADY_EXISTS = 11,
276
277 /* The specified property does not exist. */
278 MI_RESULT_NO_SUCH_PROPERTY = 12,
279
280 /* The value supplied is not compatible with the type. */
281 MI_RESULT_TYPE_MISMATCH = 13,
282
283 mike 1.1 /* The query language is not recognized or supported. */
284 MI_RESULT_QUERY_LANGUAGE_NOT_SUPPORTED = 14,
285
286 /* The query is not valid for the specified query language. */
287 MI_RESULT_INVALID_QUERY = 15,
288
289 /* The extrinsic method cannot be invoked. */
290 MI_RESULT_METHOD_NOT_AVAILABLE = 16,
291
292 /* The specified extrinsic method does not exist. */
293 MI_RESULT_METHOD_NOT_FOUND = 17,
294
295 /* The specified namespace is not empty. */
296 MI_RESULT_NAMESPACE_NOT_EMPTY = 20,
297
298 /* The enumeration identified by the specified context is invalid. */
299 MI_RESULT_INVALID_ENUMERATION_CONTEXT = 21,
300
301 /* The specified operation timeout is not supported by the CIM Server. */
302 MI_RESULT_INVALID_OPERATION_TIMEOUT = 22,
303
304 mike 1.1 /* The Pull operation has been abandoned. */
305 MI_RESULT_PULL_HAS_BEEN_ABANDONED = 23,
306
307 /* The attempt to abandon a concurrent Pull operation failed. */
308 MI_RESULT_PULL_CANNOT_BE_ABANDONED = 24,
309
310 /* Using a filter in the enumeration is not supported by the CIM server. */
311 MI_RESULT_FILTERED_ENUMERATION_NOT_SUPPORTED = 25,
312
313 /* The CIM server does not support continuation on error. */
314 MI_RESULT_CONTINUATION_ON_ERROR_NOT_SUPPORTED = 26,
315
316 /* The operation failed because server limits were exceeded. */
317 MI_RESULT_SERVER_LIMITS_EXCEEDED = 27,
318
319 /* The CIM server is shutting down and cannot process the operation. */
320 MI_RESULT_SERVER_IS_SHUTTING_DOWN = 28
321 #endif
322 };
323
|
324 krisbash 1.3 #if defined(_MSC_VER)
325 #pragma warning( push )
326 #pragma warning( disable : 4125 )
327 #endif
328
|
329 mike 1.1 /* Encodings for special XML characters */
|
330 krisbash 1.3 static const ZChar* s_specialCharEncodings[128] =
|
331 mike 1.1 {
|
332 krisbash 1.3 ZT("\004�"),
333 ZT("\004"),
334 ZT("\004"),
335 ZT("\004"),
336 ZT("\004"),
337 ZT("\004"),
338 ZT("\004"),
339 ZT("\004"),
340 ZT("\004"),
341 ZT("\004	"),
342 ZT("\005 "),
343 ZT("\005"),
344 ZT("\005"),
345 ZT("\005 "),
346 ZT("\005"),
347 ZT("\005"),
348 ZT("\005"),
349 ZT("\005"),
350 ZT("\005"),
351 ZT("\005"),
352 ZT("\005"),
353 krisbash 1.3 ZT("\005"),
354 ZT("\005"),
355 ZT("\005"),
356 ZT("\005"),
357 ZT("\005"),
358 ZT("\005"),
359 ZT("\005"),
360 ZT("\005"),
361 ZT("\005"),
362 ZT("\005"),
363 ZT("\005"),
364 ZT("\001 "),
365 ZT("\001!"),
366 ZT("\006""),
367 ZT("\001#"),
368 ZT("\001$"),
369 ZT("\001%"),
370 ZT("\005&"),
371 ZT("\006'"),
372 ZT("\001("),
373 ZT("\001)"),
374 krisbash 1.3 ZT("\001*"),
375 ZT("\001+"),
376 ZT("\001,"),
377 ZT("\001-"),
378 ZT("\001."),
379 ZT("\001/"),
380 ZT("\0010"),
381 ZT("\0011"),
382 ZT("\0012"),
383 ZT("\0013"),
384 ZT("\0014"),
385 ZT("\0015"),
386 ZT("\0016"),
387 ZT("\0017"),
388 ZT("\0018"),
389 ZT("\0019"),
390 ZT("\001:"),
391 ZT("\001;"),
392 ZT("\004<"),
393 ZT("\001="),
394 ZT("\004>"),
395 krisbash 1.3 ZT("\001?"),
396 ZT("\001@"),
397 ZT("\001A"),
398 ZT("\001B"),
399 ZT("\001C"),
400 ZT("\001D"),
401 ZT("\001E"),
402 ZT("\001F"),
403 ZT("\001G"),
404 ZT("\001H"),
405 ZT("\001I"),
406 ZT("\001J"),
407 ZT("\001K"),
408 ZT("\001L"),
409 ZT("\001M"),
410 ZT("\001N"),
411 ZT("\001O"),
412 ZT("\001P"),
413 ZT("\001Q"),
414 ZT("\001R"),
415 ZT("\001S"),
416 krisbash 1.3 ZT("\001T"),
417 ZT("\001U"),
418 ZT("\001V"),
419 ZT("\001W"),
420 ZT("\001X"),
421 ZT("\001Y"),
422 ZT("\001Z"),
423 ZT("\001["),
424 ZT("\001\\"),
425 ZT("\001]"),
426 ZT("\001^"),
427 ZT("\001_"),
428 ZT("\001`"),
429 ZT("\001a"),
430 ZT("\001b"),
431 ZT("\001c"),
432 ZT("\001d"),
433 ZT("\001e"),
434 ZT("\001f"),
435 ZT("\001g"),
436 ZT("\001h"),
437 krisbash 1.3 ZT("\001i"),
438 ZT("\001j"),
439 ZT("\001k"),
440 ZT("\001l"),
441 ZT("\001m"),
442 ZT("\001n"),
443 ZT("\001o"),
444 ZT("\001p"),
445 ZT("\001q"),
446 ZT("\001r"),
447 ZT("\001s"),
448 ZT("\001t"),
449 ZT("\001u"),
450 ZT("\001v"),
451 ZT("\001w"),
452 ZT("\001x"),
453 ZT("\001y"),
454 ZT("\001z"),
455 ZT("\001{"),
456 ZT("\001|"),
457 ZT("\001}"),
458 krisbash 1.3 ZT("\001~"),
459 ZT("\006"),
|
460 mike 1.1 };
461
|
462 krisbash 1.3 #if defined(_MSC_VER)
463 #pragma warning( pop )
464 #endif
465
|
466 mike 1.1 /* This table idnetifies special XML characters. */
467 static const char s_specialChars[256] =
468 {
469 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
470 0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,
471 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
472 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
473 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
474 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
475 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
476 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
477 };
478
479 /*
480 **==============================================================================
481 **
482 ** Local definitions:
483 **
484 **==============================================================================
485 */
486 MI_INLINE MI_Boolean _Field_GetExists(
487 mike 1.1 const void* field,
488 MI_Type type)
489 {
490 return Field_GetExists((const Field*)field, type);
491 }
492
493 static MI_Result _ReallocPage(
494 WSBuf* buf,
495 MI_Uint32 newSize)
496 {
497 Page* new_page;
498
499 /* round up to next 1k */
500 #define WSMAN_BUF_CAPACITY 1024
|
501 krisbash 1.3 newSize = ((newSize + WSMAN_BUF_CAPACITY)/ WSMAN_BUF_CAPACITY)* WSMAN_BUF_CAPACITY;
502 new_page = (Page*)PAL_Realloc(buf->page, sizeof(Page)+ newSize);
|
503 mike 1.1
504 if (!new_page)
505 return MI_RESULT_FAILED;
506
507 buf->page = new_page;
508 buf->page->u.s.size = newSize;
509 return MI_RESULT_OK;
510 }
511
512 #if 0
513 #if (MI_CHAR_TYPE == 1)
514 #define FIRST_HIGH_SURROGATE 0xD800
515 #define LAST_HIGH_SURROGATE 0xDBFF
516
517 static void _UTF16toUTF8(
518 MI_Char16 c,
519 char* s)
520 {
521 static const MI_Uint8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
522 MI_Uint8* tgt = (MI_Uint8*)s;
523 MI_Uint32 numberOfBytes;
524 mike 1.1
525 /* not a valid single char */
526 if (c >= FIRST_HIGH_SURROGATE
527 && c <= LAST_HIGH_SURROGATE)
528 {
529 s[0] = '?';
530 s[1] = 0;
531 return;
532 }
533
534 if (c < 0x80)
535 {
536 numberOfBytes = 1;
537 }
538 else if (c < 0x800)
539 {
540 numberOfBytes = 2;
541 }
542 else
543 {
544 numberOfBytes = 3;
545 mike 1.1 }
546
547 tgt += numberOfBytes;
548
549 switch (numberOfBytes)
550 {
551 case 3:
|
552 krisbash 1.3 *--tgt = (MI_Uint8)((c | 0x80)& 0xBF);
|
553 mike 1.1 c >>= 6;
554 case 2:
|
555 krisbash 1.3 *--tgt = (MI_Uint8)((c | 0x80)& 0xBF);
|
556 mike 1.1 c >>= 6;
557 case 1:
558 *--tgt = (MI_Uint8)(c | firstByteMark[numberOfBytes]);
559 }
560 }
561 #endif
562 #endif
563
564 /*
565 **==============================================================================
566 **
567 ** Public API:
568 **
569 **==============================================================================
570 */
|
571 krisbash 1.3
|
572 mike 1.1 MI_Result WSBuf_Init(
573 WSBuf* buf,
574 MI_Uint32 initialSize)
575 {
|
576 krisbash 1.3 buf->page = (Page*)PAL_Malloc(sizeof(Page)+ initialSize);
|
577 mike 1.1 buf->position = 0;
578
579 if (!buf->page)
580 {
581 return MI_RESULT_FAILED;
582 }
583
584 buf->page->u.s.size = initialSize;
585 buf->page->u.s.next = 0;
586 /* Put empty string inside */
|
587 krisbash 1.3 ((ZChar*)(buf->page +1))[0] = 0;
|
588 mike 1.1 return MI_RESULT_OK;
589 }
590
591 MI_Result WSBuf_Destroy(
592 WSBuf* buf)
593 {
594 if (buf->page)
|
595 krisbash 1.3 PAL_Free(buf->page);
|
596 mike 1.1
597 return MI_RESULT_OK;
598 }
599
600 Page* WSBuf_StealPage(
601 WSBuf* buf)
602 {
603 Page* res = buf->page;
604
605 if (!res)
606 return 0;
607
608 buf->page = 0;
609 res->u.s.size = buf->position;
610 buf->position = 0;
611
612 return res;
613 }
|
614 krisbash 1.3
615 MI_Result WSBuf_AddUint32(
616 WSBuf* buf,
617 MI_Uint32 x)
|
618 mike 1.1 {
|
619 krisbash 1.3 ZChar tmp[12];
620 size_t size;
621 const ZChar* s = Uint32ToZStr(tmp, x, &size);
622 return WSBuf_AddLit(buf, s, (MI_Uint32)size);
623 }
|
624 mike 1.1
|
625 krisbash 1.3 MI_Result __WSBuf_AddLit(
626 WSBuf* buf,
627 const ZChar* str,
628 MI_Uint32 size)
629 {
630 MI_Uint32 n = (size + 1)* sizeof(ZChar);
|
631 mike 1.1
|
632 krisbash 1.3 /* Extend buffer (WSBuf_AddLit determined it was too small)*/
633 if (_ReallocPage(buf, n + buf->position)!= MI_RESULT_OK)
634 return MI_RESULT_FAILED;
|
635 mike 1.1
|
636 krisbash 1.3 /* Add string */
|
637 mike 1.1 {
|
638 krisbash 1.3 char* data = ((char*)(buf->page+1))+ buf->position;
639 memcpy(data, str, n - sizeof(ZChar));
640 ((ZChar*)data)[size] = 0;
|
641 mike 1.1
|
642 krisbash 1.3 buf->position += n - sizeof(ZChar);
643 }
|
644 mike 1.1
|
645 krisbash 1.3 return MI_RESULT_OK;
646 }
|
647 mike 1.1
|
648 krisbash 1.3 MI_Result WSBuf_AddStartTag(
649 WSBuf* buf,
650 const ZChar* tag,
651 MI_Uint32 size)
652 {
653 /* Add 2 bytes for "<" and ">" */
654 MI_Uint32 n = (size + 1 + 2)* sizeof(ZChar);
|
655 mike 1.1
|
656 krisbash 1.3 /* Extend buffer (WSBuf_AddLit determined it was too small)*/
657 if (_ReallocPage(buf, n + buf->position)!= MI_RESULT_OK)
658 return MI_RESULT_FAILED;
|
659 mike 1.1
|
660 krisbash 1.3 /* Add string */
661 {
662 ZChar* data = (ZChar*)(((char*)(buf->page+1))+ buf->position);
663 data[0] = '<';
664 memcpy(data + 1, tag, n - sizeof(ZChar));
665 data[size + 1] = '>';
666 data[size + 2] = 0;
|
667 mike 1.1
|
668 krisbash 1.3 buf->position += n - sizeof(ZChar);
|
669 mike 1.1 }
670
|
671 krisbash 1.3 return MI_RESULT_OK;
|
672 mike 1.1 }
673
|
674 krisbash 1.3 MI_Result WSBuf_AddEndTag(
|
675 mike 1.1 WSBuf* buf,
|
676 krisbash 1.3 const ZChar* tag,
|
677 mike 1.1 MI_Uint32 size)
678 {
|
679 krisbash 1.3 /* Add 3 bytes for "</" and ">" */
680 MI_Uint32 n = (size + 1 + 3)* sizeof(ZChar);
|
681 mike 1.1
|
682 krisbash 1.3 /* Extend buffer (WSBuf_AddLit determined it was too small)*/
683 if (_ReallocPage(buf, n + buf->position)!= MI_RESULT_OK)
|
684 mike 1.1 return MI_RESULT_FAILED;
685
686 /* Add string */
687 {
|
688 krisbash 1.3 ZChar* data = (ZChar*)(((char*)(buf->page+1))+ buf->position);
689 data[0] = '<';
690 data[1] = '/';
691 memcpy(data + 2, tag, n - sizeof(ZChar));
692 data[size + 2] = '>';
693 data[size + 3] = 0;
|
694 mike 1.1
|
695 krisbash 1.3 buf->position += n - sizeof(ZChar);
|
696 mike 1.1 }
697
698 return MI_RESULT_OK;
699 }
700
701 /* Add string with proper xml encoding */
702 MI_Result WSBuf_AddString(
703 WSBuf* buf,
|
704 krisbash 1.3 const ZChar* str)
|
705 mike 1.1 {
706 #if (MI_CHAR_TYPE == 1)
|
707 krisbash 1.3
|
708 mike 1.1 /* Process leading non-special characters in the hope that little will
709 * be left over to be encoded the expensive way below this block.
710 */
711 {
712 const unsigned char* start = (const unsigned char*)str;
713 const unsigned char* p = start;
714
715 while (!s_specialChars[*p])
716 p++;
717
718 if (p != start)
719 {
720 if (WSBuf_AddLit(buf, (const char*)start, (MI_Uint32)(p - start)))
721 return MI_RESULT_FAILED;
722
723 str = (const char*)p;
724 }
725
726 if (!*str)
727 return MI_RESULT_OK;
728 }
|
729 krisbash 1.3
|
730 mike 1.1 #endif
731
|
732 krisbash 1.3 /* Now encode what remains (starting with first special char hit above)*/
|
733 mike 1.1 {
|
734 krisbash 1.3 /*MI_Uint32 size = (MI_Uint32)((MI_Strlen(str)+ 1)*sizeof(ZChar));*/
735 ZChar* start = (ZChar*)(((char*)(buf->page +1))+ buf->position);
736 ZChar* pos = start;
737 ZChar* end = (ZChar*)(((char*)(buf->page +1))+ buf->page->u.s.size);
738 /* Add reamingin characters (next character is special)*/
|
739 mike 1.1 while (*str)
740 {
|
741 krisbash 1.3 const ZChar* item;
|
742 mike 1.1 size_t size_chars;
743 MI_Uint32 c = (MI_Uint32)(MI_Sint16)*str;
744
745 /* if c is ascii ?*/
746 if (c < 128)
747 {
748 /* First byte is the length */
749 item = s_specialCharEncodings[c] + 1;
750 size_chars = s_specialCharEncodings[c][0];
751 }
752 else
753 {
754 item = str;
755 size_chars = 1;
756 }
757
758 /* Extend buffer if needed */
|
759 krisbash 1.3 if ((size_t)(end - pos)<= (size_chars + 1))
|
760 mike 1.1 {
761 size_t current_pos =
|
762 krisbash 1.3 (pos - ((ZChar*)(buf->page +1)))* sizeof(ZChar);
|
763 mike 1.1
|
764 krisbash 1.3 if (_ReallocPage(buf, (MI_Uint32)(buf->page->u.s.size + size_chars * sizeof(ZChar)))!= MI_RESULT_OK)
|
765 mike 1.1 return MI_RESULT_FAILED;
766
|
767 krisbash 1.3 pos = (ZChar*)(((char*)(buf->page +1))+ current_pos);
768 end = (ZChar*)(((char*)(buf->page +1))+ buf->page->u.s.size);
|
769 mike 1.1 }
770
771 if (1 == size_chars)
772 *pos = *item;
773 else
|
774 krisbash 1.3 memcpy(pos, item, size_chars * sizeof(ZChar));
|
775 mike 1.1
776 pos += size_chars;
777 str++;
778 }
779
|
780 krisbash 1.3 buf->position = (MI_Uint32)((pos - ((ZChar*)(buf->page +1)))* sizeof(ZChar));
|
781 mike 1.1
782 /* put \0 at the end */
|
783 krisbash 1.3 ((ZChar*)(((char*)(buf->page +1))+ buf->position))[0] = 0;
|
784 mike 1.1
785 return MI_RESULT_OK;
786 }
787 }
788
|
789 krisbash 1.3 #if defined(CONFIG_ENABLE_WCHAR)
|
790 mike 1.1 MI_Result WSBuf_AddCharLit(
791 WSBuf* buf,
792 const char* str,
793 MI_Uint32 size_)
794 {
|
795 krisbash 1.3 MI_Uint32 size = (MI_Uint32)((size_ + 1)*sizeof(ZChar));
|
796 mike 1.1
797 /* Extend buffer if needed */
798 if (size + buf->position > buf->page->u.s.size &&
|
799 krisbash 1.3 _ReallocPage(buf, size + buf->position)!= MI_RESULT_OK)
|
800 mike 1.1 return MI_RESULT_FAILED;
801
802 {
|
803 krisbash 1.3 ZChar* data = (ZChar*)(((char*)(buf->page +1))+ buf->position);
|
804 mike 1.1 MI_Uint32 i;
805
806 for (i = 0; i < size_; i++)
807 {
808 *data++ = *str++;
809 }
|
810 krisbash 1.3 buf->position += size - sizeof(ZChar);
|
811 mike 1.1 }
812
813 return MI_RESULT_OK;
814 }
|
815 krisbash 1.3 #endif /* defined(CONFIG_ENABLE_WCHAR)*/
|
816 mike 1.1
|
817 krisbash 1.3 MI_Result WSBuf_AddVerbatim(
818 WSBuf* buf,
819 const void* data,
820 MI_Uint32 size)
821 {
822 size_t newSize = buf->position + size;
823
824 /* Extend buffer if needed */
825 if (newSize > buf->page->u.s.size)
826 {
827 if (_ReallocPage(buf, newSize)!= MI_RESULT_OK)
828 return MI_RESULT_FAILED;
829 }
830
831 {
832 void* pos = ((char*)(buf->page + 1))+ buf->position;
833 memcpy(pos, data, size);
834 buf->position += size;
835 }
836
837 return MI_RESULT_OK;
838 krisbash 1.3 }
839
840 #if defined(CONFIG_ENABLE_WCHAR)
841 MI_Result WSBuf_AddCharStringNoEncoding(
842 WSBuf* buf,
843 const char* str)
844 {
845 return WSBuf_AddCharLit(buf, str, (MI_Uint32)strlen(str));
846 }
847 #endif /* defined(CONFIG_ENABLE_WCHAR)*/
|
848 mike 1.1
849 /* Callback to tag writer:
850 allows to write properties for both values/EPRs with the same routine */
851 typedef MI_Result (*PropertyTagWriter)(
852 WSBuf* buf,
|
853 krisbash 1.3 const ZChar* name,
854 MI_Boolean start,
855 MI_Uint32 flags,
856 const ZChar* nsPrefix);
857
858 static MI_Result PackCimErrorXsiType(
859 WSBuf* buf,
860 MI_Uint32 nameLength,
861 const ZChar* name)
862 {
863 if (((nameLength == 13) && (Tcscmp(name, ZT("CIMStatusCode")) == 0)) ||
864 ((nameLength == 12) && (Tcscmp(name, ZT("OMI_Category")) == 0)) ||
865 ((nameLength == 8) && (Tcscmp(name, ZT("OMI_Code")) == 0)) ||
866 ((nameLength == 17) && (Tcscmp(name, ZT("PerceivedSeverity")) == 0)) ||
867 ((nameLength == 13) && (Tcscmp(name, ZT("ProbableCause")) == 0)))
868 {
869 if (MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT(" xsi:type=\"cim:cimUnsignedInt\""))))
870 {
871 return MI_RESULT_FAILED;
872 }
873 }
874 krisbash 1.3 else
875 if (((nameLength == 7) && (Tcscmp(name, ZT("Message")) == 0)) ||
876 ((nameLength == 16) && (Tcscmp(name, ZT("MessageArguments")) == 0)) ||
877 ((nameLength == 9) && (Tcscmp(name, ZT("MessageID")) == 0)) ||
878 ((nameLength == 16) && (Tcscmp(name, ZT("OMI_ErrorMessage")) == 0)) ||
879 ((nameLength == 8) && (Tcscmp(name, ZT("OMI_Type")) == 0)) ||
880 ((nameLength == 12) && (Tcscmp(name, ZT("OwningEntity")) == 0)) ||
881 ((nameLength == 24) && (Tcscmp(name, ZT("ProbableCauseDescription")) == 0)))
882 {
883 if (MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT(" xsi:type=\"cim:cimString\""))))
884 {
885 return MI_RESULT_FAILED;
886 }
887 }
888 return MI_RESULT_OK;
889 }
|
890 mike 1.1
891 INLINE MI_Result PropertyTagWriter_PropStart(
892 WSBuf* buf,
|
893 krisbash 1.3 const ZChar* name,
894 MI_Uint32 flags,
895 const ZChar* nsPrefix)
|
896 mike 1.1 {
|
897 krisbash 1.3 MI_Uint32 n = (MI_Uint32)Tcslen(name);
|
898 mike 1.1
|
899 krisbash 1.3 if (WSBuf_AddLit1(buf, '<') != MI_RESULT_OK ||
900 WSBuf_AddStringNoEncoding(buf, nsPrefix) != MI_RESULT_OK ||
901 WSBuf_AddLit1(buf, ':') != MI_RESULT_OK ||
902 MI_RESULT_OK != WSBuf_AddLit(buf, name, n))
903 {
904 return MI_RESULT_FAILED;
905 }
906 if (flags & WSMAN_IsCimError)
907 {
908 if (MI_RESULT_OK != PackCimErrorXsiType(buf, n, name))
909 {
910 return MI_RESULT_FAILED;
911 }
912 }
913 if (MI_RESULT_OK != WSBuf_AddLit1(buf,'>'))
|
914 mike 1.1 {
915 return MI_RESULT_FAILED;
916 }
917 return MI_RESULT_OK;
918 }
919
920 INLINE MI_Result PropertyTagWriter_PropEnd(
921 WSBuf* buf,
|
922 krisbash 1.3 const ZChar* name,
923 MI_Uint32 flags,
924 const ZChar* nsPrefix)
|
925 mike 1.1 {
|
926 krisbash 1.3 MI_Uint32 n = (MI_Uint32)Tcslen(name);
|
927 mike 1.1
|
928 krisbash 1.3 if (WSBuf_AddLit2(buf, '<', '/') != MI_RESULT_OK ||
929 WSBuf_AddStringNoEncoding(buf, nsPrefix) != MI_RESULT_OK ||
930 WSBuf_AddLit1(buf, ':') != MI_RESULT_OK ||
931 MI_RESULT_OK != WSBuf_AddLit(buf, name, n)||
|
932 mike 1.1 MI_RESULT_OK != WSBuf_AddLit2(buf, '>', '\n'))
933 {
934 return MI_RESULT_FAILED;
935 }
936
937 return MI_RESULT_OK;
938 }
939
940 static MI_Result PropertyTagWriter_Prop(
941 WSBuf* buf,
|
942 krisbash 1.3 const ZChar* name,
943 MI_Boolean start,
944 MI_Uint32 flags,
945 const ZChar* nsPrefix)
|
946 mike 1.1 {
947 if (start)
|
948 krisbash 1.3 return PropertyTagWriter_PropStart(buf, name, flags, nsPrefix);
|
949 mike 1.1 else
|
950 krisbash 1.3 return PropertyTagWriter_PropEnd(buf, name, flags, nsPrefix);
|
951 mike 1.1 }
952
953 static MI_Result PropertyTagWriter_EPR(
954 WSBuf* buf,
|
955 krisbash 1.3 const ZChar* name,
956 MI_Boolean start,
957 MI_Uint32 flags,
958 const ZChar* nsPrefix) //ignored
|
959 mike 1.1 {
960 if (start)
961 {
|
962 krisbash 1.3 if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("<wsman:Selector Name=\"")))||
963 MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf,name)||
|
964 mike 1.1 MI_RESULT_OK != WSBuf_AddLit2(buf, '"', '>')
|
965 krisbash 1.3 )
|
966 mike 1.1 return MI_RESULT_FAILED;
967 }
968 else
969 {
|
970 krisbash 1.3 if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("</wsman:Selector>")XML_CR))
971 )
|
972 mike 1.1 return MI_RESULT_FAILED;
973 }
974
975 return MI_RESULT_OK;
976 }
977
978 static MI_Result _PackFieldNil(
979 WSBuf* buf,
|
980 krisbash 1.3 const ZChar* name,
981 MI_Type type,
982 MI_Uint32 flags,
983 const ZChar* parentNSPrefix)
|
984 mike 1.1 {
|
985 krisbash 1.3 if (WSBuf_AddLit1(buf, '<') != MI_RESULT_OK ||
986 WSBuf_AddStringNoEncoding(buf, parentNSPrefix) != MI_RESULT_OK ||
987 WSBuf_AddLit1(buf, ':') != MI_RESULT_OK ||
988 MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf,name))
989 return MI_RESULT_FAILED;
990
991 trace_Wsman_PackFieldNil( ((flags & WSMAN_UsePreciseArrays) != 0) );
992 // adding msft specific attributes
993 if (((flags & WSMAN_UsePreciseArrays) != 0) && (type & MI_ARRAY_BIT))
994 {
995 if(MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT(" msftwinrm:IsNullArray=\"true\""))))
996 return MI_RESULT_FAILED;
997 }
998
999 if(MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT(" xsi:nil=\"true\""))))
|
1000 mike 1.1 return MI_RESULT_FAILED;
1001
|
1002 krisbash 1.3 if (flags & WSMAN_IsCimError)
1003 {
1004 MI_Uint32 n = (MI_Uint32)Tcslen(name);
1005
1006 if (MI_RESULT_OK != PackCimErrorXsiType(buf, n, name))
1007 {
1008 return MI_RESULT_FAILED;
1009 }
1010 }
1011 if (MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT("/>")XML_CR)))
1012 {
1013 return MI_RESULT_FAILED;
1014 }
1015
|
1016 mike 1.1 return MI_RESULT_OK;
1017 }
1018
1019 static int _Base64Callback(
1020 const char* data,
1021 size_t size,
1022 void* callbackData)
1023 {
1024 WSBuf* buf = callbackData;
|
1025 krisbash 1.3 return WSBuf_AddCharLit(buf, data, size)== MI_RESULT_OK ? 0 : -1;
|
1026 mike 1.1 }
1027
1028 static MI_Result _PackFieldOctetString(
1029 WSBuf* buf,
|
1030 krisbash 1.3 const ZChar* name,
|
1031 mike 1.1 const MI_Uint8* data,
|
1032 krisbash 1.3 size_t size,
1033 const ZChar* nsPrefix)
|
1034 mike 1.1 {
1035 /* Validate first 4 bytes which contain the length then remove them */
1036 {
1037 size_t length = 0;
1038
1039 if (size < 4)
1040 return MI_RESULT_FAILED;
1041
|
1042 krisbash 1.3 length |= ((size_t)data[0]) << 24;
1043 length |= ((size_t)data[1]) << 16;
1044 length |= ((size_t)data[2]) << 8;
|
1045 mike 1.1 length |= data[3];
1046
1047 if (length != size)
1048 return MI_RESULT_FAILED;
1049
1050 data += 4;
1051 size -= 4;
1052 }
1053
|
1054 krisbash 1.3 if (WSBuf_AddLit1(buf, '<') != MI_RESULT_OK ||
1055 WSBuf_AddStringNoEncoding(buf, nsPrefix) != MI_RESULT_OK ||
1056 WSBuf_AddLit1(buf, ':') != MI_RESULT_OK)
|
1057 mike 1.1 return MI_RESULT_FAILED;
1058
|
1059 krisbash 1.3 if (WSBuf_AddStringNoEncoding(buf, name)!= MI_RESULT_OK)
|
1060 mike 1.1 return MI_RESULT_FAILED;
1061
1062 if (WSBuf_AddLit(buf,
|
1063 krisbash 1.3 LIT(ZT(" xsi:type=\"cim:cimBase64Binary\">")))!= MI_RESULT_OK)
|
1064 mike 1.1 {
1065 return MI_RESULT_FAILED;
1066 }
1067
|
1068 krisbash 1.3 if (Base64Enc(data, size, _Base64Callback, buf)!= 0)
|
1069 mike 1.1 return MI_RESULT_FAILED;
1070
|
1071 krisbash 1.3 if (PropertyTagWriter_PropEnd(buf, name, 0, nsPrefix)!= MI_RESULT_OK)
|
1072 mike 1.1 return MI_RESULT_FAILED;
1073
1074 return MI_RESULT_OK;
1075 }
1076
1077 static MI_Result _PackFieldString(
1078 WSBuf* buf,
1079 PropertyTagWriter writer,
|
1080 krisbash 1.3 const ZChar* name,
1081 const ZChar* value,
1082 MI_Uint32 flags,
1083 const ZChar* nsPrefix)
|
1084 mike 1.1 {
|
1085 krisbash 1.3 if (MI_RESULT_OK != writer(buf,name,MI_TRUE, flags, nsPrefix)||
1086 MI_RESULT_OK != WSBuf_AddString(buf,value)||
1087 MI_RESULT_OK != writer(buf,name,MI_FALSE, flags, nsPrefix)
1088 )
|
1089 mike 1.1 return MI_RESULT_FAILED;
1090
1091 return MI_RESULT_OK;
1092 }
1093
1094 static MI_Result _PackFieldStringLit(
1095 WSBuf* buf,
1096 PropertyTagWriter writer,
|
1097 krisbash 1.3 const ZChar* name,
1098 const ZChar* value,
1099 MI_Uint32 valueSize,
1100 MI_Uint32 flags,
1101 const ZChar* nsPrefix)
1102 {
1103 if (MI_RESULT_OK != writer(buf,name,MI_TRUE, flags, nsPrefix)||
1104 MI_RESULT_OK != WSBuf_AddLit(buf,value,valueSize)||
1105 MI_RESULT_OK != writer(buf,name,MI_FALSE, flags, nsPrefix)
1106 )
|
1107 mike 1.1 return MI_RESULT_FAILED;
1108
1109 return MI_RESULT_OK;
1110 }
1111
1112 static MI_Result _PackFieldEmbeddedInstance(
|
1113 krisbash 1.3 UserAgent userAgent,
|
1114 mike 1.1 WSBuf* buf,
|
1115 krisbash 1.3 const ZChar* name,
1116 const MI_Instance* value,
1117 MI_Uint32 flags,
1118 MI_Uint32 *lastPrefixIndex,
1119 const ZChar* parentNSPrefix)
|
1120 mike 1.1 {
|
1121 krisbash 1.3 if (MI_RESULT_OK != _PackInstance(
1122 buf,
1123 userAgent,
1124 value,
1125 NULL,
1126 NULL,
1127 0,
1128 WSMAN_ObjectFlag | flags,
1129 MI_TRUE,
1130 name,
1131 lastPrefixIndex,
1132 parentNSPrefix))
1133 {
|
1134 mike 1.1 return MI_RESULT_FAILED;
|
1135 krisbash 1.3 }
|
1136 mike 1.1
1137 return MI_RESULT_OK;
1138 }
1139
1140 static MI_Result _PackFieldRef(
1141 WSBuf* buf,
|
1142 krisbash 1.3 PropertyTagWriter writer,
1143 UserAgent userAgent,
1144 const ZChar* name,
1145 const MI_Instance* value,
1146 MI_Uint32 flags,
1147 const ZChar* nsPrefix)
|
1148 mike 1.1 {
|
1149 krisbash 1.3 if (MI_RESULT_OK != writer(buf,name, MI_TRUE, 0, nsPrefix)||
1150 MI_RESULT_OK != _PackEPR(buf, userAgent, value, flags)||
1151 MI_RESULT_OK != writer(buf,name, MI_FALSE, 0, nsPrefix)
1152 )
|
1153 mike 1.1 return MI_RESULT_FAILED;
1154
1155 return MI_RESULT_OK;
1156 }
1157
1158 static MI_Result _PackFieldUint32(
1159 WSBuf* buf,
1160 PropertyTagWriter writer,
|
1161 krisbash 1.3 const ZChar* name,
1162 MI_Uint32 value,
1163 MI_Uint32 flags,
1164 const ZChar* nsPrefix)
|
1165 mike 1.1 {
|
1166 krisbash 1.3 ZChar tmp[11];
|
1167 mike 1.1 size_t size;
|
1168 krisbash 1.3 const ZChar* str = Uint32ToZStr(tmp, value, &size);
1169 return _PackFieldStringLit(buf,writer, name, str, (MI_Uint32)size, flags, nsPrefix);
|
1170 mike 1.1 }
1171
1172 static MI_Result _PackFieldUint64(
1173 WSBuf* buf,
1174 PropertyTagWriter writer,
|
1175 krisbash 1.3 const ZChar* name,
1176 MI_Uint64 value,
1177 MI_Uint32 flags,
1178 const ZChar* nsPrefix)
|
1179 mike 1.1 {
|
1180 krisbash 1.3 ZChar tmp[21];
|
1181 mike 1.1 size_t size;
|
1182 krisbash 1.3 const ZChar* str = NULL;
1183 Uint64ToZStr(tmp, value, &str, &size);
1184 return _PackFieldStringLit(buf, writer, name, str, (MI_Uint32)size, flags, nsPrefix);
|
1185 mike 1.1 }
1186
1187 static MI_Result _PackFieldSint32(
1188 WSBuf* buf,
1189 PropertyTagWriter writer,
|
1190 krisbash 1.3 const ZChar* name,
1191 MI_Sint32 value,
1192 MI_Uint32 flags,
1193 const ZChar* nsPrefix)
|
1194 mike 1.1 {
|
1195 krisbash 1.3 ZChar s[24];
|
1196 mike 1.1
|
1197 krisbash 1.3 MI_Sint32 size = Stprintf(s, MI_COUNT(s), ZT("%d"), value);
1198 return _PackFieldStringLit(buf,writer,name,s,size, flags, nsPrefix);
|
1199 mike 1.1 }
1200
1201 static MI_Result _PackFieldSint64(
1202 WSBuf* buf,
1203 PropertyTagWriter writer,
|
1204 krisbash 1.3 const ZChar* name,
1205 MI_Sint64 value,
1206 MI_Uint32 flags,
1207 const ZChar* nsPrefix)
|
1208 mike 1.1 {
|
1209 krisbash 1.3 ZChar s[24];
|
1210 mike 1.1
|
1211 krisbash 1.3 MI_Sint32 size = Stprintf(s, MI_COUNT(s), SINT64_FMT_T, value);
1212 return _PackFieldStringLit(buf,writer,name,s,size,flags, nsPrefix);
|
1213 mike 1.1 }
1214
1215 static MI_Result _PackFieldReal64(
1216 WSBuf* buf,
1217 PropertyTagWriter writer,
|
1218 krisbash 1.3 const ZChar* name,
1219 MI_Real64 value,
1220 MI_Uint32 flags,
1221 const ZChar* nsPrefix)
|
1222 mike 1.1 {
|
1223 krisbash 1.3 ZChar s[24];
|
1224 mike 1.1
|
1225 krisbash 1.3 /* Use DBL_DIG=15 for precision. Check MSDN DBL_DIG */
1226 MI_Sint32 size = Stprintf(s, MI_COUNT(s), ZT("%.15g"), value);
1227 return _PackFieldStringLit(buf,writer,name,s,size,flags, nsPrefix);
|
1228 mike 1.1 }
1229
1230 static MI_Result _PackFieldDatetime(
1231 WSBuf* buf,
|
1232 krisbash 1.3 UserAgent userAgent,
|
1233 mike 1.1 PropertyTagWriter writer,
|
1234 krisbash 1.3 const ZChar* name,
1235 const MI_Datetime* p,
1236 MI_Uint32 flags,
1237 const ZChar* nsPrefix)
|
1238 mike 1.1 {
|
1239 krisbash 1.3 ZChar tmp[64];
1240 const ZChar* tag = NULL;
|
1241 mike 1.1 FormatWSManDatetime(p, tmp);
|
1242 krisbash 1.3
1243 if (writer(buf,name,MI_TRUE, flags, nsPrefix)!= MI_RESULT_OK)
1244 return MI_RESULT_FAILED;
1245
1246 if (userAgent == USERAGENT_WINRM)
1247 {
1248 tag = p->isTimestamp ? ZT("cim:Datetime"): ZT("cim:Interval");
1249 WSBuf_AddStartTag(buf, tag, 12);
1250 }
1251
1252 if (WSBuf_AddLit(buf, tmp, (MI_Uint32)Tcslen(tmp))!= MI_RESULT_OK)
1253 return MI_RESULT_FAILED;
1254
1255 if (userAgent == USERAGENT_WINRM)
1256 WSBuf_AddEndTag(buf, tag, 12);
1257
1258 if (writer(buf, name, MI_FALSE, flags, nsPrefix)!= MI_RESULT_OK)
1259 return MI_RESULT_FAILED;
1260
1261 return MI_RESULT_OK;
|
1262 mike 1.1 }
1263
1264 static MI_Result _PackValue(
1265 WSBuf* buf,
|
1266 krisbash 1.3 UserAgent userAgent,
|
1267 mike 1.1 PropertyTagWriter writer,
|
1268 krisbash 1.3 const ZChar* name,
|
1269 mike 1.1 const void* field,
|
1270 krisbash 1.3 MI_Type type,
1271 MI_Uint32 flags,
1272 MI_Uint32 *lastPrefixIndex,
1273 const ZChar* parentNSPrefix)
|
1274 mike 1.1 {
1275 switch(type)
1276 {
1277 case MI_BOOLEAN:
1278 {
1279 MI_Boolean* f = (MI_Boolean*)field;
1280
1281 if (*f)
|
1282 krisbash 1.3 return _PackFieldStringLit(buf,writer,name,LIT(ZT("TRUE")),flags, parentNSPrefix);
|
1283 mike 1.1 else
|
1284 krisbash 1.3 return _PackFieldStringLit(buf, writer, name, LIT(ZT("FALSE")), flags, parentNSPrefix);
|
1285 mike 1.1 }
1286 case MI_UINT8:
1287 {
1288 MI_Uint8* f = (MI_Uint8*)field;
1289
|
1290 krisbash 1.3 return _PackFieldUint32(buf, writer, name, *f, flags, parentNSPrefix);
|
1291 mike 1.1 }
1292 case MI_UINT16:
1293 {
1294 MI_Uint16* f = (MI_Uint16*)field;
1295
|
1296 krisbash 1.3 return _PackFieldUint32(buf, writer, name, *f, flags, parentNSPrefix);
|
1297 mike 1.1 }
1298 case MI_UINT32:
1299 {
1300 MI_Uint32* f = (MI_Uint32*)field;
1301
|
1302 krisbash 1.3 return _PackFieldUint32(buf, writer, name, *f, flags, parentNSPrefix);
|
1303 mike 1.1 }
1304 case MI_UINT64:
1305 {
1306 MI_Uint64* f = (MI_Uint64*)field;
1307
|
1308 krisbash 1.3 return _PackFieldUint64(buf, writer, name, *f, flags, parentNSPrefix);
|
1309 mike 1.1 }
1310 case MI_SINT8:
1311 {
1312 MI_Sint8* f = (MI_Sint8*)field;
1313
|
1314 krisbash 1.3 return _PackFieldSint32(buf, writer, name, *f, flags, parentNSPrefix);
|
1315 mike 1.1 }
1316 case MI_SINT16:
1317 {
1318 MI_Sint16* f = (MI_Sint16*)field;
1319
|
1320 krisbash 1.3 return _PackFieldSint32(buf, writer, name, *f, flags, parentNSPrefix);
|
1321 mike 1.1 }
1322 case MI_SINT32:
1323 {
1324 MI_Sint32* f = (MI_Sint32*)field;
1325
|
1326 krisbash 1.3 return _PackFieldSint32(buf,writer,name,*f, flags, parentNSPrefix);
|
1327 mike 1.1 }
1328 case MI_SINT64:
1329 {
1330 MI_Sint64* f = (MI_Sint64*)field;
1331
|
1332 krisbash 1.3 return _PackFieldSint64(buf, writer, name, *f, flags, parentNSPrefix);
|
1333 mike 1.1 }
1334 case MI_REAL32:
1335 {
1336 MI_Real32* f = (MI_Real32*)field;
1337
|
1338 krisbash 1.3 return _PackFieldReal64(buf, writer, name, *f, flags, parentNSPrefix);
|
1339 mike 1.1 }
1340 case MI_REAL64:
1341 {
1342 MI_Real64* f = (MI_Real64*)field;
1343
|
1344 krisbash 1.3 return _PackFieldReal64(buf, writer, name, *f, flags, parentNSPrefix);
|
1345 mike 1.1 }
1346 case MI_DATETIME:
1347 {
1348 MI_Datetime* f = (MI_Datetime*)field;
1349
|
1350 krisbash 1.3 return _PackFieldDatetime(buf, userAgent, writer, name, &*f, flags, parentNSPrefix);
|
1351 mike 1.1 }
1352 case MI_CHAR16:
1353 {
1354 MI_Char16* f = (MI_Char16*)field;
1355 #if 0
1356 #if (MI_CHAR_TYPE == 1)
1357 char s[6];
1358 memset(s,0,sizeof(s));
1359
1360 _UTF16toUTF8(*f,s);
1361 #else
1362 /* whcar_t -
1363 steal page will translate it */
1364 wchar_t s[2] = {0, 0};
1365
1366 s[0] = *f;
1367 #endif
1368
1369 /* ATTN: convert it to utf8 and encode as a string */
|
1370 krisbash 1.3 return _PackFieldString(buf,writer,name,s, flags, parentNSPrefix);
|
1371 mike 1.1 #else
|
1372 krisbash 1.3 return _PackFieldUint32(buf, writer, name, (MI_Uint32)*f, flags, parentNSPrefix);
|
1373 mike 1.1 #endif
1374 }
1375 case MI_INSTANCE:
1376 {
1377 MI_Instance** f = (MI_Instance**)field;
1378
|
1379 krisbash 1.3 return _PackFieldEmbeddedInstance(userAgent, buf, name, *f, flags, lastPrefixIndex, parentNSPrefix);
|
1380 mike 1.1 }
1381 case MI_REFERENCE:
1382 {
1383 MI_Instance** f = (MI_Instance**)field;
1384
|
1385 krisbash 1.3 return _PackFieldRef(buf, writer, userAgent, name, *f, flags, parentNSPrefix);
|
1386 mike 1.1 }
1387 case MI_STRING:
1388 {
1389 MI_String* f = (MI_String*)field;
1390
|
1391 krisbash 1.3 return _PackFieldString(buf, writer, name, *f, flags, parentNSPrefix);
|
1392 mike 1.1 }
1393 default:
1394 break;
1395 }
1396
1397 return MI_RESULT_OK;
1398 }
1399
1400 static MI_Result _PackField(
1401 WSBuf* buf,
|
1402 krisbash 1.3 UserAgent userAgent,
|
1403 mike 1.1 PropertyTagWriter writer,
|
1404 krisbash 1.3 const ZChar* name,
|
1405 mike 1.1 const void* field,
1406 MI_Type type,
|
1407 krisbash 1.3 MI_Boolean isOctetString,
1408 MI_Uint32 flags,
1409 MI_Uint32 *lastPrefixIndex,
1410 const ZChar* parentNSPrefix)
|
1411 mike 1.1 {
1412 /* Check if value is null */
1413 if (!_Field_GetExists(field, type))
|
1414 krisbash 1.3 return _PackFieldNil(buf, name, type, flags, parentNSPrefix);
|
1415 mike 1.1
1416 /* Check if type is array:
1417 Arrays are encoded the same way regular instances are
1418 with repeating instance as many times as many elements are in array */
1419 if (type & MI_ARRAY_BIT)
1420 {
1421 if (isOctetString && type == MI_UINT8A)
1422 {
1423 MI_Uint8AField* f = (MI_Uint8AField*)field;
1424 return _PackFieldOctetString(buf, name, f->value.data,
|
1425 krisbash 1.3 f->value.size, parentNSPrefix);
|
1426 mike 1.1 }
1427
1428 /* ATTN: STRING OctetString not handled! */
1429
1430 {
1431 MI_ArrayField* f = (MI_ArrayField*)field;
1432 MI_Uint32 i;
1433 MI_Type stype = type & ~MI_ARRAY_BIT;
1434 char* currentValue = (char*)f->value.data;
1435
1436 for (i = 0; i < f->value.size; i++)
1437 {
1438 if (_PackValue(
1439 buf,
|
1440 krisbash 1.3 userAgent,
|
1441 mike 1.1 writer,
1442 name,
1443 currentValue,
|
1444 krisbash 1.3 stype,
1445 flags,
1446 lastPrefixIndex,
1447 parentNSPrefix)!= MI_RESULT_OK)
|
1448 mike 1.1 {
1449 return MI_RESULT_FAILED;
1450 }
1451
1452 currentValue += Type_SizeOf(stype);
1453 }
1454
1455 return MI_RESULT_OK;
1456 }
1457 }
1458
|
1459 krisbash 1.3 return _PackValue(buf, userAgent, writer, name, field, type, flags, lastPrefixIndex, parentNSPrefix);
|
1460 mike 1.1 }
1461
1462 static MI_Result _PackEPR(
1463 WSBuf* buf,
|
1464 krisbash 1.3 UserAgent userAgent,
1465 const MI_Instance* instance,
1466 MI_Uint32 flags)
|
1467 mike 1.1 {
|
1468 krisbash 1.3 Instance* self = Instance_GetSelf( instance );
|
1469 mike 1.1 const MI_ClassDecl* cd = self->classDecl;
1470 MI_Uint32 i;
1471
1472 /* Put EPR header */
|
1473 krisbash 1.3 if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>")XML_CR
1474 ZT("<wsa:ReferenceParameters>")XML_CR
1475 ZT("<wsman:ResourceURI>http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/")))||
1476 MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf,cd->name)||
1477 MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("</wsman:ResourceURI>")XML_CR
1478 ZT("<wsman:SelectorSet>")XML_CR)))
|
1479 mike 1.1 return MI_RESULT_FAILED;
1480
1481 /* namespace (if present)*/
1482 if (self->nameSpace)
1483 {
|
1484 krisbash 1.3 WSBuf_AddLit(buf, LIT(ZT("<wsman:Selector Name=\"__cimnamespace\">")));
1485 WSBuf_AddStringNoEncoding(buf, self->nameSpace);
1486 WSBuf_AddLit(buf, LIT(ZT("</wsman:Selector>")));
|
1487 mike 1.1 }
1488
1489 /* Put properties */
|
1490 krisbash 1.3 for (i = 0; i < cd->numProperties; i++)
|
1491 mike 1.1 {
1492 const MI_PropertyDecl* pd = cd->properties[i];
1493 const void* value = (char*)self + pd->offset;
|
1494 krisbash 1.3 MI_Uint32 tmpLastPrefixIndex = 0;
|
1495 mike 1.1
|
1496 krisbash 1.3 if ((pd->flags & MI_FLAG_KEY)== 0)
|
1497 mike 1.1 continue;
1498
1499 /* skip null values */
1500 if (!_Field_GetExists(value,(MI_Type)pd->type))
1501 continue;
1502
1503 if (_PackValue(
1504 buf,
|
1505 krisbash 1.3 userAgent,
|
1506 mike 1.1 PropertyTagWriter_EPR,
1507 pd->name, value,
|
1508 krisbash 1.3 (MI_Type)pd->type,
1509 flags,
1510 &tmpLastPrefixIndex,
1511 NULL) != MI_RESULT_OK)
|
1512 mike 1.1 {
1513 return MI_RESULT_FAILED;
1514 }
1515 }
1516
1517 /* close EPR */
|
1518 krisbash 1.3 if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("</wsman:SelectorSet>")XML_CR
1519 ZT("</wsa:ReferenceParameters>")XML_CR)))
|
1520 mike 1.1 return MI_RESULT_FAILED;
1521
1522 return MI_RESULT_OK;
1523 }
1524
1525 static MI_Boolean TestOctetStringQualifier(
1526 const MI_PropertyDecl* pd)
1527 {
1528 size_t i;
1529
1530 for (i = 0; i < pd->numQualifiers; i++)
1531 {
1532 const MI_Qualifier* q = pd->qualifiers[i];
1533
|
1534 krisbash 1.3 if (Tcscasecmp(q->name, ZT("OctetString"))== 0
|
1535 mike 1.1 && q->type == MI_BOOLEAN
1536 && q->value)
1537 {
1538 return *((const MI_Boolean*)q->value);
1539 }
1540 }
1541
1542 return MI_FALSE;
1543 }
1544
|
1545 krisbash 1.3 #define WSMAN_SchemaFlagMask 0xf00
1546 MI_Result WSBuf_ClassToBuf(_In_ const MI_Class *classObject,
1547 MI_Uint32 flags,
1548 Batch* batch,
1549 void** ptrOut,
1550 MI_Uint32* sizeOut)
1551 {
1552 WSBuf buf;
1553 Page* page;
1554
1555 MI_Result result = MI_RESULT_OK;
1556 MI_Application mi_application = MI_APPLICATION_NULL;
1557 MI_Serializer mi_serializer;
1558 MI_Uint32 bufferLenForSerialization = 0;
1559
1560 // in future flags will be converted to the actual flags needed for serialization; for now just pass 0
1561 MI_UNREFERENCED_PARAMETER(flags);
1562
1563 result = XmlSerializer_Create(&mi_application, 0, ZT("MI_XML"), &mi_serializer);
1564 if(result != MI_RESULT_OK)
1565 return result;
1566 krisbash 1.3
1567 trace_XmlSerializer_SerializeClass(flags & WSMAN_SchemaFlagMask);
1568
1569 // pass 1 to compute the total needed length for serializing the class
1570 XmlSerializer_SerializeClass(&mi_serializer, flags & WSMAN_SchemaFlagMask, classObject, NULL, 0, &bufferLenForSerialization);
1571
1572 // this was just length computation; we will get MI_RESULT_FAILED from here but the bufferLenForSerialization will have the needed length
1573 // we will just check whether even length returned was 0; in that case we fail immediately
1574 // but if we get non-zero length required, we will go ahead and allocate the necessary buffer and then do the serialization again to see if it succeeds.
1575 if(bufferLenForSerialization == 0)
1576 {
1577 result = MI_RESULT_FAILED;
1578 goto End;
1579 }
1580
1581 // allocating the needed size buffer before pass 2
1582 result = WSBuf_Init(&buf, bufferLenForSerialization);
1583
1584 if (MI_RESULT_OK != result)
1585 goto End;
1586
1587 krisbash 1.3 // pass 2 to serialize the class into allocated buffer
1588 result = XmlSerializer_SerializeClass(&mi_serializer, flags & WSMAN_SchemaFlagMask, classObject, ((MI_Uint8*)(buf.page +1)), bufferLenForSerialization, &bufferLenForSerialization);
1589
1590 if(result != MI_RESULT_OK)
1591 {
1592 WSBuf_Destroy(&buf);
1593 goto End;
1594 }
1595
1596 // directly assigning the position since we already know how much we wrote in serialization
1597 buf.position = bufferLenForSerialization;
1598 page = WSBuf_StealPage(&buf);
1599 Batch_AttachPage(batch, page);
1600
1601 *ptrOut = page + 1;
1602
1603 *sizeOut = (MI_Uint32)page->u.s.size;
1604 result = MI_RESULT_OK;
1605
1606 End:
1607 XmlSerializer_Close(&mi_serializer);
1608 krisbash 1.3 return result;
1609 }
1610
|
1611 mike 1.1 static MI_Result _PackInstance(
1612 WSBuf* buf,
|
1613 krisbash 1.3 UserAgent userAgent,
|
1614 mike 1.1 const MI_Instance* instance,
|
1615 krisbash 1.3 MI_Boolean (*filterProperty)(const ZChar* name, void* data),
|
1616 mike 1.1 void* filterPropertyData,
1617 const MI_ClassDecl* castToClassDecl,
1618 MI_Uint32 flags,
|
1619 krisbash 1.3 MI_Boolean embedded,
1620 const ZChar* propName,
1621 MI_Uint32 *lastPrefixIndex,
1622 const ZChar* parentNSPrefix) //optional
|
1623 mike 1.1 {
|
1624 krisbash 1.3 Instance* self = Instance_GetSelf( instance );
|
1625 mike 1.1 const MI_ClassDecl* cd = castToClassDecl ? castToClassDecl : self->classDecl;
1626 MI_Uint32 i;
|
1627 krisbash 1.3 const ZChar* name;
|
1628 mike 1.1
1629 /* Check for null arguments */
1630 if (!self || !buf)
1631 MI_RETURN(MI_RESULT_INVALID_PARAMETER);
1632
1633 /* For Object & EPR, add <Item> tag */
|
1634 krisbash 1.3 if (!embedded &&
1635 ((flags & WSMAN_ObjectAndEPRFlag)== WSMAN_ObjectAndEPRFlag))
|
1636 mike 1.1 {
|
1637 krisbash 1.3 if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("<wsman:Item>")XML_CR)))
|
1638 mike 1.1 return MI_RESULT_FAILED;
1639 }
1640
1641 /* If object was requested */
|
1642 krisbash 1.3 if ((flags & WSMAN_ObjectFlag)== WSMAN_ObjectFlag)
|
1643 mike 1.1 {
|
1644 krisbash 1.3 const ZChar* cn;
1645 const ZChar* elementName;
1646 ZChar nsPrefix[12]; // p followed by index and
|
1647 mike 1.1
|
1648 krisbash 1.3 //GeneratePrefix
|
1649 mike 1.1 {
|
1650 krisbash 1.3 MI_Uint32 used = 1;
1651 nsPrefix[0] = ZT('p');
1652
1653 if (*lastPrefixIndex)
1654 {
1655 used += Stprintf(nsPrefix + 1, 11, ZT("%d"), *lastPrefixIndex);
1656 }
1657
1658 if (used > 11) // should never happen
1659 return MI_RESULT_FAILED;
1660
1661 nsPrefix[used] = ZT('\0');
1662 (*lastPrefixIndex)++;
1663 }
1664
1665 if ((cd->flags & MI_FLAG_METHOD) && ((MI_MethodDecl*)cd)->propagator)
1666 cn = ((MI_MethodDecl*)cd)->propagator;
1667 else
1668 cn = cd->name;
1669
1670 elementName = propName ? propName : cn;
1671 krisbash 1.3
1672 /* <p:propName ... type='class_Type> */
1673 if ((flags & WSMAN_IsCimError) == 0)
1674 {
1675 if (WSBuf_AddLit1(buf, '<') != MI_RESULT_OK ||
1676 WSBuf_AddStringNoEncoding(buf, parentNSPrefix ? parentNSPrefix:nsPrefix) != MI_RESULT_OK ||
1677 WSBuf_AddLit1(buf, ':') != MI_RESULT_OK ||
1678 WSBuf_AddStringNoEncoding(buf, elementName) != MI_RESULT_OK)
1679 {
1680 return MI_RESULT_FAILED;
1681 }
1682
1683 /* If parameters, append "_OUTPUT" suffix */
1684
1685 if ((cd->flags & MI_FLAG_METHOD) &&
1686 WSBuf_AddStringNoEncoding(buf, ZT("_OUTPUT")) != MI_RESULT_OK)
1687 {
1688 return MI_RESULT_FAILED;
1689 }
1690
1691 if (WSBuf_AddLit(buf, LIT(ZT(" xmlns:"))) != MI_RESULT_OK ||
1692 krisbash 1.3 WSBuf_AddStringNoEncoding(buf, nsPrefix) != MI_RESULT_OK ||
1693 WSBuf_AddLit(buf, LIT(ZT("=\"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"))) != MI_RESULT_OK ||
1694 WSBuf_AddStringNoEncoding(buf, cn) != MI_RESULT_OK ||
1695 WSBuf_AddLit2(buf, '"', '\n') != MI_RESULT_OK)
1696 {
1697 return MI_RESULT_FAILED;
1698 }
1699
1700 if (embedded)
1701 {
1702 if (WSBuf_AddLit(buf,LIT(ZT(" xsi:type=\""))) != MI_RESULT_OK ||
1703 WSBuf_AddStringNoEncoding(buf, nsPrefix) != MI_RESULT_OK ||
1704 WSBuf_AddLit1(buf, ':') != MI_RESULT_OK ||
1705 WSBuf_AddStringNoEncoding(buf,cn) != MI_RESULT_OK ||
1706 MI_RESULT_OK != WSBuf_AddLit(buf,ZT("_Type\""), 6))
1707 {
1708 return MI_RESULT_FAILED;
1709 }
1710 }
1711
1712 if (WSBuf_AddLit2(buf, '>', '\n') != MI_RESULT_OK)
|
1713 mike 1.1 return MI_RESULT_FAILED;
1714 }
1715
1716 /* Put properties */
|
1717 krisbash 1.3 for (i = 0; i < cd->numProperties; i++)
|
1718 mike 1.1 {
1719 const MI_PropertyDecl* pd = cd->properties[i];
1720 const void* value = (char*)self + pd->offset;
1721 MI_Boolean isOctetString = MI_FALSE;
1722
1723 if (filterProperty &&
1724 (*filterProperty)(pd->name, filterPropertyData))
1725 {
1726 continue;
1727 }
1728
1729 /* Search for OctetString qualifier */
1730
1731 if (pd->type == MI_UINT8A || pd->type == MI_STRINGA)
1732 isOctetString = TestOctetStringQualifier(pd);
1733
|
1734 krisbash 1.3 /* Skip non-out params; rename 'MIReturn' to 'ReturnValue' */
1735
1736 name = pd->name;
1737
1738 if (pd->flags & MI_FLAG_PARAMETER)
1739 {
1740 if (!(pd->flags & MI_FLAG_OUT))
1741 continue;
1742
1743 if (name[0] == 'M' && Tcscmp(name, ZT("MIReturn"))== 0)
1744 name = ZT("ReturnValue");
1745 }
1746
|
1747 mike 1.1 /* Pack the field */
1748
1749 if (_PackField(
1750 buf,
|
1751 krisbash 1.3 userAgent,
|
1752 mike 1.1 PropertyTagWriter_Prop,
|
1753 krisbash 1.3 name,
|
1754 mike 1.1 value,
1755 (MI_Type)pd->type,
|
1756 krisbash 1.3 isOctetString,
1757 flags, lastPrefixIndex, nsPrefix)!= MI_RESULT_OK)
|
1758 mike 1.1 {
1759 return MI_RESULT_FAILED;
1760 }
1761 }
1762
|
1763 krisbash 1.3 /* </p:elementName> */
1764 if ((flags & WSMAN_IsCimError) == 0)
1765 {
1766 if (WSBuf_AddLit2(buf, '<', '/') != MI_RESULT_OK ||
1767 WSBuf_AddStringNoEncoding(buf, parentNSPrefix ? parentNSPrefix : nsPrefix) != MI_RESULT_OK ||
1768 WSBuf_AddLit1(buf, ':') != MI_RESULT_OK ||
1769 WSBuf_AddStringNoEncoding(buf, elementName) != MI_RESULT_OK)
1770 {
1771 return MI_RESULT_FAILED;
1772 }
1773
1774 if ((cd->flags & MI_FLAG_METHOD) &&
1775 WSBuf_AddStringNoEncoding(buf, ZT("_OUTPUT")) != MI_RESULT_OK)
1776 {
1777 return MI_RESULT_FAILED;
1778 }
1779
1780 if (WSBuf_AddLit2(buf, '>', '\n') != MI_RESULT_OK)
1781 return MI_RESULT_FAILED;
1782 }
|
1783 mike 1.1 }
1784
1785 /* If EPR was requested */
|
1786 krisbash 1.3 if (!embedded &&
1787 ((flags & WSMAN_EPRFlag)== WSMAN_EPRFlag))
|
1788 mike 1.1 {
|
1789 krisbash 1.3 if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("<wsa:EndpointReference>")XML_CR))||
1790 MI_RESULT_OK != _PackEPR(buf, userAgent, instance, flags)||
1791 MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("</wsa:EndpointReference>")XML_CR)))
|
1792 mike 1.1 return MI_RESULT_FAILED;
1793 }
1794
1795 /* If EPR was requested */
|
1796 krisbash 1.3 if ((flags & WSMAN_CreatedEPRFlag)== WSMAN_CreatedEPRFlag)
|
1797 mike 1.1 {
|
1798 krisbash 1.3 if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("<wxf:ResourceCreated>")XML_CR))||
1799 MI_RESULT_OK != _PackEPR(buf, userAgent, instance, flags)||
1800 MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("</wxf:ResourceCreated>")XML_CR)))
|
1801 mike 1.1 return MI_RESULT_FAILED;
1802 }
1803
1804 /* For Object & EPR, add </Item> tag */
|
1805 krisbash 1.3 if (!embedded &&
1806 ((flags & WSMAN_ObjectAndEPRFlag)== WSMAN_ObjectAndEPRFlag))
|
1807 mike 1.1 {
|
1808 krisbash 1.3 if (MI_RESULT_OK != WSBuf_AddLit(buf,LIT(ZT("</wsman:Item>")XML_CR)))
|
1809 mike 1.1 return MI_RESULT_FAILED;
1810 }
1811
1812
1813 return MI_RESULT_OK;
1814 }
1815
1816 MI_Result WSBuf_InstanceToBuf(
|
1817 krisbash 1.3 UserAgent userAgent,
|
1818 mike 1.1 const MI_Instance* instance,
|
1819 krisbash 1.3 MI_Boolean (*filterProperty)(const ZChar* name, void* data),
|
1820 mike 1.1 void* filterPropertyData,
1821 const MI_ClassDecl* castToClassDecl,
1822 Batch* batch,
1823 MI_Uint32 flags,
1824 void** ptrOut,
1825 MI_Uint32* sizeOut)
1826 {
1827 WSBuf buf;
1828 MI_Result r;
1829 Page* page;
|
1830 krisbash 1.3 MI_Uint32 lastPrefixIndex = 0;
|
1831 mike 1.1
1832 r = WSBuf_Init(&buf,1024);
1833
1834 if (MI_RESULT_OK != r)
1835 return r;
1836
|
1837 krisbash 1.3 // Passing NULL as the PropName as this is not embeddedInstance
1838 // As the second last parameter is MI_FALSE
1839 r = _PackInstance(&buf, userAgent, instance, filterProperty,
1840 filterPropertyData, castToClassDecl, flags, MI_FALSE, NULL, &lastPrefixIndex, NULL);
|
1841 mike 1.1
1842 if (MI_RESULT_OK != r)
1843 {
1844 WSBuf_Destroy(&buf);
1845 return r;
1846 }
1847
1848 page = WSBuf_StealPage(&buf);
1849 Batch_AttachPage(batch, page);
1850
1851 *ptrOut = page + 1;
1852 *sizeOut = (MI_Uint32)page->u.s.size;
1853 return MI_RESULT_OK;
1854 }
1855
|
1856 krisbash 1.3 _Use_decl_annotations_
|
1857 mike 1.1 void WSBuf_GenerateMessageID(
|
1858 krisbash 1.3 ZChar msgID[WS_MSG_ID_SIZE])
|
1859 mike 1.1 {
1860 //WS-Management qualifies the use of wsa:MessageID and wsa:RelatesTo as follows:
1861 //R5.4.6.4-1: The MessageID and RelatesTo URIs may be of any format, as long as they are valid
1862 //URIs according to RFC 3986. Two URIs are considered different even if the characters in the
1863 //URIs differ only by case.
1864 //The following two formats are endorsed by this specification. The first is considered a best
1865 //practice because it is backed by RFC 4122:
1866 //urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
1867 //or
1868 //uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
1869 //In these formats, each x is an uppercase or lowercase hexadecimal digit (lowercase is required
1870 //by RFC 4122); there are no spaces or other tokens. The value may be a DCE-style universally
|
1871 krisbash 1.3 //unique identifier (UUID)with provable uniqueness properties in this format, however, it is not
|
1872 mike 1.1 //necessary to have provable uniqueness properties in the URIs used in the wsa:MessageID and
1873 //wsa:RelatesTo headers.
1874 //Regardless of format, the URI should not exceed the maximum defined in R13.1-6.
1875 //UUIDs have a numeric meaning as well as a string meaning, and this can lead to confusion. A UUID
1876 //in lowercase is a different URI from the same UUID in uppercase. This is because URIs are case1619
1877 //tive. If a UUID is converted to its decimal equivalent the case of the original characters is lost.
1878 //WS-Management works with the URI value itself, not the underlying decimal equivalent
1879 //representation. Services are free to interpret the URI in any way, but are not allowed to alter the case
1880 //usage when repeating the message or any of the MessageID values in subsequent messages.
1881 //The RFC 4122 requires the digits to be lowercase, which is the responsibility of the client. The service
1882 //simply processes the values as URI values and is not required to analyze the URI for correctness or
1883 //compliance. The service replicates the client usage in the wsa:RelatesTo reply header and is not
1884 //allowed to alter the case usage.
1885 //R5.4.6.4-2: The MessageID should be generated according to any algorithm that ensures that no
1886 //two MessageIDs are repeated. Because the value is treated as case-sensitive (R5.4.6.4-1),
1887 //confusion can arise if the same value is reused differing only in case. As a result, the service shall
1888 //not create or employ MessageID values that differ only in case. For any message transmitted by
1889 //the service, the MessageID shall not be reused.
1890
1891 static MI_Uint64 s1, s2;
1892
1893 mike 1.1 if (!s1)
|
1894 krisbash 1.3 PAL_Time(&s1);
|
1895 mike 1.1
1896 s2++;
1897
1898 /* ADC */
1899 if (!s2)
1900 s1++;
1901
|
1902 krisbash 1.3 Stprintf(msgID, WS_MSG_ID_SIZE,
1903 ZT("uuid:%08X-%04X-%04X-%04X-%08X%04X"),
|
1904 mike 1.1 (MI_Uint32)(s1 & 0xFFFFFFFF),
|
1905 krisbash 1.3 (MI_Uint32)((s1 >> 32)& 0xFFFF),
1906 (MI_Uint32)((s1 >> 48)& 0xFFFF),
1907 (MI_Uint32)((s2 >> 48)& 0xFFFF),
|
1908 mike 1.1 (MI_Uint32)(s2 & 0xFFFFFFFF),
|
1909 krisbash 1.3 (MI_Uint32)((s2 >> 32)& 0xFFFF));
|
1910 mike 1.1 }
1911
1912 MI_Result WSBuf_CreateSoapResponseHeader(
|
1913 krisbash 1.3 WSBuf* buf,
1914 const ZChar* action,
1915 MI_Uint32 actionSize,
1916 const ZChar* relatesTo)
|
1917 mike 1.1 {
|
1918 krisbash 1.3 ZChar msgID[WS_MSG_ID_SIZE];
|
1919 mike 1.1
1920 /* Response header */
1921 if (MI_RESULT_OK != WSBuf_AddLit(buf,
1922 LIT(
|
1923 krisbash 1.3 ZT("<SOAP-ENV:Envelope ")
1924 ZT("xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\" ")
1925 ZT("xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" ")
1926 ZT("xmlns:wsen=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\" ")
1927 ZT("xmlns:e=\"http://schemas.xmlsoap.org/ws/2004/08/eventing\" ")
1928 ZT("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ")
1929 ZT("xmlns:wsmb=\"http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd\" ")
1930 ZT("xmlns:wsman=\"http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd\" ")
1931 ZT("xmlns:wxf=\"http://schemas.xmlsoap.org/ws/2004/09/transfer\" ")
1932 ZT("xmlns:cim=\"http://schemas.dmtf.org/wbem/wscim/1/common\" ")
1933 ZT("xmlns:msftwinrm=\"http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd\" ")
1934 /* ZT("xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" ")*/
1935 ZT("xmlns:wsmid=\"http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd\">")
|
1936 mike 1.1 XML_CR
|
1937 krisbash 1.3 ZT("<SOAP-ENV:Header>")XML_CR
1938 ZT("<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>")XML_CR
1939 ZT("<wsa:Action>"))))
|
1940 mike 1.1 {
1941 goto failed;
1942 }
1943
1944 if (MI_RESULT_OK != WSBuf_AddLit(buf, action, actionSize))
1945 goto failed;
1946
1947 if (MI_RESULT_OK != WSBuf_AddLit(buf,
|
1948 krisbash 1.3 LIT(ZT("</wsa:Action>")XML_CR
1949 ZT("<wsa:MessageID>"))))
|
1950 mike 1.1 goto failed;
1951
1952 /* Generate new uniqueue msg id */
1953 WSBuf_GenerateMessageID(msgID);
1954
1955 if (MI_RESULT_OK != WSBuf_AddLit(buf, msgID, WS_MSG_ID_SIZE - 1))
1956 goto failed;
1957
1958 if (MI_RESULT_OK != WSBuf_AddLit(buf,
|
1959 krisbash 1.3 LIT(ZT("</wsa:MessageID>")XML_CR)))
|
1960 mike 1.1 goto failed;
1961
1962 if (relatesTo)
1963 {
1964 if (MI_RESULT_OK != WSBuf_AddLit(buf,
|
1965 krisbash 1.3 LIT(ZT("<wsa:RelatesTo>"))))
|
1966 mike 1.1 goto failed;
1967
|
1968 krisbash 1.3 if (MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf, relatesTo))
|
1969 mike 1.1 goto failed;
1970
1971 if (MI_RESULT_OK != WSBuf_AddLit(buf,
|
1972 krisbash 1.3 LIT(ZT("</wsa:RelatesTo>")XML_CR)))
|
1973 mike 1.1 goto failed;
1974 }
1975
1976 return MI_RESULT_OK;
1977
1978 failed:
1979 return MI_RESULT_FAILED;
1980 }
1981
1982 Page* WSBuf_CreateFaultResponsePage(
1983 WSBUF_FAULT_CODE faultCode,
|
1984 krisbash 1.3 const ZChar* notUnderstoodTag,
1985 const ZChar* requestMessageID,
1986 const PostResultMsg* message)
|
1987 mike 1.1 {
1988 WSBuf outBuf;
1989 const BUF_FaultItem* fault;
|
1990 krisbash 1.3 const ZChar* textToSend;
|
1991 mike 1.1
|
1992 krisbash 1.3 if (((MI_Uint32)faultCode)>= MI_COUNT(s_faults))
|
1993 mike 1.1 {
1994 fault = s_faults + 0; /* internal error */
1995 }
1996 else
1997 {
1998 fault = s_faults + (MI_Uint32)faultCode;
1999 }
2000
2001 /* prepare soap response with error */
|
2002 krisbash 1.3 if (WSBuf_Init(&outBuf, 1024)!= MI_RESULT_OK)
|
2003 mike 1.1 return 0;
2004
2005 /* fault header */
2006 if (MI_RESULT_OK != WSBuf_CreateSoapResponseHeader(&outBuf,
2007 fault->action, fault->actionSize, requestMessageID))
2008 goto failed;
2009
2010 if (notUnderstoodTag)
2011 {
2012 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
|
2013 krisbash 1.3 LIT(ZT("<SOAP-ENV:NotUnderstood qname=\""))))
|
2014 mike 1.1 goto failed;
2015
|
2016 krisbash 1.3 if (MI_RESULT_OK != WSBuf_AddStringNoEncoding(
2017 &outBuf,
2018 notUnderstoodTag))
2019 {
|
2020 mike 1.1 goto failed;
|
2021 krisbash 1.3 }
|
2022 mike 1.1
2023 if (MI_RESULT_OK != WSBuf_AddLit3(&outBuf, '"', '/', '>'))
2024 goto failed;
2025 }
2026
2027 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2028 LIT(
|
2029 krisbash 1.3 ZT("</SOAP-ENV:Header>")XML_CR XML_CR
2030 ZT("<SOAP-ENV:Body>")XML_CR
2031 ZT("<SOAP-ENV:Fault>")XML_CR
2032 ZT("<SOAP-ENV:Code>")XML_CR
2033 ZT("<SOAP-ENV:Value>"))))
|
2034 mike 1.1 goto failed;
2035
2036 if (MI_RESULT_OK != WSBuf_AddCharStringNoEncoding(&outBuf, fault->code))
2037 goto failed;
2038 //SOAP-ENV:Sender
2039
2040 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
|
2041 krisbash 1.3 LIT(ZT("</SOAP-ENV:Value>")XML_CR)))
|
2042 mike 1.1 goto failed;
2043
2044 if (fault->subCode)
2045 {
2046 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
|
2047 krisbash 1.3 LIT(ZT("<SOAP-ENV:Subcode>")XML_CR
2048 ZT("<SOAP-ENV:Value>"))))
|
2049 mike 1.1 goto failed;
2050
|
2051 krisbash 1.3 if (MI_RESULT_OK != WSBuf_AddCharStringNoEncoding(
2052 &outBuf,
2053 fault->subCode))
2054 {
|
2055 mike 1.1 goto failed;
|
2056 krisbash 1.3 }
|
2057 mike 1.1
2058 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
|
2059 krisbash 1.3 LIT(ZT("</SOAP-ENV:Value>")XML_CR
2060 ZT("</SOAP-ENV:Subcode>")XML_CR)))
|
2061 mike 1.1 goto failed;
2062 }
2063
2064 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
|
2065 krisbash 1.3 LIT(ZT("</SOAP-ENV:Code>")XML_CR
2066 ZT("<SOAP-ENV:Reason>")XML_CR
2067 ZT("<SOAP-ENV:Text xml:lang=\"en-US\">"))))
2068 goto failed;
2069
2070 textToSend = fault->defaultText;
2071
2072 if (message->errorMessage)
2073 {
2074 textToSend = message->errorMessage;
2075 }
2076
2077 if (MI_RESULT_OK != WSBuf_AddString(&outBuf, textToSend))
2078 {
|
2079 mike 1.1 goto failed;
|
2080 krisbash 1.3 }
|
2081 mike 1.1
|
2082 krisbash 1.3 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2083 LIT(ZT("</SOAP-ENV:Text>")XML_CR
2084 ZT("</SOAP-ENV:Reason>")XML_CR)))
|
2085 mike 1.1 {
|
2086 krisbash 1.3 goto failed;
|
2087 mike 1.1 }
|
2088 krisbash 1.3
2089 if ((message->result != MI_RESULT_OK) || (NULL != message->packedInstancePtr))
|
2090 mike 1.1 {
|
2091 krisbash 1.3 if ((MI_RESULT_OK != WSBuf_AddLit(&outBuf, LIT(ZT("<SOAP-ENV:Detail>")XML_CR ZT("<p:")))) ||
2092 (MI_RESULT_OK != WSBuf_AddString(&outBuf, (message->cimErrorClassName?message->cimErrorClassName:ZT("OMI_Error")))) ||
2093 (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2094 LIT(ZT(" wsmb:IsCIM_Error=\"true\" ")
2095 ZT("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ")
2096 ZT("xmlns:wsmb=\"http://schemas.dmtf.org/wbem/wsman/1/cimbinding.xsd\" ")
2097 ZT("xmlns:p=\"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/OMI_Error\" ")
2098 ZT("xmlns:cim=\"http://schemas.dmtf.org/wbem/wscim/1/common\">")))))
2099 {
|
2100 mike 1.1 goto failed;
|
2101 krisbash 1.3 }
2102
2103 if (message->packedInstancePtr)
2104 {
2105 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf, message->packedInstancePtr, message->packedInstanceSize/sizeof(MI_Char)))
2106 {
2107 goto failed;
2108 }
2109 }
2110 else
2111 {
2112 /* Create OMI_Error from the error code and string passed in */
2113
2114 // CIM_Error:CIMStatusCode
2115 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2116 LIT(ZT("<p:CIMStatusCode xsi:type=\"cim:cimUnsignedInt\">"))))
2117 {
2118 goto failed;
2119 }
2120
2121 if (MI_RESULT_OK != WSBuf_AddUint32(&outBuf, message->result))
2122 krisbash 1.3 goto failed;
2123
2124 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2125 LIT(ZT("</p:CIMStatusCode>")XML_CR)))
2126 {
2127 goto failed;
2128 }
2129
2130 // CIM_Error:Message
2131 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2132 LIT(ZT("<p:Message xsi:type=\"cim:cimString\">"))))
2133 {
2134 goto failed;
2135 }
2136
2137 if (MI_RESULT_OK != WSBuf_AddString(&outBuf, textToSend))
2138 {
2139 goto failed;
2140 }
2141
2142 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2143 krisbash 1.3 LIT(ZT("</p:Message>")XML_CR)))
2144 {
2145 goto failed;
2146 }
2147
2148 // CIM_Error:MessageArguments
2149 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2150 LIT(ZT("<p:MessageArguments xsi:type=\"cim:cimString\"></p:MessageArguments>"))))
2151 {
2152 goto failed;
2153 }
2154
2155 // CIM_Error:MessageID
2156 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2157 LIT(ZT("<p:MessageID xsi:type=\"cim:cimString\">OMI:MI_Result:"))))
2158 {
2159 goto failed;
2160 }
2161
2162 if (MI_RESULT_OK != WSBuf_AddUint32(&outBuf, message->result))
2163 goto failed;
2164 krisbash 1.3
2165 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2166 LIT(ZT("</p:MessageID>")XML_CR)))
2167 {
2168 goto failed;
2169 }
2170
2171 //OMI_Category - uint32
2172 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2173 LIT(ZT("<p:OMI_Category xsi:type=\"cim:cimUnsignedInt\">"))))
2174 {
2175 goto failed;
2176 }
2177
2178 if (MI_RESULT_OK != WSBuf_AddUint32(&outBuf, ErrorCategoryFromErrorCode(message->result, PAL_T("MI"))))
2179 goto failed;
2180
2181 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2182 LIT(ZT("</p:OMI_Category>")XML_CR)))
2183 {
2184 goto failed;
2185 krisbash 1.3 }
2186
2187 //OMI_Code - uint32
2188 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2189 LIT(ZT("<p:OMI_Code xsi:type=\"cim:cimUnsignedInt\">"))))
2190 {
2191 goto failed;
2192 }
2193
2194 if (MI_RESULT_OK != WSBuf_AddUint32(&outBuf, message->result))
2195 goto failed;
2196
2197 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2198 LIT(ZT("</p:OMI_Code>")XML_CR)))
2199 {
2200 goto failed;
2201 }
2202
2203 //OMI_ErrorMessage - string
2204 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2205 LIT(ZT("<p:OMI_ErrorMessage xsi:type=\"cim:cimString\">"))))
2206 krisbash 1.3 {
2207 goto failed;
2208 }
2209
2210 if (MI_RESULT_OK != WSBuf_AddString(&outBuf, textToSend))
2211 {
2212 goto failed;
2213 }
2214
2215 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2216 LIT(ZT("</p:OMI_ErrorMessage>")XML_CR)))
2217 {
2218 goto failed;
2219 }
2220
2221
2222 //OMI_Type - string
2223 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2224 LIT(ZT("<p:OMI_Type xsi:type=\"cim:cimString\">MI</p:OMI_Type>"))))
2225 {
2226 goto failed;
2227 krisbash 1.3 }
2228
2229 // CIM_Error:OwningEntity
2230 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2231 LIT(ZT("<p:OwningEntity xsi:type=\"cim:cimString\">OMI:CIMOM</p:OwningEntity>"))))
2232 {
2233 goto failed;
2234 }
2235
2236 // CIM_Error:PerceivedSeverity
2237 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2238 LIT(ZT("<p:PerceivedSeverity xsi:type=\"cim:cimUnsignedInt\">7</p:PerceivedSeverity>"))))
2239 {
2240 goto failed;
2241 }
2242
2243 // CIM_Error:ProbableCause
2244 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2245 LIT(ZT("<p:ProbableCause xsi:type=\"cim:cimUnsignedInt\">0</p:ProbableCause>"))))
2246 {
2247 goto failed;
2248 krisbash 1.3 }
2249
2250 // CIM_Error:ProbableCauseDescription
2251 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2252 LIT(ZT("<p:ProbableCauseDescription xsi:type=\"cim:cimString\">Unknown</p:ProbableCauseDescription>"))))
2253 {
2254 goto failed;
2255 }
2256 }
2257
2258
2259 if ((MI_RESULT_OK != WSBuf_AddLit(&outBuf, LIT(ZT("</p:"))) ||
2260 (MI_RESULT_OK != WSBuf_AddString(&outBuf, (message->cimErrorClassName?message->cimErrorClassName:ZT("OMI_Error")))) ||
2261 (MI_RESULT_OK != WSBuf_AddLit(&outBuf, LIT(ZT(">") XML_CR ZT("</SOAP-ENV:Detail>")XML_CR)))))
2262 {
2263 goto failed;
2264 }
|
2265 mike 1.1 }
2266
2267 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
|
2268 krisbash 1.3 LIT(ZT("</SOAP-ENV:Fault>")XML_CR
2269 ZT("</SOAP-ENV:Body>")XML_CR
2270 ZT("</SOAP-ENV:Envelope>")XML_CR)))
2271 {
|
2272 mike 1.1 goto failed;
|
2273 krisbash 1.3 }
|
2274 mike 1.1
2275 return WSBuf_StealPage(&outBuf);
2276
2277 failed:
2278
2279 WSBuf_Destroy(&outBuf);
2280 return 0;
2281 }
2282
2283 Page* WSBuf_CreateReleaseResponsePage(
|
2284 krisbash 1.3 const ZChar* requestMessageID)
|
2285 mike 1.1 {
2286 WSBuf outBuf;
2287
2288 /* prepare soap response with error */
|
2289 krisbash 1.3 if (WSBuf_Init(&outBuf, 1024)!= MI_RESULT_OK)
|
2290 mike 1.1 return 0;
2291
2292 /* fault header */
2293 if (MI_RESULT_OK != WSBuf_CreateSoapResponseHeader(&outBuf,
|
2294 krisbash 1.3 LIT(ZT("http://schemas.xmlsoap.org/ws/2004/09/enumeration/ReleaseResponse")),
|
2295 mike 1.1 requestMessageID))
2296 goto failed;
2297
2298 if (MI_RESULT_OK != WSBuf_AddLit(&outBuf,
2299 LIT(
|
2300 krisbash 1.3 ZT("</SOAP-ENV:Header>")XML_CR XML_CR
2301 ZT("<SOAP-ENV:Body/>")XML_CR
2302 ZT("</SOAP-ENV:Envelope>")XML_CR)))
|
2303 mike 1.1 goto failed;
2304
2305 return WSBuf_StealPage(&outBuf);
2306
2307 failed:
2308
2309 WSBuf_Destroy(&outBuf);
2310 return 0;
2311 }
2312
|
2313 krisbash 1.3 WSBUF_FAULT_CODE WSBuf_CIMErrorToWSFault(
2314 MI_Uint32 cimErrorCode,
2315 const ZChar** description)
|
2316 mike 1.1 {
|
2317 krisbash 1.3 MI_Uint32 index = cimErrorCode < MI_COUNT(s_cimerrors)? cimErrorCode : MI_RESULT_FAILED;
|
2318 mike 1.1
|
2319 krisbash 1.3 if (description)
|
2320 mike 1.1 *description = s_cimerrors[index].description;
2321
2322 return s_cimerrors[index].faultCode;
2323 }
|