last patch removed, changed CURLOPT_FILE to CURLOPT_WRITEDATA
[strongswan.git] / src / charon / encoding / parser.c
index 4215d38..d7caf70 100644 (file)
@@ -27,8 +27,7 @@
 
 #include "parser.h"
 
-#include <types.h>
-#include <definitions.h>
+#include <library.h>
 #include <daemon.h>
 #include <utils/linked_list.h>
 #include <encoding/payloads/encodings.h>
@@ -176,7 +175,7 @@ struct private_parser_t {
        /**
         * @brief Parse substructures in a list
         * 
-        * This function calls the parser recursivly to parse contained substructures
+        * This function calls the parser recursively to parse contained substructures
         * in a linked_list_t. The list must already be created. Payload defines
         * the type of the substructures. parsing is continued until the specified length
         * is completely parsed.
@@ -241,7 +240,7 @@ static status_t parse_uint4(private_parser_t *this, int rule_number, u_int8_t *o
 {
        if (this->byte_pos + sizeof(u_int8_t)  > this->input_roof)
        {
-               DBG1(SIG_DBG_ENC, "  not enough input to parse rule %d %N",
+               DBG1(DBG_ENC, "  not enough input to parse rule %d %N",
                         rule_number, encoding_type_names, this->rules[rule_number].type);
                return PARSE_ERROR;
        }
@@ -265,7 +264,7 @@ static status_t parse_uint4(private_parser_t *this, int rule_number, u_int8_t *o
                        this->byte_pos++;
                        break;
                default:
-                       DBG2(SIG_DBG_ENC, "  found rule %d %N on bitpos %d",
+                       DBG2(DBG_ENC, "  found rule %d %N on bitpos %d",
                                 rule_number, encoding_type_names,
                                 this->rules[rule_number].type, this->bit_pos);
                        return PARSE_ERROR;
@@ -273,7 +272,7 @@ static status_t parse_uint4(private_parser_t *this, int rule_number, u_int8_t *o
        
        if (output_pos != NULL)
        {
-               DBG3(SIG_DBG_ENC, "   => %d", *output_pos);
+               DBG3(DBG_ENC, "   => %d", *output_pos);
        }
        
        return SUCCESS;
@@ -286,13 +285,13 @@ static status_t parse_uint8(private_parser_t *this, int rule_number, u_int8_t *o
 {
        if (this->byte_pos + sizeof(u_int8_t)  > this->input_roof)
        {
-               DBG1(SIG_DBG_ENC, "  not enough input to parse rule %d %N",
+               DBG1(DBG_ENC, "  not enough input to parse rule %d %N",
                         rule_number, encoding_type_names, this->rules[rule_number].type);
                return PARSE_ERROR;
        }
        if (this->bit_pos)
        {
-               DBG1(SIG_DBG_ENC, "  found rule %d %N on bitpos %d",
+               DBG1(DBG_ENC, "  found rule %d %N on bitpos %d",
                         rule_number, encoding_type_names,
                         this->rules[rule_number].type, this->bit_pos);
                return PARSE_ERROR;
@@ -302,7 +301,7 @@ static status_t parse_uint8(private_parser_t *this, int rule_number, u_int8_t *o
        if (output_pos != NULL)
        {
                *output_pos = *(this->byte_pos);
-               DBG3(SIG_DBG_ENC, "   => %d", *output_pos);
+               DBG3(DBG_ENC, "   => %d", *output_pos);
        }
        this->byte_pos++;
        
@@ -316,13 +315,13 @@ static status_t parse_uint15(private_parser_t *this, int rule_number, u_int16_t
 {
        if (this->byte_pos + sizeof(u_int16_t) > this->input_roof)
        {
-               DBG1(SIG_DBG_ENC, "  not enough input to parse rule %d %N",
+               DBG1(DBG_ENC, "  not enough input to parse rule %d %N",
                         rule_number, encoding_type_names, this->rules[rule_number].type);
                return PARSE_ERROR;
        }
        if (this->bit_pos != 1)
        {
-               DBG2(SIG_DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
+               DBG2(DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
                         encoding_type_names, this->rules[rule_number].type, this->bit_pos);
                return PARSE_ERROR;
        }
@@ -330,7 +329,7 @@ static status_t parse_uint15(private_parser_t *this, int rule_number, u_int16_t
        if (output_pos != NULL)
        {
                *output_pos = ntohs(*((u_int16_t*)this->byte_pos)) & ~0x8000;
-               DBG3(SIG_DBG_ENC, "   => %d", *output_pos);
+               DBG3(DBG_ENC, "   => %d", *output_pos);
        }
        this->byte_pos += 2;
        this->bit_pos = 0;
@@ -345,13 +344,13 @@ static status_t parse_uint16(private_parser_t *this, int rule_number, u_int16_t
 {
        if (this->byte_pos + sizeof(u_int16_t) > this->input_roof)
        {
-               DBG1(SIG_DBG_ENC, "  not enough input to parse rule %d %N",
+               DBG1(DBG_ENC, "  not enough input to parse rule %d %N",
                         rule_number, encoding_type_names, this->rules[rule_number].type);
                return PARSE_ERROR;
        }
        if (this->bit_pos)
        {
-               DBG1(SIG_DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
+               DBG1(DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
                         encoding_type_names, this->rules[rule_number].type, this->bit_pos);
                return PARSE_ERROR;
        }
@@ -360,7 +359,7 @@ static status_t parse_uint16(private_parser_t *this, int rule_number, u_int16_t
        {
                *output_pos = ntohs(*((u_int16_t*)this->byte_pos));
                
-               DBG3(SIG_DBG_ENC, "   => %d", *output_pos);
+               DBG3(DBG_ENC, "   => %d", *output_pos);
        }
        this->byte_pos += 2;
        
@@ -373,13 +372,13 @@ static status_t parse_uint32(private_parser_t *this, int rule_number, u_int32_t
 {
        if (this->byte_pos + sizeof(u_int32_t) > this->input_roof)
        {
-               DBG1(SIG_DBG_ENC, "  not enough input to parse rule %d %N",
+               DBG1(DBG_ENC, "  not enough input to parse rule %d %N",
                         rule_number, encoding_type_names, this->rules[rule_number].type);
                return PARSE_ERROR;
        }
        if (this->bit_pos)
        {
-               DBG1(SIG_DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
+               DBG1(DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
                         encoding_type_names, this->rules[rule_number].type, this->bit_pos);
                return PARSE_ERROR;
        }
@@ -388,7 +387,7 @@ static status_t parse_uint32(private_parser_t *this, int rule_number, u_int32_t
        {
                *output_pos = ntohl(*((u_int32_t*)this->byte_pos));
                
-               DBG3(SIG_DBG_ENC, "   => %d", *output_pos);
+               DBG3(DBG_ENC, "   => %d", *output_pos);
        }
        this->byte_pos += 4;
        
@@ -402,13 +401,13 @@ static status_t parse_uint64(private_parser_t *this, int rule_number, u_int64_t
 {
        if (this->byte_pos + sizeof(u_int64_t) > this->input_roof)
        {
-               DBG1(SIG_DBG_ENC, "  not enough input to parse rule %d %N",
+               DBG1(DBG_ENC, "  not enough input to parse rule %d %N",
                         rule_number, encoding_type_names, this->rules[rule_number].type);
                return PARSE_ERROR;
        }
        if (this->bit_pos)
        {
-               DBG1(SIG_DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
+               DBG1(DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
                         encoding_type_names, this->rules[rule_number].type, this->bit_pos);
                return PARSE_ERROR;
        }
@@ -419,7 +418,7 @@ static status_t parse_uint64(private_parser_t *this, int rule_number, u_int64_t
                *(output_pos + 1) = ntohl(*((u_int32_t*)this->byte_pos));
                *output_pos = ntohl(*(((u_int32_t*)this->byte_pos) + 1));
                
-               DBG3(SIG_DBG_ENC, "   => %b", (void*)output_pos, sizeof(u_int64_t));
+               DBG3(DBG_ENC, "   => %b", (void*)output_pos, sizeof(u_int64_t));
        }
        this->byte_pos += 8;
 
@@ -433,13 +432,13 @@ static status_t parse_bytes (private_parser_t *this, int rule_number, u_int8_t *
 {
        if (this->byte_pos + bytes > this->input_roof)
        {
-               DBG1(SIG_DBG_ENC, "  not enough input to parse rule %d %N",
+               DBG1(DBG_ENC, "  not enough input to parse rule %d %N",
                         rule_number, encoding_type_names, this->rules[rule_number].type);
                return PARSE_ERROR;
        }
        if (this->bit_pos)
        {
-               DBG1(SIG_DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
+               DBG1(DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
                         encoding_type_names, this->rules[rule_number].type, this->bit_pos);
                return PARSE_ERROR;
        }
@@ -449,7 +448,7 @@ static status_t parse_bytes (private_parser_t *this, int rule_number, u_int8_t *
        {
                memcpy(output_pos,this->byte_pos,bytes);
                
-               DBG3(SIG_DBG_ENC, "   => %b", (void*)output_pos, bytes);
+               DBG3(DBG_ENC, "   => %b", (void*)output_pos, bytes);
        }
        this->byte_pos += bytes;
        
@@ -463,7 +462,7 @@ static status_t parse_bit(private_parser_t *this, int rule_number, bool *output_
 {
        if (this->byte_pos + sizeof(u_int8_t) > this->input_roof)
        {
-               DBG1(SIG_DBG_ENC, "  not enough input to parse rule %d %N",
+               DBG1(DBG_ENC, "  not enough input to parse rule %d %N",
                         rule_number, encoding_type_names, this->rules[rule_number].type);
                return PARSE_ERROR;
        }
@@ -480,7 +479,7 @@ static status_t parse_bit(private_parser_t *this, int rule_number, bool *output_
                        *output_pos = TRUE;
                }
                
-               DBG3(SIG_DBG_ENC, "   => %d", *output_pos);
+               DBG3(DBG_ENC, "   => %d", *output_pos);
        }
        this->bit_pos = (this->bit_pos + 1) % 8;
        if (this->bit_pos == 0) 
@@ -500,14 +499,14 @@ static status_t parse_list(private_parser_t *this, int rule_number, linked_list_
        
        if (length < 0)
        {
-               DBG1(SIG_DBG_ENC, "  invalid length for rule %d %N",
+               DBG1(DBG_ENC, "  invalid length for rule %d %N",
                         rule_number, encoding_type_names, this->rules[rule_number].type);
                return PARSE_ERROR;     
        }
        
        if (this->bit_pos)
        {
-               DBG1(SIG_DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
+               DBG1(DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
                         encoding_type_names, this->rules[rule_number].type, this->bit_pos);
                return PARSE_ERROR;
        }
@@ -517,14 +516,14 @@ static status_t parse_list(private_parser_t *this, int rule_number, linked_list_
                u_int8_t *pos_before = this->byte_pos;
                payload_t *payload;
                status_t status;
-               DBG2(SIG_DBG_ENC, "  %d bytes left, parsing recursivly %N",
+               DBG2(DBG_ENC, "  %d bytes left, parsing recursively %N",
                         length, payload_type_names, payload_type);
                status = this->public.parse_payload((parser_t*)this, payload_type, &payload);
                if (status != SUCCESS)
                {
-                       DBG1(SIG_DBG_ENC, "  parsing of a %N substructure failed",
+                       DBG1(DBG_ENC, "  parsing of a %N substructure failed",
                                 payload_type_names, payload_type);
-                       return status;  
+                       return status;
                }
                list->insert_last(list, payload);
                length -= this->byte_pos - pos_before;
@@ -540,13 +539,13 @@ static status_t parse_chunk(private_parser_t *this, int rule_number, chunk_t *ou
 {
        if (this->byte_pos + length > this->input_roof)
        {
-               DBG1(SIG_DBG_ENC, "  not enough input (%d bytes) to parse rule %d %N",
+               DBG1(DBG_ENC, "  not enough input (%d bytes) to parse rule %d %N",
                         length, rule_number, encoding_type_names, this->rules[rule_number].type);
                return PARSE_ERROR;
        }
        if (this->bit_pos)
        {
-               DBG1(SIG_DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
+               DBG1(DBG_ENC, "  found rule %d %N on bitpos %d", rule_number,
                         encoding_type_names, this->rules[rule_number].type, this->bit_pos);
                return PARSE_ERROR;
        }
@@ -557,7 +556,7 @@ static status_t parse_chunk(private_parser_t *this, int rule_number, chunk_t *ou
                memcpy(output_pos->ptr, this->byte_pos, length);
        }
        this->byte_pos += length;
-       DBG3(SIG_DBG_ENC, "   => %b", (void*)output_pos->ptr, length);
+       DBG3(DBG_ENC, "   => %b", (void*)output_pos->ptr, length);
        
        return SUCCESS;
 }
@@ -578,15 +577,15 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
        /* create instance of the payload to parse */
        pld = payload_create(payload_type);
        
-       DBG2(SIG_DBG_ENC, "parsing %N payload, %d bytes left",
+       DBG2(DBG_ENC, "parsing %N payload, %d bytes left",
                 payload_type_names, payload_type, this->input_roof - this->byte_pos);
        
-       DBG3(SIG_DBG_ENC, "parsing payload from %b",
+       DBG3(DBG_ENC, "parsing payload from %b",
                 this->byte_pos, this->input_roof-this->byte_pos);
        
        if (pld->get_type(pld) == UNKNOWN_PAYLOAD)
        {
-               DBG1(SIG_DBG_ENC, "  payload type %d is unknown, handling as %N",
+               DBG1(DBG_ENC, "  payload type %d is unknown, handling as %N",
                         payload_type, payload_type_names, UNKNOWN_PAYLOAD);
        }
        
@@ -598,7 +597,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
        for (rule_number = 0; rule_number < rule_count; rule_number++)
        {
                rule = &(this->rules[rule_number]);
-               DBG2(SIG_DBG_ENC, "  parsing rule %d %N",
+               DBG2(DBG_ENC, "  parsing rule %d %N",
                         rule_number, encoding_type_names, rule->type);
                switch (rule->type)
                {
@@ -627,7 +626,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }
-                               break;                                  
+                               break;
                        }
                        case U_INT_32:
                        {
@@ -636,7 +635,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }
-                               break;          
+                               break;
                        }
                        case U_INT_64:
                        {
@@ -645,7 +644,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }
-                               break;  
+                               break;
                        }
                        case IKE_SPI:
                        {
@@ -654,7 +653,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }
-                               break;  
+                               break;
                        }
                        case RESERVED_BIT:
                        {
@@ -663,7 +662,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }
-                               break;  
+                               break;
                        }
                        case RESERVED_BYTE:
                        {
@@ -681,7 +680,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }
-                               break;  
+                               break;
                        }
                        case PAYLOAD_LENGTH:
                        {
@@ -691,7 +690,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        return PARSE_ERROR;
                                }
                                payload_length = *(u_int16_t*)(output + rule->offset);
