Changeset 4601

Show
Ignore:
Timestamp:
02/13/07 19:38:10 (2 years ago)
Author:
morris
Message:

More p7 support:

- Add <p7:and> and <p7:or> for transaction replies
- Improve error checking
- Add enumerations

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libwired/trunk/libwired/base/wi-error.c

    r4590 r4601  
    9191        "No such syslog facility", 
    9292         
     93        /* WI_ERROR_P7_INVALIDSPEC */ 
     94        "Invalid specification", 
     95         
    9396        /* WI_ERROR_REGEXP_NOSLASH */ 
    9497        "Missing \"/\"", 
  • libwired/trunk/libwired/base/wi-error.h

    r4590 r4601  
    5757         
    5858        WI_ERROR_LOG_NOSUCHFACILITY, 
     59         
     60        WI_ERROR_P7_INVALIDSPEC, 
    5961 
    6062        WI_ERROR_REGEXP_NOSLASH, 
  • libwired/trunk/libwired/p7/wi-p7-message.c

    r4591 r4601  
    383383        wi_date_t                               *date; 
    384384        wi_p7_boolean_t                 p7_bool; 
     385        wi_p7_enum_t                    p7_enum; 
    385386        wi_p7_int32_t                   p7_int32; 
    386387        wi_p7_uint32_t                  p7_uint32; 
     
    398399                        break; 
    399400                         
     401                case WI_P7_ENUM: 
     402                        if(wi_p7_message_get_enum_for_name(p7_message, &p7_enum, field_name)) 
     403                                field_value = wi_string_with_format(WI_STR("%u"), p7_enum); 
     404                        break; 
     405                         
    400406                case WI_P7_INT32: 
    401407                        if(wi_p7_message_get_int32_for_name(p7_message, &p7_int32, field_name)) 
     
    760766 
    761767 
     768wi_boolean_t wi_p7_message_set_enum_for_name(wi_p7_message_t *p7_message, wi_p7_enum_t value, wi_string_t *field_name) { 
     769        wi_string_t             *string; 
     770        unsigned char   *binary; 
     771        uint32_t                field_id; 
     772 
     773        if(p7_message->serialization == WI_P7_BINARY) { 
     774                if(!_wi_p7_message_get_binary_buffer_for_writing_for_name(p7_message, field_name, 0, &binary, &field_id)) 
     775                        return false; 
     776                 
     777                wi_write_swap_host_to_big_int32(binary, 0, field_id); 
     778                wi_write_swap_host_to_big_int32(binary, 4, value); 
     779        } else { 
     780                string = wi_string_with_format(WI_STR("%u"), value); 
     781 
     782                _wi_p7_message_set_xml_field(p7_message, WI_P7_ENUM, field_name, string); 
     783        } 
     784         
     785        return true; 
     786} 
     787 
     788 
     789 
     790wi_boolean_t wi_p7_message_get_enum_for_name(wi_p7_message_t *p7_message, wi_p7_enum_t *value, wi_string_t *field_name) { 
     791        wi_string_t             *string; 
     792        unsigned char   *binary; 
     793         
     794        if(p7_message->serialization == WI_P7_BINARY) { 
     795                if(!_wi_p7_message_get_binary_buffer_for_reading_for_name(p7_message, field_name, &binary, NULL)) 
     796                        return false; 
     797                 
     798                *value = wi_read_swap_big_to_host_int32(binary, 0); 
     799        } else { 
     800                string = _wi_p7_message_xml_value_for_name(p7_message, field_name); 
     801                 
     802                if(!string) 
     803                        return false; 
     804                 
     805                *value = wi_string_uint32(string); 
     806        } 
     807         
     808        return true; 
     809} 
     810 
     811 
     812 
    762813wi_boolean_t wi_p7_message_set_int32_for_name(wi_p7_message_t *p7_message, wi_p7_int32_t value, wi_string_t *field_name) { 
    763814        wi_string_t             *string; 
  • libwired/trunk/libwired/p7/wi-p7-message.h

    r4590 r4601  
    3939 
    4040typedef char                                            wi_p7_boolean_t; 
     41typedef uint32_t                                        wi_p7_enum_t; 
    4142typedef int32_t                                         wi_p7_int32_t; 
    4243typedef uint32_t                                        wi_p7_uint32_t; 
     
    4950enum _wi_p7_type { 
    5051        WI_P7_BOOL                                              = 1, 
    51         WI_P7_INT32                                             = 2, 
    52         WI_P7_UINT32                                    = 3, 
    53         WI_P7_INT64                                             = 4, 
    54         WI_P7_UINT64                                    = 5, 
    55         WI_P7_DOUBLE                                    = 6, 
    56         WI_P7_STRING                                    = 7, 
    57         WI_P7_UUID                                              = 8, 
    58         WI_P7_DATE                                              = 9, 
    59         WI_P7_DATA                                              = 10, 
    60         WI_P7_OOBDATA                                   = 11 
     52        WI_P7_ENUM                                              = 2, 
     53        WI_P7_INT32                                             = 3, 
     54        WI_P7_UINT32                                    = 4, 
     55        WI_P7_INT64                                             = 5, 
     56        WI_P7_UINT64                                    = 6, 
     57        WI_P7_DOUBLE                                    = 7, 
     58        WI_P7_STRING                                    = 8, 
     59        WI_P7_UUID                                              = 9, 
     60        WI_P7_DATE                                              = 10, 
     61        WI_P7_DATA                                              = 11, 
     62        WI_P7_OOBDATA                                   = 12 
    6163}; 
    6264typedef enum _wi_p7_type                        wi_p7_type_t; 
     
    8082WI_EXPORT wi_boolean_t                          wi_p7_message_set_bool_for_name(wi_p7_message_t *, wi_p7_boolean_t, wi_string_t *); 
    8183WI_EXPORT wi_boolean_t                          wi_p7_message_get_bool_for_name(wi_p7_message_t *, wi_p7_boolean_t *, wi_string_t *); 
     84WI_EXPORT wi_boolean_t                          wi_p7_message_set_enum_for_name(wi_p7_message_t *, wi_p7_enum_t, wi_string_t *); 
     85WI_EXPORT wi_boolean_t                          wi_p7_message_get_enum_for_name(wi_p7_message_t *, wi_p7_enum_t *, wi_string_t *); 
    8286WI_EXPORT wi_boolean_t                          wi_p7_message_set_int32_for_name(wi_p7_message_t *, wi_p7_int32_t, wi_string_t *); 
    8387WI_EXPORT wi_boolean_t                          wi_p7_message_get_int32_for_name(wi_p7_message_t *, wi_p7_int32_t *, wi_string_t *); 
  • libwired/trunk/libwired/p7/wi-p7-private.c

    r4578 r4601  
    5454 
    5555 
    56 int32_t wi_p7_xml_int32_for_attribute(xmlNodePtr node, wi_string_t *attribute) { 
    57         xmlChar                 *prop; 
    58         int32_t                 value; 
     56wi_integer_t wi_p7_xml_integer_for_attribute(xmlNodePtr node, wi_string_t *attribute) { 
     57        wi_string_t             *string; 
    5958         
    60         prop = xmlGetProp(node, (xmlChar *) wi_string_cstring(attribute)); 
     59        string = wi_p7_xml_string_for_attribute(node, attribute); 
    6160         
    62         if(!prop
     61        if(!string
    6362                return 0; 
    6463         
    65         value = strtol((const char *) prop, NULL, 0); 
    66          
    67         xmlFree(prop); 
    68          
    69         return value; 
     64        return wi_string_integer(string); 
    7065} 
    7166 
  • libwired/trunk/libwired/p7/wi-p7-private.h

    r4578 r4601  
    6363WI_EXPORT void                                          wi_p7_message_deserialize(wi_p7_message_t *); 
    6464 
     65WI_EXPORT wi_boolean_t                          wi_p7_spec_is_checking(wi_p7_spec_t *); 
     66 
    6567WI_EXPORT wi_string_t *                         wi_p7_xml_string_for_attribute(xmlNodePtr, wi_string_t *); 
    66 WI_EXPORT int32_t                                      wi_p7_xml_int32_for_attribute(xmlNodePtr, wi_string_t *); 
     68WI_EXPORT wi_integer_t                         wi_p7_xml_integer_for_attribute(xmlNodePtr, wi_string_t *); 
    6769 
    6870#endif 
  • libwired/trunk/libwired/p7/wi-p7-socket.c

    r4598 r4601  
    718718                return false; 
    719719         
    720         wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_xml_string(p7_socket->spec), WI_STR("p7.compatibility_check.specification")); 
     720        wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_xml(p7_socket->spec), WI_STR("p7.compatibility_check.specification")); 
    721721 
    722722        if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message)) { 
     
    779779        } 
    780780         
    781         p7_spec = wi_p7_spec_init_with_string(wi_p7_spec_alloc(), string, true); 
     781        p7_spec = wi_p7_spec_init_with_string(wi_p7_spec_alloc(), string, wi_p7_spec_is_checking(p7_socket->spec)); 
    782782         
    783783        if(!p7_spec) { 
  • libwired/trunk/libwired/p7/wi-p7-spec.c

    r4590 r4601  
    4747#include <wired/wi-string.h> 
    4848 
     49typedef struct _wi_p7_spec_type                         _wi_p7_spec_type_t; 
     50typedef struct _wi_p7_spec_field                        _wi_p7_spec_field_t; 
     51typedef struct _wi_p7_spec_message                      _wi_p7_spec_message_t; 
     52typedef struct _wi_p7_spec_parameter            _wi_p7_spec_parameter_t; 
     53typedef struct _wi_p7_spec_transaction          _wi_p7_spec_transaction_t; 
     54typedef struct _wi_p7_spec_andor                        _wi_p7_spec_andor_t; 
     55typedef struct _wi_p7_spec_reply                        _wi_p7_spec_reply_t; 
     56 
     57 
    4958struct _wi_p7_spec_type { 
    5059        wi_runtime_base_t                                               base; 
    5160         
    5261        wi_string_t                                                             *name; 
    53         uint32_t                                                              size; 
    54         uint32_t                                                              id; 
     62        wi_integer_t                                                  size; 
     63        wi_integer_t                                                  id; 
    5564}; 
    56 typedef struct _wi_p7_spec_type                         _wi_p7_spec_type_t; 
    57  
    58  
    59 static _wi_p7_spec_type_t *                                     _wi_p7_spec_type_alloc(void); 
    60 static _wi_p7_spec_type_t *                                     _wi_p7_spec_type_init(_wi_p7_spec_type_t *); 
    61  
     65 
     66static _wi_p7_spec_type_t *                                     _wi_p7_spec_type_with_node(wi_p7_spec_t *, xmlNodePtr); 
    6267static void                                                                     _wi_p7_spec_type_dealloc(wi_runtime_instance_t *); 
    6368static wi_string_t *                                            _wi_p7_spec_type_description(wi_runtime_instance_t *); 
    64  
    6569 
    6670static wi_runtime_id_t                                          _wi_p7_spec_type_runtime_id = WI_RUNTIME_ID_NULL; 
     
    8084         
    8185        wi_string_t                                                             *name; 
    82         uint32_t                                                              id; 
     86        wi_integer_t                                                  id; 
    8387        _wi_p7_spec_type_t                                              *type; 
     88        wi_hash_t                                                               *enums; 
    8489}; 
    85 typedef struct _wi_p7_spec_field                        _wi_p7_spec_field_t; 
    86  
    87  
    88 static _wi_p7_spec_field_t *                            _wi_p7_spec_field_alloc(void); 
    89 static _wi_p7_spec_field_t *                            _wi_p7_spec_field_init(_wi_p7_spec_field_t *); 
    90  
     90 
     91static _wi_p7_spec_field_t *                            _wi_p7_spec_field_with_node(wi_p7_spec_t *, xmlNodePtr); 
    9192static void                                                                     _wi_p7_spec_field_dealloc(wi_runtime_instance_t *); 
    9293static wi_string_t *                                            _wi_p7_spec_field_description(wi_runtime_instance_t *); 
    93  
    9494 
    9595static wi_runtime_id_t                                          _wi_p7_spec_field_runtime_id = WI_RUNTIME_ID_NULL; 
     
    109109         
    110110        wi_string_t                                                             *name; 
    111         uint32_t                                                              id; 
     111        wi_integer_t                                                  id; 
    112112        wi_hash_t                                                               *parameters; 
    113113}; 
    114 typedef struct _wi_p7_spec_message                      _wi_p7_spec_message_t; 
    115  
    116  
    117 static _wi_p7_spec_message_t *                          _wi_p7_spec_message_alloc(void); 
    118 static _wi_p7_spec_message_t *                          _wi_p7_spec_message_init(_wi_p7_spec_message_t *); 
    119  
     114 
     115static _wi_p7_spec_message_t *                          _wi_p7_spec_message_with_node(wi_p7_spec_t *, xmlNodePtr); 
    120116static void                                                                     _wi_p7_spec_message_dealloc(wi_runtime_instance_t *); 
    121117static wi_string_t *                                            _wi_p7_spec_message_description(wi_runtime_instance_t *); 
    122  
    123118 
    124119static wi_runtime_id_t                                          _wi_p7_spec_message_runtime_id = WI_RUNTIME_ID_NULL; 
     
    140135        wi_boolean_t                                                    required; 
    141136}; 
    142 typedef struct _wi_p7_spec_parameter            _wi_p7_spec_parameter_t; 
    143  
    144  
    145 static _wi_p7_spec_parameter_t *                        _wi_p7_spec_parameter_alloc(void); 
    146 static _wi_p7_spec_parameter_t *                        _wi_p7_spec_parameter_init(_wi_p7_spec_parameter_t *); 
    147  
     137 
     138static _wi_p7_spec_parameter_t *                        _wi_p7_spec_parameter_with_node(wi_p7_spec_t *, xmlNodePtr, _wi_p7_spec_message_t *); 
    148139static void                                                                     _wi_p7_spec_parameter_dealloc(wi_runtime_instance_t *); 
    149140static wi_string_t *                                            _wi_p7_spec_parameter_description(wi_runtime_instance_t *); 
    150  
    151141 
    152142static wi_runtime_id_t                                          _wi_p7_spec_parameter_runtime_id = WI_RUNTIME_ID_NULL; 
     
    162152 
    163153 
     154enum _wi_p7_spec_originator { 
     155        _WI_P7_SPEC_BOTH, 
     156        _WI_P7_SPEC_CLIENT, 
     157        _WI_P7_SPEC_SERVER 
     158}; 
     159typedef enum _wi_p7_spec_originator                     _wi_p7_spec_originator_t; 
     160 
    164161struct _wi_p7_spec_transaction { 
    165162        wi_runtime_base_t                                               base; 
    166163 
    167164        _wi_p7_spec_message_t                                   *message; 
     165        _wi_p7_spec_originator_t                                originator; 
    168166        wi_boolean_t                                                    required; 
    169         wi_array_t                                                              *replies_array; 
    170         wi_hash_t                                                               *replies_hash; 
     167        _wi_p7_spec_andor_t                                             *andor; 
    171168}; 
    172 typedef struct _wi_p7_spec_transaction          _wi_p7_spec_transaction_t; 
    173  
    174  
    175 static _wi_p7_spec_transaction_t *                      _wi_p7_spec_transaction_alloc(void); 
    176 static _wi_p7_spec_transaction_t *                      _wi_p7_spec_transaction_init(_wi_p7_spec_transaction_t *); 
    177  
     169 
     170static _wi_p7_spec_transaction_t *                      _wi_p7_spec_transaction_with_node(wi_p7_spec_t *, xmlNodePtr); 
    178171static void                                                                     _wi_p7_spec_transaction_dealloc(wi_runtime_instance_t *); 
    179172static wi_string_t *                                            _wi_p7_spec_transaction_description(wi_runtime_instance_t *); 
    180  
    181173 
    182174static wi_runtime_id_t                                          _wi_p7_spec_transaction_runtime_id = WI_RUNTIME_ID_NULL; 
     
    192184 
    193185 
     186enum _wi_p7_spec_andor_type { 
     187        _WI_P7_SPEC_AND, 
     188        _WI_P7_SPEC_OR 
     189}; 
     190typedef enum _wi_p7_spec_andor_type                     _wi_p7_spec_andor_type_t; 
     191 
     192struct _wi_p7_spec_andor { 
     193        wi_runtime_base_t                                               base; 
     194 
     195        _wi_p7_spec_andor_type_t                                type; 
     196        wi_array_t                                                              *children; 
     197        wi_array_t                                                              *replies_array; 
     198        wi_hash_t                                                               *replies_hash; 
     199}; 
     200 
     201static _wi_p7_spec_andor_t *                            _wi_p7_spec_andor(_wi_p7_spec_andor_type_t, wi_p7_spec_t *, xmlNodePtr, _wi_p7_spec_transaction_t *); 
     202static void                                                                     _wi_p7_spec_andor_dealloc(wi_runtime_instance_t *); 
     203static wi_string_t *                                            _wi_p7_spec_andor_description(wi_runtime_instance_t *); 
     204 
     205static wi_runtime_id_t                                          _wi_p7_spec_andor_runtime_id = WI_RUNTIME_ID_NULL; 
     206static wi_runtime_class_t                                       _wi_p7_spec_andor_runtime_class = { 
     207    "_wi_p7_spec_andor_t", 
     208    _wi_p7_spec_andor_dealloc, 
     209    NULL, 
     210    NULL, 
     211    _wi_p7_spec_andor_description, 
     212    NULL 
     213}; 
     214 
     215 
     216 
    194217struct _wi_p7_spec_reply { 
    195218        wi_runtime_base_t                                               base; 
    196219 
    197220        _wi_p7_spec_message_t                                   *message; 
    198         uint32_t                                                              count; 
     221        wi_integer_t                                                  count; 
    199222        wi_boolean_t                                                    required; 
    200223}; 
    201 typedef struct _wi_p7_spec_reply                        _wi_p7_spec_reply_t; 
    202  
    203  
    204 static _wi_p7_spec_reply_t *                            _wi_p7_spec_reply_alloc(void); 
    205 static _wi_p7_spec_reply_t *                            _wi_p7_spec_reply_init(_wi_p7_spec_reply_t *); 
    206  
     224 
     225static _wi_p7_spec_reply_t *                            _wi_p7_spec_reply_with_node(wi_p7_spec_t *, xmlNodePtr, _wi_p7_spec_transaction_t *); 
    207226static void                                                                     _wi_p7_spec_reply_dealloc(wi_runtime_instance_t *); 
    208227static wi_string_t *                                            _wi_p7_spec_reply_description(wi_runtime_instance_t *); 
    209  
    210228 
    211229static wi_runtime_id_t                                          _wi_p7_spec_reply_runtime_id = WI_RUNTIME_ID_NULL; 
     
    226244        wi_boolean_t                                                    checking; 
    227245         
    228         xmlDocPtr                                                              xml_doc
    229         wi_string_t                                                            *xml_string; 
    230          
     246        wi_string_t                                                            *xml
     247         
     248        wi_string_t                                                            *filename; 
    231249        wi_uuid_t                                                               *id; 
    232250        wi_set_t                                                                *compatible_ids; 
     
    238256}; 
    239257 
    240  
    241258static void                                                                     _wi_p7_spec_dealloc(wi_runtime_instance_t *); 
    242259static wi_string_t *                                            _wi_p7_spec_description(wi_runtime_instance_t *); 
     260 
     261static void                                                                     _wi_p7_spec_log_warn(wi_p7_spec_t *, wi_string_t *, ...); 
    243262 
    244263static wi_boolean_t                                                     _wi_p7_spec_load_builtin(wi_p7_spec_t *, wi_boolean_t); 
     
    247266static wi_boolean_t                                                     _wi_p7_spec_load_spec(wi_p7_spec_t *, xmlDocPtr); 
    248267static wi_boolean_t                                                     _wi_p7_spec_load_types(wi_p7_spec_t *, xmlNodePtr); 
    249 static _wi_p7_spec_type_t *                                     _wi_p7_spec_load_type(wi_p7_spec_t *, xmlNodePtr); 
    250268static wi_boolean_t                                                     _wi_p7_spec_load_fields(wi_p7_spec_t *, xmlNodePtr); 
    251 static _wi_p7_spec_field_t *                            _wi_p7_spec_load_field(wi_p7_spec_t *, xmlNodePtr); 
    252269static wi_boolean_t                                                     _wi_p7_spec_load_messages(wi_p7_spec_t *, xmlNodePtr); 
    253 static _wi_p7_spec_message_t *                          _wi_p7_spec_load_message(wi_p7_spec_t *, xmlNodePtr); 
    254 static _wi_p7_spec_parameter_t *                        _wi_p7_spec_load_parameter(wi_p7_spec_t *, xmlNodePtr); 
    255270static wi_boolean_t                                                     _wi_p7_spec_load_transactions(wi_p7_spec_t *, xmlNodePtr); 
    256 static _wi_p7_spec_transaction_t *                      _wi_p7_spec_load_transaction(wi_p7_spec_t *, xmlNodePtr); 
    257 static _wi_p7_spec_reply_t *                            _wi_p7_spec_load_reply(wi_p7_spec_t *, xmlNodePtr); 
    258271 
    259272static wi_boolean_t                                                     _wi_p7_spec_is_compatible(wi_p7_spec_t *, wi_p7_spec_t *); 
    260 static wi_boolean_t                                                     _wi_p7_spec_transaction_is_compatible(_wi_p7_spec_transaction_t *, _wi_p7_spec_transaction_t *); 
    261 static wi_boolean_t                                                     _wi_p7_spec_reply_is_compatible(_wi_p7_spec_reply_t *, _wi_p7_spec_reply_t *); 
    262 static wi_boolean_t                                                     _wi_p7_spec_message_is_compatible(_wi_p7_spec_message_t *, _wi_p7_spec_message_t *); 
    263  
     273static wi_boolean_t                                                     _wi_p7_spec_transaction_is_compatible(wi_p7_spec_t *, _wi_p7_spec_transaction_t *, _wi_p7_spec_transaction_t *); 
     274static wi_boolean_t                                                     _wi_p7_spec_andor_is_compatible(wi_p7_spec_t *, _wi_p7_spec_transaction_t *, _wi_p7_spec_andor_t *, _wi_p7_spec_andor_t *); 
     275static wi_boolean_t                                                     _wi_p7_spec_reply_is_compatible(wi_p7_spec_t *, _wi_p7_spec_transaction_t *, _wi_p7_spec_reply_t *, _wi_p7_spec_reply_t *); 
     276static wi_boolean_t                                                     _wi_p7_spec_message_is_compatible(wi_p7_spec_t *, _wi_p7_spec_transaction_t *, _wi_p7_spec_message_t *, _wi_p7_spec_message_t *); 
    264277 
    265278static wi_p7_spec_t                                                     *_wi_p7_spec_builtin_spec; 
     
    347360    _wi_p7_spec_parameter_runtime_id = wi_runtime_register_class(&_wi_p7_spec_parameter_runtime_class); 
    348361    _wi_p7_spec_transaction_runtime_id = wi_runtime_register_class(&_wi_p7_spec_transaction_runtime_class); 
     362    _wi_p7_spec_andor_runtime_id = wi_runtime_register_class(&_wi_p7_spec_andor_runtime_class); 
    349363    _wi_p7_spec_reply_runtime_id = wi_runtime_register_class(&_wi_p7_spec_reply_runtime_class); 
    350364} 
     
    404418        p7_spec = _wi_p7_spec_init(p7_spec); 
    405419         
     420        p7_spec->filename = wi_retain(WI_STR("(builtin)")); 
     421 
    406422        if(!_wi_p7_spec_load_builtin(p7_spec, true)) { 
     423                wi_error_set_lib_error(WI_ERROR_P7_INVALIDSPEC); 
     424                 
    407425                wi_release(p7_spec); 
    408426                 
     
    427445         
    428446        p7_spec = _wi_p7_spec_init(p7_spec); 
     447        p7_spec->checking = checking; 
     448        p7_spec->filename = wi_retain(wi_string_last_path_component(path)); 
    429449         
    430450        if(!_wi_p7_spec_load_file(p7_spec, path, checking)) { 
     451                wi_error_set_lib_error(WI_ERROR_P7_INVALIDSPEC); 
     452                 
    431453                wi_release(p7_spec); 
    432454                 
     
    453475         
    454476        if(!_wi_p7_spec_load_string(p7_spec, string, checking)) { 
     477                wi_error_set_lib_error(WI_ERROR_P7_INVALIDSPEC); 
     478                 
    455479                wi_release(p7_spec); 
    456480                 
     
    466490        wi_p7_spec_t            *p7_spec = instance; 
    467491         
    468         if(p7_spec->xml_doc) 
    469                 xmlFreeDoc(p7_spec->xml_doc); 
    470          
    471         wi_release(p7_spec->xml_string); 
    472  
     492        wi_release(p7_spec->xml); 
     493 
     494        wi_release(p7_spec->filename); 
    473495        wi_release(p7_spec->id); 
    474496         
     
    502524#pragma mark - 
    503525 
     526static void _wi_p7_spec_log_warn(wi_p7_spec_t *p7_spec, wi_string_t *fmt, ...) { 
     527        wi_string_t             *string; 
     528        va_list                 ap; 
     529         
     530        if(p7_spec->checking) { 
     531                va_start(ap, fmt); 
     532                string = wi_string_init_with_format_and_arguments(wi_string_alloc(), fmt, ap); 
     533                va_end(ap); 
     534                 
     535                if(p7_spec->filename) 
     536                        wi_log_warn(WI_STR("%@: %@"), p7_spec->filename, string); 
     537                else 
     538                        wi_log_warn(WI_STR("%@"), string); 
     539        } 
     540} 
     541 
     542 
     543 
     544#pragma mark - 
     545 
    504546static wi_boolean_t _wi_p7_spec_load_builtin(wi_p7_spec_t *p7_spec, wi_boolean_t checking) { 
    505         xmlDocPtr               xml_doc; 
    506         wi_boolean_t    result = false; 
    507          
    508 //      xml_doc = xmlParseDoc(_wi_p7_spec_builtin); 
    509         xml_doc = xmlParseFile("p7spec.xml"); 
    510          
    511         if(!xml_doc) { 
     547        xmlDocPtr               doc; 
     548         
     549//      doc = xmlParseDoc(_wi_p7_spec_builtin); 
     550        doc = xmlParseFile("p7.xml"); 
     551         
     552        if(!doc) { 
    512553                wi_error_set_libxml2_error(); 
    513554                 
    514                 goto end
     555                return false
    515556        } 
    516557         
    517558        p7_spec->checking = checking; 
    518559         
    519         if(_wi_p7_spec_load_spec(p7_spec, xml_doc)) 
    520                 result = true; 
    521  
    522 end: 
    523         if(xml_doc) 
    524                 xmlFreeDoc(xml_doc); 
    525          
    526         return result; 
     560        if(!_wi_p7_spec_load_spec(p7_spec, doc)) { 
     561                xmlFreeDoc(doc); 
     562                 
     563                return false; 
     564        } 
     565 
     566        xmlFreeDoc(doc); 
     567         
     568        return true; 
    527569} 
    528570 
     
    530572 
    531573static wi_boolean_t _wi_p7_spec_load_file(wi_p7_spec_t *p7_spec, wi_string_t *path, wi_boolean_t checking) { 
     574        xmlDocPtr       doc; 
    532575        xmlChar         *buffer; 
    533576        int                     length; 
    534577         
    535         p7_spec->checking = checking; 
    536         p7_spec->xml_doc = xmlReadFile(wi_string_cstring(path), NULL, 0); 
    537          
    538         if(!p7_spec->xml_doc) { 
     578        doc = xmlReadFile(wi_string_cstring(path), NULL, 0); 
     579         
     580        if(!doc) { 
    539581                wi_error_set_libxml2_error(); 
    540582                 
     
    542584        } 
    543585         
    544         if(!_wi_p7_spec_load_spec(p7_spec, p7_spec->xml_doc)) { 
    545                 xmlFreeDoc(p7_spec->xml_doc); 
    546                 p7_spec->xml_doc = NULL; 
    547                  
    548                 wi_error_set_libxml2_error(); 
     586        if(!_wi_p7_spec_load_spec(p7_spec, doc)) { 
     587                xmlFreeDoc(doc); 
    549588 
    550589                return false; 
    551590        } 
    552591         
    553         xmlDocDumpMemory(p7_spec->xml_doc, &buffer, &length); 
    554          
    555         p7_spec->xml_string = wi_string_init_with_bytes(wi_string_alloc(), (const char *) buffer, length); 
    556          
     592        xmlDocDumpMemory(doc, &buffer, &length); 
     593         
     594        p7_spec->xml = wi_string_init_with_bytes(wi_string_alloc(), (const char *) buffer, length); 
     595         
     596        xmlFreeDoc(doc); 
    557597        xmlFree(buffer); 
    558598 
     
    563603 
    564604static wi_boolean_t _wi_p7_spec_load_string(wi_p7_spec_t *p7_spec, wi_string_t *string, wi_boolean_t checking) { 
     605        xmlDocPtr       doc; 
    565606        xmlChar         *buffer; 
    566607        int                     length; 
    567608         
     609        doc = xmlReadMemory(wi_string_cstring(string), wi_string_length(string), NULL, NULL, 0); 
     610         
     611        if(!doc) { 
     612                wi_error_set_libxml2_error(); 
     613 
     614                return false; 
     615        } 
     616         
    568617        p7_spec->checking = checking; 
    569         p7_spec->xml_doc = xmlReadMemory(wi_string_cstring(string), wi_string_length(string), NULL, NULL, 0); 
    570          
    571         if(!p7_spec->xml_doc) { 
    572                 wi_error_set_libxml2_error(); 
     618         
     619        if(!_wi_p7_spec_load_spec(p7_spec, doc)) { 
     620                xmlFreeDoc(doc); 
    573621 
    574622                return false; 
    575623        } 
    576624         
    577         if(!_wi_p7_spec_load_spec(p7_spec, p7_spec->xml_doc)) { 
    578                 xmlFreeDoc(p7_spec->xml_doc); 
    579                 p7_spec->xml_doc = NULL; 
    580                  
    581                 wi_error_set_libxml2_error(); 
    582  
    583                 return false; 
    584         } 
    585          
    586         xmlDocDumpMemory(p7_spec->xml_doc, &buffer, &length); 
    587          
    588         p7_spec->xml_string = wi_string_init_with_bytes(wi_string_alloc(), (const char *) buffer, length); 
    589          
     625        xmlDocDumpMemory(doc, &buffer, &length); 
     626         
     627        p7_spec->xml = wi_string_init_with_bytes(wi_string_alloc(), (const char *) buffer, length); 
     628         
     629        xmlFreeDoc(doc); 
    590630        xmlFree(buffer); 
    591631 
     
    595635 
    596636 
    597 static wi_boolean_t _wi_p7_spec_load_spec(wi_p7_spec_t *p7_spec, xmlDocPtr xml_doc) { 
     637static wi_boolean_t _wi_p7_spec_load_spec(wi_p7_spec_t *p7_spec, xmlDocPtr doc) { 
    598638        wi_string_t             *string; 
    599639        xmlNodePtr              root_node, node; 
    600640         
    601         root_node = xmlDocGetRootElement(xml_doc); 
     641        root_node = xmlDocGetRootElement(doc); 
    602642         
    603643        string = wi_p7_xml_string_for_attribute(root_node, WI_STR("id")); 
     
    632672 
    633673 
    634 static wi_boolean_t _wi_p7_spec_load_types(wi_p7_spec_t *p7_spec, xmlNodePtr types_node) { 
     674static wi_boolean_t _wi_p7_spec_load_types(wi_p7_spec_t *p7_spec, xmlNodePtr node) { 
    635675        _wi_p7_spec_type_t              *type; 
    636676        xmlNodePtr                              type_node; 
    637677         
    638         for(type_node = types_node->children; type_node != NULL; type_node = type_node->next) { 
     678        for(type_node = node->children; type_node != NULL; type_node = type_node->next) { 
    639679                if(type_node->type == XML_ELEMENT_NODE) { 
    640                         type = _wi_p7_spec_load_type(p7_spec, type_node); 
     680                        type = _wi_p7_spec_type_with_node(p7_spec, type_node); 
    641681                         
    642682                        if(!type) { 
     
    649689                        if(p7_spec->checking) { 
    650690                                if(wi_hash_data_for_key(p7_spec->types_name, type->name)) { 
    651                                         wi_log_warn(WI_STR("type with name \"%@\" already exists"), type->name); 
     691                                        _wi_p7_spec_log_warn(p7_spec, WI_STR("Type with name \"%@\" already exists"), 
     692                                                type->name); 
    652693                                         
    653694                                        return false; 
     
    655696 
    656697                                if(wi_hash_data_for_key(p7_spec->types_id, (void *) type->id)) { 
    657                                         wi_log_warn(WI_STR("type with id %u already exists"), type->id); 
     698                                        _wi_p7_spec_log_warn(p7_spec, WI_STR("Type with id %u (name \"%@\") already exists"), 
     699                                                type->name, type->id); 
    658700                                         
    659701                                        return false; 
     
    671713 
    672714 
    673 static _wi_p7_spec_type_t * _wi_p7_spec_load_type(wi_p7_spec_t *p7_spec, xmlNodePtr type_node) { 
    674         _wi_p7_spec_type_t              *type; 
    675  
    676         type                    = wi_autorelease(_wi_p7_spec_type_init(_wi_p7_spec_type_alloc())); 
    677         type->name              = wi_retain(wi_p7_xml_string_for_attribute(type_node, WI_STR("name"))); 
    678         type->size              = wi_p7_xml_int32_for_attribute(type_node, WI_STR("size")); 
    679         type->id                = wi_p7_xml_int32_for_attribute(type_node, WI_STR("id")); 
    680          
    681         if(!type->name) { 
    682                 wi_log_warn(WI_STR("type has no name")); 
    683                  
    684                 return NULL; 
    685         } 
    686          
    687         if(type->id == 0) { 
    688                 wi_log_warn(WI_STR("type has no id")); 
    689                  
    690                 return NULL; 
    691         } 
    692          
    693         return type; 
    694 
    695  
    696  
    697  
    698 static wi_boolean_t _wi_p7_spec_load_fields(wi_p7_spec_t *p7_spec, xmlNodePtr fields_node) { 
     715static wi_boolean_t _wi_p7_spec_load_fields(wi_p7_spec_t *p7_spec, xmlNodePtr node) { 
    699716        _wi_p7_spec_field_t             *field; 
    700717        xmlNodePtr                              field_node; 
    701718         
    702         for(field_node = fields_node->children; field_node != NULL; field_node = field_node->next) { 
     719        for(field_node = node->children; field_node != NULL; field_node = field_node->next) { 
    703720                if(field_node->type == XML_ELEMENT_NODE) { 
    704                         field = _wi_p7_spec_load_field(p7_spec, field_node); 
     721                        field = _wi_p7_spec_field_with_node(p7_spec, field_node); 
    705722                         
    706723                        if(!field) { 
     
    713730                        if(p7_spec->checking) { 
    714731                                if(wi_hash_data_for_key(p7_spec->fields_name, field->name)) { 
    715                                         wi_log_warn(WI_STR("field with name \"%@\" already exists"), field->name); 
     732                                        _wi_p7_spec_log_warn(p7_spec, WI_STR("Field with name \"%@\" already exists"), 
     733                                                field->name); 
    716734                                         
    717735                                        return false; 
     
    719737                                 
    720738                                if(wi_hash_data_for_key(p7_spec->fields_id, (void *) field->id)) { 
    721                                         wi_log_warn(WI_STR("field with id %u already exists"), field->id); 
     739                                        _wi_p7_spec_log_warn(p7_spec, WI_STR("Field with id %u (name \"%@\") already exists"), 
     740                                                field->name, field->id); 
    722741                                         
    723742                                        return false; 
     
    735754 
    736755 
    737 static _wi_p7_spec_field_t * _wi_p7_spec_load_field(wi_p7_spec_t *p7_spec, xmlNodePtr field_node) { 
    738         _wi_p7_spec_field_t             *field; 
    739         wi_string_t                             *type_name; 
    740  
    741         field                   = wi_autorelease(_wi_p7_spec_field_init(_wi_p7_spec_field_alloc())); 
    742         field->name             = wi_retain(wi_p7_xml_string_for_attribute(field_node, WI_STR("name"))); 
    743       &nbs