diff --git a/Config.cpp b/Config.cpp index 9a630c2a..05ef459c 100644 --- a/Config.cpp +++ b/Config.cpp @@ -48,12 +48,17 @@ Config::Config() config_t* obs_config = obs_frontend_get_global_config(); if (obs_config) { - config_set_default_bool(obs_config, SECTION_NAME, PARAM_ENABLE, ServerEnabled); - config_set_default_uint(obs_config, SECTION_NAME, PARAM_PORT, ServerPort); + config_set_default_bool(obs_config, + SECTION_NAME, PARAM_ENABLE, ServerEnabled); + config_set_default_uint(obs_config, + SECTION_NAME, PARAM_PORT, ServerPort); - config_set_default_bool(obs_config, SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired); - config_set_default_string(obs_config, SECTION_NAME, PARAM_SECRET, Secret); - config_set_default_string(obs_config, SECTION_NAME, PARAM_SALT, Salt); + config_set_default_bool(obs_config, + SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired); + config_set_default_string(obs_config, + SECTION_NAME, PARAM_SECRET, Secret); + config_set_default_string(obs_config, + SECTION_NAME, PARAM_SALT, Salt); } mbedtls_entropy_init(&entropy); @@ -105,7 +110,9 @@ const char* Config::GenerateSalt() // Convert the 32 random chars to a base64 string char* salt = (char*)bzalloc(64); size_t salt_bytes; - mbedtls_base64_encode((unsigned char*)salt, 64, &salt_bytes, random_chars, 32); + mbedtls_base64_encode( + (unsigned char*)salt, 64, &salt_bytes, + random_chars, 32); bfree(random_chars); return salt; @@ -120,12 +127,16 @@ const char* Config::GenerateSecret(const char *password, const char *salt) // Generate a SHA256 hash of the password unsigned char* challengeHash = (unsigned char*)bzalloc(32); - mbedtls_sha256((unsigned char*)passAndSalt.c_str(), passAndSalt.length(), challengeHash, 0); + mbedtls_sha256( + (unsigned char*)passAndSalt.c_str(), passAndSalt.length(), + challengeHash, 0); // Encode SHA256 hash to Base64 char* challenge = (char*)bzalloc(64); size_t challenge_bytes = 0; - mbedtls_base64_encode((unsigned char*)challenge, 64, &challenge_bytes, challengeHash, 32); + mbedtls_base64_encode( + (unsigned char*)challenge, 64, &challenge_bytes, + challengeHash, 32); bfree(challengeHash); return challenge; @@ -149,12 +160,17 @@ bool Config::CheckAuth(const char *response) // Generate a SHA256 hash of challengeAndResponse unsigned char* hash = (unsigned char*)bzalloc(32); - mbedtls_sha256((unsigned char*)challengeAndResponse.c_str(), challengeAndResponse.length(), hash, 0); + mbedtls_sha256( + (unsigned char*)challengeAndResponse.c_str(), + challengeAndResponse.length(), + hash, 0); // Encode the SHA256 hash to Base64 char* expected_response = (char*)bzalloc(64); size_t base64_size = 0; - mbedtls_base64_encode((unsigned char*)expected_response, 64, &base64_size, hash, 32); + mbedtls_base64_encode( + (unsigned char*)expected_response, 64, &base64_size, + hash, 32); bool authSuccess = false; if (strcmp(expected_response, response) == 0) { diff --git a/Utils.cpp b/Utils.cpp index c477d6ac..cc773f9b 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -85,9 +85,12 @@ obs_data_t* Utils::GetSceneItemData(obs_sceneitem_t *item) { float item_height = float(obs_source_get_height(item_source)); obs_data_t *data = obs_data_create(); - obs_data_set_string(data, "name", obs_source_get_name(obs_sceneitem_get_source(item))); - obs_data_set_string(data, "type", obs_source_get_id(obs_sceneitem_get_source(item))); - obs_data_set_double(data, "volume", obs_source_get_volume(obs_sceneitem_get_source(item))); + obs_data_set_string(data, "name", + obs_source_get_name(obs_sceneitem_get_source(item))); + obs_data_set_string(data, "type", + obs_source_get_id(obs_sceneitem_get_source(item))); + obs_data_set_double(data, "volume", + obs_source_get_volume(obs_sceneitem_get_source(item))); obs_data_set_double(data, "x", pos.x); obs_data_set_double(data, "y", pos.y); obs_data_set_int(data, "source_cx", (int)item_width); @@ -117,7 +120,9 @@ obs_sceneitem_t* Utils::GetSceneItemFromName(obs_source_t* source, const char* n obs_scene_enum_items(scene, [](obs_scene_t *scene, obs_sceneitem_t *currentItem, void *param) { current_search *search = static_cast(param); - const char* currentItemName = obs_source_get_name(obs_sceneitem_get_source(currentItem)); + const char* currentItemName = + obs_source_get_name(obs_sceneitem_get_source(currentItem)); + if (strcmp(currentItemName, search->query) == 0) { search->result = currentItem; obs_sceneitem_addref(search->result); @@ -339,7 +344,8 @@ bool Utils::SetPreviewScene(const char* name) if (IsPreviewModeActive()) { QListWidget* sceneList = GetSceneListControl(); - QList matchingItems = sceneList->findItems(name, Qt::MatchExactly); + QList matchingItems = + sceneList->findItems(name, Qt::MatchExactly); if (matchingItems.count() > 0) { diff --git a/WSEvents.cpp b/WSEvents.cpp index d78ee17f..3f3fa3e3 100644 --- a/WSEvents.cpp +++ b/WSEvents.cpp @@ -50,7 +50,8 @@ const char* ns_to_timestamp(uint64_t ns) uint64_t ms_part = ms % 1000; char* ts = (char*)bmalloc(64); - sprintf(ts, "%02d:%02d:%02d.%03d", hours_part, minutes_part, secs_part, ms_part); + sprintf(ts, "%02d:%02d:%02d.%03d", + hours_part, minutes_part, secs_part, ms_part); return ts; } @@ -63,14 +64,17 @@ WSEvents::WSEvents(WSServer *srv) obs_frontend_add_event_callback(WSEvents::FrontendEventHandler, this); QSpinBox* duration_control = Utils::GetTransitionDurationControl(); - connect(duration_control, SIGNAL(valueChanged(int)), this, SLOT(TransitionDurationChanged(int))); + connect(duration_control, SIGNAL(valueChanged(int)), + this, SLOT(TransitionDurationChanged(int))); QTimer *statusTimer = new QTimer(); - connect(statusTimer, SIGNAL(timeout()), this, SLOT(StreamStatus())); + connect(statusTimer, SIGNAL(timeout()), + this, SLOT(StreamStatus())); statusTimer->start(2000); // equal to frontend's constant BITRATE_UPDATE_SECONDS QListWidget* sceneList = Utils::GetSceneListControl(); - connect(sceneList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(SelectedSceneChanged(QListWidgetItem*, QListWidgetItem*))); + connect(sceneList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), + this, SLOT(SelectedSceneChanged(QListWidgetItem*, QListWidgetItem*))); QPushButton* modeSwitch = Utils::GetPreviewModeButtonControl(); connect(modeSwitch, SIGNAL(clicked(bool)), this, SLOT(ModeSwitchClicked(bool))); @@ -219,13 +223,15 @@ void WSEvents::connectTransitionSignals(obs_source_t* transition) { if (transition_handler) { - signal_handler_disconnect(transition_handler, "transition_start", OnTransitionBegin, this); + signal_handler_disconnect(transition_handler, + "transition_start", OnTransitionBegin, this); } if (!transition_is_cut(transition)) { transition_handler = obs_source_get_signal_handler(transition); - signal_handler_connect(transition_handler, "transition_start", OnTransitionBegin, this); } + signal_handler_connect(transition_handler, + "transition_start", OnTransitionBegin, this); } else { transition_handler = nullptr; @@ -236,18 +242,26 @@ void WSEvents::connectSceneSignals(obs_source_t* scene) { if (scene_handler) { - signal_handler_disconnect(scene_handler, "reorder", OnSceneReordered, this); - signal_handler_disconnect(scene_handler, "item_add", OnSceneItemAdd, this); - signal_handler_disconnect(scene_handler, "item_remove", OnSceneItemDelete, this); - signal_handler_disconnect(scene_handler, "item_visible", OnSceneItemVisibilityChanged, this); + signal_handler_disconnect(scene_handler, + "reorder", OnSceneReordered, this); + signal_handler_disconnect(scene_handler, + "item_add", OnSceneItemAdd, this); + signal_handler_disconnect(scene_handler, + "item_remove", OnSceneItemDelete, this); + signal_handler_disconnect(scene_handler, + "item_visible", OnSceneItemVisibilityChanged, this); } // TODO : connect to all scenes, not just the current one. scene_handler = obs_source_get_signal_handler(scene); - signal_handler_connect(scene_handler, "reorder", OnSceneReordered, this); - signal_handler_connect(scene_handler, "item_add", OnSceneItemAdd, this); - signal_handler_connect(scene_handler, "item_remove", OnSceneItemDelete, this); - signal_handler_connect(scene_handler, "item_visible", OnSceneItemVisibilityChanged, this); + signal_handler_connect(scene_handler, + "reorder", OnSceneReordered, this); + signal_handler_connect(scene_handler, + "item_add", OnSceneItemAdd, this); + signal_handler_connect(scene_handler, + "item_remove", OnSceneItemDelete, this); + signal_handler_connect(scene_handler, + "item_visible", OnSceneItemVisibilityChanged, this); } uint64_t WSEvents::GetStreamingTime() @@ -333,7 +347,8 @@ void WSEvents::OnTransitionChange() connectTransitionSignals(current_transition); obs_data_t *data = obs_data_create(); - obs_data_set_string(data, "transition-name", obs_source_get_name(current_transition)); + obs_data_set_string(data, "transition-name", + obs_source_get_name(current_transition)); broadcastUpdate("SwitchTransition", data); @@ -450,14 +465,16 @@ void WSEvents::StreamStatus() } uint64_t bytes_between = bytes_sent - _lastBytesSent; - double time_passed = double(bytes_sent_time - _lastBytesSentTime) / 1000000000.0; + double time_passed = + double(bytes_sent_time - _lastBytesSentTime) / 1000000000.0; uint64_t bytes_per_sec = bytes_between / time_passed; _lastBytesSent = bytes_sent; _lastBytesSentTime = bytes_sent_time; - uint64_t totalStreamTime = (os_gettime_ns() - _stream_starttime) / 1000000000; + uint64_t totalStreamTime = + (os_gettime_ns() - _stream_starttime) / 1000000000; int total_frames = obs_output_get_total_frames(stream_output); int dropped_frames = obs_output_get_frames_dropped(stream_output); @@ -510,7 +527,8 @@ void WSEvents::OnSceneReordered(void *param, calldata_t *data) calldata_get_ptr(data, "scene", &scene); obs_data_t *fields = obs_data_create(); - obs_data_set_string(fields, "scene-name", obs_source_get_name(obs_scene_get_source(scene))); + obs_data_set_string(fields, "scene-name", + obs_source_get_name(obs_scene_get_source(scene))); instance->broadcastUpdate("SourceOrderChanged", fields); @@ -527,8 +545,10 @@ void WSEvents::OnSceneItemAdd(void *param, calldata_t *data) obs_sceneitem_t* scene_item = nullptr; calldata_get_ptr(data, "item", &scene_item); - const char* scene_name = obs_source_get_name(obs_scene_get_source(scene)); - const char* sceneitem_name = obs_source_get_name(obs_sceneitem_get_source(scene_item)); + const char* scene_name = + obs_source_get_name(obs_scene_get_source(scene)); + const char* sceneitem_name = + obs_source_get_name(obs_sceneitem_get_source(scene_item)); obs_data_t* fields = obs_data_create(); obs_data_set_string(fields, "scene-name", scene_name); @@ -549,8 +569,10 @@ void WSEvents::OnSceneItemDelete(void *param, calldata_t *data) obs_sceneitem_t* scene_item = nullptr; calldata_get_ptr(data, "item", &scene_item); - const char* scene_name = obs_source_get_name(obs_scene_get_source(scene)); - const char* sceneitem_name = obs_source_get_name(obs_sceneitem_get_source(scene_item)); + const char* scene_name = + obs_source_get_name(obs_scene_get_source(scene)); + const char* sceneitem_name = + obs_source_get_name(obs_sceneitem_get_source(scene_item)); obs_data_t* fields = obs_data_create(); obs_data_set_string(fields, "scene-name", scene_name); @@ -574,8 +596,10 @@ void WSEvents::OnSceneItemVisibilityChanged(void *param, calldata_t *data) bool visible = false; calldata_get_bool(data, "visible", &visible); - const char* scene_name = obs_source_get_name(obs_scene_get_source(scene)); - const char* sceneitem_name = obs_source_get_name(obs_sceneitem_get_source(scene_item)); + const char* scene_name = + obs_source_get_name(obs_scene_get_source(scene)); + const char* sceneitem_name = + obs_source_get_name(obs_sceneitem_get_source(scene_item)); obs_data_t* fields = obs_data_create(); obs_data_set_string(fields, "scene-name", scene_name); diff --git a/WSRequestHandler.cpp b/WSRequestHandler.cpp index d9047b05..1aa18a50 100644 --- a/WSRequestHandler.cpp +++ b/WSRequestHandler.cpp @@ -199,8 +199,10 @@ void WSRequestHandler::HandleGetAuthRequired(WSRequestHandler *req) if (authRequired) { - obs_data_set_string(data, "challenge", Config::Current()->SessionChallenge); - obs_data_set_string(data, "salt", Config::Current()->Salt); + obs_data_set_string(data, "challenge", + Config::Current()->SessionChallenge); + obs_data_set_string(data, "salt", + Config::Current()->Salt); } req->SendOKResponse(data); @@ -223,7 +225,8 @@ void WSRequestHandler::HandleAuthenticate(WSRequestHandler *req) return; } - if ((req->_client->property(PROP_AUTHENTICATED).toBool() == false) && Config::Current()->CheckAuth(auth)) + if ((req->_client->property(PROP_AUTHENTICATED).toBool() == false) + && Config::Current()->CheckAuth(auth)) { req->_client->setProperty(PROP_AUTHENTICATED, true); req->SendOKResponse(); @@ -282,7 +285,8 @@ void WSRequestHandler::HandleGetSceneList(WSRequestHandler *req) obs_data_array_t *scenes = Utils::GetScenes(); obs_data_t *data = obs_data_create(); - obs_data_set_string(data, "current-scene", obs_source_get_name(current_scene)); + obs_data_set_string(data, "current-scene", + obs_source_get_name(current_scene)); obs_data_set_array(data, "scenes", scenes); req->SendOKResponse(data); @@ -450,7 +454,8 @@ void WSRequestHandler::HandleGetTransitionList(WSRequestHandler *req) obs_frontend_source_list_free(&transitionList); obs_data_t *response = obs_data_create(); - obs_data_set_string(response, "current-transition", obs_source_get_name(current_transition)); + obs_data_set_string(response, "current-transition", + obs_source_get_name(current_transition)); obs_data_set_array(response, "transitions", transitions); req->SendOKResponse(response); @@ -465,7 +470,8 @@ void WSRequestHandler::HandleGetCurrentTransition(WSRequestHandler *req) obs_source_t *current_transition = obs_frontend_get_current_transition(); obs_data_t *response = obs_data_create(); - obs_data_set_string(response, "name", obs_source_get_name(current_transition)); + obs_data_set_string(response, "name", + obs_source_get_name(current_transition)); if (!obs_transition_fixed(current_transition)) { @@ -512,7 +518,8 @@ void WSRequestHandler::HandleSetTransitionDuration(WSRequestHandler *req) void WSRequestHandler::HandleGetTransitionDuration(WSRequestHandler *req) { obs_data_t* response = obs_data_create(); - obs_data_set_int(response, "transition-duration", Utils::GetTransitionDuration()); + obs_data_set_int(response, "transition-duration", + Utils::GetTransitionDuration()); req->SendOKResponse(response); obs_data_release(response); @@ -835,7 +842,8 @@ void WSRequestHandler::HandleSetCurrentSceneCollection(WSRequestHandler *req) void WSRequestHandler::HandleGetCurrentSceneCollection(WSRequestHandler *req) { obs_data_t *response = obs_data_create(); - obs_data_set_string(response, "sc-name", obs_frontend_get_current_scene_collection()); + obs_data_set_string(response, "sc-name", + obs_frontend_get_current_scene_collection()); req->SendOKResponse(response); @@ -880,7 +888,8 @@ void WSRequestHandler::HandleSetCurrentProfile(WSRequestHandler *req) void WSRequestHandler::HandleGetCurrentProfile(WSRequestHandler *req) { obs_data_t *response = obs_data_create(); - obs_data_set_string(response, "profile-name", obs_frontend_get_current_profile()); + obs_data_set_string(response, "profile-name", + obs_frontend_get_current_profile()); req->SendOKResponse(response); @@ -971,11 +980,14 @@ void WSRequestHandler::HandleTransitionToProgram(WSRequestHandler *req) if (req->hasField("with-transition")) { - obs_data_t* transitionInfo = obs_data_get_obj(req->data, "with-transition"); + obs_data_t* transitionInfo = + obs_data_get_obj(req->data, "with-transition"); if (obs_data_has_user_value(transitionInfo, "name")) { - const char* transitionName = obs_data_get_string(transitionInfo, "name"); + const char* transitionName = + obs_data_get_string(transitionInfo, "name"); + if (!str_valid(transitionName)) { req->SendErrorResponse("invalid request parameters"); @@ -993,7 +1005,9 @@ void WSRequestHandler::HandleTransitionToProgram(WSRequestHandler *req) if (obs_data_has_user_value(transitionInfo, "duration")) { - int transitionDuration = obs_data_get_int(transitionInfo, "duration"); + int transitionDuration = + obs_data_get_int(transitionInfo, "duration"); + Utils::SetTransitionDuration(transitionDuration); } diff --git a/WSServer.cpp b/WSServer.cpp index c7e49fa5..c74fd2be 100644 --- a/WSServer.cpp +++ b/WSServer.cpp @@ -64,7 +64,8 @@ void WSServer::Start(quint16 port) bool serverStarted = _wsServer->listen(QHostAddress::Any, port); if (serverStarted) { - connect(_wsServer, &QWebSocketServer::newConnection, this, &WSServer::onNewConnection); + connect(_wsServer, &QWebSocketServer::newConnection, + this, &WSServer::onNewConnection); } } @@ -105,8 +106,10 @@ void WSServer::onNewConnection() if (pSocket) { - connect(pSocket, &QWebSocket::textMessageReceived, this, &WSServer::textMessageReceived); - connect(pSocket, &QWebSocket::disconnected, this, &WSServer::socketDisconnected); + connect(pSocket, &QWebSocket::textMessageReceived, + this, &WSServer::textMessageReceived); + connect(pSocket, &QWebSocket::disconnected, + this, &WSServer::socketDisconnected); pSocket->setProperty(PROP_AUTHENTICATED, false); _clMutex.lock(); @@ -116,13 +119,16 @@ void WSServer::onNewConnection() QHostAddress clientAddr = pSocket->peerAddress(); QString clientIp = Utils::FormatIPAddress(clientAddr); - blog(LOG_INFO, "new client connection from %s:%d", clientIp.toUtf8().constData(), pSocket->peerPort()); + blog(LOG_INFO, "new client connection from %s:%d", + clientIp.toUtf8().constData(), pSocket->peerPort()); QString msg = QString(obs_module_text("OBSWebsocket.ConnectNotify.ClientIP")) + QString(" ") + clientAddr.toString(); - Utils::SysTrayNotify(msg, QSystemTrayIcon::Information, QString(obs_module_text("OBSWebsocket.ConnectNotify.Connected"))); + Utils::SysTrayNotify(msg, + QSystemTrayIcon::Information, + QString(obs_module_text("OBSWebsocket.ConnectNotify.Connected"))); } } @@ -154,12 +160,15 @@ void WSServer::socketDisconnected() QHostAddress clientAddr = pSocket->peerAddress(); QString clientIp = Utils::FormatIPAddress(clientAddr); - blog(LOG_INFO, "client %s:%d disconnected", clientIp.toUtf8().constData(), pSocket->peerPort()); + blog(LOG_INFO, "client %s:%d disconnected", + clientIp.toUtf8().constData(), pSocket->peerPort()); QString msg = QString(obs_module_text("OBSWebsocket.ConnectNotify.ClientIP")) + QString(" ") + clientAddr.toString(); - Utils::SysTrayNotify(msg, QSystemTrayIcon::Information, QString(obs_module_text("OBSWebsocket.ConnectNotify.Disconnected"))); + Utils::SysTrayNotify(msg, + QSystemTrayIcon::Information, + QString(obs_module_text("OBSWebsocket.ConnectNotify.Disconnected"))); } } diff --git a/forms/settings-dialog.cpp b/forms/settings-dialog.cpp index dc2cae0d..e677f175 100644 --- a/forms/settings-dialog.cpp +++ b/forms/settings-dialog.cpp @@ -27,13 +27,16 @@ with this program. If not, see #define CHANGE_ME "changeme" SettingsDialog::SettingsDialog(QWidget *parent) : - QDialog(parent, Qt::Dialog), - ui(new Ui::SettingsDialog) + QDialog(parent, Qt::Dialog), + ui(new Ui::SettingsDialog) { - ui->setupUi(this); + ui->setupUi(this); - connect(ui->authRequired, &QCheckBox::stateChanged, this, &SettingsDialog::AuthCheckboxChanged); - connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::FormAccepted); + connect(ui->authRequired, &QCheckBox::stateChanged, + this, &SettingsDialog::AuthCheckboxChanged); + connect(ui->buttonBox, &QDialogButtonBox::accepted, + this, &SettingsDialog::FormAccepted); + AuthCheckboxChanged(); } @@ -114,5 +117,5 @@ void SettingsDialog::FormAccepted() SettingsDialog::~SettingsDialog() { - delete ui; + delete ui; } diff --git a/obs-websocket.cpp b/obs-websocket.cpp index 07f23b60..56b3ac3d 100644 --- a/obs-websocket.cpp +++ b/obs-websocket.cpp @@ -48,7 +48,8 @@ bool obs_module_load(void) WSServer::Instance->Start(config->ServerPort); // UI setup - 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); QMainWindow* main_window = (QMainWindow*)obs_frontend_get_main_window();