moved ifmap code into tnc_ifmap_soap
[strongswan.git] / src / libcharon / plugins / tnc_ifmap / tnc_ifmap_listener.c
1 /*
2 * Copyright (C) 2011 Andreas Steffen
3 * HSR 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 "tnc_ifmap_listener.h"
17 #include "tnc_ifmap_soap.h"
18
19 #include <daemon.h>
20 #include <debug.h>
21
22 typedef struct private_tnc_ifmap_listener_t private_tnc_ifmap_listener_t;
23
24 /**
25 * Private data of an tnc_ifmap_listener_t object.
26 */
27 struct private_tnc_ifmap_listener_t {
28
29 /**
30 * Public tnc_ifmap_listener_t interface.
31 */
32 tnc_ifmap_listener_t public;
33
34 /**
35 * TNC IF-MAP 2.0 SOAP interface
36 */
37 tnc_ifmap_soap_t *ifmap;
38
39 };
40
41 METHOD(listener_t, ike_updown, bool,
42 private_tnc_ifmap_listener_t *this, ike_sa_t *ike_sa, bool up)
43 {
44 u_int32_t ike_sa_id;
45 identification_t *id;
46 host_t *host;
47
48 ike_sa_id = ike_sa->get_unique_id(ike_sa);
49 id = ike_sa->get_other_id(ike_sa);
50 host = ike_sa->get_other_host(ike_sa);
51
52 DBG2(DBG_TNC, "sending ifmap->publish");
53 if (!this->ifmap->publish(this->ifmap, ike_sa_id, id, host, up))
54 {
55 DBG1(DBG_TNC, "ifmap->publish with MAP server failed");
56 }
57
58 return TRUE;
59 }
60
61 METHOD(tnc_ifmap_listener_t, destroy, void,
62 private_tnc_ifmap_listener_t *this)
63 {
64 DESTROY_IF(this->ifmap);
65 free(this);
66 }
67
68 /**
69 * See header
70 */
71 tnc_ifmap_listener_t *tnc_ifmap_listener_create()
72 {
73 private_tnc_ifmap_listener_t *this;
74
75 INIT(this,
76 .public = {
77 .listener = {
78 .ike_updown = _ike_updown,
79 },
80 .destroy = _destroy,
81 },
82 .ifmap = tnc_ifmap_soap_create(),
83 );
84
85 if (!this->ifmap)
86 {
87 destroy(this);
88 return NULL;
89 }
90
91 DBG2(DBG_TNC, "sending ifmap->newSession");
92 if (!this->ifmap->newSession(this->ifmap))
93 {
94 DBG1(DBG_TNC, "ifmap->newSession with MAP server failed");
95 destroy(this);
96 return NULL;
97 }
98
99 DBG2(DBG_TNC, "sending ifmap->purgePublisher");
100 if (!this->ifmap->purgePublisher(this->ifmap))
101 {
102 DBG1(DBG_TNC, "ifmap->purgePublisher with MAP server failed");
103 destroy(this);
104 return NULL;
105 }
106
107 return &this->public;
108 }
109