Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
xml.h
Go to the documentation of this file.
1 // Copyright (C) 2001-2005 Open Source Telecom Corporation.
2 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 // As a special exception, you may use this file as part of a free software
19 // library without restriction. Specifically, if other files instantiate
20 // templates or use macros or inline functions from this file, or you compile
21 // this file and link it with other files to produce an executable, this
22 // file does not by itself cause the resulting executable to be covered by
23 // the GNU General Public License. This exception does not however
24 // invalidate any other reasons why the executable file might be covered by
25 // the GNU General Public License.
26 //
27 // This exception applies only to the code released under the name GNU
28 // Common C++. If you copy code from other releases into a copy of GNU
29 // Common C++, as the General Public License permits, the exception does
30 // not apply to the code that you add in this way. To avoid misleading
31 // anyone as to the status of such modified files, you must delete
32 // this exception notice from them.
33 //
34 // If you write modifications of your own for GNU Common C++, it is your choice
35 // whether to permit this exception to apply to your modifications.
36 // If you do not wish that, delete this exception notice.
37 //
38 
44 #ifndef CCXX_XML_H_
45 #define CCXX_XML_H_
46 
47 #ifndef CCXX_MISSING_H_
48 #include <cc++/missing.h>
49 #endif
50 
51 #ifndef CCXX_THREAD_H_
52 #include <cc++/thread.h>
53 #endif
54 
55 #ifndef CCXX_SLOG_H_
56 #include <cc++/slog.h>
57 #endif
58 
59 #ifdef CCXX_NAMESPACES
60 namespace ost {
61 #endif
62 
74 {
75 private:
76  int ecount, dcount;
77  enum { TAG, CDATA, COMMENT, DTD, AMP, NONE} state;
78  char dbuf[8192];
79  unsigned dp;
80  bool parseChunk(const char *chunk, size_t len);
81  void parseInit(void);
82  bool parseTag(void);
83  void putData(char c);
84  void clrData(void);
85 
86 protected:
87  virtual ~XMLStream();
88 
89 public:
99  virtual bool open(const char *resource);
100 
105  virtual void close(void);
106 
112  virtual Slog::Level getLogging(void);
113 
121  virtual void comment(const unsigned char *text, size_t len);
122 
130  virtual int read(unsigned char *buffer, size_t len) = 0;
131 
139  virtual void characters(const unsigned char *text, size_t len) = 0;
140 
144  virtual void startDocument(void);
145 
149  virtual void endDocument(void);
150 
157  virtual void startElement(const unsigned char *name, const unsigned char **attr) = 0;
158 
164  virtual void endElement(const unsigned char *name) = 0;
165 
172  bool parse(const char *resource = NULL);
173 };
174 
184 class __EXPORT XMLRPC : public XMLStream
185 {
186 private:
187 #ifdef HAVE_SSTREAM
188  std::stringstream strBuf;
189 #else
190  char *buffer;
191  std::strstream *oldStrBuf;
192  size_t bufSize;
193 #endif
195  bool reply, fault;
196  unsigned array;
197 
198 protected:
208  virtual bool post(const char *resource, const char *msg) = 0;
209 
213  void begStruct(void);
214 
215 public:
223  XMLRPC(size_t bufferSize = 512);
224 
228  virtual ~XMLRPC();
229 
233  void begArray(void);
234 
238  void endArray(void);
239 
245  void invoke(const char *method);
246 
252  void response(bool fault);
253 
259  void addParam(bool value);
260 
267  void addMember(const char *name, bool value);
268 
274  void addParam(long value);
275 
282  void addMember(const char *name, long value);
283 
289  void addParam(const char *string);
290 
297  void addMember(const char *name, const char *value);
298 
302  void endStruct(void);
303 
310  bool send(const char *resource);
311 };
312 
313 //#else
314 //#error "XML support has been selected, but libxml could not be found"
315 //#endif // ifdef HAVE_XML
316 
317 //#else
318 //#error "XML support is not available."
319 //#endif // ifdef COMMON_XML_PARSING
320 
321 #ifdef CCXX_NAMESPACES
322 }
323 #endif
324 
325 #endif
326 
This class impliments a basic XML stream parser that can be used to examine an XML resource thru virt...
Definition: xml.h:73
bool structFlag
Definition: xml.h:194
size_t bufSize
Definition: xml.h:192
substitute functions which may be missing in target platform libc.
char * buffer
Definition: xml.h:190
Synchronization and threading services.
unsigned dp
Definition: xml.h:79
Level
Definition: slog.h:123
std::strstream * oldStrBuf
Definition: xml.h:191
This class impliments a core XMLRPC service without the underlying transports.
Definition: xml.h:184
#define __EXPORT
Definition: audio2.h:51
int ecount
Definition: xml.h:76
bool reply
Definition: xml.h:195
System logging facilities abstraction.
unsigned array
Definition: xml.h:196