2 * libuci - Library for the Unified Configuration Interface
3 * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version 2.1
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 * This file contains wrappers to standard functions, which
17 * throw exceptions upon failure.
22 static void *uci_malloc(struct uci_context *ctx, size_t size)
28 UCI_THROW(ctx, UCI_ERR_MEM);
34 static void *uci_realloc(struct uci_context *ctx, void *ptr, size_t size)
36 ptr = realloc(ptr, size);
38 UCI_THROW(ctx, UCI_ERR_MEM);
43 static char *uci_strdup(struct uci_context *ctx, const char *str)
49 UCI_THROW(ctx, UCI_ERR_MEM);
54 static bool uci_validate_name(const char *str)
60 if (!isalnum(*str) && (*str != '_'))
67 int uci_parse_tuple(struct uci_context *ctx, char *str, char **package, char **section, char **option, char **value)
72 UCI_ASSERT(ctx, str && package && section && option);
74 *package = strtok(str, ".");
75 if (!*package || !uci_validate_name(*package))
79 *section = strtok(NULL, ".");
84 *option = strtok(NULL, ".");
91 last = strchr(last, '=');
103 if (*section && !uci_validate_name(*section))
105 if (*option && !uci_validate_name(*option))
111 UCI_THROW(ctx, UCI_ERR_PARSE);