# sippres.h

Go to the documentation of this file.

    00001 /*
    00002  * sippres.h
    00003  *
    00004  * SIP Presence classes for Opal
    00005  *
    00006  * Open Phone Abstraction Library (OPAL)
    00007  *
    00008  * Copyright (c) 2009 Post Increment
    00009  *
    00010  * The contents of this file are subject to the Mozilla Public License
    00011  * Version 1.0 (the "License"); you may not use this file except in
    00012  * compliance with the License. You may obtain a copy of the License at
    00013  * http://www.mozilla.org/MPL/
    00014  *
    00015  * Software distributed under the License is distributed on an "AS IS"
    00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
    00017  * the License for the specific language governing rights and limitations
    00018  * under the License.
    00019  *
    00020  * The Original Code is Open Phone Abstraction Library.
    00021  *
    00022  * The Initial Developer of the Original Code is Post Increment
    00023  *
    00024  * Contributor(s): ______________________________________.
    00025  *
    00026  * $Revision: 29727 $
    00027  * $Author: rjongbloed $
    00028  * $Date: 2013-05-15 21:11:54 -0500 (Wed, 15 May 2013) $
    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
    00037
    00038 #if OPAL_SIP_PRESENCE
    00039
    00040 #include <opal/pres_ent.h>
    00041 #include <ptclib/pxml.h>
    00042 #include <sip/sipep.h>
    00043 #include <ptlib/notifier_ext.h>
    00044
    00045
    00046 class XCAPClient : public PHTTPClient
    00047 {
    00048   public:
    00049     struct ElementSelector {
    00050       ElementSelector(
    00051         const PString & name = PString::Empty(),
    00052         const PString & position = PString::Empty()
    00053       ) : m_name(name)
    00054         , m_position(position)
    00055       { PAssert(!m_name.IsEmpty(), PInvalidParameter); }
    00056
    00057       ElementSelector(
    00058         const PString & name,
    00059         const PString & attribute,
    00060         const PString & value
    00061       ) : m_name(name)
    00062         , m_attribute(attribute)
    00063         , m_value(value)
    00064       { PAssert(!m_name.IsEmpty(), PInvalidParameter); }
    00065
    00066       ElementSelector(
    00067         const PString & name,
    00068         const PString & position,
    00069         const PString & attribute,
    00070         const PString & value
    00071       ) : m_name(name)
    00072         , m_position(position)
    00073         , m_attribute(attribute)
    00074         , m_value(value)
    00075       { PAssert(!m_name.IsEmpty(), PInvalidParameter); }
    00076
    00077       PString AsString() const;
    00078
    00079       PString m_name;
    00080       PString m_position;
    00081       PString m_attribute;
    00082       PString m_value;
    00083     };
    00084
    00085     class NodeSelector : public std::list<ElementSelector>
    00086     {
    00087       public:
    00088         NodeSelector()
    00089           { }
    00090         NodeSelector(
    00091           const ElementSelector & selector
    00092         ) { push_back(selector); }
    00093         NodeSelector(
    00094           const ElementSelector & selector1,
    00095           const ElementSelector & selector2
    00096         ) { push_back(selector1); push_back(selector2); }
    00097         NodeSelector(
    00098           const ElementSelector & selector1,
    00099           const ElementSelector & selector2,
    00100           const ElementSelector & selector3
    00101         ) { push_back(selector1); push_back(selector2); push_back(selector3); }
    00102
    00103         void AddElement(
    00104           const PString & name,
    00105           const PString & position = PString::Empty()
    00106         ) { push_back(ElementSelector(name, position)); }
    00107
    00108         void AddElement(
    00109           const PString & name,
    00110           const PString & attribute,
    00111           const PString & value
    00112         ) { push_back(ElementSelector(name, attribute, value)); }
    00113
    00114         void AddElement(
    00115           const PString & name,
    00116           const PString & position,
    00117           const PString & attribute,
    00118           const PString & value
    00119         ) { push_back(ElementSelector(name, position, attribute, value)); }
    00120
    00121         void SetNamespace(
    00122           const PString & space,
    00123           const PString & alias = PString::Empty()
    00124         ) { PAssert(!space.IsEmpty(), PInvalidParameter); m_namespaces[alias] = space; }
    00125
    00126         void AddToURL(
    00127           PURL & url
    00128         ) const;
    00129
    00130       protected:
    00131         std::map<PString, PString> m_namespaces;
    00132     };
    00133
    00134
    00135     XCAPClient();
    00136
    00137     bool GetXml(
    00138       PXML & xml
    00139     ) { return GetXml(BuildURL(), xml); }
    00140
    00141     bool GetXml(
    00142       const PURL & url,
    00143       PXML & xml
    00144     );
    00145
    00146     bool PutXml(
    00147       const PXML & xml
    00148     ) { return PutXml(BuildURL(), xml); }
    00149
    00150     bool PutXml(
    00151       const PURL & url,
    00152       const PXML & xml
    00153     );
    00154
    00155     bool DeleteXml() { return DeleteDocument(BuildURL()); }
    00156
    00157
    00158     PURL BuildURL();
    00159
    00160
    00161     void SetRoot(
    00162       const PURL & server
    00163     ) { m_root = server; }
    00164     const PURL & GetRoot() const { return m_root; }
    00165
    00166     void SetApplicationUniqueID(
    00167       const PString & id
    00168     ) { m_auid = id; }
    00169     const PString & GetApplicationUniqueID() const { return m_auid; }
    00170
    00171     void SetGlobal() { m_global = true; }
    00172     bool IsGlobal() const { return m_global; }
    00173
    00174     void SetUserIdentifier(
    00175       const PString & id
    00176     ) { m_global = false; m_xui = id; }
    00177     const PString & GetUserIdentifier() const { return m_xui; }
    00178
    00179     void SetFilename(
    00180       const PString & fn
    00181     ) { m_filename = fn; }
    00182     const PString & GetFilename() const { return m_filename; }
    00183
    00184     void SetNode(
    00185       const NodeSelector & node
    00186     ) { m_node = node; }
    00187     const NodeSelector & GetNode() const { return m_node; }
    00188     void ClearNode() { m_node.clear(); }
    00189
    00190     void SetContentType(
    00191       const PString & type
    00192     ) { m_contentType = type; }
    00193     const PString & GetContentType() const { return m_contentType; }
    00194
    00195   protected:
    00196     PURL         m_root;
    00197     PString      m_auid;
    00198     bool         m_global;
    00199     PString      m_xui;
    00200     PString      m_filename;
    00201     NodeSelector m_node;
    00202     PString      m_contentType;
    00203 };
    00204
    00205
    00206 class SIPWatcherInfoCommand : public OpalPresentityCommand {
    00207   public:
    00208     SIPWatcherInfoCommand(bool unsubscribe = false) : m_unsubscribe(unsubscribe) { }
    00209
    00210     bool m_unsubscribe;
    00211 };
    00212
    00213
    00216 class SIP_Presentity : public OpalPresentityWithCommandThread, public PValidatedNotifierTarget
    00217 {
    00218     PCLASSINFO(SIP_Presentity, OpalPresentityWithCommandThread);
    00219
    00220   public:
    00221     SIP_Presentity();
    00222     SIP_Presentity(const SIP_Presentity & other);
    00223     ~SIP_Presentity();
    00224
    00225     virtual PObject * Clone() const { return new SIP_Presentity(*this); }
    00226
    00227     enum SubProtocol {
    00228       // Note order is important
    00229       e_PeerToPeer,
    00230       e_WithAgent,
    00231       e_XCAP,
    00232       e_OMA
    00233     };
    00234
    00235     static const PCaselessString & PIDFEntityKey();
    00236     static const PCaselessString & SubProtocolKey();
    00237     static const PCaselessString & PresenceAgentKey();
    00238     static const PCaselessString & TransportKey();
    00239     static const PCaselessString & XcapRootKey();
    00240     static const PCaselessString & XcapAuthIdKey();
    00241     static const PCaselessString & XcapPasswordKey();
    00242     static const PCaselessString & XcapAuthAuidKey();
    00243     static const PCaselessString & XcapAuthFileKey();
    00244     static const PCaselessString & XcapBuddyListKey();
    00245
    00246     virtual PStringArray GetAttributeNames() const;
    00247     virtual PStringArray GetAttributeTypes() const;
    00248
    00249     virtual bool Open();
    00250     virtual bool Close();
    00251     virtual BuddyStatus GetBuddyListEx(BuddyList & buddies);
    00252     virtual BuddyStatus SetBuddyListEx(const BuddyList & buddies);
    00253     virtual BuddyStatus DeleteBuddyListEx();
    00254     virtual BuddyStatus GetBuddyEx(BuddyInfo & buddy);
    00255     virtual BuddyStatus SetBuddyEx(const BuddyInfo & buddy);
    00256     virtual BuddyStatus DeleteBuddyEx(const PURL & presentity);
    00257     virtual BuddyStatus SubscribeBuddyListEx(PINDEX & successful, bool subscribe = true);
    00258
    00259     SIPEndPoint & GetEndpoint() { return *m_endpoint; }
    00260
    00261     void Internal_SendLocalPresence(const OpalSetLocalPresenceCommand & cmd);
    00262     void Internal_SubscribeToPresence(const OpalSubscribeToPresenceCommand & cmd);
    00263     void Internal_SubscribeToWatcherInfo(const SIPWatcherInfoCommand & cmd);
    00264     void Internal_AuthorisationRequest(const OpalAuthorisationRequestCommand & cmd);
    00265
    00266     unsigned GetExpiryTime() const;
    00267
    00268   protected:
    00269     PDECLARE_VALIDATED_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnPresenceSubscriptionStatus, const SIPSubscribe::SubscriptionStatus &);
    00270     PDECLARE_VALIDATED_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnPresenceNotify, SIPSubscribe::NotifyCallbackInfo &);
    00271     PDECLARE_VALIDATED_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnWatcherInfoSubscriptionStatus, const SIPSubscribe::SubscriptionStatus &);
    00272     PDECLARE_VALIDATED_NOTIFIER2(SIPSubscribeHandler, SIP_Presentity, OnWatcherInfoNotify, SIPSubscribe::NotifyCallbackInfo &);
    00273     void OnReceivedWatcherStatus(PXMLElement * watcher);
    00274     void SetPIDFEntity(PURL & entity);
    00275     bool ChangeAuthNode(XCAPClient & xcap, const OpalAuthorisationRequestCommand & cmd);
    00276     void InitRootXcap(XCAPClient & xcap);
    00277     void InitBuddyXcap(
    00278       XCAPClient & xcap,
    00279       const PString & entryName = PString::Empty(),
    00280       const PString & listName = PString::Empty()
    00281     );
    00282
    00283     SIPEndPoint * m_endpoint;
    00284     SubProtocol   m_subProtocol;
    00285     SIPURL        m_presenceAgentURL;
    00286     PURL          m_defaultRootURL;
    00287     PString       m_watcherSubscriptionAOR;
    00288     int           m_watcherInfoVersion;
    00289     PString       m_publishedTupleId;
    00290
    00291     typedef std::map<PString, PString> StringMap;
    00292     StringMap m_watcherAorById;
    00293     StringMap m_presenceIdByAor;
    00294     StringMap m_presenceAorById;
    00295     StringMap m_authorisationIdByAor;
    00296
    00297   private:
    00298     void operator=(const SIP_Presentity &) { }
    00299 };
    00300
    00301
    00302 #endif // OPAL_SIP_PRESENCE
    00303
    00304 #endif // OPAL_SIP_SIPPRES_H