diff options
Diffstat (limited to 'src/libcharon/plugins/tnc_imc/tnc_imc.c')
-rw-r--r-- | src/libcharon/plugins/tnc_imc/tnc_imc.c | 102 |
1 files changed, 69 insertions, 33 deletions
diff --git a/src/libcharon/plugins/tnc_imc/tnc_imc.c b/src/libcharon/plugins/tnc_imc/tnc_imc.c index a1f2d770f..9ac578401 100644 --- a/src/libcharon/plugins/tnc_imc/tnc_imc.c +++ b/src/libcharon/plugins/tnc_imc/tnc_imc.c @@ -20,9 +20,10 @@ #include <tncif_pa_subtypes.h> -#include <debug.h> +#include <utils/debug.h> +#include <daemon.h> #include <library.h> -#include <utils/linked_list.h> +#include <collections/linked_list.h> #include <threading/mutex.h> typedef struct private_tnc_imc_t private_tnc_imc_t; @@ -38,11 +39,6 @@ struct private_tnc_imc_t { imc_t public; /** - * Path of loaded IMC - */ - char *path; - - /** * Name of loaded IMC */ char *name; @@ -291,10 +287,10 @@ METHOD(imc_t, type_supported, bool, for (i = 0; i < this->type_count; i++) { - vid = this->supported_vids[i]; - subtype = this->supported_subtypes[i]; + vid = this->supported_vids[i]; + subtype = this->supported_subtypes[i]; - if ((vid == TNC_VENDORID_ANY && subtype == TNC_SUBTYPE_ANY) || + if ((vid == TNC_VENDORID_ANY && subtype == TNC_SUBTYPE_ANY) || (vid == msg_vid && (subtype == TNC_SUBTYPE_ANY || subtype == msg_subtype))) { @@ -307,20 +303,23 @@ METHOD(imc_t, type_supported, bool, METHOD(imc_t, destroy, void, private_tnc_imc_t *this) { - dlclose(this->handle); + if (this->handle && lib->settings->get_bool(lib->settings, + "%s.plugins.tnc-imc.dlclose", TRUE, charon->name)) + { + dlclose(this->handle); + } this->mutex->destroy(this->mutex); this->additional_ids->destroy(this->additional_ids); free(this->supported_vids); free(this->supported_subtypes); free(this->name); - free(this->path); free(this); } /** - * Described in header. + * Generic constructor */ -imc_t* tnc_imc_create(char *name, char *path) +static private_tnc_imc_t* tnc_imc_create_empty(char *name) { private_tnc_imc_t *this; @@ -335,59 +334,96 @@ imc_t* tnc_imc_create(char *name, char *path) .set_message_types_long = _set_message_types_long, .type_supported = _type_supported, .destroy = _destroy, - }, - .name = name, - .path = path, + }, + .name = strdup(name), .additional_ids = linked_list_create(), .mutex = mutex_create(MUTEX_TYPE_DEFAULT), ); + return this; +} + +/** + * See header + */ +imc_t* tnc_imc_create(char *name, char *path) +{ + private_tnc_imc_t *this; + + this = tnc_imc_create_empty(name); + this->handle = dlopen(path, RTLD_LAZY); if (!this->handle) { DBG1(DBG_TNC, "IMC \"%s\" failed to load: %s", name, dlerror()); - free(this); + destroy(this); return NULL; } this->public.initialize = dlsym(this->handle, "TNC_IMC_Initialize"); if (!this->public.initialize) - { + { DBG1(DBG_TNC, "could not resolve TNC_IMC_Initialize in %s: %s\n", path, dlerror()); - dlclose(this->handle); - free(this); + destroy(this); return NULL; } this->public.notify_connection_change = dlsym(this->handle, "TNC_IMC_NotifyConnectionChange"); - this->public.begin_handshake = dlsym(this->handle, "TNC_IMC_BeginHandshake"); + this->public.begin_handshake = dlsym(this->handle, "TNC_IMC_BeginHandshake"); if (!this->public.begin_handshake) - { + { DBG1(DBG_TNC, "could not resolve TNC_IMC_BeginHandshake in %s: %s\n", path, dlerror()); - dlclose(this->handle); - free(this); + destroy(this); return NULL; } - this->public.receive_message = + this->public.receive_message = dlsym(this->handle, "TNC_IMC_ReceiveMessage"); - this->public.receive_message_long = + this->public.receive_message_long = dlsym(this->handle, "TNC_IMC_ReceiveMessageLong"); - this->public.batch_ending = + this->public.batch_ending = dlsym(this->handle, "TNC_IMC_BatchEnding"); - this->public.terminate = + this->public.terminate = dlsym(this->handle, "TNC_IMC_Terminate"); - this->public.provide_bind_function = + this->public.provide_bind_function = dlsym(this->handle, "TNC_IMC_ProvideBindFunction"); - if (!this->public.provide_bind_function) + if (!this->public.provide_bind_function) { DBG1(DBG_TNC, "could not resolve TNC_IMC_ProvideBindFunction in %s: %s\n", path, dlerror()); - dlclose(this->handle); - free(this); + destroy(this); return NULL; } return &this->public; } + +/** + * See header + */ +imc_t* tnc_imc_create_from_functions(char *name, + TNC_IMC_InitializePointer initialize, + TNC_IMC_NotifyConnectionChangePointer notify_connection_change, + TNC_IMC_BeginHandshakePointer begin_handshake, + TNC_IMC_ReceiveMessagePointer receive_message, + TNC_IMC_ReceiveMessageLongPointer receive_message_long, + TNC_IMC_BatchEndingPointer batch_ending, + TNC_IMC_TerminatePointer terminate, + TNC_IMC_ProvideBindFunctionPointer provide_bind_function) +{ + private_tnc_imc_t *this; + + this = tnc_imc_create_empty(name); + + this->public.initialize = initialize; + this->public.notify_connection_change = notify_connection_change; + this->public.begin_handshake = begin_handshake; + this->public.receive_message = receive_message; + this->public.receive_message_long = receive_message_long; + this->public.batch_ending = batch_ending; + this->public.terminate = terminate; + this->public.provide_bind_function = provide_bind_function; + + return &this->public; +} |