PTLib Version 2.12.9

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
xmpp_roster.h
Go to the documentation of this file.
1 /*
2 * xmpp_roster.h
3 *
4 * Extensible Messaging and Presence Protocol (XMPP) IM
5 * Roster management classes
6 *
7 * Portable Windows Library
8 *
9 * Copyright (c) 2004 Reitek S.p.A.
10 *
11 * The contents of this file are subject to the Mozilla Public License
12 * Version 1.0 (the "License"); you may not use this file except in
13 * compliance with the License. You may obtain a copy of the License at
14 * http://www.mozilla.org/MPL/
15 *
16 * Software distributed under the License is distributed on an "AS IS"
17 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18 * the License for the specific language governing rights and limitations
19 * under the License.
20 *
21 * The Original Code is Portable Windows Library.
22 *
23 * The Initial Developer of the Original Code is Post Increment
24 *
25 * Contributor(s): ______________________________________.
26 *
27 * $Revision: 24177 $
28 * $Author: rjongbloed $
29 * $Date: 2010-04-05 21:52:04 +1000 (Mon, 05 Apr 2010) $
30 */
31
32 #ifndef PTLIB_XMPP_ROSTER_H
33 #define PTLIB_XMPP_ROSTER_H
34
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38
39 #include <ptclib/xmpp_c2s.h>
40
41 #if P_EXPAT
42
44
45 namespace XMPP
46 {
47 class Roster : public PObject
48 {
49 PCLASSINFO(Roster, PObject);
50 public:
51
52 enum ItemType { // Subscription type
53 None,
54 To,
55 From,
56 Both,
57 Unknown = 999
58 };
59
60 class Item : public PObject
61 {
62 PCLASSINFO(Item, PObject);
63 PDICTIONARY(PresenceInfo, PString, Presence);
64
65 public:
66 Item(PXMLElement * item = 0);
67 Item(PXMLElement& item);
68 Item(const JID& jid, ItemType type, const PString& group, const PString& name = PString::Empty());
69
70 const JID& GetJID() const { return m_JID; }
71 ItemType GetType() const { return m_Type; }
72 const PString& GetName() const { return m_Name; }
73 const PStringSet& GetGroups() const { return m_Groups; }
74 const PresenceInfo& GetPresence() const { return m_Presence; }
75
76 virtual void SetJID(const JID& jid, PBoolean dirty = true)
77 { m_JID = jid; if (dirty) SetDirty(); }
78 virtual void SetType(ItemType type, PBoolean dirty = true)
79 { m_Type = type; if (dirty) SetDirty(); }
80 virtual void SetName(const PString& name, PBoolean dirty = true)
81 { m_Name = name; if (dirty) SetDirty(); }
82
83 virtual void AddGroup(const PString& group, PBoolean dirty = true);
84 virtual void RemoveGroup(const PString& group, PBoolean dirty = true);
85
86 virtual void SetPresence(const Presence& p);
87
88 void SetDirty(PBoolean b = true) { m_IsDirty = b; }
89
92 Item & operator=(
93 const PXMLElement& item
94 );
95
96 virtual PXMLElement * AsXML(PXMLElement * parent) const;
97
98 protected:
99 BareJID m_JID;
100 ItemType m_Type;
101 PString m_Name;
102 PStringSet m_Groups;
103
104 // The item's presence state: for each resource (the key to the dictionary) a
105 // a presence stanza if kept.
106 PDictionary<PString, Presence> m_Presence;
107
108 PBoolean m_IsDirty; // item modified locally, server needs to be updated
109 };
110 PLIST(ItemList, Item);
111
112 public:
113 Roster(XMPP::C2S::StreamHandler * handler = 0);
114 ~Roster();
115
116 const ItemList& GetItems() const { return m_Items; }
117
118 virtual Item * FindItem(const PString& jid);
119
120 virtual PBoolean SetItem(Item * item, PBoolean localOnly = false);
121 virtual PBoolean RemoveItem(const PString& jid, PBoolean localOnly = false);
122 virtual PBoolean RemoveItem(Item * item, PBoolean localOnly = false);
123
124 virtual void Attach(XMPP::C2S::StreamHandler * handler);
125 virtual void Detach();
126 virtual void Refresh(PBoolean sendPresence = true);
127
128 virtual PNotifierList& ItemChangedHandlers() { return m_ItemChangedHandlers; }
129 virtual PNotifierList& RosterChangedHandlers() { return m_RosterChangedHandlers; }
130
131 protected:
132 PDECLARE_NOTIFIER(XMPP::C2S::StreamHandler, Roster, OnSessionEstablished);
133 PDECLARE_NOTIFIER(XMPP::C2S::StreamHandler, Roster, OnSessionReleased);
134 PDECLARE_NOTIFIER(XMPP::Presence, Roster, OnPresence);
135 PDECLARE_NOTIFIER(XMPP::IQ, Roster, OnIQ);
136
137 ItemList m_Items;
138 XMPP::C2S::StreamHandler * m_Handler;
139 PNotifierList m_ItemChangedHandlers;
140 PNotifierList m_RosterChangedHandlers;
141 };
142
143 } // namespace XMPP
144
145
146 #endif // P_EXPAT
147
148 #endif // PTLIB_XMPP_ROSTER_H
149
150 // End of File ///////////////////////////////////////////////////////////////