1 mike 1.23 //%/////////////////////////////////////////////////////////////////////////////
2 //
|
3 mike 1.24 // Copyright (c) 2000, 2001 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
|
5 mike 1.23 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 //==============================================================================
23 //
24 // Author: Mike Brasher (mbrasher@bmc.com)
25 //
|
26 mike 1.24 // Modified By: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
27 // Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
28 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
29 mike 1.23 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include <cstdlib>
33 #include <cstdio>
|
34 kumpf 1.28 #include "Destroyer.h"
|
35 mike 1.23 #include "CIMClass.h"
36 #include "CIMInstance.h"
37 #include "CIMQualifierDecl.h"
38 #include "XmlWriter.h"
39 #include "XmlParser.h"
40
41 PEGASUS_NAMESPACE_BEGIN
42
|
43 kumpf 1.27 Array<Sint8>& operator<<(Array<Sint8>& out, const char* x)
44 {
45 XmlWriter::append(out, x);
46 return out;
47 }
48
49 Array<Sint8>& operator<<(Array<Sint8>& out, char x)
50 {
51 XmlWriter::append(out, x);
52 return out;
53 }
54
55 Array<Sint8>& operator<<(Array<Sint8>& out, Char16 x)
56 {
57 XmlWriter::append(out, x);
58 return out;
59 }
60
61 Array<Sint8>& operator<<(Array<Sint8>& out, const String& x)
62 {
63 XmlWriter::append(out, x);
64 kumpf 1.27 return out;
65 }
66
67 Array<Sint8>& operator<<(Array<Sint8>& out, const Indentor& x)
68 {
69 XmlWriter::append(out, x);
70 return out;
71 }
72
73 Array<Sint8>& operator<<(Array<Sint8>& out, const Array<Sint8>& x)
74 {
75 out.appendArray(x);
76 return out;
77 }
78
79 Array<Sint8>& operator<<(Array<Sint8>& out, Uint32 x)
80 {
81 XmlWriter::append(out, x);
82 return out;
83 }
84
85 kumpf 1.27 inline void _appendChar(Array<Sint8>& out, Char16 c)
|
86 mike 1.23 {
87 out.append(Sint8(c));
88 }
89
|
90 kumpf 1.27 inline void _appendSpecialChar(Array<Sint8>& out, Char16 c)
|
91 mike 1.23 {
92 // ATTN-B: Only UTF-8 handled for now.
93
94 switch (c)
95 {
96 case '&':
97 out.append("&", 5);
98 break;
99
100 case '<':
101 out.append("<", 4);
102 break;
103
104 case '>':
105 out.append(">", 4);
106 break;
107
108 case '"':
109 out.append(""", 6);
110 break;
111
112 mike 1.23 case '\'':
113 out.append("'", 6);
114 break;
115
116 default:
117 out.append(Sint8(c));
118 }
119 }
120
|
121 kumpf 1.27 static inline void _appendSpecialChar(PEGASUS_STD(ostream)& os, char c)
122 {
123 switch (c)
124 {
125 case '&':
126 os << "&";
127 break;
128
129 case '<':
130 os << "<";
131 break;
132
133 case '>':
134 os << ">";
135 break;
136
137 case '"':
138 os << """;
139 break;
140
141 case '\'':
142 kumpf 1.27 os << "'";
143 break;
144
145 default:
146 os << c;
147 }
148 }
149
150 static inline void _appendSpecial(PEGASUS_STD(ostream)& os, const char* str)
151 {
152 while (*str)
153 _appendSpecialChar(os, *str++);
154 }
155
|
156 mike 1.23 void XmlWriter::append(Array<Sint8>& out, Char16 x)
157 {
|
158 kumpf 1.27 _appendChar(out, x);
|
159 mike 1.23 }
160
161 void XmlWriter::append(Array<Sint8>& out, Uint32 x)
162 {
163 char buffer[32];
164 sprintf(buffer, "%d", x);
165 append(out, buffer);
166 }
167
168 void XmlWriter::append(Array<Sint8>& out, const char* str)
169 {
170 while (*str)
|
171 kumpf 1.27 _appendChar(out, *str++);
172 }
173
174 void XmlWriter::append(Array<Sint8>& out, const String& str)
175 {
176 const Char16* tmp = str.getData();
177
178 while (*tmp)
179 _appendChar(out, *tmp++);
180 }
181
182 void XmlWriter::append(Array<Sint8>& out, const Indentor& x)
183 {
184 for (Uint32 i = 0; i < 4 * x.getLevel(); i++)
185 out.append(' ');
|
186 mike 1.23 }
187
188 void XmlWriter::appendSpecial(Array<Sint8>& out, Char16 x)
189 {
|
190 kumpf 1.27 _appendSpecialChar(out, x);
|
191 mike 1.23 }
192
193 void XmlWriter::appendSpecial(Array<Sint8>& out, char x)
194 {
|
195 kumpf 1.27 _appendSpecialChar(out, Char16(x));
|
196 mike 1.23 }
197
198 void XmlWriter::appendSpecial(Array<Sint8>& out, const char* str)
199 {
200 while (*str)
|
201 kumpf 1.27 _appendSpecialChar(out, *str++);
|
202 mike 1.23 }
203
204 void XmlWriter::appendSpecial(Array<Sint8>& out, const String& str)
205 {
206 const Char16* tmp = str.getData();
207
208 while (*tmp)
|
209 kumpf 1.27 _appendSpecialChar(out, *tmp++);
|
210 mike 1.23 }
211
|
212 kumpf 1.29 //------------------------------------------------------------------------------
213 //
214 // appendLocalNameSpacePathElement()
215 //
216 // <!ELEMENT LOCALNAMESPACEPATH (NAMESPACE+)>
217 //
218 //------------------------------------------------------------------------------
219
220 void XmlWriter::appendLocalNameSpacePathElement(
221 Array<Sint8>& out,
|
222 mike 1.23 const String& nameSpace)
223 {
224 out << "<LOCALNAMESPACEPATH>\n";
225
226 char* tmp = nameSpace.allocateCString();
227
228 for (char* p = strtok(tmp, "/"); p; p = strtok(NULL, "/"))
229 {
230 out << "<NAMESPACE NAME=\"" << p << "\"/>\n";
231 }
232
233 delete [] tmp;
234
235 out << "</LOCALNAMESPACEPATH>\n";
236 }
237
238 //------------------------------------------------------------------------------
239 //
|
240 kumpf 1.29 // appendNameSpacePathElement()
241 //
242 // <!ELEMENT NAMESPACEPATH (HOST,LOCALNAMESPACEPATH)>
243 //
244 //------------------------------------------------------------------------------
245
246 void XmlWriter::appendNameSpacePathElement(
247 Array<Sint8>& out,
248 const String& host,
249 const String& nameSpace)
250 {
251 out << "<NAMESPACEPATH>\n";
252 out << "<HOST>" << host << "</HOST>\n";
253 appendLocalNameSpacePathElement(out, nameSpace);
254 out << "</NAMESPACEPATH>\n";
255 }
256
257 //------------------------------------------------------------------------------
258 //
259 // appendClassNameElement()
260 //
261 kumpf 1.29 // <!ELEMENT CLASSNAME EMPTY>
262 // <!ATTLIST CLASSNAME
263 // %CIMName;>
264 //
265 //------------------------------------------------------------------------------
266
267 void XmlWriter::appendClassNameElement(
268 Array<Sint8>& out,
269 const String& className)
270 {
271 out << "<CLASSNAME NAME=\"" << className << "\"/>\n";
272 }
273
274 //------------------------------------------------------------------------------
275 //
276 // appendInstanceNameElement()
277 //
278 // <!ELEMENT INSTANCENAME (KEYBINDING*|KEYVALUE?|VALUE.REFERENCE?)>
279 // <!ATTLIST INSTANCENAME
280 // %ClassName;>
281 //
282 kumpf 1.29 //------------------------------------------------------------------------------
283
284 void XmlWriter::appendInstanceNameElement(
285 Array<Sint8>& out,
286 const CIMReference& instanceName)
287 {
288 out << "<INSTANCENAME CLASSNAME=\"" << instanceName.getClassName() << "\">\n";
289
290 Array<KeyBinding> keyBindings = instanceName.getKeyBindings();
291 for (Uint32 i = 0, n = keyBindings.size(); i < n; i++)
292 {
293 out << "<KEYBINDING NAME=\"" << keyBindings[i].getName() << "\">\n";
294
295 if (keyBindings[i].getType() == KeyBinding::REFERENCE)
296 {
297 CIMReference ref = keyBindings[i].getValue();
298 ref.toXml(out, true);
299 }
300 else {
301 out << "<KEYVALUE VALUETYPE=\"";
302 out << KeyBinding::typeToString(keyBindings[i].getType());
303 kumpf 1.29 out << "\">";
304
305 // fixed the special character problem - Markus
306
307 appendSpecial(out, keyBindings[i].getValue());
308 out << "</KEYVALUE>\n";
309 }
310 out << "</KEYBINDING>\n";
311 }
312 out << "</INSTANCENAME>\n";
313 }
314
315 //------------------------------------------------------------------------------
316 //
317 // appendClassPathElement()
318 //
319 // <!ELEMENT CLASSPATH (NAMESPACEPATH,CLASSNAME)>
320 //
321 //------------------------------------------------------------------------------
322
323 void XmlWriter::appendClassPathElement(
324 kumpf 1.29 Array<Sint8>& out,
325 const CIMReference& classPath)
326 {
327 out << "<CLASSPATH>\n";
328 appendNameSpacePathElement(out,
329 classPath.getHost(),
330 classPath.getNameSpace());
331 appendClassNameElement(out, classPath.getClassName());
332 out << "</CLASSPATH>\n";
333 }
334
335 //------------------------------------------------------------------------------
336 //
337 // appendInstancePathElement()
338 //
339 // <!ELEMENT INSTANCEPATH (NAMESPACEPATH,INSTANCENAME)>
340 //
341 //------------------------------------------------------------------------------
342
343 void XmlWriter::appendInstancePathElement(
344 Array<Sint8>& out,
345 kumpf 1.29 const CIMReference& instancePath)
346 {
347 out << "<INSTANCEPATH>\n";
348 appendNameSpacePathElement(out,
349 instancePath.getHost(),
350 instancePath.getNameSpace());
351 appendInstanceNameElement(out, instancePath);
352 out << "</INSTANCEPATH>\n";
353 }
354
355 //------------------------------------------------------------------------------
356 //
357 // appendLocalClassPathElement()
358 //
359 // <!ELEMENT LOCALCLASSPATH (LOCALNAMESPACEPATH, CLASSNAME)>
360 //
361 //------------------------------------------------------------------------------
362
363 void XmlWriter::appendLocalClassPathElement(
364 Array<Sint8>& out,
365 const CIMReference& classPath)
366 kumpf 1.29 {
367 out << "<LOCALCLASSPATH>\n";
368 appendLocalNameSpacePathElement(out, classPath.getNameSpace());
369 appendClassNameElement(out, classPath.getClassName());
370 out << "</LOCALCLASSPATH>\n";
371 }
372
373 //------------------------------------------------------------------------------
374 //
375 // appendLocalInstancePathElement()
376 //
377 // <!ELEMENT LOCALINSTANCEPATH (LOCALNAMESPACEPATH, INSTANCENAME)>
378 //
379 //------------------------------------------------------------------------------
380
381 void XmlWriter::appendLocalInstancePathElement(
382 Array<Sint8>& out,
383 const CIMReference& instancePath)
384 {
385 out << "<LOCALINSTANCEPATH>\n";
386 appendLocalNameSpacePathElement(out, instancePath.getNameSpace());
387 kumpf 1.29 appendInstanceNameElement(out, instancePath);
388 out << "</LOCALINSTANCEPATH>\n";
389 }
390
391 //------------------------------------------------------------------------------
392 //
|
393 kumpf 1.30 // appendLocalObjectPathElement()
394 //
|
395 kumpf 1.31 // If the reference refers to an instance, write a LOCALINSTANCEPATH;
396 // otherwise write a LOCALCLASSPATH.
|
397 kumpf 1.30 //
398 //------------------------------------------------------------------------------
399
400 void XmlWriter::appendLocalObjectPathElement(
401 Array<Sint8>& out,
402 const CIMReference& objectPath)
403 {
|
404 kumpf 1.31 if (objectPath.isInstanceName())
|
405 kumpf 1.30 {
406 appendLocalInstancePathElement(out, objectPath);
407 }
408 else
409 {
410 appendLocalClassPathElement(out, objectPath);
411 }
412 }
413
414 //------------------------------------------------------------------------------
415 //
|
416 kumpf 1.27 // appendMethodCallHeader()
|
417 mike 1.23 //
|
418 kumpf 1.31 // Build HTTP method call request header.
|
419 mike 1.23 //
420 //------------------------------------------------------------------------------
421
|
422 kumpf 1.27 void XmlWriter::appendMethodCallHeader(
423 Array<Sint8>& out,
|
424 mike 1.23 const char* host,
425 const char* cimMethod,
426 const String& cimObject,
|
427 mike 1.24 const String& authenticationHeader,
|
428 kumpf 1.27 Uint32 contentLength)
|
429 mike 1.23 {
430 char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
431
432 out << "M-POST /cimom HTTP/1.1\r\n";
433 out << "HOST: " << host << "\r\n";
434 out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n";
|
435 kumpf 1.27 out << "Content-Length: " << contentLength << "\r\n";
|
436 mike 1.23 out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
437 out << nn <<"\r\n";
|
438 kumpf 1.27 out << nn << "-CIMOperation: MethodCall\r\n";
|
439 mike 1.23 out << nn << "-CIMMethod: " << cimMethod << "\r\n";
|
440 mike 1.24 out << nn << "-CIMObject: " << cimObject << "\r\n";
441 if (authenticationHeader.size())
442 {
443 out << authenticationHeader << "\r\n";
444 }
445 out << "\r\n";
|
446 mike 1.23 }
447
448 //------------------------------------------------------------------------------
449 //
|
450 kumpf 1.27 // appendMethodResponseHeader()
|
451 mike 1.23 //
452 // Build HTTP response header.
453 //
454 //------------------------------------------------------------------------------
455
|
456 kumpf 1.27 void XmlWriter::appendMethodResponseHeader(
457 Array<Sint8>& out,
458 Uint32 contentLength)
|
459 mike 1.23 {
460 char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
461
462 out << "HTTP/1.1 200 OK\r\n";
463 out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n";
|
464 kumpf 1.27 out << "Content-Length: " << contentLength << "\r\n";
|
465 mike 1.23 out << "Ext:\r\n";
466 out << "Cache-Control: no-cache\r\n";
467 out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
468 out << nn <<"\r\n";
469 out << nn << "-CIMOperation: MethodResponse\r\n\r\n";
470 }
471
472 //------------------------------------------------------------------------------
473 //
|
474 kumpf 1.40 // appendHttpErrorResponseHeader()
475 //
476 // Build HTTP error response header.
477 //
478 // Returns error response message in the following format:
479 //
|
480 kumpf 1.41 // HTTP/1.1 400 Bad Request (using specified status code)
481 // CIMError: <error type> (if specified by caller)
482 // PGErrorDetail: <error text> (if specified by caller)
|
483 kumpf 1.40 //
484 //------------------------------------------------------------------------------
485
486 void XmlWriter::appendHttpErrorResponseHeader(
487 Array<Sint8>& out,
488 const String& status,
489 const String& cimError,
|
490 kumpf 1.41 const String& errorDetail)
|
491 kumpf 1.40 {
492 out << "HTTP/1.1 " << status << "\r\n";
493 if (cimError != String::EMPTY)
494 {
495 out << "CIMError: " << cimError << "\r\n";
496 }
|
497 kumpf 1.41 if (errorDetail != String::EMPTY)
|
498 kumpf 1.40 {
|
499 kumpf 1.41 // ATTN-RK-P3-20020404: It is critical that this text not contain '\n'
500 // ATTN-RK-P3-20020404: Need to encode this value properly. (See
501 // CIM/HTTP Specification section 3.3.2
502 out << "PGErrorDetail: " << errorDetail << "\r\n";
|
503 kumpf 1.40 }
504 out << "\r\n";
505 }
506
507 //------------------------------------------------------------------------------
508 //
|
509 kumpf 1.27 // appendUnauthorizedResponseHeader()
510 //
511 // Build HTTP authentication response header for unauthorized requests.
512 //
513 // Returns unauthorized message in the following format:
514 //
515 // HTTP/1.1 401 Unauthorized
516 // WWW-Authenticate: Basic "hostname:80"
517 // <HTML><HEAD>
518 // <TITLE>401 Unauthorized</TITLE>
519 // </HEAD><BODY BGCOLOR="#99cc99">
520 // <H2>TEST401 Unauthorized</H2>
521 // <HR>
522 // </BODY></HTML>
523 //
524 //------------------------------------------------------------------------------
525
526 void XmlWriter::appendUnauthorizedResponseHeader(
527 Array<Sint8>& out,
528 const String& content)
529 {
|
530 kumpf 1.40 out << "HTTP/1.1 " HTTP_STATUS_UNAUTHORIZED "\r\n";
|
531 kumpf 1.27 out << content << "\r\n";
532 out << "\r\n";
533
534 //ATTN: We may need to include the following line, so that the browsers
535 // can display the error message.
536 // out << "<HTML><HEAD>\r\n";
537 // out << "<TITLE>" << "401 Unauthorized" << "</TITLE>\r\n";
538 // out << "</HEAD><BODY BGCOLOR=\"#99cc99\">\r\n";
539 // out << "<H2>TEST" << "401 Unauthorized" << "</H2>\r\n";
540 // out << "<HR>\r\n";
541 // out << "</BODY></HTML>\r\n";
542 }
543
544 //------------------------------------------------------------------------------
545 //
|
546 kumpf 1.29 // _appendMessageElementBegin()
547 // _appendMessageElementEnd()
|
548 mike 1.23 //
549 // <!ELEMENT MESSAGE (SIMPLEREQ|MULTIREQ|SIMPLERSP|MULTIRSP)>
550 // <!ATTLIST MESSAGE
551 // ID CDATA #REQUIRED
552 // PROTOCOLVERSION CDATA #REQUIRED>
553 //
554 //------------------------------------------------------------------------------
555
|
556 kumpf 1.29 void XmlWriter::_appendMessageElementBegin(
|
557 kumpf 1.27 Array<Sint8>& out,
558 const String& messageId)
|
559 mike 1.23 {
560 out << "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
561 out << "<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">\n";
562 out << "<MESSAGE ID=\"" << messageId << "\" PROTOCOLVERSION=\"1.0\">\n";
|
563 kumpf 1.27 }
564
|
565 kumpf 1.29 void XmlWriter::_appendMessageElementEnd(
|
566 kumpf 1.27 Array<Sint8>& out)
567 {
|
568 mike 1.23 out << "</MESSAGE>\n";
569 out << "</CIM>\n";
570 }
571
572 //------------------------------------------------------------------------------
573 //
|
574 kumpf 1.29 // _appendSimpleReqElementBegin()
575 // _appendSimpleReqElementEnd()
|
576 mike 1.23 //
577 // <!ELEMENT SIMPLEREQ (IMETHODCALL|METHODCALL)>
578 //
579 //------------------------------------------------------------------------------
580
|
581 kumpf 1.29 void XmlWriter::_appendSimpleReqElementBegin(
|
582 kumpf 1.27 Array<Sint8>& out)
583 {
584 out << "<SIMPLEREQ>\n";
585 }
586
|
587 kumpf 1.29 void XmlWriter::_appendSimpleReqElementEnd(
|
588 kumpf 1.27 Array<Sint8>& out)
|
589 mike 1.23 {
|
590 kumpf 1.27 out << "</SIMPLEREQ>\n";
|
591 mike 1.23 }
592
593 //------------------------------------------------------------------------------
594 //
|
595 kumpf 1.29 // _appendMethodCallElementBegin()
596 // _appendMethodCallElementEnd()
|
597 mike 1.23 //
|
598 kumpf 1.27 // <!ELEMENT METHODCALL ((LOCALCLASSPATH|LOCALINSTANCEPATH),PARAMVALUE*)>
599 // <!ATTLIST METHODCALL %CIMName;>
|
600 mike 1.23 //
601 //------------------------------------------------------------------------------
602
|
603 kumpf 1.29 void XmlWriter::_appendMethodCallElementBegin(
|
604 kumpf 1.27 Array<Sint8>& out,
605 const char* name)
606 {
607 out << "<METHODCALL NAME=\"" << name << "\">\n";
608 }
609
|
610 kumpf 1.29 void XmlWriter::_appendMethodCallElementEnd(
|
611 kumpf 1.27 Array<Sint8>& out)
|
612 mike 1.23 {
|
613 kumpf 1.27 out << "</METHODCALL>\n";
|
614 mike 1.23 }
615
616 //------------------------------------------------------------------------------
617 //
|
618 kumpf 1.29 // _appendIMethodCallElementBegin()
619 // _appendIMethodCallElementEnd()
|
620 mike 1.23 //
621 // <!ELEMENT IMETHODCALL (LOCALNAMESPACEPATH,IPARAMVALUE*)>
622 // <!ATTLIST IMETHODCALL %CIMName;>
623 //
624 //------------------------------------------------------------------------------
625
|
626 kumpf 1.29 void XmlWriter::_appendIMethodCallElementBegin(
|
627 kumpf 1.27 Array<Sint8>& out,
628 const char* name)
|
629 mike 1.23 {
630 out << "<IMETHODCALL NAME=\"" << name << "\">\n";
|
631 kumpf 1.27 }
632
|
633 kumpf 1.29 void XmlWriter::_appendIMethodCallElementEnd(
|
634 kumpf 1.27 Array<Sint8>& out)
635 {
|
636 mike 1.23 out << "</IMETHODCALL>\n";
637 }
638
639 //------------------------------------------------------------------------------
640 //
|
641 kumpf 1.29 // _appendIParamValueElementBegin()
642 // _appendIParamValueElementEnd()
|
643 mike 1.23 //
|
644 kumpf 1.27 // <!ELEMENT IPARAMVALUE (VALUE|VALUE.ARRAY|VALUE.REFERENCE
645 // |INSTANCENAME|CLASSNAME|QUALIFIER.DECLARATION
646 // |CLASS|INSTANCE|VALUE.NAMEDINSTANCE)?>
647 // <!ATTLIST IPARAMVALUE %CIMName;>
|
648 mike 1.23 //
649 //------------------------------------------------------------------------------
650
|
651 kumpf 1.29 void XmlWriter::_appendIParamValueElementBegin(
|
652 kumpf 1.27 Array<Sint8>& out,
653 const char* name)
654 {
655 out << "<IPARAMVALUE NAME=\"" << name << "\">\n";
656 }
657
|
658 kumpf 1.29 void XmlWriter::_appendIParamValueElementEnd(
|
659 kumpf 1.27 Array<Sint8>& out)
|
660 mike 1.23 {
|
661 kumpf 1.27 out << "</IPARAMVALUE>\n";
|
662 mike 1.23 }
663
664 //------------------------------------------------------------------------------
665 //
|
666 kumpf 1.29 // _appendSimpleRspElementBegin()
667 // _appendSimpleRspElementEnd()
|
668 mike 1.23 //
|
669 kumpf 1.27 // <!ELEMENT SIMPLERSP (METHODRESPONSE|IMETHODRESPONSE)>
|
670 mike 1.23 //
671 //------------------------------------------------------------------------------
672
|
673 kumpf 1.29 void XmlWriter::_appendSimpleRspElementBegin(
|
674 kumpf 1.27 Array<Sint8>& out)
675 {
676 out << "<SIMPLERSP>\n";
677 }
678
|
679 kumpf 1.29 void XmlWriter::_appendSimpleRspElementEnd(
|
680 kumpf 1.27 Array<Sint8>& out)
|
681 mike 1.23 {
|
682 kumpf 1.27 out << "</SIMPLERSP>\n";
|
683 mike 1.23 }
684
685 //------------------------------------------------------------------------------
686 //
|
687 kumpf 1.29 // _appendMethodResponseElementBegin()
688 // _appendMethodResponseElementEnd()
|
689 mike 1.23 //
|
690 kumpf 1.27 // <!ELEMENT METHODRESPONSE (ERROR|IRETURNVALUE?)>
691 // <!ATTLIST METHODRESPONSE %CIMName;>
|
692 mike 1.23 //
693 //------------------------------------------------------------------------------
694
|
695 kumpf 1.29 void XmlWriter::_appendMethodResponseElementBegin(
|
696 mike 1.23 Array<Sint8>& out,
|
697 kumpf 1.27 const char* name)
698 {
699 out << "<METHODRESPONSE NAME=\"" << name << "\">\n";
700 }
701
|
702 kumpf 1.29 void XmlWriter::_appendMethodResponseElementEnd(
|
703 kumpf 1.27 Array<Sint8>& out)
|
704 mike 1.23 {
|
705 kumpf 1.27 out << "</METHODRESPONSE>\n";
706 }
707
708 //------------------------------------------------------------------------------
709 //
|
710 kumpf 1.29 // _appendIMethodResponseElementBegin()
711 // _appendIMethodResponseElementEnd()
|
712 kumpf 1.27 //
713 // <!ELEMENT IMETHODRESPONSE (ERROR|IRETURNVALUE?)>
714 // <!ATTLIST IMETHODRESPONSE %CIMName;>
715 //
716 //------------------------------------------------------------------------------
717
|
718 kumpf 1.29 void XmlWriter::_appendIMethodResponseElementBegin(
|
719 kumpf 1.27 Array<Sint8>& out,
720 const char* name)
721 {
722 out << "<IMETHODRESPONSE NAME=\"" << name << "\">\n";
723 }
724
|
725 kumpf 1.29 void XmlWriter::_appendIMethodResponseElementEnd(
|
726 kumpf 1.27 Array<Sint8>& out)
727 {
728 out << "</IMETHODRESPONSE>\n";
|
729 mike 1.23 }
730
731 //------------------------------------------------------------------------------
732 //
|
733 kumpf 1.29 // _appendErrorElement()
|
734 mike 1.23 //
735 //------------------------------------------------------------------------------
736
|
737 kumpf 1.29 void XmlWriter::_appendErrorElement(
|
738 kumpf 1.27 Array<Sint8>& out,
|
739 mike 1.23 CIMStatusCode code,
740 const char* description)
741 {
742 out << "<ERROR";
743 out << " CODE=\"" << Uint32(code) << "\"";
744 out << " DESCRIPTION=\"";
745 appendSpecial(out, description);
746 out << "\"/>";
747 }
748
749 //------------------------------------------------------------------------------
750 //
|
751 kumpf 1.27 // appendReturnValueElement()
752 //
753 // <!ELEMENT RETURNVALUE (VALUE|VALUE.REFERENCE)>
754 // <!ATTLIST RETURNVALUE
755 // %ParamType;>
|
756 mike 1.23 //
757 //------------------------------------------------------------------------------
758
|
759 kumpf 1.27 void XmlWriter::appendReturnValueElement(
|
760 mike 1.23 Array<Sint8>& out,
|
761 kumpf 1.27 const CIMValue& value)
762 {
763 out << "<RETURNVALUE";
764
765 CIMType type = value.getType();
766 if (type != CIMType::NONE)
767 {
768 out << " PARAMTYPE=\"" << TypeToString(type) << "\"";
769 }
770
771 out << ">\n";
|
772 karl 1.37
773 // Add value. If no value is Null, do not put <VALUE> tags on
|
774 karl 1.33 value.toXml(out, false);
|
775 kumpf 1.27 out << "</RETURNVALUE>\n";
776 }
777
778 //------------------------------------------------------------------------------
779 //
|
780 kumpf 1.29 // _appendIReturnValueElementBegin()
781 // _appendIReturnValueElementEnd()
|
782 kumpf 1.27 //
783 // <!ELEMENT IRETURNVALUE (CLASSNAME*|INSTANCENAME*|VALUE*|
784 // VALUE.OBJECTWITHPATH*|VALUE.OBJECTWITHLOCALPATH*|VALUE.OBJECT*|
785 // OBJECTPATH*|QUALIFIER.DECLARATION*|VALUE.ARRAY?|VALUE.REFERENCE?|
786 // CLASS*|INSTANCE*|VALUE.NAMEDINSTANCE*)>
787 //
788 //------------------------------------------------------------------------------
789
|
790 kumpf 1.29 void XmlWriter::_appendIReturnValueElementBegin(
|
791 kumpf 1.27 Array<Sint8>& out)
792 {
793 out << "<IRETURNVALUE>\n";
794 }
795
|
796 kumpf 1.29 void XmlWriter::_appendIReturnValueElementEnd(
|
797 kumpf 1.27 Array<Sint8>& out)
|
798 mike 1.23 {
|
799 kumpf 1.27 out << "</IRETURNVALUE>\n";
|
800 mike 1.23 }
801
802 //------------------------------------------------------------------------------
803 //
|
804 kumpf 1.27 // appendBooleanIParameter()
|
805 mike 1.23 //
806 //------------------------------------------------------------------------------
807
|
808 kumpf 1.27 void XmlWriter::appendBooleanIParameter(
|
809 mike 1.23 Array<Sint8>& out,
810 const char* name,
|
811 kumpf 1.27 Boolean flag)
|
812 mike 1.23 {
|
813 kumpf 1.29 _appendIParamValueElementBegin(out, name);
|
814 kumpf 1.27 out << "<VALUE>" << (flag ? "TRUE" : "FALSE") << "</VALUE>\n";
|
815 kumpf 1.29 _appendIParamValueElementEnd(out);
|
816 mike 1.23 }
817
818 //------------------------------------------------------------------------------
819 //
|
820 kumpf 1.27 // appendStringIParameter()
|
821 mike 1.23 //
822 //------------------------------------------------------------------------------
823
|
824 kumpf 1.27 void XmlWriter::appendStringIParameter(
|
825 mike 1.23 Array<Sint8>& out,
826 const char* name,
|
827 kumpf 1.27 const String& str)
|
828 mike 1.23 {
|
829 kumpf 1.29 _appendIParamValueElementBegin(out, name);
|
830 kumpf 1.27 out << "<VALUE>";
831 appendSpecial(out, str);
832 out << "</VALUE>\n";
|
833 kumpf 1.29 _appendIParamValueElementEnd(out);
|
834 mike 1.23 }
835
836 //------------------------------------------------------------------------------
837 //
|
838 kumpf 1.27 // appendQualifierNameIParameter()
|
839 mike 1.23 //
840 //------------------------------------------------------------------------------
841
|
842 kumpf 1.27 void XmlWriter::appendQualifierNameIParameter(
|
843 mike 1.23 Array<Sint8>& out,
844 const char* name,
845 const String& qualifierName)
846 {
847 // <!ELEMENT IPARAMVALUE (VALUE|VALUE.ARRAY|VALUE.REFERENCE
848 // |INSTANCENAME|CLASSNAME|QUALIFIER.DECLARATION
849 // |CLASS|INSTANCE|VALUE.NAMEDINSTANCE)?>
850 //
851 // ATTN: notice that there is really no way to pass a qualifier name
852 // as an IPARAMVALUE element according to the spec (look above). So we
853 // just pass it as a class name. An answer must be obtained later.
854
|
855 kumpf 1.29 _appendIParamValueElementBegin(out, name);
|
856 kumpf 1.27 appendClassNameElement(out, qualifierName);
|
857 kumpf 1.29 _appendIParamValueElementEnd(out);
|
858 mike 1.23 }
859
860 //------------------------------------------------------------------------------
861 //
|
862 kumpf 1.27 // appendClassNameIParameter()
|
863 mike 1.23 //
864 //------------------------------------------------------------------------------
865
|
866 kumpf 1.27 void XmlWriter::appendClassNameIParameter(
|
867 mike 1.23 Array<Sint8>& out,
|
868 kumpf 1.27 const char* name,
869 const String& className)
|
870 mike 1.23 {
|
871 kumpf 1.29 _appendIParamValueElementBegin(out, name);
|
872 kumpf 1.27 appendClassNameElement(out, className);
|
873 kumpf 1.29 _appendIParamValueElementEnd(out);
|
874 mike 1.23 }
875
876 //------------------------------------------------------------------------------
877 //
|
878 kumpf 1.27 // appendInstanceNameIParameter()
|
879 mike 1.23 //
880 //------------------------------------------------------------------------------
881
|
882 kumpf 1.27 void XmlWriter::appendInstanceNameIParameter(
|
883 mike 1.23 Array<Sint8>& out,
|
884 kumpf 1.27 const char* name,
|
885 mike 1.23 const CIMReference& instanceName)
886 {
|
887 kumpf 1.29 _appendIParamValueElementBegin(out, name);
888 appendInstanceNameElement(out, instanceName);
889 _appendIParamValueElementEnd(out);
|
890 kumpf 1.27 }
891
892 void XmlWriter::appendObjectNameIParameter(
893 Array<Sint8>& out,
894 const char* name,
895 const CIMReference& objectName)
896 {
897 if (objectName.isClassName())
898 {
899 XmlWriter::appendClassNameIParameter(
900 out, name, objectName.getClassName());
901 }
902 else
903 {
904 XmlWriter::appendInstanceNameIParameter(
905 out, name, objectName);
906 }
907 }
908
909 //------------------------------------------------------------------------------
910 //
911 kumpf 1.27 // appendClassIParameter()
912 //
913 //------------------------------------------------------------------------------
914
915 void XmlWriter::appendClassIParameter(
916 Array<Sint8>& out,
917 const char* name,
918 const CIMConstClass& cimClass)
919 {
|
920 kumpf 1.29 _appendIParamValueElementBegin(out, name);
|
921 kumpf 1.27 cimClass.toXml(out);
|
922 kumpf 1.29 _appendIParamValueElementEnd(out);
|
923 mike 1.23 }
924
925 //------------------------------------------------------------------------------
926 //
|
927 kumpf 1.27 // appendInstanceIParameter()
|
928 mike 1.23 //
929 //------------------------------------------------------------------------------
930
|
931 kumpf 1.27 void XmlWriter::appendInstanceIParameter(
|
932 mike 1.23 Array<Sint8>& out,
|
933 kumpf 1.27 const char* name,
|
934 mike 1.23 const CIMConstInstance& instance)
935 {
|
936 kumpf 1.29 _appendIParamValueElementBegin(out, name);
|
937 kumpf 1.27 instance.toXml(out);
|
938 kumpf 1.29 _appendIParamValueElementEnd(out);
|
939 mike 1.23 }
940
|
941 mike 1.24 //------------------------------------------------------------------------------
942 //
|
943 kumpf 1.27 // appendNamedInstanceIParameter()
|
944 mike 1.24 //
945 //------------------------------------------------------------------------------
946
|
947 kumpf 1.27 void XmlWriter::appendNamedInstanceIParameter(
|
948 mike 1.24 Array<Sint8>& out,
|
949 kumpf 1.27 const char* name,
|
950 mike 1.24 const CIMNamedInstance& namedInstance)
951 {
|
952 kumpf 1.29 _appendIParamValueElementBegin(out, name);
|
953 kumpf 1.27 namedInstance.toXml(out);
|
954 kumpf 1.29 _appendIParamValueElementEnd(out);
|
955 mike 1.24 }
956
|
957 mike 1.23 //----------------------------------------------------------
958 //
|
959 kumpf 1.27 // appendPropertyNameIParameter()
|
960 mike 1.23 //
961 // </IPARAMVALUE>
962 // <IPARAMVALUE NAME="PropertyName"><VALUE>FreeSpace</VALUE></IPARAMVALUE>
963 //
964 // USE: Create parameter for getProperty operation
965 //==========================================================
|
966 kumpf 1.27 void XmlWriter::appendPropertyNameIParameter(
|
967 mike 1.23 Array<Sint8>& out,
968 const String& propertyName)
969 {
|
970 kumpf 1.29 _appendIParamValueElementBegin(out, "PropertyName");
|
971 kumpf 1.27 out << "<VALUE>" << propertyName << "</VALUE>\n";
|
972 kumpf 1.29 _appendIParamValueElementEnd(out);
|
973 kumpf 1.27 }
|
974 mike 1.23
975 //------------------------------------------------------------------------------
976 //
|
977 kumpf 1.27 // appendPropertyValueIParameter()
|
978 mike 1.24 //
979 //------------------------------------------------------------------------------
980
|
981 kumpf 1.27 void XmlWriter::appendPropertyValueIParameter(
|
982 mike 1.24 Array<Sint8>& out,
|
983 kumpf 1.27 const char* name,
|
984 mike 1.24 const CIMValue& value)
985 {
|
986 kumpf 1.29 _appendIParamValueElementBegin(out, name);
|
987 karl 1.33 value.toXml(out, false);
|
988 kumpf 1.29 _appendIParamValueElementEnd(out);
|
989 mike 1.24 }
990
991 //------------------------------------------------------------------------------
992 //
|
993 kumpf 1.27 // appendPropertyListIParameter()
|
994 mike 1.24 //
995 //------------------------------------------------------------------------------
996
|
997 kumpf 1.27 void XmlWriter::appendPropertyListIParameter(
|
998 mike 1.24 Array<Sint8>& out,
999 const CIMPropertyList& propertyList)
1000 {
|
1001 karl 1.37 // ATTN: P3 KS 4 Mar 2002 - As check shouldn't we check for null property list
|
1002 kumpf 1.29 _appendIParamValueElementBegin(out, "PropertyList");
|
1003 mike 1.24
|
1004 kumpf 1.27 out << "<VALUE.ARRAY>\n";
|
1005 mike 1.24 for (Uint32 i = 0; i < propertyList.getNumProperties(); i++)
1006 {
|
1007 kumpf 1.27 out << "<VALUE>" << propertyList.getPropertyName(i) << "</VALUE>\n";
|
1008 mike 1.24 }
|
1009 kumpf 1.27 out << "</VALUE.ARRAY>\n";
1010
|
1011 kumpf 1.29 _appendIParamValueElementEnd(out);
|
1012 mike 1.24 }
1013
1014 //------------------------------------------------------------------------------
1015 //
|
1016 kumpf 1.27 // appendQualifierDeclarationIParameter()
|
1017 mike 1.23 //
1018 //------------------------------------------------------------------------------
1019
|
1020 kumpf 1.27 void XmlWriter::appendQualifierDeclarationIParameter(
|
1021 mike 1.23 Array<Sint8>& out,
|
1022 kumpf 1.27 const char* name,
|
1023 mike 1.23 const CIMConstQualifierDecl& qualifierDecl)
1024 {
|
1025 kumpf 1.29 _appendIParamValueElementBegin(out, name);
|
1026 kumpf 1.27 qualifierDecl.toXml(out);
|
1027 kumpf 1.29 _appendIParamValueElementEnd(out);
|
1028 kumpf 1.40 }
1029
1030 //------------------------------------------------------------------------------
1031 //
1032 // XmlWriter::formatHttpErrorRspMessage()
1033 //
1034 //------------------------------------------------------------------------------
1035
1036 Array<Sint8> XmlWriter::formatHttpErrorRspMessage(
1037 const String& status,
1038 const String& cimError,
|
1039 kumpf 1.41 const String& errorDetail)
|
1040 kumpf 1.40 {
1041 Array<Sint8> out;
1042
|
1043 kumpf 1.41 appendHttpErrorResponseHeader(out, status, cimError, errorDetail);
|
1044 kumpf 1.40
|
1045 kumpf 1.41 return out;
|
1046 mike 1.23 }
1047
1048 //------------------------------------------------------------------------------
1049 //
|
1050 kumpf 1.27 // XmlWriter::formatSimpleMethodReqMessage()
|
1051 mike 1.23 //
1052 //------------------------------------------------------------------------------
1053
|
1054 kumpf 1.27 // ATTN-RK-P1-20020228: Need to complete copy elimination optimization
1055 Array<Sint8> XmlWriter::formatSimpleMethodReqMessage(
1056 const char* host,
|
1057 kumpf 1.38 const String& nameSpace,
|
1058 kumpf 1.29 const CIMReference& path,
|
1059 kumpf 1.27 const char* methodName,
|
1060 kumpf 1.30 const Array<CIMParamValue>& parameters,
|
1061 kumpf 1.27 const String& messageId,
|
1062 kumpf 1.30 const String& authenticationHeader)
|
1063 kumpf 1.27 {
1064 Array<Sint8> out;
1065 Array<Sint8> tmp;
|
1066 kumpf 1.38 CIMReference localObjectPath = path;
1067 localObjectPath.setNameSpace(nameSpace);
|
1068 kumpf 1.27
|
1069 kumpf 1.29 _appendMessageElementBegin(out, messageId);
1070 _appendSimpleReqElementBegin(out);
1071 _appendMethodCallElementBegin(out, methodName);
|
1072 kumpf 1.38 appendLocalObjectPathElement(out, localObjectPath);
|
1073 kumpf 1.30 for (Uint32 i=0; i < parameters.size(); i++)
|
1074 kumpf 1.29 {
|
1075 kumpf 1.30 parameters[i].toXml(out);
|
1076 kumpf 1.29 }
1077 _appendMethodCallElementEnd(out);
1078 _appendSimpleReqElementEnd(out);
1079 _appendMessageElementEnd(out);
|
1080 kumpf 1.27
1081 appendMethodCallHeader(
1082 tmp,
1083 host,
1084 methodName,
|
1085 kumpf 1.39 localObjectPath.toString(false),
|
1086 kumpf 1.27 authenticationHeader,
1087 out.size());
1088 tmp << out;
1089
1090 return tmp;
1091 }
1092
1093 Array<Sint8> XmlWriter::formatSimpleMethodRspMessage(
1094 const char* methodName,
1095 const String& messageId,
1096 const Array<Sint8>& body)
|
1097 mike 1.23 {
|
1098 kumpf 1.27 Array<Sint8> out;
1099 Array<Sint8> tmp;
1100
|
1101 kumpf 1.29 _appendMessageElementBegin(out, messageId);
1102 _appendSimpleRspElementBegin(out);
1103 _appendMethodResponseElementBegin(out, methodName);
|
1104 kumpf 1.27 out << body;
|
1105 kumpf 1.29 _appendMethodResponseElementEnd(out);
1106 _appendSimpleRspElementEnd(out);
1107 _appendMessageElementEnd(out);
|
1108 mike 1.23
|
1109 kumpf 1.27 appendMethodResponseHeader(tmp, out.size());
1110 tmp << out;
|
1111 mike 1.23
|
1112 kumpf 1.27 return tmp;
|
1113 mike 1.23 }
1114
1115 //------------------------------------------------------------------------------
1116 //
|
1117 kumpf 1.28 // XmlWriter::formatSimpleMethodErrorRspMessage()
1118 //
1119 //------------------------------------------------------------------------------
1120
1121 Array<Sint8> XmlWriter::formatSimpleMethodErrorRspMessage(
1122 const String& methodName,
1123 const String& messageId,
1124 CIMStatusCode code,
1125 const String& description)
1126 {
1127 ArrayDestroyer<char> tmp1(methodName.allocateCString());
1128 ArrayDestroyer<char> tmp2(description.allocateCString());
1129 Array<Sint8> out;
1130 Array<Sint8> tmp;
1131
|
1132 kumpf 1.29 _appendMessageElementBegin(out, messageId);
1133 _appendSimpleRspElementBegin(out);
1134 _appendMethodResponseElementBegin(out, tmp1.getPointer());
1135 _appendErrorElement(out, code, tmp2.getPointer());
1136 _appendMethodResponseElementEnd(out);
1137 _appendSimpleRspElementEnd(out);
1138 _appendMessageElementEnd(out);
|
1139 kumpf 1.28
1140 appendMethodResponseHeader(tmp, out.size());
1141 tmp << out;
1142
1143 return tmp;
1144 }
1145
1146 //------------------------------------------------------------------------------
1147 //
|
1148 kumpf 1.27 // XmlWriter::formatSimpleIMethodReqMessage()
|
1149 mike 1.23 //
1150 //------------------------------------------------------------------------------
1151
|
1152 kumpf 1.27 Array<Sint8> XmlWriter::formatSimpleIMethodReqMessage(
1153 const char* host,
1154 const String& nameSpace,
1155 const char* iMethodName,
1156 const String& messageId,
1157 const String& authenticationHeader,
1158 const Array<Sint8>& body)
|
1159 mike 1.23 {
|
1160 kumpf 1.27 Array<Sint8> out;
1161 Array<Sint8> tmp;
1162
|
1163 kumpf 1.29 _appendMessageElementBegin(out, messageId);
1164 _appendSimpleReqElementBegin(out);
1165 _appendIMethodCallElementBegin(out, iMethodName);
1166 appendLocalNameSpacePathElement(out, nameSpace);
|
1167 kumpf 1.27 out << body;
|
1168 kumpf 1.29 _appendIMethodCallElementEnd(out);
1169 _appendSimpleReqElementEnd(out);
1170 _appendMessageElementEnd(out);
|
1171 kumpf 1.27
1172 appendMethodCallHeader(
1173 tmp,
1174 host,
1175 iMethodName,
1176 nameSpace,
1177 authenticationHeader,
1178 out.size());
1179 tmp << out;
|
1180 mike 1.23
|
1181 kumpf 1.27 return tmp;
|
1182 mike 1.23 }
1183
1184 //------------------------------------------------------------------------------
1185 //
|
1186 kumpf 1.27 // XmlWriter::formatSimpleIMethodRspMessage()
|
1187 mike 1.23 //
1188 //------------------------------------------------------------------------------
1189
|
1190 kumpf 1.27 Array<Sint8> XmlWriter::formatSimpleIMethodRspMessage(
1191 const char* iMethodName,
1192 const String& messageId,
1193 const Array<Sint8>& body)
|
1194 mike 1.23 {
|
1195 kumpf 1.27 Array<Sint8> out;
1196 Array<Sint8> tmp;
|
1197 mike 1.23
|
1198 kumpf 1.29 _appendMessageElementBegin(out, messageId);
1199 _appendSimpleRspElementBegin(out);
1200 _appendIMethodResponseElementBegin(out, iMethodName);
1201 _appendIReturnValueElementBegin(out);
|
1202 kumpf 1.27 out << body;
|
1203 kumpf 1.29 _appendIReturnValueElementEnd(out);
1204 _appendIMethodResponseElementEnd(out);
1205 _appendSimpleRspElementEnd(out);
1206 _appendMessageElementEnd(out);
|
1207 mike 1.23
|
1208 kumpf 1.27 appendMethodResponseHeader(tmp, out.size());
1209 tmp << out;
|
1210 mike 1.23
|
1211 kumpf 1.27 return tmp;
1212 }
|
1213 mike 1.23
|
1214 kumpf 1.28 //------------------------------------------------------------------------------
1215 //
1216 // XmlWriter::formatSimpleIMethodErrorRspMessage()
1217 //
1218 //------------------------------------------------------------------------------
1219
1220 Array<Sint8> XmlWriter::formatSimpleIMethodErrorRspMessage(
1221 const String& iMethodName,
1222 const String& messageId,
1223 CIMStatusCode code,
1224 const String& description)
1225 {
1226 ArrayDestroyer<char> tmp1(iMethodName.allocateCString());
1227 ArrayDestroyer<char> tmp2(description.allocateCString());
1228 Array<Sint8> out;
1229 Array<Sint8> tmp;
1230
|
1231 kumpf 1.29 _appendMessageElementBegin(out, messageId);
1232 _appendSimpleRspElementBegin(out);
1233 _appendIMethodResponseElementBegin(out, tmp1.getPointer());
1234 _appendErrorElement(out, code, tmp2.getPointer());
1235 _appendIMethodResponseElementEnd(out);
1236 _appendSimpleRspElementEnd(out);
1237 _appendMessageElementEnd(out);
|
1238 kumpf 1.28
1239 appendMethodResponseHeader(tmp, out.size());
1240 tmp << out;
1241
1242 return tmp;
1243 }
1244
|
1245 kumpf 1.27 //******************************************************************************
1246 //
1247 // Export Messages (used for indications)
1248 //
1249 //******************************************************************************
|
1250 mike 1.23
|
1251 kumpf 1.27 //------------------------------------------------------------------------------
1252 //
1253 // appendEMethodRequestHeader()
1254 //
1255 // Build HTTP request header for export operation.
1256 //
1257 //------------------------------------------------------------------------------
|
1258 mike 1.23
|
1259 kumpf 1.27 void XmlWriter::appendEMethodRequestHeader(
1260 Array<Sint8>& out,
1261 const char* host,
1262 const char* cimMethod,
1263 const String& authenticationHeader,
1264 Uint32 contentLength)
1265 {
1266 char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
|
1267 mike 1.23
|
1268 kumpf 1.27 out << "M-POST /cimom HTTP/1.1\r\n";
1269 out << "HOST: " << host << "\r\n";
1270 out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n";
1271 out << "Content-Length: " << contentLength << "\r\n";
1272 out << "Man: http://www.hp.com; ns=";
1273 out << nn <<"\r\n";
|
1274 kumpf 1.32 out << nn << "-CIMExport: MethodRequest\r\n";
|
1275 kumpf 1.27 out << nn << "-CIMExportMethod: " << cimMethod << "\r\n";
1276 if (authenticationHeader.size())
1277 {
1278 out << authenticationHeader << "\r\n";
1279 }
1280 out << "\r\n";
1281 }
|
1282 mike 1.23
|
1283 kumpf 1.27 //------------------------------------------------------------------------------
1284 //
1285 // appendEMethodResponseHeader()
1286 //
1287 // Build HTTP response header for export operation.
1288 //
1289 //------------------------------------------------------------------------------
|
1290 mike 1.23
|
1291 kumpf 1.27 void XmlWriter::appendEMethodResponseHeader(
1292 Array<Sint8>& out,
1293 Uint32 contentLength)
1294 {
1295 char nn[] = { '0' + (rand() % 10), '0' + (rand() % 10), '\0' };
|
1296 mike 1.23
|
1297 kumpf 1.27 out << "HTTP/1.1 200 OK\r\n";
1298 out << "Content-CIMType: application/xml; charset=\"utf-8\"\r\n";
1299 out << "Content-Length: " << contentLength << "\r\n";
1300 out << "Ext:\r\n";
1301 out << "Cache-Control: no-cache\r\n";
1302 out << "Man: http://www.dmtf.org/cim/mapping/http/v1.0; ns=";
1303 out << nn <<"\r\n";
1304 out << nn << "-CIMExport: MethodResponse\r\n\r\n";
|
1305 mike 1.23 }
1306
1307 //------------------------------------------------------------------------------
1308 //
|
1309 kumpf 1.29 // _appendSimpleExportReqElementBegin()
1310 // _appendSimpleExportReqElementEnd()
|
1311 kumpf 1.27 //
1312 // <!ELEMENT SIMPLEEXPREQ (EXPMETHODCALL)>
|
1313 mike 1.23 //
1314 //------------------------------------------------------------------------------
1315
|
1316 kumpf 1.29 void XmlWriter::_appendSimpleExportReqElementBegin(
|
1317 kumpf 1.27 Array<Sint8>& out)
|
1318 mike 1.23 {
|
1319 kumpf 1.27 out << "<SIMPLEEXPREQ>\n";
1320 }
|
1321 mike 1.23
|
1322 kumpf 1.29 void XmlWriter::_appendSimpleExportReqElementEnd(
|
1323 kumpf 1.27 Array<Sint8>& out)
1324 {
1325 out << "</SIMPLEEXPREQ>\n";
|
1326 mike 1.23 }
1327
1328 //------------------------------------------------------------------------------
1329 //
|
1330 kumpf 1.29 // _appendEMethodCallElementBegin()
1331 // _appendEMethodCallElementEnd()
|
1332 kumpf 1.27 //
1333 // <!ELEMENT EXPMETHODCALL (IPARAMVALUE*)>
1334 // <!ATTLIST EXPMETHODCALL %CIMName;>
|
1335 mike 1.23 //
1336 //------------------------------------------------------------------------------
1337
|
1338 kumpf 1.29 void XmlWriter::_appendEMethodCallElementBegin(
|
1339 mike 1.23 Array<Sint8>& out,
|
1340 kumpf 1.27 const char* name)
|
1341 mike 1.23 {
|
1342 kumpf 1.27 out << "<EXPMETHODCALL NAME=\"" << name << "\">\n";
|
1343 mike 1.24 }
1344
|
1345 kumpf 1.29 void XmlWriter::_appendEMethodCallElementEnd(
|
1346 kumpf 1.27 Array<Sint8>& out)
|
1347 mike 1.24 {
1348 out << "</EXPMETHODCALL>\n";
1349 }
1350
1351 //------------------------------------------------------------------------------
1352 //
|
1353 kumpf 1.29 // _appendSimpleExportRspElementBegin()
1354 // _appendSimpleExportRspElementEnd()
|
1355 mike 1.24 //
|
1356 kumpf 1.27 // <!ELEMENT SIMPLEEXPRSP (EXPMETHODRESPONSE)>
|
1357 mike 1.24 //
1358 //------------------------------------------------------------------------------
1359
|
1360 kumpf 1.29 void XmlWriter::_appendSimpleExportRspElementBegin(
|
1361 kumpf 1.27 Array<Sint8>& out)
1362 {
1363 out << "<SIMPLEEXPRSP>\n";
1364 }
1365
|
1366 kumpf 1.29 void XmlWriter::_appendSimpleExportRspElementEnd(
|
1367 kumpf 1.27 Array<Sint8>& out)
|
1368 mike 1.24 {
|
1369 kumpf 1.27 out << "</SIMPLEEXPRSP>\n";
|
1370 mike 1.24 }
1371
1372 //------------------------------------------------------------------------------
1373 //
|
1374 kumpf 1.29 // _appendEMethodResponseElementBegin()
1375 // _appendEMethodResponseElementEnd()
|
1376 mike 1.24 //
1377 // <!ELEMENT EXPMETHODRESPONSE (ERROR|IRETURNVALUE?)>
1378 // <!ATTLIST EXPMETHODRESPONSE %CIMName;>
1379 //
1380 //------------------------------------------------------------------------------
1381
|
1382 kumpf 1.29 void XmlWriter::_appendEMethodResponseElementBegin(
|
1383 kumpf 1.27 Array<Sint8>& out,
1384 const char* name)
|
1385 mike 1.24 {
1386 out << "<EXPMETHODRESPONSE NAME=\"" << name << "\">\n";
|
1387 kumpf 1.27 }
1388
|
1389 kumpf 1.29 void XmlWriter::_appendEMethodResponseElementEnd(
|
1390 kumpf 1.27 Array<Sint8>& out)
1391 {
|
1392 mike 1.24 out << "</EXPMETHODRESPONSE>\n";
1393 }
1394
1395 //------------------------------------------------------------------------------
1396 //
|
1397 kumpf 1.27 // XmlWriter::formatSimpleEMethodReqMessage()
|
1398 mike 1.24 //
1399 //------------------------------------------------------------------------------
1400
|
1401 kumpf 1.27 Array<Sint8> XmlWriter::formatSimpleEMethodReqMessage(
1402 const char* host,
1403 const char* eMethodName,
1404 const String& messageId,
1405 const String& authenticationHeader,
1406 const Array<Sint8>& body)
|
1407 mike 1.24 {
1408 Array<Sint8> out;
|
1409 kumpf 1.27 Array<Sint8> tmp;
1410
|
1411 kumpf 1.29 _appendMessageElementBegin(out, messageId);
1412 _appendSimpleExportReqElementBegin(out);
1413 _appendEMethodCallElementBegin(out, eMethodName);
|
1414 kumpf 1.27 out << body;
|
1415 kumpf 1.29 _appendEMethodCallElementEnd(out);
1416 _appendSimpleExportReqElementEnd(out);
1417 _appendMessageElementEnd(out);
|
1418 kumpf 1.27
1419 appendEMethodRequestHeader(
1420 tmp,
1421 host,
1422 eMethodName,
1423 authenticationHeader,
1424 out.size());
1425 tmp << out;
|
1426 mike 1.24
1427 return out;
1428 }
1429
1430 //------------------------------------------------------------------------------
1431 //
|
1432 kumpf 1.27 // XmlWriter::formatSimpleEMethodRspMessage()
|
1433 mike 1.24 //
1434 //------------------------------------------------------------------------------
1435
|
1436 kumpf 1.27 Array<Sint8> XmlWriter::formatSimpleEMethodRspMessage(
1437 const char* eMethodName,
|
1438 mike 1.24 const String& messageId,
1439 const Array<Sint8>& body)
1440 {
|
1441 kumpf 1.27 Array<Sint8> out;
1442 Array<Sint8> tmp;
1443
|
1444 kumpf 1.29 _appendMessageElementBegin(out, messageId);
1445 _appendSimpleExportRspElementBegin(out);
1446 _appendEMethodResponseElementBegin(out, eMethodName);
|
1447 kumpf 1.27 out << body;
|
1448 kumpf 1.29 _appendEMethodResponseElementEnd(out);
1449 _appendSimpleExportRspElementEnd(out);
1450 _appendMessageElementEnd(out);
|
1451 kumpf 1.28
1452 appendEMethodResponseHeader(tmp, out.size());
1453 tmp << out;
1454
1455 return tmp;
1456 }
1457
1458 //------------------------------------------------------------------------------
1459 //
1460 // XmlWriter::formatSimpleEMethodErrorRspMessage()
1461 //
1462 //------------------------------------------------------------------------------
1463
1464 Array<Sint8> XmlWriter::formatSimpleEMethodErrorRspMessage(
1465 const String& eMethodName,
1466 const String& messageId,
1467 CIMStatusCode code,
1468 const String& description)
1469 {
1470 ArrayDestroyer<char> tmp1(eMethodName.allocateCString());
1471 ArrayDestroyer<char> tmp2(description.allocateCString());
1472 kumpf 1.28 Array<Sint8> out;
1473 Array<Sint8> tmp;
1474
|
1475 kumpf 1.29 _appendMessageElementBegin(out, messageId);
1476 _appendSimpleExportRspElementBegin(out);
1477 _appendEMethodResponseElementBegin(out, tmp1.getPointer());
1478 _appendErrorElement(out, code, tmp2.getPointer());
1479 _appendEMethodResponseElementEnd(out);
1480 _appendSimpleExportRspElementEnd(out);
1481 _appendMessageElementEnd(out);
|
1482 kumpf 1.27
1483 appendEMethodResponseHeader(tmp, out.size());
1484 tmp << out;
1485
1486 return tmp;
|
1487 mike 1.24 }
1488
1489 //------------------------------------------------------------------------------
1490 //
|
1491 kumpf 1.27 // _printAttributes()
|
1492 mike 1.24 //
1493 //------------------------------------------------------------------------------
1494
|
1495 kumpf 1.27 static void _printAttributes(
1496 PEGASUS_STD(ostream)& os,
1497 const XmlAttribute* attributes,
1498 Uint32 attributeCount)
|
1499 mike 1.24 {
|
1500 kumpf 1.27 for (Uint32 i = 0; i < attributeCount; i++)
1501 {
1502 os << attributes[i].name << "=";
1503
1504 os << '"';
1505 _appendSpecial(os, attributes[i].value);
1506 os << '"';
|
1507 mike 1.24
|
1508 kumpf 1.27 if (i + 1 != attributeCount)
1509 os << ' ';
1510 }
|
1511 mike 1.24 }
1512
1513 //------------------------------------------------------------------------------
1514 //
|
1515 kumpf 1.27 // _indent()
|
1516 mike 1.24 //
1517 //------------------------------------------------------------------------------
1518
|
1519 kumpf 1.27 static void _indent(PEGASUS_STD(ostream)& os, Uint32 level, Uint32 indentChars)
|
1520 mike 1.24 {
|
1521 kumpf 1.27 Uint32 n = level * indentChars;
1522
1523 for (Uint32 i = 0; i < n; i++)
1524 os << ' ';
|
1525 mike 1.24 }
1526
1527 //------------------------------------------------------------------------------
1528 //
|
1529 kumpf 1.27 // indentedPrint()
|
1530 mike 1.24 //
1531 //------------------------------------------------------------------------------
1532
|
1533 kumpf 1.27 void XmlWriter::indentedPrint(
1534 PEGASUS_STD(ostream)& os,
1535 const char* text,
1536 Uint32 indentChars)
|
1537 mike 1.24 {
|
1538 kumpf 1.27 char* tmp = strcpy(new char[strlen(text) + 1], text);
1539
1540 XmlParser parser(tmp);
1541 XmlEntry entry;
1542 Stack<const char*> stack;
|
1543 kumpf 1.26
|
1544 kumpf 1.27 while (parser.next(entry))
|
1545 kumpf 1.26 {
|
1546 kumpf 1.27 switch (entry.type)
1547 {
1548 case XmlEntry::XML_DECLARATION:
1549 {
1550 _indent(os, stack.size(), indentChars);
1551
1552 os << "<?" << entry.text << " ";
1553 _printAttributes(os, entry.attributes, entry.attributeCount);
1554 os << "?>";
1555 break;
1556 }
1557
1558 case XmlEntry::START_TAG:
1559 {
1560 _indent(os, stack.size(), indentChars);
1561
1562 os << "<" << entry.text;
1563
1564 if (entry.attributeCount)
1565 os << ' ';
1566
1567 kumpf 1.27 _printAttributes(os, entry.attributes, entry.attributeCount);
1568 os << ">";
1569 stack.push(entry.text);
1570 break;
1571 }
1572
1573 case XmlEntry::EMPTY_TAG:
1574 {
1575 _indent(os, stack.size(), indentChars);
1576
1577 os << "<" << entry.text << " ";
1578 _printAttributes(os, entry.attributes, entry.attributeCount);
1579 os << "/>";
1580 break;
1581 }
1582
1583 case XmlEntry::END_TAG:
1584 {
1585 if (!stack.isEmpty() && strcmp(stack.top(), entry.text) == 0)
1586 stack.pop();
1587
1588 kumpf 1.27 _indent(os, stack.size(), indentChars);
1589
1590 os << "</" << entry.text << ">";
1591 break;
1592 }
1593
1594 case XmlEntry::COMMENT:
1595 {
1596
1597 _indent(os, stack.size(), indentChars);
1598 os << "<!--";
1599 _appendSpecial(os, entry.text);
1600 os << "-->";
1601 break;
1602 }
1603
1604 case XmlEntry::CONTENT:
1605 {
1606 _indent(os, stack.size(), indentChars);
1607 _appendSpecial(os, entry.text);
1608 break;
1609 kumpf 1.27 }
1610
1611 case XmlEntry::CDATA:
1612 {
1613 _indent(os, stack.size(), indentChars);
1614 os << "<![CDATA[...]]>";
1615 break;
1616 }
1617
1618 case XmlEntry::DOCTYPE:
1619 {
1620 _indent(os, stack.size(), indentChars);
1621 os << "<!DOCTYPE...>";
1622 break;
1623 }
1624 }
1625
1626 os << PEGASUS_STD(endl);
|
1627 kumpf 1.26 }
1628
|
1629 kumpf 1.27 delete [] tmp;
|
1630 mike 1.24 }
1631
1632 //------------------------------------------------------------------------------
1633 //
|
1634 kumpf 1.27 // XmlWriter::getNextMessageId()
|
1635 mike 1.24 //
1636 //------------------------------------------------------------------------------
1637
|
1638 kumpf 1.27 String XmlWriter::getNextMessageId()
|
1639 mike 1.24 {
|
1640 kumpf 1.27 // ATTN: make thread-safe:
1641 static Uint32 messageId = 1000;
|
1642 mike 1.24
|
1643 kumpf 1.27 messageId++;
|
1644 mike 1.24
|
1645 kumpf 1.27 if (messageId < 1000)
1646 messageId = 1001;
|
1647 mike 1.23
|
1648 kumpf 1.27 char buffer[16];
1649 sprintf(buffer, "%d", messageId);
1650 return buffer;
|
1651 mike 1.23 }
1652
1653 PEGASUS_NAMESPACE_END
|