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