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 #if OPAL_VIDEO
00048 #include <opal/pcss.h>
00049 #include <codec/vidcodec.h>
00050 #endif
00051
00052 class OpalCall;
00053 class SIPEndPoint;
00054
00055 #define SIP_HEADER_PREFIX "SIP-Header:"
00056 #define SIP_HEADER_REPLACES SIP_HEADER_PREFIX"Replaces"
00057
00058
00060
00063
00064 class SIPConnection : public OpalRTPConnection
00065 {
00066 PCLASSINFO(SIPConnection, OpalRTPConnection);
00067 public:
00068
00073 SIPConnection(
00074 OpalCall & call,
00075 SIPEndPoint & endpoint,
00076 const PString & token,
00077 const SIPURL & address,
00078 OpalTransport * transport,
00079 unsigned int options = 0,
00080 OpalConnection::StringOptions * stringOptions = NULL
00081 );
00082
00085 ~SIPConnection();
00087
00098 virtual bool IsNetworkConnection() const { return true; }
00099
00102 virtual PString GetPrefixName() const;
00103
00106 virtual PString GetIdentifier() const;
00107
00114 virtual PString GetRemotePartyURL() const;
00115
00122 virtual PBoolean SetUpConnection();
00123
00130 virtual PString GetDestinationAddress();
00131
00139 virtual PString GetCalledPartyURL();
00140
00154 virtual PString GetAlertingType() const;
00155
00169 virtual bool SetAlertingType(const PString & info);
00170
00177 virtual bool TransferConnection(
00178 const PString & remoteParty
00179 );
00180
00183 virtual bool HoldConnection();
00184
00188 virtual bool RetrieveConnection();
00189
00192 virtual PBoolean IsConnectionOnHold();
00193
00204 virtual PBoolean SetAlerting(
00205 const PString & calleeName,
00206 PBoolean withMedia
00207 );
00208
00213 virtual PBoolean SetConnected();
00214
00217 virtual OpalMediaFormatList GetMediaFormats() const;
00218
00221 virtual OpalMediaStreamPtr OpenMediaStream(
00222 const OpalMediaFormat & mediaFormat,
00223 unsigned sessionID,
00224 bool isSource
00225 );
00226
00231 virtual bool CloseMediaStream(
00232 OpalMediaStream & stream
00233 );
00234
00252 virtual void OnReleased();
00253
00263 virtual PBoolean ForwardCall(
00264 const PString & forwardParty
00265 );
00266
00272 virtual SendUserInputModes GetRealSendUserInputMode() const;
00273
00290 PBoolean SendUserInputTone(char tone, unsigned duration);
00291
00299 virtual void OnRTPStatistics(
00300 const RTP_Session & session
00301 ) const;
00303
00308 virtual void OnTransactionFailed(
00309 SIPTransaction & transaction
00310 );
00311
00314 virtual void OnReceivedPDU(SIP_PDU & pdu);
00315
00318 virtual void OnReceivedINVITE(SIP_PDU & pdu);
00319
00322 virtual void OnReceivedReINVITE(SIP_PDU & pdu);
00323
00326 virtual void OnReceivedACK(SIP_PDU & pdu);
00327
00330 virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
00331
00334 virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
00335
00338 virtual void OnReceivedREFER(SIP_PDU & pdu);
00339
00342 virtual void OnReceivedINFO(SIP_PDU & pdu);
00343
00346 virtual void OnReceivedPING(SIP_PDU & pdu);
00347
00350 virtual void OnReceivedBYE(SIP_PDU & pdu);
00351
00354 virtual void OnReceivedCANCEL(SIP_PDU & pdu);
00355
00360 virtual void OnReceivedResponseToINVITE(
00361 SIPTransaction & transaction,
00362 SIP_PDU & response
00363 );
00364
00367 virtual void OnReceivedResponse(
00368 SIPTransaction & transaction,
00369 SIP_PDU & response
00370 );
00371
00374 virtual void OnReceivedTrying(
00375 SIPTransaction & transaction,
00376 SIP_PDU & response
00377 );
00378
00381 virtual void OnReceivedRinging(SIP_PDU & pdu);
00382
00385 virtual void OnReceivedSessionProgress(SIP_PDU & pdu);
00386
00390 virtual PBoolean OnReceivedAuthenticationRequired(
00391 SIPTransaction & transaction,
00392 SIP_PDU & response
00393 );
00394
00397 virtual void OnReceivedRedirection(SIP_PDU & pdu);
00398
00402 virtual void OnReceivedOK(
00403 SIPTransaction & transaction,
00404 SIP_PDU & response
00405 );
00406
00409 virtual void OnCreatingINVITE(SIPInvite & pdu);
00410
00413 virtual PBoolean SendInviteOK(const SDPSessionDescription & sdp);
00414
00417 virtual PBoolean SendInviteResponse(
00418 SIP_PDU::StatusCodes code,
00419 const char * contact = NULL,
00420 const char * extra = NULL,
00421 const SDPSessionDescription * sdp = NULL
00422 );
00424
00425 OpalTransportAddress GetDefaultSDPConnectAddress(WORD port = 0) const;
00426
00427 OpalTransport & GetTransport() const { return *transport; }
00428
00429 SIPEndPoint & GetEndPoint() const { return endpoint; }
00430 SIPDialogContext & GetDialog() { return m_dialog; }
00431 const SIPDialogContext & GetDialog() const { return m_dialog; }
00432 SIPAuthentication * GetAuthenticator() const { return authentication; }
00433
00434 #if OPAL_VIDEO
00435
00440 virtual PBoolean OnMediaControlXML(SIP_PDU & pdu);
00441 #endif
00442
00443 virtual void OnMediaCommand(OpalMediaCommand & note, INT extra);
00444
00445 virtual void OnStartTransaction(SIPTransaction & transaction);
00446
00447 virtual void OnReceivedMESSAGE(SIP_PDU & pdu);
00448 virtual void OnMessageReceived(const SIPURL & from, const SIP_PDU & pdu);
00449
00450 PString GetLocalPartyURL() const;
00451
00452 protected:
00453 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseRetry);
00454 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnAckTimeout);
00455
00456 virtual bool OnSendSDP(
00457 bool isAnswerSDP,
00458 OpalRTPSessionManager & rtpSessions,
00459 SDPSessionDescription & sdpOut
00460 );
00461 virtual bool OfferSDPMediaDescription(
00462 const OpalMediaType & mediaType,
00463 unsigned sessionID,
00464 OpalRTPSessionManager & rtpSessions,
00465 SDPSessionDescription & sdpOut
00466 );
00467 virtual bool AnswerSDPMediaDescription(
00468 const SDPSessionDescription & sdpIn,
00469 unsigned sessionIndex,
00470 SDPSessionDescription & sdpOut
00471 );
00472
00473 virtual void OnReceivedSDP(
00474 SIP_PDU & pdu
00475 );
00476 virtual bool OnReceivedSDPMediaDescription(
00477 SDPSessionDescription & sdp,
00478 unsigned sessionId
00479 );
00480
00481 virtual OpalMediaSession * SetUpMediaSession(
00482 const unsigned rtpSessionId,
00483 const OpalMediaType & mediaType,
00484 SDPMediaDescription * mediaDescription,
00485 OpalTransportAddress & localAddress,
00486 bool & remoteChanged
00487 );
00488
00489 bool SendReINVITE(PTRACE_PARAM(const char * msg));
00490 void StartPendingReINVITE();
00491
00492 friend class SIPInvite;
00493 static PBoolean WriteINVITE(OpalTransport & transport, void * param);
00494 bool WriteINVITE(OpalTransport & transport);
00495
00496 OpalTransport * CreateTransport(const OpalTransportAddress & address, PBoolean isLocalAddress = PFalse);
00497
00498 void UpdateRemoteAddresses();
00499
00500 void NotifyDialogState(
00501 SIPDialogNotification::States state,
00502 SIPDialogNotification::Events eventType = SIPDialogNotification::NoEvent,
00503 unsigned eventCode = 0
00504 );
00505
00506
00507
00508 SIPEndPoint & endpoint;
00509 OpalTransport * transport;
00510 bool deleteTransport;
00511
00512 enum HoldState {
00513 eHoldOff,
00514 eRetrieveInProgress,
00515
00516
00517 eHoldOn,
00518 eHoldInProgress
00519 };
00520 HoldState m_holdToRemote;
00521 bool m_holdFromRemote;
00522 PString forwardParty;
00523
00524 SIP_PDU * originalInvite;
00525 PTime originalInviteTime;
00526 time_t m_sdpSessionId;
00527 unsigned m_sdpVersion;
00528 bool needReINVITE;
00529 bool m_handlingINVITE;
00530 SIPDialogContext m_dialog;
00531 OpalGloballyUniqueID m_dialogNotifyId;
00532 int m_appearanceCode;
00533 PString m_alertInfo;
00534 SIPAuthentication * authentication;
00535
00536 std::map<SIP_PDU::Methods, unsigned> m_lastRxCSeq;
00537
00538 PTimer ackTimer;
00539 PTimer ackRetry;
00540 SIP_PDU ackPacket;
00541 bool ackReceived;
00542 PSafePtr<SIPTransaction> referTransaction;
00543 PSafeList<SIPTransaction> forkedInvitations;
00544 PSafeList<SIPTransaction> pendingInvitations;
00545
00546 enum {
00547 ReleaseWithBYE,
00548 ReleaseWithCANCEL,
00549 ReleaseWithResponse,
00550 ReleaseWithNothing,
00551 } releaseMethod;
00552
00553 OpalMediaFormatList remoteFormatList;
00554
00555 protected:
00556 PTimer sessionTimer;
00557 public:
00558 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnSessionTimeout);
00559
00560 private:
00561 P_REMOVE_VIRTUAL_VOID(OnCreatingINVITE(SIP_PDU&));
00562 P_REMOVE_VIRTUAL_VOID(OnReceivedTrying(SIP_PDU &));
00563 };
00564
00565
00568 class SIP_RTP_Session : public RTP_UserData
00569 {
00570 PCLASSINFO(SIP_RTP_Session, RTP_UserData);
00571
00576 SIP_RTP_Session(
00577 const SIPConnection & connection
00578 );
00580
00589 virtual void OnTxStatistics(
00590 const RTP_Session & session
00591 ) const;
00592
00599 virtual void OnRxStatistics(
00600 const RTP_Session & session
00601 ) const;
00602
00603 #if OPAL_VIDEO
00604
00608 virtual void OnRxIntraFrameRequest(
00609 const RTP_Session & session
00610 ) const;
00611
00615 virtual void OnTxIntraFrameRequest(
00616 const RTP_Session & session
00617 ) const;
00618 #endif
00619
00620
00621 virtual void SessionFailing(RTP_Session & );
00622
00623 protected:
00624 const SIPConnection & connection;
00625 };
00626
00627
00628 #endif // OPAL_SIP
00629
00630 #endif // OPAL_SIP_SIPCON_H
00631
00632
00633