1 /* 2 * coap_cache_internal.h -- Cache functions for libcoap 3 * 4 * Copyright (C) 2019--2020 Olaf Bergmann <bergmann@tzi.org> and others 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 12 /** 13 * @file coap_cache_internal.h 14 * @brief COAP cache internal information 15 */ 16 17 #ifndef COAP_CACHE_INTERNAL_H_ 18 #define COAP_CACHE_INTERNAL_H_ 19 20 #include "coap_io.h" 21 22 /** 23 * @defgroup cache_internal Cache Support (Internal) 24 * CoAP Cache Structures, Enums and Functions that are not exposed to 25 * applications 26 * @{ 27 */ 28 29 /* Holds a digest in binary typically sha256 except for notls */ 30 typedef struct coap_digest_t { 31 uint8_t key[32]; 32 } coap_digest_t; 33 34 struct coap_cache_key_t { 35 uint8_t key[32]; 36 }; 37 38 struct coap_cache_entry_t { 39 UT_hash_handle hh; 40 coap_cache_key_t *cache_key; 41 coap_session_t *session; 42 coap_pdu_t *pdu; 43 void* app_data; 44 coap_tick_t expire_ticks; 45 unsigned int idle_timeout; 46 coap_cache_app_data_free_callback_t callback; 47 }; 48 49 /** 50 * Expire coap_cache_entry_t entries 51 * 52 * Internal function. 53 * 54 * @param context The context holding the coap-entries to exire 55 */ 56 void coap_expire_cache_entries(coap_context_t *context); 57 58 typedef void coap_digest_ctx_t; 59 60 /** 61 * Initialize a coap_digest 62 * 63 * Internal function. 64 * 65 * @return The digest context or @c NULL if failure. 66 */ 67 coap_digest_ctx_t *coap_digest_setup(void); 68 69 /** 70 * Free off coap_digest_ctx_t. Always done by 71 * coap_digest_final() 72 * 73 * Internal function. 74 * 75 * @param digest_ctx The coap_digest context. 76 */ 77 void coap_digest_free(coap_digest_ctx_t *digest_ctx); 78 79 /** 80 * Update the coap_digest information with the next chunk of data 81 * 82 * Internal function. 83 * 84 * @param digest_ctx The coap_digest context. 85 * @param data Pointer to data. 86 * @param data_len Number of bytes. 87 * 88 * @return @c 1 success, @c 0 failure. 89 */ 90 int coap_digest_update(coap_digest_ctx_t *digest_ctx, 91 const uint8_t *data, 92 size_t data_len 93 ); 94 95 /** 96 * Finalize the coap_digest information into the provided 97 * @p digest_buffer. 98 * 99 * Internal function. 100 * 101 * @param digest_ctx The coap_digest context. 102 * @param digest_buffer Pointer to digest buffer to update 103 * 104 * @return @c 1 success, @c 0 failure. 105 */ 106 int coap_digest_final(coap_digest_ctx_t *digest_ctx, 107 coap_digest_t *digest_buffer); 108 109 /** @} */ 110 111 #endif /* COAP_CACHE_INTERNAL_H_ */ 112