AERA
xml_parser.h
1 
38 #ifndef __INCLUDE_XML_NODE__
39 #define __INCLUDE_XML_NODE__
40 
41 #include <stdlib.h>
42 
43 #ifdef _UNICODE
44 // If you comment the next "define" line then the library will never "switch to" _UNICODE (wchar_t*) mode (16/32 bits per characters).
45 // This is useful when you get error messages like:
46 // 'XMLNode::openFileHelper' : cannot convert parameter 2 from 'const char [5]' to 'const wchar_t *'
47 // The _XMLWIDECHAR preprocessor variable force the XMLParser library into either utf16/32-mode (the proprocessor variable
48 // must be defined) or utf8-mode(the pre-processor variable must be undefined).
49 #define _XMLWIDECHAR
50 #endif
51 
52 #if defined(WIN32) || defined(UNDER_CE)
53 // comment the next line if you are under windows and the compiler is not Microsoft Visual Studio (6.0 or .NET)
54 #define _XMLWINDOWS
55 #endif
56 
57 #define _USE_XMLPARSER_DLL
58 
59 #ifdef XMLDLLENTRY
60 #undef XMLDLLENTRY
61 #endif
62 #ifdef _USE_XMLPARSER_DLL
63 #ifdef CORELIBRARY_EXPORTS
64 #define XMLDLLENTRY __declspec(dllexport)
65 #else
66 #define XMLDLLENTRY __declspec(dllimport)
67 #endif
68 #else
69 #define XMLDLLENTRY
70 #endif
71 
72 // uncomment the next line if you want no support for wchar_t* (no need for the <wchar.h> or <tchar.h> libraries anymore to compile)
73 //#define XML_NO_WIDE_CHAR
74 
75 #ifdef XML_NO_WIDE_CHAR
76 #undef _XMLWINDOWS
77 #undef _XMLWIDECHAR
78 #endif
79 
80 #ifdef _XMLWINDOWS
81 #include <tchar.h>
82 #else
83 #undef XMLDLLENTRY
84 #define XMLDLLENTRY
85 #ifndef XML_NO_WIDE_CHAR
86 #include <wchar.h> // to have 'wcsrtombs' for ANSI version
87  // to have 'mbsrtowcs' for WIDECHAR version
88 #endif
89 #endif
90 
91 // Some common types for char set portable code
92 #ifdef _XMLWIDECHAR
93  #ifndef _X
94  #define _X(c) L ## c
95  #endif
96  #define XMLCSTR const wchar_t *
97  #define XMLSTR wchar_t *
98  #define XMLCHAR wchar_t
99 #else
100  #ifndef _X
101  #define _X(c) c
102  #endif
103  #define XMLCSTR const char *
104  #define XMLSTR char *
105  #define XMLCHAR char
106 #endif
107 #ifndef FALSE
108  #define FALSE 0
109 #endif /* FALSE */
110 #ifndef TRUE
111  #define TRUE 1
112 #endif /* TRUE */
113 
114 namespace core{
115 // Enumeration for XML parse errors.
116 typedef enum XMLError
117 {
118  eXMLErrorNone = 0,
119  eXMLErrorMissingEndTag,
120  eXMLErrorNoXMLTagFound,
121  eXMLErrorEmpty,
122  eXMLErrorMissingTagName,
123  eXMLErrorMissingEndTagName,
124  eXMLErrorUnmatchedEndTag,
125  eXMLErrorUnmatchedEndClearTag,
126  eXMLErrorUnexpectedToken,
127  eXMLErrorNoElements,
128  eXMLErrorFileNotFound,
129  eXMLErrorFirstTagNotFound,
130  eXMLErrorUnknownCharacterEntity,
131  eXMLErrorCharConversionError,
132  eXMLErrorCannotOpenWriteFile,
133  eXMLErrorCannotWriteFile,
134 
135  eXMLErrorBase64DataSizeIsNotMultipleOf4,
136  eXMLErrorBase64DecodeIllegalCharacter,
137  eXMLErrorBase64DecodeTruncatedData,
138  eXMLErrorBase64DecodeBufferTooSmall
139 } XMLError;
140 
141 
142 // Enumeration used to manage type of data. Use in conjunction with structure XMLNodeContents
143 typedef enum XMLElementType
144 {
145  eNodeChild=0,
146  eNodeAttribute=1,
147  eNodeText=2,
148  eNodeClear=3,
149  eNodeNULL=4
150 } XMLElementType;
151 
152 // Structure used to obtain error details if the parse fails.
153 typedef struct XMLResults
154 {
155  enum XMLError error;
156  int nLine,nColumn;
157 } XMLResults;
158 
159 // Structure for XML clear (unformatted) node (usually comments)
160 typedef struct XMLClear {
161  XMLCSTR lpszValue; XMLCSTR lpszOpenTag; XMLCSTR lpszCloseTag;
162 } XMLClear;
163 
164 // Structure for XML attribute.
165 typedef struct XMLAttribute {
166  XMLCSTR lpszName; XMLCSTR lpszValue;
167 } XMLAttribute;
168 
169 struct XMLNodeContents;
170 
171 typedef struct XMLDLLENTRY XMLNode
172 {
173  private:
174 
175  struct XMLNodeDataTag;
176 
177  // protected constructors: use one of these four methods to get your first instance of XMLNode:
178  // - parseString
179  // - parseFile
180  // - openFileHelper
181  // - createXMLTopNode
182  XMLNode(struct XMLNodeDataTag *pParent, XMLSTR lpszName, char isDeclaration);
183  XMLNode(struct XMLNodeDataTag *p);
184 
185  public:
186 
187  // You can create your first instance of XMLNode with these 4 functions:
188  // (see complete explanation of parameters below)
189 
190  static XMLNode createXMLTopNode(XMLCSTR lpszName, char isDeclaration=FALSE);
191  static XMLNode parseString (XMLCSTR lpXMLString, XMLCSTR tag=NULL, XMLResults *pResults=NULL);
192  static XMLNode parseFile (XMLCSTR filename, XMLCSTR tag=NULL, XMLResults *pResults=NULL);
193  static XMLNode openFileHelper(XMLCSTR filename, XMLCSTR tag=NULL );
194 
195  // The tag parameter should be the name of the first tag inside the XML file.
196  // If the tag parameter is omitted, the 3 functions return a node that represents
197  // the head of the xml document including the declaration term (<? ... ?>).
198 
199  // The "openFileHelper" reports to the screen all the warnings & errors that occurred during
200  // parsing of the XML file. Since each application has its own way to report and deal with errors,
201  // you should rather use the "parseFile" function to parse XML files and program yourself thereafter
202  // an "error reporting" tailored for your needs (instead of using the very crude "error reporting"
203  // mechanism included inside the "openFileHelper" function).
204 
205  // If the XML document is corrupted:
206  // * The "openFileHelper" method will:
207  // - display an error message on the console (or inside a messageBox for windows).
208  // - stop execution (exit).
209  // I suggest that you write your own "openFileHelper" method tailored to your needs.
210  // * The 2 other methods will initialize the "pResults" variable with some information that
211  // can be used to trace the error.
212  // * If you still want to parse the file, you can use the APPROXIMATE_PARSING option as
213  // explained inside the note at the beginning of the "xmlParser.cpp" file.
214  // You can have a user-friendly explanation of the parsing error with this function:
215  static XMLCSTR getError(XMLError error);
216  static XMLCSTR getVersion();
217 
218  XMLCSTR getName() const; // name of the node
219  XMLCSTR getText(int i=0) const; // return ith text field
220  int nText() const; // nbr of text field
221  XMLNode getParentNode() const; // return the parent node
222  XMLNode getChildNode(int i=0) const; // return ith child node
223  XMLNode getChildNode(XMLCSTR name, int i) const; // return ith child node with specific name
224  // (return an empty node if failing)
225  XMLNode getChildNode(XMLCSTR name, int *i=NULL) const; // return next child node with specific name
226  // (return an empty node if failing)
227  XMLNode getChildNodeWithAttribute(XMLCSTR tagName, // return child node with specific name/attribute
228  XMLCSTR attributeName, // (return an empty node if failing)
229  XMLCSTR attributeValue=NULL, //
230  int *i=NULL) const; //
231  int nChildNode(XMLCSTR name) const; // return the number of child node with specific name
232  int nChildNode() const; // nbr of child node
233  XMLAttribute getAttribute(int i=0) const; // return ith attribute
234  XMLCSTR getAttributeName(int i=0) const; // return ith attribute name
235  XMLCSTR getAttributeValue(int i=0) const; // return ith attribute value
236  char isAttributeSet(XMLCSTR name) const; // test if an attribute with a specific name is given
237  XMLCSTR getAttribute(XMLCSTR name, int i) const; // return ith attribute content with specific name
238  // (return a NULL if failing)
239  XMLCSTR getAttribute(XMLCSTR name, int *i=NULL) const; // return next attribute content with specific name
240  // (return a NULL if failing)
241  int nAttribute() const; // nbr of attribute
242  XMLClear getClear(int i=0) const; // return ith clear field (comments)
243  int nClear() const; // nbr of clear field
244  XMLSTR createXMLString(int nFormat=1, int *pnSize=NULL) const; // create XML string starting from current XMLNode
245  // if nFormat==0, no formatting is required
246  // otherwise this returns an user friendly XML string from a
247  // given element with appropriate white spaces and carriage returns.
248  // if pnSize is given it returns the size in character of the string.
249  XMLError writeToFile(XMLCSTR filename, const char *encoding=NULL, char nFormat=1) const;
250  // Save the content of an xmlNode inside a file.
251  // The nFormat parameter has the same meaning as in the
252  // createXMLString function. If the global parameter
253  // "characterEncoding==encoding_UTF8", then the "encoding" parameter is
254  // ignored and always set to "utf-8". If the global parameter
255  // "characterEncoding==encoding_ShiftJIS", then the "encoding" parameter
256  // is ignored and always set to "SHIFT-JIS". If "_XMLWIDECHAR=1", then
257  // the "encoding" parameter is ignored and always set to "utf-16".
258  // If no "encoding" parameter is given the "ISO-8859-1" encoding is used.
259  XMLNodeContents enumContents(int i) const; // enumerate all the different contents (attribute,child,text,
260  // clear) of the current XMLNode. The order is reflecting
261  // the order of the original file/string.
262  // NOTE: 0 <= i < nElement();
263  int nElement() const; // nbr of different contents for current node
264  char isEmpty() const; // is this node Empty?
265  char isDeclaration() const; // is this node a declaration <? .... ?>
266  static XMLNode emptyNode(); // return XMLNode::emptyXMLNode;
267 
268  #pragma warning(disable: 4800) // warning: forcing value to bool
269  bool operator !(){ return isEmpty(); }
270 
271 // to allow shallow/fast copy:
272  ~XMLNode();
273  XMLNode(const XMLNode &A);
274  XMLNode& operator=( const XMLNode& A );
275 
276  XMLNode(): d(NULL){};
277  static XMLNode emptyXMLNode;
278  static XMLClear emptyXMLClear;
279  static XMLAttribute emptyXMLAttribute;
280 
281  // The following functions allows you to create from scratch (or update) a XMLNode structure
282  // Start by creating your top node with the "createXMLTopNode" function and then add new nodes with the "addChild" function.
283  // The parameter 'pos' gives the position where the childNode, the text or the XMLClearTag will be inserted.
284  // The default value (pos=-1) inserts at the end. The value (pos=0) insert at the beginning (Insertion at the beginning is slower than at the end).
285  // REMARK: 0 <= pos < nChild()+nText()+nClear()
286  XMLNode addChild(XMLCSTR lpszName, char isDeclaration=FALSE, int pos=-1);
287  XMLAttribute *addAttribute(XMLCSTR lpszName, XMLCSTR lpszValuev);
288  XMLCSTR addText(XMLCSTR lpszValue, int pos=-1);
289  XMLClear *addClear(XMLCSTR lpszValue, XMLCSTR lpszOpen=NULL, XMLCSTR lpszClose=NULL, int pos=-1);
290  // default values: lpszOpen ="<![CDATA["
291  // lpszClose="]]>"
292  XMLNode addChild(XMLNode nodeToAdd, int pos=-1); // If the "nodeToAdd" has some parents, it will be detached
293  // from it's parents before being attached to the current XMLNode
294  // Some update functions:
295  XMLCSTR updateName(XMLCSTR lpszName); // change node's name
296  XMLAttribute *updateAttribute(XMLAttribute *newAttribute, XMLAttribute *oldAttribute); // if the attribute to update is missing, a new one will be added
297  XMLAttribute *updateAttribute(XMLCSTR lpszNewValue, XMLCSTR lpszNewName=NULL,int i=0); // if the attribute to update is missing, a new one will be added
298  XMLAttribute *updateAttribute(XMLCSTR lpszNewValue, XMLCSTR lpszNewName,XMLCSTR lpszOldName); // set lpszNewName=NULL if you don't want to change the name of the attribute
299  // if the attribute to update is missing, a new one will be added
300  XMLCSTR updateText(XMLCSTR lpszNewValue, int i=0); // if the text to update is missing, a new one will be added
301  XMLCSTR updateText(XMLCSTR lpszNewValue, XMLCSTR lpszOldValue); // if the text to update is missing, a new one will be added
302  XMLClear *updateClear(XMLCSTR lpszNewContent, int i=0); // if the clearTag to update is missing, a new one will be added
303  XMLClear *updateClear(XMLClear *newP,XMLClear *oldP); // if the clearTag to update is missing, a new one will be added
304  XMLClear *updateClear(XMLCSTR lpszNewValue, XMLCSTR lpszOldValue); // if the clearTag to update is missing, a new one will be added
305 
306  // Some deletion functions:
307  void deleteNodeContent(); // delete the content of this XMLNode and the subtree.
308  void deleteAttribute(XMLCSTR lpszName);
309  void deleteAttribute(int i=0);
310  void deleteAttribute(XMLAttribute *anAttribute);
311  void deleteText(int i=0);
312  void deleteText(XMLCSTR lpszValue);
313  void deleteClear(int i=0);
314  void deleteClear(XMLClear *p);
315  void deleteClear(XMLCSTR lpszValue);
316 
317  // The strings given as parameters for the following add and update methods (all these methods have
318  // a name with the postfix "_WOSD" that means "WithOut String Duplication" ) will be free'd by the
319  // XMLNode class. For example, it means that this is incorrect:
320  // xNode.addText_WOSD("foo");
321  // xNode.updateAttribute_WOSD("#newcolor" ,NULL,"color");
322  // In opposition, this is correct:
323  // xNode.addText("foo");
324  // xNode.addText_WOSD(stringDup("foo"));
325  // xNode.updateAttribute("#newcolor" ,NULL,"color");
326  // xNode.updateAttribute_WOSD(stringDup("#newcolor"),NULL,"color");
327  // Typically, you will never do:
328  // char *b=(char*)malloc(...);
329  // xNode.addText(b);
330  // free(b);
331  // ... but rather:
332  // char *b=(char*)malloc(...);
333  // xNode.addText_WOSD(b);
334  // ('free(b)' is performed by the XMLNode class)
335 
336  static XMLNode createXMLTopNode_WOSD(XMLSTR lpszName, char isDeclaration=FALSE);
337  XMLNode addChild_WOSD(XMLSTR lpszName, char isDeclaration=FALSE, int pos=-1);
338  XMLAttribute *addAttribute_WOSD(XMLSTR lpszName, XMLSTR lpszValue);
339  XMLCSTR addText_WOSD(XMLSTR lpszValue, int pos=-1);
340  XMLClear *addClear_WOSD(XMLSTR lpszValue, XMLCSTR lpszOpen=NULL, XMLCSTR lpszClose=NULL, int pos=-1);
341 
342  XMLCSTR updateName_WOSD(XMLSTR lpszName);
343  XMLAttribute *updateAttribute_WOSD(XMLAttribute *newAttribute, XMLAttribute *oldAttribute);
344  XMLAttribute *updateAttribute_WOSD(XMLSTR lpszNewValue, XMLSTR lpszNewName=NULL,int i=0);
345  XMLAttribute *updateAttribute_WOSD(XMLSTR lpszNewValue, XMLSTR lpszNewName,XMLCSTR lpszOldName);
346  XMLCSTR updateText_WOSD(XMLSTR lpszNewValue, int i=0);
347  XMLCSTR updateText_WOSD(XMLSTR lpszNewValue, XMLCSTR lpszOldValue);
348  XMLClear *updateClear_WOSD(XMLSTR lpszNewContent, int i=0);
349  XMLClear *updateClear_WOSD(XMLClear *newP,XMLClear *oldP);
350  XMLClear *updateClear_WOSD(XMLSTR lpszNewValue, XMLCSTR lpszOldValue);
351 
352  // These are some useful functions when you want to insert a childNode, a text or a XMLClearTag in the
353  // middle (at a specified position) of a XMLNode tree already constructed. The value returned by these
354  // methods is to be used as last parameter (parameter 'pos') of addChild, addText or addClear.
355  int positionOfText(int i=0) const;
356  int positionOfText(XMLCSTR lpszValue) const;
357  int positionOfClear(int i=0) const;
358  int positionOfClear(XMLCSTR lpszValue) const;
359  int positionOfClear(XMLClear *a) const;
360  int positionOfChildNode(int i=0) const;
361  int positionOfChildNode(XMLNode x) const;
362  int positionOfChildNode(XMLCSTR name, int i=0) const; // return the position of the ith childNode with the specified name
363  // if (name==NULL) return the position of the ith childNode
364 
365  // The setGlobalOptions function allows you to change tree global parameters that affect string&file
366  // parsing. First of all, you most-probably will never have to change these 3 global parameters.
367  // The return value of the setGlobalOptions function is "0" when there are no errors. If you try to
368  // set an unrecognized encoding then the return value will be "1" to signal an error.
369  //
370  // About the "guessWideCharChars" parameter:
371  // If "guessWideCharChars=1" and if this library is compiled in WideChar mode, then the
372  // "parseFile" and "openFileHelper" functions will test if the file contains ASCII
373  // characters. If this is the case, then the file will be loaded and converted in memory to
374  // WideChar before being parsed. If "guessWideCharChars=0", no conversion will
375  // be performed.
376  //
377  // If "guessWideCharChars=1" and if this library is compiled in ASCII/UTF8/char* mode, then the
378  // "parseFile" and "openFileHelper" functions will test if the file contains WideChar
379  // characters. If this is the case, then the file will be loaded and converted in memory to
380  // ASCII/UTF8/char* before being parsed. If "guessWideCharChars=0", no conversion will
381  // be performed
382  //
383  // Sometime, it's useful to set "guessWideCharChars=0" to disable any conversion
384  // because the test to detect the file-type (ASCII/UTF8/char* or WideChar) may fail (rarely).
385  //
386  // About the "characterEncoding" parameter:
387  // This parameter is only meaningful when compiling in char* mode (multibyte character mode).
388  // In wchar_t* (wide char mode), this parameter is ignored. This parameter should be one of the
389  // three currently recognized encodings: XMLNode::encoding_UTF8, XMLNode::encoding_ascii,
390  // XMLNode::encoding_ShiftJIS.
391  //
392  // About the "dropWhiteSpace" parameter:
393  // In most situations, text fields containing only white spaces (and carriage returns)
394  // are useless. Even more, these "empty" text fields are annoying because they increase the
395  // complexity of the user's code for parsing. So, 99% of the time, it's better to drop
396  // the "empty" text fields. However The XML specification indicates that no white spaces
397  // should be lost when parsing the file. So to be perfectly XML-compliant, you should set
398  // dropWhiteSpace=0. A note of caution: if you set "dropWhiteSpace=0", the parser will be
399  // slower and your code will be more complex.
400 
401  // Enumeration for XML character encoding.
402  typedef enum XMLCharEncoding { encoding_UTF8=1, encoding_ascii=2, encoding_ShiftJIS=3 } XMLCharEncoding;
403 
404  static char setGlobalOptions(XMLCharEncoding characterEncoding=XMLNode::encoding_UTF8, char guessWideCharChars=1, char dropWhiteSpace=1);
405 
406  // The next function try to guess the character encoding. You most-probably will never
407  // have to use this function. It then returns the appropriate value of the global parameter
408  // "characterEncoding" described above. The guess is based on the content of a buffer of length
409  // "bufLen" bytes that contains the first bytes (minimum 25 bytes; 200 bytes is a good value) of the
410  // file to be parsed. The "openFileHelper" function is using this function to automatically compute
411  // the value of the "characterEncoding" global parameter. There are several heuristics used to do the
412  // guess. One of the heuristic is based on the "encoding" attribute. The original XML specifications
413  // forbids to use this attribute to do the guess but you can still use it if you set
414  // "useXMLEncodingAttribute" to 1 (this is the default behavior and the behavior of most parsers).
415  // If an inconsistency in the encoding is detected, then the return value is "0".
416 
417  static XMLCharEncoding guessCharEncoding(void *buffer, int bufLen, char useXMLEncodingAttribute=1);
418 
419  private:
420 
421 // these are functions and structures used internally by the XMLNode class (don't bother about them):
422 
423  typedef struct XMLNodeDataTag // to allow shallow copy and "intelligent/smart" pointers (automatic delete):
424  {
425  XMLCSTR lpszName; // Element name (=NULL if root)
426  int nChild, // Number of child nodes
427  nText, // Number of text fields
428  nClear, // Number of Clear fields (comments)
429  nAttribute; // Number of attributes
430  char isDeclaration; // Whether node is an XML declaration - '<?xml ?>'
431  struct XMLNodeDataTag *pParent; // Pointer to parent element (=NULL if root)
432  XMLNode *pChild; // Array of child nodes
433  XMLCSTR *pText; // Array of text fields
434  XMLClear *pClear; // Array of clear fields
435  XMLAttribute *pAttribute; // Array of attributes
436  int *pOrder; // order of the child_nodes,text_fields,clear_fields
437  int ref_count; // for garbage collection (smart pointers)
438  } XMLNodeData;
439  XMLNodeData *d;
440 
441  char parseClearTag(void *px, void *pa);
442  char maybeAddTxT(void *pa, XMLCSTR tokenPStr);
443  int ParseXMLElement(void *pXML);
444  void *addToOrder(int memInc, int *_pos, int nc, void *p, int size, XMLElementType xtype);
445  int indexText(XMLCSTR lpszValue) const;
446  int indexClear(XMLCSTR lpszValue) const;
447  XMLNode addChild_priv(int,XMLSTR,char,int);
448  XMLAttribute *addAttribute_priv(int,XMLSTR,XMLSTR);
449  XMLCSTR addText_priv(int,XMLSTR,int);
450  XMLClear *addClear_priv(int,XMLSTR,XMLCSTR,XMLCSTR,int);
451  void deleteNodeContent_priv(char,char);
452  static inline int findPosition(XMLNodeData *d, int index, XMLElementType xtype);
453  static int CreateXMLStringR(XMLNodeData *pEntry, XMLSTR lpszMarker, int nFormat);
454  static int removeOrderElement(XMLNodeData *d, XMLElementType t, int index);
455  static void exactMemory(XMLNodeData *d);
456  static int detachFromParent(XMLNodeData *d);
457 } XMLNode;
458 
459 // This structure is given by the function "enumContents".
460 typedef struct XMLNodeContents
461 {
462  // This dictates what's the content of the XMLNodeContent
463  enum XMLElementType type;
464  // should be an union to access the appropriate data.
465  // compiler does not allow union of object with constructor... too bad.
466  XMLNode child;
467  XMLAttribute attrib;
468  XMLCSTR text;
469  XMLClear clear;
470 
472 
473 XMLDLLENTRY void freeXMLString(XMLSTR t); // {free(t);}
474 
475 // Duplicate (copy in a new allocated buffer) the source string. This is
476 // a very handy function when used with all the "XMLNode::*_WOSD" functions.
477 // (If (cbData!=0) then cbData is the number of chars to duplicate)
478 XMLDLLENTRY XMLSTR stringDup(XMLCSTR source, int cbData=0);
479 
480 // The following class is processing strings so that all the characters
481 // &,",',<,> are replaced by their XML equivalent: &amp;, &quot;, &apos;, &lt;, &gt;.
482 // This class is useful when creating from scratch an XML file using the
483 // "printf", "fprintf", "cout",... functions. If you are creating from scratch an
484 // XML file using the provided XMLNode class you must not use the "ToXMLStringTool"
485 // class (the "XMLNode" class does the processing job for you during rendering).
486 // Using the "ToXMLStringTool class" and the "fprintf function" is THE most efficient
487 // way to produce VERY large XML documents VERY fast.
488 typedef struct XMLDLLENTRY ToXMLStringTool
489 {
490 public:
491  ToXMLStringTool(): buf(NULL),buflen(0){}
492  ~ToXMLStringTool();
493  void freeBuffer();
494 
495  XMLSTR toXML(XMLCSTR source);
496 
497  // The next function is deprecated because there is a possibility of
498  // "destination-buffer-overflow". It converts the string
499  // "source" to the string "dest".
500  static XMLSTR toXMLUnSafe(XMLSTR dest,XMLCSTR source);
501 
502 private:
503  XMLSTR buf;
504  int buflen;
506 
507 // Below is a class that allows you to include any binary data (images, sounds,...)
508 // into an XML document using "Base64 encoding". This class is completely
509 // separated from the rest of the xmlParser library and can be removed without any problem.
510 // To include some binary data into an XML file, you must convert the binary data into
511 // standard text (using "encode"). To retrieve the original binary data from the
512 // b64-encoded text included inside the XML file use "decode". Alternatively, these
513 // functions can also be used to "encrypt/decrypt" some critical data contained inside
514 // the XML (it's not a strong encryption at all, but sometimes it can be useful).
515 
516 typedef struct XMLDLLENTRY XMLParserBase64Tool
517 {
518 public:
519  XMLParserBase64Tool(): buf(NULL),buflen(0){}
521  void freeBuffer();
522 
523  // returns the length of the base64 string that encodes a data buffer of size inBufLen bytes.
524  // If "formatted" parameter is true, some space will be reserved for a carriage-return every 72 chars.
525  static int encodeLength(int inBufLen, char formatted=0);
526 
527  // The "base64Encode" function returns a string containing the base64 encoding of "inByteLen" bytes
528  // from "inByteBuf". If "formatted" parameter is true, then there will be a carriage-return every 72 chars.
529  // The string will be free'd when the XMLParserBase64Tool object is deleted.
530  // All returned strings are sharing the same memory space.
531  XMLSTR encode(unsigned char *inByteBuf, unsigned int inByteLen, char formatted=0);
532 
533  // returns the number of bytes which will be decoded from "inString".
534  static unsigned int decodeSize(XMLCSTR inString, XMLError *xe=NULL);
535 
536  // returns a pointer to a buffer containing the binary data decoded from "inString"
537  // If "inString" is malformed NULL will be returned
538  // The output buffer will be free'd when the XMLParserBase64Tool object is deleted.
539  // All output buffer are sharing the same memory space.
540  unsigned char* decode(XMLCSTR inString, int *outByteLen=NULL, XMLError *xe=NULL);
541 
542  // The next function is deprecated.
543  // decodes data from "inString" to "outByteBuf". You need to provide the size (in byte) of "outByteBuf"
544  // in "inMaxByteOutBuflen". If "outByteBuf" is not large enough or if data is malformed, then "FALSE"
545  // will be returned; otherwise "TRUE".
546  static unsigned char decode(XMLCSTR inString, unsigned char *outByteBuf, int inMaxByteOutBuflen, XMLError *xe=NULL);
547 
548 private:
549  void *buf;
550  int buflen;
551  void alloc(int newsize);
553 }
554 #undef XMLDLLENTRY
555 
556 #endif
core::XMLAttribute
Definition: xml_parser.h:165
core::ToXMLStringTool
Definition: xml_parser.h:489
core::XMLParserBase64Tool
Definition: xml_parser.h:517
core::XMLResults
Definition: xml_parser.h:154
core::XMLNodeContents
Definition: xml_parser.h:461
core::XMLNode
Definition: xml_parser.h:172
core::XMLClear
Definition: xml_parser.h:160