Add debug_set_threshold() and thresholding of messages
diff --git a/library/debug.c b/library/debug.c
index 40a4399..60e39ed 100644
--- a/library/debug.c
+++ b/library/debug.c
@@ -47,12 +47,18 @@
 #endif /* _MSC_VER */
 
 static int debug_log_mode = POLARSSL_DEBUG_DFL_MODE;
+static int debug_threshold = 0;
 
 void debug_set_log_mode( int log_mode )
 {
     debug_log_mode = log_mode;
 }
 
+void debug_set_threshold( int threshold )
+{
+    debug_threshold = threshold;
+}
+
 char *debug_fmt( const char *format, ... )
 {
     va_list argp;
@@ -73,7 +79,7 @@
     char str[512];
     int maxlen = sizeof( str ) - 1;
 
-    if( ssl->f_dbg == NULL )
+    if( ssl->f_dbg == NULL || level > debug_threshold )
         return;
 
     if( debug_log_mode == POLARSSL_DEBUG_LOG_RAW )
@@ -95,7 +101,7 @@
     int maxlen = sizeof( str ) - 1;
     size_t idx = 0;
 
-    if( ssl->f_dbg == NULL )
+    if( ssl->f_dbg == NULL || level > debug_threshold )
         return;
 
     if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
@@ -115,7 +121,7 @@
     char str[512];
     size_t i, maxlen = sizeof( str ) - 1, idx = 0;
 
-    if( ssl->f_dbg == NULL )
+    if( ssl->f_dbg == NULL || level > debug_threshold )
         return;
 
     if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
@@ -169,6 +175,9 @@
     char str[512];
     int maxlen = sizeof( str ) - 1;
 
+    if( ssl->f_dbg == NULL || level > debug_threshold )
+        return;
+
     snprintf( str, maxlen, "%s(X)", text );
     str[maxlen] = '\0';
     debug_print_mpi( ssl, level, file, line, str, &X->X );
@@ -188,7 +197,7 @@
     int j, k, maxlen = sizeof( str ) - 1, zeros = 1;
     size_t i, n, idx = 0;
 
-    if( ssl->f_dbg == NULL || X == NULL )
+    if( ssl->f_dbg == NULL || X == NULL || level > debug_threshold )
         return;
 
     for( n = X->n - 1; n > 0; n-- )
@@ -301,7 +310,7 @@
     char str[1024], prefix[64];
     int i = 0, maxlen = sizeof( prefix ) - 1, idx = 0;
 
-    if( ssl->f_dbg == NULL || crt == NULL )
+    if( ssl->f_dbg == NULL || crt == NULL || level > debug_threshold )
         return;
 
     if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )