Mixe for Privacy and Anonymity in the Internet
DOM_Output.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 #ifndef __DOM_OUTPUT__
29 #define __DOM_OUTPUT__
30 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX
31 #include "../CAQueue.hpp"
32 
34 
35 class MemFormatTarget: public XMLFormatTarget
36  {
37 #define MEM_FORMART_TARGET_SPACE 1024
38  public:
40  {
41  m_pQueue=new CAQueue();
43  m_aktIndex=0;
44  }
45 
46  virtual ~MemFormatTarget()
47  {
48  delete m_pQueue;
49  m_pQueue = NULL;
50  delete[] m_Buff;
51  m_Buff = NULL;
52  }
53 
54 #if (XERCES_VERSION_MAJOR <3)
55  virtual void writeChars(const XMLByte* const toWrite, const unsigned int count, XMLFormatter* const /*formatter*/)
56 #else
57  virtual void writeChars(const XMLByte* const toWrite, const XMLSize_t count, XMLFormatter* const /*formatter*/)
58 #endif
59  {
60  const XMLByte* write=toWrite;
61  UINT32 c=count;
62  while(c>0)
63  {
65  if(space>=c)
66  {
67  memcpy(m_Buff+m_aktIndex,write,c);
68  m_aktIndex+=c;
69  return;
70  }
71  else
72  {
73  memcpy(m_Buff+m_aktIndex,write,space);
74  write+=space;
75  c-=space;
77  m_aktIndex=0;
78  }
79  }
80  }
81 
89  SINT32 dumpMem(UINT8* buff,UINT32* size)
90  {
91  if(buff==NULL||size==NULL)
92  return E_UNKNOWN;
94  return E_UNKNOWN;
95  m_aktIndex=0;
96  if(*size<m_pQueue->getSize())
97  return E_SPACE;
98  if(m_pQueue->peek(buff,size)!=E_SUCCESS)
99  return E_UNKNOWN;
100  return E_SUCCESS;
101  }
102 
109  UINT8* dumpMem(UINT32* size, OUTPUT_FORMAT a_outputFormat)
110  {
111  if(size==NULL)
112  return NULL;
114  return NULL;
115  m_aktIndex=0;
116  *size=m_pQueue->getSize();
117  if (OF_NULL_TERMINATED == a_outputFormat)
118  {
119  *size += 1;
120  }
121  else if (OF_NEWLINE == a_outputFormat)
122  {
123  *size += 2;
124  }
125  UINT8* tmp=new UINT8[*size];
126  if(m_pQueue->peek(tmp,size)!=E_SUCCESS)
127  {
128  delete[] tmp;
129  tmp = NULL;
130  }
131  if (OF_NULL_TERMINATED == a_outputFormat)
132  {
133  tmp[*size] =0;
134  }
135  else if (OF_NEWLINE == a_outputFormat)
136  {
137  tmp[*size] = '\n';
138  tmp[*size+1] = 0;
139  }
140  return tmp;
141  }
142 
143  private:
147  };
148 
150  {
151  public:
161  static SINT32 dumpToMem(const DOMNode* node,UINT8* buff, UINT32* size)
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  }
168 
176  static UINT8* dumpToMem(const DOMNode* node,UINT32* size)
177  {
178  return dumpToMem(node, size, OF_DEFAULT);
179  }
180 
181 
182 
190  static UINT8* dumpToString(const DOMNode* node, bool a_bAddNewLine)
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  }
202 
203 
212  static SINT32 makeCanonical(const DOMNode* node,UINT8* buff,UINT32* size)
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  }
219 
220 
227  static UINT8* makeCanonical(const DOMNode* node,UINT32* size)
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  }
234 
235  private:
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  }
248  {
249  delete m_pFormatTarget;
250  m_pFormatTarget = NULL;
251  delete m_pFormatter;
252  m_pFormatter = NULL;
253  }
254 
255 
263  static UINT8* dumpToMem(const DOMNode* node,UINT32* size, OUTPUT_FORMAT a_outputFormat)
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  }
270 
271 
272  SINT32 dumpNode(const DOMNode* toWrite,bool bCanonical);
273  XMLFormatter* m_pFormatter;
275  static const XMLCh m_XML[41];
276  static const XMLCh m_UTF8[6];
277  static const XMLCh m_1_0[4];
278 
279 };
280 
281 #endif
282 #endif //ONLY_LOCAL_PROXY
OUTPUT_FORMAT
Definition: DOM_Output.hpp:33
@ OF_NULL_TERMINATED
Definition: DOM_Output.hpp:33
@ OF_NEWLINE
Definition: DOM_Output.hpp:33
@ OF_DEFAULT
Definition: DOM_Output.hpp:33
#define MEM_FORMART_TARGET_SPACE
Definition: DOM_Output.hpp:37
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
This is a simple FIFO-Queue.
Definition: CAQueue.hpp:50
SINT32 add(const void *buff, UINT32 size)
Adds data to the Queue.
Definition: CAQueue.cpp:76
SINT32 peek(UINT8 *pbuff, UINT32 *psize)
Peeks data from the Queue.
Definition: CAQueue.cpp:258
UINT32 getSize()
Returns the size of stored data in byte.
Definition: CAQueue.hpp:101
static UINT8 * dumpToMem(const DOMNode *node, UINT32 *size)
Dumps the Node an returns a pointer to the memory.
Definition: DOM_Output.hpp:176
static UINT8 * dumpToString(const DOMNode *node, bool a_bAddNewLine)
Dumps the Node an returns a pointer to a null terminated string.
Definition: DOM_Output.hpp:190
MemFormatTarget * m_pFormatTarget
Definition: DOM_Output.hpp:274
static SINT32 makeCanonical(const DOMNode *node, UINT8 *buff, UINT32 *size)
Dumps the node and all childs in a 'cannonical form' into buff.
Definition: DOM_Output.hpp:212
static const XMLCh m_UTF8[6]
Definition: DOM_Output.hpp:276
XMLFormatter * m_pFormatter
Definition: DOM_Output.hpp:273
static const XMLCh m_XML[41]
Definition: DOM_Output.hpp:275
static const XMLCh m_1_0[4]
Definition: DOM_Output.hpp:277
static UINT8 * makeCanonical(const DOMNode *node, UINT32 *size)
Dumps the Node in a cannonical form and returns a pointer to the memory.
Definition: DOM_Output.hpp:227
static UINT8 * dumpToMem(const DOMNode *node, UINT32 *size, OUTPUT_FORMAT a_outputFormat)
Dumps the Node an returns a pointer to the memory.
Definition: DOM_Output.hpp:263
SINT32 dumpNode(const DOMNode *toWrite, bool bCanonical)
Dumps a Node of an XML Document.
Definition: DOM_Output.cpp:80
static SINT32 dumpToMem(const DOMNode *node, UINT8 *buff, UINT32 *size)
Dumps the node and all childs into buff.
Definition: DOM_Output.hpp:161
CAQueue * m_pQueue
Definition: DOM_Output.hpp:144
virtual void writeChars(const XMLByte *const toWrite, const unsigned int count, XMLFormatter *const)
Definition: DOM_Output.hpp:55
SINT32 dumpMem(UINT8 *buff, UINT32 *size)
Copys the XML-chars into buff.
Definition: DOM_Output.hpp:89
virtual ~MemFormatTarget()
Definition: DOM_Output.hpp:46
UINT8 * dumpMem(UINT32 *size, OUTPUT_FORMAT a_outputFormat)
Returns a Copy of the XML-chars.
Definition: DOM_Output.hpp:109
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_SPACE
Definition: errorcodes.hpp:7
#define E_UNKNOWN
Definition: errorcodes.hpp:3