14e65409ff8a31523e2849fd25243bf66d6919bf
[strongswan.git] / src / libcharon / plugins / dhcp / dhcp_transaction.c
1 /*
2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 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 "dhcp_transaction.h"
17
18 typedef struct private_dhcp_transaction_t private_dhcp_transaction_t;
19
20 /**
21 * Private data of an dhcp_transaction_t object.
22 */
23 struct private_dhcp_transaction_t {
24
25 /**
26 * Public dhcp_transaction_t interface.
27 */
28 dhcp_transaction_t public;
29
30 /**
31 * DHCP transaction ID
32 */
33 u_int32_t id;
34
35 /**
36 * Peer identity
37 */
38 identification_t *identity;
39
40 /**
41 * received DHCP address
42 */
43 host_t *address;
44 };
45
46 METHOD(dhcp_transaction_t, get_id, u_int32_t,
47 private_dhcp_transaction_t *this)
48 {
49 return this->id;
50 }
51
52 METHOD(dhcp_transaction_t, get_identity, identification_t*,
53 private_dhcp_transaction_t *this)
54 {
55 return this->identity;
56 }
57
58 METHOD(dhcp_transaction_t, set_address, void,
59 private_dhcp_transaction_t *this, host_t *address)
60 {
61 DESTROY_IF(this->address);
62 this->address = address;
63 }
64
65 METHOD(dhcp_transaction_t, get_address, host_t*,
66 private_dhcp_transaction_t *this)
67 {
68 return this->address;
69 }
70
71 METHOD(dhcp_transaction_t, destroy, void,
72 private_dhcp_transaction_t *this)
73 {
74 this->identity->destroy(this->identity);
75 DESTROY_IF(this->address);
76 free(this);
77 }
78
79 /**
80 * See header
81 */
82 dhcp_transaction_t *dhcp_transaction_create(u_int32_t id,
83 identification_t *identity)
84 {
85 private_dhcp_transaction_t *this;
86
87 INIT(this,
88 .public = {
89 .get_id = _get_id,
90 .get_identity = _get_identity,
91 .set_address = _set_address,
92 .get_address = _get_address,
93 .destroy = _destroy,
94 },
95 .id = id,
96 .identity = identity->clone(identity),
97 );
98
99 return &this->public;
100 }
101