[Pkg-libvirt-commits] [libguestfs] 192/233: generator: generate code for parameter validation

Hilko Bengen bengen at moszumanska.debian.org
Wed Feb 19 21:12:22 UTC 2014


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

bengen pushed a commit to branch experimental
in repository libguestfs.

commit 775cad63a3f2156b38e7d8360b88ed11615779e8
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Thu Feb 6 20:02:51 2014 +0100

    generator: generate code for parameter validation
    
    Implemented only in the C output, since every binding uses it anyway,
    and just for the "GUID" type (since its format is well-known).
---
 generator/c.ml | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/generator/c.ml b/generator/c.ml
index e2d5754..c3185be 100644
--- a/generator/c.ml
+++ b/generator/c.ml
@@ -1329,6 +1329,47 @@ and generate_client_actions hash () =
         pr "\n";
   in
 
+  (* Generate code to check for parameter validation (where supported
+   * for the type).
+   *)
+  let check_args_validity c_name (ret, args, optargs) =
+    let pr_newline = ref false in
+    List.iter (
+      function
+      | GUID n ->
+          pr "  if (!guestfs___validate_guid (%s)) {\n" n;
+          pr "    error (g, \"%%s: %%s: parameter is not a valid GUID\",\n";
+          pr "           \"%s\", \"%s\");\n" c_name n;
+          let errcode =
+            match errcode_of_ret ret with
+            | `CannotReturnError -> assert false
+            | (`ErrorIsMinusOne |`ErrorIsNULL) as e -> e in
+          pr "    return %s;\n" (string_of_errcode errcode);
+          pr "  }\n";
+          pr_newline := true
+
+      (* not applicable *)
+      | String _
+      | Device _
+      | Mountable _
+      | Pathname _
+      | Dev_or_Path _ | Mountable_or_Path _
+      | FileIn _
+      | FileOut _
+      | BufferIn _
+      | StringList _
+      | DeviceList _
+      | Key _
+      | Pointer (_, _)
+      | OptString _
+      | Bool _
+      | Int _
+      | Int64 _ -> ()
+    ) args;
+
+    if !pr_newline then pr "\n";
+  in
+
   (* Generate code to generate guestfish call traces. *)
   let trace_call name c_name (ret, args, optargs) =
     pr "  if (trace_flag) {\n";
@@ -1547,6 +1588,7 @@ and generate_client_actions hash () =
     enter_event name;
     check_null_strings c_name style;
     reject_unknown_optargs c_name style;
+    check_args_validity c_name style;
     trace_call name c_name style;
     pr "  r = guestfs__%s " c_name;
     generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style;
@@ -1649,6 +1691,7 @@ and generate_client_actions hash () =
     enter_event name;
     check_null_strings c_name style;
     reject_unknown_optargs c_name style;
+    check_args_validity c_name style;
     trace_call name c_name style;
 
     (* Calculate the total size of all FileIn arguments to pass

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