00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef OPAL_SIP_SIPPRES_H
00032 #define OPAL_SIP_SIPPRES_H
00033
00034 #include <ptlib.h>
00035 #include <opal/buildopts.h>
00036 #include <sip/sipep.h>
00037
00038 #if P_EXPAT && OPAL_SIP
00039
00040 #include <opal/pres_ent.h>
00041 #include <ptclib/pxml.h>
00042
00043
00044 class XCAPClient : public PHTTPClient
00045 {
00046 public:
00047 struct ElementSelector {
00048 ElementSelector(
00049 const PString & name = PString::Empty(),
00050 const PString & position = PString::Empty()
00051 ) : m_name(name)
00052 , m_position(position)
00053 { PAssert(!m_name.IsEmpty(), PInvalidParameter); }
00054
00055 ElementSelector(
00056 const PString & name,
00057 const PString & attribute,
00058 const PString & value
00059 ) : m_name(name)
00060 , m_attribute(attribute)
00061 , m_value(value)
00062 { PAssert(!m_name.IsEmpty(), PInvalidParameter); }
00063
00064 ElementSelector(
00065 const PString & name,
00066 const PString & position,
00067 const PString & attribute,
00068 const PString & value
00069 ) : m_name(name)
00070 , m_position(position)
00071 , m_attribute(attribute)
00072 , m_value(value)
00073 { PAssert(!m_name.IsEmpty(), PInvalidParameter); }
00074
00075 PString AsString() const;
00076
00077 PString m_name;
00078 PString m_position;
00079 PString m_attribute;
00080 PString m_value;
00081 };
00082
00083 class NodeSelector : public std::list<ElementSelector>
00084 {
00085 public:
00086 NodeSelector()
00087 { }
00088 NodeSelector(
00089 const ElementSelector & selector
00090 ) { push_back(selector); }
00091 NodeSelector(
00092 const ElementSelector & selector1,
00093 const ElementSelector & selector2
00094 ) { push_back(selector1); push_back(selector2); }
00095 NodeSelector(
00096 const ElementSelector & selector1,
00097 const ElementSelector & selector2,
00098 const ElementSelector & selector3
00099 ) { push_back(selector1); push_back(selector2); push_back(selector3); }
00100
00101 void AddElement(
00102 const PString & name,
00103 const PString & position = PString::Empty()
00104 ) { push_back(ElementSelector(name, position)); }
00105
00106 void AddElement(
00107 const PString & name,
00108 const PString & attribute,
00109 const PString & value
00110 ) { push_back(ElementSelector(name, attribute, value)); }
00111
00112 void AddElement(
00113 const PString & name,
00114 const PString & position,
00115 const PString & attribute,
00116 const PString & value
00117 ) { push_back(ElementSelector(name, position, attribute, value)); }
00118
00119 void SetNamespace(
00120 const PString & space,
00121 const PString & alias = PString::Empty()
00122 ) { PAssert(!space.IsEmpty(), PInvalidParameter); m_namespaces[alias] = space; }
00123
00124 void AddToURL(
00125 PURL & url
00126 ) const;
00127
00128 protected:
00129 std::map<PString, PString> m_namespaces;
00130 };
00131
00132
00133 XCAPClient();
00134
00135 bool GetXml(
00136 PXML & xml
00137 ) { return GetXml(BuildURL(), xml); }
00138
00139 bool GetXml(
00140 const PURL & url,
00141 PXML & xml
00142 );
00143
00144 bool PutXml(
00145 const PXML & xml
00146 ) { return PutXml(BuildURL(), xml); }
00147
00148 bool PutXml(
00149 const PURL & url,
00150 const PXML & xml
00151 );
00152
00153 bool DeleteXml() { return DeleteDocument(BuildURL()); }
00154
00155
00156 PURL BuildURL();
00157
00158
00159 void SetRoot(
00160 const PURL & server
00161 ) { m_root = server; }
00162 const PURL & GetRoot() const { return m_root; }
00163
00164 void SetApplicationUniqueID(
00165 const PString & id
00166 ) { m_auid = id; }
00167 const PString & GetApplicationUniqueID() const { return m_auid; }
00168
00169 void SetGlobal() { m_global = true; }
00170 bool IsGlobal() const { return m_global; }
00171
00172 void SetUserIdentifier(
00173 const PString & id
00174 ) { m_global = false; m_xui = id; }
00175 const PString & GetUserIdentifier() const { return m_xui; }
00176
00177 void SetFilename(
00178 const PString & fn
00179 ) { m_filename = fn; }
00180 const PString & GetFilename() const { return m_filename; }
00181
00182 void SetNode(
00183 const NodeSelector & node
00184 ) { m_node = node; }
00185 const NodeSelector & GetNode() const { return m_node; }
00186 void ClearNode() { m_node.clear(); }
00187
00188 void SetContentType(
00189 const PString & type
00190 ) { m_contentType = type; }
00191 const PString & GetContentType() const { return m_contentType; }
00192
00193 protected:
00194 PURL m_root;
00195 PString m_auid;
00196 bool m_global;
00197 PString m_xui;
00198 PString m_filename;
00199 NodeSelector m_node;
00200 PString m_contentType;
00201 };
00202
00203
00204 class SIPWatcherInfoCommand : public OpalPresentityCommand {
00205 public:
00206 SIPWatcherInfoCommand(bool unsubscribe = false) : m_unsubscribe(unsubscribe) { }
00207
00208 bool m_unsubscribe;
00209 };
00210
00211
00214 class SIP_Presentity : public OpalPresentityWithCommandThread
00215 {
00216 PCLASSINFO(SIP_Presentity, OpalPresentityWithCommandThread);
00217
00218 public:
00219 SIP_Presentity();
00220 SIP_Presentity(const SIP_Presentity & other);
00221 ~SIP_Presentity();
00222
00223 virtual PObject * Clone() const { return new SIP_Presentity(*this); }
00224
00225 enum SubProtocol {
00226
00227 e_PeerToPeer,
00228 e_WithAgent,
00229 e_XCAP,
00230 e_OMA
00231 };
00232
00233 static const PCaselessString & PIDFEntityKey();
00234 static const PCaselessString & SubProtocolKey();
00235 static const PCaselessString & PresenceAgentKey();
00236 static const PCaselessString & TransportKey();
00237 static const PCaselessString & XcapRootKey();
00238 static const PCaselessString & XcapAuthIdKey();
00239 static const PCaselessString & XcapPasswordKey();
00240 static const PCaselessString & XcapAuthAuidKey();
00241 static const PCaselessString & XcapAuthFileKey();
00242 static const PCaselessString & XcapBuddyListKey();
00243
00244 virtual PStringArray GetAttributeNames() const;
00245 virtual PStringArray GetAttributeTypes() const;
00246
00247 virtual bool Open();
00248 virtual bool Close();
00249 virtual BuddyStatus GetBuddyListEx(BuddyList & buddies);
00250 virtual BuddyStatus SetBuddyListEx(const BuddyList & buddies);
00251 virtual BuddyStatus DeleteBuddyListEx();
00252 virtual BuddyStatus GetBuddyEx(BuddyInfo & buddy);
00253 virtual BuddyStatus SetBuddyEx(const BuddyInfo & buddy);
00254 virtual BuddyStatus DeleteBuddyEx(const PURL & presentity);
00255 virtual BuddyStatus SubscribeBuddyListEx(PINDEX & successful, bool subscribe = true);
00256
00257 SIPEndPoint & GetEndpoint() { return *m_endpoint; }
00258
00259 void Internal_SendLocalPresence(const OpalSetLocalPresenceCommand & cmd);
00260 void Internal_SubscribeToPresence(const OpalSubscribeToPresenceCommand & cmd);
00261 void Internal_SubscribeToWatcherInfo(const SIPWatcherInfoCommand & cmd);
00262 void Internal_AuthorisationRequest(const OpalAuthorisationRequestCommand & cmd);
00263
00264 unsigned GetExpiryTime() const;
00265
00266 protected:
00267 PDECLARE_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnPresenceSubscriptionStatus, const SIPSubscribe::SubscriptionStatus &);
00268 PDECLARE_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnPresenceNotify, SIPSubscribe::NotifyCallbackInfo &);
00269 PDECLARE_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnWatcherInfoSubscriptionStatus, const SIPSubscribe::SubscriptionStatus &);
00270 PDECLARE_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnWatcherInfoNotify, SIPSubscribe::NotifyCallbackInfo &);
00271 void OnReceivedWatcherStatus(PXMLElement * watcher);
00272 void SetPIDFEntity(PURL & entity);
00273 bool ChangeAuthNode(XCAPClient & xcap, const OpalAuthorisationRequestCommand & cmd);
00274 void InitRootXcap(XCAPClient & xcap);
00275 void InitBuddyXcap(
00276 XCAPClient & xcap,
00277 const PString & entryName = PString::Empty(),
00278 const PString & listName = PString::Empty()
00279 );
00280
00281 SIPEndPoint * m_endpoint;
00282 SubProtocol m_subProtocol;
00283 PString m_presenceAgent;
00284 PString m_watcherSubscriptionAOR;
00285 int m_watcherInfoVersion;
00286 PString m_publishedTupleId;
00287
00288 typedef std::map<PString, PString> StringMap;
00289 StringMap m_watcherAorById;
00290 StringMap m_presenceIdByAor;
00291 StringMap m_presenceAorById;
00292 StringMap m_authorisationIdByAor;
00293
00294 private:
00295 void operator=(const SIP_Presentity &) { }
00296 };
00297
00298
00299 #endif // P_EXPAT && OPAL_SIP
00300
00301 #endif // OPAL_SIP_SIPPRES_H