diff options
Diffstat (limited to 'libsoup/content-sniffer')
-rw-r--r-- | libsoup/content-sniffer/soup-content-sniffer-stream.c | 14 | ||||
-rw-r--r-- | libsoup/content-sniffer/soup-content-sniffer.c | 27 | ||||
-rw-r--r-- | libsoup/content-sniffer/soup-content-sniffer.h | 12 |
3 files changed, 13 insertions, 40 deletions
diff --git a/libsoup/content-sniffer/soup-content-sniffer-stream.c b/libsoup/content-sniffer/soup-content-sniffer-stream.c index b3e107e9..30a7b372 100644 --- a/libsoup/content-sniffer/soup-content-sniffer-stream.c +++ b/libsoup/content-sniffer/soup-content-sniffer-stream.c @@ -34,7 +34,7 @@ typedef struct { SoupMessage *msg; guchar *buffer; - gsize buffer_size, buffer_nread; + gsize buffer_nread; gboolean sniffing; GError *error; @@ -42,6 +42,8 @@ typedef struct { GHashTable *sniffed_params; } SoupContentSnifferStreamPrivate; +#define BUFFER_SIZE 512 + static void soup_content_sniffer_stream_pollable_init (GPollableInputStreamInterface *pollable_interface, gpointer interface_data); G_DEFINE_TYPE_WITH_CODE (SoupContentSnifferStream, soup_content_sniffer_stream, G_TYPE_FILTER_INPUT_STREAM, @@ -75,9 +77,6 @@ soup_content_sniffer_stream_set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_SNIFFER: priv->sniffer = g_value_dup_object (value); - /* FIXME: supposed to wait until after got-headers for this */ - priv->buffer_size = soup_content_sniffer_get_buffer_size (priv->sniffer); - priv->buffer = g_malloc (priv->buffer_size); break; case PROP_MESSAGE: priv->msg = g_value_dup_object (value); @@ -118,15 +117,18 @@ read_and_sniff (GInputStream *stream, gboolean blocking, GError *my_error = NULL; GBytes *buf; + if (!priv->buffer) + priv->buffer = g_malloc (BUFFER_SIZE); + do { nread = g_pollable_stream_read (G_FILTER_INPUT_STREAM (stream)->base_stream, priv->buffer + priv->buffer_nread, - priv->buffer_size - priv->buffer_nread, + BUFFER_SIZE - priv->buffer_nread, blocking, cancellable, &my_error); if (nread <= 0) break; priv->buffer_nread += nread; - } while (priv->buffer_nread < priv->buffer_size); + } while (priv->buffer_nread < BUFFER_SIZE); /* If we got EAGAIN or cancellation before filling the buffer, * just return that right away. Likewise if we got any other diff --git a/libsoup/content-sniffer/soup-content-sniffer.c b/libsoup/content-sniffer/soup-content-sniffer.c index 0b8c6749..7319a7f9 100644 --- a/libsoup/content-sniffer/soup-content-sniffer.c +++ b/libsoup/content-sniffer/soup-content-sniffer.c @@ -867,36 +867,11 @@ soup_content_sniffer_sniff (SoupContentSniffer *sniffer, SoupMessage *msg, return g_strdup (content_type); } -/** - * soup_content_sniffer_get_buffer_size: - * @sniffer: a #SoupContentSniffer - * - * Gets the number of bytes @sniffer needs in order to properly sniff - * a buffer. - * - * Returns: the number of bytes to sniff - * - */ -gsize -soup_content_sniffer_get_buffer_size (SoupContentSniffer *sniffer) -{ - return 512; -} - -static void -soup_content_sniffer_got_headers_cb (SoupMessage *msg, SoupContentSniffer *sniffer) -{ - soup_message_set_bytes_for_sniffing (msg, soup_content_sniffer_get_buffer_size (sniffer)); -} - static void soup_content_sniffer_request_queued (SoupSessionFeature *feature, SoupMessage *msg) { soup_message_set_content_sniffer (msg, SOUP_CONTENT_SNIFFER (feature)); - g_signal_connect (msg, "got-headers", - G_CALLBACK (soup_content_sniffer_got_headers_cb), - feature); } static void @@ -904,8 +879,6 @@ soup_content_sniffer_request_unqueued (SoupSessionFeature *feature, SoupMessage *msg) { soup_message_set_content_sniffer (msg, NULL); - - g_signal_handlers_disconnect_by_func (msg, soup_content_sniffer_got_headers_cb, feature); } static void diff --git a/libsoup/content-sniffer/soup-content-sniffer.h b/libsoup/content-sniffer/soup-content-sniffer.h index 19f204d3..7f23b65d 100644 --- a/libsoup/content-sniffer/soup-content-sniffer.h +++ b/libsoup/content-sniffer/soup-content-sniffer.h @@ -15,15 +15,13 @@ SOUP_AVAILABLE_IN_ALL G_DECLARE_FINAL_TYPE (SoupContentSniffer, soup_content_sniffer, SOUP, CONTENT_SNIFFER, GObject) SOUP_AVAILABLE_IN_ALL -SoupContentSniffer *soup_content_sniffer_new (void); +SoupContentSniffer *soup_content_sniffer_new (void); SOUP_AVAILABLE_IN_ALL -char *soup_content_sniffer_sniff (SoupContentSniffer *sniffer, - SoupMessage *msg, - GBytes *buffer, - GHashTable **params); -SOUP_AVAILABLE_IN_ALL -gsize soup_content_sniffer_get_buffer_size (SoupContentSniffer *sniffer); +char *soup_content_sniffer_sniff (SoupContentSniffer *sniffer, + SoupMessage *msg, + GBytes *buffer, + GHashTable **params); G_END_DECLS |