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: 19970 $
00028  * $Author: csoutheren $
00029  * $Date: 2008-04-11 05:20:10 +0000 (Fri, 11 Apr 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   
00293     virtual void OnReceivedResponseToINVITE(
00294       SIPTransaction & transaction,
00295       SIP_PDU & response
00296     );
00297 
00300     virtual void OnReceivedResponse(
00301       SIPTransaction & transaction,
00302       SIP_PDU & response
00303     );
00304 
00307     virtual void OnReceivedTrying(SIP_PDU & pdu);
00308   
00311     virtual void OnReceivedRinging(SIP_PDU & pdu);
00312   
00315     virtual void OnReceivedSessionProgress(SIP_PDU & pdu);
00316   
00320     virtual PBoolean OnReceivedAuthenticationRequired(
00321       SIPTransaction & transaction,
00322       SIP_PDU & response
00323     );
00324   
00327     virtual void OnReceivedRedirection(SIP_PDU & pdu);
00328 
00332     virtual void OnReceivedOK(
00333       SIPTransaction & transaction,
00334       SIP_PDU & response
00335     );
00336   
00339     virtual void OnCreatingINVITE(SIP_PDU & pdu);
00340 
00348     virtual void OnRTPStatistics(
00349       const RTP_Session & session         
00350     ) const;
00352 
00353 
00363     virtual PBoolean ForwardCall(
00364       const PString & forwardParty   
00365     );
00366 
00372     virtual SendUserInputModes GetRealSendUserInputMode() const;
00373 
00390     PBoolean SendUserInputTone(char tone, unsigned duration);
00391     
00394     virtual PBoolean SendInviteOK(const SDPSessionDescription & sdp);
00395         
00398     virtual PBoolean SendInviteResponse(
00399       SIP_PDU::StatusCodes code,
00400       const char * contact = NULL,
00401       const char * extra = NULL,
00402       const SDPSessionDescription * sdp = NULL
00403     );
00404 
00408     virtual PBoolean SendPDU(SIP_PDU &, const OpalTransportAddress &);
00409 
00410     unsigned GetNextCSeq() { return ++lastSentCSeq; }
00411 
00412     OpalTransportAddress GetLocalAddress(WORD port = 0) const;
00413 
00414     OpalTransport & GetTransport() const { return *transport; }
00415 
00416     void AdjustOutgoingINVITE();
00417 
00422     const PString GetRemotePartyCallbackURL() const;
00423 
00424     SIPEndPoint & GetEndPoint() const { return endpoint; }
00425     const SIPURL & GetRequestURI() const { return m_requestURI; }
00426     const PString & GetDialogFrom() const { return m_dialogFrom; }
00427     const PString & GetDialogTo() const { return m_dialogTo; }
00428     const PStringList & GetRouteSet() const { return routeSet; }
00429     const SIPAuthentication & GetAuthenticator() const { return authentication; }
00430 
00431     PBoolean OnOpenIncomingMediaChannels();
00432 
00433 #if OPAL_VIDEO
00434 
00439     virtual PBoolean OnMediaControlXML(SIP_PDU & pdu);
00440 #endif
00441 
00442     virtual void OnMediaCommand(OpalMediaCommand & note, INT extra);
00443 
00444   protected:
00445     PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseRetry);
00446     PDECLARE_NOTIFIER(PTimer, SIPConnection, OnAckTimeout);
00447 
00448     virtual RTP_UDP *OnUseRTPSession(
00449       const unsigned rtpSessionId,
00450       const OpalTransportAddress & mediaAddress,
00451       OpalTransportAddress & localAddress
00452     );
00453 
00454     virtual bool OnSendSDP(
00455       bool isAnswerSDP,
00456       RTP_SessionManager & rtpSessions,
00457       SDPSessionDescription & sdpOut
00458     );
00459     virtual bool OfferSDPMediaDescription(
00460       unsigned rtpSessionId,
00461       RTP_SessionManager & rtpSessions,
00462       SDPSessionDescription & sdpOut
00463     );
00464     virtual bool AnswerSDPMediaDescription(
00465       const SDPSessionDescription & sdpIn,
00466       SDPMediaDescription::MediaType mediaType,
00467       unsigned sessionId,
00468       SDPSessionDescription & sdpOut
00469     );
00470 
00471     virtual void OnReceivedSDP(
00472       SIP_PDU & pdu
00473     );
00474     virtual bool OnReceivedSDPMediaDescription(
00475       SDPSessionDescription & sdp,
00476       SDPMediaDescription::MediaType mediaType,
00477       unsigned sessionId
00478     );
00479     friend class SIPInvite;
00480     static PBoolean WriteINVITE(OpalTransport & transport, void * param);
00481 
00482     OpalTransport * CreateTransport(const OpalTransportAddress & address, PBoolean isLocalAddress = PFalse);
00483 
00484     void UpdateRemoteAddresses(const PString & addr);
00485 
00486     SIPEndPoint         & endpoint;
00487     OpalTransport       * transport;
00488 
00489     PMutex                transportMutex;
00490     bool                  local_hold;
00491     bool                  remote_hold;
00492     PString               forwardParty;
00493 
00494     SIP_PDU             * originalInvite;
00495     PTime                 originalInviteTime;
00496 
00497     bool                  needReINVITE;
00498     PStringList           routeSet;
00499     SIPURL                m_requestURI;
00500     PString               m_dialogFrom;
00501     PString               m_dialogTo;
00502     SIPAuthentication     authentication;
00503 
00504     PTimer                    ackTimer;
00505     PTimer                    ackRetry;
00506     SIP_PDU                   ackPacket;
00507     bool                      ackReceived;
00508     PSafePtr<SIPTransaction>  referTransaction;
00509     PSafeList<SIPTransaction> forkedInvitations; // Not for re-INVITE
00510     PAtomicInteger            lastSentCSeq;
00511 
00512     enum {
00513       ReleaseWithBYE,
00514       ReleaseWithCANCEL,
00515       ReleaseWithResponse,
00516       ReleaseWithNothing,
00517     } releaseMethod;
00518 
00519     OpalMediaFormatList remoteFormatList;
00520 
00521 #ifdef HAS_LIBZRTP
00522   public:
00523     zrtp_conn_ctx_t     *zrtpSession;
00524     virtual RTP_Session * CreateSession(const OpalTransport & transport, unsigned sessionID, RTP_QOS * rtpqos);
00525     virtual void ReleaseSession(unsigned sessionID,    
00526                                 PBoolean clearAll = PFalse  
00527                                );
00528 #endif
00529 };
00530 
00531 
00534 class SIP_RTP_Session : public RTP_UserData
00535 {
00536   PCLASSINFO(SIP_RTP_Session, RTP_UserData);
00537 
00542     SIP_RTP_Session(
00543       const SIPConnection & connection  
00544     );
00546 
00555     virtual void OnTxStatistics(
00556       const RTP_Session & session   
00557     ) const;
00558 
00565     virtual void OnRxStatistics(
00566       const RTP_Session & session   
00567     ) const;
00568 
00569 #if OPAL_VIDEO
00570 
00574     virtual void OnRxIntraFrameRequest(
00575       const RTP_Session & session   
00576     ) const;
00577 
00581     virtual void OnTxIntraFrameRequest(
00582       const RTP_Session & session   
00583     ) const;
00584 #endif
00585 
00586 
00587   protected:
00588     const SIPConnection & connection; 
00589 };
00590 
00591 
00592 #endif // __OPAL_SIPCON_H
00593 
00594 
00595 // End of File ///////////////////////////////////////////////////////////////

Generated on Wed May 7 00:56:03 2008 for OPAL by  doxygen 1.5.1