Commit 61ee351a authored by Manuel Pégourié-Gonnard's avatar Manuel Pégourié-Gonnard
Browse files

Adapt programs to the new debug API

parent fd474233
......@@ -71,11 +71,13 @@ int main( void )
#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);
mbedtls_fprintf( (FILE *) ctx, "%s", str );
mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx );
}
......
......@@ -79,11 +79,13 @@ int main( void )
#define READ_TIMEOUT_MS 10000 /* 5 seconds */
#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);
mbedtls_fprintf( (FILE *) ctx, "%s", str );
mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx );
}
......
......@@ -66,11 +66,13 @@ int main( void )
#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);
mbedtls_fprintf( (FILE *) ctx, "%s", str );
mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx );
}
......
......@@ -311,11 +311,13 @@ struct options
int etm; /* negotiate encrypt then mac? */
} 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);
mbedtls_fprintf( (FILE *) ctx, "%s", str );
mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx );
}
......
......@@ -83,13 +83,14 @@ int main( void )
#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 )
{
mbedtls_fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
((void) level);
mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx );
}
int main( void )
......
......@@ -154,13 +154,14 @@ struct options
int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
} 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 )
{
mbedtls_fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
((void) level);
mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx );
}
static int do_handshake( mbedtls_ssl_context *ssl )
......
......@@ -89,14 +89,19 @@ int main( void )
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 );
if( level < DEBUG_LEVEL )
{
mbedtls_fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
((void) level);
mbedtls_fprintf( (FILE *) ctx, "%s:%04d: [ #%ld ] %s",
file, line, thread_id, str );
fflush( (FILE *) ctx );
mbedtls_mutex_unlock( &debug_mutex );
}
......
......@@ -78,11 +78,13 @@ int main( void )
#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);
mbedtls_fprintf( (FILE *) ctx, "%s", str );
mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx );
}
......
......@@ -390,11 +390,13 @@ struct options
int badmac_limit; /* Limit of records with bad MAC */
} 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);
mbedtls_fprintf( (FILE *) ctx, "%s", str );
mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx );
}
......
......@@ -110,13 +110,14 @@ struct options
int permissive; /* permissive parsing */
} 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 )
{
mbedtls_fprintf( (FILE *) ctx, "%s", str );
fflush( (FILE *) ctx );
}
((void) level);
mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
fflush( (FILE *) ctx );
}
static int my_verify( void *data, mbedtls_x509_crt *crt, int depth, uint32_t *flags )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment