struct RIACK_STRING_LINKED_LIST *test_make_links(struct RIACK_STRING_LINKED_LIST *keys_answers, struct RIACK_CONTENT *content) { struct RIACK_STRING_LINKED_LIST *current; current = keys_answers; if (current) { if (current->next) { content->link_count = 2; } else { content->link_count = 1; } content->links = malloc(sizeof(struct RIACK_LINK) * content->link_count); content->links[0].bucket = riack_copy_from_cstring(test_client, RIAK_TEST_BUCKET_ANSWERS); content->links[0].key = riack_copy_string(test_client, current->string); content->links[0].tag = riack_copy_from_cstring(test_client, "link1"); if (current->next) { current = current->next; content->links[1].bucket = riack_copy_from_cstring(test_client, RIAK_TEST_BUCKET_ANSWERS); content->links[1].key = riack_copy_string(test_client, current->string); content->links[1].tag = riack_copy_from_cstring(test_client, "link2"); } if (current->next) { current = current->next; } } return current; }
void RiakTest::riack_copy_pair(riack_pair& obj, riack_pair& src) { riack_copy_string(obj.key, src.key); obj.value_present = src.value_present; obj.value_len = src.value_len; obj.value = (uint8_t*)malloc(sizeof(uint8_t)*src.value_len); memcpy(obj.value, src.value, src.value_len); }
void RiakTest::Add_Link_test_111_v2() { const char* bucket = "test"; const char* key = "key_111"; const char* type = "text/plain"; const char* data = "value_111"; //const char* bucket = "rfs"; //const char* key = "root"; //const char* type = "text/plain"; //const char* data = "value_111"; riack_string rbucket, rkey; riack_get_object *robj = NULL; rbucket.len = strlen(bucket); rbucket.value = (char*)bucket; rkey.len = strlen(key); rkey.value = (char*)key; int ret = riack_get(m_riak, &rbucket, &rkey, NULL, &robj); riack_copy_string(robj->object.bucket, rbucket); riack_copy_string(robj->object.key, rkey); riack_content& r_content = robj->object.content[0]; riack_link* r_link = r_content.links; r_content.links = (riack_link*)realloc(r_link, (r_content.link_count + 1)*sizeof(riack_link)); r_link = r_content.links + r_content.link_count; r_content.link_count += 1; const char* l_bucket = "test_444"; const char* l_key = "key_444"; const char* l_tag = "parent"; memset(r_link, 0, sizeof(r_link)); riack_set_link(*r_link, l_bucket, l_key, l_tag); riack_put(m_riak, &(robj->object), NULL, NULL); riack_free_get_object_p(m_riak, &robj); }
void RiakTest::riack_copy_link(riack_link& obj, riack_link& src) { riack_copy_string(obj.bucket, src.bucket); riack_copy_string(obj.key, src.key); riack_copy_string(obj.tag, src.tag); }
/* typedef struct _riack_content { size_t data_len; uint8_t *data; riack_string content_type; riack_string charset; riack_string content_encoding; riack_string vtag; size_t link_count; riack_link* links; // uint8_t last_modified_present; uint32_t last_modified; uint8_t last_modified_usecs_present; uint32_t last_modified_usecs; uint8_t deleted_present; uint8_t deleted; // size_t usermeta_count; riack_pair *usermetas; size_t index_count; riack_pair *indexes; } riack_content; */ riack_object* RiakTest::riack_object_add_link_new(riack_object* sobj, const char* bucket, const char* key, const char* link_bucket, const char* link_key, const char* link_tag) { riack_object* nobj = riack_object_alloc(m_riak); memset(nobj, 0, sizeof(riack_object)); nobj->bucket.value = (char*)strdup(bucket); nobj->bucket.len = strlen(bucket); nobj->key.value = (char*)strdup(key); nobj->key.len = strlen(key); nobj->content_count = 1; nobj->content = (riack_content*)malloc(sizeof(riack_content)); memset(nobj->content, 0, sizeof(riack_content)); riack_content* n_content = nobj->content; riack_content* s_content = sobj->content; //[data] riack_copy_string(n_content->content_type, s_content->content_type); //[content_type] n_content->data_len = s_content->data_len; n_content->data = (uint8_t*)calloc(n_content->data_len, sizeof(uint8_t)); memcpy(n_content->data, s_content->data, n_content->data_len); //[content_encoding] if (s_content->content_encoding.len > 0) { riack_copy_string(n_content->content_encoding, s_content->content_encoding); } //[vtag] if (s_content->vtag.len > 0) { riack_copy_string(n_content->vtag, s_content->vtag); } // [last_modified_present] // [last_modified] // [last_modified_usecs_present] // [last_modified_usecs] // [deleted_present] // [deleted] //n_content->last_modified_present = s_content->last_modified_present; //n_content->last_modified = s_content->last_modified; //n_content->last_modified_usecs_present = s_content->last_modified_usecs_present; //n_content->last_modified_usecs = s_content->last_modified_usecs; //n_content->deleted_present = s_content->deleted_present; //n_content->deleted = s_content->deleted; // [usermeta_count] //n_content->usermeta_count = s_content->usermeta_count; //n_content->usermetas = (riack_pair*)calloc(sizeof(riack_pair), n_content->usermeta_count); //riack_pair* upair = n_content->usermetas; //for (int i = 0; i < n_content->usermeta_count; i++, upair++) //{ // riack_copy_pair(*upair, s_content->usermetas[i]); //} //size_t link_count; //riack_link* links; // [link] n_content->link_count = s_content->link_count+1; n_content->links = (riack_link*)calloc(sizeof(riack_link), n_content->link_count); riack_link* r_link = n_content->links; for (int i = 0; i < s_content->link_count; i++, r_link++) { riack_copy_link(*r_link, s_content->links[i]); } riack_set_link(*r_link, link_bucket, link_key, link_tag); return nobj; }