Exemplo n.º 1
0
dpl_status_t
dpl_cdmi_put_id(dpl_ctx_t *ctx,
                const char *bucket,
                const char *id,
                const char *subresource,
                const dpl_option_t *option,
                dpl_ftype_t object_type,
                const dpl_condition_t *condition,
                const dpl_range_t *range,
                const dpl_dict_t *metadata,
                const dpl_sysmd_t *sysmd,
                const char *data_buf,
                unsigned int data_len,
                const dpl_dict_t *query_params,
                dpl_sysmd_t *returned_sysmdp,
                char **locationp)
{
  dpl_status_t ret, ret2;
  char *id_path = NULL;
  char resource[DPL_MAXPATHLEN];
  char *native_id = NULL;

  DPL_TRACE(ctx, DPL_TRACE_ID, "put_id bucket=%s id=%s subresource=%s", bucket, id, subresource);

  ret = dpl_cdmi_get_id_path(ctx, bucket, &id_path);
  if (DPL_SUCCESS != ret)
    {
      goto end;
    }

  ret2 = dpl_cdmi_convert_id_to_native(ctx, id, ctx->enterprise_number, &native_id);
  if (DPL_SUCCESS != ret2)
    {
      ret = ret2;
      goto end;
    }

  snprintf(resource, sizeof (resource), "%s%s", id_path ? id_path : "", native_id);

  ret = dpl_cdmi_put(ctx, bucket, resource, subresource, option, object_type, condition,
                     range, metadata, sysmd, data_buf, data_len, query_params, returned_sysmdp, locationp);

 end:

  if (NULL != native_id)
    free(native_id);

  if (NULL != id_path)
    free(id_path);

  DPL_TRACE(ctx, DPL_TRACE_ID, "ret=%d", ret);
  
  return ret;
}
Exemplo n.º 2
0
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,
              dpl_ftype_t object_type,
              dpl_metadata_directive_t metadata_directive,
              const dpl_dict_t *metadata,
              const dpl_sysmd_t *sysmd,
              const dpl_condition_t *condition)
{
  int ret, ret2;

  switch (metadata_directive)
    {
    case DPL_METADATA_DIRECTIVE_UNDEF:
      ret = DPL_ENOTSUPP;
      goto end;
    case DPL_METADATA_DIRECTIVE_COPY:
      ret = DPL_ENOTSUPP;
      goto end;
    case DPL_METADATA_DIRECTIVE_REPLACE:

      //replace the metadata
      ret2 = dpl_cdmi_put(ctx, dst_bucket, dst_resource,
                          NULL != dst_subresource ? dst_subresource : "metadata",
                          object_type, metadata, DPL_CANNED_ACL_UNDEF, NULL, 0);
      if (DPL_SUCCESS != ret2)
        {
          ret = ret2;
          goto end;
        }

      break ;
    }

  ret = DPL_SUCCESS;
  
 end:

  return ret;
}
Exemplo n.º 3
0
dpl_status_t
dpl_cdmi_copy_id(dpl_ctx_t *ctx,
                 const char *src_bucket,
                 const char *src_id,
                 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)
{
  dpl_status_t ret, ret2;
  char *id_path = NULL;
  char src_resource[DPL_MAXPATHLEN];
  char *src_native_id = NULL;

  DPL_TRACE(ctx, DPL_TRACE_ID, "delete src_bucket=%s src_id=%s src_subresource=%s", src_bucket, src_id, src_subresource);

  if (DPL_COPY_DIRECTIVE_MKDENT == copy_directive)
    id_path = NULL;
  else
    {
      ret = dpl_cdmi_get_id_path(ctx, src_bucket, &id_path);
      if (DPL_SUCCESS != ret)
        {
          goto end;
        }
    }

  ret2 = dpl_cdmi_convert_id_to_native(ctx, src_id, ctx->enterprise_number, &src_native_id);
  if (DPL_SUCCESS != ret2)
    {
      ret = ret2;
      goto end;
    }

  snprintf(src_resource, sizeof (src_resource), "%s%s", id_path ? id_path : "", src_native_id);

  if (DPL_COPY_DIRECTIVE_METADATA_REPLACE == copy_directive)
    ret = dpl_cdmi_put(ctx, src_bucket, src_resource, NULL, NULL,
                       object_type, condition, NULL, metadata, DPL_CANNED_ACL_UNDEF, NULL, 0, 
                       NULL, NULL, locationp);
  else
    ret = dpl_cdmi_copy(ctx, src_bucket, src_resource, src_subresource, dst_bucket, dst_resource, dst_subresource,
                        option, object_type, copy_directive, metadata, sysmd, condition, locationp);
  
 end:

  if (NULL != src_native_id)
    free(src_native_id);

  if (NULL != id_path)
    free(id_path);

  DPL_TRACE(ctx, DPL_TRACE_ID, "ret=%d", ret);
  
  return ret;
}
Exemplo n.º 4
0
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;
}