Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

xml.h

Go to the documentation of this file.
00001 // Copyright (C) 2001,2002 Open Source Telecom Corporation.
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 // 
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 // 
00017 // As a special exception to the GNU General Public License, permission is 
00018 // granted for additional uses of the text contained in its release 
00019 // of Common C++.
00020 // 
00021 // The exception is that, if you link the Common C++ library with other files
00022 // to produce an executable, this does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public License.
00024 // Your use of that executable is in no way restricted on account of
00025 // linking the Common C++ library code into it.
00026 //
00027 // This exception does not however invalidate any other reasons why
00028 // the executable file might be covered by the GNU General Public License.
00029 //
00030 // This exception applies only to the code released under the 
00031 // name Common C++.  If you copy code from other releases into a copy of
00032 // Common C++, as the General Public License permits, the exception does
00033 // not apply to the code that you add in this way.  To avoid misleading
00034 // anyone as to the status of such modified files, you must delete
00035 // this exception notice from them.
00036 // 
00037 // If you write modifications of your own for Common C++, it is your choice
00038 // whether to permit this exception to apply to your modifications.
00039 // If you do not wish that, delete this exception notice.
00040 
00046 #ifndef CCXX_XML_H_
00047 #define CCXX_XML_H_
00048 
00049 #ifndef CCXX_MISSING_H_
00050 #include <cc++/missing.h>
00051 #endif
00052 
00053 #ifndef CCXX_THREAD_H_
00054 #include <cc++/thread.h>
00055 #endif
00056 
00057 #ifndef CCXX_SLOG_H_
00058 #include <cc++/slog.h>
00059 #endif
00060 
00061 #ifdef  CCXX_NAMESPACES
00062 namespace ost {
00063 #endif
00064 
00075 class __EXPORT XMLStream
00076 {
00077 #ifndef HAVE_LIBXML
00078 private:
00079         int ecount, dcount;
00080         enum { TAG, CDATA, COMMENT, DTD, AMP, NONE} state;
00081         char dbuf[8192];
00082         unsigned dp;
00083         bool parseChunk(const char *chunk, unsigned len);
00084         void parseInit(void);
00085         bool parseTag(void);
00086         void putData(char c);
00087         void clrData(void);
00088 
00089 #endif
00090 public:
00100         virtual bool open(const char *resource)
00101                 {return true;};
00102 
00107         virtual void close(void)
00108                 {return;};
00109 
00115         virtual Slog::Level getLogging(void)
00116                 {return Slog::levelCritical;};
00117 
00125         virtual void comment(const unsigned char *text, unsigned len)
00126                 {return;};
00127 
00135         virtual int read(unsigned char *buffer, int len) = 0;
00136 
00144         virtual void characters(const unsigned char *text, unsigned len) = 0;
00145 
00149         virtual void startDocument(void)
00150                 {return;};
00151 
00155         virtual void endDocument(void)
00156                 {return;};
00157 
00164         virtual void startElement(const unsigned char *name, const unsigned char **attr) = 0;
00165 
00171         virtual void endElement(const unsigned char *name) = 0;
00172 
00179         bool parse(const char *resource = NULL);
00180 };
00181 
00191 class __EXPORT XMLRPC : public XMLStream
00192 {
00193 private:
00194 #ifdef HAVE_SSTREAM
00195         std::stringstream strBuf;
00196 #else
00197         char *buffer;
00198         std::strstream *oldStrBuf;
00199         size_t bufSize;
00200 #endif
00201         bool structFlag;
00202         bool reply, fault;
00203         unsigned array;
00204         
00205 protected:
00215         virtual bool post(const char *resource, const char *msg) = 0;
00216         
00220         void begStruct(void);
00221 
00222 public:
00230         XMLRPC(size_t bufferSize = 512);
00231         
00235         virtual ~XMLRPC();
00236 
00240         void begArray(void);
00241 
00245         void endArray(void);
00246         
00252         void invoke(const char *method);
00253 
00259         void response(bool fault);
00260         
00266         void addParam(bool value);
00267 
00274         void addMember(const char *name, bool value);
00275 
00281         void addParam(long value);
00282 
00289         void addMember(const char *name, long value);
00290 
00296         void addParam(const char *string);
00297 
00304         void addMember(const char *name, const char *value);
00305 
00309         void endStruct(void);
00310         
00317         bool send(const char *resource);
00318 };
00319 
00320 //#else
00321 //#error "XML support has been selected, but libxml could not be found"
00322 //#endif // ifdef HAVE_XML
00323 
00324 //#else
00325 //#error "XML support is not available."
00326 //#endif // ifdef COMMON_XML_PARSING
00327         
00328 #ifdef  CCXX_NAMESPACES
00329 }
00330 #endif
00331 
00332 #endif
00333 

Generated on Tue Jan 18 14:32:37 2005 for GNU CommonC++ by  doxygen 1.3.9.1