Connection string support for XRay protocol (#777)

* Connection string support for XRay protocol
This commit is contained in:
Mykola Baibuz 2024-05-27 16:15:55 +01:00 committed by GitHub
parent d8020878d5
commit e6ee9085a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 20709 additions and 11 deletions

View file

@ -6,6 +6,8 @@
#include <QRegularExpression>
#include <QStandardPaths>
#include <QUrl>
#include <QJsonDocument>
#include <QJsonObject>
#include "utilities.h"
#include "version.h"
@ -23,6 +25,50 @@ QString Utils::getRandomString(int len)
return randomString;
}
QString Utils::VerifyJsonString(const QString &source)
{
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(source.toUtf8(), &error);
Q_UNUSED(doc)
if (error.error == QJsonParseError::NoError) {
return "";
} else {
qDebug() << "WARNING: Json parse returns: " + error.errorString();
return error.errorString();
}
}
QJsonObject Utils::JsonFromString(const QString &string)
{
auto removeComment = string.trimmed();
if (removeComment != string.trimmed()) {
qDebug() << "Some comments have been removed from the json.";
}
QJsonDocument doc = QJsonDocument::fromJson(removeComment.toUtf8());
return doc.object();
}
QString Utils::SafeBase64Decode(QString string)
{
QByteArray ba = string.replace(QChar('-'), QChar('+')).replace(QChar('_'), QChar('/')).toUtf8();
return QByteArray::fromBase64(ba, QByteArray::Base64Option::OmitTrailingEquals);
}
QString Utils::JsonToString(const QJsonObject &json, QJsonDocument::JsonFormat format)
{
QJsonDocument doc;
doc.setObject(json);
return doc.toJson(format);
}
QString Utils::JsonToString(const QJsonArray &array, QJsonDocument::JsonFormat format)
{
QJsonDocument doc;
doc.setArray(array);
return doc.toJson(format);
}
QString Utils::systemLogPath()
{
#ifdef Q_OS_WIN