_ prefix not required
[strongswan.git] / src / libcharon / processing / jobs / start_action_job.c
1 /*
2 * Copyright (C) 2011 Andreas Steffen
3 * HSR 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 "start_action_job.h"
17
18 #include <daemon.h>
19
20
21 typedef struct private_start_action_job_t private_start_action_job_t;
22
23 /**
24 * Private data of an start_action_job_t object.
25 */
26 struct private_start_action_job_t {
27 /**
28 * Public start_action_job_t interface.
29 */
30 start_action_job_t public;
31 };
32
33 METHOD(job_t, destroy, void,
34 private_start_action_job_t *this)
35 {
36 free(this);
37 }
38
39 METHOD(job_t, execute, void,
40 private_start_action_job_t *this)
41 {
42 enumerator_t *enumerator, *children;
43 peer_cfg_t *peer_cfg;
44 child_cfg_t *child_cfg;
45 char *name;
46
47 enumerator = charon->backends->create_peer_cfg_enumerator(charon->backends,
48 NULL, NULL, NULL, NULL);
49 while (enumerator->enumerate(enumerator, &peer_cfg))
50 {
51 if (peer_cfg->get_ike_version(peer_cfg) != 2)
52 {
53 continue;
54 }
55
56 children = peer_cfg->create_child_cfg_enumerator(peer_cfg);
57 while (children->enumerate(children, &child_cfg))
58 {
59 name = child_cfg->get_name(child_cfg);
60
61 switch (child_cfg->get_start_action(child_cfg))
62 {
63 case ACTION_RESTART:
64 DBG1(DBG_JOB, "start action: initiate '%s'", name);
65 charon->controller->initiate(charon->controller,
66 peer_cfg->get_ref(peer_cfg),
67 child_cfg->get_ref(child_cfg),
68 NULL, NULL);
69 break;
70 case ACTION_ROUTE:
71 DBG1(DBG_JOB, "start action: route '%s'", name);
72 charon->traps->install(charon->traps, peer_cfg, child_cfg);
73 break;
74 case ACTION_NONE:
75 break;
76 }
77 }
78 children->destroy(children);
79 }
80 enumerator->destroy(enumerator);
81 destroy(this);
82 }
83
84 /*
85 * Described in header
86 */
87 start_action_job_t *start_action_job_create(void)
88 {
89 private_start_action_job_t *this;
90
91 INIT(this,
92 .public = {
93 .job_interface = {
94 .execute = _execute,
95 .destroy = _destroy,
96 },
97 },
98 )
99 return &this->public;
100 }
101