X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=ucimap-example.c;h=6f06451b12c29f99ab742e3542ec392f8799b858;hp=d433f6155bdaf374fca440e04227012f4fb7a75b;hb=160a9e13133aee87d8efcc838a2157073d5616d3;hpb=0a115f989a9eeef8505c0f5dab4ac6a5a6c0af34 diff --git a/ucimap-example.c b/ucimap-example.c index d433f61..6f06451 100644 --- a/ucimap-example.c +++ b/ucimap-example.c @@ -1,6 +1,6 @@ /* * ucimap-example - sample code for the ucimap library - * Copyright (C) 2008 Felix Fietkau + * Copyright (C) 2008-2009 Felix Fietkau * * 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 #include #include +#include "list.h" 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; - *data->data = target; + data->ptr = target; for (i = 0; i < 4; i++) target[i] = (char) tmp[i]; @@ -66,7 +67,7 @@ static int network_format_ip(void *section, struct uci_optmap *om, union ucimap_data *data, char **str) { 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]); @@ -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)); + if (!p) + return NULL; memset(p, 0, sizeof(struct uci_network)); return &p->map; } @@ -148,7 +151,6 @@ static struct my_optmap network_interface_options[] = { .map = { UCIMAP_OPTION(struct uci_network, proto), .type = UCIMAP_STRING, - .name = "proto", .data.s.maxlen = 32, } }, @@ -156,14 +158,12 @@ static struct my_optmap network_interface_options[] = { .map = { UCIMAP_OPTION(struct uci_network, ifname), .type = UCIMAP_STRING, - .name = "ifname" } }, { .map = { UCIMAP_OPTION(struct uci_network, ipaddr), .type = UCIMAP_CUSTOM, - .name = "ipaddr", .parse = network_parse_ip, .format = network_format_ip, .free = network_free_ip, @@ -173,14 +173,12 @@ static struct my_optmap network_interface_options[] = { .map = { UCIMAP_OPTION(struct uci_network, enabled), .type = UCIMAP_BOOL, - .name = "enabled", } }, { .map = { UCIMAP_OPTION(struct uci_network, test), .type = UCIMAP_INT, - .name = "test" } }, { @@ -243,6 +241,8 @@ int main(int argc, char **argv) INIT_LIST_HEAD(&ifs); ctx = uci_alloc_context(); + if (!ctx) + return -1; ucimap_init(&network_map); if ((argc >= 2) && !strcmp(argv[1], "-s")) {