gloox 1.0

privatexml.h

00001 /*
00002   Copyright (c) 2004-2009 by Jakob Schroeter <js@camaya.net>
00003   This file is part of the gloox library. http://camaya.net/gloox
00004 
00005   This software is distributed under a license. The full license
00006   agreement can be found in the file LICENSE in this distribution.
00007   This software may not be copied, modified, sold or distributed
00008   other than expressed in the named license agreement.
00009 
00010   This software is distributed without any warranty.
00011 */
00012 
00013 
00014 
00015 #ifndef PRIVATEXML_H__
00016 #define PRIVATEXML_H__
00017 
00018 #include "iqhandler.h"
00019 #include "privatexmlhandler.h"
00020 
00021 #include <string>
00022 #include <list>
00023 #include <map>
00024 
00025 namespace gloox
00026 {
00027 
00028   class ClientBase;
00029   class Tag;
00030   class Stanza;
00031 
00037   class GLOOX_API PrivateXML : public IqHandler
00038   {
00039     public:
00046       PrivateXML( ClientBase* parent );
00047 
00051       virtual ~PrivateXML();
00052 
00060       std::string requestXML( const std::string& tag, const std::string& xmlns, PrivateXMLHandler* pxh );
00061 
00069       std::string storeXML( const Tag* tag, PrivateXMLHandler* pxh );
00070 
00071       // reimplemented from IqHandler.
00072       virtual bool handleIq( const IQ& iq ) { (void)iq; return false; }
00073 
00074       // reimplemented from IqHandler.
00075       virtual void handleIqID( const IQ& iq, int context );
00076 
00077     protected:
00078       ClientBase* m_parent;
00079 
00080     private:
00081 #ifdef PRIVATEXML_TEST
00082     public:
00083 #endif
00084 
00090       class Query : public StanzaExtension
00091       {
00092         public:
00098           Query( const std::string& tag, const std::string& xmlns )
00099             : StanzaExtension( ExtPrivateXML )
00100           {
00101             m_privateXML = new Tag( tag, XMLNS, xmlns );
00102           }
00103 
00109           Query( const Tag* tag = 0 );
00110 
00114           ~Query() { delete m_privateXML; }
00115 
00120           const Tag* privateXML() const { return m_privateXML; }
00121 
00122           // reimplemented from StanzaExtension
00123           virtual const std::string& filterString() const;
00124 
00125           // reimplemented from StanzaExtension
00126           virtual StanzaExtension* newInstance( const Tag* tag ) const
00127           {
00128             return new Query( tag );
00129           }
00130 
00131           // reimplemented from StanzaExtension
00132           virtual Tag* tag() const;
00133 
00134           // reimplemented from StanzaExtension
00135           virtual StanzaExtension* clone() const
00136           {
00137             Query* q = new Query();
00138             q->m_privateXML = m_privateXML ? m_privateXML->clone() : 0;
00139             return q;
00140           }
00141 
00142         private:
00143           const Tag* m_privateXML;
00144 
00145       };
00146 
00147       enum IdType
00148       {
00149         RequestXml,
00150         StoreXml
00151       };
00152 
00153       typedef std::map<std::string, PrivateXMLHandler*> TrackMap;
00154 
00155       TrackMap m_track;
00156   };
00157 
00158 }
00159 
00160 #endif // PRIVATEXML_H__