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 Lesser General Public License for more details.
20 void uci_parse_section(struct uci_section *s, const struct uci_parse_option *opts,
21 int n_opts, struct uci_option **tb)
23 struct uci_element *e;
25 memset(tb, 0, n_opts * sizeof(*tb));
27 uci_foreach_element(&s->options, e) {
28 struct uci_option *o = uci_to_option(e);
31 for (i = 0; i < n_opts; i++) {
35 if (strcmp(opts[i].name, o->e.name) != 0)
38 if (opts[i].type >= 0 && opts[i].type != o->type)
48 //-----------------------------------------------------------------------------
49 // MurmurHashNeutral2, by Austin Appleby
51 // Same as MurmurHash2, but endian- and alignment-neutral.
52 static uint32_t hash_murmur2(uint32_t h, const void * key, int len)
54 const unsigned char * data = key;
55 const uint32_t m = 0x5bd1e995;
80 case 3: h ^= data[2] << 16;
81 case 2: h ^= data[1] << 8;
93 static uint32_t uci_hash_list(uint32_t h, const struct uci_list *list)
95 const struct uci_element *e;
97 uci_foreach_element(list, e) {
98 h = hash_murmur2(h, e->name, strlen(e->name) + 1);
103 uint32_t uci_hash_options(struct uci_option **tb, int n_opts)
105 uint32_t h = 0xdeadc0de;
108 for (i = 0; i < n_opts; i++) {
109 const struct uci_option *o = tb[i];
114 h = hash_murmur2(h, o->e.name, strlen(o->e.name) + 1);
115 h = hash_murmur2(h, &o->type, sizeof(o->type));
117 switch (tb[i]->type) {
118 case UCI_TYPE_STRING:
119 h = hash_murmur2(h, o->v.string, strlen(o->v.string) + 1);
122 h = uci_hash_list(h, &o->v.list);