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: 24993 $
00027  * $Author: rjongbloed $
00028  * $Date: 2011-01-04 16:38:21 -0600 (Tue, 04 Jan 2011) $
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 
00212 class SIP_Presentity : public OpalPresentityWithCommandThread
00213 {
00214     PCLASSINFO(SIP_Presentity, OpalPresentityWithCommandThread);
00215 
00216   public:
00217     static const PString & DefaultPresenceServerKey();
00218     static const PString & PresenceServerKey();
00219 
00220     ~SIP_Presentity();
00221 
00222     virtual bool Open();
00223     virtual bool IsOpen() const;
00224     virtual bool Close();
00225 
00226     SIPEndPoint & GetEndpoint() { return *m_endpoint; }
00227 
00233     static bool SetDefaultPresentity(
00234       const PString & prefix
00235     );
00236 
00237   protected:
00238     SIP_Presentity();
00239 
00240     SIPEndPoint * m_endpoint;
00241     int           m_watcherInfoVersion;
00242     PString       m_publishedTupleId;
00243 };
00244 
00245 
00246 class SIPLocal_Presentity : public SIP_Presentity
00247 {
00248     PCLASSINFO(SIPLocal_Presentity, SIP_Presentity);
00249 
00250   public:
00251     ~SIPLocal_Presentity();
00252 };
00253 
00254 
00255 class SIPXCAP_Presentity : public SIP_Presentity
00256 {
00257     PCLASSINFO(SIPXCAP_Presentity, SIP_Presentity);
00258 
00259   public:
00260     static const PString & XcapRootKey();
00261     static const PString & XcapAuthIdKey();
00262     static const PString & XcapPasswordKey();
00263     static const PString & XcapAuthAuidKey();
00264     static const PString & XcapAuthFileKey();
00265     static const PString & XcapBuddyListKey();
00266 
00267     SIPXCAP_Presentity();
00268     ~SIPXCAP_Presentity();
00269 
00271     virtual bool Open();
00272     virtual bool Close();
00273 
00274     virtual bool GetBuddyList(BuddyList & buddies);
00275     virtual bool SetBuddyList(const BuddyList & buddies);
00276     virtual bool DeleteBuddyList();
00277     virtual bool GetBuddy(BuddyInfo & buddy);
00278     virtual bool SetBuddy(const BuddyInfo & buddy);
00279     virtual bool DeleteBuddy(const PURL & presentity);
00280     virtual bool SubscribeBuddyList(bool subscribe = true);
00282 
00283     void Internal_SendLocalPresence(const OpalSetLocalPresenceCommand & cmd);
00284     void Internal_SubscribeToPresence(const OpalSubscribeToPresenceCommand & cmd);
00285     void Internal_AuthorisationRequest(const OpalAuthorisationRequestCommand & cmd);
00286     void Internal_SubscribeToWatcherInfo(const SIPWatcherInfoCommand & cmd);
00287 
00288   protected:
00289     PDECLARE_NOTIFIER2(SIPSubscribeHandler, SIPXCAP_Presentity, OnWatcherInfoSubscriptionStatus, const SIPSubscribe::SubscriptionStatus &);
00290     PDECLARE_NOTIFIER2(SIPSubscribeHandler, SIPXCAP_Presentity, OnWatcherInfoNotify, SIPSubscribe::NotifyCallbackInfo &);
00291     PDECLARE_NOTIFIER2(SIPSubscribeHandler, SIPXCAP_Presentity, OnPresenceSubscriptionStatus, const SIPSubscribe::SubscriptionStatus &);
00292     PDECLARE_NOTIFIER2(SIPSubscribeHandler, SIPXCAP_Presentity, OnPresenceNotify, SIPSubscribe::NotifyCallbackInfo &);
00293 
00294     unsigned GetExpiryTime() const;
00295     virtual void OnReceivedWatcherStatus(PXMLElement * watcher);
00296     virtual void InitRuleSet(PXML & xml);
00297     bool ChangeAuthNode(XCAPClient & xcap, const OpalAuthorisationRequestCommand & cmd);
00298     void InitBuddyXcap(
00299       XCAPClient & xcap,
00300       const PString & entryName = PString::Empty(),
00301       const PString & listName = PString::Empty()
00302     );
00303 
00304     PIPSocketAddressAndPort m_presenceServer;
00305     PString                 m_watcherSubscriptionAOR;
00306 
00307     typedef std::map<PString, PString> StringMap;
00308     StringMap m_watcherAorById;
00309     StringMap m_presenceIdByAor;
00310     StringMap m_presenceAorById;
00311     StringMap m_authorisationIdByAor;
00312 };
00313 
00314 
00315 class SIPOMA_Presentity : public SIPXCAP_Presentity
00316 {
00317     PCLASSINFO(SIPOMA_Presentity, SIPXCAP_Presentity);
00318 
00319   public:
00320     SIPOMA_Presentity();
00321 
00322   protected:
00323     virtual void InitRuleSet(PXML & xml);
00324 };
00325 
00326 
00327 #endif // P_EXPAT && OPAL_SIP
00328 
00329 #endif // OPAL_SIP_SIPPRES_H

Generated on Mon Feb 21 20:19:21 2011 for OPAL by  doxygen 1.4.7