From: Michael Vrable Date: Wed, 18 Nov 2009 01:16:26 +0000 (-0800) Subject: Fix the S3Store get operation to handle arbitrarily-sized objects. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=e53d372f2e2d81a4a0958425bd7cb41e3e6f4a57;p=bluesky.git Fix the S3Store get operation to handle arbitrarily-sized objects. --- diff --git a/bluesky/bluesky.h b/bluesky/bluesky.h index 9808434..73c2157 100644 --- a/bluesky/bluesky.h +++ b/bluesky/bluesky.h @@ -38,6 +38,7 @@ typedef struct { } BlueSkyRCStr; BlueSkyRCStr *bluesky_string_new(gpointer data, gsize len); +BlueSkyRCStr *bluesky_string_new_from_string(GString *s); void bluesky_string_ref(BlueSkyRCStr *string); void bluesky_string_unref(BlueSkyRCStr *string); BlueSkyRCStr *bluesky_string_dup(BlueSkyRCStr *string); diff --git a/bluesky/s3store.c b/bluesky/s3store.c index 2ac2c3a..083023e 100644 --- a/bluesky/s3store.c +++ b/bluesky/s3store.c @@ -61,17 +61,14 @@ static void s3store_destroy(gpointer store) } struct get_info { - gchar *buf; - gint offset; + GString *buf; }; 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; + g_string_append_len(info->buf, buffer, bufferSize); return S3StatusOK; } @@ -113,8 +110,7 @@ static BlueSkyRCStr *s3store_get(gpointer s, const gchar *key) S3Store *store = (S3Store *)s; struct get_info info; - info.buf = (char *)g_malloc0(BLUESKY_BLOCK_SIZE); - info.offset = 0; + info.buf = g_string_new(""); struct S3GetObjectHandler handler; handler.responseHandler.propertiesCallback = s3store_properties_callback; @@ -126,7 +122,7 @@ static BlueSkyRCStr *s3store_get(gpointer s, const gchar *key) &handler, &info); BlueSkyRCStr *raw, *decrypted; - raw = bluesky_string_new(info.buf, BLUESKY_BLOCK_SIZE); + raw = bluesky_string_new_from_string(info.buf); decrypted = bluesky_crypt_decrypt(raw, store->encryption_key); bluesky_string_unref(raw); return decrypted; diff --git a/bluesky/util.c b/bluesky/util.c index 1f21bbf..54c3c36 100644 --- a/bluesky/util.c +++ b/bluesky/util.c @@ -51,6 +51,13 @@ BlueSkyRCStr *bluesky_string_new(gpointer data, gsize len) return string; } +/* Create a new BlueSkyRCStr from a GString. The GString is destroyed. */ +BlueSkyRCStr *bluesky_string_new_from_string(GString *s) +{ + gsize len = s->len; + return bluesky_string_new(g_string_free(s, FALSE), len); +} + void bluesky_string_ref(BlueSkyRCStr *string) { if (string == NULL)