From 122b13ec955deb718aca280112584b645c9caea0 Mon Sep 17 00:00:00 2001 From: defanor Date: Tue, 23 May 2023 12:05:13 +0300 Subject: Replace libxml2's xmlNode with a custom XML structure The new structure (rexmpp_xml) is simpler, and should allow manipulation from Rust without any dependency on libxml2 from the Rust code (while Rust has its own parsers, such as rxml). Alternative XML parsers (e.g., libexpat) now can be used from the C code. The replacement/abstraction is not quite complete yet: the parsing process itself (xmlParseChunk and friends) should be abstracted out. --- examples/basic.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/basic.c b/examples/basic.c index 982106a..66c54f6 100644 --- a/examples/basic.c +++ b/examples/basic.c @@ -13,6 +13,7 @@ #include #include #include +#include #include int log_level = 8; @@ -66,7 +67,7 @@ int my_sasl_property_cb (rexmpp_t *s, rexmpp_sasl_property prop) { } /* An XML in callback, printing what was received. */ -int my_xml_in_cb (rexmpp_t *s, xmlNodePtr node) { +int my_xml_in_cb (rexmpp_t *s, rexmpp_xml_t *node) { char *xml_buf = rexmpp_xml_serialize(node); printf("recv: %s\n", xml_buf); free(xml_buf); @@ -74,7 +75,7 @@ int my_xml_in_cb (rexmpp_t *s, xmlNodePtr node) { } /* An XML out callback, printing what is about to be sent. */ -int my_xml_out_cb (rexmpp_t *s, xmlNodePtr node) { +int my_xml_out_cb (rexmpp_t *s, rexmpp_xml_t *node) { char *xml_buf = rexmpp_xml_serialize(node); printf("send: %s\n", xml_buf); free(xml_buf); @@ -178,9 +179,11 @@ int main (int argc, char **argv) { /* Raw XML input. */ xmlDocPtr doc = xmlReadMemory(input, input_len, "", "utf-8", 0); if (doc != NULL) { - xmlNodePtr node = xmlDocGetRootElement(doc); - if (node != NULL) { - xmlUnlinkNode(node); + xmlNodePtr node_libxml2 = xmlDocGetRootElement(doc); + if (node_libxml2 != NULL) { + xmlUnlinkNode(node_libxml2); + rexmpp_xml_t *node = rexmpp_xml_from_libxml2(node_libxml2); + xmlFreeNode(node_libxml2); rexmpp_send(&s, node); } else { puts("No root node"); -- cgit v1.2.3