removed %M printf handler, five more to go
[strongswan.git] / src / charon / encoding / message.c
index 65e4729..077b767 100644 (file)
 
 #include <stdlib.h>
 #include <string.h>
-#include <printf.h>
 
 #include "message.h"
 
-#include <types.h>
+#include <library.h>
 #include <daemon.h>
 #include <sa/ike_sa_id.h>
 #include <encoding/generator.h>
@@ -125,6 +124,7 @@ static payload_rule_t ike_sa_init_i_payload_rules[] = {
        {SECURITY_ASSOCIATION,1,1,FALSE,FALSE},
        {KEY_EXCHANGE,1,1,FALSE,FALSE},
        {NONCE,1,1,FALSE,FALSE},
+       {VENDOR_ID,0,10,FALSE,FALSE},
 };
 
 /**
@@ -135,6 +135,7 @@ static payload_rule_t ike_sa_init_r_payload_rules[] = {
        {SECURITY_ASSOCIATION,1,1,FALSE,FALSE},
        {KEY_EXCHANGE,1,1,FALSE,FALSE},
        {NONCE,1,1,FALSE,FALSE},
+       {VENDOR_ID,0,10,FALSE,FALSE},
 };
 
 /**
@@ -142,15 +143,17 @@ static payload_rule_t ike_sa_init_r_payload_rules[] = {
  */
 static payload_rule_t ike_auth_i_payload_rules[] = {
        {NOTIFY,0,MAX_NOTIFY_PAYLOADS,TRUE,FALSE},
+       {EXTENSIBLE_AUTHENTICATION,0,1,TRUE,TRUE},
+       {AUTHENTICATION,0,1,TRUE,TRUE},
        {ID_INITIATOR,1,1,TRUE,FALSE},
        {CERTIFICATE,0,1,TRUE,FALSE},
        {CERTIFICATE_REQUEST,0,1,TRUE,FALSE},
        {ID_RESPONDER,0,1,TRUE,FALSE},
-       {AUTHENTICATION,1,1,TRUE,FALSE},
        {SECURITY_ASSOCIATION,1,1,TRUE,FALSE},
        {TRAFFIC_SELECTOR_INITIATOR,1,1,TRUE,FALSE},
        {TRAFFIC_SELECTOR_RESPONDER,1,1,TRUE,FALSE},
        {CONFIGURATION,0,1,TRUE,FALSE},
+       {VENDOR_ID,0,10,TRUE,FALSE},
 };
 
 /**
@@ -158,13 +161,15 @@ static payload_rule_t ike_auth_i_payload_rules[] = {
  */
 static payload_rule_t ike_auth_r_payload_rules[] = {
        {NOTIFY,0,MAX_NOTIFY_PAYLOADS,TRUE,TRUE},
+       {EXTENSIBLE_AUTHENTICATION,0,1,TRUE,TRUE},
        {CERTIFICATE,0,1,TRUE,FALSE},
-       {ID_RESPONDER,1,1,TRUE,FALSE},
-       {AUTHENTICATION,1,1,TRUE,FALSE},
-       {SECURITY_ASSOCIATION,1,1,TRUE,FALSE},
-       {TRAFFIC_SELECTOR_INITIATOR,1,1,TRUE,FALSE},
-       {TRAFFIC_SELECTOR_RESPONDER,1,1,TRUE,FALSE},
+       {ID_RESPONDER,0,1,TRUE,FALSE},
+       {AUTHENTICATION,0,1,TRUE,FALSE},
+       {SECURITY_ASSOCIATION,0,1,TRUE,FALSE},
+       {TRAFFIC_SELECTOR_INITIATOR,0,1,TRUE,FALSE},
+       {TRAFFIC_SELECTOR_RESPONDER,0,1,TRUE,FALSE},
        {CONFIGURATION,0,1,TRUE,FALSE},
+       {VENDOR_ID,0,10,TRUE,FALSE},
 };
 
 
@@ -175,6 +180,7 @@ static payload_rule_t informational_i_payload_rules[] = {
        {NOTIFY,0,MAX_NOTIFY_PAYLOADS,TRUE,FALSE},
        {CONFIGURATION,0,1,TRUE,FALSE},
        {DELETE,0,1,TRUE,FALSE},
+       {VENDOR_ID,0,10,TRUE,FALSE},
        
 };
 
