| 1 | /* |
|---|
| 2 | * Copyright (c) 2010, |
|---|
| 3 | * Gavriloaie Eugen-Andrei (shiretu@gmail.com) |
|---|
| 4 | * |
|---|
| 5 | * This file is part of crtmpserver. |
|---|
| 6 | * crtmpserver is free software: you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation, either version 3 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * crtmpserver is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with crtmpserver. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | #ifdef HAS_PROTOCOL_RTMP |
|---|
| 22 | #include "protocols/rtmp/rtmpeprotocol.h" |
|---|
| 23 | |
|---|
| 24 | RTMPEProtocol::RTMPEProtocol(RC4_KEY *pKeyIn, RC4_KEY *pKeyOut, uint32_t skipBytes) |
|---|
| 25 | : BaseProtocol(PT_RTMPE) { |
|---|
| 26 | _pKeyIn = pKeyIn; |
|---|
| 27 | _pKeyOut = pKeyOut; |
|---|
| 28 | _skipBytes = skipBytes; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | RTMPEProtocol::~RTMPEProtocol() { |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | bool RTMPEProtocol::AllowFarProtocol(uint64_t type) { |
|---|
| 35 | return (type == PT_INBOUND_HTTP_FOR_RTMP) |
|---|
| 36 | || (type == PT_TCP); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | bool RTMPEProtocol::AllowNearProtocol(uint64_t type) { |
|---|
| 40 | return (type == PT_INBOUND_RTMP) |
|---|
| 41 | || (type == PT_OUTBOUND_RTMP); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | IOBuffer * RTMPEProtocol::GetInputBuffer() { |
|---|
| 45 | return &_inputBuffer; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | IOBuffer * RTMPEProtocol::GetOutputBuffer() { |
|---|
| 49 | if (GETAVAILABLEBYTESCOUNT(_outputBuffer) > 0) |
|---|
| 50 | return &_outputBuffer; |
|---|
| 51 | return NULL; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | bool RTMPEProtocol::SignalInputData(int32_t recvAmount) { |
|---|
| 55 | ASSERT("OPERATION NOT SUPPORTED"); |
|---|
| 56 | return false; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | bool RTMPEProtocol::SignalInputData(IOBuffer &buffer) { |
|---|
| 60 | RC4(_pKeyIn, GETAVAILABLEBYTESCOUNT(buffer), |
|---|
| 61 | GETIBPOINTER(buffer), |
|---|
| 62 | GETIBPOINTER(buffer)); |
|---|
| 63 | |
|---|
| 64 | _inputBuffer.ReadFromBuffer(GETIBPOINTER(buffer), |
|---|
| 65 | GETAVAILABLEBYTESCOUNT(buffer)); |
|---|
| 66 | buffer.IgnoreAll(); |
|---|
| 67 | |
|---|
| 68 | if (_pNearProtocol != NULL) |
|---|
| 69 | return _pNearProtocol->SignalInputData(_inputBuffer); |
|---|
| 70 | return true; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | bool RTMPEProtocol::EnqueueForOutbound() { |
|---|
| 74 | |
|---|
| 75 | IOBuffer *pOutputBuffer = _pNearProtocol->GetOutputBuffer(); |
|---|
| 76 | |
|---|
| 77 | if (pOutputBuffer == NULL) |
|---|
| 78 | return true; |
|---|
| 79 | |
|---|
| 80 | RC4(_pKeyOut, GETAVAILABLEBYTESCOUNT(*pOutputBuffer) - _skipBytes, |
|---|
| 81 | GETIBPOINTER(*pOutputBuffer) + _skipBytes, |
|---|
| 82 | GETIBPOINTER(*pOutputBuffer) + _skipBytes); |
|---|
| 83 | _skipBytes = 0; |
|---|
| 84 | |
|---|
| 85 | _outputBuffer.ReadFromInputBuffer(pOutputBuffer, 0, GETAVAILABLEBYTESCOUNT(*pOutputBuffer)); |
|---|
| 86 | pOutputBuffer->Ignore(GETAVAILABLEBYTESCOUNT(*pOutputBuffer)); |
|---|
| 87 | |
|---|
| 88 | if (_pFarProtocol != NULL) |
|---|
| 89 | return _pFarProtocol->EnqueueForOutbound(); |
|---|
| 90 | |
|---|
| 91 | return true; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | #endif /* HAS_PROTOCOL_RTMP */ |
|---|
| 95 | |
|---|