Added a task stub to create and process IKEv1 informational exchanges
[strongswan.git] / src / libcharon / sa / tasks / informational.c
1 /*
2 * Copyright (C) 2011 Martin Willi
3 * Copyright (C) 2011 revosec AG
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 "informational.h"
17
18 #include <daemon.h>
19
20 typedef struct private_informational_t private_informational_t;
21
22 /**
23 * Private members of a informational_t task.
24 */
25 struct private_informational_t {
26
27 /**
28 * Public methods and task_t interface.
29 */
30 informational_t public;
31
32 /**
33 * Assigned IKE_SA.
34 */
35 ike_sa_t *ike_sa;
36
37 /**
38 * Notify payload to send
39 */
40 notify_payload_t *notify;
41 };
42
43 METHOD(task_t, build_i, status_t,
44 private_informational_t *this, message_t *message)
45 {
46 message->add_payload(message, &this->notify->payload_interface);
47 this->notify = NULL;
48 return SUCCESS;
49 }
50
51 METHOD(task_t, process_r, status_t,
52 private_informational_t *this, message_t *message)
53 {
54 return FAILED;
55 }
56
57 METHOD(task_t, build_r, status_t,
58 private_informational_t *this, message_t *message)
59 {
60 return FAILED;
61 }
62
63 METHOD(task_t, process_i, status_t,
64 private_informational_t *this, message_t *message)
65 {
66 return FAILED;
67 }
68
69 METHOD(task_t, get_type, task_type_t,
70 private_informational_t *this)
71 {
72 return TASK_INFORMATIONAL;
73 }
74
75 METHOD(task_t, migrate, void,
76 private_informational_t *this, ike_sa_t *ike_sa)
77 {
78 this->ike_sa = ike_sa;
79 }
80
81 METHOD(task_t, destroy, void,
82 private_informational_t *this)
83 {
84 DESTROY_IF(this->notify);
85 free(this);
86 }
87
88 /*
89 * Described in header.
90 */
91 informational_t *informational_create(ike_sa_t *ike_sa, notify_payload_t *notify)
92 {
93 private_informational_t *this;
94
95 INIT(this,
96 .public = {
97 .task = {
98 .get_type = _get_type,
99 .migrate = _migrate,
100 .destroy = _destroy,
101 },
102 },
103 .ike_sa = ike_sa,
104 .notify = notify,
105 );
106
107 if (notify)
108 {
109 this->public.task.build = _build_i;
110 this->public.task.process = _process_i;
111 }
112 else
113 {
114 this->public.task.build = _build_r;
115 this->public.task.process = _process_r;
116 }
117
118 return &this->public;
119 }