root/trunk/src/libopensc/log.c

Revision 3405, 3.4 KB (checked in by alonbl, 9 months ago)

Complete rewrite of OpenSC build system.

1. Build system now supports MinGW (Windows) compilation using msys and cross compilation.
2. Ability to explicitly disable and enable dependencies of the package.
3. openct, pcsc and nsplugins features are disabled by default.
4. Modified pcsc driver to use pcsc dynamically, no compile time dependency is required.
5. --enable-pcsc-lite configuration option renamed to --enable-pcsc.
6. Install opensc.conf file (as opensc.conf.new if opensc.conf exists).
7. Add--enable-doc configuration option, allow installing documentation into target.
8. Add --disable-man configuration option, allow msys mingw32 users to

build from svn without extra dependencies.

9. Add export files to each library in order to export only required symbols.

Windows native build may use these files instead of scanning objects' symbols.

10. Add opensc-tool --info to display some general information about the build.
11. Create compatibility library to be linked against library instread of recompiling the

same source files in different places.

12. Add different win32 version resource to each class of outputs.
13. Make xsl-stylesheets location selectable.
14. Some win32 fixups.
15. Some warning fixups.
16. Many other autoconf/automake cleanups.

Alon Bar-Lev

svn diff -r 3315:3399 https://www.opensc-project.org/svn/opensc/branches/alonbl/mingw

