X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=util.c;h=f098c4bbcd29d1c5b34f9a9022d601a22f4ce7b9;hp=eb50b89c30792ac6983a736cc8cf2581d5616e9c;hb=9f540f2106dcf724e4b8c41489d4bda6ccfe65d8;hpb=20925c2795005338ae4de0149201f406ba7e6786 diff --git a/util.c b/util.c index eb50b89..f098c4b 100644 --- a/util.c +++ b/util.c @@ -13,8 +13,8 @@ */ /* - * This file contains wrappers to standard functions, which - * throw exceptions upon failure. + * This file contains misc utility functions and wrappers to standard + * functions, which throw exceptions upon failure. */ #include #include @@ -59,6 +59,22 @@ static char *uci_strdup(struct uci_context *ctx, const char *str) return ptr; } +/* Based on an efficient hash function published by D. J. Bernstein */ +static unsigned int djbhash(unsigned int hash, char *str) +{ + int len = strlen(str); + int i; + + /* initial value */ + if (hash == ~0) + hash = 5381; + + for(i = 0; i < len; i++) { + hash = ((hash << 5) + hash) + str[i]; + } + return (hash & 0x7FFFFFFF); +} + /* * validate strings for names and types, reject special characters * for names, only alphanum and _ is allowed (shell compatibility) @@ -125,7 +141,7 @@ lastval: *value = last; } - if (*section && !uci_validate_name(*section)) + if (*section && *section[0] && !uci_validate_name(*section)) goto error; if (*option && !uci_validate_name(*option)) goto error;