1 /* Blue Sky: File Systems in the Cloud
3 * Copyright (C) 2009 The Regents of the University of California
4 * Written by Michael Vrable <mvrable@cs.ucsd.edu>
17 /* Interface to Amazon S3 storage. */
19 /* Simple in-memory data store for test purposes. */
21 S3BucketContext bucket;
24 S3Store *s3store_new()
26 S3Store *store = g_new(S3Store, 1);
27 store->bucket.bucketName = "mvrable-bluesky";
28 store->bucket.protocol = S3ProtocolHTTP;
29 store->bucket.uriStyle = S3UriStylePath;
30 store->bucket.accessKeyId = getenv("AWS_ACCESS_KEY_ID");
31 store->bucket.secretAccessKey = getenv("AWS_SECRET_ACCESS_KEY");
33 g_print("Initializing S3 with bucket %s, access key %s\n",
34 store->bucket.bucketName, store->bucket.accessKeyId);
39 BlueSkyRCStr *s3store_get(S3Store *store, const gchar *key)
49 static int s3store_put_handler(int bufferSize, char *buffer,
52 struct put_info *info = (struct put_info *)callbackData;
53 gint bytes = MIN(bufferSize, (int)(info->val->len - info->offset));
54 memcpy(buffer, (char *)info->val->data + info->offset, bytes);
55 info->offset += bytes;
59 static S3Status s3store_properties_callback(const S3ResponseProperties *properties,
62 g_print("(Properties callback)\n");
66 void s3store_response_callback(S3Status status,
67 const S3ErrorDetails *errorDetails,
70 g_print("S3 operation complete, status=%s\n",
71 S3_get_status_name(status));
72 if (errorDetails != NULL) {
73 g_print(" Error message: %s\n", errorDetails->message);
77 void s3store_put(S3Store *store, const gchar *key, BlueSkyRCStr *val)
83 struct S3PutObjectHandler handler;
84 handler.responseHandler.propertiesCallback = s3store_properties_callback;
85 handler.responseHandler.completeCallback = s3store_response_callback;
86 handler.putObjectDataCallback = s3store_put_handler;
88 g_print("Starting store of %s to S3...\n", key);
89 S3_put_object(&store->bucket, key, val->len, NULL, NULL,