OPAL  Version 3.12.5
sipcon.h
Go to the documentation of this file.
1 /*
2  * sipcon.h
3  *
4  * Session Initiation Protocol connection.
5  *
6  * Open Phone Abstraction Library (OPAL)
7  * Formally known as the Open H323 project.
8  *
9  * Copyright (c) 2001 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: 30265 $
28  * $Author: rjongbloed $
29  * $Date: 2013-08-07 02:34:58 -0500 (Wed, 07 Aug 2013) $
30  */
31 
32 #ifndef OPAL_SIP_SIPCON_H
33 #define OPAL_SIP_SIPCON_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 <rtp/rtpconn.h>
44 #include <sip/sippdu.h>
45 #include <sip/handlers.h>
46 
47 
48 class OpalSIPIMContext;
49 
50 
55 #define OPAL_OPT_FORWARD_REFER "Forward-Refer"
56 
60 #define OPAL_OPT_REFER_SUB "Refer-Sub"
61 
67 #define OPAL_OPT_PRACK_MODE "PRACK-Mode"
68 
72 #define OPAL_OPT_INITIAL_OFFER "Initial-Offer"
73 
89 #define OPAL_OPT_SYMMETRIC_HOLD_PRODUCT "Symmetric-Hold-Product"
90 
101 #define OPAL_OPT_ALLOW_EARLY_REPLACE "Allow-Early-Replace"
102 
113 #define OPAL_OPT_EXTERNAL_SDP "External-SDP"
114 
115 #define SIP_HEADER_PREFIX "SIP-Header:"
116 #define SIP_HEADER_REPLACES SIP_HEADER_PREFIX"Replaces"
117 #define SIP_HEADER_REFERRED_BY SIP_HEADER_PREFIX"Referred-By"
118 #define SIP_HEADER_CONTACT SIP_HEADER_PREFIX"Contact"
119 
120 #define OPAL_SIP_REFERRED_CONNECTION "Referred-Connection"
121 
122 
124 
129 {
130  PCLASSINFO(SIPConnection, OpalRTPConnection);
131  public:
132 
135  struct Init {
137  : m_call(call)
138  , m_endpoint(endpoint)
139  , m_userData(NULL)
140  , m_invite(NULL)
141  , m_options(0)
142  , m_stringOptions(NULL)
143  { }
144 
147  PString m_token;
149  void * m_userData;
151  unsigned m_options;
153  };
154 
158  const Init & init
159  );
160 
163  ~SIPConnection();
165 
176  virtual bool IsNetworkConnection() const { return true; }
177 
180  virtual PString GetPrefixName() const;
181 
184  virtual PString GetIdentifier() const;
185 
187  virtual void OnApplyStringOptions();
188 
195  virtual PBoolean SetUpConnection();
196 
200 
207  virtual PString GetDestinationAddress();
208 
216  virtual PString GetCalledPartyURL();
217 
231  virtual PString GetAlertingType() const;
232 
246  virtual bool SetAlertingType(const PString & info);
247 
255  virtual PString GetCallInfo() const;
256 
277  virtual bool TransferConnection(
278  const PString & remoteParty
279  );
280 
288  virtual bool Hold(
289  bool fromRemote,
290  bool placeOnHold
291  );
292 
297  virtual bool IsOnHold(
298  bool fromRemote
299  );
300 
311  virtual PBoolean SetAlerting(
312  const PString & calleeName,
313  PBoolean withMedia
314  );
315 
320  virtual PBoolean SetConnected();
321 
324  virtual OpalMediaFormatList GetMediaFormats() const;
325 
329  virtual bool RequireSymmetricMediaStreams() const;
330 
331 #if OPAL_T38_CAPABILITY
332 
334  virtual bool SwitchFaxMediaStreams(
335  bool toT38
336  );
337 #endif
338 
342  const OpalMediaFormat & mediaFormat,
343  unsigned sessionID,
344  PBoolean isSource
345  );
346 
350  const OpalMediaFormat & mediaFormat,
351  unsigned sessionID,
352  bool isSource
353  );
354 
359  virtual void OnClosedMediaStream(
360  const OpalMediaStream & stream
361  );
362 
372  virtual bool GetMediaTransportAddresses(
373  const OpalMediaType & mediaType,
374  OpalTransportAddressArray & transports
375  ) const;
376 
385  virtual void OnPatchMediaStream(
386  PBoolean isSource,
387  OpalMediaPatch & patch
388  );
389 
392  virtual void OnPauseMediaStream(
393  OpalMediaStream & strm,
394  bool paused
395  );
396 
414  virtual void OnReleased();
415 
425  virtual PBoolean ForwardCall(
426  const PString & forwardParty
427  );
428 
434  virtual SendUserInputModes GetRealSendUserInputMode() const;
435 
442  virtual PBoolean SendUserInputString(
443  const PString & value
444  );
445 
462  PBoolean SendUserInputTone(char tone, unsigned duration);
464 
469  virtual void OnTransactionFailed(
470  SIPTransaction & transaction
471  );
472 
475  virtual void OnReceivedPDU(SIP_PDU & pdu);
476 
479  virtual void OnReceivedINVITE(SIP_PDU & pdu);
480 
483  virtual void OnReceivedReINVITE(SIP_PDU & pdu);
484 
487  virtual void OnReceivedACK(SIP_PDU & pdu);
488 
491  virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
492 
495  virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
496 
500  virtual void OnAllowedEventNotify(
501  const PString & eventName
502  );
503 
506  virtual void OnReceivedREFER(SIP_PDU & pdu);
507 
510  virtual void OnReceivedINFO(SIP_PDU & pdu);
511 
514  virtual void OnReceivedPING(SIP_PDU & pdu);
515 
518  virtual void OnReceivedPRACK(SIP_PDU & pdu);
519 
522  virtual void OnReceivedBYE(SIP_PDU & pdu);
523 
526  virtual void OnReceivedCANCEL(SIP_PDU & pdu);
527 
532  virtual bool OnReceivedResponseToINVITE(
533  SIPTransaction & transaction,
534  SIP_PDU & response
535  );
536 
539  virtual void OnReceivedResponse(
540  SIPTransaction & transaction,
541  SIP_PDU & response
542  );
543 
546  virtual void OnReceivedTrying(
547  SIPTransaction & transaction,
548  SIP_PDU & response
549  );
550 
553  virtual void OnReceivedRinging(SIPTransaction & transaction, SIP_PDU & pdu);
554 
557  virtual void OnReceivedSessionProgress(SIPTransaction & transaction, SIP_PDU & pdu);
558 
562  virtual PBoolean OnReceivedAuthenticationRequired(
563  SIPTransaction & transaction,
564  SIP_PDU & response
565  );
566 
569  virtual void OnReceivedRedirection(SIP_PDU & pdu);
570 
574  virtual void OnReceivedOK(
575  SIPTransaction & transaction,
576  SIP_PDU & response
577  );
578 
581  virtual void OnCreatingINVITE(SIPInvite & pdu);
582 
588  };
589 
592  const SIP_PDU & pdu
593  ) const;
594 
600  bool SendOPTIONS(
601  const SIPOptions::Params & params,
602  SIP_PDU * reply = NULL
603  );
604 
610  bool SendINFO(
611  const SIPInfo::Params & params,
612  SIP_PDU * reply = NULL
613  );
615 
617 
620 
622  enum PRACKMode {
634  };
637  PRACKMode GetPRACKMode() const { return m_prackMode; }
638 
641  virtual unsigned GetAllowedMethods() const;
642 
645  bool DoesRemoteAllowMethod(SIP_PDU::Methods method) const { return (m_allowedMethods&(1<<method)) != 0; }
646 
647 #if OPAL_VIDEO
648 
653  virtual PBoolean OnMediaControlXML(SIP_PDU & pdu);
654 #endif
655 
661  virtual bool OnMediaCommand(
662  OpalMediaStream & stream,
663  const OpalMediaCommand & command
664  );
665 
666  // Overrides from SIPTransactionOwner
667  virtual PString GetAuthID() const;
668 
669 
670  virtual void OnStartTransaction(SIPTransaction & transaction);
671  virtual void OnReceivedMESSAGE(SIP_PDU & pdu);
672  virtual void OnReceivedSUBSCRIBE(SIP_PDU & pdu);
673 
674  PString GetLocalPartyURL() const;
675 
676  virtual void PrintOn(ostream & strm) const { OpalRTPConnection::PrintOn(strm); }
677 
678  protected:
679  virtual bool GarbageCollection();
681  void OnSessionTimeout();
682  void OnInviteResponseRetry();
684  void OnInviteCollision();
685 
686  virtual bool OnSendOfferSDP(
687  SDPSessionDescription & sdpOut,
688  bool offerCurrentOnly
689  );
690  virtual bool OnSendOfferSDPSession(
691  unsigned sessionID,
692  SDPSessionDescription & sdpOut,
693  bool offerOpenMediaStreamOnly
694  );
695 
696  virtual bool OnSendAnswerSDP(
697  SDPSessionDescription & sdpOut
698  );
699  virtual bool OnSendAnswerSDP(
700  const SDPSessionDescription & sdpOffer,
701  SDPSessionDescription & sdpAnswer
702  );
703  virtual bool OnSendAnswerSDPSession(
704  const SDPSessionDescription & sdpIn,
705  unsigned sessionIndex,
706  SDPSessionDescription & sdpOut
707  );
708 
709  virtual void OnReceivedAnswerSDP(
710  SIP_PDU & response,
711  SIPTransaction * transaction
712  );
713  virtual bool OnReceivedAnswerSDPSession(
714  SDPSessionDescription & sdp,
715  unsigned sessionId,
716  bool & multipleFormats
717  );
718 
720  const unsigned rtpSessionId,
721  const OpalMediaType & mediaType,
722  const SDPMediaDescription & mediaDescription,
723  OpalTransportAddress & localAddress,
724  bool & remoteChanged
725  );
726 
727  bool SendReINVITE(PTRACE_PARAM(const char * msg));
728  bool StartPendingReINVITE();
729 
730  friend class SIPInvite;
732 
733  virtual void SendDelayedACK(bool force);
734  void OnDelayedAckTimeout();
735 
736  virtual bool SendInviteOK();
737  virtual PBoolean SendInviteResponse(
739  const SDPSessionDescription * sdp = NULL
740  );
741  virtual void AdjustInviteResponse(
742  SIP_PDU & response
743  );
744 
745  void UpdateRemoteAddresses();
746 #if OPAL_SRTP
747  virtual bool CanDoSRTP() const { return m_dialog.GetRemoteTransportAddress(m_dnsEntry).GetProtoPrefix() == OpalTransportAddress::TlsPrefix(); }
748 #endif
749 
750  void NotifyDialogState(
751  SIPDialogNotification::States state,
752  SIPDialogNotification::Events eventType = SIPDialogNotification::NoEvent,
753  unsigned eventCode = 0
754  );
755 
756  virtual bool InviteConferenceParticipant(const PString & conf, const PString & dest);
757 
758  // Member variables
760  PStringSet m_allowedEvents;
761 
762  enum HoldState {
765 
766  // Order is important!
769  };
772  PString m_forwardParty;
776 
780  PTimeInterval m_delayedAckTimeout;
783  unsigned m_sdpVersion; // Really a sequence number
790  PString m_alertInfo;
792 
796  std::queue<SIP_PDU> m_responsePackets;
801 
803  PSafeList<SIPTransaction> m_forkedInvitations; // Not for re-INVITE
804  PSafeList<SIPTransaction> m_pendingInvitations; // For re-INVITE
805 
806  enum {
811  } releaseMethod;
812 
815  bool SetRemoteMediaFormats(SIP_PDU * pdu);
816 
817  std::map<std::string, SIP_PDU *> m_responses;
818 
819 #if OPAL_HAS_SIPIM
820  PSafePtr<OpalSIPIMContext> m_imContext;
821 #endif
822 
823 #if OPAL_VIDEO
825 #endif
826 
827  enum {
832  void OnUserInputInlineRFC2833(OpalRFC2833Info & info, INT type);
833 
834 
835  private:
836  P_REMOVE_VIRTUAL_VOID(OnCreatingINVITE(SIP_PDU&));
837  P_REMOVE_VIRTUAL_VOID(OnReceivedTrying(SIP_PDU &));
838  P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIPURL & /*from*/, const SIP_PDU & /*pdu*/));
839  P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIP_PDU & /*pdu*/));
840 
841  friend class SIPTransaction;
842  friend class SIP_RTP_Session;
843 };
844 
845 
846 #endif // OPAL_SIP
847 
848 #endif // OPAL_SIP_SIPCON_H
849 
850 
851 // End of File ///////////////////////////////////////////////////////////////