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