@@ -185,6 +191,7 @@ static payload_rule_t informational_r_payload_rules[] = {
        {NOTIFY,0,MAX_NOTIFY_PAYLOADS,TRUE,FALSE},
        {CONFIGURATION,0,1,TRUE,FALSE},
        {DELETE,0,1,TRUE,FALSE},
+       {VENDOR_ID,0,10,TRUE,FALSE},
 };
 
 /**
@@ -198,6 +205,7 @@ static payload_rule_t create_child_sa_i_payload_rules[] = {
        {TRAFFIC_SELECTOR_INITIATOR,0,1,TRUE,FALSE},
        {TRAFFIC_SELECTOR_RESPONDER,0,1,TRUE,FALSE},
        {CONFIGURATION,0,1,TRUE,FALSE},
+       {VENDOR_ID,0,10,TRUE,FALSE},
 };
 
 /**
@@ -211,6 +219,7 @@ static payload_rule_t create_child_sa_r_payload_rules[] = {
        {TRAFFIC_SELECTOR_INITIATOR,0,1,TRUE,FALSE},
        {TRAFFIC_SELECTOR_RESPONDER,0,1,TRUE,FALSE},
        {CONFIGURATION,0,1,TRUE,FALSE},
+       {VENDOR_ID,0,10,TRUE,FALSE},
 };
 
 
@@ -343,6 +352,7 @@ static status_t get_payload_rule(private_message_t *this, payload_type_t payload
  */
 static void set_ike_sa_id (private_message_t *this,ike_sa_id_t *ike_sa_id)
 {
+       DESTROY_IF(this->ike_sa_id);
        this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
 }
 
@@ -470,24 +480,67 @@ static bool is_encoded(private_message_t *this)
  */
 static void add_payload(private_message_t *this, payload_t *payload)
 {
-       payload_t *last_payload;
-       if (this->payloads->get_count(this->payloads) > 0)
+       payload_t *last_payload, *first_payload;
+       
+       if ((this->is_request && payload->get_type(payload) == ID_INITIATOR) ||
+               (!this->is_request && payload->get_type(payload) == ID_RESPONDER))
        {
-               this->payloads->get_last(this->payloads,(void **) &last_payload);
-               last_payload->set_next_type(last_payload, payload->get_type(payload));
+               /* HOTD: insert ID payload in the beginning to respect RFC */
+               if (this->payloads->get_first(this->payloads,
+                                                                         (void **)&first_payload) == SUCCESS)
+               {
+                       payload->set_next_type(payload, first_payload->get_type(first_payload));
+               }
+               else
+               {
+                       payload->set_next_type(payload, NO_PAYLOAD);
+               }
+               this->first_payload = payload->get_type(payload);
+               this->payloads->insert_first(this->payloads, payload);
        }
        else
        {
-               this->first_payload = payload->get_type(payload);
+               if (this->payloads->get_count(this->payloads) > 0)
+               {
+                       this->payloads->get_last(this->payloads,(void **) &last_payload);
+                       last_payload->set_next_type(last_payload, payload->get_type(payload));
+               }
+               else
+               {
+                       this->first_payload = payload->get_type(payload);
+               }
+               payload->set_next_type(payload, NO_PAYLOAD);
+               this->payloads->insert_last(this->payloads, payload);
        }
-       payload->set_next_type(payload, NO_PAYLOAD);
-       this->payloads->insert_last(this->payloads, (void*)payload);
 
-       DBG2(SIG_DBG_ENC ,"added payload of type %N to message",
+       DBG2(DBG_ENC ,"added payload of type %N to message",
                 payload_type_names, payload->get_type(payload));
 }
 
 /**
+ * Implementation of message_t.add_notify.
+ */
+static void add_notify(private_message_t *this, bool flush, notify_type_t type, 
+                                          chunk_t data)
+{
+       notify_payload_t *notify;
+       payload_t *payload;
+       
+       if (flush)
+       {
+               while (this->payloads->remove_last(this->payloads, 
+                                                                                               (void**)&payload) == SUCCESS)
+               {
+                       payload->destroy(payload);
+               }
+       }
+       notify = notify_payload_create();
+       notify->set_notify_type(notify, type);
+       notify->set_notification_data(notify, data);
+       add_payload(this, (payload_t*)notify);
+}
+
+/**
  * Implementation of message_t.set_source.
  */
 static void set_source(private_message_t *this, host_t *host)
@@ -520,7 +573,7 @@ static host_t * get_destination(private_message_t *this)
 }
 
 /**
- * Implementation of message_t.get_destination.
+ * Implementation of message_t.get_payload_iterator.
  */
 static iterator_t *get_payload_iterator(private_message_t *this)
 {
@@ -528,84 +581,63 @@ static iterator_t *get_payload_iterator(private_message_t *this)
 }
 
 /**
- * output handler in printf()
+ * Implementation of message_t.get_payload.
  */
