X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Fstore-s3.c;h=e762ebda090df5324c4bc867f5ede15f884afc0e;hb=cd654b732384d42784fb995ac94940a57223ab32;hp=8ffc296f855993549dc21932cc472275539bd6c8;hpb=d7d143ef0ccf0f49a8fd23a3c76bc68c0b04e07e;p=bluesky.git diff --git a/bluesky/store-s3.c b/bluesky/store-s3.c index 8ffc296..e762ebd 100644 --- a/bluesky/store-s3.c +++ b/bluesky/store-s3.c @@ -34,10 +34,16 @@ struct get_info { }; struct put_info { + int success; BlueSkyRCStr *val; gint offset; }; +struct list_info { + int success; + char *last_entry; +}; + static S3Status s3store_get_handler(int bufferSize, const char *buffer, void *callbackData) { @@ -99,22 +105,15 @@ static void s3store_task(gpointer a, gpointer s) &handler, &info); 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.val = async->data; info.offset = 0; struct S3PutObjectHandler handler; @@ -123,11 +122,9 @@ 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; } @@ -135,6 +132,42 @@ static void s3store_task(gpointer a, gpointer s) 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); + } + return S3StatusOK; +} + +static char *s3store_lookup_last(gpointer s, const char *prefix) +{ + S3Store *store = (S3Store *)s; + struct list_info info = {0, NULL}; + + struct S3ListBucketHandler handler; + handler.responseHandler.propertiesCallback + = s3store_properties_callback; + handler.responseHandler.completeCallback = s3store_response_callback; + handler.listBucketCallback = s3store_list_handler; + + char *marker = NULL; + + S3_list_bucket(&store->bucket, prefix, marker, NULL, 1024, NULL, &handler, &info); + + g_print("Last key: %s\n", info.last_entry); + + return S3StatusOK; +} + static gpointer s3store_new(const gchar *path) { S3Store *store = g_new(S3Store, 1); @@ -201,6 +234,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)