00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef OPAL_SIP_SIPCON_H
00033 #define OPAL_SIP_SIPCON_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 <opal/buildopts.h>
00044 #include <opal/rtpconn.h>
00045 #include <sip/sippdu.h>
00046 #include <sip/handlers.h>
00047
00048 #if OPAL_VIDEO
00049 #include <opal/pcss.h>
00050 #include <codec/vidcodec.h>
00051 #endif
00052
00053 #if OPAL_HAS_IM
00054 #include <im/rfc4103.h>
00055 #endif
00056
00057 class OpalCall;
00058 class SIPEndPoint;
00059
00060 #define SIP_HEADER_PREFIX "SIP-Header:"
00061 #define SIP_HEADER_REPLACES SIP_HEADER_PREFIX"Replaces"
00062
00063
00065
00069 class SIPConnection : public OpalRTPConnection
00070 {
00071 PCLASSINFO(SIPConnection, OpalRTPConnection);
00072 public:
00073
00078 SIPConnection(
00079 OpalCall & call,
00080 SIPEndPoint & endpoint,
00081 const PString & token,
00082 const SIPURL & address,
00083 OpalTransport * transport,
00084 unsigned int options = 0,
00085 OpalConnection::StringOptions * stringOptions = NULL
00086 );
00087
00090 ~SIPConnection();
00092
00103 virtual bool IsNetworkConnection() const { return true; }
00104
00107 virtual PString GetPrefixName() const;
00108
00111 virtual PString GetIdentifier() const;
00112
00119 virtual PString GetRemotePartyURL() const;
00120
00127 virtual PBoolean SetUpConnection();
00128
00135 virtual PString GetDestinationAddress();
00136
00144 virtual PString GetCalledPartyURL();
00145
00159 virtual PString GetAlertingType() const;
00160
00174 virtual bool SetAlertingType(const PString & info);
00175
00182 virtual bool TransferConnection(
00183 const PString & remoteParty
00184 );
00185
00188 virtual bool HoldConnection();
00189
00193 virtual bool RetrieveConnection();
00194
00197 virtual PBoolean IsConnectionOnHold();
00198
00209 virtual PBoolean SetAlerting(
00210 const PString & calleeName,
00211 PBoolean withMedia
00212 );
00213
00218 virtual PBoolean SetConnected();
00219
00222 virtual OpalMediaFormatList GetMediaFormats() const;
00223
00226 virtual OpalMediaStreamPtr OpenMediaStream(
00227 const OpalMediaFormat & mediaFormat,
00228 unsigned sessionID,
00229 bool isSource
00230 );
00231
00236 virtual bool CloseMediaStream(
00237 OpalMediaStream & stream
00238 );
00239
00257 virtual void OnReleased();
00258
00268 virtual PBoolean ForwardCall(
00269 const PString & forwardParty
00270 );
00271
00277 virtual SendUserInputModes GetRealSendUserInputMode() const;
00278
00295 PBoolean SendUserInputTone(char tone, unsigned duration);
00296
00304 virtual void OnRTPStatistics(
00305 const RTP_Session & session
00306 ) const;
00308
00313 virtual void OnTransactionFailed(
00314 SIPTransaction & transaction
00315 );
00316
00319 virtual void OnReceivedPDU(SIP_PDU & pdu);
00320
00323 virtual void OnReceivedINVITE(SIP_PDU & pdu);
00324
00327 virtual void OnReceivedReINVITE(SIP_PDU & pdu);
00328
00331 virtual void OnReceivedACK(SIP_PDU & pdu);
00332
00335 virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
00336
00339 virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
00340
00343 virtual void OnReceivedREFER(SIP_PDU & pdu);
00344
00347 virtual void OnReceivedINFO(SIP_PDU & pdu);
00348
00351 virtual void OnReceivedPING(SIP_PDU & pdu);
00352
00355 virtual void OnReceivedBYE(SIP_PDU & pdu);
00356
00359 virtual void OnReceivedCANCEL(SIP_PDU & pdu);
00360
00365 virtual void OnReceivedResponseToINVITE(
00366 SIPTransaction & transaction,
00367 SIP_PDU & response
00368 );
00369
00372 virtual void OnReceivedResponse(
00373 SIPTransaction & transaction,
00374 SIP_PDU & response
00375 );
00376
00379 virtual void OnReceivedTrying(
00380 SIPTransaction & transaction,
00381 SIP_PDU & response
00382 );
00383
00386 virtual void OnReceivedRinging(SIP_PDU & pdu);
00387
00390 virtual void OnReceivedSessionProgress(SIP_PDU & pdu);
00391
00395 virtual PBoolean OnReceivedAuthenticationRequired(
00396 SIPTransaction & transaction,
00397 SIP_PDU & response
00398 );
00399
00402 virtual void OnReceivedRedirection(SIP_PDU & pdu);
00403
00407 virtual void OnReceivedOK(
00408 SIPTransaction & transaction,
00409 SIP_PDU & response
00410 );
00411
00414 virtual void OnCreatingINVITE(SIPInvite & pdu);
00415
00418 virtual PBoolean SendInviteOK(const SDPSessionDescription & sdp);
00419
00422 virtual PBoolean SendInviteResponse(
00423 SIP_PDU::StatusCodes code,
00424 const char * contact = NULL,
00425 const char * extra = NULL,
00426 const SDPSessionDescription * sdp = NULL
00427 );
00429
00430 OpalTransportAddress GetDefaultSDPConnectAddress(WORD port = 0) const;
00431
00432 OpalTransport & GetTransport() const { return *transport; }
00433
00434 SIPEndPoint & GetEndPoint() const { return endpoint; }
00435 SIPDialogContext & GetDialog() { return m_dialog; }
00436 const SIPDialogContext & GetDialog() const { return m_dialog; }
00437 SIPAuthentication * GetAuthenticator() const { return authentication; }
00438
00439 #if OPAL_VIDEO
00440
00445 virtual PBoolean OnMediaControlXML(SIP_PDU & pdu);
00446 #endif
00447
00448 virtual void OnMediaCommand(OpalMediaCommand & note, INT extra);
00449
00450 virtual void OnStartTransaction(SIPTransaction & transaction);
00451
00452 virtual void OnReceivedMESSAGE(SIP_PDU & pdu);
00453
00454 P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIPURL & , const SIP_PDU & ));
00455 P_REMOVE_VIRTUAL_VOID(OnMessageReceived(const SIP_PDU & ));
00456
00457 #if OPAL_HAS_IM
00458 virtual bool TransmitExternalIM(
00459 const OpalMediaFormat & format,
00460 RTP_DataFrame & body
00461 );
00462 #endif
00463
00464 PString GetLocalPartyURL() const;
00465
00466 protected:
00467 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseRetry);
00468 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnAckTimeout);
00469
00470 virtual RTP_UDP *OnUseRTPSession(
00471 const unsigned rtpSessionId,
00472 const OpalMediaType & mediaType,
00473 const OpalTransportAddress & mediaAddress,
00474 OpalTransportAddress & localAddress
00475 );
00476
00477 virtual bool OnSendSDP(
00478 bool isAnswerSDP,
00479 OpalRTPSessionManager & rtpSessions,
00480 SDPSessionDescription & sdpOut
00481 );
00482 virtual bool OfferSDPMediaDescription(
00483 const OpalMediaType & mediaType,
00484 unsigned sessionID,
00485 OpalRTPSessionManager & rtpSessions,
00486 SDPSessionDescription & sdpOut
00487 );
00488 virtual bool AnswerSDPMediaDescription(
00489 const SDPSessionDescription & sdpIn,
00490 unsigned sessionIndex,
00491 SDPSessionDescription & sdpOut
00492 );
00493
00494 virtual void OnReceivedSDP(
00495 SIP_PDU & pdu
00496 );
00497 virtual bool OnReceivedSDPMediaDescription(
00498 SDPSessionDescription & sdp,
00499 unsigned sessionId
00500 );
00501 friend class SIPInvite;
00502 static PBoolean WriteINVITE(OpalTransport & transport, void * param);
00503 bool WriteINVITE(OpalTransport & transport);
00504
00505 OpalTransport * CreateTransport(const OpalTransportAddress & address, PBoolean isLocalAddress = PFalse);
00506
00507 void UpdateRemoteAddresses();
00508
00509 void NotifyDialogState(
00510 SIPDialogNotification::States state,
00511 SIPDialogNotification::Events eventType = SIPDialogNotification::NoEvent,
00512 unsigned eventCode = 0
00513 );
00514
00515
00516
00517 SIPEndPoint & endpoint;
00518 OpalTransport * transport;
00519 bool deleteTransport;
00520
00521 enum HoldState {
00522 eHoldOff,
00523 eRetrieveInProgress,
00524
00525
00526 eHoldOn,
00527 eHoldInProgress
00528 };
00529 HoldState m_holdToRemote;
00530 bool m_holdFromRemote;
00531 PString forwardParty;
00532
00533 SIP_PDU * originalInvite;
00534 PTime originalInviteTime;
00535 time_t m_sdpSessionId;
00536 unsigned m_sdpVersion;
00537 bool needReINVITE;
00538 SIPDialogContext m_dialog;
00539 OpalGloballyUniqueID m_dialogNotifyId;
00540 int m_appearanceCode;
00541 PString m_alertInfo;
00542 SIPAuthentication * authentication;
00543
00544 std::map<SIP_PDU::Methods, unsigned> m_lastRxCSeq;
00545
00546 PTimer ackTimer;
00547 PTimer ackRetry;
00548 SIP_PDU ackPacket;
00549 bool ackReceived;
00550 PSafePtr<SIPTransaction> referTransaction;
00551 PSafeList<SIPTransaction> forkedInvitations;
00552
00553 enum {
00554 ReleaseWithBYE,
00555 ReleaseWithCANCEL,
00556 ReleaseWithResponse,
00557 ReleaseWithNothing,
00558 } releaseMethod;
00559
00560 OpalMediaFormatList remoteFormatList;
00561
00562 protected:
00563 PTimer sessionTimer;
00564 #if OPAL_HAS_IM
00565 RFC4103Context rfc4103Context;
00566 #endif
00567
00568 public:
00569 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnSessionTimeout);
00570
00571 private:
00572 P_REMOVE_VIRTUAL_VOID(OnCreatingINVITE(SIP_PDU&));
00573 P_REMOVE_VIRTUAL_VOID(OnReceivedTrying(SIP_PDU &));
00574 };
00575
00576
00579 class SIP_RTP_Session : public RTP_UserData
00580 {
00581 PCLASSINFO(SIP_RTP_Session, RTP_UserData);
00582
00587 SIP_RTP_Session(
00588 const SIPConnection & connection
00589 );
00591
00600 virtual void OnTxStatistics(
00601 const RTP_Session & session
00602 ) const;
00603
00610 virtual void OnRxStatistics(
00611 const RTP_Session & session
00612 ) const;
00613
00614 #if OPAL_VIDEO
00615
00619 virtual void OnRxIntraFrameRequest(
00620 const RTP_Session & session
00621 ) const;
00622
00626 virtual void OnTxIntraFrameRequest(
00627 const RTP_Session & session
00628 ) const;
00629 #endif
00630
00631
00632 virtual void SessionFailing(RTP_Session & );
00633
00634 protected:
00635 const SIPConnection & connection;
00636 };
00637
00638
00639 #endif // OPAL_SIP
00640
00641 #endif // OPAL_SIP_SIPCON_H
00642
00643
00644