Changeset 4696
- Timestamp:
- 02/23/07 17:10:29 (2 years ago)
- Files:
-
- libwired/trunk/Makefile.in (modified) (1 diff)
- libwired/trunk/libwired/p7/wi-p7-message.c (modified) (5 diffs)
- libwired/trunk/libwired/p7/wi-p7-private.h (modified) (1 diff)
- libwired/trunk/libwired/p7/wi-p7-socket.c (modified) (8 diffs)
- libwired/trunk/libwired/p7/wi-p7-socket.h (modified) (1 diff)
- libwired/trunk/libwired/p7/wi-p7-spec.c (modified) (12 diffs)
- libwired/trunk/libwired/p7/wi-p7-spec.h (modified) (1 diff)
- libwired/trunk/test/tests/wi-p7-spec-tests.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libwired/trunk/Makefile.in
r4661 r4696 107 107 clean: 108 108 rm -f $(objdir)/libwired/*.o 109 rm -f $(objdir)/libwired/*.d 109 110 rm -f $(headerdir)/*.h 110 111 rm -f $(rundir)/lib/libwired.a libwired/trunk/libwired/p7/wi-p7-message.c
r4687 r4696 1108 1108 uint32_t field_size, field_id; 1109 1109 1110 if(!string) 1111 string = WI_STR(""); 1112 1110 1113 if(p7_message->serialization == WI_P7_BINARY) { 1111 1114 field_size = wi_string_length(string) + 1; … … 1153 1156 uint32_t field_size, field_id; 1154 1157 1158 if(!data) 1159 data = wi_data(); 1160 1155 1161 if(p7_message->serialization == WI_P7_BINARY) { 1156 1162 field_size = wi_data_length(data); … … 1195 1201 1196 1202 wi_boolean_t wi_p7_message_set_number_for_name(wi_p7_message_t *p7_message, wi_number_t *number, wi_string_t *field_name) { 1203 if(!number) 1204 number = wi_number_with_int32(0); 1205 1197 1206 if(wi_number_type(number) == WI_NUMBER_BOOL) { 1198 1207 return wi_p7_message_set_bool_for_name(p7_message, wi_number_bool(number), field_name); … … 1270 1279 uint32_t field_id; 1271 1280 1281 if(!uuid) 1282 return false; 1283 1272 1284 if(p7_message->serialization == WI_P7_BINARY) { 1273 1285 if(!_wi_p7_message_get_binary_buffer_for_writing_for_name(p7_message, field_name, 0, &binary, &field_id)) … … 1316 1328 uint32_t field_id, field_size; 1317 1329 1330 if(!date) 1331 date = wi_date(); 1332 1318 1333 string = wi_date_iso8601_string(date); 1319 1334 libwired/trunk/libwired/p7/wi-p7-private.h
r4687 r4696 61 61 WI_EXPORT void wi_p7_message_deserialize(wi_p7_message_t *); 62 62 63 WI_EXPORT wi_boolean_t wi_p7_spec_is_compatible_with_protocol(wi_p7_spec_t *, wi_string_t *, double); 64 63 65 WI_EXPORT wi_string_t * wi_p7_xml_string_for_attribute(xmlNodePtr, wi_string_t *); 64 66 WI_EXPORT wi_integer_t wi_p7_xml_integer_for_attribute(xmlNodePtr, wi_string_t *); libwired/trunk/libwired/p7/wi-p7-socket.c
r4691 r4696 51 51 52 52 #define _WI_P7_SOCKET_XML_MAGIC 0x3C3F786D 53 #define _WI_P7_SOCKET_BINARY_MAGIC_SIZE 5 253 #define _WI_P7_SOCKET_BINARY_MAGIC_SIZE 58 54 54 55 55 #define _WI_P7_SOCKET_OPTIONS_ENCRYPTION_ENABLED(options) \ … … 242 242 243 243 static wi_boolean_t _wi_p7_socket_connect_handshake(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_p7_options_t options) { 244 wi_ uuid_t *protocol;244 wi_string_t *protocol_name; 245 245 wi_p7_message_t *p7_message; 246 wi_p7_ uint32_tversion;246 wi_p7_double_t version, protocol_version; 247 247 wi_p7_uint32_t compression, encryption; 248 248 … … 255 255 } 256 256 257 wi_p7_message_set_uint32_for_name(p7_message, WI_P7_VERSION, WI_STR("p7.handshake.version")); 258 wi_p7_message_set_uuid_for_name(p7_message, wi_p7_spec_id(p7_socket->spec), WI_STR("p7.handshake.protocol")); 257 wi_p7_message_set_double_for_name(p7_message, wi_p7_spec_version(wi_p7_spec_builtin_spec()), WI_STR("p7.handshake.version")); 258 wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_name(p7_socket->spec), WI_STR("p7.handshake.protocol_name")); 259 wi_p7_message_set_double_for_name(p7_message, wi_p7_spec_version(p7_socket->spec), WI_STR("p7.handshake.protocol_version")); 259 260 260 261 if(p7_socket->serialization == WI_P7_BINARY) { … … 290 291 } 291 292 292 if(!wi_p7_message_get_uint32_for_name(p7_message, &version, WI_STR("p7.handshake.version")) || 293 !(protocol = wi_p7_message_uuid_for_name(p7_message, WI_STR("p7.handshake.protocol")))) { 294 wi_log_warn(WI_STR("missing keys: version/protocol")); 295 296 return false; 297 } 298 299 if(version != WI_P7_VERSION) { 300 wi_log_warn(WI_STR("version mismatch (%u != %u)"), version, WI_P7_VERSION); 301 302 return false; 303 } 304 305 p7_socket->local_compatibility_check = !wi_p7_spec_is_compatible_with_id(p7_socket->spec, protocol); 293 if(!wi_p7_message_get_double_for_name(p7_message, &version, WI_STR("p7.handshake.version"))) { 294 wi_log_warn(WI_STR("missing keys: version")); 295 296 return false; 297 } 298 299 if(version != wi_p7_spec_version(wi_p7_spec_builtin_spec())) { 300 wi_log_warn(WI_STR("version mismatch (%.1f != %.1f)"), version, wi_p7_spec_version(wi_p7_spec_builtin_spec())); 301 302 return false; 303 } 304 305 protocol_name = wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol_name")); 306 307 if(!protocol_name) { 308 wi_log_warn(WI_STR("missing keys: protocol_name")); 309 310 return false; 311 } 312 313 if(!wi_p7_message_get_double_for_name(p7_message, &protocol_version, WI_STR("p7.handshake.protocol_version"))) { 314 wi_log_warn(WI_STR("missing keys: protocol_version")); 315 316 return false; 317 } 318 319 p7_socket->local_compatibility_check = !wi_p7_spec_is_compatible_with_protocol(p7_socket->spec, protocol_name, protocol_version); 306 320 307 321 if(wi_p7_message_get_uint32_for_name(p7_message, &compression, WI_STR("p7.handshake.compression"))) { … … 345 359 346 360 static wi_boolean_t _wi_p7_socket_accept_handshake(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout, wi_p7_options_t options) { 347 wi_ uuid_t *protocol;361 wi_string_t *protocol_name; 348 362 wi_p7_message_t *p7_message; 349 wi_p7_ uint32_tversion;363 wi_p7_double_t version, protocol_version; 350 364 wi_p7_enum_t compression, encryption; 351 365 … … 364 378 } 365 379 366 protocol = wi_p7_message_uuid_for_name(p7_message, WI_STR("p7.handshake.protocol")); 367 368 if(!wi_p7_message_get_uint32_for_name(p7_message, &version, WI_STR("p7.handshake.version")) || 369 !protocol) { 370 wi_log_warn(WI_STR("missing keys: version/protocol")); 371 372 return false; 373 } 374 375 if(version != WI_P7_VERSION) { 376 wi_log_warn(WI_STR("version mismatch (%u != %u)"), version, WI_P7_VERSION); 377 378 return false; 379 } 380 381 p7_socket->local_compatibility_check = !wi_p7_spec_is_compatible_with_id(p7_socket->spec, protocol); 380 if(!wi_p7_message_get_double_for_name(p7_message, &version, WI_STR("p7.handshake.version"))) { 381 wi_log_warn(WI_STR("missing keys: version")); 382 383 return false; 384 } 385 386 if(version != wi_p7_spec_version(wi_p7_spec_builtin_spec())) { 387 wi_log_warn(WI_STR("version mismatch (%u != %u)"), version, wi_p7_spec_version(wi_p7_spec_builtin_spec())); 388 389 return false; 390 } 391 392 protocol_name = wi_p7_message_string_for_name(p7_message, WI_STR("p7.handshake.protocol_name")); 393 394 if(!protocol_name) { 395 wi_log_warn(WI_STR("missing keys: protocol_name")); 396 397 return false; 398 } 399 400 if(!wi_p7_message_get_double_for_name(p7_message, &protocol_version, WI_STR("p7.handshake.protocol_version"))) { 401 wi_log_warn(WI_STR("missing keys: protocol_version")); 402 403 return false; 404 } 405 406 p7_socket->local_compatibility_check = !wi_p7_spec_is_compatible_with_protocol(p7_socket->spec, protocol_name, protocol_version); 382 407 383 408 if(p7_socket->serialization == WI_P7_BINARY) { … … 405 430 } 406 431 407 wi_p7_message_set_uint32_for_name(p7_message, WI_P7_VERSION, WI_STR("p7.handshake.version")); 408 wi_p7_message_set_uuid_for_name(p7_message, wi_p7_spec_id(p7_socket->spec), WI_STR("p7.handshake.protocol")); 432 wi_p7_message_set_double_for_name(p7_message, wi_p7_spec_version(wi_p7_spec_builtin_spec()), WI_STR("p7.handshake.version")); 433 wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_name(p7_socket->spec), WI_STR("p7.handshake.protocol_name")); 434 wi_p7_message_set_double_for_name(p7_message, wi_p7_spec_version(p7_socket->spec), WI_STR("p7.handshake.protocol_version")); 409 435 410 436 if(p7_socket->options & WI_P7_COMPRESSION_DEFLATE) … … 1245 1271 wi_p7_message_deserialize(p7_message); 1246 1272 1247 wi_log_info(WI_STR("data = %@"), wi_data_with_bytes(p7_message->binary_buffer, p7_message->binary_size));1248 1249 1273 wi_log_info(WI_STR("Received %@"), p7_message); 1250 1274 libwired/trunk/libwired/p7/wi-p7-socket.h
r4680 r4696 34 34 #include <wired/wi-runtime.h> 35 35 #include <wired/wi-socket.h> 36 37 #define WI_P7_VERSION 138 36 39 37 enum _wi_p7_options { libwired/trunk/libwired/p7/wi-p7-spec.c
r4680 r4696 252 252 253 253 wi_string_t *filename; 254 wi_uuid_t *id; 255 wi_set_t *compatible_ids; 254 wi_string_t *name; 255 double version; 256 257 wi_set_t *compatible_protocols; 256 258 257 259 wi_hash_t *messages_name, *messages_id; … … 290 292 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" 291 293 " xsi:schemaLocation=\"http://www.zankasoftware.com/P7/Specification p7-specification.xsd\"" 292 " id=\"FC154842-628F-4CA1-854B-32A652C92882\">"294 " name=\"P7\" version=\"1.0\">" 293 295 " <p7:types>" 294 296 " <p7:type name=\"bool\" id=\"1\" size=\"1\" />" … … 307 309 "" 308 310 " <p7:fields>" 309 " <p7:field name=\"p7.handshake.version\" type=\"uint32\" id=\"1\" />" 310 " <p7:field name=\"p7.handshake.protocol\" type=\"uuid\" id=\"2\" />" 311 " <p7:field name=\"p7.handshake.compression\" type=\"enum\" id=\"3\">" 311 " <p7:field name=\"p7.handshake.version\" type=\"double\" id=\"1\" />" 312 " <p7:field name=\"p7.handshake.protocol_name\" type=\"string\" id=\"2\" />" 313 " <p7:field name=\"p7.handshake.protocol_version\" type=\"double\" id=\"3\" />" 314 " <p7:field name=\"p7.handshake.compression\" type=\"enum\" id=\"4\">" 312 315 " <p7:enum name=\"p7.handshake.compression.deflate\" value=\"0\" />" 313 316 " </p7:field>" 314 " <p7:field name=\"p7.handshake.encryption\" type=\"enum\" id=\" 4\">"317 " <p7:field name=\"p7.handshake.encryption\" type=\"enum\" id=\"5\">" 315 318 " <p7:enum name=\"p7.handshake.encryption.rsa_aes256_sha1\" value=\"0\" />" 316 319 " <p7:enum name=\"p7.handshake.encryption.rsa_bf128_sha1\" value=\"1\" />" 317 320 " <p7:enum name=\"p7.handshake.encryption.rsa_3des192_sha1\" value=\"2\" />" 318 321 " </p7:field>" 319 " <p7:field name=\"p7.handshake.compatibility_check\" type=\"bool\" id=\" 5\" />"322 " <p7:field name=\"p7.handshake.compatibility_check\" type=\"bool\" id=\"6\" />" 320 323 "" 321 " <p7:field name=\"p7.encryption.envelope_key\" id=\" 6\" type=\"data\" />"322 " <p7:field name=\"p7.encryption.cipher_key\" id=\" 7\" type=\"data\" />"323 " <p7:field name=\"p7.encryption.cipher_iv\" id=\" 8\" type=\"data\" />"324 " <p7:field name=\"p7.encryption.username\" id=\" 9\" type=\"data\" />"325 " <p7:field name=\"p7.encryption.client_password\" id=\"1 0\" type=\"data\" />"326 " <p7:field name=\"p7.encryption.server_password\" id=\"1 1\" type=\"data\" />"324 " <p7:field name=\"p7.encryption.envelope_key\" id=\"7\" type=\"data\" />" 325 " <p7:field name=\"p7.encryption.cipher_key\" id=\"8\" type=\"data\" />" 326 " <p7:field name=\"p7.encryption.cipher_iv\" id=\"9\" type=\"data\" />" 327 " <p7:field name=\"p7.encryption.username\" id=\"10\" type=\"data\" />" 328 " <p7:field name=\"p7.encryption.client_password\" id=\"11\" type=\"data\" />" 329 " <p7:field name=\"p7.encryption.server_password\" id=\"12\" type=\"data\" />" 327 330 "" 328 " <p7:field name=\"p7.compatibility_check.specification\" id=\"1 2\" type=\"string\" />"329 " <p7:field name=\"p7.compatibility_check.status\" id=\"1 3\" type=\"bool\" />"331 " <p7:field name=\"p7.compatibility_check.specification\" id=\"13\" type=\"string\" />" 332 " <p7:field name=\"p7.compatibility_check.status\" id=\"14\" type=\"bool\" />" 330 333 " </p7:fields>" 331 334 "" … … 333 336 " <p7:message name=\"p7.handshake\" id=\"1\">" 334 337 " <p7:parameter field=\"p7.handshake.version\" use=\"required\" />" 335 " <p7:parameter field=\"p7.handshake.protocol\" use=\"required\" />" 338 " <p7:parameter field=\"p7.handshake.protocol_name\" use=\"required\" />" 339 " <p7:parameter field=\"p7.handshake.protocol_version\" use=\"required\" />" 336 340 " <p7:parameter field=\"p7.handshake.encryption\" />" 337 341 " <p7:parameter field=\"p7.handshake.compression\" />" … … 340 344 " <p7:message name=\"p7.handshake.reply\" id=\"2\">" 341 345 " <p7:parameter field=\"p7.handshake.version\" use=\"required\" />" 342 " <p7:parameter field=\"p7.handshake.protocol\" use=\"required\" />" 346 " <p7:parameter field=\"p7.handshake.protocol_name\" use=\"required\" />" 347 " <p7:parameter field=\"p7.handshake.protocol_version\" use=\"required\" />" 343 348 " <p7:parameter field=\"p7.handshake.encryption\" />" 344 349 " <p7:parameter field=\"p7.handshake.compression\" />" … … 464 469 }; 465 470 466 p7_spec->compatible_ids = wi_set_init(wi_set_alloc()); 467 468 p7_spec->messages_name = wi_hash_init_with_capacity(wi_hash_alloc(), 500); 469 p7_spec->messages_id = wi_hash_init_with_capacity_and_callbacks(wi_hash_alloc(), 500, key_callbacks, wi_hash_default_value_callbacks); 470 471 p7_spec->fields_name = wi_hash_init_with_capacity(wi_hash_alloc(), 500); 472 p7_spec->fields_id = wi_hash_init_with_capacity_and_callbacks(wi_hash_alloc(), 500, key_callbacks, wi_hash_default_value_callbacks); 473 474 p7_spec->types_name = wi_hash_init_with_capacity(wi_hash_alloc(), 20); 475 p7_spec->types_id = wi_hash_init_with_capacity_and_callbacks(wi_hash_alloc(), 20, key_callbacks, wi_hash_default_value_callbacks); 476 477 p7_spec->transactions_name = wi_hash_init_with_capacity(wi_hash_alloc(), 20); 471 p7_spec->compatible_protocols = wi_set_init(wi_set_alloc()); 472 473 p7_spec->messages_name = wi_hash_init_with_capacity(wi_hash_alloc(), 500); 474 p7_spec->messages_id = wi_hash_init_with_capacity_and_callbacks(wi_hash_alloc(), 475 500, key_callbacks, wi_hash_default_value_callbacks); 476 477 p7_spec->fields_name = wi_hash_init_with_capacity(wi_hash_alloc(), 500); 478 p7_spec->fields_id = wi_hash_init_with_capacity_and_callbacks(wi_hash_alloc(), 479 500, key_callbacks, wi_hash_default_value_callbacks); 480 481 p7_spec->types_name = wi_hash_init_with_capacity(wi_hash_alloc(), 20); 482 p7_spec->types_id = wi_hash_init_with_capacity_and_callbacks(wi_hash_alloc(), 483 20, key_callbacks, wi_hash_default_value_callbacks); 484 485 p7_spec->transactions_name = wi_hash_init_with_capacity(wi_hash_alloc(), 20); 478 486 479 487 return p7_spec; … … 536 544 537 545 wi_release(p7_spec->filename); 538 wi_release(p7_spec-> id);539 wi_release(p7_spec->compatible_ ids);546 wi_release(p7_spec->name); 547 wi_release(p7_spec->compatible_protocols); 540 548 541 549 wi_release(p7_spec->messages_name); … … 556 564 wi_p7_spec_t *p7_spec = instance; 557 565 558 return wi_string_with_format(WI_STR("<%@ %p>{ types = %@, fields = %@, messages = %@}"),566 return wi_string_with_format(WI_STR("<%@ %p>{name = %@, version = %.1f, types = %@, fields = %@, messages = %@}"), 559 567 wi_runtime_class_name(p7_spec), 560 568 p7_spec, 569 p7_spec->name, 570 p7_spec->version, 561 571 p7_spec->types_name, 562 572 p7_spec->fields_name, … … 655 665 656 666 static wi_boolean_t _wi_p7_spec_load_spec(wi_p7_spec_t *p7_spec, xmlDocPtr doc) { 657 wi_string_t * string;667 wi_string_t *version; 658 668 xmlNodePtr root_node, node; 659 669 660 670 root_node = xmlDocGetRootElement(doc); 661 671 662 string = wi_p7_xml_string_for_attribute(root_node, WI_STR("id")); 663 664 if(string) 665 p7_spec->id = wi_uuid_init_with_string(wi_uuid_alloc(), string); 672 p7_spec->name = wi_retain(wi_p7_xml_string_for_attribute(root_node, WI_STR("name"))); 673 674 if(!p7_spec->name) { 675 wi_error_set_libwired_p7_error(WI_ERROR_P7_INVALIDSPEC, 676 WI_STR("Protocol has no \"name\"")); 677 678 return false; 679 } 680 681 version = wi_p7_xml_string_for_attribute(root_node, WI_STR("version")); 682 683 if(!version) { 684 wi_error_set_libwired_p7_error(WI_ERROR_P7_INVALIDSPEC, 685 WI_STR("Protocol has no \"version\"")); 686 687 return false; 688 } 689 690 p7_spec->version = wi_string_double(version); 666 691 667 692 for(node = root_node->children; node != NULL; node = node->next) { … … 840 865 #pragma mark - 841 866 842 wi_boolean_t wi_p7_spec_is_compatible_with_id(wi_p7_spec_t *p7_spec, wi_uuid_t *id) { 843 return (wi_is_equal(p7_spec->id, id) || wi_set_contains_data(p7_spec->compatible_ids, id)); 867 wi_boolean_t wi_p7_spec_is_compatible_with_protocol(wi_p7_spec_t *p7_spec, wi_string_t *name, double version) { 868 return ((wi_is_equal(p7_spec->name, name) && p7_spec->version == version) || 869 wi_set_contains_data(p7_spec->compatible_protocols, wi_string_with_format(WI_STR("%@ %.1f"), name, version))); 844 870 } 845 871 … … 851 877 compatible = _wi_p7_spec_is_compatible(p7_spec, other_p7_spec); 852 878 853 if(compatible) 854 wi_set_add_data(p7_spec->compatible_ids, other_p7_spec->id); 879 if(compatible) { 880 wi_set_add_data(p7_spec->compatible_protocols, wi_string_with_format(WI_STR("%@ %.1f"), 881 other_p7_spec->name, other_p7_spec->version)); 882 } 855 883 856 884 return compatible; … … 1132 1160 #pragma mark - 1133 1161 1134 wi_uuid_t * wi_p7_spec_id(wi_p7_spec_t *p7_spec) { 1135 return p7_spec->id; 1162 wi_string_t * wi_p7_spec_name(wi_p7_spec_t *p7_spec) { 1163 return p7_spec->name; 1164 } 1165 1166 1167 1168 double wi_p7_spec_version(wi_p7_spec_t *p7_spec) { 1169 return p7_spec->version; 1136 1170 } 1137 1171 libwired/trunk/libwired/p7/wi-p7-spec.h
r4679 r4696 47 47 WI_EXPORT wi_p7_spec_t * wi_p7_spec_init_with_string(wi_p7_spec_t *, wi_string_t *); 48 48 49 WI_EXPORT wi_boolean_t wi_p7_spec_is_compatible_with_id(wi_p7_spec_t *, wi_uuid_t *);50 49 WI_EXPORT wi_boolean_t wi_p7_spec_is_compatible_with_spec(wi_p7_spec_t *, wi_p7_spec_t *); 51 50 52 WI_EXPORT wi_uuid_t * wi_p7_spec_id(wi_p7_spec_t *); 51 WI_EXPORT wi_string_t * wi_p7_spec_name(wi_p7_spec_t *); 52 WI_EXPORT double wi_p7_spec_version(wi_p7_spec_t *); 53 53 WI_EXPORT wi_string_t * wi_p7_spec_xml(wi_p7_spec_t *); 54 54 WI_EXPORT wi_uinteger_t wi_p7_spec_message_id(wi_p7_spec_t *, wi_string_t *); libwired/trunk/test/tests/wi-p7-spec-tests.c
r4668 r4696 38 38 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" 39 39 " xsi:schemaLocation=\"http://www.zankasoftware.com/P7/Specification p7.xsd\"" 40 " id=\"097CDA0A-1DDF-43AA-BC4C-17C275FD14E8\">" 40 " name=\"test\"" 41 " version=\"1.0\">" 41 42 " <p7:fields>" 42 43 " <p7:field name=\"test.bool\" type=\"bool\" id=\"1000\" />" … … 124 125 WI_TEST_ASSERT_NOT_NULL(p7_spec, ""); 125 126 126 WI_TEST_ASSERT_EQUAL_INSTANCES(wi_p7_spec_id(p7_spec), wi_uuid_with_string(WI_STR("097CDA0A-1DDF-43AA-BC4C-17C275FD14E8")), ""); 127 WI_TEST_ASSERT_EQUAL_INSTANCES(wi_p7_spec_name(p7_spec), WI_STR("test"), ""); 128 WI_TEST_ASSERT_EQUALS_WITH_ACCURACY(wi_p7_spec_version(p7_spec), 1.0, 0.001, ""); 127 129 128 130 WI_TEST_ASSERT_EQUALS(wi_p7_spec_message_id(p7_spec, WI_STR("test")), 1000U, "");
