From: <dg...@su...> - 2009-01-11 02:40:11
|
Author: ianmartin Date: Sun Jan 11 03:39:34 2009 New Revision: 5091 URL: http://www.opensync.org/changeset/5091 Log: Use new OSyncAnchor API added in r5021. Fixes #1025, thanks to HaltonHuo Modified: plugins/evolution2/src/evolution2_ebook.c plugins/evolution2/src/evolution2_ecal.c Modified: plugins/evolution2/src/evolution2_ebook.c ============================================================================== --- plugins/evolution2/src/evolution2_ebook.c Sun Jan 11 03:26:25 2009 (r5090) +++ plugins/evolution2/src/evolution2_ebook.c Sun Jan 11 03:39:34 2009 (r5091) @@ -139,23 +139,36 @@ osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, data, info, ctx); OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); OSyncEvoEnv *env = (OSyncEvoEnv *)data; + osync_bool anchor_match; if (!(env->addressbook = evo2_ebook_open_book(osync_strdup(env->addressbook_path), &error))) { goto error; } - char *anchorpath = g_strdup_printf("%s/anchor.db", osync_plugin_info_get_configdir(info)); - if (!osync_anchor_compare(anchorpath, "contact", env->addressbook_path)) + OSyncAnchor *anchor = osync_objtype_sink_get_anchor(sink); + if (!anchor) { + osync_error_set(&error, OSYNC_ERROR_GENERIC, "Anchor missing for objtype \"%s\"", osync_objtype_sink_get_name(sink)); + goto error_free_book; + } + if (!osync_anchor_compare(anchor, env->addressbook_path, &anchor_match, &error)) { + osync_error_set(&error, OSYNC_ERROR_GENERIC, "Anchor comparison failed for objtype \"%s\"", osync_objtype_sink_get_name(sink)); + goto error_free_book; + } + if (!anchor_match) { + osync_trace(TRACE_INTERNAL, "EBook slow sync, due to anchor mismatch"); osync_objtype_sink_set_slowsync(sink, TRUE); - g_free(anchorpath); + } osync_context_report_success(ctx); osync_trace(TRACE_EXIT, "%s", __func__); return; - -error: + + error_free_book: + g_object_unref(env->addressbook); + env->addressbook = NULL; + error: osync_context_report_osyncerror(ctx, error); osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); osync_error_unref(&error); @@ -183,24 +196,33 @@ OSyncError *error = NULL; GError *gerror=NULL; - char *anchorpath = g_strdup_printf("%s/anchor.db", osync_plugin_info_get_configdir(info)); - osync_anchor_update(anchorpath, "contact", env->addressbook_path); - g_free(anchorpath); - + OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); + OSyncAnchor *anchor = osync_objtype_sink_get_anchor(sink); + if (!anchor) { + osync_error_set(&error, OSYNC_ERROR_GENERIC, "Anchor missing for objtype \"%s\"", osync_objtype_sink_get_name(sink)); + goto error; + } + if (!osync_anchor_update(anchor, env->addressbook_path, &error)) + goto error; GList *changes = NULL; if (!e_book_get_changes(env->addressbook, env->change_id, &changes, &gerror)) { osync_error_set(&error, OSYNC_ERROR_GENERIC, "Unable to update EBook time of last sync: %s", gerror ? gerror->message : "None"); g_clear_error(&gerror); - osync_context_report_osyncerror(ctx, error); - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); - osync_error_unref(&error); + goto error; } e_book_free_change_list(changes); osync_context_report_success(ctx); osync_trace(TRACE_EXIT, "%s", __func__); + return; + + error: + osync_context_report_osyncerror(ctx, error); + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); + osync_error_unref(&error); + } void evo2_report_change(OSyncContext *ctx, OSyncObjFormat *format, char *data, unsigned int size, const char *uid, OSyncChangeType changetype) @@ -411,6 +433,8 @@ functions.commit = evo2_ebook_modify; functions.sync_done = evo2_ebook_sync_done; + osync_objtype_sink_enable_anchor(sink, TRUE); + OSyncPluginConfig *config = osync_plugin_info_get_config(info); OSyncPluginResource *resource = osync_plugin_config_find_active_resource(config, "contact"); env->addressbook_path = osync_plugin_resource_get_url(resource); Modified: plugins/evolution2/src/evolution2_ecal.c ============================================================================== --- plugins/evolution2/src/evolution2_ecal.c Sun Jan 11 03:26:25 2009 (r5090) +++ plugins/evolution2/src/evolution2_ecal.c Sun Jan 11 03:39:34 2009 (r5091) @@ -90,22 +90,33 @@ OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); OSyncEvoCalendar * evo_cal = (OSyncEvoCalendar *)osync_objtype_sink_get_userdata(sink); - OSyncEvoEnv *env = (OSyncEvoEnv *)data; - if (!(evo_cal->calendar = evo2_ecal_open_cal(osync_strdup(evo_cal->uri), evo_cal->source_type, &error))) { goto error; } - char *anchorpath = g_strdup_printf("%s/anchor.db", osync_plugin_info_get_configdir(info)); - if (!osync_anchor_compare(anchorpath, evo_cal->objtype, evo_cal->uri)) - osync_objtype_sink_set_slowsync(sink, TRUE); - g_free(anchorpath); + OSyncAnchor *anchor = osync_objtype_sink_get_anchor(sink); + osync_bool anchor_match; + if (!anchor) { + osync_error_set(&error, OSYNC_ERROR_GENERIC, "Anchor missing for objtype \"%s\"", osync_objtype_sink_get_name(sink)); + goto error_free_cal; + } + if (!osync_anchor_compare(anchor, evo_cal->uri, &anchor_match, &error)) { + osync_error_set(&error, OSYNC_ERROR_GENERIC, "Anchor comparison failed for objtype \"%s\"", osync_objtype_sink_get_name(sink)); + goto error_free_cal; + } + if (!anchor_match) { + osync_trace(TRACE_INTERNAL, "ECal slow sync, due to anchor mismatch for objtype \"%s\"", osync_objtype_sink_get_name(sink)); + osync_objtype_sink_set_slowsync(sink, TRUE); + } osync_context_report_success(ctx); osync_trace(TRACE_EXIT, "%s", __func__); return; + error_free_cal: + g_object_unref(evo_cal->calendar); + evo_cal->calendar = NULL; error: osync_context_report_osyncerror(ctx, error); osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); @@ -115,7 +126,6 @@ static void evo2_ecal_disconnect(void *data, OSyncPluginInfo *info, OSyncContext *ctx) { osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, data, info, ctx); - OSyncEvoEnv *env = (OSyncEvoEnv *)data; OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); OSyncEvoCalendar * evo_cal = (OSyncEvoCalendar *)osync_objtype_sink_get_userdata(sink); @@ -140,24 +150,31 @@ OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); OSyncEvoCalendar * evo_cal = (OSyncEvoCalendar *)osync_objtype_sink_get_userdata(sink); - char *anchorpath = g_strdup_printf("%s/anchor.db", osync_plugin_info_get_configdir(info)); - osync_anchor_update(anchorpath, evo_cal->objtype, evo_cal->uri); - g_free(anchorpath); - + OSyncAnchor *anchor = osync_objtype_sink_get_anchor(sink); + if (!anchor) { + osync_error_set(&error, OSYNC_ERROR_GENERIC, "Anchor missing for objtype \"%s\"", osync_objtype_sink_get_name(sink)); + goto error; + } + if (!osync_anchor_update(anchor, evo_cal->uri, &error)) + goto error; GList *changes = NULL; if (!e_cal_get_changes(evo_cal->calendar, env->change_id, &changes, &gerror)) { osync_error_set(&error, OSYNC_ERROR_GENERIC, "Unable to update %s ECal time of last sync: %s", evo_cal->objtype, gerror ? gerror->message : "None"); g_clear_error(&gerror); - osync_context_report_osyncerror(ctx, error); - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); - osync_error_unref(&error); + goto error; } e_cal_free_change_list(changes); osync_context_report_success(ctx); osync_trace(TRACE_EXIT, "%s", __func__); + return; + + error: + osync_context_report_osyncerror(ctx, error); + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); + osync_error_unref(&error); } void evo2_ecal_report_change(OSyncContext *ctx, OSyncObjFormat *format, char *data, unsigned int size, const char *uid, OSyncChangeType changetype) @@ -269,7 +286,6 @@ static void evo2_ecal_modify(void *data, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *change) { osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, data, info, ctx, change); - OSyncEvoEnv *env = (OSyncEvoEnv *)data; const char *uid = osync_change_get_uid(change); icalcomponent *icomp = NULL; @@ -410,6 +426,8 @@ functions.commit = evo2_ecal_modify; functions.sync_done = evo2_ecal_sync_done; + osync_objtype_sink_enable_anchor(sink, TRUE); + OSyncEvoCalendar *cal = osync_try_malloc0(sizeof(OSyncEvoCalendar), error); if (!cal) { return FALSE; |