1 unstable release

0.1.5 May 22, 2021
0.1.4 May 22, 2021
0.1.0 Mar 25, 2021

#589 in Configuration

Download history 10/week @ 2024-05-16 9/week @ 2024-05-23 6/week @ 2024-05-30 1/week @ 2024-06-06 18/week @ 2024-07-25 11/week @ 2024-08-01

154 downloads per month

MIT/Apache

380KB
13K SLoC

C 10K SLoC // 0.1% comments Rust 2K SLoC // 0.0% comments Shell 653 SLoC // 0.0% comments Lua 59 SLoC // 0.1% comments

rust-uci

crates.io

OpenWRT libuci bindings for the Rust programming language.

Documentation

License

libuci is licensed under GPLv2.

The files in this repository are licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Bindings to OpenWRT UCI

This crate provides a safe interface to OpenWRT's Unified Configuration Interface C-Library.

Building

Both UCI libraries and headers are required to build this crate. There are multiple options available to locate UCI.

Inside OpenWRT SDK

If building inside the OpenWRT SDK with OpenWRT's UCI package set the environment variable UCI_DIR=$(STAGING_DIR)/usr using the corresponding Makefile. rust-uci will automatically use the headers and libraries for the target system.

Vendored

If no UCI_DIR variable is set, rust-uci will compile against the distributed libuci source files licensed under GPLv2.

Example Usage

use rust_uci::Uci;

let mut uci = Uci::new()?;
// Get type of a section
assert_eq!(uci.get("network.wan")?, "interface");
// Get value of an option, UCI's extended syntax is supported
assert_eq!(uci.get("network.@interface[0].proto")?, "static");
assert_eq!(uci.get("network.lan.proto")?, "static");

// Create a new section
uci.set("network.newnet", "interface")?;
uci.set("network.newnet.proto", "static")?;
uci.set("network.newnet.ifname", "en0")?;
uci.set("network.newnet.enabled", "1")?;
uci.set("network.newnet.ipaddr", "2.3.4.5")?;
uci.set("network.newnet.test", "123")?;
uci.delete("network.newnet.test")?;
// IMPORTANT: Commit or revert the changes
uci.commit("network")?;
uci.revert("network")?;

Dependencies

~0–2.2MB
~42K SLoC