Parses a single IncomingServer or OutgoingServer section.
(
reader: &mut quick_xml::Reader<B>,
server_event: &BytesStart,
)
| 54 | |
| 55 | /// Parses a single IncomingServer or OutgoingServer section. |
| 56 | fn parse_server<B: BufRead>( |
| 57 | reader: &mut quick_xml::Reader<B>, |
| 58 | server_event: &BytesStart, |
| 59 | ) -> Result<Option<Server>, quick_xml::Error> { |
| 60 | let end_tag = String::from_utf8_lossy(server_event.name().as_ref()) |
| 61 | .trim() |
| 62 | .to_lowercase(); |
| 63 | |
| 64 | let typ = server_event |
| 65 | .attributes() |
| 66 | .find_map(|attr| { |
| 67 | attr.ok().filter(|a| { |
| 68 | String::from_utf8_lossy(a.key.as_ref()) |
| 69 | .trim() |
| 70 | .eq_ignore_ascii_case("type") |
| 71 | }) |
| 72 | }) |
| 73 | .map(|typ| { |
| 74 | typ.decode_and_unescape_value(reader.decoder()) |
| 75 | .unwrap_or_default() |
| 76 | .to_lowercase() |
| 77 | }) |
| 78 | .unwrap_or_default(); |
| 79 | |
| 80 | let mut hostname = None; |
| 81 | let mut port = None; |
| 82 | let mut sockettype = Socket::Automatic; |
| 83 | let mut username = None; |
| 84 | |
| 85 | let mut tag_config = MozConfigTag::Undefined; |
| 86 | let mut buf = Vec::new(); |
| 87 | loop { |
| 88 | match reader.read_event_into(&mut buf)? { |
| 89 | Event::Start(ref event) => { |
| 90 | tag_config = String::from_utf8_lossy(event.name().as_ref()) |
| 91 | .parse() |
| 92 | .unwrap_or_default(); |
| 93 | } |
| 94 | Event::End(ref event) => { |
| 95 | let tag = String::from_utf8_lossy(event.name().as_ref()) |
| 96 | .trim() |
| 97 | .to_lowercase(); |
| 98 | |
| 99 | if tag == end_tag { |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | Event::Text(ref event) => { |
| 104 | let val = event.xml_content().unwrap_or_default().trim().to_owned(); |
| 105 | |
| 106 | match tag_config { |
| 107 | MozConfigTag::Hostname => hostname = Some(val), |
| 108 | MozConfigTag::Port => port = Some(val.parse().unwrap_or_default()), |
| 109 | MozConfigTag::Username => username = Some(val), |
| 110 | MozConfigTag::Sockettype => { |
| 111 | sockettype = match val.to_lowercase().as_ref() { |
| 112 | "ssl" => Socket::Ssl, |
| 113 | "starttls" => Socket::Starttls, |
no test coverage detected