xmpp_roster.h

Go to the documentation of this file.
00001 /*
00002  * xmpp_roster.h
00003  *
00004  * Extensible Messaging and Presence Protocol (XMPP) IM
00005  * Roster management classes
00006  *
00007  * Portable Windows Library
00008  *
00009  * Copyright (c) 2004 Reitek S.p.A.
00010  *
00011  * The contents of this file are subject to the Mozilla Public License
00012  * Version 1.0 (the "License"); you may not use this file except in
00013  * compliance with the License. You may obtain a copy of the License at
00014  * http://www.mozilla.org/MPL/
00015  *
00016  * Software distributed under the License is distributed on an "AS IS"
00017  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00018  * the License for the specific language governing rights and limitations
00019  * under the License.
00020  *
00021  * The Original Code is Portable Windows Library.
00022  *
00023  * The Initial Developer of the Original Code is Post Increment
00024  *
00025  * Contributor(s): ______________________________________.
00026  *
00027  * $Log: xmpp_roster.h,v $
00028  * Revision 1.2  2004/05/09 07:23:46  rjongbloed
00029  * More work on XMPP, thanks Federico Pinna and Reitek S.p.A.
00030  *
00031  * Revision 1.1  2004/04/26 01:51:57  rjongbloed
00032  * More implementation of XMPP, thanks a lot to Federico Pinna & Reitek S.p.A.
00033  *
00034  *
00035  */
00036 
00037 #ifndef _XMPP_ROSTER
00038 #define _XMPP_ROSTER
00039 
00040 #ifdef P_USE_PRAGMA
00041 #pragma interface
00042 #endif
00043 
00044 #include <ptclib/xmpp_c2s.h>
00045 
00046 #if P_EXPAT
00047 
00049 
00050 namespace XMPP
00051 {
00052   class Roster : public PObject
00053   {
00054     PCLASSINFO(Roster, PObject);
00055   public:
00056 
00057     enum ItemType { // Subscription type
00058       None,
00059       To,
00060       From,
00061       Both,
00062       Unknown = 999
00063     };
00064 
00065     class Item : public PObject
00066     {
00067       PCLASSINFO(Item, PObject);
00068       PDICTIONARY(PresenceInfo, PString, Presence);
00069 
00070     public:
00071       Item(PXMLElement * item = 0);
00072       Item(PXMLElement& item);
00073       Item(const JID& jid, ItemType type, const PString& group, const PString& name = PString::Empty());
00074 
00075       const JID&          GetJID() const        { return m_JID; }
00076       ItemType            GetType() const       { return m_Type; }
00077       const PString&      GetName() const       { return m_Name; }
00078       const PStringSet&   GetGroups() const     { return m_Groups; }
00079       const PresenceInfo& GetPresence() const   { return m_Presence; }
00080 
00081       virtual void  SetJID(const JID& jid, BOOL dirty = TRUE)
00082                                                 { m_JID = jid; if (dirty) SetDirty(); }
00083       virtual void  SetType(ItemType type, BOOL dirty = TRUE)
00084                                                 { m_Type = type; if (dirty) SetDirty(); }
00085       virtual void  SetName(const PString& name, BOOL dirty = TRUE) 
00086                                                 { m_Name = name; if (dirty) SetDirty(); }
00087 
00088       virtual void  AddGroup(const PString& group, BOOL dirty = TRUE);
00089       virtual void  RemoveGroup(const PString& group, BOOL dirty = TRUE);
00090 
00091       virtual void  SetPresence(const Presence& p);
00092 
00093       void SetDirty(BOOL b = TRUE) { m_IsDirty = b; }
00094 
00097       Item & operator=(
00098         const PXMLElement& item
00099       );
00100 
00101       virtual PXMLElement * AsXML(PXMLElement * parent) const;
00102 
00103     protected:
00104       BareJID     m_JID;
00105       ItemType    m_Type;
00106       PString     m_Name;
00107       PStringSet  m_Groups;
00108 
00109       // The item's presence state: for each resource (the key to the dictionary) a
00110       // a presence stanza if kept.
00111       PDictionary<PString, Presence> m_Presence;
00112 
00113       BOOL        m_IsDirty; // item modified locally, server needs to be updated
00114     };
00115     PLIST(ItemList, Item);
00116 
00117   public:
00118     Roster(XMPP::C2S::StreamHandler * handler = 0);
00119     ~Roster();
00120 
00121     const ItemList& GetItems() const    { return m_Items; }
00122 
00123     virtual Item * FindItem(const PString& jid);
00124 
00125     virtual BOOL SetItem(Item * item, BOOL localOnly = FALSE);
00126     virtual BOOL RemoveItem(const PString& jid, BOOL localOnly = FALSE);
00127     virtual BOOL RemoveItem(Item * item, BOOL localOnly = FALSE);
00128 
00129     virtual void  Attach(XMPP::C2S::StreamHandler * handler);
00130     virtual void  Detach();
00131     virtual void  Refresh(BOOL sendPresence = TRUE);
00132 
00133     virtual PNotifierList& ItemChangedHandlers()    { return m_ItemChangedHandlers; }
00134     virtual PNotifierList& RosterChangedHandlers()  { return m_RosterChangedHandlers; }
00135 
00136   protected:
00137     PDECLARE_NOTIFIER(XMPP::C2S::StreamHandler, Roster, OnSessionEstablished);
00138     PDECLARE_NOTIFIER(XMPP::C2S::StreamHandler, Roster, OnSessionReleased);
00139     PDECLARE_NOTIFIER(XMPP::Presence, Roster, OnPresence);
00140     PDECLARE_NOTIFIER(XMPP::IQ, Roster, OnIQ);
00141 
00142     ItemList m_Items;
00143     XMPP::C2S::StreamHandler * m_Handler;
00144     PNotifierList m_ItemChangedHandlers;
00145     PNotifierList m_RosterChangedHandlers;
00146   };
00147 
00148 } // namespace XMPP
00149 
00150 
00151 #endif  // P_EXPAT
00152 
00153 #endif  // _XMPP_ROSTER
00154 
00155 // End of File ///////////////////////////////////////////////////////////////
00156 

Generated on Fri Mar 7 06:25:03 2008 for PTLib by  doxygen 1.5.1