[librsvg: 7/20] xml2_load.rs: Switch to using the namespaced SAX2 callbacks



commit 735910b8eea59d8d61d39f7a3d707f92650bad26
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue May 28 18:58:14 2019 -0500

    xml2_load.rs: Switch to using the namespaced SAX2 callbacks
    
    The tests fail currently as we are outputting "xlink:href" attributes
    as just "href", and dropping the namespace.

 rsvg_internals/src/xml2.rs      | 13 ++----------
 rsvg_internals/src/xml2_load.rs | 46 +++++++++++++++++++++++++++--------------
 2 files changed, 32 insertions(+), 27 deletions(-)
---
diff --git a/rsvg_internals/src/xml2.rs b/rsvg_internals/src/xml2.rs
index f7dbf39e..05118213 100644
--- a/rsvg_internals/src/xml2.rs
+++ b/rsvg_internals/src/xml2.rs
@@ -60,17 +60,8 @@ pub struct xmlSAXHandler {
     pub setDocumentLocator: UnusedFn,
     pub startDocument:      UnusedFn,
     pub endDocument:        UnusedFn,
-
-    pub startElement: Option<unsafe extern "C" fn(
-        ctx: *mut libc::c_void,
-        name: *const libc::c_char,
-        atts: *const *const libc::c_char,
-    )>,
-
-    pub endElement: Option<unsafe extern "C" fn(
-        ctx: *mut libc::c_void,
-        name: *const libc::c_char,
-    )>,
+    pub startElement:       UnusedFn,
+    pub endElement:         UnusedFn,
 
     pub reference: UnusedFn,
 
diff --git a/rsvg_internals/src/xml2_load.rs b/rsvg_internals/src/xml2_load.rs
index 7e50a33d..12e60267 100644
--- a/rsvg_internals/src/xml2_load.rs
+++ b/rsvg_internals/src/xml2_load.rs
@@ -42,8 +42,6 @@ fn get_xml2_sax_handler() -> xmlSAXHandler {
         error:                 None,
         fatalError:            None,
         externalSubset:        None,
-        startElementNs:        None,
-        endElementNs:          None,
 
         _private:              ptr::null_mut(),
 
@@ -54,12 +52,14 @@ fn get_xml2_sax_handler() -> xmlSAXHandler {
         getParameterEntity:    Some(sax_get_parameter_entity_cb),
         characters:            Some(sax_characters_cb),
         cdataBlock:            Some(sax_characters_cb),
-        startElement:          Some(sax_start_element_cb),
-        endElement:            Some(sax_end_element_cb),
+        startElement:          None,
+        endElement:            None,
         processingInstruction: Some(sax_processing_instruction_cb),
+        startElementNs:        Some(sax_start_element_ns_cb),
+        endElementNs:          Some(sax_end_element_ns_cb),
         serror:                Some(rsvg_sax_serror_cb),
 
-        initialized:           0,
+        initialized:           XML_SAX2_MAGIC,
     }
 }
 
@@ -173,19 +173,28 @@ unsafe extern "C" fn sax_unparsed_entity_decl_cb(
     );
 }
 
-unsafe extern "C" fn sax_start_element_cb(
+unsafe extern "C" fn sax_start_element_ns_cb(
     user_data: *mut libc::c_void,
-    name: *const libc::c_char,
-    atts: *const *const libc::c_char,
+    localname: *mut libc::c_char,
+    prefix: *mut libc::c_char,
+    uri: *mut libc::c_char,
+    nb_namespaces: libc::c_int,
+    namespaces: *mut *mut libc::c_char,
+    nb_attributes: libc::c_int,
+    nb_defaulted: libc::c_int,
+    attributes: *mut *mut libc::c_char,
 ) {
     let xml2_parser = &*(user_data as *mut Xml2Parser);
 
-    assert!(!name.is_null());
-    let name = utf8_cstr(name);
+    assert!(!localname.is_null());
+
+    let localname = utf8_cstr(localname);
 
-    let pbag = PropertyBag::new_from_key_value_pairs(atts);
+    let nb_attributes = nb_attributes as usize;
+    let pbag =
+        PropertyBag::new_from_namespaced_attributes(nb_attributes, attributes as *const *const _);
 
-    if let Err(e) = xml2_parser.state.start_element(name, &pbag) {
+    if let Err(e) = xml2_parser.state.start_element(localname, &pbag) {
         let _: () = e; // guard in case we change the error type later
 
         let parser = xml2_parser.parser.get();
@@ -193,13 +202,18 @@ unsafe extern "C" fn sax_start_element_cb(
     }
 }
 
-unsafe extern "C" fn sax_end_element_cb(user_data: *mut libc::c_void, name: *const libc::c_char) {
+unsafe extern "C" fn sax_end_element_ns_cb(
+    user_data: *mut libc::c_void,
+    localname: *mut libc::c_char,
+    prefix: *mut libc::c_char,
+    uri: *mut libc::c_char,
+) {
     let xml2_parser = &*(user_data as *mut Xml2Parser);
 
-    assert!(!name.is_null());
-    let name = utf8_cstr(name);
+    assert!(!localname.is_null());
+    let localname = utf8_cstr(localname);
 
-    xml2_parser.state.end_element(name);
+    xml2_parser.state.end_element(localname);
 }
 
 unsafe extern "C" fn sax_characters_cb(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]