static void dump_hash(OSyncGroupEnv *env, const char *objtype, const char *groupname, char *memberid) { OSyncGroup *group = osync_group_env_find_group(env, groupname); #if 0 /* Unused */ OSyncError *error = NULL; long long int id = 0; OSyncMember *member = NULL; char *path = NULL; OSyncHashTable *table = NULL; #endif if (!group) { printf("Unable to find group with name \"%s\"\n", groupname); return; } printf("Dumping hashtable is currently not implemented!\n"); return; /* FIXME: public interface osync_hashltable_new() is gone! * no interface to access the disk directly! * */ #if 0 id = atoi(memberid); member = osync_group_find_member(group, id); if (!member) { printf("Unable to find member with id %s\n", memberid); return; } path = g_strdup_printf("%s/hashtable.db", osync_member_get_configdir(member)); table = osync_hashtable_new(path, objtype, &error); if (!table) goto error; g_free(path); if (!osync_hashtable_load(table, &error)) goto error; osync_hashtable_foreach(table, print_hashtable, NULL); osync_hashtable_unref(table); error: printf("ERROR: %s", osync_error_print(&error)); osync_error_unref(&error); #endif }
static void disconnect(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) { OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); sink_environment *sinkenv = osync_objtype_sink_get_userdata(sink); //Close all stuff you need to close //Close the hashtable osync_hashtable_unref(sinkenv->hashtable); sinkenv->hashtable = NULL; //Answer the call osync_context_report_success(ctx); }
static void dump_hash(OSyncGroupEnv *env, const char *objtype, const char *groupname, char *memberid) { OSyncError *error = NULL; OSyncGroup *group = osync_group_env_find_group(env, groupname); long long int id = 0; OSyncMember *member = NULL; char *path = NULL; OSyncHashTable *table = NULL; if (!group) { printf("Unable to find group with name \"%s\"\n", groupname); return; } id = atoi(memberid); member = osync_group_find_member(group, id); if (!member) { printf("Unable to find member with id %s\n", memberid); return; } path = g_strdup_printf("%s/hashtable.db", osync_member_get_configdir(member)); table = osync_hashtable_new(path, objtype, &error); if (!table) goto error; g_free(path); osync_hashtable_foreach(table, print_hashtable, NULL); osync_hashtable_unref(table); return; error: printf("ERROR: %s", osync_error_print(&error)); osync_error_unref(&error); }
END_TEST START_TEST (hashtable_reload) { OSyncError *error = NULL; char *testbed = setup_testbed(NULL); osync_bool new_hashtable = FALSE; reset_hashtable_counters(); char *hashpath = g_strdup_printf("%s%chashtable.db", testbed, G_DIR_SEPARATOR); OSyncHashTable *table = osync_hashtable_new(hashpath, "contact", &new_hashtable, &error); fail_unless(!error, NULL); fail_unless(table != NULL, NULL); fail_unless(new_hashtable != FALSE, NULL); /* Expecting a new/fresh hastable */ /***** load */ fail_unless(osync_hashtable_load(table, &error), NULL); OSyncChange *fakechange = osync_change_new(&error); osync_change_set_uid(fakechange, "test1"); char *rndhash = osync_rand_str(g_random_int_range(100, 200), &error); osync_assert(error == NULL); osync_change_set_hash(fakechange, rndhash); osync_change_set_changetype(fakechange, OSYNC_CHANGE_TYPE_ADDED); osync_hashtable_update_change(table, fakechange); osync_change_unref(fakechange); /*** store - commit hashtable */ fail_unless(osync_hashtable_save(table, &error), NULL); fail_unless(!error, NULL); osync_hashtable_unref(table); table = NULL; /** reload the hashtable */ OSyncHashTable *newtable = osync_hashtable_new(hashpath, "contact", &new_hashtable, &error); fail_unless(!error, NULL); fail_unless(newtable != NULL, NULL); fail_unless(new_hashtable != TRUE, NULL); /* We expect here no new hashtable */ /* 0 entries - since not loaded! */ fail_unless(osync_hashtable_num_entries(newtable) == 0, NULL); /* load and count and compare hashs */ fail_unless(osync_hashtable_load(newtable, &error), NULL); fail_unless(osync_hashtable_num_entries(newtable) == 1, NULL); const char *newhash = osync_hashtable_get_hash(newtable, "test1"); fail_unless(newhash != NULL, NULL); fail_unless(!strcmp(newhash, rndhash), NULL); g_free(rndhash); g_free(hashpath); destroy_testbed(testbed); }