-                               break;                                                  
+                               break;
                        }
                        case HEADER_LENGTH:
                        {
@@ -700,7 +699,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }
-                               break;                                                  
+                               break;
                        }
                        case SPI_SIZE:
                        {
@@ -710,7 +709,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        return PARSE_ERROR;
                                }
                                spi_size = *(u_int8_t*)(output + rule->offset);
-                               break;                                                  
+                               break;
                        }
                        case SPI:
                        {
@@ -719,7 +718,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }
-                               break;                                                  
+                               break;
                        }
                        case PROPOSALS:
                        {
@@ -729,7 +728,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }
-                               break;                                                  
+                               break;
                        }
                        case TRANSFORMS:
                        {
@@ -739,7 +738,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }
-                               break;                                                  
+                               break;
                        }
                        case TRANSFORM_ATTRIBUTES:
                        {
@@ -749,7 +748,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }
-                               break;                                                  
+                               break;
                        }
                        case CONFIGURATION_ATTRIBUTES:
                        {
@@ -759,7 +758,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }
-                               break;                                                  
+                               break;
                        }
                        case ATTRIBUTE_FORMAT:
                        {
@@ -790,7 +789,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                }
                                attribute_length = *(u_int16_t*)(output + rule->offset);
                                break;
-                       }                       
+                       }
                        case ATTRIBUTE_LENGTH_OR_VALUE:
                        {       
                                if (this->parse_uint16(this, rule_number, output + rule->offset) != SUCCESS) 
@@ -821,7 +820,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }               
-                               break;                  
+                               break;
                        }
                        case ID_DATA:
                        {
@@ -831,7 +830,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
                                }       
