S3Status cloud_list_bucket(const char *bucketName, list_bucket_filler_t filler) {
  S3BucketContext bucketContext =
  {
    0,
    bucketName,
    protocolG,
    uriStyleG,
    accessKeyIdG,
    secretAccessKeyG
  };

  S3ListBucketHandler listBucketHandler =
  {
    { &responsePropertiesCallback, &responseCompleteCallback },
    &listBucketCallback
  };

  list_bucket_callback_data data;

  const char *prefix = 0, *marker = 0, *delimiter = 0;
  int maxkeys = 0;
  snprintf(data.nextMarker, sizeof(data.nextMarker), "%s", marker);
  data.filler = filler;

  do {
    data.isTruncated = 0;
    S3_list_bucket(&bucketContext, prefix, data.nextMarker,
                   delimiter, maxkeys, 0, &listBucketHandler, &data);
    if (statusG != S3StatusOK) {
        break;
    }
  } while (data.isTruncated);

  return statusG;
}
Esempio n. 2
0
static char *s3store_lookup_last(gpointer s, const char *prefix)
{
    S3Store *store = (S3Store *)s;
    struct list_info info = {0, NULL, FALSE};

    struct S3ListBucketHandler handler;
    handler.responseHandler.propertiesCallback
        = s3store_properties_callback;
    handler.responseHandler.completeCallback = s3store_response_callback;
    handler.listBucketCallback = s3store_list_handler;

    char *marker = NULL;

    do {
        S3_list_bucket(&store->bucket, prefix, marker, NULL, 1024, NULL,
                       &handler, &info);
        g_free(marker);
        marker = g_strdup(info.last_entry);
        g_print("Last key: %s\n", info.last_entry);
    } while (info.truncated);

    g_free(marker);

    return info.last_entry;
}
Esempio n. 3
0
void list_bucket(const char *bucketName, const char *prefix,
                        const char *marker, const char *delimiter,
                        int maxkeys, const char* ak, const char* sk)
{

    S3_init();
    savedCommonPrefixes.clear();
    savedContents.clear();
    savedKeys.clear();

    S3BucketContext bucketContext =
    {
        0,
        bucketName,
        S3ProtocolHTTPS,
        S3UriStyleVirtualHost,
        ak,
        sk
    };

    S3ListBucketHandler listBucketHandler =
    {
        { &responsePropertiesCallback, &responseCompleteCallback },
        &listBucketCallback
    };

    list_bucket_callback_data data;

    snprintf(data.nextMarker, sizeof(data.nextMarker), "%s", marker);
    data.keyCount = 0;
    data.allDetails = 0;

    do {
        data.isTruncated = 0;
        do {
            S3_list_bucket(&bucketContext, prefix, data.nextMarker,
                           delimiter, maxkeys, 0, &listBucketHandler, &data);
        } while (S3_status_is_retryable((S3Status)statusG) && should_retry());
        if (statusG != S3StatusOK) {
            break;
        }
    } while (data.isTruncated && (!maxkeys || (data.keyCount < maxkeys)));

    if (statusG == S3StatusOK) {
//        if (!data.keyCount) {
//            printListBucketHeader(allDetails);
//        }
    }
    else {
        printError();
    }

    S3_deinitialize();
}
Esempio n. 4
0
int
list_bucket(const char *bucketName, const char *prefix, const char *marker, 
const char *delimiter, int maxkeys, int allDetails, s3Stat_t *s3Stat)
{
    int status;
    callback_data_t data;
    S3BucketContext bucketContext;

    if ((status = myS3Init ()) != S3StatusOK) return (status);

      /* {myBucket,  1, 0, S3Auth.accessKeyId, S3Auth.secretAccessKey}; */
      /* XXXXX using S3UriStyleVirtualHost causes operation containing
       * the sub-string "S3" to fail. use S3UriStylePath instead */
      /* this initialization failed for 3-2.0 because of the hostName
       * element
      S3BucketContext bucketContext =
      {bucketName,  S3ProtocolHTTPS, S3UriStylePath, S3Auth.accessKeyId,
        S3Auth.secretAccessKey}; */
    bzero (&bucketContext, sizeof (bucketContext));
    bucketContext.bucketName = bucketName;
    bucketContext.protocol = S3ProtocolHTTPS;
    bucketContext.uriStyle = S3UriStylePath;
    bucketContext.accessKeyId = S3Auth.accessKeyId;
    bucketContext.secretAccessKey = S3Auth.secretAccessKey;

    S3ListBucketHandler listBucketHandler = {
        { &responsePropertiesCallback, &responseCompleteCallback },
        &listBucketCallback
    };

#if 0
    if (marker != NULL)
        snprintf(data.nextMarker, sizeof(data.nextMarker), "%s", marker);
    else
	 data.nextMarker[0] = '\0';
#endif
    data.keyCount = 0;
    data.allDetails = allDetails;

    S3_list_bucket(&bucketContext, prefix, marker,
      delimiter, maxkeys, 0, &listBucketHandler, &data);

    if (data.keyCount > 0) {
	*s3Stat = data.s3Stat;
	status = 0;
    } else {
	 status = myS3Error (data.status, S3_FILE_STAT_ERR);
    }
    /* S3_deinitialize(); */

    return status;
}
int __s3fs_clear_bucket(const char *bucketName) {
    S3_init();

    const char *prefix = 0, *marker = 0, *delimiter = 0;
    int maxkeys = 0, allDetails = 0;
    
    S3BucketContext bucketContext =
    {
        0,
        bucketName,
        protocolG,
        uriStyleG,
        accessKeyIdG,
        secretAccessKeyG
    };

    S3ListBucketHandler listBucketHandler =
    {
        { &responsePropertiesCallback, &responseCompleteCallback },
        &traverseBucketCallback
    };

    traverse_bucket_callback_data data;

    snprintf(data.nextMarker, sizeof(data.nextMarker), "%s", marker);
    data.keyCount = 0;
    data.keylist = NULL;
    data.allDetails = allDetails;

    do {
        data.isTruncated = 0;
        do {
            S3_list_bucket(&bucketContext, prefix, data.nextMarker,
                           delimiter, maxkeys, 0, &listBucketHandler, &data);
        } while (S3_status_is_retryable(statusG) && should_retry());
        if (statusG != S3StatusOK) {
            break;
        }
    } while (data.isTruncated && (!maxkeys || (data.keyCount < maxkeys)));

    int rv = statusG == S3StatusOK ? 0 : -1;

    S3_deinitialize();

    struct node *klist = data.keylist;

    // try to remove objects
    if (rv == 0) {
        while (klist) {
            struct node *el = klist;
            int thisrv = __s3fs_remove_object(bucketName, el->key);
            if (thisrv < 0) {
                rv = -1;
            }
            klist = klist->next;
        }
    }

    // free keylist
    klist = data.keylist;
    while (klist) {
        struct node *el = klist;
        klist = klist->next;
        free(el->key);
        free(el);
    }

    return rv;
}