Adapt programs to the new debug API

This commit is contained in:
Manuel Pégourié-Gonnard 2015-06-23 17:35:03 +02:00
parent fd474233c8
commit 61ee351af4
10 changed files with 56 additions and 36 deletions

View file

@ -71,11 +71,13 @@ int main( void )
#define DEBUG_LEVEL 0 #define DEBUG_LEVEL 0
static void my_debug( void *ctx, int level, const char *str ) static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )
{ {
((void) level); ((void) level);
mbedtls_fprintf( (FILE *) ctx, "%s", str ); mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx ); fflush( (FILE *) ctx );
} }

View file

@ -79,11 +79,13 @@ int main( void )
#define READ_TIMEOUT_MS 10000 /* 5 seconds */ #define READ_TIMEOUT_MS 10000 /* 5 seconds */
#define DEBUG_LEVEL 0 #define DEBUG_LEVEL 0
static void my_debug( void *ctx, int level, const char *str ) static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )
{ {
((void) level); ((void) level);
mbedtls_fprintf( (FILE *) ctx, "%s", str ); mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx ); fflush( (FILE *) ctx );
} }

View file

@ -66,11 +66,13 @@ int main( void )
#define DEBUG_LEVEL 1 #define DEBUG_LEVEL 1
static void my_debug( void *ctx, int level, const char *str ) static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )
{ {
((void) level); ((void) level);
mbedtls_fprintf( (FILE *) ctx, "%s", str ); mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx ); fflush( (FILE *) ctx );
} }

View file

@ -311,11 +311,13 @@ struct options
int etm; /* negotiate encrypt then mac? */ int etm; /* negotiate encrypt then mac? */
} opt; } opt;
static void my_debug( void *ctx, int level, const char *str ) static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )
{ {
((void) level); ((void) level);
mbedtls_fprintf( (FILE *) ctx, "%s", str ); mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx ); fflush( (FILE *) ctx );
} }

View file

@ -83,13 +83,14 @@ int main( void )
#define DEBUG_LEVEL 0 #define DEBUG_LEVEL 0
static void my_debug( void *ctx, int level, const char *str ) static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )
{ {
if( level < DEBUG_LEVEL ) ((void) level);
{
mbedtls_fprintf( (FILE *) ctx, "%s", str ); mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx ); fflush( (FILE *) ctx );
}
} }
int main( void ) int main( void )

View file

@ -154,13 +154,14 @@ struct options
int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */ int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
} opt; } opt;
static void my_debug( void *ctx, int level, const char *str ) static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )
{ {
if( level < opt.debug_level ) ((void) level);
{
mbedtls_fprintf( (FILE *) ctx, "%s", str ); mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx ); fflush( (FILE *) ctx );
}
} }
static int do_handshake( mbedtls_ssl_context *ssl ) static int do_handshake( mbedtls_ssl_context *ssl )

View file

@ -89,14 +89,19 @@ int main( void )
mbedtls_threading_mutex_t debug_mutex; mbedtls_threading_mutex_t debug_mutex;
static void my_mutexed_debug( void *ctx, int level, const char *str ) static void my_mutexed_debug( void *ctx, int level,
const char *file, int line,
const char *str )
{ {
long int thread_id = (long int) pthread_self();
mbedtls_mutex_lock( &debug_mutex ); mbedtls_mutex_lock( &debug_mutex );
if( level < DEBUG_LEVEL )
{ ((void) level);
mbedtls_fprintf( (FILE *) ctx, "%s", str ); mbedtls_fprintf( (FILE *) ctx, "%s:%04d: [ #%ld ] %s",
fflush( (FILE *) ctx ); file, line, thread_id, str );
} fflush( (FILE *) ctx );
mbedtls_mutex_unlock( &debug_mutex ); mbedtls_mutex_unlock( &debug_mutex );
} }

View file

@ -78,11 +78,13 @@ int main( void )
#define DEBUG_LEVEL 0 #define DEBUG_LEVEL 0
static void my_debug( void *ctx, int level, const char *str ) static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )
{ {
((void) level); ((void) level);
mbedtls_fprintf( (FILE *) ctx, "%s", str ); mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx ); fflush( (FILE *) ctx );
} }

View file

@ -390,11 +390,13 @@ struct options
int badmac_limit; /* Limit of records with bad MAC */ int badmac_limit; /* Limit of records with bad MAC */
} opt; } opt;
static void my_debug( void *ctx, int level, const char *str ) static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )
{ {
((void) level); ((void) level);
mbedtls_fprintf( (FILE *) ctx, "%s", str ); mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx ); fflush( (FILE *) ctx );
} }

View file

@ -110,13 +110,14 @@ struct options
int permissive; /* permissive parsing */ int permissive; /* permissive parsing */
} opt; } opt;
static void my_debug( void *ctx, int level, const char *str ) static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )
{ {
if( level < opt.debug_level ) ((void) level);
{
mbedtls_fprintf( (FILE *) ctx, "%s", str ); mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx ); fflush( (FILE *) ctx );
}
} }
static int my_verify( void *data, mbedtls_x509_crt *crt, int depth, uint32_t *flags ) static int my_verify( void *data, mbedtls_x509_crt *crt, int depth, uint32_t *flags )