/*! @brief dlopen()s a format plugin * * The get_info() function on the format plugin gets called * * @param env The environment in which to open the plugin * @param path Where to find this plugin * @param error Pointer to a error struct * @return Pointer to the plugin on success, NULL otherwise * */ osync_bool osync_module_load(OSyncModule *module, const char *path, OSyncError **error) { osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, module, path, error); osync_assert(module); osync_assert(!module->module); if (!g_module_supported()) { osync_error_set(error, OSYNC_ERROR_GENERIC, "This platform does not support loading of modules"); goto error; } /* Try to open the module or fail if an error occurs */ module->module = g_module_open(path, 0); if (!module->module) { osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to open module %s: %s", path, g_module_error()); goto error; } module->path = g_strdup(path); osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return FALSE; }
osync_bool osync_xml_validate_document(xmlDocPtr doc, char *schemafilepath) { int rc = 0; xmlSchemaParserCtxtPtr xmlSchemaParserCtxt = NULL; xmlSchemaPtr xmlSchema = NULL; xmlSchemaValidCtxtPtr xmlSchemaValidCtxt = NULL; osync_assert(doc); osync_assert(schemafilepath); xmlSchemaParserCtxt = xmlSchemaNewParserCtxt(schemafilepath); xmlSchema = xmlSchemaParse(xmlSchemaParserCtxt); xmlSchemaFreeParserCtxt(xmlSchemaParserCtxt); xmlSchemaValidCtxt = xmlSchemaNewValidCtxt(xmlSchema); if (xmlSchemaValidCtxt == NULL) { xmlSchemaFree(xmlSchema); rc = 1; }else{ /* Validate the document */ rc = xmlSchemaValidateDoc(xmlSchemaValidCtxt, doc); xmlSchemaFree(xmlSchema); xmlSchemaFreeValidCtxt(xmlSchemaValidCtxt); } if(rc != 0) return FALSE; return TRUE; }
osync_bool osync_xmlfield_set_key_value(OSyncXMLField *xmlfield, const char *key, const char *value, OSyncError **error) { xmlNodePtr cur = NULL; osync_assert(xmlfield); osync_assert(key); // If value is null we don't add it to a xmlfield if (!value) return TRUE; cur = xmlfield->node->children; for(; cur != NULL; cur = cur->next) { if(!xmlStrcmp(cur->name, BAD_CAST key)) { xmlNodeSetContent(xmlfield->node, BAD_CAST value); break; } } /* TODO: error handling */ if(cur == NULL) cur = xmlNewTextChild(xmlfield->node, NULL, BAD_CAST key, BAD_CAST value); if (!osync_xmlfield_new_xmlfield(xmlfield, cur, error)) goto error; xmlfield->sorted = FALSE; return TRUE; error: return FALSE; }
void osync_plugin_info_set_main_sink(OSyncPluginInfo *info, OSyncObjTypeSink *sink) { osync_assert(info); osync_assert(sink); info->main_sink = sink; osync_objtype_sink_ref(sink); }
osync_bool get_conversion_info(OSyncFormatEnv *env, OSyncError **error) { OSyncFormatConverter *conv = NULL; /* mock converter */ OSyncObjFormat *mockformat1 = osync_format_env_find_objformat(env, "mockformat1"); osync_assert(mockformat1); OSyncObjFormat *mockformat2 = osync_format_env_find_objformat(env, "mockformat2"); osync_assert(mockformat2); conv = osync_converter_new(OSYNC_CONVERTER_DECAP, mockformat1, mockformat2, conv_file_to_plain, error); osync_assert(conv); osync_format_env_register_converter(env, conv); osync_converter_unref(conv); conv = osync_converter_new(OSYNC_CONVERTER_ENCAP, mockformat2, mockformat1, conv_plain_to_file, error); osync_assert(conv); osync_format_env_register_converter(env, conv); osync_converter_unref(conv); return TRUE; }
osync_bool get_format_info(OSyncFormatEnv *env, OSyncError **error) { OSyncObjFormat *format = NULL; /* mockformat1 */ format = osync_objformat_new("mockformat1", "mockobjtype1", error); osync_assert(format); _format_set_functions(format); osync_format_env_register_objformat(env, format); osync_objformat_unref(format); /* mockformat2 */ format = osync_objformat_new("mockformat2", "mockobjtype2", error); osync_assert(format); _format_set_functions(format); osync_format_env_register_objformat(env, format); osync_objformat_unref(format); /* mockformat3 */ format = osync_objformat_new("mockformat3", "mockobjtype3", error); osync_assert(format); _format_set_functions(format); osync_format_env_register_objformat(env, format); osync_objformat_unref(format); return TRUE; }
static void mock_mainsink_disconnect(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *data) { osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, sink, info, ctx, data); mock_env *env = data; osync_assert(data); GList *o = env->directories; for (; o; o = o->next) { MockDir *sink_dir = o->data; if (!g_getenv("NO_COMMITTED_ALL_CHECK")) osync_assert(sink_dir->committed_all == TRUE); sink_dir->committed_all = FALSE; } if (mock_get_error(info->memberid, "DISCONNECT_ERROR")) { osync_context_report_error(ctx, OSYNC_ERROR_EXPECTED, "Triggering DISCONNECT_ERROR error"); return; } if (mock_get_error(info->memberid, "DISCONNECT_TIMEOUT")) return; osync_context_report_success(ctx); osync_trace(TRACE_EXIT, "%s", __func__); }
OSyncConvCmpResult osync_data_compare(OSyncData *leftdata, OSyncData *rightdata) { OSyncConvCmpResult ret = 0; osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, leftdata, rightdata); osync_assert(leftdata); osync_assert(rightdata); if (leftdata == rightdata) { osync_trace(TRACE_EXIT, "%s: SAME: OK. data is the same", __func__); return OSYNC_CONV_DATA_SAME; } if (leftdata->data == rightdata->data && leftdata->size == rightdata->size) { osync_trace(TRACE_EXIT, "%s: SAME: OK. data point to same memory", __func__); return OSYNC_CONV_DATA_SAME; } if (!leftdata->objformat || !rightdata->objformat || strcmp(osync_objformat_get_name(leftdata->objformat), osync_objformat_get_name(rightdata->objformat))) { osync_trace(TRACE_EXIT, "%s: MISMATCH: Objformats do not match", __func__); return OSYNC_CONV_DATA_MISMATCH; } if (!rightdata->data || !leftdata->data) { osync_trace(TRACE_EXIT, "%s: MISMATCH: One change has no data", __func__); return OSYNC_CONV_DATA_MISMATCH; } ret = osync_objformat_compare(leftdata->objformat, leftdata->data, leftdata->size, rightdata->data, rightdata->size); osync_trace(TRACE_EXIT, "%s: %i", __func__, ret); return ret; }
osync_bool osync_merger_demerge(OSyncMerger *merger, OSyncChange *change, OSyncCapabilities *caps, OSyncError **error) { char *buffer; unsigned int size; osync_assert(merger); osync_assert(change); osync_return_val_if_fail(caps, TRUE); OSyncData *data = osync_change_get_data(change); osync_data_get_data(data, &buffer, &size); if (size == 0) { osync_error_set(error, OSYNC_ERROR_GENERIC, "Can't demerge data with 0 size."); goto error; } if (buffer == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "No data to demerge."); goto error; } if (!merger->demerge_func(&buffer, &size, caps, NULL /*userdata!*/, error)) goto error; return TRUE; error: return FALSE; }
static osync_bool _inject_changelog_entries(OSyncObjEngine *engine, OSyncError **error) { OSyncList *ids = NULL; OSyncList *changetypes = NULL; OSyncList *j = NULL, *t = NULL; osync_trace(TRACE_ENTRY, "%s(%p)", __func__, engine); osync_assert(engine); osync_assert(engine->archive); osync_assert(engine->objtype); if (!osync_archive_load_ignored_conflicts(engine->archive, engine->objtype, &ids, &changetypes, error)) { osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return FALSE; } t = changetypes; for (j = ids; j; j = j->next) { long long int id = (long long int)GPOINTER_TO_INT(j->data); OSyncMapping *ignored_mapping = osync_mapping_table_find_mapping(engine->mapping_table, id); GList *e; for (e = engine->mapping_engines; e; e = e->next) { OSyncMappingEngine *mapping_engine = e->data; if (mapping_engine->mapping == ignored_mapping) { GList *m; for (m = mapping_engine->entries; m; m = m->next) { OSyncMappingEntryEngine *entry = m->data; OSyncChangeType changetype = (OSyncChangeType) t->data; OSyncChange *ignored_change = osync_change_new(error); OSyncObjFormat *dummyformat = NULL; OSyncData *data = NULL; osync_change_set_changetype(ignored_change, changetype); osync_entry_engine_update(entry, ignored_change); dummyformat = osync_objformat_new("plain", engine->objtype, NULL); data = osync_data_new(NULL, 0, dummyformat, NULL); osync_change_set_data(ignored_change, data); osync_objformat_unref(dummyformat); osync_change_set_uid(ignored_change, osync_mapping_entry_get_uid(entry->entry)); osync_trace(TRACE_INTERNAL, "CHANGE: %p", entry->change); } break; } } t = t->next; } osync_list_free(ids); osync_list_free(changetypes); osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; }
OSyncCapabilitiesObjType *osync_capabilities_add_new_objtype(OSyncCapabilities *capabilities, const char *objtype, OSyncError **error) { OSyncCapabilitiesObjType *capsobjtype = NULL; osync_trace(TRACE_ENTRY, "%s: %p %p", __func__, capabilities, objtype); osync_assert(capabilities); osync_assert(objtype); capsobjtype = osync_capabilities_objtype_new(objtype, error); if (!capsobjtype) goto error; osync_capabilities_add_objtype(capabilities, capsobjtype); osync_capabilities_objtype_unref(capsobjtype); osync_trace(TRACE_EXIT, "%s: %p", __func__, capsobjtype); return capsobjtype; error: if (capsobjtype) osync_capabilities_objtype_unref(capsobjtype); osync_trace(TRACE_EXIT, "%s: %s", __func__, osync_error_print(error)); return NULL; }
OSyncSinkEngine *osync_sink_engine_new(int position, OSyncClientProxy *proxy, OSyncObjEngine *objengine, OSyncError **error) { OSyncSinkEngine *sinkengine = NULL; osync_trace(TRACE_ENTRY, "%s(%i, %p, %p, %p)", __func__, position, proxy, objengine, error); osync_assert(proxy); osync_assert(objengine); sinkengine = osync_try_malloc0(sizeof(OSyncSinkEngine), error); if (!sinkengine) goto error; sinkengine->ref_count = 1; sinkengine->position = position; /* we dont reference the proxy to avoid circular dependencies. This object is completely * dependent on the proxy anyways */ sinkengine->proxy = proxy; sinkengine->engine = objengine; osync_obj_engine_ref(objengine); osync_trace(TRACE_EXIT, "%s: %p", __func__, sinkengine); return sinkengine; error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return NULL; }
void osync_xmlfield_set_name(OSyncXMLField *xmlfield, const char *name) { osync_assert(xmlfield); osync_assert(name); xmlNodeSetName(xmlfield->node, BAD_CAST name); }
static osync_bool conv_mockformat1_to_mockformat1a(char *input, unsigned int inpsize, char **output, unsigned int *outpsize, osync_bool *free_input, const char *config, void *userdata, OSyncError **error) { osync_trace(TRACE_INTERNAL, "Converting file to fileA"); *free_input = FALSE; char *identifier = " "; OSyncFileFormat *file = (OSyncFileFormat *)input; OSyncFileFormat *fileA = osync_try_malloc0(sizeof(OSyncFileFormat), error); osync_assert(fileA); char *filedata = osync_try_malloc0(file->size + 2, error); memcpy(filedata, file->data, file->size); memcpy(filedata + file->size, identifier , 2); fileA->path = file->path; osync_assert(*error == NULL); fileA->data = filedata; fileA->size = file->size + 2; *output = (char *)fileA; *outpsize = sizeof(OSyncFileFormat); return TRUE; }
static OSyncConvCmpResult compare_file(const char *leftdata, unsigned int leftsize, const char *rightdata, unsigned int rightsize, void *user_data, OSyncError **error) { osync_trace(TRACE_ENTRY, "%s(%p, %i, %p, %i)", __func__, leftdata, leftsize, rightdata, rightsize); osync_assert(leftdata); osync_assert(rightdata); OSyncFileFormat *leftfile = (OSyncFileFormat *)leftdata; OSyncFileFormat *rightfile = (OSyncFileFormat *)rightdata; osync_assert(rightfile->path); osync_assert(leftfile->path); osync_trace(TRACE_INTERNAL, "Comparing %s and %s", leftfile->path, rightfile->path); if (mock_format_get_error("MOCK_FORMAT_PATH_COMPARE_NO") || !strcmp(leftfile->path, rightfile->path)) { if (leftfile->size == rightfile->size) { if (leftfile->size == 0 || !memcmp(leftfile->data, rightfile->data, rightfile->size)) { osync_trace(TRACE_EXIT, "%s: Same", __func__); return OSYNC_CONV_DATA_SAME; } } osync_trace(TRACE_EXIT, "%s: Similar", __func__); return OSYNC_CONV_DATA_SIMILAR; } osync_trace(TRACE_EXIT, "%s: Mismatch", __func__); return OSYNC_CONV_DATA_MISMATCH; }
osync_bool osync_capabilities_save(OSyncCapabilities *capabilities, const char *file, OSyncError **error) { unsigned int size; char *buffer; osync_bool ret; osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, capabilities, __NULLSTR(file), error); osync_assert(capabilities); osync_assert(file); osync_capabilities_sort(capabilities); ret = osync_capabilities_assemble(capabilities, &buffer, &size, error); if (!ret) goto error; ret = osync_file_write(file, buffer, size, 0600, error); osync_free(buffer); if (!ret) goto error; osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; error: osync_trace(TRACE_EXIT_ERROR, "%s: %s" , __func__, osync_error_print(error)); return FALSE; }
osync_bool osync_capabilities_objtype_assemble(OSyncCapabilitiesObjType *capsobjtype, xmlNode *node, OSyncError **error) { const char *name; OSyncList *l; xmlNode *cur; osync_assert(capsobjtype); osync_assert(node); name = osync_capabilities_objtype_get_name(capsobjtype); osync_assert(name); cur = xmlNewChild(node, NULL, (xmlChar*)"ObjType", NULL); if (!cur) goto error_oom; xmlSetProp(cur, (const xmlChar*)"Name", (const xmlChar*)name); for (l = capsobjtype->capabilities; l; l = l->next) { OSyncCapability *capability; capability = (OSyncCapability *) l->data; if (!osync_capability_assemble(capability, cur, error)) goto error; } return TRUE; error_oom: osync_error_set(error, OSYNC_ERROR_GENERIC, "Couldn't allocate memory to assemble capabilities objtype file."); error: osync_trace(TRACE_EXIT_ERROR, "%s: %s" , __func__, osync_error_print(error)); return FALSE; }
osync_bool osync_module_load(OSyncModule *module, const char *path, OSyncError **error) { osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, module, path, error); osync_assert(module); osync_assert(!module->module); if (!g_module_supported()) { osync_error_set(error, OSYNC_ERROR_GENERIC, "This platform does not support loading of modules"); goto error; } /* Try to open the module or fail if an error occurs. * * Do local bind to avoid symbol-clashing - i.e. plugins having the same * functions name - e.g. finalize(). * * Don't do lazy binding, otherwise symbols of kdepim-sync can't get loaded. * Related to C++ and dlopen? */ module->module = g_module_open(path, G_MODULE_BIND_LOCAL); if (!module->module) { osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to open module %s: %s", path, g_module_error()); goto error; } module->path = osync_strdup(path); osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return FALSE; }
OSyncXMLField *osync_xmlfield_new(OSyncXMLFormat *xmlformat, const char *name, OSyncError **error) { xmlNodePtr node = NULL; OSyncXMLField *xmlfield = NULL; osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, xmlformat, name, error); osync_assert(xmlformat); osync_assert(name); node = xmlNewTextChild(xmlDocGetRootElement(xmlformat->doc), NULL, BAD_CAST name, NULL); xmlfield = osync_xmlfield_new_node(xmlformat, node, error); if(!xmlfield) { xmlUnlinkNode(node); xmlFreeNode(node); osync_trace(TRACE_EXIT_ERROR, "%s: %s" , __func__, osync_error_print(error)); return NULL; } /* XMLFormat entry got added - not sure if it is still sorted */ osync_xmlformat_set_unsorted(xmlformat); /* This XMLField has no keys, so it's for sure it's sorted */ xmlfield->sorted = TRUE; osync_trace(TRACE_EXIT, "%s: %p", __func__, xmlfield); return xmlfield; }
/** @brief Creates a simple OSyncPluginConfig with a single resource. * If config is not null the resource information gets added. * * @param config OSyncPluginConfig pointer to add resource info * @param path relative path of resource * @param objformat the objformat of the resource * @param format_config the format converter config paramter * @returns OSyncPluginConfig pointer or asserts on error * */ OSyncPluginConfig *simple_plugin_config(OSyncPluginConfig *config, const char *path, const char *objtype, const char *objformat, const char *format_config) { OSyncError *error = NULL; OSyncObjFormatSink *format_sink = NULL; OSyncPluginResource *res = NULL; osync_assert(objtype); osync_assert(objformat); if (!config) config = osync_plugin_config_new(&error); fail_unless(config != NULL, NULL); fail_unless(error == NULL, NULL); format_sink = osync_objformat_sink_new(objformat, &error); if (format_config) osync_objformat_sink_set_config(format_sink, format_config); res = osync_plugin_resource_new(&error); osync_plugin_resource_set_objtype(res, objtype); osync_plugin_resource_set_path(res, path); osync_plugin_resource_enable(res, TRUE); osync_plugin_resource_add_objformat_sink(res, format_sink); osync_plugin_config_add_resource(config, res); return config; }
void osync_mapping_remove_entry(OSyncMapping *mapping, OSyncMappingEntry *entry) { osync_assert(mapping); osync_assert(entry); mapping->entries = g_list_remove(mapping->entries, entry); osync_mapping_entry_unref(entry); }
void osync_mapping_add_entry(OSyncMapping *mapping, OSyncMappingEntry *entry) { osync_assert(mapping); osync_assert(entry); mapping->entries = g_list_append(mapping->entries, entry); osync_mapping_entry_ref(entry); }
void osync_format_env_register_filter(OSyncFormatEnv *env, OSyncCustomFilter *filter) { osync_assert(env); osync_assert(filter); env->custom_filters = g_list_append(env->custom_filters, filter); osync_custom_filter_ref(filter); }
void osync_plugin_env_register_plugin(OSyncPluginEnv *env, OSyncPlugin *plugin) { osync_assert(env); osync_assert(plugin); env->plugins = g_list_append(env->plugins, plugin); osync_plugin_ref(plugin); }
void osync_format_env_register_objformat(OSyncFormatEnv *env, OSyncObjFormat *format) { osync_assert(env); osync_assert(format); env->objformats = g_list_append(env->objformats, format); osync_objformat_ref(format); }
void osync_xmlfield_set_attr(OSyncXMLField *xmlfield, const char *attr, const char *value) { osync_assert(xmlfield); osync_assert(attr); osync_assert(value); xmlSetProp(xmlfield->node, BAD_CAST attr, BAD_CAST value); }
osync_bool osync_xmlformat_assemble(OSyncXMLFormat *xmlformat, char **buffer, unsigned int *size) { osync_assert(xmlformat); osync_assert(buffer); osync_assert(size); xmlDocDumpFormatMemoryEnc(xmlformat->doc, (xmlChar **)buffer, (int *)size, NULL, 1); return TRUE; }
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); }
/*! @brief Get fixed conflict resolution for the group for all appearing conflicts * * @param group The group * @param res Pointer to set conflict resolution value * @param num Pointer to set Member ID value which solves the conflict (winner) * */ void osync_group_get_conflict_resolution(OSyncGroup *group, OSyncConflictResolution *res, int *num) { osync_assert(group); osync_assert(res); osync_assert(num); *res = group->conflict_resolution; *num = group->conflict_winner; }
void osync_mapping_entry_set_uid(OSyncMappingEntry *entry, const char *uid) { osync_assert(entry); osync_assert(uid); if (entry->uid) osync_free(entry->uid); entry->uid = osync_strdup(uid); }