OPAL  Version 3.10.10
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  * $Revision: 28081 $
27  * $Author: rjongbloed $
28  * $Date: 2012-07-22 07:24:14 -0500 (Sun, 22 Jul 2012) $
29  */
30 
31 #ifndef OPAL_SIP_SIPPRES_H
32 #define OPAL_SIP_SIPPRES_H
33 
34 #include <ptlib.h>
35 #include <opal/buildopts.h>
36 #include <sip/sipep.h>
37 
38 #if P_EXPAT && OPAL_SIP
39 
40 #include <opal/pres_ent.h>
41 #include <ptclib/pxml.h>
42 
43 
44 class XCAPClient : public PHTTPClient
45 {
46  public:
47  struct ElementSelector {
48  ElementSelector(
49  const PString & name = PString::Empty(),
50  const PString & position = PString::Empty()
51  ) : m_name(name)
52  , m_position(position)
53  { PAssert(!m_name.IsEmpty(), PInvalidParameter); }
54 
55  ElementSelector(
56  const PString & name,
57  const PString & attribute,
58  const PString & value
59  ) : m_name(name)
60  , m_attribute(attribute)
61  , m_value(value)
62  { PAssert(!m_name.IsEmpty(), PInvalidParameter); }
63 
64  ElementSelector(
65  const PString & name,
66  const PString & position,
67  const PString & attribute,
68  const PString & value
69  ) : m_name(name)
70  , m_position(position)
71  , m_attribute(attribute)
72  , m_value(value)
73  { PAssert(!m_name.IsEmpty(), PInvalidParameter); }
74 
75  PString AsString() const;
76 
77  PString m_name;
78  PString m_position;
79  PString m_attribute;
80  PString m_value;
81  };
82 
83  class NodeSelector : public std::list<ElementSelector>
84  {
85  public:
86  NodeSelector()
87  { }
88  NodeSelector(
89  const ElementSelector & selector
90  ) { push_back(selector); }
91  NodeSelector(
92  const ElementSelector & selector1,
93  const ElementSelector & selector2
94  ) { push_back(selector1); push_back(selector2); }
95  NodeSelector(
96  const ElementSelector & selector1,
97  const ElementSelector & selector2,
98  const ElementSelector & selector3
99  ) { push_back(selector1); push_back(selector2); push_back(selector3); }
100 
101  void AddElement(
102  const PString & name,
103  const PString & position = PString::Empty()
104  ) { push_back(ElementSelector(name, position)); }
105 
106  void AddElement(
107  const PString & name,
108  const PString & attribute,
109  const PString & value
110  ) { push_back(ElementSelector(name, attribute, value)); }
111 
112  void AddElement(
113  const PString & name,
114  const PString & position,
115  const PString & attribute,
116  const PString & value
117  ) { push_back(ElementSelector(name, position, attribute, value)); }
118 
119  void SetNamespace(
120  const PString & space,
121  const PString & alias = PString::Empty()
122  ) { PAssert(!space.IsEmpty(), PInvalidParameter); m_namespaces[alias] = space; }
123 
124  void AddToURL(
125  PURL & url
126  ) const;
127 
128  protected:
129  std::map<PString, PString> m_namespaces;
130  };
131 
132 
133  XCAPClient();
134 
135  bool GetXml(
136  PXML & xml
137  ) { return GetXml(BuildURL(), xml); }
138 
139  bool GetXml(
140  const PURL & url,
141  PXML & xml
142  );
143 
144  bool PutXml(
145  const PXML & xml
146  ) { return PutXml(BuildURL(), xml); }
147 
148  bool PutXml(
149  const PURL & url,
150  const PXML & xml
151  );
152 
153  bool DeleteXml() { return DeleteDocument(BuildURL()); }
154 
155 
156  PURL BuildURL();
157 
158 
159  void SetRoot(
160  const PURL & server
161  ) { m_root = server; }
162  const PURL & GetRoot() const { return m_root; }
163 
164  void SetApplicationUniqueID(
165  const PString & id
166  ) { m_auid = id; }
167  const PString & GetApplicationUniqueID() const { return m_auid; }
168 
169  void SetGlobal() { m_global = true; }
170  bool IsGlobal() const { return m_global; }
171 
172  void SetUserIdentifier(
173  const PString & id
174  ) { m_global = false; m_xui = id; }
175  const PString & GetUserIdentifier() const { return m_xui; }
176 
177  void SetFilename(
178  const PString & fn
179  ) { m_filename = fn; }
180  const PString & GetFilename() const { return m_filename; }
181 
182  void SetNode(
183  const NodeSelector & node
184  ) { m_node = node; }
185  const NodeSelector & GetNode() const { return m_node; }
186  void ClearNode() { m_node.clear(); }
187 
188  void SetContentType(
189  const PString & type
190  ) { m_contentType = type; }
191  const PString & GetContentType() const { return m_contentType; }
192 
193  protected:
194  PURL m_root;
195  PString m_auid;
196  bool m_global;
197  PString m_xui;
198  PString m_filename;
199  NodeSelector m_node;
200  PString m_contentType;
201 };
202 
203 
204 class SIPWatcherInfoCommand : public OpalPresentityCommand {
205  public:
206  SIPWatcherInfoCommand(bool unsubscribe = false) : m_unsubscribe(unsubscribe) { }
207 
208  bool m_unsubscribe;
209 };
210 
211 
214 class SIP_Presentity : public OpalPresentityWithCommandThread
215 {
216  PCLASSINFO(SIP_Presentity, OpalPresentityWithCommandThread);
217 
218  public:
219  SIP_Presentity();
220  SIP_Presentity(const SIP_Presentity & other);
221  ~SIP_Presentity();
222 
223  virtual PObject * Clone() const { return new SIP_Presentity(*this); }
224 
225  enum SubProtocol {
226  // Note order is important
227  e_PeerToPeer,
228  e_WithAgent,
229  e_XCAP,
230  e_OMA
231  };
232 
233  static const PCaselessString & PIDFEntityKey();
234  static const PCaselessString & SubProtocolKey();
235  static const PCaselessString & PresenceAgentKey();
236  static const PCaselessString & TransportKey();
237  static const PCaselessString & XcapRootKey();
238  static const PCaselessString & XcapAuthIdKey();
239  static const PCaselessString & XcapPasswordKey();
240  static const PCaselessString & XcapAuthAuidKey();
241  static const PCaselessString & XcapAuthFileKey();
242  static const PCaselessString & XcapBuddyListKey();
243 
244  virtual PStringArray GetAttributeNames() const;
245  virtual PStringArray GetAttributeTypes() const;
246 
247  virtual bool Open();
248  virtual bool Close();
249  virtual BuddyStatus GetBuddyListEx(BuddyList & buddies);
250  virtual BuddyStatus SetBuddyListEx(const BuddyList & buddies);
251  virtual BuddyStatus DeleteBuddyListEx();
252  virtual BuddyStatus GetBuddyEx(BuddyInfo & buddy);
253  virtual BuddyStatus SetBuddyEx(const BuddyInfo & buddy);
254  virtual BuddyStatus DeleteBuddyEx(const PURL & presentity);
255  virtual BuddyStatus SubscribeBuddyListEx(PINDEX & successful, bool subscribe = true);
256 
257  SIPEndPoint & GetEndpoint() { return *m_endpoint; }
258 
259  void Internal_SendLocalPresence(const OpalSetLocalPresenceCommand & cmd);
260  void Internal_SubscribeToPresence(const OpalSubscribeToPresenceCommand & cmd);
261  void Internal_SubscribeToWatcherInfo(const SIPWatcherInfoCommand & cmd);
262  void Internal_AuthorisationRequest(const OpalAuthorisationRequestCommand & cmd);
263 
264  unsigned GetExpiryTime() const;
265 
266  protected:
267  PDECLARE_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnPresenceSubscriptionStatus, const SIPSubscribe::SubscriptionStatus &);
268  PDECLARE_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnPresenceNotify, SIPSubscribe::NotifyCallbackInfo &);
269  PDECLARE_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnWatcherInfoSubscriptionStatus, const SIPSubscribe::SubscriptionStatus &);
270  PDECLARE_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnWatcherInfoNotify, SIPSubscribe::NotifyCallbackInfo &);
271  void OnReceivedWatcherStatus(PXMLElement * watcher);
272  void SetPIDFEntity(PURL & entity);
273  bool ChangeAuthNode(XCAPClient & xcap, const OpalAuthorisationRequestCommand & cmd);
274  void InitRootXcap(XCAPClient & xcap);
275  void InitBuddyXcap(
276  XCAPClient & xcap,
277  const PString & entryName = PString::Empty(),
278  const PString & listName = PString::Empty()
279  );
280 
281  SIPEndPoint * m_endpoint;
282  SubProtocol m_subProtocol;
283  PString m_presenceAgent;
284  PString m_watcherSubscriptionAOR;
285  int m_watcherInfoVersion;
286  PString m_publishedTupleId;
287 
288  typedef std::map<PString, PString> StringMap;
289  StringMap m_watcherAorById;
290  StringMap m_presenceIdByAor;
291  StringMap m_presenceAorById;
292  StringMap m_authorisationIdByAor;
293 
294  private:
295  void operator=(const SIP_Presentity &) { }
296 };
297 
298 
299 #endif // P_EXPAT && OPAL_SIP
300 
301 #endif // OPAL_SIP_SIPPRES_H
Definition: pres_ent.h:680
Definition: sipep.h:86
Definition: pres_ent.h:665
Definition: sippdu.h:1139
Definition: pres_ent.h:547
Definition: pres_ent.h:694
Definition: handlers.h:222
Definition: pres_ent.h:632
Definition: sippdu.h:1149