OPAL  Version 3.10.10
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: 28445 $
28  * $Author: rjongbloed $
29  * $Date: 2012-10-02 20:11:02 -0500 (Tue, 02 Oct 2012) $
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 <opal/buildopts.h>
44 #include <opal/rtpconn.h>
45 #include <sip/sippdu.h>
46 #include <sip/handlers.h>
47 
48 #if OPAL_VIDEO
49 #include <opal/pcss.h> // for OpalPCSSConnection
50 #include <codec/vidcodec.h> // for OpalVideoUpdatePicture command
51 #endif
52 
53 #if OPAL_HAS_IM
54 #include <im/sipim.h>
55 #include <im/rfc4103.h>
56 #endif
57 
58 class OpalCall;
59 class SIPEndPoint;
60 
61 
65 #define OPAL_OPT_OFFER_SDP_PTIME "Offer-SDP-PTime"
66 
70 #define OPAL_OPT_REFER_SUB "Refer-Sub"
71 
77 #define OPAL_OPT_PRACK_MODE "PRACK-Mode"
78 
82 #define OPAL_OPT_INITIAL_OFFER "Initial-Offer"
83 
99 #define OPAL_OPT_SYMMETRIC_HOLD_PRODUCT "Symmetric-Hold-Product"
100 
111 #define OPAL_OPT_EXTERNAL_SDP "External-SDP"
112 
113 #define SIP_HEADER_PREFIX "SIP-Header:"
114 #define SIP_HEADER_REPLACES SIP_HEADER_PREFIX"Replaces"
115 #define SIP_HEADER_REFERRED_BY SIP_HEADER_PREFIX"Referred-By"
116 #define SIP_HEADER_CONTACT SIP_HEADER_PREFIX"Contact"
117 
118 #define OPAL_SIP_REFERRED_CONNECTION "Referred-Connection"
119 
120 
122 
127 {
128  PCLASSINFO(SIPConnection, OpalRTPConnection);
129  public:
130 
136  OpalCall & call,
138  const PString & token,
139  const SIPURL & address,
141  unsigned int options = 0,
142  OpalConnection::StringOptions * stringOptions = NULL
143  );
144 
147  ~SIPConnection();
149 
160  virtual bool IsNetworkConnection() const { return true; }
161 
164  virtual PString GetPrefixName() const;
165 
168  virtual PString GetIdentifier() const;
169 
171  virtual void OnApplyStringOptions();
172 
179  virtual PBoolean SetUpConnection();
180 
187  virtual PString GetDestinationAddress();
188 
196  virtual PString GetCalledPartyURL();
197 
211  virtual PString GetAlertingType() const;
212 
226  virtual bool SetAlertingType(const PString & info);
227 
235  virtual PString GetCallInfo() const;
236 
257  virtual bool TransferConnection(
258  const PString & remoteParty
259  );
260 
268  virtual bool Hold(
269  bool fromRemote,
270  bool placeOnHold
271  );
272 
277  virtual bool IsOnHold(
278  bool fromRemote
279  );
280 
291  virtual PBoolean SetAlerting(
292  const PString & calleeName,
293  PBoolean withMedia
294  );
295 
300  virtual PBoolean SetConnected();
301 
304  virtual OpalMediaFormatList GetMediaFormats() const;
305 
309  const OpalMediaFormat & mediaFormat,
310  unsigned sessionID,
311  bool isSource
312  );
313 
318  virtual bool CloseMediaStream(
319  OpalMediaStream & stream
320  );
321 
324  virtual void OnPauseMediaStream(
325  OpalMediaStream & strm,
326  bool paused
327  );
328 
346  virtual void OnReleased();
347 
357  virtual PBoolean ForwardCall(
358  const PString & forwardParty
359  );
360 
367 
374  virtual PBoolean SendUserInputString(
375  const PString & value
376  );
377 
394  PBoolean SendUserInputTone(char tone, unsigned duration);
395 
403  virtual void OnRTPStatistics(
404  const RTP_Session & session
405  ) const;
407 
412  virtual void OnTransactionFailed(
413  SIPTransaction & transaction
414  );
415 
418  virtual void OnReceivedPDU(SIP_PDU & pdu);
419 
422  virtual void OnReceivedINVITE(SIP_PDU & pdu);
423 
426  virtual void OnReceivedReINVITE(SIP_PDU & pdu);
427 
430  virtual void OnReceivedACK(SIP_PDU & pdu);
431 
434  virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
435 
438  virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
439 
443  virtual void OnAllowedEventNotify(
444  const PString & eventName
445  );
446 
449  virtual void OnReceivedREFER(SIP_PDU & pdu);
450 
453  virtual void OnReceivedINFO(SIP_PDU & pdu);
454 
457  virtual void OnReceivedPING(SIP_PDU & pdu);
458 
461  virtual void OnReceivedPRACK(SIP_PDU & pdu);
462 
465  virtual void OnReceivedBYE(SIP_PDU & pdu);
466 
469  virtual void OnReceivedCANCEL(SIP_PDU & pdu);
470 
475  virtual void OnReceivedResponseToINVITE(
476  SIPTransaction & transaction,
477  SIP_PDU & response
478  );
479 
482  virtual void OnReceivedResponse(
483  SIPTransaction & transaction,
484  SIP_PDU & response
485  );
486 
489  virtual void OnReceivedTrying(
490  SIPTransaction & transaction,
491  SIP_PDU & response
492  );
493 
496  virtual void OnReceivedRinging(SIP_PDU & pdu);
497 
500  virtual void OnReceivedSessionProgress(SIP_PDU & pdu);
501 
505  virtual PBoolean OnReceivedAuthenticationRequired(
506  SIPTransaction & transaction,
507  SIP_PDU & response
508  );
509 
512  virtual void OnReceivedRedirection(SIP_PDU & pdu);
513 
517  virtual void OnReceivedOK(
518  SIPTransaction & transaction,
519  SIP_PDU & response
520  );
521 
524  virtual void OnCreatingINVITE(SIPInvite & pdu);
525 
531  };
532 
535  const SIP_PDU & pdu
536  ) const;
537 
543  bool SendOPTIONS(
544  const SIPOptions::Params & params,
545  SIP_PDU * reply = NULL
546  );
547 
553  bool SendINFO(
554  const SIPInfo::Params & params,
555  SIP_PDU * reply = NULL
556  );
558 
560 
561  OpalTransport & GetTransport() const { return *transport; }
562  bool SetTransport(const SIPURL & destination);
563 
564  SIPEndPoint & GetEndPoint() const { return endpoint; }
566  const SIPDialogContext & GetDialog() const { return m_dialog; }
568 
570  enum PRACKMode {
582  };
585  PRACKMode GetPRACKMode() const { return m_prackMode; }
586 
589  virtual unsigned GetAllowedMethods() const;
590 
591 #if OPAL_VIDEO
592 
597  virtual PBoolean OnMediaControlXML(SIP_PDU & pdu);
598 #endif
599 
605  virtual bool OnMediaCommand(
606  OpalMediaStream & stream,
607  const OpalMediaCommand & command
608  );
609 
610  virtual void OnStartTransaction(SIPTransaction & transaction);
611 
612  virtual void OnReceivedMESSAGE(SIP_PDU & pdu);
613 
614  P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIPURL & /*from*/, const SIP_PDU & /*pdu*/));
615  P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIP_PDU & /*pdu*/));
616 
617 #if 0 // OPAL_HAS_IM
618  virtual bool TransmitExternalIM(
619  const OpalMediaFormat & format,
620  RTP_IMFrame & body
621  );
622 #endif
623 
624  PString GetLocalPartyURL() const;
625 
626  protected:
627  virtual bool GarbageCollection();
628  void OnUserInputInlineRFC2833(OpalRFC2833Info & info, INT type);
629 
630  PDECLARE_NOTIFIER(PTimer, SIPConnection, OnSessionTimeout);
631  PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseRetry);
632  PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseTimeout);
633 
634  virtual bool OnSendOfferSDP(
635  OpalRTPSessionManager & rtpSessions,
636  SDPSessionDescription & sdpOut,
637  bool offerCurrentOnly
638  );
639  virtual bool OnSendOfferSDPSession(
640  const OpalMediaType & mediaType,
641  unsigned sessionID,
642  OpalRTPSessionManager & rtpSessions,
643  SDPSessionDescription & sdpOut,
644  bool offerOpenMediaStreamOnly
645  );
646 
647  virtual bool OnSendAnswerSDP(
648  OpalRTPSessionManager & rtpSessions,
649  SDPSessionDescription & sdpOut
650  );
651  virtual bool OnSendAnswerSDPSession(
652  const SDPSessionDescription & sdpIn,
653  unsigned sessionIndex,
654  SDPSessionDescription & sdpOut
655  );
656 
657  virtual void OnReceivedAnswerSDP(
658  SIP_PDU & pdu
659  );
660  virtual bool OnReceivedAnswerSDPSession(
661  SDPSessionDescription & sdp,
662  unsigned sessionId,
663  bool & multipleFormats
664  );
665 
667  const unsigned rtpSessionId,
668  const OpalMediaType & mediaType,
669  const SDPMediaDescription & mediaDescription,
670  OpalTransportAddress & localAddress,
671  bool & remoteChanged
672  );
673 
674  bool SendReINVITE(PTRACE_PARAM(const char * msg));
675  bool StartPendingReINVITE();
676 
677  friend class SIPInvite;
678  static PBoolean WriteINVITE(OpalTransport & transport, void * param);
679  bool WriteINVITE();
680 
681  virtual bool SendInviteOK();
682  virtual PBoolean SendInviteResponse(
684  const SDPSessionDescription * sdp = NULL
685  );
686  virtual void AdjustInviteResponse(
687  SIP_PDU & response
688  );
689 
690  void UpdateRemoteAddresses();
691 
692  void NotifyDialogState(
695  unsigned eventCode = 0
696  );
697 
698 
699  // Member variables
704  PStringList m_allowedEvents;
705 
706  enum HoldState {
709 
710  // Order is important!
713  };
716  PString m_forwardParty;
719 
723  unsigned m_sdpVersion; // Really a sequence number
731  PString m_alertInfo;
734  PTimer sessionTimer;
735 
736  std::map<SIP_PDU::Methods, unsigned> m_lastRxCSeq;
737 
741  queue<SIP_PDU> m_responsePackets;
745 
747  PSafeList<SIPTransaction> forkedInvitations; // Not for re-INVITE
748  PSafeList<SIPTransaction> pendingInvitations; // For re-INVITE
749  PSafeList<SIPTransaction> m_pendingTransactions;
750 
751 #if OPAL_FAX
753 #endif
754 
755  enum {
760  } releaseMethod;
761 
765 
766  std::map<std::string, SIP_PDU *> m_responses;
767 
768 #if OPAL_HAS_IM
769  PSafePtr<OpalSIPIMContext> m_imContext;
770 #endif
771 
772  enum {
777 
778  private:
781 
782  friend class SIPTransaction;
783  friend class SIP_RTP_Session;
784 };
785 
786 
790 {
791  PCLASSINFO(SIP_RTP_Session, RTP_UserData);
792 
799  );
801 
810  virtual void OnTxStatistics(
811  const RTP_Session & session
812  ) const;
813 
820  virtual void OnRxStatistics(
821  const RTP_Session & session
822  ) const;
823 
824 #if OPAL_VIDEO
825 
829  virtual void OnRxIntraFrameRequest(
830  const RTP_Session & session
831  ) const;
832 
836  virtual void OnTxIntraFrameRequest(
837  const RTP_Session & session
838  ) const;
839 #endif
840 
841 
842  virtual void SessionFailing(RTP_Session & /*session*/);
843 
844  protected:
846 };
847 
848 
849 #endif // OPAL_SIP
850 
851 #endif // OPAL_SIP_SIPCON_H
852 
853 
854 // End of File ///////////////////////////////////////////////////////////////