|
|
cd6068 |
From d1758344fa7e87002de857328af2963ff6fab7e1 Mon Sep 17 00:00:00 2001
|
|
|
cd6068 |
From: Pino Toscano <ptoscano@redhat.com>
|
|
|
cd6068 |
Date: Thu, 6 Feb 2014 20:02:51 +0100
|
|
|
cd6068 |
Subject: [PATCH] generator: generate code for parameter validation
|
|
|
cd6068 |
|
|
|
cd6068 |
Implemented only in the C output, since every binding uses it anyway,
|
|
|
cd6068 |
and just for the "GUID" type (since its format is well-known).
|
|
|
cd6068 |
|
|
|
cd6068 |
(cherry picked from commit 775cad63a3f2156b38e7d8360b88ed11615779e8)
|
|
|
cd6068 |
---
|
|
|
cd6068 |
generator/c.ml | 43 +++++++++++++++++++++++++++++++++++++++++++
|
|
|
cd6068 |
1 file changed, 43 insertions(+)
|
|
|
cd6068 |
|
|
|
cd6068 |
diff --git a/generator/c.ml b/generator/c.ml
|
|
|
cd6068 |
index 1ce9e9f..2137c7e 100644
|
|
|
cd6068 |
--- a/generator/c.ml
|
|
|
cd6068 |
+++ b/generator/c.ml
|
|
|
cd6068 |
@@ -1048,6 +1048,47 @@ and generate_client_actions hash () =
|
|
|
cd6068 |
pr "\n";
|
|
|
cd6068 |
in
|
|
|
cd6068 |
|
|
|
cd6068 |
+ (* Generate code to check for parameter validation (where supported
|
|
|
cd6068 |
+ * for the type).
|
|
|
cd6068 |
+ *)
|
|
|
cd6068 |
+ let check_args_validity c_name (ret, args, optargs) =
|
|
|
cd6068 |
+ let pr_newline = ref false in
|
|
|
cd6068 |
+ List.iter (
|
|
|
cd6068 |
+ function
|
|
|
cd6068 |
+ | GUID n ->
|
|
|
cd6068 |
+ pr " if (!guestfs___validate_guid (%s)) {\n" n;
|
|
|
cd6068 |
+ pr " error (g, \"%%s: %%s: parameter is not a valid GUID\",\n";
|
|
|
cd6068 |
+ pr " \"%s\", \"%s\");\n" c_name n;
|
|
|
cd6068 |
+ let errcode =
|
|
|
cd6068 |
+ match errcode_of_ret ret with
|
|
|
cd6068 |
+ | `CannotReturnError -> assert false
|
|
|
cd6068 |
+ | (`ErrorIsMinusOne |`ErrorIsNULL) as e -> e in
|
|
|
cd6068 |
+ pr " return %s;\n" (string_of_errcode errcode);
|
|
|
cd6068 |
+ pr " }\n";
|
|
|
cd6068 |
+ pr_newline := true
|
|
|
cd6068 |
+
|
|
|
cd6068 |
+ (* not applicable *)
|
|
|
cd6068 |
+ | String _
|
|
|
cd6068 |
+ | Device _
|
|
|
cd6068 |
+ | Mountable _
|
|
|
cd6068 |
+ | Pathname _
|
|
|
cd6068 |
+ | Dev_or_Path _ | Mountable_or_Path _
|
|
|
cd6068 |
+ | FileIn _
|
|
|
cd6068 |
+ | FileOut _
|
|
|
cd6068 |
+ | BufferIn _
|
|
|
cd6068 |
+ | StringList _
|
|
|
cd6068 |
+ | DeviceList _
|
|
|
cd6068 |
+ | Key _
|
|
|
cd6068 |
+ | Pointer (_, _)
|
|
|
cd6068 |
+ | OptString _
|
|
|
cd6068 |
+ | Bool _
|
|
|
cd6068 |
+ | Int _
|
|
|
cd6068 |
+ | Int64 _ -> ()
|
|
|
cd6068 |
+ ) args;
|
|
|
cd6068 |
+
|
|
|
cd6068 |
+ if !pr_newline then pr "\n";
|
|
|
cd6068 |
+ in
|
|
|
cd6068 |
+
|
|
|
cd6068 |
(* Generate code to generate guestfish call traces. *)
|
|
|
cd6068 |
let trace_call name c_name (ret, args, optargs) =
|
|
|
cd6068 |
pr " if (trace_flag) {\n";
|
|
|
cd6068 |
@@ -1266,6 +1307,7 @@ and generate_client_actions hash () =
|
|
|
cd6068 |
enter_event name;
|
|
|
cd6068 |
check_null_strings c_name style;
|
|
|
cd6068 |
reject_unknown_optargs c_name style;
|
|
|
cd6068 |
+ check_args_validity c_name style;
|
|
|
cd6068 |
trace_call name c_name style;
|
|
|
cd6068 |
pr " r = guestfs__%s " c_name;
|
|
|
cd6068 |
generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style;
|
|
|
cd6068 |
@@ -1368,6 +1410,7 @@ and generate_client_actions hash () =
|
|
|
cd6068 |
enter_event name;
|
|
|
cd6068 |
check_null_strings c_name style;
|
|
|
cd6068 |
reject_unknown_optargs c_name style;
|
|
|
cd6068 |
+ check_args_validity c_name style;
|
|
|
cd6068 |
trace_call name c_name style;
|
|
|
cd6068 |
|
|
|
cd6068 |
(* Calculate the total size of all FileIn arguments to pass
|
|
|
cd6068 |
--
|
|
|
cd6068 |
1.8.3.1
|
|
|
cd6068 |
|