systime-fix: Use plugin features to register validator
authorTobias Brunner <tobias@strongswan.org>
Sat, 8 Jun 2013 08:34:31 +0000 (10:34 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 11 Jun 2013 09:18:19 +0000 (11:18 +0200)
src/libcharon/plugins/systime_fix/systime_fix_plugin.c

index 7727ba0..c859611 100644 (file)
@@ -1,4 +1,7 @@
 /*
+ * Copyright (C) 2013 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
  * Copyright (C) 2013 Martin Willi
  * Copyright (C) 2013 revosec AG
  *
@@ -68,17 +71,6 @@ METHOD(plugin_t, get_name, char*,
        return "systime-fix";
 }
 
-METHOD(plugin_t, destroy, void,
-       private_systime_fix_plugin_t *this)
-{
-       if (this->validator)
-       {
-               lib->credmgr->remove_validator(lib->credmgr, &this->validator->validator);
-               this->validator->destroy(this->validator);
-       }
-       free(this);
-}
-
 /**
  * Check if all certificates associated to an IKE_SA have valid lifetimes
  */
@@ -215,11 +207,57 @@ static bool load_validator(private_systime_fix_plugin_t *this)
 
        DBG1(DBG_CFG, "enabling %s, threshold: %s", get_name(this), asctime(&tm));
        this->validator = systime_fix_validator_create(this->threshold);
-       lib->credmgr->add_validator(lib->credmgr, &this->validator->validator);
+       return TRUE;
+}
 
+/**
+ * Load validator
+ */
+static bool plugin_cb(private_systime_fix_plugin_t *this,
+                                         plugin_feature_t *feature, bool reg, void *cb_data)
+{
+       if (reg)
+       {
+               if (!load_validator(this))
+               {
+                       return FALSE;
+               }
+               lib->credmgr->add_validator(lib->credmgr, &this->validator->validator);
+               if (this->interval != 0)
+               {
+                       DBG1(DBG_CFG, "starting systime check, interval: %ds",
+                                this->interval);
+                       lib->scheduler->schedule_job(lib->scheduler, (job_t*)
+                                       callback_job_create((callback_job_cb_t)check_systime,
+                                                                               this, NULL, NULL), this->interval);
+               }
+       }
+       else
+       {
+               lib->credmgr->remove_validator(lib->credmgr,
+                                                                          &this->validator->validator);
+               this->validator->destroy(this->validator);
+       }
        return TRUE;
 }
 
+METHOD(plugin_t, get_features, int,
+       private_systime_fix_plugin_t *this, plugin_feature_t *features[])
+{
+       static plugin_feature_t f[] = {
+               PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
+                       PLUGIN_PROVIDE(CUSTOM, "systime-fix"),
+       };
+       *features = f;
+       return countof(f);
+}
+
+METHOD(plugin_t, destroy, void,
+       private_systime_fix_plugin_t *this)
+{
+       free(this);
+}
+
 /**
  * Plugin constructor
  */
@@ -231,7 +269,7 @@ plugin_t *systime_fix_plugin_create()
                .public = {
                        .plugin = {
                                .get_name = _get_name,
-                               .reload = (void*)return_false,
+                               .get_features = _get_features,
                                .destroy = _destroy,
                        },
                },
@@ -241,16 +279,5 @@ plugin_t *systime_fix_plugin_create()
                                "%s.plugins.%s.reauth", FALSE, charon->name, get_name(this)),
        );
 
-       if (load_validator(this))
-       {
-               if (this->interval != 0)
-               {
-                       DBG1(DBG_CFG, "starting systime check, interval: %ds",
-                                this->interval);
-                       lib->scheduler->schedule_job(lib->scheduler, (job_t*)
-                                       callback_job_create((callback_job_cb_t)check_systime, this,
-                                                                               NULL, NULL), this->interval);
-               }
-       }
        return &this->public.plugin;
 }