+
+ log->fp = fopen(log->filename, "a+");
+ if (!log->fp)
+ SILC_LOG_WARNING(("Couldn't reset log file '%s' for type '%s': %s",
+ log->filename, log->typename, strerror(errno)));
+}
+
+/* Reset all log files */
+
+void silc_log_reset_all(void)
+{
+ SilcLog log;
+ log = silc_log_get_context(SILC_LOG_INFO);
+ if (log->fp)
+ silc_log_reset(log);
+ log = silc_log_get_context(SILC_LOG_WARNING);
+ if (log->fp)
+ silc_log_reset(log);
+ log = silc_log_get_context(SILC_LOG_ERROR);
+ if (log->fp)
+ silc_log_reset(log);
+ log = silc_log_get_context(SILC_LOG_FATAL);
+ if (log->fp)
+ silc_log_reset(log);
+ silc_log_flush_all();
+}
+
+/* Sets debug callbacks */
+
+void silc_log_set_debug_callbacks(SilcLogDebugCb debug_cb,
+ void *debug_context,
+ SilcLogHexdumpCb hexdump_cb,
+ void *hexdump_context)
+{
+ silclog.debug_cb = debug_cb;
+ silclog.debug_context = debug_context;
+ silclog.hexdump_cb = hexdump_cb;
+ silclog.hexdump_context = hexdump_context;
+}
+
+/* Resets debug callbacks */
+
+void silc_log_reset_debug_callbacks()
+{
+ silclog.debug_cb = NULL;
+ silclog.debug_context = NULL;
+ silclog.hexdump_cb = NULL;
+ silclog.hexdump_context = NULL;
+}
+
+/* Set current debug string */
+
+void silc_log_set_debug_string(const char *debug_string)
+{
+ char *string;
+ int len;
+ if ((strchr(debug_string, '(') && strchr(debug_string, ')')) ||
+ strchr(debug_string, '$'))
+ string = strdup(debug_string);
+ else
+ string = silc_string_regexify(debug_string);
+ len = strlen(string);
+ if (len >= sizeof(silclog.debug_string))
+ len = sizeof(silclog.debug_string) - 1;
+ memset(silclog.debug_string, 0, sizeof(silclog.debug_string));
+ strncpy(silclog.debug_string, string, len);
+ silc_free(string);
+}
+
+/* Set timestamp */
+
+void silc_log_timestamp(SilcBool enable)
+{
+ silclog.timestamp = enable;
+}
+
+/* Set flushdelay */
+
+void silc_log_flushdelay(SilcUInt32 flushdelay)
+{
+ silclog.flushdelay = flushdelay;
+}
+
+/* Set quick logging */
+
+void silc_log_quick(SilcBool enable)
+{
+ silclog.quick = enable;
+}
+
+/* Set debugging */
+
+void silc_log_debug(SilcBool enable)
+{
+ silclog.debug = enable;
+}
+
+/* Set debug hexdump */
+
+void silc_log_debug_hexdump(SilcBool enable)
+{
+ silclog.debug_hexdump = enable;
+}
+
+/* Outputs the debug message to stderr. */
+
+void silc_log_output_debug(char *file, const char *function,
+ int line, char *string)
+{
+ if (!silclog.debug)
+ goto end;
+
+ if (!silc_string_regex_match(silclog.debug_string, file) &&
+ !silc_string_regex_match(silclog.debug_string, function))
+ goto end;
+
+ if (silclog.debug_cb) {
+ if ((*silclog.debug_cb)(file, (char *)function, line, string,
+ silclog.debug_context))
+ goto end;