check if optional terminate() function exists
[strongswan.git] / src / libcharon / plugins / tnc_imc / tnc_imc_plugin.c
index 43ba844..21cca66 100644 (file)
  */
 
 #include "tnc_imc_plugin.h"
-
-#include <libtnctncc.h>
+#include "tnc_imc.h"
 
 #include <daemon.h>
 
 METHOD(plugin_t, destroy, void,
        tnc_imc_plugin_t *this)
 {
-       libtnc_tncc_Terminate();
+       imc_t *imc;
+
+       while (charon->imcs->remove_last(charon->imcs, (void**)&imc) == SUCCESS)
+       {
+               if (imc->terminate &&
+                       imc->terminate(imc->get_id(imc)) != TNC_RESULT_SUCCESS)
+               {
+                       DBG1(DBG_TNC, "IMC '%s' not terminated successfully",
+                                                  imc->get_name(imc));
+               }
+               imc->destroy(imc);
+       }
        free(this);
 }
 
@@ -31,9 +41,11 @@ METHOD(plugin_t, destroy, void,
  */
 plugin_t *tnc_imc_plugin_create()
 {
-       char *tnc_config, *pref_lang;
-       int imc_count;
+       TNC_IMCID next_id = 1;
+       TNC_Version version;
+       char *tnc_config, *pref_lang, *name, *filename;
        tnc_imc_plugin_t *this;
+       imc_t *imc;
 
        INIT(this,
                .plugin = {
@@ -46,20 +58,25 @@ plugin_t *tnc_imc_plugin_create()
        tnc_config = lib->settings->get_str(lib->settings,
                                        "charon.plugins.tnc-imc.tnc_config", "/etc/tnc_config");
 
-       imc_count = libtnc_imc_load_config(tnc_config);
-       if (imc_count < 0)
+       name = "Dummy";
+       filename = "/usr/local/lib/libdummyimc.so";
+       imc = tnc_imc_create(name, filename, next_id);
+       if (imc)
        {
-               free(this);
-               DBG1(DBG_IKE, "TNC IMC initialization failed");
-               return NULL;
+               /* Initialize the module */
+               if (imc->initialize(next_id, TNC_IFIMC_VERSION_1, TNC_IFIMC_VERSION_1,
+                                                       &version) != TNC_RESULT_SUCCESS)
+               {
+                       DBG1(DBG_TNC, "could not initialize IMC '%s'\n",
+                                                  imc->get_name(imc));
+                       imc->destroy(imc);
+               }
+               else
+               {
+                       charon->imcs->insert_last(charon->imcs, imc);
+                       next_id++;
+               }
        }
-       else
-       {
-               DBG1(DBG_IKE, "loaded %d TNC IMC%s", imc_count,
-                                                                                       (imc_count == 1) ? "":"s");
-               libtnc_tncc_PreferredLanguage(pref_lang);
-       }
-
        return &this->plugin;
 }