mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-05-20 07:26:58 -04:00
Code refactor, support multiple gateways and non-SAML authentication (#9)
* Code refactor * Update README.md
This commit is contained in:
145
GPClient/portalconfigresponse.cpp
Normal file
145
GPClient/portalconfigresponse.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
#include "portalconfigresponse.h"
|
||||
|
||||
#include <QXmlStreamReader>
|
||||
#include <plog/Log.h>
|
||||
|
||||
QString PortalConfigResponse::xmlUserAuthCookie = "portal-userauthcookie";
|
||||
QString PortalConfigResponse::xmlPrelogonUserAuthCookie = "portal-prelogonuserauthcookie";
|
||||
QString PortalConfigResponse::xmlGateways = "gateways";
|
||||
|
||||
PortalConfigResponse::PortalConfigResponse()
|
||||
{
|
||||
}
|
||||
|
||||
PortalConfigResponse PortalConfigResponse::parse(const QByteArray& xml)
|
||||
{
|
||||
QXmlStreamReader xmlReader(xml);
|
||||
PortalConfigResponse response;
|
||||
response.setRawResponse(xml);
|
||||
|
||||
while (!xmlReader.atEnd()) {
|
||||
xmlReader.readNextStartElement();
|
||||
|
||||
QString name = xmlReader.name().toString();
|
||||
|
||||
if (name == xmlUserAuthCookie) {
|
||||
response.setUserAuthCookie(xmlReader.readElementText());
|
||||
} else if (name == xmlPrelogonUserAuthCookie) {
|
||||
response.setPrelogonUserAuthCookie(xmlReader.readElementText());
|
||||
} else if (name == xmlGateways) {
|
||||
response.setGateways(parseGateways(xmlReader));
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
const QByteArray& PortalConfigResponse::rawResponse() const
|
||||
{
|
||||
return _rawResponse;
|
||||
}
|
||||
|
||||
QString PortalConfigResponse::username() const
|
||||
{
|
||||
return _username;
|
||||
}
|
||||
|
||||
QString PortalConfigResponse::password() const
|
||||
{
|
||||
return _password;
|
||||
}
|
||||
|
||||
QList<GPGateway> PortalConfigResponse::parseGateways(QXmlStreamReader &xmlReader)
|
||||
{
|
||||
QList<GPGateway> gateways;
|
||||
|
||||
while (xmlReader.name() != xmlGateways || !xmlReader.isEndElement()) {
|
||||
xmlReader.readNext();
|
||||
// Parse the gateways -> external -> list -> entry
|
||||
if (xmlReader.name() == "entry" && xmlReader.isStartElement()) {
|
||||
GPGateway gateway;
|
||||
QString address = xmlReader.attributes().value("name").toString();
|
||||
gateway.setAddress(address);
|
||||
gateway.setPriorityRules(parsePriorityRules(xmlReader));
|
||||
gateway.setName(parseGatewayName(xmlReader));
|
||||
gateways.append(gateway);
|
||||
}
|
||||
}
|
||||
return gateways;
|
||||
}
|
||||
|
||||
QMap<QString, int> PortalConfigResponse::parsePriorityRules(QXmlStreamReader &xmlReader)
|
||||
{
|
||||
QMap<QString, int> priorityRules;
|
||||
|
||||
while (xmlReader.name() != "priority-rule" || !xmlReader.isEndElement()) {
|
||||
xmlReader.readNext();
|
||||
|
||||
if (xmlReader.name() == "entry" && xmlReader.isStartElement()) {
|
||||
QString ruleName = xmlReader.attributes().value("name").toString();
|
||||
// Read the priority tag
|
||||
xmlReader.readNextStartElement();
|
||||
int ruleValue = xmlReader.readElementText().toUInt();
|
||||
priorityRules.insert(ruleName, ruleValue);
|
||||
}
|
||||
}
|
||||
return priorityRules;
|
||||
}
|
||||
|
||||
QString PortalConfigResponse::parseGatewayName(QXmlStreamReader &xmlReader)
|
||||
{
|
||||
while (xmlReader.name() != "description" || !xmlReader.isEndElement()) {
|
||||
xmlReader.readNext();
|
||||
if (xmlReader.name() == "description" && xmlReader.tokenType() == xmlReader.StartElement) {
|
||||
return xmlReader.readElementText();
|
||||
}
|
||||
}
|
||||
|
||||
PLOGE << "Error: <description> tag not found";
|
||||
return "";
|
||||
}
|
||||
|
||||
QString PortalConfigResponse::userAuthCookie() const
|
||||
{
|
||||
return _userAuthCookie;
|
||||
}
|
||||
|
||||
QString PortalConfigResponse::prelogonUserAuthCookie() const
|
||||
{
|
||||
return _prelogonAuthCookie;
|
||||
}
|
||||
|
||||
QList<GPGateway>& PortalConfigResponse::allGateways()
|
||||
{
|
||||
return _gateways;
|
||||
}
|
||||
|
||||
void PortalConfigResponse::setRawResponse(const QByteArray &response)
|
||||
{
|
||||
_rawResponse = response;
|
||||
}
|
||||
|
||||
void PortalConfigResponse::setUsername(const QString& username)
|
||||
{
|
||||
_username = username;
|
||||
}
|
||||
|
||||
void PortalConfigResponse::setPassword(const QString& password)
|
||||
{
|
||||
_password = password;
|
||||
}
|
||||
|
||||
void PortalConfigResponse::setUserAuthCookie(const QString &cookie)
|
||||
{
|
||||
_userAuthCookie = cookie;
|
||||
}
|
||||
|
||||
void PortalConfigResponse::setPrelogonUserAuthCookie(const QString &cookie)
|
||||
{
|
||||
_prelogonAuthCookie = cookie;
|
||||
}
|
||||
|
||||
void PortalConfigResponse::setGateways(const QList<GPGateway> &gateways)
|
||||
{
|
||||
_gateways = gateways;
|
||||
}
|
Reference in New Issue
Block a user