Skip to content

Commit

Permalink
Config: Use std::string for ServerPassword instead of QString
Browse files Browse the repository at this point in the history
Less Qt leeching into things is better.
  • Loading branch information
tt2468 committed Apr 23, 2024
1 parent 9db7464 commit 9123879
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ void Config::Load(json config)
if (config.contains(PARAM_AUTHREQUIRED) && config[PARAM_AUTHREQUIRED].is_boolean())
AuthRequired = config[PARAM_AUTHREQUIRED];
if (config.contains(PARAM_PASSWORD) && config[PARAM_PASSWORD].is_string())
ServerPassword = QString::fromStdString(config[PARAM_PASSWORD].get<std::string>());
ServerPassword = config[PARAM_PASSWORD];

// Set server password and save it to the config before processing overrides,
// so that there is always a true configured password regardless of if
// future loads use the override flag.
if (FirstLoad) {
FirstLoad = false;
if (ServerPassword.isEmpty()) {
if (ServerPassword.empty()) {
blog(LOG_INFO, "[Config::Load] (FirstLoad) Generating new server password.");
ServerPassword = QString::fromStdString(Utils::Crypto::GeneratePassword());
ServerPassword = Utils::Crypto::GeneratePassword();
} else {
blog(LOG_INFO, "[Config::Load] (FirstLoad) Not generating new password since one is already configured.");
}
Expand Down Expand Up @@ -111,7 +111,7 @@ void Config::Load(json config)
blog(LOG_INFO, "[Config::Load] --websocket_password passed. Overriding WebSocket password.");
PasswordOverridden = true;
AuthRequired = true;
ServerPassword = passwordArgument;
ServerPassword = passwordArgument.toStdString();
}

// Process `--websocket_debug` override
Expand All @@ -136,7 +136,7 @@ void Config::Save()
config[PARAM_ALERTS] = AlertsEnabled.load();
if (!PasswordOverridden) {
config[PARAM_AUTHREQUIRED] = AuthRequired.load();
config[PARAM_PASSWORD] = ServerPassword.toStdString();
config[PARAM_PASSWORD] = ServerPassword;
}

if (!Utils::Json::SetJsonFileContent(configFilePath, config))
Expand Down
2 changes: 1 addition & 1 deletion src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct Config {
std::atomic<bool> DebugEnabled = false;
std::atomic<bool> AlertsEnabled = false;
std::atomic<bool> AuthRequired = true;
QString ServerPassword;
std::string ServerPassword;
};

json MigrateGlobalConfigData();
Expand Down
2 changes: 1 addition & 1 deletion src/forms/ConnectInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void ConnectInfo::RefreshData()
QString serverPassword;
if (conf->AuthRequired) {
ui->copyServerPasswordButton->setEnabled(true);
serverPassword = QUrl::toPercentEncoding(conf->ServerPassword);
serverPassword = QUrl::toPercentEncoding(QString::fromStdString(conf->ServerPassword));
} else {
ui->copyServerPasswordButton->setEnabled(false);
serverPassword = obs_module_text("OBSWebSocket.ConnectInfo.ServerPasswordPlaceholderText");
Expand Down
10 changes: 5 additions & 5 deletions src/forms/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void SettingsDialog::RefreshData()
ui->enableDebugLoggingCheckBox->setChecked(conf->DebugEnabled);
ui->serverPortSpinBox->setValue(conf->ServerPort);
ui->enableAuthenticationCheckBox->setChecked(conf->AuthRequired);
ui->serverPasswordLineEdit->setText(conf->ServerPassword);
ui->serverPasswordLineEdit->setText(QString::fromStdString(conf->ServerPassword));

ui->serverPasswordLineEdit->setEnabled(conf->AuthRequired);
ui->generatePasswordButton->setEnabled(conf->AuthRequired);
Expand Down Expand Up @@ -158,7 +158,7 @@ void SettingsDialog::SaveFormData()
}

// Show a confirmation box to the user if they attempt to provide their own password
if (passwordManuallyEdited && (conf->ServerPassword != ui->serverPasswordLineEdit->text())) {
if (passwordManuallyEdited && (conf->ServerPassword != ui->serverPasswordLineEdit->text().toStdString())) {
QMessageBox msgBox;
msgBox.setWindowTitle(obs_module_text("OBSWebSocket.Settings.Save.UserPasswordWarningTitle"));
msgBox.setText(obs_module_text("OBSWebSocket.Settings.Save.UserPasswordWarningMessage"));
Expand All @@ -172,22 +172,22 @@ void SettingsDialog::SaveFormData()
break;
case QMessageBox::No:
default:
ui->serverPasswordLineEdit->setText(conf->ServerPassword);
ui->serverPasswordLineEdit->setText(QString::fromStdString(conf->ServerPassword));
return;
}
}

bool needsRestart =
(conf->ServerEnabled != ui->enableWebSocketServerCheckBox->isChecked()) ||
(conf->ServerPort != ui->serverPortSpinBox->value()) ||
(ui->enableAuthenticationCheckBox->isChecked() && conf->ServerPassword != ui->serverPasswordLineEdit->text());
(ui->enableAuthenticationCheckBox->isChecked() && conf->ServerPassword != ui->serverPasswordLineEdit->text().toStdString());

conf->ServerEnabled = ui->enableWebSocketServerCheckBox->isChecked();
conf->AlertsEnabled = ui->enableSystemTrayAlertsCheckBox->isChecked();
conf->DebugEnabled = ui->enableDebugLoggingCheckBox->isChecked();
conf->ServerPort = ui->serverPortSpinBox->value();
conf->AuthRequired = ui->enableAuthenticationCheckBox->isChecked();
conf->ServerPassword = ui->serverPasswordLineEdit->text();
conf->ServerPassword = ui->serverPasswordLineEdit->text().toStdString();

conf->Save();

Expand Down
2 changes: 1 addition & 1 deletion src/websocketserver/WebSocketServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void WebSocketServer::Start()
}

_authenticationSalt = Utils::Crypto::GenerateSalt();
_authenticationSecret = Utils::Crypto::GenerateSecret(conf->ServerPassword.toStdString(), _authenticationSalt);
_authenticationSecret = Utils::Crypto::GenerateSecret(conf->ServerPassword, _authenticationSalt);

// Set log levels if debug is enabled
if (IsDebugEnabled()) {
Expand Down

0 comments on commit 9123879

Please sign in to comment.