mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
Port the splitCommand method (#79)
This commit is contained in:
parent
53c8572cf6
commit
42cae3ff26
@ -39,6 +39,47 @@ QString GPService::findBinary()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Port from https://github.com/qt/qtbase/blob/11d1dcc6e263c5059f34b44d531c9ccdf7c0b1d6/src/corelib/io/qprocess.cpp#L2115 */
|
||||||
|
QStringList GPService::splitCommand(QStringView command)
|
||||||
|
{
|
||||||
|
QStringList args;
|
||||||
|
QString tmp;
|
||||||
|
int quoteCount = 0;
|
||||||
|
bool inQuote = false;
|
||||||
|
|
||||||
|
// handle quoting. tokens can be surrounded by double quotes
|
||||||
|
// "hello world". three consecutive double quotes represent
|
||||||
|
// the quote character itself.
|
||||||
|
for (int i = 0; i < command.size(); ++i) {
|
||||||
|
if (command.at(i) == QLatin1Char('"')) {
|
||||||
|
++quoteCount;
|
||||||
|
if (quoteCount == 3) {
|
||||||
|
// third consecutive quote
|
||||||
|
quoteCount = 0;
|
||||||
|
tmp += command.at(i);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (quoteCount) {
|
||||||
|
if (quoteCount == 1)
|
||||||
|
inQuote = !inQuote;
|
||||||
|
quoteCount = 0;
|
||||||
|
}
|
||||||
|
if (!inQuote && command.at(i).isSpace()) {
|
||||||
|
if (!tmp.isEmpty()) {
|
||||||
|
args += tmp;
|
||||||
|
tmp.clear();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tmp += command.at(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!tmp.isEmpty())
|
||||||
|
args += tmp;
|
||||||
|
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
void GPService::quit()
|
void GPService::quit()
|
||||||
{
|
{
|
||||||
if (openconnect->state() == QProcess::NotRunning) {
|
if (openconnect->state() == QProcess::NotRunning) {
|
||||||
@ -65,7 +106,7 @@ void GPService::connect(QString server, QString username, QString passwd, QStrin
|
|||||||
QStringList args;
|
QStringList args;
|
||||||
args << QCoreApplication::arguments().mid(1)
|
args << QCoreApplication::arguments().mid(1)
|
||||||
<< "--protocol=gp"
|
<< "--protocol=gp"
|
||||||
<< QProcess::splitCommand(extraArgs)
|
<< splitCommand(extraArgs)
|
||||||
<< "-u" << username
|
<< "-u" << username
|
||||||
<< "-C" << passwd
|
<< "-C" << passwd
|
||||||
<< server;
|
<< server;
|
||||||
|
@ -53,6 +53,7 @@ private:
|
|||||||
|
|
||||||
void log(QString msg);
|
void log(QString msg);
|
||||||
static QString findBinary();
|
static QString findBinary();
|
||||||
|
static QStringList splitCommand(QStringView command);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GLOBALPROTECTSERVICE_H
|
#endif // GLOBALPROTECTSERVICE_H
|
||||||
|
Loading…
Reference in New Issue
Block a user