Changeset 5538
- Timestamp:
- 05/28/08 13:49:25 (4 months ago)
- Files:
-
- libwired/trunk/libwired/p7/wi-p7-message.c (modified) (42 diffs)
- libwired/trunk/libwired/p7/wi-p7-socket.c (modified) (4 diffs)
- libwired/trunk/libwired/p7/wi-p7-socket.h (modified) (2 diffs)
- libwired/trunk/libwired/p7/wi-p7-spec.c (modified) (60 diffs)
- libwired/trunk/libwired/p7/wi-p7-spec.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libwired/trunk/libwired/p7/wi-p7-message.c
r5453 r5538 55 55 static wi_string_t * _wi_p7_message_description(wi_runtime_instance_t *); 56 56 57 static wi_string_t * _wi_p7_message_field_string_value(wi_p7_message_t *, wi_ string_t *, wi_p7_type_t);57 static wi_string_t * _wi_p7_message_field_string_value(wi_p7_message_t *, wi_p7_spec_field_t *); 58 58 static wi_boolean_t _wi_p7_message_get_binary_buffer_for_reading_for_id(wi_p7_message_t *, uint32_t, unsigned char **, uint32_t *); 59 59 static wi_boolean_t _wi_p7_message_get_binary_buffer_for_reading_for_name(wi_p7_message_t *, wi_string_t *, unsigned char **, uint32_t *); 60 60 static wi_boolean_t _wi_p7_message_get_binary_buffer_for_writing_for_id(wi_p7_message_t *, uint32_t, uint32_t, unsigned char **); 61 61 static wi_boolean_t _wi_p7_message_get_binary_buffer_for_writing_for_name(wi_p7_message_t *, wi_string_t *, uint32_t, unsigned char **, uint32_t *); 62 static void _wi_p7_message_set_xml_field(wi_p7_message_t *, wi_ p7_type_t, wi_string_t *, wi_string_t *);62 static void _wi_p7_message_set_xml_field(wi_p7_message_t *, wi_string_t *, wi_string_t *, wi_p7_spec_type_t *); 63 63 static xmlNodePtr _wi_p7_message_xml_node_for_name(wi_p7_message_t *, const char *); 64 64 static wi_string_t * _wi_p7_message_xml_copy_value_for_name(wi_p7_message_t *, wi_string_t *); 65 static wi_p7_ type_t_wi_p7_message_xml_type_for_name(wi_p7_message_t *, wi_string_t *);65 static wi_p7_spec_type_t * _wi_p7_message_xml_type_for_name(wi_p7_message_t *, wi_string_t *); 66 66 67 67 … … 203 203 204 204 static wi_string_t * _wi_p7_message_description(wi_runtime_instance_t *instance) { 205 wi_p7_message_t *p7_message = instance; 206 wi_string_t *description, *xml_string, *field_name, *type_name, *field_value; 207 xmlNodePtr node; 208 unsigned char *buffer, *start; 209 wi_p7_type_t type_id; 210 uint32_t message_size, field_id, field_size; 211 205 wi_p7_message_t *p7_message = instance; 206 wi_string_t *description, *xml_string, *field_name, *field_value; 207 wi_p7_spec_field_t *field; 208 xmlNodePtr node; 209 unsigned char *buffer, *start; 210 uint32_t message_size, field_id, field_size; 212 211 213 212 description = wi_string_init_with_format(wi_string_alloc(), WI_STR("<%@ %p>{name = %@, serialization = %@"), … … 238 237 buffer += sizeof(field_id); 239 238 240 field_size = wi_p7_spec_field_size(p7_message->spec, field_id); 239 field = wi_p7_spec_field_with_id(p7_message->spec, field_id); 240 field_size = wi_p7_spec_field_size(field); 241 241 242 242 if(field_size == 0) { … … 246 246 } 247 247 248 field_name = wi_p7_spec_field_name(p7_message->spec, field_id); 249 type_id = wi_p7_spec_field_type(p7_message->spec, field_id); 250 field_value = _wi_p7_message_field_string_value(p7_message, field_name, type_id); 248 field_name = wi_p7_spec_field_name(field); 249 field_value = _wi_p7_message_field_string_value(p7_message, field); 251 250 252 251 wi_string_append_format(description, WI_STR(" %@ = %@\n"), … … 260 259 if(node->type == XML_ELEMENT_NODE) { 261 260 field_name = wi_autorelease(wi_p7_xml_copy_string_for_attribute(node, WI_STR("name"))); 262 type_name = wi_autorelease(wi_p7_xml_copy_string_for_attribute(node, WI_STR("type"))); 263 type_id = wi_p7_spec_type_id(p7_message->spec, type_name); 264 field_value = _wi_p7_message_field_string_value(p7_message, field_name, type_id); 261 field = wi_p7_spec_field_with_name(p7_message->spec, field_name); 262 field_value = _wi_p7_message_field_string_value(p7_message, field); 265 263 266 264 wi_string_append_format(description, WI_STR(" %@ = %@\n"), … … 442 440 #pragma mark - 443 441 444 static wi_string_t * _wi_p7_message_field_string_value(wi_p7_message_t *p7_message, wi_ string_t *field_name, wi_p7_type_t type_id) {445 wi_string_t *field_ value = NULL;442 static wi_string_t * _wi_p7_message_field_string_value(wi_p7_message_t *p7_message, wi_p7_spec_field_t *field) { 443 wi_string_t *field_name, *field_value = NULL; 446 444 wi_uuid_t *uuid; 447 445 wi_date_t *date; … … 458 456 wi_array_t *list; 459 457 460 switch(type_id) { 458 field_name = wi_p7_spec_field_name(field); 459 460 switch(wi_p7_spec_type_id(wi_p7_spec_field_type(field))) { 461 461 case WI_P7_BOOL: 462 462 if(wi_p7_message_get_bool_for_name(p7_message, &p7_bool, field_name)) … … 466 466 case WI_P7_ENUM: 467 467 if(wi_p7_message_get_enum_for_name(p7_message, &p7_enum, field_name)) 468 field_value = wi_ p7_spec_enum_name(p7_message->spec, wi_p7_spec_field_id(p7_message->spec, field_name),p7_enum);468 field_value = wi_hash_data_for_key(wi_p7_spec_field_enums_by_value(field), (void *) p7_enum); 469 469 break; 470 470 … … 541 541 542 542 static wi_boolean_t _wi_p7_message_get_binary_buffer_for_reading_for_id(wi_p7_message_t *p7_message, uint32_t in_field_id, unsigned char **out_buffer, uint32_t *out_field_size) { 543 unsigned char *buffer, *start; 544 uint32_t message_size, field_id, field_size; 543 wi_p7_spec_field_t *field; 544 unsigned char *buffer, *start; 545 uint32_t message_size, field_id, field_size; 545 546 546 547 message_size = p7_message->binary_size - WI_P7_MESSAGE_BINARY_HEADER_SIZE; … … 552 553 buffer += sizeof(field_id); 553 554 554 field_size = wi_p7_spec_field_size(p7_message->spec, field_id); 555 555 field = wi_p7_spec_field_with_id(p7_message->spec, field_id); 556 field_size = wi_p7_spec_field_size(field); 557 556 558 if(field_size == 0) { 557 559 field_size = wi_read_swap_big_to_host_int32(buffer, 0); … … 579 581 580 582 static wi_boolean_t _wi_p7_message_get_binary_buffer_for_reading_for_name(wi_p7_message_t *p7_message, wi_string_t *field_name, unsigned char **out_buffer, uint32_t *out_field_size) { 581 uint32_t field_id; 582 583 field_id = wi_p7_spec_field_id(p7_message->spec, field_name); 584 585 if(field_id == WI_P7_SPEC_FIELD_ID_NULL) { 583 wi_p7_spec_field_t *field; 584 uint32_t field_id; 585 586 field = wi_p7_spec_field_with_name(p7_message->spec, field_name); 587 588 if(!field) { 586 589 wi_error_set_libwired_p7_error(WI_ERROR_P7_UNKNOWNFIELD, 587 590 WI_STR("No id found for field \"%@\""), field_name); … … 593 596 } 594 597 598 field_id = wi_p7_spec_field_id(field); 599 595 600 return _wi_p7_message_get_binary_buffer_for_reading_for_id(p7_message, field_id, out_buffer, out_field_size); 596 601 } … … 599 604 600 605 static wi_boolean_t _wi_p7_message_get_binary_buffer_for_writing_for_id(wi_p7_message_t *p7_message, uint32_t field_id, uint32_t length, unsigned char **out_buffer) { 601 uint32_t field_size, new_size; 602 603 new_size = sizeof(field_id); 604 field_size = wi_p7_spec_field_size(p7_message->spec, field_id); 606 wi_p7_spec_field_t *field; 607 uint32_t field_size, new_size; 608 609 new_size = sizeof(field_id); 610 field = wi_p7_spec_field_with_id(p7_message->spec, field_id); 611 field_size = wi_p7_spec_field_size(field); 605 612 606 613 if(field_size == 0) { … … 630 637 631 638 static wi_boolean_t _wi_p7_message_get_binary_buffer_for_writing_for_name(wi_p7_message_t *p7_message, wi_string_t *field_name, uint32_t length, unsigned char **out_buffer, uint32_t *out_field_id) { 632 uint32_t field_id; 633 634 field_id = wi_p7_spec_field_id(p7_message->spec, field_name); 635 636 if(field_id == WI_P7_SPEC_FIELD_ID_NULL) { 639 wi_p7_spec_field_t *field; 640 uint32_t field_id; 641 642 field = wi_p7_spec_field_with_name(p7_message->spec, field_name); 643 644 if(!field) { 637 645 wi_error_set_libwired_p7_error(WI_ERROR_P7_UNKNOWNFIELD, 638 646 WI_STR("No id found for field \"%@\""), field_name); … … 644 652 } 645 653 654 field_id = wi_p7_spec_field_id(field); 655 646 656 if(out_field_id) 647 657 *out_field_id = field_id; … … 652 662 653 663 654 static void _wi_p7_message_set_xml_field(wi_p7_message_t *p7_message, wi_ p7_type_t type_id, wi_string_t *field_name, wi_string_t *field_value) {664 static void _wi_p7_message_set_xml_field(wi_p7_message_t *p7_message, wi_string_t *field_name, wi_string_t *field_value, wi_p7_spec_type_t *type) { 655 665 xmlNodePtr node; 656 666 … … 660 670 node = xmlNewNode(p7_message->xml_ns, (xmlChar *) "field"); 661 671 xmlSetProp(node, (xmlChar *) "name", (xmlChar *) wi_string_cstring(field_name)); 662 xmlSetProp(node, (xmlChar *) "type", (xmlChar *) wi_string_cstring(wi_p7_spec_type_name( p7_message->spec, type_id)));672 xmlSetProp(node, (xmlChar *) "type", (xmlChar *) wi_string_cstring(wi_p7_spec_type_name(type))); 663 673 xmlAddChild(p7_message->xml_root_node, node); 664 674 } … … 713 723 714 724 715 static wi_p7_ type_t_wi_p7_message_xml_type_for_name(wi_p7_message_t *p7_message, wi_string_t *field_name) {716 xmlNodePtr node;717 xml Char *prop;718 wi_p7_type_t type = WI_P7_SPEC_TYPE_ID_NULL;725 static wi_p7_spec_type_t * _wi_p7_message_xml_type_for_name(wi_p7_message_t *p7_message, wi_string_t *field_name) { 726 wi_p7_spec_type_t *type; 727 xmlNodePtr node; 728 xmlChar *prop; 719 729 720 730 node = _wi_p7_message_xml_node_for_name(p7_message, wi_string_cstring(field_name)); 721 731 722 732 if(!node) 723 return WI_P7_SPEC_TYPE_ID_NULL;733 return NULL; 724 734 725 735 prop = xmlGetProp(node, (xmlChar *) "type"); 726 736 727 737 if(prop) { 728 type = wi_p7_spec_type_ id(p7_message->spec, wi_string_with_cstring_no_copy((char *) prop, false));738 type = wi_p7_spec_type_with_name(p7_message->spec, wi_string_with_cstring_no_copy((char *) prop, false)); 729 739 730 740 xmlFree(prop); … … 733 743 } 734 744 735 return WI_P7_SPEC_TYPE_ID_NULL;745 return NULL; 736 746 } 737 747 … … 742 752 void wi_p7_message_serialize(wi_p7_message_t *p7_message, wi_p7_serialization_t serialization) { 743 753 xmlNodePtr listnode, itemnode; 754 wi_p7_spec_field_t *field; 755 wi_p7_spec_type_t *type, *listtype; 744 756 wi_runtime_instance_t *instance; 745 757 wi_string_t *field_name, *field_value; … … 757 769 wi_data_t *data; 758 770 wi_array_t *list; 759 wi_p7_type_t type_id, listtype_id;760 771 wi_uinteger_t i, count; 761 772 uint32_t message_size, field_id, field_size; … … 785 796 786 797 while((uint32_t) (buffer - start) < message_size) { 787 field_id = wi_read_swap_big_to_host_int32(buffer, 0);788 buffer += sizeof(field_id);789 790 field_size = wi_p7_spec_field_size(p7_message->spec, field_id);798 field_id = wi_read_swap_big_to_host_int32(buffer, 0); 799 buffer += sizeof(field_id); 800 field = wi_p7_spec_field_with_id(p7_message->spec, field_id); 801 field_size = wi_p7_spec_field_size(field); 791 802 792 803 if(field_size == 0) { … … 796 807 } 797 808 798 field_name = wi_p7_spec_field_name(p7_message->spec, field_id); 799 type_id = wi_p7_spec_field_type(p7_message->spec, field_id); 809 field_name = wi_p7_spec_field_name(field); 800 810 field_value = NULL; 801 802 switch(type_id) { 811 type = wi_p7_spec_field_type(field); 812 813 switch(wi_p7_spec_type_id(type)) { 803 814 case WI_P7_BOOL: 804 815 if(wi_p7_message_get_bool_for_name(p7_message, &p7_bool, field_name)) … … 878 889 879 890 if(!listnode) { 880 listtype _id = wi_p7_spec_field_listtype(p7_message->spec, wi_p7_spec_field_id(p7_message->spec, field_name));891 listtype = wi_p7_spec_field_listtype(field); 881 892 listnode = xmlNewNode(p7_message->xml_ns, (xmlChar *) "field"); 882 893 xmlSetProp(listnode, (xmlChar *) "name", (xmlChar *) wi_string_cstring(field_name)); 883 xmlSetProp(listnode, (xmlChar *) "type", (xmlChar *) wi_string_cstring(wi_p7_spec_type_name( p7_message->spec, type_id)));884 xmlSetProp(listnode, (xmlChar *) "listtype", (xmlChar *) wi_string_cstring(wi_p7_spec_type_name( p7_message->spec, listtype_id)));894 xmlSetProp(listnode, (xmlChar *) "type", (xmlChar *) wi_string_cstring(wi_p7_spec_type_name(type))); 895 xmlSetProp(listnode, (xmlChar *) "listtype", (xmlChar *) wi_string_cstring(wi_p7_spec_type_name(listtype))); 885 896 xmlAddChild(p7_message->xml_root_node, listnode); 886 897 } … … 902 913 903 914 if(field_value) 904 _wi_p7_message_set_xml_field(p7_message, type_id, field_name, field_value);915 _wi_p7_message_set_xml_field(p7_message, field_name, field_value, type); 905 916 906 917 buffer += field_size; … … 917 928 918 929 void wi_p7_message_deserialize(wi_p7_message_t *p7_message) { 930 wi_p7_spec_message_t *message; 931 919 932 if(p7_message->serialization == WI_P7_BINARY) { 920 933 p7_message->binary_id = wi_read_swap_big_to_host_int32(p7_message->binary_buffer, 0); 921 p7_message->name = wi_retain(wi_p7_spec_message_name(p7_message->spec, p7_message->binary_id)); 934 935 message = wi_p7_spec_message_with_id(p7_message->spec, p7_message->binary_id); 936 937 if(message) 938 p7_message->name = wi_retain(wi_p7_spec_message_name(message)); 922 939 } else { 923 940 p7_message->xml_doc = xmlParseDoc((xmlChar *) wi_string_cstring(p7_message->xml_string)); … … 937 954 938 955 wi_boolean_t wi_p7_message_set_name(wi_p7_message_t *p7_message, wi_string_t *name) { 956 wi_p7_spec_message_t *message; 957 939 958 if(p7_message->serialization == WI_P7_BINARY) { 940 p7_message->binary_id = wi_p7_spec_message_id(p7_message->spec, name);941 942 if( p7_message->binary_id == WI_P7_SPEC_MESSAGE_ID_NULL) {959 message = wi_p7_spec_message_with_name(p7_message->spec, name); 960 961 if(!message) { 943 962 wi_error_set_libwired_p7_error(WI_ERROR_P7_UNKNOWNMESSAGE, 944 963 WI_STR("No id found for message \"%@\""), name); … … 950 969 } 951 970 971 p7_message->binary_id = wi_p7_spec_message_id(message); 972 952 973 wi_write_swap_host_to_big_int32(p7_message->binary_buffer, 0, p7_message->binary_id); 953 974 } … … 978 999 979 1000 wi_hash_t * wi_p7_message_fields(wi_p7_message_t *p7_message) { 980 wi_ hash_t *fields;981 wi_ string_t *field_name, *type_name, *field_value;982 xmlNodePtr node;983 unsigned char *buffer, *start;984 wi_p7_type_t type_id;985 uint32_t message_size, field_id, field_size;1001 wi_p7_spec_field_t *field; 1002 wi_hash_t *fields; 1003 wi_string_t *field_name, *field_value; 1004 xmlNodePtr node; 1005 unsigned char *buffer, *start; 1006 uint32_t message_size, field_id, field_size; 986 1007 987 1008 fields = wi_hash_init(wi_hash_alloc()); … … 992 1013 993 1014 while((uint32_t) (buffer - start) < message_size) { 994 field_id = wi_read_swap_big_to_host_int32(buffer, 0);995 buffer += sizeof(field_id);996 997 field_size = wi_p7_spec_field_size(p7_message->spec, field_id);1015 field_id = wi_read_swap_big_to_host_int32(buffer, 0); 1016 buffer += sizeof(field_id); 1017 field = wi_p7_spec_field_with_id(p7_message->spec, field_id); 1018 field_size = wi_p7_spec_field_size(field); 998 1019 999 1020 if(field_size == 0) { … … 1003 1024 } 1004 1025 1005 field_name = wi_p7_spec_field_name(p7_message->spec, field_id); 1006 type_id = wi_p7_spec_field_type(p7_message->spec, field_id); 1007 field_value = _wi_p7_message_field_string_value(p7_message, field_name, type_id); 1026 field_name = wi_p7_spec_field_name(field); 1027 field_value = _wi_p7_message_field_string_value(p7_message, field); 1008 1028 1009 1029 wi_hash_set_data_for_key(fields, field_value, field_name); … … 1016 1036 if(node->type == XML_ELEMENT_NODE) { 1017 1037 field_name = wi_autorelease(wi_p7_xml_copy_string_for_attribute(node, WI_STR("name"))); 1018 type_name = wi_autorelease(wi_p7_xml_copy_string_for_attribute(node, WI_STR("type"))); 1019 type_id = wi_p7_spec_type_id(p7_message->spec, type_name); 1020 field_value = _wi_p7_message_field_string_value(p7_message, field_name, type_id); 1038 field = wi_p7_spec_field_with_name(p7_message->spec, field_name); 1039 field_value = _wi_p7_message_field_string_value(p7_message, field); 1021 1040 1022 1041 wi_hash_set_data_for_key(fields, field_value, field_name); … … 1473 1492 1474 1493 wi_number_t * wi_p7_message_number_for_name(wi_p7_message_t *p7_message, wi_string_t *field_name) { 1494 wi_p7_spec_field_t *field; 1495 wi_p7_spec_type_t *type; 1475 1496 wi_p7_boolean_t p7_bool; 1476 1497 wi_p7_int32_t p7_int32; … … 1479 1500 wi_p7_uint64_t p7_uint64; 1480 1501 wi_p7_double_t p7_double; 1481 wi_p7_type_t type_id;1482 uint32_t field_id;1483 1502 1484 1503 if(p7_message->serialization == WI_P7_BINARY) { 1485 field _id = wi_p7_spec_field_id(p7_message->spec, field_name);1486 1487 if( field_id == WI_P7_SPEC_FIELD_ID_NULL)1504 field = wi_p7_spec_field_with_name(p7_message->spec, field_name); 1505 1506 if(!field) 1488 1507 return NULL; 1489 1508 1490 type_id = wi_p7_spec_field_type(p7_message->spec, field_id); 1491 } else { 1492 type_id = _wi_p7_message_xml_type_for_name(p7_message, field_name); 1493 } 1494 1495 switch(type_id) { 1509 type = wi_p7_spec_field_type(field); 1510 } else { 1511 type = _wi_p7_message_xml_type_for_name(p7_message, field_name); 1512 } 1513 1514 if(!type) 1515 return NULL; 1516 1517 switch(wi_p7_spec_type_id(type)) { 1496 1518 case WI_P7_BOOL: 1497 1519 if(wi_p7_message_get_bool_for_name(p7_message, &p7_bool, field_name)) … … 1534 1556 1535 1557 wi_boolean_t wi_p7_message_set_enum_name_for_name(wi_p7_message_t *p7_message, wi_string_t *enum_name, wi_string_t *field_name) { 1558 wi_p7_spec_field_t *field; 1559 wi_hash_t *enums; 1536 1560 wi_p7_enum_t enum_value; 1537 1561 1538 enum_value = wi_p7_spec_enum_value(p7_message->spec, wi_p7_spec_field_id(p7_message->spec, field_name), enum_name); 1562 field = wi_p7_spec_field_with_name(p7_message->spec, field_name); 1563 1564 if(!field) { 1565 wi_error_set_libwired_p7_error(WI_ERROR_P7_UNKNOWNFIELD, 1566 WI_STR("No id found for field \"%@\""), field_name); 1567 1568 if(wi_p7_message_debug) 1569 wi_log_debug(WI_STR("wi_p7_message_set_enum_name_for_name: %m")); 1570 1571 return false; 1572 } 1573 1574 enums = wi_p7_spec_field_enums_by_name(field); 1575 1576 if(!wi_hash_contains_key(enums, enum_name)) { 1577 wi_error_set_libwired_p7_error(WI_ERROR_P7_UNKNOWNFIELD, 1578 WI_STR("No value found for enum \"%@\""), enum_name); 1579 1580 if(wi_p7_message_debug) 1581 wi_log_debug(WI_STR("wi_p7_message_set_enum_name_for_name: %m")); 1582 1583 return false; 1584 } 1585 1586 enum_value = (wi_p7_enum_t) wi_hash_data_for_key(enums, enum_name); 1539 1587 1540 1588 return wi_p7_message_set_enum_for_name(p7_message, enum_value, field_name); … … 1544 1592 1545 1593 wi_string_t * wi_p7_message_enum_name_for_name(wi_p7_message_t *p7_message, wi_string_t *field_name) { 1594 wi_p7_spec_field_t *field; 1595 wi_hash_t *enums; 1546 1596 wi_p7_enum_t enum_value; 1547 1597 … … 1549 1599 return NULL; 1550 1600 1551 return wi_p7_spec_enum_name(p7_message->spec, wi_p7_spec_field_id(p7_message->spec, field_name), enum_value); 1601 field = wi_p7_spec_field_with_name(p7_message->spec, field_name); 1602 enums = wi_p7_spec_field_enums_by_value(field); 1603 1604 if(!wi_hash_contains_key(enums, (void *) enum_value)) { 1605 wi_error_set_libwired_p7_error(WI_ERROR_P7_UNKNOWNFIELD, 1606 WI_STR("No name found for enum \"%u\""), enum_value); 1607 1608 if(wi_p7_message_debug) 1609 wi_log_debug(WI_STR("wi_p7_message_enum_name_for_name: %m")); 1610 1611 return false; 1612 } 1613 1614 return wi_hash_data_for_key(enums, (void *) enum_value); 1552 1615 } 1553 1616 … … 1703 1766 xmlNodePtr listnode, itemnode; 1704 1767 xmlChar *content; 1768 wi_p7_spec_field_t *field; 1769 wi_p7_spec_type_t *listtype; 1705 1770 wi_array_t *list; 1706 1771 wi_runtime_instance_t *instance; 1707 1772 unsigned char *binary; 1708 wi_p7_type_t listtype ;1773 wi_p7_type_t listtype_id; 1709 1774 uint32_t field_size, list_size, string_size; 1710 1775 1711 listtype = wi_p7_spec_field_listtype(p7_message->spec, wi_p7_spec_field_id(p7_message->spec, field_name));1712 1713 if( listtype != WI_P7_STRING) {1776 field = wi_p7_spec_field_with_name(p7_message->spec, field_name); 1777 1778 if(!field) { 1714 1779 wi_error_set_libwired_p7_error(WI_ERROR_P7_UNKNOWNFIELD, 1715 WI_STR("Unhandled type %@ in list"), wi_p7_spec_type_name(p7_message->spec, listtype)); 1780 WI_STR("No id found for field \"%@\""), field_name); 1781 1782 if(wi_p7_message_debug) 1783 wi_log_debug(WI_STR("wi_p7_message_list_for_name: %m")); 1784 1785 return NULL; 1786 } 1787 1788 listtype = wi_p7_spec_field_listtype(field); 1789 listtype_id = wi_p7_spec_type_id(listtype); 1790 1791 if(listtype_id != WI_P7_STRING) { 1792 wi_error_set_libwired_p7_error(WI_ERROR_P7_UNKNOWNFIELD, 1793 WI_STR("Unhandled type %@ in list"), wi_p7_spec_type_name(listtype)); 1716 1794 1717 1795 if(wi_p7_message_debug) … … 1730 1808 1731 1809 while(list_size < field_size) { 1732 if(listtype == WI_P7_STRING) {1810 if(listtype_id == WI_P7_STRING) { 1733 1811 string_size = wi_read_swap_big_to_host_int32(binary, list_size); 1734 1812 … … 1752 1830 continue; 1753 1831 1754 if(listtype == WI_P7_STRING)1832 if(listtype_id == WI_P7_STRING) 1755 1833 instance = wi_string_with_cstring_no_copy((char *) content, true); 1756 1834 … … 1768 1846 1769 1847 wi_boolean_t wi_p7_message_write_binary(wi_p7_message_t *p7_message, const void *buffer, uint32_t field_size, wi_uinteger_t field_id) { 1770 unsigned char *binary; 1848 wi_p7_spec_field_t *field; 1849 unsigned char *binary; 1771 1850 1772 1851 if(p7_message->serialization != WI_P7_BINARY) … … 1777 1856 1778 1857 wi_write_swap_host_to_big_int32(binary, 0, field_id); 1779 1780 if(wi_p7_spec_field_size(p7_message->spec, field_id) > 0) { 1858 1859 field = wi_p7_spec_field_with_id(p7_message->spec, field_id); 1860 1861 if(wi_p7_spec_field_size(field) > 0) { 1781 1862 memcpy(binary + 4, buffer, field_size); 1782 1863 } else { libwired/trunk/libwired/p7/wi-p7-socket.c
r5535 r5538 166 166 wi_uinteger_t oobdata_read_buffer_length; 167 167 168 wi_p7_socket_message_callback_func_t *read_message_callback; 169 void *read_message_context; 170 171 wi_p7_socket_message_callback_func_t *wrote_message_callback; 172 void *wrote_message_context; 173 168 174 uint64_t read_raw_bytes, read_processed_bytes; 169 175 uint64_t sent_raw_bytes, sent_processed_bytes; … … 342 348 343 349 350 void wi_p7_socket_set_read_message_callback(wi_p7_socket_t *p7_socket, wi_p7_socket_message_callback_func_t *callback, void *context) { 351 p7_socket->read_message_callback = callback; 352 p7_socket->read_message_context = context; 353 } 354 355 356 357 void wi_p7_socket_set_wrote_message_callback(wi_p7_socket_t *p7_socket, wi_p7_socket_message_callback_func_t *callback, void *context) { 358 p7_socket->wrote_message_callback = callback; 359 p7_socket->wrote_message_context = context; 360 } 361 362 363 344 364 #pragma mark - 345 365 … … 1549 1569 ((double) p7_socket->sent_processed_bytes / (double) p7_socket->sent_raw_bytes) * 100.0); 1550 1570 } 1571 1572 if(p7_socket->wrote_message_callback) 1573 (*p7_socket->wrote_message_callback)(p7_socket, p7_message, p7_socket->wrote_message_context); 1551 1574 1552 1575 return true; … … 1610 1633 } 1611 1634 1635 if(p7_socket->read_message_callback) 1636 (*p7_socket->read_message_callback)(p7_socket, p7_message, p7_socket->read_message_context); 1637 1612 1638 return p7_message; 1613 1639 } libwired/trunk/libwired/p7/wi-p7-socket.h
r5535 r5538 73 73 typedef enum _wi_p7_options wi_p7_options_t; 74 74 75 typedef void wi_p7_socket_message_callback_func_t(wi_p7_socket_t *, wi_p7_message_t *, void *); 76 75 77 76 78 typedef wi_string_t * wi_p7_socket_password_provider_func_t(wi_string_t *); … … 88 90 WI_EXPORT void wi_p7_socket_set_tls(wi_p7_socket_t *, wi_socket_tls_t *); 89 91 WI_EXPORT wi_socket_tls_t * wi_p7_socket_tls(wi_p7_socket_t *); 92 WI_EXPORT void wi_p7_socket_set_read_message_callback(wi_p7_socket_t *, wi_p7_socket_message_callback_func_t *, void *); 93 WI_EXPORT void wi_p7_socket_set_wrote_message_callback(wi_p7_socket_t *, wi_p7_socket_message_callback_func_t *, void *); 90 94 91 95 WI_EXPORT wi_socket_t * wi_p7_socket_socket(wi_p7_socket_t *); libwired/trunk/libwired/p7/wi-p7-spec.c
r5532 r5538 52 52 #include <wired/wi-string.h> 53 53 54 typedef struct _wi_p7_spec_type _wi_p7_spec_type_t;55 typedef struct _wi_p7_spec_field _wi_p7_spec_field_t;56 54 typedef struct _wi_p7_spec_collection _wi_p7_spec_collection_t; 57 typedef struct _wi_p7_spec_message _wi_p7_spec_message_t;58 typedef struct _wi_p7_spec_parameter _wi_p7_spec_parameter_t;59 55 typedef struct _wi_p7_spec_transaction _wi_p7_spec_transaction_t; 60 56 typedef struct _wi_p7_spec_broadcast _wi_p7_spec_broadcast_t; … … 71 67 }; 72 68 73 static _wi_p7_spec_type_t * _wi_p7_spec_type_with_node(wi_p7_spec_t *, xmlNodePtr);69 static wi_p7_spec_type_t * _wi_p7_spec_type_with_node(wi_p7_spec_t *, xmlNodePtr); 74 70 static void _wi_p7_spec_type_dealloc(wi_runtime_instance_t *); 75 71 static wi_string_t * _wi_p7_spec_type_description(wi_runtime_instance_t *); … … 77 73 static wi_runtime_id_t _wi_p7_spec_type_runtime_id = WI_RUNTIME_ID_NULL; 78 74 static wi_runtime_class_t _wi_p7_spec_type_runtime_class = { 79 " _wi_p7_spec_type_t",75 "wi_p7_spec_type_t", 80 76 _wi_p7_spec_type_dealloc, 81 77 NULL, … … 92 88 wi_string_t *name; 93 89 wi_uinteger_t id; 94 _wi_p7_spec_type_t *type;95 _wi_p7_spec_type_t *listtype;90 wi_p7_spec_type_t *type; 91 wi_p7_spec_type_t *listtype; 96 92 wi_hash_t *enums_name; 97 wi_hash_t *enums_ id;93 wi_hash_t *enums_value; 98 94 }; 99 95 100 static _wi_p7_spec_field_t *_wi_p7_spec_field_with_node(wi_p7_spec_t *, xmlNodePtr);96 static wi_p7_spec_field_t * _wi_p7_spec_field_with_node(wi_p7_spec_t *, xmlNodePtr); 101 97 static void _wi_p7_spec_field_dealloc(wi_runtime_instance_t *); 102 98 static wi_string_t * _wi_p7_spec_field_description(wi_runtime_instance_t *); … … 104 100 static wi_runtime_id_t _wi_p7_spec_field_runtime_id = WI_RUNTIME_ID_NULL; 105 101 static wi_runtime_class_t _wi_p7_spec_field_runtime_class = { 106 " _wi_p7_spec_field_t",102 "wi_p7_spec_field_t", 107 103 _wi_p7_spec_field_dealloc, 108 104 NULL, … … 148 144 }; 149 145 150 static _wi_p7_spec_message_t * _wi_p7_spec_message_with_node(wi_p7_spec_t *, xmlNodePtr);146 static wi_p7_spec_message_t * _wi_p7_spec_message_with_node(wi_p7_spec_t *, xmlNodePtr); 151 147 static void _wi_p7_spec_message_dealloc(wi_runtime_instance_t *); 152 148 static wi_string_t * _wi_p7_spec_message_description(wi_runtime_instance_t *); … … 154 150 static wi_runtime_id_t _wi_p7_spec_message_runtime_id = WI_RUNTIME_ID_NULL; 155 151 static wi_runtime_class_t _wi_p7_spec_message_runtime_class = { 156 " _wi_p7_spec_message_t",152 "wi_p7_spec_message_t", 157 153 _wi_p7_spec_message_dealloc, 158 154 NULL, … … 167 163 wi_runtime_base_t base; 168 164 169 _wi_p7_spec_field_t *field;165 wi_p7_spec_field_t *field; 170 166 wi_boolean_t required; 171 167 }; 172 168 173 static _wi_p7_spec_parameter_t * _wi_p7_spec_parameter_with_node(wi_p7_spec_t *, xmlNodePtr, _wi_p7_spec_message_t *);174 static _wi_p7_spec_parameter_t * &n
