1 unstable release

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

#779 in Configuration

Download history 29/week @ 2024-07-28 11/week @ 2024-09-22 12/week @ 2024-09-29 2/week @ 2024-10-06 2/week @ 2024-10-13 56/week @ 2024-11-10

56 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.3MB
~46K SLoC