OPAL Version 3.10.2
|
00001 /* 00002 * sipcon.h 00003 * 00004 * Session Initiation Protocol connection. 00005 * 00006 * Open Phone Abstraction Library (OPAL) 00007 * Formally known as the Open H323 project. 00008 * 00009 * Copyright (c) 2001 Equivalence Pty. Ltd. 00010 * 00011 * The contents of this file are subject to the Mozilla Public License 00012 * Version 1.0 (the "License"); you may not use this file except in 00013 * compliance with the License. You may obtain a copy of the License at 00014 * http://www.mozilla.org/MPL/ 00015 * 00016 * Software distributed under the License is distributed on an "AS IS" 00017 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00018 * the License for the specific language governing rights and limitations 00019 * under the License. 00020 * 00021 * The Original Code is Open Phone Abstraction Library. 00022 * 00023 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00024 * 00025 * Contributor(s): ______________________________________. 00026 * 00027 * $Revision: 26222 $ 00028 * $Author: rjongbloed $ 00029 * $Date: 2011-07-18 04:52:34 -0500 (Mon, 18 Jul 2011) $ 00030 */ 00031 00032 #ifndef OPAL_SIP_SIPCON_H 00033 #define OPAL_SIP_SIPCON_H 00034 00035 #ifdef P_USE_PRAGMA 00036 #pragma interface 00037 #endif 00038 00039 #include <opal/buildopts.h> 00040 00041 #if OPAL_SIP 00042 00043 #include <opal/buildopts.h> 00044 #include <opal/rtpconn.h> 00045 #include <sip/sippdu.h> 00046 #include <sip/handlers.h> 00047 00048 #if OPAL_VIDEO 00049 #include <opal/pcss.h> // for OpalPCSSConnection 00050 #include <codec/vidcodec.h> // for OpalVideoUpdatePicture command 00051 #endif 00052 00053 #if OPAL_HAS_IM 00054 #include <im/sipim.h> 00055 #include <im/rfc4103.h> 00056 #endif 00057 00058 class OpalCall; 00059 class SIPEndPoint; 00060 00061 00065 #define OPAL_OPT_OFFER_SDP_PTIME "Offer-SDP-PTime" 00066 00070 #define OPAL_OPT_REFER_SUB "Refer-Sub" 00071 00077 #define OPAL_OPT_PRACK_MODE "PRACK-Mode" 00078 00082 #define OPAL_OPT_INITIAL_OFFER "Initial-Offer" 00083 00099 #define OPAL_OPT_SYMMETRIC_HOLD_PRODUCT "Symmetric-Hold-Product" 00100 00111 #define OPAL_OPT_EXTERNAL_SDP "External-SDP" 00112 00113 #define SIP_HEADER_PREFIX "SIP-Header:" 00114 #define SIP_HEADER_REPLACES SIP_HEADER_PREFIX"Replaces" 00115 #define SIP_HEADER_REFERRED_BY SIP_HEADER_PREFIX"Referred-By" 00116 #define SIP_HEADER_CONTACT SIP_HEADER_PREFIX"Contact" 00117 00118 #define OPAL_SIP_REFERRED_CONNECTION "Referred-Connection" 00119 00120 00122 00126 class SIPConnection : public OpalRTPConnection 00127 { 00128 PCLASSINFO(SIPConnection, OpalRTPConnection); 00129 public: 00130 00135 SIPConnection( 00136 OpalCall & call, 00137 SIPEndPoint & endpoint, 00138 const PString & token, 00139 const SIPURL & address, 00140 OpalTransport * transport, 00141 unsigned int options = 0, 00142 OpalConnection::StringOptions * stringOptions = NULL 00143 ); 00144 00147 ~SIPConnection(); 00149 00160 virtual bool IsNetworkConnection() const { return true; } 00161 00164 virtual PString GetPrefixName() const; 00165 00168 virtual PString GetIdentifier() const; 00169 00171 virtual void OnApplyStringOptions(); 00172 00179 virtual PBoolean SetUpConnection(); 00180 00187 virtual PString GetDestinationAddress(); 00188 00196 virtual PString GetCalledPartyURL(); 00197 00211 virtual PString GetAlertingType() const; 00212 00226 virtual bool SetAlertingType(const PString & info); 00227 00235 virtual PString GetCallInfo() const; 00236 00257 virtual bool TransferConnection( 00258 const PString & remoteParty 00259 ); 00260 00268 virtual bool Hold( 00269 bool fromRemote, 00270 bool placeOnHold 00271 ); 00272 00277 virtual bool IsOnHold( 00278 bool fromRemote 00279 ); 00280 00291 virtual PBoolean SetAlerting( 00292 const PString & calleeName, 00293 PBoolean withMedia 00294 ); 00295 00300 virtual PBoolean SetConnected(); 00301 00304 virtual OpalMediaFormatList GetMediaFormats() const; 00305 00308 virtual OpalMediaStreamPtr OpenMediaStream( 00309 const OpalMediaFormat & mediaFormat, 00310 unsigned sessionID, 00311 bool isSource 00312 ); 00313 00318 virtual bool CloseMediaStream( 00319 OpalMediaStream & stream 00320 ); 00321 00324 virtual void OnPauseMediaStream( 00325 OpalMediaStream & strm, 00326 bool paused 00327 ); 00328 00346 virtual void OnReleased(); 00347 00357 virtual PBoolean ForwardCall( 00358 const PString & forwardParty 00359 ); 00360 00366 virtual SendUserInputModes GetRealSendUserInputMode() const; 00367 00374 virtual PBoolean SendUserInputString( 00375 const PString & value 00376 ); 00377 00394 PBoolean SendUserInputTone(char tone, unsigned duration); 00395 00403 virtual void OnRTPStatistics( 00404 const RTP_Session & session 00405 ) const; 00407 00412 virtual void OnTransactionFailed( 00413 SIPTransaction & transaction 00414 ); 00415 00418 virtual void OnReceivedPDU(SIP_PDU & pdu); 00419 00422 virtual void OnReceivedINVITE(SIP_PDU & pdu); 00423 00426 virtual void OnReceivedReINVITE(SIP_PDU & pdu); 00427 00430 virtual void OnReceivedACK(SIP_PDU & pdu); 00431 00434 virtual void OnReceivedOPTIONS(SIP_PDU & pdu); 00435 00438 virtual void OnReceivedNOTIFY(SIP_PDU & pdu); 00439 00443 virtual void OnAllowedEventNotify( 00444 const PString & eventName 00445 ); 00446 00449 virtual void OnReceivedREFER(SIP_PDU & pdu); 00450 00453 virtual void OnReceivedINFO(SIP_PDU & pdu); 00454 00457 virtual void OnReceivedPING(SIP_PDU & pdu); 00458 00461 virtual void OnReceivedPRACK(SIP_PDU & pdu); 00462 00465 virtual void OnReceivedBYE(SIP_PDU & pdu); 00466 00469 virtual void OnReceivedCANCEL(SIP_PDU & pdu); 00470 00475 virtual void OnReceivedResponseToINVITE( 00476 SIPTransaction & transaction, 00477 SIP_PDU & response 00478 ); 00479 00482 virtual void OnReceivedResponse( 00483 SIPTransaction & transaction, 00484 SIP_PDU & response 00485 ); 00486 00489 virtual void OnReceivedTrying( 00490 SIPTransaction & transaction, 00491 SIP_PDU & response 00492 ); 00493 00496 virtual void OnReceivedRinging(SIP_PDU & pdu); 00497 00500 virtual void OnReceivedSessionProgress(SIP_PDU & pdu); 00501 00505 virtual PBoolean OnReceivedAuthenticationRequired( 00506 SIPTransaction & transaction, 00507 SIP_PDU & response 00508 ); 00509 00512 virtual void OnReceivedRedirection(SIP_PDU & pdu); 00513 00517 virtual void OnReceivedOK( 00518 SIPTransaction & transaction, 00519 SIP_PDU & response 00520 ); 00521 00524 virtual void OnCreatingINVITE(SIPInvite & pdu); 00525 00526 enum TypeOfINVITE { 00527 IsNewINVITE, 00528 IsDuplicateINVITE, 00529 IsReINVITE, 00530 IsLoopedINVITE 00531 }; 00532 00534 TypeOfINVITE CheckINVITE( 00535 const SIP_PDU & pdu 00536 ) const; 00537 00543 bool SendOPTIONS( 00544 const SIPOptions::Params & params, 00545 SIP_PDU * reply = NULL 00546 ); 00547 00553 bool SendINFO( 00554 const SIPInfo::Params & params, 00555 SIP_PDU * reply = NULL 00556 ); 00558 00559 OpalTransportAddress GetDefaultSDPConnectAddress(WORD port = 0) const; 00560 00561 OpalTransport & GetTransport() const { return *transport; } 00562 bool SetTransport(const SIPURL & destination); 00563 00564 SIPEndPoint & GetEndPoint() const { return endpoint; } 00565 SIPDialogContext & GetDialog() { return m_dialog; } 00566 const SIPDialogContext & GetDialog() const { return m_dialog; } 00567 SIPAuthentication * GetAuthenticator() const { return m_authentication; } 00568 00570 enum PRACKMode { 00571 e_prackDisabled, 00575 e_prackSupported, 00578 e_prackRequired 00582 }; 00585 PRACKMode GetPRACKMode() const { return m_prackMode; } 00586 00587 #if OPAL_VIDEO 00588 00593 virtual PBoolean OnMediaControlXML(SIP_PDU & pdu); 00594 #endif 00595 00596 virtual void OnMediaCommand(OpalMediaCommand & note, INT extra); 00597 00598 virtual void OnStartTransaction(SIPTransaction & transaction); 00599 00600 virtual void OnReceivedMESSAGE(SIP_PDU & pdu); 00601 00602 P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIPURL & /*from*/, const SIP_PDU & /*pdu*/)); 00603 P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIP_PDU & /*pdu*/)); 00604 00605 #if 0 // OPAL_HAS_IM 00606 virtual bool TransmitExternalIM( 00607 const OpalMediaFormat & format, 00608 RTP_IMFrame & body 00609 ); 00610 #endif 00611 00612 PString GetLocalPartyURL() const; 00613 00614 protected: 00615 virtual bool GarbageCollection(); 00616 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnSessionTimeout); 00617 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseRetry); 00618 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseTimeout); 00619 00620 virtual bool OnSendOfferSDP( 00621 OpalRTPSessionManager & rtpSessions, 00622 SDPSessionDescription & sdpOut 00623 ); 00624 virtual bool OnSendOfferSDPSession( 00625 const OpalMediaType & mediaType, 00626 unsigned sessionID, 00627 OpalRTPSessionManager & rtpSessions, 00628 SDPSessionDescription & sdpOut, 00629 bool offerOpenMediaStreamOnly 00630 ); 00631 00632 virtual bool OnSendAnswerSDP( 00633 OpalRTPSessionManager & rtpSessions, 00634 SDPSessionDescription & sdpOut 00635 ); 00636 virtual bool OnSendAnswerSDPSession( 00637 const SDPSessionDescription & sdpIn, 00638 unsigned sessionIndex, 00639 SDPSessionDescription & sdpOut 00640 ); 00641 00642 virtual void OnReceivedAnswerSDP( 00643 SIP_PDU & pdu 00644 ); 00645 virtual bool OnReceivedAnswerSDPSession( 00646 SDPSessionDescription & sdp, 00647 unsigned sessionId 00648 ); 00649 00650 virtual OpalMediaSession * SetUpMediaSession( 00651 const unsigned rtpSessionId, 00652 const OpalMediaType & mediaType, 00653 const SDPMediaDescription & mediaDescription, 00654 OpalTransportAddress & localAddress, 00655 bool & remoteChanged 00656 ); 00657 00658 bool SendReINVITE(PTRACE_PARAM(const char * msg)); 00659 void StartPendingReINVITE(); 00660 00661 friend class SIPInvite; 00662 static PBoolean WriteINVITE(OpalTransport & transport, void * param); 00663 bool WriteINVITE(); 00664 00665 virtual bool SendInviteOK(); 00666 virtual PBoolean SendInviteResponse( 00667 SIP_PDU::StatusCodes code, 00668 const SDPSessionDescription * sdp = NULL 00669 ); 00670 virtual void AdjustInviteResponse( 00671 SIP_PDU & response 00672 ); 00673 00674 void UpdateRemoteAddresses(); 00675 00676 void NotifyDialogState( 00677 SIPDialogNotification::States state, 00678 SIPDialogNotification::Events eventType = SIPDialogNotification::NoEvent, 00679 unsigned eventCode = 0 00680 ); 00681 00682 00683 // Member variables 00684 SIPEndPoint & endpoint; 00685 OpalTransport * transport; 00686 bool deleteTransport; 00687 unsigned m_allowedMethods; 00688 PStringList m_allowedEvents; 00689 00690 enum HoldState { 00691 eHoldOff, 00692 eRetrieveInProgress, 00693 00694 // Order is important! 00695 eHoldOn, 00696 eHoldInProgress 00697 }; 00698 HoldState m_holdToRemote; 00699 bool m_holdFromRemote; 00700 PString forwardParty; 00701 SIPURL m_ciscoRemotePartyID; 00702 00703 SIP_PDU * originalInvite; 00704 PTime originalInviteTime; 00705 time_t m_sdpSessionId; 00706 unsigned m_sdpVersion; // Really a sequence number 00707 bool m_needReINVITE; 00708 bool m_handlingINVITE; 00709 bool m_symmetricOpenStream; 00710 SIPDialogContext m_dialog; 00711 OpalGloballyUniqueID m_dialogNotifyId; 00712 int m_appearanceCode; 00713 PString m_alertInfo; 00714 SIPAuthentication * m_authentication; 00715 unsigned m_authenticatedCseq; 00716 PTimer sessionTimer; 00717 00718 std::map<SIP_PDU::Methods, unsigned> m_lastRxCSeq; 00719 00720 PRACKMode m_prackMode; 00721 bool m_prackEnabled; 00722 unsigned m_prackSequenceNumber; 00723 queue<SIP_PDU> m_responsePackets; 00724 PTimer m_responseFailTimer; 00725 PTimer m_responseRetryTimer; 00726 unsigned m_responseRetryCount; 00727 00728 bool m_referInProgress; 00729 PSafeList<SIPTransaction> forkedInvitations; // Not for re-INVITE 00730 PSafeList<SIPTransaction> pendingInvitations; // For re-INVITE 00731 PSafeList<SIPTransaction> m_pendingTransactions; 00732 00733 #if OPAL_FAX 00734 bool m_switchedToFaxMode; 00735 #endif 00736 00737 enum { 00738 ReleaseWithBYE, 00739 ReleaseWithCANCEL, 00740 ReleaseWithResponse, 00741 ReleaseWithNothing, 00742 } releaseMethod; 00743 00744 OpalMediaFormatList m_remoteFormatList; 00745 OpalMediaFormatList m_answerFormatList; 00746 bool SetRemoteMediaFormats(SDPSessionDescription * sdp); 00747 00748 std::map<std::string, SIP_PDU *> m_responses; 00749 00750 #if OPAL_HAS_IM 00751 PSafePtr<OpalSIPIMContext> m_imContext; 00752 #endif 00753 00754 private: 00755 P_REMOVE_VIRTUAL_VOID(OnCreatingINVITE(SIP_PDU&)); 00756 P_REMOVE_VIRTUAL_VOID(OnReceivedTrying(SIP_PDU &)); 00757 00758 friend class SIPTransaction; 00759 friend class SIP_RTP_Session; 00760 }; 00761 00762 00765 class SIP_RTP_Session : public RTP_UserData 00766 { 00767 PCLASSINFO(SIP_RTP_Session, RTP_UserData); 00768 00773 SIP_RTP_Session( 00774 SIPConnection & connection 00775 ); 00777 00786 virtual void OnTxStatistics( 00787 const RTP_Session & session 00788 ) const; 00789 00796 virtual void OnRxStatistics( 00797 const RTP_Session & session 00798 ) const; 00799 00800 #if OPAL_VIDEO 00801 00805 virtual void OnRxIntraFrameRequest( 00806 const RTP_Session & session 00807 ) const; 00808 00812 virtual void OnTxIntraFrameRequest( 00813 const RTP_Session & session 00814 ) const; 00815 #endif 00816 00817 00818 virtual void SessionFailing(RTP_Session & /*session*/); 00819 00820 protected: 00821 SIPConnection & connection; 00822 }; 00823 00824 00825 #endif // OPAL_SIP 00826 00827 #endif // OPAL_SIP_SIPCON_H 00828 00829 00830 // End of File ///////////////////////////////////////////////////////////////