Fork of CyaSSL for my specific settings
Fork of CyaSSL by
ctaocrypt/src/logging.c@4:28ac50e1d49c, 2015-03-03 (annotated)
- Committer:
- d0773d
- Date:
- Tue Mar 03 22:52:52 2015 +0000
- Revision:
- 4:28ac50e1d49c
- Parent:
- 0:1239e9b70ca2
CyaSSL example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 0:1239e9b70ca2 | 1 | /* logging.c |
wolfSSL | 0:1239e9b70ca2 | 2 | * |
wolfSSL | 0:1239e9b70ca2 | 3 | * Copyright (C) 2006-2014 wolfSSL Inc. |
wolfSSL | 0:1239e9b70ca2 | 4 | * |
wolfSSL | 0:1239e9b70ca2 | 5 | * This file is part of CyaSSL. |
wolfSSL | 0:1239e9b70ca2 | 6 | * |
wolfSSL | 0:1239e9b70ca2 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
wolfSSL | 0:1239e9b70ca2 | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 0:1239e9b70ca2 | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 0:1239e9b70ca2 | 10 | * (at your option) any later version. |
wolfSSL | 0:1239e9b70ca2 | 11 | * |
wolfSSL | 0:1239e9b70ca2 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
wolfSSL | 0:1239e9b70ca2 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 0:1239e9b70ca2 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 0:1239e9b70ca2 | 15 | * GNU General Public License for more details. |
wolfSSL | 0:1239e9b70ca2 | 16 | * |
wolfSSL | 0:1239e9b70ca2 | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 0:1239e9b70ca2 | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 0:1239e9b70ca2 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
wolfSSL | 0:1239e9b70ca2 | 20 | */ |
wolfSSL | 0:1239e9b70ca2 | 21 | |
wolfSSL | 0:1239e9b70ca2 | 22 | #ifdef HAVE_CONFIG_H |
wolfSSL | 0:1239e9b70ca2 | 23 | #include <config.h> |
wolfSSL | 0:1239e9b70ca2 | 24 | #endif |
wolfSSL | 0:1239e9b70ca2 | 25 | |
wolfSSL | 0:1239e9b70ca2 | 26 | #include <cyassl/ctaocrypt/settings.h> |
wolfSSL | 0:1239e9b70ca2 | 27 | |
wolfSSL | 0:1239e9b70ca2 | 28 | /* submitted by eof */ |
wolfSSL | 0:1239e9b70ca2 | 29 | |
wolfSSL | 0:1239e9b70ca2 | 30 | #include <cyassl/ctaocrypt/logging.h> |
wolfSSL | 0:1239e9b70ca2 | 31 | #include <cyassl/ctaocrypt/error-crypt.h> |
wolfSSL | 0:1239e9b70ca2 | 32 | |
wolfSSL | 0:1239e9b70ca2 | 33 | |
wolfSSL | 0:1239e9b70ca2 | 34 | #ifdef __cplusplus |
wolfSSL | 0:1239e9b70ca2 | 35 | extern "C" { |
wolfSSL | 0:1239e9b70ca2 | 36 | #endif |
wolfSSL | 0:1239e9b70ca2 | 37 | CYASSL_API int CyaSSL_Debugging_ON(void); |
wolfSSL | 0:1239e9b70ca2 | 38 | CYASSL_API void CyaSSL_Debugging_OFF(void); |
wolfSSL | 0:1239e9b70ca2 | 39 | #ifdef __cplusplus |
wolfSSL | 0:1239e9b70ca2 | 40 | } |
wolfSSL | 0:1239e9b70ca2 | 41 | #endif |
wolfSSL | 0:1239e9b70ca2 | 42 | |
wolfSSL | 0:1239e9b70ca2 | 43 | |
wolfSSL | 0:1239e9b70ca2 | 44 | #ifdef DEBUG_CYASSL |
wolfSSL | 0:1239e9b70ca2 | 45 | |
wolfSSL | 0:1239e9b70ca2 | 46 | /* Set these to default values initially. */ |
wolfSSL | 0:1239e9b70ca2 | 47 | static CyaSSL_Logging_cb log_function = 0; |
wolfSSL | 0:1239e9b70ca2 | 48 | static int loggingEnabled = 0; |
wolfSSL | 0:1239e9b70ca2 | 49 | |
wolfSSL | 0:1239e9b70ca2 | 50 | #endif /* DEBUG_CYASSL */ |
wolfSSL | 0:1239e9b70ca2 | 51 | |
wolfSSL | 0:1239e9b70ca2 | 52 | |
wolfSSL | 0:1239e9b70ca2 | 53 | int CyaSSL_SetLoggingCb(CyaSSL_Logging_cb f) |
wolfSSL | 0:1239e9b70ca2 | 54 | { |
wolfSSL | 0:1239e9b70ca2 | 55 | #ifdef DEBUG_CYASSL |
wolfSSL | 0:1239e9b70ca2 | 56 | int res = 0; |
wolfSSL | 0:1239e9b70ca2 | 57 | |
wolfSSL | 0:1239e9b70ca2 | 58 | if (f) |
wolfSSL | 0:1239e9b70ca2 | 59 | log_function = f; |
wolfSSL | 0:1239e9b70ca2 | 60 | else |
wolfSSL | 0:1239e9b70ca2 | 61 | res = BAD_FUNC_ARG; |
wolfSSL | 0:1239e9b70ca2 | 62 | |
wolfSSL | 0:1239e9b70ca2 | 63 | return res; |
wolfSSL | 0:1239e9b70ca2 | 64 | #else |
wolfSSL | 0:1239e9b70ca2 | 65 | (void)f; |
wolfSSL | 0:1239e9b70ca2 | 66 | return NOT_COMPILED_IN; |
wolfSSL | 0:1239e9b70ca2 | 67 | #endif |
wolfSSL | 0:1239e9b70ca2 | 68 | } |
wolfSSL | 0:1239e9b70ca2 | 69 | |
wolfSSL | 0:1239e9b70ca2 | 70 | |
wolfSSL | 0:1239e9b70ca2 | 71 | int CyaSSL_Debugging_ON(void) |
wolfSSL | 0:1239e9b70ca2 | 72 | { |
wolfSSL | 0:1239e9b70ca2 | 73 | #ifdef DEBUG_CYASSL |
wolfSSL | 0:1239e9b70ca2 | 74 | loggingEnabled = 1; |
wolfSSL | 0:1239e9b70ca2 | 75 | return 0; |
wolfSSL | 0:1239e9b70ca2 | 76 | #else |
wolfSSL | 0:1239e9b70ca2 | 77 | return NOT_COMPILED_IN; |
wolfSSL | 0:1239e9b70ca2 | 78 | #endif |
wolfSSL | 0:1239e9b70ca2 | 79 | } |
wolfSSL | 0:1239e9b70ca2 | 80 | |
wolfSSL | 0:1239e9b70ca2 | 81 | |
wolfSSL | 0:1239e9b70ca2 | 82 | void CyaSSL_Debugging_OFF(void) |
wolfSSL | 0:1239e9b70ca2 | 83 | { |
wolfSSL | 0:1239e9b70ca2 | 84 | #ifdef DEBUG_CYASSL |
wolfSSL | 0:1239e9b70ca2 | 85 | loggingEnabled = 0; |
wolfSSL | 0:1239e9b70ca2 | 86 | #endif |
wolfSSL | 0:1239e9b70ca2 | 87 | } |
wolfSSL | 0:1239e9b70ca2 | 88 | |
wolfSSL | 0:1239e9b70ca2 | 89 | |
wolfSSL | 0:1239e9b70ca2 | 90 | #ifdef DEBUG_CYASSL |
wolfSSL | 0:1239e9b70ca2 | 91 | |
wolfSSL | 0:1239e9b70ca2 | 92 | #ifdef FREESCALE_MQX |
wolfSSL | 0:1239e9b70ca2 | 93 | #include <fio.h> |
wolfSSL | 0:1239e9b70ca2 | 94 | #else |
wolfSSL | 0:1239e9b70ca2 | 95 | #include <stdio.h> /* for default printf stuff */ |
wolfSSL | 0:1239e9b70ca2 | 96 | #endif |
wolfSSL | 0:1239e9b70ca2 | 97 | |
wolfSSL | 0:1239e9b70ca2 | 98 | #ifdef THREADX |
wolfSSL | 0:1239e9b70ca2 | 99 | int dc_log_printf(char*, ...); |
wolfSSL | 0:1239e9b70ca2 | 100 | #endif |
wolfSSL | 0:1239e9b70ca2 | 101 | |
wolfSSL | 0:1239e9b70ca2 | 102 | static void cyassl_log(const int logLevel, const char *const logMessage) |
wolfSSL | 0:1239e9b70ca2 | 103 | { |
wolfSSL | 0:1239e9b70ca2 | 104 | if (log_function) |
wolfSSL | 0:1239e9b70ca2 | 105 | log_function(logLevel, logMessage); |
wolfSSL | 0:1239e9b70ca2 | 106 | else { |
wolfSSL | 0:1239e9b70ca2 | 107 | if (loggingEnabled) { |
wolfSSL | 0:1239e9b70ca2 | 108 | #ifdef THREADX |
wolfSSL | 0:1239e9b70ca2 | 109 | dc_log_printf("%s\n", logMessage); |
wolfSSL | 0:1239e9b70ca2 | 110 | #elif defined(MICRIUM) |
wolfSSL | 0:1239e9b70ca2 | 111 | #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED) |
wolfSSL | 0:1239e9b70ca2 | 112 | NetSecure_TraceOut((CPU_CHAR *)logMessage); |
wolfSSL | 0:1239e9b70ca2 | 113 | #endif |
wolfSSL | 0:1239e9b70ca2 | 114 | #elif defined(CYASSL_MDK_ARM) |
wolfSSL | 0:1239e9b70ca2 | 115 | fflush(stdout) ; |
wolfSSL | 0:1239e9b70ca2 | 116 | printf("%s\n", logMessage); |
wolfSSL | 0:1239e9b70ca2 | 117 | fflush(stdout) ; |
wolfSSL | 0:1239e9b70ca2 | 118 | #else |
wolfSSL | 0:1239e9b70ca2 | 119 | fprintf(stderr, "%s\n", logMessage); |
wolfSSL | 0:1239e9b70ca2 | 120 | #endif |
wolfSSL | 0:1239e9b70ca2 | 121 | } |
wolfSSL | 0:1239e9b70ca2 | 122 | } |
wolfSSL | 0:1239e9b70ca2 | 123 | } |
wolfSSL | 0:1239e9b70ca2 | 124 | |
wolfSSL | 0:1239e9b70ca2 | 125 | |
wolfSSL | 0:1239e9b70ca2 | 126 | void CYASSL_MSG(const char* msg) |
wolfSSL | 0:1239e9b70ca2 | 127 | { |
wolfSSL | 0:1239e9b70ca2 | 128 | if (loggingEnabled) |
wolfSSL | 0:1239e9b70ca2 | 129 | cyassl_log(INFO_LOG , msg); |
wolfSSL | 0:1239e9b70ca2 | 130 | } |
wolfSSL | 0:1239e9b70ca2 | 131 | |
wolfSSL | 0:1239e9b70ca2 | 132 | |
wolfSSL | 0:1239e9b70ca2 | 133 | void CYASSL_ENTER(const char* msg) |
wolfSSL | 0:1239e9b70ca2 | 134 | { |
wolfSSL | 0:1239e9b70ca2 | 135 | if (loggingEnabled) { |
wolfSSL | 0:1239e9b70ca2 | 136 | char buffer[80]; |
wolfSSL | 0:1239e9b70ca2 | 137 | sprintf(buffer, "CyaSSL Entering %s", msg); |
wolfSSL | 0:1239e9b70ca2 | 138 | cyassl_log(ENTER_LOG , buffer); |
wolfSSL | 0:1239e9b70ca2 | 139 | } |
wolfSSL | 0:1239e9b70ca2 | 140 | } |
wolfSSL | 0:1239e9b70ca2 | 141 | |
wolfSSL | 0:1239e9b70ca2 | 142 | |
wolfSSL | 0:1239e9b70ca2 | 143 | void CYASSL_LEAVE(const char* msg, int ret) |
wolfSSL | 0:1239e9b70ca2 | 144 | { |
wolfSSL | 0:1239e9b70ca2 | 145 | if (loggingEnabled) { |
wolfSSL | 0:1239e9b70ca2 | 146 | char buffer[80]; |
wolfSSL | 0:1239e9b70ca2 | 147 | sprintf(buffer, "CyaSSL Leaving %s, return %d", msg, ret); |
wolfSSL | 0:1239e9b70ca2 | 148 | cyassl_log(LEAVE_LOG , buffer); |
wolfSSL | 0:1239e9b70ca2 | 149 | } |
wolfSSL | 0:1239e9b70ca2 | 150 | } |
wolfSSL | 0:1239e9b70ca2 | 151 | |
wolfSSL | 0:1239e9b70ca2 | 152 | |
wolfSSL | 0:1239e9b70ca2 | 153 | void CYASSL_ERROR(int error) |
wolfSSL | 0:1239e9b70ca2 | 154 | { |
wolfSSL | 0:1239e9b70ca2 | 155 | if (loggingEnabled) { |
wolfSSL | 0:1239e9b70ca2 | 156 | char buffer[80]; |
wolfSSL | 0:1239e9b70ca2 | 157 | sprintf(buffer, "CyaSSL error occured, error = %d", error); |
wolfSSL | 0:1239e9b70ca2 | 158 | cyassl_log(ERROR_LOG , buffer); |
wolfSSL | 0:1239e9b70ca2 | 159 | } |
wolfSSL | 0:1239e9b70ca2 | 160 | } |
wolfSSL | 0:1239e9b70ca2 | 161 | |
wolfSSL | 0:1239e9b70ca2 | 162 | #endif /* DEBUG_CYASSL */ |
wolfSSL | 0:1239e9b70ca2 | 163 |