2001-12-13 21:19:11 +00:00
|
|
|
/*
|
2002-01-08 13:56:50 +00:00
|
|
|
* log.c: Miscellaneous logging functions
|
2001-12-13 21:19:11 +00:00
|
|
|
*
|
2006-12-19 21:31:17 +00:00
|
|
|
* Copyright (C) 2001, 2002 Juha Yrjölä <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
|
|
|
|
*/
|
|
|
|
|
2015-04-22 21:55:33 +00:00
|
|
|
#if HAVE_CONFIG_H
|
2010-03-04 08:14:36 +00:00
|
|
|
#include "config.h"
|
2015-04-22 21:55:33 +00:00
|
|
|
#endif
|
2010-03-04 08:14:36 +00:00
|
|
|
|
2001-12-13 21:19:11 +00:00
|
|
|
#include <stdarg.h>
|
2001-12-19 21:58:04 +00:00
|
|
|
#include <stdlib.h>
|
2001-12-13 21:19:11 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
2009-11-17 11:11:05 +00:00
|
|
|
#include <time.h>
|
2002-10-19 14:04:52 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2002-06-14 12:52:56 +00:00
|
|
|
#include <unistd.h>
|
2002-10-19 14:04:52 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
2002-01-07 18:32:13 +00:00
|
|
|
#include <sys/time.h>
|
2002-10-19 14:04:52 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_IO_H
|
2002-06-14 12:52:56 +00:00
|
|
|
#include <io.h>
|
|
|
|
#endif
|
2010-02-05 11:21:31 +00:00
|
|
|
#ifdef HAVE_PTHREAD
|
2010-02-04 06:19:52 +00:00
|
|
|
#include <pthread.h>
|
2010-02-05 11:21:31 +00:00
|
|
|
#endif
|
2018-11-25 21:08:36 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2001-12-13 21:19:11 +00:00
|
|
|
|
2010-03-04 08:14:36 +00:00
|
|
|
#include "internal.h"
|
|
|
|
|
2018-11-25 21:08:36 +00:00
|
|
|
static void sc_do_log_va(sc_context_t *ctx, int level, const char *file, int line, const char *func, int color, const char *format, va_list args);
|
2021-06-11 12:17:38 +00:00
|
|
|
static int sc_color_fprintf_va(int colors, struct sc_context *ctx, FILE * stream, const char *format, va_list args);
|
2011-05-08 08:07:03 +00:00
|
|
|
|
2010-03-15 12:17:13 +00:00
|
|
|
void sc_do_log(sc_context_t *ctx, int level, const char *file, int line, const char *func, const char *format, ...)
|
2001-12-13 21:19:11 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2010-04-14 11:52:27 +00:00
|
|
|
va_start(ap, format);
|
2018-11-25 21:08:36 +00:00
|
|
|
sc_do_log_va(ctx, level, file, line, func, 0, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sc_do_log_color(sc_context_t *ctx, int level, const char *file, int line, const char *func, int color, const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
sc_do_log_va(ctx, level, file, line, func, color, format, ap);
|
2010-04-14 11:52:27 +00:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2011-05-08 08:07:03 +00:00
|
|
|
void sc_do_log_noframe(sc_context_t *ctx, int level, const char *format, va_list args)
|
|
|
|
{
|
2018-11-25 21:08:36 +00:00
|
|
|
sc_do_log_va(ctx, level, NULL, 0, NULL, 0, format, args);
|
2011-05-08 08:07:03 +00:00
|
|
|
}
|
|
|
|
|
2018-11-25 21:08:36 +00:00
|
|
|
static void sc_do_log_va(sc_context_t *ctx, int level, const char *file, int line, const char *func, int color, const char *format, va_list args)
|
2010-04-14 11:52:27 +00:00
|
|
|
{
|
2009-11-17 11:11:05 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
SYSTEMTIME st;
|
|
|
|
#else
|
|
|
|
struct tm *tm;
|
2009-11-17 13:27:15 +00:00
|
|
|
struct timeval tv;
|
|
|
|
char time_string[40];
|
2009-11-17 11:11:05 +00:00
|
|
|
#endif
|
2001-12-13 21:19:11 +00:00
|
|
|
|
2015-04-03 19:07:49 +00:00
|
|
|
if (!ctx || ctx->debug < level)
|
2002-01-24 16:02:54 +00:00
|
|
|
return;
|
2003-10-22 06:49:59 +00:00
|
|
|
|
2018-11-25 21:08:36 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
/* In Windows, file handles can not be shared between DLL-s, each DLL has a
|
|
|
|
* separate file handle table. Make sure we always have a valid file
|
|
|
|
* descriptor. */
|
|
|
|
if (sc_ctx_log_to_file(ctx, ctx->debug_filename) < 0)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
if (ctx->debug_file == NULL)
|
|
|
|
return;
|
2009-11-17 11:11:05 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
GetLocalTime(&st);
|
2018-11-25 21:08:36 +00:00
|
|
|
sc_color_fprintf(SC_COLOR_FG_GREEN|SC_COLOR_BOLD,
|
|
|
|
ctx, ctx->debug_file,
|
|
|
|
"P:%lu; T:%lu",
|
2017-11-15 07:25:07 +00:00
|
|
|
(unsigned long)GetCurrentProcessId(),
|
2018-11-25 21:08:36 +00:00
|
|
|
(unsigned long)GetCurrentThreadId());
|
|
|
|
sc_color_fprintf(SC_COLOR_FG_GREEN,
|
|
|
|
ctx, ctx->debug_file,
|
|
|
|
" %i-%02i-%02i %02i:%02i:%02i.%03i",
|
2009-11-17 11:11:05 +00:00
|
|
|
st.wYear, st.wMonth, st.wDay,
|
|
|
|
st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
|
|
|
|
#else
|
2018-11-25 21:08:36 +00:00
|
|
|
sc_color_fprintf(SC_COLOR_FG_GREEN|SC_COLOR_BOLD,
|
|
|
|
ctx, ctx->debug_file,
|
|
|
|
"P:%lu; T:0x%lu",
|
|
|
|
(unsigned long)getpid(),
|
|
|
|
(unsigned long)pthread_self());
|
2009-11-17 13:27:15 +00:00
|
|
|
gettimeofday (&tv, NULL);
|
|
|
|
tm = localtime (&tv.tv_sec);
|
2010-01-24 15:25:08 +00:00
|
|
|
strftime (time_string, sizeof(time_string), "%H:%M:%S", tm);
|
2018-11-25 21:08:36 +00:00
|
|
|
sc_color_fprintf(SC_COLOR_FG_GREEN,
|
|
|
|
ctx, ctx->debug_file,
|
|
|
|
" %s.%03ld",
|
|
|
|
time_string,
|
|
|
|
(long)tv.tv_usec / 1000);
|
2009-11-17 11:11:05 +00:00
|
|
|
#endif
|
2018-11-25 21:08:36 +00:00
|
|
|
|
|
|
|
sc_color_fprintf(SC_COLOR_FG_YELLOW,
|
|
|
|
ctx, ctx->debug_file,
|
|
|
|
" [");
|
|
|
|
sc_color_fprintf(SC_COLOR_FG_YELLOW|SC_COLOR_BOLD,
|
|
|
|
ctx, ctx->debug_file,
|
|
|
|
"%s",
|
|
|
|
ctx->app_name);
|
|
|
|
sc_color_fprintf(SC_COLOR_FG_YELLOW,
|
|
|
|
ctx, ctx->debug_file,
|
|
|
|
"] ");
|
2009-11-17 11:11:05 +00:00
|
|
|
|
2001-12-13 21:19:11 +00:00
|
|
|
if (file != NULL) {
|
2018-11-25 21:08:36 +00:00
|
|
|
sc_color_fprintf(SC_COLOR_FG_YELLOW,
|
|
|
|
ctx, ctx->debug_file,
|
|
|
|
"%s:%d:%s: ",
|
|
|
|
file, line, func ? func : "");
|
2012-05-29 17:44:54 +00:00
|
|
|
}
|
2010-02-04 06:19:52 +00:00
|
|
|
|
2021-06-11 12:17:38 +00:00
|
|
|
sc_color_fprintf_va(color, ctx, ctx->debug_file, format, args);
|
2021-08-06 18:53:49 +00:00
|
|
|
if (strlen(format) == 0 || format[strlen(format) - 1] != '\n')
|
|
|
|
sc_color_fprintf(color, ctx, ctx->debug_file, "\n");
|
2018-11-25 21:08:36 +00:00
|
|
|
fflush(ctx->debug_file);
|
2010-03-15 12:17:13 +00:00
|
|
|
|
2018-01-30 12:38:15 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (ctx->debug_file && (ctx->debug_file != stderr && ctx->debug_file != stdout))
|
|
|
|
fclose(ctx->debug_file);
|
|
|
|
ctx->debug_file = NULL;
|
|
|
|
#endif
|
2001-12-13 21:19:11 +00:00
|
|
|
}
|
|
|
|
|
2010-04-14 11:52:27 +00:00
|
|
|
void _sc_debug(struct sc_context *ctx, int level, const char *format, ...)
|
2012-05-29 17:44:54 +00:00
|
|
|
{
|
2010-04-14 11:52:27 +00:00
|
|
|
va_list ap;
|
|
|
|
|
tools: fix segfault with verbose log into 'stderr'
Issue #824
In Windows, file handles (including 'stderr', 'stdout') can not be shared
between DLL-s, and so, the log handle (File *), defined in one module, cannot
be reused in another.
That is the situation when, for example, the SM is processed
in external, dynamically loadable module as it currently implemented for
IAS/ECC card.
That's for the configuration option 're-open of log file on each message' was
introduced.
This 're-open' logic has not been tested in the particular case of opensc-*
tools used with verbose log into 'stderr' -- in dynamically loaded module the
'stderr' handle, defined in the 'main' module, was not recognized as 'stderr'
and there was an attempt to close it.
closes #910
2016-11-23 10:24:41 +00:00
|
|
|
va_start(ap, format);
|
2018-11-25 21:08:36 +00:00
|
|
|
sc_do_log_va(ctx, level, NULL, 0, NULL, 0, format, ap);
|
tools: fix segfault with verbose log into 'stderr'
Issue #824
In Windows, file handles (including 'stderr', 'stdout') can not be shared
between DLL-s, and so, the log handle (File *), defined in one module, cannot
be reused in another.
That is the situation when, for example, the SM is processed
in external, dynamically loadable module as it currently implemented for
IAS/ECC card.
That's for the configuration option 're-open of log file on each message' was
introduced.
This 're-open' logic has not been tested in the particular case of opensc-*
tools used with verbose log into 'stderr' -- in dynamically loaded module the
'stderr' handle, defined in the 'main' module, was not recognized as 'stderr'
and there was an attempt to close it.
closes #910
2016-11-23 10:24:41 +00:00
|
|
|
va_end(ap);
|
2010-04-14 11:52:27 +00:00
|
|
|
}
|
|
|
|
|
2011-01-04 11:33:03 +00:00
|
|
|
void _sc_log(struct sc_context *ctx, const char *format, ...)
|
2011-01-04 09:17:37 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, format);
|
2018-11-25 21:08:36 +00:00
|
|
|
sc_do_log_va(ctx, SC_LOG_DEBUG_NORMAL, NULL, 0, NULL, 0, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2019-01-04 19:22:46 +00:00
|
|
|
static int is_a_tty(FILE *fp)
|
|
|
|
{
|
|
|
|
if (fp != NULL) {
|
|
|
|
int fd = fileno(fp);
|
|
|
|
if (fd >= 0) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
HANDLE h = (HANDLE)_get_osfhandle(fd);
|
|
|
|
if (h != INVALID_HANDLE_VALUE) {
|
|
|
|
return GetFileType(h) == FILE_TYPE_CHAR;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
return isatty(fd);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-25 21:08:36 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define set_color(sc_color, win_color, vt100_color) \
|
|
|
|
do { if (colors & sc_color) { attr |= win_color; } } while (0)
|
|
|
|
#else
|
|
|
|
#define set_color(sc_color, win_color, vt100_color) \
|
|
|
|
do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int sc_color_fprintf(int colors, struct sc_context *ctx, FILE * stream, const char * format, ...)
|
|
|
|
{
|
2021-06-11 12:17:38 +00:00
|
|
|
int r;
|
2018-11-25 21:08:36 +00:00
|
|
|
va_list ap;
|
2021-06-11 12:17:38 +00:00
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
r = sc_color_fprintf_va(colors, ctx, stream, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sc_color_fprintf_va(int colors, struct sc_context *ctx, FILE * stream, const char *format, va_list args)
|
|
|
|
{
|
2018-11-25 21:08:36 +00:00
|
|
|
int r;
|
|
|
|
#ifdef _WIN32
|
|
|
|
WORD old_attr = 0;
|
|
|
|
int fd = stream ? fileno(stream) : -1;
|
|
|
|
HANDLE handle = fd >= 0 ? (HANDLE) _get_osfhandle(fd) : INVALID_HANDLE_VALUE;
|
|
|
|
#endif
|
|
|
|
|
2019-01-04 19:22:46 +00:00
|
|
|
if (!is_a_tty(stream))
|
|
|
|
colors = 0;
|
|
|
|
|
2018-11-25 21:08:36 +00:00
|
|
|
if (colors && (!ctx || (!(ctx->flags & SC_CTX_FLAG_DISABLE_COLORS)))) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
WORD attr = 0;
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
GetConsoleScreenBufferInfo(handle, &csbi);
|
|
|
|
old_attr = csbi.wAttributes;
|
|
|
|
#endif
|
|
|
|
set_color(SC_COLOR_FG_RED,
|
|
|
|
FOREGROUND_RED,
|
|
|
|
"\x1b[31m");
|
|
|
|
set_color(SC_COLOR_FG_GREEN,
|
|
|
|
FOREGROUND_GREEN,
|
|
|
|
"\x1b[32m");
|
|
|
|
set_color(SC_COLOR_FG_YELLOW,
|
|
|
|
FOREGROUND_GREEN|FOREGROUND_RED,
|
|
|
|
"\x1b[33m");
|
|
|
|
set_color(SC_COLOR_FG_BLUE,
|
|
|
|
FOREGROUND_BLUE,
|
|
|
|
"\x1b[34m");
|
|
|
|
set_color(SC_COLOR_FG_MAGENTA,
|
|
|
|
FOREGROUND_BLUE|FOREGROUND_RED,
|
|
|
|
"\x1b[35m");
|
|
|
|
set_color(SC_COLOR_FG_CYAN,
|
|
|
|
FOREGROUND_BLUE|FOREGROUND_GREEN,
|
|
|
|
"\x1b[36m");
|
|
|
|
set_color(SC_COLOR_BG_RED,
|
|
|
|
FOREGROUND_RED,
|
|
|
|
"\x1b[41m");
|
|
|
|
set_color(SC_COLOR_BG_GREEN,
|
|
|
|
BACKGROUND_GREEN,
|
|
|
|
"\x1b[42m");
|
|
|
|
set_color(SC_COLOR_BG_YELLOW,
|
|
|
|
BACKGROUND_GREEN|BACKGROUND_RED,
|
|
|
|
"\x1b[43m");
|
|
|
|
set_color(SC_COLOR_BG_BLUE,
|
|
|
|
BACKGROUND_BLUE,
|
|
|
|
"\x1b[44m");
|
|
|
|
set_color(SC_COLOR_BG_MAGENTA,
|
|
|
|
BACKGROUND_BLUE|BACKGROUND_RED,
|
|
|
|
"\x1b[45m");
|
|
|
|
set_color(SC_COLOR_BG_CYAN,
|
|
|
|
BACKGROUND_BLUE|BACKGROUND_GREEN,
|
|
|
|
"\x1b[46m");
|
|
|
|
set_color(SC_COLOR_BOLD,
|
|
|
|
FOREGROUND_INTENSITY,
|
|
|
|
"\x1b[1m");
|
|
|
|
#ifdef _WIN32
|
|
|
|
SetConsoleTextAttribute(handle, attr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:17:38 +00:00
|
|
|
r = vfprintf(stream, format, args);
|
2018-11-25 21:08:36 +00:00
|
|
|
|
|
|
|
if (colors && (!ctx || (!(ctx->flags & SC_CTX_FLAG_DISABLE_COLORS)))) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
SetConsoleTextAttribute(handle, old_attr);
|
|
|
|
#else
|
|
|
|
fprintf(stream, "\x1b[0m");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
2011-01-04 09:17:37 +00:00
|
|
|
}
|
2010-04-14 11:52:27 +00:00
|
|
|
|
2012-08-03 21:12:12 +00:00
|
|
|
void _sc_debug_hex(sc_context_t *ctx, int type, const char *file, int line,
|
tools: fix segfault with verbose log into 'stderr'
Issue #824
In Windows, file handles (including 'stderr', 'stdout') can not be shared
between DLL-s, and so, the log handle (File *), defined in one module, cannot
be reused in another.
That is the situation when, for example, the SM is processed
in external, dynamically loadable module as it currently implemented for
IAS/ECC card.
That's for the configuration option 're-open of log file on each message' was
introduced.
This 're-open' logic has not been tested in the particular case of opensc-*
tools used with verbose log into 'stderr' -- in dynamically loaded module the
'stderr' handle, defined in the 'main' module, was not recognized as 'stderr'
and there was an attempt to close it.
closes #910
2016-11-23 10:24:41 +00:00
|
|
|
const char *func, const char *label, const u8 *data, size_t len)
|
2012-08-03 21:12:12 +00:00
|
|
|
{
|
|
|
|
size_t blen = len * 5 + 128;
|
|
|
|
char *buf = malloc(blen);
|
|
|
|
if (buf == NULL)
|
|
|
|
return;
|
|
|
|
|
2017-11-13 14:11:58 +00:00
|
|
|
sc_hex_dump(data, len, buf, blen);
|
2016-08-27 21:19:52 +00:00
|
|
|
|
|
|
|
if (label)
|
|
|
|
sc_do_log(ctx, type, file, line, func,
|
2017-11-13 14:11:58 +00:00
|
|
|
"\n%s (%"SC_FORMAT_LEN_SIZE_T"u byte%s):\n%s",
|
|
|
|
label, len, len==1?"":"s", buf);
|
2016-08-27 21:19:52 +00:00
|
|
|
else
|
|
|
|
sc_do_log(ctx, type, file, line, func,
|
2017-11-13 14:11:58 +00:00
|
|
|
"%"SC_FORMAT_LEN_SIZE_T"u byte%s:\n%s",
|
|
|
|
len, len==1?"":"s", buf);
|
2012-08-03 21:12:12 +00:00
|
|
|
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
2017-11-13 14:11:58 +00:00
|
|
|
void sc_hex_dump(const u8 * in, size_t count, char *buf, size_t len)
|
2001-12-13 21:19:11 +00:00
|
|
|
{
|
2001-12-30 21:17:34 +00:00
|
|
|
char *p = buf;
|
2001-12-13 21:19:11 +00:00
|
|
|
int lines = 0;
|
|
|
|
|
2017-02-22 08:32:18 +00:00
|
|
|
if (buf == NULL || (in == NULL && count != 0)) {
|
|
|
|
return;
|
|
|
|
}
|
2001-12-13 21:19:11 +00:00
|
|
|
buf[0] = 0;
|
2003-01-06 21:46:46 +00:00
|
|
|
if ((count * 5) > len)
|
2001-12-13 21:19:11 +00:00
|
|
|
return;
|
2003-01-06 21:46:46 +00:00
|
|
|
while (count) {
|
2001-12-13 21:19:11 +00:00
|
|
|
char ascbuf[17];
|
2003-05-30 08:54:42 +00:00
|
|
|
size_t i;
|
2001-12-13 21:19:11 +00:00
|
|
|
|
|
|
|
for (i = 0; i < count && i < 16; i++) {
|
|
|
|
sprintf(p, "%02X ", *in);
|
|
|
|
if (isprint(*in))
|
|
|
|
ascbuf[i] = *in;
|
|
|
|
else
|
|
|
|
ascbuf[i] = '.';
|
|
|
|
p += 3;
|
|
|
|
in++;
|
|
|
|
}
|
|
|
|
count -= i;
|
|
|
|
ascbuf[i] = 0;
|
|
|
|
for (; i < 16 && lines; i++) {
|
|
|
|
strcat(p, " ");
|
|
|
|
p += 3;
|
|
|
|
}
|
|
|
|
strcat(p, ascbuf);
|
|
|
|
p += strlen(p);
|
|
|
|
sprintf(p, "\n");
|
|
|
|
p++;
|
2001-12-19 21:58:04 +00:00
|
|
|
lines++;
|
2001-12-13 21:19:11 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-17 11:11:05 +00:00
|
|
|
|
2017-11-13 14:11:58 +00:00
|
|
|
const char *
|
2009-11-17 11:11:05 +00:00
|
|
|
sc_dump_hex(const u8 * in, size_t count)
|
|
|
|
{
|
|
|
|
static char dump_buf[0x1000];
|
|
|
|
size_t ii, size = sizeof(dump_buf) - 0x10;
|
2013-06-13 18:13:01 +00:00
|
|
|
size_t offs = 0;
|
2009-11-17 11:11:05 +00:00
|
|
|
|
|
|
|
memset(dump_buf, 0, sizeof(dump_buf));
|
|
|
|
if (in == NULL)
|
2013-06-13 18:13:01 +00:00
|
|
|
return dump_buf;
|
2009-11-17 11:11:05 +00:00
|
|
|
|
|
|
|
for (ii=0; ii<count; ii++) {
|
2014-01-01 16:51:54 +00:00
|
|
|
if (ii && !(ii%16)) {
|
|
|
|
if (!(ii%48))
|
2009-11-17 11:11:05 +00:00
|
|
|
snprintf(dump_buf + offs, size - offs, "\n");
|
|
|
|
else
|
|
|
|
snprintf(dump_buf + offs, size - offs, " ");
|
2013-06-13 18:13:01 +00:00
|
|
|
offs = strlen(dump_buf);
|
2009-11-17 11:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(dump_buf + offs, size - offs, "%02X", *(in + ii));
|
2013-06-13 18:13:01 +00:00
|
|
|
offs += 2;
|
2009-11-17 11:11:05 +00:00
|
|
|
|
|
|
|
if (offs > size)
|
2013-06-13 18:13:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-11-17 11:11:05 +00:00
|
|
|
|
2013-06-13 18:13:01 +00:00
|
|
|
if (ii<count)
|
|
|
|
snprintf(dump_buf + offs, sizeof(dump_buf) - offs, "....\n");
|
2009-11-17 11:11:05 +00:00
|
|
|
|
|
|
|
return dump_buf;
|
|
|
|
}
|
2015-02-02 15:25:54 +00:00
|
|
|
|
2017-11-13 14:11:58 +00:00
|
|
|
const char *
|
2015-02-02 15:25:54 +00:00
|
|
|
sc_dump_oid(const struct sc_object_id *oid)
|
|
|
|
{
|
|
|
|
static char dump_buf[SC_MAX_OBJECT_ID_OCTETS * 20];
|
|
|
|
size_t ii;
|
|
|
|
|
|
|
|
memset(dump_buf, 0, sizeof(dump_buf));
|
|
|
|
if (oid)
|
|
|
|
for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS && oid->value[ii] != -1; ii++)
|
|
|
|
snprintf(dump_buf + strlen(dump_buf), sizeof(dump_buf) - strlen(dump_buf), "%s%i", (ii ? "." : ""), oid->value[ii]);
|
|
|
|
|
|
|
|
return dump_buf;
|
|
|
|
}
|