generator rewritten (no memory allocation test anymore)
[strongswan.git] / Source / charon / encoding / generator.c
index 734c089..e1da403 100644 (file)
 #include <encoding/payloads/notify_payload.h>
 #include <encoding/payloads/nonce_payload.h>
 
+
+typedef struct private_generator_t private_generator_t;
+
 /**
- * Private part of a generator_t object
+ * Private part of a generator_t object.
  */
-typedef struct private_generator_s private_generator_t;
-
-struct private_generator_s {
+struct private_generator_t {
        /**
-        * Public part of a generator_t object
+        * Public part of a generator_t object.
         */
         generator_t public;
 
@@ -63,10 +64,11 @@ struct private_generator_s {
         *                                                              ATTRIBUTE_TYPE is also generated in this function
         * @param offset                                offset of value in data struct
         * @param generator_contexts            generator_contexts_t object where the context is written or read from
-        * @return                                              - SUCCESS if succeeded
-        *                                                              - OUT_OF_RES if out of ressources
+        * @return
+        *                                                              - SUCCESS
+        *                                                              - FAILED if allignment is wrong
         */
-       status_t (*generate_u_int_type) (private_generator_t *this,encoding_type_t int_type,u_int32_t offset);
+       void (*generate_u_int_type) (private_generator_t *this,encoding_type_t int_type,u_int32_t offset);
 
        /**
         * Get size of current buffer in bytes.
@@ -107,11 +109,8 @@ struct private_generator_s {
         * @param this                                  private_generator_t object
         * @param generator_contexts            generator_contexts_t object where the context is written or read from
         * @param bits                                  number of bits to generate
-        * @return                                              - SUCCESS if succeeded
-        *                                                              - OUT_OF_RES if out of ressources
-        *                                                              - FAILED if bit count not supported
         */
-       status_t (*generate_reserved_field) (private_generator_t *this,int bits);
+       void (*generate_reserved_field) (private_generator_t *this,int bits);
        
        /**
         * Generates a FLAG field
@@ -119,10 +118,8 @@ struct private_generator_s {
         * @param this                                  private_generator_t object
         * @param generator_contexts            generator_contexts_t object where the context is written or read from
         * @param offset                                        offset of flag value in data struct
-        * @return                                              - SUCCESS if succeeded
-        *                                                              - OUT_OF_RES if out of ressources
         */
-       status_t (*generate_flag) (private_generator_t *this,u_int32_t offset);
+       void (*generate_flag) (private_generator_t *this,u_int32_t offset);
        
        /**
         * Writes the current buffer content into a chunk_t
@@ -131,21 +128,16 @@ struct private_generator_s {
         *
         * @param this                          calling private_generator_t object
         * @param data                          pointer of chunk_t to write to
-        * @return 
-        *                                                      - SUCCESSFUL if succeeded
-        *                                                      - OUT_OF_RES otherwise
         */
-       status_t (*write_chunk) (private_generator_t *this,chunk_t *data);
+       void (*write_chunk) (private_generator_t *this,chunk_t *data);
        
        /**
         * Generates a bytestream from a chunk_t
         *
         * @param this                                  private_generator_t object
         * @param offset                                        offset of chunk_t value in data struct
-        * @return                                              - SUCCESS if succeeded
-        *                                                              - OUT_OF_RES if out of ressources
         */
-       status_t (*generate_from_chunk) (private_generator_t *this,u_int32_t offset);   
+       void (*generate_from_chunk) (private_generator_t *this,u_int32_t offset);       
 
        /**
         * Makes sure enough space is available in buffer to store amount of bits.
@@ -155,11 +147,8 @@ struct private_generator_s {
         *
         * @param this                          calling private_generator_t object
         * @param bits                          number of bits to make available in buffer
-        * @return 
-        *                                                      - SUCCESSFUL if succeeded
-        *                                                      - OUT_OF_RES otherwise
         */
-       status_t (*make_space_available) (private_generator_t *this,size_t bits);
+       void (*make_space_available) (private_generator_t *this,size_t bits);
 
        /**
         * Writes a specific amount of byte into the buffer.
@@ -170,11 +159,8 @@ struct private_generator_s {
         * @param this                          calling private_generator_t object
         * @param bytes                                 pointer to bytes to write
         * @param number_of_bytes       number of bytes to write into buffer
-        * @return 
-        *                                                      - SUCCESSFUL if succeeded
-        *                                                      - OUT_OF_RES otherwise
         */
-       status_t (*write_bytes_to_buffer) (private_generator_t *this,void * bytes,size_t number_of_bytes);
+       void (*write_bytes_to_buffer) (private_generator_t *this,void * bytes,size_t number_of_bytes);
        
        
        /**
@@ -186,11 +172,8 @@ struct private_generator_s {
         * @param bytes                                 pointer to bytes to write
         * @param number_of_bytes       number of bytes to write into buffer
         * @param offset                                offset to write the data into
-        * @return 
-        *                                                      - SUCCESSFUL if succeeded
-        *                                                      - OUT_OF_RES otherwise
         */
-       status_t (*write_bytes_to_buffer_at_offset) (private_generator_t *this,void * bytes,size_t number_of_bytes,u_int32_t offset);
+       void (*write_bytes_to_buffer_at_offset) (private_generator_t *this,void * bytes,size_t number_of_bytes,u_int32_t offset);
        
        /**
         * Buffer used to generate the data into.
@@ -295,10 +278,9 @@ static u_int32_t get_current_buffer_offset (private_generator_t *this)
  * Implements private_generator_t's generate_u_int_type function.
  * See #private_generator_s.generate_u_int_type.
  */
-static status_t generate_u_int_type (private_generator_t *this,encoding_type_t int_type,u_int32_t offset)
+static void generate_u_int_type (private_generator_t *this,encoding_type_t int_type,u_int32_t offset)
 {
        size_t number_of_bits = 0;
-       status_t status;
 
        /* find out number of bits of each U_INT type to check for enough space 
           in buffer */
@@ -327,7 +309,10 @@ static status_t generate_u_int_type (private_generator_t *this,encoding_type_t i
                                break;
 
                        default:
-                       return FAILED;
+                       this->logger->log(this->logger, ERROR, "U_INT Type %s is not supported", 
+                                                       mapping_find(encoding_type_m,int_type));
+
+                       return;
        }
        /* U_INT Types of multiple then 8 bits must be aligned */
        if (((number_of_bits % 8) == 0) && (this->current_bit != 0))
@@ -335,147 +320,137 @@ static status_t generate_u_int_type (private_generator_t *this,encoding_type_t i
                this->logger->log(this->logger, ERROR, "U_INT Type %s is not 8 Bit aligned", 
                                                        mapping_find(encoding_type_m,int_type));
                /* current bit has to be zero for values multiple of 8 bits */
-               return FAILED;
+               return;
        }
        
        /* make sure enough space is available in buffer */
-       status = this->make_space_available(this,number_of_bits);
-       if (status != SUCCESS)
-       {
-               return status;
-       }
+       this->make_space_available(this,number_of_bits);
        /* now handle each u int type differently */
        switch (int_type)
        {
-                       case U_INT_4:
+               case U_INT_4:
+               {
+                       if (this->current_bit == 0)
                        {
-                               if (this->current_bit == 0)
-                               {
-                                       /* highval of current byte in buffer has to be set to the new value*/
-                                       u_int8_t high_val = *((u_int8_t *)(this->data_struct + offset)) << 4;
-                                       /* lowval in buffer is not changed */
-                                       u_int8_t low_val = *(this->out_position) & 0x0F;
-                                       /* highval is set, low_val is not changed */
-                                       *(this->out_position) = high_val | low_val;
-                                       this->logger->log(this->logger, RAW|MOST, "   => 0x%x", *(this->out_position));
-                                       /* write position is not changed, just bit position is moved */
-                                       this->current_bit = 4;
-                               }
-                               else if (this->current_bit == 4)
-                               {
-                                       /* highval in buffer is not changed */
-                                       u_int high_val = *(this->out_position) & 0xF0;
-                                       /* lowval of current byte in buffer has to be set to the new value*/
-                                       u_int low_val = *((u_int8_t *)(this->data_struct + offset)) & 0x0F;
-                                       *(this->out_position) = high_val | low_val;
-                                       this->logger->log(this->logger, RAW|MOST, "   => 0x%x", *(this->out_position));
-                                       this->out_position++;
-                                       this->current_bit = 0;
-
-                               }
-                               else
-                               {
-                                       this->logger->log(this->logger, ERROR, "U_INT_4 Type is not 4 Bit aligned");
-                                       /* 4 Bit integers must have a 4 bit alignment */
-                                       return FAILED;
-                               };
-                               break;
+                               /* highval of current byte in buffer has to be set to the new value*/
+                               u_int8_t high_val = *((u_int8_t *)(this->data_struct + offset)) << 4;
+                               /* lowval in buffer is not changed */
+                               u_int8_t low_val = *(this->out_position) & 0x0F;
+                               /* highval is set, low_val is not changed */
+                               *(this->out_position) = high_val | low_val;
+                               this->logger->log(this->logger, RAW|MOST, "   => 0x%x", *(this->out_position));
+                               /* write position is not changed, just bit position is moved */
+                               this->current_bit = 4;
                        }
-                       case U_INT_8:
+                       else if (this->current_bit == 4)
                        {
-                               /* 8 bit values are written as they are */
-                               *this->out_position = *((u_int8_t *)(this->data_struct + offset));
+                               /* highval in buffer is not changed */
+                               u_int high_val = *(this->out_position) & 0xF0;
+                               /* lowval of current byte in buffer has to be set to the new value*/
+                               u_int low_val = *((u_int8_t *)(this->data_struct + offset)) & 0x0F;
+                               *(this->out_position) = high_val | low_val;
                                this->logger->log(this->logger, RAW|MOST, "   => 0x%x", *(this->out_position));
                                this->out_position++;
-                               break;
-
-                       }
-                       case ATTRIBUTE_TYPE:
-                       {
-                               /* attribute type must not change first bit uf current byte ! */
-                               if (this->current_bit != 1)
-                               {
-                                       this->logger->log(this->logger, ERROR, "ATTRIBUTE FORMAT flag is not set");
-                                       /* first bit has to be set! */
-                                       return FAILED;
-                               }
-                               /* get value of attribute format flag */
-                               u_int8_t attribute_format_flag = *(this->out_position) & 0x80;
-                               /* get attribute type value as 16 bit integer*/
-                               u_int16_t int16_val = htons(*((u_int16_t*)(this->data_struct + offset)));
-                               /* last bit must be unset */
-                               int16_val = int16_val & 0xFF7F;
-                               
-                               int16_val = int16_val | attribute_format_flag;
-                               this->logger->log(this->logger, RAW|MOST, "   => 0x%x", int16_val);
-                               /* write bytes to buffer (set bit is overwritten)*/                             
-                               this->write_bytes_to_buffer(this,&int16_val,sizeof(u_int16_t));
                                this->current_bit = 0;
-                               break;
-                               
+
                        }
-                       case U_INT_16:
+                       else
                        {
-                               u_int16_t int16_val = htons(*((u_int16_t*)(this->data_struct + offset)));
-                               this->logger->log_bytes(this->logger, RAW|MOST, "   =>", (void*)&int16_val, sizeof(int16_val));
-                               this->write_bytes_to_buffer(this,&int16_val,sizeof(u_int16_t));
-                               break;
-                       }
-                       case U_INT_32:
+                               this->logger->log(this->logger, ERROR, "U_INT_4 Type is not 4 Bit aligned");
+                               /* 4 Bit integers must have a 4 bit alignment */
+                               return;
+                       };
+                       break;
+               }
+               case U_INT_8:
+               {
+                       /* 8 bit values are written as they are */
+                       *this->out_position = *((u_int8_t *)(this->data_struct + offset));
+                       this->logger->log(this->logger, RAW|MOST, "   => 0x%x", *(this->out_position));
+                       this->out_position++;
+                       break;
+
+               }
+               case ATTRIBUTE_TYPE:
+               {
+                       /* attribute type must not change first bit uf current byte ! */
+                       if (this->current_bit != 1)
                        {
-                               u_int32_t int32_val = htonl(*((u_int32_t*)(this->data_struct + offset)));
-                               this->logger->log_bytes(this->logger, RAW|MOST, "   =>", (void*)&int32_val, sizeof(int32_val));
-                               this->write_bytes_to_buffer(this,&int32_val,sizeof(u_int32_t));
-                               break;
-                       }
-                       case U_INT_64:
-                       {
-                               /* 64 bit integers are written as two 32 bit integers */
-                               u_int32_t int32_val_low = htonl(*((u_int32_t*)(this->data_struct + offset)));
-                               u_int32_t int32_val_high = htonl(*((u_int32_t*)(this->data_struct + offset) + 1));
-                               this->logger->log_bytes(this->logger, RAW|MOST, "   => (low)", (void*)&int32_val_low, sizeof(int32_val_low));
-                               this->logger->log_bytes(this->logger, RAW|MOST, "   => (high)", (void*)&int32_val_high, sizeof(int32_val_high));
-                               /* TODO add support for big endian machines */
-                               this->write_bytes_to_buffer(this,&int32_val_high,sizeof(u_int32_t));
-                               this->write_bytes_to_buffer(this,&int32_val_low,sizeof(u_int32_t));
-                               break;
+                               this->logger->log(this->logger, ERROR, "ATTRIBUTE FORMAT flag is not set");
+                               /* first bit has to be set! */
+                               return;
                        }
+                       /* get value of attribute format flag */
+                       u_int8_t attribute_format_flag = *(this->out_position) & 0x80;
+                       /* get attribute type value as 16 bit integer*/
+                       u_int16_t int16_val = htons(*((u_int16_t*)(this->data_struct + offset)));
+                       /* last bit must be unset */
+                       int16_val = int16_val & 0xFF7F;
                        
-                       case IKE_SPI:
-                       {
-                               /* 64 bit are written as they come :-) */
-                               this->write_bytes_to_buffer(this,(this->data_struct + offset),sizeof(u_int64_t));
-                               this->logger->log_bytes(this->logger, RAW|MOST, "   =>", (void*)(this->data_struct + offset), sizeof(u_int64_t));
-                               break;
-                       }
-
-                       default:
+                       int16_val = int16_val | attribute_format_flag;
+                       this->logger->log(this->logger, RAW|MOST, "   => 0x%x", int16_val);
+                       /* write bytes to buffer (set bit is overwritten)*/                             
+                       this->write_bytes_to_buffer(this,&int16_val,sizeof(u_int16_t));
+                       this->current_bit = 0;
+                       break;
+                       
+               }
+               case U_INT_16:
+               {
+                       u_int16_t int16_val = htons(*((u_int16_t*)(this->data_struct + offset)));
+                       this->logger->log_bytes(this->logger, RAW|MOST, "   =>", (void*)&int16_val, sizeof(int16_val));
+                       this->write_bytes_to_buffer(this,&int16_val,sizeof(u_int16_t));
+                       break;
+               }
+               case U_INT_32:
+               {
+                       u_int32_t int32_val = htonl(*((u_int32_t*)(this->data_struct + offset)));
+                       this->logger->log_bytes(this->logger, RAW|MOST, "   =>", (void*)&int32_val, sizeof(int32_val));
+                       this->write_bytes_to_buffer(this,&int32_val,sizeof(u_int32_t));
+                       break;
+               }
+               case U_INT_64:
+               {
+                       /* 64 bit integers are written as two 32 bit integers */
+                       u_int32_t int32_val_low = htonl(*((u_int32_t*)(this->data_struct + offset)));
+                       u_int32_t int32_val_high = htonl(*((u_int32_t*)(this->data_struct + offset) + 1));
+                       this->logger->log_bytes(this->logger, RAW|MOST, "   => (low)", (void*)&int32_val_low, sizeof(int32_val_low));
+                       this->logger->log_bytes(this->logger, RAW|MOST, "   => (high)", (void*)&int32_val_high, sizeof(int32_val_high));
+                       /* TODO add support for big endian machines */
+                       this->write_bytes_to_buffer(this,&int32_val_high,sizeof(u_int32_t));
+                       this->write_bytes_to_buffer(this,&int32_val_low,sizeof(u_int32_t));
+                       break;
+               }
+               
+               case IKE_SPI:
+               {
+                       /* 64 bit are written as they come :-) */
+                       this->write_bytes_to_buffer(this,(this->data_struct + offset),sizeof(u_int64_t));
+                       this->logger->log_bytes(this->logger, RAW|MOST, "   =>", (void*)(this->data_struct + offset), sizeof(u_int64_t));
+                       break;
+               }
+               default:
+               {
                        this->logger->log(this->logger, ERROR, "U_INT Type %s is not supported", mapping_find(encoding_type_m,int_type));
-                       return FAILED;
+                       return;
+               }
        }
-       return SUCCESS;
 }
 
 /**
  * Implements private_generator_t's generate_reserved_field function.
  * See #private_generator_s.generate_reserved_field.
  */
-static status_t generate_reserved_field(private_generator_t *this,int bits)
+static void generate_reserved_field(private_generator_t *this,int bits)
 {
-       status_t status;
-       
        /* only one bit or 8 bit fields are supported */
        if ((bits != 1) && (bits != 8))
        {
                this->logger->log(this->logger, ERROR, "Reserved field of %d bits cannot be generated", bits);
-               return FAILED;
+               return ;
        }
        /* make sure enough space is available in buffer */
-       status = this->make_space_available(this,bits);
-       if (status != SUCCESS)
-       {
-               return status;
-       }
+       this->make_space_available(this,bits);
        
        if (bits == 1)
        {       
@@ -504,24 +479,19 @@ static status_t generate_reserved_field(private_generator_t *this,int bits)
                        this->logger->log(this->logger, ERROR, 
                                                                "Reserved field cannot be written cause allignement of current bit is %d",
                                                                this->current_bit);
-                       return FAILED;
+                       return;
                }
                *(this->out_position) = 0x00;
                this->out_position++;
        }
-
-       return SUCCESS;
-               
-               
 }
 
 /**
  * Implements private_generator_t's generate_flag function.
  * See #private_generator_s.generate_flag.
  */
-static status_t generate_flag (private_generator_t *this,u_int32_t offset)
+static void generate_flag (private_generator_t *this,u_int32_t offset)
 {
-       status_t status;
        /* value of current flag */
        u_int8_t flag_value;
        /* position of flag in current byte */
@@ -533,11 +503,7 @@ static status_t generate_flag (private_generator_t *this,u_int32_t offset)
        flag = (flag_value << (7 - this->current_bit));
        
        /* make sure one bit is available in buffer */
-       status = this->make_space_available(this,1);
-       if (status != SUCCESS)
-       {
-               return status;
-       }
+       this->make_space_available(this,1);
        if (this->current_bit == 0)
        {
                /* memory must be zero */
@@ -555,19 +521,18 @@ static status_t generate_flag (private_generator_t *this,u_int32_t offset)
                this->current_bit = this->current_bit % 8;
                this->out_position++;
        }
-       return SUCCESS;
 }
 
 /**
  * Implements private_generator_t's generate_from_chunk function.
  * See #private_generator_s.generate_from_chunk.
  */
-static status_t generate_from_chunk (private_generator_t *this,u_int32_t offset)
+static void generate_from_chunk (private_generator_t *this,u_int32_t offset)
 {
        if (this->current_bit != 0)
        {
                this->logger->log(this->logger, ERROR, "can not generate a chunk at Bitpos %d", this->current_bit);
-               return FAILED;
+               return ;
        }
        
        /* position in buffer */
@@ -576,15 +541,14 @@ static status_t generate_from_chunk (private_generator_t *this,u_int32_t offset)
        this->logger->log_chunk(this->logger, RAW|MOST, "   =>", attribute_value);
        
        /* use write_bytes_to_buffer function to do the job */
-       return this->write_bytes_to_buffer(this,attribute_value->ptr,attribute_value->len);
-       
+       this->write_bytes_to_buffer(this,attribute_value->ptr,attribute_value->len);
 }
 
 /**
  * Implements private_generator_t's generator_context_make_space_available function.
  * See #private_generator_s.generator_context_make_space_available.
  */
-static status_t make_space_available (private_generator_t *this, size_t bits)
+static void make_space_available (private_generator_t *this, size_t bits)
 {
        while (((this->get_current_buffer_space(this) * 8) - this->current_bit) < bits)
        {
@@ -602,7 +566,6 @@ static status_t make_space_available (private_generator_t *this, size_t bits)
                if (new_buffer == NULL)
                {
                        this->logger->log(this->logger, ERROR, "reallocation of gen buffer failed!!!");
-                       return OUT_OF_RES;
                }
 
                this->buffer = new_buffer;
@@ -610,24 +573,18 @@ static status_t make_space_available (private_generator_t *this, size_t bits)
                this->out_position = (this->buffer + out_position_offset);
                this->roof_position = (this->buffer + new_buffer_size);
        }
-       return SUCCESS;
 }
 
 /**
  * Implements private_generator_t's write_bytes_to_buffer function.
  * See #private_generator_s.write_bytes_to_buffer.
  */
-static status_t write_bytes_to_buffer (private_generator_t *this,void * bytes, size_t number_of_bytes)
+static void write_bytes_to_buffer (private_generator_t *this,void * bytes, size_t number_of_bytes)
 {
        int i;
-       status_t status;
        u_int8_t *read_position = (u_int8_t *) bytes;
        
-       status = this->make_space_available(this,number_of_bytes * 8);
-       if (status != SUCCESS)
-       {
-               return status;
-       }
+       this->make_space_available(this,number_of_bytes * 8);
 
        for (i = 0; i < number_of_bytes; i++)
        {
@@ -635,17 +592,15 @@ static status_t write_bytes_to_buffer (private_generator_t *this,void * bytes, s
                read_position++;
                this->out_position++;
        }
-       return status;
 }
 
 /**
  * Implements private_generator_t's write_bytes_to_buffer_at_offset function.
  * See #private_generator_s.write_bytes_to_buffer_at_offset.
  */
-static status_t write_bytes_to_buffer_at_offset (private_generator_t *this,void * bytes,size_t number_of_bytes,u_int32_t offset)
+static void write_bytes_to_buffer_at_offset (private_generator_t *this,void * bytes,size_t number_of_bytes,u_int32_t offset)
 {
        int i;
-       status_t status;
        u_int8_t *read_position = (u_int8_t *) bytes;
        u_int8_t *write_position;
        u_int32_t free_space_after_offset = (this->get_current_buffer_size(this) - offset);
@@ -653,7 +608,7 @@ static status_t write_bytes_to_buffer_at_offset (private_generator_t *this,void
        /* check first if enough space for new data is available */     
        if (number_of_bytes > free_space_after_offset)
        {
-               status = this->make_space_available(this,(number_of_bytes - free_space_after_offset) * 8);
+               this->make_space_available(this,(number_of_bytes - free_space_after_offset) * 8);
        }
        
        write_position = this->buffer + offset;
@@ -663,14 +618,14 @@ static status_t write_bytes_to_buffer_at_offset (private_generator_t *this,void
                read_position++;
                write_position++;
        }
-       return SUCCESS;
+
 }
 
 /**
  * Implements generator_t's write_chunk function.
  * See #generator_s.write_chunk.
  */
-static status_t write_to_chunk (private_generator_t *this,chunk_t *data)
+static void write_to_chunk (private_generator_t *this,chunk_t *data)
 {
        size_t data_length = this->get_current_data_length(this);
        u_int32_t header_length_field = data_length;
@@ -685,28 +640,19 @@ static status_t write_to_chunk (private_generator_t *this,chunk_t *data)
        if (this->current_bit > 0)
        data_length++;
        data->ptr = allocator_alloc(data_length);
-       if (data->ptr == NULL)
-       {
-               data->len = 0;
-               this->logger->log(this->logger, ERROR, "not enougth ressources to allocate chunk");
-               return OUT_OF_RES;
-       }
        memcpy(data->ptr,this->buffer,data_length);
        data->len = data_length;
        
        this->logger->log_chunk(this->logger, RAW, "generated data of this parser", data);
-       
-       return SUCCESS;
 }
 
 /**
  * Implements generator_t's generate_payload function.
  * See #generator_s.generate_payload.
  */
-static status_t generate_payload (private_generator_t *this,payload_t *payload)
+static void generate_payload (private_generator_t *this,payload_t *payload)
 {
        int i;
-       status_t status;
        this->data_struct = payload;
        size_t rule_count;
        encoding_rule_t *rules;
@@ -721,14 +667,13 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
        payload_start = this->out_position;
        
        this->logger->log(this->logger, CONTROL, "generating payload of type %s",
-                                               mapping_find(payload_type_m,payload_type));
+                                                                                       mapping_find(payload_type_m,payload_type));
        
        /* each payload has its own encoding rules */
        payload->get_encoding_rules(payload,&rules,&rule_count);
 
        for (i = 0; i < rule_count;i++)
        {
-               status = SUCCESS;
                this->logger->log(this->logger, CONTROL|MORE, "  generating rule %d %s",
                                                        i, mapping_find(encoding_type_m,rules[i].type));
                switch (rules[i].type)
@@ -742,22 +687,22 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                        case IKE_SPI:
                        case ATTRIBUTE_TYPE:
                        {
-                               status = this->generate_u_int_type(this,rules[i].type,rules[i].offset);
+                               this->generate_u_int_type(this,rules[i].type,rules[i].offset);
                                break;
                        }
                        case RESERVED_BIT:
                        {
-                               status = this->generate_reserved_field(this,1);
+                               this->generate_reserved_field(this,1);
                                break;
                        }
                        case RESERVED_BYTE:
                        {
-                               status = this->generate_reserved_field(this,8);
+                               this->generate_reserved_field(this,8);
                                break;
                        } 
                        case FLAG:
                        {
-                               status = this->generate_flag(this,rules[i].offset);
+                               this->generate_flag(this,rules[i].offset);
                                break;
                        }
                        case PAYLOAD_LENGTH:
@@ -765,7 +710,7 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                                /* position of payload lenght field is temporary stored */
                                this->last_payload_length_position_offset = this->get_current_buffer_offset(this);
                                /* payload length is generated like an U_INT_16 */
-                               status = this->generate_u_int_type(this,U_INT_16,rules[i].offset);
+                               this->generate_u_int_type(this,U_INT_16,rules[i].offset);
                                break;
                        }
                        case HEADER_LENGTH:
@@ -773,53 +718,38 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                                /* position of header length field is temporary stored */                       
                                this->header_length_position_offset = this->get_current_buffer_offset(this);    
                                /* header length is generated like an U_INT_32 */
-                               status = this->generate_u_int_type(this,U_INT_32,rules[i].offset);
+                               this->generate_u_int_type(this,U_INT_32,rules[i].offset);
                                break;
                        }
                        case SPI_SIZE:
                                /* spi size is handled as 8 bit unsigned integer */
-                               status = this->generate_u_int_type(this,U_INT_8,rules[i].offset);
+                               this->generate_u_int_type(this,U_INT_8,rules[i].offset);
                                /* last spi size is temporary stored */
                                this->last_spi_size = *((u_int8_t *)(this->data_struct + rules[i].offset));
                                break;
                        case SPI:
                        {
                                /* the SPI value is generated from chunk */
-                               status = this->generate_from_chunk(this,rules[i].offset);
+                               this->generate_from_chunk(this,rules[i].offset);
                                break;
                        }
                        case KEY_EXCHANGE_DATA:
                        {
                                /* the Key Exchange Data value is generated from chunk */
-                               status = this->generate_from_chunk(this,rules[i].offset);
-                               if (status != SUCCESS)
-                               {
-                                       this->logger->log(this->logger, ERROR, "could no write key exchange data from chunk");  
-                                       return status;
-                               }
-                               
+                               this->generate_from_chunk(this,rules[i].offset);
+
                                u_int32_t payload_length_position_offset = this->last_payload_length_position_offset;
                                /* Length of KE_PAYLOAD is calculated */
                                u_int16_t length_of_ke_payload = KE_PAYLOAD_HEADER_LENGTH + ((chunk_t *)(this->data_struct + rules[i].offset))->len;
 
                                u_int16_t int16_val = htons(length_of_ke_payload);                      
-                               status = this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
-                               if (status != SUCCESS)
-                               {
-                                       this->logger->log(this->logger, ERROR, "could not write payload length into buffer");                                   
-                                       return status;
-                               }
+                               this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
                                break;
                        }               
                        case NOTIFICATION_DATA:
                        {
                                /* the Notification Data value is generated from chunk */
-                               status = this->generate_from_chunk(this,rules[i].offset);
-                               if (status != SUCCESS)
-                               {
-                                       this->logger->log(this->logger, ERROR, "Could not generate notification data from chunk");      
-                                       return status;
-                               }
+                               this->generate_from_chunk(this,rules[i].offset);
                                
                                u_int32_t payload_length_position_offset = this->last_payload_length_position_offset;
                                /* Length of Notification PAYLOAD is calculated */
@@ -827,36 +757,20 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                                length_of_notify_payload += this->last_spi_size;
                                u_int16_t int16_val = htons(length_of_notify_payload);
 
-                               status = this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
-                               if (status != SUCCESS)
-                               {
-                                       this->logger->log(this->logger, ERROR, "could not write payload length into buffer");                                   
-                                       return status;
-                               }
+                               this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
                                break;
                        }               
                        case NONCE_DATA:
                        {
                                /* the Nonce Data value is generated from chunk */
-                               status = this->generate_from_chunk(this, rules[i].offset);
-                               
-                               if (status != SUCCESS)
-                               {
-                                       this->logger->log(this->logger, ERROR, "could not write nonce data from chunk");        
-                                       return status;
-                               }
+                               this->generate_from_chunk(this, rules[i].offset);
                                
                                u_int32_t payload_length_position_offset = this->last_payload_length_position_offset;
                                /* Length of nonce PAYLOAD is calculated */
                                u_int16_t length_of_nonce_payload = NONCE_PAYLOAD_HEADER_LENGTH + ((chunk_t *)(this->data_struct + rules[i].offset))->len;
                                u_int16_t int16_val = htons(length_of_nonce_payload);
 
-                               status = this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
-                               if (status != SUCCESS)
-                               {
-                                       this->logger->log(this->logger, ERROR, "could not write payload length into buffer");                                   
-                                       return status;
-                               }
+                               this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
                                break;
                        }
                        case PROPOSALS:
@@ -869,14 +783,9 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                                /* proposals are stored in a linked list and so accessed */
                                linked_list_t *proposals = *((linked_list_t **)(this->data_struct + rules[i].offset));
 
-                               linked_list_iterator_t *iterator;
+                               iterator_t *iterator;
                                /* create forward iterator */
-                               status = proposals->create_iterator(proposals,&iterator,TRUE);
-                               if (status != SUCCESS)
-                               {
-                                       this->logger->log(this->logger, ERROR, "could not create iterator for proposals");
-                                       return status;
-                               }
+                               proposals->create_iterator(proposals,&iterator,TRUE);
                                /* every proposal is processed (iterative call )*/
                                while (iterator->has_next(iterator))
                                {
@@ -884,20 +793,11 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                                        u_int32_t before_generate_position_offset;
                                        u_int32_t after_generate_position_offset;
                                        
-                                       status = iterator->current(iterator,(void **)&current_proposal);
-                                       if (status != SUCCESS)
-                                       {
-                                               iterator->destroy(iterator);    
-                                               return status;
-                                       }
+                                       iterator->current(iterator,(void **)&current_proposal);
+
                                        before_generate_position_offset = this->get_current_buffer_offset(this);
-                                       status = this->public.generate_payload(&(this->public),current_proposal);
+                                       this->public.generate_payload(&(this->public),current_proposal);
                                        after_generate_position_offset = this->get_current_buffer_offset(this);
-                                       if (status != SUCCESS)
-                                       {
-                                               iterator->destroy(iterator);    
-                                               return status;
-                                       }
                                        
                                        /* increase size of transform */
                                        length_of_sa_payload += (after_generate_position_offset - before_generate_position_offset);
@@ -905,12 +805,7 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                                iterator->destroy(iterator);
                                
                                int16_val = htons(length_of_sa_payload);
-                               status = this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
-                               if (status != SUCCESS)
-                               {
-                                       this->logger->log(this->logger, ERROR, "could not write payload length into buffer");                                   
-                                       return status;
-                               }
+                               this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
                                break;
                        }       
 
@@ -921,35 +816,21 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                                u_int16_t length_of_proposal = PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH + this->last_spi_size;
                                u_int16_t int16_val;
                                linked_list_t *transforms = *((linked_list_t **)(this->data_struct + rules[i].offset));
-                               linked_list_iterator_t *iterator;
+                               iterator_t *iterator;
                                                                
                                /* create forward iterator */
-                               status = transforms->create_iterator(transforms,&iterator,TRUE);
-                               if (status != SUCCESS)
-                               {
-                                       return status;
-                               }
+                               transforms->create_iterator(transforms,&iterator,TRUE);
                                while (iterator->has_next(iterator))
                                {
                                        payload_t *current_transform;
                                        u_int32_t before_generate_position_offset;
                                        u_int32_t after_generate_position_offset;
                                        
-                                       status = iterator->current(iterator,(void **)&current_transform);
-                                       if (status != SUCCESS)
-                                       {
-                                               iterator->destroy(iterator);    
-                                               return status;
-                                       }
+                                       iterator->current(iterator,(void **)&current_transform);
                                        
                                        before_generate_position_offset = this->get_current_buffer_offset(this);
-                                       status = this->public.generate_payload(&(this->public),current_transform);
+                                       this->public.generate_payload(&(this->public),current_transform);
                                        after_generate_position_offset = this->get_current_buffer_offset(this);
-                                       if (status != SUCCESS)
-                                       {
-                                               iterator->destroy(iterator);    
-                                               return status;
-                                       }
                                        
                                        /* increase size of transform */
                                        length_of_proposal += (after_generate_position_offset - before_generate_position_offset);
@@ -971,25 +852,16 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                                u_int16_t int16_val;
                                linked_list_t *transform_attributes =*((linked_list_t **)(this->data_struct + rules[i].offset));
 
-                               linked_list_iterator_t *iterator;
+                               iterator_t *iterator;
                                /* create forward iterator */
-                               status = transform_attributes->create_iterator(transform_attributes,&iterator,TRUE);
-                               if (status != SUCCESS)
-                               {
-                                       return status;
-                               }
+                               transform_attributes->create_iterator(transform_attributes,&iterator,TRUE);
                                while (iterator->has_next(iterator))
                                {
                                        payload_t *current_attribute;
                                        u_int32_t before_generate_position_offset;
                                        u_int32_t after_generate_position_offset;
                                        
-                                       status = iterator->current(iterator,(void **)&current_attribute);
-                                       if (status != SUCCESS)
-                                       {
-                                               iterator->destroy(iterator);    
-                                               return status;
-                                       }
+                                       iterator->current(iterator,(void **)&current_attribute);
                                        
                                        before_generate_position_offset = this->get_current_buffer_offset(this);
                                        this->public.generate_payload(&(this->public),current_attribute);
@@ -1008,7 +880,7 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                        }       
                        case ATTRIBUTE_FORMAT:
                        {
-                               status = this->generate_flag(this,rules[i].offset);
+                               this->generate_flag(this,rules[i].offset);
                                /* Attribute format is a flag which is stored in context*/
                                this->attribute_format = *((bool *) (this->data_struct + rules[i].offset));
                                break;
@@ -1018,13 +890,13 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                        {
                                if (this->attribute_format == FALSE)
                                {
-                                       status = this->generate_u_int_type(this,U_INT_16,rules[i].offset);
+                                       this->generate_u_int_type(this,U_INT_16,rules[i].offset);
                                        /* this field hold the length of the attribute */
                                        this->attribute_length = *((u_int16_t *)(this->data_struct + rules[i].offset));
                                }
                                else
                                {
-                                       status = this->generate_u_int_type(this,U_INT_16,rules[i].offset);
+                                       this->generate_u_int_type(this,U_INT_16,rules[i].offset);
 //                                     status = this->write_bytes_to_buffer(this,(this->data_struct + rules[i].offset),2);
                                }
                                break;
@@ -1035,20 +907,24 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
                                {
                                        this->logger->log(this->logger, CONTROL|MOST, "attribute value has not fixed size");
                                        /* the attribute value is generated */
-                                       status = this->generate_from_chunk(this,rules[i].offset);
+                                       this->generate_from_chunk(this,rules[i].offset);
                                }
                                break;
                        }
+                       case ENCRYPTED_DATA:
+                       {
+                               this->generate_from_chunk(this, rules[i].offset);
+                               break;
+                       }
                        default:
                                this->logger->log(this->logger, ERROR, "field type %s is not supported",
                                                                        mapping_find(encoding_type_m,rules[i].type));
-                               return NOT_SUPPORTED;
+                               return;
                }
        }
        this->logger->log_bytes(this->logger, RAW|MORE, "generated data for this payload",
                                                        payload_start, this->out_position-payload_start);
 
-       return status;
 }
 
 /**
@@ -1077,9 +953,9 @@ generator_t * generator_create()
        }
 
        /* initiate public functions */
-       this->public.generate_payload = (status_t(*)(generator_t*, payload_t *)) generate_payload;
-       this->public.destroy = (status_t(*)(generator_t*)) destroy;
-       this->public.write_to_chunk = (status_t (*) (generator_t *,chunk_t *)) write_to_chunk;
+       this->public.generate_payload = (void(*)(generator_t*, payload_t *)) generate_payload;
+       this->public.destroy = (void(*)(generator_t*)) destroy;
+       this->public.write_to_chunk = (void (*) (generator_t *,chunk_t *)) write_to_chunk;
        
        
        /* initiate private functions */
@@ -1112,8 +988,6 @@ generator_t * generator_create()
        this->last_payload_length_position_offset = 0;
        this->header_length_position_offset = 0;
        this->logger = global_logger_manager->create_logger(global_logger_manager,GENERATOR,NULL);
-       this->logger->disable_level(this->logger, FULL);
-       this->logger->enable_level(this->logger, CONTROL);
        
        if (this->logger == NULL)
        {