OPAL  Version 3.12.5
sipep.h
Go to the documentation of this file.
1 /*
2  * sipep.h
3  *
4  * Session Initiation Protocol endpoint.
5  *
6  * Open Phone Abstraction Library (OPAL)
7  * Formally known as the Open H323 project.
8  *
9  * Copyright (c) 2001 Equivalence Pty. Ltd.
10  *
11  * The contents of this file are subject to the Mozilla Public License
12  * Version 1.0 (the "License"); you may not use this file except in
13  * compliance with the License. You may obtain a copy of the License at
14  * http://www.mozilla.org/MPL/
15  *
16  * Software distributed under the License is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18  * the License for the specific language governing rights and limitations
19  * under the License.
20  *
21  * The Original Code is Open Phone Abstraction Library.
22  *
23  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24  *
25  * Contributor(s): ______________________________________.
26  *
27  * $Revision: 30261 $
28  * $Author: rjongbloed $
29  * $Date: 2013-08-07 01:17:47 -0500 (Wed, 07 Aug 2013) $
30  */
31 
32 #ifndef OPAL_SIP_SIPEP_H
33 #define OPAL_SIP_SIPEP_H
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
39 #ifndef _PTLIB_H
40 #include <ptlib.h>
41 #endif
42 
43 #include <opal/buildopts.h>
44 
45 #if OPAL_SIP
46 
47 #include <rtp/rtpep.h>
48 #include <sip/sipcon.h>
49 #include <sip/handlers.h>
50 
51 
53 
57 {
58  PCLASSINFO(SIPEndPoint, OpalRTPEndPoint);
59  public:
66  unsigned maxThreads = 15
67  );
68 
71  ~SIPEndPoint();
73 
80  virtual void ShutDown();
81 
85  virtual PString GetDefaultTransport() const;
86 
89  virtual WORD GetDefaultSignalPort() const;
90 
95  virtual PStringList GetNetworkURIs(
96  const PString & name
97  ) const;
98 
101  virtual void NewIncomingConnection(
102  OpalListener & listener,
103  const OpalTransportPtr & transport
104  );
105 
135  virtual PSafePtr<OpalConnection> MakeConnection(
136  OpalCall & call,
137  const PString & party,
138  void * userData,
139  unsigned int options,
140  OpalConnection::StringOptions * stringOptions
141  );
142 
161  virtual void OnReleased(
162  OpalConnection & connection
163  );
164 
172  virtual void OnConferenceStatusChanged(
173  OpalEndPoint & endpoint,
174  const PString & uri,
176  );
177 
182  virtual PBoolean GarbageCollection();
184 
191  const SIPConnection::Init & init
192 
193  );
194 
197  virtual PBoolean SetupTransfer(
198  const PString & token,
199  const PString & callIdentity,
200  const PString & remoteParty,
201  void * userData = NULL
202  );
203 
207  virtual PBoolean ForwardConnection(
208  SIPConnection & connection,
209  const PString & forwardParty
210  );
211 
222  bool ClearDialogContext(
223  const PString & descriptor
224  );
225  bool ClearDialogContext(
226  SIPDialogContext & context
227  );
229 
232 
238  const SIPTransactionOwner & transactor,
239  SIP_PDU::StatusCodes & reason
240  );
241 
242  virtual void HandlePDU(
243  const OpalTransportPtr & transport
244  );
245 
249  virtual bool OnReceivedPDU(
250  SIP_PDU * pdu
251  );
252 
255  virtual void OnReceivedResponse(
256  SIPTransaction & transaction,
257  SIP_PDU & response
258  );
259 
263  virtual bool OnReceivedINVITE(
264  SIP_PDU * pdu
265  );
266 
270  virtual bool OnReceivedNOTIFY(
271  SIP_PDU & request
272  );
273 
277  virtual bool OnReceivedREGISTER(
278  SIP_PDU & request
279  );
280 
284  virtual bool OnReceivedSUBSCRIBE(
285  SIP_PDU & request,
286  SIPDialogContext * dialog
287  );
288 
292  virtual bool OnReceivedMESSAGE(
293  SIP_PDU & request
294  );
295 
299  virtual bool OnReceivedOPTIONS(
300  SIP_PDU & request
301  );
302 
305  virtual void OnTransactionFailed(
306  SIPTransaction & transaction
307  );
309 
310 
318  PSafePtr<SIPConnection> GetSIPConnectionWithLock(
319  const PString & token,
320  PSafetyMode mode = PSafeReadWrite,
321  SIP_PDU::StatusCodes * errorCode = NULL
322  );
323 
324  virtual PBoolean IsAcceptedAddress(const SIPURL & toAddr);
325 
326 
361  bool Register(
362  const SIPRegister::Params & params,
363  PString & aor,
364  SIP_PDU::StatusCodes * reason = NULL
365  );
366 
367  // For backward compatibility
368  bool Register(
369  const SIPRegister::Params & params,
370  PString & aor,
371  bool asynchronous
372  );
373 
375  bool P_DEPRECATED Register(
376  const PString & host,
377  const PString & user = PString::Empty(),
378  const PString & autName = PString::Empty(),
379  const PString & password = PString::Empty(),
380  const PString & authRealm = PString::Empty(),
381  unsigned expire = 0,
382  const PTimeInterval & minRetryTime = PMaxTimeInterval,
383  const PTimeInterval & maxRetryTime = PMaxTimeInterval
384  );
385 
400  PBoolean IsRegistered(
401  const PString & aor,
402  bool includeOffline = false
403  );
404 
414  bool Unregister(
415  const PString & aor
416  );
417 
421  bool UnregisterAll();
422 
426 
429  PStringList GetRegistrations(
430  bool includeOffline = false
431  ) const { return activeSIPHandlers.GetAddresses(includeOffline, SIP_PDU::Method_REGISTER); }
432 
441  void * m_userData;
442  };
443 
448  const PString & token,
449  RegistrationStatus & status
450  );
451 
454  virtual void OnRegistrationStatus(
455  const RegistrationStatus & status
456  );
457 
458  // For backward compatibility
459  virtual void OnRegistrationStatus(
460  const PString & aor,
461  PBoolean wasRegistering,
462  PBoolean reRegistering,
463  SIP_PDU::StatusCodes reason
464  );
465 
469  virtual void OnRegistrationFailed(
470  const PString & aor,
471  SIP_PDU::StatusCodes reason,
472  PBoolean wasRegistering
473  );
474 
478  virtual void OnRegistered(
479  const PString & aor,
480  PBoolean wasRegistering
481  );
482 
483 
523  bool Subscribe(
524  const SIPSubscribe::Params & params,
525  PString & token,
526  bool tokenIsAOR = true
527  );
528 
529  // For backward compatibility
530  bool Subscribe(
531  SIPSubscribe::PredefinedPackages eventPackage,
532  unsigned expire,
533  const PString & aor
534  );
535 
542  bool IsSubscribed(
543  const PString & aor,
544  bool includeOffline = false
545  );
546  bool IsSubscribed(
547  const PString & eventPackage,
548  const PString & aor,
549  bool includeOffline = false
550  );
551 
561  bool Unsubscribe(
562  const PString & aor,
563  bool invalidateNotifiers = false
564  );
565  bool Unsubscribe(
566  SIPSubscribe::PredefinedPackages eventPackage,
567  const PString & aor,
568  bool invalidateNotifiers = false
569  );
570  bool Unsubscribe(
571  const PString & eventPackage,
572  const PString & aor,
573  bool invalidateNotifiers = false
574  );
575 
579  bool UnsubcribeAll(
581  );
582  bool UnsubcribeAll(
583  const PString & eventPackage
584  );
585 
589  const SIPSubscribe::EventPackage & eventPackage
590  ) { return activeSIPHandlers.GetCount(SIP_PDU::Method_SUBSCRIBE, eventPackage); }
591 
594  PStringList GetSubscriptions(
595  const SIPSubscribe::EventPackage & eventPackage,
596  bool includeOffline = false
597  ) const { return activeSIPHandlers.GetAddresses(includeOffline, SIP_PDU::Method_REGISTER, eventPackage); }
598 
601 
606  const PString & token,
607  const PString & eventPackage,
608  SubscriptionStatus & status
609  );
610 
613  virtual void OnSubscriptionStatus(
614  const SubscriptionStatus & status
615  );
616 
620  virtual void OnSubscriptionStatus(
621  const PString & eventPackage,
622  const SIPURL & uri,
623  bool wasSubscribing,
624  bool reSubscribing,
625  SIP_PDU::StatusCodes reason
626  );
627 
628  virtual void OnSubscriptionStatus(
629  SIPSubscribeHandler & handler,
630  const SIPURL & uri,
631  bool wasSubscribing,
632  bool reSubscribing,
633  SIP_PDU::StatusCodes reason
634  );
635 
647  };
648 
651  virtual CanNotifyResult CanNotify(
652  const PString & eventPackage,
653  const SIPURL & aor
654  );
655 
656  // For backward compatobility
657  virtual bool CanNotify(const PString & eventPackage);
658 
661  bool Notify(
662  const SIPURL & targetAddress,
663  const PString & eventPackage,
664  const PObject & body
665  );
666 
667 
670  virtual void OnDialogInfoReceived(
671  const SIPDialogNotification & info
672  );
673 
675  const SIPDialogNotification & info
676  );
677 
678 
681  virtual void OnRegInfoReceived(
682  const SIPRegNotification & info
683  );
684 
685 
688  bool SendMESSAGE(
689  SIPMessage::Params & params
690  );
691 
694  virtual void OnMESSAGECompleted(
695  const SIPMessage::Params & params,
696  SIP_PDU::StatusCodes reason
697  );
698 
701  : m_pdu(pdu)
702  , m_transport(*pdu.GetTransport())
704  { }
705 
708  enum {
713  } m_status;
714  };
715 
716  typedef PNotifierTemplate<ConnectionlessMessageInfo &> ConnectionlessMessageNotifier;
717  #define PDECLARE_ConnectionlessMessageNotifier(cls, fn) PDECLARE_NOTIFIER2(SIPEndPoint, cls, fn, SIPEndPoint::ConnectionlessMessageInfo &)
718  #define PCREATE_ConnectionlessMessageNotifier(fn) PCREATE_NOTIFIER2(fn, SIPEndPoint::ConnectionlessMessageInfo &)
719 
721  const ConnectionlessMessageNotifier & notifier
722  )
723  { m_onConnectionlessMessage = notifier; }
724 
725 
728  virtual bool SendOPTIONS(
729  const SIPOptions::Params & params
730  );
731 
735  virtual void OnOptionsCompleted(
736  const SIPOptions::Params & params,
737  const SIP_PDU & response
738  );
739 
740 
744  bool Publish(
745  const SIPSubscribe::Params & params,
746  const PString & body,
747  PString & aor
748  );
749  bool Publish(
750  const PString & to,
751  const PString & body,
752  unsigned expire = 300
753  );
754 
757  PStringList GetPublications(
758  const SIPSubscribe::EventPackage & eventPackage,
759  bool includeOffline = false
760  ) const { return activeSIPHandlers.GetAddresses(includeOffline, SIP_PDU::Method_PUBLISH, eventPackage); }
761 
762 
763 #if OPAL_SIP_PRESENCE
764 
767  bool PublishPresence(
768  const SIPPresenceInfo & info,
769  unsigned expire = 300
770  );
771 
774  virtual void OnPresenceInfoReceived (
775  const SIPPresenceInfo & info
776  );
777  virtual void OnPresenceInfoReceived (
778  const PString & identity,
779  const PString & basic,
780  const PString & note
781  );
782 #endif // OPAL_SIP_PRESENCE
783 
784 
787  PBoolean Ping(
788  const PURL & to
789  );
790 
793  const PStringSet & GetAllowedEvents() const { return m_allowedEvents; }
794 
798 
802 
803  void SetMaxPacketSizeUDP(PINDEX sz) { m_maxPacketSizeUDP = sz; }
804  PINDEX GetMaxPacketSizeUDP() const { return m_maxPacketSizeUDP; }
805 
806  void SetMaxRetries(unsigned r) { maxRetries = r; }
807  unsigned GetMaxRetries() const { return maxRetries; }
808 
810  const PTimeInterval & t1,
811  const PTimeInterval & t2
812  ) { retryTimeoutMin = t1; retryTimeoutMax = t2; }
813  const PTimeInterval & GetRetryTimeoutMin() const { return retryTimeoutMin; }
814  const PTimeInterval & GetRetryTimeoutMax() const { return retryTimeoutMax; }
815 
817  const PTimeInterval & t
818  ) { nonInviteTimeout = t; }
819  const PTimeInterval & GetNonInviteTimeout() const { return nonInviteTimeout; }
820 
822  const PTimeInterval & t
823  ) { pduCleanUpTimeout = t; }
824  const PTimeInterval & GetPduCleanUpTimeout() const { return pduCleanUpTimeout; }
825 
827  const PTimeInterval & t
828  ) { inviteTimeout = t; }
829  const PTimeInterval & GetInviteTimeout() const { return inviteTimeout; }
830 
832  const PTimeInterval & t
833  ) { m_progressTimeout = t; }
834  const PTimeInterval & GetProgressTimeout() const { return m_progressTimeout; }
835 
837  const PTimeInterval & t
838  ) { ackTimeout = t; }
839  const PTimeInterval & GetAckTimeout() const { return ackTimeout; }
840 
842  const PTimeInterval & t
843  ) { registrarTimeToLive = t; }
844  const PTimeInterval & GetRegistrarTimeToLive() const { return registrarTimeToLive; }
845 
847  const PTimeInterval & t
848  ) { notifierTimeToLive = t; }
849  const PTimeInterval & GetNotifierTimeToLive() const { return notifierTimeToLive; }
850 
851  P_DEPRECATED void SetNATBindingTimeout(
852  const PTimeInterval & t
853  ) { m_keepAliveTimeout = t; }
854  P_DEPRECATED const PTimeInterval & GetNATBindingTimeout() const { return m_keepAliveTimeout; }
855 
863  };
865  PTimeInterval & timeout,
866  KeepAliveType & type
867  ) { timeout = m_keepAliveTimeout; type = m_keepAliveType; }
869  const PTimeInterval & timeout,
870  KeepAliveType type
871  ) { m_keepAliveTimeout = timeout; m_keepAliveType = type; }
872 
873 
875  SIPTransaction * transaction
876  ) { m_transactions.Append(transaction); }
877 
878  PSafePtr<SIPTransaction> GetTransaction(const PString & transactionID, PSafetyMode mode = PSafeReadWrite)
879  { return PSafePtrCast<SIPTransactionBase, SIPTransaction>(m_transactions.FindWithLock(transactionID, mode)); }
880 
883  unsigned GetNextCSeq() { return ++m_lastSentCSeq; }
884 
892 
895  bool GetAuthentication(
896  const PString & realm,
897  PString & authId,
898  PString & password
899  );
900 
903  virtual SIPURL GetDefaultLocalURL(const OpalTransport & transport);
904 
914  SIP_PDU & pdu,
915  SIPConnection * connection = NULL,
916  const OpalTransport * transport = NULL
917  );
918 
919 
922  const SIPURL & GetProxy() const { return m_proxy; }
923 
926  void SetProxy(const SIPURL & url);
927 
930  void SetProxy(
931  const PString & hostname,
932  const PString & username,
933  const PString & password
934  );
935 
936 
940 
944 
951  virtual PString GetUserAgent() const;
952 
955  void SetUserAgent(const PString & str) { m_userAgentString = str; }
956 
957 
960  virtual unsigned GetAllowedMethods() const;
961 
962 
965 
967 
968  virtual void OnStartTransaction(SIPConnection & conn, SIPTransaction & transaction);
969 
970 
971  PSafePtr<SIPHandler> FindSIPHandlerByCallID(const PString & callID, PSafetyMode m)
972  { return activeSIPHandlers.FindSIPHandlerByCallID(callID, m); }
973 
975  { activeSIPHandlers.Update(handler); }
976 
977 
979 
980 
981  protected:
982  void AddTransport(const OpalTransportPtr & transport);
983  void TransportThreadMain(OpalTransportPtr transport);
984 
987  PStringSet m_allowedEvents;
988 
990 
992  unsigned maxRetries;
993  PTimeInterval retryTimeoutMin; // T1
994  PTimeInterval retryTimeoutMax; // T2
995  PTimeInterval nonInviteTimeout; // T3
996  PTimeInterval pduCleanUpTimeout; // T4
997  PTimeInterval inviteTimeout;
998  PTimeInterval m_progressTimeout;
999  PTimeInterval ackTimeout;
1000  PTimeInterval registrarTimeToLive;
1001  PTimeInterval notifierTimeToLive;
1002  PTimeInterval natBindingTimeout;
1003  PTimeInterval m_keepAliveTimeout;
1007 
1008  // Transport management
1009  PSafeDictionary<OpalTransportAddress, OpalTransport> m_transportsTable;
1010 
1011  // Sub-protocol handlers
1013  PSafePtr<SIPHandler> FindHandlerByPDU(const SIP_PDU & pdu, PSafetyMode mode);
1014 
1017 
1018  PSafeSortedList<SIPTransactionBase> m_transactions;
1019 
1020  PAtomicInteger m_lastSentCSeq;
1022 
1024  PSyncPoint m_sync;
1026  RegistrationCompletion() : m_reason(SIP_PDU::Information_Trying) { }
1027  };
1028  std::map<PString, RegistrationCompletion> m_registrationComplete;
1029 
1031  typedef std::multimap<PString, SIPURL> ConferenceMap;
1033 
1034  // Thread pooling
1036 
1037  // Network interface checking
1038  PDECLARE_InterfaceNotifier(SIPEndPoint, OnHighPriorityInterfaceChange);
1039  PDECLARE_InterfaceNotifier(SIPEndPoint, OnLowPriorityInterfaceChange);
1040  PInterfaceMonitor::Notifier m_onHighPriorityInterfaceChange;
1041  PInterfaceMonitor::Notifier m_onLowPriorityInterfaceChange;
1042 
1044 
1045  P_REMOVE_VIRTUAL_VOID(OnReceivedIntervalTooBrief(SIPTransaction &, SIP_PDU &));
1046  P_REMOVE_VIRTUAL_VOID(OnReceivedAuthenticationRequired(SIPTransaction &, SIP_PDU &));
1047  P_REMOVE_VIRTUAL_VOID(OnReceivedOK(SIPTransaction &, SIP_PDU &));
1048  P_REMOVE_VIRTUAL_VOID(OnMessageFailed(const SIPURL &, SIP_PDU::StatusCodes));
1049  P_REMOVE_VIRTUAL(SIPConnection *,CreateConnection(OpalCall &, const PString &, void *, const SIPURL &, OpalTransport *, SIP_PDU *, unsigned, OpalConnection::StringOptions *), NULL);
1050  P_REMOVE_VIRTUAL(PBoolean, OnReceivedPDU(OpalTransport &, SIP_PDU *), false);
1051  P_REMOVE_VIRTUAL(bool, OnReceivedConnectionlessPDU(OpalTransport &, SIP_PDU *), false);
1052  P_REMOVE_VIRTUAL(bool, OnReceivedConnectionlessPDU(SIP_PDU *), false);
1053  P_REMOVE_VIRTUAL(PBoolean, OnReceivedINVITE(OpalTransport &, SIP_PDU *), false);
1054  P_REMOVE_VIRTUAL(PBoolean, OnReceivedNOTIFY(OpalTransport &, SIP_PDU &), false);
1055  P_REMOVE_VIRTUAL(PBoolean, OnReceivedREGISTER(OpalTransport &, SIP_PDU &), false);
1059 };
1060 
1061 
1062 #endif // OPAL_SIP
1063 
1064 #endif // OPAL_SIP_SIPEP_H
1065 
1066 
1067 // End of File ///////////////////////////////////////////////////////////////