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  * $Log: sipcon.h,v $
00028  * Revision 2.41.2.2  2006/03/08 21:55:59  dsandras
00029  * Forgot to commit this file. Sorry.
00030  *
00031  * Revision 2.41.2.1  2006/02/11 13:32:24  csoutheren
00032  * Backported fixed from CVS head
00033  *
00034  * Revision 2.42  2006/02/10 23:44:03  csoutheren
00035  * Applied fix for SetConnection and RFC2833 startup
00036  *
00037  * Revision 2.41  2006/01/02 14:47:28  dsandras
00038  * More code cleanups.
00039  *
00040  * Revision 2.40  2005/11/30 13:35:26  csoutheren
00041  * Changed tags for Doxygen
00042  *
00043  * Revision 2.39  2005/10/22 12:16:05  dsandras
00044  * Moved mutex preventing media streams to be opened before they are completely closed to the SIPConnection class.
00045  *
00046  * Revision 2.38  2005/10/13 19:33:50  dsandras
00047  * Added GetDirection to get the default direction for a media stream. Modified OnSendMediaDescription to call BuildSDP if no reverse streams can be opened.
00048  *
00049  * Revision 2.37  2005/10/04 12:57:18  rjongbloed
00050  * Removed CanOpenSourceMediaStream/CanOpenSinkMediaStream functions and
00051  *   now use overides on OpenSourceMediaStream/OpenSinkMediaStream
00052  *
00053  * Revision 2.36  2005/09/27 16:03:46  dsandras
00054  * Removed SendResponseToInvite and added SendPDU function that will change the transport address right before sending the PDU. This operation is atomic.
00055  *
00056  * Revision 2.35  2005/09/15 17:08:36  dsandras
00057  * Added support for CanOpen[Source|Sink]MediaStream.
00058  *
00059  * Revision 2.34  2005/08/25 18:49:52  dsandras
00060  * Added SIP Video support. Changed API of BuildSDP to allow it to be called
00061  * for both audio and video.
00062  *
00063  * Revision 2.33  2005/07/11 01:52:24  csoutheren
00064  * Extended AnsweringCall to work for SIP as well as H.323
00065  * Fixed problems with external RTP connection in H.323
00066  * Added call to OnClosedMediaStream
00067  *
00068  * Revision 2.32  2005/05/06 07:37:06  csoutheren
00069  * Various changed while working with SIP carrier
00070  *   - remove assumption that authentication realm is a domain name.
00071  *   - stopped rewrite of "To" field when proxy being used
00072  *   - fix Contact field in REGISTER to match actual port used when Symmetric NATin use
00073  *   - lots of formatting changes and cleanups
00074  *
00075  * Revision 2.31  2005/04/28 20:22:53  dsandras
00076  * Applied big sanity patch for SIP thanks to Ted Szoczei <tszoczei@microtronix.ca>.
00077  * Thanks a lot!
00078  *
00079  * Revision 2.30  2005/04/10 20:59:42  dsandras
00080  * Added call hold support (local and remote).
00081  *
00082  * Revision 2.29  2005/04/10 20:58:21  dsandras
00083  * Added function to handle incoming transfer (REFER).
00084  *
00085  * Revision 2.28  2005/04/10 20:57:18  dsandras
00086  * Added support for Blind Transfer (transfering and being transfered)
00087  *
00088  * Revision 2.27  2005/04/10 20:54:35  dsandras
00089  * Added function that returns the "best guess" callback URL of a connection.
00090  *
00091  * Revision 2.26  2005/02/19 22:48:48  dsandras
00092  * Added the possibility to register to several registrars and be able to do authenticated calls to each of them. Added SUBSCRIBE/NOTIFY support for Message Waiting Indications.
00093  *
00094  * Revision 2.25  2005/01/16 11:28:05  csoutheren
00095  * Added GetIdentifier virtual function to OpalConnection, and changed H323
00096  * and SIP descendants to use this function. This allows an application to
00097  * obtain a GUID for any connection regardless of the protocol used
00098  *
00099  * Revision 2.24  2004/12/25 20:43:41  dsandras
00100  * Attach the RFC2833 handlers when we are in connected state to ensure
00101  * OpalMediaPatch exist. Fixes problem for DTMF sending.
00102  *
00103  * Revision 2.23  2004/12/22 18:53:18  dsandras
00104  * Added definition for ForwardCall.
00105  *
00106  * Revision 2.22  2004/08/20 12:13:31  rjongbloed
00107  * Added correct handling of SIP 180 response
00108  *
00109  * Revision 2.21  2004/08/14 07:56:30  rjongbloed
00110  * Major revision to utilise the PSafeCollection classes for the connections and calls.
00111  *
00112  * Revision 2.20  2004/04/26 05:40:38  rjongbloed
00113  * Added RTP statistics callback to SIP
00114  *
00115  * Revision 2.19  2004/03/14 10:09:53  rjongbloed
00116  * Moved transport on SIP top be constructed by endpoint as any transport created on
00117  *   an endpoint can receive data for any connection.
00118  *
00119  * Revision 2.18  2004/03/13 06:30:03  rjongbloed
00120  * Changed parameter in UDP write function to void * from PObject *.
00121  *
00122  * Revision 2.17  2004/02/24 11:33:46  rjongbloed
00123  * Normalised RTP session management across protocols
00124  * Added support for NAT (via STUN)
00125  *
00126  * Revision 2.16  2004/02/07 02:20:32  rjongbloed
00127  * Changed to allow opening of more than just audio streams.
00128  *
00129  * Revision 2.15  2003/12/20 12:21:18  rjongbloed
00130  * Applied more enhancements, thank you very much Ted Szoczei
00131  *
00132  * Revision 2.14  2003/03/17 10:26:59  robertj
00133  * Added video support.
00134  *
00135  * Revision 2.13  2003/03/06 03:57:47  robertj
00136  * IVR support (work in progress) requiring large changes everywhere.
00137  *
00138  * Revision 2.12  2002/09/16 02:52:35  robertj
00139  * Added #define so can select if #pragma interface/implementation is used on
00140  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00141  *
00142  * Revision 2.11  2002/04/16 07:53:15  robertj
00143  * Changes to support calls through proxies.
00144  *
00145  * Revision 2.10  2002/04/10 03:13:45  robertj
00146  * Moved code for handling media bypass address resolution into ancestor as
00147  *   now done ths same way in both SIP and H.323.
00148  * Major changes to RTP session management when initiating an INVITE.
00149  *
00150  * Revision 2.9  2002/04/09 01:02:14  robertj
00151  * Fixed problems with restarting INVITE on  authentication required response.
00152  *
00153  * Revision 2.8  2002/04/08 02:40:13  robertj
00154  * Fixed issues with using double originate call, eg from simple app command line.
00155  *
00156  * Revision 2.7  2002/04/05 10:42:04  robertj
00157  * Major changes to support transactions (UDP timeouts and retries).
00158  *
00159  * Revision 2.6  2002/03/15 10:55:28  robertj
00160  * Added ability to specify proxy username/password in URL.
00161  *
00162  * Revision 2.5  2002/03/08 06:28:19  craigs
00163  * Changed to allow Authorisation to be included in other PDUs
00164  *
00165  * Revision 2.4  2002/02/19 07:52:40  robertj
00166  * Restructured media bypass functions to fix problems with RFC2833.
00167  *
00168  * Revision 2.3  2002/02/13 04:55:59  craigs
00169  * Fixed problem with endless loop if proxy keeps failing authentication with 407
00170  *
00171  * Revision 2.2  2002/02/11 07:34:06  robertj
00172  * Changed SDP to use OpalTransport for hosts instead of IP addresses/ports
00173  * Added media bypass for streams between compatible protocols.
00174  *
00175  * Revision 2.1  2002/02/01 04:53:01  robertj
00176  * Added (very primitive!) SIP support.
00177  *
00178  */
00179 
00180 #ifndef __OPAL_SIPCON_H
00181 #define __OPAL_SIPCON_H
00182 
00183 #ifdef P_USE_PRAGMA
00184 #pragma interface
00185 #endif
00186 
00187 
00188 #include <opal/connection.h>
00189 #include <sip/sippdu.h>
00190 
00191 
00192 class OpalCall;
00193 class SIPEndPoint;
00194 
00195 
00197 
00200 class SIPConnection : public OpalConnection
00201 {
00202   PCLASSINFO(SIPConnection, OpalConnection);
00203   public:
00204 
00209     SIPConnection(
00210       OpalCall & call,            
00211       SIPEndPoint & endpoint,     
00212       const PString & token,      
00213       const SIPURL & address,     
00214       OpalTransport * transport   
00215     );
00216 
00219     ~SIPConnection();
00221 
00230     virtual BOOL SetUpConnection();
00231 
00235     virtual void TransferConnection(
00236       const PString & remoteParty,   
00237       const PString & callIdentity = PString::Empty()
00239     );
00240 
00243     virtual void HoldConnection();
00244 
00248     virtual void RetrieveConnection();
00249 
00252     virtual BOOL IsConnectionOnHold();
00253 
00264     virtual BOOL SetAlerting(
00265       const PString & calleeName,   
00266       BOOL withMedia
00267     );
00268 
00273     virtual BOOL SetConnected();
00274 
00277     virtual OpalMediaFormatList GetMediaFormats() const;
00278     
00281     virtual BOOL OpenSourceMediaStream(
00282       const OpalMediaFormatList & mediaFormats, 
00283       unsigned sessionID                   
00284     );
00285 
00288     virtual OpalMediaStream * OpenSinkMediaStream(
00289       OpalMediaStream & source    
00290     );
00291 
00306     virtual OpalMediaStream * CreateMediaStream(
00307       const OpalMediaFormat & mediaFormat, 
00308       unsigned sessionID,                  
00309       BOOL isSource                        
00310     );
00311 
00312 
00328     virtual OpalConnection::AnswerCallResponse OnAnswerCall(
00329       const PString & callerName      
00330     );
00331 
00342     void AnsweringCall(
00343       AnswerCallResponse response 
00344     );
00345 
00346 
00358     virtual void OnConnected();
00359 
00365     virtual BOOL IsMediaBypassPossible(
00366       unsigned sessionID                  
00367     ) const;
00368 
00386     virtual void OnReleased();
00388 
00393     virtual void OnTransactionFailed(
00394       SIPTransaction & transaction
00395     );
00396 
00399     virtual void OnReceivedPDU(SIP_PDU & pdu);
00400 
00403     virtual void OnReceivedINVITE(SIP_PDU & pdu);
00404 
00407     virtual void OnReceivedACK(SIP_PDU & pdu);
00408   
00411     virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
00412 
00415     virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
00416 
00419     virtual void OnReceivedREFER(SIP_PDU & pdu);
00420   
00423     virtual void OnReceivedBYE(SIP_PDU & pdu);
00424   
00427     virtual void OnReceivedCANCEL(SIP_PDU & pdu);
00428   
00431     virtual void OnReceivedResponse(
00432       SIPTransaction & transaction,
00433       SIP_PDU & response
00434     );
00435 
00438     virtual void OnReceivedTrying(SIP_PDU & pdu);
00439   
00442     virtual void OnReceivedRinging(SIP_PDU & pdu);
00443   
00446     virtual void OnReceivedSessionProgress(SIP_PDU & pdu);
00447   
00450     virtual void OnReceivedAuthenticationRequired(
00451       SIPTransaction & transaction,
00452       SIP_PDU & response
00453     );
00454   
00457     virtual void OnReceivedRedirection(SIP_PDU & pdu);
00458 
00462     virtual void OnReceivedOK(
00463       SIPTransaction & transaction,
00464       SIP_PDU & response
00465     );
00466   
00474     void QueuePDU(
00475       SIP_PDU * pdu
00476     );
00477 
00485     virtual void OnRTPStatistics(
00486       const RTP_Session & session         
00487     ) const;
00489 
00490 
00500     virtual BOOL ForwardCall(
00501       const PString & forwardParty   
00502     );
00503     
00507     BOOL SendPDU(SIP_PDU &, const OpalTransportAddress &);
00508 
00509     unsigned GetNextCSeq() { return ++lastSentCSeq; }
00510 
00511     BOOL BuildSDP(
00512       SDPSessionDescription * &,                             
00513       RTP_SessionManager & rtpSessions,
00514       unsigned rtpSessionId
00515     );
00516 
00517         SIPTransaction * GetTransaction (PString transactionID) { return transactions.GetAt(transactionID); }
00518 
00519     void AddTransaction(
00520       SIPTransaction * transaction
00521     ) { transactions.SetAt(transaction->GetTransactionID(), transaction); }
00522 
00523     void RemoveTransaction(
00524       SIPTransaction * transaction
00525     ) { transactions.SetAt(transaction->GetTransactionID(), NULL); }
00526 
00527 
00528     OpalTransportAddress GetLocalAddress(WORD port = 0) const;
00529 
00530     OpalTransport & GetTransport() const { return *transport; }
00531 
00532     PString GetLocalPartyAddress() const { return localPartyAddress; }
00533 
00536     void SetLocalPartyAddress();
00537     void SetLocalPartyAddress(
00538       const PString & addr
00539     ) { localPartyAddress = addr; }
00540 
00545     const PString GetRemotePartyCallbackURL() const;
00546 
00547     PString GetTag() const { return GetIdentifier().AsString(); }
00548     SIPEndPoint & GetEndPoint() const { return endpoint; }
00549     const SIPURL & GetTargetAddress() const { return targetAddress; }
00550     const PStringList & GetRouteSet() const { return routeSet; }
00551     const SIPAuthentication & GetAuthenticator() const { return authentication; }
00552 
00553   protected:
00554     PDECLARE_NOTIFIER(PThread, SIPConnection, HandlePDUsThreadMain);
00555     virtual RTP_UDP *OnUseRTPSession(
00556       const unsigned rtpSessionId,
00557       const OpalTransportAddress & mediaAddress,
00558       OpalTransportAddress & localAddress
00559     );
00560     virtual void OnReceivedSDP(SIP_PDU & pdu);
00561     virtual BOOL OnReceivedSDPMediaDescription(
00562       SDPSessionDescription & sdp,
00563       SDPMediaDescription::MediaType mediaType,
00564       unsigned sessionId
00565     );
00566     virtual BOOL OnSendSDPMediaDescription(
00567       const SDPSessionDescription & sdpIn,
00568       SDPMediaDescription::MediaType mediaType,
00569       unsigned sessionId,
00570       SDPSessionDescription & sdpOut
00571     );
00572     virtual BOOL OnOpenSourceMediaStreams(
00573       const OpalMediaFormatList & remoteFormatList,
00574       unsigned sessionId,
00575       SDPMediaDescription *localMedia
00576     );
00577     SDPMediaDescription::Direction GetDirection(unsigned sessionId);
00578     static BOOL WriteINVITE(OpalTransport & transport, void * param);
00579 
00580     void InitRFC2833Handler();
00581 
00582     SIPEndPoint         & endpoint;
00583     OpalTransport       * transport;
00584     OpalTransportAddress  lastTransportAddress;
00585 
00586     PMutex                transportMutex;
00587     PMutex                streamsMutex;
00588     BOOL                  local_hold;
00589     BOOL                  remote_hold;
00590     PString               localPartyAddress;
00591     PString               forwardParty;
00592     SIP_PDU             * originalInvite;
00593     SDPSessionDescription remoteSDP;
00594     PStringList           routeSet;
00595     SIPURL                targetAddress;
00596     SIPAuthentication     authentication;
00597 
00598     SIP_PDU_Queue pduQueue;
00599     PSemaphore    pduSemaphore;
00600     PThread     * pduHandler;
00601 
00602     SIPTransaction   * referTransaction;
00603     SIPTransactionList invitations;
00604     SIPTransactionDict transactions;
00605     unsigned           lastSentCSeq;
00606 
00607     enum {
00608       ReleaseWithBYE,
00609       ReleaseWithCANCEL,
00610       ReleaseWithResponse,
00611       ReleaseWithNothing,
00612     } releaseMethod;
00613 
00614     OpalMediaFormatList remoteFormatList;
00615 };
00616 
00617 
00620 class SIP_RTP_Session : public RTP_UserData
00621 {
00622   PCLASSINFO(SIP_RTP_Session, RTP_UserData);
00623 
00628     SIP_RTP_Session(
00629       const SIPConnection & connection  
00630     );
00632 
00641     virtual void OnTxStatistics(
00642       const RTP_Session & session   
00643     ) const;
00644 
00651     virtual void OnRxStatistics(
00652       const RTP_Session & session   
00653     ) const;
00655 
00656 
00657   protected:
00658     const SIPConnection & connection; 
00659 };
00660 
00661 
00662 #endif // __OPAL_SIPCON_H
00663 
00664 
00665 // End of File ///////////////////////////////////////////////////////////////

Generated on Mon Sep 25 16:20:10 2006 for OPAL by  doxygen 1.4.7