Browse Source

ucimap: simplify the parse/format callbacks. the data argument now always points to the field in the data structure

Felix Fietkau 14 years ago
parent
commit
97e71a1c1b
2 changed files with 3 additions and 11 deletions
  1. 2 2
      ucimap-example.c
  2. 1 9
      ucimap.c

+ 2 - 2
ucimap-example.c

@@ -56,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];
 
@@ -67,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]);

+ 1 - 9
ucimap.c

@@ -404,11 +404,10 @@ ucimap_add_value(union ucimap_data *data, struct uci_optmap *om, struct ucimap_s
 		ucimap_add_fixup(sd, data, om, str);
 		return;
 	case UCIMAP_CUSTOM:
-		tdata.s = (char *) data;
 		break;
 	}
 	if (om->parse) {
-		if (om->parse(ucimap_section_ptr(sd), om, &tdata, str) < 0)
+		if (om->parse(ucimap_section_ptr(sd), om, data, str) < 0)
 			return;
 		if (ucimap_is_custom(om->type) && om->free) {
 			if (tdata.ptr != data->ptr)
@@ -795,13 +794,6 @@ ucimap_data_to_string(struct ucimap_section_data *sd, struct uci_optmap *om, uni
 	}
 
 	if (om->format) {
-		union ucimap_data tdata;
-
-		if (ucimap_is_custom(om->type)) {
-			tdata.s = (char *)data;
-			data = &tdata;
-		}
-
 		if (om->format(ucimap_section_ptr(sd), om, data, &str) < 0)
 			return NULL;