2 * Copyright (C) 2007 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
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>.
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
16 #include "mediation_job.h"
18 #include <encoding/payloads/endpoint_notify.h>
22 typedef struct private_mediation_job_t private_mediation_job_t
;
25 * Private data of an mediation_job_t Object
27 struct private_mediation_job_t
{
29 * public mediation_job_t interface
31 mediation_job_t
public;
36 identification_t
*target
;
39 * ID of the source peer.
41 identification_t
*source
;
56 linked_list_t
*endpoints
;
59 * Is this a callback job?
69 METHOD(job_t
, destroy
, void,
70 private_mediation_job_t
*this)
72 DESTROY_IF(this->target
);
73 DESTROY_IF(this->source
);
74 chunk_free(&this->connect_id
);
75 chunk_free(&this->connect_key
);
76 DESTROY_OFFSET_IF(this->endpoints
, offsetof(endpoint_notify_t
, destroy
));
80 METHOD(job_t
, execute
, void,
81 private_mediation_job_t
*this)
83 ike_sa_id_t
*target_sa_id
;
85 target_sa_id
= charon
->mediation_manager
->check(charon
->mediation_manager
, this->target
);
89 ike_sa_t
*target_sa
= charon
->ike_sa_manager
->checkout(charon
->ike_sa_manager
,
95 /* send callback to a peer */
96 if (target_sa
->callback(target_sa
, this->source
) != SUCCESS
)
98 DBG1(DBG_JOB
, "callback for '%Y' to '%Y' failed",
99 this->source
, this->target
);
100 charon
->ike_sa_manager
->checkin(charon
->ike_sa_manager
, target_sa
);
107 /* normal mediation between two peers */
108 if (target_sa
->relay(target_sa
, this->source
, this->connect_id
,
109 this->connect_key
, this->endpoints
, this->response
) != SUCCESS
)
111 DBG1(DBG_JOB
, "mediation between '%Y' and '%Y' failed",
112 this->source
, this->target
);
113 charon
->ike_sa_manager
->checkin(charon
->ike_sa_manager
, target_sa
);
114 /* FIXME: notify the initiator */
120 charon
->ike_sa_manager
->checkin(charon
->ike_sa_manager
, target_sa
);
124 DBG1(DBG_JOB
, "mediation between '%Y' and '%Y' failed: "
125 "SA not found", this->source
, this->target
);
130 DBG1(DBG_JOB
, "mediation between '%Y' and '%Y' failed: "
131 "peer is not online anymore", this->source
, this->target
);
136 METHOD(job_t
, get_priority
, job_priority_t
,
137 private_mediation_job_t
*this)
139 return JOB_PRIO_MEDIUM
;
143 * Creates an empty mediation job
145 static private_mediation_job_t
*mediation_job_create_empty()
147 private_mediation_job_t
*this;
152 .get_priority
= _get_priority
,
161 * Described in header
163 mediation_job_t
*mediation_job_create(identification_t
*peer_id
,
164 identification_t
*requester
, chunk_t connect_id
, chunk_t connect_key
,
165 linked_list_t
*endpoints
, bool response
)
167 private_mediation_job_t
*this = mediation_job_create_empty();
169 this->target
= peer_id
->clone(peer_id
);
170 this->source
= requester
->clone(requester
);
171 this->connect_id
= chunk_clone(connect_id
);
172 this->connect_key
= chunk_clone(connect_key
);
173 this->endpoints
= endpoints
->clone_offset(endpoints
, offsetof(endpoint_notify_t
, clone
));
174 this->response
= response
;
176 return &this->public;
180 * Described in header
182 mediation_job_t
*mediation_callback_job_create(identification_t
*requester
,
183 identification_t
*peer_id
)
185 private_mediation_job_t
*this = mediation_job_create_empty();
187 this->target
= requester
->clone(requester
);
188 this->source
= peer_id
->clone(peer_id
);
189 this->callback
= TRUE
;
191 return &this->public;