Moving charon to libcharon.
[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 /**
49 * Implementation of job_t.destroy.
50 */
51 static void destroy(private_acquire_job_t *this)
52 {
53 DESTROY_IF(this->src_ts);
54 DESTROY_IF(this->dst_ts);
55 free(this);
56 }
57
58 /**
59 * Implementation of job_t.execute.
60 */
61 static void execute(private_acquire_job_t *this)
62 {
63 charon->traps->acquire(charon->traps, this->reqid,
64 this->src_ts, this->dst_ts);
65 destroy(this);
66 }
67
68 /*
69 * Described in header
70 */
71 acquire_job_t *acquire_job_create(u_int32_t reqid,
72 traffic_selector_t *src_ts,
73 traffic_selector_t *dst_ts)
74 {
75 private_acquire_job_t *this = malloc_thing(private_acquire_job_t);
76
77 this->public.job_interface.execute = (void (*) (job_t *)) execute;
78 this->public.job_interface.destroy = (void (*)(job_t*)) destroy;
79
80 this->reqid = reqid;
81 this->src_ts = src_ts;
82 this->dst_ts = dst_ts;
83
84 return &this->public;
85 }
86