Mixe for Privacy and Anonymity in the Internet
Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
DOM_Output Class Reference

#include <DOM_Output.hpp>

Collaboration diagram for DOM_Output:

Static Public Member Functions

static SINT32 dumpToMem (const DOMNode *node, UINT8 *buff, UINT32 *size)
 Dumps the node and all childs into buff. More...
 
static UINT8dumpToMem (const DOMNode *node, UINT32 *size)
 Dumps the Node an returns a pointer to the memory. More...
 
static UINT8dumpToString (const DOMNode *node, bool a_bAddNewLine)
 Dumps the Node an returns a pointer to a null terminated string. More...
 
static SINT32 makeCanonical (const DOMNode *node, UINT8 *buff, UINT32 *size)
 Dumps the node and all childs in a 'cannonical form' into buff. More...
 
static UINT8makeCanonical (const DOMNode *node, UINT32 *size)
 Dumps the Node in a cannonical form and returns a pointer to the memory. More...
 

Private Member Functions

 DOM_Output ()
 
 ~DOM_Output ()
 
SINT32 dumpNode (const DOMNode *toWrite, bool bCanonical)
 Dumps a Node of an XML Document. More...
 

Static Private Member Functions

static UINT8dumpToMem (const DOMNode *node, UINT32 *size, OUTPUT_FORMAT a_outputFormat)
 Dumps the Node an returns a pointer to the memory. More...
 

Private Attributes

XMLFormatter * m_pFormatter
 
MemFormatTargetm_pFormatTarget
 

Static Private Attributes

static const XMLCh m_XML [41]
 
static const XMLCh m_UTF8 [6]
 
static const XMLCh m_1_0 [4]
 

Detailed Description

Definition at line 149 of file DOM_Output.hpp.

Constructor & Destructor Documentation

◆ DOM_Output()

DOM_Output::DOM_Output ( )
inlineprivate

Definition at line 236 of file DOM_Output.hpp.

237  {
239  #if (_XERCES_VERSION >= 20300) //XMl-Version since Xerces 2.3.0
240  m_pFormatter=new XMLFormatter(m_UTF8,m_1_0, m_pFormatTarget,
241  XMLFormatter::NoEscapes, XMLFormatter::UnRep_Fail);
242  #else
243  m_pFormatter=new XMLFormatter(m_UTF8, m_pFormatTarget,
244  XMLFormatter::NoEscapes, XMLFormatter::UnRep_Fail);
245  #endif
246  }
MemFormatTarget * m_pFormatTarget
Definition: DOM_Output.hpp:274
static const XMLCh m_UTF8[6]
Definition: DOM_Output.hpp:276
XMLFormatter * m_pFormatter
Definition: DOM_Output.hpp:273
static const XMLCh m_1_0[4]
Definition: DOM_Output.hpp:277

References m_1_0, m_pFormatTarget, m_pFormatter, and m_UTF8.

◆ ~DOM_Output()

DOM_Output::~DOM_Output ( )
inlineprivate

Definition at line 247 of file DOM_Output.hpp.

248  {
249  delete m_pFormatTarget;
250  m_pFormatTarget = NULL;
251  delete m_pFormatter;
252  m_pFormatter = NULL;
253  }

References m_pFormatTarget, and m_pFormatter.

Member Function Documentation

◆ dumpNode()

SINT32 DOM_Output::dumpNode ( const DOMNode *  toWrite,
bool  bCanonical 
)
private

Dumps a Node of an XML Document.

Parameters
toWriteNode which will be dumped
bCanonicalif true the dump is done in a 'canonical' way, e.g. white spaces are eliminated etc.
Return values
E_SUCCESSif successful
E_UNKNOWNotherwise

Definition at line 80 of file DOM_Output.cpp.

