[libsoup] Make it possibe to request the boundary be discarded by SoupFilterInputStream
- From: Gustavo Noronha Silva <gns src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] Make it possibe to request the boundary be discarded by SoupFilterInputStream
- Date: Mon, 20 Aug 2012 18:02:55 +0000 (UTC)
commit 207b8aa56d272e20d5d3e052753e15b8fb43214f
Author: Gustavo Noronha Silva <gustavo noronha collabora com>
Date: Mon Aug 20 10:37:41 2012 -0300
Make it possibe to request the boundary be discarded by SoupFilterInputStream
This makes it easier to implement streams that discard the boundary, like
SoupMultipartInputStream.
https://bugzilla.gnome.org/show_bug.cgi?id=656684
libsoup/soup-filter-input-stream.c | 18 +++++++++++-------
libsoup/soup-filter-input-stream.h | 1 +
libsoup/soup-socket.c | 2 +-
3 files changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/libsoup/soup-filter-input-stream.c b/libsoup/soup-filter-input-stream.c
index 79159c3..f8c7251 100644
--- a/libsoup/soup-filter-input-stream.c
+++ b/libsoup/soup-filter-input-stream.c
@@ -177,7 +177,7 @@ soup_filter_input_stream_read_line (SoupFilterInputStream *fstream,
{
return soup_filter_input_stream_read_until (fstream, buffer, length,
"\n", 1, blocking,
- got_line,
+ TRUE, got_line,
cancellable, error);
}
@@ -188,6 +188,7 @@ soup_filter_input_stream_read_until (SoupFilterInputStream *fstream,
const void *boundary,
gsize boundary_length,
gboolean blocking,
+ gboolean include_boundary,
gboolean *got_boundary,
GCancellable *cancellable,
GError **error)
@@ -197,7 +198,7 @@ soup_filter_input_stream_read_until (SoupFilterInputStream *fstream,
gboolean eof = FALSE;
g_return_val_if_fail (SOUP_IS_FILTER_INPUT_STREAM (fstream), -1);
- g_return_val_if_fail (boundary_length < length, -1);
+ g_return_val_if_fail (!include_boundary || (boundary_length < length), -1);
*got_boundary = FALSE;
@@ -237,8 +238,10 @@ soup_filter_input_stream_read_until (SoupFilterInputStream *fstream,
if (!eof)
end -= boundary_length;
for (p = buf; p <= end; p++) {
- if (!memcmp (p, boundary, boundary_length)) {
- p += boundary_length;
+ if (*p == *(guint8*)boundary &&
+ !memcmp (p, boundary, boundary_length)) {
+ if (include_boundary)
+ p += boundary_length;
*got_boundary = TRUE;
break;
}
@@ -247,9 +250,10 @@ soup_filter_input_stream_read_until (SoupFilterInputStream *fstream,
if (!*got_boundary && fstream->priv->buf->len < length && !eof)
goto fill_buffer;
- /* Return everything up to 'p' (which is either just after the
- * boundary, @boundary_len - 1 bytes before the end of the
- * buffer, or end-of-file).
+ /* Return everything up to 'p' (which is either just after the boundary if
+ * include_boundary is TRUE, just before the boundary if include_boundary is
+ * FALSE, @boundary_len - 1 bytes before the end of the buffer, or end-of-
+ * file).
*/
return read_from_buf (fstream, buffer, p - buf);
}
diff --git a/libsoup/soup-filter-input-stream.h b/libsoup/soup-filter-input-stream.h
index b86a476..276b60f 100644
--- a/libsoup/soup-filter-input-stream.h
+++ b/libsoup/soup-filter-input-stream.h
@@ -47,6 +47,7 @@ gssize soup_filter_input_stream_read_until (SoupFilterInputStream *fstre
const void *boundary,
gsize boundary_len,
gboolean blocking,
+ gboolean include_boundary,
gboolean *got_boundary,
GCancellable *cancellable,
GError **error);
diff --git a/libsoup/soup-socket.c b/libsoup/soup-socket.c
index f44cf34..a9d6bd5 100644
--- a/libsoup/soup-socket.c
+++ b/libsoup/soup-socket.c
@@ -1565,7 +1565,7 @@ soup_socket_read_until (SoupSocket *sock, gpointer buffer, gsize len,
SOUP_FILTER_INPUT_STREAM (priv->istream),
buffer, len, boundary, boundary_len,
!priv->non_blocking,
- got_boundary, cancellable, &my_err);
+ TRUE, got_boundary, cancellable, &my_err);
status = translate_read_status (sock, cancellable,
my_nread, nread, my_err, error);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]