Config: remove flawed qstring_data_copy and add toUtf8() macro

This commit is contained in:
Stéphane L 2018-03-13 22:46:03 +01:00
parent 357691bad5
commit 389ef2aea9
5 changed files with 7 additions and 17 deletions

View File

@ -34,6 +34,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include "Config.h" #include "Config.h"
#include "Utils.h" #include "Utils.h"
#define QT_TO_UTF8(str) str.toUtf8().constData()
Config* Config::_instance = new Config(); Config* Config::_instance = new Config();
Config::Config() : Config::Config() :
@ -62,9 +64,9 @@ Config::Config() :
config_set_default_bool(obsConfig, config_set_default_bool(obsConfig,
SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired); SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired);
config_set_default_string(obsConfig, config_set_default_string(obsConfig,
SECTION_NAME, PARAM_SECRET, qstring_data_copy(Secret)); SECTION_NAME, PARAM_SECRET, QT_TO_UTF8(Secret));
config_set_default_string(obsConfig, config_set_default_string(obsConfig,
SECTION_NAME, PARAM_SALT, qstring_data_copy(Salt)); SECTION_NAME, PARAM_SALT, QT_TO_UTF8(Salt));
} }
mbedtls_entropy_init(&entropy); mbedtls_entropy_init(&entropy);
@ -104,9 +106,9 @@ void Config::Save() {
config_set_bool(obsConfig, SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired); config_set_bool(obsConfig, SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired);
config_set_string(obsConfig, SECTION_NAME, PARAM_SECRET, config_set_string(obsConfig, SECTION_NAME, PARAM_SECRET,
qstring_data_copy(Secret)); QT_TO_UTF8(Secret));
config_set_string(obsConfig, SECTION_NAME, PARAM_SALT, config_set_string(obsConfig, SECTION_NAME, PARAM_SALT,
qstring_data_copy(Salt)); QT_TO_UTF8(Salt));
config_save(obsConfig); config_save(obsConfig);
} }

View File

@ -28,13 +28,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>
Q_DECLARE_METATYPE(OBSScene); Q_DECLARE_METATYPE(OBSScene);
const char* qstring_data_copy(QString value) {
QByteArray stringData = value.toUtf8();
const char* constStringData = new const char[stringData.size()]();
memcpy((void*)constStringData, stringData.constData(), stringData.size());
return constStringData;
}
obs_data_array_t* Utils::StringListToArray(char** strings, char* key) { obs_data_array_t* Utils::StringListToArray(char** strings, char* key) {
if (!strings) if (!strings)
return obs_data_array_create(); return obs_data_array_create();

View File

@ -32,8 +32,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include <obs-module.h> #include <obs-module.h>
#include <util/config-file.h> #include <util/config-file.h>
const char* qstring_data_copy(QString value);
class Utils { class Utils {
public: public:
static obs_data_array_t* StringListToArray(char** strings, char* key); static obs_data_array_t* StringListToArray(char** strings, char* key);

View File

@ -22,7 +22,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include "../Config.h" #include "../Config.h"
#include "../WSServer.h" #include "../WSServer.h"
#include "settings-dialog.h" #include "settings-dialog.h"
#include "ui_settings-dialog.h"
#define CHANGE_ME "changeme" #define CHANGE_ME "changeme"

View File

@ -21,9 +21,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include <QDialog> #include <QDialog>
namespace Ui { #include "ui_settings-dialog.h"
class SettingsDialog;
}
class SettingsDialog : public QDialog class SettingsDialog : public QDialog
{ {