Ejemplo n.º 1
0
dpl_status_t
dpl_cdmi_head_all(dpl_ctx_t *ctx,
                  const char *bucket,
                  const char *resource,
                  const char *subresource,
                  dpl_ftype_t object_type,
                  const dpl_condition_t *condition,
                  dpl_dict_t **metadatap)
{
  int ret, ret2;
  char *md_buf = NULL;
  u_int md_len;
  dpl_dict_t *metadata = NULL;
  
  //fetch metadata from JSON content
  ret2 = dpl_cdmi_get(ctx, bucket, resource, NULL != subresource ? subresource : "metadata", object_type, condition, &md_buf, &md_len, NULL);
  if (DPL_SUCCESS != ret2)
    {
      ret = DPL_FAILURE;
      goto end;
    }
  
  metadata = dpl_dict_new(13);
  if (NULL == metadata)
    {
      ret = DPL_ENOMEM;
      goto end;
    }

  ret2 = dpl_cdmi_parse_metadata(ctx, md_buf, md_len, metadata);
  if (DPL_SUCCESS != ret2)
    {
      ret = ret2;
      goto end;
    }

  if (NULL != metadatap)
    {
      *metadatap = metadata;
      metadata = NULL;
    }
  
  ret = DPL_SUCCESS;
  
 end:

  if (NULL != metadata)
    dpl_dict_free(metadata);

  if (NULL != md_buf)
    free(md_buf);
  
  return ret;
}
Ejemplo n.º 2
0
dpl_status_t
dpl_cdmi_get_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,
                char **data_bufp,
                unsigned int *data_lenp,
                dpl_dict_t **metadatap,
                dpl_sysmd_t *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, "get_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_get(ctx, bucket, resource, subresource, option, object_type, condition, range, data_bufp, data_lenp, metadatap, 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;
}
Ejemplo n.º 3
0
dpl_status_t
dpl_cdmi_head_raw(dpl_ctx_t *ctx,
                  const char *bucket,
                  const char *resource,
                  const char *subresource,
                  const dpl_option_t *option,
                  dpl_ftype_t object_type,
                  const dpl_condition_t *condition,
                  dpl_dict_t **metadatap,
                  char **locationp)
{
  int ret, ret2;
  char *md_buf = NULL;
  u_int md_len;
  dpl_value_t *val = NULL;
  dpl_option_t option2;

  DPL_TRACE(ctx, DPL_TRACE_BACKEND, "");
  
  //fetch metadata from JSON content
  memset(&option2, 0, sizeof (option2));
  option2.mask |= DPL_OPTION_RAW;
  ret2 = dpl_cdmi_get(ctx, bucket, resource, NULL != subresource ? subresource : "metadata;objectID;parentID;objectType", &option2, object_type, condition, NULL, &md_buf, &md_len, NULL, NULL, locationp);
  if (DPL_SUCCESS != ret2)
    {
      ret = ret2;
      goto end;
    }
  
  ret2 = dpl_cdmi_parse_json_buffer(ctx, md_buf, md_len, &val);
  if (DPL_SUCCESS != ret2)
    {
      ret = ret2;
      goto end;
    }

  if (DPL_VALUE_SUBDICT != val->type)
    {
      ret = DPL_EINVAL;
      goto end;
    }
  
  if (NULL != metadatap)
    {
      *metadatap = val->subdict;
      val->subdict = NULL;
    }
  
  ret = DPL_SUCCESS;
  
 end:

  if (NULL != val)
    dpl_value_free(val);

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

  DPL_TRACE(ctx, DPL_TRACE_BACKEND, "ret=%d", ret);
  
  return ret;
}