X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Fstore-s3.c;h=fd2da4f5431b96c5f2598d900cbc49e4f903540c;hb=388030970805a70cb4fad34ade5e3de7a3607a57;hp=8ffc296f855993549dc21932cc472275539bd6c8;hpb=d7d143ef0ccf0f49a8fd23a3c76bc68c0b04e07e;p=bluesky.git diff --git a/bluesky/store-s3.c b/bluesky/store-s3.c index 8ffc296..fd2da4f 100644 --- a/bluesky/store-s3.c +++ b/bluesky/store-s3.c @@ -34,10 +34,17 @@ struct get_info { }; struct put_info { + int success; BlueSkyRCStr *val; gint offset; }; +struct list_info { + int success; + char *last_entry; + gboolean truncated; +}; + static S3Status s3store_get_handler(int bufferSize, const char *buffer, void *callbackData) { @@ -95,26 +102,21 @@ static void s3store_task(gpointer a, gpointer s) handler.responseHandler.completeCallback = s3store_response_callback; handler.getObjectDataCallback = s3store_get_handler; - S3_get_object(&store->bucket, async->key, NULL, 0, 0, NULL, - &handler, &info); + S3_get_object(&store->bucket, async->key, NULL, + async->start, async->len, NULL, &handler, &info); + async->range_done = TRUE; if (info.success) { - BlueSkyRCStr *raw, *decrypted; - raw = bluesky_string_new_from_gstring(info.buf); - decrypted = bluesky_crypt_decrypt(raw, store->encryption_key); - bluesky_string_unref(raw); - async->data = decrypted; + async->data = bluesky_string_new_from_gstring(info.buf); async->result = 0; } else { g_string_free(info.buf, TRUE); } } else if (async->op == STORE_OP_PUT) { - BlueSkyRCStr *encrypted = bluesky_crypt_encrypt(async->data, - store->encryption_key); - struct put_info info; - info.val = encrypted; + info.success = 0; + info.val = async->data; info.offset = 0; struct S3PutObjectHandler handler; @@ -123,26 +125,74 @@ static void s3store_task(gpointer a, gpointer s) handler.responseHandler.completeCallback = s3store_response_callback; handler.putObjectDataCallback = s3store_put_handler; - S3_put_object(&store->bucket, async->key, encrypted->len, NULL, NULL, + S3_put_object(&store->bucket, async->key, async->data->len, NULL, NULL, &handler, &info); - bluesky_string_unref(encrypted); - - async->result = 0; + if (info.success) { + async->result = 0; + } else { + g_warning("Error completing S3 put operation; client must retry!"); + } } bluesky_store_async_mark_complete(async); bluesky_store_async_unref(async); } +static S3Status s3store_list_handler(int isTruncated, + const char *nextMarker, + int contentsCount, + const S3ListBucketContent *contents, + int commonPrefixesCount, + const char **commonPrefixes, + void *callbackData) +{ + struct list_info *info = (struct list_info *)callbackData; + if (contentsCount > 0) { + g_free(info->last_entry); + info->last_entry = g_strdup(contents[contentsCount - 1].key); + } + info->truncated = isTruncated; + return S3StatusOK; +} + +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; +} + static gpointer s3store_new(const gchar *path) { S3Store *store = g_new(S3Store, 1); store->thread_pool = g_thread_pool_new(s3store_task, store, -1, FALSE, NULL); - store->bucket.bucketName = "mvrable-bluesky"; + if (path == NULL || strlen(path) == 0) + store->bucket.bucketName = "mvrable-bluesky"; + else + store->bucket.bucketName = g_strdup(path); store->bucket.protocol = S3ProtocolHTTP; - store->bucket.uriStyle = S3UriStylePath; + store->bucket.uriStyle = S3UriStyleVirtualHost; store->bucket.accessKeyId = getenv("AWS_ACCESS_KEY_ID"); store->bucket.secretAccessKey = getenv("AWS_SECRET_ACCESS_KEY"); @@ -201,6 +251,7 @@ static BlueSkyStoreImplementation store_impl = { .destroy = s3store_destroy, .submit = s3store_submit, .cleanup = s3store_cleanup, + .lookup_last = s3store_lookup_last, }; void bluesky_store_init_s3(void)