Changeset 3311
- Timestamp:
- 05/04/08 01:24:22 (5 months ago)
- Files:
-
- trunk/misc/schemas/plugin_config.xsd (modified) (2 diffs)
- trunk/opensync/CMakeLists.txt (modified) (1 diff)
- trunk/opensync/opensync.h (modified) (1 diff)
- trunk/opensync/plugin/opensync_plugin_config.c (modified) (6 diffs)
- trunk/opensync/plugin/opensync_plugin_config.h (modified) (1 diff)
- trunk/opensync/plugin/opensync_plugin_config_internals.h (modified) (1 diff)
- trunk/opensync/plugin/opensync_plugin_ressource.c (added)
- trunk/opensync/plugin/opensync_plugin_ressource.h (added)
- trunk/opensync/plugin/opensync_plugin_ressource_internals.h (added)
- trunk/tests/plugin-tests/check_plugin_config.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/misc/schemas/plugin_config.xsd
r3246 r3311 8 8 <xsd:element maxOccurs="1" minOccurs="0" name="Connection" type="Connection"/> 9 9 <xsd:element maxOccurs="1" minOccurs="0" name="Localization" type="Localization"/> 10 <!-- <xsd:element maxOccurs="1" minOccurs="0" name="Ressources" type="Ressources"/> -->10 <xsd:element maxOccurs="1" minOccurs="0" name="Ressources" type="Ressources"/> 11 11 <!-- <xsd:element maxOccurs="1" minOccurs="0" name="AdvancedOptions" type="AdvancedOptions"/> --> 12 12 </xsd:sequence> … … 37 37 </xsd:complexType> 38 38 39 <!-- 39 <xsd:complexType name="Ressource"> 40 <xsd:sequence> 41 <xsd:element maxOccurs="1" minOccurs="0" name="Name" type="xsd:string" /> 42 <xsd:element maxOccurs="1" minOccurs="0" name="MIME" type="xsd:string" /> 43 <xsd:element maxOccurs="1" minOccurs="0" name="ObjFormat" type="xsd:string" /> 44 <xsd:element maxOccurs="1" minOccurs="0" name="Path" type="xsd:string" /> 45 <xsd:element maxOccurs="1" minOccurs="0" name="Url" type="xsd:string" /> 46 </xsd:sequence> 47 </xsd:complexType> 48 40 49 <xsd:complexType name="Ressources"> 41 50 <xsd:sequence> 42 <xsd:element name="Name" type="xsd:string" /> 43 <xsd:element name="MIME" type="xsd:string" /> 44 <xsd:element name="ObjFormat" type="xsd:string" /> 45 <xsd:element name="Path" type="xsd:string" /> 46 <xsd:element name="Url" type="xsd:string" /> 51 <xsd:element maxOccurs="unbounded" minOccurs="1" name="Ressource" type="Ressource" /> 47 52 </xsd:sequence> 48 53 </xsd:complexType> 49 -->50 54 51 55 <xsd:complexType name="ConnectionBluetooth"> trunk/opensync/CMakeLists.txt
r3248 r3311 54 54 plugin/opensync_plugin_info.c 55 55 plugin/opensync_plugin_localization.c 56 plugin/opensync_plugin_ressource.c 56 57 plugin/opensync_sink.c 57 58 version/opensync_version.c trunk/opensync/opensync.h
r3230 r3311 151 151 typedef struct OSyncPluginConnection OSyncPluginConnection; 152 152 typedef struct OSyncPluginLocalization OSyncPluginLocalization; 153 typedef struct OSyncPluginRessource OSyncPluginRessource; 153 154 154 155 /* Engine component */ trunk/opensync/plugin/opensync_plugin_config.c
r3244 r3311 331 331 } 332 332 333 334 static OSyncPluginRessource *_osync_plugin_config_parse_ressource(OSyncPluginConfig *config, xmlNode *cur, OSyncError **error) 335 { 336 337 osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, config, cur, error); 338 339 OSyncPluginRessource *res = osync_plugin_ressource_new(error); 340 if (!res) 341 goto error; 342 343 for (; cur != NULL; cur = cur->next) { 344 345 if (cur->type != XML_ELEMENT_NODE) 346 continue; 347 348 char *str = (char*)xmlNodeGetContent(cur); 349 if (!str) 350 continue; 351 352 if (!xmlStrcmp(cur->name, (const xmlChar *)"Name")) 353 osync_plugin_ressource_set_name(res, str); 354 else if (!xmlStrcmp(cur->name, (const xmlChar *)"MIME")) 355 osync_plugin_ressource_set_mime(res, str); 356 else if (!xmlStrcmp(cur->name, (const xmlChar *)"ObjFormat")) 357 osync_plugin_ressource_set_objformat(res, str); 358 else if (!xmlStrcmp(cur->name, (const xmlChar *)"Path")) 359 osync_plugin_ressource_set_path(res, str); 360 else if (!xmlStrcmp(cur->name, (const xmlChar *)"Url")) 361 osync_plugin_ressource_set_url(res, str); 362 363 xmlFree(str); 364 } 365 366 osync_trace(TRACE_EXIT, "%s", __func__); 367 return res; 368 369 error: 370 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); 371 return NULL; 372 } 373 333 374 static osync_bool _osync_plugin_config_parse_ressources(OSyncPluginConfig *config, xmlNode *cur, OSyncError **error) 334 375 { … … 336 377 osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, config, cur, error); 337 378 338 339 /* TODO: Implementaion of OSyncRessource(s) 340 OSyncRessource *ressource = osync_ressource_new(&error); 341 if (!ressource) 342 goto error; 343 344 for (; cur != NULL; cur = cur->next) { 345 346 if (cur->type != XML_ELEMENT_NODE) 347 continue; 348 349 } 350 351 osync_trace(TRACE_EXIT, "%s", __func__); 352 return TRUE; 353 354 error: 355 356 */ 379 OSyncPluginRessource *res; 380 OSyncList *ressources = osync_plugin_config_get_ressources(config); 381 382 for (; cur != NULL; cur = cur->next) { 383 384 if (cur->type != XML_ELEMENT_NODE) 385 continue; 386 387 if (!xmlStrcmp(cur->name, (const xmlChar *)"Ressource")) { 388 if (!(res = _osync_plugin_config_parse_ressource(config, cur->xmlChildrenNode, error))) 389 goto error; 390 391 ressources = osync_list_prepend(ressources, res); 392 } 393 } 394 395 osync_plugin_config_set_ressources(config, ressources); 396 397 osync_trace(TRACE_EXIT, "%s", __func__); 398 return TRUE; 399 400 error: 357 401 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); 358 402 return FALSE; … … 625 669 } 626 670 671 static osync_bool _osync_plugin_config_assemble_ressource(xmlNode *cur, OSyncPluginRessource *res, OSyncError **error) 672 { 673 osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, cur, res, error); 674 675 const char *name, *mime, *objformat, *path, *url; 676 677 xmlNode *node = xmlNewChild(cur, NULL, (xmlChar*)"Ressource", NULL); 678 if (!node) { 679 osync_error_set(error, OSYNC_ERROR_GENERIC, "No memory left to assemble configuration."); 680 goto error; 681 } 682 683 if ((name = osync_plugin_ressource_get_name(res))) 684 xmlNewChild(node, NULL, (xmlChar*)"Name", (xmlChar*)name); 685 686 if ((mime = osync_plugin_ressource_get_mime(res))) 687 xmlNewChild(node, NULL, (xmlChar*)"MIME", (xmlChar*)mime); 688 689 if ((objformat = osync_plugin_ressource_get_objformat(res))) 690 xmlNewChild(node, NULL, (xmlChar*)"ObjFormat", (xmlChar*)objformat); 691 692 if ((path = osync_plugin_ressource_get_path(res))) 693 xmlNewChild(node, NULL, (xmlChar*)"Path", (xmlChar*)path); 694 695 if ((url = osync_plugin_ressource_get_url(res))) 696 xmlNewChild(node, NULL, (xmlChar*)"Url", (xmlChar*)url); 697 698 osync_trace(TRACE_EXIT, "%s", __func__); 699 return TRUE; 700 error: 701 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); 702 return FALSE; 703 } 704 705 static osync_bool _osync_plugin_config_assemble_ressources(xmlNode *cur, OSyncList *ressources, OSyncError **error) 706 { 707 osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, cur, ressources, error); 708 709 OSyncList *res; 710 711 xmlNode *node = xmlNewChild(cur, NULL, (xmlChar*)"Ressources", NULL); 712 if (!node) { 713 osync_error_set(error, OSYNC_ERROR_GENERIC, "No memory left to assemble configuration."); 714 goto error; 715 } 716 717 for (res = ressources; res; res = res->next) 718 if (!_osync_plugin_config_assemble_ressource(node, res->data, error)) 719 goto error; 720 721 722 osync_trace(TRACE_EXIT, "%s", __func__); 723 return TRUE; 724 error: 725 osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); 726 return FALSE; 727 } 728 729 627 730 OSyncPluginConfig *osync_plugin_config_new(OSyncError **error) 628 731 { … … 679 782 OSyncPluginAuthentication *auth; 680 783 OSyncPluginLocalization *local; 784 OSyncList *ressources; 681 785 682 786 doc = xmlNewDoc((xmlChar*)"1.0"); … … 713 817 714 818 /* Ressources */ 715 /* TODO: impelement OSyncRessources 716 if ((ressources = osync_plugin_config_get_resssoures(config))) 717 if (_osync_plugin_config_assemble_ressources(doc->children, ressources, error)) 819 if ((ressources = osync_plugin_config_get_ressources(config))) 820 if (!_osync_plugin_config_assemble_ressources(doc->children, ressources, error)) 718 821 goto error_and_free; 719 */720 822 721 823 xmlSaveFormatFile(path, doc, 1); … … 765 867 766 868 /* Ressources */ 767 /* TODO: Implement OSyncRessource 768 OSyncRessource *osync_plugin_config_get_ressource(OSyncPluginConfig *plugin) 769 { 770 osync_assert(config); 771 772 } 773 774 void osync_plugin_config_set_ressource(OSyncPluginConfig *plugin, OSyncRessource *ressource) 775 { 776 osync_assert(config); 777 778 } 779 */ 869 OSyncList *osync_plugin_config_get_ressources(OSyncPluginConfig *config) 870 { 871 osync_assert(config); 872 return config->ressources; 873 874 } 875 876 void osync_plugin_config_set_ressources(OSyncPluginConfig *config, OSyncList *ressources) 877 { 878 osync_assert(config); 879 OSyncList *r; 880 881 /* First increase refcount - in case one ressource ise used in different 882 ressource lists. */ 883 for (r = ressources; r; r = r->next) 884 osync_plugin_ressource_ref(r->data); 885 886 if (config->ressources) 887 for (r = config->ressources; r; r = r->next) 888 osync_plugin_ressource_unref(r->data); 889 890 config->ressources = ressources; 891 } 780 892 781 893 OSyncPluginConnection *osync_plugin_config_get_connection(OSyncPluginConfig *config) trunk/opensync/plugin/opensync_plugin_config.h
r3235 r3311 38 38 39 39 /* Ressources */ 40 /* TODO: Implement OSyncRessource 41 OSYNC_EXPORT OSyncRessource *osync_plugin_config_get_ressource(OSyncPluginConfig *plugin); 42 OSYNC_EXPORT void osync_plugin_config_set_ressource(OSyncPluginConfig *plugin, OSyncRessource *ressource); 43 */ 40 OSYNC_EXPORT OSyncList *osync_plugin_config_get_ressources(OSyncPluginConfig *plugin); 41 OSYNC_EXPORT void osync_plugin_config_set_ressources(OSyncPluginConfig *plugin, OSyncList *ressources); 44 42 45 43 /* Connection */ trunk/opensync/plugin/opensync_plugin_config_internals.h
r3242 r3311 35 35 /** Localization configuration */ 36 36 OSyncPluginLocalization *localization; 37 /** List of ressource configurations */ 38 OSyncList *ressources; 37 39 38 40 /** Object reference counting */ trunk/tests/plugin-tests/check_plugin_config.c
r3245 r3311 147 147 osync_error_unref(&error); 148 148 149 /* Ressource(s) */ 150 OSyncPluginRessource *res = osync_plugin_ressource_new(&error); 151 fail_unless(error != NULL, NULL); 152 fail_unless(res == NULL, NULL); 153 osync_error_unref(&error); 154 149 155 osync_plugin_config_unref(config); 150 156 … … 369 375 END_TEST 370 376 377 START_TEST (plugin_config_ressources) 378 { 379 char *testbed = setup_testbed(NULL); 380 381 OSyncError *error = NULL; 382 OSyncPluginConfig *config = osync_plugin_config_new(&error); 383 fail_unless(error == NULL, NULL); 384 fail_unless(config != NULL, NULL); 385 386 /* Ressources */ 387 OSyncList *ressources = NULL; 388 389 /* Ressource */ 390 OSyncPluginRessource *ressource = osync_plugin_ressource_new(&error); 391 fail_unless(error == NULL, NULL); 392 fail_unless(ressource != NULL, NULL); 393 394 /* Name */ 395 osync_plugin_ressource_set_name(ressource, "foobar"); 396 fail_unless(!strcmp(osync_plugin_ressource_get_name(ressource), "foobar"), NULL); 397 398 /* Overwrite (leak check) */ 399 osync_plugin_ressource_set_name(ressource, "barfoo"); 400 fail_unless(!strcmp(osync_plugin_ressource_get_name(ressource), "barfoo"), NULL); 401 402 /* MIME */ 403 osync_plugin_ressource_set_mime(ressource, "foobar"); 404 fail_unless(!strcmp(osync_plugin_ressource_get_mime(ressource), "foobar"), NULL); 405 406 /* Overwrite (leak check) */ 407 osync_plugin_ressource_set_mime(ressource, "barfoo"); 408 fail_unless(!strcmp(osync_plugin_ressource_get_mime(ressource), "barfoo"), NULL); 409 410 /* ObjFormat */ 411 osync_plugin_ressource_set_objformat(ressource, "foobar"); 412 fail_unless(!strcmp(osync_plugin_ressource_get_objformat(ressource), "foobar"), NULL); 413 414 /* Overwrite (leak check) */ 415 osync_plugin_ressource_set_objformat(ressource, "barfoo"); 416 fail_unless(!strcmp(osync_plugin_ressource_get_objformat(ressource), "barfoo"), NULL); 417 418 /* Path */ 419 osync_plugin_ressource_set_path(ressource, "foobar"); 420 fail_unless(!strcmp(osync_plugin_ressource_get_path(ressource), "foobar"), NULL); 421 422 /* Overwrite (leak check) */ 423 osync_plugin_ressource_set_path(ressource, "barfoo"); 424 fail_unless(!strcmp(osync_plugin_ressource_get_path(ressource), "barfoo"), NULL); 425 426 /* URL */ 427 osync_plugin_ressource_set_url(ressource, "foobar"); 428 fail_unless(!strcmp(osync_plugin_ressource_get_url(ressource), "foobar"), NULL); 429 430 /* Overwrite (leak check) */ 431 osync_plugin_ressource_set_url(ressource, "barfoo"); 432 fail_unless(!strcmp(osync_plugin_ressource_get_url(ressource), "barfoo"), NULL); 433 434 /* Invoke OSyncPluginConfig */ 435 ressources = osync_list_prepend(ressources, ressource); 436 osync_plugin_config_set_ressources(config, ressources); 437 /* Twice to check for correct order of ref/unref calls in set_ressources() */ 438 osync_plugin_config_set_ressources(config, ressources); 439 ressources = osync_plugin_config_get_ressources(config); 440 fail_unless(!strcmp(osync_plugin_ressource_get_url(ressources->data), "barfoo"), NULL); 441 osync_plugin_ressource_unref(ressources->data); 442 443 fail_unless(osync_plugin_ressource_ref(ressource) != NULL, NULL); 444 osync_plugin_ressource_unref(ressource); 445 osync_plugin_ressource_unref(ressource); 446 447 osync_plugin_config_unref(config); 448 449 destroy_testbed(testbed); 450 } 451 END_TEST 371 452 372 453 START_TEST (plugin_config_save_and_load) … … 402 483 osync_plugin_authentication_set_password(auth, "bar"); 403 484 osync_plugin_authentication_set_reference(auth, "ref"); 485 486 /* Ressources */ 487 OSyncList *ressources = NULL; 488 489 /* Ressource #1 */ 490 OSyncPluginRessource *ressource1 = osync_plugin_ressource_new(&error); 491 fail_unless(error == NULL, NULL); 492 fail_unless(ressource1 != NULL, NULL); 493 494 /* Name */ 495 osync_plugin_ressource_set_name(ressource1, "foobar1"); 496 osync_plugin_ressource_set_mime(ressource1, "foobar1"); 497 osync_plugin_ressource_set_objformat(ressource1, "foobar1"); 498 osync_plugin_ressource_set_path(ressource1, "foobar1"); 499 osync_plugin_ressource_set_url(ressource1, "foobar1"); 500 501 ressources = osync_list_prepend(ressources, ressource1); 502 503 /* Ressource #2 */ 504 OSyncPluginRessource *ressource2 = osync_plugin_ressource_new(&error); 505 fail_unless(error == NULL, NULL); 506 fail_unless(ressource2 != NULL, NULL); 507 508 osync_plugin_ressource_set_name(ressource2, "foobar2"); 509 osync_plugin_ressource_set_mime(ressource2, "foobar2"); 510 osync_plugin_ressource_set_objformat(ressource2, "foobar2"); 511 osync_plugin_ressource_set_path(ressource2, "foobar2"); 512 osync_plugin_ressource_set_url(ressource2, "foobar2"); 513 514 ressources = osync_list_prepend(ressources, ressource2); 404 515 405 516 /* Set subcomponents */ … … 408 519 osync_plugin_config_set_localization(config, local); 409 520 osync_plugin_localization_unref(local); 521 osync_plugin_config_set_ressources(config, ressources); 522 osync_plugin_ressource_unref(ressource1); 523 osync_plugin_ressource_unref(ressource2); 410 524 411 525 char *config_file = g_strdup_printf("%s/dummy_config.xml", testbed); … … 418 532 OSyncPluginLocalization *reloaded_local = osync_plugin_config_get_localization(reloaded_config); 419 533 OSyncPluginAuthentication *reloaded_auth = osync_plugin_config_get_authentication(reloaded_config); 534 OSyncList *reloaded_ressources = osync_plugin_config_get_ressources(reloaded_config); 420 535 421 536 fail_unless(reloaded_local != NULL, NULL); 537 fail_unless(reloaded_auth != NULL, NULL); 538 fail_unless(reloaded_ressources != NULL, NULL); 422 539 423 540 fail_unless(!strcmp(osync_plugin_localization_get_language(reloaded_local), "de_DE"), NULL); … … 429 546 fail_unless(!strcmp(osync_plugin_authentication_get_reference(reloaded_auth), "ref"), NULL); 430 547 548 OSyncList *r; 549 int i; 550 for (i = 1, r = reloaded_ressources; r; r = r->next, i++) { 551 char *value = g_strdup_printf("foobar%i", i); 552 fail_unless(!strcmp(osync_plugin_ressource_get_name(r->data), value), NULL); 553 fail_unless(!strcmp(osync_plugin_ressource_get_mime(r->data), value), NULL); 554 fail_unless(!strcmp(osync_plugin_ressource_get_objformat(r->data), value), NULL); 555 fail_unless(!strcmp(osync_plugin_ressource_get_path(r->data), value), NULL); 556 fail_unless(!strcmp(osync_plugin_ressource_get_url(r->data), value), NULL); 557 g_free(value); 558 } 431 559 432 560 osync_plugin_config_unref(config); … … 689 817 create_case(s, "plugin_config_connection", plugin_config_connection); 690 818 create_case(s, "plugin_config_localization", plugin_config_localization); 819 create_case(s, "plugin_config_ressources", plugin_config_ressources); 691 820 create_case(s, "plugin_config_save_and_load", plugin_config_save_and_load); 692 821 create_case(s, "plugin_config_save_and_load_connection_bluetooth", plugin_config_save_and_load_connection_bluetooth);
