OPAL  Version 3.10.9
sippdu.h
Go to the documentation of this file.
1 /*
2  * sippdu.h
3  *
4  * Session Initiation Protocol PDU support.
5  *
6  * Open Phone Abstraction Library (OPAL)
7  * Formally known as the Open H323 project.
8  *
9  * Copyright (c) 2002 Equivalence Pty. Ltd.
10  *
11  * The contents of this file are subject to the Mozilla Public License
12  * Version 1.0 (the "License"); you may not use this file except in
13  * compliance with the License. You may obtain a copy of the License at
14  * http://www.mozilla.org/MPL/
15  *
16  * Software distributed under the License is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18  * the License for the specific language governing rights and limitations
19  * under the License.
20  *
21  * The Original Code is Open Phone Abstraction Library.
22  *
23  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24  *
25  * Contributor(s): ______________________________________.
26  *
27  * $Revision: 27589 $
28  * $Author: rjongbloed $
29  * $Date: 2012-05-07 23:01:54 -0500 (Mon, 07 May 2012) $
30  */
31 
32 #ifndef OPAL_SIP_SIPPDU_H
33 #define OPAL_SIP_SIPPDU_H
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
39 #include <opal/buildopts.h>
40 
41 #if OPAL_SIP
42 
43 #include <ptclib/mime.h>
44 #include <ptclib/url.h>
45 #include <ptclib/http.h>
46 #include <sip/sdp.h>
47 #include <opal/rtpconn.h>
48 
49 
50 class OpalTransport;
52 class OpalProductInfo;
53 
54 class SIPEndPoint;
55 class SIPConnection;
56 class SIP_PDU;
58 class SIPDialogContext;
59 class SIPMIMEInfo;
60 
61 
63 // SIPURL
64 
70 class SIPURL : public PURL
71 {
72  PCLASSINFO(SIPURL, PURL);
73  public:
74  SIPURL();
75 
77  const PURL & url
78  ) : PURL(url) { }
80  const PURL & url
81  ) { PURL::operator=(url); return *this; }
82 
85  SIPURL(
86  const char * cstr,
87  const char * defaultScheme = NULL
88  );
90  const char * cstr
91  ) { Parse(cstr); return *this; }
92 
95  SIPURL(
96  const PString & str,
97  const char * defaultScheme = NULL
98  );
100  const PString & str
101  ) { Parse(str); return *this; }
102 
112  SIPURL(
113  const PString & name,
114  const OpalTransportAddress & address,
115  WORD listenerPort = 0
116  );
117 
118  SIPURL(
119  const OpalTransportAddress & address,
120  WORD listenerPort = 0
121  );
122  SIPURL & operator=(
123  const OpalTransportAddress & address
124  );
125 
126  SIPURL(
127  const SIPMIMEInfo & mime,
128  const char * name
129  );
130 
139  virtual Comparison Compare(
140  const PObject & obj
141  ) const;
142 
146  PString AsQuotedString() const;
147 
150  PString GetDisplayName(PBoolean useDefault = true) const;
151 
152  void SetDisplayName(const PString & str)
153  {
154  m_displayName = str;
155  }
156 
158  const PStringOptions & GetFieldParameters() const { return m_fieldParameters; }
159  PStringOptions & GetFieldParameters() { return m_fieldParameters; }
160 
164 
167  void SetHostAddress(const OpalTransportAddress & addr);
168 
179  };
180 
186  void Sanitise(
187  UsageContext context
188  );
189 
195  PBoolean AdjustToDNS(
196  PINDEX entry = 0
197  );
198 
200  static PString GenerateTag();
201 
203  void SetTag(
204  const PString & tag = PString::Empty(),
205  bool force = false
206  );
207 
208  protected:
209  void ParseAsAddress(const PString & name, const OpalTransportAddress & _address, WORD listenerPort = 0);
210 
211  // Override from PURL()
212  virtual PBoolean InternalParse(
213  const char * cstr,
214  const char * defaultScheme
215  ) { return ReallyInternalParse(false, cstr, defaultScheme); }
216 
217  bool ReallyInternalParse(
218  bool fromField,
219  const char * cstr,
220  const char * defaultScheme
221  );
222 
223  PString m_displayName;
224  PStringOptions m_fieldParameters;
225 };
226 
227 
228 class SIPURLList : public std::list<SIPURL>
229 {
230  public:
231  bool FromString(
232  const PString & str,
234  bool reversed = false
235  );
236  PString ToString() const;
237 };
238 
239 
240 
242 // SIPMIMEInfo
243 
274 class SIPMIMEInfo : public PMIMEInfo
275 {
276  PCLASSINFO(SIPMIMEInfo, PMIMEInfo);
277  public:
278  SIPMIMEInfo(bool compactForm = false);
279 
280  virtual void PrintOn(ostream & strm) const;
281  virtual bool InternalAddMIME(const PString & fieldName, const PString & fieldValue);
282 
283  void SetCompactForm(bool form) { compactForm = form; }
284 
285  PCaselessString GetContentType(bool includeParameters = false) const;
286  void SetContentType(const PString & v);
287 
288  PCaselessString GetContentEncoding() const;
289  void SetContentEncoding(const PString & v);
290 
291  SIPURL GetFrom() const;
292  void SetFrom(const PString & v);
293 
295  void SetPAssertedIdentity(const PString & v);
296 
298  void SetPPreferredIdentity(const PString & v);
299 
300  PString GetAccept() const;
301  void SetAccept(const PString & v);
302 
303  PString GetAcceptEncoding() const;
304  void SetAcceptEncoding(const PString & v);
305 
306  PString GetAcceptLanguage() const;
307  void SetAcceptLanguage(const PString & v);
308 
309  PString GetAllow() const;
310  unsigned GetAllowBitMask() const;
311  void SetAllow(const PString & v);
312 
313  PString GetCallID() const;
314  void SetCallID(const PString & v);
315 
316  SIPURL GetContact() const;
317  bool GetContacts(SIPURLList & contacts) const;
318  void SetContact(const PString & v);
319 
320  PString GetSubject() const;
321  void SetSubject(const PString & v);
322 
323  SIPURL GetTo() const;
324  void SetTo(const PString & v);
325 
326  PString GetVia() const;
327  void SetVia(const PString & v);
328 
329  bool GetViaList(PStringList & v) const;
330  void SetViaList(const PStringList & v);
331 
332  PString GetFirstVia() const;
334 
335  SIPURL GetReferTo() const;
336  void SetReferTo(const PString & r);
337 
338  SIPURL GetReferredBy() const;
339  void SetReferredBy(const PString & r);
340 
341  PINDEX GetContentLength() const;
342  void SetContentLength(PINDEX v);
343  PBoolean IsContentLengthPresent() const;
344 
345  PString GetCSeq() const;
346  void SetCSeq(const PString & v);
347 
348  PString GetDate() const;
349  void SetDate(const PString & v);
350  void SetDate(const PTime & t);
351  void SetDate(void); // set to current date
352 
353  unsigned GetExpires(unsigned dflt = UINT_MAX) const;// returns default value if not found
354  void SetExpires(unsigned v);
355 
356  PINDEX GetMaxForwards() const;
357  void SetMaxForwards(PINDEX v);
358 
359  PINDEX GetMinExpires() const;
360  void SetMinExpires(PINDEX v);
361 
362  PString GetProxyAuthenticate() const;
363  void SetProxyAuthenticate(const PString & v);
364 
365  PString GetRoute() const;
366  bool GetRoute(SIPURLList & proxies) const;
367  void SetRoute(const PString & v);
368  void SetRoute(const SIPURLList & proxies);
369 
370  PString GetRecordRoute() const;
371  bool GetRecordRoute(SIPURLList & proxies, bool reversed) const;
372  void SetRecordRoute(const PString & v);
373  void SetRecordRoute(const SIPURLList & proxies);
374 
375  unsigned GetCSeqIndex() const { return GetCSeq().AsUnsigned(); }
376 
377  PStringSet GetRequire() const;
378  void SetRequire(const PStringSet & v);
379  void AddRequire(const PString & v);
380 
381  PStringSet GetSupported() const;
382  void SetSupported(const PStringSet & v);
383  void AddSupported(const PString & v);
384 
385  PStringSet GetUnsupported() const;
386  void SetUnsupported(const PStringSet & v);
387  void AddUnsupported(const PString & v);
388 
389  PString GetEvent() const;
390  void SetEvent(const PString & v);
391 
392  PCaselessString GetSubscriptionState(PStringToString & info) const;
393  void SetSubscriptionState(const PString & v);
394 
395  PString GetUserAgent() const;
396  void SetUserAgent(const PString & v);
397 
398  PString GetOrganization() const;
399  void SetOrganization(const PString & v);
400 
401  void GetProductInfo(OpalProductInfo & info) const;
402  void SetProductInfo(const PString & ua, const OpalProductInfo & info);
403 
404  PString GetWWWAuthenticate() const;
405  void SetWWWAuthenticate(const PString & v);
406 
407  PString GetSIPIfMatch() const;
408  void SetSIPIfMatch(const PString & v);
409 
410  PString GetSIPETag() const;
411  void SetSIPETag(const PString & v);
412 
413  void GetAlertInfo(PString & info, int & appearance);
414  void SetAlertInfo(const PString & info, int appearance);
415 
416  PString GetCallInfo() const;
417 
418  PString GetAllowEvents() const;
419  void SetAllowEvents(const PString & v);
420 
424  const PString & fieldName,
425  const PString & paramName,
426  const PString & defaultValue = PString::Empty()
427  ) const { return ExtractFieldParameter((*this)(fieldName), paramName, defaultValue); }
428 
434  const PString & fieldName,
435  const PString & paramName,
436  const PString & newValue
437  ) { SetAt(fieldName, InsertFieldParameter((*this)(fieldName), paramName, newValue)); }
438 
441  static PString ExtractFieldParameter(
442  const PString & fieldValue,
443  const PString & paramName,
444  const PString & defaultValue = PString::Empty()
445  );
446 
451  static PString InsertFieldParameter(
452  const PString & fieldValue,
453  const PString & paramName,
454  const PString & newValue
455  );
456 
457  protected:
458  PStringSet GetTokenSet(const char * field) const;
459  void AddTokenSet(const char * field, const PString & token);
460  void SetTokenSet(const char * field, const PStringSet & tokens);
461 
464 };
465 
466 
468 // SIPAuthentication
469 
470 typedef PHTTPClientAuthentication SIPAuthentication;
471 
472 class SIPAuthenticator : public PHTTPClientAuthentication::AuthObject
473 {
474  public:
475  SIPAuthenticator(SIP_PDU & pdu);
476  virtual PMIMEInfo & GetMIME();
477  virtual PString GetURI();
478  virtual PString GetEntityBody();
479  virtual PString GetMethod();
480 
481  protected:
483 };
484 
485 
486 
488 // SIP_PDU
489 
495 class SIP_PDU : public PSafeObject
496 {
497  PCLASSINFO(SIP_PDU, PSafeObject);
498  public:
499  enum Methods {
515  };
516 
517  enum StatusCodes {
522 
528 
531 
537 
569 
577 
582 
584  };
585 
586  static const char * GetStatusCodeDescription(int code);
587  friend ostream & operator<<(ostream & strm, StatusCodes status);
588 
589  SIP_PDU(
591  );
592 
596  SIP_PDU(
597  const SIP_PDU & request,
598  StatusCodes code,
599  const SDPSessionDescription * sdp = NULL
600  );
601 
602  SIP_PDU(const SIP_PDU &);
603  SIP_PDU & operator=(const SIP_PDU &);
604  ~SIP_PDU();
605 
606  void PrintOn(
607  ostream & strm
608  ) const;
609 
610  void InitialiseHeaders(
611  const SIPURL & dest,
612  const SIPURL & to,
613  const SIPURL & from,
614  const PString & callID,
615  unsigned cseq,
616  const PString & via
617  );
618  void InitialiseHeaders(
619  SIPDialogContext & dialog,
620  const PString & via = PString::Empty(),
621  unsigned cseq = 0
622  );
623  void InitialiseHeaders(
624  SIPConnection & connection,
625  const OpalTransport & transport,
626  unsigned cseq = 0
627  );
628  void InitialiseHeaders(
629  const SIP_PDU & request
630  );
631 
636  bool SetRoute(const SIPURLList & routeSet);
637  bool SetRoute(const SIPURL & proxy);
638 
641  void SetAllow(unsigned bitmask);
642 
645  void AdjustVia(OpalTransport & transport);
646 
647  PString CreateVia(
648  SIPEndPoint & endpoint,
649  const OpalTransport & transport,
650  SIPConnection * connection = NULL
651  );
652 
656  OpalTransport & transport
657  );
658 
661  PBoolean Write(
662  OpalTransport & transport,
663  const OpalTransportAddress & remoteAddress = OpalTransportAddress(),
664  const PString & localInterface = PString::Empty()
665  );
666 
669  bool SendResponse(
670  OpalTransport & transport,
671  StatusCodes code,
672  SIPEndPoint * endpoint = NULL
673  ) const;
674  bool SendResponse(
675  OpalTransport & transport,
676  SIP_PDU & response,
677  SIPEndPoint * endpoint = NULL
678  ) const;
679 
683  PString Build();
684 
685  PString GetTransactionID() const;
686 
687  Methods GetMethod() const { return m_method; }
690  const SIPURL & GetURI() const { return m_uri; }
691  void SetURI(const SIPURL & newuri) { m_uri = newuri; }
692  unsigned GetVersionMajor() const { return m_versionMajor; }
693  unsigned GetVersionMinor() const { return m_versionMinor; }
694  void SetCSeq(unsigned cseq);
695  const PString & GetEntityBody() const { return m_entityBody; }
696  void SetEntityBody(const PString & body) { m_entityBody = body; }
697  void SetEntityBody();
698  const PString & GetInfo() const { return m_info; }
699  void SetInfo(const PString & info) { m_info = info; }
700  const SIPMIMEInfo & GetMIME() const { return m_mime; }
701  SIPMIMEInfo & GetMIME() { return m_mime; }
702  SDPSessionDescription * GetSDP(const OpalMediaFormatList & masterList);
703  void SetSDP(SDPSessionDescription * sdp);
704 
705  protected:
706  Methods m_method; // Request type, ==NumMethods for Response
708  SIPURL m_uri; // display name & URI, no tag
709  unsigned m_versionMajor;
710  unsigned m_versionMinor;
711  PString m_info;
713  PString m_entityBody;
714 
716 
717  mutable PString m_transactionID;
718 };
719 
720 
721 PQUEUE(SIP_PDU_Queue, SIP_PDU);
722 
723 
724 #if PTRACING
725 ostream & operator<<(ostream & strm, SIP_PDU::Methods method);
726 #endif
727 
728 
730 // SIPDialogContext
731 
735 {
736  public:
738  SIPDialogContext(const SIPMIMEInfo & mime);
739 
740  PString AsString() const;
741  bool FromString(
742  const PString & str
743  );
744 
745  const PString & GetCallID() const { return m_callId; }
746  void SetCallID(const PString & id) { m_callId = id; }
747 
748  const SIPURL & GetRequestURI() const { return m_requestURI; }
749  void SetRequestURI(const SIPURL & url) { m_requestURI = url; }
750 
751  const PString & GetLocalTag() const { return m_localTag; }
752  void SetLocalTag(const PString & tag) { m_localTag = tag; }
753 
754  const SIPURL & GetLocalURI() const { return m_localURI; }
755  void SetLocalURI(const SIPURL & url);
756 
757  const PString & GetRemoteTag() const { return m_remoteTag; }
758  void SetRemoteTag(const PString & tag) { m_remoteTag = tag; }
759 
760  const SIPURL & GetRemoteURI() const { return m_remoteURI; }
761  void SetRemoteURI(const SIPURL & url);
762 
763  const SIPURLList & GetRouteSet() const { return m_routeSet; }
764  void SetRouteSet(const PString & str) { m_routeSet.FromString(str); }
765 
766  const SIPURL & GetProxy() const { return m_proxy; }
767  void SetProxy(const SIPURL & proxy, bool addToRouteSet);
768 
769  void Update(OpalTransport & transport, const SIP_PDU & response);
770 
771  unsigned GetNextCSeq();
772  void IncrementCSeq(unsigned inc) { m_lastSentCSeq += inc; }
773 
774  bool IsDuplicateCSeq(unsigned sequenceNumber);
775 
776  bool IsEstablished() const
777  {
778  return !m_callId.IsEmpty() &&
779  !m_requestURI.IsEmpty() &&
780  !m_localTag.IsEmpty() &&
781  !m_remoteTag.IsEmpty();
782  }
783 
785 
786  void SetForking(bool f) { m_forking = f; }
787 
788  protected:
789  PString m_callId;
792  PString m_localTag;
794  PString m_remoteTag;
796  unsigned m_lastSentCSeq;
799  bool m_forking;
801 };
802 
803 
805 
807 {
809  const PString & aor = PString::Empty(),
810  const PString & remote = PString::Empty()
811  );
812 
813  void Normalise(
814  const PString & defaultUser,
815  const PTimeInterval & defaultExpire
816  );
817 
818  PCaselessString m_remoteAddress;
819  PCaselessString m_localAddress;
820  PCaselessString m_proxyAddress;
821  PCaselessString m_addressOfRecord;
822  PCaselessString m_contactAddress;
824  PString m_authID;
825  PString m_password;
826  PString m_realm;
827  unsigned m_expire;
828  unsigned m_restoreTime;
829  PTimeInterval m_minRetryTime;
830  PTimeInterval m_maxRetryTime;
831  void * m_userData;
832 };
833 
834 
835 #if PTRACING
836 ostream & operator<<(ostream & strm, const SIPParameters & params);
837 #endif
838 
839 
841 // SIPTransaction
842 
853 class SIPTransaction : public SIP_PDU
854 {
855  PCLASSINFO(SIPTransaction, SIP_PDU);
856  public:
858  Methods method,
859  SIPEndPoint & endpoint,
860  OpalTransport & transport
861  );
866  Methods method,
867  SIPConnection & connection
868  );
869  ~SIPTransaction();
870 
871  /* Under some circumstances a new transaction with all the same parameters
872  but different ID needs to be created, e.g. when get authentication error. */
873  virtual SIPTransaction * CreateDuplicate() const = 0;
874 
875  PBoolean Start();
876  bool IsTrying() const { return m_state == Trying; }
877  bool IsProceeding() const { return m_state == Proceeding; }
878  bool IsInProgress() const { return m_state == Trying || m_state == Proceeding; }
879  bool IsFailed() const { return m_state > Terminated_Success; }
880  bool IsCompleted() const { return m_state >= Completed; }
882  bool IsTerminated() const { return m_state >= Terminated_Success; }
883 
884  void WaitForCompletion();
885  PBoolean Cancel();
886  void Abort();
887 
888  virtual PBoolean OnReceivedResponse(SIP_PDU & response);
889  virtual PBoolean OnCompleted(SIP_PDU & response);
890 
891  OpalTransport & GetTransport() const { return m_transport; }
893  PString GetInterface() const { return m_localInterface; }
894  void SetInterface(const PString & localIf) { m_localInterface = localIf; }
895 
896  static PString GenerateCallID();
897 
898  protected:
899  bool SendPDU(SIP_PDU & pdu);
900  bool ResendCANCEL();
901  void SetParameters(const SIPParameters & params);
902 
903  PDECLARE_NOTIFIER(PTimer, SIPTransaction, OnRetry);
904  PDECLARE_NOTIFIER(PTimer, SIPTransaction, OnTimeout);
905 
906  enum States {
919  };
920  virtual void SetTerminated(States newState);
921 
924  PSafePtr<SIPConnection> m_connection;
925  PTimeInterval m_retryTimeoutMin;
926  PTimeInterval m_retryTimeoutMax;
927 
929  unsigned m_retry;
930  PTimer m_retryTimer;
932  PSyncPoint m_completed;
933 
936 };
937 
938 
939 #define OPAL_PROXY_PARAM "OPAL-proxy"
940 #define OPAL_LOCAL_ID_PARAM "OPAL-local-id"
941 
942 
944 // SIPResponse
945 
949 {
950  PCLASSINFO(SIPResponse, SIPTransaction);
951  public:
952  SIPResponse(
953  SIPEndPoint & endpoint,
954  StatusCodes code
955  );
956 
957  virtual SIPTransaction * CreateDuplicate() const;
958 
959  bool Send(OpalTransport & transport, const SIP_PDU & command);
960 };
961 
962 
964 // SIPInvite
965 
971 class SIPInvite : public SIPTransaction
972 {
973  PCLASSINFO(SIPInvite, SIPTransaction);
974  public:
975  SIPInvite(
976  SIPConnection & connection,
977  const OpalRTPSessionManager & sm
978  );
979 
980  virtual SIPTransaction * CreateDuplicate() const;
981 
982  virtual PBoolean OnReceivedResponse(SIP_PDU & response);
983 
986 
987  protected:
989 };
990 
991 
993 
994 /* This is the ACK request sent when receiving a response to an outgoing
995  * INVITE.
996  */
997 class SIPAck : public SIP_PDU
998 {
999  PCLASSINFO(SIPAck, SIP_PDU);
1000  public:
1001  SIPAck(
1002  SIPTransaction & invite,
1003  SIP_PDU & response
1004  );
1005 
1006  virtual SIPTransaction * CreateDuplicate() const;
1007 };
1008 
1009 
1011 
1012 /* This is a BYE request
1013  */
1014 class SIPBye : public SIPTransaction
1015 {
1016  PCLASSINFO(SIPBye, SIPTransaction);
1017 
1018  public:
1019  SIPBye(
1020  SIPEndPoint & ep,
1021  OpalTransport & trans,
1022  SIPDialogContext dialog
1023  );
1024  SIPBye(
1025  SIPConnection & conn
1026  );
1027 
1028  virtual SIPTransaction * CreateDuplicate() const;
1029 };
1030 
1031 
1033 
1035 {
1036  PCLASSINFO(SIPRegister, SIPTransaction);
1037  public:
1054  };
1055 
1057  struct Params : public SIPParameters {
1061  { }
1062 
1063  Params(const Params & param)
1064  : SIPParameters(param)
1067  { }
1068 
1069  PCaselessString & m_registrarAddress; // For backward compatibility
1071  };
1072 
1073  SIPRegister(
1074  SIPEndPoint & endpoint,
1075  OpalTransport & transport,
1076  const PString & callId,
1077  unsigned cseq,
1078  const Params & params
1079  );
1080 
1081  virtual SIPTransaction * CreateDuplicate() const;
1082 };
1083 
1084 
1085 #if PTRACING
1086 ostream & operator<<(ostream & strm, SIPRegister::CompatibilityModes mode);
1087 ostream & operator<<(ostream & strm, const SIPRegister::Params & params);
1088 #endif
1089 
1090 
1092 
1094 {
1095  PCLASSINFO(SIPSubscribe, SIPTransaction);
1096  public:
1103 
1105 
1106  Watcher = 0x8000,
1107 
1111 
1113  };
1115 
1116  class EventPackage : public PCaselessString
1117  {
1118  PCLASSINFO(EventPackage, PCaselessString);
1119  public:
1121  explicit EventPackage(const PString & str) : PCaselessString(str) { }
1122  explicit EventPackage(const char * str) : PCaselessString(str) { }
1123 
1125  EventPackage & operator=(const PString & str) { PCaselessString::operator=(str); return *this; }
1126  EventPackage & operator=(const char * str) { PCaselessString::operator=(str); return *this; }
1127 
1128  bool operator==(PredefinedPackages pkg) const { return Compare(EventPackage(pkg)) == EqualTo; }
1129  bool operator==(const PString & str) const { return Compare(str) == EqualTo; }
1130  bool operator==(const char * cstr) const { return InternalCompare(0, P_MAX_INDEX, cstr) == EqualTo; }
1131  virtual Comparison InternalCompare(PINDEX offset, PINDEX length, const char * cstr) const;
1132 
1133  bool IsWatcher() const;
1134  };
1135 
1144  void * m_userData;
1145  };
1146 
1149  SIPEndPoint & ep,
1150  OpalTransport & trans,
1151  SIP_PDU & notify,
1152  SIP_PDU & response
1153  );
1154 
1155  bool SendResponse(
1156  SIP_PDU::StatusCodes status,
1157  const char * extra = NULL
1158  );
1159 
1165  };
1166 
1167  struct Params : public SIPParameters
1168  {
1171  , m_eventPackage(pkg)
1172  , m_eventList(false)
1173  { }
1174 
1175  Params(const Params & param)
1176  : SIPParameters(param)
1179  , m_eventList(param.m_eventList)
1180  , m_contentType(param.m_contentType)
1182  , m_onNotify(param.m_onNotify)
1183  { }
1184 
1185  PCaselessString & m_agentAddress; // For backward compatibility
1187  bool m_eventList; // Enable RFC4662
1188  PCaselessString m_contentType; // May be \n separated list of types
1189 
1190  PNotifierTemplate<const SubscriptionStatus &> m_onSubcribeStatus;
1191  PNotifierTemplate<NotifyCallbackInfo &> m_onNotify;
1192  };
1193 
1194  SIPSubscribe(
1195  SIPEndPoint & ep,
1196  OpalTransport & trans,
1197  SIPDialogContext & dialog,
1198  const Params & params
1199  );
1200 
1201  virtual SIPTransaction * CreateDuplicate() const;
1202 };
1203 
1204 
1205 #if PTRACING
1206 ostream & operator<<(ostream & strm, const SIPSubscribe::Params & params);
1207 #endif
1208 
1209 
1211 
1212 
1214 
1215 class SIPHandler;
1216 
1218 {
1219 public:
1221  virtual PCaselessString GetContentType() const = 0;
1222  virtual bool ValidateContentType(const PString & type, const SIPMIMEInfo & mime);
1223  virtual bool OnReceivedNOTIFY(SIPHandler & handler, SIP_PDU & request) = 0;
1224  virtual PString OnSendNOTIFY(SIPHandler & /*handler*/, const PObject * /*body*/) { return PString::Empty(); }
1225 };
1226 
1227 
1228 typedef PFactory<SIPEventPackageHandler, SIPEventPackage> SIPEventPackageFactory;
1229 
1230 
1232 
1234 {
1235  PCLASSINFO(SIPNotify, SIPTransaction);
1236  public:
1237  SIPNotify(
1238  SIPEndPoint & ep,
1239  OpalTransport & trans,
1240  SIPDialogContext & dialog,
1241  const SIPEventPackage & eventPackage,
1242  const PString & state,
1243  const PString & body
1244  );
1245 
1246  virtual SIPTransaction * CreateDuplicate() const;
1247 };
1248 
1249 
1251 
1253 {
1254  PCLASSINFO(SIPPublish, SIPTransaction);
1255  public:
1256  SIPPublish(
1257  SIPEndPoint & ep,
1258  OpalTransport & trans,
1259  const PString & id,
1260  const PString & sipIfMatch,
1261  const SIPSubscribe::Params & params,
1262  const PString & body
1263  );
1264 
1265  virtual SIPTransaction * CreateDuplicate() const;
1266 };
1267 
1268 
1270 
1271 class SIPRefer : public SIPTransaction
1272 {
1273  PCLASSINFO(SIPRefer, SIPTransaction);
1274  public:
1275  SIPRefer(
1276  SIPConnection & connection,
1277  const SIPURL & referTo,
1278  const SIPURL & referred_by,
1279  bool referSub
1280  );
1281 
1282  virtual SIPTransaction * CreateDuplicate() const;
1283 };
1284 
1285 
1287 
1288 /* This is not a generic NOTIFY PDU, but the minimal one
1289  * that gets sent when receiving a REFER
1290  */
1292 {
1293  PCLASSINFO(SIPReferNotify, SIPTransaction);
1294  public:
1296  SIPConnection & connection,
1297  StatusCodes code
1298  );
1299 
1300  virtual SIPTransaction * CreateDuplicate() const;
1301 };
1302 
1303 
1305 
1306 /* This is a MESSAGE PDU, with a body
1307  */
1309 {
1310  PCLASSINFO(SIPMessage, SIPTransaction);
1311  public:
1312  struct Params : public SIPParameters
1313  {
1315  : m_contentType("text/plain;charset=UTF-8")
1316  {
1317  m_expire = 5000;
1318  }
1319 
1320  PCaselessString m_contentType;
1321  PString m_id;
1322  PString m_body;
1323  PAtomicInteger::IntegerType m_messageId;
1324  };
1325 
1326  SIPMessage(
1327  SIPEndPoint & ep,
1328  OpalTransport & trans,
1329  const Params & params
1330  );
1331  SIPMessage(
1332  SIPConnection & connection,
1333  const Params & params
1334  );
1335 
1336  virtual SIPTransaction * CreateDuplicate() const;
1337 
1338  const SIPURL & GetLocalAddress() const { return m_localAddress; }
1339 
1340  private:
1341  void Construct(const Params & params);
1342 
1343  SIPURL m_localAddress;
1344 };
1345 
1346 
1348 
1349 /* This is an OPTIONS request
1350  */
1352 {
1353  PCLASSINFO(SIPOptions, SIPTransaction);
1354 
1355  public:
1356  struct Params : public SIPParameters
1357  {
1359  : m_acceptContent("application/sdp, application/media_control+xml, application/dtmf, application/dtmf-relay")
1360  {
1361  }
1362 
1363  PCaselessString m_acceptContent;
1364  PCaselessString m_contentType;
1365  PString m_body;
1366  };
1367 
1368  SIPOptions(
1369  SIPEndPoint & ep,
1370  OpalTransport & trans,
1371  const PString & id,
1372  const Params & params
1373  );
1374  SIPOptions(
1375  SIPConnection & conn,
1376  const Params & params
1377  );
1378 
1379  virtual SIPTransaction * CreateDuplicate() const;
1380 
1381  protected:
1382  void Construct(const Params & params);
1383 };
1384 
1385 
1387 
1388 /* This is an INFO request
1389  */
1390 class SIPInfo : public SIPTransaction
1391 {
1392  PCLASSINFO(SIPInfo, SIPTransaction);
1393 
1394  public:
1395  struct Params
1396  {
1397  Params(const PString & contentType = PString::Empty(),
1398  const PString & body = PString::Empty())
1399  : m_contentType(contentType)
1400  , m_body(body)
1401  {
1402  }
1403 
1404  PCaselessString m_contentType;
1405  PString m_body;
1406  };
1407 
1408  SIPInfo(
1409  SIPConnection & conn,
1410  const Params & params
1411  );
1412 
1413  virtual SIPTransaction * CreateDuplicate() const;
1414 };
1415 
1416 
1418 
1419 /* This is a PING PDU, with a body
1420  */
1421 class SIPPing : public SIPTransaction
1422 {
1423  PCLASSINFO(SIPPing, SIPTransaction);
1424 
1425  public:
1426  SIPPing(
1427  SIPEndPoint & ep,
1428  OpalTransport & trans,
1429  const SIPURL & address
1430  );
1431 
1432  virtual SIPTransaction * CreateDuplicate() const;
1433 };
1434 
1435 
1437 
1438 /* This is a PRACK PDU
1439  */
1440 class SIPPrack : public SIPTransaction
1441 {
1442  PCLASSINFO(SIPPrack, SIPTransaction);
1443 
1444  public:
1445  SIPPrack(
1446  SIPConnection & conn,
1447  const PString & rack
1448  );
1449 
1450  virtual SIPTransaction * CreateDuplicate() const;
1451 };
1452 
1453 
1454 #endif // OPAL_SIP
1455 
1456 #endif // OPAL_SIP_SIPPDU_H
1457 
1458 
1459 // End of File ///////////////////////////////////////////////////////////////