Config: Use std::string for ServerPassword instead of QString

Less Qt leeching into things is better.
This commit is contained in:
tt2468 2024-04-22 22:50:10 -07:00
parent 9db7464faa
commit 9123879c76
5 changed files with 13 additions and 13 deletions

View File

@ -69,16 +69,16 @@ void Config::Load(json config)
if (config.contains(PARAM_AUTHREQUIRED) && config[PARAM_AUTHREQUIRED].is_boolean()) if (config.contains(PARAM_AUTHREQUIRED) && config[PARAM_AUTHREQUIRED].is_boolean())
AuthRequired = config[PARAM_AUTHREQUIRED]; AuthRequired = config[PARAM_AUTHREQUIRED];
if (config.contains(PARAM_PASSWORD) && config[PARAM_PASSWORD].is_string()) 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, // Set server password and save it to the config before processing overrides,
// so that there is always a true configured password regardless of if // so that there is always a true configured password regardless of if
// future loads use the override flag. // future loads use the override flag.
if (FirstLoad) { if (FirstLoad) {
FirstLoad = false; FirstLoad = false;
if (ServerPassword.isEmpty()) { if (ServerPassword.empty()) {
blog(LOG_INFO, "[Config::Load] (FirstLoad) Generating new server password."); blog(LOG_INFO, "[Config::Load] (FirstLoad) Generating new server password.");
ServerPassword = QString::fromStdString(Utils::Crypto::GeneratePassword()); ServerPassword = Utils::Crypto::GeneratePassword();
} else { } else {
blog(LOG_INFO, "[Config::Load] (FirstLoad) Not generating new password since one is already configured."); blog(LOG_INFO, "[Config::Load] (FirstLoad) Not generating new password since one is already configured.");
} }
@ -111,7 +111,7 @@ void Config::Load(json config)
blog(LOG_INFO, "[Config::Load] --websocket_password passed. Overriding WebSocket password."); blog(LOG_INFO, "[Config::Load] --websocket_password passed. Overriding WebSocket password.");
PasswordOverridden = true; PasswordOverridden = true;
AuthRequired = true; AuthRequired = true;
ServerPassword = passwordArgument; ServerPassword = passwordArgument.toStdString();
} }
// Process `--websocket_debug` override // Process `--websocket_debug` override
@ -136,7 +136,7 @@ void Config::Save()
config[PARAM_ALERTS] = AlertsEnabled.load(); config[PARAM_ALERTS] = AlertsEnabled.load();
if (!PasswordOverridden) { if (!PasswordOverridden) {
config[PARAM_AUTHREQUIRED] = AuthRequired.load(); config[PARAM_AUTHREQUIRED] = AuthRequired.load();
config[PARAM_PASSWORD] = ServerPassword.toStdString(); config[PARAM_PASSWORD] = ServerPassword;
} }
if (!Utils::Json::SetJsonFileContent(configFilePath, config)) if (!Utils::Json::SetJsonFileContent(configFilePath, config))

View File

@ -40,7 +40,7 @@ struct Config {
std::atomic<bool> DebugEnabled = false; std::atomic<bool> DebugEnabled = false;
std::atomic<bool> AlertsEnabled = false; std::atomic<bool> AlertsEnabled = false;
std::atomic<bool> AuthRequired = true; std::atomic<bool> AuthRequired = true;
QString ServerPassword; std::string ServerPassword;
}; };
json MigrateGlobalConfigData(); json MigrateGlobalConfigData();

View File

