uci函数接口都在uci.h文件中
struct uci_context *uci_alloc_context(void)
动态申请一块内存用于struct uci_context结构。
void uci_free_context(struct uci_context *ctx)
释放struct uci_context结构内存,以及为其成员申请的所有内存
void uci_perror(struct uci_context *ctx, const char *str);
打印最后一条出错信息,如果在打印出错信息前想打印其他信息,则传入str即可
/**
* @ctx: uci context
* @stream: file stream to import from
* @name: (optional) assume the config has the given name
* @package: (optional) store the last parsed config package in this variable
* @single: ignore the 'package' keyword and parse everything into a single package
*
*/
int uci_import(struct uci_context *ctx, FILE *stream, const char *name, struct uci_package **package, bool single);
从文件流中导入uci的配置数据
int uci_export(struct uci_context *ctx, FILE *stream, struct uci_package *package, bool header);
导出uci的配置文件数据到文件流stream
int uci_load(struct uci_context *ctx, const char *name, struct uci_package **package);
解析一个uci配置文件并把它存到ctx中
int uci_unload(struct uci_context *ctx, struct uci_package *p);
从ctx中卸载一个配置文件包
/*
* @ctx: uci context
* @ptr: lookup result struct
* @str: uci tuple string to look up
* @extended: allow extended syntax lookup
*/
int uci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *str, bool extended);
分离一个uci类型的字符串元组,且查找对应的元素树
int uci_add_section(struct uci_context *ctx, struct uci_package *p, const char *type, struct uci_section **res);
增加一个匿名节
int uci_set(struct uci_context *ctx, struct uci_ptr *ptr);
设置一个元素值,必要的话新建这个元素
int uci_add_list(struct uci_context *ctx, struct uci_ptr *ptr);
附加一个字符串到一个元素列表
int uci_del_list(struct uci_context *ctx, struct uci_ptr *ptr);
从一个元素列表中删除一个元素
int uci_reorder_section(struct uci_context *ctx, struct uci_section *s, int pos);
改变一个节的(顺序)位置
int uci_rename(struct uci_context *ctx, struct uci_ptr *ptr);
重命名一个元素
int uci_delete(struct uci_context *ctx, struct uci_ptr *ptr);
删除一个节或选项
int uci_save(struct uci_context *ctx, struct uci_package *p);
为一个package保存改变的delta
/*
@overwrite: overwrite existing config data and flush delta
*/
int uci_commit(struct uci_context *ctx, struct uci_package **p, bool overwrite);
提交改动到一个package
int uci_list_configs(struct uci_context *ctx, char ***list);
列出可用的uci配置文件
int uci_set_savedir(struct uci_context *ctx, const char *dir);
覆盖默认的delta保存的目录
int uci_set_confdir(struct uci_context *ctx, const char *dir);
覆盖默认的配置文件存储目录
int uci_add_delta_path(struct uci_context *ctx, const char *dir);
为detal文件添加一个目录到搜索路径
int uci_revert(struct uci_context *ctx, struct uci_ptr *ptr);
恢复一个配置项的所有变更
int uci_parse_argument(struct uci_context *ctx, FILE *stream, char **str, char **result);
解析一个shell风格的参数
/**
* uci_set_backend: change the default backend
* @ctx: uci context
* @name: name of the backend
*
* The default backend is "file", which uses /etc/config for config storage
*/
extern int uci_set_backend(struct uci_context *ctx, const char *name);
/*
* this function checks whether a given string is acceptable as value
* for uci options
* */
bool uci_validate_text(const char *str);
验证uci options中的一个字符串值
int uci_parse_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *str);
解析一个uci字符串到uci_prt结构中
/*
if parent is NULL, the function looks up the package with the given name
*/
int uci_lookup_next(struct uci_context *ctx, struct uci_element **e, struct uci_list *list, const char *name);
int uci_set_confdir(struct uci_context *ctx, const char *dir)
重新设置配置文件默认路径。该函数重新申请内存,用于存放新的路径,同时释放已经申请的内存(如果申请过的话)。
__private void uci_cleanup(struct uci_context *ctx)