OPAL  Version 3.14.3
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: 32929 $
28  * $Author: rjongbloed $
29  * $Date: 2014-10-08 11:47:45 +1100 (Wed, 08 Oct 2014) $
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_config.h>
40 
41 #if OPAL_SIP
42 
43 #include <rtp/rtpconn.h>
44 #include <sip/sippdu.h>
45 #include <sip/handlers.h>
46 #include <sip/sdp.h>
47 
48 
49 class OpalSIPIMContext;
50 
51 
56 #define OPAL_OPT_FORWARD_REFER "Forward-Refer"
57 
61 #define OPAL_OPT_REFER_SUB "Refer-Sub"
62 
68 #define OPAL_OPT_PRACK_MODE "PRACK-Mode"
69 
73 #define OPAL_OPT_INITIAL_OFFER "Initial-Offer"
74 
90 #define OPAL_OPT_SYMMETRIC_HOLD_PRODUCT "Symmetric-Hold-Product"
91 
102 #define OPAL_OPT_ALLOW_EARLY_REPLACE "Allow-Early-Replace"
103 
114 #define OPAL_OPT_EXTERNAL_SDP "External-SDP"
115 
122 #define OPAL_OPT_RTCP_MUX "RTCP-Mux"
123 
124 
131 #define OPAL_OPT_AV_GROUPING "AV-Grouping"
132 
140 #define OPAL_OPT_UNSECURE_SRTP "Unsecure-SRTP"
141 
142 
143 #define SIP_HEADER_PREFIX "SIP-Header:"
144 #define SIP_HEADER_REPLACES SIP_HEADER_PREFIX"Replaces"
145 #define SIP_HEADER_REFERRED_BY SIP_HEADER_PREFIX"Referred-By"
146 #define SIP_HEADER_CONTACT SIP_HEADER_PREFIX"Contact"
147 
148 #define OPAL_SIP_REFERRED_CONNECTION "Referred-Connection"
149 
150 
152 
157 {
158  PCLASSINFO(SIPConnection, OpalRTPConnection);
159  public:
160 
163  struct Init {
165  : m_call(call)
166  , m_endpoint(endpoint)
167  , m_userData(NULL)
168  , m_invite(NULL)
169  , m_options(0)
170  , m_stringOptions(NULL)
171  { }
172 
175  PString m_token;
177  void * m_userData;
179  unsigned m_options;
181  };
182 
186  const Init & init
187  );
188 
191  ~SIPConnection();
193 
204  virtual bool IsNetworkConnection() const { return true; }
205 
208  virtual PString GetPrefixName() const;
209 
212  virtual PString GetIdentifier() const;
213 
215  virtual void OnApplyStringOptions();
216 
223  virtual PBoolean SetUpConnection();
224 
228 
234  virtual PString GetRemoteIdentity() const;
235 
242  virtual PString GetDestinationAddress();
243 
251  virtual PString GetCalledPartyURL();
252 
266  virtual PString GetAlertingType() const;
267 
281  virtual bool SetAlertingType(const PString & info);
282 
290  virtual PString GetCallInfo() const;
291 
312  virtual bool TransferConnection(
313  const PString & remoteParty
314  );
315 
330  virtual bool HoldRemote(
331  bool placeOnHold
332  );
333 
338  virtual bool IsOnHold(
339  bool fromRemote
340  ) const;
341 
352  virtual PBoolean SetAlerting(
353  const PString & calleeName,
354  PBoolean withMedia
355  );
356 
361  virtual PBoolean SetConnected();
362 
365  virtual OpalMediaFormatList GetMediaFormats() const;
366 
370  virtual bool RequireSymmetricMediaStreams() const;
371 
372 #if OPAL_T38_CAPABILITY
373 
375  virtual bool SwitchFaxMediaStreams(
376  bool toT38
377  );
378 #endif
379 
383  const OpalMediaFormat & mediaFormat,
384  unsigned sessionID,
385  PBoolean isSource
386  );
387 
391  const OpalMediaFormat & mediaFormat,
392  unsigned sessionID,
393  bool isSource
394  );
395 
400  virtual void OnClosedMediaStream(
401  const OpalMediaStream & stream
402  );
403 
413  virtual bool GetMediaTransportAddresses(
414  OpalConnection & otherConnection,
415  const OpalMediaType & mediaType,
416  OpalTransportAddressArray & transports
417  ) const;
418 
427  virtual void OnPatchMediaStream(
428  PBoolean isSource,
429  OpalMediaPatch & patch
430  );
431 
434  virtual void OnPauseMediaStream(
435  OpalMediaStream & strm,
436  bool paused
437  );
438 
456  virtual void OnReleased();
457 
467  virtual PBoolean ForwardCall(
468  const PString & forwardParty
469  );
470 
476  virtual SendUserInputModes GetRealSendUserInputMode() const;
477 
484  virtual PBoolean SendUserInputString(
485  const PString & value
486  );
487 
504  PBoolean SendUserInputTone(char tone, unsigned duration);
506 
511  virtual void OnTransactionFailed(
512  SIPTransaction & transaction
513  );
514 
517  virtual void OnReceivedPDU(SIP_PDU & pdu);
518 
521  virtual void OnReceivedINVITE(SIP_PDU & pdu);
522 
525  virtual void OnReceivedReINVITE(SIP_PDU & pdu);
526 
529  virtual void OnReceivedACK(SIP_PDU & pdu);
530 
533  virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
534 
537  virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
538 
542  virtual void OnAllowedEventNotify(
543  const PString & eventName
544  );
545 
548  virtual void OnReceivedREFER(SIP_PDU & pdu);
549 
552  virtual void OnReceivedINFO(SIP_PDU & pdu);
553 
556  virtual void OnReceivedPING(SIP_PDU & pdu);
557 
560  virtual void OnReceivedPRACK(SIP_PDU & pdu);
561 
564  virtual void OnReceivedBYE(SIP_PDU & pdu);
565 
568  virtual void OnReceivedCANCEL(SIP_PDU & pdu);
569 
574  virtual bool OnReceivedResponseToINVITE(
575  SIPTransaction & transaction,
576  SIP_PDU & response
577  );
578 
581  virtual void OnReceivedResponse(
582  SIPTransaction & transaction,
583  SIP_PDU & response
584  );
585 
588  virtual void OnReceivedTrying(
589  SIPTransaction & transaction,
590  SIP_PDU & response
591  );
592 
595  virtual void OnReceivedRinging(SIPTransaction & transaction, SIP_PDU & pdu);
596 
599  virtual void OnReceivedSessionProgress(SIPTransaction & transaction, SIP_PDU & pdu);
600 
604  virtual PBoolean OnReceivedAuthenticationRequired(
605  SIPTransaction & transaction,
606  SIP_PDU & response
607  );
608 
611  virtual void OnReceivedRedirection(SIP_PDU & pdu);
612 
616  virtual void OnReceivedOK(
617  SIPTransaction & transaction,
618  SIP_PDU & response
619  );
620 
623  virtual void OnCreatingINVITE(SIPInvite & pdu);
624 
630  };
631 
634  const SIP_PDU & pdu
635  ) const;
636 
642  bool SendOPTIONS(
643  const SIPOptions::Params & params,
644  SIP_PDU * reply = NULL
645  );
646 
652  bool SendINFO(
653  const SIPInfo::Params & params,
654  SIP_PDU * reply = NULL
655  );
657 
659 
662 
664  enum PRACKMode {
676  };
679  PRACKMode GetPRACKMode() const { return m_prackMode; }
680 
683  virtual unsigned GetAllowedMethods() const;
684 
687  bool DoesRemoteAllowMethod(SIP_PDU::Methods method) const { return (m_allowedMethods&(1<<method)) != 0; }
688 
689 #if OPAL_VIDEO
690 
695  virtual PBoolean OnMediaControlXML(SIP_PDU & pdu);
696 #endif
697 
703  virtual bool OnMediaCommand(
704  OpalMediaStream & stream,
705  const OpalMediaCommand & command
706  );
707 
708  // Overrides from SIPTransactionOwner
709  virtual PString GetAuthID() const;
710 
711 
712  virtual void OnStartTransaction(SIPTransaction & transaction);
713  virtual void OnReceivedMESSAGE(SIP_PDU & pdu);
714  virtual void OnReceivedSUBSCRIBE(SIP_PDU & pdu);
715 
716  PString GetLocalPartyURL() const;
717 
718  virtual void PrintOn(ostream & strm) const { OpalRTPConnection::PrintOn(strm); }
719 
720  protected:
721  virtual bool GarbageCollection();
723  void OnSessionTimeout();
724  void OnInviteResponseRetry();
726  void OnInviteCollision();
727 
729  SIPTransaction & transaction,
730  SIP_PDU & response
731  );
732  virtual bool OnSendOfferSDP(
733  SDPSessionDescription & sdpOut,
734  bool offerCurrentOnly
735  );
736  virtual bool OnSendOfferSDPSession(
737  unsigned sessionID,
738  SDPSessionDescription & sdpOut,
739  bool offerOpenMediaStreamOnly
740  );
741 
742  virtual bool OnSendAnswerSDP(
743  SDPSessionDescription & sdpOut
744  );
745  virtual bool OnSendAnswerSDP(
746  const SDPSessionDescription & sdpOffer,
747  SDPSessionDescription & sdpAnswer
748  );
749  virtual SDPMediaDescription * OnSendAnswerSDPSession(
750  SDPMediaDescription * incomingMedia,
751  unsigned sessionId,
752  SDPMediaDescription::Direction otherSidesDir
753  );
754 
755  virtual bool OnReceivedAnswerSDP(
756  SIP_PDU & response,
757  SIPTransaction * transaction
758  );
759  virtual bool OnReceivedAnswerSDPSession(
760  SDPSessionDescription & sdp,
761  unsigned sessionId,
762  bool & multipleFormats
763  );
764 
766  const unsigned rtpSessionId,
767  const OpalMediaType & mediaType,
768  const SDPMediaDescription & mediaDescription,
769  OpalTransportAddress & localAddress,
770  bool & remoteChanged
771  );
772 #if OPAL_VIDEO
773  void SetAudioVideoGroup();
774 #endif
775 
776  bool SendReINVITE(PTRACE_PARAM(const char * msg));
777  bool StartPendingReINVITE();
778 
779  friend class SIPInvite;
781 
782  virtual bool SendDelayedACK(bool force);
783  void OnDelayedAckTimeout();
784 
785  void RetryHoldRemote(bool placeOnHold);
786 
787  virtual bool SendInviteOK();
788  virtual PBoolean SendInviteResponse(
790  const SDPSessionDescription * sdp = NULL
791  );
792  virtual void AdjustInviteResponse(
793  SIP_PDU & response
794  );
795 
796  void UpdateRemoteAddresses();
797 #if OPAL_SRTP
798  virtual bool CanDoSRTP() const;
799 #endif
800 
801  void NotifyDialogState(
802  SIPDialogNotification::States state,
803  SIPDialogNotification::Events eventType = SIPDialogNotification::NoEvent,
804  unsigned eventCode = 0
805  );
806 
807  virtual bool InviteConferenceParticipant(const PString & conf, const PString & dest);
808 
809  // Member variables
811  PStringSet m_allowedEvents;
812 
813  enum HoldState {
816 
817  // Order is important!
820  };
823  PString m_forwardParty;
828 
832  PTimeInterval m_delayedAckTimeout1;
833  PTimeInterval m_delayedAckTimeout2;
836  unsigned m_sdpVersion; // Really a sequence number
843  PString m_alertInfo;
844 #if OPAL_VIDEO
846 #endif
848 
852  std::queue<SIP_PDU> m_responsePackets;
857 
859  PSafeList<SIPTransaction> m_forkedInvitations; // Not for re-INVITE
860  PSafeList<SIPTransaction> m_pendingInvitations; // For re-INVITE
861 
862  enum {
867  } releaseMethod;
868 
871  int SetRemoteMediaFormats(SIP_PDU & pdu);
872 
873  std::map<std::string, SIP_PDU *> m_responses;
874 
875 #if OPAL_HAS_SIPIM
876  PSafePtr<OpalSIPIMContext> m_imContext;
877 #endif
878 
879  enum {
884  void OnUserInputInlineRFC2833(OpalRFC2833Info & info, INT type);
885 
886 
887  private:
888  P_REMOVE_VIRTUAL_VOID(OnCreatingINVITE(SIP_PDU&));
889  P_REMOVE_VIRTUAL_VOID(OnReceivedTrying(SIP_PDU &));
890  P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIPURL & /*from*/, const SIP_PDU & /*pdu*/));
891  P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIP_PDU & /*pdu*/));
892 
893  friend class SIPTransaction;
894  friend class SIP_RTP_Session;
895 };
896 
897 
898 #endif // OPAL_SIP
899 
900 #endif // OPAL_SIP_SIPCON_H
901 
902 
903 // End of File ///////////////////////////////////////////////////////////////