Repository navigation
Expand file tree
/
Copy pathBasicServerSession.cpp
More file actions
64 lines (52 loc) · 1.54 KB
/
Copy pathBasicServerSession.cpp
File metadata and controls
64 lines (52 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "BasicServerSession.h"
#include <glib.h>
#include "RtspParser/RtspParser.h"
#include "RtspParser/RtspSerialize.h"
#include "Helpers/TurnRestApi.h"
#include "Log.h"
BasicServerSession::BasicServerSession(
const Config* config,
SharedData* sharedData,
const std::optional<std::string>& authCookie,
const CreatePeer& createPeer,
const rtsp::Session::SendRequest& sendRequest,
const rtsp::Session::SendResponse& sendResponse) noexcept :
StreamSession(
config->webRTCConfig,
createPeer,
sendRequest,
sendResponse),
_config(config),
_sharedData(sharedData),
_authCookie(authCookie)
{
}
BasicServerSession::~BasicServerSession()
{
}
bool BasicServerSession::hasValidCookie() const noexcept
{
if(!_authCookie.has_value() || _authCookie->empty())
return false;
auto it = _sharedData->authTokens.find(_authCookie.value());
if(it == _sharedData->authTokens.end())
return false;
const AuthTokenData& tokenData = it->second;
if(tokenData.expiresAt < std::chrono::steady_clock::now())
return false;
return true;
}
bool BasicServerSession::authorize(const std::unique_ptr<rtsp::Request>& requestPtr) noexcept
{
switch(requestPtr->method) {
case rtsp::Method::OPTIONS:
case rtsp::Method::DESCRIBE:
case rtsp::Method::SETUP:
case rtsp::Method::PLAY:
case rtsp::Method::TEARDOWN:
case rtsp::Method::GET_PARAMETER:
return (_config->authRequired) ? hasValidCookie() : true;
default:
return false;
}
}