-static int print(FILE *stream, const struct printf_info *info,
-                                const void *const *args)
+static payload_t *get_payload(private_message_t *this, payload_type_t type)
 {
-       private_message_t *this = *((private_message_t**)(args[0]));
+       payload_t *current, *found = NULL;
        iterator_t *iterator;
-       payload_t *payload;
-       bool first = TRUE;
-       size_t total_written = 0;
-       size_t written;
-       
-       if (this == NULL)
-       {
-               return fprintf(stream, "(null)");
-       }
-       
-       written = fprintf(stream, "%N %s [", 
-                                         exchange_type_names, this->exchange_type,
-                                         this->is_request ? "request" : "response");
-       if (written < 0)
-       {
-               return written;
-       }
-       total_written += written;
        
        iterator = this->payloads->create_iterator(this->payloads, TRUE);
-       while (iterator->iterate(iterator, (void**)&payload))
+       while (iterator->iterate(iterator, (void**)&current))
        {
-               if (!first)
+               if (current->get_type(current) == type)
                {
-                       written = fprintf(stream, " ");
-                       if (written < 0)
-                       {
-                               return written;
-                       }
-                       total_written += written;
-               }
-               else
-               {
-                       first = FALSE;
-               }
-               written = fprintf(stream, "%N", payload_type_short_names,
-                                                 payload->get_type(payload));
-               if (written < 0)
-               {
-                       return written;
+                       found = current;
+                       break;
                }
-               total_written += written;
        }
        iterator->destroy(iterator);
-       written = fprintf(stream, "]");
-       if (written < 0)
-       {
-               return written;
-       }
-       total_written += written;
-       return total_written;
+       return found;
 }
 
 /**
- * arginfo handler in printf()
+ * get a string representation of the message
  */
-static int print_arginfo(const struct printf_info *info, size_t n, int *argtypes)
+static void get_string(private_message_t *this, char *buf, int len)
 {
-       if (n > 0)
+       iterator_t *iterator;
+       payload_t *payload;
+       int written;
+       
+       written = snprintf(buf, len, "%N %s [", 
+                                          exchange_type_names, this->exchange_type,
+                                          this->is_request ? "request" : "response");
+       if (written >= len || written < 0)
        {
-               argtypes[0] = PA_POINTER;
+               return;
        }
-       return 1;
-}
-
-/**
- * register printf() handlers
- */
-static void __attribute__ ((constructor))print_register()
-{
-       register_printf_function(MESSAGE_PRINTF_SPEC, print, print_arginfo);
+       buf += written;
+       len -= written;
+       
+       iterator = this->payloads->create_iterator(this->payloads, TRUE);
+       while (iterator->iterate(iterator, (void**)&payload))
+       {
+               written = snprintf(buf, len, "%N ", payload_type_short_names,
+                                                  payload->get_type(payload));
+               if (written >= len || written < 0)
+               {
+                       return;
+               }
+               buf += written;
+               len -= written;
+       }
+       iterator->destroy(iterator);
+       
+       /* remove last space */
+       len++;
+       buf--;
+       snprintf(buf, len, "]");
 }
 
 /**
@@ -619,12 +651,12 @@ static status_t encrypt_payloads (private_message_t *this,crypter_t *crypter, si
        
        if (!this->message_rule->encrypted_content)
        {
-               DBG2(SIG_DBG_ENC, "message doesn't have to be encrypted");
+               DBG2(DBG_ENC, "message doesn't have to be encrypted");
                /* message contains no content to encrypt */
                return SUCCESS;
        }
        
-       DBG2(SIG_DBG_ENC, "copy all payloads to a temporary list");
+       DBG2(DBG_ENC, "copy all payloads to a temporary list");
        all_payloads = linked_list_create();
        
        /* first copy all payloads in a temporary list */
