8d98aad7e1a5cfad6089761ae4a6003fcb2d107c
[strongswan.git] / src / libcharon / processing / jobs / send_keepalive_job.c
1 /*
2 * Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
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 "send_keepalive_job.h"
19
20 #include <sa/ike_sa.h>
21 #include <daemon.h>
22
23
24 typedef struct private_send_keepalive_job_t private_send_keepalive_job_t;
25
26 /**
27 * Private data of an send_keepalive_job_t Object
28 */
29 struct private_send_keepalive_job_t {
30 /**
31 * public send_keepalive_job_t interface
32 */
33 send_keepalive_job_t public;
34
35 /**
36 * ID of the IKE_SA which the message belongs to.
37 */
38 ike_sa_id_t *ike_sa_id;
39 };
40
41 METHOD(job_t, destroy, void,
42 private_send_keepalive_job_t *this)
43 {
44 this->ike_sa_id->destroy(this->ike_sa_id);
45 free(this);
46 }
47
48 METHOD(job_t, execute, void,
49 private_send_keepalive_job_t *this)
50 {
51 ike_sa_t *ike_sa;
52
53 ike_sa = charon->ike_sa_manager->checkout(charon->ike_sa_manager,
54 this->ike_sa_id);
55 if (ike_sa)
56 {
57 ike_sa->send_keepalive(ike_sa);
58 charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
59 }
60 destroy(this);
61 }
62
63 /*
64 * Described in header
65 */
66 send_keepalive_job_t *send_keepalive_job_create(ike_sa_id_t *ike_sa_id)
67 {
68 private_send_keepalive_job_t *this;
69
70 INIT(this,
71 .public = {
72 .job_interface = {
73 .execute = _execute,
74 .destroy = _destroy,
75 },
76 },
77 .ike_sa_id = ike_sa_id->clone(ike_sa_id),
78 );
79
80 return &this->public;
81 }