[gmime] Added GMimeStreamFilter:owner
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Added GMimeStreamFilter:owner
- Date: Sat, 18 Mar 2017 11:51:08 +0000 (UTC)
commit 66b651b084fdde1ec30049528d0c7f0a7b805b30
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date: Sat Mar 18 07:23:58 2017 -0400
Added GMimeStreamFilter:owner
Also don't flush the source stream when we flush the filtered stream.
gmime/gmime-stream-filter.c | 49 +++++++++++++++++++++++++++++++++++++++---
gmime/gmime-stream-filter.h | 4 +++
2 files changed, 49 insertions(+), 4 deletions(-)
---
diff --git a/gmime/gmime-stream-filter.c b/gmime/gmime-stream-filter.c
index e5a90ee..faa4471 100644
--- a/gmime/gmime-stream-filter.c
+++ b/gmime/gmime-stream-filter.c
@@ -139,6 +139,7 @@ static void
g_mime_stream_filter_init (GMimeStreamFilter *stream, GMimeStreamFilterClass *klass)
{
stream->source = NULL;
+ stream->owner = FALSE;
stream->priv = g_new (struct _GMimeStreamFilterPrivate, 1);
stream->priv->filters = NULL;
stream->priv->filterid = 0;
@@ -287,7 +288,7 @@ stream_flush (GMimeStream *stream)
if (len > 0 && g_mime_stream_write (filter->source, buffer, len) == -1)
return -1;
- return g_mime_stream_flush (filter->source);
+ return 0;
}
static int
@@ -299,7 +300,10 @@ stream_close (GMimeStream *stream)
if (!priv->last_was_read)
stream_flush (stream);
- return g_mime_stream_close (filter->source);
+ if (filter->owner)
+ return g_mime_stream_close (filter->source);
+
+ return 0;
}
static gboolean
@@ -392,9 +396,9 @@ stream_substream (GMimeStream *stream, gint64 start, gint64 end)
sub->priv->filterid = filter->priv->filterid;
}
- g_mime_stream_construct (GMIME_STREAM (filter), start, end);
+ g_mime_stream_construct ((GMimeStream *) filter, start, end);
- return GMIME_STREAM (sub);
+ return (GMimeStream *) sub;
}
@@ -497,3 +501,40 @@ g_mime_stream_filter_remove (GMimeStreamFilter *stream, int id)
f = f->next;
}
}
+
+
+/**
+ * g_mime_stream_filter_set_owner:
+ * @stream: a #GMimeStreamFilter
+ * @owner: %TRUE if this stream should own the source stream or %FALSE otherwise
+ *
+ * Sets whether or not @stream owns the source stream..
+ *
+ * Note: @owner should be %TRUE if the stream should close() the
+ * backend source stream when destroyed or %FALSE otherwise.
+ **/
+void
+g_mime_stream_filter_set_owner (GMimeStreamFilter *stream, gboolean owner)
+{
+ g_return_if_fail (GMIME_IS_STREAM_FILTER (stream));
+
+ stream->owner = owner;
+}
+
+
+/**
+ * g_mime_stream_filter_get_owner:
+ * @stream: a #GMimeStreamFilter
+ *
+ * Gets whether or not @stream owns the source stream.
+ *
+ * Returns: %TRUE if @stream owns the source stream or %FALSE
+ * otherwise.
+ **/
+gboolean
+g_mime_stream_filter_get_owner (GMimeStreamFilter *stream)
+{
+ g_return_val_if_fail (GMIME_IS_STREAM_FILTER (stream), FALSE);
+
+ return stream->owner;
+}
diff --git a/gmime/gmime-stream-filter.h b/gmime/gmime-stream-filter.h
index a4544b4..58c5bd6 100644
--- a/gmime/gmime-stream-filter.h
+++ b/gmime/gmime-stream-filter.h
@@ -51,6 +51,7 @@ struct _GMimeStreamFilter {
struct _GMimeStreamFilterPrivate *priv;
GMimeStream *source;
+ gboolean owner;
};
struct _GMimeStreamFilterClass {
@@ -66,6 +67,9 @@ GMimeStream *g_mime_stream_filter_new (GMimeStream *stream);
int g_mime_stream_filter_add (GMimeStreamFilter *stream, GMimeFilter *filter);
void g_mime_stream_filter_remove (GMimeStreamFilter *stream, int id);
+void g_mime_stream_filter_set_owner (GMimeStreamFilter *stream, gboolean owner);
+gboolean g_mime_stream_filter_get_owner (GMimeStreamFilter *stream);
+
G_END_DECLS
#endif /* __GMIME_STREAM_FILTER_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]