Debian Codegraph @

src/xml/davxmlparser.hpp

raw
1 /*
2 * This File is part of Davix, The IO library for HTTP based protocols
3 * Copyright (C) CERN 2013
4 * Author: Adrien Devresse <[email protected]>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22 #ifndef DAVIX_DAVXMLPARSER_H
23 #define DAVIX_DAVXMLPARSER_H
24
25
26 #include <utils/davix_types.hpp>
27 #include <status/davixstatusrequest.hpp>
28 #include <xml/davix_ptree.hpp>
29 #include <ne_xml.h>
30
31 #include <utils/davix_fileproperties.hpp>
32
33
34 namespace Davix {
35
36
37 class XMLSAXParser : NonCopyable
38 {
39 public:
40 typedef std::string::iterator startIterChunk;
41 typedef std::string::iterator endIterChunk;
42 typedef std::pair<startIterChunk, endIterChunk> Chunk;
43
44
45 XMLSAXParser();
46 virtual ~XMLSAXParser();
47
48 //
49 // parse a block of character with a maximum size of 'len' characters
50 // return negative value if failure or 0 if success
51 int parseChunk(const char * partial_string, dav_size_t len);
52
53 inline int parseChunk(const std::string & partial_string){
54 return parseChunk(partial_string.c_str(), partial_string.size());
55 }
56
57 protected:
58
59 ///
60 /// callback to reimplement in subclass for parsing
61 /// codes :
62 /// retcode < 0 -> error
63 /// retcode == 0 -> skip this element
64 /// retcode > 0 -> accept this element
65
66 /// start element callback
67 virtual int parserStartElemCb(int parent,
68 const char *nspace, const char *name,
69 const char **atts);
70
71
72
73 /// cdata element callback
74 virtual int parserCdataCb(int state,
75 const char *cdata, size_t len);
76
77
78
79 /// end element callback
80 virtual int parserEndElemCb(int state,
81 const char *nspace, const char *name);
82
83 /// start element callback
84 virtual int startElemCb(const Chunk & data,
85 const std::vector<Chunk> & attrs);
86
87 virtual int cdataCb(const Chunk & data);
88
89 virtual int endElemCb(const Chunk & data);
90
91 virtual int commentCb(const Chunk & data);
92
93 private:
94 ne_xml_parser* _ne_parser;
95 friend struct InternalDavParser;
96 };
97
98
99
100 class ElementsParser {
101 public:
102 ElementsParser(){}
103 virtual ~ElementsParser(){}
104
105 virtual std::deque<FileProperties> & getProperties()=0;
106 virtual std::string getNextMarker() { return ""; };
107
108 };
109
110
111 class XMLPropParser: public XMLSAXParser, public ElementsParser{
112 public:
113 XMLPropParser(){}
114 virtual ~XMLPropParser(){}
115
116 };
117
118
119
120 } // namespace Davix
121
122 #endif // DAVIX_DAVXMLPARSER_H