time values in strongswan.conf can be optionally specified in days (d), hours (h...
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 4 Sep 2008 16:19:46 +0000 (16:19 -0000)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 4 Sep 2008 16:19:46 +0000 (16:19 -0000)
src/charon/plugins/medcli/medcli_config.c
src/charon/plugins/medsrv/medsrv_config.c
src/charon/sa/ike_sa.c
src/libstrongswan/settings.c
src/libstrongswan/settings.h
src/manager/main.c
src/medsrv/main.c

index 05699f7..d1e6c0c 100644 (file)
@@ -354,9 +354,8 @@ medcli_config_t *medcli_config_create(database_t *db)
        this->public.destroy = (void(*)(medcli_config_t*))destroy;
        
        this->db = db;
-       this->rekey = lib->settings->get_int(lib->settings,
-                                                                                "medcli.rekey", 20) * 60;
-       this->dpd = lib->settings->get_int(lib->settings, "medcli.dpd", 300);
+       this->rekey = lib->settings->get_time(lib->settings, "medcli.rekey", 1200);
+       this->dpd = lib->settings->get_time(lib->settings, "medcli.dpd", 300);
        this->ike = ike_cfg_create(FALSE, FALSE, "0.0.0.0", "0.0.0.0");
        this->ike->add_proposal(this->ike, proposal_create_default(PROTO_IKE));
        
index 4cea6b7..bec6837 100644 (file)
@@ -135,9 +135,8 @@ medsrv_config_t *medsrv_config_create(database_t *db)
        this->public.destroy = (void(*)(medsrv_config_t*))destroy;
        
        this->db = db;
-       this->rekey = lib->settings->get_int(lib->settings,
-                                                                                "medsrv.rekey", 20) * 60;
-       this->dpd = lib->settings->get_int(lib->settings, "medsrv.dpd", 300);
+       this->rekey = lib->settings->get_time(lib->settings, "medsrv.rekey", 1200);
+       this->dpd = lib->settings->get_time(lib->settings, "medsrv.dpd", 300);
        this->ike = ike_cfg_create(FALSE, FALSE, "0.0.0.0", "0.0.0.0");
        this->ike->add_proposal(this->ike, proposal_create_default(PROTO_IKE));
        
index e116ebb..4151127 100644 (file)
@@ -2621,7 +2621,7 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
        this->skp_build = chunk_empty;
        this->child_prf = NULL;
        this->state = IKE_CREATED;
-       this->keepalive_interval = lib->settings->get_int(lib->settings,
+       this->keepalive_interval = lib->settings->get_time(lib->settings,
                                                                        "charon.keep_alive", KEEPALIVE_INTERVAL);
        this->time.inbound = this->time.outbound = time(NULL);
        this->time.established = 0;
index 7c87dcc..6f9e403 100644 (file)
@@ -203,8 +203,44 @@ static int get_int(private_settings_t *this, char *key, int def)
 }
 
 /**
- * destry a section
-*/
+ * Implementation of settings_t.get_time.
+ */
+static u_int32_t get_time(private_settings_t *this, char *key, u_int32_t def)
+{
+       char *value, *endptr;
+       u_int32_t timeval;
+       
+       value = find(this->top, key);
+       if (value)
+       {
+               errno = 0;
+               timeval = strtol(value, &endptr, 10);
+               if (errno == 0 && timeval >= 0)
+               {
+                       switch (*endptr)
+                       {
+                               case 'd':               /* time in days */
+                                       timeval *= 24 * 3600;
+                                       break;
+                               case 'h':               /* time in hours */
+                                       timeval *= 3600;
+                                       break;
+                               case 'm':               /* time in minutes */
+                                       timeval *= 60;
+                                       break;
+                               case 's':               /* time in seconds */
+                                       default:
+                                       break;
+                       }
+                       return timeval;
+               }
+       }
+       return def;
+}
+
+/**
+ * destroy a section
+ */
 static void section_destroy(section_t *this)
 {
        this->kv->destroy_function(this->kv, free);
@@ -365,7 +401,8 @@ settings_t *settings_create(char *file)
        private_settings_t *this = malloc_thing(private_settings_t);
        
        this->public.get_str = (char*(*)(settings_t*, char *key, char* def))get_str;
-       this->public.get_int = (int(*)(settings_t*, char *key, bool def))get_int;
+       this->public.get_int = (int(*)(settings_t*, char *key, int def))get_int;
+       this->public.get_time = (u_int32_t(*)(settings_t*, char *key, u_int32_t def))get_time;
        this->public.get_bool = (bool(*)(settings_t*, char *key, bool def))get_bool;
        this->public.destroy = (void(*)(settings_t*))destroy;
        
index 9177097..451c2a5 100644 (file)
@@ -80,9 +80,18 @@ struct settings_t {
         * @param def           default value to return if key not found
         * @return                      value of the key
         */
-       int (*get_int)(settings_t *this, char *key, bool def);
+       int (*get_int)(settings_t *this, char *key, int def);
        
        /**
+        * Get a time value.
+        *
+        * @param key           key including sections
+        * @param def           default value to return if key not found
+        * @return                      value of the key
+        */
+       u_int32_t (*get_time)(settings_t *this, char *key, u_int32_t def);
+
+       /**
      * Destroy a settings instance.
      */
     void (*destroy)(settings_t *this);
index cfecc71..b1b4e16 100644 (file)
@@ -42,7 +42,7 @@ int main (int arc, char *argv[])
        
        socket = lib->settings->get_str(lib->settings, "manager.socket", NULL);
        debug = lib->settings->get_bool(lib->settings, "manager.debug", FALSE);
-       timeout = lib->settings->get_int(lib->settings, "manager.timeout", 900);
+       timeout = lib->settings->get_time(lib->settings, "manager.timeout", 900);
        threads = lib->settings->get_int(lib->settings, "manager.threads", 10);
        database = lib->settings->get_str(lib->settings, "manager.database", NULL);
        if (!database)
index 00975e9..1f7b675 100644 (file)
@@ -41,7 +41,7 @@ int main(int arc, char *argv[])
        
        socket = lib->settings->get_str(lib->settings, "medsrv.socket", NULL);
        debug = lib->settings->get_bool(lib->settings, "medsrv.debug", FALSE);
-       timeout = lib->settings->get_int(lib->settings, "medsrv.timeout", 900);
+       timeout = lib->settings->get_time(lib->settings, "medsrv.timeout", 900);
        threads = lib->settings->get_int(lib->settings, "medsrv.threads", 5);
        uri = lib->settings->get_str(lib->settings, "medsrv.database", NULL);
        if (uri == NULL)