fn xml_body(mxdepth: usize, args: &mut RequestField, body: &[u8]) -> Result<(), String> {
    let body_utf8 = String::from_utf8_lossy(body);
    let mut stack: Vec<(String, u64)> = Vec::new();
    for rtoken in xmlparser::Tokenizer::from(body_utf8.as_ref()) {
        if stack.len() >= mxdepth {
            return Err(format!("XML nesting level exceeded: {}", mxdepth));
        }
        let token = rtoken.map_err(|rr| format!("XML parsing error: {}", rr))?;
        match token {
            Token::ProcessingInstruction { .. } => (),
            Token::Comment { .. } => (),
            Token::Declaration { .. } => (),
            Token::DtdStart { external_id, name, .. } => xml_external_id(args, &stack, name.as_str(), external_id),
            Token::DtdEnd { .. } => (),
            Token::EmptyDtd { external_id, name, .. } => xml_external_id(args, &stack, name.as_str(), external_id),
            Token::EntityDeclaration { name, definition, .. } => match definition {
                EntityDefinition::EntityValue(span) => args.add(
                    "_XMLENTITY_VALUE_".to_string() + name.as_str(),
                    DataSource::FromBody,
                    span.to_string(),
                ),
                EntityDefinition::ExternalId(eid) => xml_external_id(args, &stack, "entity", Some(eid)),
            },
            Token::ElementStart { local, .. } => {
                // increment element index for the current element
                xml_increment_last(&mut stack);
                // and push the new element
                stack.push((local.to_string(), 0))
            }
            Token::ElementEnd { end, .. } => match end {
                //  <foo/>
                ElementEnd::Empty => close_xml_element(args, &mut stack, None)?,
                //  <foo>
                ElementEnd::Open => (),
                //  </foo>
                ElementEnd::Close(_, local) => close_xml_element(args, &mut stack, Some(local.as_str()))?,
            },
            Token::Attribute { local, value, .. } => {
                let path = xml_path(&stack) + local.as_str();
                args.add(path, DataSource::FromBody, value.to_string());
            }
            Token::Text { text } => {
                let trimmed = text.trim();
                if !trimmed.is_empty() {
                    xml_increment_last(&mut stack);
                    args.add(xml_path(&stack), DataSource::FromBody, trimmed.to_string());
                }
            }
            Token::Cdata { text, .. } => {
                xml_increment_last(&mut stack);
                args.add(xml_path(&stack), DataSource::FromBody, text.to_string());
            }
        }
    }
    if stack.is_empty() {
        Ok(())
    } else {
        Err("XML error: premature end of document".to_string())
    }
}
/// Parses the XML body by iterating on the token stream
///
/// This checks the following errors, in addition to the what the lexer gets:
///   * mismatched opening and closing tags
///   * premature end of document
Parses the XML body by iterating on the token stream
This checks the following errors, in addition to the what the lexer gets:
mismatched opening and closing tags
premature end of document
Parses the XML body by iterating on the token stream This checks the following errors in addition to the what the lexer gets : mismatched opening and closing tags premature end of document
fn xml_body(mxdepth: usize, args: &mut RequestField, body: &[u8]) -> Result<(), String> {
    let body_utf8 = String::from_utf8_lossy(body);
    let mut stack: Vec<(String, u64)> = Vec::new();
    for rtoken in xmlparser::Tokenizer::from(body_utf8.as_ref()) {
        if stack.len() >= mxdepth {
            return Err(format!("XML nesting level exceeded: {}", mxdepth));
        }
        let token = rtoken.map_err(|rr| format!("XML parsing error: {}", rr))?;
        match token {
            Token::ProcessingInstruction { .. } => (),
            Token::Comment { .. } => (),
            Token::Declaration { .. } => (),
            Token::DtdStart { external_id, name, .. } => xml_external_id(args, &stack, name.as_str(), external_id),
            Token::DtdEnd { .. } => (),
            Token::EmptyDtd { external_id, name, .. } => xml_external_id(args, &stack, name.as_str(), external_id),
            Token::EntityDeclaration { name, definition, .. } => match definition {
                EntityDefinition::EntityValue(span) => args.add(
                    "_XMLENTITY_VALUE_".to_string() + name.as_str(),
                    DataSource::FromBody,
                    span.to_string(),
                ),
                EntityDefinition::ExternalId(eid) => xml_external_id(args, &stack, "entity", Some(eid)),
            },
            Token::ElementStart { local, .. } => {
                // increment element index for the current element
                xml_increment_last(&mut stack);
                // and push the new element
                stack.push((local.to_string(), 0))
            }
            Token::ElementEnd { end, .. } => match end {
                //  <foo/>
                ElementEnd::Empty => close_xml_element(args, &mut stack, None)?,
                //  <foo>
                ElementEnd::Open => (),
                //  </foo>
                ElementEnd::Close(_, local) => close_xml_element(args, &mut stack, Some(local.as_str()))?,
            },
            Token::Attribute { local, value, .. } => {
                let path = xml_path(&stack) + local.as_str();
                args.add(path, DataSource::FromBody, value.to_string());
            }
            Token::Text { text } => {
                let trimmed = text.trim();
                if !trimmed.is_empty() {
                    xml_increment_last(&mut stack);
                    args.add(xml_path(&stack), DataSource::FromBody, trimmed.to_string());
                }
            }
            Token::Cdata { text, .. } => {
                xml_increment_last(&mut stack);
                args.add(xml_path(&stack), DataSource::FromBody, text.to_string());
            }
        }
    }
    if stack.is_empty() {
        Ok(())
    } else {
        Err("XML error: premature end of document".to_string())
    }
}
fn xml_body ( mxdepth : usize , args : & mut RequestField , body : & [ u8 ] ) -> Result < ( ) , String > { let body_utf8 = String :: from_utf8_lossy ( body ) ; let mut stack : Vec < ( String , u64 ) > = Vec :: new ( ) ; for rtoken in xmlparser :: Tokenizer :: from ( body_utf8 . as_ref ( ) ) { if stack . len ( ) >= mxdepth { return Err ( format ! ( " " mxdepth ) ) ; } let token = rtoken . map_err ( | rr | format ! ( " " rr ) ) ? ; match token { Token :: ProcessingInstruction { .. } => ( ) , Token :: Comment { .. } => ( ) , Token :: Declaration { .. } => ( ) , Token :: DtdStart { external_id , name , .. } => xml_external_id ( args , & stack , name . as_str ( ) , external_id ) , Token :: DtdEnd { .. } => ( ) , Token :: EmptyDtd { external_id , name , .. } => xml_external_id ( args , & stack , name . as_str ( ) , external_id ) , Token :: EntityDeclaration { name , definition , .. } => match definition { EntityDefinition :: EntityValue ( span ) => args . add ( " " . to_string ( ) + name . as_str ( ) , DataSource :: FromBody , span . to_string ( ) , ) , EntityDefinition :: ExternalId ( eid ) => xml_external_id ( args , & stack , " " , Some ( eid ) ) , } , Token :: ElementStart { local , .. } => { // increment element index for the current element xml_increment_last ( & mut stack ) ; // and push the new element stack . push ( ( local . to_string ( ) , 0 ) ) } Token :: ElementEnd { end , .. } => match end { //  <foo/> ElementEnd :: Empty => close_xml_element ( args , & mut stack , None ) ? , //  <foo> ElementEnd :: Open => ( ) , //  </foo> ElementEnd :: Close ( _ , local ) => close_xml_element ( args , & mut stack , Some ( local . as_str ( ) ) ) ? , } , Token :: Attribute { local , value , .. } => { let path = xml_path ( & stack ) + local . as_str ( ) ; args . add ( path , DataSource :: FromBody , value . to_string ( ) ) ; } Token :: Text { text } => { let trimmed = text . trim ( ) ; if ! trimmed . is_empty ( ) { xml_increment_last ( & mut stack ) ; args . add ( xml_path ( & stack ) , DataSource :: FromBody , trimmed . to_string ( ) ) ; } } Token :: Cdata { text , .. } => { xml_increment_last ( & mut stack ) ; args . add ( xml_path ( & stack ) , DataSource :: FromBody , text . to_string ( ) ) ; } } } if stack . is_empty ( ) { Ok ( ( ) ) } else { Err ( " " . to_string ( ) ) } }
Parses the XML body by iterating on the token stream
This checks the following errors, in addition to the what the lexer gets:
 mismatched opening and closing tags
 premature end of document
Parses the XML body by iterating on the token stream This checks the following errors in addition to the what the lexer gets : mismatched opening and closing tags premature end of document
mxdepth
usize
args
&mut RequestField
body
&[u8]