Skip to content

Commit 9123879

Browse files
committed
Config: Use std::string for ServerPassword instead of QString
Less Qt leeching into things is better.
1 parent 9db7464 commit 9123879

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

src/Config.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ void Config::Load(json config)
6969
if (config.contains(PARAM_AUTHREQUIRED) && config[PARAM_AUTHREQUIRED].is_boolean())
7070
AuthRequired = config[PARAM_AUTHREQUIRED];
7171
if (config.contains(PARAM_PASSWORD) && config[PARAM_PASSWORD].is_string())
72-
ServerPassword = QString::fromStdString(config[PARAM_PASSWORD].get<std::string>());
72+
ServerPassword = config[PARAM_PASSWORD];
7373

7474
// Set server password and save it to the config before processing overrides,
7575
// so that there is always a true configured password regardless of if
7676
// future loads use the override flag.
7777
if (FirstLoad) {
7878
FirstLoad = false;
79-
if (ServerPassword.isEmpty()) {
79+
if (ServerPassword.empty()) {
8080
blog(LOG_INFO, "[Config::Load] (FirstLoad) Generating new server password.");
81-
ServerPassword = QString::fromStdString(Utils::Crypto::GeneratePassword());
81+
ServerPassword = Utils::Crypto::GeneratePassword();
8282
} else {
8383
blog(LOG_INFO, "[Config::Load] (FirstLoad) Not generating new password since one is already configured.");
8484
}
@@ -111,7 +111,7 @@ void Config::Load(json config)
111111
blog(LOG_INFO, "[Config::Load] --websocket_password passed. Overriding WebSocket password.");
112112
PasswordOverridden = true;
113113
AuthRequired = true;
114-
ServerPassword = passwordArgument;
114+
ServerPassword = passwordArgument.toStdString();
115115
}
116116

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

142142
if (!Utils::Json::SetJsonFileContent(configFilePath, config))

src/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct Config {
4040
std::atomic<bool> DebugEnabled = false;
4141
std::atomic<bool> AlertsEnabled = false;
4242
std::atomic<bool> AuthRequired = true;
43-
QString ServerPassword;
43+
std::string ServerPassword;
4444
};
4545

4646
json MigrateGlobalConfigData();

src/forms/ConnectInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void ConnectInfo::RefreshData()
6464
QString serverPassword;
6565
if (conf->AuthRequired) {
6666
ui->copyServerPasswordButton->setEnabled(true);
67-
serverPassword = QUrl::toPercentEncoding(conf->ServerPassword);
67+
serverPassword = QUrl::toPercentEncoding(QString::fromStdString(conf->ServerPassword));
6868
} else {
6969
ui->copyServerPasswordButton->setEnabled(false);
7070
serverPassword = obs_module_text("OBSWebSocket.ConnectInfo.ServerPasswordPlaceholderText");

src/forms/SettingsDialog.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void SettingsDialog::RefreshData()
123123
ui->enableDebugLoggingCheckBox->setChecked(conf->DebugEnabled);
124124
ui->serverPortSpinBox->setValue(conf->ServerPort);
125125
ui->enableAuthenticationCheckBox->setChecked(conf->AuthRequired);
126-
ui->serverPasswordLineEdit->setText(conf->ServerPassword);
126+
ui->serverPasswordLineEdit->setText(QString::fromStdString(conf->ServerPassword));
127127

128128
ui->serverPasswordLineEdit->setEnabled(conf->AuthRequired);
129129
ui->generatePasswordButton->setEnabled(conf->AuthRequired);
@@ -158,7 +158,7 @@ void SettingsDialog::SaveFormData()
158158
}
159159

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

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

185185
conf->ServerEnabled = ui->enableWebSocketServerCheckBox->isChecked();
186186
conf->AlertsEnabled = ui->enableSystemTrayAlertsCheckBox->isChecked();
187187
conf->DebugEnabled = ui->enableDebugLoggingCheckBox->isChecked();
188188
conf->ServerPort = ui->serverPortSpinBox->value();
189189
conf->AuthRequired = ui->enableAuthenticationCheckBox->isChecked();
190-
conf->ServerPassword = ui->serverPasswordLineEdit->text();
190+
conf->ServerPassword = ui->serverPasswordLineEdit->text().toStdString();
191191

192192
conf->Save();
193193

src/websocketserver/WebSocketServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void WebSocketServer::Start()
9797
}
9898

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

102102
// Set log levels if debug is enabled
103103
if (IsDebugEnabled()) {

0 commit comments

Comments
 (0)