forked from shadowsocks/shadowsocks-qt5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssvalidator.cpp
37 lines (33 loc) · 931 Bytes
/
ssvalidator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "ssvalidator.h"
#include <QtShadowsocks>
QStringList SSValidator::supportedMethodList()
{
std::vector<std::string> methodBA = QSS::Cipher::supportedMethods();
std::sort(methodBA.begin(), methodBA.end());
QStringList methodList;
for (const std::string& method : methodBA) {
methodList.push_back(QString::fromStdString(method).toUpper());
}
return methodList;
}
bool SSValidator::validate(const QString &input)
{
bool valid = true;
try {
QSS::Profile::fromUri(input.toStdString());
} catch(const std::exception&) {
valid = false;
}
return valid;
}
bool SSValidator::validatePort(const QString &port)
{
bool ok;
port.toUShort(&ok);
return ok;
}
bool SSValidator::validateMethod(const QString &method)
{
static const QStringList validMethodList = supportedMethodList();
return validMethodList.contains(method, Qt::CaseInsensitive);
}