X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=s3store.cc;fp=s3store.cc;h=aff9080d3d22cdbc6040db50613e7f3060868ba6;hb=3ebe1efb5570c4a678774ebdf33b36be6dc49bbc;hp=0000000000000000000000000000000000000000;hpb=386250b1e7b69e1050b8eb96402ea764dbc77b25;p=bluesky.git diff --git a/s3store.cc b/s3store.cc new file mode 100644 index 0000000..aff9080 --- /dev/null +++ b/s3store.cc @@ -0,0 +1,91 @@ +/* Blue Sky: File Systems in the Cloud + * + * Copyright (C) 2009 The Regents of the University of California + * Written by Michael Vrable + * + * TODO: Licensing + */ + +#include +#include +#include +#include + +#include "bluesky.h" +#include "libs3.h" + +/* Interface to Amazon S3 storage. */ + +/* Simple in-memory data store for test purposes. */ +struct S3Store { + S3BucketContext bucket; +}; + +S3Store *s3store_new() +{ + S3Store *store = g_new(S3Store, 1); + store->bucket.bucketName = "mvrable-bluesky"; + store->bucket.protocol = S3ProtocolHTTP; + store->bucket.uriStyle = S3UriStylePath; + store->bucket.accessKeyId = getenv("AWS_ACCESS_KEY_ID"); + store->bucket.secretAccessKey = getenv("AWS_SECRET_ACCESS_KEY"); + + g_print("Initializing S3 with bucket %s, access key %s\n", + store->bucket.bucketName, store->bucket.accessKeyId); + + return store; +} + +BlueSkyRCStr *s3store_get(S3Store *store, const gchar *key) +{ + return NULL; +} + +struct put_info { + BlueSkyRCStr *val; + gint offset; +}; + +static int s3store_put_handler(int bufferSize, char *buffer, + void *callbackData) +{ + struct put_info *info = (struct put_info *)callbackData; + gint bytes = MIN(bufferSize, (int)(info->val->len - info->offset)); + memcpy(buffer, (char *)info->val->data + info->offset, bytes); + info->offset += bytes; + return bytes; +} + +static S3Status s3store_properties_callback(const S3ResponseProperties *properties, + void *callbackData) +{ + g_print("(Properties callback)\n"); + return S3StatusOK; +} + +void s3store_response_callback(S3Status status, + const S3ErrorDetails *errorDetails, + void *callbackData) +{ + g_print("S3 operation complete, status=%s\n", + S3_get_status_name(status)); + if (errorDetails != NULL) { + g_print(" Error message: %s\n", errorDetails->message); + } +} + +void s3store_put(S3Store *store, const gchar *key, BlueSkyRCStr *val) +{ + struct put_info info; + info.val = val; + info.offset = 0; + + struct S3PutObjectHandler handler; + handler.responseHandler.propertiesCallback = s3store_properties_callback; + handler.responseHandler.completeCallback = s3store_response_callback; + handler.putObjectDataCallback = s3store_put_handler; + + g_print("Starting store of %s to S3...\n", key); + S3_put_object(&store->bucket, key, val->len, NULL, NULL, + &handler, &info); +}