summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Griffis <pgriffis@igalia.com>2020-08-31 17:24:21 -0500
committerPatrick Griffis <pgriffis@igalia.com>2020-08-31 17:34:22 -0500
commitb57fee6c73f319df381c8483a9083beda22fcf3d (patch)
tree1c071432025dbbba4e71f1623b72ce85b1ecaf20
parent31343377f1944d3dc2d994e25d7663504325841e (diff)
downloadlibsoup-wip/remove-deprecations.tar.gz
Replace SoupBuffer with GByteswip/remove-deprecations
-rw-r--r--docs/reference/libsoup-2.4-sections.txt14
-rw-r--r--examples/simple-httpd.c12
-rw-r--r--examples/simple-proxy.c12
-rw-r--r--libsoup/Soup-2.4.metadata4
-rw-r--r--libsoup/cache/soup-cache-input-stream.c28
-rw-r--r--libsoup/content-sniffer/soup-content-sniffer-stream.c6
-rw-r--r--libsoup/content-sniffer/soup-content-sniffer.c44
-rw-r--r--libsoup/content-sniffer/soup-content-sniffer.h4
-rw-r--r--libsoup/soup-directory-input-stream.c42
-rw-r--r--libsoup/soup-directory-input-stream.h2
-rw-r--r--libsoup/soup-form.c12
-rw-r--r--libsoup/soup-form.h2
-rw-r--r--libsoup/soup-logger.c4
-rw-r--r--libsoup/soup-message-body.c438
-rw-r--r--libsoup/soup-message-body.h53
-rw-r--r--libsoup/soup-message-io.c52
-rw-r--r--libsoup/soup-message-server-io.c30
-rw-r--r--libsoup/soup-message.c30
-rw-r--r--libsoup/soup-message.h6
-rw-r--r--libsoup/soup-multipart.c57
-rw-r--r--libsoup/soup-multipart.h6
-rw-r--r--libsoup/soup-server.c2
-rw-r--r--tests/chunk-io-test.c47
-rw-r--r--tests/chunk-test.c64
-rw-r--r--tests/coding-test.c29
-rw-r--r--tests/forms-test.c14
-rw-r--r--tests/header-parsing-test.c10
-rw-r--r--tests/pull-api-test.c52
-rw-r--r--tests/range-test.c38
-rw-r--r--tests/resource-test.c7
-rw-r--r--tests/server-test.c12
-rw-r--r--tests/sniffing-test.c40
-rw-r--r--tests/streaming-test.c19
-rw-r--r--tests/test-utils.c18
-rw-r--r--tests/test-utils.h4
35 files changed, 408 insertions, 806 deletions
diff --git a/docs/reference/libsoup-2.4-sections.txt b/docs/reference/libsoup-2.4-sections.txt
index b258c9ae..5a608fd3 100644
--- a/docs/reference/libsoup-2.4-sections.txt
+++ b/docs/reference/libsoup-2.4-sections.txt
@@ -164,17 +164,7 @@ soup_message_headers_get_type
<SECTION>
<FILE>soup-message-body</FILE>
<TITLE>SoupMessageBody</TITLE>
-SoupBuffer
SoupMemoryUse
-soup_buffer_new
-soup_buffer_new_subbuffer
-soup_buffer_new_with_owner
-soup_buffer_new_take
-soup_buffer_get_owner
-soup_buffer_get_data
-soup_buffer_copy
-soup_buffer_free
-soup_buffer_get_as_bytes
<SUBSECTION>
SoupMessageBody
soup_message_body_new
@@ -184,7 +174,7 @@ soup_message_body_set_accumulate
soup_message_body_get_accumulate
<SUBSECTION>
soup_message_body_append
-soup_message_body_append_buffer
+soup_message_body_append_bytes
soup_message_body_append_take
soup_message_body_truncate
soup_message_body_complete
@@ -194,8 +184,6 @@ soup_message_body_get_chunk
soup_message_body_got_chunk
soup_message_body_wrote_chunk
<SUBSECTION Standard>
-SOUP_TYPE_BUFFER
-soup_buffer_get_type
SOUP_TYPE_MESSAGE_BODY
soup_message_body_get_type
</SECTION>
diff --git a/examples/simple-httpd.c b/examples/simple-httpd.c
index ab755b96..9d280ac3 100644
--- a/examples/simple-httpd.c
+++ b/examples/simple-httpd.c
@@ -119,7 +119,7 @@ do_get (SoupServer *server, SoupMessage *msg, const char *path)
if (msg->method == SOUP_METHOD_GET) {
GMappedFile *mapping;
- SoupBuffer *buffer;
+ GBytes *buffer;
mapping = g_mapped_file_new (path, FALSE, NULL);
if (!mapping) {
@@ -127,11 +127,11 @@ do_get (SoupServer *server, SoupMessage *msg, const char *path)
return;
}
- buffer = soup_buffer_new_with_owner (g_mapped_file_get_contents (mapping),
- g_mapped_file_get_length (mapping),
- mapping, (GDestroyNotify)g_mapped_file_unref);
- soup_message_body_append_buffer (msg->response_body, buffer);
- soup_buffer_free (buffer);
+ buffer = g_bytes_new_with_free_func (g_mapped_file_get_contents (mapping),
+ g_mapped_file_get_length (mapping),
+ (GDestroyNotify)g_mapped_file_unref, g_steal_pointer (&mapping));
+ soup_message_body_append_bytes (msg->response_body, buffer);
+ g_bytes_unref (buffer);
} else /* msg->method == SOUP_METHOD_HEAD */ {
char *length;
diff --git a/examples/simple-proxy.c b/examples/simple-proxy.c
index e585490a..b1f2abde 100644
--- a/examples/simple-proxy.c
+++ b/examples/simple-proxy.c
@@ -248,12 +248,12 @@ send_headers (SoupMessage *from, SoupMessage *to)
}
static void
-send_chunk (SoupMessage *from, SoupBuffer *chunk, SoupMessage *to)
+send_chunk (SoupMessage *from, GBytes *chunk, SoupMessage *to)
{
g_print ("[%p] writing chunk of %lu bytes\n", to,
- (unsigned long)chunk->length);
+ (unsigned long)g_bytes_get_size (chunk));
- soup_message_body_append_buffer (to->response_body, chunk);
+ soup_message_body_append_bytes (to->response_body, chunk);
soup_server_unpause_message (server, to);
}
@@ -300,9 +300,9 @@ server_callback (SoupServer *server, SoupMessage *msg,
soup_message_headers_remove (msg2->request_headers, "Connection");
if (msg->request_body->length) {
- SoupBuffer *request = soup_message_body_flatten (msg->request_body);
- soup_message_body_append_buffer (msg2->request_body, request);
- soup_buffer_free (request);
+ GBytes *request = soup_message_body_flatten (msg->request_body);
+ soup_message_body_append_bytes (msg2->request_body, request);
+ g_bytes_unref (request);
}
soup_message_headers_set_encoding (msg->response_headers,
SOUP_ENCODING_CHUNKED);
diff --git a/libsoup/Soup-2.4.metadata b/libsoup/Soup-2.4.metadata
index 3fd48166..da138e39 100644
--- a/libsoup/Soup-2.4.metadata
+++ b/libsoup/Soup-2.4.metadata
@@ -15,7 +15,6 @@ AuthDomain
.accepts#method name="accepts_authorization"
AuthDomainBasic.new skip=false
AuthDomainDigest.new skip=false
-Buffer.new_subbuffer skip
ContentSniffer.sniff.params nullable
form_* skip=false
Message
@@ -35,14 +34,11 @@ URI
// uri_host_*.* type="Soup.URI"
// Not enough GIR information
-Buffer.data type="uint8[]" array_length_field="length"
MessageBody.data type="uint8[]" array_length_field="length"
Date
.new_from_time_t.when type="time_t"
.to_time_t type="time_t"
// Simplify memory management
-Buffer
- .new deprecated_since="2.32" replacement="Buffer.take"
MessageBody
.append deprecated_since="2.32" replacement="MessageBody.append_take"
diff --git a/libsoup/cache/soup-cache-input-stream.c b/libsoup/cache/soup-cache-input-stream.c
index e93b43fd..649d23fc 100644
--- a/libsoup/cache/soup-cache-input-stream.c
+++ b/libsoup/cache/soup-cache-input-stream.c
@@ -35,7 +35,7 @@ struct _SoupCacheInputStreamPrivate
gsize bytes_written;
gboolean read_finished;
- SoupBuffer *current_writing_buffer;
+ GBytes *current_writing_buffer;
GQueue *buffer_queue;
};
@@ -148,8 +148,8 @@ soup_cache_input_stream_finalize (GObject *object)
g_clear_object (&priv->cancellable);
g_clear_object (&priv->output_stream);
- g_clear_pointer (&priv->current_writing_buffer, soup_buffer_free);
- g_queue_free_full (priv->buffer_queue, (GDestroyNotify) soup_buffer_free);
+ g_clear_pointer (&priv->current_writing_buffer, g_bytes_unref);
+ g_queue_free_full (priv->buffer_queue, (GDestroyNotify) g_bytes_unref);
G_OBJECT_CLASS (soup_cache_input_stream_parent_class)->finalize (object);
}
@@ -171,15 +171,15 @@ write_ready_cb (GObject *source, GAsyncResult *result, SoupCacheInputStream *ist
}
/* Check that we have written everything */
- pending = priv->current_writing_buffer->length - write_size;
+ pending = g_bytes_get_size (priv->current_writing_buffer) - write_size;
if (pending) {
- SoupBuffer *subbuffer = soup_buffer_new_subbuffer (priv->current_writing_buffer,
- write_size, pending);
- g_queue_push_head (priv->buffer_queue, subbuffer);
+ GBytes *subbuffer = g_bytes_new_from_bytes (priv->current_writing_buffer,
+ write_size, pending);
+ g_queue_push_head (priv->buffer_queue, g_steal_pointer (&subbuffer));
}
priv->bytes_written += write_size;
- g_clear_pointer (&priv->current_writing_buffer, soup_buffer_free);
+ g_clear_pointer (&priv->current_writing_buffer, g_bytes_unref);
try_write_next_buffer (istream);
g_object_unref (istream);
@@ -189,12 +189,12 @@ static void
soup_cache_input_stream_write_next_buffer (SoupCacheInputStream *istream)
{
SoupCacheInputStreamPrivate *priv = istream->priv;
- SoupBuffer *buffer = g_queue_pop_head (priv->buffer_queue);
+ GBytes *buffer = g_queue_pop_head (priv->buffer_queue);
int priority;
g_assert (priv->output_stream && !g_output_stream_is_closed (priv->output_stream));
- g_clear_pointer (&priv->current_writing_buffer, soup_buffer_free);
+ g_clear_pointer (&priv->current_writing_buffer, g_bytes_unref);
priv->current_writing_buffer = buffer;
if (priv->buffer_queue->length > 10)
@@ -202,7 +202,9 @@ soup_cache_input_stream_write_next_buffer (SoupCacheInputStream *istream)
else
priority = G_PRIORITY_LOW;
- g_output_stream_write_async (priv->output_stream, buffer->data, buffer->length,
+ g_output_stream_write_async (priv->output_stream,
+ g_bytes_get_data (buffer, NULL),
+ g_bytes_get_size (buffer),
priority, priv->cancellable,
(GAsyncReadyCallback) write_ready_cb,
g_object_ref (istream));
@@ -234,8 +236,8 @@ read_internal (GInputStream *stream,
if (priv->current_writing_buffer == NULL && priv->output_stream)
notify_and_clear (istream, NULL);
} else {
- SoupBuffer *soup_buffer = soup_buffer_new (SOUP_MEMORY_COPY, buffer, nread);
- g_queue_push_tail (priv->buffer_queue, soup_buffer);
+ GBytes *local_buffer = g_bytes_new (buffer, nread);
+ g_queue_push_tail (priv->buffer_queue, g_steal_pointer (&local_buffer));
if (priv->current_writing_buffer == NULL && priv->output_stream)
soup_cache_input_stream_write_next_buffer (istream);
diff --git a/libsoup/content-sniffer/soup-content-sniffer-stream.c b/libsoup/content-sniffer/soup-content-sniffer-stream.c
index 4b026e01..465648e5 100644
--- a/libsoup/content-sniffer/soup-content-sniffer-stream.c
+++ b/libsoup/content-sniffer/soup-content-sniffer-stream.c
@@ -112,7 +112,7 @@ read_and_sniff (GInputStream *stream, gboolean blocking,
SoupContentSnifferStreamPrivate *priv = soup_content_sniffer_stream_get_instance_private (sniffer);
gssize nread;
GError *my_error = NULL;
- SoupBuffer *buf;
+ GBytes *buf;
do {
nread = g_pollable_stream_read (G_FILTER_INPUT_STREAM (stream)->base_stream,
@@ -140,11 +140,11 @@ read_and_sniff (GInputStream *stream, gboolean blocking,
}
/* Sniff, then return the data */
- buf = soup_buffer_new (SOUP_MEMORY_TEMPORARY, priv->buffer, priv->buffer_nread);
+ buf = g_bytes_new (priv->buffer, priv->buffer_nread);
priv->sniffed_type =
soup_content_sniffer_sniff (priv->sniffer, priv->msg, buf,
&priv->sniffed_params);
- soup_buffer_free (buf);
+ g_bytes_unref (buf);
priv->sniffing = FALSE;
return priv->buffer_nread;
diff --git a/libsoup/content-sniffer/soup-content-sniffer.c b/libsoup/content-sniffer/soup-content-sniffer.c
index 14ff38ae..f5653417 100644
--- a/libsoup/content-sniffer/soup-content-sniffer.c
+++ b/libsoup/content-sniffer/soup-content-sniffer.c
@@ -86,12 +86,14 @@ typedef struct {
static char*
sniff_media (SoupContentSniffer *sniffer,
- SoupBuffer *buffer,
+ GBytes *buffer,
SoupContentSnifferMediaPattern table[],
int table_length)
{
- const guchar *resource = (const guchar *)buffer->data;
- guint resource_length = MIN (512, buffer->length);
+
+ gsize resource_length;
+ const guchar *resource = g_bytes_get_data (buffer, &resource_length);
+ resource_length = MIN (512, resource_length);
int i;
for (i = 0; i < table_length; i++) {
@@ -168,7 +170,7 @@ static SoupContentSnifferMediaPattern image_types_table[] = {
};
static char*
-sniff_images (SoupContentSniffer *sniffer, SoupBuffer *buffer)
+sniff_images (SoupContentSniffer *sniffer, GBytes *buffer)
{
return sniff_media (sniffer,
buffer,
@@ -223,10 +225,11 @@ static SoupContentSnifferMediaPattern audio_video_types_table[] = {
};
static gboolean
-sniff_mp4 (SoupContentSniffer *sniffer, SoupBuffer *buffer)
+sniff_mp4 (SoupContentSniffer *sniffer, GBytes *buffer)
{
- const char *resource = (const char *)buffer->data;
- guint resource_length = MIN (512, buffer->length);
+ gsize resource_length;
+ const char *resource = g_bytes_get_data (buffer, &resource_length);
+ resource_length = MIN (512, resource_length);
guint32 box_size = *((guint32*)resource);
guint i;
@@ -255,7 +258,7 @@ sniff_mp4 (SoupContentSniffer *sniffer, SoupBuffer *buffer)
}
static char*
-sniff_audio_video (SoupContentSniffer *sniffer, SoupBuffer *buffer)
+sniff_audio_video (SoupContentSniffer *sniffer, GBytes *buffer)
{
char *sniffed_type;
@@ -485,12 +488,13 @@ static char byte_looks_binary[] = {
/* HTML5: 2.7.4 Content-Type sniffing: unknown type */
static char*
-sniff_unknown (SoupContentSniffer *sniffer, SoupBuffer *buffer,
+sniff_unknown (SoupContentSniffer *sniffer, GBytes *buffer,
gboolean sniff_scriptable)
{
char *sniffed_type = NULL;
- const guchar *resource = (const guchar *)buffer->data;
- guint resource_length = MIN (512, buffer->length);
+ gsize resource_length;
+ const guchar *resource = g_bytes_get_data (buffer, &resource_length);
+ resource_length = MIN (512, resource_length);
guint i;
for (i = 0; i < G_N_ELEMENTS (types_table); i++) {
@@ -574,10 +578,11 @@ sniff_unknown (SoupContentSniffer *sniffer, SoupBuffer *buffer,
/* MIMESNIFF: 7.2 Sniffing a mislabeled binary resource */
static char*
-sniff_text_or_binary (SoupContentSniffer *sniffer, SoupBuffer *buffer)
+sniff_text_or_binary (SoupContentSniffer *sniffer, GBytes *buffer)
{
- const guchar *resource = (const guchar *)buffer->data;
- int resource_length = MIN (512, buffer->length);
+ gsize resource_length;
+ const guchar *resource = g_bytes_get_data (buffer, &resource_length);
+ resource_length = MIN (512, resource_length);
gboolean looks_binary = FALSE;
int i;
@@ -628,10 +633,11 @@ skip_insignificant_space (const char *resource, int *pos, int resource_length)
}
static char*
-sniff_feed_or_html (SoupContentSniffer *sniffer, SoupBuffer *buffer)
+sniff_feed_or_html (SoupContentSniffer *sniffer, GBytes *buffer)
{
- const char *resource = (const char *)buffer->data;
- int resource_length = MIN (512, buffer->length);
+ gsize resource_length;
+ const char *resource = g_bytes_get_data (buffer, &resource_length);
+ resource_length = MIN (512, resource_length);
int pos = 0;
if (resource_length < 3)
@@ -762,7 +768,7 @@ sniff_feed_or_html (SoupContentSniffer *sniffer, SoupBuffer *buffer)
static char *
soup_content_sniffer_real_sniff (SoupContentSniffer *sniffer, SoupMessage *msg,
- SoupBuffer *buffer, GHashTable **params)
+ GBytes *buffer, GHashTable **params)
{
const char *content_type;
const char *x_content_type_options;
@@ -915,7 +921,7 @@ soup_content_sniffer_new (void)
*/
char *
soup_content_sniffer_sniff (SoupContentSniffer *sniffer,
- SoupMessage *msg, SoupBuffer *buffer,
+ SoupMessage *msg, GBytes *buffer,
GHashTable **params)
{
g_return_val_if_fail (SOUP_IS_CONTENT_SNIFFER (sniffer), NULL);
diff --git a/libsoup/content-sniffer/soup-content-sniffer.h b/libsoup/content-sniffer/soup-content-sniffer.h
index cc9aa2b9..6931b6e4 100644
--- a/libsoup/content-sniffer/soup-content-sniffer.h
+++ b/libsoup/content-sniffer/soup-content-sniffer.h
@@ -19,7 +19,7 @@ struct _SoupContentSnifferClass {
char* (*sniff) (SoupContentSniffer *sniffer,
SoupMessage *msg,
- SoupBuffer *buffer,
+ GBytes *buffer,
GHashTable **params);
gsize (*get_buffer_size) (SoupContentSniffer *sniffer);
@@ -32,7 +32,7 @@ SoupContentSniffer *soup_content_sniffer_new (void);
SOUP_AVAILABLE_IN_2_28
char *soup_content_sniffer_sniff (SoupContentSniffer *sniffer,
SoupMessage *msg,
- SoupBuffer *buffer,
+ GBytes *buffer,
GHashTable **params);
SOUP_AVAILABLE_IN_2_28
gsize soup_content_sniffer_get_buffer_size (SoupContentSniffer *sniffer);
diff --git a/libsoup/soup-directory-input-stream.c b/libsoup/soup-directory-input-stream.c
index 572f167e..5c24883f 100644
--- a/libsoup/soup-directory-input-stream.c
+++ b/libsoup/soup-directory-input-stream.c
@@ -35,11 +35,10 @@
G_DEFINE_TYPE (SoupDirectoryInputStream, soup_directory_input_stream, G_TYPE_INPUT_STREAM)
-static SoupBuffer *
+static GBytes *
soup_directory_input_stream_parse_info (SoupDirectoryInputStream *stream,
GFileInfo *info)
{
- SoupBuffer *buffer;
GString *string;
const char *file_name;
char *escaped, *path, *xml_string, *size, *date, *time, *name;
@@ -90,7 +89,6 @@ soup_directory_input_stream_parse_info (SoupDirectoryInputStream *stream,
g_string_append_printf (string, ROW_FORMAT, name, path, xml_string, raw_size, size, timestamp, time, date);
g_string_append (string, "</tr>\n");
- buffer = soup_buffer_new (SOUP_MEMORY_TAKE, string->str, string->len);
g_free (time);
g_free (date);
@@ -98,18 +96,17 @@ soup_directory_input_stream_parse_info (SoupDirectoryInputStream *stream,
g_free (size);
g_free (path);
g_free (xml_string);
- g_string_free (string, FALSE);
- return buffer;
+ return g_string_free_to_bytes (string);
}
-static SoupBuffer *
+static GBytes *
soup_directory_input_stream_read_next_file (SoupDirectoryInputStream *stream,
GCancellable *cancellable,
GError **error)
{
GFileInfo *info;
- SoupBuffer *buffer;
+ GBytes *buffer;
GError *err = NULL;
do {
@@ -120,9 +117,7 @@ soup_directory_input_stream_read_next_file (SoupDirectoryInputStream *stream,
return NULL;
} else if (!stream->done) {
stream->done = TRUE;
- return soup_buffer_new (SOUP_MEMORY_STATIC,
- EXIT_STRING,
- sizeof (EXIT_STRING));
+ return g_bytes_new_static (EXIT_STRING, sizeof (EXIT_STRING));
} else {
return NULL;
}
@@ -156,16 +151,16 @@ soup_directory_input_stream_read (GInputStream *input,
}
}
- size = MIN (stream->buffer->length, count - total);
- memcpy ((char *)buffer + total, stream->buffer->data, size);
- if (size == stream->buffer->length) {
- soup_buffer_free (stream->buffer);
- stream->buffer = NULL;
+ gsize buffer_len = g_bytes_get_size (stream->buffer);
+ size = MIN (buffer_len, count - total);
+ memcpy ((char *)buffer + total, g_bytes_get_data (stream->buffer, NULL), size);
+ if (size == buffer_len) {
+ g_clear_pointer (&stream->buffer, g_bytes_unref);
} else {
- SoupBuffer *sub = soup_buffer_new_subbuffer (stream->buffer,
- size,
- stream->buffer->length - size);
- soup_buffer_free (stream->buffer);
+ GBytes *sub = g_bytes_new_from_bytes (stream->buffer,
+ size,
+ buffer_len - size);
+ g_bytes_unref (stream->buffer);
stream->buffer = sub;
}
}
@@ -181,10 +176,7 @@ soup_directory_input_stream_close (GInputStream *input,
SoupDirectoryInputStream *stream = SOUP_DIRECTORY_INPUT_STREAM (input);
gboolean result;
- if (stream->buffer) {
- soup_buffer_free (stream->buffer);
- stream->buffer = NULL;
- }
+ g_clear_pointer (&stream->buffer, g_bytes_unref);
result = g_file_enumerator_close (stream->enumerator,
cancellable,
@@ -244,9 +236,7 @@ soup_directory_input_stream_setup_buffer (SoupDirectoryInputStream *stream)
{
char *init = soup_directory_input_stream_create_header (stream);
- stream->buffer = soup_buffer_new (SOUP_MEMORY_TAKE,
- init,
- strlen (init));
+ stream->buffer = g_bytes_new_take (init, strlen (init));
}
GInputStream *
diff --git a/libsoup/soup-directory-input-stream.h b/libsoup/soup-directory-input-stream.h
index 4c83e355..1ffb84eb 100644
--- a/libsoup/soup-directory-input-stream.h
+++ b/libsoup/soup-directory-input-stream.h
@@ -43,7 +43,7 @@ struct _SoupDirectoryInputStream {
GFileEnumerator *enumerator;
char *uri;
- SoupBuffer *buffer;
+ GBytes *buffer;
gboolean done;
};
diff --git a/libsoup/soup-form.c b/libsoup/soup-form.c
index aa0974f2..1de391d1 100644
--- a/libsoup/soup-form.c
+++ b/libsoup/soup-form.c
@@ -133,7 +133,7 @@ soup_form_decode (const char *encoded_form)
* care about those fields. soup_form_decode_multipart() may also
* return %NULL in those fields if the client did not provide that
* information. You must free the returned filename and content-type
- * with g_free(), and the returned file data with soup_buffer_free().
+ * with g_free(), and the returned file data with g_bytes_unref().
*
* If you have a form with more than one file upload control, you will
* need to decode it manually, using soup_multipart_new_from_message()
@@ -149,12 +149,12 @@ soup_form_decode (const char *encoded_form)
GHashTable *
soup_form_decode_multipart (SoupMessage *msg, const char *file_control_name,
char **filename, char **content_type,
- SoupBuffer **file)
+ GBytes **file)
{
SoupMultipart *multipart;
GHashTable *form_data_set, *params;
SoupMessageHeaders *part_headers;
- SoupBuffer *part_body;
+ GBytes *part_body;
char *disposition, *name;
int i;
@@ -193,12 +193,12 @@ soup_form_decode_multipart (SoupMessage *msg, const char *file_control_name,
if (content_type)
*content_type = g_strdup (soup_message_headers_get_content_type (part_headers, NULL));
if (file)
- *file = soup_buffer_copy (part_body);
+ *file = g_bytes_ref (part_body);
} else {
g_hash_table_insert (form_data_set,
g_strdup (name),
- g_strndup (part_body->data,
- part_body->length));
+ g_strndup (g_bytes_get_data (part_body, NULL),
+ g_bytes_get_size (part_body)));
}
g_free (disposition);
diff --git a/libsoup/soup-form.h b/libsoup/soup-form.h
index 6774f5d8..4880e7be 100644
--- a/libsoup/soup-form.h
+++ b/libsoup/soup-form.h
@@ -21,7 +21,7 @@ GHashTable *soup_form_decode_multipart (SoupMessage *msg,
const char *file_control_name,
char **filename,
char **content_type,
- SoupBuffer **file);
+ GBytes **file);
SOUP_AVAILABLE_IN_2_4
char *soup_form_encode (const char *first_field,
diff --git a/libsoup/soup-logger.c b/libsoup/soup-logger.c
index 40d5f3e8..cf2eedde 100644
--- a/libsoup/soup-logger.c
+++ b/libsoup/soup-logger.c
@@ -602,11 +602,11 @@ print_request (SoupLogger *logger, SoupMessage *msg,
if (msg->request_body->length &&
soup_message_body_get_accumulate (msg->request_body)) {
- SoupBuffer *request;
+ GBytes *request;
request = soup_message_body_flatten (msg->request_body);
g_return_if_fail (request != NULL);
- soup_buffer_free (request);
+ g_bytes_unref (request);
if (soup_message_headers_get_expectations (msg->request_headers) != SOUP_EXPECTATION_CONTINUE) {
soup_logger_print (logger, SOUP_LOGGER_LOG_BODY, '>',
diff --git a/libsoup/soup-message-body.c b/libsoup/soup-message-body.c
index eb6d5f5a..82c6b887 100644
--- a/libsoup/soup-message-body.c
+++ b/libsoup/soup-message-body.c
@@ -21,12 +21,6 @@
*
* #SoupMessageBody represents the request or response body of a
* #SoupMessage.
- *
- * In addition to #SoupMessageBody, libsoup also defines a "smaller"
- * data buffer type, #SoupBuffer, which is primarily used as a
- * component of #SoupMessageBody. In particular, when using chunked
- * encoding to transmit or receive a message, each chunk is
- * represented as a #SoupBuffer.
**/
/**
@@ -34,311 +28,12 @@
* @SOUP_MEMORY_STATIC: The memory is statically allocated and
* constant; libsoup can use the passed-in buffer directly and not
* need to worry about it being modified or freed.
- * @SOUP_MEMORY_TAKE: The caller has allocated the memory for the
- * #SoupBuffer's use; libsoup will assume ownership of it and free it
- * (with g_free()) when it is done with it.
- * @SOUP_MEMORY_COPY: The passed-in data belongs to the caller; the
- * #SoupBuffer will copy it into new memory, leaving the caller free
+ * @SOUP_MEMORY_TAKE: The caller has allocated the memory and libsoup
+ * will assume ownership of it and free it with g_free().
+ * @SOUP_MEMORY_COPY: The passed-in data belongs to the caller and
+ * libsoup will copy it into new memory leaving the caller free
* to reuse the original memory.
- * @SOUP_MEMORY_TEMPORARY: The passed-in data belongs to the caller,
- * but will remain valid for the lifetime of the #SoupBuffer. The
- * difference between this and @SOUP_MEMORY_STATIC is that if you copy
- * a @SOUP_MEMORY_TEMPORARY buffer, it will make a copy of the memory
- * as well, rather than reusing the original memory.
- *
- * Describes how #SoupBuffer should use the data passed in by the
- * caller.
- *
- * See also soup_buffer_new_with_owner(), which allows to you create a
- * buffer containing data which is owned by another object.
- **/
-
-/* Internal SoupMemoryUse values */
-enum {
- SOUP_MEMORY_SUBBUFFER = SOUP_MEMORY_TEMPORARY + 1,
- SOUP_MEMORY_OWNED
-};
-
-/**
- * SoupBuffer:
- * @data: (type gpointer): the data
- * @length: length of @data
- *
- * A data buffer, generally used to represent a chunk of a
- * #SoupMessageBody.
- *
- * @data is a #char because that's generally convenient; in some
- * situations you may need to cast it to #guchar or another type.
- **/
-
-typedef struct {
- SoupBuffer buffer;
- SoupMemoryUse use;
- guint refcount;
-
- gpointer owner;
- GDestroyNotify owner_dnotify;
-} SoupBufferPrivate;
-
-/**
- * soup_buffer_new:
- * @use: how @data is to be used by the buffer
- * @data: (array length=length) (element-type guint8): data
- * @length: length of @data
- *
- * Creates a new #SoupBuffer containing @length bytes from @data.
- *
- * Return value: the new #SoupBuffer.
- **/
-SoupBuffer *
-soup_buffer_new (SoupMemoryUse use, gconstpointer data, gsize length)
-{
- SoupBufferPrivate *priv = g_slice_new0 (SoupBufferPrivate);
-
- if (use == SOUP_MEMORY_COPY) {
- data = g_memdup (data, length);
- use = SOUP_MEMORY_TAKE;
- }
-
- priv->buffer.data = data;
- priv->buffer.length = length;
- priv->use = use;
- priv->refcount = 1;
-
- if (use == SOUP_MEMORY_TAKE) {
- priv->owner = (gpointer)data;
- priv->owner_dnotify = g_free;
- }
-
- return (SoupBuffer *)priv;
-}
-
-/**
- * soup_buffer_new_take: (rename-to soup_buffer_new)
- * @data: (array length=length) (transfer full): data
- * @length: length of @data
- *
- * Creates a new #SoupBuffer containing @length bytes from @data.
- *
- * This function is exactly equivalent to soup_buffer_new() with
- * %SOUP_MEMORY_TAKE as first argument; it exists mainly for
- * convenience and simplifying language bindings.
- *
- * Return value: the new #SoupBuffer.
- *
- * Since: 2.32
- **/
-SoupBuffer *
-soup_buffer_new_take (guchar *data, gsize length)
-{
- return soup_buffer_new (SOUP_MEMORY_TAKE, data, length);
-}
-
-/**
- * soup_buffer_new_subbuffer:
- * @parent: the parent #SoupBuffer
- * @offset: offset within @parent to start at
- * @length: number of bytes to copy from @parent
- *
- * Creates a new #SoupBuffer containing @length bytes "copied" from
- * @parent starting at @offset. (Normally this will not actually copy
- * any data, but will instead simply reference the same data as
- * @parent does.)
- *
- * Return value: the new #SoupBuffer.
- **/
-SoupBuffer *
-soup_buffer_new_subbuffer (SoupBuffer *parent, gsize offset, gsize length)
-{
- SoupBufferPrivate *priv;
-
- /* Normally this is just a ref, but if @parent is TEMPORARY,
- * it will do an actual copy.
- */
- parent = soup_buffer_copy (parent);
-
- priv = g_slice_new0 (SoupBufferPrivate);
- priv->buffer.data = parent->data + offset;
- priv->buffer.length = length;
- priv->use = SOUP_MEMORY_SUBBUFFER;
- priv->owner = parent;
- priv->owner_dnotify = (GDestroyNotify)soup_buffer_free;
- priv->refcount = 1;
-
- return (SoupBuffer *)priv;
-}
-
-/**
- * soup_buffer_new_with_owner:
- * @data: (array length=length) (element-type guint8): data
- * @length: length of @data
- * @owner: pointer to an object that owns @data
- * @owner_dnotify: (allow-none): a function to free/unref @owner when
- * the buffer is freed
- *
- * Creates a new #SoupBuffer containing @length bytes from @data. When
- * the #SoupBuffer is freed, it will call @owner_dnotify, passing
- * @owner to it. You must ensure that @data will remain valid until
- * @owner_dnotify is called.
- *
- * For example, you could use this to create a buffer containing data
- * returned from libxml without needing to do an extra copy:
- *
- * <informalexample><programlisting>
- * xmlDocDumpMemory (doc, &xmlbody, &len);
- * return soup_buffer_new_with_owner (xmlbody, len, xmlbody,
- * (GDestroyNotify)xmlFree);
- * </programlisting></informalexample>
- *
- * In this example, @data and @owner are the same, but in other cases
- * they would be different (eg, @owner would be a object, and @data
- * would be a pointer to one of the object's fields).
- *
- * Return value: the new #SoupBuffer.
- **/
-SoupBuffer *
-soup_buffer_new_with_owner (gconstpointer data, gsize length,
- gpointer owner, GDestroyNotify owner_dnotify)
-{
- SoupBufferPrivate *priv = g_slice_new0 (SoupBufferPrivate);
-
- priv->buffer.data = data;
- priv->buffer.length = length;
- priv->use = SOUP_MEMORY_OWNED;
- priv->owner = owner;
- priv->owner_dnotify = owner_dnotify;
- priv->refcount = 1;
-
- return (SoupBuffer *)priv;
-}
-
-/**
- * soup_buffer_get_owner:
- * @buffer: a #SoupBuffer created with soup_buffer_new_with_owner()
- *
- * Gets the "owner" object for a buffer created with
- * soup_buffer_new_with_owner().
- *
- * Return value: (transfer none): the owner pointer
- **/
-gpointer
-soup_buffer_get_owner (SoupBuffer *buffer)
-{
- SoupBufferPrivate *priv = (SoupBufferPrivate *)buffer;
-
- g_return_val_if_fail ((int)priv->use == (int)SOUP_MEMORY_OWNED, NULL);
- return priv->owner;
-}
-
-/**
- * soup_buffer_get_data:
- * @buffer: a #SoupBuffer
- * @data: (out) (array length=length) (transfer none): the pointer
- * to the buffer data is stored here
- * @length: (out): the length of the buffer data is stored here
- *
- * This function exists for use by language bindings, because it's not
- * currently possible to get the right effect by annotating the fields
- * of #SoupBuffer.
- *
- * Since: 2.32
- */
-void
-soup_buffer_get_data (SoupBuffer *buffer,
- const guint8 **data,
- gsize *length)
-{
- *data = (const guint8 *)buffer->data;
- *length = buffer->length;
-}
-
-/**
- * soup_buffer_copy:
- * @buffer: a #SoupBuffer
- *
- * Makes a copy of @buffer. In reality, #SoupBuffer is a refcounted
- * type, and calling soup_buffer_copy() will normally just increment
- * the refcount on @buffer and return it. However, if @buffer was
- * created with #SOUP_MEMORY_TEMPORARY memory, then soup_buffer_copy()
- * will actually return a copy of it, so that the data in the copy
- * will remain valid after the temporary buffer is freed.
- *
- * Return value: the new (or newly-reffed) buffer
- **/
-SoupBuffer *
-soup_buffer_copy (SoupBuffer *buffer)
-{
- SoupBufferPrivate *priv = (SoupBufferPrivate *)buffer;
-
- /* For non-TEMPORARY buffers, this is just a ref */
- if (priv->use != SOUP_MEMORY_TEMPORARY) {
- g_atomic_int_inc (&priv->refcount);
- return buffer;
- }
-
- /* For TEMPORARY buffers, we need to do a real copy the first
- * time, and then after that, we just keep returning the copy.
- * We store the copy in priv->owner, which is technically
- * backwards, but it saves us from having to keep an extra
- * pointer in SoupBufferPrivate.
- */
-
- if (!priv->owner) {
- priv->owner = soup_buffer_new (SOUP_MEMORY_COPY,
- buffer->data,
- buffer->length);
- priv->owner_dnotify = (GDestroyNotify)soup_buffer_free;
- }
- return soup_buffer_copy (priv->owner);
-}
-
-/**
- * soup_buffer_free:
- * @buffer: a #SoupBuffer
- *
- * Frees @buffer. (In reality, as described in the documentation for
- * soup_buffer_copy(), this is actually an "unref" operation, and may
- * or may not actually free @buffer.)
**/
-void
-soup_buffer_free (SoupBuffer *buffer)
-{
- SoupBufferPrivate *priv = (SoupBufferPrivate *)buffer;
-
- if (!g_atomic_int_dec_and_test (&priv->refcount))
- return;
-
- if (priv->owner_dnotify)
- priv->owner_dnotify (priv->owner);
- g_slice_free (SoupBufferPrivate, priv);
-}
-
-/**
- * soup_buffer_get_as_bytes:
- * @buffer: a #SoupBuffer
- *
- * Creates a #GBytes pointing to the same memory as @buffer. The
- * #GBytes will hold a reference on @buffer to ensure that it is not
- * freed while the #GBytes is still valid.
- *
- * Returns: (transfer full): a new #GBytes which has the same content
- * as the #SoupBuffer.
- *
- * Since: 2.40
- */
-GBytes *
-soup_buffer_get_as_bytes (SoupBuffer *buffer)
-{
- SoupBuffer *copy;
-
- copy = soup_buffer_copy (buffer);
- return g_bytes_new_with_free_func (copy->data, copy->length,
- (GDestroyNotify)soup_buffer_free,
- copy);
-}
-
-G_DEFINE_BOXED_TYPE (SoupBuffer, soup_buffer, soup_buffer_copy, soup_buffer_free)
-
/**
* SoupMessageBody:
@@ -362,7 +57,7 @@ G_DEFINE_BOXED_TYPE (SoupBuffer, soup_buffer, soup_buffer_copy, soup_buffer_free
typedef struct {
SoupMessageBody body;
GSList *chunks, *last;
- SoupBuffer *flattened;
+ GBytes *flattened;
gboolean accumulate;
goffset base_offset;
int ref_count;
@@ -451,7 +146,7 @@ soup_message_body_get_accumulate (SoupMessageBody *body)
}
static void
-append_buffer (SoupMessageBody *body, SoupBuffer *buffer)
+append_buffer (SoupMessageBody *body, GBytes *buffer)
{
SoupMessageBodyPrivate *priv = (SoupMessageBodyPrivate *)body;
@@ -461,12 +156,9 @@ append_buffer (SoupMessageBody *body, SoupBuffer *buffer)
} else
priv->chunks = priv->last = g_slist_append (NULL, buffer);
- if (priv->flattened) {
- soup_buffer_free (priv->flattened);
- priv->flattened = NULL;
- body->data = NULL;
- }
- body->length += buffer->length;
+ g_clear_pointer (&priv->flattened, g_bytes_unref);
+ body->data = NULL;
+ body->length += g_bytes_get_size (buffer);
}
/**
@@ -482,8 +174,16 @@ void
soup_message_body_append (SoupMessageBody *body, SoupMemoryUse use,
gconstpointer data, gsize length)
{
- if (length > 0)
- append_buffer (body, soup_buffer_new (use, data, length));
+ GBytes *bytes;
+ if (length > 0) {
+ if (use == SOUP_MEMORY_TAKE)
+ bytes = g_bytes_new_take ((guchar*)data, length);
+ else if (use == SOUP_MEMORY_STATIC)
+ bytes = g_bytes_new_static (data, length);
+ else
+ bytes = g_bytes_new (data, length);
+ append_buffer (body, g_steal_pointer (&bytes));
+ }
else if (use == SOUP_MEMORY_TAKE)
g_free ((gpointer)data);
}
@@ -510,20 +210,17 @@ soup_message_body_append_take (SoupMessageBody *body,
}
/**
- * soup_message_body_append_buffer:
+ * soup_message_body_append_bytes:
* @body: a #SoupMessageBody
- * @buffer: a #SoupBuffer
+ * @buffer: a #GBytes
*
- * Appends the data from @buffer to @body. (#SoupMessageBody uses
- * #SoupBuffers internally, so this is normally a constant-time
- * operation that doesn't actually require copying the data in
- * @buffer.)
+ * Appends the data from @buffer to @body.
**/
void
-soup_message_body_append_buffer (SoupMessageBody *body, SoupBuffer *buffer)
+soup_message_body_append_bytes (SoupMessageBody *body, GBytes *buffer)
{
- g_return_if_fail (buffer->length > 0);
- append_buffer (body, soup_buffer_copy (buffer));
+ g_return_if_fail (g_bytes_get_size (buffer) > 0);
+ append_buffer (body, g_bytes_ref (buffer));
}
/**
@@ -537,15 +234,11 @@ soup_message_body_truncate (SoupMessageBody *body)
{
SoupMessageBodyPrivate *priv = (SoupMessageBodyPrivate *)body;
- g_slist_free_full (priv->chunks, (GDestroyNotify)soup_buffer_free);
+ g_slist_free_full (priv->chunks, (GDestroyNotify)g_bytes_unref);
priv->chunks = priv->last = NULL;
priv->base_offset = 0;
-
- if (priv->flattened) {
- soup_buffer_free (priv->flattened);
- priv->flattened = NULL;
- body->data = NULL;
- }
+ g_clear_pointer (&priv->flattened, g_bytes_unref);
+ body->data = NULL;
body->length = 0;
}
@@ -559,7 +252,7 @@ soup_message_body_truncate (SoupMessageBody *body)
void
soup_message_body_complete (SoupMessageBody *body)
{
- append_buffer (body, soup_buffer_new (SOUP_MEMORY_STATIC, NULL, 0));
+ append_buffer (body, g_bytes_new_static (NULL, 0));
}
/**
@@ -570,16 +263,13 @@ soup_message_body_complete (SoupMessageBody *body)
* data in @body (plus an additional '\0' byte not counted by @body's
* length field).
*
- * Return value: a #SoupBuffer containing the same data as @body.
- * (You must free this buffer if you do not want it.)
+ * Return: (transfer full): a #GBytes containing the same data as @body.
+ * (You must g_bytes_unref() this if you do not want it.)
**/
-SoupBuffer *
+GBytes *
soup_message_body_flatten (SoupMessageBody *body)
{
SoupMessageBodyPrivate *priv = (SoupMessageBodyPrivate *)body;
- char *buf, *ptr;
- GSList *iter;
- SoupBuffer *chunk;
g_return_val_if_fail (priv->accumulate == TRUE, NULL);
@@ -588,20 +278,22 @@ soup_message_body_flatten (SoupMessageBody *body)
g_return_val_if_fail (body->length < G_MAXSIZE, NULL);
#endif
- buf = ptr = g_malloc (body->length + 1);
- for (iter = priv->chunks; iter; iter = iter->next) {
- chunk = iter->data;
- memcpy (ptr, chunk->data, chunk->length);
- ptr += chunk->length;
+ GByteArray *array = g_byte_array_sized_new (body->length + 1);
+ for (GSList *iter = priv->chunks; iter; iter = iter->next) {
+ GBytes *chunk = iter->data;
+ gsize chunk_size;
+ const guchar *chunk_data = g_bytes_get_data (chunk, &chunk_size);
+ g_byte_array_append (array, chunk_data, chunk_size);
}
- *ptr = '\0';
+ // NUL terminate the array but don't reflect that in the length
+ g_byte_array_append (array, (guchar*)"\0", 1);
+ array->len -= 1;
- priv->flattened = soup_buffer_new (SOUP_MEMORY_TAKE,
- buf, body->length);
- body->data = priv->flattened->data;
+ priv->flattened = g_byte_array_free_to_bytes (array);
+ body->data = g_bytes_get_data (priv->flattened, NULL);
}
- return soup_buffer_copy (priv->flattened);
+ return g_bytes_ref (priv->flattened);
}
/**
@@ -609,7 +301,7 @@ soup_message_body_flatten (SoupMessageBody *body)
* @body: a #SoupMessageBody
* @offset: an offset
*
- * Gets a #SoupBuffer containing data from @body starting at @offset.
+ * Gets a #GBytes containing data from @body starting at @offset.
* The size of the returned chunk is unspecified. You can iterate
* through the entire body by first calling
* soup_message_body_get_chunk() with an offset of 0, and then on each
@@ -625,44 +317,40 @@ soup_message_body_flatten (SoupMessageBody *body)
* @body may still potentially have more data, but that data is not
* currently available).
*
- * Return value: (nullable): a #SoupBuffer, or %NULL.
+ * Return value: (nullable): a #GBytes, or %NULL.
**/
-SoupBuffer *
+GBytes *
soup_message_body_get_chunk (SoupMessageBody *body, goffset offset)
{
SoupMessageBodyPrivate *priv = (SoupMessageBodyPrivate *)body;
GSList *iter;
- SoupBuffer *chunk = NULL;
+ GBytes *chunk = NULL;
offset -= priv->base_offset;
for (iter = priv->chunks; iter; iter = iter->next) {
chunk = iter->data;
+ gsize chunk_length = g_bytes_get_size (chunk);
- if (offset < chunk->length || offset == 0)
+ if (offset < chunk_length || offset == 0)
break;
- offset -= chunk->length;
+ offset -= chunk_length;
}
if (!iter)
return NULL;
- if (offset == 0)
- return soup_buffer_copy (chunk);
- else {
- return soup_buffer_new_subbuffer (chunk, offset,
- chunk->length - offset);
- }
+ return g_bytes_new_from_bytes (chunk, offset, g_bytes_get_size (chunk) - offset);
}
/**
* soup_message_body_got_chunk:
* @body: a #SoupMessageBody
- * @chunk: a #SoupBuffer received from the network
+ * @chunk: a #GBytes received from the network
*
* Handles the #SoupMessageBody part of receiving a chunk of data from
* the network. Normally this means appending @chunk to @body, exactly
- * as with soup_message_body_append_buffer(), but if you have set
+ * as with soup_message_body_append_bytes(), but if you have set
* @body's accumulate flag to %FALSE, then that will not happen.
*
* This is a low-level method which you should not normally need to
@@ -671,20 +359,20 @@ soup_message_body_get_chunk (SoupMessageBody *body, goffset offset)
* Since: 2.24
**/
void
-soup_message_body_got_chunk (SoupMessageBody *body, SoupBuffer *chunk)
+soup_message_body_got_chunk (SoupMessageBody *body, GBytes *chunk)
{
SoupMessageBodyPrivate *priv = (SoupMessageBodyPrivate *)body;
if (!priv->accumulate)
return;
- soup_message_body_append_buffer (body, chunk);
+ soup_message_body_append_bytes (body, chunk);
}
/**
* soup_message_body_wrote_chunk:
* @body: a #SoupMessageBody
- * @chunk: a #SoupBuffer returned from soup_message_body_get_chunk()
+ * @chunk: a #GBytes returned from soup_message_body_get_chunk()
*
* Handles the #SoupMessageBody part of writing a chunk of data to the
* network. Normally this is a no-op, but if you have set @body's
@@ -698,24 +386,24 @@ soup_message_body_got_chunk (SoupMessageBody *body, SoupBuffer *chunk)
* Since: 2.24
**/
void
-soup_message_body_wrote_chunk (SoupMessageBody *body, SoupBuffer *chunk)
+soup_message_body_wrote_chunk (SoupMessageBody *body, GBytes *chunk)
{
SoupMessageBodyPrivate *priv = (SoupMessageBodyPrivate *)body;
- SoupBuffer *chunk2;
+ GBytes *chunk2;
if (priv->accumulate)
return;
chunk2 = priv->chunks->data;
- g_return_if_fail (chunk->length == chunk2->length);
- g_return_if_fail (chunk == chunk2 || ((SoupBufferPrivate *)chunk2)->use == SOUP_MEMORY_TEMPORARY);
+ g_return_if_fail (g_bytes_get_size (chunk) == g_bytes_get_size (chunk2));
+ g_return_if_fail (chunk == chunk2);
priv->chunks = g_slist_remove (priv->chunks, chunk2);
if (!priv->chunks)
priv->last = NULL;
- priv->base_offset += chunk2->length;
- soup_buffer_free (chunk2);
+ priv->base_offset += g_bytes_get_size (chunk2);
+ g_bytes_unref (chunk2);
}
static SoupMessageBody *
diff --git a/libsoup/soup-message-body.h b/libsoup/soup-message-body.h
index c08e26ae..4b757af9 100644
--- a/libsoup/soup-message-body.h
+++ b/libsoup/soup-message-body.h
@@ -18,46 +18,6 @@ typedef enum {
typedef struct {
const char *data;
- gsize length;
-} SoupBuffer;
-
-SOUP_AVAILABLE_IN_2_4
-GType soup_buffer_get_type (void);
-#define SOUP_TYPE_BUFFER (soup_buffer_get_type ())
-
-SOUP_AVAILABLE_IN_2_4
-SoupBuffer *soup_buffer_new (SoupMemoryUse use,
- gconstpointer data,
- gsize length);
-SOUP_AVAILABLE_IN_2_32
-SoupBuffer *soup_buffer_new_take (guchar *data,
- gsize length);
-SOUP_AVAILABLE_IN_2_4
-SoupBuffer *soup_buffer_new_subbuffer (SoupBuffer *parent,
- gsize offset,
- gsize length);
-
-SOUP_AVAILABLE_IN_2_4
-SoupBuffer *soup_buffer_new_with_owner (gconstpointer data,
- gsize length,
- gpointer owner,
- GDestroyNotify owner_dnotify);
-SOUP_AVAILABLE_IN_2_4
-gpointer soup_buffer_get_owner (SoupBuffer *buffer);
-SOUP_AVAILABLE_IN_2_32
-void soup_buffer_get_data (SoupBuffer *buffer,
- const guint8 **data,
- gsize *length);
-SOUP_AVAILABLE_IN_2_40
-GBytes *soup_buffer_get_as_bytes (SoupBuffer *buffer);
-
-SOUP_AVAILABLE_IN_2_4
-SoupBuffer *soup_buffer_copy (SoupBuffer *buffer);
-SOUP_AVAILABLE_IN_2_4
-void soup_buffer_free (SoupBuffer *buffer);
-
-typedef struct {
- const char *data;
goffset length;
} SoupMessageBody;
@@ -84,31 +44,30 @@ void soup_message_body_append_take (SoupMessageBody *body,
guchar *data,
gsize length);
SOUP_AVAILABLE_IN_2_4
-void soup_message_body_append_buffer (SoupMessageBody *body,
- SoupBuffer *buffer);
+void soup_message_body_append_bytes (SoupMessageBody *body,
+ GBytes *buffer);
SOUP_AVAILABLE_IN_2_4
void soup_message_body_truncate (SoupMessageBody *body);
SOUP_AVAILABLE_IN_2_4
void soup_message_body_complete (SoupMessageBody *body);
SOUP_AVAILABLE_IN_2_4
-SoupBuffer *soup_message_body_flatten (SoupMessageBody *body);
+GBytes *soup_message_body_flatten (SoupMessageBody *body);
SOUP_AVAILABLE_IN_2_4
-SoupBuffer *soup_message_body_get_chunk (SoupMessageBody *body,
+GBytes *soup_message_body_get_chunk (SoupMessageBody *body,
goffset offset);
SOUP_AVAILABLE_IN_2_24
void soup_message_body_got_chunk (SoupMessageBody *body,
- SoupBuffer *chunk);
+ GBytes *chunk);
SOUP_AVAILABLE_IN_2_24
void soup_message_body_wrote_chunk (SoupMessageBody *body,
- SoupBuffer *chunk);
+ GBytes *chunk);
SOUP_AVAILABLE_IN_2_4
void soup_message_body_free (SoupMessageBody *body);
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (SoupBuffer, soup_buffer_free)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SoupMessageBody, soup_message_body_free)
G_END_DECLS
diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c
index 302630ba..0acae00d 100644
--- a/libsoup/soup-message-io.c
+++ b/libsoup/soup-message-io.c
@@ -76,7 +76,7 @@ typedef struct {
SoupEncoding write_encoding;
GString *write_buf;
SoupMessageBody *write_body;
- SoupBuffer *write_chunk;
+ GBytes *write_chunk;
goffset write_body_offset;
goffset write_length;
goffset written;
@@ -130,8 +130,7 @@ soup_message_io_cleanup (SoupMessage *msg)
g_byte_array_free (io->read_header_buf, TRUE);
g_string_free (io->write_buf, TRUE);
- if (io->write_chunk)
- soup_buffer_free (io->write_chunk);
+ g_clear_pointer (&io->write_chunk, g_bytes_unref);
if (io->async_close_wait) {
g_cancellable_cancel (io->async_close_wait);
@@ -388,7 +387,7 @@ io_write (SoupMessage *msg, gboolean blocking,
GCancellable *cancellable, GError **error)
{
SoupMessageIOData *io = soup_message_get_io_data (msg);
- SoupBuffer *chunk;
+ GBytes *chunk;
gssize nwrote;
if (io->async_close_error) {
@@ -513,37 +512,36 @@ io_write (SoupMessage *msg, gboolean blocking,
soup_message_io_pause (msg);
return FALSE;
}
- if (!io->write_chunk->length) {
+ if (!g_bytes_get_size (io->write_chunk)) {
io->write_state = SOUP_MESSAGE_IO_STATE_BODY_FLUSH;
break;
}
}
nwrote = g_pollable_stream_write (io->body_ostream,
- io->write_chunk->data + io->written,
- io->write_chunk->length - io->written,
+ g_bytes_get_data (io->write_chunk, NULL) + io->written,
+ g_bytes_get_size (io->write_chunk) - io->written,
blocking,
cancellable, error);
if (nwrote == -1)
return FALSE;
- chunk = soup_buffer_new_subbuffer (io->write_chunk,
- io->written, nwrote);
+ chunk = g_bytes_new_from_bytes (io->write_chunk, io->written, nwrote);
io->written += nwrote;
if (io->write_length)
io->write_length -= nwrote;
- if (io->written == io->write_chunk->length)
+ if (io->written == g_bytes_get_size (io->write_chunk))
io->write_state = SOUP_MESSAGE_IO_STATE_BODY_DATA;
soup_message_wrote_body_data (msg, chunk);
- soup_buffer_free (chunk);
+ g_bytes_unref (chunk);
break;
case SOUP_MESSAGE_IO_STATE_BODY_DATA:
io->written = 0;
- if (io->write_chunk->length == 0) {
+ if (g_bytes_get_size (io->write_chunk) == 0) {
io->write_state = SOUP_MESSAGE_IO_STATE_BODY_FLUSH;
break;
}
@@ -551,9 +549,8 @@ io_write (SoupMessage *msg, gboolean blocking,
if (io->mode == SOUP_MESSAGE_IO_SERVER ||
soup_message_get_flags (msg) & SOUP_MESSAGE_CAN_REBUILD)
soup_message_body_wrote_chunk (io->write_body, io->write_chunk);
- io->write_body_offset += io->write_chunk->length;
- soup_buffer_free (io->write_chunk);
- io->write_chunk = NULL;
+ io->write_body_offset += g_bytes_get_size (io->write_chunk);
+ g_clear_pointer (&io->write_chunk, g_bytes_unref);
io->write_state = SOUP_MESSAGE_IO_STATE_BODY;
soup_message_wrote_chunk (msg);
@@ -612,9 +609,7 @@ io_read (SoupMessage *msg, gboolean blocking,
GCancellable *cancellable, GError **error)
{
SoupMessageIOData *io = soup_message_get_io_data (msg);
- guchar *stack_buf = NULL;
gssize nread;
- SoupBuffer *buffer;
guint status;
switch (io->read_state) {
@@ -749,34 +744,29 @@ io_read (SoupMessage *msg, gboolean blocking,
break;
- case SOUP_MESSAGE_IO_STATE_BODY:
- if (!stack_buf)
- stack_buf = alloca (RESPONSE_BLOCK_SIZE);
- buffer = soup_buffer_new (SOUP_MEMORY_TEMPORARY,
- stack_buf,
- RESPONSE_BLOCK_SIZE);
+ case SOUP_MESSAGE_IO_STATE_BODY: {
+ guchar buf[RESPONSE_BLOCK_SIZE];
nread = g_pollable_stream_read (io->body_istream,
- (guchar *)buffer->data,
- buffer->length,
+ buf,
+ RESPONSE_BLOCK_SIZE,
blocking,
cancellable, error);
if (nread > 0) {
- buffer->length = nread;
- soup_message_body_got_chunk (io->read_body, buffer);
- soup_message_got_chunk (msg, buffer);
- soup_buffer_free (buffer);
+ GBytes *bytes = g_bytes_new (buf, nread);
+ soup_message_body_got_chunk (io->read_body, bytes);
+ soup_message_got_chunk (msg, bytes);
+ g_bytes_unref (bytes);
break;
}
- soup_buffer_free (buffer);
if (nread == -1)
return FALSE;
/* else nread == 0 */
io->read_state = SOUP_MESSAGE_IO_STATE_BODY_DONE;
break;
-
+ }
case SOUP_MESSAGE_IO_STATE_BODY_DONE:
io->read_state = SOUP_MESSAGE_IO_STATE_FINISHING;
diff --git a/libsoup/soup-message-server-io.c b/libsoup/soup-message-server-io.c
index 3e00f3ea..2c0ee91c 100644
--- a/libsoup/soup-message-server-io.c
+++ b/libsoup/soup-message-server-io.c
@@ -144,7 +144,7 @@ handle_partial_get (SoupMessage *msg)
{
SoupRange *ranges;
int nranges;
- SoupBuffer *full_response;
+ GBytes *full_response;
guint status;
/* Make sure the message is set up right for us to return a
@@ -185,23 +185,23 @@ handle_partial_get (SoupMessage *msg)
soup_message_body_truncate (msg->response_body);
if (nranges == 1) {
- SoupBuffer *range_buf;
+ GBytes *range_buf;
/* Single range, so just set Content-Range and fix the body. */
soup_message_headers_set_content_range (msg->response_headers,
ranges[0].start,
ranges[0].end,
- full_response->length);
- range_buf = soup_buffer_new_subbuffer (full_response,
- ranges[0].start,
- ranges[0].end - ranges[0].start + 1);
- soup_message_body_append_buffer (msg->response_body, range_buf);
- soup_buffer_free (range_buf);
+ g_bytes_get_size (full_response));
+ range_buf = g_bytes_new_from_bytes (full_response,
+ ranges[0].start,
+ ranges[0].end - ranges[0].start + 1);
+ soup_message_body_append_bytes (msg->response_body, range_buf);
+ g_bytes_unref (range_buf);
} else {
SoupMultipart *multipart;
SoupMessageHeaders *part_headers;
- SoupBuffer *part_body;
+ GBytes *part_body;
const char *content_type;
int i;
@@ -222,14 +222,14 @@ handle_partial_get (SoupMessage *msg)
soup_message_headers_set_content_range (part_headers,
ranges[i].start,
ranges[i].end,
- full_response->length);
- part_body = soup_buffer_new_subbuffer (full_response,
- ranges[i].start,
- ranges[i].end - ranges[i].start + 1);
+ g_bytes_get_size (full_response));
+ part_body = g_bytes_new_from_bytes (full_response,
+ ranges[i].start,
+ ranges[i].end - ranges[i].start + 1);
soup_multipart_append_part (multipart, part_headers,
part_body);
soup_message_headers_free (part_headers);
- soup_buffer_free (part_body);
+ g_bytes_unref (part_body);
}
soup_multipart_to_message (multipart, msg->response_headers,
@@ -237,7 +237,7 @@ handle_partial_get (SoupMessage *msg)
soup_multipart_free (multipart);
}
- soup_buffer_free (full_response);
+ g_bytes_unref (full_response);
soup_message_headers_free_ranges (msg->request_headers, ranges);
}
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index 68bc0df2..36c45c45 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -267,7 +267,7 @@ soup_message_get_property (GObject *object, guint prop_id,
{
SoupMessage *msg = SOUP_MESSAGE (object);
SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
- SoupBuffer *buf;
+ GBytes *buf;
switch (prop_id) {
case PROP_METHOD:
@@ -305,8 +305,7 @@ soup_message_get_property (GObject *object, guint prop_id,
break;
case PROP_REQUEST_BODY_DATA:
buf = soup_message_body_flatten (msg->request_body);
- g_value_take_boxed (value, soup_buffer_get_as_bytes (buf));
- soup_buffer_free (buf);
+ g_value_take_boxed (value, buf);
break;
case PROP_REQUEST_HEADERS:
g_value_set_boxed (value, msg->request_headers);
@@ -316,8 +315,7 @@ soup_message_get_property (GObject *object, guint prop_id,
break;
case PROP_RESPONSE_BODY_DATA:
buf = soup_message_body_flatten (msg->response_body);
- g_value_take_boxed (value, soup_buffer_get_as_bytes (buf));
- soup_buffer_free (buf);
+ g_value_take_boxed (value, buf);
break;
case PROP_RESPONSE_HEADERS:
g_value_set_boxed (value, msg->response_headers);
@@ -345,10 +343,8 @@ soup_message_real_got_body (SoupMessage *msg)
body = priv->server_side ? msg->request_body : msg->response_body;
if (soup_message_body_get_accumulate (body)) {
- SoupBuffer *buffer;
-
- buffer = soup_message_body_flatten (body);
- soup_buffer_free (buffer);
+ GBytes *buffer = soup_message_body_flatten (body);
+ g_bytes_unref (buffer);
}
}
@@ -410,7 +406,7 @@ soup_message_class_init (SoupMessageClass *message_class)
* Note that this signal is not parallel to
* #SoupMessage::got_chunk; it is emitted only when a complete
* chunk (added with soup_message_body_append() or
- * soup_message_body_append_buffer()) has been written. To get
+ * soup_message_body_append_bytes()) has been written. To get
* more useful continuous progress information, use
* #SoupMessage::wrote_body_data.
**/
@@ -445,7 +441,7 @@ soup_message_class_init (SoupMessageClass *message_class)
NULL, NULL,
NULL,
G_TYPE_NONE, 1,
- SOUP_TYPE_BUFFER);
+ G_TYPE_BYTES);
/**
* SoupMessage::wrote-body:
@@ -544,13 +540,7 @@ soup_message_class_init (SoupMessageClass *message_class)
NULL, NULL,
NULL,
G_TYPE_NONE, 1,
- /* Use %G_SIGNAL_TYPE_STATIC_SCOPE so that
- * the %SOUP_MEMORY_TEMPORARY buffers used
- * by soup-message-io.c when emitting this
- * signal don't get forcibly copied by
- * g_signal_emit().
- */
- SOUP_TYPE_BUFFER | G_SIGNAL_TYPE_STATIC_SCOPE);
+ G_TYPE_BYTES);
/**
* SoupMessage::got-body:
@@ -1160,7 +1150,7 @@ soup_message_wrote_chunk (SoupMessage *msg)
}
void
-soup_message_wrote_body_data (SoupMessage *msg, SoupBuffer *chunk)
+soup_message_wrote_body_data (SoupMessage *msg, GBytes *chunk)
{
g_signal_emit (msg, signals[WROTE_BODY_DATA], 0, chunk);
}
@@ -1184,7 +1174,7 @@ soup_message_got_headers (SoupMessage *msg)
}
void
-soup_message_got_chunk (SoupMessage *msg, SoupBuffer *chunk)
+soup_message_got_chunk (SoupMessage *msg, GBytes *chunk)
{
g_signal_emit (msg, signals[GOT_CHUNK], 0, chunk);
}
diff --git a/libsoup/soup-message.h b/libsoup/soup-message.h
index c4cd49e8..70a0becb 100644
--- a/libsoup/soup-message.h
+++ b/libsoup/soup-message.h
@@ -46,7 +46,7 @@ typedef struct {
void (*wrote_body) (SoupMessage *msg);
void (*got_informational) (SoupMessage *msg);
void (*got_headers) (SoupMessage *msg);
- void (*got_chunk) (SoupMessage *msg, SoupBuffer *chunk);
+ void (*got_chunk) (SoupMessage *msg, GBytes *chunk);
void (*got_body) (SoupMessage *msg);
void (*restarted) (SoupMessage *msg);
void (*finished) (SoupMessage *msg);
@@ -228,7 +228,7 @@ void soup_message_wrote_headers (SoupMessage *msg);
SOUP_AVAILABLE_IN_2_4
void soup_message_wrote_chunk (SoupMessage *msg);
SOUP_AVAILABLE_IN_2_4
-void soup_message_wrote_body_data (SoupMessage *msg, SoupBuffer *chunk);
+void soup_message_wrote_body_data (SoupMessage *msg, GBytes *chunk);
SOUP_AVAILABLE_IN_2_4
void soup_message_wrote_body (SoupMessage *msg);
SOUP_AVAILABLE_IN_2_4
@@ -236,7 +236,7 @@ void soup_message_got_informational (SoupMessage *msg);
SOUP_AVAILABLE_IN_2_4
void soup_message_got_headers (SoupMessage *msg);
SOUP_AVAILABLE_IN_2_4
-void soup_message_got_chunk (SoupMessage *msg, SoupBuffer *chunk);
+void soup_message_got_chunk (SoupMessage *msg, GBytes *chunk);
SOUP_AVAILABLE_IN_2_4
void soup_message_got_body (SoupMessage *msg);
SOUP_AVAILABLE_IN_2_4
diff --git a/libsoup/soup-multipart.c b/libsoup/soup-multipart.c
index 1844de98..67df98fa 100644
--- a/libsoup/soup-multipart.c
+++ b/libsoup/soup-multipart.c
@@ -54,7 +54,7 @@ soup_multipart_new_internal (char *mime_type, char *boundary)
multipart->mime_type = mime_type;
multipart->boundary = boundary;
multipart->headers = g_ptr_array_new_with_free_func ((GDestroyNotify)soup_message_headers_free);
- multipart->bodies = g_ptr_array_new_with_free_func ((GDestroyNotify)soup_buffer_free);
+ multipart->bodies = g_ptr_array_new_with_free_func ((GDestroyNotify)g_bytes_unref);
return multipart;
}
@@ -140,10 +140,10 @@ soup_multipart_new_from_message (SoupMessageHeaders *headers,
const char *content_type, *boundary;
GHashTable *params;
int boundary_len;
- SoupBuffer *flattened;
+ GBytes *flattened;
const char *start, *split, *end, *body_end;
SoupMessageHeaders *part_headers;
- SoupBuffer *part_body;
+ GBytes *part_body;
content_type = soup_message_headers_get_content_type (headers, &params);
if (!content_type)
@@ -160,16 +160,18 @@ soup_multipart_new_from_message (SoupMessageHeaders *headers,
g_hash_table_destroy (params);
flattened = soup_message_body_flatten (body);
- body_end = flattened->data + flattened->length;
+ gsize flattened_size;
+ const char *flattened_data = g_bytes_get_data (flattened, &flattened_size);
+ body_end = flattened_data + flattened_size;
boundary = multipart->boundary;
boundary_len = strlen (boundary);
/* skip preamble */
- start = find_boundary (flattened->data, body_end,
+ start = find_boundary (flattened_data, body_end,
boundary, boundary_len);
if (!start) {
soup_multipart_free (multipart);
- soup_buffer_free (flattened);
+ g_bytes_unref (flattened);
return NULL;
}
@@ -178,14 +180,14 @@ soup_multipart_new_from_message (SoupMessageHeaders *headers,
boundary, boundary_len);
if (!end) {
soup_multipart_free (multipart);
- soup_buffer_free (flattened);
+ g_bytes_unref (flattened);
return NULL;
}
split = strstr (start, "\r\n\r\n");
if (!split || split > end) {
soup_multipart_free (multipart);
- soup_buffer_free (flattened);
+ g_bytes_unref (flattened);
return NULL;
}
split += 4;
@@ -204,7 +206,7 @@ soup_multipart_new_from_message (SoupMessageHeaders *headers,
if (!soup_headers_parse (start, split - 2 - start,
part_headers)) {
soup_multipart_free (multipart);
- soup_buffer_free (flattened);
+ g_bytes_unref (flattened);
return NULL;
}
@@ -213,15 +215,15 @@ soup_multipart_new_from_message (SoupMessageHeaders *headers,
* the following boundary line, which is to say 2 bytes
* after the end of the body.
*/
- part_body = soup_buffer_new_subbuffer (flattened,
- split - flattened->data,
- end - 2 - split);
+ part_body = g_bytes_new_from_bytes (flattened, // FIXME
+ split - flattened_data,
+ end - 2 - split);
g_ptr_array_add (multipart->bodies, part_body);
start = end;
}
- soup_buffer_free (flattened);
+ g_bytes_unref (flattened);
return multipart;
}
@@ -259,7 +261,7 @@ soup_multipart_get_length (SoupMultipart *multipart)
**/
gboolean
soup_multipart_get_part (SoupMultipart *multipart, int part,
- SoupMessageHeaders **headers, SoupBuffer **body)
+ SoupMessageHeaders **headers, GBytes **body)
{
if (part < 0 || part >= multipart->bodies->len)
return FALSE;
@@ -284,7 +286,7 @@ soup_multipart_get_part (SoupMultipart *multipart, int part,
void
soup_multipart_append_part (SoupMultipart *multipart,
SoupMessageHeaders *headers,
- SoupBuffer *body)
+ GBytes *body)
{
SoupMessageHeaders *headers_copy;
SoupMessageHeadersIter iter;
@@ -307,7 +309,7 @@ soup_multipart_append_part (SoupMultipart *multipart,
* 3) We don't want to steal the reference to @headers,
* because then we'd have to either also steal the
* reference to @body (which would be inconsistent with
- * other SoupBuffer methods), or NOT steal the reference to
+ * other GBytes methods), or NOT steal the reference to
* @body, in which case there'd be inconsistency just
* between the two arguments of this method!
*/
@@ -317,7 +319,7 @@ soup_multipart_append_part (SoupMultipart *multipart,
soup_message_headers_append (headers_copy, name, value);
g_ptr_array_add (multipart->headers, headers_copy);
- g_ptr_array_add (multipart->bodies, soup_buffer_copy (body));
+ g_ptr_array_add (multipart->bodies, g_bytes_ref (body));
}
/**
@@ -337,12 +339,12 @@ void
soup_multipart_append_form_string (SoupMultipart *multipart,
const char *control_name, const char *data)
{
- SoupBuffer *body;
+ GBytes *body;
- body = soup_buffer_new (SOUP_MEMORY_COPY, data, strlen (data));
+ body = g_bytes_new (data, strlen (data));
soup_multipart_append_form_file (multipart, control_name,
NULL, NULL, body);
- soup_buffer_free (body);
+ g_bytes_unref (body);
}
/**
@@ -363,7 +365,7 @@ soup_multipart_append_form_string (SoupMultipart *multipart,
void
soup_multipart_append_form_file (SoupMultipart *multipart,
const char *control_name, const char *filename,
- const char *content_type, SoupBuffer *body)
+ const char *content_type, GBytes *body)
{
SoupMessageHeaders *headers;
GString *disposition;
@@ -385,7 +387,7 @@ soup_multipart_append_form_file (SoupMultipart *multipart,
}
g_ptr_array_add (multipart->headers, headers);
- g_ptr_array_add (multipart->bodies, soup_buffer_copy (body));
+ g_ptr_array_add (multipart->bodies, g_bytes_ref (body));
}
/**
@@ -404,7 +406,7 @@ soup_multipart_to_message (SoupMultipart *multipart,
SoupMessageBody *dest_body)
{
SoupMessageHeaders *part_headers;
- SoupBuffer *part_body;
+ GBytes *part_body;
SoupMessageHeadersIter iter;
const char *name, *value;
GString *str;
@@ -430,11 +432,12 @@ soup_multipart_to_message (SoupMultipart *multipart,
while (soup_message_headers_iter_next (&iter, &name, &value))
g_string_append_printf (str, "%s: %s\r\n", name, value);
g_string_append (str, "\r\n");
- soup_message_body_append (dest_body, SOUP_MEMORY_TAKE,
- str->str, str->len);
- g_string_free (str, FALSE);
- soup_message_body_append_buffer (dest_body, part_body);
+ GBytes *buffer = g_string_free_to_bytes (str);
+ soup_message_body_append_bytes (dest_body, buffer);
+ g_bytes_unref (buffer);
+
+ soup_message_body_append_bytes (dest_body, part_body);
}
str = g_string_new ("\r\n--");
diff --git a/libsoup/soup-multipart.h b/libsoup/soup-multipart.h
index 22675c39..e5a46c24 100644
--- a/libsoup/soup-multipart.h
+++ b/libsoup/soup-multipart.h
@@ -29,12 +29,12 @@ SOUP_AVAILABLE_IN_2_26
gboolean soup_multipart_get_part (SoupMultipart *multipart,
int part,
SoupMessageHeaders **headers,
- SoupBuffer **body);
+ GBytes **body);
SOUP_AVAILABLE_IN_2_26
void soup_multipart_append_part (SoupMultipart *multipart,
SoupMessageHeaders *headers,
- SoupBuffer *body);
+ GBytes *body);
SOUP_AVAILABLE_IN_2_26
void soup_multipart_append_form_string (SoupMultipart *multipart,
@@ -45,7 +45,7 @@ void soup_multipart_append_form_file (SoupMultipart *multipart,
const char *control_name,
const char *filename,
const char *content_type,
- SoupBuffer *body);
+ GBytes *body);
SOUP_AVAILABLE_IN_2_26
void soup_multipart_to_message (SoupMultipart *multipart,
diff --git a/libsoup/soup-server.c b/libsoup/soup-server.c
index ae2301d4..2aa4a7e2 100644
--- a/libsoup/soup-server.c
+++ b/libsoup/soup-server.c
@@ -2020,7 +2020,7 @@ get_or_create_handler (SoupServer *server, const char *exact_path)
* To send the response body a bit at a time using "chunked" encoding,
* first call soup_message_headers_set_encoding() to set
* %SOUP_ENCODING_CHUNKED on the #SoupMessage:response-headers. Then call
- * soup_message_body_append() (or soup_message_body_append_buffer())
+ * soup_message_body_append() (or soup_message_body_append_bytes))
* to append each chunk as it becomes ready, and
* soup_server_unpause_message() to make sure it's running. (The
* server will automatically pause the message if it is using chunked
diff --git a/tests/chunk-io-test.c b/tests/chunk-io-test.c
index 4746ea6c..8c1423bf 100644
--- a/tests/chunk-io-test.c
+++ b/tests/chunk-io-test.c
@@ -324,16 +324,16 @@ breaking_pollable_output_stream_init (GPollableOutputStreamInterface *pollable_i
#define CHUNK_SIZE 1024
static GString *
-chunkify (const char *str, gsize length)
+chunkify (GBytes *data)
{
GString *gstr;
int i, size;
gstr = g_string_new (NULL);
- for (i = 0; i < length; i += CHUNK_SIZE) {
- size = MIN (CHUNK_SIZE, length - i);
+ for (i = 0; i < g_bytes_get_size (data); i += CHUNK_SIZE) {
+ size = MIN (CHUNK_SIZE, g_bytes_get_size (data) - i);
g_string_append_printf (gstr, "%x\r\n", size);
- g_string_append_len (gstr, str + i, size);
+ g_string_append_len (gstr, (char*)g_bytes_get_data (data, NULL) + i, size);
g_string_append (gstr, "\r\n");
}
g_string_append (gstr, "0\r\n\r\n");
@@ -347,7 +347,9 @@ do_io_tests (void)
GInputStream *imem, *islow, *in;
GOutputStream *omem, *oslow, *out;
GMemoryOutputStream *mem;
- SoupBuffer *raw_contents;
+ GBytes *raw_contents;
+ gsize raw_contents_length;
+ const guchar *raw_contents_data;
char *buf;
GString *chunkified;
GError *error = NULL;
@@ -355,7 +357,8 @@ do_io_tests (void)
gssize chunk_length, chunk_total;
raw_contents = soup_test_get_index ();
- chunkified = chunkify (raw_contents->data, raw_contents->length);
+ raw_contents_data = g_bytes_get_data (raw_contents, &raw_contents_length);
+ chunkified = chunkify (raw_contents);
debug_printf (1, " sync read\n");
@@ -372,11 +375,11 @@ do_io_tests (void)
g_object_unref (imem);
g_object_unref (islow);
- buf = g_malloc (raw_contents->length);
+ buf = g_malloc (raw_contents_length);
total = 0;
while (TRUE) {
nread = g_input_stream_read (in, buf + total,
- raw_contents->length - total,
+ raw_contents_length - total,
NULL, &error);
g_assert_no_error (error);
g_clear_error (&error);
@@ -391,7 +394,7 @@ do_io_tests (void)
g_clear_error (&error);
g_object_unref (in);
- soup_assert_cmpmem (buf, total, raw_contents->data, raw_contents->length);
+ soup_assert_cmpmem (buf, total, g_bytes_get_data (raw_contents, NULL), raw_contents_length);
g_free (buf);
debug_printf (1, " async read\n");
@@ -409,12 +412,12 @@ do_io_tests (void)
g_object_unref (imem);
g_object_unref (islow);
- buf = g_malloc (raw_contents->length);
+ buf = g_malloc (raw_contents_length);
total = 0;
while (TRUE) {
nread = g_pollable_input_stream_read_nonblocking (G_POLLABLE_INPUT_STREAM (in),
buf + total,
- raw_contents->length - total,
+ raw_contents_length - total,
NULL, &error);
if (nread == -1 && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
GSource *source;
@@ -443,7 +446,7 @@ do_io_tests (void)
g_clear_error (&error);
g_object_unref (in);
- soup_assert_cmpmem (buf, total, raw_contents->data, raw_contents->length);
+ soup_assert_cmpmem (buf, total, raw_contents_data, raw_contents_length);
g_free (buf);
debug_printf (1, " sync write\n");
@@ -463,12 +466,12 @@ do_io_tests (void)
g_object_unref (oslow);
total = chunk_length = chunk_total = 0;
- while (total < raw_contents->length) {
+ while (total < raw_contents_length) {
if (chunk_total == chunk_length) {
- chunk_length = MIN (CHUNK_SIZE, raw_contents->length - total);
+ chunk_length = MIN (CHUNK_SIZE, raw_contents_length - total);
chunk_total = 0;
}
- nwrote = g_output_stream_write (out, raw_contents->data + total,
+ nwrote = g_output_stream_write (out, raw_contents_data + total,
chunk_length - chunk_total, NULL, &error);
g_assert_no_error (error);
g_clear_error (&error);
@@ -508,13 +511,13 @@ do_io_tests (void)
g_object_unref (oslow);
total = chunk_length = chunk_total = 0;
- while (total < raw_contents->length) {
+ while (total < raw_contents_length) {
if (chunk_total == chunk_length) {
- chunk_length = MIN (CHUNK_SIZE, raw_contents->length - total);
+ chunk_length = MIN (CHUNK_SIZE, raw_contents_length - total);
chunk_total = 0;
}
nwrote = g_pollable_output_stream_write_nonblocking (G_POLLABLE_OUTPUT_STREAM (out),
- raw_contents->data + total,
+ raw_contents_data + total,
chunk_length - chunk_total,
NULL, &error);
if (nwrote == -1 && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
@@ -569,16 +572,16 @@ do_io_tests (void)
g_object_unref (oslow);
total = 0;
- while (total < raw_contents->length) {
- nwrote = g_output_stream_write (out, raw_contents->data + total,
- raw_contents->length - total, NULL, NULL);
+ while (total < raw_contents_length) {
+ nwrote = g_output_stream_write (out, raw_contents_data + total,
+ raw_contents_length - total, NULL, NULL);
if (nwrote == -1)
break;
else
total += nwrote;
}
- g_assert_cmpint (total, !=, raw_contents->length);
+ g_assert_cmpint (total, !=, raw_contents_length);
g_output_stream_close (out, NULL, NULL);
g_object_unref (out);
diff --git a/tests/chunk-test.c b/tests/chunk-test.c
index 86d7e9ba..04c62533 100644
--- a/tests/chunk-test.c
+++ b/tests/chunk-test.c
@@ -10,7 +10,7 @@ static SoupURI *base_uri;
typedef struct {
SoupSession *session;
- SoupBuffer *chunks[3];
+ GBytes *chunks[3];
int next, nwrote, nfreed;
gboolean streaming;
} PutTestData;
@@ -28,9 +28,9 @@ write_next_chunk (SoupMessage *msg, gpointer user_data)
}
if (ptd->next < G_N_ELEMENTS (ptd->chunks)) {
- soup_message_body_append_buffer (msg->request_body,
+ soup_message_body_append_bytes (msg->request_body,
ptd->chunks[ptd->next]);
- soup_buffer_free (ptd->chunks[ptd->next]);
+ g_bytes_unref (ptd->chunks[ptd->next]);
ptd->next++;
} else
soup_message_body_complete (msg->request_body);
@@ -43,14 +43,14 @@ static void
write_next_chunk_streaming_hack (SoupMessage *msg, gpointer user_data)
{
PutTestData *ptd = user_data;
- SoupBuffer *chunk;
+ GBytes *chunk;
debug_printf (2, " freeing chunk at %d\n", ptd->nfreed);
chunk = soup_message_body_get_chunk (msg->request_body, ptd->nfreed);
if (chunk) {
- ptd->nfreed += chunk->length;
+ ptd->nfreed += g_bytes_get_size (chunk);
soup_message_body_wrote_chunk (msg->request_body, chunk);
- soup_buffer_free (chunk);
+ g_bytes_unref (chunk);
} else {
soup_test_assert (chunk,
"written chunk does not exist");
@@ -59,25 +59,23 @@ write_next_chunk_streaming_hack (SoupMessage *msg, gpointer user_data)
}
static void
-wrote_body_data (SoupMessage *msg, SoupBuffer *chunk, gpointer user_data)
+wrote_body_data (SoupMessage *msg, GBytes *chunk, gpointer user_data)
{
PutTestData *ptd = user_data;
debug_printf (2, " wrote_body_data, %d bytes\n",
- (int)chunk->length);
- ptd->nwrote += chunk->length;
+ (int)g_bytes_get_size (chunk));
+ ptd->nwrote += g_bytes_get_size (chunk);
}
static void
clear_buffer_ptr (gpointer data)
{
- SoupBuffer **buffer_ptr = data;
+ GBytes **buffer_ptr = data;
debug_printf (2, " clearing chunk\n");
if (*buffer_ptr) {
- (*buffer_ptr)->length = 0;
- g_free ((char *)(*buffer_ptr)->data);
- *buffer_ptr = NULL;
+ *buffer_ptr = NULL;
} else {
soup_test_assert (*buffer_ptr,
"chunk is already clear");
@@ -89,10 +87,10 @@ clear_buffer_ptr (gpointer data)
* the set_accumulate(FALSE) is working.
*/
static void
-make_put_chunk (SoupBuffer **buffer, const char *text)
+make_put_chunk (GBytes **buffer, const char *text)
{
- *buffer = soup_buffer_new_with_owner (g_strdup (text), strlen (text),
- buffer, clear_buffer_ptr);
+ *buffer = g_bytes_new_with_free_func (g_strdup (text), strlen (text),
+ clear_buffer_ptr, buffer);
}
static void
@@ -160,9 +158,9 @@ do_request_test (gconstpointer data)
check = g_checksum_new (G_CHECKSUM_MD5);
length = 0;
for (i = 0; i < 3; i++) {
- g_checksum_update (check, (guchar *)ptd.chunks[i]->data,
- ptd.chunks[i]->length);
- length += ptd.chunks[i]->length;
+ g_checksum_update (check, (guchar *)g_bytes_get_data (ptd.chunks[i], NULL),
+ g_bytes_get_size (ptd.chunks[i]));
+ length += g_bytes_get_size (ptd.chunks[i]);
}
client_md5 = g_checksum_get_string (check);
@@ -217,7 +215,7 @@ do_request_test (gconstpointer data)
static void
temp_test_wrote_chunk (SoupMessage *msg, gpointer session)
{
- SoupBuffer *chunk;
+ GBytes *chunk;
chunk = soup_message_body_get_chunk (msg->request_body, 5);
@@ -227,7 +225,7 @@ temp_test_wrote_chunk (SoupMessage *msg, gpointer session)
* done, but it hasn't written Content-Length bytes yet.
*/
if (chunk)
- soup_buffer_free (chunk);
+ g_bytes_unref (chunk);
else {
soup_test_assert (chunk, "Lost second chunk");
soup_session_abort (session);
@@ -247,7 +245,7 @@ do_temporary_test (void)
g_test_bug ("18343");
msg = soup_message_new_from_uri ("PUT", base_uri);
- soup_message_body_append (msg->request_body, SOUP_MEMORY_TEMPORARY,
+ soup_message_body_append (msg->request_body, SOUP_MEMORY_STATIC,
"one\r\n", 5);
soup_message_body_append (msg->request_body, SOUP_MEMORY_STATIC,
"two\r\n", 5);
@@ -272,19 +270,21 @@ do_temporary_test (void)
#define LARGE_CHUNK_SIZE 1000000
typedef struct {
- SoupBuffer *buf;
+ GBytes *buf;
gsize offset;
} LargeChunkData;
static void
-large_wrote_body_data (SoupMessage *msg, SoupBuffer *chunk, gpointer user_data)
+large_wrote_body_data (SoupMessage *msg, GBytes *chunk, gpointer user_data)
{
LargeChunkData *lcd = user_data;
+ gsize chunk_length;
+ const guchar *chunk_data = g_bytes_get_data (chunk, &chunk_length);
- soup_assert_cmpmem (chunk->data, chunk->length,
- lcd->buf->data + lcd->offset,
- chunk->length);
- lcd->offset += chunk->length;
+ soup_assert_cmpmem (chunk_data, chunk_length,
+ (guchar*)g_bytes_get_data (lcd->buf, NULL) + lcd->offset,
+ chunk_length);
+ lcd->offset += chunk_length;
}
static void
@@ -300,9 +300,9 @@ do_large_chunk_test (void)
buf_data = g_malloc0 (LARGE_CHUNK_SIZE);
for (i = 0; i < LARGE_CHUNK_SIZE; i++)
buf_data[i] = i & 0xFF;
- lcd.buf = soup_buffer_new (SOUP_MEMORY_TAKE, buf_data, LARGE_CHUNK_SIZE);
+ lcd.buf = g_bytes_new_take (buf_data, LARGE_CHUNK_SIZE);
lcd.offset = 0;
- soup_message_body_append_buffer (msg->request_body, lcd.buf);
+ soup_message_body_append_bytes (msg->request_body, lcd.buf);
soup_message_body_set_accumulate (msg->request_body, FALSE);
g_signal_connect (msg, "wrote_body_data",
@@ -311,7 +311,7 @@ do_large_chunk_test (void)
soup_test_assert_message_status (msg, SOUP_STATUS_CREATED);
- soup_buffer_free (lcd.buf);
+ g_bytes_unref (lcd.buf);
g_object_unref (msg);
}
@@ -333,7 +333,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
SOUP_MEMORY_STATIC,
"three\r\ntwo\r\none\r\n",
strlen ("three\r\ntwo\r\none\r\n"));
- soup_buffer_free (soup_message_body_flatten (msg->response_body));
+ g_bytes_unref (soup_message_body_flatten (msg->response_body));
md5_body = msg->response_body;
soup_message_set_status (msg, SOUP_STATUS_OK);
} else if (msg->method == SOUP_METHOD_PUT) {
diff --git a/tests/coding-test.c b/tests/coding-test.c
index a7c59650..e8a33508 100644
--- a/tests/coding-test.c
+++ b/tests/coding-test.c
@@ -16,7 +16,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
{
const char *accept_encoding, *options;
GSList *codings;
- SoupBuffer *response = NULL;
+ GBytes *response = NULL;
options = soup_message_headers_get_one (msg->request_headers,
"X-Test-Options");
@@ -106,8 +106,8 @@ server_callback (SoupServer *server, SoupMessage *msg,
soup_message_headers_set_encoding (msg->response_headers, SOUP_ENCODING_CHUNKED);
if (!soup_header_contains (options, "empty"))
- soup_message_body_append_buffer (msg->response_body, response);
- soup_buffer_free (response);
+ soup_message_body_append_bytes (msg->response_body, response);
+ g_bytes_unref (response);
if (soup_header_contains (options, "trailing-junk")) {
soup_message_body_append (msg->response_body, SOUP_MEMORY_COPY,
@@ -120,7 +120,7 @@ typedef struct {
SoupSession *session;
SoupMessage *msg;
SoupRequest *req;
- SoupBuffer *response;
+ GBytes *response;
} CodingTestData;
typedef enum {
@@ -141,7 +141,7 @@ check_response (CodingTestData *data,
const char *expected_encoding,
const char *expected_content_type,
MessageContentStatus status,
- GByteArray *body)
+ GBytes *body)
{
const char *coding, *type;
@@ -161,15 +161,12 @@ check_response (CodingTestData *data,
g_assert_cmpstr (type, ==, expected_content_type);
if (body) {
- soup_assert_cmpmem (body->data,
- body->len,
- data->response->data,
- data->response->length);
+ g_assert_true (g_bytes_equal (body, data->response));
} else {
soup_assert_cmpmem (data->msg->response_body->data,
data->msg->response_body->length,
- data->response->data,
- data->response->length);
+ g_bytes_get_data (data->response, NULL),
+ g_bytes_get_size (data->response));
}
}
@@ -186,7 +183,7 @@ setup_coding_test (CodingTestData *data, gconstpointer test_data)
uri = soup_uri_new_with_base (base_uri, "/mbox");
if (test_type & CODING_TEST_EMPTY)
- data->response = soup_buffer_new (SOUP_MEMORY_STATIC, "", 0);
+ data->response = g_bytes_new_static (NULL, 0);
else {
msg = soup_message_new_from_uri ("GET", uri);
soup_session_send_message (data->session, msg);
@@ -213,7 +210,7 @@ setup_coding_test (CodingTestData *data, gconstpointer test_data)
static void
teardown_coding_test (CodingTestData *data, gconstpointer test_data)
{
- soup_buffer_free (data->response);
+ g_bytes_unref (data->response);
g_clear_object (&data->req);
g_object_unref (data->msg);
@@ -342,6 +339,7 @@ do_single_coding_req_test (CodingTestData *data,
{
GInputStream *stream;
GByteArray *body;
+ GBytes *body_bytes;
guchar buf[1024];
gssize nread;
GError *error = NULL;
@@ -372,8 +370,9 @@ do_single_coding_req_test (CodingTestData *data,
g_clear_error (&error);
g_object_unref (stream);
- check_response (data, expected_encoding, expected_content_type, status, body);
- g_byte_array_free (body, TRUE);
+ body_bytes = g_byte_array_free_to_bytes (body);
+ check_response (data, expected_encoding, expected_content_type, status, body_bytes);
+ g_bytes_unref (body_bytes);
}
static void
diff --git a/tests/forms-test.c b/tests/forms-test.c
index f76733d1..1ad1c84a 100644
--- a/tests/forms-test.c
+++ b/tests/forms-test.c
@@ -184,7 +184,7 @@ do_md5_test_libsoup (gconstpointer data)
char *contents, *md5;
gsize length;
SoupMultipart *multipart;
- SoupBuffer *buffer;
+ GBytes *buffer;
SoupMessage *msg;
SoupSession *session;
@@ -195,12 +195,12 @@ do_md5_test_libsoup (gconstpointer data)
return;
multipart = soup_multipart_new (SOUP_FORM_MIME_TYPE_MULTIPART);
- buffer = soup_buffer_new (SOUP_MEMORY_COPY, contents, length);
+ buffer = g_bytes_new (contents, length);
soup_multipart_append_form_file (multipart, "file",
MD5_TEST_FILE_BASENAME,
MD5_TEST_FILE_MIME_TYPE,
buffer);
- soup_buffer_free (buffer);
+ g_bytes_unref (buffer);
soup_multipart_append_form_string (multipart, "fmt", "text");
msg = soup_form_request_new_from_multipart (uri, multipart);
@@ -354,7 +354,7 @@ md5_post_callback (SoupServer *server, SoupMessage *msg,
GHashTable *params;
const char *fmt;
char *filename, *md5sum, *redirect_uri;
- SoupBuffer *file;
+ GBytes *file;
SoupURI *uri;
content_type = soup_message_headers_get_content_type (msg->request_headers, NULL);
@@ -371,10 +371,8 @@ md5_post_callback (SoupServer *server, SoupMessage *msg,
}
fmt = g_hash_table_lookup (params, "fmt");
- md5sum = g_compute_checksum_for_data (G_CHECKSUM_MD5,
- (gpointer)file->data,
- file->length);
- soup_buffer_free (file);
+ md5sum = g_compute_checksum_for_bytes (G_CHECKSUM_MD5, file);
+ g_bytes_unref (file);
uri = soup_uri_copy (soup_message_get_uri (msg));
soup_uri_set_query_from_fields (uri,
diff --git a/tests/header-parsing-test.c b/tests/header-parsing-test.c
index 31edfd02..40b5fd37 100644
--- a/tests/header-parsing-test.c
+++ b/tests/header-parsing-test.c
@@ -1040,7 +1040,7 @@ do_content_disposition_tests (void)
GHashTable *params;
const char *header, *filename;
char *disposition;
- SoupBuffer *buffer;
+ GBytes *buffer;
SoupMultipart *multipart;
SoupMessageBody *body;
@@ -1106,10 +1106,10 @@ do_content_disposition_tests (void)
/* Ensure that soup-multipart always quotes filename */
g_test_bug ("641280");
multipart = soup_multipart_new (SOUP_FORM_MIME_TYPE_MULTIPART);
- buffer = soup_buffer_new (SOUP_MEMORY_STATIC, "foo", 3);
+ buffer = g_bytes_new_static ("foo", 3);
soup_multipart_append_form_file (multipart, "test", "token",
"text/plain", buffer);
- soup_buffer_free (buffer);
+ g_bytes_unref (buffer);
hdrs = soup_message_headers_new (SOUP_MESSAGE_HEADERS_MULTIPART);
body = soup_message_body_new ();
@@ -1120,9 +1120,9 @@ do_content_disposition_tests (void)
buffer = soup_message_body_flatten (body);
soup_message_body_free (body);
- g_assert_true (strstr (buffer->data, "filename=\"token\""));
+ g_assert_nonnull (strstr (g_bytes_get_data (buffer, NULL), "filename=\"token\""));
- soup_buffer_free (buffer);
+ g_bytes_unref (buffer);
}
#define CONTENT_TYPE_TEST_MIME_TYPE "text/plain"
diff --git a/tests/pull-api-test.c b/tests/pull-api-test.c
index 3e515850..5b9bd5ea 100644
--- a/tests/pull-api-test.c
+++ b/tests/pull-api-test.c
@@ -2,7 +2,7 @@
#include "test-utils.h"
-static SoupBuffer *correct_response;
+static GBytes *correct_response;
static void
authenticate (SoupSession *session, SoupMessage *msg,
@@ -54,7 +54,7 @@ typedef struct {
} FullyAsyncData;
static void fully_async_got_headers (SoupMessage *msg, gpointer user_data);
-static void fully_async_got_chunk (SoupMessage *msg, SoupBuffer *chunk,
+static void fully_async_got_chunk (SoupMessage *msg, GBytes *chunk,
gpointer user_data);
static void fully_async_finished (SoupSession *session, SoupMessage *msg,
gpointer user_data);
@@ -180,23 +180,24 @@ fully_async_got_headers (SoupMessage *msg, gpointer user_data)
}
static void
-fully_async_got_chunk (SoupMessage *msg, SoupBuffer *chunk, gpointer user_data)
+fully_async_got_chunk (SoupMessage *msg, GBytes *chunk, gpointer user_data)
{
FullyAsyncData *ad = user_data;
debug_printf (2, " got chunk from %lu - %lu\n",
(unsigned long) ad->read_so_far,
- (unsigned long) ad->read_so_far + chunk->length);
+ (unsigned long) ad->read_so_far + g_bytes_get_size (chunk));
/* We've got a chunk, let's process it. In the case of the
* test program, that means comparing it against
* correct_response to make sure that we got the right data.
*/
- g_assert_cmpint (ad->read_so_far + chunk->length, <=, correct_response->length);
- soup_assert_cmpmem (chunk->data, chunk->length,
- correct_response->data + ad->read_so_far,
- chunk->length);
- ad->read_so_far += chunk->length;
+ gsize chunk_length = g_bytes_get_size (chunk);
+ g_assert_cmpint (ad->read_so_far + chunk_length, <=, g_bytes_get_size (correct_response));
+ soup_assert_cmpmem (g_bytes_get_data (chunk, NULL), chunk_length,
+ (guchar*)g_bytes_get_data (correct_response, NULL) + ad->read_so_far,
+ chunk_length);
+ ad->read_so_far += chunk_length;
/* Now pause I/O, and prepare to read another chunk later.
* (Again, the timeout just abstractly represents the idea of
@@ -273,17 +274,17 @@ do_slow_async_test (gconstpointer data)
typedef struct {
GMainLoop *loop;
SoupSession *session;
- SoupBuffer *chunk;
+ GBytes *chunk;
} SyncAsyncData;
static void sync_async_send (SoupSession *session,
SoupMessage *msg);
static gboolean sync_async_is_finished(SoupMessage *msg);
-static SoupBuffer *sync_async_read_chunk (SoupMessage *msg);
+static GBytes *sync_async_read_chunk (SoupMessage *msg);
static void sync_async_cleanup (SoupMessage *msg);
static void sync_async_got_headers (SoupMessage *msg, gpointer user_data);
-static void sync_async_copy_chunk (SoupMessage *msg, SoupBuffer *chunk,
+static void sync_async_copy_chunk (SoupMessage *msg, GBytes *chunk,
gpointer user_data);
static void sync_async_finished (SoupSession *session, SoupMessage *msg,
gpointer user_data);
@@ -296,7 +297,7 @@ do_synchronously_async_test (SoupSession *session,
SoupMessage *msg;
char *uri;
gsize read_so_far;
- SoupBuffer *chunk;
+ GBytes *chunk;
uri = g_build_filename (base_uri, sub_uri, NULL);
debug_printf (1, "GET %s\n", uri);
@@ -324,23 +325,24 @@ do_synchronously_async_test (SoupSession *session,
*/
read_so_far = 0;
while ((chunk = sync_async_read_chunk (msg))) {
+ gsize chunk_length = g_bytes_get_size (chunk);
debug_printf (2, " read chunk from %lu - %lu\n",
(unsigned long) read_so_far,
- (unsigned long) read_so_far + chunk->length);
+ (unsigned long) read_so_far + chunk_length);
- g_assert_cmpint (read_so_far + chunk->length, <=, correct_response->length);
- soup_assert_cmpmem (chunk->data, chunk->length,
- correct_response->data + read_so_far,
- chunk->length);
+ g_assert_cmpint (read_so_far + chunk_length, <=, g_bytes_get_size (correct_response));
+ soup_assert_cmpmem (g_bytes_get_data (chunk, NULL), chunk_length,
+ (guchar*) g_bytes_get_data (correct_response, NULL) + read_so_far,
+ chunk_length);
- read_so_far += chunk->length;
- soup_buffer_free (chunk);
+ read_so_far += chunk_length;
+ g_bytes_unref (chunk);
}
g_assert_true (sync_async_is_finished (msg));
soup_test_assert_message_status (msg, expected_status);
if (msg->status_code == SOUP_STATUS_OK)
- g_assert_cmpint (read_so_far, ==, correct_response->length);
+ g_assert_cmpint (read_so_far, ==, g_bytes_get_size (correct_response));
sync_async_cleanup (msg);
g_object_unref (msg);
@@ -424,7 +426,7 @@ sync_async_is_finished (SoupMessage *msg)
}
/* Tries to read a chunk. Returns %NULL on error/end-of-response. */
-static SoupBuffer *
+static GBytes *
sync_async_read_chunk (SoupMessage *msg)
{
SyncAsyncData *ad = g_object_get_data (G_OBJECT (msg), "SyncAsyncData");
@@ -445,11 +447,11 @@ sync_async_read_chunk (SoupMessage *msg)
}
static void
-sync_async_copy_chunk (SoupMessage *msg, SoupBuffer *chunk, gpointer user_data)
+sync_async_copy_chunk (SoupMessage *msg, GBytes *chunk, gpointer user_data)
{
SyncAsyncData *ad = user_data;
- ad->chunk = soup_buffer_copy (chunk);
+ ad->chunk = g_bytes_ref (chunk);
/* Now pause and return from the g_main_loop_run() call in
* sync_async_read_chunk().
@@ -525,7 +527,7 @@ main (int argc, char **argv)
ret = g_test_run ();
#ifdef HAVE_APACHE
- soup_buffer_free (correct_response);
+ g_bytes_unref (correct_response);
#endif
test_cleanup ();
diff --git a/tests/range-test.c b/tests/range-test.c
index d32b13f6..83b59694 100644
--- a/tests/range-test.c
+++ b/tests/range-test.c
@@ -2,7 +2,7 @@
#include "test-utils.h"
-SoupBuffer *full_response;
+GBytes *full_response;
int total_length;
char *test_response;
@@ -11,6 +11,7 @@ check_part (SoupMessageHeaders *headers, const char *body, gsize body_len,
gboolean check_start_end, int expected_start, int expected_end)
{
goffset start, end, total_length;
+ gsize full_response_length = g_bytes_get_size (full_response);
debug_printf (1, " Content-Range: %s\n",
soup_message_headers_get_one (headers, "Content-Range"));
@@ -20,7 +21,7 @@ check_part (SoupMessageHeaders *headers, const char *body, gsize body_len,
return;
}
- if (total_length != full_response->length && total_length != -1) {
+ if (total_length != full_response_length && total_length != -1) {
soup_test_assert (FALSE,
"Unexpected total length %" G_GINT64_FORMAT " in response\n",
total_length);
@@ -29,7 +30,7 @@ check_part (SoupMessageHeaders *headers, const char *body, gsize body_len,
if (check_start_end) {
if ((expected_start >= 0 && start != expected_start) ||
- (expected_start < 0 && start != full_response->length + expected_start)) {
+ (expected_start < 0 && start != full_response_length + expected_start)) {
soup_test_assert (FALSE,
"Unexpected range start %" G_GINT64_FORMAT " in response\n",
start);
@@ -37,7 +38,7 @@ check_part (SoupMessageHeaders *headers, const char *body, gsize body_len,
}
if ((expected_end >= 0 && end != expected_end) ||
- (expected_end < 0 && end != full_response->length - 1)) {
+ (expected_end < 0 && end != full_response_length - 1)) {
soup_test_assert (FALSE,
"Unexpected range end %" G_GINT64_FORMAT " in response\n",
end);
@@ -134,11 +135,11 @@ do_multi_range (SoupSession *session, SoupMessage *msg,
for (i = 0; i < length; i++) {
SoupMessageHeaders *headers;
- SoupBuffer *body;
+ GBytes *body;
debug_printf (1, " Part %d\n", i + 1);
soup_multipart_get_part (multipart, i, &headers, &body);
- check_part (headers, body->data, body->length, FALSE, 0, 0);
+ check_part (headers, g_bytes_get_data (body, NULL), g_bytes_get_size (body), FALSE, 0, 0);
}
soup_multipart_free (multipart);
@@ -223,9 +224,10 @@ static void
do_range_test (SoupSession *session, const char *uri,
gboolean expect_coalesce, gboolean expect_partial_coalesce)
{
- int twelfths = full_response->length / 12;
+ gsize full_response_length = g_bytes_get_size (full_response);
+ int twelfths = full_response_length / 12;
- memset (test_response, 0, full_response->length);
+ memset (test_response, 0, full_response_length);
/* We divide the response into 12 ranges and request them
* as follows:
@@ -306,22 +308,22 @@ do_range_test (SoupSession *session, const char *uri,
10 * twelfths - 5, 11 * twelfths,
expect_partial_coalesce ? 2 : 3);
- soup_assert_cmpmem (full_response->data, full_response->length,
- test_response, full_response->length);
+ soup_assert_cmpmem (g_bytes_get_data (full_response, NULL), full_response_length,
+ test_response, full_response_length);
debug_printf (1, "Requesting (invalid) %d-%d\n",
- (int) full_response->length + 1,
- (int) full_response->length + 100);
+ (int) full_response_length + 1,
+ (int) full_response_length + 100);
request_single_range (session, uri,
- full_response->length + 1, full_response->length + 100,
+ full_response_length + 1, full_response_length + 100,
FALSE);
debug_printf (1, "Requesting (semi-invalid) 1-10,%d-%d,20-30\n",
- (int) full_response->length + 1,
- (int) full_response->length + 100);
+ (int) full_response_length + 1,
+ (int) full_response_length + 100);
request_semi_invalid_range (session, uri,
1, 10,
- full_response->length + 1, full_response->length + 100,
+ full_response_length + 1, full_response_length + 100,
20, 30);
}
@@ -348,7 +350,7 @@ server_handler (SoupServer *server,
gpointer user_data)
{
soup_message_set_status (msg, SOUP_STATUS_OK);
- soup_message_body_append_buffer (msg->response_body,
+ soup_message_body_append_bytes (msg->response_body,
full_response);
}
@@ -383,7 +385,7 @@ main (int argc, char **argv)
apache_init ();
full_response = soup_test_get_index ();
- test_response = g_malloc0 (full_response->length);
+ test_response = g_malloc0 (g_bytes_get_size (full_response));
g_test_add_func ("/ranges/apache", do_apache_range_test);
g_test_add_func ("/ranges/libsoup", do_libsoup_range_test);
diff --git a/tests/resource-test.c b/tests/resource-test.c
index e048a2c8..22ff223b 100644
--- a/tests/resource-test.c
+++ b/tests/resource-test.c
@@ -5,7 +5,7 @@
#include "test-utils.h"
-SoupBuffer *index_buffer;
+GBytes *index_buffer;
typedef struct {
GString *body;
@@ -85,7 +85,8 @@ do_async_request (SoupRequest *request)
g_main_loop_unref (data.loop);
soup_assert_cmpmem (data.body->str, data.body->len,
- index_buffer->data, index_buffer->length);
+ g_bytes_get_data (index_buffer, NULL),
+ g_bytes_get_size (index_buffer));
g_string_free (data.body, TRUE);
}
@@ -128,7 +129,7 @@ do_request_data_test (gconstpointer type)
gchar *base64;
char *uri_string;
- base64 = g_base64_encode ((const guchar *)index_buffer->data, index_buffer->length);
+ base64 = g_base64_encode ((const guchar *)g_bytes_get_data (index_buffer, NULL), g_bytes_get_size (index_buffer));
uri_string = g_strdup_printf ("data:text/plain;charset=utf8;base64,%s", base64);
g_free (base64);
diff --git a/tests/server-test.c b/tests/server-test.c
index 2f2bb814..e6ef4d15 100644
--- a/tests/server-test.c
+++ b/tests/server-test.c
@@ -934,11 +934,11 @@ do_fail_500_test (ServerData *sd, gconstpointer pause)
}
static void
-stream_got_chunk (SoupMessage *msg, SoupBuffer *chunk, gpointer user_data)
+stream_got_chunk (SoupMessage *msg, GBytes *chunk, gpointer user_data)
{
GChecksum *checksum = user_data;
- g_checksum_update (checksum, (const guchar *)chunk->data, chunk->length);
+ g_checksum_update (checksum, g_bytes_get_data (chunk, NULL), g_bytes_get_size (chunk));
}
static void
@@ -979,7 +979,7 @@ do_early_stream_test (ServerData *sd, gconstpointer test_data)
{
SoupSession *session;
SoupMessage *msg;
- SoupBuffer *index;
+ GBytes *index;
char *md5;
server_add_early_handler (sd, NULL, early_stream_callback, NULL, NULL);
@@ -989,14 +989,12 @@ do_early_stream_test (ServerData *sd, gconstpointer test_data)
msg = soup_message_new_from_uri ("POST", sd->base_uri);
index = soup_test_get_index ();
- soup_message_body_append (msg->request_body, SOUP_MEMORY_COPY,
- index->data, index->length);
+ soup_message_body_append_bytes (msg->request_body, index);
soup_session_send_message (session, msg);
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
- md5 = g_compute_checksum_for_data (G_CHECKSUM_MD5,
- (guchar *) index->data, index->length);
+ md5 = g_compute_checksum_for_bytes (G_CHECKSUM_MD5, index);
g_assert_cmpstr (md5, ==, msg->response_body->data);
g_free (md5);
diff --git a/tests/sniffing-test.c b/tests/sniffing-test.c
index 85b66810..6b85cc01 100644
--- a/tests/sniffing-test.c
+++ b/tests/sniffing-test.c
@@ -16,7 +16,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
{
GError *error = NULL;
char *query_key;
- SoupBuffer *response = NULL;
+ GBytes *response = NULL;
gsize offset;
gboolean empty_response = FALSE;
@@ -118,14 +118,14 @@ server_callback (SoupServer *server, SoupMessage *msg,
}
if (response) {
- for (offset = 0; offset < response->length; offset += 500) {
- soup_message_body_append (msg->response_body,
- SOUP_MEMORY_COPY,
- response->data + offset,
- MIN (500, response->length - offset));
+ gsize response_size = g_bytes_get_size (response);
+ for (offset = 0; offset < response_size; offset += 500) {
+ GBytes *chunk = g_bytes_new_from_bytes (response, offset, MIN (500, response_size - offset));
+ soup_message_body_append_bytes (msg->response_body, chunk);
+ g_bytes_unref (chunk);
}
- soup_buffer_free (response);
+ g_bytes_unref (response);
}
soup_message_body_complete (msg->response_body);
@@ -180,7 +180,7 @@ got_headers (SoupMessage *msg, gpointer data)
}
static void
-got_chunk (SoupMessage *msg, SoupBuffer *chunk, gpointer data)
+got_chunk (SoupMessage *msg, GBytes *chunk, gpointer data)
{
gboolean should_accumulate = GPOINTER_TO_INT (data);
@@ -191,7 +191,7 @@ got_chunk (SoupMessage *msg, SoupBuffer *chunk, gpointer data)
if (!should_accumulate) {
if (!chunk_data)
chunk_data = soup_message_body_new ();
- soup_message_body_append_buffer (chunk_data, chunk);
+ soup_message_body_append_bytes (chunk_data, chunk);
}
}
@@ -204,9 +204,9 @@ do_signals_test (gboolean should_content_sniff,
{
SoupURI *uri = soup_uri_new_with_base (base_uri, "/mbox");
SoupMessage *msg = soup_message_new_from_uri ("GET", uri);
- SoupBuffer *expected;
+ GBytes *expected;
GError *error = NULL;
- SoupBuffer *body = NULL;
+ GBytes *body = NULL;
debug_printf (1, "do_signals_test(%ssniff, %spause, %saccumulate, %schunked, %sempty)\n",
should_content_sniff ? "" : "!",
@@ -248,7 +248,7 @@ do_signals_test (gboolean should_content_sniff,
}
if (empty_response)
- expected = soup_buffer_new (SOUP_MEMORY_STATIC, "", 0);
+ expected = g_bytes_new_static (NULL, 0);
else {
expected = soup_test_load_resource ("mbox", &error);
g_assert_no_error (error);
@@ -260,18 +260,14 @@ do_signals_test (gboolean should_content_sniff,
body = soup_message_body_flatten (msg->response_body);
if (body) {
- soup_assert_cmpmem (body->data, body->length,
- expected->data, expected->length);
- }
-
- soup_buffer_free (expected);
- if (body)
- soup_buffer_free (body);
- if (chunk_data) {
- soup_message_body_free (chunk_data);
- chunk_data = NULL;
+ //g_message ("|||body (%zu): %s", g_bytes_get_size (body), (char*)g_bytes_get_data (body, NULL));
+ //g_message ("|||expected (%zu): %s", g_bytes_get_size (expected), (char*)g_bytes_get_data (expected, NULL));
+ g_assert_true (g_bytes_equal (body, expected));
}
+ g_bytes_unref (expected);
+ g_bytes_unref (body);
+ g_clear_pointer (&chunk_data, soup_message_body_free);
soup_uri_free (uri);
g_object_unref (msg);
}
diff --git a/tests/streaming-test.c b/tests/streaming-test.c
index 9654541e..b4091938 100644
--- a/tests/streaming-test.c
+++ b/tests/streaming-test.c
@@ -7,7 +7,7 @@
#define RESPONSE_CHUNK_SIZE 1024
-SoupBuffer *full_response;
+GBytes *full_response;
char *full_response_md5;
static void
@@ -16,13 +16,12 @@ write_next_chunk (SoupMessage *msg, gpointer user_data)
gsize *offset = user_data;
gsize chunk_length;
- chunk_length = MIN (RESPONSE_CHUNK_SIZE, full_response->length - *offset);
+ chunk_length = MIN (RESPONSE_CHUNK_SIZE, g_bytes_get_size (full_response) - *offset);
if (chunk_length > 0) {
debug_printf (2, " writing chunk\n");
- soup_message_body_append (msg->response_body,
- SOUP_MEMORY_STATIC,
- full_response->data + *offset,
- chunk_length);
+ GBytes *chunk = g_bytes_new_from_bytes (full_response, *offset, chunk_length);
+ soup_message_body_append_bytes (msg->response_body, chunk);
+ g_bytes_unref (chunk);
*offset += chunk_length;
} else {
debug_printf (2, " done\n");
@@ -54,7 +53,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
soup_message_headers_set_encoding (msg->response_headers,
SOUP_ENCODING_CONTENT_LENGTH);
soup_message_headers_set_content_length (msg->response_headers,
- full_response->length);
+ g_bytes_get_size (full_response));
} else if (!strcmp (path, "/eof")) {
soup_message_headers_set_encoding (msg->response_headers,
SOUP_ENCODING_EOF);
@@ -87,7 +86,7 @@ do_request (SoupSession *session, SoupURI *base_uri, char *path)
soup_test_session_async_send_message (session, msg);
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
- g_assert_cmpint (msg->response_body->length, ==, full_response->length);
+ g_assert_cmpint (msg->response_body->length, ==, g_bytes_get_size (full_response));
md5 = g_compute_checksum_for_data (G_CHECKSUM_MD5,
(guchar *)msg->response_body->data,
@@ -144,9 +143,7 @@ main (int argc, char **argv)
test_init (argc, argv, NULL);
full_response = soup_test_get_index ();
- full_response_md5 = g_compute_checksum_for_data (G_CHECKSUM_MD5,
- (guchar *)full_response->data,
- full_response->length);
+ full_response_md5 = g_compute_checksum_for_bytes (G_CHECKSUM_MD5, full_response);
server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
soup_server_add_handler (server, NULL,
diff --git a/tests/test-utils.c b/tests/test-utils.c
index 1315bcff..036bb9c5 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -13,7 +13,7 @@ static gboolean apache_running;
#endif
static SoupLogger *logger;
-static SoupBuffer *index_buffer;
+static GBytes *index_buffer;
int debug_level;
gboolean expect_warning, tls_available;
@@ -112,7 +112,7 @@ test_cleanup (void)
if (logger)
g_object_unref (logger);
if (index_buffer)
- soup_buffer_free (index_buffer);
+ g_bytes_unref (index_buffer);
g_main_context_unref (g_main_context_default ());
@@ -762,7 +762,7 @@ soup_test_register_resources (void)
registered = TRUE;
}
-SoupBuffer *
+GBytes *
soup_test_load_resource (const char *name,
GError **error)
{
@@ -775,16 +775,10 @@ soup_test_load_resource (const char *name,
bytes = g_resources_lookup_data (path, G_RESOURCE_LOOKUP_FLAGS_NONE, error);
g_free (path);
- if (!bytes)
- return NULL;
-
- return soup_buffer_new_with_owner (g_bytes_get_data (bytes, NULL),
- g_bytes_get_size (bytes),
- bytes,
- (GDestroyNotify) g_bytes_unref);
+ return bytes;
}
-SoupBuffer *
+GBytes *
soup_test_get_index (void)
{
if (!index_buffer) {
@@ -800,7 +794,7 @@ soup_test_get_index (void)
}
g_free (path);
- index_buffer = soup_buffer_new (SOUP_MEMORY_TAKE, contents, length);
+ index_buffer = g_bytes_new_take (contents, length);
}
return index_buffer;
diff --git a/tests/test-utils.h b/tests/test-utils.h
index ba062129..0586df9a 100644
--- a/tests/test-utils.h
+++ b/tests/test-utils.h
@@ -83,10 +83,10 @@ gboolean soup_test_request_close_stream (SoupRequest *req,
GError **error);
void soup_test_register_resources (void);
-SoupBuffer *soup_test_load_resource (const char *name,
+GBytes *soup_test_load_resource (const char *name,
GError **error);
-SoupBuffer *soup_test_get_index (void);
+GBytes *soup_test_get_index (void);
#ifdef G_HAVE_ISO_VARARGS
#define soup_test_assert(expr, ...) \