Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

sipep.h

Go to the documentation of this file.
00001 /*
00002  * sipep.h
00003  *
00004  * Session Initiation Protocol endpoint.
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: sipep.h,v $
00028  * Revision 2.46.2.8  2006/04/30 17:26:22  dsandras
00029  * Backported various HEAD cleanups.
00030  *
00031  * Revision 2.58  2006/04/30 17:24:39  dsandras
00032  * Various clean ups.
00033  *
00034  * Revision 2.46.2.7  2006/04/11 21:59:46  dsandras
00035  * More backports from HEAD.
00036  *
00037  * Revision 2.57  2006/04/11 21:58:25  dsandras
00038  * Various cleanups and fixes. Fixes Ekiga report #336444.
00039  *
00040  * Revision 2.46.2.6  2006/03/27 20:29:55  dsandras
00041  * Backports from HEAD.
00042  *
00043  * Revision 2.56  2006/03/27 20:28:18  dsandras
00044  * Added mutex to fix concurrency issues between OnReceivedPDU which checks
00045  * if a connection is in the list, and OnReceivedINVITE, which adds it to the
00046  * list. Fixes Ekiga report #334847. Thanks Robert for your input on this!
00047  * 
00048  * Revision 2.46.2.5  2006/03/19 18:59:02  dsandras
00049  * More backports from HEAD.
00050  *
00051  * Revision 2.55  2006/03/19 18:57:06  dsandras
00052  * More work on Ekiga report #334999.
00053  *
00054  * Revision 2.46.2.4  2006/03/19 18:15:59  dsandras
00055  * Backports from HEAD.
00056  *
00057  * Revision 2.54  2006/03/19 17:26:15  dsandras
00058  * Fixed FindSIPInfoByDomain so that it doesn't return unregistered accounts.
00059  * Fixes Ekiga report #335006.
00060  *
00061  * Revision 2.53  2006/03/19 12:32:05  dsandras
00062  * RFC3261 says that "CANCEL messages "SHOULD NOT" be sent for anything but INVITE
00063  * requests". Fixes Ekiga report #334985.
00064  *
00065  * Revision 2.52  2006/03/19 11:45:47  dsandras
00066  * The remote address of the registrar transport might have changed due
00067  * to the Via field. This affected unregistering which was reusing
00068  * the exact same transport to unregister. Fixed Ekiga report #334999.
00069  * Revision 2.46.2.3  2006/03/06 19:04:39  dsandras
00070  * Backports from HEAD.
00071  *
00072  * Revision 2.50  2006/03/06 19:01:30  dsandras
00073  * Allow registering several accounts with the same realm but different
00074  * user names to the same provider. Fixed possible crash due to transport
00075  * deletion before the transaction is over.
00076  *
00077  * Revision 2.46.2.2  2006/02/19 11:53:22  dsandras
00078  * More backports from HEAD.
00079  *
00080  * Revision 2.48  2006/02/19 11:51:46  dsandras
00081  * Fixed FindSIPInfoByDomain.
00082  *
00083  * Revision 2.46.2.1  2006/01/29 21:01:40  dsandras
00084  * Backports from CVS HEAD.
00085  *
00086  * Revision 2.47  2006/01/29 20:55:32  dsandras
00087  * Allow using a simple username or a fill url when registering.
00088  *
00089  * Revision 2.46  2006/01/08 21:53:40  dsandras
00090  * Changed IsRegistered so that it takes the registration url as argument,
00091  * allowing it to work when there are several accounts on the same server.
00092  *
00093  * Revision 2.45  2006/01/08 14:43:46  dsandras
00094  * Improved the NAT binding refresh methods so that it works with all endpoint
00095  * created transports that require it and so that it can work by sending
00096  * SIP Options, or empty SIP requests. More methods can be added later.
00097  *
00098  * Revision 2.44  2006/01/02 11:28:07  dsandras
00099  * Some documentation. Various code cleanups to prevent duplicate code.
00100  *
00101  * Revision 2.43  2005/12/18 21:06:56  dsandras
00102  * Added function to clean up the registrations object. Moved DeleteObjectsToBeRemoved call outside of the loop.
00103  *
00104  * Revision 2.42  2005/12/14 17:59:50  dsandras
00105  * Added ForwardConnection executed when the remote asks for a call forwarding.
00106  * Similar to what is done in the H.323 part with the method of the same name.
00107  *
00108  * Revision 2.41  2005/12/11 19:14:20  dsandras
00109  * Added support for setting a different user name and authentication user name
00110  * as required by some providers like digisip.
00111  *
00112  * Revision 2.40  2005/12/08 21:14:54  dsandras
00113  * Added function allowing to change the nat binding refresh timeout.
00114  *
00115  * Revision 2.39  2005/12/05 22:20:57  dsandras
00116  * Update the transport when the computer is behind NAT, using STUN, the IP
00117  * address has changed compared to the original transport and a registration
00118  * refresh must occur.
00119  *
00120  * Revision 2.38  2005/12/04 22:08:58  dsandras
00121  * Added possibility to provide an expire time when registering, if not
00122  * the default expire time for the endpoint will be used.
00123  *
00124  * Revision 2.37  2005/11/30 13:35:26  csoutheren
00125  * Changed tags for Doxygen
00126  *
00127  * Revision 2.36  2005/11/28 19:07:56  dsandras
00128  * Moved OnNATTimeout to SIPInfo and use it for active conversations too.
00129  * Added E.164 support.
00130  *
00131  * Revision 2.35  2005/10/30 23:01:29  dsandras
00132  * Added possibility to have a body for SIPInfo. Moved MESSAGE sending to SIPInfo for more efficiency during conversations.
00133  *
00134  * Revision 2.34  2005/10/22 17:14:45  dsandras
00135  * Send an OPTIONS request periodically when STUN is being used to maintain the registrations binding alive.
00136  *
00137  * Revision 2.33  2005/10/20 20:26:58  dsandras
00138  * Made the transactions handling thread-safe.
00139  *
00140  * Revision 2.32  2005/10/02 21:46:20  dsandras
00141  * Added more doc.
00142  *
00143  * Revision 2.31  2005/10/02 17:47:37  dsandras
00144  * Added function to return the translated contact address of the endpoint.
00145  * Added some doc.
00146  *
00147  * Revision 2.30  2005/05/23 20:14:05  dsandras
00148  * Added preliminary support for basic instant messenging.
00149  *
00150  * Revision 2.29  2005/05/06 07:37:06  csoutheren
00151  * Various changed while working with SIP carrier
00152  *   - remove assumption that authentication realm is a domain name.
00153  *   - stopped rewrite of "To" field when proxy being used
00154  *   - fix Contact field in REGISTER to match actual port used when Symmetric NATin use
00155  *   - lots of formatting changes and cleanups
00156  *
00157  * Revision 2.28  2005/05/03 20:41:51  dsandras
00158  * Do not count SUBSCRIBEs when returning the number of registered accounts.
00159  *
00160  * Revision 2.27  2005/04/28 20:22:53  dsandras
00161  * Applied big sanity patch for SIP thanks to Ted Szoczei <tszoczei@microtronix.ca>.
00162  * Thanks a lot!
00163  *
00164  * Revision 2.25  2005/04/26 19:50:54  dsandras
00165  * Added function to return the number of registered accounts.
00166  *
00167  * Revision 2.24  2005/04/10 21:01:09  dsandras
00168  * Added Blind Transfer support.
00169  *
00170  * Revision 2.23  2005/03/11 18:12:08  dsandras
00171  * Added support to specify the realm when registering. That way softphones already know what authentication information to use when required. The realm/domain can also be used in the From field.
00172  *
00173  * Revision 2.22  2005/02/19 22:48:48  dsandras
00174  * 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.
00175  *
00176  * Revision 2.21  2004/12/17 12:06:52  dsandras
00177  * Added error code to OnRegistrationFailed. Made Register/Unregister wait until the transaction is over. Fixed Unregister so that the SIPRegister is used as a pointer or the object is deleted at the end of the function and make Opal crash when transactions are cleaned. Reverted part of the patch that was sending authentication again when it had already been done on a Register.
00178  *
00179  * Revision 2.20  2004/12/12 12:30:09  dsandras
00180  * Added virtual function called when registration to a registrar fails.
00181  *
00182  * Revision 2.19  2004/11/29 08:18:31  csoutheren
00183  * Added support for setting the SIP authentication domain/realm as needed for many service
00184  *  providers
00185  *
00186  * Revision 2.18  2004/10/02 04:30:10  rjongbloed
00187  * Added unregister function for SIP registrar
00188  *
00189  * Revision 2.17  2004/08/22 12:27:44  rjongbloed
00190  * More work on SIP registration, time to live refresh and deregistration on exit.
00191  *
00192  * Revision 2.16  2004/08/14 07:56:30  rjongbloed
00193  * Major revision to utilise the PSafeCollection classes for the connections and calls.
00194  *
00195  * Revision 2.15  2004/07/11 12:42:10  rjongbloed
00196  * Added function on endpoints to get the list of all media formats any
00197  *   connection the endpoint may create can support.
00198  *
00199  * Revision 2.14  2004/06/05 14:36:32  rjongbloed
00200  * Added functions to get registration URL.
00201  * Added ability to set proxy bu host/user/password strings.
00202  *
00203  * Revision 2.13  2004/04/26 06:30:33  rjongbloed
00204  * Added ability to specify more than one defualt listener for an endpoint,
00205  *   required by SIP which listens on both UDP and TCP.
00206  *
00207  * Revision 2.12  2004/04/26 05:40:38  rjongbloed
00208  * Added RTP statistics callback to SIP
00209  *
00210  * Revision 2.11  2004/03/14 11:32:19  rjongbloed
00211  * Changes to better support SIP proxies.
00212  *
00213  * Revision 2.10  2004/03/14 10:13:03  rjongbloed
00214  * Moved transport on SIP top be constructed by endpoint as any transport created on
00215  *   an endpoint can receive data for any connection.
00216  * Changes to REGISTER to support authentication
00217  *
00218  * Revision 2.9  2004/03/14 08:34:09  csoutheren
00219  * Added ability to set User-Agent string
00220  *
00221  * Revision 2.8  2004/03/13 06:51:31  rjongbloed
00222  * Alllowed for empty "username" in registration
00223  *
00224  * Revision 2.7  2004/03/13 06:32:17  rjongbloed
00225  * Fixes for removal of SIP and H.323 subsystems.
00226  * More registration work.
00227  *
00228  * Revision 2.6  2003/03/06 03:57:47  robertj
00229  * IVR support (work in progress) requiring large changes everywhere.
00230  *
00231  * Revision 2.5  2002/09/16 02:52:35  robertj
00232  * Added #define so can select if #pragma interface/implementation is used on
00233  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00234  *
00235  * Revision 2.4  2002/07/04 07:41:47  robertj
00236  * Fixed memory/thread leak of transports.
00237  *
00238  * Revision 2.3  2002/04/16 08:06:35  robertj
00239  * Fixed GNU warnings.
00240  *
00241  * Revision 2.2  2002/04/05 10:42:04  robertj
00242  * Major changes to support transactions (UDP timeouts and retries).
00243  *
00244  * Revision 2.1  2002/02/01 04:53:01  robertj
00245  * Added (very primitive!) SIP support.
00246  *
00247  */
00248 
00249 #ifndef __OPAL_SIPEP_H
00250 #define __OPAL_SIPEP_H
00251 
00252 #ifdef P_USE_PRAGMA
00253 #pragma interface
00254 #endif
00255 
00256 
00257 #include <opal/endpoint.h>
00258 #include <sip/sippdu.h>
00259  
00260 
00261 class SIPConnection;
00262 
00264 
00265 /* Class to contain parameters about SIP requests which maintain a
00266  * transport open such as REGISTER, SUBSCRIBE and MESSAGE.
00267  * Required to support several concurrent registrations or conversations.
00268  */
00269 class SIPInfo : public PSafeObject 
00270 {
00271   PCLASSINFO(SIPInfo, PSafeObject);
00272   public:
00273     SIPInfo(
00274       SIPEndPoint & ep, 
00275       const PString & name
00276     );
00277 
00278     ~SIPInfo();
00279   
00280     virtual BOOL CreateTransport(OpalTransportAddress & addr);
00281 
00282     virtual OpalTransport *GetTransport()
00283     { PWaitAndSignal m(transportMutex); return registrarTransport; }
00284 
00285     virtual SIPAuthentication & GetAuthentication()
00286     { return authentication; }
00287 
00288     virtual const OpalTransportAddress & GetRegistrarAddress()
00289     { return registrarAddress; }
00290 
00291     virtual const SIPURL & GetRegistrationAddress()
00292     { return registrationAddress; }
00293     
00294     virtual void AppendTransaction(SIPTransaction * transaction) 
00295     { registrations.Append (transaction); }
00296     
00297     virtual void RemoveTransactions() 
00298     { registrations.RemoveAll (); }
00299 
00300     virtual BOOL IsRegistered() 
00301     { return registered; }
00302 
00303     virtual void SetRegistered(BOOL r) 
00304     { registered = r; if (r) registrationTime = PTime ();}
00305 
00306     // An expire time of -1 corresponds to an invalid SIPInfo that 
00307     // should be deleted.
00308     virtual void SetExpire(int e)
00309     { expire = e; }
00310 
00311     virtual int GetExpire()
00312     { return expire; }
00313 
00314     virtual PString GetRegistrationID()
00315     { return registrationID; }
00316 
00317     virtual BOOL HasExpired()
00318     { return (registered && (PTime () - registrationTime) >= PTimeInterval (0, expire)); }
00319 
00320     virtual void SetAuthUser(const PString & u)
00321     { authUser = u;}
00322     
00323     virtual void SetPassword(const PString & p)
00324     { password = p;}
00325     
00326     virtual void SetAuthRealm(const PString & r)
00327     { authRealm = r;}
00328     
00329     virtual void SetBody(const PString & b)
00330     { body = b;}
00331    
00332     virtual SIPTransaction * CreateTransaction(
00333       OpalTransport & t, 
00334       BOOL unregister
00335     ) = 0;
00336 
00337     virtual SIP_PDU::Methods GetMethod() = 0;
00338 
00339     virtual void OnSuccess() = 0;
00340 
00341     virtual void OnFailed(
00342       SIP_PDU::StatusCodes
00343     ) = 0;
00344 
00345     protected:
00346       SIPEndPoint      & ep;
00347       SIPAuthentication  authentication;
00348       OpalTransport    * registrarTransport;
00349       OpalTransportAddress registrarAddress;
00350       SIPURL             registrationAddress;
00351       PString            registrationID;
00352       SIPTransactionList registrations;
00353       PTime              registrationTime;
00354       BOOL               registered;
00355       int                expire;
00356       PString            authRealm;
00357       PString            authUser;
00358       PString            password;
00359       PString            body;
00360       PMutex             transportMutex;
00361     
00362     private:
00363 };
00364 
00365 class SIPRegisterInfo : public SIPInfo
00366 {
00367   PCLASSINFO(SIPRegisterInfo, SIPInfo);
00368 
00369   public:
00370     SIPRegisterInfo(SIPEndPoint & ep, const PString & adjustedUsername, const PString & authName, const PString & password, int expire);
00371     ~SIPRegisterInfo();
00372     virtual SIPTransaction * CreateTransaction(OpalTransport &, BOOL);
00373     virtual SIP_PDU::Methods GetMethod()
00374     { return SIP_PDU::Method_REGISTER; }
00375 
00376     virtual void OnSuccess();
00377     virtual void OnFailed(SIP_PDU::StatusCodes r);
00378 };
00379 
00380 class SIPMWISubscribeInfo : public SIPInfo
00381 {
00382   PCLASSINFO(SIPMWISubscribeInfo, SIPInfo);
00383   public:
00384     SIPMWISubscribeInfo (SIPEndPoint & ep, const PString & adjustedUsername, int expire);
00385     virtual SIPTransaction * CreateTransaction (OpalTransport &, BOOL);
00386     virtual SIP_PDU::Methods GetMethod ()
00387     { return SIP_PDU::Method_SUBSCRIBE; }
00388     virtual void OnSuccess ();
00389     virtual void OnFailed (SIP_PDU::StatusCodes);
00390 };
00391 
00392 class SIPMessageInfo : public SIPInfo
00393 {
00394   PCLASSINFO(SIPMessageInfo, SIPInfo);
00395   public:
00396     SIPMessageInfo (SIPEndPoint & ep, const PString & adjustedUsername, const PString & body);
00397     virtual SIPTransaction * CreateTransaction (OpalTransport &, BOOL);
00398     virtual SIP_PDU::Methods GetMethod ()
00399     { return SIP_PDU::Method_MESSAGE; }
00400     virtual void OnSuccess ();
00401     virtual void OnFailed (SIP_PDU::StatusCodes);
00402 };
00403 
00404 
00406 
00410 class SIPAuthInfo : public PObject
00411 {
00412   public:
00413     SIPAuthInfo()
00414     { }
00415 
00416     SIPAuthInfo(const PString & u, const PString & p)
00417     { username = u; password = p; }
00418     PString username;
00419     PString password;
00420 };
00421 
00423 
00426 class SIPEndPoint : public OpalEndPoint
00427 {
00428   PCLASSINFO(SIPEndPoint, OpalEndPoint);
00429 
00430   public:
00435     SIPEndPoint(
00436       OpalManager & manager
00437     );
00438 
00441     ~SIPEndPoint();
00443 
00449     virtual PStringArray GetDefaultListeners() const;
00450 
00455     virtual BOOL NewIncomingConnection(
00456       OpalTransport * transport  
00457     );
00458 
00488     virtual BOOL MakeConnection(
00489       OpalCall & call,        
00490       const PString & party,  
00491       void * userData = NULL  
00492     );
00493 
00503     virtual OpalMediaFormatList GetMediaFormats() const;
00505 
00511     virtual SIPConnection * CreateConnection(
00512       OpalCall & call,            
00513       const PString & token,      
00514       void * userData,            
00515       const SIPURL & destination, 
00516       OpalTransport * transport,  
00517       SIP_PDU * invite            
00518     );
00519     
00522     virtual BOOL SetupTransfer(
00523       const PString & token,        
00524       const PString & callIdentity, 
00525       const PString & remoteParty,  
00526       void * userData = NULL        
00527     );
00528     
00532     virtual BOOL ForwardConnection(
00533       SIPConnection & connection,     
00534       const PString & forwardParty    
00535     );
00536 
00538   
00541     OpalTransport * CreateTransport(
00542       const OpalTransportAddress & address
00543     );
00544 
00545     virtual void HandlePDU(
00546       OpalTransport & transport
00547     );
00548 
00551     virtual BOOL OnReceivedPDU(
00552       OpalTransport & transport,
00553       SIP_PDU * pdu
00554     );
00555 
00558     virtual void OnReceivedResponse(
00559       SIPTransaction & transaction,
00560       SIP_PDU & response
00561     );
00562 
00565     virtual BOOL OnReceivedINVITE(
00566       OpalTransport & transport,
00567       SIP_PDU * pdu
00568     );
00569   
00572     virtual void OnReceivedAuthenticationRequired(
00573       SIPTransaction & transaction,
00574       SIP_PDU & response
00575     );
00576 
00580     virtual void OnReceivedOK(
00581       SIPTransaction & transaction,
00582       SIP_PDU & response
00583     );
00584     
00587     virtual BOOL OnReceivedNOTIFY(
00588       OpalTransport & transport,
00589       SIP_PDU & response
00590     );
00591 
00594     virtual void OnReceivedMESSAGE(
00595       OpalTransport & transport,
00596       SIP_PDU & response
00597     );
00598     
00606     virtual void OnRTPStatistics(
00607       const SIPConnection & connection,  
00608       const RTP_Session & session         
00609     ) const;
00611  
00612 
00617     PSafePtr<SIPConnection> GetSIPConnectionWithLock(
00618       const PString & token,     
00619       PSafetyMode mode = PSafeReadWrite
00620     ) { return PSafePtrCast<OpalConnection, SIPConnection>(GetConnectionWithLock(token, mode)); }
00621 
00622     virtual BOOL IsAcceptedAddress(const SIPURL & toAddr);
00623 
00624 
00627     virtual void OnMessageReceived (const SIPURL & from,
00628                                     const PString & body);
00629 
00630                                 
00643     BOOL Register(
00644       const PString & host,
00645       const PString & username = PString::Empty(),
00646       const PString & autName = PString::Empty(),
00647       const PString & password = PString::Empty(),
00648       const PString & authRealm = PString::Empty(),
00649       int timeout = 0
00650     );
00651 
00654     virtual void OnMWIReceived (
00655       const PString & host,
00656       const PString & user,
00657       SIPMWISubscribe::MWIType type,
00658       const PString & msgs);
00659 
00660     
00664     BOOL MWISubscribe(
00665       const PString & host,
00666       const PString & username,
00667       int timeout = 0
00668     );
00669    
00670     
00675     virtual void OnRegistrationFailed(
00676       const PString & host,
00677       const PString & userName,
00678       SIP_PDU::StatusCodes reason,
00679       BOOL wasRegistering);
00680     
00681       
00686     virtual void OnRegistered(
00687       const PString & host,
00688       const PString & userName,
00689       BOOL wasRegistering);
00690 
00691     
00695     BOOL IsRegistered(const PString & host);
00696 
00697 
00700     unsigned GetRegistrationsCount () { return activeSIPInfo.GetRegistrationsCount (); }
00701     
00702     
00705     BOOL IsSubscribed(
00706       const PString & host, 
00707       const PString & user);
00708  
00709     
00713     BOOL Unregister(const PString & host,
00714                     const PString & user);
00715 
00716     
00720     BOOL MWIUnsubscribe(
00721       const PString & host,
00722       const PString & user);
00723     
00724     
00729     virtual void OnMessageFailed(
00730       const SIPURL & messageUrl,
00731       SIP_PDU::StatusCodes reason);
00732     
00733 
00734     void SetMIMEForm(BOOL v) { mimeForm = v; }
00735     BOOL GetMIMEForm() const { return mimeForm; }
00736 
00737     void SetMaxRetries(unsigned r) { maxRetries = r; }
00738     unsigned GetMaxRetries() const { return maxRetries; }
00739 
00740     void SetRetryTimeouts(
00741       const PTimeInterval & t1,
00742       const PTimeInterval & t2
00743     ) { retryTimeoutMin = t1; retryTimeoutMax = t2; }
00744     const PTimeInterval & GetRetryTimeoutMin() const { return retryTimeoutMin; }
00745     const PTimeInterval & GetRetryTimeoutMax() const { return retryTimeoutMax; }
00746 
00747     void SetNonInviteTimeout(
00748       const PTimeInterval & t
00749     ) { nonInviteTimeout = t; }
00750     const PTimeInterval & GetNonInviteTimeout() const { return nonInviteTimeout; }
00751 
00752     void SetPduCleanUpTimeout(
00753       const PTimeInterval & t
00754     ) { pduCleanUpTimeout = t; }
00755     const PTimeInterval & GetPduCleanUpTimeout() const { return pduCleanUpTimeout; }
00756 
00757     void SetInviteTimeout(
00758       const PTimeInterval & t
00759     ) { inviteTimeout = t; }
00760     const PTimeInterval & GetInviteTimeout() const { return inviteTimeout; }
00761 
00762     void SetAckTimeout(
00763       const PTimeInterval & t
00764     ) { ackTimeout = t; }
00765     const PTimeInterval & GetAckTimeout() const { return ackTimeout; }
00766 
00767     void SetRegistrarTimeToLive(
00768       const PTimeInterval & t
00769     ) { registrarTimeToLive = t; }
00770     const PTimeInterval & GetRegistrarTimeToLive() const { return registrarTimeToLive; }
00771     
00772     void SetNotifierTimeToLive(
00773       const PTimeInterval & t
00774     ) { notifierTimeToLive = t; }
00775     const PTimeInterval & GetNotifierTimeToLive() const { return notifierTimeToLive; }
00776     
00777     void SetNATBindingTimeout(
00778       const PTimeInterval & t
00779     ) { natBindingTimeout = t; natBindingTimer.RunContinuous (natBindingTimeout); }
00780     const PTimeInterval & GetNATBindingTimeout() const { return natBindingTimeout; }
00781 
00782     void AddTransaction(
00783       SIPTransaction * transaction
00784     ) { PWaitAndSignal m(transactionsMutex); transactions.SetAt(transaction->GetTransactionID(), transaction); }
00785 
00786     void RemoveTransaction(
00787       SIPTransaction * transaction
00788     ) { PWaitAndSignal m(transactionsMutex); transactions.SetAt(transaction->GetTransactionID(), NULL); }
00789 
00790     
00793     unsigned GetNextCSeq() { return ++lastSentCSeq; }
00794 
00795     
00798     BOOL GetAuthentication(const PString & authRealm, SIPAuthentication &); 
00799     
00800 
00806     virtual SIPURL GetRegisteredPartyName(const PString &);
00807 
00808 
00811     virtual SIPURL GetDefaultRegisteredPartyName();
00812     
00813 
00823     SIPURL GetLocalURL(
00824        const OpalTransport & transport,             
00825        const PString & userName = PString::Empty()  
00826     );
00827     
00828     
00831     const SIPURL & GetProxy() const { return proxy; }
00832 
00833     
00836     void SetProxy(const SIPURL & url);
00837     
00838     
00841     void SetProxy(
00842       const PString & hostname,
00843       const PString & username,
00844       const PString & password
00845     );
00846 
00847     
00850     virtual PString GetUserAgent() const;
00851 
00852     
00855     void SetUserAgent(const PString & str) { userAgentString = str; }
00856 
00857     
00860     BOOL SendMessage (const SIPURL & url, const PString & body);
00861     
00862 
00865     enum NATBindingRefreshMethod{
00866       None,
00867       Options,
00868       EmptyRequest,
00869       NumMethods
00870     };
00871 
00872 
00875     void SetNATBindingRefreshMethod(const NATBindingRefreshMethod m) { natMethod = m; }
00876 
00877 
00878   protected:
00879     PDECLARE_NOTIFIER(PThread, SIPEndPoint, TransportThreadMain);
00880     PDECLARE_NOTIFIER(PTimer, SIPEndPoint, NATBindingRefresh);
00881     PDECLARE_NOTIFIER(PTimer, SIPEndPoint, RegistrationRefresh);
00882 
00887     class RegistrationList : public PSafeList<SIPInfo>
00888     {
00889       public:
00890 
00894             unsigned GetRegistrationsCount ()
00895             {
00896               unsigned count = 0;
00897               for (PSafePtr<SIPInfo> info(*this, PSafeReference); info != NULL; ++info)
00898                 if (info->IsRegistered() && info->GetMethod() == SIP_PDU::Method_REGISTER) 
00899                   count++;
00900               return count;
00901             }
00902           
00906             SIPInfo *FindSIPInfoByCallID (const PString & callID, PSafetyMode m)
00907             {
00908               for (PSafePtr<SIPInfo> info(*this, m); info != NULL; ++info)
00909                       if (callID == info->GetRegistrationID())
00910                         return info;
00911               return NULL;
00912             }
00913 
00917             SIPInfo *FindSIPInfoByAuthRealm (const PString & authRealm, const PString & userName, PSafetyMode m)
00918             {
00919               for (PSafePtr<SIPInfo> info(*this, m); info != NULL; ++info)
00920                       if (authRealm == info->GetAuthentication().GetAuthRealm() && (userName.IsEmpty() || userName == info->GetAuthentication().GetUsername()))
00921                         return info;
00922               return NULL;
00923             }
00924 
00932             SIPInfo *FindSIPInfoByUrl (const PString & url, SIP_PDU::Methods meth, PSafetyMode m)
00933             {
00934               for (PSafePtr<SIPInfo> info(*this, m); info != NULL; ++info) {
00935                       if (SIPURL(url) == info->GetRegistrationAddress() && meth == info->GetMethod())
00936                         return info;
00937               }
00938               return NULL;
00939             }
00940 
00946             SIPInfo *FindSIPInfoByDomain (const PString & name, SIP_PDU::Methods meth, PSafetyMode m)
00947             {
00948               OpalTransportAddress addr = name;
00949               for (PSafePtr<SIPInfo> info(*this, m); info != NULL; ++info) {
00950                       if (info->IsRegistered() && (name == info->GetRegistrationAddress().GetHostName() || (info->GetTransport() && addr.GetHostName() == info->GetTransport()->GetRemoteAddress().GetHostName())) && meth == info->GetMethod())
00951                         return info;
00952               }
00953               return NULL;
00954             }
00955     };
00956 
00957     static BOOL WriteSIPInfo(
00958       OpalTransport & transport, 
00959       void * info
00960     );
00961 
00962     BOOL TransmitSIPInfo (
00963       SIP_PDU::Methods method,
00964       const PString & host, 
00965       const PString & username, 
00966       const PString & authName = PString::Empty(),
00967       const PString & password = PString::Empty(), 
00968       const PString & authRealm = PString::Empty(),
00969       const PString & body = PString::Empty(),
00970       int timeout = 0
00971     );
00972 
00973     BOOL TransmitSIPUnregistrationInfo (
00974       const PString & host, 
00975       const PString & username, 
00976       SIP_PDU::Methods method
00977     );
00978     
00979     void ParsePartyName(
00980       const PString & remoteParty,     
00981       PString & party);                
00982 
00983     SIPURL            proxy;
00984     PString           userAgentString;
00985 
00986     BOOL          mimeForm;
00987     unsigned      maxRetries;
00988     PTimeInterval retryTimeoutMin;   // T1
00989     PTimeInterval retryTimeoutMax;   // T2
00990     PTimeInterval nonInviteTimeout;  // T3
00991     PTimeInterval pduCleanUpTimeout; // T4
00992     PTimeInterval inviteTimeout;
00993     PTimeInterval ackTimeout;
00994     PTimeInterval registrarTimeToLive;
00995     PTimeInterval notifierTimeToLive;
00996     PTimeInterval natBindingTimeout;
00997     
00998     RegistrationList   activeSIPInfo;
00999 
01000     PTimer registrationTimer; // Used to refresh the REGISTER and the SUBSCRIBE transactions.
01001     SIPTransactionList messages;
01002     SIPTransactionDict transactions;
01003 
01004     PTimer                  natBindingTimer;
01005     NATBindingRefreshMethod natMethod;
01006 
01007     PMutex             transactionsMutex;
01008     PMutex             connectionsActiveInUse;
01009 
01010     unsigned           lastSentCSeq;
01011 };
01012 
01013 #endif // __OPAL_SIPEP_H
01014 
01015 
01016 // End of File ///////////////////////////////////////////////////////////////

Generated on Fri Jun 16 09:21:05 2006 for OPAL by  doxygen 1.4.2