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

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