dpl_status_t dpl_cdmi_copy(dpl_ctx_t *ctx, const char *src_bucket, const char *src_resource, const char *src_subresource, const char *dst_bucket, const char *dst_resource, const char *dst_subresource, const dpl_option_t *option, dpl_ftype_t object_type, dpl_copy_directive_t copy_directive, const dpl_dict_t *metadata, const dpl_sysmd_t *sysmd, const dpl_condition_t *condition, char **locationp) { int ret, ret2; dpl_conn_t *conn = NULL; char header[dpl_header_size]; u_int header_len; struct iovec iov[10]; int n_iov = 0; int connection_close = 0; dpl_dict_t *headers_request = NULL; dpl_dict_t *headers_reply = NULL; dpl_req_t *req = NULL; char *body_str = NULL; int body_len = 0; int add_base_path; DPL_TRACE(ctx, DPL_TRACE_BACKEND, ""); if (DPL_COPY_DIRECTIVE_METADATA_REPLACE == copy_directive) { ret = dpl_cdmi_put(ctx, dst_bucket, dst_resource, NULL, NULL, object_type, condition, NULL, metadata, DPL_CANNED_ACL_UNDEF, NULL, 0, NULL, NULL, locationp); goto end; } req = dpl_req_new(ctx); if (NULL == req) { ret = DPL_ENOMEM; goto end; } dpl_req_set_method(req, DPL_METHOD_PUT); ret2 = dpl_cdmi_req_set_resource(req, dst_resource); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } if (NULL != dst_subresource) { ret2 = dpl_req_set_subresource(req, dst_subresource); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } } if (copy_directive == DPL_COPY_DIRECTIVE_MKDENT || copy_directive == DPL_COPY_DIRECTIVE_RMDENT) add_base_path = 0; else add_base_path = 1; ret2 = dpl_req_set_src_resource_ext(req, src_resource, add_base_path); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } if (NULL != src_subresource) { ret2 = dpl_req_set_src_subresource(req, src_subresource); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } } dpl_req_set_copy_directive(req, copy_directive); dpl_req_set_object_type(req, object_type); dpl_req_add_behavior(req, DPL_BEHAVIOR_MD5); if (NULL != sysmd) { ret2 = dpl_cdmi_add_sysmd_to_req(sysmd, req); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } } if (NULL != metadata) { ret2 = dpl_cdmi_req_add_metadata(req, metadata, option ? option->mask & DPL_OPTION_APPEND_METADATA : 0); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } } //build request ret2 = dpl_cdmi_req_build(req, 0, &headers_request, &body_str, &body_len); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } //contact default host dpl_req_rm_behavior(req, DPL_BEHAVIOR_VIRTUAL_HOSTING); ret2 = dpl_try_connect(ctx, req, &conn); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } ret2 = dpl_add_host_to_headers(req, headers_request); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } ret2 = dpl_req_gen_http_request(ctx, req, headers_request, NULL, header, sizeof (header), &header_len); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } iov[n_iov].iov_base = header; iov[n_iov].iov_len = header_len; n_iov++; //final crlf iov[n_iov].iov_base = "\r\n"; iov[n_iov].iov_len = 2; n_iov++; //buffer iov[n_iov].iov_base = body_str; iov[n_iov].iov_len = body_len; n_iov++; ret2 = dpl_conn_writev_all(conn, iov, n_iov, conn->ctx->write_timeout); if (DPL_SUCCESS != ret2) { DPL_TRACE(conn->ctx, DPL_TRACE_ERR, "writev failed"); connection_close = 1; ret = ret2; goto end; } ret2 = dpl_read_http_reply(conn, 1, NULL, NULL, &headers_reply, &connection_close); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } ret = DPL_SUCCESS; end: if (NULL != body_str) free(body_str); if (NULL != conn) { if (1 == connection_close) dpl_conn_terminate(conn); else dpl_conn_release(conn); } if (NULL != headers_reply) dpl_dict_free(headers_reply); if (NULL != headers_request) dpl_dict_free(headers_request); if (NULL != req) dpl_req_free(req); DPL_TRACE(ctx, DPL_TRACE_BACKEND, "ret=%d", ret); return ret; }
dpl_status_t dpl_req_set_src_resource(dpl_req_t *req, const char *src_resource) { return dpl_req_set_src_resource_ext(req, src_resource, 1); }