Added socket plugin feature loading callback
authorMartin Willi <martin@revosec.ch>
Thu, 13 Oct 2011 09:41:16 +0000 (11:41 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 14 Oct 2011 08:05:48 +0000 (10:05 +0200)
src/libcharon/Makefile.am
src/libcharon/network/socket.c [new file with mode: 0644]
src/libcharon/network/socket.h

index 7b46186..371c787 100644 (file)
@@ -39,10 +39,9 @@ encoding/payloads/ts_payload.c encoding/payloads/ts_payload.h \
 encoding/payloads/unknown_payload.c encoding/payloads/unknown_payload.h \
 encoding/payloads/vendor_id_payload.c encoding/payloads/vendor_id_payload.h \
 kernel/kernel_handler.c kernel/kernel_handler.h \
-network/packet.c network/packet.h \
-network/receiver.c network/receiver.h \
-network/sender.c network/sender.h \
-network/socket_manager.c network/socket_manager.h network/socket.h \
+network/receiver.c network/receiver.h network/sender.c network/sender.h \
+network/packet.c network/packet.h network/socket.c network/socket.h \
+network/socket_manager.c network/socket_manager.h \
 processing/jobs/acquire_job.c processing/jobs/acquire_job.h \
 processing/jobs/delete_child_sa_job.c processing/jobs/delete_child_sa_job.h \
 processing/jobs/delete_ike_sa_job.c processing/jobs/delete_ike_sa_job.h \
diff --git a/src/libcharon/network/socket.c b/src/libcharon/network/socket.c
new file mode 100644 (file)
index 0000000..cdb14b4
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2011 Martin Willi
+ * Copyright (C) 2011 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 "socket.h"
+
+#include <daemon.h>
+
+/**
+ * See header
+ */
+bool socket_register(plugin_t *plugin, plugin_feature_t *feature,
+                                        bool reg, void *data)
+{
+       if (reg)
+       {
+               charon->socket->add_socket(charon->socket, (socket_constructor_t)data);
+       }
+       else
+       {
+               charon->socket->remove_socket(charon->socket,
+                                                                         (socket_constructor_t)data);
+       }
+       return TRUE;
+}
index 51b2692..be87503 100644 (file)
@@ -29,6 +29,7 @@ typedef struct socket_t socket_t;
 #include <library.h>
 #include <network/packet.h>
 #include <utils/enumerator.h>
+#include <plugins/plugin.h>
 
 /**
  * Constructor prototype for sockets.
@@ -72,4 +73,18 @@ struct socket_t {
        void (*destroy) (socket_t *this);
 };
 
+/**
+ * Helper function to (un-)register socket interfaces from plugin features.
+ *
+ * This function is a plugin_feature_callback_t and can be used with the
+ * PLUGIN_CALLBACK macro to register an socket interface constructor.
+ *
+ * @param plugin               plugin registering the socket interface
+ * @param feature              associated plugin feature
+ * @param reg                  TRUE to register, FALSE to unregister
+ * @param data                 data passed to callback, a socket_constructor_t
+ */
+bool socket_register(plugin_t *plugin, plugin_feature_t *feature,
+                                        bool reg, void *data);
+
 #endif /** SOCKET_H_ @}*/