1 LUCI 配置文件简介
LUCI 的配置文件一般存储在 /etc/config 目录下。比如网络配置文件则是 /etc/config/network,无线的配置文件是 /etc/config/wireless。更多配置文件的含义参考官方 WIKI.
2 简单的基本关系
这里画一个图让大家大致了解配置文件的内容和 uci 的几个基本结构之间的对应关系。(例举文件为 uhttpd 的配置文件)

3 结构体介绍
-
struct uci_package: 包结构体,它对应一个配置文件内容。
struct uci_package { struct uci_element e; struct uci_list sections; struct uci_context *ctx; bool has_delta; char *path; /* private: */ struct uci_backend *backend; void *priv; int n_section; struct uci_list delta; struct uci_list saved_delta; }; -
struct uci_section:节结构体,它对应配置文件中的节。
struct uci_section { struct uci_element e; struct uci_list options; struct uci_package *package; bool anonymous; char *type; }; -
struct uci_option:选项结构体,它对应配置文件里节中的 option 或者 list。
struct uci_option { struct uci_element e; struct uci_section *section; enum uci_option_type type; union { struct uci_list list; char *string; } v; }; -
struct uci_ptr:元素位置指针结构,用来查询并保存对应位置元素。
struct uci_ptr { enum uci_type target; enum { UCI_LOOKUP_DONE = (1 << 0), UCI_LOOKUP_COMPLETE = (1 << 1), UCI_LOOKUP_EXTENDED = (1 << 2), } flags; struct uci_package *p; struct uci_section *s; struct uci_option *o; struct uci_element *last; const char *package; const char *section; const char *option; const char *value; }; -
struct uci_context: uci 上下文结构,贯穿查询、更改配置文件全过程。
struct uci_context { /* 配置文件包列表 */ struct uci_list root; /* 解析上下文,只用于错误处理 */ struct uci_parse_context *

本文介绍了LUCI配置文件的结构,包括uci_package、uci_section和uci_option等结构体,并提供了uci_lookup_ptr、uci_alloc_context和uci_free_context等API的说明。通过代码实例展示了如何遍历配置文件、获取和设置option的值。内容适用于OpenWRT等系统中对LUCI配置文件的操作。
2338

被折叠的 条评论
为什么被折叠?



