blob: 96e08f378ab9498a8d05652be502d176d439ae39 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file debug.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief Debug functions
5 *
Paul Bakkercce9d772011-11-18 14:26:47 +00006 * Copyright (C) 2006-2011, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00009 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +000010 *
Paul Bakker77b385e2009-07-28 17:23:11 +000011 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000012 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000013 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000026 */
Paul Bakkercce9d772011-11-18 14:26:47 +000027#ifndef POLARSSL_DEBUG_H
28#define POLARSSL_DEBUG_H
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Paul Bakker314052f2011-08-15 09:07:52 +000030#include "config.h"
31#include "ssl.h"
Paul Bakker41c83d32013-03-20 14:39:14 +010032#if defined(POLARSSL_ECP_C)
33#include "ecp.h"
34#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000035
Paul Bakker1504af52012-02-11 16:17:43 +000036#if defined(POLARSSL_DEBUG_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000037
Paul Bakkereaebbd52014-04-25 15:04:14 +020038#define POLARSSL_DEBUG_LOG_FULL 0 /**< Include file:line in log lines */
39#define POLARSSL_DEBUG_LOG_RAW 1 /**< Only log raw debug lines */
40
41/**
42 * \name SECTION: Module settings
43 *
44 * The configuration options you can set for this module are in this section.
45 * Either change them in config.h or define them on the compiler command line.
46 * \{
47 */
48
49#if !defined(POLARSSL_DEBUG_DFL_MODE)
50#define POLARSSL_DEBUG_DFL_MODE POLARSSL_DEBUG_LOG_FULL /**< Default log: Full or Raw */
51#endif
52
53/* \} name SECTION: Module settings */
54
55/**
56 * \brief Set the log mode for the debug functions globally
57 * (Default value: POLARSSL_DEBUG_DFL_MODE)
58 *
59 * \param log_mode The log mode to use (POLARSSL_DEBUG_LOG_FULL or
60 * POLARSSL_DEBUG_LOG_RAW)
61 */
62void debug_set_log_mode( int log_mode );
63
Paul Bakker5121ce52009-01-03 21:22:43 +000064#define SSL_DEBUG_MSG( level, args ) \
65 debug_print_msg( ssl, level, __FILE__, __LINE__, debug_fmt args );
66
67#define SSL_DEBUG_RET( level, text, ret ) \
68 debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret );
69
70#define SSL_DEBUG_BUF( level, text, buf, len ) \
71 debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len );
72
Paul Bakkered27a042013-04-18 22:46:23 +020073#if defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000074#define SSL_DEBUG_MPI( level, text, X ) \
75 debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X );
Paul Bakkered27a042013-04-18 22:46:23 +020076#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000077
Paul Bakkered27a042013-04-18 22:46:23 +020078#if defined(POLARSSL_ECP_C)
Paul Bakker41c83d32013-03-20 14:39:14 +010079#define SSL_DEBUG_ECP( level, text, X ) \
80 debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X );
Paul Bakkered27a042013-04-18 22:46:23 +020081#endif
Paul Bakker41c83d32013-03-20 14:39:14 +010082
Paul Bakker7c6b2c32013-09-16 13:49:26 +020083#if defined(POLARSSL_X509_CRT_PARSE_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000084#define SSL_DEBUG_CRT( level, text, crt ) \
85 debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt );
Paul Bakkered27a042013-04-18 22:46:23 +020086#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000087
88#else
89
90#define SSL_DEBUG_MSG( level, args ) do { } while( 0 )
91#define SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
92#define SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
93#define SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
Paul Bakker41c83d32013-03-20 14:39:14 +010094#define SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +000095#define SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
96
97#endif
98
99#ifdef __cplusplus
100extern "C" {
101#endif
102
103char *debug_fmt( const char *format, ... );
104
Paul Bakkerff60ee62010-03-16 21:09:09 +0000105void debug_print_msg( const ssl_context *ssl, int level,
106 const char *file, int line, const char *text );
Paul Bakker5121ce52009-01-03 21:22:43 +0000107
Paul Bakkerff60ee62010-03-16 21:09:09 +0000108void debug_print_ret( const ssl_context *ssl, int level,
109 const char *file, int line,
110 const char *text, int ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000111
Paul Bakkerff60ee62010-03-16 21:09:09 +0000112void debug_print_buf( const ssl_context *ssl, int level,
113 const char *file, int line, const char *text,
Paul Bakker23986e52011-04-24 08:57:21 +0000114 unsigned char *buf, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +0000115
Paul Bakkered27a042013-04-18 22:46:23 +0200116#if defined(POLARSSL_BIGNUM_C)
Paul Bakkerff60ee62010-03-16 21:09:09 +0000117void debug_print_mpi( const ssl_context *ssl, int level,
118 const char *file, int line,
119 const char *text, const mpi *X );
Paul Bakkered27a042013-04-18 22:46:23 +0200120#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000121
Paul Bakker41c83d32013-03-20 14:39:14 +0100122#if defined(POLARSSL_ECP_C)
123void debug_print_ecp( const ssl_context *ssl, int level,
124 const char *file, int line,
125 const char *text, const ecp_point *X );
126#endif
127
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200128#if defined(POLARSSL_X509_CRT_PARSE_C)
Paul Bakkerff60ee62010-03-16 21:09:09 +0000129void debug_print_crt( const ssl_context *ssl, int level,
130 const char *file, int line,
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200131 const char *text, const x509_crt *crt );
Paul Bakkered27a042013-04-18 22:46:23 +0200132#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000133
134#ifdef __cplusplus
135}
136#endif
137
138#endif /* debug.h */