Changeset 3311

Show
Ignore:
Timestamp:
05/04/08 01:24:22 (5 months ago)
Author:
dgollub
Message:

Implemented Ressource subcomponennt of OSyncPluginConfig.
See wiki:PluginConfigXsd

XML Schema changed slightly. <Ressources> is represented in API as
OSyncList of OSyncPluginRessource.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/misc/schemas/plugin_config.xsd

    r3246 r3311  
    88        <xsd:element maxOccurs="1" minOccurs="0" name="Connection" type="Connection"/> 
    99        <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"/
    1111<!--    <xsd:element maxOccurs="1" minOccurs="0" name="AdvancedOptions" type="AdvancedOptions"/> --> 
    1212      </xsd:sequence> 
     
    3737  </xsd:complexType> 
    3838 
    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 
    4049  <xsd:complexType name="Ressources"> 
    4150    <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" /> 
    4752    </xsd:sequence> 
    4853  </xsd:complexType> 
    49   --> 
    5054 
    5155  <xsd:complexType name="ConnectionBluetooth"> 
  • trunk/opensync/CMakeLists.txt

    r3248 r3311  
    5454   plugin/opensync_plugin_info.c 
    5555   plugin/opensync_plugin_localization.c 
     56   plugin/opensync_plugin_ressource.c 
    5657   plugin/opensync_sink.c 
    5758   version/opensync_version.c 
  • trunk/opensync/opensync.h

    r3230 r3311  
    151151typedef struct OSyncPluginConnection OSyncPluginConnection; 
    152152typedef struct OSyncPluginLocalization OSyncPluginLocalization; 
     153typedef struct OSyncPluginRessource OSyncPluginRessource; 
    153154 
    154155/* Engine component */ 
  • trunk/opensync/plugin/opensync_plugin_config.c

    r3244 r3311  
    331331} 
    332332 
     333 
     334static 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 
     369error: 
     370        osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); 
     371        return NULL; 
     372} 
     373 
    333374static osync_bool _osync_plugin_config_parse_ressources(OSyncPluginConfig *config, xmlNode *cur, OSyncError **error) 
    334375{ 
     
    336377        osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, config, cur, error); 
    337378 
    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 
     400error: 
    357401        osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); 
    358402        return FALSE; 
     
    625669} 
    626670 
     671static 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; 
     700error: 
     701        osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); 
     702        return FALSE; 
     703} 
     704 
     705static 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; 
     724error: 
     725        osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); 
     726        return FALSE; 
     727} 
     728 
     729 
    627730OSyncPluginConfig *osync_plugin_config_new(OSyncError **error) 
    628731{ 
     
    679782        OSyncPluginAuthentication *auth; 
    680783        OSyncPluginLocalization *local; 
     784        OSyncList *ressources; 
    681785         
    682786        doc = xmlNewDoc((xmlChar*)"1.0"); 
     
    713817 
    714818        /* 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)) 
    718821                        goto error_and_free; 
    719         */ 
    720822 
    721823        xmlSaveFormatFile(path, doc, 1); 
     
    765867 
    766868/* 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 */ 
     869OSyncList *osync_plugin_config_get_ressources(OSyncPluginConfig *config) 
     870
     871        osync_assert(config); 
     872        return config->ressources; 
     873 
     874
     875 
     876void 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
    780892 
    781893OSyncPluginConnection *osync_plugin_config_get_connection(OSyncPluginConfig *config) 
  • trunk/opensync/plugin/opensync_plugin_config.h

    r3235 r3311  
    3838 
    3939/* 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 */ 
     40OSYNC_EXPORT OSyncList *osync_plugin_config_get_ressources(OSyncPluginConfig *plugin); 
     41OSYNC_EXPORT void osync_plugin_config_set_ressources(OSyncPluginConfig *plugin, OSyncList *ressources); 
    4442 
    4543/* Connection */ 
  • trunk/opensync/plugin/opensync_plugin_config_internals.h

    r3242 r3311  
    3535        /** Localization configuration */ 
    3636        OSyncPluginLocalization *localization; 
     37        /** List of ressource configurations */ 
     38        OSyncList *ressources; 
    3739 
    3840        /** Object reference counting */ 
  • trunk/tests/plugin-tests/check_plugin_config.c

    r3245 r3311  
    147147        osync_error_unref(&error); 
    148148 
     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 
    149155        osync_plugin_config_unref(config); 
    150156 
     
    369375END_TEST 
    370376 
     377START_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} 
     451END_TEST 
    371452 
    372453START_TEST (plugin_config_save_and_load) 
     
    402483        osync_plugin_authentication_set_password(auth, "bar"); 
    403484        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); 
    404515 
    405516        /* Set subcomponents */ 
     
    408519        osync_plugin_config_set_localization(config, local); 
    409520        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); 
    410524 
    411525        char *config_file = g_strdup_printf("%s/dummy_config.xml", testbed); 
     
    418532        OSyncPluginLocalization *reloaded_local = osync_plugin_config_get_localization(reloaded_config); 
    419533        OSyncPluginAuthentication *reloaded_auth = osync_plugin_config_get_authentication(reloaded_config); 
     534        OSyncList *reloaded_ressources = osync_plugin_config_get_ressources(reloaded_config); 
    420535 
    421536        fail_unless(reloaded_local != NULL, NULL); 
     537        fail_unless(reloaded_auth != NULL, NULL); 
     538        fail_unless(reloaded_ressources != NULL, NULL); 
    422539 
    423540        fail_unless(!strcmp(osync_plugin_localization_get_language(reloaded_local), "de_DE"), NULL); 
     
    429546        fail_unless(!strcmp(osync_plugin_authentication_get_reference(reloaded_auth), "ref"), NULL); 
    430547 
     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        } 
    431559 
    432560        osync_plugin_config_unref(config); 
     
    689817        create_case(s, "plugin_config_connection", plugin_config_connection); 
    690818        create_case(s, "plugin_config_localization", plugin_config_localization); 
     819        create_case(s, "plugin_config_ressources", plugin_config_ressources); 
    691820        create_case(s, "plugin_config_save_and_load", plugin_config_save_and_load); 
    692821        create_case(s, "plugin_config_save_and_load_connection_bluetooth", plugin_config_save_and_load_connection_bluetooth);