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.17  2007/04/17 21:50:19  dsandras
00029  * Fixed Via field in previous commit.
00030  * Make sure the correct port is being used.
00031  * Improved FindSIPInfoByDomain.
00032  *
00033  * Revision 2.46.2.16  2007/04/15 09:54:47  dsandras
00034  * Some systems like CISCO Call Manager do like having a Contact field in INVITE
00035  * PDUs which is different to the one being used in the original REGISTER request.
00036  * Added code to use the same Contact field in both cases if we can determine that
00037  * we are registered to that specific account and if there is a transport running.
00038  * Fixed problem where the SIP connection was not released with a BYE PDU when
00039  * the ACK is received while we are already in EstablishedPhase.
00040  *
00041  * Revision 2.46.2.15  2007/03/27 20:23:22  dsandras
00042  * Added Garbage collector. Make sure the transport is closed before
00043  * deleting it. Better handling of SIPInfo objects.
00044  *
00045  * Revision 2.46.2.14  2007/03/10 16:48:21  dsandras
00046  * Improved locking.
00047  *
00048  * Revision 2.46.2.13  2007/02/27 21:24:07  dsandras
00049  * Added missing locking. Fixes Ekiga report #411438.
00050  *
00051  * Revision 2.46.2.12  2007/01/15 22:16:42  dsandras
00052  * Backported patches improving stability from HEAD to Phobos.
00053  *
00054  * Revision 2.46.2.11  2007/01/02 15:26:46  dsandras
00055  * Added DNS Fallback for realm authentication if the classical comparison
00056  * doesn't work. Fixes problems with broken SIP proxies. (Ekiga report #377346)
00057  *
00058  * Revision 2.46.2.10  2006/10/08 13:25:48  dsandras
00059  * Fixed previous commit.
00060  *
00061  * Revision 2.46.2.9  2006/08/07 19:46:19  dsandras
00062  * Backported fix from HEAD to abort registration after a given amount of failures.
00063  *
00064  * Revision 2.46.2.8  2006/04/30 17:26:22  dsandras
00065  * Backported various HEAD cleanups.
00066  *
00067  * Revision 2.58  2006/04/30 17:24:39  dsandras
00068  * Various clean ups.
00069  *
00070  * Revision 2.46.2.7  2006/04/11 21:59:46  dsandras
00071  * More backports from HEAD.
00072  *
00073  * Revision 2.57  2006/04/11 21:58:25  dsandras
00074  * Various cleanups and fixes. Fixes Ekiga report #336444.
00075  *
00076  * Revision 2.46.2.6  2006/03/27 20:29:55  dsandras
00077  * Backports from HEAD.
00078  *
00079  * Revision 2.56  2006/03/27 20:28:18  dsandras
00080  * Added mutex to fix concurrency issues between OnReceivedPDU which checks
00081  * if a connection is in the list, and OnReceivedINVITE, which adds it to the
00082  * list. Fixes Ekiga report #334847. Thanks Robert for your input on this!
00083  * 
00084  * Revision 2.46.2.5  2006/03/19 18:59:02  dsandras
00085  * More backports from HEAD.
00086  *
00087  * Revision 2.55  2006/03/19 18:57:06  dsandras
00088  * More work on Ekiga report #334999.
00089  *
00090  * Revision 2.46.2.4  2006/03/19 18:15:59  dsandras
00091  * Backports from HEAD.
00092  *
00093  * Revision 2.54  2006/03/19 17:26:15  dsandras
00094  * Fixed FindSIPInfoByDomain so that it doesn't return unregistered accounts.
00095  * Fixes Ekiga report #335006.
00096  *
00097  * Revision 2.53  2006/03/19 12:32:05  dsandras
00098  * RFC3261 says that "CANCEL messages "SHOULD NOT" be sent for anything but INVITE
00099  * requests". Fixes Ekiga report #334985.
00100  *
00101  * Revision 2.52  2006/03/19 11:45:47  dsandras
00102  * The remote address of the registrar transport might have changed due
00103  * to the Via field. This affected unregistering which was reusing
00104  * the exact same transport to unregister. Fixed Ekiga report #334999.
00105  * Revision 2.46.2.3  2006/03/06 19:04:39  dsandras
00106  * Backports from HEAD.
00107  *
00108  * Revision 2.50  2006/03/06 19:01:30  dsandras
00109  * Allow registering several accounts with the same realm but different
00110  * user names to the same provider. Fixed possible crash due to transport
00111  * deletion before the transaction is over.
00112  *
00113  * Revision 2.46.2.2  2006/02/19 11:53:22  dsandras
00114  * More backports from HEAD.
00115  *
00116  * Revision 2.48  2006/02/19 11:51:46  dsandras
00117  * Fixed FindSIPInfoByDomain.
00118  *
00119  * Revision 2.46.2.1  2006/01/29 21:01:40  dsandras
00120  * Backports from CVS HEAD.
00121  *
00122  * Revision 2.47  2006/01/29 20:55:32  dsandras
00123  * Allow using a simple username or a fill url when registering.
00124  *
00125  * Revision 2.46  2006/01/08 21:53:40  dsandras
00126  * Changed IsRegistered so that it takes the registration url as argument,
00127  * allowing it to work when there are several accounts on the same server.
00128  *
00129  * Revision 2.45  2006/01/08 14:43:46  dsandras
00130  * Improved the NAT binding refresh methods so that it works with all endpoint
00131  * created transports that require it and so that it can work by sending
00132  * SIP Options, or empty SIP requests. More methods can be added later.
00133  *
00134  * Revision 2.44  2006/01/02 11:28:07  dsandras
00135  * Some documentation. Various code cleanups to prevent duplicate code.
00136  *
00137  * Revision 2.43  2005/12/18 21:06:56  dsandras
00138  * Added function to clean up the registrations object. Moved DeleteObjectsToBeRemoved call outside of the loop.
00139  *
00140  * Revision 2.42  2005/12/14 17:59:50  dsandras
00141  * Added ForwardConnection executed when the remote asks for a call forwarding.
00142  * Similar to what is done in the H.323 part with the method of the same name.
00143  *
00144  * Revision 2.41  2005/12/11 19:14:20  dsandras
00145  * Added support for setting a different user name and authentication user name
00146  * as required by some providers like digisip.
00147  *
00148  * Revision 2.40  2005/12/08 21:14:54  dsandras
00149  * Added function allowing to change the nat binding refresh timeout.
00150  *
00151  * Revision 2.39  2005/12/05 22:20:57  dsandras
00152  * Update the transport when the computer is behind NAT, using STUN, the IP
00153  * address has changed compared to the original transport and a registration
00154  * refresh must occur.
00155  *
00156  * Revision 2.38  2005/12/04 22:08:58  dsandras
00157  * Added possibility to provide an expire time when registering, if not
00158  * the default expire time for the endpoint will be used.
00159  *
00160  * Revision 2.37  2005/11/30 13:35:26  csoutheren
00161  * Changed tags for Doxygen
00162  *
00163  * Revision 2.36  2005/11/28 19:07:56  dsandras
00164  * Moved OnNATTimeout to SIPInfo and use it for active conversations too.
00165  * Added E.164 support.
00166  *
00167  * Revision 2.35  2005/10/30 23:01:29  dsandras
00168  * Added possibility to have a body for SIPInfo. Moved MESSAGE sending to SIPInfo for more efficiency during conversations.
00169  *
00170  * Revision 2.34  2005/10/22 17:14:45  dsandras
00171  * Send an OPTIONS request periodically when STUN is being used to maintain the registrations binding alive.
00172  *
00173  * Revision 2.33  2005/10/20 20:26:58  dsandras
00174  * Made the transactions handling thread-safe.
00175  *
00176  * Revision 2.32  2005/10/02 21:46:20  dsandras
00177  * Added more doc.
00178  *
00179  * Revision 2.31  2005/10/02 17:47:37  dsandras
00180  * Added function to return the translated contact address of the endpoint.
00181  * Added some doc.
00182  *
00183  * Revision 2.30  2005/05/23 20:14:05  dsandras
00184  * Added preliminary support for basic instant messenging.
00185  *
00186  * Revision 2.29  2005/05/06 07:37:06  csoutheren
00187  * Various changed while working with SIP carrier
00188  *   - remove assumption that authentication realm is a domain name.
00189  *   - stopped rewrite of "To" field when proxy being used
00190  *   - fix Contact field in REGISTER to match actual port used when Symmetric NATin use
00191  *   - lots of formatting changes and cleanups
00192  *
00193  * Revision 2.28  2005/05/03 20:41:51  dsandras
00194  * Do not count SUBSCRIBEs when returning the number of registered accounts.
00195  *
00196  * Revision 2.27  2005/04/28 20:22:53  dsandras
00197  * Applied big sanity patch for SIP thanks to Ted Szoczei <tszoczei@microtronix.ca>.
00198  * Thanks a lot!
00199  *
00200  * Revision 2.25  2005/04/26 19:50:54  dsandras
00201  * Added function to return the number of registered accounts.
00202  *
00203  * Revision 2.24  2005/04/10 21:01:09  dsandras
00204  * Added Blind Transfer support.
00205  *
00206  * Revision 2.23  2005/03/11 18:12:08  dsandras
00207  * 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.
00208  *
00209  * Revision 2.22  2005/02/19 22:48:48  dsandras
00210  * 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.
00211  *
00212  * Revision 2.21  2004/12/17 12:06:52  dsandras
00213  * 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.
00214  *
00215  * Revision 2.20  2004/12/12 12:30:09  dsandras
00216  * Added virtual function called when registration to a registrar fails.
00217  *
00218  * Revision 2.19  2004/11/29 08:18:31  csoutheren
00219  * Added support for setting the SIP authentication domain/realm as needed for many service
00220  *  providers
00221  *
00222  * Revision 2.18  2004/10/02 04:30:10  rjongbloed
00223  * Added unregister function for SIP registrar
00224  *
00225  * Revision 2.17  2004/08/22 12:27:44  rjongbloed
00226  * More work on SIP registration, time to live refresh and deregistration on exit.
00227  *
00228  * Revision 2.16  2004/08/14 07:56:30  rjongbloed
00229  * Major revision to utilise the PSafeCollection classes for the connections and calls.
00230  *
00231  * Revision 2.15  2004/07/11 12:42:10  rjongbloed
00232  * Added function on endpoints to get the list of all media formats any
00233  *   connection the endpoint may create can support.
00234  *
00235  * Revision 2.14  2004/06/05 14:36:32  rjongbloed
00236  * Added functions to get registration URL.
00237  * Added ability to set proxy bu host/user/password strings.
00238  *
00239  * Revision 2.13  2004/04/26 06:30:33  rjongbloed
00240  * Added ability to specify more than one defualt listener for an endpoint,
00241  *   required by SIP which listens on both UDP and TCP.
00242  *
00243  * Revision 2.12  2004/04/26 05:40:38  rjongbloed
00244  * Added RTP statistics callback to SIP
00245  *
00246  * Revision 2.11  2004/03/14 11:32:19  rjongbloed
00247  * Changes to better support SIP proxies.
00248  *
00249  * Revision 2.10  2004/03/14 10:13:03  rjongbloed
00250  * Moved transport on SIP top be constructed by endpoint as any transport created on
00251  *   an endpoint can receive data for any connection.
00252  * Changes to REGISTER to support authentication
00253  *
00254  * Revision 2.9  2004/03/14 08:34:09  csoutheren
00255  * Added ability to set User-Agent string
00256  *
00257  * Revision 2.8  2004/03/13 06:51:31  rjongbloed
00258  * Alllowed for empty "username" in registration
00259  *
00260  * Revision 2.7  2004/03/13 06:32:17  rjongbloed
00261  * Fixes for removal of SIP and H.323 subsystems.
00262  * More registration work.
00263  *
00264  * Revision 2.6  2003/03/06 03:57:47  robertj
00265  * IVR support (work in progress) requiring large changes everywhere.
00266  *
00267  * Revision 2.5  2002/09/16 02:52:35  robertj
00268  * Added #define so can select if #pragma interface/implementation is used on
00269  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00270  *
00271  * Revision 2.4  2002/07/04 07:41:47  robertj
00272  * Fixed memory/thread leak of transports.
00273  *
00274  * Revision 2.3  2002/04/16 08:06:35  robertj
00275  * Fixed GNU warnings.
00276  *
00277  * Revision 2.2  2002/04/05 10:42:04  robertj
00278  * Major changes to support transactions (UDP timeouts and retries).
00279  *
00280  * Revision 2.1  2002/02/01 04:53:01  robertj
00281  * Added (very primitive!) SIP support.
00282  *
00283  */
00284 
00285 #ifndef __OPAL_SIPEP_H
00286 #define __OPAL_SIPEP_H
00287 
00288 #ifdef P_USE_PRAGMA
00289 #pragma interface
00290 #endif
00291 
00292 
00293 #include <opal/endpoint.h>
00294 #include <sip/sippdu.h>
00295  
00296 
00297 class SIPConnection;
00298 
00300 
00301 /* Class to contain parameters about SIP requests which maintain a
00302  * transport open such as REGISTER, SUBSCRIBE and MESSAGE.
00303  * Required to support several concurrent registrations or conversations.
00304  */
00305 class SIPInfo : public PSafeObject 
00306 {
00307   PCLASSINFO(SIPInfo, PSafeObject);
00308   public:
00309     SIPInfo(
00310       SIPEndPoint & ep, 
00311       const PString & name,
00312       const PTimeInterval & retryMin = PMaxTimeInterval,
00313       const PTimeInterval & retryMax = PMaxTimeInterval
00314     );
00315 
00316     ~SIPInfo();
00317   
00318     virtual BOOL CreateTransport(OpalTransportAddress & addr);
00319 
00320     virtual OpalTransport *GetTransport()
00321     { PWaitAndSignal m(transportMutex); return registrarTransport; }
00322 
00323     virtual SIPAuthentication & GetAuthentication()
00324     { return authentication; }
00325 
00326     virtual const OpalTransportAddress & GetRegistrarAddress()
00327     { return registrarAddress; }
00328 
00329     virtual const SIPURL & GetRegistrationAddress()
00330     { return registrationAddress; }
00331     
00332     virtual void AppendTransaction(SIPTransaction * transaction) 
00333     { PWaitAndSignal m(registrationsMutex); registrations.Append (transaction); }
00334     
00335     virtual void RemoveTransactions() 
00336     { PWaitAndSignal m(registrationsMutex); registrations.RemoveAll (); }
00337 
00338     virtual BOOL IsRegistered() 
00339     { return registered; }
00340 
00341     virtual void SetRegistered(BOOL r) 
00342     { registered = r; if (r) registrationTime = PTime ();}
00343 
00344     // An expire time of -1 corresponds to an invalid SIPInfo that 
00345     // should be deleted.
00346     virtual void SetExpire(int e)
00347     { expire = e; }
00348 
00349     virtual int GetExpire()
00350     { return expire; }
00351 
00352     virtual PString GetRegistrationID()
00353     { return registrationID; }
00354 
00355     virtual BOOL HasExpired()
00356     { return (registered && (PTime () - registrationTime) >= PTimeInterval (0, expire)); }
00357 
00358     virtual void SetAuthUser(const PString & u)
00359     { authUser = u;}
00360     
00361     virtual PString GetAuthUser() const
00362     { return authUser;}
00363 
00364     virtual void SetPassword(const PString & p)
00365     { password = p;}
00366     
00367     virtual void SetAuthRealm(const PString & r)
00368     { authRealm = r;}
00369     
00370     virtual void SetBody(const PString & b)
00371     { body = b;}
00372    
00373     virtual SIPTransaction * CreateTransaction(
00374       OpalTransport & t, 
00375       BOOL unregister
00376     ) = 0;
00377 
00378     virtual SIP_PDU::Methods GetMethod() = 0;
00379 
00380     virtual void OnSuccess() = 0;
00381 
00382     virtual void OnFailed(
00383       SIP_PDU::StatusCodes
00384     ) = 0;
00385         
00386         int GetAuthenticationAttempts() { return authenticationAttempts; };
00387         void SetAuthenticationAttempts(unsigned attempts) { authenticationAttempts = attempts; };
00388 
00389     protected:
00390       SIPEndPoint      & ep;
00391       SIPAuthentication  authentication;
00392       OpalTransport    * registrarTransport;
00393       OpalTransportAddress registrarAddress;
00394       SIPURL             registrationAddress;
00395       PString            registrationID;
00396       SIPTransactionList registrations;
00397       PMutex             registrationsMutex;
00398       PTime              registrationTime;
00399       BOOL               registered;
00400       int                      expire;
00401       PString              authRealm;
00402       PString            authUser;
00403       PString            password;
00404       PString                    body;
00405       PMutex             transportMutex;
00406       unsigned           authenticationAttempts;
00407 
00408       PTimeInterval retryTimeoutMin; 
00409       PTimeInterval retryTimeoutMax; 
00410     
00411     private:
00412 };
00413 
00414 class SIPRegisterInfo : public SIPInfo
00415 {
00416   PCLASSINFO(SIPRegisterInfo, SIPInfo);
00417 
00418   public:
00419     SIPRegisterInfo(
00420       SIPEndPoint & ep, 
00421       const PString & originalHost,
00422       const PString & adjustedUsername, 
00423       const PString & authName, 
00424       const PString & password, 
00425       int expire, 
00426       const PTimeInterval & minRetryTime, 
00427       const PTimeInterval & maxRetryTime
00428     );
00429     ~SIPRegisterInfo();
00430     virtual SIPTransaction * CreateTransaction(OpalTransport &, BOOL);
00431     virtual SIP_PDU::Methods GetMethod()
00432     { return SIP_PDU::Method_REGISTER; }
00433 
00434     virtual void OnSuccess();
00435     virtual void OnFailed(SIP_PDU::StatusCodes r);
00436 
00437     PString originalHost;
00438 };
00439 
00440 class SIPMWISubscribeInfo : public SIPInfo
00441 {
00442   PCLASSINFO(SIPMWISubscribeInfo, SIPInfo);
00443   public:
00444     SIPMWISubscribeInfo (SIPEndPoint & ep, const PString & adjustedUsername, int expire);
00445     virtual SIPTransaction * CreateTransaction (OpalTransport &, BOOL);
00446     virtual SIP_PDU::Methods GetMethod ()
00447     { return SIP_PDU::Method_SUBSCRIBE; }
00448     virtual void OnSuccess ();
00449     virtual void OnFailed (SIP_PDU::StatusCodes);
00450 };
00451 
00452 class SIPMessageInfo : public SIPInfo
00453 {
00454   PCLASSINFO(SIPMessageInfo, SIPInfo);
00455   public:
00456     SIPMessageInfo (SIPEndPoint & ep, const PString & adjustedUsername, const PString & body);
00457     virtual SIPTransaction * CreateTransaction (OpalTransport &, BOOL);
00458     virtual SIP_PDU::Methods GetMethod ()
00459     { return SIP_PDU::Method_MESSAGE; }
00460     virtual void OnSuccess ();
00461     virtual void OnFailed (SIP_PDU::StatusCodes);
00462 };
00463 
00464 
00466 
00470 class SIPAuthInfo : public PObject
00471 {
00472   public:
00473     SIPAuthInfo()
00474     { }
00475 
00476     SIPAuthInfo(const PString & u, const PString & p)
00477     { username = u; password = p; }
00478     PString username;
00479     PString password;
00480 };
00481 
00483 
00486 class SIPEndPoint : public OpalEndPoint
00487 {
00488   PCLASSINFO(SIPEndPoint, OpalEndPoint);
00489 
00490   public:
00495     SIPEndPoint(
00496       OpalManager & manager
00497     );
00498 
00501     ~SIPEndPoint();
00503 
00509     virtual PStringArray GetDefaultListeners() const;
00510 
00515     virtual BOOL NewIncomingConnection(
00516       OpalTransport * transport  
00517     );
00518 
00548     virtual BOOL MakeConnection(
00549       OpalCall & call,        
00550       const PString & party,  
00551       void * userData = NULL  
00552     );
00553 
00563     virtual OpalMediaFormatList GetMediaFormats() const;
00565 
00571     virtual SIPConnection * CreateConnection(
00572       OpalCall & call,            
00573       const PString & token,      
00574       void * userData,            
00575       const SIPURL & destination, 
00576       OpalTransport * transport,  
00577       SIP_PDU * invite            
00578     );
00579     
00582     virtual BOOL SetupTransfer(
00583       const PString & token,        
00584       const PString & callIdentity, 
00585       const PString & remoteParty,  
00586       void * userData = NULL        
00587     );
00588     
00592     virtual BOOL ForwardConnection(
00593       SIPConnection & connection,     
00594       const PString & forwardParty    
00595     );
00596 
00598   
00601 
00612     OpalTransport * CreateTransport(
00613       const OpalTransportAddress & address,
00614       BOOL isLocalAddress = FALSE
00615     );
00616 
00617     virtual void HandlePDU(
00618       OpalTransport & transport
00619     );
00620 
00623     virtual BOOL OnReceivedPDU(
00624       OpalTransport & transport,
00625       SIP_PDU * pdu
00626     );
00627 
00630     virtual void OnReceivedResponse(
00631       SIPTransaction & transaction,
00632       SIP_PDU & response
00633     );
00634 
00637     virtual BOOL OnReceivedINVITE(
00638       OpalTransport & transport,
00639       SIP_PDU * pdu
00640     );
00641   
00644     virtual void OnReceivedAuthenticationRequired(
00645       SIPTransaction & transaction,
00646       SIP_PDU & response
00647     );
00648 
00652     virtual void OnReceivedOK(
00653       SIPTransaction & transaction,
00654       SIP_PDU & response
00655     );
00656     
00659     virtual BOOL OnReceivedNOTIFY(
00660       OpalTransport & transport,
00661       SIP_PDU & response
00662     );
00663 
00666     virtual void OnReceivedMESSAGE(
00667       OpalTransport & transport,
00668       SIP_PDU & response
00669     );
00670     
00678     virtual void OnRTPStatistics(
00679       const SIPConnection & connection,  
00680       const RTP_Session & session         
00681     ) const;
00683  
00684 
00689     PSafePtr<SIPConnection> GetSIPConnectionWithLock(
00690       const PString & token,     
00691       PSafetyMode mode = PSafeReadWrite
00692     ) { return PSafePtrCast<OpalConnection, SIPConnection>(GetConnectionWithLock(token, mode)); }
00693 
00694     virtual BOOL IsAcceptedAddress(const SIPURL & toAddr);
00695 
00696 
00699     virtual void OnMessageReceived (const SIPURL & from,
00700                                     const PString & body);
00701 
00702                                 
00715     BOOL Register(
00716       const PString & host,
00717       const PString & username = PString::Empty(),
00718       const PString & autName = PString::Empty(),
00719       const PString & password = PString::Empty(),
00720       const PString & authRealm = PString::Empty(),
00721       int timeout = 0,
00722       const PTimeInterval & minRetryTime = PMaxTimeInterval, 
00723       const PTimeInterval & maxRetryTime = PMaxTimeInterval
00724     );
00725 
00728     virtual void OnMWIReceived (
00729       const PString & host,
00730       const PString & user,
00731       SIPMWISubscribe::MWIType type,
00732       const PString & msgs);
00733 
00734     
00738     BOOL MWISubscribe(
00739       const PString & host,
00740       const PString & username,
00741       int timeout = 0
00742     );
00743    
00744     
00749     virtual void OnRegistrationFailed(
00750       const PString & host,
00751       const PString & userName,
00752       SIP_PDU::StatusCodes reason,
00753       BOOL wasRegistering);
00754     
00755       
00760     virtual void OnRegistered(
00761       const PString & host,
00762       const PString & userName,
00763       BOOL wasRegistering);
00764 
00765     
00769     BOOL IsRegistered(const PString & host);
00770 
00771 
00774     unsigned GetRegistrationsCount () { return activeSIPInfo.GetRegistrationsCount (); }
00775     
00776     
00779     BOOL IsSubscribed(
00780       const PString & host, 
00781       const PString & user);
00782  
00783     
00787     BOOL Unregister(const PString & host,
00788                     const PString & user);
00789 
00790     
00794     BOOL MWIUnsubscribe(
00795       const PString & host,
00796       const PString & user);
00797     
00798     
00803     virtual void OnMessageFailed(
00804       const SIPURL & messageUrl,
00805       SIP_PDU::StatusCodes reason);
00806     
00807 
00808     void SetMIMEForm(BOOL v) { mimeForm = v; }
00809     BOOL GetMIMEForm() const { return mimeForm; }
00810 
00811     void SetMaxRetries(unsigned r) { maxRetries = r; }
00812     unsigned GetMaxRetries() const { return maxRetries; }
00813 
00814     void SetRetryTimeouts(
00815       const PTimeInterval & t1,
00816       const PTimeInterval & t2
00817     ) { retryTimeoutMin = t1; retryTimeoutMax = t2; }
00818     const PTimeInterval & GetRetryTimeoutMin() const { return retryTimeoutMin; }
00819     const PTimeInterval & GetRetryTimeoutMax() const { return retryTimeoutMax; }
00820 
00821     void SetNonInviteTimeout(
00822       const PTimeInterval & t
00823     ) { nonInviteTimeout = t; }
00824     const PTimeInterval & GetNonInviteTimeout() const { return nonInviteTimeout; }
00825 
00826     void SetPduCleanUpTimeout(
00827       const PTimeInterval & t
00828     ) { pduCleanUpTimeout = t; }
00829     const PTimeInterval & GetPduCleanUpTimeout() const { return pduCleanUpTimeout; }
00830 
00831     void SetInviteTimeout(
00832       const PTimeInterval & t
00833     ) { inviteTimeout = t; }
00834     const PTimeInterval & GetInviteTimeout() const { return inviteTimeout; }
00835 
00836     void SetAckTimeout(
00837       const PTimeInterval & t
00838     ) { ackTimeout = t; }
00839     const PTimeInterval & GetAckTimeout() const { return ackTimeout; }
00840 
00841     void SetRegistrarTimeToLive(
00842       const PTimeInterval & t
00843     ) { registrarTimeToLive = t; }
00844     const PTimeInterval & GetRegistrarTimeToLive() const { return registrarTimeToLive; }
00845     
00846     void SetNotifierTimeToLive(
00847       const PTimeInterval & t
00848     ) { notifierTimeToLive = t; }
00849     const PTimeInterval & GetNotifierTimeToLive() const { return notifierTimeToLive; }
00850     
00851     void SetNATBindingTimeout(
00852       const PTimeInterval & t
00853     ) { natBindingTimeout = t; natBindingTimer.RunContinuous (natBindingTimeout); }
00854     const PTimeInterval & GetNATBindingTimeout() const { return natBindingTimeout; }
00855 
00856     void AddTransaction(
00857       SIPTransaction * transaction
00858     ) { PWaitAndSignal m(transactionsMutex); transactions.SetAt(transaction->GetTransactionID(), transaction); }
00859 
00860     void RemoveTransaction(
00861       SIPTransaction * transaction
00862     ) { PWaitAndSignal m(transactionsMutex); transactions.SetAt(transaction->GetTransactionID(), NULL); }
00863 
00864     
00867     unsigned GetNextCSeq() { PWaitAndSignal m(transactionsMutex); return ++lastSentCSeq; }
00868 
00869     
00872     BOOL GetAuthentication(const PString & authRealm, SIPAuthentication &); 
00873     
00874 
00880     virtual SIPURL GetRegisteredPartyName(const PString &);
00881 
00882 
00885     virtual SIPURL GetDefaultRegisteredPartyName();
00886     
00887 
00899     SIPURL GetContactURL(const OpalTransport &transport, const PString & userName, const PString & host);
00900 
00901 
00911     SIPURL GetLocalURL(
00912        const OpalTransport & transport,             
00913        const PString & userName = PString::Empty()  
00914     );
00915     
00916     
00919     const SIPURL & GetProxy() const { return proxy; }
00920 
00921     
00924     void SetProxy(const SIPURL & url);
00925     
00926     
00929     void SetProxy(
00930       const PString & hostname,
00931       const PString & username,
00932       const PString & password
00933     );
00934 
00935     
00938     virtual PString GetUserAgent() const;
00939 
00940     
00943     void SetUserAgent(const PString & str) { userAgentString = str; }
00944 
00945     
00948     BOOL SendMessage (const SIPURL & url, const PString & body);
00949     
00950 
00953     enum NATBindingRefreshMethod{
00954       None,
00955       Options,
00956       EmptyRequest,
00957       NumMethods
00958     };
00959 
00960 
00963     void SetNATBindingRefreshMethod(const NATBindingRefreshMethod m) { natMethod = m; }
00964 
00965 
00970     class RegistrationList : public PSafeList<SIPInfo>
00971     {
00972       public:
00973 
00977             unsigned GetRegistrationsCount ()
00978             {
00979               unsigned count = 0;
00980               for (PSafePtr<SIPInfo> info(*this, PSafeReference); info != NULL; ++info)
00981                 if (info->IsRegistered() && info->GetMethod() == SIP_PDU::Method_REGISTER) 
00982                   count++;
00983               return count;
00984             }
00985           
00989             PSafePtr<SIPInfo> FindSIPInfoByCallID (const PString & callID, PSafetyMode m)
00990             {
00991               for (PSafePtr<SIPInfo> info(*this, m); info != NULL; ++info)
00992                       if (callID == info->GetRegistrationID())
00993                         return info;
00994               return NULL;
00995             }
00996 
01000             PSafePtr<SIPInfo> FindSIPInfoByAuthRealm (const PString & authRealm, const PString & userName, PSafetyMode m)
01001             {
01002               PIPSocket::Address realmAddress;
01003 
01004               for (PSafePtr<SIPInfo> info(*this, m); info != NULL; ++info)
01005                 if (authRealm == info->GetAuthentication().GetAuthRealm() && (userName.IsEmpty() || userName == info->GetAuthentication().GetUsername()))
01006                   return info;
01007               for (PSafePtr<SIPInfo> info(*this, m); info != NULL; ++info) {
01008                 if (PIPSocket::GetHostAddress(info->GetAuthentication().GetAuthRealm(), realmAddress))
01009                   if (realmAddress == PIPSocket::Address(authRealm) && (userName.IsEmpty() || userName == info->GetAuthentication().GetUsername()))
01010                     return info;
01011               }
01012               return NULL;
01013             }
01014 
01022             PSafePtr<SIPInfo> FindSIPInfoByUrl (const PString & url, SIP_PDU::Methods meth, PSafetyMode m)
01023             {
01024               for (PSafePtr<SIPInfo> info(*this, m); info != NULL; ++info) {
01025                       if (SIPURL(url) == info->GetRegistrationAddress() && meth == info->GetMethod())
01026                         return info;
01027               }
01028               return NULL;
01029             }
01030 
01036             PSafePtr <SIPInfo> FindSIPInfoByDomain (const PString & name, SIP_PDU::Methods meth, PSafetyMode m)
01037             {
01038               for (PSafePtr<SIPInfo> info(*this, m); info != NULL; ++info) {
01039 
01040                 if (name == info->GetRegistrationAddress().GetHostName())
01041                   return info;
01042 
01043                 OpalTransportAddress addr;
01044                 PIPSocket::Address infoIP;
01045                 PIPSocket::Address nameIP;
01046                 WORD port = 5060;
01047                 addr = name;
01048 
01049                 if (addr.GetIpAndPort (nameIP, port)) {
01050                   addr = info->GetRegistrationAddress().GetHostName();
01051                   if (addr.GetIpAndPort (infoIP, port)) {
01052                     if (infoIP == nameIP) {
01053                       return info;
01054                     }
01055                   }
01056                 }
01057               }
01058               return NULL;
01059             }
01060     };
01061 
01062     RegistrationList & GetActiveSIPInfo() 
01063     { return activeSIPInfo; }
01064 
01067     virtual SIPRegisterInfo * CreateRegisterInfo(
01068       const PString & originalHost,
01069       const PString & adjustedUsername, 
01070       const PString & authName, 
01071       const PString & password, 
01072       int expire, 
01073       const PTimeInterval & minRetryTime, 
01074       const PTimeInterval & maxRetryTime
01075     );
01076     virtual SIPMWISubscribeInfo * CreateMWISubscribeInfo(const PString & adjustedUsername, int expire);
01077     virtual SIPMessageInfo *      CreateMessageInfo(const PString & adjustedUsername, const PString & body);
01078 
01079   protected:
01080     PDECLARE_NOTIFIER(PThread, SIPEndPoint, TransportThreadMain);
01081     PDECLARE_NOTIFIER(PTimer, SIPEndPoint, NATBindingRefresh);
01082     PDECLARE_NOTIFIER(PTimer, SIPEndPoint, GarbageCollect);
01083     PDECLARE_NOTIFIER(PTimer, SIPEndPoint, RegistrationRefresh);
01084 
01085     static BOOL WriteSIPInfo(
01086       OpalTransport & transport, 
01087       void * info
01088     );
01089 
01090     BOOL TransmitSIPInfo (
01091       SIP_PDU::Methods method,
01092       const PString & host, 
01093       const PString & username, 
01094       const PString & authName = PString::Empty(),
01095       const PString & password = PString::Empty(), 
01096       const PString & authRealm = PString::Empty(),
01097       const PString & body = PString::Empty(),
01098       int timeout = 0,
01099       const PTimeInterval & minRetryTime = PMaxTimeInterval, 
01100       const PTimeInterval & maxRetryTime = PMaxTimeInterval
01101     );
01102 
01103     BOOL TransmitSIPUnregistrationInfo (
01104       const PString & host, 
01105       const PString & username, 
01106       SIP_PDU::Methods method
01107     );
01108     
01109     void ParsePartyName(
01110       const PString & remoteParty,     
01111       PString & party);                
01112 
01113     SIPURL            proxy;
01114     PString           userAgentString;
01115 
01116     BOOL          mimeForm;
01117     unsigned      maxRetries;
01118     PTimeInterval retryTimeoutMin;   // T1
01119     PTimeInterval retryTimeoutMax;   // T2
01120     PTimeInterval nonInviteTimeout;  // T3
01121     PTimeInterval pduCleanUpTimeout; // T4
01122     PTimeInterval inviteTimeout;
01123     PTimeInterval ackTimeout;
01124     PTimeInterval registrarTimeToLive;
01125     PTimeInterval notifierTimeToLive;
01126     PTimeInterval natBindingTimeout;
01127     
01128     RegistrationList   activeSIPInfo;
01129 
01130     PTimer registrationTimer; // Used to refresh the REGISTER and the SUBSCRIBE transactions.
01131     PTimer garbageTimer;
01132     SIPTransactionList messages;
01133     SIPTransactionDict transactions;
01134 
01135     PTimer                  natBindingTimer;
01136     NATBindingRefreshMethod natMethod;
01137 
01138     PMutex             transactionsMutex;
01139     PMutex             connectionsActiveInUse;
01140 
01141     unsigned           lastSentCSeq;
01142 };
01143 
01144 #endif // __OPAL_SIPEP_H
01145 
01146 
01147 // End of File ///////////////////////////////////////////////////////////////

Generated on Fri Sep 28 13:16:52 2007 for OPAL by  doxygen 1.5.3