summaryrefslogtreecommitdiffstats
path: root/common/eurephia_log.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/eurephia_log.c')
-rw-r--r--common/eurephia_log.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/common/eurephia_log.c b/common/eurephia_log.c
index 8063321..a25964d 100644
--- a/common/eurephia_log.c
+++ b/common/eurephia_log.c
@@ -1,6 +1,6 @@
/* eurephia_log.c -- eurephia logging
*
- * GPLv2 only - Copyright (C) 2008 - 2012
+ * GPLv2 only - Copyright (C) 2008 - 2013
* David Sommerseth <dazo@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or
@@ -86,6 +86,20 @@ static const int syslog_priority[] = {
/**
+ * Mapping table for eurephia log types to OpenVPN's plug-in v3 log API
+ */
+static const int openvpnlog_flags[] = {
+ -1,
+ PLOG_NOTE, /**< LOG_INFO */
+ PLOG_DEBUG, /**< LOG_DEBUG */
+ PLOG_WARN, /**< LOG_WARNING */
+ PLOG_ERR, /**< LOG_ERROR */
+ PLOG_ERR | PLOG_NOMUTE, /**< LOG_CRITICAL */
+ PLOG_ERR | PLOG_NOMUTE, /**< LOG_FATAL */
+ PLOG_ERR | PLOG_NOMUTE /**< LOG_PANIC */
+};
+
+/**
* Converts eurephiaLOGTYPE value to a string
*
* @param lt eurephiaLOGTYPE, must be either logFILE or logSYSLOG
@@ -98,6 +112,8 @@ static inline const char *logtype_str(eurephiaLOGTYPE lt) {
return "file\0";
case logSYSLOG:
return "syslog\0";
+ case logOPENVPN:
+ return "openvpn::plugin_vlog\0";
}
return NULL;
}
@@ -229,6 +245,9 @@ void _veurephia_log_func(eurephiaCTX *ctx, int logdst, int loglvl, const char *f
case logSYSLOG:
vsyslog(syslog_priority[logdst], fmt, ap);
break;
+ case logOPENVPN:
+ ctx->log->ovpn_log(openvpnlog_flags[logdst], "eurephia", fmt, ap);
+ break;
}
}
}
@@ -260,6 +279,9 @@ void eurephia_log_close(eurephiaCTX *ctx) {
case logSYSLOG:
closelog();
break;
+ case logOPENVPN:
+ // The OpenVPN plug-in v3 log API does not need to close the log
+ break;
}
ctx->log->opened = 0;
}
@@ -281,7 +303,8 @@ void eurephia_log_close(eurephiaCTX *ctx) {
*
* @return Returns 1 on success, otherwise 0;
*/
-int eurephia_log_init(eurephiaCTX *ctx, const char *ident, const char *dest, int loglevel) {
+int eurephia_log_init(eurephiaCTX *ctx, const char *ident, const char *dest,
+ int loglevel, plugin_vlog_t plglog_fnc) {
assert( (ctx != NULL) && (dest != NULL) );
@@ -294,11 +317,14 @@ int eurephia_log_init(eurephiaCTX *ctx, const char *ident, const char *dest, int
if( strncmp(dest, "syslog:", 7) == 0 ) {
ctx->log->logtype = logSYSLOG;
ctx->log->destination = strdup(dest+7);
+ } else if( strcmp(dest, "openvpn:") == 0 ) {
+ ctx->log->logtype = logOPENVPN;
+ ctx->log->ovpn_log = plglog_fnc;
} else {
ctx->log->logtype = logFILE;
ctx->log->destination = strdup(dest);
}
- if( ctx->log->destination == NULL) {
+ if( (ctx->log->destination == NULL) && (ctx->log->logtype != logOPENVPN) ) {
free_nullsafe(ctx, ctx->log);
return 0;
}
@@ -326,6 +352,10 @@ int eurephia_log_init(eurephiaCTX *ctx, const char *ident, const char *dest, int
case logSYSLOG: // Open syslog
openlog(ident, LOG_PID, syslog_logdest(ctx->log->destination));
break;
+
+ case logOPENVPN:
+ // Logging via OpenVPN's log function do not require any init
+ break;
}
ctx->log->opened = 1;
eurephia_log(ctx, LOG_INFO, 1, "Logging to %s (%s) started",