GNU CommonC++
|
00001 // Copyright (C) 2001-2005 Open Source Telecom Corporation. 00002 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks. 00003 // 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 // 00018 // As a special exception, you may use this file as part of a free software 00019 // library without restriction. Specifically, if other files instantiate 00020 // templates or use macros or inline functions from this file, or you compile 00021 // this file and link it with other files to produce an executable, this 00022 // file does not by itself cause the resulting executable to be covered by 00023 // the GNU General Public License. This exception does not however 00024 // invalidate any other reasons why the executable file might be covered by 00025 // the GNU General Public License. 00026 // 00027 // This exception applies only to the code released under the name GNU 00028 // Common C++. If you copy code from other releases into a copy of GNU 00029 // Common C++, as the General Public License permits, the exception does 00030 // not apply to the code that you add in this way. To avoid misleading 00031 // anyone as to the status of such modified files, you must delete 00032 // this exception notice from them. 00033 // 00034 // If you write modifications of your own for GNU Common C++, it is your choice 00035 // whether to permit this exception to apply to your modifications. 00036 // If you do not wish that, delete this exception notice. 00037 // 00038 00044 #ifndef CCXX_XML_H_ 00045 #define CCXX_XML_H_ 00046 00047 #ifndef CCXX_MISSING_H_ 00048 #include <cc++/missing.h> 00049 #endif 00050 00051 #ifndef CCXX_THREAD_H_ 00052 #include <cc++/thread.h> 00053 #endif 00054 00055 #ifndef CCXX_SLOG_H_ 00056 #include <cc++/slog.h> 00057 #endif 00058 00059 #ifdef CCXX_NAMESPACES 00060 namespace ost { 00061 #endif 00062 00073 class __EXPORT XMLStream 00074 { 00075 private: 00076 int ecount, dcount; 00077 enum { TAG, CDATA, COMMENT, DTD, AMP, NONE} state; 00078 char dbuf[8192]; 00079 unsigned dp; 00080 bool parseChunk(const char *chunk, size_t len); 00081 void parseInit(void); 00082 bool parseTag(void); 00083 void putData(char c); 00084 void clrData(void); 00085 00086 protected: 00087 virtual ~XMLStream(); 00088 00089 public: 00099 virtual bool open(const char *resource); 00100 00105 virtual void close(void); 00106 00112 virtual Slog::Level getLogging(void); 00113 00121 virtual void comment(const unsigned char *text, size_t len); 00122 00130 virtual int read(unsigned char *buffer, size_t len) = 0; 00131 00139 virtual void characters(const unsigned char *text, size_t len) = 0; 00140 00144 virtual void startDocument(void); 00145 00149 virtual void endDocument(void); 00150 00157 virtual void startElement(const unsigned char *name, const unsigned char **attr) = 0; 00158 00164 virtual void endElement(const unsigned char *name) = 0; 00165 00172 bool parse(const char *resource = NULL); 00173 }; 00174 00184 class __EXPORT XMLRPC : public XMLStream 00185 { 00186 private: 00187 #ifdef HAVE_SSTREAM 00188 std::stringstream strBuf; 00189 #else 00190 char *buffer; 00191 std::strstream *oldStrBuf; 00192 size_t bufSize; 00193 #endif 00194 bool structFlag; 00195 bool reply, fault; 00196 unsigned array; 00197 00198 protected: 00208 virtual bool post(const char *resource, const char *msg) = 0; 00209 00213 void begStruct(void); 00214 00215 public: 00223 XMLRPC(size_t bufferSize = 512); 00224 00228 virtual ~XMLRPC(); 00229 00233 void begArray(void); 00234 00238 void endArray(void); 00239 00245 void invoke(const char *method); 00246 00252 void response(bool fault); 00253 00259 void addParam(bool value); 00260 00267 void addMember(const char *name, bool value); 00268 00274 void addParam(long value); 00275 00282 void addMember(const char *name, long value); 00283 00289 void addParam(const char *string); 00290 00297 void addMember(const char *name, const char *value); 00298 00302 void endStruct(void); 00303 00310 bool send(const char *resource); 00311 }; 00312 00313 //#else 00314 //#error "XML support has been selected, but libxml could not be found" 00315 //#endif // ifdef HAVE_XML 00316 00317 //#else 00318 //#error "XML support is not available." 00319 //#endif // ifdef COMMON_XML_PARSING 00320 00321 #ifdef CCXX_NAMESPACES 00322 } 00323 #endif 00324 00325 #endif 00326