sippdu.h

Go to the documentation of this file.
00001 /*
00002  * sippdu.h
00003  *
00004  * Session Initiation Protocol PDU support.
00005  *
00006  * Open Phone Abstraction Library (OPAL)
00007  * Formally known as the Open H323 project.
00008  *
00009  * Copyright (c) 2002 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: 22097 $
00028  * $Author: rjongbloed $
00029  * $Date: 2009-02-21 04:55:10 +0000 (Sat, 21 Feb 2009) $
00030  */
00031 
00032 #ifndef OPAL_SIP_SIPPDU_H
00033 #define OPAL_SIP_SIPPDU_H
00034 
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 
00039 #include <opal/buildopts.h>
00040 
00041 #if OPAL_SIP
00042 
00043 #include <ptclib/mime.h>
00044 #include <ptclib/url.h>
00045 #include <sip/sdp.h>
00046 #include <opal/rtpconn.h>
00047 
00048  
00049 class OpalTransport;
00050 class OpalTransportAddress;
00051 class OpalProductInfo;
00052 
00053 class SIPEndPoint;
00054 class SIPConnection;
00055 class SIP_PDU;
00056 
00057 
00059 // SIPURL
00060 
00066 class SIPURL : public PURL
00067 {
00068   PCLASSINFO(SIPURL, PURL);
00069   public:
00070     SIPURL();
00071 
00074     SIPURL(
00075       const char * cstr,    
00076       const char * defaultScheme = NULL 
00077     );
00078 
00081     SIPURL(
00082       const PString & str,  
00083       const char * defaultScheme = NULL 
00084     );
00085 
00093     SIPURL(
00094       const PString & name,
00095       const OpalTransportAddress & address,
00096       WORD listenerPort = 0
00097     );
00098 
00099     SIPURL(
00100       const OpalTransportAddress & _address, 
00101       WORD listenerPort = 0
00102     );
00103 
00112     virtual Comparison Compare(
00113       const PObject & obj   
00114     ) const;
00115 
00119     PString AsQuotedString() const;
00120 
00123     PString GetDisplayName(PBoolean useDefault = PTrue) const;
00124     
00125     void SetDisplayName(const PString & str) 
00126       { displayName = str; }
00127 
00130     PString GetFieldParameters() const { return fieldParameters; }
00131 
00134     void SetFieldParameters(const PString & str ) { fieldParameters = str; }
00135 
00138     OpalTransportAddress GetHostAddress() const;
00139 
00140     enum UsageContext {
00141       ExternalURI,  
00142       RequestURI,   
00143       ToURI,        
00144       FromURI,      
00145       ContactURI,   
00146       RouteURI,     
00147       RegisterURI   
00148     };
00149 
00155     void Sanitise(
00156       UsageContext context  
00157     );
00158 
00164     PBoolean AdjustToDNS(
00165       PINDEX entry = 0  
00166     );
00167 
00169     static PString GenerateTag();
00170 
00172     void SetTag(
00173       const PString & tag = GenerateTag()
00174     );
00175 
00176   protected:
00177     void ParseAsAddress(const PString & name, const OpalTransportAddress & _address, WORD listenerPort = 0);
00178 
00197     virtual PBoolean InternalParse(
00198       const char * cstr,
00199       const char * defaultScheme
00200     );
00201 
00202     PString displayName;
00203     PString fieldParameters;
00204 };
00205 
00206 
00208 // SIPMIMEInfo
00209 
00240 class SIPMIMEInfo : public PMIMEInfo
00241 {
00242   PCLASSINFO(SIPMIMEInfo, PMIMEInfo);
00243   public:
00244     SIPMIMEInfo(bool compactForm = false);
00245 
00246     virtual void PrintOn(ostream & strm) const;
00247     virtual void ReadFrom(istream & strm);
00248 
00249     void SetCompactForm(bool form) { compactForm = form; }
00250 
00251     PString GetContentType() const;
00252     void SetContentType(const PString & v);
00253 
00254     PString GetContentEncoding() const;
00255     void SetContentEncoding(const PString & v);
00256 
00257     PString GetFrom() const;
00258     void SetFrom(const PString & v);
00259 
00260     PString GetPAssertedIdentity() const;
00261     void SetPAssertedIdentity(const PString & v);
00262 
00263     PString GetPPreferredIdentity() const;
00264     void SetPPreferredIdentity(const PString & v);
00265 
00266     PString GetAccept() const;
00267     void SetAccept(const PString & v);
00268 
00269     PString GetAcceptEncoding() const;
00270     void SetAcceptEncoding(const PString & v);
00271 
00272     PString GetAcceptLanguage() const;
00273     void SetAcceptLanguage(const PString & v);
00274 
00275     PString GetAllow() const;
00276     void SetAllow(const PString & v);
00277 
00278     PString GetCallID() const;
00279     void SetCallID(const PString & v);
00280 
00281     PString GetContact() const;
00282     bool GetContacts(std::list<SIPURL> & contacts) const;
00283     void SetContact(const PString & v);
00284     void SetContact(const SIPURL & url);
00285 
00286     PString GetSubject() const;
00287     void SetSubject(const PString & v);
00288 
00289     PString GetTo() const;
00290     void SetTo(const PString & v);
00291 
00292     PString GetVia() const;
00293     void SetVia(const PString & v);
00294 
00295     PStringList GetViaList() const;
00296     void SetViaList(const PStringList & v);
00297 
00298     PString GetReferTo() const;
00299     void SetReferTo(const PString & r);
00300 
00301     PString GetReferredBy() const;
00302     void SetReferredBy(const PString & r);
00303 
00304     PINDEX  GetContentLength() const;
00305     void SetContentLength(PINDEX v);
00306     PBoolean IsContentLengthPresent() const;
00307 
00308     PString GetCSeq() const;
00309     void SetCSeq(const PString & v);
00310 
00311     PString GetDate() const;
00312     void SetDate(const PString & v);
00313     void SetDate(const PTime & t);
00314     void SetDate(void); // set to current date
00315 
00316     unsigned GetExpires(unsigned dflt = UINT_MAX) const;// returns default value if not found
00317     void SetExpires(unsigned v);
00318 
00319     PINDEX GetMaxForwards() const;
00320     void SetMaxForwards(PINDEX v);
00321 
00322     PINDEX GetMinExpires() const;
00323     void SetMinExpires(PINDEX v);
00324 
00325     PString GetProxyAuthenticate() const;
00326     void SetProxyAuthenticate(const PString & v);
00327 
00328     PStringList GetRoute() const;
00329     void SetRoute(const PString & v);
00330     void SetRoute(const PStringList & v);
00331 
00332     PStringList GetRecordRoute(bool reversed) const;
00333     void SetRecordRoute(const PStringList & v);
00334 
00335     unsigned GetCSeqIndex() const { return GetCSeq().AsUnsigned(); }
00336 
00337     PString GetSupported() const;
00338     void SetSupported(const PString & v);
00339 
00340     PString GetUnsupported() const;
00341     void SetUnsupported(const PString & v);
00342     
00343     PString GetEvent() const;
00344     void SetEvent(const PString & v);
00345     
00346     PString GetSubscriptionState() const;
00347     void SetSubscriptionState(const PString & v);
00348     
00349     PString GetUserAgent() const;
00350     void SetUserAgent(const PString & v);
00351 
00352     PString GetOrganization() const;
00353     void SetOrganization(const PString & v);
00354 
00355     void GetProductInfo(OpalProductInfo & info);
00356     void SetProductInfo(const PString & ua, const OpalProductInfo & info);
00357 
00358     PString GetWWWAuthenticate() const;
00359     void SetWWWAuthenticate(const PString & v);
00360 
00361     PString GetSIPIfMatch() const;
00362     void SetSIPIfMatch(const PString & v);
00363 
00364     PString GetSIPETag() const;
00365     void SetSIPETag(const PString & v);
00366 
00367     PString GetRequire() const;
00368     void SetRequire(const PString & v, bool overwrite);
00369 
00370     void GetAlertInfo(PString & info, int & appearance);
00371     void SetAlertInfo(const PString & info, int appearance);
00372 
00375     PString GetFieldParameter(
00376       const PString & fieldName,    
00377       const PString & paramName,    
00378       const PString & defaultValue = PString::Empty()  
00379     ) const { return ExtractFieldParameter((*this)(fieldName), paramName, defaultValue); }
00380 
00385     void SetFieldParameter(
00386       const PString & fieldName,    
00387       const PString & paramName,    
00388       const PString & newValue      
00389     ) { SetAt(fieldName, InsertFieldParameter((*this)(fieldName), paramName, newValue)); }
00390 
00393     static PString ExtractFieldParameter(
00394       const PString & fieldValue,   
00395       const PString & paramName,    
00396       const PString & defaultValue = PString::Empty()  
00397     );
00398 
00403     static PString InsertFieldParameter(
00404       const PString & fieldValue,   
00405       const PString & paramName,    
00406       const PString & newValue      
00407     );
00408 
00409   protected:
00412     PStringList GetRouteList(const char * name, bool reversed) const;
00413 
00417     void SetRouteList(const char * name, const PStringList & v);
00418 
00420     bool compactForm;
00421 };
00422 
00423 
00425 // SIPAuthentication
00426 
00427 class SIPAuthentication : public PObject
00428 {
00429   PCLASSINFO(SIPAuthentication, PObject);
00430   public:
00431     SIPAuthentication();
00432 
00433     virtual Comparison Compare(
00434       const PObject & other
00435     ) const;
00436 
00437     virtual PBoolean Parse(
00438       const PString & auth,
00439       PBoolean proxy
00440     ) = 0;
00441 
00442     virtual PBoolean Authorise(
00443       SIP_PDU & pdu
00444     ) const =  0;
00445 
00446     virtual PBoolean IsProxy() const               { return isProxy; }
00447 
00448     virtual PString GetUsername() const   { return username; }
00449     virtual PString GetPassword() const   { return password; }
00450     virtual PString GetAuthRealm() const  { return PString::Empty(); }
00451 
00452     virtual void SetUsername(const PString & user) { username = user; }
00453     virtual void SetPassword(const PString & pass) { password = pass; }
00454     virtual void SetAuthRealm(const PString &)     { }
00455 
00456     PString GetAuthParam(const PString & auth, const char * name) const;
00457     PString AsHex(PMessageDigest5::Code & digest) const;
00458     PString AsHex(const PBYTEArray & data) const;
00459 
00460     static SIPAuthentication * ParseAuthenticationRequired(bool isProxy,
00461                                                 const PString & line,
00462                                                       PString & errorMsg);
00463 
00464   protected:
00465     PBoolean  isProxy;
00466 
00467     PString   username;
00468     PString   password;
00469 };
00470 
00471 typedef PFactory<SIPAuthentication> SIPAuthenticationFactory;
00472 
00474 
00475 class SIPDigestAuthentication : public SIPAuthentication
00476 {
00477   PCLASSINFO(SIPDigestAuthentication, SIPAuthentication);
00478   public:
00479     SIPDigestAuthentication();
00480 
00481     SIPDigestAuthentication & operator =(
00482       const SIPDigestAuthentication & auth
00483     );
00484 
00485     virtual Comparison Compare(
00486       const PObject & other
00487     ) const;
00488 
00489     virtual PBoolean Parse(
00490       const PString & auth,
00491       PBoolean proxy
00492     );
00493 
00494     virtual PBoolean Authorise(
00495       SIP_PDU & pdu
00496     ) const;
00497 
00498     virtual PString GetAuthRealm() const         { return authRealm; }
00499     virtual void SetAuthRealm(const PString & r) { authRealm = r; }
00500 
00501     enum Algorithm {
00502       Algorithm_MD5,
00503       NumAlgorithms
00504     };
00505     const PString & GetNonce() const       { return nonce; }
00506     Algorithm GetAlgorithm() const         { return algorithm; }
00507     const PString & GetOpaque() const      { return opaque; }
00508 
00509   protected:
00510     PString   authRealm;
00511     PString   nonce;
00512     Algorithm algorithm;
00513     PString   opaque;
00514 
00515     PBoolean qopAuth;
00516     PBoolean qopAuthInt;
00517     PString cnonce;
00518     mutable PAtomicInteger nonceCount;
00519 };
00520 
00522 // SIP_PDU
00523 
00529 class SIP_PDU : public PSafeObject
00530 {
00531   PCLASSINFO(SIP_PDU, PSafeObject);
00532   public:
00533     enum Methods {
00534       Method_INVITE,
00535       Method_ACK,
00536       Method_OPTIONS,
00537       Method_BYE,
00538       Method_CANCEL,
00539       Method_REGISTER,
00540       Method_SUBSCRIBE,
00541       Method_NOTIFY,
00542       Method_REFER,
00543       Method_MESSAGE,
00544       Method_INFO,
00545       Method_PING,
00546       Method_PUBLISH,
00547       NumMethods
00548     };
00549 
00550     enum StatusCodes {
00551       IllegalStatusCode,
00552       Local_TransportError,
00553       Local_BadTransportAddress,
00554 
00555       Information_Trying                  = 100,
00556       Information_Ringing                 = 180,
00557       Information_CallForwarded           = 181,
00558       Information_Queued                  = 182,
00559       Information_Session_Progress        = 183,
00560 
00561       Successful_OK                       = 200,
00562       Successful_Accepted                         = 202,
00563 
00564       Redirection_MultipleChoices         = 300,
00565       Redirection_MovedPermanently        = 301,
00566       Redirection_MovedTemporarily        = 302,
00567       Redirection_UseProxy                = 305,
00568       Redirection_AlternativeService      = 380,
00569 
00570       Failure_BadRequest                  = 400,
00571       Failure_UnAuthorised                = 401,
00572       Failure_PaymentRequired             = 402,
00573       Failure_Forbidden                   = 403,
00574       Failure_NotFound                    = 404,
00575       Failure_MethodNotAllowed            = 405,
00576       Failure_NotAcceptable               = 406,
00577       Failure_ProxyAuthenticationRequired = 407,
00578       Failure_RequestTimeout              = 408,
00579       Failure_Conflict                    = 409,
00580       Failure_Gone                        = 410,
00581       Failure_LengthRequired              = 411,
00582       Failure_RequestEntityTooLarge       = 413,
00583       Failure_RequestURITooLong           = 414,
00584       Failure_UnsupportedMediaType        = 415,
00585       Failure_UnsupportedURIScheme        = 416,
00586       Failure_BadExtension                = 420,
00587       Failure_ExtensionRequired           = 421,
00588       Failure_IntervalTooBrief            = 423,
00589       Failure_TemporarilyUnavailable      = 480,
00590       Failure_TransactionDoesNotExist     = 481,
00591       Failure_LoopDetected                = 482,
00592       Failure_TooManyHops                 = 483,
00593       Failure_AddressIncomplete           = 484,
00594       Failure_Ambiguous                   = 485,
00595       Failure_BusyHere                    = 486,
00596       Failure_RequestTerminated           = 487,
00597       Failure_NotAcceptableHere           = 488,
00598       Failure_BadEvent                    = 489,
00599       Failure_RequestPending              = 491,
00600       Failure_Undecipherable              = 493,
00601 
00602       Failure_InternalServerError         = 500,
00603       Failure_NotImplemented              = 501,
00604       Failure_BadGateway                  = 502,
00605       Failure_ServiceUnavailable          = 503,
00606       Failure_ServerTimeout               = 504,
00607       Failure_SIPVersionNotSupported      = 505,
00608       Failure_MessageTooLarge             = 513,
00609 
00610       GlobalFailure_BusyEverywhere        = 600,
00611       GlobalFailure_Decline               = 603,
00612       GlobalFailure_DoesNotExistAnywhere  = 604,
00613       GlobalFailure_NotAcceptable         = 606,
00614 
00615       MaxStatusCode                       = 699
00616     };
00617 
00618         static const char * GetStatusCodeDescription(int code);
00619     friend ostream & operator<<(ostream & strm, StatusCodes status);
00620 
00621     enum {
00622       MaxSize = 65535
00623     };
00624 
00625     SIP_PDU();
00626 
00629     SIP_PDU(
00630       Methods method,
00631       const SIPURL & dest,
00632       const PString & to,
00633       const PString & from,
00634       const PString & callID,
00635       unsigned cseq,
00636       const OpalTransportAddress & via
00637     );
00640     SIP_PDU(
00641       Methods method,
00642       SIPConnection & connection,
00643       const OpalTransport & transport
00644     );
00645 
00649     SIP_PDU(
00650       const SIP_PDU & request,
00651       StatusCodes code,
00652       const char * contact = NULL,
00653       const char * extra = NULL,
00654       const SDPSessionDescription * sdp = NULL
00655     );
00656     SIP_PDU(const SIP_PDU &);
00657     SIP_PDU & operator=(const SIP_PDU &);
00658     ~SIP_PDU();
00659 
00660     void PrintOn(
00661       ostream & strm
00662     ) const;
00663 
00664     void Construct(
00665       Methods method
00666     );
00667     void Construct(
00668       Methods method,
00669       const SIPURL & dest,
00670       const PString & to,
00671       const PString & from,
00672       const PString & callID,
00673       unsigned cseq,
00674       const OpalTransportAddress & via
00675     );
00676     void Construct(
00677       Methods method,
00678       SIPConnection & connection,
00679       const OpalTransport & transport
00680     );
00681 
00686     bool SetRoute(const PStringList & routeSet);
00687     bool SetRoute(const SIPURL & proxy);
00688 
00691     void SetAllow(unsigned bitmask);
00692 
00695     void AdjustVia(OpalTransport & transport);
00696     
00699     PBoolean Read(
00700       OpalTransport & transport
00701     );
00702 
00705     PBoolean Write(
00706       OpalTransport & transport,
00707       const OpalTransportAddress & remoteAddress = OpalTransportAddress(),
00708       const PString & localInterface = PString::Empty()
00709     );
00710 
00713     bool SendResponse(
00714       OpalTransport & transport,
00715       StatusCodes code,
00716       SIPEndPoint * endpoint = NULL,
00717       const char * contact = NULL,
00718       const char * extra = NULL
00719     );
00720     bool SendResponse(
00721       OpalTransport & transport,
00722       SIP_PDU & response,
00723       SIPEndPoint * endpoint = NULL
00724     );
00725 
00729     PString Build();
00730 
00731     PString GetTransactionID() const;
00732 
00733     Methods GetMethod() const                { return method; }
00734     StatusCodes GetStatusCode () const       { return statusCode; }
00735     const SIPURL & GetURI() const            { return uri; }
00736     unsigned GetVersionMajor() const         { return versionMajor; }
00737     unsigned GetVersionMinor() const         { return versionMinor; }
00738     const PString & GetEntityBody() const    { return entityBody; }
00739           PString & GetEntityBody()          { return entityBody; }
00740     const PString & GetInfo() const          { return info; }
00741     const SIPMIMEInfo & GetMIME() const      { return mime; }
00742           SIPMIMEInfo & GetMIME()            { return mime; }
00743     void SetURI(const SIPURL & newuri)       { uri = newuri; }
00744     SDPSessionDescription * GetSDP();
00745 
00746   protected:
00747     Methods     method;                 // Request type, ==NumMethods for Response
00748     StatusCodes statusCode;
00749     SIPURL      uri;                    // display name & URI, no tag
00750     unsigned    versionMajor;
00751     unsigned    versionMinor;
00752     PString     info;
00753     SIPMIMEInfo mime;
00754     PString     entityBody;
00755 
00756     SDPSessionDescription * m_SDP;
00757 
00758     mutable PString transactionID;
00759 };
00760 
00761 
00762 PQUEUE(SIP_PDU_Queue, SIP_PDU);
00763 
00764 
00765 #if PTRACING
00766 ostream & operator<<(ostream & strm, SIP_PDU::Methods method);
00767 #endif
00768 
00769 
00771 // SIPDialogContext
00772 
00775 class SIPDialogContext
00776 {
00777   public:
00778     SIPDialogContext();
00779 
00780     const PString & GetCallID() const { return m_callId; }
00781     void SetCallID(const PString & id) { m_callId = id; }
00782 
00783     const SIPURL & GetRequestURI() const { return m_requestURI; }
00784     void SetRequestURI(const SIPURL & url) { m_requestURI = url; }
00785     bool SetRequestURI(const PString & uri) { return m_requestURI.Parse(uri); }
00786 
00787     const PString & GetLocalTag() const { return m_localTag; }
00788     void SetLocalTag(const PString & tag) { m_localTag = tag; }
00789 
00790     const SIPURL & GetLocalURI() const { return m_localURI; }
00791     void SetLocalURI(const SIPURL & url);
00792     bool SetLocalURI(const PString & uri);
00793 
00794     const PString & GetRemoteTag() const { return m_remoteTag; }
00795     void SetRemoteTag(const PString & tag) { m_remoteTag = tag; }
00796 
00797     const SIPURL & GetRemoteURI() const { return m_remoteURI; }
00798     void SetRemoteURI(const SIPURL & url);
00799     bool SetRemoteURI(const PString & uri);
00800 
00801     const PStringList & GetRouteSet() const { return m_routeSet; }
00802     void SetRouteSet(const PStringList & routes) { m_routeSet = routes; }
00803     void UpdateRouteSet(const SIPURL & proxy);
00804 
00805     void Update(const SIP_PDU & response);
00806 
00807     unsigned GetNextCSeq() { return ++m_lastSentCSeq; }
00808     bool IsDuplicateCSeq(unsigned sequenceNumber);
00809 
00810     bool IsEstablished() const { return !m_remoteTag.IsEmpty(); }
00811 
00812   protected:
00813     PString     m_callId;
00814     SIPURL      m_requestURI;
00815     SIPURL      m_localURI;
00816     PString     m_localTag;
00817     SIPURL      m_remoteURI;
00818     PString     m_remoteTag;
00819     PStringList m_routeSet;
00820     unsigned    m_lastSentCSeq;
00821     unsigned    m_lastReceivedCSeq;
00822 };
00823 
00824 
00826 // SIPTransaction
00827 
00838 class SIPTransaction : public SIP_PDU
00839 {
00840     PCLASSINFO(SIPTransaction, SIP_PDU);
00841   public:
00842     SIPTransaction(
00843       SIPEndPoint   & endpoint,
00844       OpalTransport & transport,
00845       const PTimeInterval & minRetryTime = PMaxTimeInterval, 
00846       const PTimeInterval & maxRetryTime = PMaxTimeInterval
00847     );
00851     SIPTransaction(
00852       SIPConnection & connection,
00853       OpalTransport & transport,
00854       Methods method = NumMethods
00855     );
00856     ~SIPTransaction();
00857 
00858     PBoolean Start();
00859     bool IsTrying()     const { return state == Trying; }
00860     bool IsProceeding() const { return state == Proceeding; }
00861     bool IsInProgress() const { return state == Trying || state == Proceeding; }
00862     bool IsFailed()     const { return state > Terminated_Success; }
00863     bool IsCompleted()  const { return state >= Completed; }
00864     bool IsCanceled()   const { return state == Cancelling || state == Terminated_Cancelled || state == Terminated_Aborted; }
00865     bool IsTerminated() const { return state >= Terminated_Success; }
00866 
00867     void WaitForCompletion();
00868     PBoolean Cancel();
00869     void Abort();
00870 
00871     virtual PBoolean OnReceivedResponse(SIP_PDU & response);
00872     virtual PBoolean OnCompleted(SIP_PDU & response);
00873 
00874     OpalTransport & GetTransport() const  { return transport; }
00875     SIPConnection * GetConnection() const { return connection; }
00876     PString         GetInterface() const { return m_localInterface; }
00877 
00878     static PString GenerateCallID();
00879     
00880   protected:
00881     void Construct(
00882       const PTimeInterval & minRetryTime = PMaxTimeInterval,
00883       const PTimeInterval & maxRetryTime = PMaxTimeInterval
00884     );
00885     void Construct(
00886       Methods method, 
00887       SIPDialogContext & dialog
00888     );
00889     bool SendPDU(SIP_PDU & pdu);
00890     bool ResendCANCEL();
00891 
00892     PDECLARE_NOTIFIER(PTimer, SIPTransaction, OnRetry);
00893     PDECLARE_NOTIFIER(PTimer, SIPTransaction, OnTimeout);
00894 
00895     enum States {
00896       NotStarted,
00897       Trying,
00898       Proceeding,
00899       Cancelling,
00900       Completed,
00901       Terminated_Success,
00902       Terminated_Timeout,
00903       Terminated_RetriesExceeded,
00904       Terminated_TransportError,
00905       Terminated_Cancelled,
00906       Terminated_Aborted,
00907       NumStates
00908     };
00909     virtual void SetTerminated(States newState);
00910 
00911     SIPEndPoint           & endpoint;
00912     OpalTransport         & transport;
00913     PSafePtr<SIPConnection> connection;
00914     PTimeInterval           retryTimeoutMin; 
00915     PTimeInterval           retryTimeoutMax; 
00916 
00917     States     state;
00918     unsigned   retry;
00919     PTimer     retryTimer;
00920     PTimer     completionTimer;
00921     PSyncPoint completed;
00922     PString              m_localInterface;
00923     OpalTransportAddress m_remoteAddress;
00924 };
00925 
00926 
00928 // SIPInvite
00929 
00935 class SIPInvite : public SIPTransaction
00936 {
00937     PCLASSINFO(SIPInvite, SIPTransaction);
00938   public:
00939     SIPInvite(
00940       SIPConnection & connection,
00941       OpalTransport & transport,
00942       const OpalRTPSessionManager & sm
00943     );
00944 
00945     virtual PBoolean OnReceivedResponse(SIP_PDU & response);
00946 
00947     const OpalRTPSessionManager & GetSessionManager() const { return rtpSessions; }
00948 
00949   protected:
00950     OpalRTPSessionManager rtpSessions;
00951 };
00952 
00953 
00955 
00956 class SIPRegister : public SIPTransaction
00957 {
00958     PCLASSINFO(SIPRegister, SIPTransaction);
00959   public:
00960     struct Params {
00961       Params();
00962 
00963       PString       m_addressOfRecord;
00964       PString       m_registrarAddress;
00965       PString       m_contactAddress;
00966       PString       m_authID;
00967       PString       m_password;
00968       PString       m_realm;
00969       unsigned      m_expire;
00970       unsigned      m_restoreTime;
00971       PTimeInterval m_minRetryTime;
00972       PTimeInterval m_maxRetryTime;
00973     };
00974 
00975     SIPRegister(
00976       SIPEndPoint   & endpoint,
00977       OpalTransport & transport,
00978       const SIPURL & proxy,
00979       const PString & callId,
00980       unsigned cseq,
00981       const Params & params
00982     );
00983 };
00984 
00985 
00987 
00988 class SIPSubscribe : public SIPTransaction
00989 {
00990     PCLASSINFO(SIPSubscribe, SIPTransaction);
00991   public:
00994     enum PredefinedPackages {
00995       MessageSummary,
00996       Presence,
00997       Dialog,
00998       NumPredefinedPackages
00999     };
01000 
01001     class EventPackage : public PCaselessString
01002     {
01003         PCLASSINFO(EventPackage, PCaselessString);
01004       public:
01005         EventPackage(PredefinedPackages);
01006         EventPackage(const PString & str) : PCaselessString(str) { }
01007         EventPackage(const char * cstr) : PCaselessString(cstr) { }
01008         bool operator==(PredefinedPackages) const;
01009         bool operator==(const PString & str) const { return Compare(str) == EqualTo; }
01010         bool operator==(const char * cstr) const { return InternalCompare(0, P_MAX_INDEX, cstr) == EqualTo; }
01011         virtual Comparison InternalCompare(PINDEX offset, PINDEX length, const char * cstr) const;
01012     };
01013 
01014     struct Params {
01015       Params(PredefinedPackages pkg = NumPredefinedPackages);
01016 
01017       EventPackage  m_eventPackage;
01018       PString       m_agentAddress;
01019       PString       m_addressOfRecord;
01020       PString       m_contactAddress;
01021       PString       m_authID;
01022       PString       m_password;
01023       PString       m_realm;
01024       unsigned      m_expire;
01025       unsigned      m_restoreTime;
01026       PTimeInterval m_minRetryTime;
01027       PTimeInterval m_maxRetryTime;
01028     };
01029 
01030     SIPSubscribe(
01031         SIPEndPoint & ep,
01032         OpalTransport & trans,
01033         SIPDialogContext & dialog,
01034         const Params & params
01035     );
01036 };
01037 
01038 
01039 typedef SIPSubscribe::EventPackage SIPEventPackage;
01040 
01041 
01043 
01044 class SIPHandler;
01045 
01046 class SIPEventPackageHandler
01047 {
01048 public:
01049   virtual ~SIPEventPackageHandler() { }
01050   virtual PString GetContentType() const = 0;
01051   virtual bool OnReceivedNOTIFY(SIPHandler & handler, SIP_PDU & request) = 0;
01052   virtual PString OnSendNOTIFY(SIPHandler & /*handler*/, const PObject * /*body*/) { return PString::Empty(); }
01053 };
01054 
01055 
01056 typedef PFactory<SIPEventPackageHandler, SIPEventPackage> SIPEventPackageFactory;
01057 
01058 
01060 
01061 class SIPNotify : public SIPTransaction
01062 {
01063     PCLASSINFO(SIPNotify, SIPTransaction);
01064   public:
01065     SIPNotify(
01066         SIPEndPoint & ep,
01067         OpalTransport & trans,
01068         SIPDialogContext & dialog,
01069         const SIPEventPackage & eventPackage,
01070         const PString & state,
01071         const PString & body
01072     );
01073 };
01074 
01075 
01077 
01078 class SIPPublish : public SIPTransaction
01079 {
01080     PCLASSINFO(SIPPublish, SIPTransaction);
01081   public:
01082     SIPPublish(
01083       SIPEndPoint & ep,
01084       OpalTransport & trans,
01085       const PString & id,
01086       const PString & sipIfMatch,
01087       SIPSubscribe::Params & params,
01088       const PString & body
01089     );
01090 };
01091 
01092 
01094 
01095 class SIPRefer : public SIPTransaction
01096 {
01097   PCLASSINFO(SIPRefer, SIPTransaction);
01098   public:
01099     SIPRefer(
01100       SIPConnection & connection,
01101       OpalTransport & transport,
01102       const SIPURL & refer
01103     );
01104     SIPRefer(
01105       SIPConnection & connection,
01106       OpalTransport & transport,
01107       const SIPURL & refer,
01108       const SIPURL & referred_by
01109     );
01110   protected:
01111     void Construct(
01112       SIPConnection & connection,
01113       OpalTransport & transport,
01114       const SIPURL & refer,
01115       const SIPURL & referred_by
01116     );
01117 };
01118 
01119 
01121 
01122 /* This is not a generic NOTIFY PDU, but the minimal one
01123  * that gets sent when receiving a REFER
01124  */
01125 class SIPReferNotify : public SIPTransaction
01126 {
01127     PCLASSINFO(SIPReferNotify, SIPTransaction);
01128   public:
01129     SIPReferNotify(
01130       SIPConnection & connection,
01131       OpalTransport & transport,
01132       StatusCodes code
01133     );
01134 };
01135 
01136 
01138 
01139 /* This is a MESSAGE PDU, with a body
01140  */
01141 class SIPMessage : public SIPTransaction
01142 {
01143     PCLASSINFO(SIPMessage, SIPTransaction);
01144     
01145   public:
01146     SIPMessage(
01147       SIPEndPoint & ep,
01148       OpalTransport & trans,
01149       const SIPURL & proxy,
01150       const SIPURL & to,
01151       const PString & id,
01152       const PString & body
01153     );
01154 };
01155 
01156 
01158 
01159 /* This is the ACK request sent when receiving a response to an outgoing
01160  * INVITE.
01161  */
01162 class SIPAck : public SIP_PDU
01163 {
01164     PCLASSINFO(SIPAck, SIP_PDU);
01165   public:
01166     SIPAck(
01167       SIPTransaction & invite,
01168       SIP_PDU & response
01169     );
01170 };
01171 
01172 
01174 
01175 /* This is an OPTIONS request
01176  */
01177 class SIPOptions : public SIPTransaction
01178 {
01179     PCLASSINFO(SIPOptions, SIPTransaction);
01180     
01181   public:
01182     SIPOptions(
01183         SIPEndPoint & ep,
01184       OpalTransport & trans,
01185        const SIPURL & address
01186     );
01187 };
01188 
01189 
01191 
01192 /* This is a PING PDU, with a body
01193  */
01194 class SIPPing : public SIPTransaction
01195 {
01196   PCLASSINFO(SIPPing, SIPTransaction);
01197 
01198   public:
01199     SIPPing(
01200                SIPEndPoint & ep,
01201              OpalTransport & trans,
01202               const SIPURL & address,
01203               const PString & body = PString::Empty()
01204    );
01205 };
01206 
01207 
01208 #endif // OPAL_SIP
01209 
01210 #endif // OPAL_SIP_SIPPDU_H
01211 
01212 
01213 // End of File ///////////////////////////////////////////////////////////////

Generated on Tue May 19 09:56:27 2009 for OPAL by  doxygen 1.5.1