2 * Copyright (C) 2005-2006 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
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>.
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
19 typedef struct private_packet_t private_packet_t
;
22 * Private data of an packet_t object.
24 struct private_packet_t
{
27 * Public part of a packet_t object.
47 METHOD(packet_t
, set_source
, void,
48 private_packet_t
*this, host_t
*source
)
50 DESTROY_IF(this->source
);
51 this->source
= source
;
54 METHOD(packet_t
, set_destination
, void,
55 private_packet_t
*this, host_t
*destination
)
57 DESTROY_IF(this->destination
);
58 this->destination
= destination
;
61 METHOD(packet_t
, get_source
, host_t
*,
62 private_packet_t
*this)
67 METHOD(packet_t
, get_destination
, host_t
*,
68 private_packet_t
*this)
70 return this->destination
;
73 METHOD(packet_t
, get_data
, chunk_t
,
74 private_packet_t
*this)
79 METHOD(packet_t
, set_data
, void,
80 private_packet_t
*this, chunk_t data
)
86 METHOD(packet_t
, destroy
, void,
87 private_packet_t
*this)
89 DESTROY_IF(this->source
);
90 DESTROY_IF(this->destination
);
95 METHOD(packet_t
, clone_
, packet_t
*,
96 private_packet_t
*this)
100 other
= packet_create();
101 if (this->destination
!= NULL
)
103 other
->set_destination(other
, this->destination
->clone(this->destination
));
105 if (this->source
!= NULL
)
107 other
->set_source(other
, this->source
->clone(this->source
));
109 if (this->data
.ptr
!= NULL
)
111 other
->set_data(other
, chunk_clone(this->data
));
117 * Documented in header
119 packet_t
*packet_create(void)
121 private_packet_t
*this;
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
,
136 return &this->public;