mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
fix: improve the portal config parsing
This commit is contained in:
parent
ffa99d3783
commit
d5cd90373b
@ -78,10 +78,7 @@ QList<GPGateway> PortalConfigResponse::parseGateways(QXmlStreamReader &xmlReader
|
|||||||
// Parse the gateways -> external -> list -> entry
|
// Parse the gateways -> external -> list -> entry
|
||||||
if (xmlReader.name() == "entry" && xmlReader.isStartElement()) {
|
if (xmlReader.name() == "entry" && xmlReader.isStartElement()) {
|
||||||
GPGateway g;
|
GPGateway g;
|
||||||
QString address = xmlReader.attributes().value("name").toString();
|
parseGateway(xmlReader, g);
|
||||||
g.setAddress(address);
|
|
||||||
g.setPriorityRules(parsePriorityRules(xmlReader));
|
|
||||||
g.setName(parseGatewayName(xmlReader));
|
|
||||||
gateways.append(g);
|
gateways.append(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,45 +88,44 @@ QList<GPGateway> PortalConfigResponse::parseGateways(QXmlStreamReader &xmlReader
|
|||||||
return gateways;
|
return gateways;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, int> PortalConfigResponse::parsePriorityRules(QXmlStreamReader &xmlReader)
|
void PortalConfigResponse::parseGateway(QXmlStreamReader &reader, GPGateway &gateway) {
|
||||||
{
|
PLOGI << "Start parsing gateway...";
|
||||||
PLOGI << "Start parsing the priority rules...";
|
|
||||||
|
|
||||||
QMap<QString, int> priorityRules;
|
auto finished = false;
|
||||||
|
while (!finished) {
|
||||||
while ((xmlReader.name() != "priority-rule" || !xmlReader.isEndElement()) && !xmlReader.hasError()) {
|
if (reader.name() == "entry") {
|
||||||
xmlReader.readNext();
|
auto address = reader.attributes().value("name").toString();
|
||||||
|
gateway.setAddress(address);
|
||||||
if (xmlReader.name() == "entry" && xmlReader.isStartElement()) {
|
} else if (reader.name() == "description") { // gateway name
|
||||||
QString ruleName = xmlReader.attributes().value("name").toString();
|
gateway.setName(reader.readElementText());
|
||||||
// Read the priority tag
|
} else if (reader.name() == "priority-rule") { // priority rules
|
||||||
while (xmlReader.name() != "priority"){
|
parsePriorityRule(reader, gateway);
|
||||||
xmlReader.readNext();
|
|
||||||
}
|
}
|
||||||
int ruleValue = xmlReader.readElementText().toUInt();
|
finished = !reader.readNextStartElement();
|
||||||
priorityRules.insert(ruleName, ruleValue);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
PLOGI << "Finished parsing the priority rules.";
|
|
||||||
|
|
||||||
return priorityRules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PortalConfigResponse::parseGatewayName(QXmlStreamReader &xmlReader)
|
void PortalConfigResponse::parsePriorityRule(QXmlStreamReader &reader, GPGateway &gateway) {
|
||||||
{
|
PLOGI << "Start parsing priority rule...";
|
||||||
PLOGI << "Start parsing the gateway name...";
|
|
||||||
|
|
||||||
while (xmlReader.name() != "description" || !xmlReader.isEndElement()) {
|
QMap<QString, int> priorityRules;
|
||||||
xmlReader.readNext();
|
auto finished = false;
|
||||||
if (xmlReader.name() == "description" && xmlReader.tokenType() == xmlReader.StartElement) {
|
|
||||||
PLOGI << "Finished parsing the gateway name";
|
while (!finished) {
|
||||||
return xmlReader.readElementText();
|
// Parse the priority-rule -> entry
|
||||||
|
if (reader.name() == "entry") {
|
||||||
|
auto ruleName = reader.attributes().value("name").toString();
|
||||||
|
// move to the priority value
|
||||||
|
while (reader.name() != "priority") {
|
||||||
|
reader.readNextStartElement();
|
||||||
}
|
}
|
||||||
|
auto priority = reader.readElementText().toInt();
|
||||||
|
priorityRules.insert(ruleName, priority);
|
||||||
|
}
|
||||||
|
finished = !reader.readNextStartElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
PLOGE << "Error: <description> tag not found";
|
gateway.setPriorityRules(priorityRules);
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PortalConfigResponse::userAuthCookie() const
|
QString PortalConfigResponse::userAuthCookie() const
|
||||||
@ -137,11 +133,6 @@ QString PortalConfigResponse::userAuthCookie() const
|
|||||||
return m_userAuthCookie;
|
return m_userAuthCookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PortalConfigResponse::prelogonUserAuthCookie() const
|
|
||||||
{
|
|
||||||
return m_prelogonAuthCookie;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<GPGateway> PortalConfigResponse::allGateways() const
|
QList<GPGateway> PortalConfigResponse::allGateways() const
|
||||||
{
|
{
|
||||||
return m_gateways;
|
return m_gateways;
|
||||||
@ -176,3 +167,4 @@ void PortalConfigResponse::setPrelogonUserAuthCookie(const QString cookie)
|
|||||||
{
|
{
|
||||||
m_prelogonAuthCookie = cookie;
|
m_prelogonAuthCookie = cookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ public:
|
|||||||
const QString &username() const;
|
const QString &username() const;
|
||||||
QString password() const;
|
QString password() const;
|
||||||
QString userAuthCookie() const;
|
QString userAuthCookie() const;
|
||||||
QString prelogonUserAuthCookie() const;
|
|
||||||
QList<GPGateway> allGateways() const;
|
QList<GPGateway> allGateways() const;
|
||||||
void setAllGateways(QList<GPGateway> gateways);
|
void setAllGateways(QList<GPGateway> gateways);
|
||||||
|
|
||||||
@ -44,8 +43,9 @@ private:
|
|||||||
void setPrelogonUserAuthCookie(const QString cookie);
|
void setPrelogonUserAuthCookie(const QString cookie);
|
||||||
|
|
||||||
static QList<GPGateway> parseGateways(QXmlStreamReader &xmlReader);
|
static QList<GPGateway> parseGateways(QXmlStreamReader &xmlReader);
|
||||||
static QMap<QString, int> parsePriorityRules(QXmlStreamReader &xmlReader);
|
static void parseGateway(QXmlStreamReader &reader, GPGateway &gateway);
|
||||||
static QString parseGatewayName(QXmlStreamReader &xmlReader);
|
static void parsePriorityRule(QXmlStreamReader &reader, GPGateway &gateway);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PORTALCONFIGRESPONSE_H
|
#endif // PORTALCONFIGRESPONSE_H
|
||||||
|
Loading…
Reference in New Issue
Block a user