libcoap  4.3.0
coap_hashkey.h
Go to the documentation of this file.
1 /*
2  * coap_hashkey.h -- definition of hash key type and helper functions
3  *
4  * Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
5  *
6  * SPDX-License-Identifier: BSD-2-Clause
7  *
8  * This file is part of the CoAP library libcoap. Please see README for terms
9  * of use.
10  */
11 
17 #ifndef COAP_HASHKEY_H_
18 #define COAP_HASHKEY_H_
19 
20 #include "libcoap.h"
21 #include "uthash.h"
22 #include "str.h"
23 
24 typedef unsigned char coap_key_t[4];
25 
26 #ifndef coap_hash
36 void coap_hash_impl(const unsigned char *s, size_t len, coap_key_t h);
37 
38 #define coap_hash(String,Length,Result) \
39  coap_hash_impl((String),(Length),(Result))
40 
41 /* This is used to control the pre-set hash-keys for resources. */
42 #define COAP_DEFAULT_HASH
43 #else
44 #undef COAP_DEFAULT_HASH
45 #endif /* coap_hash */
46 
55 #define coap_str_hash(Str,H) { \
56  assert(Str); \
57  memset((H), 0, sizeof(coap_key_t)); \
58  coap_hash((Str)->s, (Str)->length, (H)); \
59  }
60 
61 #endif /* COAP_HASHKEY_H_ */
unsigned char coap_key_t[4]
Definition: coap_hashkey.h:24
void coap_hash_impl(const unsigned char *s, size_t len, coap_key_t h)
Calculates a fast hash over the given string s of length len and stores the result into h.
Definition: coap_hashkey.c:14