_M .
D configure.in
_M src
_M src/openssh
M src/openssh/Makefile.am
_M src/tools
M src/tools/rutoken-tool.c
M src/tools/opensc-tool.c
M src/tools/cardos-info.c
M src/tools/pkcs15-crypt.c
M src/tools/pkcs15-init.c
M src/tools/piv-tool.c
M src/tools/netkey-tool.c
M src/tools/eidenv.c
M src/tools/cryptoflex-tool.c
M src/tools/util.c
M src/tools/pkcs11-tool.c
M src/tools/pkcs15-tool.c
M src/tools/util.h
M src/tools/opensc-explorer.c
M src/tools/Makefile.am
_M src/pkcs11
M src/pkcs11/pkcs11-global.c
M src/pkcs11/framework-pkcs15.c
M src/pkcs11/mechanism.c
M src/pkcs11/pkcs11-display.c
M src/pkcs11/pkcs11-object.c
A src/pkcs11/opensc-pkcs11.exports
M src/pkcs11/sc-pkcs11.h
M src/pkcs11/pkcs11-spy.c
M src/pkcs11/openssl.c
M src/pkcs11/Makefile.am
A src/pkcs11/pkcs11-spy.exports
_M src/tests
_M src/tests/regression
M src/tests/regression/Makefile.am
M src/tests/sc-test.c
M src/tests/pintest.c
M src/tests/Makefile.am
_M src/include
_M src/include/opensc
M src/include/opensc/Makefile.am
A src/include/opensc/svnignore
M src/include/Makefile.am
_M src/signer
_M src/signer/npinclude
M src/signer/npinclude/Makefile.am
M src/signer/Makefile.am
A src/signer/signer.exports
_M src/common
A src/common/compat_dummy.c
D src/common/getopt.txt
D src/common/strlcpy.c
D src/common/LICENSE
A src/common/compat_getopt.txt
A src/common/compat_strlcpy.c
A src/common/LICENSE.compat_getopt
A src/common/compat_getopt.c
D src/common/strlcpy.h
D src/common/ChangeLog
D src/common/getpass.c
D src/common/my_getopt.c
A src/common/compat_strlcpy.h
A src/common/compat_getpass.c
A src/common/compat_getopt.h
A src/common/ChangeLog.compat_getopt
D src/common/README.strlcpy
D src/common/my_getopt.h
A src/common/compat_getpass.h
A src/common/README.compat_strlcpy
D src/common/strlcpy.3
A src/common/README.compat_getopt
D src/common/getopt.3
D src/common/README.my_getopt
A src/common/compat_strlcpy.3
A src/common/compat_getopt.3
M src/common/Makefile.am
M src/Makefile.am
_M src/pkcs15init
M src/pkcs15init/pkcs15-oberthur.c
M src/pkcs15init/profile.c
M src/pkcs15init/pkcs15-lib.c
M src/pkcs15init/pkcs15-rutoken.c
A src/pkcs15init/pkcs15init.exports
M src/pkcs15init/pkcs15-gpk.c
M src/pkcs15init/Makefile.am
_M src/scconf
M src/scconf/Makefile.am
M src/scconf/parse.c
A src/scconf/scconf.exports
_M src/libopensc
M src/libopensc/card-rutoken.c
M src/libopensc/compression.c
M src/libopensc/sc.c
M src/libopensc/card-piv.c
M src/libopensc/pkcs15-openpgp.c
M src/libopensc/pkcs15-postecert.c
M src/libopensc/pkcs15-tcos.c
M src/libopensc/opensc-config.in
M src/libopensc/reader-pcsc.c
A src/libopensc/internal-winscard.h
M src/libopensc/ctx.c
A src/libopensc/libopensc.exports
M src/libopensc/pkcs15-piv.c
M src/libopensc/pkcs15-infocamere.c
M src/libopensc/internal.h
M src/libopensc/pkcs15-actalis.c
M src/libopensc/pkcs15-starcert.c
M src/libopensc/card-oberthur.c
M src/libopensc/pkcs15-atrust-acos.c
M src/libopensc/p15card-helper.c
D src/libopensc/part10.h
M src/libopensc/ui.c
M src/libopensc/card-gpk.c
M src/libopensc/pkcs15-wrap.c
M src/libopensc/pkcs15-gemsafeGPK.c
M src/libopensc/log.c
M src/libopensc/pkcs15-esteid.c
M src/libopensc/pkcs15-prkey-rutoken.c
M src/libopensc/log.h
M src/libopensc/Makefile.am
M src/libopensc/reader-openct.c
_M aclocal
M aclocal/Makefile.am
_M win32
M win32/Makefile.am
A win32/versioninfo.rc.in
A win32/ltrc.inc
A configure.ac
_M doc
_M doc/tools
M doc/tools/pkcs15-profile.xml
D doc/changelog.sh
D doc/export-wiki.xsl
_M doc/api
_M doc/api/file
M doc/api/man.xsl
_M doc/api/asn1
_M doc/api/apps
_M doc/api/init
_M doc/api/types
_M doc/api/card
M doc/api/html.xsl
_M doc/api/misc
_M doc/api/util
M doc/Makefile.am
D doc/export-wiki.sh
AM doc/nonpersistent
A doc/nonpersistent/export-wiki.xsl
A doc/nonpersistent/Makefile.am
A doc/nonpersistent/export-wiki.sh
A doc/nonpersistent/svn2cl.xsl
D doc/generate-man.sh
D doc/svn2cl.xsl
M Makefile.am
A svnignore
_M etc
M etc/opensc.conf.in
M etc/Makefile.am
D man
_M solaris
M solaris/Makefile

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * log.c: Miscellaneous logging functions
3 *
4 * Copyright (C) 2001, 2002  Juha YrjölÀ <juha.yrjola@iki.fi>
5 * Copyright (C) 2003  Antti Tapaninen <aet@cc.hut.fi>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
21
22#include "internal.h"
23#include <stdarg.h>
24#include <stdlib.h>
25#include <assert.h>
26#include <ctype.h>
27#include <string.h>
28#ifdef HAVE_UNISTD_H
29#include <unistd.h>
30#endif
31#ifdef HAVE_SYS_TIME_H
32#include <sys/time.h>
33#endif
34#ifdef HAVE_IO_H
35#include <io.h>
36#endif
37
38/* Although not used, we need this for consistent exports */
39void _sc_error(sc_context_t *ctx, const char *format, ...)
40{
41        va_list ap;
42
43        va_start(ap, format);
44        sc_do_log_va(ctx, SC_LOG_TYPE_ERROR, NULL, 0, NULL, format, ap);
45        va_end(ap);
46}
47
48/* Although not used, we need this for consistent exports */
49void _sc_debug(sc_context_t *ctx, const char *format, ...)
50{
51        va_list ap;
52
53        va_start(ap, format);
54        sc_do_log_va(ctx, SC_LOG_TYPE_DEBUG, NULL, 0, NULL, format, ap);
55        va_end(ap);
56}
57
58void sc_do_log(sc_context_t *ctx, int type, const char *file, int line, const char *func, const char *format, ...)
59{
60        va_list ap;
61
62        va_start(ap, format);
63        sc_do_log_va(ctx, type, file, line, func, format, ap);
64        va_end(ap);
65}
66
67void sc_do_log_va(sc_context_t *ctx, int type, const char *file, int line, const char *func, const char *format, va_list args)
68{
69        int     (*display_fn)(sc_context_t *, const char *);
70        char    buf[1836], *p;
71        const char *tag = "";
72        int     r;
73        size_t  left;
74
75        assert(ctx != NULL);
76
77        switch (type) {
78        case SC_LOG_TYPE_ERROR:
79                if (!ctx->suppress_errors) {
80                        display_fn = &sc_ui_display_error;
81                        tag = "error:";
82                        break;
83                }
84                /* Fall thru - suppressed errors are logged as
85                 * debug messages */
86                tag = "error (suppressed):";
87                type = SC_LOG_TYPE_DEBUG;
88
89        case SC_LOG_TYPE_DEBUG:
90                if (ctx->debug == 0)
91                        return;
92                display_fn = &sc_ui_display_debug;
93                break;
94
95        default:
96                return;
97        }
98
99        if (file != NULL) {
100                r = snprintf(buf, sizeof(buf), "[%s] %s:%d:%s: ",
101                        ctx->app_name, file, line, func ? func : "");
102                if (r < 0 || (unsigned int)r > sizeof(buf))
103                        return;
104        } else {
105                r = 0;
106        }
107        p = buf + r;
108        left = sizeof(buf) - r;
109
110        r = vsnprintf(p, left, format, args);
111        if (r < 0)
112                return;
113        p += r;
114        left -= r;
115
116        display_fn(ctx, buf);
117}
118
119void sc_hex_dump(sc_context_t *ctx, const u8 * in, size_t count, char *buf, size_t len)
120{
121        char *p = buf;
122        int lines = 0;
123
124        assert(buf != NULL && in != NULL);
125        buf[0] = 0;
126        if ((count * 5) > len)
127                return;
128        while (count) {
129                char ascbuf[17];
130                size_t i;
131
132                for (i = 0; i < count && i < 16; i++) {
133                        sprintf(p, "%02X ", *in);
134                        if (isprint(*in))
135                                ascbuf[i] = *in;
136                        else
137                                ascbuf[i] = '.';
138                        p += 3;
139                        in++;
140                }
141                count -= i;
142                ascbuf[i] = 0;
143                for (; i < 16 && lines; i++) {
144                        strcat(p, "   ");
145                        p += 3;
146                }
147                strcat(p, ascbuf);
148                p += strlen(p);
149                sprintf(p, "\n");
150                p++;
151                lines++;
152        }
153}
Note: See TracBrowser for help on using the browser.