81  {
82  if(toWrite==0)
83  return E_UNKNOWN;
84  // Get the name and value out for convenience
85  const XMLCh* pNodeName = toWrite->getNodeName();
86 
87  switch (toWrite->getNodeType())
88  {
89  case DOMNode::TEXT_NODE:
90  {
91  const XMLCh* pNodeValue = toWrite->getNodeValue();
92  if (pNodeValue == NULL)
93  break;
94  if(!bCanonical)
95  {
96  m_pFormatter->formatBuf(pNodeValue,XMLString::stringLen(pNodeValue),XMLFormatter::CharEscapes);
97  }
98  else //strip whitespaces...
99  {
100  XMLCh* pText=XMLString::replicate(pNodeValue);
101  XMLString::trim(pText);
102  char* tmpStr=XMLString::transcode(pText);
103  m_pFormatter->formatBuf(pText,XMLString::stringLen(pText),XMLFormatter::CharEscapes);
104  XMLString::release(&pText);
105  XMLString::release(&tmpStr);
106  }
107  break;
108  }
109 
110 
111  /* case DOM_Node::PROCESSING_INSTRUCTION_NODE :
112  {
113  *gFormatter << XMLFormatter::NoEscapes << gStartPI << nodeName;
114  if (lent > 0)
115  {
116  *gFormatter << chSpace << nodeValue;
117  }
118  *gFormatter << XMLFormatter::NoEscapes << gEndPI;
119  break;
120  }
121 */
122 
123  case DOMNode::DOCUMENT_NODE :
124  *m_pFormatter<<XMLFormatter::NoEscapes<<m_XML;
125  case DOMNode::DOCUMENT_FRAGMENT_NODE :
126  {
127 
128  DOMNode* pChild = toWrite->getFirstChild();
129  while( pChild != NULL)
130  {
131  dumpNode(pChild,bCanonical);
132  // add linefeed in requested output encoding
133  if(!bCanonical)
134  *m_pFormatter << chLF;
135  pChild = pChild->getNextSibling();
136  }
137  break;
138  }
139 
140 
141  case DOMNode::ELEMENT_NODE :
142  {
143  // The name has to be representable without any escapes
144  *m_pFormatter << XMLFormatter::NoEscapes
145  << chOpenAngle << pNodeName;
146 
147  // Output the element start tag.
148 
149  // Output any attributes on this element in lexicograhpical order
150  DOMNamedNodeMap* pAttributes = toWrite->getAttributes();
151  UINT32 attrCount = pAttributes->getLength();
152  const XMLCh** attr_names=NULL;
153  UINT32* sort_indices=NULL;
154  if(attrCount>0)
155  {
156  attr_names=new const XMLCh*[attrCount];
157  sort_indices=new UINT32[attrCount];
158  for(UINT32 i=0;i<attrCount;i++)
159  {
160  DOMNode* pAttribute = pAttributes->item(i);
161  attr_names[i]=pAttribute->getNodeName();
162  sort_indices[i]=i;
163  }
164  //now sort them
165  if(attrCount>1)
166  {
167  for(UINT32 i=0;i<attrCount;i++)
168  {
169  const XMLCh *akt=attr_names[sort_indices[i]];
170  for(UINT32 j=i+1;j<attrCount;j++)
171  {
172  const XMLCh* tmp=attr_names[sort_indices[j]];
173  if(XMLString::compareString(akt,tmp)>0)
174  {
175  UINT32 t=sort_indices[i];
176  sort_indices[i]=sort_indices[j];
177  sort_indices[j]=t;
178  akt=tmp;
179  }
180  }
181  }
182  }
183  }
184 
185  for (UINT32 i = 0; i < attrCount; i++)
186  {
187  //delete[] attr_names[i];
188  DOMNode* pAttribute = pAttributes->item(sort_indices[i]);
189 
190  //
191  // Again the name has to be completely representable. But the
192  // attribute can have refs and requires the attribute style
193  // escaping.
194  //
195  *m_pFormatter << XMLFormatter::NoEscapes
196  << chSpace << pAttribute->getNodeName()
197  << chEqual << chDoubleQuote
198  << XMLFormatter::AttrEscapes
199  << pAttribute->getNodeValue()
200  << XMLFormatter::NoEscapes
201  << chDoubleQuote;
202  }
203  *m_pFormatter << XMLFormatter::NoEscapes << chCloseAngle;
204 
205  delete[] attr_names;
206  attr_names = NULL;
207  delete[] sort_indices;
208  sort_indices = NULL;
209 
210  //
211  // Test for the presence of children, which includes both
212  // text content and nested elements.
213  //
214  DOMNode* pChild = toWrite->getFirstChild();
215  while( pChild != NULL)
216  {
217  dumpNode(pChild,bCanonical);
218  pChild = pChild->getNextSibling();
219  }
220 
221  *m_pFormatter << XMLFormatter::NoEscapes << gEndElement
222  << pNodeName << chCloseAngle;
223  break;
224  }
225 
226 /*
227  case DOM_Node::ENTITY_REFERENCE_NODE:
228  {
229  DOM_Node child;
230 #if 0
231  for (child = toWrite.getFirstChild();
232  child != 0;
233  child = child.getNextSibling())
234  {
235  dumpNode(child);
236  }
237 #else
238  //
239  // Instead of printing the refernece tree
240  // we'd output the actual text as it appeared in the xml file.
241  // This would be the case when -e option was chosen
242  //
243  m_Formatter << XMLFormatter::NoEscapes << chAmpersand
244  << nodeName << chSemiColon;
245 #endif
246  break;
247  }
248 
249 
250  case DOM_Node::CDATA_SECTION_NODE:
251  {
252  m_Formatter << XMLFormatter::NoEscapes << gStartCDATA
253  << nodeValue << gEndCDATA;
254  break;
255  }
256 
257 
258  case DOM_Node::COMMENT_NODE:
259  {
260  m_Formatter << XMLFormatter::NoEscapes << gStartComment
261  << nodeValue << gEndComment;
262  break;
263  }
264 
265 
266  case DOM_Node::DOCUMENT_TYPE_NODE:
267  {
268  DOM_DocumentType doctype = (DOM_DocumentType &)toWrite;;
269 
270  m_Formatter << XMLFormatter::NoEscapes << gStartDoctype
271  << nodeName;
272 
273  DOMString id = doctype.getPublicId();
274  if (id != 0)
275  {
276  m_Formatter << XMLFormatter::NoEscapes << chSpace << gPublic
277  << id << chDoubleQuote;
278  id = doctype.getSystemId();
279  if (id != 0)
280  {
281  m_Formatter << XMLFormatter::NoEscapes << chSpace
282  << chDoubleQuote << id << chDoubleQuote;
283  }
284  }
285  else
286  {
287  id = doctype.getSystemId();
288  if (id != 0)
289  {
290  m_Formatter << XMLFormatter::NoEscapes << chSpace << gSystem
291  << id << chDoubleQuote;
292  }
293  }
294 
295  id = doctype.getInternalSubset();
296  if (id !=0)
297  m_Formatter << XMLFormatter::NoEscapes << chOpenSquare
298  << id << chCloseSquare;
299 
300  m_Formatter << XMLFormatter::NoEscapes << chCloseAngle;
301  break;
302  }
303 
304 
305  case DOM_Node::ENTITY_NODE:
306  {
307  m_Formatter << XMLFormatter::NoEscapes << gStartEntity
308  << nodeName;
309 
310  DOMString id = ((DOM_Entity &)toWrite).getPublicId();
311  if (id != 0)
312  m_Formatter << XMLFormatter::NoEscapes << gPublic
313  << id << chDoubleQuote;
314 
315  id = ((DOM_Entity &)toWrite).getSystemId();
316  if (id != 0)
317  m_Formatter << XMLFormatter::NoEscapes << gSystem
318  << id << chDoubleQuote;
319 
320  id = ((DOM_Entity &)toWrite).getNotationName();
321  if (id != 0)
322  m_Formatter << XMLFormatter::NoEscapes << gNotation
323  << id << chDoubleQuote;
324 
325  m_Formatter << XMLFormatter::NoEscapes << chCloseAngle << chLF;
326 
327  break;
328  }
329 
330 
331  case DOM_Node::XML_DECL_NODE:
332  {
333  DOMString str;
334 
335  m_Formatter << gXMLDecl1 << ((DOM_XMLDecl &)toWrite).getVersion();
336 
337  m_Formatter << gXMLDecl2 << gEncodingName;
338 
339  str = ((DOM_XMLDecl &)toWrite).getStandalone();
340  if (str != 0)
341  m_Formatter << gXMLDecl3 << str;
342 
343  m_Formatter << gXMLDecl4;
344 
345  break;
346  }
347 
348 */
349  default:
350  return E_UNKNOWN;
351  }
352  return E_SUCCESS;
353 }
unsigned int UINT32
Definition: basetypedefs.h:131
static const XMLCh m_XML[41]
Definition: DOM_Output.hpp:275
SINT32 dumpNode(const DOMNode *toWrite, bool bCanonical)
Dumps a Node of an XML Document.
Definition: DOM_Output.cpp:80
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3

