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: 21283 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-10-11 07:10:58 +0000 (Sat, 11 Oct 2008) $
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 #if OPAL_VIDEO
00047 #include <opal/pcss.h>                  // for OpalPCSSConnection
00048 #include <codec/vidcodec.h>             // for OpalVideoUpdatePicture command
00049 #endif
00050 
00051 class OpalCall;
00052 class SIPEndPoint;
00053 
00054 
00056 
00059 //class SIPConnection : public OpalConnection
00060 class SIPConnection : public OpalRTPConnection
00061 {
00062   PCLASSINFO(SIPConnection, OpalRTPConnection);
00063   public:
00064 
00069     SIPConnection(
00070       OpalCall & call,                          
00071       SIPEndPoint & endpoint,                   
00072       const PString & token,                    
00073       const SIPURL & address,                   
00074       OpalTransport * transport,                
00075       unsigned int options = 0,                 
00076       OpalConnection::StringOptions * stringOptions = NULL  
00077     );
00078 
00081     ~SIPConnection();
00083 
00094     virtual bool IsNetworkConnection() const { return true; }
00095 
00098     virtual PString GetPrefixName() const;
00099 
00106     virtual PString GetRemotePartyURL() const;
00107 
00114     virtual PBoolean SetUpConnection();
00115 
00122     virtual PString GetDestinationAddress();
00123 
00131     virtual PString GetCalledPartyURL();
00132 
00139     virtual bool TransferConnection(
00140       const PString & remoteParty   
00141     );
00142 
00145     virtual bool HoldConnection();
00146 
00150     virtual bool RetrieveConnection();
00151 
00154     virtual PBoolean IsConnectionOnHold();
00155 
00166     virtual PBoolean SetAlerting(
00167       const PString & calleeName,   
00168       PBoolean withMedia
00169     );
00170 
00175     virtual PBoolean SetConnected();
00176 
00179     virtual OpalMediaFormatList GetMediaFormats() const;
00180     
00183     virtual OpalMediaStreamPtr OpenMediaStream(
00184       const OpalMediaFormat & mediaFormat, 
00185       unsigned sessionID,                  
00186       bool isSource                        
00187     );
00188 
00193     virtual bool CloseMediaStream(
00194       OpalMediaStream & stream  
00195     );
00196 
00214     virtual void OnReleased();
00215 
00225     virtual PBoolean ForwardCall(
00226       const PString & forwardParty   
00227     );
00228 
00234     virtual SendUserInputModes GetRealSendUserInputMode() const;
00235 
00252     PBoolean SendUserInputTone(char tone, unsigned duration);
00253 
00261     virtual void OnRTPStatistics(
00262       const RTP_Session & session         
00263     ) const;
00265 
00270     virtual void OnTransactionFailed(
00271       SIPTransaction & transaction
00272     );
00273 
00276     virtual void OnReceivedPDU(SIP_PDU & pdu);
00277 
00280     virtual void OnReceivedINVITE(SIP_PDU & pdu);
00281 
00284     virtual void OnReceivedReINVITE(SIP_PDU & pdu);
00285 
00288     virtual void OnReceivedACK(SIP_PDU & pdu);
00289   
00292     virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
00293 
00296     virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
00297 
00300     virtual void OnReceivedREFER(SIP_PDU & pdu);
00301   
00304     virtual void OnReceivedINFO(SIP_PDU & pdu);
00305 
00308     virtual void OnReceivedPING(SIP_PDU & pdu);
00309 
00312     virtual void OnReceivedBYE(SIP_PDU & pdu);
00313   
00316     virtual void OnReceivedCANCEL(SIP_PDU & pdu);
00317   
00322     virtual void OnReceivedResponseToINVITE(
00323       SIPTransaction & transaction,
00324       SIP_PDU & response
00325     );
00326 
00329     virtual void OnReceivedResponse(
00330       SIPTransaction & transaction,
00331       SIP_PDU & response
00332     );
00333 
00336     virtual void OnReceivedTrying(SIP_PDU & pdu);
00337   
00340     virtual void OnReceivedRinging(SIP_PDU & pdu);
00341   
00344     virtual void OnReceivedSessionProgress(SIP_PDU & pdu);
00345   
00349     virtual PBoolean OnReceivedAuthenticationRequired(
00350       SIPTransaction & transaction,
00351       SIP_PDU & response
00352     );
00353   
00356     virtual void OnReceivedRedirection(SIP_PDU & pdu);
00357 
00361     virtual void OnReceivedOK(
00362       SIPTransaction & transaction,
00363       SIP_PDU & response
00364     );
00365   
00368     virtual void OnCreatingINVITE(SIP_PDU & pdu);
00369 
00372     virtual PBoolean SendInviteOK(const SDPSessionDescription & sdp);
00373         
00376     virtual PBoolean SendInviteResponse(
00377       SIP_PDU::StatusCodes code,
00378       const char * contact = NULL,
00379       const char * extra = NULL,
00380       const SDPSessionDescription * sdp = NULL
00381     );
00383 
00384     unsigned GetNextCSeq() { return ++lastSentCSeq; }
00385 
00386     OpalTransportAddress GetLocalAddress(WORD port = 0) const;
00387 
00388     OpalTransport & GetTransport() const { return *transport; }
00389 
00390     SIPEndPoint & GetEndPoint() const { return endpoint; }
00391     const SIPURL & GetRequestURI() const { return m_requestURI; }
00392     const PString & GetDialogFrom() const { return m_dialogFrom; }
00393     const PString & GetDialogTo() const { return m_dialogTo; }
00394     const PStringList & GetRouteSet() const { return routeSet; }
00395     SIPAuthentication * GetAuthenticator() const { return authentication; }
00396 
00397 #if OPAL_VIDEO
00398 
00403     virtual PBoolean OnMediaControlXML(SIP_PDU & pdu);
00404 #endif
00405 
00406     virtual void OnMediaCommand(OpalMediaCommand & note, INT extra);
00407 
00408   protected:
00409     PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseRetry);
00410     PDECLARE_NOTIFIER(PTimer, SIPConnection, OnAckTimeout);
00411 
00412     void AdjustOutgoingINVITE();
00413     virtual RTP_UDP *OnUseRTPSession(
00414       const unsigned rtpSessionId,
00415       const OpalMediaType & mediaType,
00416       const OpalTransportAddress & mediaAddress,
00417       OpalTransportAddress & localAddress
00418     );
00419 
00420     virtual bool OnSendSDP(
00421       bool isAnswerSDP,
00422       OpalRTPSessionManager & rtpSessions,
00423       SDPSessionDescription & sdpOut
00424     );
00425     virtual bool OfferSDPMediaDescription(
00426       const OpalMediaType & mediaType,
00427       unsigned sessionID,
00428       OpalRTPSessionManager & rtpSessions,
00429       SDPSessionDescription & sdpOut
00430     );
00431     virtual bool AnswerSDPMediaDescription(
00432       const SDPSessionDescription & sdpIn,
00433       unsigned sessionIndex,
00434       SDPSessionDescription & sdpOut
00435     );
00436 
00437     virtual void OnReceivedSDP(
00438       SIP_PDU & pdu
00439     );
00440     virtual bool OnReceivedSDPMediaDescription(
00441       SDPSessionDescription & sdp,
00442       unsigned sessionId
00443     );
00444     friend class SIPInvite;
00445     static PBoolean WriteINVITE(OpalTransport & transport, void * param);
00446 
00447     OpalTransport * CreateTransport(const OpalTransportAddress & address, PBoolean isLocalAddress = PFalse);
00448 
00449     void UpdateRemoteAddresses(const PString & addr);
00450 
00451     SIPEndPoint         & endpoint;
00452     OpalTransport       * transport;
00453     bool                  deleteTransport;
00454 
00455     enum HoldState {
00456       eHoldOff,
00457       eRetrieveInProgress,
00458 
00459       // Order is important!
00460       eHoldOn,
00461       eHoldInProgress
00462     };
00463     HoldState             m_holdToRemote;
00464     bool                  m_holdFromRemote;
00465     PString               forwardParty;
00466 
00467     SIP_PDU             * originalInvite;
00468     PTime                 originalInviteTime;
00469 
00470     bool                  needReINVITE;
00471     PStringList           routeSet;
00472     SIPURL                m_requestURI;
00473     PString               m_dialogFrom;
00474     PString               m_dialogTo;
00475     SIPAuthentication   * authentication;
00476 
00477     std::map<SIP_PDU::Methods, unsigned> m_lastRxCSeq;
00478 
00479     PTimer                    ackTimer;
00480     PTimer                    ackRetry;
00481     SIP_PDU                   ackPacket;
00482     bool                      ackReceived;
00483     PSafePtr<SIPTransaction>  referTransaction;
00484     PSafeList<SIPTransaction> forkedInvitations; // Not for re-INVITE
00485     PAtomicInteger            lastSentCSeq;
00486 
00487     enum {
00488       ReleaseWithBYE,
00489       ReleaseWithCANCEL,
00490       ReleaseWithResponse,
00491       ReleaseWithNothing,
00492     } releaseMethod;
00493 
00494     OpalMediaFormatList remoteFormatList;
00495 
00496   protected:
00497     PTimer sessionTimer;
00498   public:
00499     PDECLARE_NOTIFIER(PTimer, SIPConnection, OnSessionTimeout);
00500 };
00501 
00502 
00505 class SIP_RTP_Session : public RTP_UserData
00506 {
00507   PCLASSINFO(SIP_RTP_Session, RTP_UserData);
00508 
00513     SIP_RTP_Session(
00514       const SIPConnection & connection  
00515     );
00517 
00526     virtual void OnTxStatistics(
00527       const RTP_Session & session   
00528     ) const;
00529 
00536     virtual void OnRxStatistics(
00537       const RTP_Session & session   
00538     ) const;
00539 
00540 #if OPAL_VIDEO
00541 
00545     virtual void OnRxIntraFrameRequest(
00546       const RTP_Session & session   
00547     ) const;
00548 
00552     virtual void OnTxIntraFrameRequest(
00553       const RTP_Session & session   
00554     ) const;
00555 #endif
00556 
00557 
00558     void OnClearCall(const RTP_Session & /*session*/);
00559 
00560   protected:
00561     const SIPConnection & connection; 
00562 };
00563 
00564 
00565 #endif // OPAL_SIP
00566 
00567 #endif // OPAL_SIP_SIPCON_H
00568 
00569 
00570 // End of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 23 02:01:39 2009 for OPAL by  doxygen 1.5.1