GNU CommonC++
xml.h
Go to the documentation of this file.
1 // Copyright (C) 2001-2005 Open Source Telecom Corporation.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // Common C++. If you copy code from other releases into a copy of GNU
28 // Common C++, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU Common C++, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37 
43 #ifndef CCXX_XML_H_
44 #define CCXX_XML_H_
45 
46 #ifndef CCXX_MISSING_H_
47 #include <cc++/missing.h>
48 #endif
49 
50 #ifndef CCXX_THREAD_H_
51 #include <cc++/thread.h>
52 #endif
53 
54 #ifndef CCXX_SLOG_H_
55 #include <cc++/slog.h>
56 #endif
57 
58 #ifdef CCXX_NAMESPACES
59 namespace ost {
60 #endif
61 
73 {
74 private:
75  int ecount, dcount;
76  enum { TAG, CDATA, COMMENT, DTD, AMP, NONE} state;
77  char dbuf[8192];
78  unsigned dp;
79  bool parseChunk(const char *chunk, size_t len);
80  void parseInit(void);
81  bool parseTag(void);
82  void putData(char c);
83  void clrData(void);
84 
85 protected:
86  virtual ~XMLStream();
87 
88 public:
98  virtual bool open(const char *resource);
99 
104  virtual void close(void);
105 
111  virtual Slog::Level getLogging(void);
112 
120  virtual void comment(const unsigned char *text, size_t len);
121 
129  virtual int read(unsigned char *buffer, size_t len) = 0;
130 
138  virtual void characters(const unsigned char *text, size_t len) = 0;
139 
143  virtual void startDocument(void);
144 
148  virtual void endDocument(void);
149 
156  virtual void startElement(const unsigned char *name, const unsigned char **attr) = 0;
157 
163  virtual void endElement(const unsigned char *name) = 0;
164 
171  bool parse(const char *resource = NULL);
172 };
173 
183 class __EXPORT XMLRPC : public XMLStream
184 {
185 private:
186 #ifdef HAVE_SSTREAM
187  std::stringstream strBuf;
188 #else
189  char *buffer;
190  std::strstream *oldStrBuf;
191  size_t bufSize;
192 #endif
193  bool structFlag;
194  bool reply, fault;
195  unsigned array;
196 
197 protected:
207  virtual bool post(const char *resource, const char *msg) = 0;
208 
212  void begStruct(void);
213 
214 public:
222  XMLRPC(size_t bufferSize = 512);
223 
227  virtual ~XMLRPC();
228 
232  void begArray(void);
233 
237  void endArray(void);
238 
244  void invoke(const char *method);
245 
251  void response(bool fault);
252 
258  void addParam(bool value);
259 
266  void addMember(const char *name, bool value);
267 
273  void addParam(long value);
274 
281  void addMember(const char *name, long value);
282 
288  void addParam(const char *string);
289 
296  void addMember(const char *name, const char *value);
297 
301  void endStruct(void);
302 
309  bool send(const char *resource);
310 };
311 
312 //#else
313 //#error "XML support has been selected, but libxml could not be found"
314 //#endif // ifdef HAVE_XML
315 
316 //#else
317 //#error "XML support is not available."
318 //#endif // ifdef COMMON_XML_PARSING
319 
320 #ifdef CCXX_NAMESPACES
321 }
322 #endif
323 
324 #endif
325