@@ -637,7 +669,7 @@ static status_t encrypt_payloads (private_message_t *this,crypter_t *crypter, si
        
        encryption_payload = encryption_payload_create();
 
-       DBG2(SIG_DBG_ENC, "check each payloads if they have to get encrypted");
+       DBG2(DBG_ENC, "check each payloads if they have to get encrypted");
        while (all_payloads->get_count(all_payloads) > 0)
        {
                payload_rule_t *payload_rule;
@@ -652,30 +684,30 @@ static status_t encrypt_payloads (private_message_t *this,crypter_t *crypter, si
                 * it is presumed that they don't have to be encrypted */
                if ((status == SUCCESS) && (payload_rule->encrypted))
                {
-                       DBG2(SIG_DBG_ENC, "payload %N gets encrypted",
+                       DBG2(DBG_ENC, "payload %N gets encrypted",
                                 payload_type_names, current_payload->get_type(current_payload));
                        to_encrypt = TRUE;
                }
                
                if (to_encrypt)
                {
-                       DBG2(SIG_DBG_ENC, "insert payload %N to encryption payload",
+                       DBG2(DBG_ENC, "insert payload %N to encryption payload",
                                 payload_type_names, current_payload->get_type(current_payload));
                        encryption_payload->add_payload(encryption_payload,current_payload);
                }
                else
                {
-                       DBG2(SIG_DBG_ENC, "insert payload %N unencrypted",
+                       DBG2(DBG_ENC, "insert payload %N unencrypted",
                                 payload_type_names ,current_payload->get_type(current_payload));
                        add_payload(this, (payload_t*)encryption_payload);
                }
        }
 
        status = SUCCESS;
-       DBG2(SIG_DBG_ENC, "encrypting encryption payload");
+       DBG2(DBG_ENC, "encrypting encryption payload");
        encryption_payload->set_transforms(encryption_payload, crypter,signer);
        status = encryption_payload->encrypt(encryption_payload);
-       DBG2(SIG_DBG_ENC, "add encrypted payload to payload list");
+       DBG2(DBG_ENC, "add encrypted payload to payload list");
        add_payload(this, (payload_t*)encryption_payload);
        
        all_payloads->destroy(all_payloads);
@@ -694,6 +726,7 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t*
        iterator_t *iterator;
        status_t status;
        chunk_t packet_data;
+       char str[128];
        
        if (is_encoded(this))
        {
@@ -702,18 +735,19 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t*
                return SUCCESS;
        }
        
-       DBG1(SIG_DBG_ENC, "generating %M", this);
+       get_string(this, str, sizeof(str));
+       DBG1(DBG_ENC, "generating %s", str);
        
        if (this->exchange_type == EXCHANGE_TYPE_UNDEFINED)
        {
-               DBG1(SIG_DBG_ENC, "exchange type is not defined");
+               DBG1(DBG_ENC, "exchange type is not defined");
                return INVALID_STATE;
        }
        
        if (this->packet->get_source(this->packet) == NULL ||
                this->packet->get_destination(this->packet) == NULL) 
        {
-               DBG1(SIG_DBG_ENC, "%s not defined",
+               DBG1(DBG_ENC, "%s not defined",
                         !this->packet->get_source(this->packet) ? "source" : "destination");
                return INVALID_STATE;
        }
@@ -722,7 +756,7 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t*
        status = set_message_rule(this);
        if (status != SUCCESS)
        {
-               DBG1(SIG_DBG_ENC, "no message rules specified for this message type");
+               DBG1(DBG_ENC, "no message rules specified for this message type");
                return NOT_SUPPORTED;
        }
        
@@ -730,7 +764,7 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t*
        status = encrypt_payloads(this, crypter, signer);
        if (status != SUCCESS)
        {
-               DBG1(SIG_DBG_ENC, "payload encryption failed");
+               DBG1(DBG_ENC, "payload encryption failed");
                return status;
        }
        
@@ -751,9 +785,8 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t*
        
        /* generate every payload expect last one, this is doen later*/
        iterator = this->payloads->create_iterator(this->payloads, TRUE);
-       while(iterator->has_next(iterator))
+       while(iterator->iterate(iterator, (void**)&next_payload))
        {
-               iterator->current(iterator, (void**)&next_payload);
                payload->set_next_type(payload, next_payload->get_type(next_payload));
                generator->generate_payload(generator, payload);
                payload = next_payload;
@@ -774,7 +807,7 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t*
        /* if last payload is of type encrypted, integrity checksum if necessary */
        if (payload->get_type(payload) == ENCRYPTED)
        {
-               DBG2(SIG_DBG_ENC, "build signature on whole message");
+               DBG2(DBG_ENC, "build signature on whole message");
                encryption_payload_t *encryption_payload = (encryption_payload_t*)payload;
                status = encryption_payload->build_signature(encryption_payload, packet_data);
                if (status != SUCCESS)
@@ -788,7 +821,7 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t*
        /* clone packet for caller */
        *packet = this->packet->clone(this->packet);
        
-       DBG2(SIG_DBG_ENC, "message generated successfully");
+       DBG2(DBG_ENC, "message generated successfully");
        return SUCCESS;
 }
 
@@ -797,6 +830,10 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t*
  */
 static packet_t *get_packet (private_message_t *this)
 {
+       if (this->packet == NULL)
+       {
+               return NULL;
+       }
        return this->packet->clone(this->packet);
 }
 
@@ -805,6 +842,10 @@ static packet_t *get_packet (private_message_t *this)
  */
 static chunk_t get_packet_data (private_message_t *this)
 {
+       if (this->packet == NULL)
+       {
+               return chunk_empty;
+       }
        return chunk_clone(this->packet->get_data(this->packet));
 }
 
@@ -816,13 +857,13 @@ static status_t parse_header(private_message_t *this)
        ike_header_t *ike_header;
        status_t status;
        
-       DBG2(SIG_DBG_ENC, "parsing header of message");
+       DBG2(DBG_ENC, "parsing header of message");
        
        this->parser->reset_context(this->parser);
        status = this->parser->parse_payload(this->parser,HEADER,(payload_t **) &ike_header);
        if (status != SUCCESS)
        {
-               DBG1(SIG_DBG_ENC, "header could not be parsed");
+               DBG1(DBG_ENC, "header could not be parsed");
                return status;
                
        }
@@ -831,7 +872,7 @@ static status_t parse_header(private_message_t *this)
        status = ike_header->payload_interface.verify(&(ike_header->payload_interface));
        if (status != SUCCESS)
        {
-               DBG1(SIG_DBG_ENC, "header verification failed");
+               DBG1(DBG_ENC, "header verification failed");
                ike_header->destroy(ike_header);
                return status;
        }
@@ -852,7 +893,7 @@ static status_t parse_header(private_message_t *this)
        this->minor_version = ike_header->get_min_version(ike_header);
        this->first_payload = ike_header->payload_interface.get_next_type(&(ike_header->payload_interface));
        
-       DBG2(SIG_DBG_ENC, "parsed a %N %s", exchange_type_names, this->exchange_type,
+       DBG2(DBG_ENC, "parsed a %N %s", exchange_type_names, this->exchange_type,
                 this->is_request ? "request" : "response");
        
        ike_header->destroy(ike_header);
@@ -861,7 +902,7 @@ static status_t parse_header(private_message_t *this)
        status = set_message_rule(this);
        if (status != SUCCESS)
        {
-               DBG1(SIG_DBG_ENC, "no message rules specified for a %N %s",
+               DBG1(DBG_ENC, "no message rules specified for a %N %s",
                         exchange_type_names, this->exchange_type,
                         this->is_request ? "request" : "response");
        }
@@ -878,24 +919,21 @@ static status_t decrypt_payloads(private_message_t *this,crypter_t *crypter, sig
        payload_t *previous_payload = NULL;
        int payload_number = 1;
        iterator_t *iterator;
+       payload_t *current_payload;
        status_t status;
 
        iterator = this->payloads->create_iterator(this->payloads,TRUE);
 
        /* process each payload and decrypt a encryption payload */
-       while(iterator->has_next(iterator))
+       while(iterator->iterate(iterator, (void**)&current_payload))
        {
                payload_rule_t *payload_rule;
                payload_type_t current_payload_type;
-               payload_t *current_payload;
-
-               /* get current payload */               
-               iterator->current(iterator,(void **)&current_payload);
                
                /* needed to check */
                current_payload_type = current_payload->get_type(current_payload);
                
-               DBG2(SIG_DBG_ENC, "process payload of type %N",
+               DBG2(DBG_ENC, "process payload of type %N",
                         payload_type_names, current_payload_type);
                
                if (current_payload_type == ENCRYPTED)
@@ -905,31 +943,31 @@ static status_t decrypt_payloads(private_message_t *this,crypter_t *crypter, sig
                        
                        encryption_payload = (encryption_payload_t*)current_payload;
                        
-                       DBG2(SIG_DBG_ENC, "found an encryption payload");
+                       DBG2(DBG_ENC, "found an encryption payload");
 
                        if (payload_number != this->payloads->get_count(this->payloads))
                        {
                                /* encrypted payload is not last one */
-                               DBG1(SIG_DBG_ENC, "encrypted payload is not last payload");
+                               DBG1(DBG_ENC, "encrypted payload is not last payload");
                                iterator->destroy(iterator);
                                return VERIFY_ERROR;
                        }
                        /* decrypt */
                        encryption_payload->set_transforms(encryption_payload, crypter, signer);
-                       DBG2(SIG_DBG_ENC, "verify signature of encryption payload");
+                       DBG2(DBG_ENC, "verify signature of encryption payload");
                        status = encryption_payload->verify_signature(encryption_payload,
                                                                                this->packet->get_data(this->packet));
                        if (status != SUCCESS)
                        {
-                               DBG1(SIG_DBG_ENC, "encryption payload signature invalid");
+                               DBG1(DBG_ENC, "encryption payload signature invalid");
                                iterator->destroy(iterator);
                                return FAILED;
                        }
-                       DBG2(SIG_DBG_ENC, "decrypting content of encryption payload");
+                       DBG2(DBG_ENC, "decrypting content of encryption payload");
                        status = encryption_payload->decrypt(encryption_payload);
                        if (status != SUCCESS)
                        {
-                               DBG1(SIG_DBG_ENC, "encrypted payload could not be decrypted and parsed");
+                               DBG1(DBG_ENC, "encrypted payload could not be decrypted and parsed");
                                iterator->destroy(iterator);
                                return PARSE_ERROR;
                        }
@@ -940,7 +978,7 @@ static status_t decrypt_payloads(private_message_t *this,crypter_t *crypter, sig
                        /* check if there are payloads contained in the encryption payload */
                        if (encryption_payload->get_payload_count(encryption_payload) == 0)
                        {
-                               DBG2(SIG_DBG_ENC, "encrypted payload is empty");
+                               DBG2(DBG_ENC, "encrypted payload is empty");
                                /* remove the encryption payload, is not needed anymore */
                                iterator->remove(iterator);
                                /* encrypted payload contains no other payload */
@@ -970,7 +1008,7 @@ static status_t decrypt_payloads(private_message_t *this,crypter_t *crypter, sig
                        while (encryption_payload->get_payload_count(encryption_payload) > 0)
                        {
                                encryption_payload->remove_first_payload(encryption_payload, &current_encrypted_payload);
-                               DBG2(SIG_DBG_ENC, "insert unencrypted payload of type %N at end of list",
+                               DBG2(DBG_ENC, "insert unencrypted payload of type %N at end of list",
                                         payload_type_names, current_encrypted_payload->get_type(current_encrypted_payload));
                                this->payloads->insert_last(this->payloads,current_encrypted_payload);
                        }
@@ -987,7 +1025,7 @@ static status_t decrypt_payloads(private_message_t *this,crypter_t *crypter, sig
                        if (status != SUCCESS)
                        {
                                /* payload is not allowed */
-                               DBG1(SIG_DBG_ENC, "payload type %N not allowed",
+                               DBG1(DBG_ENC, "payload type %N not allowed",
                                                                  payload_type_names, current_payload_type);
                                iterator->destroy(iterator);
                                return VERIFY_ERROR;
@@ -997,7 +1035,7 @@ static status_t decrypt_payloads(private_message_t *this,crypter_t *crypter, sig
                        if (payload_rule->encrypted != current_payload_was_encrypted)
                        {
                                /* payload was not encrypted, but should have been. or vice-versa */
-                               DBG1(SIG_DBG_ENC, "payload type %N should be %s!",
+                               DBG1(DBG_ENC, "payload type %N should be %s!",
                                         payload_type_names, current_payload_type,
                                         (payload_rule->encrypted) ? "encrypted" : "not encrypted");
                                iterator->destroy(iterator);
@@ -1020,9 +1058,10 @@ static status_t verify(private_message_t *this)
 {
        int i;
        iterator_t *iterator;
+       payload_t *current_payload;
        size_t total_found_payloads = 0;
        
-       DBG2(SIG_DBG_ENC, "verifying message structure");
+       DBG2(DBG_ENC, "verifying message structure");
        
        iterator = this->payloads->create_iterator(this->payloads,TRUE);
        /* check for payloads with wrong count*/
@@ -1033,21 +1072,18 @@ static status_t verify(private_message_t *this)
                /* check all payloads for specific rule */
                iterator->reset(iterator);
                
-               while(iterator->has_next(iterator))
+               while(iterator->iterate(iterator,(void **)&current_payload))
                {
-                       payload_t *current_payload;
                        payload_type_t current_payload_type;
                        
-                       iterator->current(iterator,(void **)&current_payload);
                        current_payload_type = current_payload->get_type(current_payload);
-                       
                        if (current_payload_type == UNKNOWN_PAYLOAD)
                        {
                                /* unknown payloads are ignored, IF they are not critical */
                                unknown_payload_t *unknown_payload = (unknown_payload_t*)current_payload;
                                if (unknown_payload->is_critical(unknown_payload))
                                {
-                                       DBG1(SIG_DBG_ENC, "%N is not supported, but its critical!",
+                                       DBG1(DBG_ENC, "%N is not supported, but its critical!",
                                                 payload_type_names, current_payload_type);
                                        iterator->destroy(iterator);
                                        return NOT_SUPPORTED;   
@@ -1057,13 +1093,13 @@ static status_t verify(private_message_t *this)
                        {
                                found_payloads++;
                                total_found_payloads++;
-                               DBG2(SIG_DBG_ENC, "found payload of type %N",
+                               DBG2(DBG_ENC, "found payload of type %N",
                                         payload_type_names, this->message_rule->payload_rules[i].payload_type);
                                
                                /* as soon as ohe payload occures more then specified, the verification fails */
                                if (found_payloads > this->message_rule->payload_rules[i].max_occurence)
                                {
-                                       DBG1(SIG_DBG_ENC, "payload of type %N more than %d times (%d) occured in current message",
+                                       DBG1(DBG_ENC, "payload of type %N more than %d times (%d) occured in current message",
                                                 payload_type_names, current_payload_type,
                                                 this->message_rule->payload_rules[i].max_occurence, found_payloads);
                                        iterator->destroy(iterator);
@@ -1074,7 +1110,7 @@ static status_t verify(private_message_t *this)
                
                if (found_payloads < this->message_rule->payload_rules[i].min_occurence)
                {
-                       DBG1(SIG_DBG_ENC, "payload of type %N not occured %d times (%d)",
+                       DBG1(DBG_ENC, "payload of type %N not occured %d times (%d)",
                                 payload_type_names, this->message_rule->payload_rules[i].payload_type,
                                 this->message_rule->payload_rules[i].min_occurence, found_payloads);
                        iterator->destroy(iterator);
@@ -1097,10 +1133,11 @@ static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t
 {
        status_t status = SUCCESS;
        payload_type_t current_payload_type;
+       char str[128];
                
        current_payload_type = this->first_payload;     
                
-       DBG2(SIG_DBG_ENC, "parsing body of message, first payload is %N",
+       DBG2(DBG_ENC, "parsing body of message, first payload is %N",
                 payload_type_names, current_payload_type);
 
        /* parse payload for payload, while there are more available */
@@ -1108,7 +1145,7 @@ static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t
        {
                payload_t *current_payload;
                
-               DBG2(SIG_DBG_ENC, "starting parsing a %N payload", 
+               DBG2(DBG_ENC, "starting parsing a %N payload", 
                         payload_type_names, current_payload_type);
                
                /* parse current payload */
@@ -1116,32 +1153,32 @@ static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t
                
                if (status != SUCCESS)
                {
-                       DBG1(SIG_DBG_ENC, "payload type %N could not be parsed",
+                       DBG1(DBG_ENC, "payload type %N could not be parsed",
                                 payload_type_names, current_payload_type);
                        return PARSE_ERROR;
                }
 
-               DBG2(SIG_DBG_ENC, "verifying payload of type %N",
+               DBG2(DBG_ENC, "verifying payload of type %N",
                         payload_type_names, current_payload_type);
                
                /* verify it, stop parsig if its invalid */
                status = current_payload->verify(current_payload);
                if (status != SUCCESS)
                {
-                       DBG1(SIG_DBG_ENC, "%N payload verification failed",
+                       DBG1(DBG_ENC, "%N payload verification failed",
                                 payload_type_names, current_payload_type);
                        current_payload->destroy(current_payload);
                        return VERIFY_ERROR;
                }
                
-               DBG2(SIG_DBG_ENC, "%N payload verified. Adding to payload list",
+               DBG2(DBG_ENC, "%N payload verified. Adding to payload list",
                         payload_type_names, current_payload_type);
                this->payloads->insert_last(this->payloads,current_payload);
                
                /* an encryption payload is the last one, so STOP here. decryption is done later */
                if (current_payload_type == ENCRYPTED)
                {
-                       DBG2(SIG_DBG_ENC, "%N payload found. Stop parsing",
+                       DBG2(DBG_ENC, "%N payload found. Stop parsing",
                                 payload_type_names, current_payload_type);
                        break;
                }
@@ -1155,7 +1192,7 @@ static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t
                status = decrypt_payloads(this,crypter,signer);
                if (status != SUCCESS)
                {
-                       DBG1(SIG_DBG_ENC, "could not decrypt payloads");
+                       DBG1(DBG_ENC, "could not decrypt payloads");
                        return status;
                }
        }
@@ -1163,11 +1200,11 @@ static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t
        status = verify(this);
        if (status != SUCCESS)
        {
-               DBG1(SIG_DBG_ENC, "verification of message failed");
                return status;
        }
        
-       DBG1(SIG_DBG_ENC, "parsed %M", this);
+       get_string(this, str, sizeof(str));
+       DBG1(DBG_ENC, "parsed %s", str);
        
        return SUCCESS;
 }
@@ -1177,26 +1214,10 @@ static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t
  */
 static void destroy (private_message_t *this)
 {
-       iterator_t *iterator;
-       
+       DESTROY_IF(this->ike_sa_id);
+       this->payloads->destroy_offset(this->payloads, offsetof(payload_t, destroy));
        this->packet->destroy(this->packet);
-
-       if (this->ike_sa_id != NULL)
-       {
-               this->ike_sa_id->destroy(this->ike_sa_id);
-       }
-       
-       iterator = this->payloads->create_iterator(this->payloads, TRUE);
-       while (iterator->has_next(iterator))
-       {
-               payload_t *payload;
-               iterator->current(iterator, (void**)&payload);  
-               payload->destroy(payload);
-       }
-       iterator->destroy(iterator);
-       this->payloads->destroy(this->payloads);
        this->parser->destroy(this->parser);
-       
        free(this);
 }
 
@@ -1223,12 +1244,14 @@ message_t *message_create_from_packet(packet_t *packet)
        this->public.set_request = (void(*)(message_t*, bool))set_request;
        this->public.get_request = (bool(*)(message_t*))get_request;
        this->public.add_payload = (void(*)(message_t*,payload_t*))add_payload;
+       this->public.add_notify = (void(*)(message_t*,bool,notify_type_t,chunk_t))add_notify;
        this->public.generate = (status_t (*) (message_t *,crypter_t*,signer_t*,packet_t**)) generate;
        this->public.set_source = (void (*) (message_t*,host_t*)) set_source;
        this->public.get_source = (host_t * (*) (message_t*)) get_source;
        this->public.set_destination = (void (*) (message_t*,host_t*)) set_destination;
        this->public.get_destination = (host_t * (*) (message_t*)) get_destination;
        this->public.get_payload_iterator = (iterator_t * (*) (message_t *)) get_payload_iterator;
+       this->public.get_payload = (payload_t * (*) (message_t *, payload_type_t)) get_payload;
        this->public.parse_header = (status_t (*) (message_t *)) parse_header;
        this->public.parse_body = (status_t (*) (message_t *,crypter_t*,signer_t*)) parse_body;
        this->public.get_packet = (packet_t * (*) (message_t*)) get_packet;