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 CONFIG_H 17 #define CONFIG_H 18 19 #include <stdint.h> 20 #include "bsl_log_internal.h" 21 #include "bsl_binlog_id.h" 22 #include "hitls_type.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #define PROCESS_PARAM_INT32(tmpParam, paramObj, params, paramName, destField) \ 29 do { \ 30 (tmpParam) = BSL_PARAM_FindParam((BSL_Param *)(uintptr_t)(params), (paramName)); \ 31 if ((tmpParam) == NULL || (tmpParam)->valueType != BSL_PARAM_TYPE_INT32) { \ 32 BSL_LOG_BINLOG_FIXLEN(BINLOG_ID05075, BSL_LOG_LEVEL_ERR, BSL_LOG_BINLOG_TYPE_RUN, \ 33 "tls config: not found int32 param %s", #paramName, 0, 0, 0); \ 34 goto ERR; \ 35 } \ 36 (paramObj)->destField = *(int32_t *)(tmpParam)->value; \ 37 } while (0) 38 39 #define PROCESS_PARAM_UINT16(tmpParam, paramObj, params, paramName, destField) \ 40 do { \ 41 (tmpParam) = BSL_PARAM_FindParam((BSL_Param *)(uintptr_t)(params), (paramName)); \ 42 if ((tmpParam) == NULL || (tmpParam)->valueType != BSL_PARAM_TYPE_UINT16) { \ 43 BSL_LOG_BINLOG_FIXLEN(BINLOG_ID05076, BSL_LOG_LEVEL_ERR, BSL_LOG_BINLOG_TYPE_RUN, \ 44 "tls config: not found uint16 param %s", #paramName, 0, 0, 0); \ 45 goto ERR; \ 46 } \ 47 (paramObj)->destField = *(uint16_t *)(tmpParam)->value; \ 48 } while (0) 49 50 #define PROCESS_PARAM_UINT32(tmpParam, paramObj, params, paramName, destField) \ 51 do { \ 52 (tmpParam) = BSL_PARAM_FindParam((BSL_Param *)(uintptr_t)(params), (paramName)); \ 53 if ((tmpParam) == NULL || (tmpParam)->valueType != BSL_PARAM_TYPE_UINT32) { \ 54 BSL_LOG_BINLOG_FIXLEN(BINLOG_ID05077, BSL_LOG_LEVEL_ERR, BSL_LOG_BINLOG_TYPE_RUN, \ 55 "tls config: not found uint32 param %s", #paramName, 0, 0, 0); \ 56 goto ERR; \ 57 } \ 58 (paramObj)->destField = *(uint32_t *)(tmpParam)->value; \ 59 } while (0) 60 61 #define PROCESS_PARAM_BOOL(tmpParam, paramObj, params, paramName, destField) \ 62 do { \ 63 (tmpParam) = BSL_PARAM_FindParam((BSL_Param *)(uintptr_t)(params), (paramName)); \ 64 if ((tmpParam) == NULL || (tmpParam)->valueType != BSL_PARAM_TYPE_BOOL) { \ 65 BSL_LOG_BINLOG_FIXLEN(BINLOG_ID05078, BSL_LOG_LEVEL_ERR, BSL_LOG_BINLOG_TYPE_RUN, \ 66 "tls config: not found bool param %s", #paramName, 0, 0, 0); \ 67 goto ERR; \ 68 } \ 69 (paramObj)->destField = *(bool *)(tmpParam)->value; \ 70 } while (0) 71 72 #define PROCESS_STRING_PARAM(tmpParam, paramObj, params, paramName, destField) \ 73 do { \ 74 (tmpParam) = BSL_PARAM_FindParam((BSL_Param *)(uintptr_t)(params), (paramName)); \ 75 if ((tmpParam) == NULL || (tmpParam)->valueType != BSL_PARAM_TYPE_OCTETS_PTR) { \ 76 BSL_LOG_BINLOG_FIXLEN(BINLOG_ID05079, BSL_LOG_LEVEL_ERR, BSL_LOG_BINLOG_TYPE_RUN, \ 77 "tls config: not found string param %s", #paramName, 0, 0, 0); \ 78 goto ERR; \ 79 } \ 80 (paramObj)->destField = BSL_SAL_Calloc((tmpParam)->valueLen + 1, sizeof(char)); \ 81 if ((paramObj)->destField == NULL) { \ 82 goto ERR; \ 83 } \ 84 (void)memcpy_s((paramObj)->destField, (tmpParam)->valueLen + 1, (tmpParam)->value, (tmpParam)->valueLen); \ 85 } while (0) 86 87 #define PROCESS_OPTIONAL_STRING_PARAM(tmpParam, params, paramName, outString, outStringLen, nameParamName, outName) \ 88 do { \ 89 (tmpParam) = BSL_PARAM_FindParam((BSL_Param *)(uintptr_t)(params), (paramName)); \ 90 if ((tmpParam) == NULL) { \ 91 (outString) = NULL; \ 92 } else if ((tmpParam)->valueType == BSL_PARAM_TYPE_OCTETS_PTR) { \ 93 (outString) = (const char *)(tmpParam)->value; \ 94 (outStringLen) = (tmpParam)->valueLen; \ 95 (tmpParam) = BSL_PARAM_FindParam((BSL_Param *)(uintptr_t)(params), (nameParamName)); \ 96 if ((tmpParam) == NULL || (tmpParam)->valueType != BSL_PARAM_TYPE_OCTETS_PTR) { \ 97 BSL_LOG_BINLOG_FIXLEN(BINLOG_ID05080, BSL_LOG_LEVEL_ERR, BSL_LOG_BINLOG_TYPE_RUN, \ 98 "tls config: not found optional string param %s", #nameParamName, 0, 0, 0); \ 99 goto ERR; \ 100 } \ 101 (outName) = (const char *)(tmpParam)->value; \ 102 } else { \ 103 goto ERR; \ 104 } \ 105 } while (0) 106 107 /** clear the TLS configuration */ 108 void CFG_CleanConfig(HITLS_Config *config); 109 110 /** copy the TLS configuration */ 111 int32_t DumpConfig(HITLS_Ctx *ctx, const HITLS_Config *srcConfig); 112 113 #ifdef __cplusplus 114 } 115 #endif 116 117 #endif