# HG changeset patch
# User John Aspden <john.aspden@xensource.com>
# Date 1194957388 0
# Node ID 212dd2e2b166e496681b7531e6c075d08cefa58f
# Parent  cfceb249cbfd3126f61089e6713655e21722eb02
modification to the server code to record in its log file when exceptions not listed in the data model are thrown.

To see the output, you must also comment out the line

log = debug;dispatcher;nil

in /etc/xapi.conf on the server.

diff -r cfceb249cbfd -r 212dd2e2b166 ocaml/idl/ocaml_backend/gen_server.ml
--- a/ocaml/idl/ocaml_backend/gen_server.ml	Tue Nov 13 10:33:34 2007 +0000
+++ b/ocaml/idl/ocaml_backend/gen_server.ml	Tue Nov 13 12:36:28 2007 +0000
@@ -243,7 +243,7 @@ let gen_module api : O.Module.t =
 	      "  Fault(0l, \"No async mode for this operation (rpc: \"^__call^\")\") in" ] @
 	      [
 	      debug "%s %s" [ "__call"; "(if __async then \"(async)\" else \"\")" ];
-	      "Server_helpers.dispatch_exn_wrapper (fun () -> (match (__call, __params) with ";
+	      "Server_helpers.dispatch_exn_wrapper __call (fun () -> (match (__call, __params) with ";
 	    ] @ (List.flatten (List.map obj all_objs)) @ [
 		"| func, args -> ";
 		"  " ^ (debug "Unknown rpc \"%s\"" [ "__call" ]);
diff -r cfceb249cbfd -r 212dd2e2b166 ocaml/idl/ocaml_backend/server_helpers.ml
--- a/ocaml/idl/ocaml_backend/server_helpers.ml	Tue Nov 13 10:33:34 2007 +0000
+++ b/ocaml/idl/ocaml_backend/server_helpers.ml	Tue Nov 13 12:36:28 2007 +0000
@@ -1,5 +1,6 @@ open Locking_helpers
 open Locking_helpers
 open Stringext
+
 
 module D = Debug.Debugger(struct let name = "dispatcher" end)
 open D
@@ -88,10 +89,29 @@ let empty_context =
     Context.origin = Context.Internal "server_helpers: empty_context";
     Context.name = "empty_context" }
 
-let dispatch_exn_wrapper f =
+
+open Datamodel_types;;
+open Dm_api;;
+
+let classes = objects_of_api Datamodel.all_api;;
+
+
+let dispatch_exn_wrapper __call f =
   try
     f()
-  with exn -> let code, params = ExnHelper.error_of_exn exn in XMLRPC.Failure(code, params)
+  with exn -> let code, params = ExnHelper.error_of_exn exn in 
+    begin
+      (**when an exception is thrown, check that the data model allows it for this call. If not, then log the mismatch.*)
+      let lst = (String.split '.' __call) in 
+      let object_name = (List.hd lst) in 
+      let message_name = (List.hd (List.tl lst)) in
+      let datamodel_class = (List.find (fun x -> x.name=object_name) classes) in
+      let datamodel_message = (List.find (fun x -> x.msg_name=message_name) datamodel_class.messages) in
+      let allowed_errors = (List.map (fun x -> x.err_name) datamodel_message.msg_errors) in
+      let found = List.mem code allowed_errors in 
+	if (not found) then debug "(unlisted exception is being thrown) %s %s" __call code;
+	XMLRPC.Failure(code, params)
+    end
 
 (** Called by autogenerated dispatch code *)
 let do_dispatch ?session_id ?forward_op ?op_fn ?self __type called_async supports_async called_fn_name op_fn
