Changeset 4601
- Timestamp:
- 02/13/07 19:38:10 (2 years ago)
- Files:
-
- libwired/trunk/libwired/base/wi-error.c (modified) (1 diff)
- libwired/trunk/libwired/base/wi-error.h (modified) (1 diff)
- libwired/trunk/libwired/p7/wi-p7-message.c (modified) (3 diffs)
- libwired/trunk/libwired/p7/wi-p7-message.h (modified) (3 diffs)
- libwired/trunk/libwired/p7/wi-p7-private.c (modified) (1 diff)
- libwired/trunk/libwired/p7/wi-p7-private.h (modified) (1 diff)
- libwired/trunk/libwired/p7/wi-p7-socket.c (modified) (2 diffs)
- libwired/trunk/libwired/p7/wi-p7-spec.c (modified) (55 diffs)
- libwired/trunk/libwired/p7/wi-p7-spec.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libwired/trunk/libwired/base/wi-error.c
r4590 r4601 91 91 "No such syslog facility", 92 92 93 /* WI_ERROR_P7_INVALIDSPEC */ 94 "Invalid specification", 95 93 96 /* WI_ERROR_REGEXP_NOSLASH */ 94 97 "Missing \"/\"", libwired/trunk/libwired/base/wi-error.h
r4590 r4601 57 57 58 58 WI_ERROR_LOG_NOSUCHFACILITY, 59 60 WI_ERROR_P7_INVALIDSPEC, 59 61 60 62 WI_ERROR_REGEXP_NOSLASH, libwired/trunk/libwired/p7/wi-p7-message.c
r4591 r4601 383 383 wi_date_t *date; 384 384 wi_p7_boolean_t p7_bool; 385 wi_p7_enum_t p7_enum; 385 386 wi_p7_int32_t p7_int32; 386 387 wi_p7_uint32_t p7_uint32; … … 398 399 break; 399 400 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 400 406 case WI_P7_INT32: 401 407 if(wi_p7_message_get_int32_for_name(p7_message, &p7_int32, field_name)) … … 760 766 761 767 768 wi_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 790 wi_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 762 813 wi_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) { 763 814 wi_string_t *string; libwired/trunk/libwired/p7/wi-p7-message.h
r4590 r4601 39 39 40 40 typedef char wi_p7_boolean_t; 41 typedef uint32_t wi_p7_enum_t; 41 42 typedef int32_t wi_p7_int32_t; 42 43 typedef uint32_t wi_p7_uint32_t; … … 49 50 enum _wi_p7_type { 50 51 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 61 63 }; 62 64 typedef enum _wi_p7_type wi_p7_type_t; … … 80 82 WI_EXPORT wi_boolean_t wi_p7_message_set_bool_for_name(wi_p7_message_t *, wi_p7_boolean_t, wi_string_t *); 81 83 WI_EXPORT wi_boolean_t wi_p7_message_get_bool_for_name(wi_p7_message_t *, wi_p7_boolean_t *, wi_string_t *); 84 WI_EXPORT wi_boolean_t wi_p7_message_set_enum_for_name(wi_p7_message_t *, wi_p7_enum_t, wi_string_t *); 85 WI_EXPORT wi_boolean_t wi_p7_message_get_enum_for_name(wi_p7_message_t *, wi_p7_enum_t *, wi_string_t *); 82 86 WI_EXPORT wi_boolean_t wi_p7_message_set_int32_for_name(wi_p7_message_t *, wi_p7_int32_t, wi_string_t *); 83 87 WI_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 54 54 55 55 56 int32_t wi_p7_xml_int32_for_attribute(xmlNodePtr node, wi_string_t *attribute) { 57 xmlChar *prop; 58 int32_t value; 56 wi_integer_t wi_p7_xml_integer_for_attribute(xmlNodePtr node, wi_string_t *attribute) { 57 wi_string_t *string; 59 58 60 prop = xmlGetProp(node, (xmlChar *) wi_string_cstring(attribute));59 string = wi_p7_xml_string_for_attribute(node, attribute); 61 60 62 if(! prop)61 if(!string) 63 62 return 0; 64 63 65 value = strtol((const char *) prop, NULL, 0); 66 67 xmlFree(prop); 68 69 return value; 64 return wi_string_integer(string); 70 65 } 71 66 libwired/trunk/libwired/p7/wi-p7-private.h
r4578 r4601 63 63 WI_EXPORT void wi_p7_message_deserialize(wi_p7_message_t *); 64 64 65 WI_EXPORT wi_boolean_t wi_p7_spec_is_checking(wi_p7_spec_t *); 66 65 67 WI_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 *);68 WI_EXPORT wi_integer_t wi_p7_xml_integer_for_attribute(xmlNodePtr, wi_string_t *); 67 69 68 70 #endif libwired/trunk/libwired/p7/wi-p7-socket.c
r4598 r4601 718 718 return false; 719 719 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")); 721 721 722 722 if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message)) { … … 779 779 } 780 780 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)); 782 782 783 783 if(!p7_spec) { libwired/trunk/libwired/p7/wi-p7-spec.c
r4590 r4601 47 47 #include <wired/wi-string.h> 48 48 49 typedef struct _wi_p7_spec_type _wi_p7_spec_type_t; 50 typedef struct _wi_p7_spec_field _wi_p7_spec_field_t; 51 typedef struct _wi_p7_spec_message _wi_p7_spec_message_t; 52 typedef struct _wi_p7_spec_parameter _wi_p7_spec_parameter_t; 53 typedef struct _wi_p7_spec_transaction _wi_p7_spec_transaction_t; 54 typedef struct _wi_p7_spec_andor _wi_p7_spec_andor_t; 55 typedef struct _wi_p7_spec_reply _wi_p7_spec_reply_t; 56 57 49 58 struct _wi_p7_spec_type { 50 59 wi_runtime_base_t base; 51 60 52 61 wi_string_t *name; 53 uint32_tsize;54 uint32_tid;62 wi_integer_t size; 63 wi_integer_t id; 55 64 }; 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 66 static _wi_p7_spec_type_t * _wi_p7_spec_type_with_node(wi_p7_spec_t *, xmlNodePtr); 62 67 static void _wi_p7_spec_type_dealloc(wi_runtime_instance_t *); 63 68 static wi_string_t * _wi_p7_spec_type_description(wi_runtime_instance_t *); 64 65 69 66 70 static wi_runtime_id_t _wi_p7_spec_type_runtime_id = WI_RUNTIME_ID_NULL; … … 80 84 81 85 wi_string_t *name; 82 uint32_tid;86 wi_integer_t id; 83 87 _wi_p7_spec_type_t *type; 88 wi_hash_t *enums; 84 89 }; 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 91 static _wi_p7_spec_field_t * _wi_p7_spec_field_with_node(wi_p7_spec_t *, xmlNodePtr); 91 92 static void _wi_p7_spec_field_dealloc(wi_runtime_instance_t *); 92 93 static wi_string_t * _wi_p7_spec_field_description(wi_runtime_instance_t *); 93 94 94 95 95 static wi_runtime_id_t _wi_p7_spec_field_runtime_id = WI_RUNTIME_ID_NULL; … … 109 109 110 110 wi_string_t *name; 111 uint32_tid;111 wi_integer_t id; 112 112 wi_hash_t *parameters; 113 113 }; 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 115 static _wi_p7_spec_message_t * _wi_p7_spec_message_with_node(wi_p7_spec_t *, xmlNodePtr); 120 116 static void _wi_p7_spec_message_dealloc(wi_runtime_instance_t *); 121 117 static wi_string_t * _wi_p7_spec_message_description(wi_runtime_instance_t *); 122 123 118 124 119 static wi_runtime_id_t _wi_p7_spec_message_runtime_id = WI_RUNTIME_ID_NULL; … … 140 135 wi_boolean_t required; 141 136 }; 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 138 static _wi_p7_spec_parameter_t * _wi_p7_spec_parameter_with_node(wi_p7_spec_t *, xmlNodePtr, _wi_p7_spec_message_t *); 148 139 static void _wi_p7_spec_parameter_dealloc(wi_runtime_instance_t *); 149 140 static wi_string_t * _wi_p7_spec_parameter_description(wi_runtime_instance_t *); 150 151 141 152 142 static wi_runtime_id_t _wi_p7_spec_parameter_runtime_id = WI_RUNTIME_ID_NULL; … … 162 152 163 153 154 enum _wi_p7_spec_originator { 155 _WI_P7_SPEC_BOTH, 156 _WI_P7_SPEC_CLIENT, 157 _WI_P7_SPEC_SERVER 158 }; 159 typedef enum _wi_p7_spec_originator _wi_p7_spec_originator_t; 160 164 161 struct _wi_p7_spec_transaction { 165 162 wi_runtime_base_t base; 166 163 167 164 _wi_p7_spec_message_t *message; 165 _wi_p7_spec_originator_t originator; 168 166 wi_boolean_t required; 169 wi_array_t *replies_array; 170 wi_hash_t *replies_hash; 167 _wi_p7_spec_andor_t *andor; 171 168 }; 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 170 static _wi_p7_spec_transaction_t * _wi_p7_spec_transaction_with_node(wi_p7_spec_t *, xmlNodePtr); 178 171 static void _wi_p7_spec_transaction_dealloc(wi_runtime_instance_t *); 179 172 static wi_string_t * _wi_p7_spec_transaction_description(wi_runtime_instance_t *); 180 181 173 182 174 static wi_runtime_id_t _wi_p7_spec_transaction_runtime_id = WI_RUNTIME_ID_NULL; … … 192 184 193 185 186 enum _wi_p7_spec_andor_type { 187 _WI_P7_SPEC_AND, 188 _WI_P7_SPEC_OR 189 }; 190 typedef enum _wi_p7_spec_andor_type _wi_p7_spec_andor_type_t; 191 192 struct _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 201 static _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 *); 202 static void _wi_p7_spec_andor_dealloc(wi_runtime_instance_t *); 203 static wi_string_t * _wi_p7_spec_andor_description(wi_runtime_instance_t *); 204 205 static wi_runtime_id_t _wi_p7_spec_andor_runtime_id = WI_RUNTIME_ID_NULL; 206 static 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 194 217 struct _wi_p7_spec_reply { 195 218 wi_runtime_base_t base; 196 219 197 220 _wi_p7_spec_message_t *message; 198 uint32_tcount;221 wi_integer_t count; 199 222 wi_boolean_t required; 200 223 }; 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 225 static _wi_p7_spec_reply_t * _wi_p7_spec_reply_with_node(wi_p7_spec_t *, xmlNodePtr, _wi_p7_spec_transaction_t *); 207 226 static void _wi_p7_spec_reply_dealloc(wi_runtime_instance_t *); 208 227 static wi_string_t * _wi_p7_spec_reply_description(wi_runtime_instance_t *); 209 210 228 211 229 static wi_runtime_id_t _wi_p7_spec_reply_runtime_id = WI_RUNTIME_ID_NULL; … … 226 244 wi_boolean_t checking; 227 245 228 xmlDocPtr xml_doc;229 wi_string_t *xml_string;230 246 wi_string_t *xml; 247 248 wi_string_t *filename; 231 249 wi_uuid_t *id; 232 250 wi_set_t *compatible_ids; … … 238 256 }; 239 257 240 241 258 static void _wi_p7_spec_dealloc(wi_runtime_instance_t *); 242 259 static wi_string_t * _wi_p7_spec_description(wi_runtime_instance_t *); 260 261 static void _wi_p7_spec_log_warn(wi_p7_spec_t *, wi_string_t *, ...); 243 262 244 263 static wi_boolean_t _wi_p7_spec_load_builtin(wi_p7_spec_t *, wi_boolean_t); … … 247 266 static wi_boolean_t _wi_p7_spec_load_spec(wi_p7_spec_t *, xmlDocPtr); 248 267 static 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);250 268 static 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);252 269 static 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);255 270 static 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);258 271 259 272 static 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 273 static wi_boolean_t _wi_p7_spec_transaction_is_compatible(wi_p7_spec_t *, _wi_p7_spec_transaction_t *, _wi_p7_spec_transaction_t *); 274 static 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 *); 275 static 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 *); 276 static 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 *); 264 277 265 278 static wi_p7_spec_t *_wi_p7_spec_builtin_spec; … … 347 360 _wi_p7_spec_parameter_runtime_id = wi_runtime_register_class(&_wi_p7_spec_parameter_runtime_class); 348 361 _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); 349 363 _wi_p7_spec_reply_runtime_id = wi_runtime_register_class(&_wi_p7_spec_reply_runtime_class); 350 364 } … … 404 418 p7_spec = _wi_p7_spec_init(p7_spec); 405 419 420 p7_spec->filename = wi_retain(WI_STR("(builtin)")); 421 406 422 if(!_wi_p7_spec_load_builtin(p7_spec, true)) { 423 wi_error_set_lib_error(WI_ERROR_P7_INVALIDSPEC); 424 407 425 wi_release(p7_spec); 408 426 … … 427 445 428 446 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)); 429 449 430 450 if(!_wi_p7_spec_load_file(p7_spec, path, checking)) { 451 wi_error_set_lib_error(WI_ERROR_P7_INVALIDSPEC); 452 431 453 wi_release(p7_spec); 432 454 … … 453 475 454 476 if(!_wi_p7_spec_load_string(p7_spec, string, checking)) { 477 wi_error_set_lib_error(WI_ERROR_P7_INVALIDSPEC); 478 455 479 wi_release(p7_spec); 456 480 … … 466 490 wi_p7_spec_t *p7_spec = instance; 467 491 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); 473 495 wi_release(p7_spec->id); 474 496 … … 502 524 #pragma mark - 503 525 526 static 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 504 546 static 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) { 512 553 wi_error_set_libxml2_error(); 513 554 514 goto end;555 return false; 515 556 } 516 557 517 558 p7_spec->checking = checking; 518 559 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; 527 569 } 528 570 … … 530 572 531 573 static 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; 532 575 xmlChar *buffer; 533 576 int length; 534 577 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) { 539 581 wi_error_set_libxml2_error(); 540 582 … … 542 584 } 543 585 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); 549 588 550 589 return false; 551 590 } 552 591 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); 557 597 xmlFree(buffer); 558 598 … … 563 603 564 604 static 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; 565 606 xmlChar *buffer; 566 607 int length; 567 608 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 568 617 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); 573 621 574 622 return false; 575 623 } 576 624 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); 590 630 xmlFree(buffer); 591 631 … … 595 635 596 636 597 static wi_boolean_t _wi_p7_spec_load_spec(wi_p7_spec_t *p7_spec, xmlDocPtr xml_doc) {637 static wi_boolean_t _wi_p7_spec_load_spec(wi_p7_spec_t *p7_spec, xmlDocPtr doc) { 598 638 wi_string_t *string; 599 639 xmlNodePtr root_node, node; 600 640 601 root_node = xmlDocGetRootElement( xml_doc);641 root_node = xmlDocGetRootElement(doc); 602 642 603 643 string = wi_p7_xml_string_for_attribute(root_node, WI_STR("id")); … … 632 672 633 673 634 static wi_boolean_t _wi_p7_spec_load_types(wi_p7_spec_t *p7_spec, xmlNodePtr types_node) {674 static wi_boolean_t _wi_p7_spec_load_types(wi_p7_spec_t *p7_spec, xmlNodePtr node) { 635 675 _wi_p7_spec_type_t *type; 636 676 xmlNodePtr type_node; 637 677 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) { 639 679 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); 641 681 642 682 if(!type) { … … 649 689 if(p7_spec->checking) { 650 690 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); 652 693 653 694 return false; … … 655 696 656 697 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); 658 700 659 701 return false; … … 671 713 672 714 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) { 715 static wi_boolean_t _wi_p7_spec_load_fields(wi_p7_spec_t *p7_spec, xmlNodePtr node) { 699 716 _wi_p7_spec_field_t *field; 700 717 xmlNodePtr field_node; 701 718 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) { 703 720 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); 705 722 706 723 if(!field) { … … 713 730 if(p7_spec->checking) { 714 731 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); 716 734 717 735 return false; … … 719 737 720 738 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); 722 741 723 742 return false; … … 735 754 736 755 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
