2 * Copyright (C) 2011 Martin Willi
3 * Copyright (C) 2011 revosec AG
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 "informational.h"
19 #include <sa/tasks/isakmp_delete.h>
20 #include <sa/tasks/quick_delete.h>
21 #include <encoding/payloads/delete_payload.h>
23 typedef struct private_informational_t private_informational_t
;
26 * Private members of a informational_t task.
28 struct private_informational_t
{
31 * Public methods and task_t interface.
33 informational_t
public;
41 * Notify payload to send
43 notify_payload_t
*notify
;
51 METHOD(task_t
, build_i
, status_t
,
52 private_informational_t
*this, message_t
*message
)
54 message
->add_payload(message
, &this->notify
->payload_interface
);
59 METHOD(task_t
, process_r
, status_t
,
60 private_informational_t
*this, message_t
*message
)
62 enumerator_t
*enumerator
;
63 delete_payload_t
*delete;
64 notify_payload_t
*notify
;
67 status_t status
= SUCCESS
;
69 enumerator
= message
->create_payload_enumerator(message
);
70 while (enumerator
->enumerate(enumerator
, &payload
))
72 switch (payload
->get_type(payload
))
75 notify
= (notify_payload_t
*)payload
;
76 type
= notify
->get_notify_type(notify
);
78 if (type
== INITIAL_CONTACT_IKEV1
)
80 this->ike_sa
->set_condition(this->ike_sa
,
81 COND_INIT_CONTACT_SEEN
, TRUE
);
83 else if (type
< 16384)
85 DBG1(DBG_IKE
, "received %N error notify",
86 notify_type_names
, notify
->get_notify_type(notify
));
92 DBG1(DBG_IKE
, "received %N notify",
93 notify_type_names
, notify
->get_notify_type(notify
));
99 delete = (delete_payload_t
*)payload
;
100 if (delete->get_protocol_id(delete) == PROTO_IKE
)
102 this->del
= (task_t
*)isakmp_delete_create(this->ike_sa
,
107 this->del
= (task_t
*)quick_delete_create(this->ike_sa
,
117 enumerator
->destroy(enumerator
);
119 if (this->del
&& status
== SUCCESS
)
121 return this->del
->process(this->del
, message
);
126 METHOD(task_t
, build_r
, status_t
,
127 private_informational_t
*this, message_t
*message
)
131 return this->del
->build(this->del
, message
);
136 METHOD(task_t
, process_i
, status_t
,
137 private_informational_t
*this, message_t
*message
)
142 METHOD(task_t
, get_type
, task_type_t
,
143 private_informational_t
*this)
145 return TASK_INFORMATIONAL
;
148 METHOD(task_t
, migrate
, void,
149 private_informational_t
*this, ike_sa_t
*ike_sa
)
151 this->ike_sa
= ike_sa
;
154 METHOD(task_t
, destroy
, void,
155 private_informational_t
*this)
157 DESTROY_IF(this->notify
);
158 DESTROY_IF(this->del
);
163 * Described in header.
165 informational_t
*informational_create(ike_sa_t
*ike_sa
, notify_payload_t
*notify
)
167 private_informational_t
*this;
172 .get_type
= _get_type
,
183 this->public.task
.build
= _build_i
;
184 this->public.task
.process
= _process_i
;
188 this->public.task
.build
= _build_r
;
189 this->public.task
.process
= _process_r
;
192 return &this->public;