msrp.h
Go to the documentation of this file.
/*
* msrp.h
*
* Support for RFC 4975 Message Session Relay Protocol (MSRP)
*
* Open Phone Abstraction Library (OPAL)
*
* Copyright (c) 2008 Post Increment
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Open Phone Abstraction Library.
*
* The Initial Developer of the Original Code is Post Increment
*
* Contributor(s): ______________________________________.
*
* $Revision: 27149 $
* $Author: rjongbloed $
* $Date: 2012-03-07 18:32:36 -0600 (Wed, 07 Mar 2012) $
*/
#ifndef OPAL_IM_MSRP_H
#define OPAL_IM_MSRP_H
#include <ptlib.h>
#include <opal/buildopts.h>
#include <opal/rtpconn.h>
#include <opal/manager.h>
#include <opal/mediastrm.h>
#include <opal/mediatype.h>
#include <im/im.h>
#include <ptclib/inetprot.h>
#include <ptclib/guid.h>
#include <ptclib/mime.h>
#if OPAL_SIP
#include <sip/sdp.h>
#endif
#if OPAL_HAS_MSRP
class OpalMSRPMediaType : public OpalIMMediaType
{
public:
OpalMSRPMediaType();
virtual OpalMediaSession * CreateMediaSession(OpalConnection & conn, unsigned sessionID) const;
#if OPAL_SIP
SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress & localAddress);
#endif
};
//
// Ancestor for all MSRP encoding types
//
class OpalMSRPEncoding {
};
//
// Ancestor for MSRP protocol
//
class MSRPProtocol : public PInternetProtocol
{
public:
enum Commands {
SEND,
REPORT,
NumCommands
};
static const unsigned MaximumMessageLength = 1024;
class Message
{
public:
struct Chunk {
Chunk(const PString & id, unsigned from, unsigned len)
: m_chunkId(id), m_rangeFrom(from + 1), m_rangeTo(from + len) { }
PString m_chunkId;
unsigned m_rangeFrom;
unsigned m_rangeTo;
};
typedef std::vector<Chunk> ChunkList;
ChunkList m_chunks;
PString m_id;
PURL m_fromURL;
PURL m_toURL;
PString m_contentType;
unsigned m_length;
};
MSRPProtocol();
bool SendSEND(
const PURL & from,
const PURL & to,
const PString & text,
const PString & contentType,
PString & messageId
);
bool SendChunk(
const PString & transactionId,
const PString toUrl,
const PString fromUrl,
const PMIMEInfo & mime,
const PString & body
);
bool SendResponse(const PString & chunkId,
unsigned response,
const PString & text,
const PString & toUrl,
const PString & fromUrl);
bool SendREPORT(const PString & chunkId,
const PString & toUrl,
const PString & fromUrl,
const PMIMEInfo & mime);
bool ReadMessage(
int & command,
PString & chunkId,
PMIMEInfo & mime,
PString & body
);
//typedef std::map<std::string, Message> MessageMap;
//MessageMap m_messageMap;
PMutex m_mutex;
};
//
//
//
class OpalMSRPManager : public PObject
{
public:
enum {
DefaultPort = 2855
};
//
// Create an MSRP manager. This is a singleton class
//
OpalMSRPManager(OpalManager & opal, WORD port = DefaultPort);
~OpalMSRPManager();
//
// Get the local port for the MSRP manager
//
bool GetLocalPort(WORD & port);
//
// Information about a connection to another MSRP manager
//
class Connection : public PSafeObject {
public:
Connection(OpalMSRPManager & manager, const std::string & key, MSRPProtocol * protocol = NULL);
~Connection();
//
// Start handler thread for a connection
//
void StartHandler();
//
// Handler thread for a connection
//
void HandlerThread();
OpalMSRPManager & m_manager;
std::string m_key;
MSRPProtocol * m_protocol;
bool m_running;
PThread * m_handlerThread;
bool m_originating;
PAtomicInteger m_refCount;
};
//
// Get the connection to use for communicating with a remote URL
//
PSafePtr<Connection> OpenConnection(
const PURL & localURL,
const PURL & remoteURL
);
//
// close a connection
//
bool CloseConnection(
PSafePtr<OpalMSRPManager::Connection> & connection
);
//
// Create a new MSRP session ID
//
std::string CreateSessionID();
//
// return session ID as a path
//
PURL SessionIDToURL(const OpalTransportAddress & addr, const std::string & id);
//
// Main listening thread for new connections
//
void ListenerThread();
struct IncomingMSRP {
int m_command;
PString m_chunkId;
PMIMEInfo m_mime;
PString m_body;
PSafePtr<Connection> m_connection;
};
//
// dispatch an incoming MSRP message to the correct callback
//
void DispatchMessage(
IncomingMSRP & incomingMsg
);
typedef PNotifierTemplate<IncomingMSRP &> CallBack;
void SetNotifier(
const PURL & localUrl,
const PURL & remoteURL,
const CallBack & notifier
);
void RemoveNotifier(
const PURL & localUrl,
const PURL & remoteURL
);
OpalManager & GetOpalManager() { return opalManager; }
protected:
OpalManager & opalManager;
WORD m_listenerPort;
PMutex mutex;
PAtomicInteger lastID;
PTCPSocket m_listenerSocket;
PThread * m_listenerThread;
PMutex m_connectionInfoMapAddMutex;
typedef std::map<std::string, PSafePtr<Connection> > ConnectionInfoMapType;
ConnectionInfoMapType m_connectionInfoMap;
typedef std::map<std::string, CallBack> CallBackMap;
CallBackMap m_callBacks;
PMutex m_callBacksMutex;
private:
static OpalMSRPManager * msrp;
};
class OpalMSRPMediaSession : public OpalMediaSession
{
PCLASSINFO(OpalMSRPMediaSession, OpalMediaSession);
public:
OpalMSRPMediaSession(OpalConnection & connection, unsigned sessionId);
OpalMSRPMediaSession(const OpalMSRPMediaSession & _obj);
~OpalMSRPMediaSession();
bool Open(const PURL & remoteParty);
virtual void Close();
virtual PObject * Clone() const { return new OpalMSRPMediaSession(*this); }
virtual bool IsActive() const { return true; }
virtual bool IsRTP() const { return false; }
virtual bool HasFailed() const { return false; }
virtual OpalTransportAddress GetLocalMediaAddress() const;
PURL GetLocalURL() const { return m_localUrl; }
PURL GetRemoteURL() const { return m_remoteUrl; }
void SetRemoteURL(const PURL & url) { m_remoteUrl = url; }
virtual void SetRemoteMediaAddress(const OpalTransportAddress &, const OpalMediaFormatList & );
virtual bool WritePacket(
RTP_DataFrame & frame
);
PBoolean ReadData(
BYTE * data,
PINDEX length,
PINDEX & read
);
#if OPAL_SIP
virtual SDPMediaDescription * CreateSDPMediaDescription(
const OpalTransportAddress & localAddress
);
#endif
virtual OpalMediaStream * CreateMediaStream(
const OpalMediaFormat & mediaFormat,
unsigned sessionID,
PBoolean isSource
);
OpalMSRPManager & GetManager() { return m_manager; }
bool OpenMSRP(const PURL & remoteUrl);
void CloseMSRP();
void SetConnection(PSafePtr<OpalMSRPManager::Connection> & conn);
OpalMSRPManager & m_manager;
bool m_isOriginating;
std::string m_localMSRPSessionId;
PURL m_localUrl;
PURL m_remoteUrl;
PSafePtr<OpalMSRPManager::Connection> m_connectionPtr;
OpalTransportAddress m_remoteAddress;
};
class OpalMSRPMediaStream : public OpalIMMediaStream
{
public:
OpalMSRPMediaStream(
OpalConnection & conn,
const OpalMediaFormat & mediaFormat,
unsigned sessionID,
bool isSource,
OpalMSRPMediaSession & msrpSession
);
~OpalMSRPMediaStream();
virtual PBoolean RequiresPatchThread() const { return !isSource; }
virtual PBoolean ReadPacket(
RTP_DataFrame & frame
);
virtual PBoolean WritePacket(
RTP_DataFrame & frame
);
virtual bool Open();
PURL GetRemoteURL() const { return m_msrpSession.GetRemoteURL(); }
void SetRemoteURL(const PURL & url) { m_msrpSession.SetRemoteURL(url); }
PDECLARE_NOTIFIER2(OpalMSRPManager, OpalMSRPMediaStream, OnReceiveMSRP, OpalMSRPManager::IncomingMSRP &);
protected:
OpalMSRPMediaSession & m_msrpSession;
PString m_remoteParty;
RFC4103Context m_rfc4103Context;
};
// schemeName,user, passwd, host, defUser,defhost, query, params, frags, path, rel, port
#endif // OPAL_HAS_MSRP
#endif // OPAL_IM_MSRP_H
OpalMSRPManager::Connection::m_originating
bool m_originating
Definition: msrp.h:196
OpalMSRPMediaSession::Close
virtual void Close()
OpalMSRPMediaSession::m_localUrl
PURL m_localUrl
Definition: msrp.h:344
OpalMSRPMediaSession::~OpalMSRPMediaSession
~OpalMSRPMediaSession()
MSRPProtocol::SendREPORT
bool SendREPORT(const PString &chunkId, const PString &toUrl, const PString &fromUrl, const PMIMEInfo &mime)
OpalManager
Definition: manager.h:74
OpalMSRPMediaStream::PDECLARE_NOTIFIER2
PDECLARE_NOTIFIER2(OpalMSRPManager, OpalMSRPMediaStream, OnReceiveMSRP, OpalMSRPManager::IncomingMSRP &)
OpalMSRPManager::CallBackMap
std::map< std::string, CallBack > CallBackMap
Definition: msrp.h:272
OpalMSRPMediaSession::m_remoteAddress
OpalTransportAddress m_remoteAddress
Definition: msrp.h:347
OpalMSRPMediaSession::CreateSDPMediaDescription
virtual SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress &localAddress)
OpalMSRPMediaSession::GetManager
OpalMSRPManager & GetManager()
Definition: msrp.h:334
OpalMSRPManager::~OpalMSRPManager
~OpalMSRPManager()
OpalMSRPMediaStream::m_remoteParty
PString m_remoteParty
Definition: msrp.h:393
OpalMediaStream::isSource
bool isSource
Definition: mediastrm.h:421
OpalMSRPManager::m_connectionInfoMapAddMutex
PMutex m_connectionInfoMapAddMutex
Definition: msrp.h:268
OpalMSRPMediaType::CreateMediaSession
virtual OpalMediaSession * CreateMediaSession(OpalConnection &conn, unsigned sessionID) const
OpalMSRPManager::Connection::Connection
Connection(OpalMSRPManager &manager, const std::string &key, MSRPProtocol *protocol=NULL)
OpalMSRPMediaSession::IsActive
virtual bool IsActive() const
Definition: msrp.h:298
buildopts.h
OpalMSRPManager::Connection::m_refCount
PAtomicInteger m_refCount
Definition: msrp.h:197
MSRPProtocol::Commands
Commands
Definition: msrp.h:80
im.h
OpalMediaSession
Definition: rtpconn.h:72
OpalMSRPMediaSession::GetLocalMediaAddress
virtual OpalTransportAddress GetLocalMediaAddress() const
OpalMSRPMediaStream::m_msrpSession
OpalMSRPMediaSession & m_msrpSession
Definition: msrp.h:392
OpalMSRPManager
Definition: msrp.h:155
OpalMSRPMediaSession::m_localMSRPSessionId
std::string m_localMSRPSessionId
Definition: msrp.h:343
OpalMSRPManager::CallBack
PNotifierTemplate< IncomingMSRP & > CallBack
Definition: msrp.h:245
OpalMSRPMediaSession::GetRemoteURL
PURL GetRemoteURL() const
Definition: msrp.h:307
OpalMSRPMediaSession::SetConnection
void SetConnection(PSafePtr< OpalMSRPManager::Connection > &conn)
OpalMSRPEncoding
Definition: msrp.h:68
OpalMSRPMediaStream::OpalMSRPMediaStream
OpalMSRPMediaStream(OpalConnection &conn, const OpalMediaFormat &mediaFormat, unsigned sessionID, bool isSource, OpalMSRPMediaSession &msrpSession)
MSRPProtocol::ReadMessage
bool ReadMessage(int &command, PString &chunkId, PMIMEInfo &mime, PString &body)
OpalMSRPMediaStream::WritePacket
virtual PBoolean WritePacket(RTP_DataFrame &frame)
MSRPProtocol::NumCommands
Definition: msrp.h:83
MSRPProtocol::SendResponse
bool SendResponse(const PString &chunkId, unsigned response, const PString &text, const PString &toUrl, const PString &fromUrl)
OpalMSRPMediaSession::m_isOriginating
bool m_isOriginating
Definition: msrp.h:342
OpalMSRPMediaSession::m_remoteUrl
PURL m_remoteUrl
Definition: msrp.h:345
MSRPProtocol::SendSEND
bool SendSEND(const PURL &from, const PURL &to, const PString &text, const PString &contentType, PString &messageId)
OpalMSRPMediaStream::~OpalMSRPMediaStream
~OpalMSRPMediaStream()
OpalMSRPMediaType::CreateSDPMediaDescription
SDPMediaDescription * CreateSDPMediaDescription(const OpalTransportAddress &localAddress)
OpalMSRPMediaStream::GetRemoteURL
PURL GetRemoteURL() const
Definition: msrp.h:384
OpalMSRPManager::IncomingMSRP::m_connection
PSafePtr< Connection > m_connection
Definition: msrp.h:235
MSRPProtocol::Message::m_id
PString m_id
Definition: msrp.h:102
OpalMSRPMediaSession::CreateMediaStream
virtual OpalMediaStream * CreateMediaStream(const OpalMediaFormat &mediaFormat, unsigned sessionID, PBoolean isSource)
OpalMSRPMediaSession::Open
bool Open(const PURL &remoteParty)
OpalMSRPManager::OpalMSRPManager
OpalMSRPManager(OpalManager &opal, WORD port=DefaultPort)
MSRPProtocol::Message::Chunk::Chunk
Chunk(const PString &id, unsigned from, unsigned len)
Definition: msrp.h:92
MSRPProtocol
Definition: msrp.h:77
OpalMSRPManager::lastID
PAtomicInteger lastID
Definition: msrp.h:264
OpalMSRPMediaSession::OpalMSRPMediaSession
OpalMSRPMediaSession(OpalConnection &connection, unsigned sessionId)
OpalMSRPMediaStream::ReadPacket
virtual PBoolean ReadPacket(RTP_DataFrame &frame)
OpalMSRPManager::m_callBacksMutex
PMutex m_callBacksMutex
Definition: msrp.h:274
OpalMSRPManager::IncomingMSRP::m_body
PString m_body
Definition: msrp.h:234
OpalMSRPManager::mutex
PMutex mutex
Definition: msrp.h:263
OpalMSRPMediaSession
Definition: msrp.h:284
OpalMSRPManager::Connection::HandlerThread
void HandlerThread()
OpalMSRPManager::SessionIDToURL
PURL SessionIDToURL(const OpalTransportAddress &addr, const std::string &id)
MSRPProtocol::REPORT
Definition: msrp.h:82
OpalMSRPMediaStream::m_rfc4103Context
RFC4103Context m_rfc4103Context
Definition: msrp.h:394
MSRPProtocol::Message::m_chunks
ChunkList m_chunks
Definition: msrp.h:100
OpalMediaFormatList
Definition: mediafmt.h:72
MSRPProtocol::m_mutex
PMutex m_mutex
Definition: msrp.h:147
MSRPProtocol::Message::ChunkList
std::vector< Chunk > ChunkList
Definition: msrp.h:99
MSRPProtocol::Message::m_contentType
PString m_contentType
Definition: msrp.h:105
OpalMediaSession::connection
OpalConnection & connection
Definition: rtpconn.h:105
MSRPProtocol::MSRPProtocol
MSRPProtocol()
OpalMediaStream::sessionID
unsigned sessionID
Definition: mediastrm.h:417
MSRPProtocol::Message::Chunk::m_rangeFrom
unsigned m_rangeFrom
Definition: msrp.h:96
MSRPProtocol::Message::m_toURL
PURL m_toURL
Definition: msrp.h:104
OpalMSRPMediaSession::CloseMSRP
void CloseMSRP()
RTP_DataFrame
Definition: rtp.h:71
OpalMSRPMediaStream::SetRemoteURL
void SetRemoteURL(const PURL &url)
Definition: msrp.h:385
OpalMSRPMediaSession::GetLocalURL
PURL GetLocalURL() const
Definition: msrp.h:306
OpalMediaFormat
Definition: mediafmt.h:724
OpalMSRPMediaSession::HasFailed
virtual bool HasFailed() const
Definition: msrp.h:302
MSRPProtocol::Message
Definition: msrp.h:88
OpalMSRPMediaSession::m_manager
OpalMSRPManager & m_manager
Definition: msrp.h:341
OpalMSRPManager::RemoveNotifier
void RemoveNotifier(const PURL &localUrl, const PURL &remoteURL)
SDPMediaDescription
Definition: sdp.h:119
OpalIMMediaStream
Definition: im.h:399
mediatype.h
OpalMSRPManager::GetLocalPort
bool GetLocalPort(WORD &port)
OpalMSRPManager::m_listenerThread
PThread * m_listenerThread
Definition: msrp.h:266
OpalMSRPManager::GetOpalManager
OpalManager & GetOpalManager()
Definition: msrp.h:258
OpalMSRPManager::m_callBacks
CallBackMap m_callBacks
Definition: msrp.h:273
OpalMSRPManager::IncomingMSRP
Definition: msrp.h:230
manager.h
MSRPProtocol::Message::Chunk::m_rangeTo
unsigned m_rangeTo
Definition: msrp.h:97
OpalMSRPManager::IncomingMSRP::m_command
int m_command
Definition: msrp.h:231
MSRPProtocol::Message::Chunk
Definition: msrp.h:91
OpalMSRPManager::DispatchMessage
void DispatchMessage(IncomingMSRP &incomingMsg)
OpalMSRPManager::m_listenerSocket
PTCPSocket m_listenerSocket
Definition: msrp.h:265
OpalMSRPManager::Connection::StartHandler
void StartHandler()
OpalMSRPManager::DefaultPort
Definition: msrp.h:159
MSRPProtocol::Message::m_length
unsigned m_length
Definition: msrp.h:106
OpalMSRPMediaSession::m_connectionPtr
PSafePtr< OpalMSRPManager::Connection > m_connectionPtr
Definition: msrp.h:346
OpalMSRPManager::SetNotifier
void SetNotifier(const PURL &localUrl, const PURL &remoteURL, const CallBack &notifier)
OpalMSRPManager::ConnectionInfoMapType
std::map< std::string, PSafePtr< Connection > > ConnectionInfoMapType
Definition: msrp.h:269
MSRPProtocol::SendChunk
bool SendChunk(const PString &transactionId, const PString toUrl, const PString fromUrl, const PMIMEInfo &mime, const PString &body)
OpalMSRPManager::OpenConnection
PSafePtr< Connection > OpenConnection(const PURL &localURL, const PURL &remoteURL)
OpalMSRPManager::Connection::m_key
std::string m_key
Definition: msrp.h:192
OpalMSRPManager::Connection
Definition: msrp.h:176
OpalMSRPManager::Connection::~Connection
~Connection()
OpalMSRPManager::IncomingMSRP::m_mime
PMIMEInfo m_mime
Definition: msrp.h:233
MSRPProtocol::MaximumMessageLength
static const unsigned MaximumMessageLength
Definition: msrp.h:86
OpalMediaSession::sessionId
unsigned sessionId
Definition: rtpconn.h:107
OpalMSRPManager::CreateSessionID
std::string CreateSessionID()
OpalMSRPMediaSession::ReadData
PBoolean ReadData(BYTE *data, PINDEX length, PINDEX &read)
OpalMSRPManager::ListenerThread
void ListenerThread()
OpalMSRPMediaType
Definition: msrp.h:51
OpalMSRPManager::IncomingMSRP::m_chunkId
PString m_chunkId
Definition: msrp.h:232
OpalMSRPMediaStream::Open
virtual bool Open()
OpalMediaStream
Definition: mediastrm.h:111
OpalMediaStream::mediaFormat
OpalMediaFormat mediaFormat
Definition: mediastrm.h:419
OpalIMMediaType
Definition: im.h:74
OpalMSRPMediaType::OpalMSRPMediaType
OpalMSRPMediaType()
OpalMSRPManager::m_listenerPort
WORD m_listenerPort
Definition: msrp.h:262
MSRPProtocol::SEND
Definition: msrp.h:81
RFC4103Context
Definition: rfc4103.h:44
OpalMSRPMediaSession::IsRTP
virtual bool IsRTP() const
Definition: msrp.h:300
OpalConnection
Definition: connection.h:353
OpalMSRPMediaStream
Definition: msrp.h:352
OpalMSRPManager::Connection::m_manager
OpalMSRPManager & m_manager
Definition: msrp.h:191
mediastrm.h
OpalMSRPMediaSession::SetRemoteMediaAddress
virtual void SetRemoteMediaAddress(const OpalTransportAddress &, const OpalMediaFormatList &)
OpalMSRPMediaSession::WritePacket
virtual bool WritePacket(RTP_DataFrame &frame)
MSRPProtocol::Message::Chunk::m_chunkId
PString m_chunkId
Definition: msrp.h:95
sdp.h
OpalMSRPMediaSession::OpenMSRP
bool OpenMSRP(const PURL &remoteUrl)
OpalTransportAddress
Definition: transports.h:149
rtpconn.h
OpalMSRPManager::Connection::m_protocol
MSRPProtocol * m_protocol
Definition: msrp.h:193
OpalMSRPMediaSession::Clone
virtual PObject * Clone() const
Definition: msrp.h:296
MSRPProtocol::Message::m_fromURL
PURL m_fromURL
Definition: msrp.h:103
OpalMSRPManager::opalManager
OpalManager & opalManager
Definition: msrp.h:261
OpalMSRPManager::Connection::m_handlerThread
PThread * m_handlerThread
Definition: msrp.h:195
OpalMSRPManager::Connection::m_running
bool m_running
Definition: msrp.h:194
OpalMSRPManager::m_connectionInfoMap
ConnectionInfoMapType m_connectionInfoMap
Definition: msrp.h:270
OpalMSRPMediaSession::SetRemoteURL
void SetRemoteURL(const PURL &url)
Definition: msrp.h:308
OpalMSRPManager::CloseConnection
bool CloseConnection(PSafePtr< OpalMSRPManager::Connection > &connection)
OpalMSRPMediaStream::RequiresPatchThread
virtual PBoolean RequiresPatchThread() const
Definition: msrp.h:366