e066cbac5d3ad68792c81a58f4d229aa77106608
[strongswan.git] / src / charon / processing / jobs / acquire_job.c
1 /*
2 * Copyright (C) 2006 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 * $Id$
16 */
17
18 #include "acquire_job.h"
19
20 #include <daemon.h>
21
22
23 typedef struct private_acquire_job_t private_acquire_job_t;
24
25 /**
26 * Private data of an acquire_job_t object.
27 */
28 struct private_acquire_job_t {
29 /**
30 * Public acquire_job_t interface.
31 */
32 acquire_job_t public;
33
34 /**
35 * reqid of the child to rekey
36 */
37 u_int32_t reqid;
38 };
39
40 /**
41 * Implementation of job_t.destroy.
42 */
43 static void destroy(private_acquire_job_t *this)
44 {
45 free(this);
46 }
47
48 /**
49 * Implementation of job_t.execute.
50 */
51 static void execute(private_acquire_job_t *this)
52 {
53 ike_sa_t *ike_sa;
54
55 ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
56 this->reqid, TRUE);
57 if (ike_sa == NULL)
58 {
59 DBG2(DBG_JOB, "CHILD_SA with reqid %d not found for acquiring",
60 this->reqid);
61 }
62 else
63 {
64 ike_sa->acquire(ike_sa, this->reqid);
65
66 charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
67 }
68 destroy(this);
69 }
70
71 /*
72 * Described in header
73 */
74 acquire_job_t *acquire_job_create(u_int32_t reqid)
75 {
76 private_acquire_job_t *this = malloc_thing(private_acquire_job_t);
77
78 /* interface functions */
79 this->public.job_interface.execute = (void (*) (job_t *)) execute;
80 this->public.job_interface.destroy = (void (*)(job_t*)) destroy;
81
82 /* private variables */
83 this->reqid = reqid;
84
85 return &this->public;
86 }