diff options
author | defanor <defanor@uberspace.net> | 2023-05-23 12:05:13 +0300 |
---|---|---|
committer | defanor <defanor@uberspace.net> | 2023-05-23 12:05:13 +0300 |
commit | 122b13ec955deb718aca280112584b645c9caea0 (patch) | |
tree | fdaa1dce84956a33f669605e67df1a587a01fc1d /examples | |
parent | ae42bb94fd49a450690014b6039a812a251f64cd (diff) |
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.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/basic.c | 13 |
1 files changed, 8 insertions, 5 deletions
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 <gsasl.h> #include <time.h> #include <rexmpp.h> +#include <rexmpp_xml.h> #include <rexmpp_sasl.h> 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"); |