PTLib  Version 2.18.8
 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 
28 #ifndef PTLIB_XMPP_ROSTER_H
29 #define PTLIB_XMPP_ROSTER_H
30 
31 #ifdef P_USE_PRAGMA
32 #pragma interface
33 #endif
34 
35 #include <ptclib/xmpp_c2s.h>
36 
37 #if P_EXPAT
38 
40 
41 namespace XMPP
42 {
43  class Roster : public PObject
44  {
45  PCLASSINFO(Roster, PObject);
46  public:
47 
48  enum ItemType { // Subscription type
50  To,
53  Unknown = 999
54  };
55 
56  class Item : public PObject
57  {
58  PCLASSINFO(Item, PObject);
59  PDICTIONARY(PresenceInfo, PString, Presence);
60 
61  public:
62  Item(PXMLElement * item = 0);
63  Item(PXMLElement& item);
64  Item(const JID& jid, ItemType type, const PString& group, const PString& name = PString::Empty());
65 
66  const JID& GetJID() const { return m_JID; }
67  ItemType GetType() const { return m_Type; }
68  const PString& GetName() const { return m_Name; }
69  const PStringSet& GetGroups() const { return m_Groups; }
70  const PresenceInfo& GetPresence() const { return m_Presence; }
71 
72  virtual void SetJID(const JID& jid, PBoolean dirty = true)
73  { m_JID = jid; if (dirty) SetDirty(); }
74  virtual void SetType(ItemType type, PBoolean dirty = true)
75  { m_Type = type; if (dirty) SetDirty(); }
76  virtual void SetName(const PString& name, PBoolean dirty = true)
77  { m_Name = name; if (dirty) SetDirty(); }
78 
79  virtual void AddGroup(const PString& group, PBoolean dirty = true);
80  virtual void RemoveGroup(const PString& group, PBoolean dirty = true);
81 
82  virtual void SetPresence(const Presence& p);
83 
84  void SetDirty(PBoolean b = true) { m_IsDirty = b; }
85 
88  Item & operator=(
89  const PXMLElement& item
90  );
91 
92  virtual PXMLElement * AsXML(PXMLElement * parent) const;
93 
94  protected:
99 
100  // The item's presence state: for each resource (the key to the dictionary) a
101  // a presence stanza if kept.
103 
104  bool m_IsDirty; // item modified locally, server needs to be updated
105  };
106  PLIST(ItemList, Item);
107 
108  public:
109  Roster(XMPP::C2S::StreamHandler * handler = 0);
110  ~Roster();
111 
112  const ItemList& GetItems() const { return m_Items; }
113 
114  virtual Item * FindItem(const PString& jid);
115 
116  virtual PBoolean SetItem(Item * item, PBoolean localOnly = false);
117  virtual PBoolean RemoveItem(const PString& jid, PBoolean localOnly = false);
118  virtual PBoolean RemoveItem(Item * item, PBoolean localOnly = false);
119 
120  virtual void Attach(XMPP::C2S::StreamHandler * handler);
121  virtual void Detach();
122  virtual void Refresh(PBoolean sendPresence = true);
123 
126 
127  protected:
128  PDECLARE_NOTIFIER(XMPP::C2S::StreamHandler, Roster, OnSessionEstablished);
132 
137  };
138 
139 } // namespace XMPP
140 
141 
142 #endif // P_EXPAT
143 
144 #endif // PTLIB_XMPP_ROSTER_H
145 
146 // End of File ///////////////////////////////////////////////////////////////
ItemType m_Type
Definition: xmpp_roster.h:96
Definition: xmpp_roster.h:51
ItemList m_Items
Definition: xmpp_roster.h:133
virtual void Attach(XMPP::C2S::StreamHandler *handler)
Definition: xmpp_roster.h:52
virtual PXMLElement * AsXML(PXMLElement *parent) const
const PString & GetName() const
Definition: xmpp_roster.h:68
This template class maps the PAbstractDictionary to a specific key and data types.
Definition: dict.h:978
virtual void Detach()
PNotifierList m_RosterChangedHandlers
Definition: xmpp_roster.h:136
ItemList(PXMLElement *list)
Definition: xmpp.h:373
Definition: xmpp_roster.h:53
PDictionary< PString, Presence > m_Presence
Definition: xmpp_roster.h:102
Definition: xmpp_roster.h:50
PDECLARE_NOTIFIER(XMPP::C2S::StreamHandler, Roster, OnSessionEstablished)
PNotifierList m_ItemChangedHandlers
Definition: xmpp_roster.h:135
Item & operator=(const PXMLElement &item)
This operator will set the dirty flag.
bool m_IsDirty
Definition: xmpp_roster.h:104
virtual PNotifierList & ItemChangedHandlers()
Definition: xmpp_roster.h:124
Definition: xmpp_roster.h:49
const PStringSet & GetGroups() const
Definition: xmpp_roster.h:69
virtual void SetType(ItemType type, PBoolean dirty=true)
Definition: xmpp_roster.h:74
Definition: xmpp_roster.h:56
Definition: xmpp.h:55
PString m_Name
Definition: xmpp_roster.h:97
virtual Item * FindItem(const PString &jid)
PLIST(ItemList, Item)
Roster(XMPP::C2S::StreamHandler *handler=0)
bool PBoolean
Definition: object.h:174
const JID & GetJID() const
Definition: xmpp_roster.h:66
virtual void AddGroup(const PString &group, PBoolean dirty=true)
The character string class.
Definition: pstring.h:108
Definition: xmpp.h:101
This is a set collection class of PString objects.
Definition: pstring.h:2821
const PresenceInfo & GetPresence() const
Definition: xmpp_roster.h:70
Definition: xmpp.h:307
virtual void Refresh(PBoolean sendPresence=true)
const ItemList & GetItems() const
Definition: xmpp_roster.h:112
Definition: pxml.h:398
Definition: xmpp_roster.h:43
virtual void SetName(const PString &name, PBoolean dirty=true)
Definition: xmpp_roster.h:76
virtual void SetJID(const JID &jid, PBoolean dirty=true)
Definition: xmpp_roster.h:72
This class handles the client side of a C2S (Client to Server) XMPP stream.
Definition: xmpp_c2s.h:77
virtual void RemoveGroup(const PString &group, PBoolean dirty=true)
virtual PBoolean SetItem(Item *item, PBoolean localOnly=false)
static const PString & Empty()
Return an empty string.
virtual PBoolean RemoveItem(const PString &jid, PBoolean localOnly=false)
ItemType
Definition: xmpp_roster.h:48
virtual PNotifierList & RosterChangedHandlers()
Definition: xmpp_roster.h:125
Item(PXMLElement *item=0)
XMPP::C2S::StreamHandler * m_Handler
Definition: xmpp_roster.h:134
PStringSet m_Groups
Definition: xmpp_roster.h:98
ItemType GetType() const
Definition: xmpp_roster.h:67
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
void SetDirty(PBoolean b=true)
Definition: xmpp_roster.h:84
virtual void SetPresence(const Presence &p)
BareJID m_JID
Definition: xmpp_roster.h:95