static void check_c_rbtree_insert_delete(void **state) { c_rbtree_t *tree = NULL; c_rbnode_t *node = NULL; test_t *testdata = NULL; int rc; (void) state; /* unused */ rc = c_rbtree_create(&tree, key_cmp, data_cmp); assert_int_equal(rc, 0); testdata = malloc(sizeof(test_t)); testdata->key = 42; rc = c_rbtree_insert(tree, (void *) testdata); assert_int_equal(rc, 0); node = c_rbtree_head(tree); assert_non_null(node); testdata = c_rbtree_node_data(node); SAFE_FREE(testdata); rc = c_rbtree_node_delete(node); assert_int_equal(rc, 0); c_rbtree_free(tree); }
static void check_csync_detect_update_db_new(void **state) { CSYNC *csync = *state; csync_file_stat_t *st; csync_vio_file_stat_t *fs; int rc; fs = create_fstat("file.txt", 42000, 1, 0); assert_non_null(fs); rc = _csync_detect_update(csync, "/tmp/check_csync1/file.txt", fs, CSYNC_FTW_TYPE_FILE); assert_int_equal(rc, 0); /* the instruction should be set to new */ st = c_rbtree_node_data(csync->local.tree->root); assert_int_equal(st->instruction, CSYNC_INSTRUCTION_NEW); /* set the instruction to UPDATED that it gets written to the statedb */ st->instruction = CSYNC_INSTRUCTION_UPDATED; /* create a statedb */ csync_set_status(csync, 0xFFFF); csync_vio_file_stat_destroy(fs); }
static void check_c_rbtree_find(void **state) { c_rbtree_t *tree = *state; int rc, i = 42; c_rbnode_t *node; test_t *testdata; rc = c_rbtree_check_sanity(tree); assert_int_equal(rc, 0); /* find the node with the key 42 */ node = c_rbtree_find(tree, (void *) &i); assert_non_null(node); testdata = (test_t *) c_rbtree_node_data(node); assert_int_equal(testdata->key, 42); }
struct listdir_context *get_listdir_context_from_recursive_cache(const char *curi) { propfind_recursive_element_t *element = NULL; struct listdir_context *fetchCtx = NULL; struct resource *iterator, *r; if (!propfind_recursive_cache) { DEBUG_WEBDAV("get_listdir_context_from_recursive_cache No cache"); return NULL; } element = c_rbtree_node_data(c_rbtree_find(propfind_recursive_cache, curi)); if (!element) { DEBUG_WEBDAV("get_listdir_context_from_recursive_cache No element %s in cache found", curi); return NULL; } /* Out of the element, create a listdir_context.. if we could be sure that it is immutable, we could ref instead.. need to investigate */ fetchCtx = c_malloc( sizeof( struct listdir_context )); ZERO_STRUCTP(fetchCtx); fetchCtx->list = NULL; fetchCtx->target = c_strdup(curi); fetchCtx->currResource = NULL; fetchCtx->ref = 1; iterator = element->children; r = NULL; while (iterator) { r = resource_dup(iterator); r->next = fetchCtx->list; fetchCtx->list = r; iterator = iterator->next; fetchCtx->result_count++; /* DEBUG_WEBDAV("get_listdir_context_from_cache Returning cache for %s element %s", fetchCtx->target, fetchCtx->list->uri); */ } r = resource_dup(element->self); r->next = fetchCtx->list; fetchCtx->result_count++; fetchCtx->list = r; fetchCtx->currResource = fetchCtx->list; DEBUG_WEBDAV("get_listdir_context_from_cache Returning cache for %s (%d elements)", fetchCtx->target, fetchCtx->result_count); return fetchCtx; }
static void check_c_rbtree_delete(void **state) { c_rbtree_t *tree = *state; int rc, i = 42; c_rbnode_t *node = NULL; test_t *freedata = NULL; rc = c_rbtree_check_sanity(tree); assert_int_equal(rc, 0); node = c_rbtree_find(tree, (void *) &i); assert_non_null(node); freedata = (test_t *) c_rbtree_node_data(node); free(freedata); rc = c_rbtree_node_delete(node); assert_int_equal(rc, 0); rc = c_rbtree_check_sanity(tree); assert_int_equal(rc, 0); }
static void check_c_rbtree_walk(void **state) { c_rbtree_t *tree = *state; int rc, i = 42; test_t *testdata; c_rbnode_t *node; rc = c_rbtree_check_sanity(tree); assert_int_equal(rc, 0); testdata = (test_t *) c_malloc(sizeof(test_t)); testdata->key = 42; rc = c_rbtree_walk(tree, testdata, visitor); assert_int_equal(rc, 0); /* find the node with the key 42 */ node = c_rbtree_find(tree, (void *) &i); assert_non_null(node); free(testdata); testdata = (test_t *) c_rbtree_node_data(node); assert_int_equal(testdata->number, 42); }
static void check_csync_detect_update_nlink(void **state) { CSYNC *csync = *state; csync_file_stat_t *st; csync_vio_file_stat_t *fs; int rc; /* create vio file stat with nlink greater than 1 */ fs = create_fstat("file.txt", 0, 7, 0); assert_non_null(fs); /* add it to local tree */ rc = _csync_detect_update(csync, "/tmp/check_csync1/file.txt", fs, CSYNC_FTW_TYPE_FILE); assert_int_equal(rc, 0); /* the instruction should be set to ignore */ st = c_rbtree_node_data(csync->local.tree->root); assert_int_equal(st->instruction, CSYNC_INSTRUCTION_IGNORE); csync_vio_file_stat_destroy(fs); }
static void propfind_results_recursive(void *userdata, const ne_uri *uri, const ne_prop_result_set *set) { struct resource *newres = 0; const char *clength, *modtime, *file_id = NULL; const char *resourcetype = NULL; const char *md5sum = NULL; const ne_status *status = NULL; char *path = ne_path_unescape( uri->path ); char *parentPath; char *propfindRootUri = (char*) userdata; propfind_recursive_element_t *element = NULL; propfind_recursive_element_t *pElement = NULL; int depth = 0; (void) status; (void) propfindRootUri; if (!propfind_recursive_cache) { c_rbtree_create(&propfind_recursive_cache, _key_cmp, _data_cmp); } /* Fill the resource structure with the data about the file */ newres = c_malloc(sizeof(struct resource)); ZERO_STRUCTP(newres); newres->uri = path; /* no need to strdup because ne_path_unescape already allocates */ newres->name = c_basename( path ); modtime = ne_propset_value( set, &ls_props[0] ); clength = ne_propset_value( set, &ls_props[1] ); resourcetype = ne_propset_value( set, &ls_props[2] ); md5sum = ne_propset_value( set, &ls_props[3] ); file_id = ne_propset_value( set, &ls_props[4] ); newres->type = resr_normal; if( resourcetype && strncmp( resourcetype, "<DAV:collection>", 16 ) == 0) { newres->type = resr_collection; propfind_recursive_cache_folder_count++; } else { /* DEBUG_WEBDAV("propfind_results_recursive %s [%d]", newres->uri, newres->type); */ propfind_recursive_cache_file_count++; } if (modtime) { newres->modtime = oc_httpdate_parse(modtime); } /* DEBUG_WEBDAV("Parsing Modtime: %s -> %llu", modtime, (unsigned long long) newres->modtime ); */ newres->size = 0; if (clength) { newres->size = atoll(clength); /* DEBUG_WEBDAV("Parsed File size for %s from %s: %lld", newres->name, clength, (long long)newres->size ); */ } if( md5sum ) { newres->md5 = csync_normalize_etag(md5sum); } csync_vio_set_file_id(newres->file_id, file_id); /* DEBUG_WEBDAV("propfind_results_recursive %s [%s] %s", newres->uri, newres->type == resr_collection ? "collection" : "file", newres->md5); */ /* Create new item in rb tree */ if (newres->type == resr_collection) { DEBUG_WEBDAV("propfind_results_recursive %s is a folder", newres->uri); /* Check if in rb tree */ element = c_rbtree_node_data(c_rbtree_find(propfind_recursive_cache,uri->path)); /* If not, create a new item and insert it */ if (!element) { element = c_malloc(sizeof(propfind_recursive_element_t)); element->self = resource_dup(newres); element->children = NULL; element->parent = NULL; c_rbtree_insert(propfind_recursive_cache, element); /* DEBUG_WEBDAV("results_recursive Added collection %s", newres->uri); */ } } /* Check for parent in tree. If exists: Insert it into the children elements there */ parentPath = ne_path_parent(uri->path); if (parentPath) { propfind_recursive_element_t *parentElement = NULL; parentElement = c_rbtree_node_data(c_rbtree_find(propfind_recursive_cache,parentPath)); free(parentPath); if (parentElement) { newres->next = parentElement->children; parentElement->children = newres; /* If the current result is a collection we also need to set its parent */ if (element) element->parent = parentElement; pElement = element; while (pElement) { depth++; pElement = pElement->parent; } if (depth > propfind_recursive_cache_depth) { DEBUG_WEBDAV("propfind_results_recursive %s new maximum tree depth %d", newres->uri, depth); propfind_recursive_cache_depth = depth; } /* DEBUG_WEBDAV("results_recursive Added child %s to collection %s", newres->uri, element->self->uri); */ } else { /* DEBUG_WEBDAV("results_recursive No parent %s found for child %s", parentPath, newres->uri); */ resource_free(newres); newres = NULL; } } }
static void propfind_results_recursive_callback(void *userdata, const ne_uri *uri, const ne_prop_result_set *set) { struct resource *newres = 0; const ne_status *status = NULL; char *path = ne_path_unescape( uri->path ); char *parentPath; propfind_recursive_element_t *element = NULL; propfind_recursive_element_t *pElement = NULL; int depth = 0; csync_owncloud_ctx_t *ctx = (csync_owncloud_ctx_t*) userdata; (void) status; if (!ctx->propfind_recursive_cache) { c_rbtree_create(&ctx->propfind_recursive_cache, _key_cmp, _data_cmp); } /* Fill the resource structure with the data about the file */ newres = c_malloc(sizeof(struct resource)); newres->uri = path; /* no need to strdup because ne_path_unescape already allocates */ newres->name = c_basename( path ); fill_webdav_properties_into_resource(newres, set); if( newres->type == resr_collection) { ctx->propfind_recursive_cache_folder_count++; } else { ctx->propfind_recursive_cache_file_count++; } /* Create new item in rb tree */ if (newres->type == resr_collection) { DEBUG_WEBDAV("propfind_results_recursive %s is a folder", newres->uri); /* Check if in rb tree */ element = c_rbtree_node_data(c_rbtree_find(ctx->propfind_recursive_cache,uri->path)); /* If not, create a new item and insert it */ if (!element) { element = c_malloc(sizeof(propfind_recursive_element_t)); element->self = resource_dup(newres); element->self->next = 0; element->children = NULL; element->parent = NULL; c_rbtree_insert(ctx->propfind_recursive_cache, element); /* DEBUG_WEBDAV("results_recursive Added collection %s", newres->uri); */ } } /* Check for parent in tree. If exists: Insert it into the children elements there */ parentPath = ne_path_parent(uri->path); if (parentPath) { propfind_recursive_element_t *parentElement = NULL; parentElement = c_rbtree_node_data(c_rbtree_find(ctx->propfind_recursive_cache,parentPath)); free(parentPath); if (parentElement) { newres->next = parentElement->children; parentElement->children = newres; /* If the current result is a collection we also need to set its parent */ if (element) element->parent = parentElement; pElement = element; while (pElement) { depth++; pElement = pElement->parent; } if (depth > ctx->propfind_recursive_cache_depth) { DEBUG_WEBDAV("propfind_results_recursive %s new maximum tree depth %d", newres->uri, depth); ctx->propfind_recursive_cache_depth = depth; } /* DEBUG_WEBDAV("results_recursive Added child %s to collection %s", newres->uri, element->self->uri); */ return; } } resource_free(newres); newres = NULL; }