[Pkg-libvirt-commits] [libguestfs] 46/72: v2v: xml: Add some more bindings to libxml2.

Hilko Bengen bengen at moszumanska.debian.org
Sun Apr 5 15:19:51 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch master
in repository libguestfs.

commit 3962de4549049e15963dc08657fcd1baa88bcc20
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Fri Mar 6 17:05:50 2015 +0000

    v2v: xml: Add some more bindings to libxml2.
    
    These are not used by libguestfs, but are used by the external
    virt-v2v tests.
    
    (cherry picked from commit c807546619cee0faeedc5ae491f7d6623509b75a)
---
 v2v/xml-c.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 v2v/xml.ml  | 13 +++++++++++
 v2v/xml.mli | 16 +++++++++++++
 3 files changed, 103 insertions(+)

diff --git a/v2v/xml-c.c b/v2v/xml-c.c
index 2c215ca..ca62ba1 100644
--- a/v2v/xml-c.c
+++ b/v2v/xml-c.c
@@ -22,6 +22,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #include <caml/alloc.h>
@@ -121,6 +122,43 @@ v2v_xml_parse_memory (value xmlv)
 }
 
 value
+v2v_xml_copy_doc (value docv, value recursivev)
+{
+  CAMLparam2 (docv, recursivev);
+  CAMLlocal1 (copyv);
+  xmlDocPtr doc, copy;
+
+  doc = Doc_val (docv);
+  copy = xmlCopyDoc (doc, Bool_val (recursivev));
+  if (copy == NULL)
+    caml_invalid_argument ("copy_doc: failed to copy");
+
+  copyv = caml_alloc_custom (&doc_custom_operations, sizeof (xmlDocPtr), 0, 1);
+  Doc_val (copyv) = copy;
+
+  CAMLreturn (copyv);
+}
+
+value
+v2v_xml_to_string (value docv, value formatv)
+{
+  CAMLparam2 (docv, formatv);
+  CAMLlocal1 (strv);
+  xmlDocPtr doc;
+  xmlChar *mem;
+  int size;
+
+  doc = Doc_val (docv);
+  xmlDocDumpFormatMemory (doc, &mem, &size, Bool_val (formatv));
+
+  strv = caml_alloc_string (size);
+  memcpy (String_val (strv), mem, size);
+  free (mem);
+
+  CAMLreturn (strv);
+}
+
+value
 v2v_xml_xpath_new_context (value docv)
 {
   CAMLparam1 (docv);
@@ -269,6 +307,42 @@ v2v_xml_node_ptr_as_string (value docv, value nodev)
 }
 
 value
+v2v_xml_node_ptr_set_content (value nodev, value contentv)
+{
+  CAMLparam2 (nodev, contentv);
+  xmlNodePtr node = (xmlNodePtr) nodev;
+
+  xmlNodeSetContent (node, BAD_CAST String_val (contentv));
+
+  CAMLreturn (Val_unit);
+}
+
+value
+v2v_xml_node_ptr_set_prop (value nodev, value namev, value valv)
+{
+  CAMLparam3 (nodev, namev, valv);
+  xmlNodePtr node = (xmlNodePtr) nodev;
+
+  if (xmlSetProp (node, BAD_CAST String_val (namev), BAD_CAST String_val (valv))
+      == NULL)
+    caml_invalid_argument ("node_ptr_set_prop: failed to set property");
+
+  CAMLreturn (Val_unit);
+}
+
+value
+v2v_xml_node_ptr_unlink_node (value nodev)
+{
+  CAMLparam1 (nodev);
+  xmlNodePtr node = (xmlNodePtr) nodev;
+
+  xmlUnlinkNode (node);
+  xmlFreeNode (node);
+
+  CAMLreturn (Val_unit);
+}
+
+value
 v2v_xml_parse_uri (value strv)
 {
   CAMLparam1 (strv);
diff --git a/v2v/xml.ml b/v2v/xml.ml
index fea8784..8d4a4df 100644
--- a/v2v/xml.ml
+++ b/v2v/xml.ml
@@ -29,6 +29,10 @@ type xpathobj
 type node = doc * node_ptr
 
 external parse_memory : string -> doc = "v2v_xml_parse_memory"
+external copy_doc : doc -> recursive:bool -> doc = "v2v_xml_copy_doc"
+
+external to_string : doc -> format:bool -> string = "v2v_xml_to_string"
+
 external xpath_new_context : doc -> xpathctx = "v2v_xml_xpath_new_context"
 external xpath_eval_expression : xpathctx -> string -> xpathobj = "v2v_xml_xpath_eval_expression"
 external xpath_register_ns : xpathctx -> string -> string -> unit = "v2v_xml_xpath_register_ns"
@@ -50,6 +54,15 @@ external node_ptr_as_string : doc -> node_ptr -> string = "v2v_xml_node_ptr_as_s
 let node_as_string (doc, node) =
   node_ptr_as_string doc node
 
+external node_ptr_set_content : node_ptr -> string -> unit = "v2v_xml_node_ptr_set_content"
+let node_set_content (doc, node) = node_ptr_set_content node
+
+external node_ptr_set_prop : node_ptr -> string -> string -> unit = "v2v_xml_node_ptr_set_prop"
+let set_prop (doc, node) = node_ptr_set_prop node
+
+external node_ptr_unlink_node : node_ptr -> unit = "v2v_xml_node_ptr_unlink_node"
+let unlink_node (doc, node) = node_ptr_unlink_node node
+
 type uri = {
   uri_scheme : string option;
   uri_opaque : string option;
diff --git a/v2v/xml.mli b/v2v/xml.mli
index 890fa4e..82dea33 100644
--- a/v2v/xml.mli
+++ b/v2v/xml.mli
@@ -25,6 +25,12 @@ type xpathobj                           (** xmlXPathObjectPtr *)
 
 val parse_memory : string -> doc
 (** xmlParseMemory (for security reasons it actually calls xmlReadMemory) *)
+val copy_doc : doc -> recursive:bool -> doc
+(** xmlCopyDoc *)
+
+val to_string : doc -> format:bool -> string
+(** xmlDocDumpFormatMemory *)
+
 val xpath_new_context : doc -> xpathctx
 (** xmlXPathNewContext *)
 val xpath_eval_expression : xpathctx -> string -> xpathobj
@@ -58,6 +64,16 @@ val node_name : node -> string
 val node_as_string : node -> string
 (** Converter to turn a node into a string *)
 
+val node_set_content : node -> string -> unit
+(** xmlNodeSetContent *)
+
+val set_prop : node -> string -> string -> unit
+(** xmlSetProp *)
+
+val unlink_node : node -> unit
+(** xmlUnlinkNode
+    {b NB:} This frees the [node], do not use it afterwards. *)
+
 type uri = {
   uri_scheme : string option;
   uri_opaque : string option;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list