projects
/
project
/
uci.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
blob: add uci<->blob conversion library code
[project/uci.git]
/
ucimap-example.c
diff --git
a/ucimap-example.c
b/ucimap-example.c
index
1fd9530
..
18c3c1f
100644
(file)
--- a/
ucimap-example.c
+++ b/
ucimap-example.c
@@
-1,6
+1,6
@@
/*
* ucimap-example - sample code for the ucimap library
/*
* ucimap-example - sample code for the ucimap library
- * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
+ * Copyright (C) 2008
-2009
Felix Fietkau <nbd@openwrt.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
@@
-16,6
+16,7
@@
#include <stdlib.h>
#include <unistd.h>
#include <ucimap.h>
#include <stdlib.h>
#include <unistd.h>
#include <ucimap.h>
+#include "list.h"
struct list_head ifs;
struct list_head ifs;
@@
-55,7
+56,7
@@
network_parse_ip(void *section, struct uci_optmap *om, union ucimap_data *data,
if (!target)
return -1;
if (!target)
return -1;
-
*data->data
= target;
+
data->ptr
= target;
for (i = 0; i < 4; i++)
target[i] = (char) tmp[i];
for (i = 0; i < 4; i++)
target[i] = (char) tmp[i];
@@
-63,10
+64,10
@@
network_parse_ip(void *section, struct uci_optmap *om, union ucimap_data *data,
}
static int
}
static int
-network_format_ip(void *sction, struct uci_optmap *om, union ucimap_data *data, char **str)
+network_format_ip(void *s
e
ction, struct uci_optmap *om, union ucimap_data *data, char **str)
{
static char buf[16];
{
static char buf[16];
- unsigned char *ip = (unsigned char *) data->
data[0]
;
+ unsigned char *ip = (unsigned char *) data->
ptr
;
if (ip) {
sprintf(buf, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
if (ip) {
sprintf(buf, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
@@
-131,6
+132,8
@@
static struct ucimap_section_data *
network_allocate(struct uci_map *map, struct uci_sectionmap *sm, struct uci_section *s)
{
struct uci_network *p = malloc(sizeof(struct uci_network));
network_allocate(struct uci_map *map, struct uci_sectionmap *sm, struct uci_section *s)
{
struct uci_network *p = malloc(sizeof(struct uci_network));
+ if (!p)
+ return NULL;
memset(p, 0, sizeof(struct uci_network));
return &p->map;
}
memset(p, 0, sizeof(struct uci_network));
return &p->map;
}
@@
-243,6
+246,8
@@
int main(int argc, char **argv)
INIT_LIST_HEAD(&ifs);
ctx = uci_alloc_context();
INIT_LIST_HEAD(&ifs);
ctx = uci_alloc_context();
+ if (!ctx)
+ return -1;
ucimap_init(&network_map);
if ((argc >= 2) && !strcmp(argv[1], "-s")) {
ucimap_init(&network_map);
if ((argc >= 2) && !strcmp(argv[1], "-s")) {
@@
-257,6
+262,7
@@
int main(int argc, char **argv)
list_for_each(p, &ifs) {
const unsigned char *ipaddr;
list_for_each(p, &ifs) {
const unsigned char *ipaddr;
+ int n_aliases = 0;
net = list_entry(p, struct uci_network, list);
ipaddr = net->ipaddr;
net = list_entry(p, struct uci_network, list);
ipaddr = net->ipaddr;
@@
-285,6
+291,7
@@
int main(int argc, char **argv)
printf("\n");
}
list_for_each_entry(alias, &net->alias, list) {
printf("\n");
}
list_for_each_entry(alias, &net->alias, list) {
+ n_aliases++;
for (i = 0; i < net->aliases->n_items; i++) {
if (alias == net->aliases->item[i].ptr)
goto next_alias;
for (i = 0; i < net->aliases->n_items; i++) {
if (alias == net->aliases->item[i].ptr)
goto next_alias;
@@
-296,6
+303,12
@@
next_alias:
if (set && !strcmp(net->name, "lan")) {
ucimap_free_item(&net->map, &net->ipaddr);
ucimap_set_changed(&net->map, &net->ipaddr);
if (set && !strcmp(net->name, "lan")) {
ucimap_free_item(&net->map, &net->ipaddr);
ucimap_set_changed(&net->map, &net->ipaddr);
+ ucimap_resize_list(&net->map, &net->aliases, n_aliases);
+ net->aliases->n_items = 0;
+ list_for_each_entry(alias, &net->alias, list) {
+ net->aliases->item[net->aliases->n_items++].ptr = alias;
+ }
+ ucimap_set_changed(&net->map, &net->aliases);
ucimap_store_section(&network_map, pkg, &net->map);
uci_save(ctx, pkg);
}
ucimap_store_section(&network_map, pkg, &net->map);
uci_save(ctx, pkg);
}