Switch all the links to https
[ocaml-libvirt.git] / libvirt / generator.pl
index 34801ba..490ef9a 100755 (executable)
@@ -2,7 +2,7 @@
 #
 # OCaml bindings for libvirt.
 # (C) Copyright 2007-2015 Richard W.M. Jones, Red Hat Inc.
-# http://libvirt.org/
+# https://libvirt.org/
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -58,6 +58,8 @@ my @functions = (
       sig => "conn : int" },
     { name => "virConnectListDefinedStoragePools",
       sig => "conn, int : string array" },
+    { name => "virConnectNumOfSecrets", sig => "conn : int" },
+    { name => "virConnectListSecrets", sig => "conn, int : string array" },
     { name => "virConnectGetCapabilities", sig => "conn : string" },
     { name => "virConnectDomainEventDeregisterAny",
       sig => "conn, int : unit" },
@@ -169,6 +171,17 @@ my @functions = (
     { name => "virStoragePoolLookupByVolume",
       sig => "vol : pool from vol" },
 
+    { name => "virSecretFree", sig => "sec : free" },
+    { name => "virSecretUndefine", sig => "sec : unit" },
+    { name => "virSecretLookupByUUID", sig => "conn, uuid : sec" },
+    { name => "virSecretLookupByUUIDString", sig => "conn, string : sec" },
+    { name => "virSecretDefineXML", sig => "conn, string, 0 : sec" },
+    { name => "virSecretGetUUID", sig => "sec : uuid" },
+    { name => "virSecretGetUUIDString", sig => "sec : uuid string" },
+    { name => "virSecretGetUsageType", sig => "sec : int" },
+    { name => "virSecretGetUsageID", sig => "sec : static string" },
+    { name => "virSecretGetXMLDesc", sig => "sec, 0 : string" },
+
     );
 
 # Functions we haven't implemented anywhere yet but which are mentioned
@@ -200,7 +213,7 @@ print F <<'END';
 
 /* OCaml bindings for libvirt.
  * (C) Copyright 2007-2015 Richard W.M. Jones, Red Hat Inc.
- * http://libvirt.org/
+ * https://libvirt.org/
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -266,6 +279,7 @@ sub short_name_to_c_type
     elsif ($_ eq "net") { "virNetworkPtr" }
     elsif ($_ eq "pool") { "virStoragePoolPtr" }
     elsif ($_ eq "vol") { "virStorageVolPtr" }
+    elsif ($_ eq "sec") { "virSecretPtr" }
     else {
        die "unknown short name $_"
     }
@@ -350,6 +364,8 @@ sub gen_unpack_args
        "virStoragePoolPtr pool = Pool_val (poolv);"
     } elsif ($_ eq "vol") {
        "virStorageVolPtr vol = Volume_val (volv);"
+    } elsif ($_ eq "sec") {
+       "virSecretPtr sec = Secret_val (secv);"
     } else {
        die "unknown short name $_"
     }
@@ -365,6 +381,7 @@ sub gen_pack_result
     elsif ($_ eq "net") {  "rv = Val_network (r, connv);" }
     elsif ($_ eq "pool") { "rv = Val_pool (r, connv);" }
     elsif ($_ eq "vol") {  "rv = Val_volume (r, connv);" }
+    elsif ($_ eq "sec") {  "rv = Val_secret (r, connv);" }
     else {
        die "unknown short name $_"
     }
@@ -379,6 +396,7 @@ sub gen_free_arg
     elsif ($_ eq "net") {   "Network_val (netv) = NULL;" }
     elsif ($_ eq "pool") {  "Pool_val (poolv) = NULL;" }
     elsif ($_ eq "vol") {   "Volume_val (volv) = NULL;" }
+    elsif ($_ eq "sec") {   "Secret_val (secv) = NULL;" }
     else {
        die "unknown short name $_"
     }
@@ -481,7 +499,7 @@ sub gen_c_code
   CAMLlocal1 (rv);
   virConnectPtr conn = Connect_val (connv);
   int i = Int_val (iv);
-  int ids[i], r;
+  int *ids, r;
 
   /* Some libvirt List* functions still throw exceptions if i == 0,
    * so catch that and return an empty array directly.  This changes
@@ -493,12 +511,17 @@ sub gen_c_code
     CAMLreturn (rv);
   }
 
+  ids = malloc (sizeof (*ids) * i);
+  if (ids == NULL)
+    caml_raise_out_of_memory ();
+
   NONBLOCKING (r = $c_name (conn, ids, i));
-  CHECK_ERROR (r == -1, \"$c_name\");
+  CHECK_ERROR_CLEANUP (r == -1, free (ids), \"$c_name\");
 
   rv = caml_alloc (r, 0);
   for (i = 0; i < r; ++i)
     Store_field (rv, i, Val_int (ids[i]));
+  free (ids);
 
   CAMLreturn (rv);
 "
@@ -507,7 +530,7 @@ sub gen_c_code
   CAMLlocal2 (rv, strv);
   " . gen_unpack_args ($1) . "
   int i = Int_val (iv);
-  char *names[i];
+  char **names;
   int r;
 
   /* Some libvirt List* functions still throw exceptions if i == 0,
@@ -520,8 +543,12 @@ sub gen_c_code
     CAMLreturn (rv);
   }
 
+  names = malloc (sizeof (*names) * i);
+  if (names == NULL)
+    caml_raise_out_of_memory ();
+
   NONBLOCKING (r = $c_name ($1, names, i));
-  CHECK_ERROR (r == -1, \"$c_name\");
+  CHECK_ERROR_CLEANUP (r == -1, free (names), \"$c_name\");
 
   rv = caml_alloc (r, 0);
   for (i = 0; i < r; ++i) {
@@ -529,6 +556,7 @@ sub gen_c_code
     Store_field (rv, i, strv);
     free (names[i]);
   }
+  free (names);
 
   CAMLreturn (rv);
 "