OPAL  Version 3.18.8
sippres.h
Go to the documentation of this file.
1 /*
2  * sippres.h
3  *
4  * SIP Presence classes for Opal
5  *
6  * Open Phone Abstraction Library (OPAL)
7  *
8  * Copyright (c) 2009 Post Increment
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Open Phone Abstraction Library.
21  *
22  * The Initial Developer of the Original Code is Post Increment
23  *
24  * Contributor(s): ______________________________________.
25  */
26 
27 #ifndef OPAL_SIP_SIPPRES_H
28 #define OPAL_SIP_SIPPRES_H
29 
30 #include <ptlib.h>
31 #include <opal_config.h>
32 
33 
34 #if OPAL_SIP_PRESENCE
35 
36 #include <opal/pres_ent.h>
37 #include <ptclib/pxml.h>
38 #include <sip/sipep.h>
39 #include <ptlib/notifier_ext.h>
40 
41 
42 class XCAPClient : public PHTTPClient
43 {
44  public:
45  struct ElementSelector {
46  ElementSelector(
47  const PString & name = PString::Empty(),
48  const PString & position = PString::Empty()
49  ) : m_name(name)
50  , m_position(position)
51  { PAssert(!m_name.IsEmpty(), PInvalidParameter); }
52 
53  ElementSelector(
54  const PString & name,
55  const PString & attribute,
56  const PString & value
57  ) : m_name(name)
58  , m_attribute(attribute)
59  , m_value(value)
60  { PAssert(!m_name.IsEmpty(), PInvalidParameter); }
61 
62  ElementSelector(
63  const PString & name,
64  const PString & position,
65  const PString & attribute,
66  const PString & value
67  ) : m_name(name)
68  , m_position(position)
69  , m_attribute(attribute)
70  , m_value(value)
71  { PAssert(!m_name.IsEmpty(), PInvalidParameter); }
72 
73  PString AsString() const;
74 
75  PString m_name;
76  PString m_position;
77  PString m_attribute;
78  PString m_value;
79  };
80 
81  class NodeSelector : public std::list<ElementSelector>
82  {
83  public:
84  NodeSelector()
85  { }
86  NodeSelector(
87  const ElementSelector & selector
88  ) { push_back(selector); }
89  NodeSelector(
90  const ElementSelector & selector1,
91  const ElementSelector & selector2
92  ) { push_back(selector1); push_back(selector2); }
93  NodeSelector(
94  const ElementSelector & selector1,
95  const ElementSelector & selector2,
96  const ElementSelector & selector3
97  ) { push_back(selector1); push_back(selector2); push_back(selector3); }
98 
99  void AddElement(
100  const PString & name,
101  const PString & position = PString::Empty()
102  ) { push_back(ElementSelector(name, position)); }
103 
104  void AddElement(
105  const PString & name,
106  const PString & attribute,
107  const PString & value
108  ) { push_back(ElementSelector(name, attribute, value)); }
109 
110  void AddElement(
111  const PString & name,
112  const PString & position,
113  const PString & attribute,
114  const PString & value
115  ) { push_back(ElementSelector(name, position, attribute, value)); }
116 
117  void SetNamespace(
118  const PString & space,
119  const PString & alias = PString::Empty()
120  ) { PAssert(!space.IsEmpty(), PInvalidParameter); m_namespaces[alias] = space; }
121 
122  void AddToURL(
123  PURL & url
124  ) const;
125 
126  protected:
127  std::map<PString, PString> m_namespaces;
128  };
129 
130 
131  XCAPClient();
132 
133  bool GetXml(
134  PXML & xml
135  ) { return GetXml(BuildURL(), xml); }
136 
137  bool GetXml(
138  const PURL & url,
139  PXML & xml
140  );
141 
142  bool PutXml(
143  const PXML & xml
144  ) { return PutXml(BuildURL(), xml); }
145 
146  bool PutXml(
147  const PURL & url,
148  const PXML & xml
149  );
150 
151  bool DeleteXml() { return DeleteDocument(BuildURL()); }
152 
153 
154  PURL BuildURL();
155 
156 
157  void SetRoot(
158  const PURL & server
159  ) { m_root = server; }
160  const PURL & GetRoot() const { return m_root; }
161 
162  void SetApplicationUniqueID(
163  const PString & id
164  ) { m_auid = id; }
165  const PString & GetApplicationUniqueID() const { return m_auid; }
166 
167  void SetGlobal() { m_global = true; }
168  bool IsGlobal() const { return m_global; }
169 
170  void SetUserIdentifier(
171  const PString & id
172  ) { m_global = false; m_xui = id; }
173  const PString & GetUserIdentifier() const { return m_xui; }
174 
175  void SetFilename(
176  const PString & fn
177  ) { m_filename = fn; }
178  const PString & GetFilename() const { return m_filename; }
179 
180  void SetNode(
181  const NodeSelector & node
182  ) { m_node = node; }
183  const NodeSelector & GetNode() const { return m_node; }
184  void ClearNode() { m_node.clear(); }
185 
186  void SetContentType(
187  const PString & type
188  ) { m_contentType = type; }
189  const PString & GetContentType() const { return m_contentType; }
190 
191  protected:
192  PURL m_root;
193  PString m_auid;
194  bool m_global;
195  PString m_xui;
196  PString m_filename;
197  NodeSelector m_node;
198  PString m_contentType;
199 };
200 
201 
202 class SIPWatcherInfoCommand : public OpalPresentityCommand {
203  public:
204  SIPWatcherInfoCommand(bool unsubscribe = false) : m_unsubscribe(unsubscribe) { }
205 
206  bool m_unsubscribe;
207 };
208 
209 
212 class SIP_Presentity : public OpalPresentityWithCommandThread, public PValidatedNotifierTarget
213 {
214  PCLASSINFO(SIP_Presentity, OpalPresentityWithCommandThread);
215 
216  public:
217  SIP_Presentity();
218  SIP_Presentity(const SIP_Presentity & other);
219  ~SIP_Presentity();
220 
221  virtual PObject * Clone() const { return new SIP_Presentity(*this); }
222 
223  enum SubProtocol {
224  // Note order is important
225  e_PeerToPeer,
226  e_WithAgent,
227  e_XCAP,
228  e_OMA
229  };
230 
231  static const PCaselessString & PIDFEntityKey();
232  static const PCaselessString & SubProtocolKey();
233  static const PCaselessString & PresenceAgentKey();
234  static const PCaselessString & TransportKey();
235  static const PCaselessString & XcapRootKey();
236  static const PCaselessString & XcapAuthIdKey();
237  static const PCaselessString & XcapPasswordKey();
238  static const PCaselessString & XcapAuthAuidKey();
239  static const PCaselessString & XcapAuthFileKey();
240  static const PCaselessString & XcapBuddyListKey();
241 
242  virtual PStringArray GetAttributeNames() const;
243  virtual PStringArray GetAttributeTypes() const;
244 
245  virtual bool Open();
246  virtual bool Close();
247  virtual BuddyStatus GetBuddyListEx(BuddyList & buddies);
248  virtual BuddyStatus SetBuddyListEx(const BuddyList & buddies);
249  virtual BuddyStatus DeleteBuddyListEx();
250  virtual BuddyStatus GetBuddyEx(BuddyInfo & buddy);
251  virtual BuddyStatus SetBuddyEx(const BuddyInfo & buddy);
252  virtual BuddyStatus DeleteBuddyEx(const PURL & presentity);
253  virtual BuddyStatus SubscribeBuddyListEx(PINDEX & successful, bool subscribe = true);
254 
255  SIPEndPoint & GetEndpoint() { return *m_endpoint; }
256 
257  void Internal_SendLocalPresence(const OpalSetLocalPresenceCommand & cmd);
258  void Internal_SubscribeToPresence(const OpalSubscribeToPresenceCommand & cmd);
259  void Internal_SubscribeToWatcherInfo(const SIPWatcherInfoCommand & cmd);
260  void Internal_AuthorisationRequest(const OpalAuthorisationRequestCommand & cmd);
261 
262  unsigned GetExpiryTime() const;
263 
264  protected:
265  PDECLARE_VALIDATED_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnPresenceSubscriptionStatus, const SIPSubscribe::SubscriptionStatus &);
266  PDECLARE_VALIDATED_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnPresenceNotify, SIPSubscribe::NotifyCallbackInfo &);
267  PDECLARE_VALIDATED_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnWatcherInfoSubscriptionStatus, const SIPSubscribe::SubscriptionStatus &);
268  PDECLARE_VALIDATED_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnWatcherInfoNotify, SIPSubscribe::NotifyCallbackInfo &);
269  void OnReceivedWatcherStatus(PXMLElement * watcher);
270  void SetPIDFEntity(PURL & entity);
271  bool ChangeAuthNode(XCAPClient & xcap, const OpalAuthorisationRequestCommand & cmd);
272  void InitRootXcap(XCAPClient & xcap);
273  void InitBuddyXcap(
274  XCAPClient & xcap,
275  const PString & entryName = PString::Empty(),
276  const PString & listName = PString::Empty()
277  );
278 
279  SIPEndPoint * m_endpoint;
280  SubProtocol m_subProtocol;
281  SIPURL m_presenceAgentURL;
282  PURL m_defaultRootURL;
283  PString m_watcherSubscriptionAOR;
284  int m_watcherInfoVersion;
285  PString m_publishedTupleId;
286 
287  typedef std::map<PString, PString> StringMap;
288  StringMap m_watcherAorById;
289  StringMap m_presenceIdByAor;
290  StringMap m_presenceAorById;
291  StringMap m_authorisationIdByAor;
292 
293  private:
294  void operator=(const SIP_Presentity &) { }
295 };
296 
297 
298 #endif // OPAL_SIP_PRESENCE
299 
300 #endif // OPAL_SIP_SIPPRES_H
Definition: sippdu.h:71
Definition: sipep.h:52
Definition: sippdu.h:1349
Definition: handlers.h:205
Definition: sippdu.h:1360