Changeset 5325

Show
Ignore:
Timestamp:
02/28/08 15:14:07 (5 months ago)
Author:
morris
Message:

Print fields in the error they're in the buffer

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libwired/trunk/libwired/p7/wi-p7-message.c

    r5321 r5325  
    164164static wi_string_t * _wi_p7_message_description(wi_runtime_instance_t *instance) { 
    165165        wi_p7_message_t         *p7_message = instance; 
    166         wi_hash_t                       *fields; 
    167         wi_enumerator_t         *enumerator; 
    168         wi_string_t                     *description, *xml_string, *field_name; 
     166        wi_string_t                     *description, *xml_string, *field_name, *type_name, *field_value; 
     167        xmlNodePtr                      node; 
     168        unsigned char           *buffer, *start; 
     169        wi_p7_type_t            type_id; 
     170        uint32_t                        message_size, field_id, field_size; 
     171         
    169172         
    170173        description = wi_string_init_with_format(wi_string_alloc(), WI_STR("<%@ %p>{name = %@, serialization = %@"), 
     
    187190        } 
    188191         
    189         fields = wi_p7_message_fields(p7_message); 
    190         enumerator = wi_hash_key_enumerator(fields); 
    191          
    192         while((field_name = wi_enumerator_next_data(enumerator))) { 
    193                 wi_string_append_format(description, WI_STR("    %@ = %@\n"), 
    194                         field_name, wi_hash_data_for_key(fields, field_name)); 
     192        if(p7_message->serialization == WI_P7_BINARY) { 
     193                message_size = p7_message->binary_size - WI_P7_MESSAGE_BINARY_HEADER_SIZE; 
     194                buffer = start = p7_message->binary_buffer + WI_P7_MESSAGE_BINARY_HEADER_SIZE; 
     195                 
     196                while((uint32_t) (buffer - start) < message_size) { 
     197                        field_id = wi_read_swap_big_to_host_int32(buffer, 0); 
     198                        buffer += sizeof(field_id); 
     199 
     200                        field_size = wi_p7_spec_field_size(p7_message->spec, field_id); 
     201                         
     202                        if(field_size == 0) { 
     203                                field_size = wi_read_swap_big_to_host_int32(buffer, 0); 
     204                                 
     205                                buffer += sizeof(field_size); 
     206                        } 
     207                         
     208                        field_name              = wi_p7_spec_field_name(p7_message->spec, field_id); 
     209                        type_id                 = wi_p7_spec_field_type(p7_message->spec, field_id); 
     210                        field_value             = _wi_p7_message_field_string_value(p7_message, field_name, type_id); 
     211 
     212                        wi_string_append_format(description, WI_STR("    %@ = %@\n"), 
     213                                field_name, field_value); 
     214 
     215                        buffer += field_size; 
     216                } 
     217        } else { 
     218                if(p7_message->xml_root_node) { 
     219                        for(node = p7_message->xml_root_node->children; node != NULL; node = node->next) { 
     220                                if(node->type == XML_ELEMENT_NODE) { 
     221                                        field_name              = wi_autorelease(wi_p7_xml_copy_string_for_attribute(node, WI_STR("name"))); 
     222                                        type_name               = wi_autorelease(wi_p7_xml_copy_string_for_attribute(node, WI_STR("type"))); 
     223                                        type_id                 = wi_p7_spec_type_id(p7_message->spec, type_name); 
     224                                        field_value             = _wi_p7_message_field_string_value(p7_message, field_name, type_id); 
     225                                         
     226                                        wi_string_append_format(description, WI_STR("    %@ = %@\n"), 
     227                                                field_name, field_value); 
     228                                } 
     229                        } 
     230                } 
    195231        } 
    196232