mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
refactor: improve gateway parsing
This commit is contained in:
parent
68227b64a2
commit
370a32f1b5
@ -1,3 +1,4 @@
|
|||||||
|
use log::info;
|
||||||
use roxmltree::Node;
|
use roxmltree::Node;
|
||||||
|
|
||||||
use crate::utils::xml::NodeExt;
|
use crate::utils::xml::NodeExt;
|
||||||
@ -6,14 +7,19 @@ use super::{Gateway, PriorityRule};
|
|||||||
|
|
||||||
pub(crate) fn parse_gateways(node: &Node, use_internal: bool) -> Option<Vec<Gateway>> {
|
pub(crate) fn parse_gateways(node: &Node, use_internal: bool) -> Option<Vec<Gateway>> {
|
||||||
let node_gateways = node.find_child("gateways")?;
|
let node_gateways = node.find_child("gateways")?;
|
||||||
|
let internal_gateway_list = if use_internal {
|
||||||
let list_gateway = if use_internal {
|
info!("Using internal gateways");
|
||||||
node_gateways.find_child("internal")?.find_child("list")?
|
node_gateways.find_child("internal").and_then(|n| n.find_child("list"))
|
||||||
} else {
|
} else {
|
||||||
node_gateways.find_child("external")?.find_child("list")?
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let gateways = list_gateway
|
let gateway_list = internal_gateway_list.or_else(|| {
|
||||||
|
info!("Using external gateways");
|
||||||
|
node_gateways.find_child("external").and_then(|n| n.find_child("list"))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let gateways = gateway_list
|
||||||
.children()
|
.children()
|
||||||
.filter_map(|gateway_item| {
|
.filter_map(|gateway_item| {
|
||||||
if !gateway_item.has_tag_name("entry") {
|
if !gateway_item.has_tag_name("entry") {
|
||||||
|
@ -7,7 +7,7 @@ pub(crate) trait NodeExt<'a> {
|
|||||||
|
|
||||||
impl<'a> NodeExt<'a> for Node<'a, 'a> {
|
impl<'a> NodeExt<'a> for Node<'a, 'a> {
|
||||||
fn find_child(&self, name: &str) -> Option<Node<'a, 'a>> {
|
fn find_child(&self, name: &str) -> Option<Node<'a, 'a>> {
|
||||||
self.children().find(|n| n.has_tag_name(name))
|
self.descendants().find(|n| n.has_tag_name(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child_text(&self, name: &str) -> Option<&'a str> {
|
fn child_text(&self, name: &str) -> Option<&'a str> {
|
||||||
|
Loading…
Reference in New Issue
Block a user