From: Rob Hoes Date: Tue, 12 Oct 2010 09:36:54 +0000 (+0100) Subject: Require datetime values written to the DB to end with a 'Z' X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=7b96941e1d72adf96dfe410e2a70790c64939b25;p=xcp%2Fxen-api.git Require datetime values written to the DB to end with a 'Z' All datetime values in the DB need to be UTC dates, and are required to ISO 8601 formatted with a trailing 'Z' to indicate they are UTC. The XenAPI did not have any functions that allow users to write datetimes directly to the DB... until recently (e.g. VMPP.set_archive_last_run_time)! It is therefore now necessary to enforce that the datetime values in the parameters of such 'set' functions have the correct form. For backwards compatibility, XenAPI functions such as message.get_since still allow dates without 'Z', and will assume these are UTC dates. Signed-off-by: Rob Hoes --- diff --git a/ocaml/idl/ocaml_backend/exnHelper.ml b/ocaml/idl/ocaml_backend/exnHelper.ml index 8535e41e..54e3bd2a 100644 --- a/ocaml/idl/ocaml_backend/exnHelper.ml +++ b/ocaml/idl/ocaml_backend/exnHelper.ml @@ -47,10 +47,10 @@ let error_of_exn e = | Db_cache.Read_missing_uuid (tbl,ref,uuid) -> uuid_invalid, [ tbl; uuid ] - | Db_actions.DM_to_String.StringEnumTypeError s -> - invalid_value, [ s ] + | Db_actions.DM_to_String.StringEnumTypeError s + | Db_actions.DM_to_String.DateTimeError s | Db_actions.String_to_DM.StringEnumTypeError s -> - invalid_value, [ s ] + invalid_value, [ s ] (* These are the two catch-all patterns. If ever an Errors.Server_error exception *) (* is raised, this is assumed to be an API error, and passed straight on. Any other *) diff --git a/ocaml/idl/ocaml_backend/gen_db_actions.ml b/ocaml/idl/ocaml_backend/gen_db_actions.ml index ffe6623a..68f623fb 100644 --- a/ocaml/idl/ocaml_backend/gen_db_actions.ml +++ b/ocaml/idl/ocaml_backend/gen_db_actions.ml @@ -52,7 +52,7 @@ let dm_to_string tys : O.Module.t = let ty_fun ty = let body = match ty with | DT.Bool -> "string_of_bool" - | DT.DateTime -> "fun x -> Date.to_string x" + | DT.DateTime -> "fun x -> (try Date.assert_utc x with Invalid_argument s -> raise (DateTimeError s)); Date.to_string x" | DT.Enum(name, cs) -> let aux (c, _) = (OU.constructor_of c)^" -> \""^c^"\"" in "\n fun v -> match v with\n "^ @@ -80,6 +80,7 @@ let dm_to_string tys : O.Module.t = O.Module.make ~name:_dm_to_string ~preamble: [ "exception StringEnumTypeError of string"; + "exception DateTimeError of string"; "open String_marshall_helper" ] ~letrec:true ~elements:(List.map (fun ty -> O.Module.Let (ty_fun ty)) tys) ()