[Pkg-libvirt-commits] [libguestfs] 136/266: v2v: Add binding for libxml2 xmlParseURI.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:41:53 UTC 2014


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

bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.

commit 7800150d06a6ec73194def6d05f90273aa40205e
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Wed Aug 20 12:04:32 2014 +0100

    v2v: Add binding for libxml2 xmlParseURI.
    
    There is already a partial binding for this in fish/uri.c &
    mllib/uri-c.c.  However it is specialized to parsing the -a parameter
    on the command line and we want access to the full underlying
    functionality of xmlParseURI.
---
 v2v/xml-c.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 v2v/xml.ml  | 16 ++++++++++-
 v2v/xml.mli | 21 +++++++++++++-
 3 files changed, 130 insertions(+), 3 deletions(-)

diff --git a/v2v/xml-c.c b/v2v/xml-c.c
index cf5bff2..4c9bc77 100644
--- a/v2v/xml-c.c
+++ b/v2v/xml-c.c
@@ -16,7 +16,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-/* Mini interface to libxml2 for parsing libvirt XML. */
+/* Mini interface to libxml2. */
 
 #include <config.h>
 
@@ -31,6 +31,7 @@
 #include <caml/mlvalues.h>
 
 #include <libxml/xpath.h>
+#include <libxml/uri.h>
 
 #include "guestfs.h"
 #include "guestfs-internal-frontend.h"
@@ -245,3 +246,96 @@ v2v_xml_node_ptr_as_string (value docv, value nodev)
     caml_invalid_argument ("node_as_string: don't know how to convert this node to a string");
   }
 }
+
+value
+v2v_xml_parse_uri (value strv)
+{
+  CAMLparam1 (strv);
+  CAMLlocal3 (rv, sv, ov);
+  xmlURIPtr uri;
+
+  uri = xmlParseURI (String_val (strv));
+  if (uri == NULL)
+    caml_invalid_argument ("parse_uri: unable to parse URI");
+
+  rv = caml_alloc_tuple (9);
+
+  /* field 0: uri_scheme : string option */
+  if (uri->scheme) {
+    sv = caml_copy_string (uri->scheme);
+    ov = caml_alloc (1, 0);
+    Store_field (ov, 0, sv);
+  }
+  else ov = Val_int (0);
+  Store_field (rv, 0, ov);
+
+  /* field 1: uri_opaque : string option */
+  if (uri->opaque) {
+    sv = caml_copy_string (uri->opaque);
+    ov = caml_alloc (1, 0);
+    Store_field (ov, 0, sv);
+  }
+  else ov = Val_int (0);
+  Store_field (rv, 1, ov);
+
+  /* field 2: uri_authority : string option */
+  if (uri->authority) {
+    sv = caml_copy_string (uri->authority);
+    ov = caml_alloc (1, 0);
+    Store_field (ov, 0, sv);
+  }
+  else ov = Val_int (0);
+  Store_field (rv, 2, ov);
+
+  /* field 3: uri_server : string option */
+  if (uri->server) {
+    sv = caml_copy_string (uri->server);
+    ov = caml_alloc (1, 0);
+    Store_field (ov, 0, sv);
+  }
+  else ov = Val_int (0);
+  Store_field (rv, 3, ov);
+
+  /* field 4: uri_user : string option */
+  if (uri->user) {
+    sv = caml_copy_string (uri->user);
+    ov = caml_alloc (1, 0);
+    Store_field (ov, 0, sv);
+  }
+  else ov = Val_int (0);
+  Store_field (rv, 4, ov);
+
+  /* field 5: uri_port : int */
+  Store_field (rv, 5, Val_int (uri->port));
+
+  /* field 6: uri_path : string option */
+  if (uri->path) {
+    sv = caml_copy_string (uri->path);
+    ov = caml_alloc (1, 0);
+    Store_field (ov, 0, sv);
+  }
+  else ov = Val_int (0);
+  Store_field (rv, 6, ov);
+
+  /* field 7: uri_fragment : string option */
+  if (uri->fragment) {
+    sv = caml_copy_string (uri->fragment);
+    ov = caml_alloc (1, 0);
+    Store_field (ov, 0, sv);
+  }
+  else ov = Val_int (0);
+  Store_field (rv, 7, ov);
+
+  /* field 8: uri_query_raw : string option */
+  if (uri->query_raw) {
+    sv = caml_copy_string (uri->query_raw);
+    ov = caml_alloc (1, 0);
+    Store_field (ov, 0, sv);
+  }
+  else ov = Val_int (0);
+  Store_field (rv, 8, ov);
+
+  xmlFreeURI (uri);
+
+  CAMLreturn (rv);
+}
diff --git a/v2v/xml.ml b/v2v/xml.ml
index 5cd75c1..78cb022 100644
--- a/v2v/xml.ml
+++ b/v2v/xml.ml
@@ -16,7 +16,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
-(* Mini interface to libxml2 for parsing libvirt XML. *)
+(* Mini interface to libxml2. *)
 
 type doc
 type node_ptr
@@ -48,3 +48,17 @@ let node_name (_, node) = node_ptr_name node
 external node_ptr_as_string : doc -> node_ptr -> string = "v2v_xml_node_ptr_as_string"
 let node_as_string (doc, node) =
   node_ptr_as_string doc node
+
+type uri = {
+  uri_scheme : string option;
+  uri_opaque : string option;
+  uri_authority : string option;
+  uri_server : string option;
+  uri_user : string option;
+  uri_port : int;
+  uri_path : string option;
+  uri_fragment : string option;
+  uri_query_raw : string option;
+}
+
+external parse_uri : string -> uri = "v2v_xml_parse_uri"
diff --git a/v2v/xml.mli b/v2v/xml.mli
index 83d669d..38bb9cd 100644
--- a/v2v/xml.mli
+++ b/v2v/xml.mli
@@ -16,7 +16,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
-(** Mini interface to libxml2 for parsing libvirt XML. *)
+(** Mini interface to libxml2. *)
 
 type doc                                (** xmlDocPtr *)
 type node                               (** xmlNodePtr *)
@@ -55,3 +55,22 @@ val node_name : node -> string
 
 val node_as_string : node -> string
 (** Converter to turn a node into a string *)
+
+type uri = {
+  uri_scheme : string option;
+  uri_opaque : string option;
+  uri_authority : string option;
+  uri_server : string option;
+  uri_user : string option;
+  uri_port : int;
+  uri_path : string option;
+  uri_fragment : string option;
+  uri_query_raw : string option;
+}
+
+val parse_uri : string -> uri
+(** Parse URI.
+
+    Note this is different from the {!URI} module which is specialized
+    for parsing the [-a] parameter on the command line.  This function
+    exposes the full [xmlParseURI] interface. *)

-- 
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