source: trunk/sources/thelib/src/protocols/rtmp/inboundrtmpsdiscriminatorprotocol.cpp @ 410

Revision 410, 4.0 KB checked in by shiretu, 14 months ago (diff)

-- removed unused code from thelib

Line 
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#ifdef HAS_PROTOCOL_RTMP
21#include "protocols/rtmp/inboundrtmpsdiscriminatorprotocol.h"
22#include "protocols/http/inboundhttpprotocol.h"
23#include "protocols/rtmp/inboundhttp4rtmp.h"
24#include "protocols/rtmp/inboundrtmpprotocol.h"
25
26InboundRTMPSDiscriminatorProtocol::InboundRTMPSDiscriminatorProtocol()
27: BaseProtocol(PT_INBOUND_RTMPS_DISC) {
28
29}
30
31InboundRTMPSDiscriminatorProtocol::~InboundRTMPSDiscriminatorProtocol() {
32}
33
34bool InboundRTMPSDiscriminatorProtocol::Initialize(Variant &parameters) {
35        GetCustomParameters() = parameters;
36        return true;
37}
38
39bool InboundRTMPSDiscriminatorProtocol::AllowFarProtocol(uint64_t type) {
40        return type == PT_INBOUND_SSL;
41}
42
43bool InboundRTMPSDiscriminatorProtocol::AllowNearProtocol(uint64_t type) {
44        return false;
45}
46
47bool InboundRTMPSDiscriminatorProtocol::SignalInputData(int32_t recvAmount) {
48        NYIR;
49}
50
51bool InboundRTMPSDiscriminatorProtocol::SignalInputData(IOBuffer &buffer) {
52        //1. Do we have enough data?
53        if (GETAVAILABLEBYTESCOUNT(buffer) < 4)
54                return true;
55
56        //2. Get the first 4 bytes in a string
57        string method = string((char *) GETIBPOINTER(buffer), 4);
58
59        //3. Create the proper RTMP stack
60        if (method == HTTP_METHOD_POST) {
61#ifdef HAS_PROTOCOL_HTTP
62                return BindHTTP(buffer);
63#else
64                FATAL("No HTTP protocol support");
65                return false;
66#endif /* HAS_PROTOCOL_HTTP */
67        } else {
68                return BindSSL(buffer);
69        }
70}
71
72#ifdef HAS_PROTOCOL_HTTP
73
74bool InboundRTMPSDiscriminatorProtocol::BindHTTP(IOBuffer &buffer) {
75        //1. Create the HTTP protocol
76        BaseProtocol *pHTTP = new InboundHTTPProtocol();
77        if (!pHTTP->Initialize(GetCustomParameters())) {
78                FATAL("Unable to create HTTP protocol");
79                pHTTP->EnqueueForDelete();
80                return false;
81        }
82
83        //2. Create the HTTP4RTMP protocol
84        BaseProtocol *pHTTP4RTMP = new InboundHTTP4RTMP();
85        if (!pHTTP4RTMP->Initialize(GetCustomParameters())) {
86                FATAL("Unable to create HTTP4RTMP protocol");
87                pHTTP->EnqueueForDelete();
88                pHTTP4RTMP->EnqueueForDelete();
89                return false;
90        }
91
92        //3. Destroy the link
93        BaseProtocol *pFar = _pFarProtocol;
94        pFar->ResetNearProtocol();
95        ResetFarProtocol();
96
97        //4. Create the new links
98        pFar->SetNearProtocol(pHTTP);
99        pHTTP->SetFarProtocol(pFar);
100        pHTTP->SetNearProtocol(pHTTP4RTMP);
101        pHTTP4RTMP->SetFarProtocol(pHTTP);
102
103        //5. Set the application
104        pHTTP4RTMP->SetApplication(GetApplication());
105
106        //6. Enqueue for delete this protocol
107        EnqueueForDelete();
108
109        //7. Process the data
110        if (!pHTTP->SignalInputData(buffer)) {
111                FATAL("Unable to process data");
112                pHTTP4RTMP->EnqueueForDelete();
113        }
114
115        return true;
116}
117#endif /* HAS_PROTOCOL_HTTP */
118
119bool InboundRTMPSDiscriminatorProtocol::BindSSL(IOBuffer &buffer) {
120        //1. Create the RTMP protocol
121        BaseProtocol *pRTMP = new InboundRTMPProtocol();
122        if (!pRTMP->Initialize(GetCustomParameters())) {
123                FATAL("Unable to create RTMP protocol");
124                pRTMP->EnqueueForDelete();
125                return false;
126        }
127
128        //2. Destroy the link
129        BaseProtocol *pFar = _pFarProtocol;
130        pFar->ResetNearProtocol();
131        ResetFarProtocol();
132
133        //3. Create the new links
134        pFar->SetNearProtocol(pRTMP);
135        pRTMP->SetFarProtocol(pFar);
136
137        //4. Set the application
138        pRTMP->SetApplication(GetApplication());
139
140        //5. Enqueue for delete this protocol
141        EnqueueForDelete();
142
143        //6. Process the data
144        if (!pRTMP->SignalInputData(buffer)) {
145                FATAL("Unable to process data");
146                pRTMP->EnqueueForDelete();
147        }
148
149        return true;
150}
151
152#endif /* HAS_PROTOCOL_RTMP */
Note: See TracBrowser for help on using the repository browser.