libcoap  4.2.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  * This file is part of the CoAP library libcoap. Please see README for terms
7  * of use.
8  */
9 
15 #ifndef COAP_HASHKEY_H_
16 #define COAP_HASHKEY_H_
17 
18 #include "libcoap.h"
19 #include "uthash.h"
20 #include "str.h"
21 
22 typedef unsigned char coap_key_t[4];
23 
24 #ifndef coap_hash
25 
34 void coap_hash_impl(const unsigned char *s, unsigned int len, coap_key_t h);
35 
36 #define coap_hash(String,Length,Result) \
37  coap_hash_impl((String),(Length),(Result))
38 
39 /* This is used to control the pre-set hash-keys for resources. */
40 #define COAP_DEFAULT_HASH
41 #else
42 #undef COAP_DEFAULT_HASH
43 #endif /* coap_hash */
44 
53 #define coap_str_hash(Str,H) { \
54  assert(Str); \
55  memset((H), 0, sizeof(coap_key_t)); \
56  coap_hash((Str)->s, (Str)->length, (H)); \
57  }
58 
59 #endif /* COAP_HASHKEY_H_ */
unsigned char coap_key_t[4]
Definition: coap_hashkey.h:22
void coap_hash_impl(const unsigned char *s, unsigned int 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:12