summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2022-02-10 07:11:29 +0100
committerGitHub <noreply@github.com>2022-02-10 07:11:29 +0100
commit428a0ad258a7198edee0eced1023049fdc858b93 (patch)
treed396d6f5fdf81ae48d99982954f0232803103660
parent153dbd35270eafc984415369f4c05a47f5d64283 (diff)
parenteb2ec50dea6fa47326cbbe65b47c31a3a86836ba (diff)
downloadlibvyosconfig-428a0ad258a7198edee0eced1023049fdc858b93.tar.gz
libvyosconfig-428a0ad258a7198edee0eced1023049fdc858b93.zip
Merge pull request #3 from jestabro/config-diff
T4235: binding for config tree diff function
-rw-r--r--lib/bindings.ml26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/bindings.ml b/lib/bindings.ml
index 9324282..484a5d7 100644
--- a/lib/bindings.ml
+++ b/lib/bindings.ml
@@ -4,6 +4,7 @@ open Foreign
open Vyos1x
module CT = Config_tree
+module CD = Config_diff
let error_message = ref ""
@@ -45,8 +46,12 @@ let render_json c_ptr =
let render_json_ast c_ptr =
CT.render_json_ast (Root.get c_ptr)
-let render_commands c_ptr =
- CT.render_commands (Root.get c_ptr) []
+let render_commands c_ptr op =
+ match op with
+ | "delete" ->
+ CT.render_commands ~op:CT.Delete (Root.get c_ptr) []
+ | _ ->
+ CT.render_commands ~op:CT.Set (Root.get c_ptr) []
let set_add_value c_ptr path value =
let ct = Root.get c_ptr in
@@ -154,6 +159,20 @@ let copy_node c_ptr old_path new_path =
0
with Vytree.Nonexistent_path -> 1
+let diffs path c_ptr_l c_ptr_r =
+ let path = split_on_whitespace path in
+ let ct_l = Root.get c_ptr_l in
+ let ct_r = Root.get c_ptr_r in
+ try
+ let ct_add, ct_del, ct_inter = CD.diffs path ct_l ct_r in
+ let ptr_add = Ctypes.Root.create ct_add in
+ let ptr_del = Ctypes.Root.create ct_del in
+ let ptr_inter = Ctypes.Root.create ct_inter in
+ let ptr_arr = Ctypes.CArray.make (ptr void) ~initial:ptr_add 3 in Ctypes.CArray.set ptr_arr 1 ptr_del; Ctypes.CArray.set ptr_arr 2 ptr_inter; Ctypes.CArray.start ptr_arr
+
+ with
+ | CD.Incommensurable -> error_message := "Incommensurable"; Ctypes.CArray.start (Ctypes.CArray.make (ptr void) 3)
+ | CD.Empty_comparison -> error_message := "Empty comparison"; Ctypes.CArray.start (Ctypes.CArray.make (ptr void) 3)
module Stubs(I : Cstubs_inverted.INTERNAL) =
struct
@@ -165,7 +184,7 @@ struct
let () = I.internal "to_string" ((ptr void) @-> returning string) render_config
let () = I.internal "to_json" ((ptr void) @-> returning string) render_json
let () = I.internal "to_json_ast" ((ptr void) @-> returning string) render_json_ast
- let () = I.internal "to_commands" ((ptr void) @-> returning string) render_commands
+ let () = I.internal "to_commands" ((ptr void) @-> string @-> returning string) render_commands
let () = I.internal "set_add_value" ((ptr void) @-> string @-> string @-> returning int) set_add_value
let () = I.internal "set_replace_value" ((ptr void) @-> string @-> string @-> returning int) set_replace_value
let () = I.internal "set_valueless" ((ptr void) @-> string @-> returning int) set_valueless
@@ -179,4 +198,5 @@ struct
let () = I.internal "list_nodes" ((ptr void) @-> string @-> returning string) list_nodes
let () = I.internal "return_value" ((ptr void) @-> string @-> returning string) return_value
let () = I.internal "return_values" ((ptr void) @-> string @-> returning string) return_values
+ let () = I.internal "diffs" (string @-> (ptr void) @-> (ptr void) @-> returning (ptr (ptr void))) diffs
end