static void get_changes(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) { osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, userdata, info, ctx); //plugin_environment *env = (plugin_environment *)userdata; OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info); OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); sink_environment *sinkenv = osync_objtype_sink_get_userdata(sink); OSyncError *error = NULL; //If you use opensync hashtables you can detect if you need //to do a slow-sync and set this on the hastable directly //otherwise you have to make 2 function like "get_changes" and //"get_all" and decide which to use using //osync_objtype_sink_get_slow_sync if (osync_objtype_sink_get_slowsync(sinkenv->sink)) { osync_trace(TRACE_INTERNAL, "Slow sync requested"); if (osync_hashtable_slowsync(sinkenv->hashtable, &error)) { osync_context_report_osyncerror(ctx, error); osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); osync_error_unref(&error); return; } } /* * Now you can get the changes. * Loop over all changes you get and do the following: */ do { char *hash = osync_strdup("<the calculated hash of the object>"); char *uid = osync_strdup("<some uid>"); //Now get the data of this change char *data = NULL; //Make the new change to report OSyncChange *change = osync_change_new(&error); if (!change) { osync_context_report_osyncwarning(ctx, error); osync_error_unref(&error); continue; } //Now set the uid of the object osync_change_set_uid(change, uid); osync_change_set_hash(change, hash); OSyncChangeType changetype = osync_hashtable_get_changetype(sinkenv->hashtable, change); osync_change_set_changetype(change, changetype); // Update entry. // Set the hash of the object (optional, only required if you use hashtabled) osync_hashtable_update_change(sinkenv->hashtable, change); if (changetype == OSYNC_CHANGE_TYPE_UNMODIFIED) { osync_free(hash); osync_free(uid); osync_change_unref(change); continue; } osync_free(hash); osync_free(uid); OSyncObjFormat *format = osync_format_env_find_objformat(formatenv, "<objformat>"); OSyncData *odata = osync_data_new(data, 0, format, &error); if (!odata) { osync_change_unref(change); osync_context_report_osyncwarning(ctx, error); osync_error_unref(&error); continue; } osync_data_set_objtype(odata, osync_objtype_sink_get_name(sinkenv->sink)); //Now you can set the data for the object osync_change_set_data(change, odata); osync_data_unref(odata); // just report the change via osync_context_report_change(ctx, change); osync_change_unref(change); osync_free(uid); } while(0); //When you are done looping and if you are using hashtables //check for deleted entries ... via hashtable OSyncList *u, *uids = osync_hashtable_get_deleted(sinkenv->hashtable); for (u = uids; u; u = u->next) { OSyncChange *change = osync_change_new(&error); if (!change) { osync_context_report_osyncwarning(ctx, error); osync_error_unref(&error); continue; } const char *uid = u->data; osync_change_set_uid(change, uid); osync_change_set_changetype(change, OSYNC_CHANGE_TYPE_DELETED); OSyncObjFormat *format = osync_format_env_find_objformat(formatenv, "<objformat>"); OSyncData *odata = osync_data_new(NULL, 0, format, &error); if (!odata) { osync_change_unref(change); osync_context_report_osyncwarning(ctx, error); osync_error_unref(&error); continue; } osync_data_set_objtype(odata, osync_objtype_sink_get_name(sinkenv->sink)); osync_change_set_data(change, odata); osync_data_unref(odata); osync_context_report_change(ctx, change); osync_hashtable_update_change(sinkenv->hashtable, change); osync_change_unref(change); } osync_list_free(uids); //Now we need to answer the call osync_context_report_success(ctx); osync_trace(TRACE_EXIT, "%s", __func__); }
void claws_mail_event_get_changes(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) { int ii; char **uids; char *vevent; osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, userdata, info, ctx); OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); ClawsMailSinkEnv *sinkenv = osync_objtype_sink_get_userdata(sink); OSyncError *error = NULL; osync_hashtable_reset_reports(sinkenv->hashtable); /* check for slowsync and prepare the "event" hashtable if needed */ if(osync_objtype_sink_get_slowsync(sinkenv->sink)) { osync_trace(TRACE_INTERNAL, "Slow sync requested"); if(!osync_hashtable_slowsync(sinkenv->hashtable, &error)) { osync_context_report_osyncerror(ctx, error); osync_trace(TRACE_EXIT_ERROR, "%s - %s", __func__, osync_error_print(&error)); osync_error_unref(&error); return; } } /* While getting all events, one at a time */ while((vevent = claws_mail_connect_get_events()) != NULL) { gchar *uid; gchar *hash; char *data; OSyncChangeType changetype; OSyncChange *change; OSyncData *odata; hash = event_hash(vevent); uid = get_uid_from_event(vevent); /* Now get the data of this change */ data = vevent; /* Report every entry .. every unreported entry got deleted. */ osync_trace(TRACE_INTERNAL, "hhb: Report: %s",uid); osync_hashtable_report(sinkenv->hashtable, uid); changetype = osync_hashtable_get_changetype(sinkenv->hashtable, uid, hash); if (changetype == OSYNC_CHANGE_TYPE_UNMODIFIED) { g_free(hash); g_free(uid); continue; } /* Set the hash of the object */ osync_hashtable_update_hash(sinkenv->hashtable, changetype, uid, hash); /* Make the new change to report */ change = osync_change_new(&error); if(!change) { osync_context_report_osyncwarning(ctx, error); osync_error_unref(&error); g_free(uid); g_free(hash); continue; } /* Now set the uid of the object */ osync_change_set_uid(change, uid); osync_change_set_hash(change, hash); osync_change_set_changetype(change, changetype); g_free(hash); g_free(uid); odata = osync_data_new(data, strlen(data), sinkenv->objformat, &error); if (!odata) { osync_change_unref(change); osync_context_report_osyncwarning(ctx, error); osync_error_unref(&error); continue; } osync_data_set_objtype(odata, osync_objtype_sink_get_name(sinkenv->sink)); /* Set the data for the object */ osync_change_set_data(change, odata); osync_data_unref(odata); /* Report the change */ osync_context_report_change(ctx, change); osync_change_unref(change); } /* Check for deleted entries */ uids = osync_hashtable_get_deleted(sinkenv->hashtable); for (ii=0; uids[ii]; ii++) { OSyncData *odata; OSyncChange *change = osync_change_new(&error); if (!change) { g_free(uids[ii]); osync_context_report_osyncwarning(ctx, error); osync_error_unref(&error); continue; } osync_change_set_uid(change, uids[ii]); osync_change_set_changetype(change, OSYNC_CHANGE_TYPE_DELETED); odata = osync_data_new(NULL, 0, sinkenv->objformat, &error); if (!odata) { g_free(uids[ii]); osync_change_unref(change); osync_context_report_osyncwarning(ctx, error); osync_error_unref(&error); continue; } osync_data_set_objtype(odata, osync_objtype_sink_get_name(sinkenv->sink)); osync_change_set_data(change, odata); osync_data_unref(odata); osync_context_report_change(ctx, change); osync_hashtable_update_hash(sinkenv->hashtable, osync_change_get_changetype(change), osync_change_get_uid(change), NULL); osync_change_unref(change); g_free(uids[ii]); } g_free(uids); osync_context_report_success(ctx); osync_trace(TRACE_EXIT, "%s", __func__); }