summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2018-05-28 04:52:47 +0700
committerDaniil Baturin <daniil@baturin.org>2018-05-28 04:52:47 +0700
commit9dbdbc1513b9a3503ea7d125bf7aa9748c80fa8f (patch)
tree749243baa1ca44e7d2b742d82e6f3e485a6f2f45
parentd8f24a21fe821e6ce927fad66fb3f54821e9906a (diff)
downloadlibvyosconfig-9dbdbc1513b9a3503ea7d125bf7aa9748c80fa8f.tar.gz
libvyosconfig-9dbdbc1513b9a3503ea7d125bf7aa9748c80fa8f.zip
Add from_string and to_string functions to the bindings.
-rw-r--r--lib/bindings.ml11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/bindings.ml b/lib/bindings.ml
index 387e1b5..6d19a76 100644
--- a/lib/bindings.ml
+++ b/lib/bindings.ml
@@ -8,6 +8,15 @@ let make_config_tree name = Ctypes.Root.create (Config_tree.make name)
let destroy c_ptr =
Root.release c_ptr
+let from_string s =
+ try
+ let config = Vyos1x_parser.config Vyos1x_lexer.token (Lexing.from_string s) in
+ Ctypes.Root.create config
+ with _ -> Ctypes.null
+
+let render c_ptr =
+ Vyos1x_renderer.render (Root.get c_ptr)
+
let set_add_value c_ptr path value =
let ct = Root.get c_ptr in
let path = Pcre.split ~rex:(Pcre.regexp "\\s+") path in
@@ -56,6 +65,8 @@ struct
let () = I.internal "make" (string @-> returning (ptr void)) make_config_tree
let () = I.internal "destroy" ((ptr void) @-> returning void) destroy
+ let () = I.internal "from_string" (string @-> returning (ptr void)) from_string
+ let () = I.internal "to_string" ((ptr void) @-> returning string) render
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