summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2019-02-14 22:55:52 +0100
committerDaniil Baturin <daniil@baturin.org>2019-02-14 23:38:33 +0100
commit6b7b7ed091900399043d33f5d83ea16b6b4d6a67 (patch)
tree259d92cfea41d7f50cfbb2e118519ceeb9c8c85c
parenta9817fa26c1be1c4c838988d72062ee06a9f406e (diff)
downloadlibvyosconfig-6b7b7ed091900399043d33f5d83ea16b6b4d6a67.tar.gz
libvyosconfig-6b7b7ed091900399043d33f5d83ea16b6b4d6a67.zip
Add a function for copying nodes.
-rw-r--r--debian/changelog6
-rw-r--r--lib/bindings.ml12
2 files changed, 17 insertions, 1 deletions
diff --git a/debian/changelog b/debian/changelog
index 5d1a039..8cf37d0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+libvyosconfig0 (0.0.7) unstable; urgency=medium
+
+ * Add a function for copying nodes.
+
+ -- Daniil Baturin <daniil@baturin.org> Thu, 14 Feb 2019 21:00:57 +0100
+
libvyosconfig0 (0.0.6) unstable; urgency=medium
* Allow top level leaf and tag nodes.
diff --git a/lib/bindings.ml b/lib/bindings.ml
index e8e3df2..49f8ef7 100644
--- a/lib/bindings.ml
+++ b/lib/bindings.ml
@@ -126,6 +126,16 @@ let return_values c_ptr path =
Yojson.Safe.to_string values_json
with _ -> Yojson.Safe.to_string `Null
+let copy_node c_ptr old_path new_path =
+ let ct = Root.get c_ptr in
+ let old_path = Pcre.split ~rex:(Pcre.regexp "\\s+") old_path in
+ let new_path = Pcre.split ~rex:(Pcre.regexp "\\s+") new_path in
+ try
+ let new_ct = Vytree.copy ct old_path new_path in
+ Root.set c_ptr new_ct;
+ 0
+ with Vytree.Nonexistent_path -> 1
+
module Stubs(I : Cstubs_inverted.INTERNAL) =
struct
@@ -142,11 +152,11 @@ struct
let () = I.internal "delete_value" ((ptr void) @-> string @-> string @-> returning int) delete_value
let () = I.internal "delete_node" ((ptr void) @-> string @-> returning int) delete_node
let () = I.internal "rename_node" ((ptr void) @-> string @-> string @-> returning int) rename_node
+ let () = I.internal "copy_node" ((ptr void) @-> string @-> string @-> returning int) copy_node
let () = I.internal "set_tag" ((ptr void) @-> string @-> returning int) set_tag
let () = I.internal "is_tag" ((ptr void) @-> string @-> returning int) is_tag
let () = I.internal "exists" ((ptr void) @-> string @-> returning int) exists
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
-
end