OSyncList* osync_list_insert (OSyncList *list, void * data, int position) { OSyncList *new_list; OSyncList *tmp_list; if (position < 0) return osync_list_append (list, data); else if (position == 0) return osync_list_prepend (list, data); tmp_list = osync_list_nth (list, position); if (!tmp_list) return osync_list_append (list, data); new_list = _osync_list_alloc (); new_list->data = data; new_list->prev = tmp_list->prev; if (tmp_list->prev) tmp_list->prev->next = new_list; new_list->next = tmp_list; tmp_list->prev = new_list; if (tmp_list == list) return new_list; else return list; }
void osync_capabilities_add_objtype(OSyncCapabilities *capabilities, OSyncCapabilitiesObjType *capabilitiesobjtype) { osync_assert(capabilities); osync_assert(capabilitiesobjtype); capabilities->objtypes = osync_list_append(capabilities->objtypes, capabilitiesobjtype); osync_capabilities_objtype_ref(capabilitiesobjtype); }
OSyncList *osync_format_env_find_converters(OSyncFormatEnv *env, OSyncObjFormat *sourceformat, OSyncObjFormat *targetformat) { OSyncList *r = NULL; GList *c = NULL; osync_assert(env); osync_assert(sourceformat); osync_assert(targetformat); for (c = env->converters; c; c = c->next) { OSyncFormatConverter *converter = c->data; if (!osync_objformat_is_equal(sourceformat, osync_converter_get_sourceformat(converter))) continue; if (!osync_objformat_is_equal(targetformat, osync_converter_get_targetformat(converter))) continue; r = osync_list_append(r, converter); } return r; }
void osync_capabilities_objtype_add_capability(OSyncCapabilitiesObjType *capsobjtype, OSyncCapability *capability) { osync_assert(capsobjtype); capsobjtype->capabilities = osync_list_append(capsobjtype->capabilities, capability); osync_capability_ref(capability); }
static void *initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) { /* * get the config */ OSyncPluginConfig *config = osync_plugin_info_get_config(info); if (!config) { osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get config."); goto error; } /* * You need to specify the <some name>_environment somewhere with * all the members you need */ plugin_environment *env = osync_try_malloc0(sizeof(plugin_environment), error); if (!env) goto error; env->sink_envs = NULL; osync_trace(TRACE_INTERNAL, "The config: %s", osync_plugin_info_get_config(info)); /* * Process the config here and set the options on your environment */ /* * Process plugin specific advanced options */ OSyncList *optslist = osync_plugin_config_get_advancedoptions(config); for (; optslist; optslist = optslist->next) { OSyncPluginAdvancedOption *option = optslist->data; const char *val = osync_plugin_advancedoption_get_value(option); const char *name = osync_plugin_advancedoption_get_name(option); if (!strcmp(name,"<your-option>")) { if (!strcmp(val, "<your-value>")) { /* * set a varaible to a specific value */; } } } /* * Process Ressource options */ int i, numobjs = osync_plugin_info_num_objtypes(info); for (i = 0; i < numobjs; i++) { sink_environment *sinkenv = osync_try_malloc0(sizeof(sink_environment), error); if (!sinkenv) goto error_free_env; sinkenv->sink = osync_plugin_info_nth_objtype(info, i); osync_assert(sinkenv->sink); const char *objtype = osync_objtype_sink_get_name(sinkenv->sink); OSyncPluginResource *res = osync_plugin_config_find_active_resource(config, objtype); /* get objformat sinks */ OSyncList *s = osync_plugin_resource_get_objformat_sinks(res); for (; s; s = s->next) { OSyncObjFormatSink *fsink = s->data; // there could be only one sink const char *objformat = osync_objformat_sink_get_objformat(fsink); osync_assert(objformat); osync_trace(TRACE_INTERNAL, "objtype %s has objformat %s", objtype, objformat); } /* Every sink can have different functions ... */ OSyncObjTypeSinkFunctions functions; memset(&functions, 0, sizeof(functions)); functions.connect = connect; functions.disconnect = disconnect; functions.get_changes = get_changes; functions.commit = commit_change; functions.sync_done = sync_done; /* We pass the OSyncFileDir object to the sink, so we dont have to look it up * again once the functions are called */ osync_objtype_sink_set_functions(sinkenv->sink, functions, sinkenv); osync_trace(TRACE_INTERNAL, "The configdir: %s", osync_plugin_info_get_configdir(info)); char *tablepath = osync_strdup_printf("%s/hashtable.db", osync_plugin_info_get_configdir(info)); sinkenv->hashtable = osync_hashtable_new(tablepath, objtype, error); osync_free(tablepath); env->sink_envs = osync_list_append(env->sink_envs, sinkenv); } //Now your return your struct. return (void *) env; error_free_env: free_env(env); error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return NULL; }
OSyncList *osync_version_load_from_descriptions(OSyncError **error, const char *descriptiondir, const char *schemadir) { GDir *dir = NULL; GError *gerror = NULL; const char *descpath = descriptiondir ? descriptiondir : OPENSYNC_DESCRIPTIONSDIR; const char *schemapath = schemadir ? schemadir : OPENSYNC_SCHEMASDIR; char *filename = NULL; const gchar *de = NULL; OSyncList *versions = NULL; OSyncVersion *version = NULL; xmlDocPtr doc; xmlNodePtr root; xmlNodePtr cur; xmlNodePtr child; osync_trace(TRACE_ENTRY, "%s(%p)", __func__, error); dir = g_dir_open(descpath, 0, &gerror); if (!dir) { /* If description directory doesn't exist (e.g. unittests), just ignore this. */ osync_trace(TRACE_EXIT, "Unable to open directory %s: %s", descpath, gerror->message); g_error_free(gerror); return NULL; } while ((de = g_dir_read_name(dir))) { char *schemafilepath = NULL; osync_bool res; filename = osync_strdup_printf ("%s%c%s", descpath, G_DIR_SEPARATOR, de); if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR) || !g_pattern_match_simple("*.xml", filename)) { osync_free(filename); continue; } doc = xmlReadFile(filename, NULL, XML_PARSE_NOBLANKS); if(!doc) { osync_free(filename); continue; } osync_free(filename); root = xmlDocGetRootElement(doc); if(!root || !xmlStrEqual(root->name, BAD_CAST "versions")) { osync_xml_free_doc(doc); continue; } schemafilepath = osync_strdup_printf("%s%c%s", schemapath, G_DIR_SEPARATOR, "descriptions.xsd"); res = osync_xml_validate_document(doc, schemafilepath); osync_free(schemafilepath); if(res == FALSE) { osync_xml_free_doc(doc); continue; } cur = root->children; for(; cur != NULL; cur = cur->next) { version = osync_version_new(error); if(!version) { OSyncList *cur = NULL; osync_xml_free_doc(doc); cur = osync_list_first(versions); while(cur) { osync_version_unref(cur->data); cur = cur->next; } goto error; } child = cur->children; osync_version_set_plugin(version, (const char *)osync_xml_node_get_content(child)); child = child->next; osync_version_set_priority(version, (const char *)osync_xml_node_get_content(child)); child = child->next; osync_version_set_vendor(version, (const char *)osync_xml_node_get_content(child)); child = child->next; osync_version_set_modelversion(version, (const char *)osync_xml_node_get_content(child)); child = child->next; osync_version_set_firmwareversion(version, (const char *)osync_xml_node_get_content(child)); child = child->next; osync_version_set_softwareversion(version, (const char *)osync_xml_node_get_content(child)); child = child->next; osync_version_set_hardwareversion(version, (const char *)osync_xml_node_get_content(child)); child = child->next; osync_version_set_identifier(version, (const char *)osync_xml_node_get_content(child)); versions = osync_list_append(versions, version); } osync_xml_free_doc(doc); } g_dir_close(dir); osync_trace(TRACE_EXIT, "%s: %p", __func__, versions); return versions; error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return NULL; }
void osync_plugin_info_add_objtype(OSyncPluginInfo *info, OSyncObjTypeSink *sink) { osync_assert(info); info->objtype_sinks = osync_list_append(info->objtype_sinks, sink); osync_objtype_sink_ref(sink); }