| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | #ifndef _OPENSC_LOG_H |
|---|
| 23 | #define _OPENSC_LOG_H |
|---|
| 24 | |
|---|
| 25 | #ifdef __cplusplus |
|---|
| 26 | extern "C" { |
|---|
| 27 | #endif |
|---|
| 28 | |
|---|
| 29 | #include <stdarg.h> |
|---|
| 30 | #include <opensc/opensc.h> |
|---|
| 31 | |
|---|
| 32 | #define SC_LOG_TYPE_ERROR 0 |
|---|
| 33 | #define SC_LOG_TYPE_VERBOSE 1 |
|---|
| 34 | #define SC_LOG_TYPE_DEBUG 2 |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | #if !defined(__GNUC__) && !defined(__IBMC__) && !(defined(_MSC_VER) && (_MSC_VER >= 1300)) |
|---|
| 38 | #define __FUNCTION__ NULL |
|---|
| 39 | #endif |
|---|
| 40 | |
|---|
| 41 | #if defined(__GNUC__) |
|---|
| 42 | |
|---|
| 43 | #define sc_error(ctx, format, args...) sc_do_log(ctx, SC_LOG_TYPE_ERROR, __FILE__, __LINE__, __FUNCTION__, format , ## args) |
|---|
| 44 | #define sc_debug(ctx, format, args...) sc_do_log(ctx, SC_LOG_TYPE_DEBUG, __FILE__, __LINE__, __FUNCTION__, format , ## args) |
|---|
| 45 | |
|---|
| 46 | #else |
|---|
| 47 | #define sc_error _sc_error |
|---|
| 48 | #define sc_debug _sc_debug |
|---|
| 49 | #endif |
|---|
| 50 | |
|---|
| 51 | void _sc_error(struct sc_context *ctx, const char *format, ...); |
|---|
| 52 | void _sc_debug(struct sc_context *ctx, const char *format, ...); |
|---|
| 53 | void sc_do_log(struct sc_context *ctx, int type, const char *file, int line, const char *func, const char *format, ...); |
|---|
| 54 | void sc_do_log_va(struct sc_context *ctx, int type, const char *file, int line, const char *func, const char *format, va_list args); |
|---|
| 55 | |
|---|
| 56 | void sc_hex_dump(struct sc_context *ctx, const u8 * buf, size_t len, char *out, size_t outlen); |
|---|
| 57 | |
|---|
| 58 | #define SC_FUNC_CALLED(ctx, level) do { \ |
|---|
| 59 | if (ctx->debug >= level) \ |
|---|
| 60 | sc_do_log(ctx, SC_LOG_TYPE_DEBUG, __FILE__, __LINE__, __FUNCTION__, "called\n"); \ |
|---|
| 61 | } while (0) |
|---|
| 62 | |
|---|
| 63 | #define SC_FUNC_RETURN(ctx, level, r) do { \ |
|---|
| 64 | int _ret = r; \ |
|---|
| 65 | if (_ret < 0 && !ctx->suppress_errors) { \ |
|---|
| 66 | sc_do_log(ctx, SC_LOG_TYPE_ERROR, __FILE__, __LINE__, __FUNCTION__, "returning with: %s\n", sc_strerror(_ret)); \ |
|---|
| 67 | } else if (ctx->debug >= level) { \ |
|---|
| 68 | sc_do_log(ctx, SC_LOG_TYPE_DEBUG, __FILE__, __LINE__, __FUNCTION__, "returning with: %d\n", _ret); \ |
|---|
| 69 | } \ |
|---|
| 70 | return _ret; \ |
|---|
| 71 | } while(0) |
|---|
| 72 | |
|---|
| 73 | #define SC_TEST_RET(ctx, r, text) do { \ |
|---|
| 74 | int _ret = (r); \ |
|---|
| 75 | if (_ret < 0) { \ |
|---|
| 76 | sc_do_log(ctx, SC_LOG_TYPE_ERROR, __FILE__, __LINE__, __FUNCTION__, "%s: %s\n", (text), sc_strerror(_ret)); \ |
|---|
| 77 | return _ret; \ |
|---|
| 78 | } \ |
|---|
| 79 | } while(0) |
|---|
| 80 | |
|---|
| 81 | #define sc_perror(ctx, errno, str) { \ |
|---|
| 82 | sc_do_log(ctx, SC_LOG_TYPE_ERROR, __FILE__, __LINE__, __FUNCTION__, "%s: %s\n", str, sc_strerror(errno)); \ |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | #ifdef __cplusplus |
|---|
| 86 | } |
|---|
| 87 | #endif |
|---|
| 88 | |
|---|
| 89 | #endif |
|---|