Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

session.hh

00001 // session.hh
00002 // Jabber client library
00003 //
00004 // Original Code Copyright (C) 1999-2001 Dave Smith (dave@jabber.org)
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License, or (at your option) any later version.
00010 // 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 // Contributor(s): Julian Missig
00021 //
00022 // This Original Code has been modified by IBM Corporation. Modifications 
00023 // made by IBM described herein are Copyright (c) International Business 
00024 // Machines Corporation, 2002.
00025 //
00026 // Date             Modified by     Description of modification
00027 // 01/20/2002       IBM Corp.       Updated to libjudo 1.1.1
00028 // 2002-03-05       IBM Corp.       Updated to libjudo 1.1.5
00029 // 2002-07-09       IBM Corp.       Added Roster::getSession()
00030 //
00031 // =====================================================================================
00032 
00033 #ifndef SESSION_HH
00034 #define SESSION_HH
00035 
00036 #include <judo.hpp>
00037 #include <sigc++/object.h>
00038 #include <sigc++/signal.h>
00039 #include <sigc++/slot.h>
00040 // #include <jabberoofwd.h>
00041 #include <discoDB.hh>
00042 #include <roster.hh>
00043 #include <presenceDB.hh>
00044 
00045 namespace jabberoo {
00046 
00047      typedef SigC::Slot1<void, const judo::Element&> ElementCallbackFunc;
00048 
00053      class Session : 
00054         public judo::ElementStreamEventListener, 
00055         public judo::ElementStream, 
00056         public SigC::Object
00057           {
00058           public:
00062                enum AuthType
00063                { 
00064                     atPlaintextAuth, 
00065                     atDigestAuth,    
00066                     atAutoAuth,      
00067                     at0kAuth         
00068                };
00069 
00073                enum ConnectionState
00074                {
00075                     csNotConnected, 
00076                     csCreateUser,   
00077                     csAuthReq,      
00078                     csAwaitingAuth, 
00079                     csConnected     
00080                };
00081 
00082                // Initializers
00089                Session();
00094                virtual ~Session();
00095 
00096                // Helper ops
00101                Session& operator>>(const char* buffer) { push(buffer, strlen(buffer)); return *this; } 
00106                Session& operator<<(const Packet& p);
00111                Session& operator<<(const char* buffer) { evtTransmitXML(buffer); return *this;}
00112           public:
00113                // Connectivity ops
00129                void connect(const std::string& server, AuthType atype, 
00130                             const std::string& username, const std::string& resource, const std::string& password, 
00131                             bool createuser = false, bool should_auth = true);
00132 
00137                bool disconnect();
00138 
00143                ConnectionState getConnState() { return _ConnState; }
00144 
00145                // Misc ops
00152                virtual void push(const char* data, int datasz);
00159                void registerIQ(const std::string& id, ElementCallbackFunc f);
00160 
00169            judo::XPath::Query* registerXPath(const std::string& query,
00170                ElementCallbackFunc f, bool incoming=true);
00171 
00177         void unregisterXPath(judo::XPath::Query* id, bool incoming=true);
00178 
00186                void queryNamespace(const std::string& nspace, ElementCallbackFunc f, const std::string& to = "");
00187 
00188                // Structure accessors
00194                const Roster& roster() const;
00200                Roster&       roster();
00201 
00207            const DiscoDB&    discoDB() const;
00208 
00214            DiscoDB&    discoDB();
00215 
00221                const PresenceDB& presenceDB() const;
00227                PresenceDB&       presenceDB();
00228 
00229                // Property accessors
00234                AuthType      getAuthType() const;
00239                const std::string& getUserName() const;
00240 
00241                // ID/Auth ops
00247                std::string getNextID();
00252                std::string getDigest();
00253 
00254           public:
00255                // XML transmission signals
00265            SigC::Signal2<void, int, const std::string&, SigC::Marshal<void> > evtXMLParserError;
00271            SigC::Signal1<void, const char*, SigC::Marshal<void> >        evtTransmitXML;
00276            SigC::Signal1<void, const char*, SigC::Marshal<void> >        evtRecvXML;
00281            SigC::Signal1<void, const Packet&, SigC::Marshal<void> >      evtTransmitPacket;
00282                // Connectivity signals
00288            SigC::Signal1<void, const judo::Element&, SigC::Marshal<void> >         evtConnected;
00294            SigC::Signal0<void, SigC::Marshal<void> >                     evtDisconnected;
00295                // Basic signals
00301            SigC::Signal1<void, const Message&, SigC::Marshal<void> >     evtMessage;
00307            SigC::Signal1<void, const judo::Element&, SigC::Marshal<void> >         evtIQ;
00314            SigC::Signal1<void, const Presence&, SigC::Marshal<void> >    evtMyPresence;
00321            SigC::Signal2<void, const Presence&, Presence::Type, SigC::Marshal<void> >    evtPresence;
00327            SigC::Signal1<void, const Presence&, SigC::Marshal<void> >    evtPresenceRequest;
00328                // Misc signals
00334            SigC::Signal1<void, const judo::Element&, SigC::Marshal<void> >         evtUnknownPacket;
00340            SigC::Signal2<void, int, const char*, SigC::Marshal<void> >   evtAuthError;    
00349            SigC::Signal0<void, SigC::Marshal<void> > evtOnRoster;
00356            SigC::Signal3<void, std::string&, std::string&, std::string&, SigC::Marshal<void> > evtOnVersion;
00361            SigC::Signal1<void, std::string&, SigC::Marshal<void> >            evtOnLast;
00362 
00368            SigC::Signal2<void, std::string&, std::string&, SigC::Marshal<void> >            evtOnTime;
00369           protected:
00370                // Authentication handler
00371                void authenticate();
00372                void OnAuthTypeReceived(const judo::Element& t);
00373                void sendLogin(Session::AuthType atype, const judo::Element* squery);
00374 
00375                // ElementStream events
00376                virtual void onDocumentStart(judo::Element* t);
00377                virtual void onElement(judo::Element* t);
00378                virtual void onCDATA(judo::CDATA* c);
00379                virtual void onDocumentEnd();
00380 
00381                // Basic packet handlers
00382                void handleMessage(judo::Element& t);
00383                void handlePresence(judo::Element& t);
00384                void handleIQ(judo::Element& t);
00385 
00386           private:
00387                // Values
00388                std::string          _ServerID;
00389                std::string          _Username;
00390                std::string          _Password;
00391                std::string          _Resource;
00392                std::string          _SessionID;
00393                long            _ID;
00394                // Enumeration values (states)
00395                AuthType        _AuthType;
00396                ConnectionState _ConnState;
00397                // Stream header 
00398                judo::Element*            _StreamElement;
00399                // Whether or not we have received the starting stream tag
00400                bool            _StreamStart;
00401                // Whether or not we want to use jabber:iq:auth
00402                bool            _Authenticate;
00403                // Structures
00404            std::multimap<std::string, ElementCallbackFunc> _Callbacks;                   /* IQ callback funcs */
00405            typedef std::map<judo::XPath::Query*, ElementCallbackFunc> XPCBMap;
00406            typedef std::list<judo::XPath::Query*> XPQueryList;
00407            XPCBMap _incoming_XPaths;
00408            XPQueryList _incoming_queries;
00409            XPCBMap _outgoing_XPaths;
00410            XPQueryList _outgoing_queries;
00411                // Internal roster & presence db structures
00412                Roster          _Roster;
00413            DiscoDB         _DDB;
00414                PresenceDB      _PDB;
00415 
00416                // Internal IQ handlers
00417                void IQHandler_Auth(const judo::Element& t);
00418                void IQHandler_CreateUser(const judo::Element& t);
00419           };    
00420 } // namespace jabberoo
00421 
00422 #endif // SESSION_HH

Generated on Thu Jul 24 13:31:51 2003 for jabberoo by doxygen1.3-rc3