blob: 0dd79d52f04fbd8b1c3d1d86988edf43d6cf5f9c [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
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker314052f2011-08-15 09:07:52 +000031#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#else
33#include POLARSSL_CONFIG_FILE
34#endif
Paul Bakker314052f2011-08-15 09:07:52 +000035#include "ssl.h"
Paul Bakker41c83d32013-03-20 14:39:14 +010036#if defined(POLARSSL_ECP_C)
37#include "ecp.h"
38#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000039
Paul Bakker1504af52012-02-11 16:17:43 +000040#if defined(POLARSSL_DEBUG_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000041
Paul Bakkereaebbd52014-04-25 15:04:14 +020042#define POLARSSL_DEBUG_LOG_FULL 0 /**< Include file:line in log lines */
43#define POLARSSL_DEBUG_LOG_RAW 1 /**< Only log raw debug lines */
44
45/**
46 * \name SECTION: Module settings
47 *
48 * The configuration options you can set for this module are in this section.
49 * Either change them in config.h or define them on the compiler command line.
50 * \{
51 */
52
53#if !defined(POLARSSL_DEBUG_DFL_MODE)
54#define POLARSSL_DEBUG_DFL_MODE POLARSSL_DEBUG_LOG_FULL /**< Default log: Full or Raw */
55#endif
56
57/* \} name SECTION: Module settings */
58
Paul Bakkereaebbd52014-04-25 15:04:14 +020059
Paul Bakker5121ce52009-01-03 21:22:43 +000060#define SSL_DEBUG_MSG( level, args ) \
61 debug_print_msg( ssl, level, __FILE__, __LINE__, debug_fmt args );
62
63#define SSL_DEBUG_RET( level, text, ret ) \
64 debug_print_ret( ssl, level, __FILE__, __LINE__, text, ret );
65
66#define SSL_DEBUG_BUF( level, text, buf, len ) \
67 debug_print_buf( ssl, level, __FILE__, __LINE__, text, buf, len );
68
Paul Bakkered27a042013-04-18 22:46:23 +020069#if defined(POLARSSL_BIGNUM_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000070#define SSL_DEBUG_MPI( level, text, X ) \
71 debug_print_mpi( ssl, level, __FILE__, __LINE__, text, X );
Paul Bakkered27a042013-04-18 22:46:23 +020072#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000073
Paul Bakkered27a042013-04-18 22:46:23 +020074#if defined(POLARSSL_ECP_C)
Paul Bakker41c83d32013-03-20 14:39:14 +010075#define SSL_DEBUG_ECP( level, text, X ) \
76 debug_print_ecp( ssl, level, __FILE__, __LINE__, text, X );
Paul Bakkered27a042013-04-18 22:46:23 +020077#endif
Paul Bakker41c83d32013-03-20 14:39:14 +010078
Paul Bakker7c6b2c32013-09-16 13:49:26 +020079#if defined(POLARSSL_X509_CRT_PARSE_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000080#define SSL_DEBUG_CRT( level, text, crt ) \
81 debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt );
Paul Bakkered27a042013-04-18 22:46:23 +020082#endif
Paul Bakker5121ce52009-01-03 21:22:43 +000083
Paul Bakker9af723c2014-05-01 13:03:14 +020084#else /* POLARSSL_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000085
86#define SSL_DEBUG_MSG( level, args ) do { } while( 0 )
87#define SSL_DEBUG_RET( level, text, ret ) do { } while( 0 )
88#define SSL_DEBUG_BUF( level, text, buf, len ) do { } while( 0 )
89#define SSL_DEBUG_MPI( level, text, X ) do { } while( 0 )
Paul Bakker41c83d32013-03-20 14:39:14 +010090#define SSL_DEBUG_ECP( level, text, X ) do { } while( 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +000091#define SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 )
92
Paul Bakker9af723c2014-05-01 13:03:14 +020093#endif /* POLARSSL_DEBUG_C */
Paul Bakker5121ce52009-01-03 21:22:43 +000094
95#ifdef __cplusplus
96extern "C" {
97#endif
98
Paul Bakkerc73079a2014-04-25 16:34:30 +020099/**
100 * \brief Set the log mode for the debug functions globally
101 * (Default value: POLARSSL_DEBUG_DFL_MODE)
102 *
103 * \param log_mode The log mode to use (POLARSSL_DEBUG_LOG_FULL or
104 * POLARSSL_DEBUG_LOG_RAW)
105 */
106void debug_set_log_mode( int log_mode );
107
108/**
109 * \brief Set the level threshold to handle globally. Messages that have a
110 * level over the threshold value are ignored.
111 * (Default value: 0 (No debug))
112 *
113 * \param threshold maximum level of messages to pass on
114 */
115void debug_set_threshold( int threshold );
116
Paul Bakker5121ce52009-01-03 21:22:43 +0000117char *debug_fmt( const char *format, ... );
118
Paul Bakkerff60ee62010-03-16 21:09:09 +0000119void debug_print_msg( const ssl_context *ssl, int level,
120 const char *file, int line, const char *text );
Paul Bakker5121ce52009-01-03 21:22:43 +0000121
Paul Bakkerff60ee62010-03-16 21:09:09 +0000122void debug_print_ret( const ssl_context *ssl, int level,
123 const char *file, int line,
124 const char *text, int ret );
Paul Bakker5121ce52009-01-03 21:22:43 +0000125
Paul Bakkerff60ee62010-03-16 21:09:09 +0000126void debug_print_buf( const ssl_context *ssl, int level,
127 const char *file, int line, const char *text,
Paul Bakker23986e52011-04-24 08:57:21 +0000128 unsigned char *buf, size_t len );
Paul Bakker5121ce52009-01-03 21:22:43 +0000129
Paul Bakkered27a042013-04-18 22:46:23 +0200130#if defined(POLARSSL_BIGNUM_C)
Paul Bakkerff60ee62010-03-16 21:09:09 +0000131void debug_print_mpi( const ssl_context *ssl, int level,
132 const char *file, int line,
133 const char *text, const mpi *X );
Paul Bakkered27a042013-04-18 22:46:23 +0200134#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000135
Paul Bakker41c83d32013-03-20 14:39:14 +0100136#if defined(POLARSSL_ECP_C)
137void debug_print_ecp( const ssl_context *ssl, int level,
138 const char *file, int line,
139 const char *text, const ecp_point *X );
140#endif
141
Paul Bakker7c6b2c32013-09-16 13:49:26 +0200142#if defined(POLARSSL_X509_CRT_PARSE_C)
Paul Bakkerff60ee62010-03-16 21:09:09 +0000143void debug_print_crt( const ssl_context *ssl, int level,
144 const char *file, int line,
Paul Bakkerc559c7a2013-09-18 14:13:26 +0200145 const char *text, const x509_crt *crt );
Paul Bakkered27a042013-04-18 22:46:23 +0200146#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000147
148#ifdef __cplusplus
149}
150#endif
151
152#endif /* debug.h */