[libsoup/wip/new-master: 12/57] Remove deprecated SoupChunkAllocator APIs




commit 34379c7d345d816290553fe8fe8626084f183c0d
Author: Patrick Griffis <pgriffis igalia com>
Date:   Wed Feb 12 13:59:25 2020 -0800

    Remove deprecated SoupChunkAllocator APIs

 docs/reference/libsoup-2.4-sections.txt |   2 -
 libsoup/soup-message-io.c               |  19 ++----
 libsoup/soup-message-private.h          |   8 ---
 libsoup/soup-message.c                  | 108 --------------------------------
 libsoup/soup-message.h                  |  14 -----
 tests/chunk-test.c                      |  71 ---------------------
 6 files changed, 5 insertions(+), 217 deletions(-)
---
diff --git a/docs/reference/libsoup-2.4-sections.txt b/docs/reference/libsoup-2.4-sections.txt
index 17fe6462..65f4138f 100644
--- a/docs/reference/libsoup-2.4-sections.txt
+++ b/docs/reference/libsoup-2.4-sections.txt
@@ -31,8 +31,6 @@ soup_message_add_status_code_handler
 SoupMessageFlags
 soup_message_set_flags
 soup_message_get_flags
-SoupChunkAllocator
-soup_message_set_chunk_allocator
 <SUBSECTION>
 soup_message_disable_feature
 soup_message_is_feature_disabled
diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c
index c5412abb..a005fa93 100644
--- a/libsoup/soup-message-io.c
+++ b/libsoup/soup-message-io.c
@@ -752,20 +752,11 @@ io_read (SoupMessage *msg, gboolean blocking,
 
 
        case SOUP_MESSAGE_IO_STATE_BODY:
-               if (soup_message_has_chunk_allocator (msg)) {
-                       buffer = soup_message_allocate_chunk (msg, io->read_length);
-                       if (!buffer) {
-                               g_return_val_if_fail (!io->item || !io->item->new_api, FALSE);
-                               soup_message_io_pause (msg);
-                               return FALSE;
-                       }
-               } else {
-                       if (!stack_buf)
-                               stack_buf = alloca (RESPONSE_BLOCK_SIZE);
-                       buffer = soup_buffer_new (SOUP_MEMORY_TEMPORARY,
-                                                 stack_buf,
-                                                 RESPONSE_BLOCK_SIZE);
-               }
+               if (!stack_buf)
+                       stack_buf = alloca (RESPONSE_BLOCK_SIZE);
+               buffer = soup_buffer_new (SOUP_MEMORY_TEMPORARY,
+                                               stack_buf,
+                                               RESPONSE_BLOCK_SIZE);
 
                nread = g_pollable_stream_read (io->body_istream,
                                                (guchar *)buffer->data,
diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h
index c30361c0..193f226b 100644
--- a/libsoup/soup-message-private.h
+++ b/libsoup/soup-message-private.h
@@ -15,10 +15,6 @@
 typedef struct {
        gpointer           io_data;
 
-       SoupChunkAllocator chunk_allocator;
-       gpointer           chunk_allocator_data;
-       GDestroyNotify     chunk_allocator_dnotify;
-
        guint              msg_flags;
        gboolean           server_side;
 
@@ -175,8 +171,4 @@ void                soup_message_set_content_sniffer    (SoupMessage        *msg
 void                soup_message_set_bytes_for_sniffing (SoupMessage        *msg,
                                                         gsize               bytes);
 
-gboolean    soup_message_has_chunk_allocator (SoupMessage *msg);
-SoupBuffer *soup_message_allocate_chunk      (SoupMessage *msg,
-                                             goffset      read_length);
-
 #endif /* __SOUP_MESSAGE_PRIVATE_H__ */
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index 8b7b7d80..c3738c06 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -171,8 +171,6 @@ soup_message_finalize (GObject *object)
        SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
 
        soup_message_io_cleanup (msg);
-       if (priv->chunk_allocator_dnotify)
-               priv->chunk_allocator_dnotify (priv->chunk_allocator_data);
 
        g_clear_pointer (&priv->uri, soup_uri_free);
        g_clear_pointer (&priv->first_party, soup_uri_free);
@@ -1773,95 +1771,6 @@ soup_message_set_status_full (SoupMessage *msg,
        g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_REASON_PHRASE);
 }
 
-/**
- * SoupChunkAllocator:
- * @msg: the #SoupMessage the chunk is being allocated for
- * @max_len: the maximum length that will be read, or 0.
- * @user_data: the data passed to soup_message_set_chunk_allocator()
- *
- * The prototype for a chunk allocation callback. This should allocate
- * a new #SoupBuffer and return it for the I/O layer to read message
- * body data off the network into.
- *
- * If @max_len is non-0, it indicates the maximum number of bytes that
- * could be read, based on what is known about the message size. Note
- * that this might be a very large number, and you should not simply
- * try to allocate that many bytes blindly. If @max_len is 0, that
- * means that libsoup does not know how many bytes remain to be read,
- * and the allocator should return a buffer of a size that it finds
- * convenient.
- *
- * If the allocator returns %NULL, the message will be paused. It is
- * up to the application to make sure that it gets unpaused when it
- * becomes possible to allocate a new buffer.
- *
- * Return value: (nullable): the new buffer (or %NULL)
- *
- * Deprecated: Use #SoupRequest if you want to read into your
- * own buffers.
- **/
-
-/**
- * soup_message_set_chunk_allocator:
- * @msg: a #SoupMessage
- * @allocator: the chunk allocator callback
- * @user_data: data to pass to @allocator
- * @destroy_notify: destroy notifier to free @user_data when @msg is
- * destroyed
- *
- * Sets an alternate chunk-allocation function to use when reading
- * @msg's body when using the traditional (ie,
- * non-#SoupRequest<!-- -->-based) API. Every time data is available
- * to read, libsoup will call @allocator, which should return a
- * #SoupBuffer. (See #SoupChunkAllocator for additional details.)
- * Libsoup will then read data from the network into that buffer, and
- * update the buffer's <literal>length</literal> to indicate how much
- * data it read.
- *
- * Generally, a custom chunk allocator would be used in conjunction
- * with soup_message_body_set_accumulate() %FALSE and
- * #SoupMessage::got_chunk, as part of a strategy to avoid unnecessary
- * copying of data. However, you cannot assume that every call to the
- * allocator will be followed by a call to your
- * #SoupMessage::got_chunk handler; if an I/O error occurs, then the
- * buffer will be unreffed without ever having been used. If your
- * buffer-allocation strategy requires special cleanup, use
- * soup_buffer_new_with_owner() rather than doing the cleanup from the
- * #SoupMessage::got_chunk handler.
- *
- * The other thing to remember when using non-accumulating message
- * bodies is that the buffer passed to the #SoupMessage::got_chunk
- * handler will be unreffed after the handler returns, just as it
- * would be in the non-custom-allocated case. If you want to hand the
- * chunk data off to some other part of your program to use later,
- * you'll need to ref the #SoupBuffer (or its owner, in the
- * soup_buffer_new_with_owner() case) to ensure that the data remains
- * valid.
- *
- * Deprecated: #SoupRequest provides a much simpler API that lets you
- * read the response directly into your own buffers without needing to
- * mess with callbacks, pausing/unpausing, etc.
- **/
-void
-soup_message_set_chunk_allocator (SoupMessage *msg,
-                                 SoupChunkAllocator allocator,
-                                 gpointer user_data,
-                                 GDestroyNotify destroy_notify)
-{
-       SoupMessagePrivate *priv;
-
-       g_return_if_fail (SOUP_IS_MESSAGE (msg));
-
-       priv = soup_message_get_instance_private (msg);
-
-       if (priv->chunk_allocator_dnotify)
-               priv->chunk_allocator_dnotify (priv->chunk_allocator_data);
-
-       priv->chunk_allocator         = allocator;
-       priv->chunk_allocator_data    = user_data;
-       priv->chunk_allocator_dnotify = destroy_notify;
-}
-
 /**
  * soup_message_disable_feature:
  * @msg: a #SoupMessage
@@ -2364,20 +2273,3 @@ soup_message_set_bytes_for_sniffing (SoupMessage *msg, gsize bytes)
 
        priv->bytes_for_sniffing = bytes;
 }
-
-gboolean
-soup_message_has_chunk_allocator (SoupMessage *msg)
-{
-       SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
-
-       return priv->chunk_allocator != NULL;
-}
-
-SoupBuffer *
-soup_message_allocate_chunk (SoupMessage *msg,
-                            goffset read_length)
-{
-       SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
-
-       return priv->chunk_allocator (msg, read_length, priv->chunk_allocator_data);
-}
diff --git a/libsoup/soup-message.h b/libsoup/soup-message.h
index 8eb0f5c9..ed8d605e 100644
--- a/libsoup/soup-message.h
+++ b/libsoup/soup-message.h
@@ -196,20 +196,6 @@ void           soup_message_set_redirect        (SoupMessage       *msg,
                                                 guint              status_code,
                                                 const char        *redirect_uri);
 
-/* I/O */
-#ifndef SOUP_DISABLE_DEPRECATED
-typedef SoupBuffer * (*SoupChunkAllocator)      (SoupMessage       *msg,
-                                                gsize              max_len,
-                                                gpointer           user_data);
-
-SOUP_AVAILABLE_IN_2_4
-SOUP_DEPRECATED_IN_2_42_FOR(SoupRequest)
-void           soup_message_set_chunk_allocator (SoupMessage       *msg,
-                                                SoupChunkAllocator allocator,
-                                                gpointer           user_data,
-                                                GDestroyNotify     destroy_notify);
-#endif
-
 SOUP_AVAILABLE_IN_2_28
 void           soup_message_disable_feature     (SoupMessage       *msg,
                                                 GType              feature_type);
diff --git a/tests/chunk-test.c b/tests/chunk-test.c
index c658cbd4..79d5b640 100644
--- a/tests/chunk-test.c
+++ b/tests/chunk-test.c
@@ -211,76 +211,6 @@ do_request_test (gconstpointer data)
        soup_uri_free (uri);
 }
 
-typedef struct {
-       SoupBuffer *current_chunk;
-       GChecksum *check;
-       int length;
-} GetTestData;
-
-static SoupBuffer *
-chunk_allocator (SoupMessage *msg, gsize max_len, gpointer user_data)
-{
-       GetTestData *gtd = user_data;
-
-       debug_printf (2, "  allocating chunk\n");
-
-       soup_test_assert (gtd->current_chunk == NULL,
-                         "error: next chunk allocated before last one freed");
-       gtd->current_chunk = soup_buffer_new_with_owner (g_malloc (6), 6,
-                                                        &gtd->current_chunk,
-                                                        clear_buffer_ptr);
-       return gtd->current_chunk;
-}
-
-static void
-got_chunk (SoupMessage *msg, SoupBuffer *chunk, gpointer user_data)
-{
-       GetTestData *gtd = user_data;
-
-       debug_printf (2, "  got chunk, %d bytes\n",
-                     (int)chunk->length);
-       if (chunk != gtd->current_chunk) {
-               debug_printf (1, "chunk mismatch! %p vs %p\n",
-                             chunk, gtd->current_chunk);
-       }
-
-       g_checksum_update (gtd->check, (guchar *)chunk->data, chunk->length);
-       gtd->length += chunk->length;
-}
-
-static void
-do_response_test (void)
-{
-       GetTestData gtd;
-       SoupMessage *msg;
-       const char *client_md5, *server_md5;
-
-       gtd.current_chunk = NULL;
-       gtd.length = 0;
-       gtd.check = g_checksum_new (G_CHECKSUM_MD5);
-
-       msg = soup_message_new_from_uri ("GET", base_uri);
-       soup_message_body_set_accumulate (msg->response_body, FALSE);
-       G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
-       soup_message_set_chunk_allocator (msg, chunk_allocator, &gtd, NULL);
-       G_GNUC_END_IGNORE_DEPRECATIONS;
-       g_signal_connect (msg, "got_chunk",
-                         G_CALLBACK (got_chunk), &gtd);
-       soup_session_send_message (session, msg);
-
-       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
-       g_assert_null (msg->response_body->data);
-       g_assert_cmpint (soup_message_headers_get_content_length (msg->response_headers), ==, gtd.length);
-
-       client_md5 = g_checksum_get_string (gtd.check);
-       server_md5 = soup_message_headers_get_one (msg->response_headers,
-                                                  "Content-MD5");
-       g_assert_cmpstr (client_md5, ==, server_md5);
-
-       g_object_unref (msg);
-       g_checksum_free (gtd.check);
-}
-
 /* Make sure TEMPORARY buffers are handled properly with non-accumulating
  * message bodies.
  */
@@ -446,7 +376,6 @@ main (int argc, char **argv)
        g_test_add_data_func ("/chunks/request/proper-streaming/restart", GINT_TO_POINTER (PROPER_STREAMING | 
RESTART), do_request_test);
        g_test_add_data_func ("/chunks/request/hacky-streaming", GINT_TO_POINTER (HACKY_STREAMING), 
do_request_test);
        g_test_add_data_func ("/chunks/request/hacky-streaming/restart", GINT_TO_POINTER (HACKY_STREAMING | 
RESTART), do_request_test);
-       g_test_add_func ("/chunks/response", do_response_test);
        g_test_add_func ("/chunks/temporary", do_temporary_test);
        g_test_add_func ("/chunks/large", do_large_chunk_test);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]