PTLib
Version 2.10.4
|
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 * $Revision: 24177 $ 00028 * $Author: rjongbloed $ 00029 * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $ 00030 */ 00031 00032 #ifndef PTLIB_XMPP_ROSTER_H 00033 #define PTLIB_XMPP_ROSTER_H 00034 00035 #ifdef P_USE_PRAGMA 00036 #pragma interface 00037 #endif 00038 00039 #include <ptclib/xmpp_c2s.h> 00040 00041 #if P_EXPAT 00042 00044 00045 namespace XMPP 00046 { 00047 class Roster : public PObject 00048 { 00049 PCLASSINFO(Roster, PObject); 00050 public: 00051 00052 enum ItemType { // Subscription type 00053 None, 00054 To, 00055 From, 00056 Both, 00057 Unknown = 999 00058 }; 00059 00060 class Item : public PObject 00061 { 00062 PCLASSINFO(Item, PObject); 00063 PDICTIONARY(PresenceInfo, PString, Presence); 00064 00065 public: 00066 Item(PXMLElement * item = 0); 00067 Item(PXMLElement& item); 00068 Item(const JID& jid, ItemType type, const PString& group, const PString& name = PString::Empty()); 00069 00070 const JID& GetJID() const { return m_JID; } 00071 ItemType GetType() const { return m_Type; } 00072 const PString& GetName() const { return m_Name; } 00073 const PStringSet& GetGroups() const { return m_Groups; } 00074 const PresenceInfo& GetPresence() const { return m_Presence; } 00075 00076 virtual void SetJID(const JID& jid, PBoolean dirty = true) 00077 { m_JID = jid; if (dirty) SetDirty(); } 00078 virtual void SetType(ItemType type, PBoolean dirty = true) 00079 { m_Type = type; if (dirty) SetDirty(); } 00080 virtual void SetName(const PString& name, PBoolean dirty = true) 00081 { m_Name = name; if (dirty) SetDirty(); } 00082 00083 virtual void AddGroup(const PString& group, PBoolean dirty = true); 00084 virtual void RemoveGroup(const PString& group, PBoolean dirty = true); 00085 00086 virtual void SetPresence(const Presence& p); 00087 00088 void SetDirty(PBoolean b = true) { m_IsDirty = b; } 00089 00092 Item & operator=( 00093 const PXMLElement& item 00094 ); 00095 00096 virtual PXMLElement * AsXML(PXMLElement * parent) const; 00097 00098 protected: 00099 BareJID m_JID; 00100 ItemType m_Type; 00101 PString m_Name; 00102 PStringSet m_Groups; 00103 00104 // The item's presence state: for each resource (the key to the dictionary) a 00105 // a presence stanza if kept. 00106 PDictionary<PString, Presence> m_Presence; 00107 00108 PBoolean m_IsDirty; // item modified locally, server needs to be updated 00109 }; 00110 PLIST(ItemList, Item); 00111 00112 public: 00113 Roster(XMPP::C2S::StreamHandler * handler = 0); 00114 ~Roster(); 00115 00116 const ItemList& GetItems() const { return m_Items; } 00117 00118 virtual Item * FindItem(const PString& jid); 00119 00120 virtual PBoolean SetItem(Item * item, PBoolean localOnly = false); 00121 virtual PBoolean RemoveItem(const PString& jid, PBoolean localOnly = false); 00122 virtual PBoolean RemoveItem(Item * item, PBoolean localOnly = false); 00123 00124 virtual void Attach(XMPP::C2S::StreamHandler * handler); 00125 virtual void Detach(); 00126 virtual void Refresh(PBoolean sendPresence = true); 00127 00128 virtual PNotifierList& ItemChangedHandlers() { return m_ItemChangedHandlers; } 00129 virtual PNotifierList& RosterChangedHandlers() { return m_RosterChangedHandlers; } 00130 00131 protected: 00132 PDECLARE_NOTIFIER(XMPP::C2S::StreamHandler, Roster, OnSessionEstablished); 00133 PDECLARE_NOTIFIER(XMPP::C2S::StreamHandler, Roster, OnSessionReleased); 00134 PDECLARE_NOTIFIER(XMPP::Presence, Roster, OnPresence); 00135 PDECLARE_NOTIFIER(XMPP::IQ, Roster, OnIQ); 00136 00137 ItemList m_Items; 00138 XMPP::C2S::StreamHandler * m_Handler; 00139 PNotifierList m_ItemChangedHandlers; 00140 PNotifierList m_RosterChangedHandlers; 00141 }; 00142 00143 } // namespace XMPP 00144 00145 00146 #endif // P_EXPAT 00147 00148 #endif // PTLIB_XMPP_ROSTER_H 00149 00150 // End of File ///////////////////////////////////////////////////////////////