mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
server: broadcast to authenticated only + use references in handler
This commit is contained in:
parent
5b0410a207
commit
c245c24752
@ -128,7 +128,7 @@ QSet<QString> WSRequestHandler::authNotRequired {
|
||||
"Authenticate"
|
||||
};
|
||||
|
||||
WSRequestHandler::WSRequestHandler(QVariantHash* connProperties) :
|
||||
WSRequestHandler::WSRequestHandler(QVariantHash& connProperties) :
|
||||
_messageId(0),
|
||||
_requestType(""),
|
||||
data(nullptr),
|
||||
@ -163,7 +163,7 @@ std::string WSRequestHandler::processIncomingMessage(std::string& textMessage) {
|
||||
|
||||
if (Config::Current()->AuthRequired
|
||||
&& (!authNotRequired.contains(_requestType))
|
||||
&& (_connProperties->value(PROP_AUTHENTICATED).toBool() == false))
|
||||
&& (_connProperties.value(PROP_AUTHENTICATED).toBool() == false))
|
||||
{
|
||||
SendErrorResponse("Not Authenticated");
|
||||
return _response;
|
||||
|
@ -33,7 +33,7 @@ class WSRequestHandler : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WSRequestHandler(QVariantHash* connProperties);
|
||||
explicit WSRequestHandler(QVariantHash& connProperties);
|
||||
~WSRequestHandler();
|
||||
std::string processIncomingMessage(std::string& textMessage);
|
||||
bool hasField(QString name);
|
||||
@ -42,7 +42,7 @@ class WSRequestHandler : public QObject {
|
||||
const char* _messageId;
|
||||
const char* _requestType;
|
||||
std::string _response;
|
||||
QVariantHash* _connProperties;
|
||||
QVariantHash& _connProperties;
|
||||
OBSDataAutoRelease data;
|
||||
|
||||
void SendOKResponse(obs_data_t* additionalFields = NULL);
|
||||
|
@ -85,7 +85,7 @@ void WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (req->_connProperties->value(PROP_AUTHENTICATED).toBool() == true) {
|
||||
if (req->_connProperties.value(PROP_AUTHENTICATED).toBool() == true) {
|
||||
req->SendErrorResponse("already authenticated");
|
||||
return;
|
||||
}
|
||||
@ -101,7 +101,7 @@ void WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) {
|
||||
return;
|
||||
}
|
||||
|
||||
req->_connProperties->insert(PROP_AUTHENTICATED, true);
|
||||
req->_connProperties.insert(PROP_AUTHENTICATED, true);
|
||||
req->SendOKResponse();
|
||||
}
|
||||
|
||||
|
@ -96,6 +96,12 @@ void WSServer::broadcast(QString message)
|
||||
{
|
||||
QMutexLocker locker(&_clMutex);
|
||||
for (connection_hdl hdl : _connections) {
|
||||
if (Config::Current()->AuthRequired) {
|
||||
bool authenticated = _connectionProperties[hdl].value(PROP_AUTHENTICATED).toBool();
|
||||
if (!authenticated) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
_server.send(hdl, message.toStdString(), websocketpp::frame::opcode::text);
|
||||
}
|
||||
}
|
||||
@ -118,16 +124,20 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message)
|
||||
return;
|
||||
}
|
||||
|
||||
QMutexLocker locker(&_clMutex);
|
||||
QVariantHash connProperties = _connectionProperties[hdl];
|
||||
locker.unlock();
|
||||
|
||||
std::string payload = message->get_payload();
|
||||
|
||||
WSRequestHandler handler(&connProperties);
|
||||
WSRequestHandler handler(connProperties);
|
||||
std::string response = handler.processIncomingMessage(payload);
|
||||
|
||||
_connectionProperties[hdl] = connProperties;
|
||||
|
||||
_server.send(hdl, response, websocketpp::frame::opcode::text);
|
||||
|
||||
locker.relock();
|
||||
_connectionProperties[hdl] = connProperties;
|
||||
locker.unlock();
|
||||
}
|
||||
|
||||
void WSServer::onClose(connection_hdl hdl)
|
||||
|
Loading…
x
Reference in New Issue
Block a user