diff --git a/package/gluon-autoupdater/src/respondd.c b/package/gluon-autoupdater/src/respondd.c index e9738a4c..b7366860 100644 --- a/package/gluon-autoupdater/src/respondd.c +++ b/package/gluon-autoupdater/src/respondd.c @@ -37,7 +37,7 @@ static struct json_object * get_autoupdater(void) { return ret; - error: +error: uci_free_context(ctx); return NULL; } diff --git a/package/gluon-core/src/site.c b/package/gluon-core/src/site.c index 971d44cf..f90b3fce 100644 --- a/package/gluon-core/src/site.c +++ b/package/gluon-core/src/site.c @@ -10,104 +10,104 @@ static struct json_object * gluon_site_udata(lua_State *L, int narg) { - return *(struct json_object **)luaL_checkudata(L, narg, UDATA); + return *(struct json_object **)luaL_checkudata(L, narg, UDATA); } static void gluon_site_push_none(lua_State *L) { - lua_pushlightuserdata(L, gluon_site_push_none); - lua_rawget(L, LUA_REGISTRYINDEX); + lua_pushlightuserdata(L, gluon_site_push_none); + lua_rawget(L, LUA_REGISTRYINDEX); } static void gluon_site_do_wrap(lua_State *L, struct json_object *obj) { - struct json_object **objp = lua_newuserdata(L, sizeof(struct json_object *)); - *objp = json_object_get(obj); - luaL_getmetatable(L, UDATA); - lua_setmetatable(L, -2); + struct json_object **objp = lua_newuserdata(L, sizeof(struct json_object *)); + *objp = json_object_get(obj); + luaL_getmetatable(L, UDATA); + lua_setmetatable(L, -2); } static void gluon_site_wrap(lua_State *L, struct json_object *obj) { - if (obj) - gluon_site_do_wrap(L, obj); - else - gluon_site_push_none(L); + if (obj) + gluon_site_do_wrap(L, obj); + else + gluon_site_push_none(L); } static int gluon_site_index(lua_State *L) { - struct json_object *obj = gluon_site_udata(L, 1); - const char *key; - lua_Number lua_index; - size_t index; - struct json_object *v = NULL; + struct json_object *obj = gluon_site_udata(L, 1); + const char *key; + lua_Number lua_index; + size_t index; + struct json_object *v = NULL; - switch (json_object_get_type(obj)) { + switch (json_object_get_type(obj)) { case json_type_object: - key = lua_tostring(L, 2); - if (key) - json_object_object_get_ex(obj, key, &v); - break; + key = lua_tostring(L, 2); + if (key) + json_object_object_get_ex(obj, key, &v); + break; case json_type_array: - index = lua_index = lua_tonumber(L, 2); - if (lua_index == (lua_Number)index && index >= 1) - v = json_object_array_get_idx(obj, index-1); - break; + index = lua_index = lua_tonumber(L, 2); + if (lua_index == (lua_Number)index && index >= 1) + v = json_object_array_get_idx(obj, index-1); + break; case json_type_string: - case json_type_null: - break; + case json_type_null: + break; case json_type_boolean: case json_type_int: case json_type_double: - luaL_error(L, "attempt to index a number or boolean value"); - __builtin_unreachable(); - } + luaL_error(L, "attempt to index a number or boolean value"); + __builtin_unreachable(); + } - gluon_site_wrap(L, v); - return 1; + gluon_site_wrap(L, v); + return 1; } static int gluon_site_call(lua_State *L) { - struct json_object *obj = gluon_site_udata(L, 1); + struct json_object *obj = gluon_site_udata(L, 1); - if (obj) { - lua_jsonc_push_json(L, obj); - } else { - if (lua_isnone(L, 2)) - lua_pushnil(L); - else - lua_pushvalue(L, 2); - } - - return 1; -} - -static int gluon_site_gc(lua_State *L) { - json_object_put(gluon_site_udata(L, 1)); - return 0; -} - -static const luaL_reg R[] = { - { "__index", gluon_site_index }, - { "__call", gluon_site_call }, - { "__gc", gluon_site_gc }, - {} -}; - -int luaopen_gluon_site(lua_State *L) { - luaL_newmetatable(L, UDATA); - luaL_register(L, NULL, R); - lua_pop(L, 1); - - /* Create "none" object */ - lua_pushlightuserdata(L, gluon_site_push_none); - gluon_site_do_wrap(L, NULL); - lua_rawset(L, LUA_REGISTRYINDEX); - - struct json_object *site = gluonutil_load_site_config(); - gluon_site_wrap(L, site); - json_object_put(site); + if (obj) { + lua_jsonc_push_json(L, obj); + } else { + if (lua_isnone(L, 2)) + lua_pushnil(L); + else + lua_pushvalue(L, 2); + } + + return 1; +} + +static int gluon_site_gc(lua_State *L) { + json_object_put(gluon_site_udata(L, 1)); + return 0; +} + +static const luaL_reg R[] = { + { "__index", gluon_site_index }, + { "__call", gluon_site_call }, + { "__gc", gluon_site_gc }, + {} +}; + +int luaopen_gluon_site(lua_State *L) { + luaL_newmetatable(L, UDATA); + luaL_register(L, NULL, R); + lua_pop(L, 1); + + /* Create "none" object */ + lua_pushlightuserdata(L, gluon_site_push_none); + gluon_site_do_wrap(L, NULL); + lua_rawset(L, LUA_REGISTRYINDEX); + + struct json_object *site = gluonutil_load_site_config(); + gluon_site_wrap(L, site); + json_object_put(site); return 1; } diff --git a/package/gluon-ebtables-limit-arp/src/addr_store.c b/package/gluon-ebtables-limit-arp/src/addr_store.c index 140090ef..18e799a4 100644 --- a/package/gluon-ebtables-limit-arp/src/addr_store.c +++ b/package/gluon-ebtables-limit-arp/src/addr_store.c @@ -10,7 +10,7 @@ #include "lookup3.h" static struct addr_list *addr_node_alloc(void *addr, - struct addr_store *store) + struct addr_store *store) { struct addr_list *node; size_t addr_len = store->addr_len; @@ -27,8 +27,8 @@ static struct addr_list *addr_node_alloc(void *addr, } static struct addr_list *addr_list_search(void *addr, - size_t addr_len, - struct addr_list *list) + size_t addr_len, + struct addr_list *list) { struct addr_list *node = list; struct addr_list *ret = NULL; @@ -73,7 +73,7 @@ int addr_store_add(void *addr, struct addr_store *store) { struct addr_list **bucket = addr_store_get_bucket(addr, store); struct addr_list *node = addr_list_search(addr, store->addr_len, - *bucket); + *bucket); if (node) { node->tic = clock; @@ -91,9 +91,9 @@ int addr_store_add(void *addr, struct addr_store *store) } int addr_store_init(size_t addr_len, - void (*destructor)(struct addr_list *), - char *(*ntoa)(void *), - struct addr_store *store) + void (*destructor)(struct addr_list *), + char *(*ntoa)(void *), + struct addr_store *store) { int i; diff --git a/package/gluon-ebtables-limit-arp/src/addr_store.h b/package/gluon-ebtables-limit-arp/src/addr_store.h index 5d52fbaa..ca3cabc1 100644 --- a/package/gluon-ebtables-limit-arp/src/addr_store.h +++ b/package/gluon-ebtables-limit-arp/src/addr_store.h @@ -20,9 +20,9 @@ struct addr_store { }; int addr_store_init(size_t addr_len, - void (*destructor)(struct addr_list *), - char *(*ntoa)(void *), - struct addr_store *store); + void (*destructor)(struct addr_list *), + char *(*ntoa)(void *), + struct addr_store *store); int addr_store_add(void *addr, struct addr_store *store); void addr_store_cleanup(struct addr_store *store); diff --git a/package/gluon-ebtables-limit-arp/src/gluon-arp-limiter.c b/package/gluon-ebtables-limit-arp/src/gluon-arp-limiter.c index 5875e897..93940a3c 100644 --- a/package/gluon-ebtables-limit-arp/src/gluon-arp-limiter.c +++ b/package/gluon-ebtables-limit-arp/src/gluon-arp-limiter.c @@ -39,8 +39,8 @@ static void ebt_ip_call(char *mod, struct in_addr ip) int ret; snprintf(str, sizeof(str), - EBTABLES " %s ARP_LIMIT_DATCHECK -p ARP --arp-ip-dst %s -j mark --mark-or 0x2 --mark-target RETURN", - mod, inet_ntoa(ip)); + EBTABLES " %s ARP_LIMIT_DATCHECK -p ARP --arp-ip-dst %s -j mark --mark-or 0x2 --mark-target RETURN", + mod, inet_ntoa(ip)); ret = system(str); if (ret) @@ -62,8 +62,8 @@ static void ebt_mac_limit_call(char *mod, struct mac_addr *mac) int ret; snprintf(str, sizeof(str), - EBTABLES " %s ARP_LIMIT_TLCHECK --source %s --limit 6/min --limit-burst 50 -j RETURN", - mod, mac_ntoa(mac)); + EBTABLES " %s ARP_LIMIT_TLCHECK --source %s --limit 6/min --limit-burst 50 -j RETURN", + mod, mac_ntoa(mac)); ret = system(str); if (ret) @@ -78,8 +78,8 @@ static void ebt_mac_ret_call(char *mod, struct mac_addr *mac, int add) int ret; snprintf(str, sizeof(str), - EBTABLES " %s ARP_LIMIT_TLCHECK %s --source %s -j DROP", - mod, add ? "2" : "", mac_ntoa(mac)); + EBTABLES " %s ARP_LIMIT_TLCHECK %s --source %s -j DROP", + mod, add ? "2" : "", mac_ntoa(mac)); ret = system(str); if (ret) diff --git a/package/gluon-ebtables-limit-arp/src/lookup3.c b/package/gluon-ebtables-limit-arp/src/lookup3.c index 173fdef6..f8d84494 100644 --- a/package/gluon-ebtables-limit-arp/src/lookup3.c +++ b/package/gluon-ebtables-limit-arp/src/lookup3.c @@ -16,12 +16,12 @@ hashlittle() except it returns two 32-bit hashes for the price of one. You could implement hashbig2() if you wanted but I haven't bothered here. If you want to find a hash of, say, exactly 7 integers, do - a = i1; b = i2; c = i3; - mix(a,b,c); - a += i4; b += i5; c += i6; - mix(a,b,c); - a += i7; - final(a,b,c); + a = i1; b = i2; c = i3; + mix(a,b,c); + a += i4; b += i5; c += i6; + mix(a,b,c); + a += i7; + final(a,b,c); then use c as the hash value. If you have a variable length array of 4-byte integers to hash, use hashword(). If you have a byte array (like a character string), use hashlittle(). If you have several byte arrays, or @@ -48,14 +48,14 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. * need adjustment. */ #if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \ - __BYTE_ORDER == __LITTLE_ENDIAN) || \ - (defined(i386) || defined(__i386__) || defined(__i486__) || \ - defined(__i586__) || defined(__i686__) || defined(vax) || defined(MIPSEL)) + __BYTE_ORDER == __LITTLE_ENDIAN) || \ + (defined(i386) || defined(__i386__) || defined(__i486__) || \ + defined(__i586__) || defined(__i686__) || defined(vax) || defined(MIPSEL)) # define HASH_LITTLE_ENDIAN 1 # define HASH_BIG_ENDIAN 0 #elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \ - __BYTE_ORDER == __BIG_ENDIAN) || \ - (defined(sparc) || defined(POWERPC) || defined(mc68000) || defined(sel)) + __BYTE_ORDER == __BIG_ENDIAN) || \ + (defined(sparc) || defined(POWERPC) || defined(mc68000) || defined(sel)) # define HASH_LITTLE_ENDIAN 0 # define HASH_BIG_ENDIAN 1 #else @@ -79,20 +79,20 @@ mix() in reverse, there are at least 32 bits of the output that are sometimes the same for one pair and different for another pair. This was tested for: * pairs that differed by one bit, by two bits, in any combination - of top bits of (a,b,c), or in any combination of bottom bits of - (a,b,c). + of top bits of (a,b,c), or in any combination of bottom bits of + (a,b,c). * "differ" is defined as +, -, ^, or ~^. For + and -, I transformed - the output delta to a Gray code (a^(a>>1)) so a string of 1's (as - is commonly produced by subtraction) look like a single 1-bit - difference. + the output delta to a Gray code (a^(a>>1)) so a string of 1's (as + is commonly produced by subtraction) look like a single 1-bit + difference. * the base values were pseudorandom, all zero but one bit set, or - all zero plus a counter that starts at zero. + all zero plus a counter that starts at zero. Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that satisfy this are - 4 6 8 16 19 4 - 9 15 3 18 27 15 - 14 9 3 7 17 3 + 4 6 8 16 19 4 + 9 15 3 18 27 15 + 14 9 3 7 17 3 Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing for "differ" defined as + with a one-bit base and a two-bit delta. I used https://burtleburtle.net/bob/hash/avalanche.html to choose @@ -113,12 +113,12 @@ rotates. */ #define mix(a,b,c) \ { \ - a -= c; a ^= rot(c, 4); c += b; \ - b -= a; b ^= rot(a, 6); a += c; \ - c -= b; c ^= rot(b, 8); b += a; \ - a -= c; a ^= rot(c,16); c += b; \ - b -= a; b ^= rot(a,19); a += c; \ - c -= b; c ^= rot(b, 4); b += a; \ + a -= c; a ^= rot(c, 4); c += b; \ + b -= a; b ^= rot(a, 6); a += c; \ + c -= b; c ^= rot(b, 8); b += a; \ + a -= c; a ^= rot(c,16); c += b; \ + b -= a; b ^= rot(a,19); a += c; \ + c -= b; c ^= rot(b, 4); b += a; \ } /* @@ -128,46 +128,46 @@ final -- final mixing of 3 32-bit values (a,b,c) into c Pairs of (a,b,c) values differing in only a few bits will usually produce values of c that look totally different. This was tested for * pairs that differed by one bit, by two bits, in any combination - of top bits of (a,b,c), or in any combination of bottom bits of - (a,b,c). + of top bits of (a,b,c), or in any combination of bottom bits of + (a,b,c). * "differ" is defined as +, -, ^, or ~^. For + and -, I transformed - the output delta to a Gray code (a^(a>>1)) so a string of 1's (as - is commonly produced by subtraction) look like a single 1-bit - difference. + the output delta to a Gray code (a^(a>>1)) so a string of 1's (as + is commonly produced by subtraction) look like a single 1-bit + difference. * the base values were pseudorandom, all zero but one bit set, or - all zero plus a counter that starts at zero. + all zero plus a counter that starts at zero. These constants passed: - 14 11 25 16 4 14 24 - 12 14 25 16 4 14 24 + 14 11 25 16 4 14 24 + 12 14 25 16 4 14 24 and these came close: - 4 8 15 26 3 22 24 - 10 8 15 26 3 22 24 - 11 8 15 26 3 22 24 + 4 8 15 26 3 22 24 + 10 8 15 26 3 22 24 + 11 8 15 26 3 22 24 ------------------------------------------------------------------------------- */ #define final(a,b,c) \ { \ - c ^= b; c -= rot(b,14); \ - a ^= c; a -= rot(c,11); \ - b ^= a; b -= rot(a,25); \ - c ^= b; c -= rot(b,16); \ - a ^= c; a -= rot(c,4); \ - b ^= a; b -= rot(a,14); \ - c ^= b; c -= rot(b,24); \ + c ^= b; c -= rot(b,14); \ + a ^= c; a -= rot(c,11); \ + b ^= a; b -= rot(a,25); \ + c ^= b; c -= rot(b,16); \ + a ^= c; a -= rot(c,4); \ + b ^= a; b -= rot(a,14); \ + c ^= b; c -= rot(b,24); \ } /* -------------------------------------------------------------------- - This works on all machines. To be useful, it requires - -- that the key be an array of uint32_t's, and - -- that the length be the number of uint32_t's in the key +This works on all machines. To be useful, it requires +-- that the key be an array of uint32_t's, and +-- that the length be the number of uint32_t's in the key - The function hashword() is identical to hashlittle() on little-endian - machines, and identical to hashbig() on big-endian machines, - except that the length has to be measured in uint32_ts rather than in - bytes. hashlittle() is more complicated than hashword() only because - hashlittle() has to dance around fitting the key bytes into registers. +The function hashword() is identical to hashlittle() on little-endian +machines, and identical to hashbig() on big-endian machines, +except that the length has to be measured in uint32_ts rather than in +bytes. hashlittle() is more complicated than hashword() only because +hashlittle() has to dance around fitting the key bytes into registers. -------------------------------------------------------------------- */ uint32_t hashword( @@ -175,34 +175,34 @@ const uint32_t *k, /* the key, an array of uint32_t values */ size_t length, /* the length of the key, in uint32_ts */ uint32_t initval) /* the previous hash, or an arbitrary value */ { - uint32_t a,b,c; + uint32_t a,b,c; - /* Set up the internal state */ - a = b = c = 0xdeadbeef + (((uint32_t)length)<<2) + initval; + /* Set up the internal state */ + a = b = c = 0xdeadbeef + (((uint32_t)length)<<2) + initval; - /*------------------------------------------------- handle most of the key */ - while (length > 3) - { - a += k[0]; - b += k[1]; - c += k[2]; - mix(a,b,c); - length -= 3; - k += 3; - } + /*------------------------------------------------- handle most of the key */ + while (length > 3) + { + a += k[0]; + b += k[1]; + c += k[2]; + mix(a,b,c); + length -= 3; + k += 3; + } - /*------------------------------------------- handle the last 3 uint32_t's */ - switch(length) /* all the case statements fall through */ - { - case 3 : c+=k[2]; - case 2 : b+=k[1]; - case 1 : a+=k[0]; - final(a,b,c); - case 0: /* case 0: nothing left to add */ - break; - } - /*------------------------------------------------------ report the result */ - return c; + /*------------------------------------------- handle the last 3 uint32_t's */ + switch(length) /* all the case statements fall through */ + { + case 3 : c+=k[2]; + case 2 : b+=k[1]; + case 1 : a+=k[0]; + final(a,b,c); + case 0: /* case 0: nothing left to add */ + break; + } + /*------------------------------------------------------ report the result */ + return c; } @@ -215,49 +215,49 @@ both be initialized with seeds. If you pass in (*pb)==0, the output -------------------------------------------------------------------- */ void hashword2 ( -const uint32_t *k, /* the key, an array of uint32_t values */ -size_t length, /* the length of the key, in uint32_ts */ -uint32_t *pc, /* IN: seed OUT: primary hash value */ -uint32_t *pb) /* IN: more seed OUT: secondary hash value */ + const uint32_t *k, /* the key, an array of uint32_t values */ + size_t length, /* the length of the key, in uint32_ts */ + uint32_t *pc, /* IN: seed OUT: primary hash value */ + uint32_t *pb) /* IN: more seed OUT: secondary hash value */ { - uint32_t a,b,c; + uint32_t a,b,c; - /* Set up the internal state */ - a = b = c = 0xdeadbeef + ((uint32_t)(length<<2)) + *pc; - c += *pb; + /* Set up the internal state */ + a = b = c = 0xdeadbeef + ((uint32_t)(length<<2)) + *pc; + c += *pb; - /*------------------------------------------------- handle most of the key */ - while (length > 3) - { - a += k[0]; - b += k[1]; - c += k[2]; - mix(a,b,c); - length -= 3; - k += 3; - } + /*------------------------------------------------- handle most of the key */ + while (length > 3) + { + a += k[0]; + b += k[1]; + c += k[2]; + mix(a,b,c); + length -= 3; + k += 3; + } - /*------------------------------------------- handle the last 3 uint32_t's */ - switch(length) /* all the case statements fall through */ - { - case 3 : c+=k[2]; - case 2 : b+=k[1]; - case 1 : a+=k[0]; - final(a,b,c); - case 0: /* case 0: nothing left to add */ - break; - } - /*------------------------------------------------------ report the result */ - *pc=c; *pb=b; + /*------------------------------------------- handle the last 3 uint32_t's */ + switch(length) /* all the case statements fall through */ + { + case 3 : c+=k[2]; + case 2 : b+=k[1]; + case 1 : a+=k[0]; + final(a,b,c); + case 0: /* case 0: nothing left to add */ + break; + } + /*------------------------------------------------------ report the result */ + *pc=c; *pb=b; } /* ------------------------------------------------------------------------------- hashlittle() -- hash a variable-length key into a 32-bit value - k : the key (the unaligned variable-length array of bytes) - length : the length of the key, counting by bytes - initval : can be any 4-byte value + k : the key (the unaligned variable-length array of bytes) + length : the length of the key, counting by bytes + initval : can be any 4-byte value Returns a 32-bit value. Every bit of the key affects every bit of the return value. Two keys differing by one or two bits will have totally different hash values. @@ -265,11 +265,11 @@ totally different hash values. The best hash table sizes are powers of 2. There is no need to do mod a prime (mod is sooo slow!). If you need less than 32 bits, use a bitmask. For example, if you need only 10 bits, do - h = (h & hashmask(10)); + h = (h & hashmask(10)); In which case, the hash table should have hashsize(10) elements. If you are hashing n strings (uint8_t **)k, do it like this: - for (i=0, h=0; i 12) - { - a += k[0]; - b += k[1]; - c += k[2]; - mix(a,b,c); - length -= 12; - k += 3; - } + /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ + while (length > 12) + { + a += k[0]; + b += k[1]; + c += k[2]; + mix(a,b,c); + length -= 12; + k += 3; + } - /*----------------------------- handle the last (probably partial) block */ - /* - * "k[2]&0xffffff" actually reads beyond the end of the string, but - * then masks off the part it's not allowed to read. Because the - * string is aligned, the masked-off tail is in the same word as the - * rest of the string. Every machine with memory protection I've seen - * does it on word boundaries, so is OK with this. But VALGRIND will - * still catch it and complain. The masking trick does make the hash - * noticeably faster for short strings (like English words). - */ + /*----------------------------- handle the last (probably partial) block */ + /* + * "k[2]&0xffffff" actually reads beyond the end of the string, but + * then masks off the part it's not allowed to read. Because the + * string is aligned, the masked-off tail is in the same word as the + * rest of the string. Every machine with memory protection I've seen + * does it on word boundaries, so is OK with this. But VALGRIND will + * still catch it and complain. The masking trick does make the hash + * noticeably faster for short strings (like English words). + */ #ifndef VALGRIND - switch(length) - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; - case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; - case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=k[1]&0xffffff; a+=k[0]; break; - case 6 : b+=k[1]&0xffff; a+=k[0]; break; - case 5 : b+=k[1]&0xff; a+=k[0]; break; - case 4 : a+=k[0]; break; - case 3 : a+=k[0]&0xffffff; break; - case 2 : a+=k[0]&0xffff; break; - case 1 : a+=k[0]&0xff; break; - case 0 : return c; /* zero length strings require no mixing */ - } + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; + case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; + case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=k[1]&0xffffff; a+=k[0]; break; + case 6 : b+=k[1]&0xffff; a+=k[0]; break; + case 5 : b+=k[1]&0xff; a+=k[0]; break; + case 4 : a+=k[0]; break; + case 3 : a+=k[0]&0xffffff; break; + case 2 : a+=k[0]&0xffff; break; + case 1 : a+=k[0]&0xff; break; + case 0 : return c; /* zero length strings require no mixing */ + } #else /* make valgrind happy */ - k8 = (const uint8_t *)k; - switch(length) - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ - case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ - case 9 : c+=k8[8]; /* fall through */ - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ - case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ - case 5 : b+=k8[4]; /* fall through */ - case 4 : a+=k[0]; break; - case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ - case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ - case 1 : a+=k8[0]; break; - case 0 : return c; - } + k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]; break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ + case 1 : a+=k8[0]; break; + case 0 : return c; + } #endif /* !valgrind */ - } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { - const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ - const uint8_t *k8; + } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { + const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ + const uint8_t *k8; - /*--------------- all but last block: aligned reads and different mixing */ - while (length > 12) - { - a += k[0] + (((uint32_t)k[1])<<16); - b += k[2] + (((uint32_t)k[3])<<16); - c += k[4] + (((uint32_t)k[5])<<16); - mix(a,b,c); - length -= 12; - k += 6; - } + /*--------------- all but last block: aligned reads and different mixing */ + while (length > 12) + { + a += k[0] + (((uint32_t)k[1])<<16); + b += k[2] + (((uint32_t)k[3])<<16); + c += k[4] + (((uint32_t)k[5])<<16); + mix(a,b,c); + length -= 12; + k += 6; + } - /*----------------------------- handle the last (probably partial) block */ - k8 = (const uint8_t *)k; - switch(length) - { - case 12: c+=k[4]+(((uint32_t)k[5])<<16); - b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ - case 10: c+=k[4]; - b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 9 : c+=k8[8]; /* fall through */ - case 8 : b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ - case 6 : b+=k[2]; - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 5 : b+=k8[4]; /* fall through */ - case 4 : a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ - case 2 : a+=k[0]; - break; - case 1 : a+=k8[0]; - break; - case 0 : return c; /* zero length requires no mixing */ - } + /*----------------------------- handle the last (probably partial) block */ + k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[4]+(((uint32_t)k[5])<<16); + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=k[4]; + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=k[2]; + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=k[0]; + break; + case 1 : a+=k8[0]; + break; + case 0 : return c; /* zero length requires no mixing */ + } - } else { /* need to read the key one byte at a time */ - const uint8_t *k = (const uint8_t *)key; + } else { /* need to read the key one byte at a time */ + const uint8_t *k = (const uint8_t *)key; - /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ - while (length > 12) - { - a += k[0]; - a += ((uint32_t)k[1])<<8; - a += ((uint32_t)k[2])<<16; - a += ((uint32_t)k[3])<<24; - b += k[4]; - b += ((uint32_t)k[5])<<8; - b += ((uint32_t)k[6])<<16; - b += ((uint32_t)k[7])<<24; - c += k[8]; - c += ((uint32_t)k[9])<<8; - c += ((uint32_t)k[10])<<16; - c += ((uint32_t)k[11])<<24; - mix(a,b,c); - length -= 12; - k += 12; - } + /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ + while (length > 12) + { + a += k[0]; + a += ((uint32_t)k[1])<<8; + a += ((uint32_t)k[2])<<16; + a += ((uint32_t)k[3])<<24; + b += k[4]; + b += ((uint32_t)k[5])<<8; + b += ((uint32_t)k[6])<<16; + b += ((uint32_t)k[7])<<24; + c += k[8]; + c += ((uint32_t)k[9])<<8; + c += ((uint32_t)k[10])<<16; + c += ((uint32_t)k[11])<<24; + mix(a,b,c); + length -= 12; + k += 12; + } - /*-------------------------------- last block: affect all 32 bits of (c) */ - switch(length) /* all the case statements fall through */ - { - case 12: c+=((uint32_t)k[11])<<24; - case 11: c+=((uint32_t)k[10])<<16; - case 10: c+=((uint32_t)k[9])<<8; - case 9 : c+=k[8]; - case 8 : b+=((uint32_t)k[7])<<24; - case 7 : b+=((uint32_t)k[6])<<16; - case 6 : b+=((uint32_t)k[5])<<8; - case 5 : b+=k[4]; - case 4 : a+=((uint32_t)k[3])<<24; - case 3 : a+=((uint32_t)k[2])<<16; - case 2 : a+=((uint32_t)k[1])<<8; - case 1 : a+=k[0]; - break; - case 0 : return c; - } - } - - final(a,b,c); - return c; + /*-------------------------------- last block: affect all 32 bits of (c) */ + switch(length) /* all the case statements fall through */ + { + case 12: c+=((uint32_t)k[11])<<24; + case 11: c+=((uint32_t)k[10])<<16; + case 10: c+=((uint32_t)k[9])<<8; + case 9 : c+=k[8]; + case 8 : b+=((uint32_t)k[7])<<24; + case 7 : b+=((uint32_t)k[6])<<16; + case 6 : b+=((uint32_t)k[5])<<8; + case 5 : b+=k[4]; + case 4 : a+=((uint32_t)k[3])<<24; + case 3 : a+=((uint32_t)k[2])<<16; + case 2 : a+=((uint32_t)k[1])<<8; + case 1 : a+=k[0]; + break; + case 0 : return c; + } + } + final(a,b,c); + return c; } @@ -458,177 +457,177 @@ uint32_t hashlittle( const void *key, size_t length, uint32_t initval) * the key. *pc is better mixed than *pb, so use *pc first. If you want * a 64-bit value do something like "*pc + (((uint64_t)*pb)<<32)". */ -void hashlittle2( - const void *key, /* the key to hash */ - size_t length, /* length of the key */ - uint32_t *pc, /* IN: primary initval, OUT: primary hash */ - uint32_t *pb) /* IN: secondary initval, OUT: secondary hash */ +void hashlittle2( + const void *key, /* the key to hash */ + size_t length, /* length of the key */ + uint32_t *pc, /* IN: primary initval, OUT: primary hash */ + uint32_t *pb) /* IN: secondary initval, OUT: secondary hash */ { - uint32_t a,b,c; /* internal state */ - union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */ + uint32_t a,b,c; /* internal state */ + union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */ - /* Set up the internal state */ - a = b = c = 0xdeadbeef + ((uint32_t)length) + *pc; - c += *pb; + /* Set up the internal state */ + a = b = c = 0xdeadbeef + ((uint32_t)length) + *pc; + c += *pb; - u.ptr = key; - if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) { - const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ + u.ptr = key; + if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) { + const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ - /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ - while (length > 12) - { - a += k[0]; - b += k[1]; - c += k[2]; - mix(a,b,c); - length -= 12; - k += 3; - } + /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ + while (length > 12) + { + a += k[0]; + b += k[1]; + c += k[2]; + mix(a,b,c); + length -= 12; + k += 3; + } - /*----------------------------- handle the last (probably partial) block */ - /* - * "k[2]&0xffffff" actually reads beyond the end of the string, but - * then masks off the part it's not allowed to read. Because the - * string is aligned, the masked-off tail is in the same word as the - * rest of the string. Every machine with memory protection I've seen - * does it on word boundaries, so is OK with this. But VALGRIND will - * still catch it and complain. The masking trick does make the hash - * noticeably faster for short strings (like English words). - */ + /*----------------------------- handle the last (probably partial) block */ + /* + * "k[2]&0xffffff" actually reads beyond the end of the string, but + * then masks off the part it's not allowed to read. Because the + * string is aligned, the masked-off tail is in the same word as the + * rest of the string. Every machine with memory protection I've seen + * does it on word boundaries, so is OK with this. But VALGRIND will + * still catch it and complain. The masking trick does make the hash + * noticeably faster for short strings (like English words). + */ #ifndef VALGRIND - switch(length) - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; - case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; - case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=k[1]&0xffffff; a+=k[0]; break; - case 6 : b+=k[1]&0xffff; a+=k[0]; break; - case 5 : b+=k[1]&0xff; a+=k[0]; break; - case 4 : a+=k[0]; break; - case 3 : a+=k[0]&0xffffff; break; - case 2 : a+=k[0]&0xffff; break; - case 1 : a+=k[0]&0xff; break; - case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */ - } + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break; + case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break; + case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break; + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=k[1]&0xffffff; a+=k[0]; break; + case 6 : b+=k[1]&0xffff; a+=k[0]; break; + case 5 : b+=k[1]&0xff; a+=k[0]; break; + case 4 : a+=k[0]; break; + case 3 : a+=k[0]&0xffffff; break; + case 2 : a+=k[0]&0xffff; break; + case 1 : a+=k[0]&0xff; break; + case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */ + } #else /* make valgrind happy */ - k8 = (const uint8_t *)k; - switch(length) - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ - case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ - case 9 : c+=k8[8]; /* fall through */ - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ - case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ - case 5 : b+=k8[4]; /* fall through */ - case 4 : a+=k[0]; break; - case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ - case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ - case 1 : a+=k8[0]; break; - case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */ - } + k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=((uint32_t)k8[9])<<8; /* fall through */ + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */ + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]; break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */ + case 1 : a+=k8[0]; break; + case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */ + } #endif /* !valgrind */ - } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { - const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ - const uint8_t *k8; + } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) { + const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ + const uint8_t *k8; - /*--------------- all but last block: aligned reads and different mixing */ - while (length > 12) - { - a += k[0] + (((uint32_t)k[1])<<16); - b += k[2] + (((uint32_t)k[3])<<16); - c += k[4] + (((uint32_t)k[5])<<16); - mix(a,b,c); - length -= 12; - k += 6; - } + /*--------------- all but last block: aligned reads and different mixing */ + while (length > 12) + { + a += k[0] + (((uint32_t)k[1])<<16); + b += k[2] + (((uint32_t)k[3])<<16); + c += k[4] + (((uint32_t)k[5])<<16); + mix(a,b,c); + length -= 12; + k += 6; + } - /*----------------------------- handle the last (probably partial) block */ - k8 = (const uint8_t *)k; - switch(length) - { - case 12: c+=k[4]+(((uint32_t)k[5])<<16); - b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ - case 10: c+=k[4]; - b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 9 : c+=k8[8]; /* fall through */ - case 8 : b+=k[2]+(((uint32_t)k[3])<<16); - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ - case 6 : b+=k[2]; - a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 5 : b+=k8[4]; /* fall through */ - case 4 : a+=k[0]+(((uint32_t)k[1])<<16); - break; - case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ - case 2 : a+=k[0]; - break; - case 1 : a+=k8[0]; - break; - case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */ - } + /*----------------------------- handle the last (probably partial) block */ + k8 = (const uint8_t *)k; + switch(length) + { + case 12: c+=k[4]+(((uint32_t)k[5])<<16); + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 11: c+=((uint32_t)k8[10])<<16; /* fall through */ + case 10: c+=k[4]; + b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 9 : c+=k8[8]; /* fall through */ + case 8 : b+=k[2]+(((uint32_t)k[3])<<16); + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */ + case 6 : b+=k[2]; + a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 5 : b+=k8[4]; /* fall through */ + case 4 : a+=k[0]+(((uint32_t)k[1])<<16); + break; + case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */ + case 2 : a+=k[0]; + break; + case 1 : a+=k8[0]; + break; + case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */ + } - } else { /* need to read the key one byte at a time */ - const uint8_t *k = (const uint8_t *)key; + } else { /* need to read the key one byte at a time */ + const uint8_t *k = (const uint8_t *)key; - /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ - while (length > 12) - { - a += k[0]; - a += ((uint32_t)k[1])<<8; - a += ((uint32_t)k[2])<<16; - a += ((uint32_t)k[3])<<24; - b += k[4]; - b += ((uint32_t)k[5])<<8; - b += ((uint32_t)k[6])<<16; - b += ((uint32_t)k[7])<<24; - c += k[8]; - c += ((uint32_t)k[9])<<8; - c += ((uint32_t)k[10])<<16; - c += ((uint32_t)k[11])<<24; - mix(a,b,c); - length -= 12; - k += 12; - } + /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ + while (length > 12) + { + a += k[0]; + a += ((uint32_t)k[1])<<8; + a += ((uint32_t)k[2])<<16; + a += ((uint32_t)k[3])<<24; + b += k[4]; + b += ((uint32_t)k[5])<<8; + b += ((uint32_t)k[6])<<16; + b += ((uint32_t)k[7])<<24; + c += k[8]; + c += ((uint32_t)k[9])<<8; + c += ((uint32_t)k[10])<<16; + c += ((uint32_t)k[11])<<24; + mix(a,b,c); + length -= 12; + k += 12; + } - /*-------------------------------- last block: affect all 32 bits of (c) */ - switch(length) /* all the case statements fall through */ - { - case 12: c+=((uint32_t)k[11])<<24; - case 11: c+=((uint32_t)k[10])<<16; - case 10: c+=((uint32_t)k[9])<<8; - case 9 : c+=k[8]; - case 8 : b+=((uint32_t)k[7])<<24; - case 7 : b+=((uint32_t)k[6])<<16; - case 6 : b+=((uint32_t)k[5])<<8; - case 5 : b+=k[4]; - case 4 : a+=((uint32_t)k[3])<<24; - case 3 : a+=((uint32_t)k[2])<<16; - case 2 : a+=((uint32_t)k[1])<<8; - case 1 : a+=k[0]; - break; - case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */ - } - } + /*-------------------------------- last block: affect all 32 bits of (c) */ + switch(length) /* all the case statements fall through */ + { + case 12: c+=((uint32_t)k[11])<<24; + case 11: c+=((uint32_t)k[10])<<16; + case 10: c+=((uint32_t)k[9])<<8; + case 9 : c+=k[8]; + case 8 : b+=((uint32_t)k[7])<<24; + case 7 : b+=((uint32_t)k[6])<<16; + case 6 : b+=((uint32_t)k[5])<<8; + case 5 : b+=k[4]; + case 4 : a+=((uint32_t)k[3])<<24; + case 3 : a+=((uint32_t)k[2])<<16; + case 2 : a+=((uint32_t)k[1])<<8; + case 1 : a+=k[0]; + break; + case 0 : *pc=c; *pb=b; return; /* zero length strings require no mixing */ + } + } - final(a,b,c); - *pc=c; *pb=b; + final(a,b,c); + *pc=c; *pb=b; } @@ -641,123 +640,123 @@ void hashlittle2( */ uint32_t hashbig( const void *key, size_t length, uint32_t initval) { - uint32_t a,b,c; - union { const void *ptr; size_t i; } u; /* to cast key to (size_t) happily */ + uint32_t a,b,c; + union { const void *ptr; size_t i; } u; /* to cast key to (size_t) happily */ - /* Set up the internal state */ - a = b = c = 0xdeadbeef + ((uint32_t)length) + initval; + /* Set up the internal state */ + a = b = c = 0xdeadbeef + ((uint32_t)length) + initval; - u.ptr = key; - if (HASH_BIG_ENDIAN && ((u.i & 0x3) == 0)) { - const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ + u.ptr = key; + if (HASH_BIG_ENDIAN && ((u.i & 0x3) == 0)) { + const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ - /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ - while (length > 12) - { - a += k[0]; - b += k[1]; - c += k[2]; - mix(a,b,c); - length -= 12; - k += 3; - } + /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ + while (length > 12) + { + a += k[0]; + b += k[1]; + c += k[2]; + mix(a,b,c); + length -= 12; + k += 3; + } - /*----------------------------- handle the last (probably partial) block */ - /* - * "k[2]<<8" actually reads beyond the end of the string, but - * then shifts out the part it's not allowed to read. Because the - * string is aligned, the illegal read is in the same word as the - * rest of the string. Every machine with memory protection I've seen - * does it on word boundaries, so is OK with this. But VALGRIND will - * still catch it and complain. The masking trick does make the hash - * noticeably faster for short strings (like English words). - */ + /*----------------------------- handle the last (probably partial) block */ + /* + * "k[2]<<8" actually reads beyond the end of the string, but + * then shifts out the part it's not allowed to read. Because the + * string is aligned, the illegal read is in the same word as the + * rest of the string. Every machine with memory protection I've seen + * does it on word boundaries, so is OK with this. But VALGRIND will + * still catch it and complain. The masking trick does make the hash + * noticeably faster for short strings (like English words). + * */ #ifndef VALGRIND - switch(length) - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=k[2]&0xffffff00; b+=k[1]; a+=k[0]; break; - case 10: c+=k[2]&0xffff0000; b+=k[1]; a+=k[0]; break; - case 9 : c+=k[2]&0xff000000; b+=k[1]; a+=k[0]; break; - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=k[1]&0xffffff00; a+=k[0]; break; - case 6 : b+=k[1]&0xffff0000; a+=k[0]; break; - case 5 : b+=k[1]&0xff000000; a+=k[0]; break; - case 4 : a+=k[0]; break; - case 3 : a+=k[0]&0xffffff00; break; - case 2 : a+=k[0]&0xffff0000; break; - case 1 : a+=k[0]&0xff000000; break; - case 0 : return c; /* zero length strings require no mixing */ - } + switch(length) + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=k[2]&0xffffff00; b+=k[1]; a+=k[0]; break; + case 10: c+=k[2]&0xffff0000; b+=k[1]; a+=k[0]; break; + case 9 : c+=k[2]&0xff000000; b+=k[1]; a+=k[0]; break; + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=k[1]&0xffffff00; a+=k[0]; break; + case 6 : b+=k[1]&0xffff0000; a+=k[0]; break; + case 5 : b+=k[1]&0xff000000; a+=k[0]; break; + case 4 : a+=k[0]; break; + case 3 : a+=k[0]&0xffffff00; break; + case 2 : a+=k[0]&0xffff0000; break; + case 1 : a+=k[0]&0xff000000; break; + case 0 : return c; /* zero length strings require no mixing */ + } #else /* make valgrind happy */ - k8 = (const uint8_t *)k; - switch(length) /* all the case statements fall through */ - { - case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; - case 11: c+=((uint32_t)k8[10])<<8; /* fall through */ - case 10: c+=((uint32_t)k8[9])<<16; /* fall through */ - case 9 : c+=((uint32_t)k8[8])<<24; /* fall through */ - case 8 : b+=k[1]; a+=k[0]; break; - case 7 : b+=((uint32_t)k8[6])<<8; /* fall through */ - case 6 : b+=((uint32_t)k8[5])<<16; /* fall through */ - case 5 : b+=((uint32_t)k8[4])<<24; /* fall through */ - case 4 : a+=k[0]; break; - case 3 : a+=((uint32_t)k8[2])<<8; /* fall through */ - case 2 : a+=((uint32_t)k8[1])<<16; /* fall through */ - case 1 : a+=((uint32_t)k8[0])<<24; break; - case 0 : return c; - } + k8 = (const uint8_t *)k; + switch(length) /* all the case statements fall through */ + { + case 12: c+=k[2]; b+=k[1]; a+=k[0]; break; + case 11: c+=((uint32_t)k8[10])<<8; /* fall through */ + case 10: c+=((uint32_t)k8[9])<<16; /* fall through */ + case 9 : c+=((uint32_t)k8[8])<<24; /* fall through */ + case 8 : b+=k[1]; a+=k[0]; break; + case 7 : b+=((uint32_t)k8[6])<<8; /* fall through */ + case 6 : b+=((uint32_t)k8[5])<<16; /* fall through */ + case 5 : b+=((uint32_t)k8[4])<<24; /* fall through */ + case 4 : a+=k[0]; break; + case 3 : a+=((uint32_t)k8[2])<<8; /* fall through */ + case 2 : a+=((uint32_t)k8[1])<<16; /* fall through */ + case 1 : a+=((uint32_t)k8[0])<<24; break; + case 0 : return c; + } #endif /* !VALGRIND */ - } else { /* need to read the key one byte at a time */ - const uint8_t *k = (const uint8_t *)key; + } else { /* need to read the key one byte at a time */ + const uint8_t *k = (const uint8_t *)key; - /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ - while (length > 12) - { - a += ((uint32_t)k[0])<<24; - a += ((uint32_t)k[1])<<16; - a += ((uint32_t)k[2])<<8; - a += ((uint32_t)k[3]); - b += ((uint32_t)k[4])<<24; - b += ((uint32_t)k[5])<<16; - b += ((uint32_t)k[6])<<8; - b += ((uint32_t)k[7]); - c += ((uint32_t)k[8])<<24; - c += ((uint32_t)k[9])<<16; - c += ((uint32_t)k[10])<<8; - c += ((uint32_t)k[11]); - mix(a,b,c); - length -= 12; - k += 12; - } + /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ + while (length > 12) + { + a += ((uint32_t)k[0])<<24; + a += ((uint32_t)k[1])<<16; + a += ((uint32_t)k[2])<<8; + a += ((uint32_t)k[3]); + b += ((uint32_t)k[4])<<24; + b += ((uint32_t)k[5])<<16; + b += ((uint32_t)k[6])<<8; + b += ((uint32_t)k[7]); + c += ((uint32_t)k[8])<<24; + c += ((uint32_t)k[9])<<16; + c += ((uint32_t)k[10])<<8; + c += ((uint32_t)k[11]); + mix(a,b,c); + length -= 12; + k += 12; + } - /*-------------------------------- last block: affect all 32 bits of (c) */ - switch(length) /* all the case statements fall through */ - { - case 12: c+=k[11]; - case 11: c+=((uint32_t)k[10])<<8; - case 10: c+=((uint32_t)k[9])<<16; - case 9 : c+=((uint32_t)k[8])<<24; - case 8 : b+=k[7]; - case 7 : b+=((uint32_t)k[6])<<8; - case 6 : b+=((uint32_t)k[5])<<16; - case 5 : b+=((uint32_t)k[4])<<24; - case 4 : a+=k[3]; - case 3 : a+=((uint32_t)k[2])<<8; - case 2 : a+=((uint32_t)k[1])<<16; - case 1 : a+=((uint32_t)k[0])<<24; - break; - case 0 : return c; - } - } + /*-------------------------------- last block: affect all 32 bits of (c) */ + switch(length) /* all the case statements fall through */ + { + case 12: c+=k[11]; + case 11: c+=((uint32_t)k[10])<<8; + case 10: c+=((uint32_t)k[9])<<16; + case 9 : c+=((uint32_t)k[8])<<24; + case 8 : b+=k[7]; + case 7 : b+=((uint32_t)k[6])<<8; + case 6 : b+=((uint32_t)k[5])<<16; + case 5 : b+=((uint32_t)k[4])<<24; + case 4 : a+=k[3]; + case 3 : a+=((uint32_t)k[2])<<8; + case 2 : a+=((uint32_t)k[1])<<16; + case 1 : a+=((uint32_t)k[0])<<24; + break; + case 0 : return c; + } + } - final(a,b,c); - return c; + final(a,b,c); + return c; } @@ -766,19 +765,19 @@ uint32_t hashbig( const void *key, size_t length, uint32_t initval) /* used for timings */ void driver1() { - uint8_t buf[256]; - uint32_t i; - uint32_t h=0; - time_t a,z; + uint8_t buf[256]; + uint32_t i; + uint32_t h=0; + time_t a,z; - time(&a); - for (i=0; i<256; ++i) buf[i] = 'x'; - for (i=0; i<1; ++i) - { - h = hashlittle(&buf[0],1,h); - } - time(&z); - if (z-a > 0) printf("time %d %.8x\n", z-a, h); + time(&a); + for (i=0; i<256; ++i) buf[i] = 'x'; + for (i=0; i<1; ++i) + { + h = hashlittle(&buf[0],1,h); + } + time(&z); + if (z-a > 0) printf("time %d %.8x\n", z-a, h); } /* check that every input bit changes every output bit half the time */ @@ -788,211 +787,210 @@ void driver1() #define MAXLEN 70 void driver2() { - uint8_t qa[MAXLEN+1], qb[MAXLEN+2], *a = &qa[0], *b = &qb[1]; - uint32_t c[HASHSTATE], d[HASHSTATE], i=0, j=0, k, l, m=0, z; - uint32_t e[HASHSTATE],f[HASHSTATE],g[HASHSTATE],h[HASHSTATE]; - uint32_t x[HASHSTATE],y[HASHSTATE]; - uint32_t hlen; + uint8_t qa[MAXLEN+1], qb[MAXLEN+2], *a = &qa[0], *b = &qb[1]; + uint32_t c[HASHSTATE], d[HASHSTATE], i=0, j=0, k, l, m=0, z; + uint32_t e[HASHSTATE],f[HASHSTATE],g[HASHSTATE],h[HASHSTATE]; + uint32_t x[HASHSTATE],y[HASHSTATE]; + uint32_t hlen; - printf("No more than %d trials should ever be needed \n",MAXPAIR/2); - for (hlen=0; hlen < MAXLEN; ++hlen) - { - z=0; - for (i=0; i>(8-j)); - c[0] = hashlittle(a, hlen, m); - b[i] ^= ((k+1)<>(8-j)); - d[0] = hashlittle(b, hlen, m); - /* check every bit is 1, 0, set, and not set at least once */ - for (l=0; lz) z=k; - if (k==MAXPAIR) - { - printf("Some bit didn't change: "); - printf("%.8x %.8x %.8x %.8x %.8x %.8x ", - e[0],f[0],g[0],h[0],x[0],y[0]); - printf("i %d j %d m %d len %d\n", i, j, m, hlen); - } - if (z==MAXPAIR) goto done; + z=0; + for (i=0; i>(8-j)); + c[0] = hashlittle(a, hlen, m); + b[i] ^= ((k+1)<>(8-j)); + d[0] = hashlittle(b, hlen, m); + /* check every bit is 1, 0, set, and not set at least once */ + for (l=0; lz) z=k; + if (k==MAXPAIR) + { + printf("Some bit didn't change: "); + printf("%.8x %.8x %.8x %.8x %.8x %.8x ", + e[0],f[0],g[0],h[0],x[0],y[0]); + printf("i %d j %d m %d len %d\n", i, j, m, hlen); + } + if (z==MAXPAIR) goto done; + } + } + } +done: + if (z < MAXPAIR) + { + printf("Mix success %2d bytes %2d initvals ",i,m); + printf("required %d trials\n", z/2); + } } - } - } - done: - if (z < MAXPAIR) - { - printf("Mix success %2d bytes %2d initvals ",i,m); - printf("required %d trials\n", z/2); - } - } - printf("\n"); + printf("\n"); } /* Check for reading beyond the end of the buffer and alignment problems */ void driver3() { - uint8_t buf[MAXLEN+20], *b; - uint32_t len; - uint8_t q[] = "This is the time for all good men to come to the aid of their country..."; - uint32_t h; - uint8_t qq[] = "xThis is the time for all good men to come to the aid of their country..."; - uint32_t i; - uint8_t qqq[] = "xxThis is the time for all good men to come to the aid of their country..."; - uint32_t j; - uint8_t qqqq[] = "xxxThis is the time for all good men to come to the aid of their country..."; - uint32_t ref,x,y; - uint8_t *p; + uint8_t buf[MAXLEN+20], *b; + uint32_t len; + uint8_t q[] = "This is the time for all good men to come to the aid of their country..."; + uint32_t h; + uint8_t qq[] = "xThis is the time for all good men to come to the aid of their country..."; + uint32_t i; + uint8_t qqq[] = "xxThis is the time for all good men to come to the aid of their country..."; + uint32_t j; + uint8_t qqqq[] = "xxxThis is the time for all good men to come to the aid of their country..."; + uint32_t ref,x,y; + uint8_t *p; - printf("Endianness. These lines should all be the same (for values filled in):\n"); - printf("%.8x %.8x %.8x\n", - hashword((const uint32_t *)q, (sizeof(q)-1)/4, 13), - hashword((const uint32_t *)q, (sizeof(q)-5)/4, 13), - hashword((const uint32_t *)q, (sizeof(q)-9)/4, 13)); - p = q; - printf("%.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n", - hashlittle(p, sizeof(q)-1, 13), hashlittle(p, sizeof(q)-2, 13), - hashlittle(p, sizeof(q)-3, 13), hashlittle(p, sizeof(q)-4, 13), - hashlittle(p, sizeof(q)-5, 13), hashlittle(p, sizeof(q)-6, 13), - hashlittle(p, sizeof(q)-7, 13), hashlittle(p, sizeof(q)-8, 13), - hashlittle(p, sizeof(q)-9, 13), hashlittle(p, sizeof(q)-10, 13), - hashlittle(p, sizeof(q)-11, 13), hashlittle(p, sizeof(q)-12, 13)); - p = &qq[1]; - printf("%.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n", - hashlittle(p, sizeof(q)-1, 13), hashlittle(p, sizeof(q)-2, 13), - hashlittle(p, sizeof(q)-3, 13), hashlittle(p, sizeof(q)-4, 13), - hashlittle(p, sizeof(q)-5, 13), hashlittle(p, sizeof(q)-6, 13), - hashlittle(p, sizeof(q)-7, 13), hashlittle(p, sizeof(q)-8, 13), - hashlittle(p, sizeof(q)-9, 13), hashlittle(p, sizeof(q)-10, 13), - hashlittle(p, sizeof(q)-11, 13), hashlittle(p, sizeof(q)-12, 13)); - p = &qqq[2]; - printf("%.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n", - hashlittle(p, sizeof(q)-1, 13), hashlittle(p, sizeof(q)-2, 13), - hashlittle(p, sizeof(q)-3, 13), hashlittle(p, sizeof(q)-4, 13), - hashlittle(p, sizeof(q)-5, 13), hashlittle(p, sizeof(q)-6, 13), - hashlittle(p, sizeof(q)-7, 13), hashlittle(p, sizeof(q)-8, 13), - hashlittle(p, sizeof(q)-9, 13), hashlittle(p, sizeof(q)-10, 13), - hashlittle(p, sizeof(q)-11, 13), hashlittle(p, sizeof(q)-12, 13)); - p = &qqqq[3]; - printf("%.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n", - hashlittle(p, sizeof(q)-1, 13), hashlittle(p, sizeof(q)-2, 13), - hashlittle(p, sizeof(q)-3, 13), hashlittle(p, sizeof(q)-4, 13), - hashlittle(p, sizeof(q)-5, 13), hashlittle(p, sizeof(q)-6, 13), - hashlittle(p, sizeof(q)-7, 13), hashlittle(p, sizeof(q)-8, 13), - hashlittle(p, sizeof(q)-9, 13), hashlittle(p, sizeof(q)-10, 13), - hashlittle(p, sizeof(q)-11, 13), hashlittle(p, sizeof(q)-12, 13)); - printf("\n"); + printf("Endianness. These lines should all be the same (for values filled in):\n"); + printf("%.8x %.8x %.8x\n", + hashword((const uint32_t *)q, (sizeof(q)-1)/4, 13), + hashword((const uint32_t *)q, (sizeof(q)-5)/4, 13), + hashword((const uint32_t *)q, (sizeof(q)-9)/4, 13)); + p = q; + printf("%.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n", + hashlittle(p, sizeof(q)-1, 13), hashlittle(p, sizeof(q)-2, 13), + hashlittle(p, sizeof(q)-3, 13), hashlittle(p, sizeof(q)-4, 13), + hashlittle(p, sizeof(q)-5, 13), hashlittle(p, sizeof(q)-6, 13), + hashlittle(p, sizeof(q)-7, 13), hashlittle(p, sizeof(q)-8, 13), + hashlittle(p, sizeof(q)-9, 13), hashlittle(p, sizeof(q)-10, 13), + hashlittle(p, sizeof(q)-11, 13), hashlittle(p, sizeof(q)-12, 13)); + p = &qq[1]; + printf("%.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n", + hashlittle(p, sizeof(q)-1, 13), hashlittle(p, sizeof(q)-2, 13), + hashlittle(p, sizeof(q)-3, 13), hashlittle(p, sizeof(q)-4, 13), + hashlittle(p, sizeof(q)-5, 13), hashlittle(p, sizeof(q)-6, 13), + hashlittle(p, sizeof(q)-7, 13), hashlittle(p, sizeof(q)-8, 13), + hashlittle(p, sizeof(q)-9, 13), hashlittle(p, sizeof(q)-10, 13), + hashlittle(p, sizeof(q)-11, 13), hashlittle(p, sizeof(q)-12, 13)); + p = &qqq[2]; + printf("%.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n", + hashlittle(p, sizeof(q)-1, 13), hashlittle(p, sizeof(q)-2, 13), + hashlittle(p, sizeof(q)-3, 13), hashlittle(p, sizeof(q)-4, 13), + hashlittle(p, sizeof(q)-5, 13), hashlittle(p, sizeof(q)-6, 13), + hashlittle(p, sizeof(q)-7, 13), hashlittle(p, sizeof(q)-8, 13), + hashlittle(p, sizeof(q)-9, 13), hashlittle(p, sizeof(q)-10, 13), + hashlittle(p, sizeof(q)-11, 13), hashlittle(p, sizeof(q)-12, 13)); + p = &qqqq[3]; + printf("%.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x %.8x\n", + hashlittle(p, sizeof(q)-1, 13), hashlittle(p, sizeof(q)-2, 13), + hashlittle(p, sizeof(q)-3, 13), hashlittle(p, sizeof(q)-4, 13), + hashlittle(p, sizeof(q)-5, 13), hashlittle(p, sizeof(q)-6, 13), + hashlittle(p, sizeof(q)-7, 13), hashlittle(p, sizeof(q)-8, 13), + hashlittle(p, sizeof(q)-9, 13), hashlittle(p, sizeof(q)-10, 13), + hashlittle(p, sizeof(q)-11, 13), hashlittle(p, sizeof(q)-12, 13)); + printf("\n"); - /* check that hashlittle2 and hashlittle produce the same results */ - i=47; j=0; - hashlittle2(q, sizeof(q), &i, &j); - if (hashlittle(q, sizeof(q), 47) != i) - printf("hashlittle2 and hashlittle mismatch\n"); + /* check that hashlittle2 and hashlittle produce the same results */ + i=47; j=0; + hashlittle2(q, sizeof(q), &i, &j); + if (hashlittle(q, sizeof(q), 47) != i) + printf("hashlittle2 and hashlittle mismatch\n"); - /* check that hashword2 and hashword produce the same results */ - len = 0xdeadbeef; - i=47, j=0; - hashword2(&len, 1, &i, &j); - if (hashword(&len, 1, 47) != i) - printf("hashword2 and hashword mismatch %x %x\n", - i, hashword(&len, 1, 47)); + /* check that hashword2 and hashword produce the same results */ + len = 0xdeadbeef; + i=47, j=0; + hashword2(&len, 1, &i, &j); + if (hashword(&len, 1, 47) != i) + printf("hashword2 and hashword mismatch %x %x\n", + i, hashword(&len, 1, 47)); - /* check hashlittle doesn't read before or after the ends of the string */ - for (h=0, b=buf+1; h<8; ++h, ++b) - { - for (i=0; istorage; snprintf(mntoa_buf, sizeof(mntoa_buf), - "%02x:%02x:%02x:%02x:%02x:%02x", - m[0], m[1], m[2], m[3], m[4], m[5]); + "%02x:%02x:%02x:%02x:%02x:%02x", + m[0], m[1], m[2], m[3], m[4], m[5]); return mntoa_buf; } diff --git a/package/gluon-mesh-batman-adv/src/respondd-neighbours.c b/package/gluon-mesh-batman-adv/src/respondd-neighbours.c index 344b8f69..5785e358 100644 --- a/package/gluon-mesh-batman-adv/src/respondd-neighbours.c +++ b/package/gluon-mesh-batman-adv/src/respondd-neighbours.c @@ -68,7 +68,7 @@ static int parse_orig_list_netlink_cb(struct nl_msg *msg, void *arg) char mac1[18]; opts = batadv_container_of(query_opts, struct neigh_netlink_opts, - query_opts); + query_opts); if (!genlmsg_valid_hdr(nlh, 0)) return NL_OK; @@ -79,11 +79,11 @@ static int parse_orig_list_netlink_cb(struct nl_msg *msg, void *arg) return NL_OK; if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), - genlmsg_len(ghdr), batadv_genl_policy)) + genlmsg_len(ghdr), batadv_genl_policy)) return NL_OK; if (batadv_genl_missing_attrs(attrs, parse_orig_list_mandatory, - BATADV_ARRAY_SIZE(parse_orig_list_mandatory))) + BATADV_ARRAY_SIZE(parse_orig_list_mandatory))) return NL_OK; orig = nla_data(attrs[BATADV_ATTR_ORIG_ADDRESS]); diff --git a/package/gluon-mesh-batman-adv/src/respondd-nodeinfo.c b/package/gluon-mesh-batman-adv/src/respondd-nodeinfo.c index 57ca8a19..8cef4e8b 100644 --- a/package/gluon-mesh-batman-adv/src/respondd-nodeinfo.c +++ b/package/gluon-mesh-batman-adv/src/respondd-nodeinfo.c @@ -106,7 +106,7 @@ static bool interface_file_exists(const char *ifname, const char *name) { } static void mesh_add_subif(const char *ifname, struct json_object *wireless, - struct json_object *tunnel, struct json_object *other) { + struct json_object *tunnel, struct json_object *other) { struct json_object *address = gluonutil_wrap_and_free_string(gluonutil_get_interface_address(ifname)); /* In case of VLAN and bridge interfaces, we want the lower interface @@ -144,7 +144,7 @@ static struct json_object * get_mesh_subifs(const char *ifname) { size_t i; for (i = 0; i < lower.gl_pathc; i++) { mesh_add_subif(lower.gl_pathv[i] + pattern_len - 1, - wireless, tunnel, other); + wireless, tunnel, other); } globfree(&lower); diff --git a/package/gluon-mesh-batman-adv/src/respondd-statistics.c b/package/gluon-mesh-batman-adv/src/respondd-statistics.c index cc4db719..28131fda 100644 --- a/package/gluon-mesh-batman-adv/src/respondd-statistics.c +++ b/package/gluon-mesh-batman-adv/src/respondd-statistics.c @@ -57,7 +57,7 @@ static int parse_gw_list_netlink_cb(struct nl_msg *msg, void *arg) char addr[18]; opts = batadv_container_of(query_opts, struct gw_netlink_opts, - query_opts); + query_opts); if (!genlmsg_valid_hdr(nlh, 0)) return NL_OK; @@ -68,11 +68,11 @@ static int parse_gw_list_netlink_cb(struct nl_msg *msg, void *arg) return NL_OK; if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), - genlmsg_len(ghdr), batadv_genl_policy)) + genlmsg_len(ghdr), batadv_genl_policy)) return NL_OK; if (batadv_genl_missing_attrs(attrs, gateways_mandatory, - BATADV_ARRAY_SIZE(gateways_mandatory))) + BATADV_ARRAY_SIZE(gateways_mandatory))) return NL_OK; if (!attrs[BATADV_ATTR_FLAG_BEST]) @@ -105,8 +105,8 @@ static void add_gateway(struct json_object *obj) { }; batadv_genl_query("bat0", BATADV_CMD_GET_GATEWAYS, - parse_gw_list_netlink_cb, NLM_F_DUMP, - &opts.query_opts); + parse_gw_list_netlink_cb, NLM_F_DUMP, + &opts.query_opts); } static inline bool ethtool_ioctl(int fd, struct ifreq *ifr, void *data) { @@ -214,7 +214,7 @@ static struct json_object * get_traffic(void) { json_object_object_add(ret, "mgmt_rx", mgmt_rx); json_object_object_add(ret, "mgmt_tx", mgmt_tx); - out: +out: free(stats); free(strings); close(fd); @@ -241,7 +241,7 @@ static int parse_clients_list_netlink_cb(struct nl_msg *msg, void *arg) uint32_t flags, lastseen; opts = batadv_container_of(query_opts, struct clients_netlink_opts, - query_opts); + query_opts); if (!genlmsg_valid_hdr(nlh, 0)) return NL_OK; @@ -252,11 +252,11 @@ static int parse_clients_list_netlink_cb(struct nl_msg *msg, void *arg) return NL_OK; if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), - genlmsg_len(ghdr), batadv_genl_policy)) + genlmsg_len(ghdr), batadv_genl_policy)) return NL_OK; if (batadv_genl_missing_attrs(attrs, clients_mandatory, - BATADV_ARRAY_SIZE(clients_mandatory))) + BATADV_ARRAY_SIZE(clients_mandatory))) return NL_OK; flags = nla_get_u32(attrs[BATADV_ATTR_TT_FLAGS]); @@ -282,8 +282,8 @@ static struct json_object * get_clients(void) { }; batadv_genl_query("bat0", BATADV_CMD_GET_TRANSTABLE_LOCAL, - parse_clients_list_netlink_cb, NLM_F_DUMP, - &opts.query_opts); + parse_clients_list_netlink_cb, NLM_F_DUMP, + &opts.query_opts); struct json_object *ret = json_object_new_object(); diff --git a/package/gluon-mesh-vpn-fastd/src/respondd.c b/package/gluon-mesh-vpn-fastd/src/respondd.c index f48ae0c7..a7237216 100644 --- a/package/gluon-mesh-vpn-fastd/src/respondd.c +++ b/package/gluon-mesh-vpn-fastd/src/respondd.c @@ -219,7 +219,7 @@ static bool get_peer_connection(struct json_object **ret, struct json_object *co struct json_object *peer, *connection, *established; if (!json_object_object_get_ex(peers, key, &peer) || - !json_object_object_get_ex(peer, "connection", &connection)) + !json_object_object_get_ex(peer, "connection", &connection)) return false; if (json_object_object_get_ex(connection, "established", &established)) { @@ -242,7 +242,7 @@ static struct json_object * get_peer_group(struct json_object *config, struct js struct json_object *config_peers; if (json_object_object_get_ex(config, "peers", &config_peers) && - json_object_is_type(config_peers, json_type_object)) { + json_object_is_type(config_peers, json_type_object)) { struct json_object *ret_peers = json_object_new_object(); json_object_object_foreach(config_peers, peername, peerconfig) { @@ -320,7 +320,7 @@ static struct json_object * get_mesh_vpn(void) { ret = get_peer_group(mesh_vpn_fastd, peers); - end: +end: json_object_put(site); json_object_put(status); diff --git a/package/gluon-mesh-vpn-wireguard/src/respondd.c b/package/gluon-mesh-vpn-wireguard/src/respondd.c index 5a46770c..55b3f8fb 100644 --- a/package/gluon-mesh-vpn-wireguard/src/respondd.c +++ b/package/gluon-mesh-vpn-wireguard/src/respondd.c @@ -48,7 +48,7 @@ static struct json_object * stdout_read(const char *cmd, const char *skip, bool if (oneword) { for (int i = 0; i < len; i++) { if (isspace(line[i])) { - line[i] = 0; + line[i] = 0; } } } diff --git a/package/gluon-neighbour-info/src/gluon-neighbour-info.c b/package/gluon-neighbour-info/src/gluon-neighbour-info.c index 7ba5da00..12a51741 100644 --- a/package/gluon-neighbour-info/src/gluon-neighbour-info.c +++ b/package/gluon-neighbour-info/src/gluon-neighbour-info.c @@ -61,7 +61,7 @@ void resize_recvbuffer(char **recvbuffer, size_t *recvbuffer_len, size_t recvlen } ssize_t recvtimeout(int socket, char **recvbuffer, size_t *recvbuffer_len, - const struct timeval *timeout) { + const struct timeval *timeout) { struct timeval now, timeout_left; ssize_t recvlen; @@ -84,8 +84,8 @@ ssize_t recvtimeout(int socket, char **recvbuffer, size_t *recvbuffer_len, } int request(const int sock, char **recvbuffer, size_t *recvbuffer_len, - const struct sockaddr_in6 *client_addr, const char *request, - const char *sse, double timeout, unsigned int max_count) { + const struct sockaddr_in6 *client_addr, const char *request, + const char *sse, double timeout, unsigned int max_count) { ssize_t ret; unsigned int count = 0; @@ -251,7 +251,7 @@ int main(int argc, char **argv) { do { ret = request(sock, &recvbuffer, &recvbuffer_len, &client_addr, - request_string, sse, timeout, max_count); + request_string, sse, timeout, max_count); } while(loop); if (sse) diff --git a/package/gluon-radv-filterd/src/gluon-radv-filterd.c b/package/gluon-radv-filterd/src/gluon-radv-filterd.c index 662f3fe9..f9f8fb87 100644 --- a/package/gluon-radv-filterd/src/gluon-radv-filterd.c +++ b/package/gluon-radv-filterd/src/gluon-radv-filterd.c @@ -59,10 +59,10 @@ #ifdef DEBUG #define CHECK(stmt) \ - if(!(stmt)) { \ - fprintf(stderr, "check failed: " #stmt "\n"); \ - goto check_failed; \ - } + if(!(stmt)) { \ + fprintf(stderr, "check failed: " #stmt "\n"); \ + goto check_failed; \ + } #define DEBUG_MSG(msg, ...) fprintf(stderr, msg "\n", ##__VA_ARGS__) #else #define CHECK(stmt) if(!(stmt)) goto check_failed; @@ -78,8 +78,8 @@ #define foreach_safe(item, safe, list) \ for ((item) = (list); \ - (item) && (((safe) = item->next) || 1); \ - (item) = (safe)) + (item) && (((safe) = item->next) || 1); \ + (item) = (safe)) struct router { struct router *next; @@ -103,7 +103,7 @@ static struct global { }; static int fork_execvp_timeout(struct timespec *timeout, const char *file, - const char *const argv[]); + const char *const argv[]); static void error_message(int status, int errnum, char *message, ...) { va_list ap; @@ -120,7 +120,7 @@ static void error_message(int status, int errnum, char *message, ...) { } static int timespec_diff(struct timespec *tv1, struct timespec *tv2, - struct timespec *tvdiff) + struct timespec *tvdiff) { tvdiff->tv_sec = tv1->tv_sec - tv2->tv_sec; if (tv1->tv_nsec < tv2->tv_nsec) { @@ -219,8 +219,8 @@ static int init_packet_socket(unsigned int ifindex) { }; struct sock_fprog radv_filter = { - .len = ARRAY_SIZE(radv_filter_code), - .filter = radv_filter_code, + .len = ARRAY_SIZE(radv_filter_code), + .filter = radv_filter_code, }; int sock = socket(AF_PACKET, SOCK_DGRAM|SOCK_CLOEXEC, htons(ETH_P_IPV6)); @@ -382,7 +382,7 @@ static void expire_routers(void) { } static int parse_tt_global(struct nl_msg *msg, - void *arg __attribute__((unused))) + void *arg __attribute__((unused))) { static const enum batadv_nl_attrs mandatory[] = { BATADV_ATTR_TT_ADDRESS, @@ -406,7 +406,7 @@ static int parse_tt_global(struct nl_msg *msg, return NL_OK; if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), - genlmsg_len(ghdr), batadv_genl_policy)) { + genlmsg_len(ghdr), batadv_genl_policy)) { return NL_OK; } @@ -428,14 +428,14 @@ static int parse_tt_global(struct nl_msg *msg, return NL_OK; DEBUG_MSG("Found originator for " F_MAC ", it's " F_MAC, - F_MAC_VAR(router->src), F_MAC_VAR(mac_b)); + F_MAC_VAR(router->src), F_MAC_VAR(mac_b)); router->originator = mac_b; return NL_OK; } static int parse_originator(struct nl_msg *msg, - void *arg __attribute__((unused))) + void *arg __attribute__((unused))) { static const enum batadv_nl_attrs mandatory[] = { @@ -460,7 +460,7 @@ static int parse_originator(struct nl_msg *msg, return NL_OK; if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), - genlmsg_len(ghdr), batadv_genl_policy)) { + genlmsg_len(ghdr), batadv_genl_policy)) { return NL_OK; } @@ -481,7 +481,7 @@ static int parse_originator(struct nl_msg *msg, return NL_OK; DEBUG_MSG("Found TQ for router " F_MAC " (originator " F_MAC "), it's %d", - F_MAC_VAR(router->src), F_MAC_VAR(router->originator), tq); + F_MAC_VAR(router->src), F_MAC_VAR(router->originator), tq); router->tq = tq; if (router->tq > G.max_tq) G.max_tq = router->tq; @@ -490,7 +490,7 @@ static int parse_originator(struct nl_msg *msg, } static int parse_tt_local(struct nl_msg *msg, - void *arg __attribute__((unused))) + void *arg __attribute__((unused))) { static const enum batadv_nl_attrs mandatory[] = { BATADV_ATTR_TT_ADDRESS, @@ -512,7 +512,7 @@ static int parse_tt_local(struct nl_msg *msg, return NL_OK; if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), - genlmsg_len(ghdr), batadv_genl_policy)) { + genlmsg_len(ghdr), batadv_genl_policy)) { return NL_OK; } @@ -528,7 +528,7 @@ static int parse_tt_local(struct nl_msg *msg, return NL_OK; DEBUG_MSG("Found router " F_MAC " in transtable_local, assigning TQ %d", - F_MAC_VAR(router->src), LOCAL_TQ); + F_MAC_VAR(router->src), LOCAL_TQ); router->tq = LOCAL_TQ; if (router->tq > G.max_tq) G.max_tq = router->tq; @@ -770,7 +770,7 @@ int main(int argc, char *argv[]) { clock_gettime(CLOCK_MONOTONIC, &now); if (G.routers != NULL && - timespec_diff(&now, &next_update, &diff)) { + timespec_diff(&now, &next_update, &diff)) { expire_routers(); // all routers could have expired, check again diff --git a/package/gluon-radv-filterd/src/mac.h b/package/gluon-radv-filterd/src/mac.h index eece1105..ac4fcda3 100644 --- a/package/gluon-radv-filterd/src/mac.h +++ b/package/gluon-radv-filterd/src/mac.h @@ -15,7 +15,7 @@ &(var).ether_addr_octet[2], &(var).ether_addr_octet[3], \ &(var).ether_addr_octet[4], &(var).ether_addr_octet[5] #define MAC2ETHER(_ether, _mac) memcpy((_ether).ether_addr_octet, \ - (_mac), ETH_ALEN) + (_mac), ETH_ALEN) #define ether_addr_equal(_a, _b) (memcmp((_a).ether_addr_octet, \ - (_b).ether_addr_octet, ETH_ALEN) == 0) + (_b).ether_addr_octet, ETH_ALEN) == 0) diff --git a/package/gluon-respondd/src/respondd-neighbours.c b/package/gluon-respondd/src/respondd-neighbours.c index 9a96b964..f86dac45 100644 --- a/package/gluon-respondd/src/respondd-neighbours.c +++ b/package/gluon-respondd/src/respondd-neighbours.c @@ -34,8 +34,8 @@ static struct json_object * get_wifi_neighbours(const char *ifname) { char mac[18]; snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x", - entry->mac[0], entry->mac[1], entry->mac[2], - entry->mac[3], entry->mac[4], entry->mac[5]); + entry->mac[0], entry->mac[1], entry->mac[2], + entry->mac[3], entry->mac[4], entry->mac[5]); json_object_object_add(neighbours, mac, obj); } diff --git a/package/gluon-respondd/src/respondd-statistics.c b/package/gluon-respondd/src/respondd-statistics.c index e21d7b4e..4dbe9437 100644 --- a/package/gluon-respondd/src/respondd-statistics.c +++ b/package/gluon-respondd/src/respondd-statistics.c @@ -112,7 +112,7 @@ static struct json_object * get_stat(void) { if (!strcmp(label, "cpu")) { int64_t user, nice, system, idle, iowait, irq, softirq; if (sscanf(line, "%*s %"SCNd64" %"SCNd64" %"SCNd64" %"SCNd64" %"SCNd64" %"SCNd64" %"SCNd64, - &user, &nice, &system, &idle, &iowait, &irq, &softirq) != 7) + &user, &nice, &system, &idle, &iowait, &irq, &softirq) != 7) goto invalid_stat_format; struct json_object *cpu = json_object_new_object(); @@ -253,7 +253,7 @@ static void count_stations(size_t *wifi24, size_t *wifi5, size_t *owe24, size_t count_iface_stations(wifi24, wifi5, ifname); } - end: +end: uci_free_context(ctx); } diff --git a/package/gluon-status-page-mesh-batman-adv/src/neighbours-batadv.c b/package/gluon-status-page-mesh-batman-adv/src/neighbours-batadv.c index 9c2be2f7..ae930548 100644 --- a/package/gluon-status-page-mesh-batman-adv/src/neighbours-batadv.c +++ b/package/gluon-status-page-mesh-batman-adv/src/neighbours-batadv.c @@ -10,116 +10,116 @@ #define XSTR(x) STR(x) struct neigh_netlink_opts { - struct json_object *obj; - struct batadv_nlquery_opts query_opts; + struct json_object *obj; + struct batadv_nlquery_opts query_opts; }; static const enum batadv_nl_attrs parse_orig_list_mandatory[] = { - BATADV_ATTR_ORIG_ADDRESS, - BATADV_ATTR_NEIGH_ADDRESS, - BATADV_ATTR_TQ, - BATADV_ATTR_HARD_IFINDEX, - BATADV_ATTR_LAST_SEEN_MSECS, + BATADV_ATTR_ORIG_ADDRESS, + BATADV_ATTR_NEIGH_ADDRESS, + BATADV_ATTR_TQ, + BATADV_ATTR_HARD_IFINDEX, + BATADV_ATTR_LAST_SEEN_MSECS, }; static int parse_orig_list_netlink_cb(struct nl_msg *msg, void *arg) { - struct nlattr *attrs[BATADV_ATTR_MAX+1]; - struct nlmsghdr *nlh = nlmsg_hdr(msg); - struct batadv_nlquery_opts *query_opts = arg; - struct genlmsghdr *ghdr; - uint8_t *orig; - uint8_t *dest; - uint8_t tq; - uint32_t hardif; - char ifname_buf[IF_NAMESIZE], *ifname; - struct neigh_netlink_opts *opts; - char mac1[18]; + struct nlattr *attrs[BATADV_ATTR_MAX+1]; + struct nlmsghdr *nlh = nlmsg_hdr(msg); + struct batadv_nlquery_opts *query_opts = arg; + struct genlmsghdr *ghdr; + uint8_t *orig; + uint8_t *dest; + uint8_t tq; + uint32_t hardif; + char ifname_buf[IF_NAMESIZE], *ifname; + struct neigh_netlink_opts *opts; + char mac1[18]; - opts = batadv_container_of(query_opts, struct neigh_netlink_opts, query_opts); + opts = batadv_container_of(query_opts, struct neigh_netlink_opts, query_opts); - if (!genlmsg_valid_hdr(nlh, 0)) - return NL_OK; + if (!genlmsg_valid_hdr(nlh, 0)) + return NL_OK; - ghdr = nlmsg_data(nlh); + ghdr = nlmsg_data(nlh); - if (ghdr->cmd != BATADV_CMD_GET_ORIGINATORS) - return NL_OK; + if (ghdr->cmd != BATADV_CMD_GET_ORIGINATORS) + return NL_OK; - if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), - genlmsg_len(ghdr), batadv_genl_policy)) - return NL_OK; + if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), + genlmsg_len(ghdr), batadv_genl_policy)) + return NL_OK; - if (batadv_genl_missing_attrs(attrs, parse_orig_list_mandatory, - BATADV_ARRAY_SIZE(parse_orig_list_mandatory))) - return NL_OK; + if (batadv_genl_missing_attrs(attrs, parse_orig_list_mandatory, + BATADV_ARRAY_SIZE(parse_orig_list_mandatory))) + return NL_OK; - orig = nla_data(attrs[BATADV_ATTR_ORIG_ADDRESS]); - dest = nla_data(attrs[BATADV_ATTR_NEIGH_ADDRESS]); - tq = nla_get_u8(attrs[BATADV_ATTR_TQ]); - hardif = nla_get_u32(attrs[BATADV_ATTR_HARD_IFINDEX]); + orig = nla_data(attrs[BATADV_ATTR_ORIG_ADDRESS]); + dest = nla_data(attrs[BATADV_ATTR_NEIGH_ADDRESS]); + tq = nla_get_u8(attrs[BATADV_ATTR_TQ]); + hardif = nla_get_u32(attrs[BATADV_ATTR_HARD_IFINDEX]); - if (memcmp(orig, dest, 6) != 0) - return NL_OK; + if (memcmp(orig, dest, 6) != 0) + return NL_OK; - ifname = if_indextoname(hardif, ifname_buf); - if (!ifname) - return NL_OK; + ifname = if_indextoname(hardif, ifname_buf); + if (!ifname) + return NL_OK; - sprintf(mac1, "%02x:%02x:%02x:%02x:%02x:%02x", - orig[0], orig[1], orig[2], orig[3], orig[4], orig[5]); + sprintf(mac1, "%02x:%02x:%02x:%02x:%02x:%02x", + orig[0], orig[1], orig[2], orig[3], orig[4], orig[5]); - struct json_object *neigh = json_object_new_object(); - if (!neigh) - return NL_OK; + struct json_object *neigh = json_object_new_object(); + if (!neigh) + return NL_OK; - json_object_object_add(neigh, "tq", json_object_new_int(tq * 100 / 255)); - json_object_object_add(neigh, "ifname", json_object_new_string(ifname)); - json_object_object_add(neigh, "best", json_object_new_boolean(attrs[BATADV_ATTR_FLAG_BEST])); + json_object_object_add(neigh, "tq", json_object_new_int(tq * 100 / 255)); + json_object_object_add(neigh, "ifname", json_object_new_string(ifname)); + json_object_object_add(neigh, "best", json_object_new_boolean(attrs[BATADV_ATTR_FLAG_BEST])); - json_object_object_add(opts->obj, mac1, neigh); + json_object_object_add(opts->obj, mac1, neigh); - return NL_OK; + return NL_OK; } static json_object *neighbours(void) { - struct neigh_netlink_opts opts = { - .query_opts = { - .err = 0, - }, - }; - int ret; + struct neigh_netlink_opts opts = { + .query_opts = { + .err = 0, + }, + }; + int ret; - opts.obj = json_object_new_object(); - if (!opts.obj) - return NULL; + opts.obj = json_object_new_object(); + if (!opts.obj) + return NULL; - ret = batadv_genl_query("bat0", BATADV_CMD_GET_ORIGINATORS, - parse_orig_list_netlink_cb, NLM_F_DUMP, - &opts.query_opts); - if (ret < 0) { - json_object_put(opts.obj); - return NULL; - } + ret = batadv_genl_query("bat0", BATADV_CMD_GET_ORIGINATORS, + parse_orig_list_netlink_cb, NLM_F_DUMP, + &opts.query_opts); + if (ret < 0) { + json_object_put(opts.obj); + return NULL; + } - return opts.obj; + return opts.obj; } int main(void) { - struct json_object *obj; + struct json_object *obj; - printf("Content-type: text/event-stream\n\n"); - fflush(stdout); + printf("Content-type: text/event-stream\n\n"); + fflush(stdout); - while (1) { - obj = neighbours(); - if (obj) { - printf("data: %s\n\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN)); - fflush(stdout); - json_object_put(obj); - } - sleep(10); - } + while (1) { + obj = neighbours(); + if (obj) { + printf("data: %s\n\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN)); + fflush(stdout); + json_object_put(obj); + } + sleep(10); + } - return 0; + return 0; } diff --git a/package/gluon-status-page/src/stations.c b/package/gluon-status-page/src/stations.c index 24775a07..06a766e0 100644 --- a/package/gluon-status-page/src/stations.c +++ b/package/gluon-status-page/src/stations.c @@ -12,115 +12,115 @@ #define LOWERGLOB_SUFFIX "/lower_*" static struct json_object *get_stations(const struct iwinfo_ops *iw, const char *ifname) { - int len; - char buf[IWINFO_BUFSIZE]; - struct json_object *stations = json_object_new_object(); + int len; + char buf[IWINFO_BUFSIZE]; + struct json_object *stations = json_object_new_object(); - if (iw->assoclist(ifname, buf, &len) == -1) - return stations; + if (iw->assoclist(ifname, buf, &len) == -1) + return stations; - // This is just: for entry in assoclist(ifname) - for (struct iwinfo_assoclist_entry *entry = (struct iwinfo_assoclist_entry *)buf; - (char*)(entry+1) <= buf + len; entry++) { - struct json_object *station = json_object_new_object(); + // This is just: for entry in assoclist(ifname) + for (struct iwinfo_assoclist_entry *entry = (struct iwinfo_assoclist_entry *)buf; + (char*)(entry+1) <= buf + len; entry++) { + struct json_object *station = json_object_new_object(); - json_object_object_add(station, "signal", json_object_new_int(entry->signal)); - json_object_object_add(station, "noise", json_object_new_int(entry->noise)); - json_object_object_add(station, "inactive", json_object_new_int(entry->inactive)); + json_object_object_add(station, "signal", json_object_new_int(entry->signal)); + json_object_object_add(station, "noise", json_object_new_int(entry->noise)); + json_object_object_add(station, "inactive", json_object_new_int(entry->inactive)); - char macstr[18]; + char macstr[18]; - snprintf(macstr, sizeof(macstr), "%02x:%02x:%02x:%02x:%02x:%02x", - entry->mac[0], entry->mac[1], entry->mac[2], - entry->mac[3], entry->mac[4], entry->mac[5]); + snprintf(macstr, sizeof(macstr), "%02x:%02x:%02x:%02x:%02x:%02x", + entry->mac[0], entry->mac[1], entry->mac[2], + entry->mac[3], entry->mac[4], entry->mac[5]); - json_object_object_add(stations, macstr, station); - } + json_object_object_add(stations, macstr, station); + } - return stations; + return stations; } static void badrequest() { - printf("Status: 400 Bad Request\n\n"); - exit(1); + printf("Status: 400 Bad Request\n\n"); + exit(1); } // recurse down to the lowest layer-2 interface static int interface_get_lowest(const char *ifname, char *hwifname); static int interface_get_lowest(const char *ifname, char *hwifname) { - glob_t globbuf; - char *fnamebuf = alloca(1 + strlen(VIRTIF_PREFIX) + IF_NAMESIZE + - strlen(LOWERGLOB_SUFFIX)); - char *lowentry = NULL; + glob_t globbuf; + char *fnamebuf = alloca(1 + strlen(VIRTIF_PREFIX) + IF_NAMESIZE + + strlen(LOWERGLOB_SUFFIX)); + char *lowentry = NULL; - sprintf(fnamebuf, "%s%s%s", VIRTIF_PREFIX, ifname, LOWERGLOB_SUFFIX); - glob(fnamebuf, GLOB_NOSORT | GLOB_NOESCAPE, NULL, &globbuf); + sprintf(fnamebuf, "%s%s%s", VIRTIF_PREFIX, ifname, LOWERGLOB_SUFFIX); + glob(fnamebuf, GLOB_NOSORT | GLOB_NOESCAPE, NULL, &globbuf); - if (globbuf.gl_pathc == 1) { - lowentry = alloca(1 + strlen(globbuf.gl_pathv[0])); - strncpy(lowentry, globbuf.gl_pathv[0], 1 + strlen(globbuf.gl_pathv[0])); - } + if (globbuf.gl_pathc == 1) { + lowentry = alloca(1 + strlen(globbuf.gl_pathv[0])); + strncpy(lowentry, globbuf.gl_pathv[0], 1 + strlen(globbuf.gl_pathv[0])); + } - globfree(&globbuf); + globfree(&globbuf); - if (!lowentry) { - char *path = alloca(1 + strlen(NETIF_PREFIX) + strlen(ifname)); - sprintf(path, "%s%s", NETIF_PREFIX, ifname); + if (!lowentry) { + char *path = alloca(1 + strlen(NETIF_PREFIX) + strlen(ifname)); + sprintf(path, "%s%s", NETIF_PREFIX, ifname); - if(access(path, F_OK) != 0) - return false; + if(access(path, F_OK) != 0) + return false; - strncpy(hwifname, ifname, IF_NAMESIZE - 1); - return true; - } else { - char buf[PATH_MAX]; - ssize_t len; + strncpy(hwifname, ifname, IF_NAMESIZE - 1); + return true; + } else { + char buf[PATH_MAX]; + ssize_t len; - if ((len = readlink(lowentry, buf, sizeof(buf)-1)) != -1) - buf[len] = '\0'; - else - return false; + if ((len = readlink(lowentry, buf, sizeof(buf)-1)) != -1) + buf[len] = '\0'; + else + return false; - if (strncmp(buf, "../", 3) == 0) { - return interface_get_lowest(strrchr(buf, '/') + 1, hwifname); - } else { - return false; - } - } + if (strncmp(buf, "../", 3) == 0) { + return interface_get_lowest(strrchr(buf, '/') + 1, hwifname); + } else { + return false; + } + } } int main(int argc, char *argv[]) { - if (argc != 2) - badrequest(); + if (argc != 2) + badrequest(); - const char *ifname = argv[1]; - char hwifname[IF_NAMESIZE] = ""; + const char *ifname = argv[1]; + char hwifname[IF_NAMESIZE] = ""; - if (strlen(ifname) >= IF_NAMESIZE) - badrequest(); + if (strlen(ifname) >= IF_NAMESIZE) + badrequest(); - if (strcspn(ifname, "/\\[]{}*?") != strlen(ifname)) - badrequest(); + if (strcspn(ifname, "/\\[]{}*?") != strlen(ifname)) + badrequest(); - if (!interface_get_lowest(ifname, hwifname)) - badrequest(); + if (!interface_get_lowest(ifname, hwifname)) + badrequest(); - const struct iwinfo_ops *iw = iwinfo_backend(hwifname); + const struct iwinfo_ops *iw = iwinfo_backend(hwifname); - if (iw == NULL) - badrequest(); + if (iw == NULL) + badrequest(); - printf("Content-type: text/event-stream\n\n"); + printf("Content-type: text/event-stream\n\n"); - while (true) { - struct json_object *obj; - obj = get_stations(iw, hwifname); - printf("data: %s\n\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN)); - fflush(stdout); - json_object_put(obj); - usleep(150000); - } + while (true) { + struct json_object *obj; + obj = get_stations(iw, hwifname); + printf("data: %s\n\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN)); + fflush(stdout); + json_object_put(obj); + usleep(150000); + } - return 0; + return 0; } diff --git a/package/gluon-web/src/template_lmo.c b/package/gluon-web/src/template_lmo.c index 062497b3..d7b442a7 100644 --- a/package/gluon-web/src/template_lmo.c +++ b/package/gluon-web/src/template_lmo.c @@ -38,9 +38,9 @@ static inline uint16_t get_le16(const void *data) { static inline uint32_t get_be32(const void *data) { const uint8_t *d = data; return (((uint32_t)d[0]) << 24) - | (((uint32_t)d[1]) << 16) - | (((uint32_t)d[2]) << 8) - | d[3]; + | (((uint32_t)d[1]) << 16) + | (((uint32_t)d[2]) << 8) + | d[3]; } /* diff --git a/package/gluon-web/src/template_lualib.c b/package/gluon-web/src/template_lualib.c index 308011f9..819de379 100644 --- a/package/gluon-web/src/template_lualib.c +++ b/package/gluon-web/src/template_lualib.c @@ -97,8 +97,8 @@ static int template_L_load_catalog(lua_State *L) return 0; } - luaL_getmetatable(L, TEMPLATE_CATALOG); - lua_setmetatable(L, -2); + luaL_getmetatable(L, TEMPLATE_CATALOG); + lua_setmetatable(L, -2); return 1; } @@ -106,7 +106,7 @@ static int template_L_load_catalog(lua_State *L) static int template_catalog_call(lua_State *L) { size_t inlen, outlen; - lmo_catalog_t *cat = luaL_checkudata(L, 1, TEMPLATE_CATALOG); + lmo_catalog_t *cat = luaL_checkudata(L, 1, TEMPLATE_CATALOG); const char *in = luaL_checklstring(L, 2, &inlen), *out; if (!lmo_translate(cat, in, inlen, &out, &outlen)) return 0; @@ -118,7 +118,7 @@ static int template_catalog_call(lua_State *L) static int template_catalog_gc(lua_State *L) { - lmo_catalog_t *cat = luaL_checkudata(L, 1, TEMPLATE_CATALOG); + lmo_catalog_t *cat = luaL_checkudata(L, 1, TEMPLATE_CATALOG); lmo_unload(cat); return 0; @@ -133,8 +133,8 @@ static const luaL_reg R[] = { }; static const luaL_reg template_catalog_methods[] = { - { "__call", template_catalog_call }, - { "__gc", template_catalog_gc }, + { "__call", template_catalog_call }, + { "__gc", template_catalog_gc }, {} }; diff --git a/package/gluon-web/src/template_parser.c b/package/gluon-web/src/template_parser.c index d71afe72..84f053ae 100644 --- a/package/gluon-web/src/template_parser.c +++ b/package/gluon-web/src/template_parser.c @@ -414,7 +414,7 @@ int template_error(lua_State *L, struct template_parser *parser) } snprintf(msg, sizeof(msg), "Syntax error in %s:%d: %s", - parser->file ?: "[string]", line + chunkline, err ?: "(unknown error)"); + parser->file ?: "[string]", line + chunkline, err ?: "(unknown error)"); lua_pushnil(L); lua_pushinteger(L, line + chunkline); diff --git a/package/gluon-web/src/template_utils.c b/package/gluon-web/src/template_utils.c index c07eab52..d2d9d79e 100644 --- a/package/gluon-web/src/template_utils.c +++ b/package/gluon-web/src/template_utils.c @@ -130,37 +130,37 @@ static inline bool mb_is_shortest(const unsigned char *s, size_t n) case 2: /* 1100000x (10xxxxxx) */ return !(((*s >> 1) == 0x60) && - ((*(s+1) >> 6) == 0x02)); + ((*(s+1) >> 6) == 0x02)); case 3: /* 11100000 100xxxxx (10xxxxxx) */ return !((*s == 0xE0) && - ((*(s+1) >> 5) == 0x04) && - ((*(s+2) >> 6) == 0x02)); + ((*(s+1) >> 5) == 0x04) && + ((*(s+2) >> 6) == 0x02)); case 4: /* 11110000 1000xxxx (10xxxxxx 10xxxxxx) */ return !((*s == 0xF0) && - ((*(s+1) >> 4) == 0x08) && - ((*(s+2) >> 6) == 0x02) && - ((*(s+3) >> 6) == 0x02)); + ((*(s+1) >> 4) == 0x08) && + ((*(s+2) >> 6) == 0x02) && + ((*(s+3) >> 6) == 0x02)); case 5: /* 11111000 10000xxx (10xxxxxx 10xxxxxx 10xxxxxx) */ return !((*s == 0xF8) && - ((*(s+1) >> 3) == 0x10) && - ((*(s+2) >> 6) == 0x02) && - ((*(s+3) >> 6) == 0x02) && - ((*(s+4) >> 6) == 0x02)); + ((*(s+1) >> 3) == 0x10) && + ((*(s+2) >> 6) == 0x02) && + ((*(s+3) >> 6) == 0x02) && + ((*(s+4) >> 6) == 0x02)); case 6: /* 11111100 100000xx (10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx) */ return !((*s == 0xF8) && - ((*(s+1) >> 2) == 0x20) && - ((*(s+2) >> 6) == 0x02) && - ((*(s+3) >> 6) == 0x02) && - ((*(s+4) >> 6) == 0x02) && - ((*(s+5) >> 6) == 0x02)); + ((*(s+1) >> 2) == 0x20) && + ((*(s+2) >> 6) == 0x02) && + ((*(s+3) >> 6) == 0x02) && + ((*(s+4) >> 6) == 0x02) && + ((*(s+5) >> 6) == 0x02)); } return true; @@ -270,18 +270,18 @@ bool pcdata(const char *s, size_t l, char **out, size_t *outl) for (o = 0; o < l; o++) { /* Invalid XML bytes */ if ((*ptr <= 0x08) || - ((*ptr >= 0x0B) && (*ptr <= 0x0C)) || - ((*ptr >= 0x0E) && (*ptr <= 0x1F)) || - (*ptr == 0x7F)) { + ((*ptr >= 0x0B) && (*ptr <= 0x0C)) || + ((*ptr >= 0x0E) && (*ptr <= 0x1F)) || + (*ptr == 0x7F)) { ptr++; } /* Escapes */ else if ((*ptr == '\'') || - (*ptr == '"') || - (*ptr == '&') || - (*ptr == '<') || - (*ptr == '>')) { + (*ptr == '"') || + (*ptr == '&') || + (*ptr == '<') || + (*ptr == '>')) { esl = snprintf(esq, sizeof(esq), "&#%i;", *ptr); if (!buf_append(buf, esq, esl)) diff --git a/package/libbatadv/src/batadv-genl.c b/package/libbatadv/src/batadv-genl.c index 887019b8..12ea6791 100644 --- a/package/libbatadv/src/batadv-genl.c +++ b/package/libbatadv/src/batadv-genl.c @@ -45,19 +45,19 @@ struct nla_policy batadv_genl_policy[NUM_BATADV_ATTR] = { [BATADV_ATTR_ALGO_NAME] = { .type = NLA_STRING }, [BATADV_ATTR_MESH_IFINDEX] = { .type = NLA_U32 }, [BATADV_ATTR_MESH_IFNAME] = { .type = NLA_STRING, - .maxlen = IFNAMSIZ }, + .maxlen = IFNAMSIZ }, [BATADV_ATTR_MESH_ADDRESS] = { .type = NLA_UNSPEC, - .minlen = ETH_ALEN, - .maxlen = ETH_ALEN }, + .minlen = ETH_ALEN, + .maxlen = ETH_ALEN }, [BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 }, [BATADV_ATTR_HARD_IFNAME] = { .type = NLA_STRING, - .maxlen = IFNAMSIZ }, + .maxlen = IFNAMSIZ }, [BATADV_ATTR_HARD_ADDRESS] = { .type = NLA_UNSPEC, - .minlen = ETH_ALEN, - .maxlen = ETH_ALEN }, + .minlen = ETH_ALEN, + .maxlen = ETH_ALEN }, [BATADV_ATTR_ORIG_ADDRESS] = { .type = NLA_UNSPEC, - .minlen = ETH_ALEN, - .maxlen = ETH_ALEN }, + .minlen = ETH_ALEN, + .maxlen = ETH_ALEN }, [BATADV_ATTR_TPMETER_RESULT] = { .type = NLA_U8 }, [BATADV_ATTR_TPMETER_TEST_TIME] = { .type = NLA_U32 }, [BATADV_ATTR_TPMETER_BYTES] = { .type = NLA_U64 }, @@ -65,8 +65,8 @@ struct nla_policy batadv_genl_policy[NUM_BATADV_ATTR] = { [BATADV_ATTR_PAD] = { .type = NLA_UNSPEC }, [BATADV_ATTR_ACTIVE] = { .type = NLA_FLAG }, [BATADV_ATTR_TT_ADDRESS] = { .type = NLA_UNSPEC, - .minlen = ETH_ALEN, - .maxlen = ETH_ALEN }, + .minlen = ETH_ALEN, + .maxlen = ETH_ALEN }, [BATADV_ATTR_TT_TTVN] = { .type = NLA_U8 }, [BATADV_ATTR_TT_LAST_TTVN] = { .type = NLA_U8 }, [BATADV_ATTR_TT_CRC32] = { .type = NLA_U32 }, @@ -75,23 +75,23 @@ struct nla_policy batadv_genl_policy[NUM_BATADV_ATTR] = { [BATADV_ATTR_FLAG_BEST] = { .type = NLA_FLAG }, [BATADV_ATTR_LAST_SEEN_MSECS] = { .type = NLA_U32 }, [BATADV_ATTR_NEIGH_ADDRESS] = { .type = NLA_UNSPEC, - .minlen = ETH_ALEN, - .maxlen = ETH_ALEN }, + .minlen = ETH_ALEN, + .maxlen = ETH_ALEN }, [BATADV_ATTR_TQ] = { .type = NLA_U8 }, [BATADV_ATTR_THROUGHPUT] = { .type = NLA_U32 }, [BATADV_ATTR_BANDWIDTH_UP] = { .type = NLA_U32 }, [BATADV_ATTR_BANDWIDTH_DOWN] = { .type = NLA_U32 }, [BATADV_ATTR_ROUTER] = { .type = NLA_UNSPEC, - .minlen = ETH_ALEN, - .maxlen = ETH_ALEN }, + .minlen = ETH_ALEN, + .maxlen = ETH_ALEN }, [BATADV_ATTR_BLA_OWN] = { .type = NLA_FLAG }, [BATADV_ATTR_BLA_ADDRESS] = { .type = NLA_UNSPEC, - .minlen = ETH_ALEN, - .maxlen = ETH_ALEN }, + .minlen = ETH_ALEN, + .maxlen = ETH_ALEN }, [BATADV_ATTR_BLA_VID] = { .type = NLA_U16 }, [BATADV_ATTR_BLA_BACKBONE] = { .type = NLA_UNSPEC, - .minlen = ETH_ALEN, - .maxlen = ETH_ALEN }, + .minlen = ETH_ALEN, + .maxlen = ETH_ALEN }, [BATADV_ATTR_BLA_CRC] = { .type = NLA_U16 }, }; @@ -105,7 +105,7 @@ struct nla_policy batadv_genl_policy[NUM_BATADV_ATTR] = { * Return: Always NL_STOP */ static int nlquery_error_cb(struct sockaddr_nl *nla __attribute__((unused)), - struct nlmsgerr *nlerr, void *arg) + struct nlmsgerr *nlerr, void *arg) { struct batadv_nlquery_opts *query_opts = arg; @@ -147,8 +147,8 @@ static int nlquery_stop_cb(struct nl_msg *msg, void *arg) */ __attribute__ ((visibility ("default"))) int batadv_genl_query(const char *mesh_iface, enum batadv_nl_commands nl_cmd, - nl_recvmsg_msg_cb_t callback, int flags, - struct batadv_nlquery_opts *query_opts) + nl_recvmsg_msg_cb_t callback, int flags, + struct batadv_nlquery_opts *query_opts) { struct nl_sock *sock; struct nl_msg *msg; @@ -198,7 +198,7 @@ int batadv_genl_query(const char *mesh_iface, enum batadv_nl_commands nl_cmd, } genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, flags, - nl_cmd, 1); + nl_cmd, 1); nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, ifindex); nl_send_auto_complete(sock, msg); diff --git a/package/libbatadv/src/batadv-genl.h b/package/libbatadv/src/batadv-genl.h index 1643d493..d9912fb6 100644 --- a/package/libbatadv/src/batadv-genl.h +++ b/package/libbatadv/src/batadv-genl.h @@ -79,10 +79,8 @@ struct batadv_nlquery_opts { * * Return: Return true when a attribute is missing, false otherwise */ -static inline bool -batadv_genl_missing_attrs(struct nlattr *attrs[], - const enum batadv_nl_attrs mandatory[], size_t num) -{ +static inline bool batadv_genl_missing_attrs(struct nlattr *attrs[], + const enum batadv_nl_attrs mandatory[], size_t num) { size_t i; for (i = 0; i < num; i++) { @@ -96,7 +94,7 @@ batadv_genl_missing_attrs(struct nlattr *attrs[], extern struct nla_policy batadv_genl_policy[]; int batadv_genl_query(const char *mesh_iface, enum batadv_nl_commands nl_cmd, - nl_recvmsg_msg_cb_t callback, int flags, - struct batadv_nlquery_opts *query_opts); + nl_recvmsg_msg_cb_t callback, int flags, + struct batadv_nlquery_opts *query_opts); #endif /* _BATADV_GENL_H_ */