OPAL
Version 3.10.4
|
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: 26927 $ 00028 * $Author: rjongbloed $ 00029 * $Date: 2012-02-01 16:09:34 -0600 (Wed, 01 Feb 2012) $ 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 00589 virtual unsigned GetAllowedMethods() const; 00590 00591 #if OPAL_VIDEO 00592 00597 virtual PBoolean OnMediaControlXML(SIP_PDU & pdu); 00598 #endif 00599 00605 virtual bool OnMediaCommand( 00606 OpalMediaStream & stream, 00607 const OpalMediaCommand & command 00608 ); 00609 00610 virtual void OnStartTransaction(SIPTransaction & transaction); 00611 00612 virtual void OnReceivedMESSAGE(SIP_PDU & pdu); 00613 00614 P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIPURL & /*from*/, const SIP_PDU & /*pdu*/)); 00615 P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIP_PDU & /*pdu*/)); 00616 00617 #if 0 // OPAL_HAS_IM 00618 virtual bool TransmitExternalIM( 00619 const OpalMediaFormat & format, 00620 RTP_IMFrame & body 00621 ); 00622 #endif 00623 00624 PString GetLocalPartyURL() const; 00625 00626 protected: 00627 virtual bool GarbageCollection(); 00628 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnSessionTimeout); 00629 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseRetry); 00630 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseTimeout); 00631 00632 virtual bool OnSendOfferSDP( 00633 OpalRTPSessionManager & rtpSessions, 00634 SDPSessionDescription & sdpOut, 00635 bool offerCurrentOnly 00636 ); 00637 virtual bool OnSendOfferSDPSession( 00638 const OpalMediaType & mediaType, 00639 unsigned sessionID, 00640 OpalRTPSessionManager & rtpSessions, 00641 SDPSessionDescription & sdpOut, 00642 bool offerOpenMediaStreamOnly 00643 ); 00644 00645 virtual bool OnSendAnswerSDP( 00646 OpalRTPSessionManager & rtpSessions, 00647 SDPSessionDescription & sdpOut 00648 ); 00649 virtual bool OnSendAnswerSDPSession( 00650 const SDPSessionDescription & sdpIn, 00651 unsigned sessionIndex, 00652 SDPSessionDescription & sdpOut 00653 ); 00654 00655 virtual void OnReceivedAnswerSDP( 00656 SIP_PDU & pdu 00657 ); 00658 virtual bool OnReceivedAnswerSDPSession( 00659 SDPSessionDescription & sdp, 00660 unsigned sessionId, 00661 bool & multipleFormats 00662 ); 00663 00664 virtual OpalMediaSession * SetUpMediaSession( 00665 const unsigned rtpSessionId, 00666 const OpalMediaType & mediaType, 00667 const SDPMediaDescription & mediaDescription, 00668 OpalTransportAddress & localAddress, 00669 bool & remoteChanged 00670 ); 00671 00672 bool SendReINVITE(PTRACE_PARAM(const char * msg)); 00673 void StartPendingReINVITE(); 00674 00675 friend class SIPInvite; 00676 static PBoolean WriteINVITE(OpalTransport & transport, void * param); 00677 bool WriteINVITE(); 00678 00679 virtual bool SendInviteOK(); 00680 virtual PBoolean SendInviteResponse( 00681 SIP_PDU::StatusCodes code, 00682 const SDPSessionDescription * sdp = NULL 00683 ); 00684 virtual void AdjustInviteResponse( 00685 SIP_PDU & response 00686 ); 00687 00688 void UpdateRemoteAddresses(); 00689 00690 void NotifyDialogState( 00691 SIPDialogNotification::States state, 00692 SIPDialogNotification::Events eventType = SIPDialogNotification::NoEvent, 00693 unsigned eventCode = 0 00694 ); 00695 00696 00697 // Member variables 00698 SIPEndPoint & endpoint; 00699 OpalTransport * transport; 00700 bool deleteTransport; 00701 unsigned m_allowedMethods; 00702 PStringList m_allowedEvents; 00703 00704 enum HoldState { 00705 eHoldOff, 00706 eRetrieveInProgress, 00707 00708 // Order is important! 00709 eHoldOn, 00710 eHoldInProgress 00711 }; 00712 HoldState m_holdToRemote; 00713 bool m_holdFromRemote; 00714 PString m_forwardParty; 00715 SIPURL m_contactAddress; 00716 SIPURL m_ciscoRemotePartyID; 00717 00718 SIP_PDU * originalInvite; 00719 PTime originalInviteTime; 00720 time_t m_sdpSessionId; 00721 unsigned m_sdpVersion; // Really a sequence number 00722 bool m_needReINVITE; 00723 bool m_handlingINVITE; 00724 bool m_symmetricOpenStream; 00725 SIPDialogContext m_dialog; 00726 OpalGloballyUniqueID m_dialogNotifyId; 00727 int m_appearanceCode; 00728 PString m_alertInfo; 00729 SIPAuthentication * m_authentication; 00730 unsigned m_authenticatedCseq; 00731 PTimer sessionTimer; 00732 00733 std::map<SIP_PDU::Methods, unsigned> m_lastRxCSeq; 00734 00735 PRACKMode m_prackMode; 00736 bool m_prackEnabled; 00737 unsigned m_prackSequenceNumber; 00738 queue<SIP_PDU> m_responsePackets; 00739 PTimer m_responseFailTimer; 00740 PTimer m_responseRetryTimer; 00741 unsigned m_responseRetryCount; 00742 00743 bool m_referInProgress; 00744 PSafeList<SIPTransaction> forkedInvitations; // Not for re-INVITE 00745 PSafeList<SIPTransaction> pendingInvitations; // For re-INVITE 00746 PSafeList<SIPTransaction> m_pendingTransactions; 00747 00748 #if OPAL_FAX 00749 bool m_switchedToFaxMode; 00750 #endif 00751 00752 enum { 00753 ReleaseWithBYE, 00754 ReleaseWithCANCEL, 00755 ReleaseWithResponse, 00756 ReleaseWithNothing, 00757 } releaseMethod; 00758 00759 OpalMediaFormatList m_remoteFormatList; 00760 OpalMediaFormatList m_answerFormatList; 00761 bool SetRemoteMediaFormats(SDPSessionDescription * sdp); 00762 00763 std::map<std::string, SIP_PDU *> m_responses; 00764 00765 #if OPAL_HAS_IM 00766 PSafePtr<OpalSIPIMContext> m_imContext; 00767 #endif 00768 00769 private: 00770 P_REMOVE_VIRTUAL_VOID(OnCreatingINVITE(SIP_PDU&)); 00771 P_REMOVE_VIRTUAL_VOID(OnReceivedTrying(SIP_PDU &)); 00772 00773 friend class SIPTransaction; 00774 friend class SIP_RTP_Session; 00775 }; 00776 00777 00780 class SIP_RTP_Session : public RTP_UserData 00781 { 00782 PCLASSINFO(SIP_RTP_Session, RTP_UserData); 00783 00788 SIP_RTP_Session( 00789 SIPConnection & connection 00790 ); 00792 00801 virtual void OnTxStatistics( 00802 const RTP_Session & session 00803 ) const; 00804 00811 virtual void OnRxStatistics( 00812 const RTP_Session & session 00813 ) const; 00814 00815 #if OPAL_VIDEO 00816 00820 virtual void OnRxIntraFrameRequest( 00821 const RTP_Session & session 00822 ) const; 00823 00827 virtual void OnTxIntraFrameRequest( 00828 const RTP_Session & session 00829 ) const; 00830 #endif 00831 00832 00833 virtual void SessionFailing(RTP_Session & /*session*/); 00834 00835 protected: 00836 SIPConnection & connection; 00837 }; 00838 00839 00840 #endif // OPAL_SIP 00841 00842 #endif // OPAL_SIP_SIPCON_H 00843 00844 00845 // End of File ///////////////////////////////////////////////////////////////