Created
January 11, 2012 10:20
-
-
Save j0sh/1594040 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 406341615709d2fbd43dcc5b4ba2566cb4801930 Mon Sep 17 00:00:00 2001 | |
| From: Josh Allmann <joshua.allmann@gmail.com> | |
| Date: Wed, 11 Jan 2012 02:15:32 -0800 | |
| Subject: [PATCH 2/2] Check protocol direction in RTMP protocol handler. | |
| This is preferable over protocol type to allow subclassing | |
| protocols. | |
| --- | |
| .../include/protocols/rtmp/basertmpprotocol.h | 8 ++++++++ | |
| .../protocols/rtmp/basertmpappprotocolhandler.cpp | 7 ++++--- | |
| .../thelib/src/protocols/rtmp/basertmpprotocol.cpp | 6 ++++++ | |
| .../src/protocols/rtmp/inboundrtmpprotocol.cpp | 2 ++ | |
| .../src/protocols/rtmp/outboundrtmpprotocol.cpp | 1 + | |
| 5 files changed, 21 insertions(+), 3 deletions(-) | |
| diff --git a/sources/thelib/include/protocols/rtmp/basertmpprotocol.h b/sources/thelib/include/protocols/rtmp/basertmpprotocol.h | |
| index 25eab77..86fff2e 100644 | |
| --- a/sources/thelib/include/protocols/rtmp/basertmpprotocol.h | |
| +++ b/sources/thelib/include/protocols/rtmp/basertmpprotocol.h | |
| @@ -42,6 +42,12 @@ typedef enum _RTMPState { | |
| RTMP_STATE_DONE | |
| } RTMPState; | |
| +typedef enum RTMPDirection { | |
| + RTMP_DIRECTION_NONE, | |
| + RTMP_DIRECTION_INBOUND, | |
| + RTMP_DIRECTION_OUTBOUND | |
| +} RTMPDirection; | |
| + | |
| class BaseStream; | |
| class BaseOutStream; | |
| class BaseOutNetRTMPStream; | |
| @@ -78,6 +84,7 @@ protected: | |
| map<InFileRTMPStream *, InFileRTMPStream *> _inFileStreams; | |
| uint64_t _rxInvokes; | |
| uint64_t _txInvokes; | |
| + RTMPDirection _direction; | |
| public: | |
| BaseRTMPProtocol(uint64_t protocolType); | |
| virtual ~BaseRTMPProtocol(); | |
| @@ -119,6 +126,7 @@ public: | |
| Channel *ReserveChannel(); | |
| void ReleaseChannel(Channel *pChannel); | |
| virtual bool EnqueueForTimeEvent(uint32_t seconds); | |
| + RTMPDirection GetDirection(); | |
| protected: | |
| virtual bool PerformHandshake(IOBuffer &buffer) = 0; | |
| uint32_t GetDHOffset(uint8_t *pBuffer, uint8_t schemeNumber); | |
| diff --git a/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp b/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp | |
| index 1b0a6bf..87576d8 100644 | |
| --- a/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp | |
| +++ b/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp | |
| @@ -294,12 +294,13 @@ bool BaseRTMPAppProtocolHandler::InboundMessageAvailable(BaseRTMPProtocol *pFrom | |
| //1. Perform authentication | |
| Variant ¶meters = pFrom->GetCustomParameters(); | |
| +printf("%s", STR(parameters.ToString())); | |
| if (!parameters.HasKey("authState")) | |
| parameters["authState"].IsArray(false); | |
| Variant &authState = parameters["authState"]; | |
| - switch (pFrom->GetType()) { | |
| - case PT_INBOUND_RTMP: | |
| + switch (pFrom->GetDirection()) { | |
| + case RTMP_DIRECTION_INBOUND: | |
| { | |
| if (_authMethod != "") { | |
| if (!AuthenticateInbound(pFrom, request, authState)) { | |
| @@ -313,7 +314,7 @@ bool BaseRTMPAppProtocolHandler::InboundMessageAvailable(BaseRTMPProtocol *pFrom | |
| } | |
| break; | |
| } | |
| - case PT_OUTBOUND_RTMP: | |
| + case RTMP_DIRECTION_OUTBOUND: | |
| { | |
| authState["stage"] = "authenticated"; | |
| authState["canPublish"] = (bool)true; | |
| diff --git a/sources/thelib/src/protocols/rtmp/basertmpprotocol.cpp b/sources/thelib/src/protocols/rtmp/basertmpprotocol.cpp | |
| index 368d453..604b2df 100644 | |
| --- a/sources/thelib/src/protocols/rtmp/basertmpprotocol.cpp | |
| +++ b/sources/thelib/src/protocols/rtmp/basertmpprotocol.cpp | |
| @@ -84,6 +84,7 @@ BaseRTMPProtocol::BaseRTMPProtocol(uint64_t protocolType) | |
| _pSignaledRTMPOutNetStream = NULL; | |
| _rxInvokes = 0; | |
| _txInvokes = 0; | |
| + _direction = RTMP_DIRECTION_NONE; | |
| #ifdef ENFORCE_RTMP_OUTPUT_CHECKS | |
| _pMonitor = new MonitorRTMPProtocol(MAX_STREAMS_COUNT, MAX_CHANNELS_COUNT); | |
| @@ -545,6 +546,11 @@ bool BaseRTMPProtocol::EnqueueForTimeEvent(uint32_t seconds) { | |
| return false; | |
| } | |
| +RTMPDirection BaseRTMPProtocol::GetDirection() | |
| +{ | |
| + return _direction; | |
| +} | |
| + | |
| uint32_t BaseRTMPProtocol::GetDHOffset(uint8_t *pBuffer, uint8_t schemeNumber) { | |
| switch (schemeNumber) { | |
| case 0: | |
| diff --git a/sources/thelib/src/protocols/rtmp/inboundrtmpprotocol.cpp b/sources/thelib/src/protocols/rtmp/inboundrtmpprotocol.cpp | |
| index b2b8de6..11e2d54 100644 | |
| --- a/sources/thelib/src/protocols/rtmp/inboundrtmpprotocol.cpp | |
| +++ b/sources/thelib/src/protocols/rtmp/inboundrtmpprotocol.cpp | |
| @@ -29,6 +29,7 @@ InboundRTMPProtocol::InboundRTMPProtocol() | |
| _pOutputBuffer = NULL; | |
| _currentFPVersion = 0; | |
| _validationScheme = 0; | |
| + _direction = RTMP_DIRECTION_INBOUND; | |
| } | |
| InboundRTMPProtocol::InboundRTMPProtocol(uint64_t protocolType) | |
| @@ -38,6 +39,7 @@ InboundRTMPProtocol::InboundRTMPProtocol(uint64_t protocolType) | |
| _pOutputBuffer = NULL; | |
| _currentFPVersion = 0; | |
| _validationScheme = 0; | |
| + _direction = RTMP_DIRECTION_INBOUND; | |
| } | |
| InboundRTMPProtocol::~InboundRTMPProtocol() { | |
| diff --git a/sources/thelib/src/protocols/rtmp/outboundrtmpprotocol.cpp b/sources/thelib/src/protocols/rtmp/outboundrtmpprotocol.cpp | |
| index dd27090..208badc 100644 | |
| --- a/sources/thelib/src/protocols/rtmp/outboundrtmpprotocol.cpp | |
| +++ b/sources/thelib/src/protocols/rtmp/outboundrtmpprotocol.cpp | |
| @@ -38,6 +38,7 @@ OutboundRTMPProtocol::OutboundRTMPProtocol() | |
| _pKeyOut = NULL; | |
| _pDHWrapper = NULL; | |
| _usedScheme = 0; | |
| + _direction = RTMP_DIRECTION_OUTBOUND; | |
| } | |
| OutboundRTMPProtocol::~OutboundRTMPProtocol() { | |
| -- | |
| 1.7.5.4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 0fa06bc5aa77d742407f3e49caebb56ecd1bf8ff Mon Sep 17 00:00:00 2001 | |
| From: Josh Allmann <joshua.allmann@gmail.com> | |
| Date: Wed, 11 Jan 2012 01:00:30 -0800 | |
| Subject: [PATCH 1/2] Allow subclassing inbound RTMP. | |
| --- | |
| .../include/protocols/rtmp/inboundrtmpprotocol.h | 1 + | |
| .../src/protocols/rtmp/inboundrtmpprotocol.cpp | 9 +++++++++ | |
| 2 files changed, 10 insertions(+), 0 deletions(-) | |
| diff --git a/sources/thelib/include/protocols/rtmp/inboundrtmpprotocol.h b/sources/thelib/include/protocols/rtmp/inboundrtmpprotocol.h | |
| index bf71a56..f4fcd35 100644 | |
| --- a/sources/thelib/include/protocols/rtmp/inboundrtmpprotocol.h | |
| +++ b/sources/thelib/include/protocols/rtmp/inboundrtmpprotocol.h | |
| @@ -34,6 +34,7 @@ private: | |
| uint8_t _validationScheme; | |
| public: | |
| InboundRTMPProtocol(); | |
| + InboundRTMPProtocol(uint64_t protocolType); | |
| virtual ~InboundRTMPProtocol(); | |
| protected: | |
| virtual bool PerformHandshake(IOBuffer &buffer); | |
| diff --git a/sources/thelib/src/protocols/rtmp/inboundrtmpprotocol.cpp b/sources/thelib/src/protocols/rtmp/inboundrtmpprotocol.cpp | |
| index e97490b..b2b8de6 100644 | |
| --- a/sources/thelib/src/protocols/rtmp/inboundrtmpprotocol.cpp | |
| +++ b/sources/thelib/src/protocols/rtmp/inboundrtmpprotocol.cpp | |
| @@ -31,6 +31,15 @@ InboundRTMPProtocol::InboundRTMPProtocol() | |
| _validationScheme = 0; | |
| } | |
| +InboundRTMPProtocol::InboundRTMPProtocol(uint64_t protocolType) | |
| +: BaseRTMPProtocol(protocolType) { | |
| + _pKeyIn = NULL; | |
| + _pKeyOut = NULL; | |
| + _pOutputBuffer = NULL; | |
| + _currentFPVersion = 0; | |
| + _validationScheme = 0; | |
| +} | |
| + | |
| InboundRTMPProtocol::~InboundRTMPProtocol() { | |
| if (_pKeyIn != NULL) { | |
| delete _pKeyIn; | |
| -- | |
| 1.7.5.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment