700790b48e201ddf1637ec81264f7e9c42573b98
[strongswan.git] / Source / charon / encoding / message.c
1 /**
2 * @file message.c
3 *
4 * @brief Implementation of message_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include <stdlib.h>
24
25 #include "message.h"
26
27 #include <types.h>
28 #include <globals.h>
29 #include <sa/ike_sa_id.h>
30 #include <encoding/generator.h>
31 #include <encoding/parser.h>
32 #include <utils/linked_list.h>
33 #include <utils/allocator.h>
34 #include <utils/logger_manager.h>
35 #include <encoding/payloads/encodings.h>
36 #include <encoding/payloads/payload.h>
37 #include <encoding/payloads/encryption_payload.h>
38
39
40 typedef struct supported_payload_entry_t supported_payload_entry_t;
41
42 /**
43 * Supported payload entry used in message_rule_t.
44 *
45 */
46 struct supported_payload_entry_t {
47 /**
48 * Payload type.
49 */
50 payload_type_t payload_type;
51
52 /**
53 * Minimal occurence of this payload.
54 */
55 size_t min_occurence;
56
57 /**
58 * Max occurence of this payload.
59 */
60 size_t max_occurence;
61 };
62
63 typedef struct message_rule_t message_rule_t;
64
65 /**
66 * Message Rule used to find out which payloads
67 * are supported by each message type.
68 *
69 */
70 struct message_rule_t {
71 /**
72 * Type of message.
73 */
74 exchange_type_t exchange_type;
75
76 /**
77 * Is message a request or response.
78 */
79 bool is_request;
80 /**
81 * Number of supported payloads.
82 */
83 size_t supported_payloads_count;
84 /**
85 * Pointer to first supported payload entry.
86 */
87 supported_payload_entry_t *supported_payloads;
88 };
89
90 /**
91 * Message rule for IKE_SA_INIT from initiator.
92 */
93 static supported_payload_entry_t supported_ike_sa_init_i_payloads[] =
94 {
95 {SECURITY_ASSOCIATION,1,1},
96 {KEY_EXCHANGE,1,1},
97 {NONCE,1,1},
98 };
99
100 /**
101 * Message rule for IKE_SA_INIT from responder.
102 */
103 static supported_payload_entry_t supported_ike_sa_init_r_payloads[] =
104 {
105 {SECURITY_ASSOCIATION,1,1},
106 {KEY_EXCHANGE,1,1},
107 {NONCE,1,1},
108 };
109
110
111 /**
112 * Message rules, defines allowed payloads.
113 */
114 static message_rule_t message_rules[] = {
115 {IKE_SA_INIT,TRUE,(sizeof(supported_ike_sa_init_i_payloads)/sizeof(supported_payload_entry_t)),supported_ike_sa_init_i_payloads},
116 {IKE_SA_INIT,FALSE,(sizeof(supported_ike_sa_init_r_payloads)/sizeof(supported_payload_entry_t)),supported_ike_sa_init_r_payloads}
117 };
118
119 typedef struct payload_entry_t payload_entry_t;
120
121 /**
122 * Entry for a payload in the internal used linked list.
123 *
124 */
125 struct payload_entry_t {
126 /**
127 * Type of payload.
128 */
129 payload_type_t payload_type;
130 /**
131 * Data struct holding the data of given payload.
132 */
133 void *data_struct;
134 };
135
136
137 typedef struct private_message_t private_message_t;
138
139 /**
140 * Private data of an message_t object.
141 */
142 struct private_message_t {
143
144 /**
145 * Public part of a message_t object.
146 */
147 message_t public;
148
149 /**
150 * Minor version of message.
151 */
152 u_int8_t major_version;
153
154 /**
155 * Major version of message.
156 */
157 u_int8_t minor_version;
158
159 /**
160 * First Payload in message.
161 */
162 payload_type_t first_payload;
163
164 /**
165 * Assigned exchange type.
166 */
167 exchange_type_t exchange_type;
168
169
170 /**
171 * TRUE if message is request.
172 * FALSE if message is reply.
173 */
174 bool is_request;
175
176 /**
177 * Message ID of this message.
178 */
179 u_int32_t message_id;
180
181 /**
182 * ID of assigned IKE_SA.
183 */
184 ike_sa_id_t *ike_sa_id;
185
186 /**
187 * Assigned UDP packet.
188 *
189 * Stores incoming packet or last generated one.
190 */
191 packet_t *packet;
192
193 /**
194 * Linked List where payload data are stored in.
195 */
196 linked_list_t *payloads;
197
198 /**
199 * Assigned parser to parse Header and Body of this message.
200 */
201 parser_t *parser;
202
203 /**
204 * Assigned logger.
205 */
206 logger_t *logger;
207
208 /**
209 * Gets a list of supported payloads of this message type
210 *
211 * @param this calling object
212 * @param[out] supported_payloads first entry of supported payloads
213 * @param[out] supported_payloads_count number of supported payload entries
214 *
215 * @return
216 * - SUCCESS
217 * - NOT_FOUND if no supported payload definition could be found
218 */
219 status_t (*get_supported_payloads) (private_message_t *this, supported_payload_entry_t **supported_payloads,size_t *supported_payloads_count);
220
221 };
222
223 /**
224 * Implementation of private_message_t.get_supported_payloads.
225 */
226 status_t get_supported_payloads (private_message_t *this, supported_payload_entry_t **supported_payloads,size_t *supported_payloads_count)
227 {
228 int i;
229 exchange_type_t exchange_type = this->public.get_exchange_type(&(this->public));
230 bool is_request = this->public.get_request(&(this->public));
231
232
233 for (i = 0; i < (sizeof(message_rules) / sizeof(message_rule_t)); i++)
234 {
235 if ((exchange_type == message_rules[i].exchange_type) &&
236 (is_request == message_rules[i].is_request))
237 {
238 /* found rule for given exchange_type*/
239 *supported_payloads = message_rules[i].supported_payloads;
240 *supported_payloads_count = message_rules[i].supported_payloads_count;
241
242 return SUCCESS;
243 }
244
245
246 }
247 *supported_payloads = NULL;
248 *supported_payloads_count = 0;
249 return NOT_FOUND;
250 }
251
252 /**
253 * Implementation of message_t.set_ike_sa_id.
254 */
255 static void set_ike_sa_id (private_message_t *this,ike_sa_id_t *ike_sa_id)
256 {
257 this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
258 }
259
260 /**
261 * Implementation of message_t.get_ike_sa_id.
262 */
263 static status_t get_ike_sa_id (private_message_t *this,ike_sa_id_t **ike_sa_id)
264 {
265 if (this->ike_sa_id == NULL)
266 {
267 return FAILED;
268 }
269 *ike_sa_id = this->ike_sa_id->clone(this->ike_sa_id);
270 return SUCCESS;
271 }
272
273 /**
274 * Implementation of message_t.set_message_id.
275 */
276 static void set_message_id (private_message_t *this,u_int32_t message_id)
277 {
278 this->message_id = message_id;
279 }
280
281 /**
282 * Implementation of message_t.get_message_id.
283 */
284 static u_int32_t get_message_id (private_message_t *this)
285 {
286 return this->message_id;
287 }
288
289 /**
290 * Implementation of message_t.get_responder_spi.
291 */
292 static u_int64_t get_responder_spi (private_message_t *this)
293 {
294 return (this->ike_sa_id->get_responder_spi(this->ike_sa_id));
295 }
296
297 /**
298 * Implementation of message_t.set_major_version.
299 */
300 static void set_major_version (private_message_t *this,u_int8_t major_version)
301 {
302 this->major_version = major_version;
303 }
304
305
306 /**
307 * Implementation of message_t.set_major_version.
308 */
309 static u_int8_t get_major_version (private_message_t *this)
310 {
311 return this->major_version;
312 }
313
314 /**
315 * Implementation of message_t.set_minor_version.
316 */
317 static void set_minor_version (private_message_t *this,u_int8_t minor_version)
318 {
319 this->minor_version = minor_version;
320 }
321
322 /**
323 * Implementation of message_t.get_minor_version.
324 */
325 static u_int8_t get_minor_version (private_message_t *this)
326 {
327 return this->minor_version;
328 }
329
330 /**
331 * Implementation of message_t.set_exchange_type.
332 */
333 static void set_exchange_type (private_message_t *this,exchange_type_t exchange_type)
334 {
335 this->exchange_type = exchange_type;
336 }
337
338 /**
339 * Implementation of message_t.get_exchange_type.
340 */
341 static exchange_type_t get_exchange_type (private_message_t *this)
342 {
343 return this->exchange_type;
344 }
345
346 /**
347 * Implementation of message_t.set_request.
348 */
349 static void set_request (private_message_t *this,bool request)
350 {
351 this->is_request = request;
352 }
353
354 /**
355 * Implementation of message_t.get_request.
356 */
357 static exchange_type_t get_request (private_message_t *this)
358 {
359 return this->is_request;
360 }
361
362 /**
363 * Implementation of message_t.add_payload.
364 */
365 static void add_payload(private_message_t *this, payload_t *payload)
366 {
367 payload_t *last_payload;
368 if (this->payloads->get_count(this->payloads) > 0)
369 {
370 this->payloads->get_last(this->payloads,(void **) &last_payload);
371 }
372
373 this->payloads->insert_last(this->payloads, payload);
374
375 if (this->payloads->get_count(this->payloads) == 1)
376 {
377 this->first_payload = payload->get_type(payload);
378 }
379 else
380 {
381 last_payload->set_next_type(last_payload,payload->get_type(payload));
382 }
383
384 this->logger->log(this->logger, CONTROL|MORE, "added payload of type %s to message",
385 mapping_find(payload_type_m, payload->get_type(payload)));
386
387 }
388
389 /**
390 * Implementation of message_t.set_source.
391 */
392 static void set_source(private_message_t *this, host_t *host)
393 {
394 if (this->packet->source != NULL)
395 {
396 this->packet->source->destroy(this->packet->source);
397 }
398 this->packet->source = host;
399 }
400
401 /**
402 * Implementation of message_t.set_destination.
403 */
404 static void set_destination(private_message_t *this, host_t *host)
405 {
406 if (this->packet->destination != NULL)
407 {
408 this->packet->destination->destroy(this->packet->destination);
409 }
410 this->packet->destination = host;
411 }
412
413 /**
414 * Implementation of message_t.get_source.
415 */
416 static void get_source(private_message_t *this, host_t **host)
417 {
418 *host = this->packet->source;
419 }
420
421 /**
422 * Implementation of message_t.get_destination.
423 */
424 static void get_destination(private_message_t *this, host_t **host)
425 {
426 *host = this->packet->destination;
427 }
428
429 /**
430 * Implementation of message_t.get_destination.
431 */
432 static void get_payload_iterator(private_message_t *this, iterator_t **iterator)
433 {
434 this->payloads->create_iterator(this->payloads, iterator, TRUE);
435 }
436
437
438 /**
439 * Implementation of message_t.generate.
440 */
441 static status_t generate(private_message_t *this, crypter_t *crypter, signer_t* signer, packet_t **packet)
442 {
443 generator_t *generator;
444 ike_header_t *ike_header;
445 payload_t *payload, *next_payload;
446 iterator_t *iterator;
447 status_t status;
448
449
450 this->logger->log(this->logger, CONTROL, "generating message, contains %d payloads",
451 this->payloads->get_count(this->payloads));
452
453 if (this->exchange_type == EXCHANGE_TYPE_UNDEFINED)
454 {
455 this->logger->log(this->logger, ERROR, "exchange type is not defined");
456 return INVALID_STATE;
457 }
458
459 if (this->packet->source == NULL ||
460 this->packet->destination == NULL)
461 {
462 this->logger->log(this->logger, ERROR, "source/destination not defined");
463 return INVALID_STATE;
464 }
465
466 /* build ike header */
467 ike_header = ike_header_create();
468
469 ike_header->set_exchange_type(ike_header, this->exchange_type);
470 ike_header->set_message_id(ike_header, this->message_id);
471 ike_header->set_response_flag(ike_header, !this->is_request);
472 ike_header->set_initiator_flag(ike_header, this->ike_sa_id->is_initiator(this->ike_sa_id));
473 ike_header->set_initiator_spi(ike_header, this->ike_sa_id->get_initiator_spi(this->ike_sa_id));
474 ike_header->set_responder_spi(ike_header, this->ike_sa_id->get_responder_spi(this->ike_sa_id));
475
476 generator = generator_create();
477
478 payload = (payload_t*)ike_header;
479
480 this->payloads->create_iterator(this->payloads, &iterator, TRUE);
481
482 /* generate every payload, except last one */
483 while(iterator->has_next(iterator))
484 {
485 iterator->current(iterator, (void**)&next_payload);
486 payload->set_next_type(payload, next_payload->get_type(next_payload));
487 generator->generate_payload(generator, payload);
488
489 payload = next_payload;
490 }
491 iterator->destroy(iterator);
492
493 /* build last payload */
494 payload->set_next_type(payload, NO_PAYLOAD);
495 /* if it's an encryption payload, build it first */
496 if (payload->get_type(payload) == ENCRYPTED)
497 {
498 encryption_payload_t *encryption_payload = (encryption_payload_t*)payload;
499 encryption_payload->set_signer(encryption_payload, signer);
500 status = encryption_payload->encrypt(encryption_payload, crypter);
501 if (status != SUCCESS)
502 {
503 generator->destroy(generator);
504 ike_header->destroy(ike_header);
505 return status;
506 }
507 }
508 generator->generate_payload(generator, payload);
509 ike_header->destroy(ike_header);
510
511 /* build packet */
512 if (this->packet->data.ptr != NULL)
513 {
514 allocator_free(this->packet->data.ptr);
515 }
516 generator->write_to_chunk(generator, &(this->packet->data));
517 generator->destroy(generator);
518
519 /* append integrity checksum if necessary */
520 if (payload->get_type(payload) == ENCRYPTED)
521 {
522 encryption_payload_t *encryption_payload = (encryption_payload_t*)payload;
523 status = encryption_payload->build_signature(encryption_payload, this->packet->data);
524 if (status != SUCCESS)
525 {
526 return status;
527 }
528 }
529
530 /* clone packet for caller */
531 *packet = this->packet->clone(this->packet);
532
533 this->logger->log(this->logger, CONTROL, "message generated successfully");
534 return SUCCESS;
535 }
536
537 /**
538 * Implements message_t.parse_header.
539 */
540 static status_t parse_header(private_message_t *this)
541 {
542 ike_header_t *ike_header;
543 status_t status;
544
545
546 this->logger->log(this->logger, CONTROL, "parsing header of message");
547
548 this->parser->reset_context(this->parser);
549 status = this->parser->parse_payload(this->parser,HEADER,(payload_t **) &ike_header);
550 if (status != SUCCESS)
551 {
552 this->logger->log(this->logger, ERROR, "Header could not be parsed");
553 return status;
554
555 }
556
557 /* verify payload */
558 status = ike_header->payload_interface.verify(&(ike_header->payload_interface));
559 if (status != SUCCESS)
560 {
561 this->logger->log(this->logger, ERROR, "Header verification failed");
562 ike_header->destroy(ike_header);
563 return status;
564 }
565
566 if (this->ike_sa_id != NULL)
567 {
568 this->ike_sa_id->destroy(this->ike_sa_id);
569 }
570
571 this->ike_sa_id = ike_sa_id_create(ike_header->get_initiator_spi(ike_header),
572 ike_header->get_responder_spi(ike_header),
573 ike_header->get_initiator_flag(ike_header));
574
575 this->exchange_type = ike_header->get_exchange_type(ike_header);
576 this->message_id = ike_header->get_message_id(ike_header);
577 this->is_request = (!(ike_header->get_response_flag(ike_header)));
578 this->major_version = ike_header->get_maj_version(ike_header);
579 this->minor_version = ike_header->get_min_version(ike_header);
580 this->first_payload = ike_header->payload_interface.get_next_type(&(ike_header->payload_interface));
581
582
583 this->logger->log(this->logger, CONTROL, "parsing header successfully");
584
585 ike_header->destroy(ike_header);
586 return SUCCESS;
587 }
588
589 /**
590 * Implements message_t.parse_body.
591 */
592 static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t *signer)
593 {
594 status_t status = SUCCESS;
595 payload_type_t current_payload_type = this->first_payload;
596
597 this->logger->log(this->logger, CONTROL, "parsing body of message");
598
599 while (current_payload_type != NO_PAYLOAD)
600 {
601 payload_t *current_payload;
602
603 this->logger->log(this->logger, CONTROL|MORE, "start parsing payload of type %s",
604 mapping_find(payload_type_m, current_payload_type));
605
606 status = this->parser->parse_payload(this->parser,current_payload_type,(payload_t **) &current_payload);
607 if (status != SUCCESS)
608 {
609 this->logger->log(this->logger, ERROR, "payload type %s could not be parsed",mapping_find(payload_type_m,current_payload_type));
610 return status;
611 }
612
613 status = current_payload->verify(current_payload);
614 if (status != SUCCESS)
615 {
616 this->logger->log(this->logger, ERROR, "payload type %s could not be verified",mapping_find(payload_type_m,current_payload_type));
617 status = VERIFY_ERROR;
618 return status;
619 }
620
621 /* encrypted payload must be decrypted */
622 if (current_payload->get_type(current_payload) == ENCRYPTED)
623 {
624 encryption_payload_t *encryption_payload = (encryption_payload_t*)current_payload;
625 encryption_payload->set_signer(encryption_payload, signer);
626 status = encryption_payload->verify_signature(encryption_payload, this->packet->data);
627 if (status != SUCCESS)
628 {
629 this->logger->log(this->logger, ERROR, "encryption payload signature invaild");
630 return status;
631 }
632 status = encryption_payload->decrypt(encryption_payload, crypter);
633 if (status != SUCCESS)
634 {
635 this->logger->log(this->logger, ERROR, "parsing decrypted encryption payload failed");
636 return status;
637 }
638 }
639
640 /* get next payload type */
641 current_payload_type = current_payload->get_next_type(current_payload);
642
643 this->payloads->insert_last(this->payloads,current_payload);
644
645 }
646 return this->public.verify(&(this->public));
647
648 }
649
650 /**
651 * implements message_t.verify
652 */
653 static status_t verify(private_message_t *this)
654 {
655 iterator_t *iterator;
656 status_t status;
657 int i;
658 supported_payload_entry_t *supported_payloads;
659 size_t supported_payloads_count;
660
661 this->logger->log(this->logger, CONTROL|MORE, "verifying message");
662
663 status = this->get_supported_payloads(this, &supported_payloads, &supported_payloads_count);
664 if (status != SUCCESS)
665 {
666 this->logger->log(this->logger, ERROR, "could not get supported payloads: %s");
667 return status;
668 }
669
670 this->payloads->create_iterator(this->payloads,&iterator,TRUE);
671
672 /* check for payloads with wrong count*/
673 for (i = 0; i < supported_payloads_count;i++)
674 {
675 size_t min_occurence = supported_payloads[i].min_occurence;
676 size_t max_occurence = supported_payloads[i].max_occurence;
677 payload_type_t payload_type = supported_payloads[i].payload_type;
678 size_t found_payloads = 0;
679
680 iterator->reset(iterator);
681
682 while(iterator->has_next(iterator))
683 {
684 payload_t *current_payload;
685 iterator->current(iterator,(void **)&current_payload);
686
687 if (current_payload->get_type(current_payload) == payload_type)
688 {
689 found_payloads++;
690 if (found_payloads > max_occurence)
691 {
692 this->logger->log(this->logger, ERROR, "Payload of type %s more than %d times (%d) occured in current message",
693 mapping_find(payload_type_m,current_payload->get_type(current_payload)),max_occurence,found_payloads);
694 iterator->destroy(iterator);
695 return NOT_SUPPORTED;
696 }
697 }
698 }
699 if (found_payloads < min_occurence)
700 {
701 this->logger->log(this->logger, ERROR, "Payload of type %s not occured %d times",
702 mapping_find(payload_type_m,payload_type),min_occurence);
703 iterator->destroy(iterator);
704 return NOT_SUPPORTED;
705 }
706 }
707 iterator->destroy(iterator);
708
709 return SUCCESS;
710 }
711
712
713 /**
714 * Implements message_t's destroy function.
715 * See #message_s.destroy.
716 */
717 static void destroy (private_message_t *this)
718 {
719 iterator_t *iterator;
720
721 this->packet->destroy(this->packet);
722
723 if (this->ike_sa_id != NULL)
724 {
725 this->ike_sa_id->destroy(this->ike_sa_id);
726 }
727
728 this->payloads->create_iterator(this->payloads, &iterator, TRUE);
729 while (iterator->has_next(iterator))
730 {
731 payload_t *payload;
732 iterator->current(iterator, (void**)&payload);
733 this->logger->log(this->logger, CONTROL|MOST, "Destroying payload of type %s",
734 mapping_find(payload_type_m, payload->get_type(payload)));
735 payload->destroy(payload);
736 }
737 iterator->destroy(iterator);
738 this->payloads->destroy(this->payloads);
739 this->parser->destroy(this->parser);
740 global_logger_manager->destroy_logger(global_logger_manager, this->logger);
741
742 allocator_free(this);
743 }
744
745 /*
746 * Described in Header-File
747 */
748 message_t *message_create_from_packet(packet_t *packet)
749 {
750 private_message_t *this = allocator_alloc_thing(private_message_t);
751 if (this == NULL)
752 {
753 return NULL;
754 }
755
756 /* public functions */
757 this->public.set_major_version = (void(*)(message_t*, u_int8_t))set_major_version;
758 this->public.get_major_version = (u_int8_t(*)(message_t*))get_major_version;
759 this->public.set_minor_version = (void(*)(message_t*, u_int8_t))set_minor_version;
760 this->public.get_minor_version = (u_int8_t(*)(message_t*))get_minor_version;
761 this->public.set_message_id = (void(*)(message_t*, u_int32_t))set_message_id;
762 this->public.get_message_id = (u_int32_t(*)(message_t*))get_message_id;
763 this->public.get_responder_spi = (u_int64_t(*)(message_t*))get_responder_spi;
764 this->public.set_ike_sa_id = (void(*)(message_t*, ike_sa_id_t *))set_ike_sa_id;
765 this->public.get_ike_sa_id = (status_t(*)(message_t*, ike_sa_id_t **))get_ike_sa_id;
766 this->public.set_exchange_type = (void(*)(message_t*, exchange_type_t))set_exchange_type;
767 this->public.get_exchange_type = (exchange_type_t(*)(message_t*))get_exchange_type;
768 this->public.set_request = (void(*)(message_t*, bool))set_request;
769 this->public.get_request = (bool(*)(message_t*))get_request;
770 this->public.add_payload = (void(*)(message_t*,payload_t*))add_payload;
771 this->public.generate = (status_t (*) (message_t *,crypter_t*,signer_t*,packet_t**)) generate;
772 this->public.set_source = (void (*) (message_t*,host_t*)) set_source;
773 this->public.get_source = (void (*) (message_t*,host_t**)) get_source;
774 this->public.set_destination = (void (*) (message_t*,host_t*)) set_destination;
775 this->public.get_destination = (void (*) (message_t*,host_t**)) get_destination;
776 this->public.get_payload_iterator = (void (*) (message_t *, iterator_t **)) get_payload_iterator;
777 this->public.parse_header = (status_t (*) (message_t *)) parse_header;
778 this->public.parse_body = (status_t (*) (message_t *,crypter_t*,signer_t*)) parse_body;
779 this->public.verify = (status_t (*) (message_t*)) verify;
780 this->public.destroy = (void(*)(message_t*))destroy;
781
782 /* public values */
783 this->exchange_type = EXCHANGE_TYPE_UNDEFINED;
784 this->is_request = TRUE;
785 this->ike_sa_id = NULL;
786 this->first_payload = NO_PAYLOAD;
787 this->message_id = 0;
788
789 /* private functions */
790 this->get_supported_payloads = get_supported_payloads;
791
792 /* private values */
793 if (packet == NULL)
794 {
795 packet = packet_create();
796 }
797 if (packet == NULL)
798 {
799 allocator_free(this);
800 return NULL;
801 }
802 this->packet = packet;
803 this->payloads = linked_list_create();
804 if (this->payloads == NULL)
805 {
806 allocator_free(this);
807 return NULL;
808 }
809
810 /* parser is created from data of packet */
811 this->parser = parser_create(this->packet->data);
812 if (this->parser == NULL)
813 {
814 this->payloads->destroy(this->payloads);
815 allocator_free(this);
816 return NULL;
817 }
818
819 this->logger = global_logger_manager->create_logger(global_logger_manager, MESSAGE, NULL);
820 if (this->logger == NULL)
821 {
822 this->parser->destroy(this->parser);
823 this->payloads->destroy(this->payloads);
824 allocator_free(this);
825 return NULL;
826 }
827
828 return (&this->public);
829 }
830
831 /*
832 * Described in Header-File
833 */
834 message_t *message_create()
835 {
836 return message_create_from_packet(NULL);
837 }