Verify callback is run in either side.
[gnutls.git] / lib / gnutls_errors.h
blob28dc1a75580573fe9619e3fc7195fb7bc0bc80ff
1 /*
2 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 #ifndef GNUTLS_ERRORS_H
24 #define GNUTLS_ERRORS_H
26 #include <gnutls_int.h>
27 #include <gnutls_global.h>
29 #define GNUTLS_E_INT_RET_0 -1251
31 #ifdef __FILE__
32 #ifdef __LINE__
33 #define gnutls_assert() _gnutls_debug_log( "ASSERT: %s:%d\n", __FILE__,__LINE__);
34 #else
35 #define gnutls_assert()
36 #endif
37 #else /* __FILE__ not defined */
38 #define gnutls_assert()
39 #endif
41 int _gnutls_asn2err (int asn_err);
42 void
43 _gnutls_log (int, const char *fmt, ...)
44 #ifdef __GNUC__
45 __attribute__ ((format (printf, 2, 3)));
46 #else
48 #endif
50 void
51 _gnutls_audit_log (gnutls_session_t, const char *fmt, ...)
52 #ifdef __GNUC__
53 __attribute__ ((format (printf, 2, 3)));
54 #else
56 #endif
58 void _gnutls_mpi_log (const char *prefix, bigint_t a);
60 #ifdef C99_MACROS
61 #define LEVEL(l, ...) do { if (unlikely(_gnutls_log_level >= l)) \
62 _gnutls_log( l, __VA_ARGS__); } while(0)
64 #define LEVEL_EQ(l, ...) do { if (unlikely(_gnutls_log_level == l || _gnutls_log_level > 9)) \
65 _gnutls_log( l, __VA_ARGS__); } while(0)
67 #define _gnutls_debug_log(...) LEVEL(2, __VA_ARGS__)
68 #define _gnutls_handshake_log(...) LEVEL(3, __VA_ARGS__)
69 #define _gnutls_io_log(...) LEVEL_EQ(5, __VA_ARGS__)
70 #define _gnutls_buffers_log(...) LEVEL_EQ(6, __VA_ARGS__)
71 #define _gnutls_hard_log(...) LEVEL(9, __VA_ARGS__)
72 #define _gnutls_record_log(...) LEVEL(4, __VA_ARGS__)
73 #define _gnutls_dtls_log(...) LEVEL(6, __VA_ARGS__)
74 #define _gnutls_read_log(...) LEVEL_EQ(7, __VA_ARGS__)
75 #define _gnutls_write_log(...) LEVEL_EQ(7, __VA_ARGS__)
76 #else
77 #define _gnutls_debug_log _gnutls_null_log
78 #define _gnutls_handshake_log _gnutls_null_log
79 #define _gnutls_io_log _gnutls_null_log
80 #define _gnutls_buffers_log _gnutls_null_log
81 #define _gnutls_hard_log _gnutls_null_log
82 #define _gnutls_record_log _gnutls_null_log
83 #define _gnutls_dtls_log _gnutls_null_log
84 #define _gnutls_read_log _gnutls_null_log
85 #define _gnutls_write_log _gnutls_null_log
87 void _gnutls_null_log (void *, ...);
89 #endif /* C99_MACROS */
91 /* GCC won't inline this by itself and results in a "fatal warning"
92 otherwise. Making this a macro has been tried, but it interacts
93 badly with the do..while in the expansion. Welcome to the dark
94 side. */
95 static inline
96 #ifdef __GNUC__
97 __attribute__ ((always_inline))
98 #endif
99 int gnutls_assert_val_int (int val, const char *file, int line)
101 _gnutls_debug_log ("ASSERT: %s:%d\n", file, line);
102 return val;
105 #define gnutls_assert_val(x) gnutls_assert_val_int(x, __FILE__, __LINE__)
106 #define gnutls_assert_val_fatal(x) (((x)!=GNUTLS_E_AGAIN && (x)!=GNUTLS_E_INTERRUPTED)?gnutls_assert_val_int(x, __FILE__, __LINE__):(x))
108 #endif /* GNUTLS_ERRORS_H */