References E_UNKNOWN, m_pFormatter, and m_XML.

Referenced by dumpToMem(), and makeCanonical().

Here is the caller graph for this function:

◆ dumpToMem() [1/3]

static UINT8* DOM_Output::dumpToMem ( const DOMNode *  node,
UINT32 size 
)
inlinestatic

Dumps the Node an returns a pointer to the memory.

Note that the string is NOT null-terminated.

Parameters
nodeNode to dump
sizeon return contains the number of XML-Chars copied
Returns
a pointer to a newls allocated buff, which must be delete[] by the caller
NULL if an error occurs

Definition at line 176 of file DOM_Output.hpp.

177  {
178  return dumpToMem(node, size, OF_DEFAULT);
179  }
@ OF_DEFAULT
Definition: DOM_Output.hpp:33
static SINT32 dumpToMem(const DOMNode *node, UINT8 *buff, UINT32 *size)
Dumps the node and all childs into buff.
Definition: DOM_Output.hpp:161

References dumpToMem(), and OF_DEFAULT.

Here is the call graph for this function:

◆ dumpToMem() [2/3]

static UINT8* DOM_Output::dumpToMem ( const DOMNode *  node,
UINT32 size,
OUTPUT_FORMAT  a_outputFormat 
)
inlinestaticprivate

Dumps the Node an returns a pointer to the memory.

Parameters
nodeNode to dump
sizeon return contains the number of XML-Chars copied
a_outputFormatthe output format of the string, e.g. with null termination
Returns
a pointer to a newls allocated buff, which must be delete[] by the caller
NULL if an error occurs

Definition at line 263 of file DOM_Output.hpp.

264  {
265  DOM_Output out;
266  if( out.dumpNode(node,false)!=E_SUCCESS)
267  return NULL;
268  return out.m_pFormatTarget->dumpMem(size, a_outputFormat);
269  }
SINT32 dumpMem(UINT8 *buff, UINT32 *size)
Copys the XML-chars into buff.
Definition: DOM_Output.hpp:89

References MemFormatTarget::dumpMem(), dumpNode(), E_SUCCESS, and m_pFormatTarget.

Here is the call graph for this function:

◆ dumpToMem() [3/3]

static SINT32 DOM_Output::dumpToMem ( const DOMNode *  node,
UINT8 buff,
UINT32 size 
)
inlinestatic

Dumps the node and all childs into buff.

Note that the string is NOT null-terminated.

Parameters
nodeNode to dump
buffbuffer in which to copy the XML-chars
sizecontains the size of buff, on return contains the number of XML-CHars copied
Returns
E_SUCCESS if successful
E_SPACE if buff is to small
E_UNKNOWN if an error occurs

Definition at line 161 of file DOM_Output.hpp.

162  {
163  DOM_Output out;
164  if( out.dumpNode(node,false)!=E_SUCCESS)
165  return E_UNKNOWN;
166  return out.m_pFormatTarget->dumpMem(buff,size);
167  }

References MemFormatTarget::dumpMem(), dumpNode(), E_SUCCESS, E_UNKNOWN, and m_pFormatTarget.

Referenced by CAFirstMix::doUserLogin_internal(), dumpToMem(), dumpToString(), encryptXMLElement(), CAInfoService::getCascadeHeloXMLAsString(), CAASymCipher::getPublicKeyAsXML(), CAAccountingInstance::handleAccountCertificate_internal(), CALastMix::processKeyExchange(), CAMiddleMix::processKeyExchange(), CACmdLnOptions::saveToFile(), CAAccountingInstance::sendAILoginConfirmation(), CAAccountingInstance::sendCCRequest(), CAAccountingInstance::sendInitialCCRequest(), CAAbstractControlChannel::sendXMLMessage(), CACmdLnOptions::setPrevMix(), CAAccountingBIInterface::settleAll(), CAXMLErrorMessage::setValues(), CAMultiSignature::signXML(), CAAbstractXMLEncodable::toXmlString(), and CAInfoService::xmlDocToStringWithSignature().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dumpToString()

static UINT8* DOM_Output::dumpToString ( const DOMNode *  node,
bool  a_bAddNewLine 
)
inlinestatic

Dumps the Node an returns a pointer to a null terminated string.

Parameters
nodeNode to dump
a_bAddNewLinetrue if a new line should be added to the end of the string; false otherwise
Returns
a pointer to a newls allocated buff, which must be delete[] by the caller
NULL if an error occurs

Definition at line 190 of file DOM_Output.hpp.

