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: 19647 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-03-03 01:54:25 +0000 (Mon, 03 Mar 2008) $
00030  */
00031 
00032 #ifndef __OPAL_SIPCON_H
00033 #define __OPAL_SIPCON_H
00034 
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 
00039 #include <opal/buildopts.h>
00040 #include <opal/connection.h>
00041 #include <sip/sippdu.h>
00042 #if OPAL_VIDEO
00043 #include <opal/pcss.h>                  // for OpalPCSSConnection
00044 #include <codec/vidcodec.h>             // for OpalVideoUpdatePicture command
00045 #endif
00046 
00047 #ifdef HAS_LIBZRTP
00048 #ifndef __ZRTP_TYPES_H__
00049 struct zrtp_conn_ctx_t;
00050 #endif
00051 #endif
00052 
00053 class OpalCall;
00054 class SIPEndPoint;
00055 
00056 
00058 
00061 //class SIPConnection : public OpalConnection
00062 class SIPConnection : public OpalConnection
00063 {
00064   PCLASSINFO(SIPConnection, OpalConnection);
00065   public:
00066 
00071     SIPConnection(
00072       OpalCall & call,                          
00073       SIPEndPoint & endpoint,                   
00074       const PString & token,                    
00075       const SIPURL & address,                   
00076       OpalTransport * transport,                
00077       unsigned int options = 0,                 
00078       OpalConnection::StringOptions * stringOptions = NULL  
00079     );
00080 
00083     ~SIPConnection();
00085 
00094     virtual PBoolean SetUpConnection();
00095 
00103     virtual PString GetDestinationAddress();
00104 
00108     virtual void TransferConnection(
00109       const PString & remoteParty,   
00110       const PString & callIdentity = PString::Empty()
00112     );
00113 
00116     virtual void HoldConnection();
00117 
00121     virtual void RetrieveConnection();
00122 
00125     virtual PBoolean IsConnectionOnHold();
00126 
00137     virtual PBoolean SetAlerting(
00138       const PString & calleeName,   
00139       PBoolean withMedia
00140     );
00141 
00146     virtual PBoolean SetConnected();
00147 
00150     virtual OpalMediaFormatList GetMediaFormats() const;
00151     
00154     virtual OpalMediaStreamPtr OpenMediaStream(
00155       const OpalMediaFormat & mediaFormat, 
00156       unsigned sessionID,                  
00157       bool isSource                        
00158     );
00159 
00164     virtual bool CloseMediaStream(
00165       OpalMediaStream & stream  
00166     );
00167 
00182     virtual OpalMediaStream * CreateMediaStream(
00183       const OpalMediaFormat & mediaFormat, 
00184       unsigned sessionID,                  
00185       PBoolean isSource                        
00186     );
00187         
00190     virtual void OnPatchMediaStream(PBoolean isSource, OpalMediaPatch & patch);
00191 
00192 
00203     void AnsweringCall(
00204       AnswerCallResponse response 
00205     );
00206 
00207 
00213     virtual PBoolean IsMediaBypassPossible(
00214       unsigned sessionID                  
00215     ) const;
00216 
00234     virtual void OnReleased();
00236 
00241     virtual void OnTransactionFailed(
00242       SIPTransaction & transaction
00243     );
00244 
00247     virtual void OnReceivedPDU(SIP_PDU & pdu);
00248 
00251     virtual void OnReceivedINVITE(SIP_PDU & pdu);
00252 
00255     virtual void OnReceivedReINVITE(SIP_PDU & pdu);
00256 
00259     virtual void OnReceivedACK(SIP_PDU & pdu);
00260   
00263     virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
00264 
00267     virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
00268 
00271     virtual void OnReceivedREFER(SIP_PDU & pdu);
00272   
00275     virtual void OnReceivedINFO(SIP_PDU & pdu);
00276 
00279     virtual void OnReceivedPING(SIP_PDU & pdu);
00280 
00283     virtual void OnReceivedBYE(SIP_PDU & pdu);
00284   
00287     virtual void OnReceivedCANCEL(SIP_PDU & pdu);
00288   
00291     virtual void OnReceivedResponse(
00292       SIPTransaction & transaction,
00293       SIP_PDU & response
00294     );
00295 
00298     virtual void OnReceivedTrying(SIP_PDU & pdu);
00299   
00302     virtual void OnReceivedRinging(SIP_PDU & pdu);
00303   
00306     virtual void OnReceivedSessionProgress(SIP_PDU & pdu);
00307   
00311     virtual PBoolean OnReceivedAuthenticationRequired(
00312       SIPTransaction & transaction,
00313       SIP_PDU & response
00314     );
00315   
00318     virtual void OnReceivedRedirection(SIP_PDU & pdu);
00319 
00323     virtual void OnReceivedOK(
00324       SIPTransaction & transaction,
00325       SIP_PDU & response
00326     );
00327   
00330     virtual void OnCreatingINVITE(SIP_PDU & pdu);
00331 
00339     virtual void OnRTPStatistics(
00340       const RTP_Session & session         
00341     ) const;
00343 
00344 
00354     virtual PBoolean ForwardCall(
00355       const PString & forwardParty   
00356     );
00357 
00363     virtual SendUserInputModes GetRealSendUserInputMode() const;
00364 
00381     PBoolean SendUserInputTone(char tone, unsigned duration);
00382     
00385     virtual PBoolean SendInviteOK(const SDPSessionDescription & sdp);
00386         
00389     virtual PBoolean SendInviteResponse(
00390       SIP_PDU::StatusCodes code,
00391       const char * contact = NULL,
00392       const char * extra = NULL,
00393       const SDPSessionDescription * sdp = NULL
00394     );
00395 
00399     virtual PBoolean SendPDU(SIP_PDU &, const OpalTransportAddress &);
00400 
00401     unsigned GetNextCSeq() { return ++lastSentCSeq; }
00402 
00403     OpalTransportAddress GetLocalAddress(WORD port = 0) const;
00404 
00405     OpalTransport & GetTransport() const { return *transport; }
00406 
00407     virtual PString GetLocalPartyAddress() const { return localPartyAddress; }
00408     virtual PString GetExplicitFrom() const;
00409 
00412     virtual void SetLocalPartyAddress();
00413     void SetLocalPartyAddress(
00414       const PString & addr
00415     ) { localPartyAddress = addr; }
00416 
00421     const PString GetRemotePartyCallbackURL() const;
00422 
00423     SIPEndPoint & GetEndPoint() const { return endpoint; }
00424     const SIPURL & GetTargetAddress() const { return targetAddress; }
00425     const PStringList & GetRouteSet() const { return routeSet; }
00426     const SIPAuthentication & GetAuthenticator() const { return authentication; }
00427 
00428     PBoolean OnOpenIncomingMediaChannels();
00429 
00430 #if OPAL_VIDEO
00431 
00436     virtual PBoolean OnMediaControlXML(SIP_PDU & pdu);
00437 #endif
00438 
00439     virtual void OnMediaCommand(OpalMediaCommand & note, INT extra);
00440 
00441   protected:
00442     PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseRetry);
00443     PDECLARE_NOTIFIER(PTimer, SIPConnection, OnAckTimeout);
00444 
00445     virtual RTP_UDP *OnUseRTPSession(
00446       const unsigned rtpSessionId,
00447       const OpalTransportAddress & mediaAddress,
00448       OpalTransportAddress & localAddress
00449     );
00450 
00451     virtual bool OnSendSDP(
00452       bool isAnswerSDP,
00453       RTP_SessionManager & rtpSessions,
00454       SDPSessionDescription & sdpOut
00455     );
00456     virtual bool OfferSDPMediaDescription(
00457       unsigned rtpSessionId,
00458       RTP_SessionManager & rtpSessions,
00459       SDPSessionDescription & sdpOut
00460     );
00461     virtual bool AnswerSDPMediaDescription(
00462       const SDPSessionDescription & sdpIn,
00463       SDPMediaDescription::MediaType mediaType,
00464       unsigned sessionId,
00465       SDPSessionDescription & sdpOut
00466     );
00467 
00468     virtual void OnReceivedSDP(
00469       SIP_PDU & pdu
00470     );
00471     virtual bool OnReceivedSDPMediaDescription(
00472       SDPSessionDescription & sdp,
00473       SDPMediaDescription::MediaType mediaType,
00474       unsigned sessionId
00475     );
00476     friend class SIPInvite;
00477     static PBoolean WriteINVITE(OpalTransport & transport, void * param);
00478 
00479     OpalTransport * CreateTransport(const OpalTransportAddress & address, PBoolean isLocalAddress = PFalse);
00480 
00481     void UpdateRemotePartyNameAndNumber();
00482 
00483     SIPEndPoint         & endpoint;
00484     OpalTransport       * transport;
00485 
00486     PMutex                transportMutex;
00487     bool                  local_hold;
00488     bool                  remote_hold;
00489     PString               localPartyAddress;
00490     PString               forwardParty;
00491 
00492     SIP_PDU               * originalInvite;
00493     PTime                 originalInviteTime;
00494 
00495     bool                  needReINVITE;
00496     PStringList           routeSet;
00497     SIPURL                targetAddress;
00498     SIPAuthentication     authentication;
00499 
00500     PTimer                    ackTimer;
00501     PTimer                    ackRetry;
00502     SIP_PDU                   ackPacket;
00503     bool                      ackReceived;
00504     PSafePtr<SIPTransaction>  referTransaction;
00505     PSafeList<SIPTransaction> forkedInvitations; // Not for re-INVITE
00506     PAtomicInteger            lastSentCSeq;
00507 
00508     enum {
00509       ReleaseWithBYE,
00510       ReleaseWithCANCEL,
00511       ReleaseWithResponse,
00512       ReleaseWithNothing,
00513     } releaseMethod;
00514 
00515     OpalMediaFormatList remoteFormatList;
00516 
00517     PString explicitFrom;
00518 
00519 #ifdef HAS_LIBZRTP
00520   public:
00521     zrtp_conn_ctx_t     *zrtpSession;
00522     virtual RTP_Session * CreateSession(const OpalTransport & transport, unsigned sessionID, RTP_QOS * rtpqos);
00523     virtual void ReleaseSession(unsigned sessionID,    
00524                                 PBoolean clearAll = PFalse  
00525                                );
00526 #endif
00527 };
00528 
00529 
00532 class SIP_RTP_Session : public RTP_UserData
00533 {
00534   PCLASSINFO(SIP_RTP_Session, RTP_UserData);
00535 
00540     SIP_RTP_Session(
00541       const SIPConnection & connection  
00542     );
00544 
00553     virtual void OnTxStatistics(
00554       const RTP_Session & session   
00555     ) const;
00556 
00563     virtual void OnRxStatistics(
00564       const RTP_Session & session   
00565     ) const;
00566 
00567 #if OPAL_VIDEO
00568 
00572     virtual void OnRxIntraFrameRequest(
00573       const RTP_Session & session   
00574     ) const;
00575 
00579     virtual void OnTxIntraFrameRequest(
00580       const RTP_Session & session   
00581     ) const;
00582 #endif
00583 
00584 
00585   protected:
00586     const SIPConnection & connection; 
00587 };
00588 
00589 
00590 #endif // __OPAL_SIPCON_H
00591 
00592 
00593 // End of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 07:36:39 2008 for OPAL by  doxygen 1.5.1