3544dd33276090505378c578c7eb70b6e323e644
[strongswan.git] / src / libcharon / processing / jobs / acquire_job.c
1 /*
2 * Copyright (C) 2006-2009 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 "acquire_job.h"
17
18 #include <daemon.h>
19
20
21 typedef struct private_acquire_job_t private_acquire_job_t;
22
23 /**
24 * Private data of an acquire_job_t object.
25 */
26 struct private_acquire_job_t {
27 /**
28 * Public acquire_job_t interface.
29 */
30 acquire_job_t public;
31
32 /**
33 * reqid of the child to rekey
34 */
35 u_int32_t reqid;
36
37 /**
38 * acquired source traffic selector
39 */
40 traffic_selector_t *src_ts;
41
42 /**
43 * acquired destination traffic selector
44 */
45 traffic_selector_t *dst_ts;
46 };
47
48 METHOD(job_t, destroy, void,
49 private_acquire_job_t *this)
50 {
51 DESTROY_IF(this->src_ts);
52 DESTROY_IF(this->dst_ts);
53 free(this);
54 }
55
56 METHOD(job_t, execute, void,
57 private_acquire_job_t *this)
58 {
59 charon->traps->acquire(charon->traps, this->reqid,
60 this->src_ts, this->dst_ts);
61 destroy(this);
62 }
63
64 /*
65 * Described in header
66 */
67 acquire_job_t *acquire_job_create(u_int32_t reqid,
68 traffic_selector_t *src_ts,
69 traffic_selector_t *dst_ts)
70 {
71 private_acquire_job_t *this;
72
73 INIT(this,
74 .public = {
75 .job_interface = {
76 .execute = _execute,
77 .destroy = _destroy,
78 },
79 },
80 .reqid = reqid,
81 .src_ts = src_ts,
82 .dst_ts = dst_ts,
83 );
84
85 return &this->public;
86 }
87