安装完成后在: 加粗样式
/usr/local/include:目录下存放UCI.h文件可以进行参考
结构体
1、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;
};
2、struct uci_section:节结构体,它对应配置文件中的节
struct uci_section
{
struct uci_element e;
struct uci_list options;
struct uci_package *package;
bool anonymous;
char *type;
};
3、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;
};
4、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;
};
5、struct uci_context: uci上下文结构,贯穿查询、更改配置文件全过程。
struct uci_context
{
/* 配置文件包列表 */
struct uci_list root;
/* 解析上下文,只用于错误处理 */
struct uci_parse_context *pctx;
/* 后端导入导出 */
struct uci_backend *backend;
struct uci_list backends;
/* uci 运行标识 */
enum uci_flags flags;
char *confdir;
char *savedir;
/* search path for delta files */
struct uci_list delta_path;
/* 私有数据 */
int err;
const char *func;
jmp_buf trap;
bool internal, nested;
char *buf;
int bufsz;
};
6、uci_element:基本的结构
struct uci_element
{
struct uci_list list;
enum uci_type type;
char *name;
};
API函数
1、uci_alloc_context:动态申请一个uci上下文结构
struct uci_context *uci_alloc_context(void)
2、uci_free_contex:释放由uci_alloc_context申请的uci上下文结构且包括它的所有数据
void uci_free_context(struct uci_context *ctx);
3、uci_lookup_ptr:由给定的元组查找元素
/**
* uci_lookup_ptr: 分离一个uci元组字符串且查找对应元素树
* @ctx: uci context结构体指针
* @ptr: 存放元素查询结果的结构体指针
* @str: 待查找的uci元组字符串
* @extended: 允许扩展语法查询
*
*如果extended被设为ture,则uci_lookup_ptr支持下列扩展语法:
*
*例子:
* network.@interface[0].ifname ('ifname' option of the first interface section)
* network.@interface[-1] (last interface section)
* Note: 有必要的话uci_lookup_ptr将会自动加载配置文件包
* @str 不能是一个const类型指针,它在使用的过程中将会被更改且用于将字符串填写到@ptr中,因此
* 它只要@ptr还在使用,它就必须是可用的
*
* 这个函数在指定包元组的的字符串未被找到时返回UCI_ERR_NOTFOUND,否则返回UCI_OK
*
* 记住在查找其他部分失败的情况,如果它们同样被指定,包括section和option,同样会返回UCI_OK,
* 但是ptr->flags * UCI_LOOKUP_COMPLETE标志位不会被置位
*/
int uci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *str, bool extended);
4、uci_set:设置uci值
int uci_set(struct uci_context *ctx, struct uci_ptr *ptr)
5、uci_del_list: 删除list option
int uci_del_list(struct uci_context *ctx, struct uci_ptr *ptr)
6、uci_add_list:增加list option
int uci_add_list(struct uci_context *ctx, struct uci_ptr *ptr)
7、uci_delete:删除节点(option)
int uci_delete(struct uci_context *ctx, struct uci_ptr *ptr)
8、uci_lookup_ptr:查询元素指针
int uci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr,char *str, bool extended)
9、uci_rename:重命名节(option)
int uci_rename(struct uci_context *ctx, struct uci_ptr *ptr)
10、uci_add_section:添加一个节,配置一个节点的值,如果节点不存在则创建
int uci_add_section(struct uci_context *ctx, struct uci_package*p, const char *type, struct uci_section **res)
11、*uci_alloc_context:分配上下文空间
struct uci_context *uci_alloc_context(void)
12、uci_free_context:释放上下文空间
void uci_free_context(struct uci_context *ctx)
13、uci_load:加载配置到内存
int uci_load(struct uci_context *ctx, const char *name, struct uci_package **package)
14、uci_set_confdir:设置配置目录
int uci_set_confdir(struct uci_context *ctx, const char *dir)
15、uci_commit:提交修改的值,将缓冲区的更改保存到配置文件
还有uci_save ,有区别
int uci_commit(struct uci_context *ctx, struct uci_package **package, bool overwrite)
16、*uci_lookup_option:查询option指针
struct uci_option *uci_lookup_option(struct uci_context *ctx,struct uci_section *s, const char *name)
17、*uci_lookup_option_string:获取一个option string值
const char *uci_lookup_option_string(struct uci_context *ctx,struct uci_section *s, const char *name)
18、*uci_lookup_section:查询package中的section
struct uci_section *uci_lookup_section(struct uci_context *ctx,struct uci_package *p, const char *name)
19、*uci_lookup_package:在上下文中获取package指针
struct uci_package *uci_lookup_package(struct uci_context *ctx, const char *name)
20、uci_unload : 卸载包,释放
int uci_unload(struct uci_context *ctx, struct uci_package *p)
21、uci_foreach_element : 遍历uci的每个节点
#define uci_foreach_element(_list, _ptr) \
for(_ptr = list_to_element((_list)->next); \
&_ptr->list != (_list); \
_ptr = list_to_element(_ptr->list.next))
22、uci_perror : 获取最后一个uci错误的错误字符串
void uci_perror(struct uci_context *ctx, const char *str);
参考文章
1: https://blog.csdn.net/u012819339/article/details/50752157
2: https://blog.csdn.net/dxt1107/article/details/115742249
3: https://www.freesion.com/article/3143519896/
4: https://www.it610.com/article/1279508836671045632.htm