int main (int argc, char *argv[]) { int i; char *pluginname = NULL; char *plugindir = NULL; char *configfile = NULL; char *objtype = NULL; OSyncError *error = NULL; if (argc < 2) usage (argv[0], 1); pluginname = argv[1]; for (i = 2; i < argc; i++) { char *arg = argv[i]; if (!strcmp (arg, "--config")) { configfile = argv[i + 1]; i++; if (!configfile) usage (argv[0], 1); } else if (!strcmp (arg, "--type")) { objtype = argv[i + 1]; i++; if (!objtype) usage (argv[0], 1); } else if (!strcmp (arg, "--plugindir")) { printf("plugindir %s\n", argv[i + 1]); plugindir = argv[i + 1]; i++; if (!plugindir) usage (argv[0], 1); } else if (!strcmp (arg, "--random")) { only_random = TRUE; } else if (!strcmp (arg, "--help")) { usage (argv[0], 0); } else { usage (argv[0], 1); } } OSyncEnv *env = osync_env_new(NULL); osync_env_set_option(env, "LOAD_GROUPS", "FALSE"); if (plugindir) osync_env_set_option(env, "PLUGINS_DIRECTORY", plugindir); if (!osync_env_initialize(env, &error)) { printf("Unable to initialize environment: %s\n", osync_error_print(&error)); osync_error_unref(&error); return 1; } char *testdir = g_strdup_printf("%s/plgtest.XXXXXX", g_get_tmp_dir()); char *result = mkdtemp(testdir); if (result == NULL) { osync_trace(TRACE_EXIT_ERROR, "unable to create temporary dir: %s", g_strerror(errno)); return 1; } OSyncGroup *group = osync_group_new(env); osync_group_set_name(group, osync_rand_str(8)); osync_group_set_configdir(group, testdir); OSyncMember *member = osync_member_new(group); char *config = NULL; int size = 0; if (configfile) { if (!osync_file_read(configfile, &config, &size, &error)) { fprintf(stderr, "Unable to read config: %s\n", osync_error_print(&error)); osync_error_unref(&error); return 1; } osync_member_set_config(member, config, size); } osync_member_set_pluginname(member, pluginname); OSyncMember *file = osync_member_new(group); localdir = g_strdup_printf("%s/plgtest.XXXXXX", g_get_tmp_dir()); result = mkdtemp(localdir); if (result == NULL) { osync_trace(TRACE_EXIT_ERROR, "unable to create temporary dir: %s", g_strerror(errno)); return 1; } config = g_strdup_printf("<config><path>%s</path><recursive>0</recursive></config>", localdir); osync_member_set_config(file, config, strlen(config) + 1); osync_member_set_pluginname(file, "file-sync"); if (!osync_group_save(group, &error)) { printf("Error while creating syncengine: %s\n", osync_error_print(&error)); osync_error_unref(&error); goto error_free_env; } if (!g_thread_supported ()) g_thread_init (NULL); OSyncEngine *engine = osengine_new(group, &error); if (!engine) { printf("Error while creating syncengine: %s\n", osync_error_print(&error)); osync_error_unref(&error); goto error_free_env; } if (!osengine_init(engine, &error)) { printf("Error while initializing syncengine: %s\n", osync_error_print(&error)); osync_error_unref(&error); goto error_free_engine; } int count = 0; if (only_random) { do { count++; printf("++++++++++++++++++++++++++++++\n"); printf("Initializing new round #%i!\n", count); if (g_random_int_range(0, 5) == 0) { int i; OSyncFormatEnv *env = osync_group_get_format_env(group); for (i = 0; i < osync_conv_num_objtypes(env); i++) { if (g_random_int_range(0, 5) == 0) { OSyncObjType *type = osync_conv_nth_objtype(env, i); osync_group_set_slow_sync(group, osync_objtype_get_name(type), TRUE); printf("Requesting slow-sync for: %s\n", osync_objtype_get_name(type)); } } osync_conv_env_free(env); } change_content(); check_sync(engine, "Random", 1); } while (g_random_int_range(0, 3) != 0); printf("Finalizing engine\n"); osengine_finalize(engine); osengine_free(engine); engine = osengine_new(group, &error); if (!engine) { printf("Error while creating syncengine: %s\n", osync_error_print(&error)); osync_error_unref(&error); goto error_free_env; } if (!osengine_init(engine, &error)) { printf("Error while initializing syncengine: %s\n", osync_error_print(&error)); osync_error_unref(&error); goto error_free_engine; } } else { register_tests(); run_all_tests(engine, file, member, objtype); } printf("\nCompleted successfully\n"); return 0; error_free_engine: osengine_free(engine); error_free_env: osync_group_free(group); osync_env_free(env); return 1; }
/*! @brief Loads a group from a directory * * Loads a group from a directory * * @param group The group object to load into * @param path The path to the config directory of the group * @param error Pointer to an error struct * @returns TRUE on success, FALSE otherwise * */ osync_bool osync_group_load(OSyncGroup *group, const char *path, OSyncError **error) { char *filename = NULL; char *real_path = NULL; xmlDocPtr doc; xmlNodePtr cur; //xmlNodePtr filternode; osync_assert(group); osync_assert(path); osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, group, path, error); if (!g_path_is_absolute(path)) { char *curdir = g_get_current_dir(); real_path = g_strdup_printf("%s%c%s", curdir, G_DIR_SEPARATOR, path); g_free(curdir); } else { real_path = g_strdup(path); } osync_group_set_configdir(group, real_path); filename = g_strdup_printf("%s%csyncgroup.conf", real_path, G_DIR_SEPARATOR); g_free(real_path); if (!osync_xml_open_file(&doc, &cur, filename, "syncgroup", error)) { g_free(filename); goto error; } g_free(filename); while (cur != NULL) { char *str = (char*)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (str) { if (!xmlStrcmp(cur->name, (const xmlChar *)"groupname")) osync_group_set_name(group, str); if (!xmlStrcmp(cur->name, (const xmlChar *)"last_sync")) group->last_sync = (time_t)atoi(str); //TODO: remove the next 2 lines later if (!xmlStrcmp(cur->name, (const xmlChar *)"enable_merger")) group->merger_enabled = (!g_ascii_strcasecmp("true", str)) ? TRUE : FALSE; //TODO: remove the next 2 lines later if (!xmlStrcmp(cur->name, (const xmlChar *)"enable_converter")) group->converter_enabled = (!g_ascii_strcasecmp("true", str)) ? TRUE : FALSE; if (!xmlStrcmp(cur->name, (const xmlChar *)"merger_enabled")) group->merger_enabled = (!g_ascii_strcasecmp("true", str)) ? TRUE : FALSE; if (!xmlStrcmp(cur->name, (const xmlChar *)"converter_enabled")) group->converter_enabled = (!g_ascii_strcasecmp("true", str)) ? TRUE : FALSE; // TODO: reimplement the filter! /*if (!xmlStrcmp(cur->name, (const xmlChar *)"filter")) { filternode = cur->xmlChildrenNode; OSyncFilter *filter = osync_filter_new(); filter->group = group; while (filternode != NULL) { if (!xmlStrcmp(filternode->name, (const xmlChar *)"sourceobjtype")) filter->sourceobjtype = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1); if (!xmlStrcmp(filternode->name, (const xmlChar *)"destobjtype")) filter->destobjtype = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1); if (!xmlStrcmp(filternode->name, (const xmlChar *)"detectobjtype")) filter->detectobjtype = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1); if (!xmlStrcmp(filternode->name, (const xmlChar *)"config")) filter->config = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1); if (!xmlStrcmp(filternode->name, (const xmlChar *)"function_name")) { char *str = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1); if (!str) { filternode = filternode->next; continue; } osync_filter_update_hook(filter, group, str); osync_xml_free(str); } if (!xmlStrcmp(filternode->name, (const xmlChar *)"sourcemember")) { char *str = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1); if (!str) { filternode = filternode->next; continue; } filter->sourcememberid = atoll(str); osync_xml_free(str); } if (!xmlStrcmp(filternode->name, (const xmlChar *)"destmember")) { char *str = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1); if (!str) { filternode = filternode->next; continue; } filter->destmemberid = atoll(str); osync_xml_free(str); } if (!xmlStrcmp(filternode->name, (const xmlChar *)"action")) { char *str = (char*)xmlNodeListGetString(doc, filternode->xmlChildrenNode, 1); if (!str) { filternode = filternode->next; continue; } filter->action = atoi(str); osync_xml_free(str); } filternode = filternode->next; } osync_filter_register(group, filter); }*/ osync_xml_free(str); } cur = cur->next; } osync_xml_free_doc(doc); /* Check for sanity */ if (!group->name) { osync_error_set(error, OSYNC_ERROR_MISCONFIGURATION, "Loaded a group without a name"); goto error; } if (!_osync_group_load_members(group, group->configdir, error)) goto error; osync_trace(TRACE_EXIT, "%s: %p", __func__, group); return TRUE; error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); return FALSE; }