OPAL  Version 3.12.9
sipcon.h
Go to the documentation of this file.
1 /*
2  * sipcon.h
3  *
4  * Session Initiation Protocol connection.
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: 30972 $
28  * $Author: rjongbloed $
29  * $Date: 2013-11-26 10:02:24 +1100 (Tue, 26 Nov 2013) $
30  */
31 
32 #ifndef OPAL_SIP_SIPCON_H
33 #define OPAL_SIP_SIPCON_H
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
39 #include <opal/buildopts.h>
40 
41 #if OPAL_SIP
42 
43 #include <rtp/rtpconn.h>
44 #include <sip/sippdu.h>
45 #include <sip/handlers.h>
46 
47 
48 class OpalSIPIMContext;
49 
50 
55 #define OPAL_OPT_FORWARD_REFER "Forward-Refer"
56 
60 #define OPAL_OPT_REFER_SUB "Refer-Sub"
61 
67 #define OPAL_OPT_PRACK_MODE "PRACK-Mode"
68 
72 #define OPAL_OPT_INITIAL_OFFER "Initial-Offer"
73 
89 #define OPAL_OPT_SYMMETRIC_HOLD_PRODUCT "Symmetric-Hold-Product"
90 
101 #define OPAL_OPT_ALLOW_EARLY_REPLACE "Allow-Early-Replace"
102 
113 #define OPAL_OPT_EXTERNAL_SDP "External-SDP"
114 
115 #define SIP_HEADER_PREFIX "SIP-Header:"
116 #define SIP_HEADER_REPLACES SIP_HEADER_PREFIX"Replaces"
117 #define SIP_HEADER_REFERRED_BY SIP_HEADER_PREFIX"Referred-By"
118 #define SIP_HEADER_CONTACT SIP_HEADER_PREFIX"Contact"
119 
120 #define OPAL_SIP_REFERRED_CONNECTION "Referred-Connection"
121 
122 
124 
129 {
130  PCLASSINFO(SIPConnection, OpalRTPConnection);
131  public:
132 
135  struct Init {
137  : m_call(call)
138  , m_endpoint(endpoint)
139  , m_userData(NULL)
140  , m_invite(NULL)
141  , m_options(0)
142  , m_stringOptions(NULL)
143  { }
144 
147  PString m_token;
149  void * m_userData;
151  unsigned m_options;
153  };
154 
158  const Init & init
159  );
160 
163  ~SIPConnection();
165 
176  virtual bool IsNetworkConnection() const { return true; }
177 
180  virtual PString GetPrefixName() const;
181 
184  virtual PString GetIdentifier() const;
185 
187  virtual void OnApplyStringOptions();
188 
195  virtual PBoolean SetUpConnection();
196 
200 
206  virtual PString GetRemoteIdentity() const;
207 
214  virtual PString GetDestinationAddress();
215 
223  virtual PString GetCalledPartyURL();
224 
238  virtual PString GetAlertingType() const;
239 
253  virtual bool SetAlertingType(const PString & info);
254 
262  virtual PString GetCallInfo() const;
263 
284  virtual bool TransferConnection(
285  const PString & remoteParty
286  );
287 
295  virtual bool Hold(
296  bool fromRemote,
297  bool placeOnHold
298  );
299 
304  virtual bool IsOnHold(
305  bool fromRemote
306  );
307 
318  virtual PBoolean SetAlerting(
319  const PString & calleeName,
320  PBoolean withMedia
321  );
322 
327  virtual PBoolean SetConnected();
328 
331  virtual OpalMediaFormatList GetMediaFormats() const;
332 
336  virtual bool RequireSymmetricMediaStreams() const;
337 
338 #if OPAL_T38_CAPABILITY
339 
341  virtual bool SwitchFaxMediaStreams(
342  bool toT38
343  );
344 #endif
345 
349  const OpalMediaFormat & mediaFormat,
350  unsigned sessionID,
351  PBoolean isSource
352  );
353 
357  const OpalMediaFormat & mediaFormat,
358  unsigned sessionID,
359  bool isSource
360  );
361 
366  virtual void OnClosedMediaStream(
367  const OpalMediaStream & stream
368  );
369 
379  virtual bool GetMediaTransportAddresses(
380  const OpalMediaType & mediaType,
381  OpalTransportAddressArray & transports
382  ) const;
383 
392  virtual void OnPatchMediaStream(
393  PBoolean isSource,
394  OpalMediaPatch & patch
395  );
396 
399  virtual void OnPauseMediaStream(
400  OpalMediaStream & strm,
401  bool paused
402  );
403 
421  virtual void OnReleased();
422 
432  virtual PBoolean ForwardCall(
433  const PString & forwardParty
434  );
435 
441  virtual SendUserInputModes GetRealSendUserInputMode() const;
442 
449  virtual PBoolean SendUserInputString(
450  const PString & value
451  );
452 
469  PBoolean SendUserInputTone(char tone, unsigned duration);
471 
476  virtual void OnTransactionFailed(
477  SIPTransaction & transaction
478  );
479 
482  virtual void OnReceivedPDU(SIP_PDU & pdu);
483 
486  virtual void OnReceivedINVITE(SIP_PDU & pdu);
487 
490  virtual void OnReceivedReINVITE(SIP_PDU & pdu);
491 
494  virtual void OnReceivedACK(SIP_PDU & pdu);
495 
498  virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
499 
502  virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
503 
507  virtual void OnAllowedEventNotify(
508  const PString & eventName
509  );
510 
513  virtual void OnReceivedREFER(SIP_PDU & pdu);
514 
517  virtual void OnReceivedINFO(SIP_PDU & pdu);
518 
521  virtual void OnReceivedPING(SIP_PDU & pdu);
522 
525  virtual void OnReceivedPRACK(SIP_PDU & pdu);
526 
529  virtual void OnReceivedBYE(SIP_PDU & pdu);
530 
533  virtual void OnReceivedCANCEL(SIP_PDU & pdu);
534 
539  virtual bool OnReceivedResponseToINVITE(
540  SIPTransaction & transaction,
541  SIP_PDU & response
542  );
543 
546  virtual void OnReceivedResponse(
547  SIPTransaction & transaction,
548  SIP_PDU & response
549  );
550 
553  virtual void OnReceivedTrying(
554  SIPTransaction & transaction,
555  SIP_PDU & response
556  );
557 
560  virtual void OnReceivedRinging(SIPTransaction & transaction, SIP_PDU & pdu);
561 
564  virtual void OnReceivedSessionProgress(SIPTransaction & transaction, SIP_PDU & pdu);
565 
569  virtual PBoolean OnReceivedAuthenticationRequired(
570  SIPTransaction & transaction,
571  SIP_PDU & response
572  );
573 
576  virtual void OnReceivedRedirection(SIP_PDU & pdu);
577 
581  virtual void OnReceivedOK(
582  SIPTransaction & transaction,
583  SIP_PDU & response
584  );
585 
588  virtual void OnCreatingINVITE(SIPInvite & pdu);
589 
595  };
596 
599  const SIP_PDU & pdu
600  ) const;
601 
607  bool SendOPTIONS(
608  const SIPOptions::Params & params,
609  SIP_PDU * reply = NULL
610  );
611 
617  bool SendINFO(
618  const SIPInfo::Params & params,
619  SIP_PDU * reply = NULL
620  );
622 
624 
627 
629  enum PRACKMode {
641  };
644  PRACKMode GetPRACKMode() const { return m_prackMode; }
645 
648  virtual unsigned GetAllowedMethods() const;
649 
652  bool DoesRemoteAllowMethod(SIP_PDU::Methods method) const { return (m_allowedMethods&(1<<method)) != 0; }
653 
654 #if OPAL_VIDEO
655 
660  virtual PBoolean OnMediaControlXML(SIP_PDU & pdu);
661 #endif
662 
668  virtual bool OnMediaCommand(
669  OpalMediaStream & stream,
670  const OpalMediaCommand & command
671  );
672 
673  // Overrides from SIPTransactionOwner
674  virtual PString GetAuthID() const;
675 
676 
677  virtual void OnStartTransaction(SIPTransaction & transaction);
678  virtual void OnReceivedMESSAGE(SIP_PDU & pdu);
679  virtual void OnReceivedSUBSCRIBE(SIP_PDU & pdu);
680 
681  PString GetLocalPartyURL() const;
682 
683  virtual void PrintOn(ostream & strm) const { OpalRTPConnection::PrintOn(strm); }
684 
685  protected:
686  virtual bool GarbageCollection();
688  void OnSessionTimeout();
689  void OnInviteResponseRetry();
691  void OnInviteCollision();
692 
694  SIPTransaction & transaction,
695  SIP_PDU & response
696  );
697  virtual bool OnSendOfferSDP(
698  SDPSessionDescription & sdpOut,
699  bool offerCurrentOnly
700  );
701  virtual bool OnSendOfferSDPSession(
702  unsigned sessionID,
703  SDPSessionDescription & sdpOut,
704  bool offerOpenMediaStreamOnly
705  );
706 
707  virtual bool OnSendAnswerSDP(
708  SDPSessionDescription & sdpOut
709  );
710  virtual bool OnSendAnswerSDP(
711  const SDPSessionDescription & sdpOffer,
712  SDPSessionDescription & sdpAnswer
713  );
714  virtual bool OnSendAnswerSDPSession(
715  const SDPSessionDescription & sdpIn,
716  unsigned sessionIndex,
717  SDPSessionDescription & sdpOut
718  );
719 
720  virtual bool OnReceivedAnswerSDP(
721  SIP_PDU & response,
722  SIPTransaction * transaction
723  );
724  virtual bool OnReceivedAnswerSDPSession(
725  SDPSessionDescription & sdp,
726  unsigned sessionId,
727  bool & multipleFormats
728  );
729 
731  const unsigned rtpSessionId,
732  const OpalMediaType & mediaType,
733  const SDPMediaDescription & mediaDescription,
734  OpalTransportAddress & localAddress,
735  bool & remoteChanged
736  );
737 
738  bool SendReINVITE(PTRACE_PARAM(const char * msg));
739  bool StartPendingReINVITE();
740 
741  friend class SIPInvite;
743 
744  virtual void SendDelayedACK(bool force);
745  void OnDelayedAckTimeout();
746 
747  virtual bool SendInviteOK();
748  virtual PBoolean SendInviteResponse(
750  const SDPSessionDescription * sdp = NULL
751  );
752  virtual void AdjustInviteResponse(
753  SIP_PDU & response
754  );
755 
756  void UpdateRemoteAddresses();
757 #if OPAL_SRTP
758  virtual bool CanDoSRTP() const { return m_dialog.GetRemoteTransportAddress(m_dnsEntry).GetProtoPrefix() == OpalTransportAddress::TlsPrefix(); }
759 #endif
760 
761  void NotifyDialogState(
762  SIPDialogNotification::States state,
763  SIPDialogNotification::Events eventType = SIPDialogNotification::NoEvent,
764  unsigned eventCode = 0
765  );
766 
767  virtual bool InviteConferenceParticipant(const PString & conf, const PString & dest);
768 
769  // Member variables
771  PStringSet m_allowedEvents;
772 
773  enum HoldState {
776 
777  // Order is important!
780  };
783  PString m_forwardParty;
788 
792  PTimeInterval m_delayedAckTimeout;
795  unsigned m_sdpVersion; // Really a sequence number
802  PString m_alertInfo;
804 
808  std::queue<SIP_PDU> m_responsePackets;
813 
815  PSafeList<SIPTransaction> m_forkedInvitations; // Not for re-INVITE
816  PSafeList<SIPTransaction> m_pendingInvitations; // For re-INVITE
817 
818  enum {
823  } releaseMethod;
824 
827  bool SetRemoteMediaFormats(SIP_PDU * pdu);
828 
829  std::map<std::string, SIP_PDU *> m_responses;
830 
831 #if OPAL_HAS_SIPIM
832  PSafePtr<OpalSIPIMContext> m_imContext;
833 #endif
834 
835 #if OPAL_VIDEO
837 #endif
838 
839  enum {
844  void OnUserInputInlineRFC2833(OpalRFC2833Info & info, INT type);
845 
846 
847  private:
848  P_REMOVE_VIRTUAL_VOID(OnCreatingINVITE(SIP_PDU&));
849  P_REMOVE_VIRTUAL_VOID(OnReceivedTrying(SIP_PDU &));
850  P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIPURL & /*from*/, const SIP_PDU & /*pdu*/));
851  P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIP_PDU & /*pdu*/));
852 
853  friend class SIPTransaction;
854  friend class SIP_RTP_Session;
855 };
856 
857 
858 #endif // OPAL_SIP
859 
860 #endif // OPAL_SIP_SIPCON_H
861 
862 
863 // End of File ///////////////////////////////////////////////////////////////