-                               break;                  
+                               break;
                        }
                        case AUTH_DATA:
                        {
@@ -840,8 +839,8 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                {
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
-                               }               
-                               break;                  
+                               }
+                               break;
                        }
                        case CERT_DATA:
                        {
@@ -850,8 +849,8 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                {
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
-                               }               
-                               break;                  
+                               }
+                               break;
                        }
                        case CERTREQ_DATA:
                        {
@@ -860,18 +859,18 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                {
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
-                               }               
-                               break;                  
+                               }
+                               break;
                        }
-                       case EAP_MESSAGE:
+                       case EAP_DATA:
                        {
                                size_t data_length = payload_length - EAP_PAYLOAD_HEADER_LENGTH;
                                if (this->parse_chunk(this, rule_number, output + rule->offset, data_length) != SUCCESS) 
                                {
                                        pld->destroy(pld);
                                        return PARSE_ERROR;
-                               }               
-                               break;                  
+                               }
+                               break;
                        }
                        case SPIS:
                        {
@@ -975,7 +974,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                        }
                        default:
                        {
-                               DBG1(SIG_DBG_ENC, "  no rule to parse rule %d %N",
+                               DBG1(DBG_ENC, "  no rule to parse rule %d %N",
                                         rule_number, encoding_type_names, rule->type);
                                pld->destroy(pld);
                                return PARSE_ERROR;
@@ -986,7 +985,7 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
        }
        
        *payload = pld;
-       DBG2(SIG_DBG_ENC, "parsing %N payload finished",
+       DBG2(DBG_ENC, "parsing %N payload finished",
                 payload_type_names, payload_type);
        return SUCCESS;
 }