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: 19497 $
00028  * $Author: csoutheren $
00029  * $Date: 2008-02-13 11:37:13 +0000 (Wed, 13 Feb 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 
00102     virtual PString GetDefaultTransport() const;
00103 
00108     virtual PBoolean NewIncomingConnection(
00109       OpalTransport * transport  
00110     );
00111 
00141     virtual PBoolean MakeConnection(
00142       OpalCall & call,                         
00143       const PString & party,                   
00144       void * userData,                         
00145       unsigned int options,                    
00146       OpalConnection::StringOptions * stringOptions  
00147     );
00148 
00158     virtual OpalMediaFormatList GetMediaFormats() const;
00159 
00164     virtual PBoolean GarbageCollection();
00166 
00172     virtual SIPConnection * CreateConnection(
00173       OpalCall & call,                         
00174       const PString & token,                   
00175       void * userData,                         
00176       const SIPURL & destination,              
00177       OpalTransport * transport,               
00178       SIP_PDU * invite,                        
00179       unsigned int options = 0,                
00180       OpalConnection::StringOptions * stringOptions = NULL 
00181 
00182     );
00183     
00186     virtual PBoolean SetupTransfer(
00187       const PString & token,        
00188       const PString & callIdentity, 
00189       const PString & remoteParty,  
00190       void * userData = NULL        
00191     );
00192     
00196     virtual PBoolean ForwardConnection(
00197       SIPConnection & connection,     
00198       const PString & forwardParty    
00199     );
00200 
00202   
00205 
00209     OpalTransport * CreateTransport(
00210       const OpalTransportAddress & remoteAddress,
00211       const OpalTransportAddress & localAddress = OpalTransportAddress()
00212     );
00213 
00214     virtual void HandlePDU(
00215       OpalTransport & transport
00216     );
00217 
00220     virtual PBoolean OnReceivedPDU(
00221       OpalTransport & transport,
00222       SIP_PDU * pdu
00223     );
00224 
00227     virtual bool OnReceivedConnectionlessPDU(
00228       OpalTransport & transport, 
00229       SIP_PDU * pdu
00230     );
00231 
00234     virtual void OnReceivedResponse(
00235       SIPTransaction & transaction,
00236       SIP_PDU & response
00237     );
00238 
00241     virtual PBoolean OnReceivedINVITE(
00242       OpalTransport & transport,
00243       SIP_PDU * pdu
00244     );
00245 
00248     virtual void OnReceivedIntervalTooBrief(
00249       SIPTransaction & transaction, 
00250       SIP_PDU & response)
00251     ;
00252   
00255     virtual void OnReceivedAuthenticationRequired(
00256       SIPTransaction & transaction,
00257       SIP_PDU & response
00258     );
00259 
00263     virtual void OnReceivedOK(
00264       SIPTransaction & transaction,
00265       SIP_PDU & response
00266     );
00267     
00270     virtual PBoolean OnReceivedNOTIFY(
00271       OpalTransport & transport,
00272       SIP_PDU & response
00273     );
00274 
00277     virtual PBoolean OnReceivedREGISTER(
00278       OpalTransport & transport, 
00279       SIP_PDU & pdu
00280     );
00281 
00284     virtual PBoolean OnReceivedSUBSCRIBE(
00285       OpalTransport & transport, 
00286       SIP_PDU & pdu
00287     );
00288 
00291     virtual void OnReceivedMESSAGE(
00292       OpalTransport & transport,
00293       SIP_PDU & response
00294     );
00295     
00298     virtual void OnTransactionFailed(
00299       SIPTransaction & transaction
00300     );
00301     
00309     virtual void OnRTPStatistics(
00310       const SIPConnection & connection,  
00311       const RTP_Session & session         
00312     ) const;
00314  
00315 
00320     PSafePtr<SIPConnection> GetSIPConnectionWithLock(
00321       const PString & token,     
00322       PSafetyMode mode = PSafeReadWrite
00323     ) { return PSafePtrCast<OpalConnection, SIPConnection>(GetConnectionWithLock(token, mode)); }
00324 
00325     virtual PBoolean IsAcceptedAddress(const SIPURL & toAddr);
00326 
00327 
00330     virtual void OnMessageReceived (const SIPURL & from,
00331                     const PString & body);
00332 
00333 
00347     bool Register(
00348       const SIPRegister::Params & params 
00349     );
00350 
00352     bool Register(
00353       const PString & host,
00354       const PString & user = PString::Empty(),
00355       const PString & autName = PString::Empty(),
00356       const PString & password = PString::Empty(),
00357       const PString & authRealm = PString::Empty(),
00358       unsigned expire = 0,
00359       const PTimeInterval & minRetryTime = PMaxTimeInterval, 
00360       const PTimeInterval & maxRetryTime = PMaxTimeInterval
00361     );
00362 
00367     bool Unregister(const PString & aor);
00368 
00371     bool UnregisterAll();
00372     
00376     PBoolean Subscribe(
00377       SIPSubscribe::SubscribeType & type,
00378       unsigned expire,
00379       const PString & to
00380     );
00381 
00382 
00383     PBoolean Unsubscribe(
00384       SIPSubscribe::SubscribeType & type,
00385       const PString & to
00386     );
00387 
00388 
00391     PBoolean Message (
00392       const PString & to, 
00393       const PString & body
00394     );
00395     
00396 
00400     PBoolean Publish(
00401       const PString & to,
00402       const PString & body,
00403       unsigned expire = 0
00404     );
00405     
00406 
00409     PBoolean Ping(
00410       const PString & to
00411     );
00412 
00415     virtual void OnMWIReceived (
00416       const PString & to,
00417       SIPSubscribe::MWIType type,
00418       const PString & msgs);
00419     
00420     
00423     virtual void OnPresenceInfoReceived (
00424       const PString & user,
00425       const PString & basic,
00426       const PString & note);
00427 
00428     
00433     virtual void OnRegistrationStatus(
00434       const PString & aor,
00435       PBoolean wasRegistering,
00436       PBoolean reRegistering,
00437       SIP_PDU::StatusCodes reason
00438     );
00439 
00444     virtual void OnRegistrationFailed(
00445       const PString & aor,
00446       SIP_PDU::StatusCodes reason,
00447       PBoolean wasRegistering
00448     );
00449 
00454     virtual void OnRegistered(
00455       const PString & aor,
00456       PBoolean wasRegistering
00457     );
00458 
00459     
00463     PBoolean IsRegistered(const PString & aor);
00464 
00468     PBoolean IsSubscribed(
00469       SIPSubscribe::SubscribeType type,
00470       const PString & to); 
00471 
00472 
00475     unsigned GetRegistrationsCount () { return activeSIPHandlers.GetRegistrationsCount (); }
00476     
00477 
00482     virtual void OnMessageFailed(
00483       const SIPURL & messageUrl,
00484       SIP_PDU::StatusCodes reason);
00485     
00486 
00487     void SetMIMEForm(PBoolean v) { mimeForm = v; }
00488     PBoolean GetMIMEForm() const { return mimeForm; }
00489 
00490     void SetMaxRetries(unsigned r) { maxRetries = r; }
00491     unsigned GetMaxRetries() const { return maxRetries; }
00492 
00493     void SetRetryTimeouts(
00494       const PTimeInterval & t1,
00495       const PTimeInterval & t2
00496     ) { retryTimeoutMin = t1; retryTimeoutMax = t2; }
00497     const PTimeInterval & GetRetryTimeoutMin() const { return retryTimeoutMin; }
00498     const PTimeInterval & GetRetryTimeoutMax() const { return retryTimeoutMax; }
00499 
00500     void SetNonInviteTimeout(
00501       const PTimeInterval & t
00502     ) { nonInviteTimeout = t; }
00503     const PTimeInterval & GetNonInviteTimeout() const { return nonInviteTimeout; }
00504 
00505     void SetPduCleanUpTimeout(
00506       const PTimeInterval & t
00507     ) { pduCleanUpTimeout = t; }
00508     const PTimeInterval & GetPduCleanUpTimeout() const { return pduCleanUpTimeout; }
00509 
00510     void SetInviteTimeout(
00511       const PTimeInterval & t
00512     ) { inviteTimeout = t; }
00513     const PTimeInterval & GetInviteTimeout() const { return inviteTimeout; }
00514 
00515     void SetAckTimeout(
00516       const PTimeInterval & t
00517     ) { ackTimeout = t; }
00518     const PTimeInterval & GetAckTimeout() const { return ackTimeout; }
00519 
00520     void SetRegistrarTimeToLive(
00521       const PTimeInterval & t
00522     ) { registrarTimeToLive = t; }
00523     const PTimeInterval & GetRegistrarTimeToLive() const { return registrarTimeToLive; }
00524     
00525     void SetNotifierTimeToLive(
00526       const PTimeInterval & t
00527     ) { notifierTimeToLive = t; }
00528     const PTimeInterval & GetNotifierTimeToLive() const { return notifierTimeToLive; }
00529     
00530     void SetNATBindingTimeout(
00531       const PTimeInterval & t
00532     ) { natBindingTimeout = t; natBindingTimer.RunContinuous (natBindingTimeout); }
00533     const PTimeInterval & GetNATBindingTimeout() const { return natBindingTimeout; }
00534 
00535     void AddTransaction(
00536       SIPTransaction * transaction
00537     ) { transactions.SetAt(transaction->GetTransactionID(), transaction); }
00538 
00539     PSafePtr<SIPTransaction> GetTransaction(const PString & transactionID, PSafetyMode mode = PSafeReadWrite)
00540     { return transactions.FindWithLock(transactionID, mode); }
00541     
00544     unsigned GetNextCSeq() { return ++lastSentCSeq; }
00545 
00546     
00549     PBoolean GetAuthentication(const PString & authRealm, SIPAuthentication &); 
00550     
00551 
00557     virtual SIPURL GetRegisteredPartyName(const SIPURL &);
00558 
00559 
00562     virtual SIPURL GetDefaultRegisteredPartyName();
00563     
00564 
00576     SIPURL GetContactURL(const OpalTransport &transport, const PString & userName, const PString & host);
00577 
00578 
00588     virtual SIPURL GetLocalURL(
00589        const OpalTransport & transport,             
00590        const PString & userName = PString::Empty()  
00591     );
00592     
00593     
00596     const SIPURL & GetProxy() const { return proxy; }
00597 
00598     
00601     void SetProxy(const SIPURL & url);
00602     
00603     
00606     void SetProxy(
00607       const PString & hostname,
00608       const PString & username,
00609       const PString & password
00610     );
00611 
00612     
00619     virtual PString GetUserAgent() const;
00620         
00623     void SetUserAgent(const PString & str) { userAgentString = str; }
00624 
00625 
00626     PBoolean SendResponse(
00627       SIP_PDU::StatusCodes code, 
00628       OpalTransport & transport, 
00629       SIP_PDU & pdu
00630     );
00631 
00634     enum NATBindingRefreshMethod{
00635       None,
00636       Options,
00637       EmptyRequest,
00638       NumMethods
00639     };
00640 
00641 
00644     void SetNATBindingRefreshMethod(const NATBindingRefreshMethod m) { natMethod = m; }
00645 
00646     virtual SIPRegisterHandler * CreateRegisterHandler(const SIPRegister::Params & params);
00647 
00648   protected:
00649     PDECLARE_NOTIFIER(PThread, SIPEndPoint, TransportThreadMain);
00650     PDECLARE_NOTIFIER(PTimer, SIPEndPoint, NATBindingRefresh);
00651 
00652     SIPURL        proxy;
00653     PString       userAgentString;
00654 
00655     bool          mimeForm;
00656     unsigned      maxRetries;
00657     PTimeInterval retryTimeoutMin;   // T1
00658     PTimeInterval retryTimeoutMax;   // T2
00659     PTimeInterval nonInviteTimeout;  // T3
00660     PTimeInterval pduCleanUpTimeout; // T4
00661     PTimeInterval inviteTimeout;
00662     PTimeInterval ackTimeout;
00663     PTimeInterval registrarTimeToLive;
00664     PTimeInterval notifierTimeToLive;
00665     PTimeInterval natBindingTimeout;
00666     
00667     SIPHandlersList   activeSIPHandlers;
00668 
00669     PSafeDictionary<PString, SIPTransaction> transactions;
00670 
00671     PTimer                  natBindingTimer;
00672     NATBindingRefreshMethod natMethod;
00673     
00674     PAtomicInteger          lastSentCSeq;    
00675 
00676     struct SIP_PDU_Work
00677     {
00678       SIP_PDU_Work()
00679       { ep = NULL; pdu = NULL; }
00680 
00681       SIPEndPoint * ep;
00682       SIP_PDU * pdu;
00683       PString callID;
00684     };
00685 
00686     typedef std::queue<SIP_PDU_Work *> SIP_PDUWorkQueue;
00687 
00688     class SIP_PDU_Thread : public PThreadPoolWorkerBase
00689     {
00690       public:
00691         SIP_PDU_Thread(PThreadPoolBase & _pool);
00692         unsigned GetWorkSize() const;
00693         void OnAddWork(SIP_PDU_Work * work);
00694         void OnRemoveWork(SIP_PDU_Work *);
00695         void Shutdown();
00696         void Main();
00697 
00698       protected:
00699         PMutex mutex;
00700         PSyncPoint sync;
00701         SIP_PDUWorkQueue pduQueue;
00702     };
00703 
00704     typedef PThreadPool<SIP_PDU_Work, SIP_PDU_Thread> SIPMainThreadPool;
00705     SIPMainThreadPool threadPool;
00706 };
00707 
00708 #endif // __OPAL_SIPEP_H
00709 
00710 
00711 // End of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 07:36:39 2008 for OPAL by  doxygen 1.5.1