OPAL  Version 3.10.4
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: 26927 $
28  * $Author: rjongbloed $
29  * $Date: 2012-02-01 16:09:34 -0600 (Wed, 01 Feb 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  PDECLARE_NOTIFIER(PTimer, SIPConnection, OnSessionTimeout);
629  PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseRetry);
630  PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseTimeout);
631 
632  virtual bool OnSendOfferSDP(
633  OpalRTPSessionManager & rtpSessions,
634  SDPSessionDescription & sdpOut,
635  bool offerCurrentOnly
636  );
637  virtual bool OnSendOfferSDPSession(
638  const OpalMediaType & mediaType,
639  unsigned sessionID,
640  OpalRTPSessionManager & rtpSessions,
641  SDPSessionDescription & sdpOut,
642  bool offerOpenMediaStreamOnly
643  );
644 
645  virtual bool OnSendAnswerSDP(
646  OpalRTPSessionManager & rtpSessions,
647  SDPSessionDescription & sdpOut
648  );
649  virtual bool OnSendAnswerSDPSession(
650  const SDPSessionDescription & sdpIn,
651  unsigned sessionIndex,
652  SDPSessionDescription & sdpOut
653  );
654 
655  virtual void OnReceivedAnswerSDP(
656  SIP_PDU & pdu
657  );
658  virtual bool OnReceivedAnswerSDPSession(
659  SDPSessionDescription & sdp,
660  unsigned sessionId,
661  bool & multipleFormats
662  );
663 
665  const unsigned rtpSessionId,
666  const OpalMediaType & mediaType,
667  const SDPMediaDescription & mediaDescription,
668  OpalTransportAddress & localAddress,
669  bool & remoteChanged
670  );
671 
672  bool SendReINVITE(PTRACE_PARAM(const char * msg));
673  void StartPendingReINVITE();
674 
675  friend class SIPInvite;
676  static PBoolean WriteINVITE(OpalTransport & transport, void * param);
677  bool WriteINVITE();
678 
679  virtual bool SendInviteOK();
680  virtual PBoolean SendInviteResponse(
682  const SDPSessionDescription * sdp = NULL
683  );
684  virtual void AdjustInviteResponse(
685  SIP_PDU & response
686  );
687 
688  void UpdateRemoteAddresses();
689 
690  void NotifyDialogState(
693  unsigned eventCode = 0
694  );
695 
696 
697  // Member variables
702  PStringList m_allowedEvents;
703 
704  enum HoldState {
707 
708  // Order is important!
711  };
714  PString m_forwardParty;
717 
721  unsigned m_sdpVersion; // Really a sequence number
728  PString m_alertInfo;
731  PTimer sessionTimer;
732 
733  std::map<SIP_PDU::Methods, unsigned> m_lastRxCSeq;
734 
738  queue<SIP_PDU> m_responsePackets;
742 
744  PSafeList<SIPTransaction> forkedInvitations; // Not for re-INVITE
745  PSafeList<SIPTransaction> pendingInvitations; // For re-INVITE
746  PSafeList<SIPTransaction> m_pendingTransactions;
747 
748 #if OPAL_FAX
750 #endif
751 
752  enum {
757  } releaseMethod;
758 
762 
763  std::map<std::string, SIP_PDU *> m_responses;
764 
765 #if OPAL_HAS_IM
766  PSafePtr<OpalSIPIMContext> m_imContext;
767 #endif
768 
769  private:
772 
773  friend class SIPTransaction;
774  friend class SIP_RTP_Session;
775 };
776 
777 
781 {
782  PCLASSINFO(SIP_RTP_Session, RTP_UserData);
783 
790  );
792 
801  virtual void OnTxStatistics(
802  const RTP_Session & session
803  ) const;
804 
811  virtual void OnRxStatistics(
812  const RTP_Session & session
813  ) const;
814 
815 #if OPAL_VIDEO
816 
820  virtual void OnRxIntraFrameRequest(
821  const RTP_Session & session
822  ) const;
823 
827  virtual void OnTxIntraFrameRequest(
828  const RTP_Session & session
829  ) const;
830 #endif
831 
832 
833  virtual void SessionFailing(RTP_Session & /*session*/);
834 
835  protected:
837 };
838 
839 
840 #endif // OPAL_SIP
841 
842 #endif // OPAL_SIP_SIPCON_H
843 
844 
845 // End of File ///////////////////////////////////////////////////////////////