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