From: Armin B. <arm...@de...> - 2005-09-07 18:37:56
|
Hi Stefan, thanks for helping with the development! Stefan Struhs wrote: > Hi, > > don't know where to post these improvements (see attachments; whole > functions/structs to replace in the attached files). > > Reason: If you have more than one partnership it could happen, that the > current synce-plugin overwrites an existing partnership, because it > always sets the partnership to id 1. Therefore I have added some stuff > from the original MultiSync plugin. I've also extended the configuration > file. If you do not use <partnership_id_file> synce-plugin would create > resp. use "~/.synce-partner". > > I would really appreciate to see this change in the svn-repository, > because I use my devices with M$ ActiveSync and OpenSync. Dont worry. subversion is easier to use than cvs and much better :) > > If you want me to, I would join the developer group to work on > synce-plugin. Unfortunately I have not worked with svn yet, but I can > learn to use it. Sure! Just tell me what username you want and i will add an account for you. Armin > > Regards, > Stefan > > > ------------------------------------------------------------------------ > > <config> > <contact></contact> > <todos></todos> > <calendar></calendar> > <files> > <dir></dir> > </files> > <partnership_id_file></partnership_id_file> > </config> > > > ------------------------------------------------------------------------ > > osync_bool synce_parse_settings(synce_plugin_environment *env, char *data, int size, OSyncError **error) > { > osync_trace(TRACE_ENTRY, "%s(%p, %p, %i)", __func__, env, data, size); > xmlDocPtr doc; > xmlNodePtr cur; > > //set defaults > env->config_contacts = FALSE; > env->config_calendar = FALSE; > env->config_todos = FALSE; > env->config_file = NULL; > env->partnership_id_file = g_strdup_printf("%s/.synce-partner",getenv("HOME")); > > doc = xmlParseMemory(data, size); > > if (!doc) { > osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to parse settings"); > osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); > return FALSE; > } > > cur = xmlDocGetRootElement(doc); > > if (!cur) { > xmlFreeDoc(doc); > osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get root element of the settings"); > osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); > return FALSE; > } > > if (xmlStrcmp(cur->name, (xmlChar*)"config")) { > xmlFreeDoc(doc); > osync_error_set(error, OSYNC_ERROR_GENERIC, "Config valid is not valid"); > osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); > return FALSE; > } > > cur = cur->xmlChildrenNode; > > while (cur != NULL) { > char *str = (char*)xmlNodeGetContent(cur); > if (str) { > if (!xmlStrcmp(cur->name, (const xmlChar *)"contact")) { > /* Disable by mentioning NO or FALSE, otherwise enable. */ > env->config_contacts = TRUE; > if (g_ascii_strcasecmp(str, "FALSE") == 0) > env->config_contacts = FALSE; > if (g_ascii_strcasecmp(str, "NO") == 0) > env->config_contacts = FALSE; > } > if (!xmlStrcmp(cur->name, (const xmlChar *)"file")) { > env->config_file = g_strdup(str); > } > if (!xmlStrcmp(cur->name, (const xmlChar *)"calendar")) { > /* Disable by mentioning NO or FALSE, otherwise enable. */ > env->config_calendar = TRUE; > if (g_ascii_strcasecmp(str, "FALSE") == 0) > env->config_calendar = FALSE; > if (g_ascii_strcasecmp(str, "NO") == 0) > env->config_calendar = FALSE; > } > if (!xmlStrcmp(cur->name, (const xmlChar *)"todos")) { > /* Disable by mentioning NO or FALSE, otherwise enable. */ > env->config_todos = TRUE; > if (g_ascii_strcasecmp(str, "FALSE") == 0) > env->config_todos = FALSE; > if (g_ascii_strcasecmp(str, "NO") == 0) > env->config_todos = FALSE; > } > if (!xmlStrcmp(cur->name, (const xmlChar *)"partnership_id_file")) { > env->partnership_id_file = g_strdup(str); > } > > xmlFree(str); > } > cur = cur->next; > } > > /* This belongs in XXX_connect() > * if (!osync_member_objtype_enabled(env->member, "contact")) > * env->config_contacts = FALSE; > * if (!osync_member_objtype_enabled(env->member, "todos")) > * env->config_todos = FALSE; > * if (!osync_member_objtype_enabled(env->member, "calendar")) > * env->config_calendar = FALSE; > */ > > if (env->config_contacts == 0 && env->config_calendar == 0 > && env->config_todos == 0 && env->config_file == NULL) { > osync_error_set(error, OSYNC_ERROR_GENERIC, "Nothing was configured"); > osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); > return FALSE; > } > > xmlFreeDoc(doc); > osync_trace(TRACE_EXIT, "%s", __func__); > return TRUE; > } > > > ------------------------------------------------------------------------ > > static void connect(OSyncContext *ctx) > { > RRA_Matchmaker* matchmaker = NULL; > > osync_debug("SYNCE-SYNC", 4, "start: %s", __func__); > > synce_plugin_environment *env = (synce_plugin_environment *)osync_context_get_plugin_data(ctx); > > //1 - creating matchmaker > matchmaker = rra_matchmaker_new(); > if (!matchmaker){ > osync_context_report_error(ctx, 1, "building matchmaker"); > return; > } > osync_debug("SYNCE-SYNC", 4, "matchmaker built"); > > //2 - setting partnership > FILE* file = fopen(env->partnership_id_file, "r"); > uint32_t partnership_id = 0; > char id_buffer[10] = ""; > uint32_t index = 0; > > // try to get existing partnership > if (file) { > > fgets(id_buffer, sizeof(id_buffer), file); > partnership_id = strtol(id_buffer, NULL, 16); > fclose(file); > > osync_trace(TRACE_INTERNAL, "SYNCE-SYNC: %s: connected to partnership ID %08x", __func__, partnership_id); > > for (index = 1; index <= 2; index++) { > uint32_t id; > > if (rra_matchmaker_get_partner_id(matchmaker, index, &id) && id == partnership_id) { > // TODO: add check hostname too > break; > } > } > > if (index == 3) { > osync_context_report_error(ctx, 1, "no partnership on the device matches this synchronization pair"); > rra_matchmaker_destroy(matchmaker); > return; > } > else { > if (!rra_matchmaker_set_current_partner(matchmaker, index)) { > osync_context_report_error(ctx, 1, "set current partner"); > rra_matchmaker_destroy(matchmaker); > return; > } > } > } > // try to create partnership > else { > osync_trace(TRACE_EXIT_ERROR, "SYNCE-SYNC: %s: '%s' no such file (no error, if there is no partnership-file)", __func__, env->partnership_id_file); > > if (!rra_matchmaker_create_partnership(matchmaker, &index)) { > osync_context_report_error(ctx, 1, "Failed to create or select a partnership. Use the synce-matchmaker tool"); > rra_matchmaker_destroy(matchmaker); > return; > } > > if (!rra_matchmaker_get_partner_id(matchmaker, index, &partnership_id)) { > osync_context_report_error(ctx, 1, "Failed to get partnership ID"); > rra_matchmaker_destroy(matchmaker); > return; > } > > osync_trace(TRACE_INTERNAL, "SYNCE-SYNC: %s: connected to partnership ID %08x", __func__, partnership_id); > > file = fopen(env->partnership_id_file, "w"); > > if (!file) { > osync_context_report_error(ctx, 1, "Failed to create file '%s'",env->partnership_id_file); > rra_matchmaker_destroy(matchmaker); > return; > } > > snprintf(id_buffer, sizeof(id_buffer), "%08x", partnership_id); > fwrite(id_buffer, strlen(id_buffer), 1, file); > fclose(file); > //New partnership -> compare/sync everything, not only changes! > osync_trace(TRACE_INTERNAL, "SYNCE-SYNC: %s: Synchronisation is set to slow", __func__); > osync_member_set_slow_sync(env->member, "contact", TRUE); > osync_member_set_slow_sync(env->member, "event", TRUE); > osync_member_set_slow_sync(env->member, "todo", TRUE); > } > > osync_debug("SYNCE-SYNC", 4, "partner set"); > > //3 -setting timezone > if (!rra_timezone_get(&(env->timezone))){ > osync_context_report_error(ctx, 1, "getting timezone"); > rra_matchmaker_destroy(matchmaker); > return; > } > > osync_debug("SYNCE-SYNC", 4, "timezone set"); > > //4- creating syncmgr > env->syncmgr = rra_syncmgr_new(); > > if (!rra_syncmgr_connect(env->syncmgr)) > { > osync_context_report_error(ctx, 1, "can't connect"); > rra_matchmaker_destroy(matchmaker); > rra_syncmgr_destroy(env->syncmgr); > return; > } > > osync_debug("SYNCE-SYNC", 4, "syncmgr created"); > > /* if (!osync_member_objtype_enabled(env->member, "contact")) > * env->config_contacts = FALSE; > * if (!osync_member_objtype_enabled(env->member, "todos")) > * env->config_todos = FALSE; > * if (!osync_member_objtype_enabled(env->member, "calendar")) > * env->config_calendar = FALSE; > */ > > if (env->config_file) > file_connect(ctx); > > osync_context_report_success(ctx); > } > > > void get_info(OSyncPluginInfo *env) > { > OSyncPluginInfo *info = osync_plugin_new_info((void*)env); > > info->name = "synce-plugin"; > info->longname = "SynCE plugin for OpenSync"; > info->description = "This plugin allows synchronization with a device running Windows CE or Pocket PC. by mirkuz"; > > info->version = 1; > > info->is_threadsafe = FALSE; > > info->functions.initialize = initialize; > info->functions.connect = connect; > info->functions.sync_done = sync_done; > info->functions.disconnect = disconnect; > info->functions.finalize = finalize; > info->functions.get_changeinfo = get_changeinfo; > info->functions.get_data = file_get_data; > > info->timeouts.connect_timeout = 5; > > osync_plugin_accept_objtype(info, "contact"); > osync_plugin_accept_objformat(info, "contact", "vcard30", NULL); > osync_plugin_set_commit_objformat(info, "contact", "vcard30", commit_contacts_change); > > osync_plugin_accept_objtype(info, "event"); > osync_plugin_accept_objformat(info, "event", "vevent10", NULL); > osync_plugin_set_commit_objformat(info, "event", "vevent10", commit_cal_change); > > osync_plugin_accept_objtype(info, "todo"); > osync_plugin_accept_objformat(info, "todo", "vtodo10", NULL); > osync_plugin_set_commit_objformat(info, "todo", "vtodo10", commit_todo_change); > > osync_plugin_accept_objtype(info, "data"); > osync_plugin_accept_objformat(info, "data", "file", NULL); > osync_plugin_set_commit_objformat(info, "data", "file", file_commit); > #if 0 > osync_plugin_set_access_objformat(info, "data", "file", file_access); > osync_plugin_set_read_objformat(info, "data", "file", file_read); > #endif > } > > > ------------------------------------------------------------------------ > > typedef struct synce_plugin_environment { > OSyncMember *member; > OSyncHashTable *hashtable; /* Need a hash for the file sync part. */ > > RRA_SyncMgr* syncmgr; /* This is the connection to SynCE */ > RRA_Timezone timezone; > int last_change_counter; > int change_counter; > ids_list* contact_ids; > ids_list* todo_ids; > ids_list* cal_ids; > > /* Configuration */ > osync_bool config_contacts, config_todos, config_calendar; > char *config_file; > char *partnership_id_file; > } synce_plugin_environment; |