Removed strayed code fragment
[strongswan.git] / src / charon / processing / jobs / roam_job.c
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include <stdlib.h>
17
18 #include "roam_job.h"
19
20 #include <sa/ike_sa.h>
21 #include <daemon.h>
22
23
24 typedef struct private_roam_job_t private_roam_job_t;
25
26 /**
27 * Private data of an roam_job_t Object
28 */
29 struct private_roam_job_t {
30 /**
31 * public roam_job_t interface
32 */
33 roam_job_t public;
34
35 /**
36 * has the address list changed, or the routing only?
37 */
38 bool address;
39 };
40
41 /**
42 * Implements job_t.destroy.
43 */
44 static void destroy(private_roam_job_t *this)
45 {
46 free(this);
47 }
48
49 /**
50 * Implementation of job_t.execute.
51 */
52 static void execute(private_roam_job_t *this)
53 {
54 ike_sa_t *ike_sa;
55 linked_list_t *list;
56 ike_sa_id_t *id;
57 enumerator_t *enumerator;
58
59 /* enumerator over all IKE_SAs gives us no way to checkin_and_destroy
60 * after a DESTROY_ME, so we check out each available IKE_SA by hand. */
61 list = linked_list_create();
62 enumerator = charon->ike_sa_manager->create_enumerator(charon->ike_sa_manager);
63 while (enumerator->enumerate(enumerator, &ike_sa))
64 {
65 id = ike_sa->get_id(ike_sa);
66 list->insert_last(list, id->clone(id));
67 }
68 enumerator->destroy(enumerator);
69
70 while (list->remove_last(list, (void**)&id) == SUCCESS)
71 {
72 ike_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager, id);
73 if (ike_sa)
74 {
75 if (ike_sa->roam(ike_sa, this->address) == DESTROY_ME)
76 {
77 charon->ike_sa_manager->checkin_and_destroy(
78 charon->ike_sa_manager, ike_sa);
79 }
80 else
81 {
82 charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
83 }
84 }
85 id->destroy(id);
86 }
87 list->destroy(list);
88
89 destroy(this);
90 }
91
92 /*
93 * Described in header
94 */
95 roam_job_t *roam_job_create(bool address)
96 {
97 private_roam_job_t *this = malloc_thing(private_roam_job_t);
98
99 this->public.job_interface.execute = (void (*) (job_t *)) execute;
100 this->public.job_interface.destroy = (void (*) (job_t *)) destroy;
101
102 this->address = address;
103
104 return &this->public;
105 }
106