#ifndef G_OS_WIN32
if (is->is_process_stream) {
GPollFD fds[2] = { {0, 0, 0}, {0, 0, 0} };
+ CamelStream *source;
gint res;
- fds[0].fd = ((CamelStreamProcess *) is->stream->source)->sockfd;
+ source = camel_imapx_stream_ref_source (is->stream);
+
+ fds[0].fd = CAMEL_STREAM_PROCESS (source)->sockfd;
fds[0].events = G_IO_IN;
fds[1].fd = g_cancellable_get_fd (cancellable);
fds[1].events = G_IO_IN;
else if (fds[0].revents & G_IO_IN)
parse_contents (is, cancellable, &local_error);
g_cancellable_release_fd (cancellable);
+
+ g_object_unref (source);
} else
#endif
{
g_static_rec_mutex_lock (&is->ostream_lock);
if (is->stream) {
- if (camel_stream_close (is->stream->source, NULL, NULL) == -1)
+ CamelStream *source;
+
+ source = camel_imapx_stream_ref_source (is->stream);
+ if (camel_stream_close (source, NULL, NULL) == -1)
ret = FALSE;
+ g_object_unref (source);
g_object_unref (is->stream);
is->stream = NULL;
#define io(...) camel_imapx_debug(io, __VA_ARGS__)
struct _CamelIMAPXStreamPrivate {
+ CamelStream *source;
+
guchar *buf, *ptr, *end;
guint literal;
guint bufsize;
};
+enum {
+ PROP_0,
+ PROP_SOURCE
+};
+
G_DEFINE_TYPE (CamelIMAPXStream, camel_imapx_stream, CAMEL_TYPE_STREAM)
static gint
{
gint left = 0;
- if (is->source) {
+ if (is->priv->source != NULL) {
left = is->priv->end - is->priv->ptr;
memcpy (is->priv->buf, is->priv->ptr, left);
is->priv->end = is->priv->buf + left;
is->priv->ptr = is->priv->buf;
left = camel_stream_read (
- is->source, (gchar *) is->priv->end,
+ is->priv->source,
+ (gchar *) is->priv->end,
is->priv->bufsize - (is->priv->end - is->priv->buf),
cancellable, error);
if (left > 0) {
}
static void
+imapx_stream_set_source (CamelIMAPXStream *stream,
+ CamelStream *source)
+{
+ g_return_if_fail (CAMEL_IS_STREAM (source));
+ g_return_if_fail (stream->priv->source == NULL);
+
+ stream->priv->source = g_object_ref (source);
+}
+
+static void
+imapx_stream_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_SOURCE:
+ imapx_stream_set_source (
+ CAMEL_IMAPX_STREAM (object),
+ g_value_get_object (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+imapx_stream_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_SOURCE:
+ g_value_take_object (
+ value,
+ camel_imapx_stream_ref_source (
+ CAMEL_IMAPX_STREAM (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
imapx_stream_dispose (GObject *object)
{
CamelIMAPXStream *stream = CAMEL_IMAPX_STREAM (object);
- if (stream->source != NULL) {
- g_object_unref (stream->source);
- stream->source = NULL;
+ if (stream->priv->source != NULL) {
+ g_object_unref (stream->priv->source);
+ stream->priv->source = NULL;
}
/* Chain up to parent's dispose() method. */
is->priv->ptr += max;
} else {
max = MIN (is->priv->literal, n);
- max = camel_stream_read (is->source, buffer, max, cancellable, error);
+ max = camel_stream_read (
+ is->priv->source,
+ buffer, max, cancellable, error);
if (max <= 0)
return max;
}
io (is->tagprefix, "camel_imapx_write: '%.*s'\n", (gint) n, buffer);
}
- return camel_stream_write (is->source, buffer, n, cancellable, error);
+ return camel_stream_write (
+ is->priv->source,
+ buffer, n, cancellable, error);
}
static gint
g_type_class_add_private (class, sizeof (CamelIMAPXStreamPrivate));
object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = imapx_stream_set_property;
+ object_class->get_property = imapx_stream_get_property;
object_class->dispose = imapx_stream_dispose;
object_class->finalize = imapx_stream_finalize;
stream_class->close = imapx_stream_close;
stream_class->flush = imapx_stream_flush;
stream_class->eos = imapx_stream_eos;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_SOURCE,
+ g_param_spec_object (
+ "source",
+ "Source",
+ "Source stream",
+ CAMEL_TYPE_STREAM,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
}
static void
*bufptr = is->priv->buf + (*bufptr - oldbuf);
}
+GQuark
+camel_imapx_error_quark (void)
+{
+ static GQuark quark = 0;
+
+ if (G_UNLIKELY (quark == 0)) {
+ const gchar *string = "camel-imapx-error-quark";
+ quark = g_quark_from_static_string (string);
+ }
+
+ return quark;
+}
+
/**
* camel_imapx_stream_new:
*
CamelStream *
camel_imapx_stream_new (CamelStream *source)
{
- CamelIMAPXStream *is;
-
g_return_val_if_fail (CAMEL_IS_STREAM (source), NULL);
- is = g_object_new (CAMEL_TYPE_IMAPX_STREAM, NULL);
- is->source = g_object_ref (source);
-
- return (CamelStream *) is;
+ return g_object_new (
+ CAMEL_TYPE_IMAPX_STREAM,
+ "source", source, NULL);
}
-GQuark
-camel_imapx_error_quark (void)
+CamelStream *
+camel_imapx_stream_ref_source (CamelIMAPXStream *is)
{
- static GQuark quark = 0;
+ g_return_val_if_fail (CAMEL_IS_IMAPX_STREAM (is), NULL);
- if (G_UNLIKELY (quark == 0)) {
- const gchar *string = "camel-imapx-error-quark";
- quark = g_quark_from_static_string (string);
- }
-
- return quark;
+ return g_object_ref (is->priv->source);
}
/* Returns if there is any data buffered that is ready for processing */