mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
server: connection properties reference
This commit is contained in:
parent
0cf17cf3db
commit
56fc6ae47c
@ -132,7 +132,7 @@ QSet<QString> WSRequestHandler::authNotRequired {
|
|||||||
"Authenticate"
|
"Authenticate"
|
||||||
};
|
};
|
||||||
|
|
||||||
WSRequestHandler::WSRequestHandler(QSharedPointer<QVariantHash> connProperties) :
|
WSRequestHandler::WSRequestHandler(QVariantHash& connProperties) :
|
||||||
_messageId(0),
|
_messageId(0),
|
||||||
_requestType(""),
|
_requestType(""),
|
||||||
data(nullptr),
|
data(nullptr),
|
||||||
@ -174,7 +174,7 @@ HandlerResponse WSRequestHandler::processRequest(std::string& textMessage){
|
|||||||
|
|
||||||
if (Config::Current()->AuthRequired
|
if (Config::Current()->AuthRequired
|
||||||
&& (!authNotRequired.contains(_requestType))
|
&& (!authNotRequired.contains(_requestType))
|
||||||
&& (_connProperties->value(PROP_AUTHENTICATED).toBool() == false))
|
&& (_connProperties.value(PROP_AUTHENTICATED).toBool() == false))
|
||||||
{
|
{
|
||||||
return SendErrorResponse("Not Authenticated");
|
return SendErrorResponse("Not Authenticated");
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ class WSRequestHandler : public QObject {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WSRequestHandler(QSharedPointer<QVariantHash> connProperties);
|
explicit WSRequestHandler(QVariantHash& connProperties);
|
||||||
~WSRequestHandler();
|
~WSRequestHandler();
|
||||||
std::string processIncomingMessage(std::string& textMessage);
|
std::string processIncomingMessage(std::string& textMessage);
|
||||||
bool hasField(QString name);
|
bool hasField(QString name);
|
||||||
@ -44,7 +44,7 @@ class WSRequestHandler : public QObject {
|
|||||||
private:
|
private:
|
||||||
const char* _messageId;
|
const char* _messageId;
|
||||||
const char* _requestType;
|
const char* _requestType;
|
||||||
QSharedPointer<QVariantHash> _connProperties;
|
QVariantHash& _connProperties;
|
||||||
OBSDataAutoRelease data;
|
OBSDataAutoRelease data;
|
||||||
|
|
||||||
HandlerResponse processRequest(std::string& textMessage);
|
HandlerResponse processRequest(std::string& textMessage);
|
||||||
|
@ -82,7 +82,7 @@ HandlerResponse WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) {
|
|||||||
return req->SendErrorResponse("missing request parameters");
|
return req->SendErrorResponse("missing request parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req->_connProperties->value(PROP_AUTHENTICATED).toBool() == true) {
|
if (req->_connProperties.value(PROP_AUTHENTICATED).toBool() == true) {
|
||||||
return req->SendErrorResponse("already authenticated");
|
return req->SendErrorResponse("already authenticated");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ HandlerResponse WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) {
|
|||||||
return req->SendErrorResponse("Authentication Failed.");
|
return req->SendErrorResponse("Authentication Failed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
req->_connProperties->insert(PROP_AUTHENTICATED, true);
|
req->_connProperties.insert(PROP_AUTHENTICATED, true);
|
||||||
return req->SendOKResponse();
|
return req->SendOKResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ void WSServer::broadcast(std::string message)
|
|||||||
QMutexLocker locker(&_clMutex);
|
QMutexLocker locker(&_clMutex);
|
||||||
for (connection_hdl hdl : _connections) {
|
for (connection_hdl hdl : _connections) {
|
||||||
if (Config::Current()->AuthRequired) {
|
if (Config::Current()->AuthRequired) {
|
||||||
bool authenticated = _connectionProperties[hdl]->value(PROP_AUTHENTICATED).toBool();
|
bool authenticated = _connectionProperties[hdl].value(PROP_AUTHENTICATED).toBool();
|
||||||
if (!authenticated) {
|
if (!authenticated) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ void WSServer::onOpen(connection_hdl hdl)
|
|||||||
{
|
{
|
||||||
QMutexLocker locker(&_clMutex);
|
QMutexLocker locker(&_clMutex);
|
||||||
_connections.insert(hdl);
|
_connections.insert(hdl);
|
||||||
_connectionProperties[hdl] = QSharedPointer<QVariantHash>(new QVariantHash());
|
_connectionProperties[hdl] = QVariantHash();
|
||||||
locker.unlock();
|
locker.unlock();
|
||||||
|
|
||||||
QString clientIp = getRemoteEndpoint(hdl);
|
QString clientIp = getRemoteEndpoint(hdl);
|
||||||
@ -174,13 +174,16 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message)
|
|||||||
std::string payload = message->get_payload();
|
std::string payload = message->get_payload();
|
||||||
|
|
||||||
QMutexLocker locker(&_clMutex);
|
QMutexLocker locker(&_clMutex);
|
||||||
auto connProperties = _connectionProperties[hdl];
|
QVariantHash& connProperties = _connectionProperties[hdl];
|
||||||
locker.unlock();
|
locker.unlock();
|
||||||
|
|
||||||
WSRequestHandler handler(connProperties);
|
WSRequestHandler handler(connProperties);
|
||||||
std::string response = handler.processIncomingMessage(payload);
|
std::string response = handler.processIncomingMessage(payload);
|
||||||
|
|
||||||
_server.send(hdl, response, websocketpp::frame::opcode::text);
|
_server.send(hdl, response, websocketpp::frame::opcode::text);
|
||||||
|
|
||||||
|
boost::atomic<QVariantHash> atomicTest;
|
||||||
|
atomicTest.load().insert("jambon", true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,14 +18,14 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QMutex>
|
#include <QtCore/QMutex>
|
||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
#include <QtCore/QVariantHash>
|
#include <QtCore/QVariantHash>
|
||||||
#include <QtCore/QThreadPool>
|
#include <QtCore/QThreadPool>
|
||||||
|
#include <boost/atomic.hpp>
|
||||||
#include <map>
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
#include <websocketpp/config/asio_no_tls.hpp>
|
#include <websocketpp/config/asio_no_tls.hpp>
|
||||||
#include <websocketpp/server.hpp>
|
#include <websocketpp/server.hpp>
|
||||||
@ -73,7 +73,7 @@ private:
|
|||||||
server _server;
|
server _server;
|
||||||
quint16 _serverPort;
|
quint16 _serverPort;
|
||||||
std::set<connection_hdl, std::owner_less<connection_hdl>> _connections;
|
std::set<connection_hdl, std::owner_less<connection_hdl>> _connections;
|
||||||
std::map<connection_hdl, QSharedPointer<QVariantHash>, std::owner_less<connection_hdl>> _connectionProperties;
|
std::map<connection_hdl, QVariantHash, std::owner_less<connection_hdl>> _connectionProperties;
|
||||||
QMutex _clMutex;
|
QMutex _clMutex;
|
||||||
QThreadPool _threadPool;
|
QThreadPool _threadPool;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user