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