Attempt at building with CMake.
[bluesky.git] / s3store.cc
index aff9080..ac748d1 100644 (file)
@@ -36,9 +36,19 @@ S3Store *s3store_new()
     return store;
 }
 
-BlueSkyRCStr *s3store_get(S3Store *store, const gchar *key)
+struct get_info {
+    gchar *buf;
+    gint offset;
+};
+
+static S3Status s3store_get_handler(int bufferSize, const char *buffer,
+                                    void *callbackData)
 {
-    return NULL;
+    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 {
@@ -74,6 +84,24 @@ void s3store_response_callback(S3Status status,
     }
 }
 
+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;