pcsc-lite 1.9.9
debuglog.h
Go to the documentation of this file.
1/*
2 * MUSCLE SmartCard Development ( https://pcsclite.apdu.fr/ )
3 *
4 * Copyright (C) 1999-2004
5 * David Corcoran <corcoran@musclecard.com>
6 * Copyright (C) 1999-2011
7 * Ludovic Rousseau <ludovic.rousseau@free.fr>
8 *
9Redistribution and use in source and binary forms, with or without
10modification, are permitted provided that the following conditions
11are met:
12
131. Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
152. Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
183. The name of the author may not be used to endorse or promote products
19 derived from this software without specific prior written permission.
20
21THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
54#ifndef __debuglog_h__
55#define __debuglog_h__
56
57#ifndef PCSC_API
58#define PCSC_API
59#endif
60
61enum {
62 DEBUGLOG_NO_DEBUG = 0,
63 DEBUGLOG_SYSLOG_DEBUG,
64 DEBUGLOG_STDOUT_DEBUG,
65 DEBUGLOG_STDOUT_COLOR_DEBUG
66};
67
68#define DEBUG_CATEGORY_NOTHING 0
69#define DEBUG_CATEGORY_APDU 1
70#define DEBUG_CATEGORY_SW 2
71
72enum {
73 PCSC_LOG_DEBUG = 0,
74 PCSC_LOG_INFO,
75 PCSC_LOG_ERROR,
76 PCSC_LOG_CRITICAL
77};
78
79/* You can't do #ifndef __FUNCTION__ */
80#if !defined(__GNUC__) && !defined(__IBMC__)
81#define __FUNCTION__ ""
82#endif
83
84#ifndef __GNUC__
85#define __attribute__(x) /*nothing*/
86#endif
87
88#ifdef NO_LOG
89
90#define Log0(priority) do { } while(0)
91#define Log1(priority, fmt) do { } while(0)
92#define Log2(priority, fmt, data) do {(void)priority; } while(0)
93#define Log3(priority, fmt, data1, data2) do {int _p = priority; (void)_p; } while(0)
94#define Log4(priority, fmt, data1, data2, data3) do { } while(0)
95#define LogRv4(priority, rv, fmt, data1, data2) do { } while(0)
96#define Log5(priority, fmt, data1, data2, data3, data4) do { } while(0)
97#define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) do { } while(0)
98#define LogXxd(priority, msg, buffer, size) do { } while(0)
99#define rv2text(rv) ""
100
101#define DebugLogA(a)
102#define DebugLogB(a, b)
103#define DebugLogC(a, b,c)
104
105#else
106
107#define Log0(priority) log_msg(priority, "%s:%d:%s()", __FILE__, __LINE__, __FUNCTION__)
108#define Log1(priority, fmt) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__)
109#define Log2(priority, fmt, data) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data)
110#define Log3(priority, fmt, data1, data2) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2)
111#define Log4(priority, fmt, data1, data2, data3) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3)
112#define LogRv4(priority, rv, fmt, data1, data2) log_msg_rv(priority, rv, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2)
113#define Log5(priority, fmt, data1, data2, data3, data4) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4)
114#define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4, data5, data6, data7, data8)
115#define LogXxd(priority, msg, buffer, size) log_xxd(priority, msg, buffer, size)
116const char * rv2text(unsigned int rv);
117
118#define DebugLogA(a) Log1(PCSC_LOG_INFO, a)
119#define DebugLogB(a, b) Log2(PCSC_LOG_INFO, a, b)
120#define DebugLogC(a, b,c) Log3(PCSC_LOG_INFO, a, b, c)
121
122#endif /* NO_LOG */
123
124PCSC_API void log_msg_rv(const int priority, unsigned int rv, const char *fmt, ...)
125 __attribute__((format(printf, 3, 4)));
126
127PCSC_API void log_msg(const int priority, const char *fmt, ...)
128 __attribute__((format(printf, 2, 3)));
129
130PCSC_API void log_xxd(const int priority, const char *msg,
131 const unsigned char *buffer, const int size);
132
133void DebugLogSuppress(const int);
134void DebugLogSetLogType(const int);
135void DebugLogSetCategory(const int);
136void DebugLogCategory(const int, const unsigned char *, const int);
137PCSC_API void DebugLogSetLevel(const int level);
138
139#endif /* __debuglog_h__ */
140