+++ /dev/null
-/* Blue Sky: File Systems in the Cloud
- *
- * Copyright (C) 2009 The Regents of the University of California
- * Written by Michael Vrable <mvrable@cs.ucsd.edu>
- *
- * TODO: Licensing
- */
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <glib.h>
-#include <string.h>
-
-#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;
-}
-
-struct get_info {
- gchar *buf;
- gint offset;
-};
-
-static S3Status s3store_get_handler(int bufferSize, const char *buffer,
- void *callbackData)
-{
- struct get_info *info = (struct get_info *)callbackData;
- gint bytes = MIN(bufferSize, (int)(BLUESKY_BLOCK_SIZE - info->offset));
- memcpy(info->buf + info->offset, buffer, bytes);
- info->offset += bytes;
- return S3StatusOK;
-}
-
-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);
- }
-}
-
-BlueSkyRCStr *s3store_get(S3Store *store, const gchar *key)
-{
- struct get_info info;
- info.buf = (char *)g_malloc0(BLUESKY_BLOCK_SIZE);
- info.offset = 0;
-
- struct S3GetObjectHandler handler;
- handler.responseHandler.propertiesCallback = s3store_properties_callback;
- handler.responseHandler.completeCallback = s3store_response_callback;
- handler.getObjectDataCallback = s3store_get_handler;
-
- g_print("Starting fetch of %s from S3...\n", key);
- S3_get_object(&store->bucket, key, NULL, 0, 0, NULL,
- &handler, &info);
-
- return bluesky_string_new(info.buf, BLUESKY_BLOCK_SIZE);
-}
-
-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);
-}