2 * Copyright (C) 2011 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * Reference count for IMC/IMV instances
28 * Global configuration of libimcv dbg function
30 static int debug_level
= 3;
31 static bool stderr_quiet
= FALSE
;
34 * libimvc dbg function
36 static void libimcv_dbg(debug_t group
, level_t level
, char *fmt
, ...)
38 int priority
= LOG_INFO
;
40 char *current
= buffer
, *next
;
43 if (level
<= debug_level
)
48 vfprintf(stderr
, fmt
, args
);
49 fprintf(stderr
, "\n");
53 /* write in memory buffer first */
55 vsnprintf(buffer
, sizeof(buffer
), fmt
, args
);
58 /* do a syslog with every line */
61 next
= strchr(current
, '\n');
66 syslog(priority
, "%s\n", current
);
73 * Described in header.
75 bool libimcv_init(void)
77 /* initialize libstrongswan library only once */
80 /* did main program initialize libstrongswan? */
88 /* we are the first to initialize libstrongswan */
89 if (!library_init(NULL
))
94 if (!lib
->plugins
->load(lib
->plugins
, NULL
, "random"))
100 /* enable libimcv debugging hook */
102 openlog("imcv", 0, LOG_DAEMON
);
104 DBG1(DBG_LIB
, "libimcv initialized");
112 * Described in header.
114 void libimcv_deinit(void)
118 DBG1(DBG_LIB
, "libimcv terminated");