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  * $Revision: 19846 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-03-31 02:56:21 +0000 (Mon, 31 Mar 2008) $
00030  */
00031 
00032 #ifndef __OPAL_SIPEP_H
00033 #define __OPAL_SIPEP_H
00034 
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 
00039 #ifndef _PTLIB_H
00040 #include <ptlib.h>
00041 #endif
00042 
00043 #include <ptclib/sockagg.h>
00044 #include <opal/endpoint.h>
00045 #include <sip/sipcon.h>
00046 #include <sip/sippdu.h>
00047 #include <sip/handlers.h> 
00048 
00049 
00050 class SIPRegisterHandler;
00051 
00052 
00053 //
00054 //  provide flag so applications know if presence is available
00055 //
00056 #define OPAL_HAS_SIP_PRESENCE   1
00057 
00059 
00063 class SIPAuthInfo : public PObject
00064 {
00065   public:
00066     SIPAuthInfo()
00067     { }
00068 
00069     SIPAuthInfo(const PString & u, const PString & p)
00070     { username = u; password = p; }
00071     PString username;
00072     PString password;
00073 };
00074 
00076 
00079 class SIPEndPoint : public OpalEndPoint
00080 {
00081   PCLASSINFO(SIPEndPoint, OpalEndPoint);
00082 
00083   public:
00088     SIPEndPoint(
00089       OpalManager & manager
00090     );
00091 
00094     ~SIPEndPoint();
00096 
00103     virtual void ShutDown();
00104 
00108     virtual PString GetDefaultTransport() const;
00109 
00114     virtual PBoolean NewIncomingConnection(
00115       OpalTransport * transport  
00116     );
00117 
00147     virtual PBoolean MakeConnection(
00148       OpalCall & call,                         
00149       const PString & party,                   
00150       void * userData,                         
00151       unsigned int options,                    
00152       OpalConnection::StringOptions * stringOptions  
00153     );
00154 
00164     virtual OpalMediaFormatList GetMediaFormats() const;
00165 
00170     virtual PBoolean GarbageCollection();
00172 
00178     virtual SIPConnection * CreateConnection(
00179       OpalCall & call,                         
00180       const PString & token,                   
00181       void * userData,                         
00182       const SIPURL & destination,              
00183       OpalTransport * transport,               
00184       SIP_PDU * invite,                        
00185       unsigned int options = 0,                
00186       OpalConnection::StringOptions * stringOptions = NULL 
00187 
00188     );
00189     
00192     virtual PBoolean SetupTransfer(
00193       const PString & token,        
00194       const PString & callIdentity, 
00195       const PString & remoteParty,  
00196       void * userData = NULL        
00197     );
00198     
00202     virtual PBoolean ForwardConnection(
00203       SIPConnection & connection,     
00204       const PString & forwardParty    
00205     );
00206 
00208   
00211 
00215     OpalTransport * CreateTransport(
00216       const OpalTransportAddress & remoteAddress,
00217       const OpalTransportAddress & localAddress = OpalTransportAddress()
00218     );
00219 
00220     virtual void HandlePDU(
00221       OpalTransport & transport
00222     );
00223 
00226     virtual PBoolean OnReceivedPDU(
00227       OpalTransport & transport,
00228       SIP_PDU * pdu
00229     );
00230 
00233     virtual bool OnReceivedConnectionlessPDU(
00234       OpalTransport & transport, 
00235       SIP_PDU * pdu
00236     );
00237 
00240     virtual void OnReceivedResponse(
00241       SIPTransaction & transaction,
00242       SIP_PDU & response
00243     );
00244 
00247     virtual PBoolean OnReceivedINVITE(
00248       OpalTransport & transport,
00249       SIP_PDU * pdu
00250     );
00251 
00254     virtual void OnReceivedIntervalTooBrief(
00255       SIPTransaction & transaction, 
00256       SIP_PDU & response)
00257     ;
00258   
00261     virtual void OnReceivedAuthenticationRequired(
00262       SIPTransaction & transaction,
00263       SIP_PDU & response
00264     );
00265 
00269     virtual void OnReceivedOK(
00270       SIPTransaction & transaction,
00271       SIP_PDU & response
00272     );
00273     
00276     virtual PBoolean OnReceivedNOTIFY(
00277       OpalTransport & transport,
00278       SIP_PDU & response
00279     );
00280 
00283     virtual PBoolean OnReceivedREGISTER(
00284       OpalTransport & transport, 
00285       SIP_PDU & pdu
00286     );
00287 
00290     virtual PBoolean OnReceivedSUBSCRIBE(
00291       OpalTransport & transport, 
00292       SIP_PDU & pdu
00293     );
00294 
00297     virtual void OnReceivedMESSAGE(
00298       OpalTransport & transport,
00299       SIP_PDU & response
00300     );
00301     
00304     virtual void OnTransactionFailed(
00305       SIPTransaction & transaction
00306     );
00307     
00315     virtual void OnRTPStatistics(
00316       const SIPConnection & connection,  
00317       const RTP_Session & session         
00318     ) const;
00320  
00321 
00326     PSafePtr<SIPConnection> GetSIPConnectionWithLock(
00327       const PString & token,     
00328       PSafetyMode mode = PSafeReadWrite
00329     ) { return PSafePtrCast<OpalConnection, SIPConnection>(GetConnectionWithLock(token, mode)); }
00330 
00331     virtual PBoolean IsAcceptedAddress(const SIPURL & toAddr);
00332 
00333 
00336     virtual void OnMessageReceived (const SIPURL & from,
00337                     const PString & body);
00338 
00339 
00353     bool Register(
00354       const SIPRegister::Params & params 
00355     );
00356 
00358     bool Register(
00359       const PString & host,
00360       const PString & user = PString::Empty(),
00361       const PString & autName = PString::Empty(),
00362       const PString & password = PString::Empty(),
00363       const PString & authRealm = PString::Empty(),
00364       unsigned expire = 0,
00365       const PTimeInterval & minRetryTime = PMaxTimeInterval, 
00366       const PTimeInterval & maxRetryTime = PMaxTimeInterval
00367     );
00368 
00373     bool Unregister(const PString & aor);
00374 
00377     bool UnregisterAll();
00378     
00382     PBoolean Subscribe(
00383       SIPSubscribe::SubscribeType & type,
00384       unsigned expire,
00385       const PString & to
00386     );
00387 
00388 
00389     PBoolean Unsubscribe(
00390       SIPSubscribe::SubscribeType & type,
00391       const PString & to
00392     );
00393 
00394 
00397     PBoolean Message (
00398       const PString & to, 
00399       const PString & body
00400     );
00401     
00402 
00406     PBoolean Publish(
00407       const PString & to,
00408       const PString & body,
00409       unsigned expire = 0
00410     );
00411     
00412 
00415     PBoolean Ping(
00416       const PString & to
00417     );
00418 
00421     virtual void OnMWIReceived (
00422       const PString & to,
00423       SIPSubscribe::MWIType type,
00424       const PString & msgs);
00425     
00426     
00429     virtual void OnPresenceInfoReceived (
00430       const PString & user,
00431       const PString & basic,
00432       const PString & note);
00433 
00434     
00439     virtual void OnRegistrationStatus(
00440       const PString & aor,
00441       PBoolean wasRegistering,
00442       PBoolean reRegistering,
00443       SIP_PDU::StatusCodes reason
00444     );
00445 
00450     virtual void OnRegistrationFailed(
00451       const PString & aor,
00452       SIP_PDU::StatusCodes reason,
00453       PBoolean wasRegistering
00454     );
00455 
00460     virtual void OnRegistered(
00461       const PString & aor,
00462       PBoolean wasRegistering
00463     );
00464 
00465     
00469     PBoolean IsRegistered(const PString & aor);
00470 
00474     PBoolean IsSubscribed(
00475       SIPSubscribe::SubscribeType type,
00476       const PString & to); 
00477 
00478 
00481     unsigned GetRegistrationsCount () { return activeSIPHandlers.GetRegistrationsCount (); }
00482     
00483 
00488     virtual void OnMessageFailed(
00489       const SIPURL & messageUrl,
00490       SIP_PDU::StatusCodes reason);
00491     
00492 
00493     void SetMIMEForm(PBoolean v) { mimeForm = v; }
00494     PBoolean GetMIMEForm() const { return mimeForm; }
00495 
00496     void SetMaxRetries(unsigned r) { maxRetries = r; }
00497     unsigned GetMaxRetries() const { return maxRetries; }
00498 
00499     void SetRetryTimeouts(
00500       const PTimeInterval & t1,
00501       const PTimeInterval & t2
00502     ) { retryTimeoutMin = t1; retryTimeoutMax = t2; }
00503     const PTimeInterval & GetRetryTimeoutMin() const { return retryTimeoutMin; }
00504     const PTimeInterval & GetRetryTimeoutMax() const { return retryTimeoutMax; }
00505 
00506     void SetNonInviteTimeout(
00507       const PTimeInterval & t
00508     ) { nonInviteTimeout = t; }
00509     const PTimeInterval & GetNonInviteTimeout() const { return nonInviteTimeout; }
00510 
00511     void SetPduCleanUpTimeout(
00512       const PTimeInterval & t
00513     ) { pduCleanUpTimeout = t; }
00514     const PTimeInterval & GetPduCleanUpTimeout() const { return pduCleanUpTimeout; }
00515 
00516     void SetInviteTimeout(
00517       const PTimeInterval & t
00518     ) { inviteTimeout = t; }
00519     const PTimeInterval & GetInviteTimeout() const { return inviteTimeout; }
00520 
00521     void SetAckTimeout(
00522       const PTimeInterval & t
00523     ) { ackTimeout = t; }
00524     const PTimeInterval & GetAckTimeout() const { return ackTimeout; }
00525 
00526     void SetRegistrarTimeToLive(
00527       const PTimeInterval & t
00528     ) { registrarTimeToLive = t; }
00529     const PTimeInterval & GetRegistrarTimeToLive() const { return registrarTimeToLive; }
00530     
00531     void SetNotifierTimeToLive(
00532       const PTimeInterval & t
00533     ) { notifierTimeToLive = t; }
00534     const PTimeInterval & GetNotifierTimeToLive() const { return notifierTimeToLive; }
00535     
00536     void SetNATBindingTimeout(
00537       const PTimeInterval & t
00538     ) { natBindingTimeout = t; natBindingTimer.RunContinuous (natBindingTimeout); }
00539     const PTimeInterval & GetNATBindingTimeout() const { return natBindingTimeout; }
00540 
00541     void AddTransaction(
00542       SIPTransaction * transaction
00543     ) { transactions.SetAt(transaction->GetTransactionID(), transaction); }
00544 
00545     PSafePtr<SIPTransaction> GetTransaction(const PString & transactionID, PSafetyMode mode = PSafeReadWrite)
00546     { return transactions.FindWithLock(transactionID, mode); }
00547     
00550     unsigned GetNextCSeq() { return ++lastSentCSeq; }
00551 
00552     
00555     PBoolean GetAuthentication(const PString & authRealm, SIPAuthentication &); 
00556     
00557 
00563     virtual SIPURL GetRegisteredPartyName(const SIPURL &);
00564 
00565 
00568     virtual SIPURL GetDefaultRegisteredPartyName();
00569     
00570 
00582     SIPURL GetContactURL(const OpalTransport &transport, const PString & userName, const PString & host);
00583 
00584 
00594     virtual SIPURL GetLocalURL(
00595        const OpalTransport & transport,             
00596        const PString & userName = PString::Empty()  
00597     );
00598     
00599     
00602     const SIPURL & GetProxy() const { return proxy; }
00603 
00604     
00607     void SetProxy(const SIPURL & url);
00608     
00609     
00612     void SetProxy(
00613       const PString & hostname,
00614       const PString & username,
00615       const PString & password
00616     );
00617 
00618     
00625     virtual PString GetUserAgent() const;
00626         
00629     void SetUserAgent(const PString & str) { userAgentString = str; }
00630 
00631 
00632     PBoolean SendResponse(
00633       SIP_PDU::StatusCodes code, 
00634       OpalTransport & transport, 
00635       SIP_PDU & pdu
00636     );
00637 
00640     enum NATBindingRefreshMethod{
00641       None,
00642       Options,
00643       EmptyRequest,
00644       NumMethods
00645     };
00646 
00647 
00650     void SetNATBindingRefreshMethod(const NATBindingRefreshMethod m) { natMethod = m; }
00651 
00652     virtual SIPRegisterHandler * CreateRegisterHandler(const SIPRegister::Params & params);
00653 
00654   protected:
00655     PDECLARE_NOTIFIER(PThread, SIPEndPoint, TransportThreadMain);
00656     PDECLARE_NOTIFIER(PTimer, SIPEndPoint, NATBindingRefresh);
00657 
00658     SIPURL        proxy;
00659     PString       userAgentString;
00660 
00661     bool          mimeForm;
00662     unsigned      maxRetries;
00663     PTimeInterval retryTimeoutMin;   // T1
00664     PTimeInterval retryTimeoutMax;   // T2
00665     PTimeInterval nonInviteTimeout;  // T3
00666     PTimeInterval pduCleanUpTimeout; // T4
00667     PTimeInterval inviteTimeout;
00668     PTimeInterval ackTimeout;
00669     PTimeInterval registrarTimeToLive;
00670     PTimeInterval notifierTimeToLive;
00671     PTimeInterval natBindingTimeout;
00672     
00673     SIPHandlersList   activeSIPHandlers;
00674 
00675     PSafeDictionary<PString, SIPTransaction> transactions;
00676 
00677     PTimer                  natBindingTimer;
00678     NATBindingRefreshMethod natMethod;
00679     
00680     PAtomicInteger          lastSentCSeq;    
00681 
00682     struct SIP_PDU_Work
00683     {
00684       SIP_PDU_Work()
00685       { ep = NULL; pdu = NULL; }
00686 
00687       SIPEndPoint * ep;
00688       SIP_PDU * pdu;
00689       PString callID;
00690     };
00691 
00692     typedef std::queue<SIP_PDU_Work *> SIP_PDUWorkQueue;
00693 
00694     class SIP_PDU_Thread : public PThreadPoolWorkerBase
00695     {
00696       public:
00697         SIP_PDU_Thread(PThreadPoolBase & _pool);
00698         unsigned GetWorkSize() const;
00699         void OnAddWork(SIP_PDU_Work * work);
00700         void OnRemoveWork(SIP_PDU_Work *);
00701         void Shutdown();
00702         void Main();
00703 
00704       protected:
00705         PMutex mutex;
00706         PSyncPoint sync;
00707         SIP_PDUWorkQueue pduQueue;
00708     };
00709 
00710     typedef PThreadPool<SIP_PDU_Work, SIP_PDU_Thread> SIPMainThreadPool;
00711     SIPMainThreadPool threadPool;
00712 };
00713 
00714 #endif // __OPAL_SIPEP_H
00715 
00716 
00717 // End of File ///////////////////////////////////////////////////////////////

Generated on Wed May 7 00:56:03 2008 for OPAL by  doxygen 1.5.1