diff --git a/crates/gpapi/src/gateway/parse_gateways.rs b/crates/gpapi/src/gateway/parse_gateways.rs index 4810749..324cc95 100644 --- a/crates/gpapi/src/gateway/parse_gateways.rs +++ b/crates/gpapi/src/gateway/parse_gateways.rs @@ -1,3 +1,4 @@ +use log::info; use roxmltree::Node; use crate::utils::xml::NodeExt; @@ -6,14 +7,19 @@ use super::{Gateway, PriorityRule}; pub(crate) fn parse_gateways(node: &Node, use_internal: bool) -> Option> { let node_gateways = node.find_child("gateways")?; - - let list_gateway = if use_internal { - node_gateways.find_child("internal")?.find_child("list")? + let internal_gateway_list = if use_internal { + info!("Using internal gateways"); + node_gateways.find_child("internal").and_then(|n| n.find_child("list")) } 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() .filter_map(|gateway_item| { if !gateway_item.has_tag_name("entry") { diff --git a/crates/gpapi/src/utils/xml.rs b/crates/gpapi/src/utils/xml.rs index c1f9699..76bf703 100644 --- a/crates/gpapi/src/utils/xml.rs +++ b/crates/gpapi/src/utils/xml.rs @@ -7,7 +7,7 @@ pub(crate) trait NodeExt<'a> { impl<'a> NodeExt<'a> for Node<'a, 'a> { fn find_child(&self, name: &str) -> Option> { - 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> {