2001-12-13 21:19:11 +00:00
|
|
|
|
/*
|
2002-04-06 08:21:40 +00:00
|
|
|
|
* log.h: Logging functions header file
|
2001-12-13 21:19:11 +00:00
|
|
|
|
*
|
2002-04-05 14:46:44 +00:00
|
|
|
|
* Copyright (C) 2001, 2002 Juha Yrj<EFBFBD>l<EFBFBD> <juha.yrjola@iki.fi>
|
2003-01-06 21:46:46 +00:00
|
|
|
|
* Copyright (C) 2003 Antti Tapaninen <aet@cc.hut.fi>
|
2001-12-13 21:19:11 +00:00
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
|
2003-09-03 17:59:08 +00:00
|
|
|
|
#ifndef _OPENSC_LOG_H
|
|
|
|
|
#define _OPENSC_LOG_H
|
2001-12-13 21:19:11 +00:00
|
|
|
|
|
2003-01-06 21:46:46 +00:00
|
|
|
|
#ifdef __cplusplus
|
2002-04-19 14:23:31 +00:00
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-12-13 21:19:11 +00:00
|
|
|
|
#include <stdarg.h>
|
2002-04-05 13:48:00 +00:00
|
|
|
|
#include <opensc/opensc.h>
|
2001-12-13 21:19:11 +00:00
|
|
|
|
|
2001-12-21 23:34:47 +00:00
|
|
|
|
#define SC_LOG_TYPE_ERROR 0
|
|
|
|
|
#define SC_LOG_TYPE_VERBOSE 1
|
|
|
|
|
#define SC_LOG_TYPE_DEBUG 2
|
2001-12-13 21:19:11 +00:00
|
|
|
|
|
2003-01-06 21:46:46 +00:00
|
|
|
|
/* You can't do #ifndef __FUNCTION__ */
|
2005-10-24 21:58:35 +00:00
|
|
|
|
#if !defined(__GNUC__) && !defined(__IBMC__) && !(defined(_MSC_VER) && (_MSC_VER >= 1300))
|
2003-01-06 21:46:46 +00:00
|
|
|
|
#define __FUNCTION__ NULL
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-06-14 12:52:56 +00:00
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
|
|
2003-08-25 14:21:18 +00:00
|
|
|
|
#define sc_error(ctx, format, args...) sc_do_log(ctx, SC_LOG_TYPE_ERROR, __FILE__, __LINE__, __FUNCTION__, format , ## args)
|
|
|
|
|
#define sc_debug(ctx, format, args...) sc_do_log(ctx, SC_LOG_TYPE_DEBUG, __FILE__, __LINE__, __FUNCTION__, format , ## args)
|
2001-12-21 23:34:47 +00:00
|
|
|
|
|
2002-11-18 09:05:06 +00:00
|
|
|
|
#else
|
|
|
|
|
|
2003-08-25 14:21:18 +00:00
|
|
|
|
void sc_error(struct sc_context *ctx, const char *format, ...);
|
|
|
|
|
void sc_debug(struct sc_context *ctx, const char *format, ...);
|
2002-11-18 09:05:06 +00:00
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-01-06 21:46:46 +00:00
|
|
|
|
void sc_do_log(struct sc_context *ctx, int type, const char *file, int line, const char *func, const char *format, ...);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
void sc_hex_dump(struct sc_context *ctx, const u8 * buf, size_t len, char *out, size_t outlen);
|
|
|
|
|
|
|
|
|
|
#define SC_FUNC_CALLED(ctx, level) { \
|
|
|
|
|
if (ctx->debug >= level) \
|
|
|
|
|
sc_do_log(ctx, SC_LOG_TYPE_DEBUG, __FILE__, __LINE__, __FUNCTION__, "called\n"); \
|
2001-12-13 21:19:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-06 21:46:46 +00:00
|
|
|
|
#define SC_FUNC_RETURN(ctx, level, r) { \
|
|
|
|
|
int _ret = r; \
|
2003-10-14 09:56:50 +00:00
|
|
|
|
if (_ret < 0 && !ctx->suppress_errors) { \
|
2003-01-06 21:46:46 +00:00
|
|
|
|
sc_do_log(ctx, SC_LOG_TYPE_ERROR, __FILE__, __LINE__, __FUNCTION__, "returning with: %s\n", sc_strerror(_ret)); \
|
|
|
|
|
} else if (ctx->debug >= level) { \
|
|
|
|
|
sc_do_log(ctx, SC_LOG_TYPE_DEBUG, __FILE__, __LINE__, __FUNCTION__, "returning with: %d\n", _ret); \
|
|
|
|
|
} \
|
|
|
|
|
return _ret; \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define SC_TEST_RET(ctx, r, text) { \
|
|
|
|
|
int _ret = (r); \
|
|
|
|
|
if (_ret < 0) { \
|
|
|
|
|
sc_do_log(ctx, SC_LOG_TYPE_ERROR, __FILE__, __LINE__, __FUNCTION__, "%s: %s\n", (text), sc_strerror(_ret)); \
|
|
|
|
|
return _ret; \
|
|
|
|
|
} \
|
|
|
|
|
}
|
2001-12-13 21:19:11 +00:00
|
|
|
|
|
2003-01-06 21:46:46 +00:00
|
|
|
|
#define sc_perror(ctx, errno, str) { \
|
|
|
|
|
sc_do_log(ctx, SC_LOG_TYPE_ERROR, __FILE__, __LINE__, __FUNCTION__, "%s: %s\n", str, sc_strerror(errno)); \
|
|
|
|
|
}
|
2001-12-13 21:19:11 +00:00
|
|
|
|
|
2003-01-06 21:46:46 +00:00
|
|
|
|
#ifdef __cplusplus
|
2002-04-19 14:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-12-13 21:19:11 +00:00
|
|
|
|
#endif
|