Audacity  2.2.2
XMLTagHandler.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  XMLTagHandler.h
6 
7  Dominic Mazzoni
8  Vaughan Johnson
9 
10  The XMLTagHandler class is an interface which should be implemented by
11  classes which wish to be able to load and save themselves
12  using XML files.
13 
14  The XMLValueChecker class implements static bool methods for checking
15  input values from XML files.
16 
17 **********************************************************************/
18 #ifndef __AUDACITY_XML_TAG_HANDLER__
19 #define __AUDACITY_XML_TAG_HANDLER__
20 
21 #include "../Audacity.h"
22 #include <wx/string.h>
23 #include <stdio.h>
24 
25 #include "XMLWriter.h"
27 {
28 public:
29  // "Good" means well-formed and for the file-related functions, names an existing file or folder.
30  // These are used in HandleXMLTag and BuildFomXML methods to check the input for
31  // security vulnerabilites, per the NGS report for UmixIt.
32  static bool IsGoodString(const wxString & str);
33 
34  static bool IsGoodFileName(const wxString & strFileName, const wxString & strDirName = wxEmptyString);
35  static bool IsGoodFileString(const wxString &str);
36  static bool IsGoodSubdirName(const wxString & strSubdirName, const wxString & strDirName = wxEmptyString);
37  static bool IsGoodPathName(const wxString & strPathName);
38  static bool IsGoodPathString(const wxString &str);
39 
49  static bool IsGoodInt(const wxString & strInt);
59  static bool IsGoodInt64(const wxString & strInt);
60  static bool IsGoodIntForRange(const wxString & strInt, const wxString & strMAXABS);
61 
62  static bool IsValidChannel(const int nValue);
63 #ifdef USE_MIDI
64  static bool IsValidVisibleChannels(const int nValue);
65 #endif
66  static bool IsValidSampleFormat(const int nValue); // true if nValue is one sampleFormat enum values
67 };
68 
69 
70 class AUDACITY_DLL_API XMLTagHandler /* not final */ {
71  public:
73  virtual ~XMLTagHandler(){};
74  //
75  // Methods to override
76  //
77 
78  // This method will be called on your class if your class has
79  // been registered to handle this particular tag. Parse the
80  // tag and the attribute-value pairs (null-terminated), and
81  // return true on success, and false on failure. If you return
82  // false, you will not get any calls about children.
83  virtual bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) = 0;
84 
85  // This method will be called when a closing tag is encountered.
86  // It is optional to override this method.
87  virtual void HandleXMLEndTag(const wxChar * WXUNUSED(tag)) {}
88 
89  // This method will be called when element content has been
90  // encountered.
91  // It is optional to override this method.
92  virtual void HandleXMLContent(const wxString & WXUNUSED(content)) {}
93 
94  // If the XML document has children of your tag, this method
95  // should be called. Typically you should construct a NEW
96  // object for the child, insert it into your own local data
97  // structures, and then return it. If you do not wish to
98  // handle this child, return NULL and it will be ignored.
99  virtual XMLTagHandler *HandleXMLChild(const wxChar *tag) = 0;
100 
101  // These functions recieve data from expat. They do charset
102  // conversion and then pass the data to the handlers above.
103  bool ReadXMLTag(const char *tag, const char **attrs);
104  void ReadXMLEndTag(const char *tag);
105  void ReadXMLContent(const char *s, int len);
106  XMLTagHandler *ReadXMLChild(const char *tag);
107 };
108 
109 #endif // define __AUDACITY_XML_TAG_HANDLER__
110 
virtual ~XMLTagHandler()
Definition: XMLTagHandler.h:73
static bool IsValidChannel(const int nValue)
static bool IsGoodInt64(const wxString &strInt)
Check that the supplied string can be converted to a 64bit integer.
static bool IsGoodPathName(const wxString &strPathName)
static bool IsGoodPathString(const wxString &str)
static bool IsGoodInt(const wxString &strInt)
Check that the supplied string can be converted to a long (32bit) integer.
XMLValueChecker implements static bool methods for checking input values from XML files...
Definition: XMLTagHandler.h:26
static bool IsGoodString(const wxString &str)
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:70
static bool IsGoodSubdirName(const wxString &strSubdirName, const wxString &strDirName=wxEmptyString)
static bool IsValidSampleFormat(const int nValue)
static bool IsGoodFileString(const wxString &str)
static bool IsGoodFileName(const wxString &strFileName, const wxString &strDirName=wxEmptyString)
static bool IsGoodIntForRange(const wxString &strInt, const wxString &strMAXABS)
virtual void HandleXMLEndTag(const wxChar *WXUNUSED(tag))
Definition: XMLTagHandler.h:87
virtual void HandleXMLContent(const wxString &WXUNUSED(content))
Definition: XMLTagHandler.h:92