191  {
192  UINT32 dummy;
193  if (a_bAddNewLine)
194  {
195  return dumpToMem(node, &dummy, OF_NEWLINE);
196  }
197  else
198  {
199  return dumpToMem(node, &dummy, OF_NULL_TERMINATED);
200  }
201  }
@ OF_NULL_TERMINATED
Definition: DOM_Output.hpp:33
@ OF_NEWLINE
Definition: DOM_Output.hpp:33

References dumpToMem(), OF_NEWLINE, and OF_NULL_TERMINATED.

Referenced by CAXMLErrorMessage::setValues().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ makeCanonical() [1/2]

static UINT8* DOM_Output::makeCanonical ( const DOMNode *  node,
UINT32 size 
)
inlinestatic

Dumps the Node in a cannonical form and returns a pointer to the memory.

Parameters
nodeNode to dump
sizeon return contains the number of XML-Chars copied
Returns
a pointer to a newly allocated buff, which must be delete[] by the caller
NULL if an error occurs

Definition at line 227 of file DOM_Output.hpp.

228  {
229  DOM_Output out;
230  if( out.dumpNode(node,true)!=E_SUCCESS)
231  return NULL;
232  return out.m_pFormatTarget->dumpMem(size, OF_DEFAULT);
233  }

References MemFormatTarget::dumpMem(), dumpNode(), E_SUCCESS, m_pFormatTarget, and OF_DEFAULT.

Here is the call graph for this function:

◆ makeCanonical() [2/2]

static SINT32 DOM_Output::makeCanonical ( const DOMNode *  node,
UINT8 buff,
UINT32 size 
)
inlinestatic

Dumps the node and all childs in a 'cannonical form' into buff.

Parameters
nodeNode to dump
buffbuffer in which to copy the XML-chars
sizecontains the size of buff, on return contains the number of XML-CHars copied
Returns
E_SUCCESS if successful
E_SPACE if buff is to small
E_UNKNOWN if an error occurs

Definition at line 212 of file DOM_Output.hpp.

213  {
214  DOM_Output out;
215  if( out.dumpNode(node,true)!=E_SUCCESS)
216  return E_UNKNOWN;
217  return out.m_pFormatTarget->dumpMem(buff,size);
218  }

References MemFormatTarget::dumpMem(), dumpNode(), E_SUCCESS, E_UNKNOWN, and m_pFormatTarget.

Referenced by CAAccountingInstance::prepareCCRequest(), CAMultiSignature::signXML(), CAMultiSignature::verifyXML(), and CASignature::verifyXML().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_1_0

const XMLCh DOM_Output::m_1_0
staticprivate
Initial value:
=
{
chDigit_1,chPeriod,chDigit_0, chNull
}

Definition at line 277 of file DOM_Output.hpp.

Referenced by DOM_Output().

◆ m_pFormatTarget

MemFormatTarget* DOM_Output::m_pFormatTarget
private

Definition at line 274 of file DOM_Output.hpp.

Referenced by DOM_Output(), dumpToMem(), makeCanonical(), and ~DOM_Output().

◆ m_pFormatter

XMLFormatter* DOM_Output::m_pFormatter
private

Definition at line 273 of file DOM_Output.hpp.

Referenced by DOM_Output(), dumpNode(), and ~DOM_Output().

◆ m_UTF8

const XMLCh DOM_Output::m_UTF8
staticprivate
Initial value:
=
{
chLatin_U, chLatin_T,chLatin_F, chDash,chDigit_8, chNull
}

Definition at line 276 of file DOM_Output.hpp.

Referenced by DOM_Output().

◆ m_XML

const XMLCh DOM_Output::m_XML
staticprivate
Initial value:
=
{
chOpenAngle,chQuestion,chLatin_x,chLatin_m,chLatin_l,chSpace,
chLatin_v,chLatin_e,chLatin_r,chLatin_s,chLatin_i,chLatin_o,chLatin_n,chEqual,
chDoubleQuote,chDigit_1,chPeriod,chDigit_0,chDoubleQuote,chSpace,
chLatin_e,chLatin_n,chLatin_c,chLatin_o,chLatin_d,chLatin_i,chLatin_n,chLatin_g,chEqual,
chDoubleQuote,chLatin_U, chLatin_T,chLatin_F, chDash,chDigit_8, chDoubleQuote,
chSpace,chQuestion, chCloseAngle, chLF, chNull
}

Definition at line 275 of file DOM_Output.hpp.

Referenced by dumpNode().


The documentation for this class was generated from the following files: