Branch data Line data Source code
1 : : // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
2 : : //
3 : : // Permission to use, copy, modify, and/or distribute this software for any
4 : : // purpose with or without fee is hereby granted, provided that the above
5 : : // copyright notice and this permission notice appear in all copies.
6 : : //
7 : : // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
8 : : // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9 : : // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
10 : : // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11 : : // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
12 : : // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13 : : // PERFORMANCE OF THIS SOFTWARE.
14 : :
15 : : #include <cstring>
16 : :
17 : : #include <config.h>
18 : : #include "hash_key.h"
19 : :
20 : : namespace isc {
21 : : namespace nsas {
22 : :
23 : : /// Hash Equality Function
24 : 2456 : bool HashKey::operator==(const isc::nsas::HashKey& other) {
25 : :
26 : : // Check key lengths
27 [ + + ]: 2456 : if (other.keylen == keylen) {
28 : :
29 : : // ... and classes
30 [ + + ]: 2423 : if (other.class_code == class_code) {
31 : :
32 : : // ... before the expensive operation. This involves a
33 : : // byte-by-byte comparison, doing a case-independent match.
34 : : // memcmp() doesn't work (exact match) nor does strcmp or its
35 : : // variation (stops on the first null byte).
36 : : //
37 : : // TODO: Use a lookup table to map upper to lower case (for speed)
38 [ + + ]: 32258 : for (uint32_t i = 0; i < other.keylen; ++i) {
39 [ + + ]: 29802 : if (tolower(static_cast<unsigned char>(other.key[i])) !=
40 : 29802 : tolower(static_cast<unsigned char>(key[i]))) {
41 : : return false; // Mismatch
42 : : }
43 : : }
44 : : return true; // All bytes matched
45 : : }
46 : : }
47 : : return false; // Key length or class did not match
48 : : }
49 : :
50 : : } // namespace nsas
51 : : } // namespace isc
|