Removed strayed code fragment
[strongswan.git] / src / charon / network / packet.c
1 /*
2 * Copyright (C) 2005-2006 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include "packet.h"
18
19 typedef struct private_packet_t private_packet_t;
20
21 /**
22 * Private data of an packet_t object.
23 */
24 struct private_packet_t {
25
26 /**
27 * Public part of a packet_t object.
28 */
29 packet_t public;
30
31 /**
32 * source address
33 */
34 host_t *source;
35
36 /**
37 * destination address
38 */
39 host_t *destination;
40
41 /**
42 * message data
43 */
44 chunk_t data;
45 };
46
47 METHOD(packet_t, set_source, void,
48 private_packet_t *this, host_t *source)
49 {
50 DESTROY_IF(this->source);
51 this->source = source;
52 }
53
54 METHOD(packet_t, set_destination, void,
55 private_packet_t *this, host_t *destination)
56 {
57 DESTROY_IF(this->destination);
58 this->destination = destination;
59 }
60
61 METHOD(packet_t, get_source, host_t*,
62 private_packet_t *this)
63 {
64 return this->source;
65 }
66
67 METHOD(packet_t, get_destination, host_t*,
68 private_packet_t *this)
69 {
70 return this->destination;
71 }
72
73 METHOD(packet_t, get_data, chunk_t,
74 private_packet_t *this)
75 {
76 return this->data;
77 }
78
79 METHOD(packet_t, set_data, void,
80 private_packet_t *this, chunk_t data)
81 {
82 free(this->data.ptr);
83 this->data = data;
84 }
85
86 METHOD(packet_t, destroy, void,
87 private_packet_t *this)
88 {
89 DESTROY_IF(this->source);
90 DESTROY_IF(this->destination);
91 free(this->data.ptr);
92 free(this);
93 }
94
95 METHOD(packet_t, clone_, packet_t*,
96 private_packet_t *this)
97 {
98 packet_t *other;
99
100 other = packet_create();
101 if (this->destination != NULL)
102 {
103 other->set_destination(other, this->destination->clone(this->destination));
104 }
105 if (this->source != NULL)
106 {
107 other->set_source(other, this->source->clone(this->source));
108 }
109 if (this->data.ptr != NULL)
110 {
111 other->set_data(other, chunk_clone(this->data));
112 }
113 return other;
114 }
115
116 /*
117 * Documented in header
118 */
119 packet_t *packet_create(void)
120 {
121 private_packet_t *this;
122
123 INIT(this,
124 .public = {
125 .set_data = _set_data,
126 .get_data = _get_data,
127 .set_source = _set_source,
128 .get_source = _get_source,
129 .set_destination = _set_destination,
130 .get_destination = _get_destination,
131 .clone = _clone_,
132 .destroy = _destroy,
133 },
134 );
135
136 return &this->public;
137 }
138