sipcon.h

Go to the documentation of this file.
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: 22097 $
00028  * $Author: rjongbloed $
00029  * $Date: 2009-02-21 04:55:10 +0000 (Sat, 21 Feb 2009) $
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 #if OPAL_VIDEO
00048 #include <opal/pcss.h>                  // for OpalPCSSConnection
00049 #include <codec/vidcodec.h>             // for OpalVideoUpdatePicture command
00050 #endif
00051 
00052 class OpalCall;
00053 class SIPEndPoint;
00054 
00055 #define SIP_HEADER_PREFIX   "SIP-Header:"
00056 #define SIP_HEADER_REPLACES SIP_HEADER_PREFIX"Replaces"
00057 
00058 
00060 
00063 //class SIPConnection : public OpalConnection
00064 class SIPConnection : public OpalRTPConnection
00065 {
00066   PCLASSINFO(SIPConnection, OpalRTPConnection);
00067   public:
00068 
00073     SIPConnection(
00074       OpalCall & call,                          
00075       SIPEndPoint & endpoint,                   
00076       const PString & token,                    
00077       const SIPURL & address,                   
00078       OpalTransport * transport,                
00079       unsigned int options = 0,                 
00080       OpalConnection::StringOptions * stringOptions = NULL  
00081     );
00082 
00085     ~SIPConnection();
00087 
00098     virtual bool IsNetworkConnection() const { return true; }
00099 
00102     virtual PString GetPrefixName() const;
00103 
00106     virtual PString GetIdentifier() const;
00107 
00114     virtual PString GetRemotePartyURL() const;
00115 
00122     virtual PBoolean SetUpConnection();
00123 
00130     virtual PString GetDestinationAddress();
00131 
00139     virtual PString GetCalledPartyURL();
00140 
00154     virtual PString GetAlertingType() const;
00155 
00169     virtual bool SetAlertingType(const PString & info);
00170 
00177     virtual bool TransferConnection(
00178       const PString & remoteParty   
00179     );
00180 
00183     virtual bool HoldConnection();
00184 
00188     virtual bool RetrieveConnection();
00189 
00192     virtual PBoolean IsConnectionOnHold();
00193 
00204     virtual PBoolean SetAlerting(
00205       const PString & calleeName,   
00206       PBoolean withMedia
00207     );
00208 
00213     virtual PBoolean SetConnected();
00214 
00217     virtual OpalMediaFormatList GetMediaFormats() const;
00218     
00221     virtual OpalMediaStreamPtr OpenMediaStream(
00222       const OpalMediaFormat & mediaFormat, 
00223       unsigned sessionID,                  
00224       bool isSource                        
00225     );
00226 
00231     virtual bool CloseMediaStream(
00232       OpalMediaStream & stream  
00233     );
00234 
00252     virtual void OnReleased();
00253 
00263     virtual PBoolean ForwardCall(
00264       const PString & forwardParty   
00265     );
00266 
00272     virtual SendUserInputModes GetRealSendUserInputMode() const;
00273 
00290     PBoolean SendUserInputTone(char tone, unsigned duration);
00291 
00299     virtual void OnRTPStatistics(
00300       const RTP_Session & session         
00301     ) const;
00303 
00308     virtual void OnTransactionFailed(
00309       SIPTransaction & transaction
00310     );
00311 
00314     virtual void OnReceivedPDU(SIP_PDU & pdu);
00315 
00318     virtual void OnReceivedINVITE(SIP_PDU & pdu);
00319 
00322     virtual void OnReceivedReINVITE(SIP_PDU & pdu);
00323 
00326     virtual void OnReceivedACK(SIP_PDU & pdu);
00327   
00330     virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
00331 
00334     virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
00335 
00338     virtual void OnReceivedREFER(SIP_PDU & pdu);
00339   
00342     virtual void OnReceivedINFO(SIP_PDU & pdu);
00343 
00346     virtual void OnReceivedPING(SIP_PDU & pdu);
00347 
00350     virtual void OnReceivedBYE(SIP_PDU & pdu);
00351   
00354     virtual void OnReceivedCANCEL(SIP_PDU & pdu);
00355   
00360     virtual void OnReceivedResponseToINVITE(
00361       SIPTransaction & transaction,
00362       SIP_PDU & response
00363     );
00364 
00367     virtual void OnReceivedResponse(
00368       SIPTransaction & transaction,
00369       SIP_PDU & response
00370     );
00371 
00374     virtual void OnReceivedTrying(SIP_PDU & pdu);
00375   
00378     virtual void OnReceivedRinging(SIP_PDU & pdu);
00379   
00382     virtual void OnReceivedSessionProgress(SIP_PDU & pdu);
00383   
00387     virtual PBoolean OnReceivedAuthenticationRequired(
00388       SIPTransaction & transaction,
00389       SIP_PDU & response
00390     );
00391   
00394     virtual void OnReceivedRedirection(SIP_PDU & pdu);
00395 
00399     virtual void OnReceivedOK(
00400       SIPTransaction & transaction,
00401       SIP_PDU & response
00402     );
00403   
00406     virtual void OnCreatingINVITE(SIP_PDU & pdu);
00407 
00410     virtual PBoolean SendInviteOK(const SDPSessionDescription & sdp);
00411         
00414     virtual PBoolean SendInviteResponse(
00415       SIP_PDU::StatusCodes code,
00416       const char * contact = NULL,
00417       const char * extra = NULL,
00418       const SDPSessionDescription * sdp = NULL
00419     );
00421 
00422     OpalTransportAddress GetDefaultSDPConnectAddress(WORD port = 0) const;
00423 
00424     OpalTransport & GetTransport() const { return *transport; }
00425 
00426     SIPEndPoint & GetEndPoint() const { return endpoint; }
00427     SIPDialogContext & GetDialog() { return m_dialog; }
00428     const SIPDialogContext & GetDialog() const { return m_dialog; }
00429     SIPAuthentication * GetAuthenticator() const { return authentication; }
00430 
00431 #if OPAL_VIDEO
00432 
00437     virtual PBoolean OnMediaControlXML(SIP_PDU & pdu);
00438 #endif
00439 
00440     virtual void OnMediaCommand(OpalMediaCommand & note, INT extra);
00441 
00442     virtual void OnStartTransaction(SIPTransaction & transaction);
00443 
00444     virtual void OnReceivedMESSAGE(SIP_PDU & pdu);
00445     virtual void OnMessageReceived(const SIPURL & from, const SIP_PDU & pdu);
00446 
00447   protected:
00448     PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseRetry);
00449     PDECLARE_NOTIFIER(PTimer, SIPConnection, OnAckTimeout);
00450 
00451     virtual RTP_UDP *OnUseRTPSession(
00452       const unsigned rtpSessionId,
00453       const OpalMediaType & mediaType,
00454       const OpalTransportAddress & mediaAddress,
00455       OpalTransportAddress & localAddress
00456     );
00457 
00458     virtual bool OnSendSDP(
00459       bool isAnswerSDP,
00460       OpalRTPSessionManager & rtpSessions,
00461       SDPSessionDescription & sdpOut
00462     );
00463     virtual bool OfferSDPMediaDescription(
00464       const OpalMediaType & mediaType,
00465       unsigned sessionID,
00466       OpalRTPSessionManager & rtpSessions,
00467       SDPSessionDescription & sdpOut
00468     );
00469     virtual bool AnswerSDPMediaDescription(
00470       const SDPSessionDescription & sdpIn,
00471       unsigned sessionIndex,
00472       SDPSessionDescription & sdpOut
00473     );
00474 
00475     virtual void OnReceivedSDP(
00476       SIP_PDU & pdu
00477     );
00478     virtual bool OnReceivedSDPMediaDescription(
00479       SDPSessionDescription & sdp,
00480       unsigned sessionId
00481     );
00482     friend class SIPInvite;
00483     static PBoolean WriteINVITE(OpalTransport & transport, void * param);
00484     bool WriteINVITE(OpalTransport & transport);
00485 
00486     OpalTransport * CreateTransport(const OpalTransportAddress & address, PBoolean isLocalAddress = PFalse);
00487 
00488     void UpdateRemoteAddresses();
00489 
00490     void NotifyDialogState(
00491       SIPDialogNotification::States state,
00492       SIPDialogNotification::Events eventType = SIPDialogNotification::NoEvent,
00493       unsigned eventCode = 0
00494     );
00495 
00496 
00497     // Member variables
00498     SIPEndPoint         & endpoint;
00499     OpalTransport       * transport;
00500     bool                  deleteTransport;
00501 
00502     enum HoldState {
00503       eHoldOff,
00504       eRetrieveInProgress,
00505 
00506       // Order is important!
00507       eHoldOn,
00508       eHoldInProgress
00509     };
00510     HoldState             m_holdToRemote;
00511     bool                  m_holdFromRemote;
00512     PString               forwardParty;
00513 
00514     SIP_PDU             * originalInvite;
00515     PTime                 originalInviteTime;
00516 
00517     bool                  needReINVITE;
00518     SIPDialogContext      m_dialog;
00519     OpalGloballyUniqueID  m_dialogNotifyId;
00520     int                   m_appearanceCode;
00521     PString               m_alertInfo;
00522     SIPAuthentication   * authentication;
00523 
00524     std::map<SIP_PDU::Methods, unsigned> m_lastRxCSeq;
00525 
00526     PTimer                    ackTimer;
00527     PTimer                    ackRetry;
00528     SIP_PDU                   ackPacket;
00529     bool                      ackReceived;
00530     PSafePtr<SIPTransaction>  referTransaction;
00531     PSafeList<SIPTransaction> forkedInvitations; // Not for re-INVITE
00532 
00533     enum {
00534       ReleaseWithBYE,
00535       ReleaseWithCANCEL,
00536       ReleaseWithResponse,
00537       ReleaseWithNothing,
00538     } releaseMethod;
00539 
00540     OpalMediaFormatList remoteFormatList;
00541 
00542     PString GetLocalPartyURL() const;
00543 
00544   protected:
00545     PTimer sessionTimer;
00546   public:
00547     PDECLARE_NOTIFIER(PTimer, SIPConnection, OnSessionTimeout);
00548 };
00549 
00550 
00553 class SIP_RTP_Session : public RTP_UserData
00554 {
00555   PCLASSINFO(SIP_RTP_Session, RTP_UserData);
00556 
00561     SIP_RTP_Session(
00562       const SIPConnection & connection  
00563     );
00565 
00574     virtual void OnTxStatistics(
00575       const RTP_Session & session   
00576     ) const;
00577 
00584     virtual void OnRxStatistics(
00585       const RTP_Session & session   
00586     ) const;
00587 
00588 #if OPAL_VIDEO
00589 
00593     virtual void OnRxIntraFrameRequest(
00594       const RTP_Session & session   
00595     ) const;
00596 
00600     virtual void OnTxIntraFrameRequest(
00601       const RTP_Session & session   
00602     ) const;
00603 #endif
00604 
00605 
00606     virtual void SessionFailing(RTP_Session & /*session*/);
00607 
00608   protected:
00609     const SIPConnection & connection; 
00610 };
00611 
00612 
00613 #endif // OPAL_SIP
00614 
00615 #endif // OPAL_SIP_SIPCON_H
00616 
00617 
00618 // End of File ///////////////////////////////////////////////////////////////

Generated on Tue May 19 09:56:27 2009 for OPAL by  doxygen 1.5.1