GNU CommonC++
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
60namespace ost {
61#endif
62
74{
75private:
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
86protected:
87 virtual ~XMLStream();
88
89public:
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
185{
186private:
187#ifdef HAVE_SSTREAM
188 std::stringstream strBuf;
189#else
190 char *buffer;
191 std::strstream *oldStrBuf;
192 size_t bufSize;
193#endif
194 bool structFlag;
195 bool reply, fault;
196 unsigned array;
197
198protected:
208 virtual bool post(const char *resource, const char *msg) = 0;
209
213 void begStruct(void);
214
215public:
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
Level
Definition slog.h:123
This class impliments a core XMLRPC service without the underlying transports.
Definition xml.h:185
void addParam(long value)
Add an integer paramater to XMLRPC request.
void addMember(const char *name, bool value)
Add bool member to a XMLRPC struct.
bool send(const char *resource)
Complete buffer and send well formed XMLRPC request thru post.
void addParam(bool value)
Add bool param to XMLRPC request.
void begArray(void)
Create an array.
XMLRPC(size_t bufferSize=512)
Construct XMLRPC workspace.
virtual bool post(const char *resource, const char *msg)=0
Used in a derived transport class to deliver the XMLRPC encoded request and return true if successful...
void endStruct(void)
Clear a struct.
virtual ~XMLRPC()
Destroy XMLRPC object.
void invoke(const char *method)
Create XMLRPC "method" call in buffer.
void addParam(const char *string)
Add a string paramater to XMLRPC request.
void endArray(void)
end an array.
void addMember(const char *name, const char *value)
Add a string member to XMLRPC struct.
void begStruct(void)
Start member struct.
void response(bool fault)
Create XMLRPC "reply" to a method call.
void addMember(const char *name, long value)
Add an integer member to XMLRPC struct.
This class impliments a basic XML stream parser that can be used to examine an XML resource thru virt...
Definition xml.h:74
virtual Slog::Level getLogging(void)
Get error logging level.
virtual bool open(const char *resource)
May perform an open operation on behalf of a parsed resource.
virtual void startDocument(void)
Identify start of document event.
virtual void close(void)
May perform a close operation of an i/o source when the parser has completed operation.
virtual int read(unsigned char *buffer, size_t len)=0
Read method to aquire data for the parser.
virtual ~XMLStream()
virtual void endElement(const unsigned char *name)=0
Identify end of an element in the document.
bool parse(const char *resource=NULL)
Parse a resource as a stream thru the virtual read method.
virtual void startElement(const unsigned char *name, const unsigned char **attr)=0
Identify start of an element in the document.
virtual void endDocument(void)
Identify end of document event.
virtual void comment(const unsigned char *text, size_t len)
Virtual to receive embedded comments in an XML document being parsed.
virtual void characters(const unsigned char *text, size_t len)=0
Virtual to receive character text extracted from the document in the current element.
#define __EXPORT
Definition config.h:1045
substitute functions which may be missing in target platform libc.
Definition address.h:64
System logging facilities abstraction.
Synchronization and threading services.