} 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);
}
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;
}
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;
&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;
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)