@ -64,7 +64,7 @@ void ConnectInfo::RefreshData()
QString serverPassword; QString serverPassword;
if (conf->AuthRequired) { if (conf->AuthRequired) {
ui->copyServerPasswordButton->setEnabled(true); ui->copyServerPasswordButton->setEnabled(true);
serverPassword = QUrl::toPercentEncoding(conf->ServerPassword); serverPassword = QUrl::toPercentEncoding(QString::fromStdString(conf->ServerPassword));
} else { } else {
ui->copyServerPasswordButton->setEnabled(false); ui->copyServerPasswordButton->setEnabled(false);
serverPassword = obs_module_text("OBSWebSocket.ConnectInfo.ServerPasswordPlaceholderText"); serverPassword = obs_module_text("OBSWebSocket.ConnectInfo.ServerPasswordPlaceholderText");

View File

@ -123,7 +123,7 @@ void SettingsDialog::RefreshData()
ui->enableDebugLoggingCheckBox->setChecked(conf->DebugEnabled); ui->enableDebugLoggingCheckBox->setChecked(conf->DebugEnabled);
ui->serverPortSpinBox->setValue(conf->ServerPort); ui->serverPortSpinBox->setValue(conf->ServerPort);
ui->enableAuthenticationCheckBox->setChecked(conf->AuthRequired); ui->enableAuthenticationCheckBox->setChecked(conf->AuthRequired);
ui->serverPasswordLineEdit->setText(conf->ServerPassword); ui->serverPasswordLineEdit->setText(QString::fromStdString(conf->ServerPassword));
ui->serverPasswordLineEdit->setEnabled(conf->AuthRequired); ui->serverPasswordLineEdit->setEnabled(conf->AuthRequired);
ui->generatePasswordButton->setEnabled(conf->AuthRequired); ui->generatePasswordButton->setEnabled(conf->AuthRequired);
@ -158,7 +158,7 @@ void SettingsDialog::SaveFormData()
} }
// Show a confirmation box to the user if they attempt to provide their own password // 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; QMessageBox msgBox;
msgBox.setWindowTitle(obs_module_text("OBSWebSocket.Settings.Save.UserPasswordWarningTitle")); msgBox.setWindowTitle(obs_module_text("OBSWebSocket.Settings.Save.UserPasswordWarningTitle"));
msgBox.setText(obs_module_text("OBSWebSocket.Settings.Save.UserPasswordWarningMessage")); msgBox.setText(obs_module_text("OBSWebSocket.Settings.Save.UserPasswordWarningMessage"));
@ -172,7 +172,7 @@ void SettingsDialog::SaveFormData()
break; break;
case QMessageBox::No: case QMessageBox::No:
default: default:
ui->serverPasswordLineEdit->setText(conf->ServerPassword); ui->serverPasswordLineEdit->setText(QString::fromStdString(conf->ServerPassword));
return; return;
} }
} }
@ -180,14 +180,14 @@ void SettingsDialog::SaveFormData()
bool needsRestart = bool needsRestart =
(conf->ServerEnabled != ui->enableWebSocketServerCheckBox->isChecked()) || (conf->ServerEnabled != ui->enableWebSocketServerCheckBox->isChecked()) ||
(conf->ServerPort != ui->serverPortSpinBox->value()) || (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->ServerEnabled = ui->enableWebSocketServerCheckBox->isChecked();
conf->AlertsEnabled = ui->enableSystemTrayAlertsCheckBox->isChecked(); conf->AlertsEnabled = ui->enableSystemTrayAlertsCheckBox->isChecked();
conf->DebugEnabled = ui->enableDebugLoggingCheckBox->isChecked(); conf->DebugEnabled = ui->enableDebugLoggingCheckBox->isChecked();
conf->ServerPort = ui->serverPortSpinBox->value(); conf->ServerPort = ui->serverPortSpinBox->value();
conf->AuthRequired = ui->enableAuthenticationCheckBox->isChecked(); conf->AuthRequired = ui->enableAuthenticationCheckBox->isChecked();
conf->ServerPassword = ui->serverPasswordLineEdit->text(); conf->ServerPassword = ui->serverPasswordLineEdit->text().toStdString();
conf->Save(); conf->Save();

View File

@ -97,7 +97,7 @@ void WebSocketServer::Start()
} }
_authenticationSalt = Utils::Crypto::GenerateSalt(); _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 // Set log levels if debug is enabled
if (IsDebugEnabled()) { if (IsDebugEnabled()) {