Revision 82713dea src/charon/encoding/payloads/vendor_id_payload.c
| b/src/charon/encoding/payloads/vendor_id_payload.c | ||
|---|---|---|
| 1 | 1 |
/* |
| 2 |
* Copyright (C) 2005-2006 Martin Willi |
|
| 2 |
* Copyright (C) 2005-2009 Martin Willi |
|
| 3 | 3 |
* Copyright (C) 2005 Jan Hutter |
| 4 | 4 |
* Hochschule fuer Technik Rapperswil |
| 5 | 5 |
* |
| ... | ... | |
| 18 | 18 |
|
| 19 | 19 |
#include "vendor_id_payload.h" |
| 20 | 20 |
|
| 21 |
|
|
| 22 | 21 |
typedef struct private_vendor_id_payload_t private_vendor_id_payload_t; |
| 23 | 22 |
|
| 24 | 23 |
/** |
| 25 | 24 |
* Private data of an vendor_id_payload_t object. |
| 26 |
* |
|
| 27 | 25 |
*/ |
| 28 | 26 |
struct private_vendor_id_payload_t {
|
| 27 |
|
|
| 29 | 28 |
/** |
| 30 | 29 |
* Public vendor_id_payload_t interface. |
| 31 | 30 |
*/ |
| ... | ... | |
| 47 | 46 |
u_int16_t payload_length; |
| 48 | 47 |
|
| 49 | 48 |
/** |
| 50 |
* The contained vendor_id data value. |
|
| 49 |
* The contained data. |
|
| 51 | 50 |
*/ |
| 52 |
chunk_t vendor_id_data; |
|
| 51 |
chunk_t data; |
|
| 53 | 52 |
}; |
| 54 | 53 |
|
| 55 | 54 |
/** |
| ... | ... | |
| 57 | 56 |
* |
| 58 | 57 |
* The defined offsets are the positions in a object of type |
| 59 | 58 |
* private_vendor_id_payload_t. |
| 60 |
* |
|
| 61 | 59 |
*/ |
| 62 | 60 |
encoding_rule_t vendor_id_payload_encodings[] = {
|
| 63 | 61 |
/* 1 Byte next payload type, stored in the field next_payload */ |
| ... | ... | |
| 75 | 73 |
/* Length of the whole payload*/ |
| 76 | 74 |
{ PAYLOAD_LENGTH, offsetof(private_vendor_id_payload_t, payload_length)},
|
| 77 | 75 |
/* some vendor_id data bytes, length is defined in PAYLOAD_LENGTH */ |
| 78 |
{ VID_DATA, offsetof(private_vendor_id_payload_t, vendor_id_data) }
|
|
| 76 |
{ VID_DATA, offsetof(private_vendor_id_payload_t, data) }
|
|
| 79 | 77 |
}; |
| 80 | 78 |
|
| 81 | 79 |
/* |
| ... | ... | |
| 101 | 99 |
/** |
| 102 | 100 |
* Implementation of vendor_id_payload_t.get_encoding_rules. |
| 103 | 101 |
*/ |
| 104 |
static void get_encoding_rules(private_vendor_id_payload_t *this, encoding_rule_t **rules, size_t *rule_count) |
|
| 102 |
static void get_encoding_rules(private_vendor_id_payload_t *this, |
|
| 103 |
encoding_rule_t **rules, size_t *rule_count) |
|
| 105 | 104 |
{
|
| 106 | 105 |
*rules = vendor_id_payload_encodings; |
| 107 | 106 |
*rule_count = sizeof(vendor_id_payload_encodings) / sizeof(encoding_rule_t); |
| ... | ... | |
| 120 | 119 |
*/ |
| 121 | 120 |
static payload_type_t get_next_type(private_vendor_id_payload_t *this) |
| 122 | 121 |
{
|
| 123 |
return (this->next_payload); |
|
| 122 |
return this->next_payload; |
|
| 124 | 123 |
} |
| 125 | 124 |
|
| 126 | 125 |
/** |
| ... | ... | |
| 140 | 139 |
} |
| 141 | 140 |
|
| 142 | 141 |
/** |
| 143 |
* Implementation of vendor_id_payload_t.set_data. |
|
| 144 |
*/ |
|
| 145 |
static void set_data (private_vendor_id_payload_t *this, chunk_t data) |
|
| 146 |
{
|
|
| 147 |
if (this->vendor_id_data.ptr != NULL) |
|
| 148 |
{
|
|
| 149 |
chunk_free(&(this->vendor_id_data)); |
|
| 150 |
} |
|
| 151 |
this->vendor_id_data.ptr = clalloc(data.ptr,data.len); |
|
| 152 |
this->vendor_id_data.len = data.len; |
|
| 153 |
this->payload_length = VENDOR_ID_PAYLOAD_HEADER_LENGTH + this->vendor_id_data.len; |
|
| 154 |
} |
|
| 155 |
|
|
| 156 |
/** |
|
| 157 | 142 |
* Implementation of vendor_id_payload_t.get_data. |
| 158 | 143 |
*/ |
| 159 |
static chunk_t get_data (private_vendor_id_payload_t *this) |
|
| 160 |
{
|
|
| 161 |
return (this->vendor_id_data); |
|
| 162 |
} |
|
| 163 |
|
|
| 164 |
/** |
|
| 165 |
* Implementation of vendor_id_payload_t.get_data_clone. |
|
| 166 |
*/ |
|
| 167 |
static chunk_t get_data_clone (private_vendor_id_payload_t *this) |
|
| 144 |
static chunk_t get_data(private_vendor_id_payload_t *this) |
|
| 168 | 145 |
{
|
| 169 |
chunk_t cloned_data; |
|
| 170 |
if (this->vendor_id_data.ptr == NULL) |
|
| 171 |
{
|
|
| 172 |
return (this->vendor_id_data); |
|
| 173 |
} |
|
| 174 |
cloned_data.ptr = clalloc(this->vendor_id_data.ptr,this->vendor_id_data.len); |
|
| 175 |
cloned_data.len = this->vendor_id_data.len; |
|
| 176 |
return cloned_data; |
|
| 146 |
return this->data; |
|
| 177 | 147 |
} |
| 178 | 148 |
|
| 179 | 149 |
/** |
| ... | ... | |
| 181 | 151 |
*/ |
| 182 | 152 |
static void destroy(private_vendor_id_payload_t *this) |
| 183 | 153 |
{
|
| 184 |
if (this->vendor_id_data.ptr != NULL) |
|
| 185 |
{
|
|
| 186 |
chunk_free(&(this->vendor_id_data)); |
|
| 187 |
} |
|
| 154 |
free(this->data.ptr); |
|
| 188 | 155 |
free(this); |
| 189 | 156 |
} |
| 190 | 157 |
|
| ... | ... | |
| 195 | 162 |
{
|
| 196 | 163 |
private_vendor_id_payload_t *this = malloc_thing(private_vendor_id_payload_t); |
| 197 | 164 |
|
| 198 |
/* interface functions */ |
|
| 199 | 165 |
this->public.payload_interface.verify = (status_t (*) (payload_t *))verify; |
| 200 | 166 |
this->public.payload_interface.get_encoding_rules = (void (*) (payload_t *, encoding_rule_t **, size_t *) ) get_encoding_rules; |
| 201 | 167 |
this->public.payload_interface.get_length = (size_t (*) (payload_t *)) get_length; |
| ... | ... | |
| 203 | 169 |
this->public.payload_interface.set_next_type = (void (*) (payload_t *,payload_type_t)) set_next_type; |
| 204 | 170 |
this->public.payload_interface.get_type = (payload_type_t (*) (payload_t *)) get_payload_type; |
| 205 | 171 |
this->public.payload_interface.destroy = (void (*) (payload_t *))destroy; |
| 206 |
|
|
| 207 |
/* public functions */ |
|
| 208 |
this->public.destroy = (void (*) (vendor_id_payload_t *)) destroy; |
|
| 209 |
this->public.set_data = (void (*) (vendor_id_payload_t *,chunk_t)) set_data; |
|
| 210 |
this->public.get_data_clone = (chunk_t (*) (vendor_id_payload_t *)) get_data_clone; |
|
| 211 | 172 |
this->public.get_data = (chunk_t (*) (vendor_id_payload_t *)) get_data; |
| 212 | 173 |
|
| 213 |
/* private variables */ |
|
| 214 | 174 |
this->critical = FALSE; |
| 215 | 175 |
this->next_payload = NO_PAYLOAD; |
| 216 | 176 |
this->payload_length = VENDOR_ID_PAYLOAD_HEADER_LENGTH; |
| 217 |
this->vendor_id_data = chunk_empty; |
|
| 177 |
this->data = chunk_empty; |
|
| 178 |
|
|
| 179 |
return &this->public; |
|
| 180 |
} |
|
| 181 |
|
|
| 182 |
/* |
|
| 183 |
* Described in header |
|
| 184 |
*/ |
|
| 185 |
vendor_id_payload_t *vendor_id_payload_create_data(chunk_t data) |
|
| 186 |
{
|
|
| 187 |
private_vendor_id_payload_t *this; |
|
| 188 |
|
|
| 189 |
this = (private_vendor_id_payload_t*)vendor_id_payload_create(); |
|
| 190 |
this->payload_length += data.len; |
|
| 191 |
this->data = data; |
|
| 218 | 192 |
|
| 219 |
return (&(this->public)); |
|
| 193 |
return &this->public; |
|
| 220 | 194 |
} |
| 195 |
|
|
Also available in: Unified diff