A bit of cleaning

This commit is contained in:
Palakis 2017-02-24 20:09:42 +01:00
parent 5ca55fc13e
commit d6091c83e2
12 changed files with 27 additions and 26 deletions

View File

@ -20,6 +20,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include <mbedtls/sha256.h> #include <mbedtls/sha256.h>
#include <obs-frontend-api.h> #include <obs-frontend-api.h>
#include <util/config-file.h> #include <util/config-file.h>
#include "Config.h" #include "Config.h"
#define SECTION_NAME "WebsocketAPI" #define SECTION_NAME "WebsocketAPI"

View File

@ -19,7 +19,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
#include <obs-module.h>
#include <mbedtls/entropy.h> #include <mbedtls/entropy.h>
#include <mbedtls/ctr_drbg.h> #include <mbedtls/ctr_drbg.h>

View File

@ -17,6 +17,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
*/ */
#include "Utils.h" #include "Utils.h"
#include <obs-frontend-api.h>
obs_data_array_t* Utils::GetSceneItems(obs_source_t *source) { obs_data_array_t* Utils::GetSceneItems(obs_source_t *source) {
obs_data_array_t *items = obs_data_array_create(); obs_data_array_t *items = obs_data_array_create();

View File

@ -21,7 +21,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include <stdio.h> #include <stdio.h>
#include <obs-module.h> #include <obs-module.h>
#include <obs-frontend-api.h>
class Utils class Utils
{ {

View File

@ -17,6 +17,9 @@ You should have received a copy of the GNU General Public License along
with this program. If not, see <https://www.gnu.org/licenses/> with this program. If not, see <https://www.gnu.org/licenses/>
*/ */
#include <util/platform.h>
#include <QTimer>
#include "WSEvents.h" #include "WSEvents.h"
WSEvents::WSEvents(WSServer *srv) { WSEvents::WSEvents(WSServer *srv) {

View File

@ -20,10 +20,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#ifndef WSEVENTS_H #ifndef WSEVENTS_H
#define WSEVENTS_H #define WSEVENTS_H
#include <QtWebSockets/QWebSocket>
#include <QTimer>
#include <obs-frontend-api.h> #include <obs-frontend-api.h>
#include <util/platform.h>
#include "WSServer.h" #include "WSServer.h"
class WSEvents : public QObject class WSEvents : public QObject

View File

@ -73,7 +73,7 @@ void WSRequestHandler::processIncomingMessage(QString textMessage)
msg = "<null pointer>"; msg = "<null pointer>";
} }
blog(LOG_ERROR, "[obs-websockets] invalid JSON payload received for '%s'", msg); blog(LOG_ERROR, "invalid JSON payload received for '%s'", msg);
SendErrorResponse("invalid JSON payload"); SendErrorResponse("invalid JSON payload");
return; return;
} }
@ -181,18 +181,13 @@ void WSRequestHandler::HandleAuthenticate(WSRequestHandler *owner)
return; return;
} }
blog(LOG_INFO, "[obs-websocket] preauth : client_authenticated : %d", owner->_client->property(PROP_AUTHENTICATED).toBool());
if ((owner->_client->property(PROP_AUTHENTICATED).toBool() == false) && Config::Current()->CheckAuth(auth)) if ((owner->_client->property(PROP_AUTHENTICATED).toBool() == false) && Config::Current()->CheckAuth(auth))
{ {
blog(LOG_INFO, "[obs-websocket] auth successful");
owner->_client->setProperty(PROP_AUTHENTICATED, true); owner->_client->setProperty(PROP_AUTHENTICATED, true);
owner->SendOKResponse(); owner->SendOKResponse();
} }
else else
{ {
blog(LOG_INFO, "[obs-websocket] auth refused");
owner->SendErrorResponse("Authentication Failed."); owner->SendErrorResponse("Authentication Failed.");
} }
} }

View File

@ -20,9 +20,9 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#ifndef WSREQUESTHANDLER_H #ifndef WSREQUESTHANDLER_H
#define WSREQUESTHANDLER_H #define WSREQUESTHANDLER_H
#include <obs-frontend-api.h>
#include <QtWebSockets/QWebSocket> #include <QtWebSockets/QWebSocket>
#include <QtWebSockets/QWebSocketServer> #include <QtWebSockets/QWebSocketServer>
#include <obs-frontend-api.h>
class WSRequestHandler : public QObject class WSRequestHandler : public QObject
{ {

View File

@ -16,20 +16,18 @@ You should have received a copy of the GNU General Public License along
with this program. If not, see <https://www.gnu.org/licenses/> with this program. If not, see <https://www.gnu.org/licenses/>
*/ */
#include "WSServer.h"
#include "WSRequestHandler.h"
#include "Config.h"
#include <QtWebSockets/QWebSocketServer>
#include <QtWebSockets/QWebSocket> #include <QtWebSockets/QWebSocket>
#include <QtCore/QDebug>
#include <QtCore/QThread> #include <QtCore/QThread>
#include <QtCore/QByteArray>
#include <obs-frontend-api.h> #include <obs-frontend-api.h>
#include "WSServer.h"
#include "obs-websocket.h" #include "obs-websocket.h"
#include "Config.h"
QT_USE_NAMESPACE QT_USE_NAMESPACE
WSServer* WSServer::Instance = new WSServer(); WSServer* WSServer::Instance = nullptr;
WSServer::WSServer(QObject *parent) : WSServer::WSServer(QObject *parent) :
QObject(parent), QObject(parent),
@ -116,7 +114,7 @@ void WSServer::onNewConnection()
_clMutex.unlock(); _clMutex.unlock();
QByteArray client_ip = pSocket->peerAddress().toString().toUtf8(); QByteArray client_ip = pSocket->peerAddress().toString().toUtf8();
blog(LOG_INFO, "[obs-websockets] new client connection from %s:%d", client_ip.constData(), pSocket->peerPort()); blog(LOG_INFO, "new client connection from %s:%d", client_ip.constData(), pSocket->peerPort());
} }
} }
@ -146,6 +144,6 @@ void WSServer::socketDisconnected()
pSocket->deleteLater(); pSocket->deleteLater();
QByteArray client_ip = pSocket->peerAddress().toString().toUtf8(); QByteArray client_ip = pSocket->peerAddress().toString().toUtf8();
blog(LOG_INFO, "[obs-websockets] client %s:%d disconnected", client_ip.constData(), pSocket->peerPort()); blog(LOG_INFO, "client %s:%d disconnected", client_ip.constData(), pSocket->peerPort());
} }
} }

View File

@ -22,13 +22,12 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QList> #include <QtCore/QList>
#include <QtCore/QMutex> #include <QtCore/QMutex>
#include <QtCore/QByteArray>
#include <QtCore/QThread>
#include "WSRequestHandler.h"
QT_FORWARD_DECLARE_CLASS(QWebSocketServer) QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
QT_FORWARD_DECLARE_CLASS(QWebSocket) QT_FORWARD_DECLARE_CLASS(QWebSocket)
#include "WSRequestHandler.h"
class WSServer : public QObject class WSServer : public QObject
{ {
Q_OBJECT Q_OBJECT

View File

@ -19,6 +19,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include <obs-module.h> #include <obs-module.h>
#include <obs-frontend-api.h> #include <obs-frontend-api.h>
#include <QAction> #include <QAction>
#include <QMainWindow>
#include "obs-websocket.h" #include "obs-websocket.h"
#include "WSServer.h" #include "WSServer.h"
@ -34,10 +35,14 @@ SettingsDialog *settings_dialog;
bool obs_module_load(void) bool obs_module_load(void)
{ {
blog(LOG_INFO, "you can haz websockets (version %s)", OBS_WEBSOCKET_VERSION);
// Core setup // Core setup
Config* config = Config::Current(); Config* config = Config::Current();
config->Load(); config->Load();
WSServer::Instance = new WSServer();
if (config->ServerEnabled) if (config->ServerEnabled)
WSServer::Instance->Start(config->ServerPort); WSServer::Instance->Start(config->ServerPort);
@ -47,7 +52,8 @@ bool obs_module_load(void)
QAction *menu_action = (QAction*)obs_frontend_add_tools_menu_qaction(obs_module_text("OBSWebsocket.Menu.SettingsItem")); QAction *menu_action = (QAction*)obs_frontend_add_tools_menu_qaction(obs_module_text("OBSWebsocket.Menu.SettingsItem"));
obs_frontend_push_ui_translation(obs_module_get_string); obs_frontend_push_ui_translation(obs_module_get_string);
settings_dialog = new SettingsDialog(); QMainWindow* main_window = (QMainWindow*)obs_frontend_get_main_window();
settings_dialog = new SettingsDialog(main_window);
obs_frontend_pop_ui_translation(); obs_frontend_pop_ui_translation();
auto menu_cb = [] { auto menu_cb = [] {
@ -56,13 +62,13 @@ bool obs_module_load(void)
menu_action->connect(menu_action, &QAction::triggered, menu_cb); menu_action->connect(menu_action, &QAction::triggered, menu_cb);
// Loading finished // Loading finished
blog(LOG_INFO, "[obs-websockets] you can haz websockets (version %s)", OBS_WEBSOCKET_VERSION); blog(LOG_INFO, "module loaded!");
return true; return true;
} }
void obs_module_unload() void obs_module_unload()
{ {
blog(LOG_INFO, "[obs-websockets] goodbye !"); blog(LOG_INFO, "goodbye!");
} }

View File

@ -22,4 +22,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#define PROP_AUTHENTICATED "wsclient_authenticated" #define PROP_AUTHENTICATED "wsclient_authenticated"
#define OBS_WEBSOCKET_VERSION "4.0.0" #define OBS_WEBSOCKET_VERSION "4.0.0"
#define blog(level, msg, ...) blog(level, "[obs-websocket] " msg, ##__VA_ARGS__)
#endif // OBSWEBSOCKET_H #endif // OBSWEBSOCKET_H