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
22 #define IMCV_DEBUG_LEVEL 1
25 * Reference count for IMC/IMV instances
30 * Global configuration of imcv dbg function
32 static int imcv_debug_level
;
33 static bool imcv_stderr_quiet
;
38 static void imcv_dbg(debug_t group
, level_t level
, char *fmt
, ...)
40 int priority
= LOG_INFO
;
42 char *current
= buffer
, *next
;
45 if (level
<= imcv_debug_level
)
47 if (!imcv_stderr_quiet
)
50 fprintf(stderr
, "[HSR] ");
51 vfprintf(stderr
, fmt
, args
);
52 fprintf(stderr
, "\n");
56 /* write in memory buffer first */
58 vsnprintf(buffer
, sizeof(buffer
), fmt
, args
);
61 /* do a syslog with every line */
64 next
= strchr(current
, '\n');
69 syslog(priority
, "[HSR] %s\n", current
);
76 * Described in header.
78 bool libimcv_init(void)
80 /* initialize libstrongswan library only once */
83 /* did main program initialize libstrongswan? */
91 /* we are the first to initialize libstrongswan */
92 if (!library_init(NULL
))
97 if (!lib
->plugins
->load(lib
->plugins
, NULL
, "random"))
103 /* set the debug level and stderr output */
104 imcv_debug_level
= lib
->settings
->get_int(lib
->settings
,
105 "libimcv.debug_level", IMCV_DEBUG_LEVEL
);
106 imcv_stderr_quiet
= lib
->settings
->get_int(lib
->settings
,
107 "libimcv.stderr_quiet", FALSE
);
109 /* activate the imcv debugging hook */
111 openlog("imcv", 0, LOG_DAEMON
);
113 DBG1(DBG_LIB
, "libimcv initialized");
121 * Described in header.
123 void libimcv_deinit(void)
127 DBG1(DBG_LIB
, "libimcv terminated");