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 RTP_UDP *OnUseRTPSession(
00457 const unsigned rtpSessionId,
00458 const OpalMediaType & mediaType,
00459 const OpalTransportAddress & mediaAddress,
00460 OpalTransportAddress & localAddress
00461 );
00462
00463 virtual bool OnSendSDP(
00464 bool isAnswerSDP,
00465 OpalRTPSessionManager & rtpSessions,
00466 SDPSessionDescription & sdpOut
00467 );
00468 virtual bool OfferSDPMediaDescription(
00469 const OpalMediaType & mediaType,
00470 unsigned sessionID,
00471 OpalRTPSessionManager & rtpSessions,
00472 SDPSessionDescription & sdpOut
00473 );
00474 virtual bool AnswerSDPMediaDescription(
00475 const SDPSessionDescription & sdpIn,
00476 unsigned sessionIndex,
00477 SDPSessionDescription & sdpOut
00478 );
00479
00480 virtual void OnReceivedSDP(
00481 SIP_PDU & pdu
00482 );
00483 virtual bool OnReceivedSDPMediaDescription(
00484 SDPSessionDescription & sdp,
00485 unsigned sessionId
00486 );
00487 friend class SIPInvite;
00488 static PBoolean WriteINVITE(OpalTransport & transport, void * param);
00489 bool WriteINVITE(OpalTransport & transport);
00490
00491 OpalTransport * CreateTransport(const OpalTransportAddress & address, PBoolean isLocalAddress = PFalse);
00492
00493 void UpdateRemoteAddresses();
00494
00495 void NotifyDialogState(
00496 SIPDialogNotification::States state,
00497 SIPDialogNotification::Events eventType = SIPDialogNotification::NoEvent,
00498 unsigned eventCode = 0
00499 );
00500
00501
00502
00503 SIPEndPoint & endpoint;
00504 OpalTransport * transport;
00505 bool deleteTransport;
00506
00507 enum HoldState {
00508 eHoldOff,
00509 eRetrieveInProgress,
00510
00511
00512 eHoldOn,
00513 eHoldInProgress
00514 };
00515 HoldState m_holdToRemote;
00516 bool m_holdFromRemote;
00517 PString forwardParty;
00518
00519 SIP_PDU * originalInvite;
00520 PTime originalInviteTime;
00521 time_t m_sdpSessionId;
00522 unsigned m_sdpVersion;
00523 bool needReINVITE;
00524 SIPDialogContext m_dialog;
00525 OpalGloballyUniqueID m_dialogNotifyId;
00526 int m_appearanceCode;
00527 PString m_alertInfo;
00528 SIPAuthentication * authentication;
00529
00530 std::map<SIP_PDU::Methods, unsigned> m_lastRxCSeq;
00531
00532 PTimer ackTimer;
00533 PTimer ackRetry;
00534 SIP_PDU ackPacket;
00535 bool ackReceived;
00536 PSafePtr<SIPTransaction> referTransaction;
00537 PSafeList<SIPTransaction> forkedInvitations;
00538
00539 enum {
00540 ReleaseWithBYE,
00541 ReleaseWithCANCEL,
00542 ReleaseWithResponse,
00543 ReleaseWithNothing,
00544 } releaseMethod;
00545
00546 OpalMediaFormatList remoteFormatList;
00547
00548 protected:
00549 PTimer sessionTimer;
00550 public:
00551 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnSessionTimeout);
00552
00553 private:
00554 P_REMOVE_VIRTUAL_VOID(OnCreatingINVITE(SIP_PDU&));
00555 P_REMOVE_VIRTUAL_VOID(OnReceivedTrying(SIP_PDU &));
00556 };
00557
00558
00561 class SIP_RTP_Session : public RTP_UserData
00562 {
00563 PCLASSINFO(SIP_RTP_Session, RTP_UserData);
00564
00569 SIP_RTP_Session(
00570 const SIPConnection & connection
00571 );
00573
00582 virtual void OnTxStatistics(
00583 const RTP_Session & session
00584 ) const;
00585
00592 virtual void OnRxStatistics(
00593 const RTP_Session & session
00594 ) const;
00595
00596 #if OPAL_VIDEO
00597
00601 virtual void OnRxIntraFrameRequest(
00602 const RTP_Session & session
00603 ) const;
00604
00608 virtual void OnTxIntraFrameRequest(
00609 const RTP_Session & session
00610 ) const;
00611 #endif
00612
00613
00614 virtual void SessionFailing(RTP_Session & );
00615
00616 protected:
00617 const SIPConnection & connection;
00618 };
00619
00620
00621 #endif // OPAL_SIP
00622
00623 #endif // OPAL_SIP_SIPCON_H
00624
00625
00626