• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 
16 #ifndef TLS_RES_H
17 #define TLS_RES_H
18 
19 #include <stdint.h>
20 #include "lock.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 typedef struct Res {
27     void *tlsRes; // Indicates the CTX or SSL resource.
28     int  ctxId; // This field is used only in sslList, indicating the ctx from which the SSL is generated.
29     struct Res *next;
30     uint8_t id; // Indicates the sequence number of a resource, that is, the number of times that the resource
31                 // is created. The value starts from 0.
32 } Res;
33 
34 typedef struct {
35     Res *res;
36     uint8_t num;
37     Lock *resListLock;
38 } ResList;
39 
40 /**
41 * @brief  Initializing the TLS Resource Linked List
42 */
43 int InitTlsResList(void);
44 
45 /**
46 * @brief  Releasing the TLS Resource Linked List
47 */
48 void FreeTlsResList(void);
49 
50 /**
51 * @brief  Releases CTX and SSL resources in the linked list based on CTX resources.
52 */
53 int FreeResFromSsl(const void *ctx);
54 
55 /**
56 * @brief  Insert CTX resources into the linked list.
57 */
58 int InsertCtxToList(void *ctx);
59 
60 /**
61 * @brief  Insert SSL resources into the linked list.
62 */
63 int InsertSslToList(void* ctx, void *ssl);
64 
65 /**
66 * @brief  Obtains the CTX linked list from the linked list.
67 */
68 ResList* GetCtxList(void);
69 
70 /**
71 * @brief  Obtains the SSL linked list from the linked list.
72 */
73 ResList* GetSslList(void);
74 
75 /**
76 * @brief  Obtain the CTX from the CTX linked list based on the ID.
77 */
78 int GetCtxIdFromSsl(const void* tls);
79 
80 /**
81 * @brief  Obtains the TLS RES in the linked list.
82 */
83 Res* GetResFromTlsResList(ResList *resList, const void* tlsRes);
84 
85 /**
86 * @brief  Obtains TLS RES from the linked list based on the ID.
87 */
88 void* GetTlsResFromId(ResList *resList, int id);
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif // TLS_RES_H
95