aboutsummaryrefslogtreecommitdiffstats
path: root/src/frontends/osx/charon-xpc/xpc_logger.c
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2013-07-18 12:18:32 +0200
committerMartin Willi <martin@revosec.ch>2013-07-18 12:18:32 +0200
commit569d114de8cf8c35917e8c8720751c3ca32f9d47 (patch)
tree15be22d6ec8f7977bf905608610d1819300b4116 /src/frontends/osx/charon-xpc/xpc_logger.c
parent07a9d5c91a3bd88fbfe5a36a807655bebfef42ae (diff)
parentb9c47eae0668ea0c736bdbd1564631d82ab76763 (diff)
downloadstrongswan-569d114de8cf8c35917e8c8720751c3ca32f9d47.tar.bz2
strongswan-569d114de8cf8c35917e8c8720751c3ca32f9d47.tar.xz
Merge branch 'charon-xpc'
Implement a charon daemon controlled by the Apple specific XPC mechanism, acting as a backend for a yet to build unprivileged GUI. The keychain plugin coming with this merge provides certificates from the OS X keychain service.
Diffstat (limited to 'src/frontends/osx/charon-xpc/xpc_logger.c')
-rw-r--r--src/frontends/osx/charon-xpc/xpc_logger.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/frontends/osx/charon-xpc/xpc_logger.c b/src/frontends/osx/charon-xpc/xpc_logger.c
new file mode 100644
index 000000000..38c34e460
--- /dev/null
+++ b/src/frontends/osx/charon-xpc/xpc_logger.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2013 Martin Willi
+ * Copyright (C) 2013 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "xpc_logger.h"
+
+typedef struct private_xpc_logger_t private_xpc_logger_t;
+
+/**
+ * Private data of an xpc_logger_t object.
+ */
+struct private_xpc_logger_t {
+
+ /**
+ * Public xpc_logger_t interface.
+ */
+ xpc_logger_t public;
+
+ /**
+ * XPC channel to send logging messages to
+ */
+ xpc_connection_t conn;
+
+ /**
+ * IKE_SA we log for
+ */
+ u_int32_t ike_sa;
+};
+
+METHOD(logger_t, log_, void,
+ private_xpc_logger_t *this, debug_t group, level_t level, int thread,
+ ike_sa_t* ike_sa, const char *message)
+{
+ if (ike_sa && ike_sa->get_unique_id(ike_sa) == this->ike_sa)
+ {
+ xpc_object_t msg;
+
+ msg = xpc_dictionary_create(NULL, NULL, 0);
+ xpc_dictionary_set_string(msg, "type", "event");
+ xpc_dictionary_set_string(msg, "event", "log");
+ xpc_dictionary_set_string(msg, "message", message);
+ xpc_connection_send_message(this->conn, msg);
+ xpc_release(msg);
+ }
+}
+
+METHOD(logger_t, get_level, level_t,
+ private_xpc_logger_t *this, debug_t group)
+{
+ return LEVEL_CTRL;
+}
+
+METHOD(xpc_logger_t, set_ike_sa, void,
+ private_xpc_logger_t *this, u_int32_t ike_sa)
+{
+ this->ike_sa = ike_sa;
+}
+
+METHOD(xpc_logger_t, destroy, void,
+ private_xpc_logger_t *this)
+{
+ free(this);
+}
+
+/**
+ * See header
+ */
+xpc_logger_t *xpc_logger_create(xpc_connection_t conn)
+{
+ private_xpc_logger_t *this;
+
+ INIT(this,
+ .public = {
+ .logger = {
+ .log = _log_,
+ .get_level = _get_level,
+ },
+ .set_ike_sa = _set_ike_sa,
+ .destroy = _destroy,
+ },
+ .conn = conn,
+ );
+
+ return &this->public;
+}