]> git.ipfire.org Git - thirdparty/strongswan.git/blobdiff - src/libcharon/config/ike_cfg.c
ike-cfg: Pass arguments as struct
[thirdparty/strongswan.git] / src / libcharon / config / ike_cfg.c
index 93300781dc488b43062efcbb1d171c4a8aaae507..cb75b705433c7781cc6f25d71208f226072cbeb6 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * Copyright (C) 2012-2017 Tobias Brunner
+ * Copyright (C) 2012-2019 Tobias Brunner
  * Copyright (C) 2005-2007 Martin Willi
  * Copyright (C) 2005 Jan Hutter
- * Hochschule fuer Technik Rapperswil
+ * HSR Hochschule fuer Technik Rapperswil
  *
  * 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
@@ -309,6 +309,25 @@ METHOD(ike_cfg_t, get_proposals, linked_list_t*,
        return proposals;
 }
 
+METHOD(ike_cfg_t, has_proposal, bool,
+       private_ike_cfg_t *this, proposal_t *match, bool private)
+{
+       enumerator_t *enumerator;
+       proposal_t *proposal;
+
+       enumerator = this->proposals->create_enumerator(this->proposals);
+       while (enumerator->enumerate(enumerator, &proposal))
+       {
+               if (proposal->matches(proposal, match, private))
+               {
+                       enumerator->destroy(enumerator);
+                       return TRUE;
+               }
+       }
+       enumerator->destroy(enumerator);
+       return FALSE;
+}
+
 METHOD(ike_cfg_t, select_proposal, proposal_t*,
        private_ike_cfg_t *this, linked_list_t *proposals, bool private,
        bool prefer_self)
@@ -344,7 +363,7 @@ METHOD(ike_cfg_t, select_proposal, proposal_t*,
                        {
                                DBG2(DBG_CFG, "received proposals: %#P", proposals);
                                DBG2(DBG_CFG, "configured proposals: %#P", this->proposals);
-                               DBG2(DBG_CFG, "selected proposal: %P", selected);
+                               DBG1(DBG_CFG, "selected proposal: %P", selected);
                                break;
                        }
                }
@@ -580,6 +599,7 @@ bool ike_cfg_has_address(ike_cfg_t *cfg, host_t *addr, bool local)
                host = host_create_from_string(str, 0);
                if (host && addr->ip_equals(addr, host))
                {
+                       host->destroy(host);
                        found = TRUE;
                        break;
                }
@@ -589,13 +609,10 @@ bool ike_cfg_has_address(ike_cfg_t *cfg, host_t *addr, bool local)
        return found;
 }
 
-/**
- * Described in header.
+/*
+ * Described in header
  */
-ike_cfg_t *ike_cfg_create(ike_version_t version, bool certreq, bool force_encap,
-                                                 char *me, uint16_t my_port,
-                                                 char *other, uint16_t other_port,
-                                                 fragmentation_t fragmentation, uint8_t dscp)
+ike_cfg_t *ike_cfg_create(ike_cfg_create_t *data)
 {
        private_ike_cfg_t *this;
 
@@ -617,30 +634,31 @@ ike_cfg_t *ike_cfg_create(ike_version_t version, bool certreq, bool force_encap,
                        .add_proposal = _add_proposal,
                        .get_proposals = _get_proposals,
                        .select_proposal = _select_proposal,
+                       .has_proposal = _has_proposal,
                        .get_dh_group = _get_dh_group,
                        .equals = _equals,
                        .get_ref = _get_ref,
                        .destroy = _destroy,
                },
                .refcount = 1,
-               .version = version,
-               .certreq = certreq,
-               .force_encap = force_encap,
-               .fragmentation = fragmentation,
-               .me = strdup(me),
+               .version = data->version,
+               .certreq = !data->no_certreq,
+               .force_encap = data->force_encap,
+               .fragmentation = data->fragmentation,
+               .me = strdup(data->local),
                .my_ranges = linked_list_create(),
                .my_hosts = linked_list_create(),
-               .other = strdup(other),
+               .other = strdup(data->remote),
                .other_ranges = linked_list_create(),
                .other_hosts = linked_list_create(),
-               .my_port = my_port,
-               .other_port = other_port,
-               .dscp = dscp,
+               .my_port = data->local_port,
+               .other_port = data->remote_port,
+               .dscp = data->dscp,
                .proposals = linked_list_create(),
        );
 
-       parse_addresses(me, this->my_hosts, this->my_ranges);
-       parse_addresses(other, this->other_hosts, this->other_ranges);
+       parse_addresses(data->local, this->my_hosts, this->my_ranges);
+       parse_addresses(data->remote, this->other_hosts, this->other_ranges);
 
        return &this->public;
 }