3 * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
4 * Copyright (C) 2010 Steven Barth <steven@midlink.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
28 struct list_head list;
32 extern struct uci_ptr uci_ptr;
34 int ucix_get_ptr(struct uci_context *ctx, const char *p,
35 const char *s, const char *o, const char *t);
36 struct uci_context* ucix_init(const char *config_file, int state);
37 struct uci_context* ucix_init_path(const char *vpath, const char *config_file, int state);
38 int ucix_save_state(struct uci_context *ctx, const char *p);
39 char* ucix_get_option(struct uci_context *ctx,
40 const char *p, const char *s, const char *o);
41 int ucix_get_option_list(struct uci_context *ctx, const char *p,
42 const char *s, const char *o, struct list_head *l);
43 void ucix_for_each_section_type(struct uci_context *ctx,
44 const char *p, const char *t,
45 void (*cb)(const char*, void*), void *priv);
46 void ucix_for_each_section_option(struct uci_context *ctx,
47 const char *p, const char *s,
48 void (*cb)(const char*, const char*, void*), void *priv);
49 void ucix_add_list(struct uci_context *ctx, const char *p,
50 const char *s, const char *o, struct list_head *vals);
52 static inline void ucix_del(struct uci_context *ctx, const char *p, const char *s, const char *o)
54 if (!ucix_get_ptr(ctx, p, s, o, NULL))
55 uci_delete(ctx, &uci_ptr);
58 static inline void ucix_revert(struct uci_context *ctx, const char *p, const char *s, const char *o)
60 if (!ucix_get_ptr(ctx, p, s, o, NULL))
61 uci_revert(ctx, &uci_ptr);
64 static inline void ucix_add_list_single(struct uci_context *ctx, const char *p, const char *s, const char *o, const char *t)
66 if (ucix_get_ptr(ctx, p, s, o, t))
68 uci_add_list(ctx, &uci_ptr);
71 static inline void ucix_add_option(struct uci_context *ctx, const char *p, const char *s, const char *o, const char *t)
73 if (ucix_get_ptr(ctx, p, s, o, t))
75 uci_set(ctx, &uci_ptr);
78 static inline void ucix_add_section(struct uci_context *ctx, const char *p, const char *s, const char *t)
80 if(ucix_get_ptr(ctx, p, s, NULL, t))
82 uci_set(ctx, &uci_ptr);
85 static inline void ucix_add_option_int(struct uci_context *ctx, const char *p, const char *s, const char *o, int t)
88 snprintf(tmp, 64, "%d", t);
89 ucix_add_option(ctx, p, s, o, tmp);
92 static inline void ucix_add_list_single_int(struct uci_context *ctx, const char *p, const char *s, const char *o, const int t)
95 snprintf(tmp, 64, "%d", t);
96 ucix_add_list_single(ctx, p, s, o, tmp);
99 static inline int ucix_get_option_int(struct uci_context *ctx, const char *p, const char *s, const char *o, int def)
101 char *tmp = ucix_get_option(ctx, p, s, o);
112 static inline int ucix_save(struct uci_context *ctx, const char *p)
114 if(ucix_get_ptr(ctx, p, NULL, NULL, NULL))
116 uci_save(ctx, uci_ptr.p);
120 static inline int ucix_commit(struct uci_context *ctx, const char *p)
122 if(ucix_get_ptr(ctx, p, NULL, NULL, NULL))
124 return uci_commit(ctx, &uci_ptr.p, false);
127 static inline void ucix_cleanup(struct uci_context *ctx)
129 uci_free_context(ctx);